Completed
Branch master (0db715)
by
unknown
06:15 queued 04:28
created
messages/templates/ee_msg_editor_active_context_element.template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
16 16
 
17
-$active_message   = sprintf(
17
+$active_message = sprintf(
18 18
     esc_html__(
19 19
         'The template for %1$s is currently %2$sactive%3$s.',
20 20
         'event_espresso'
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@  discard block
 block discarded – undo
15 15
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
16 16
 
17 17
 $active_message   = sprintf(
18
-    esc_html__(
19
-        'The template for %1$s is currently %2$sactive%3$s.',
20
-        'event_espresso'
21
-    ),
22
-    $context_label,
23
-    '<strong>',
24
-    '</strong>'
18
+	esc_html__(
19
+		'The template for %1$s is currently %2$sactive%3$s.',
20
+		'event_espresso'
21
+	),
22
+	$context_label,
23
+	'<strong>',
24
+	'</strong>'
25 25
 );
26 26
 $inactive_message = sprintf(
27
-    esc_html__(
28
-        'The template for %1$s is currently %2$sinactive%3$s.',
29
-        'event_espresso'
30
-    ),
31
-    $context_label,
32
-    '<strong>',
33
-    '</strong>'
27
+	esc_html__(
28
+		'The template for %1$s is currently %2$sinactive%3$s.',
29
+		'event_espresso'
30
+	),
31
+	$context_label,
32
+	'<strong>',
33
+	'</strong>'
34 34
 );
35 35
 
36 36
 $context = esc_attr($context);
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
         </span>
45 45
         <span class="ee-on-off-toggle-label">
46 46
             <?php
47
-            echo ($is_active
48
-                ? wp_kses($active_message, AllowedTags::getAllowedTags())
49
-                : wp_kses($inactive_message, AllowedTags::getAllowedTags()));
50
-            ?>
47
+			echo ($is_active
48
+				? wp_kses($active_message, AllowedTags::getAllowedTags())
49
+				: wp_kses($inactive_message, AllowedTags::getAllowedTags()));
50
+			?>
51 51
         </span>
52 52
         <div class="hidden js-data">
53 53
             <span class="ee-active-message"><?php echo wp_kses($active_message, AllowedTags::getAllowedTags()); ?></span>
Please login to merge, or discard this patch.
admin_pages/messages/templates/ee_msg_mt_settings_content.template.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@
 block discarded – undo
18 18
     <div class="mt-settings">
19 19
         <form method="POST" action="" class="mt-settings-form<?php echo esc_attr($show_form); ?>">
20 20
             <?php
21
-            echo wp_kses($template_form_fields, AllowedTags::getWithFormTags());
22
-            foreach ($hidden_fields as $field) {
23
-                echo wp_kses($field['field'], AllowedTags::getWithFormTags());
24
-            }
25
-            ?>
21
+			echo wp_kses($template_form_fields, AllowedTags::getWithFormTags());
22
+			foreach ($hidden_fields as $field) {
23
+				echo wp_kses($field['field'], AllowedTags::getWithFormTags());
24
+			}
25
+			?>
26 26
             <input class='button-secondary mt-settings-submit no-drag'
27 27
                    type="submit"
28 28
                    value="<?php esc_attr_e('Submit', 'event_espresso'); ?>"
Please login to merge, or discard this patch.
messages/templates/ee_msg_details_messenger_mt_meta_box.template.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,23 +15,23 @@
 block discarded – undo
15 15
 <div class="<?php echo esc_attr($messenger); ?>-content">
16 16
     <?php echo wp_kses($content, AllowedTags::getWithFormTags()); ?>
17 17
     <?php if (empty($inactive_message_types) && empty($active_message_types)) :
18
-        echo '<p>'
19
-             . esc_html__(
20
-                 'This messenger is not currently used with any message types for templates but merely adds to the shortcodes available for templates on other messenger and message types.',
21
-                 'event_espresso'
22
-             )
23
-             . '</p>';
24
-    else : ?>
18
+		echo '<p>'
19
+			 . esc_html__(
20
+				 'This messenger is not currently used with any message types for templates but merely adds to the shortcodes available for templates on other messenger and message types.',
21
+				 'event_espresso'
22
+			 )
23
+			 . '</p>';
24
+	else : ?>
25 25
         <p class="active-on-message <?php echo esc_attr($hide_on_message); ?>">
26 26
             <?php printf(
27
-                esc_html__(
28
-                    'Below are message types that are currently %sactive%s with this messenger. Drag them over to the "Inactive Message Types" box to deactivate them.',
29
-                    'event_espresso'
30
-                ),
31
-                '<strong>',
32
-                '</strong>'
33
-            );
34
-            ?>
27
+				esc_html__(
28
+					'Below are message types that are currently %sactive%s with this messenger. Drag them over to the "Inactive Message Types" box to deactivate them.',
29
+					'event_espresso'
30
+				),
31
+				'<strong>',
32
+				'</strong>'
33
+			);
34
+			?>
35 35
         <p>
36 36
         <div<?php if ($active) : ?>
37 37
             id="active-message-types"
Please login to merge, or discard this patch.
messages/templates/ee_msg_details_main_edit_meta_box.template.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
     <input type="hidden" id="ee-msg-current-context" name="MTP_context" value="<?php echo esc_attr($context); ?>" />
20 20
     <!-- if this is not a global template then let's show the name and description fields -->
21 21
     <?php
22
-    if (! $MTP->is_global()) : ?>
22
+	if (! $MTP->is_global()) : ?>
23 23
         <div class="non-global-mtp-fields">
24 24
             <p>
25 25
                 <?php esc_html_e(
26
-                    'This is a custom template.  Custom Templates have an editable name and description to help you differentiate between templates.',
27
-                    'event_espresso'
28
-                ); ?>
26
+					'This is a custom template.  Custom Templates have an editable name and description to help you differentiate between templates.',
27
+					'event_espresso'
28
+				); ?>
29 29
             </p>
30 30
             <div id="titlediv">
31 31
                 <div id="titlewrap">
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-    else :
60
-        ?>
59
+	else :
60
+		?>
61 61
         <input type="hidden" name="ee_msg_non_global_fields[MTP_name]" value="<?php echo esc_attr($MTP->name()); ?>">
62 62
         <input type="hidden"
63 63
                name="ee_msg_non_global_fields[MTP_description]"
@@ -66,18 +66,18 @@  discard block
 block discarded – undo
66 66
     <?php endif; ?>
67 67
     <!-- we need to loop through the template_fields so we know our structure -->
68 68
     <?php
69
-    if (isset($template_fields) && ! empty($template_fields) && ! is_wp_error($template_fields)) {
70
-        echo wp_kses($template_fields, AllowedTags::getWithFormTags());
71
-    } else {
72
-        ?>
69
+	if (isset($template_fields) && ! empty($template_fields) && ! is_wp_error($template_fields)) {
70
+		echo wp_kses($template_fields, AllowedTags::getWithFormTags());
71
+	} else {
72
+		?>
73 73
         <p>
74 74
             <?php esc_html_e(
75
-                'Something has gone wrong, there are no template fields to output.',
76
-                'event_espresso'
77
-            ); ?>
75
+				'Something has gone wrong, there are no template fields to output.',
76
+				'event_espresso'
77
+			); ?>
78 78
         </p>
79 79
         <?php
80
-    }
80
+	}
81 81
 
82
-    ?>
82
+	?>
83 83
 </div> <!-- end #admin-primary-mbox-dv -->
Please login to merge, or discard this patch.
admin_pages/messages/templates/ee_msg_m_settings_content.template.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,9 +45,9 @@
 block discarded – undo
45 45
         <form method="POST" action="" class="mt-settings-form">
46 46
             <?php echo wp_kses($template_form_fields, AllowedTags::getWithFormTags()); ?>
47 47
             <?php
48
-            foreach ($hidden_fields as $name => $field) {
49
-                echo wp_kses($field['field'], AllowedTags::getWithFormTags());
50
-            } ?>
48
+			foreach ($hidden_fields as $name => $field) {
49
+				echo wp_kses($field['field'], AllowedTags::getWithFormTags());
50
+			} ?>
51 51
             <input type="submit"
52 52
                    value="<?php esc_attr_e('Submit', 'event_espresso'); ?>"
53 53
                    class="button-secondary no-drag"
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Spacing   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function getMsgModel()
117 117
     {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
119 119
             $this->MSG_MODEL = EEM_Message::instance();
120 120
         }
121 121
         return $this->MSG_MODEL;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function getMtpModel()
130 130
     {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
132 132
             $this->MTP_MODEL = EEM_Message_Template::instance();
133 133
         }
134 134
         return $this->MTP_MODEL;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function getMtgModel()
143 143
     {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145 145
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146 146
         }
147 147
         return $this->MTG_MODEL;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
         $i = 1;
212 212
         foreach ($active_messengers as $active_messenger) {
213 213
             if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
214
+                $m_values[$i]['id']   = $active_messenger->messenger();
215
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
216 216
                 $i++;
217 217
             }
218 218
         }
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
         $i               = 1;
249 249
         foreach ($active_messages as $active_message) {
250 250
             if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
251
+                $mt_values[$i]['id']   = $active_message->message_type();
252
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
253 253
                 $i++;
254 254
             }
255 255
         }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 if ($message_type instanceof EE_message_type) {
289 289
                     $message_type_contexts = $message_type->get_contexts();
290 290
                     foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
291
+                        $contexts[$context] = $context_details['label'];
292 292
                     }
293 293
                 }
294 294
             }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322 322
             $messenger_options
323 323
         );
324
-        $input             = new EE_Select_Input(
324
+        $input = new EE_Select_Input(
325 325
             $messenger_options,
326 326
             [
327 327
                 'html_name'  => 'ee_messenger_filter_by',
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359 359
             $message_type_options
360 360
         );
361
-        $input                = new EE_Select_Input(
361
+        $input = new EE_Select_Input(
362 362
             $message_type_options,
363 363
             [
364 364
                 'html_name'  => 'ee_message_type_filter_by',
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396 396
             $context_options
397 397
         );
398
-        $input           = new EE_Select_Input(
398
+        $input = new EE_Select_Input(
399 399
             $context_options,
400 400
             [
401 401
                 'html_name'  => 'ee_context_filter_by',
@@ -769,53 +769,53 @@  discard block
 block discarded – undo
769 769
 
770 770
     public function messages_help_tab()
771 771
     {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
773 773
     }
774 774
 
775 775
 
776 776
     public function messengers_help_tab()
777 777
     {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
779 779
     }
780 780
 
781 781
 
782 782
     public function message_types_help_tab()
783 783
     {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
785 785
     }
786 786
 
787 787
 
788 788
     public function messages_overview_help_tab()
789 789
     {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
791 791
     }
792 792
 
793 793
 
794 794
     public function message_templates_help_tab()
795 795
     {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
797 797
     }
798 798
 
799 799
 
800 800
     public function edit_message_template_help_tab()
801 801
     {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
803 803
                         . esc_attr__('Editor Title', 'event_espresso')
804 804
                         . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
806 806
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
807 807
                         . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
809 809
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
810 810
                         . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
812 812
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
813 813
                         . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
815 815
                         . esc_attr__('Publish Metabox', 'event_espresso')
816 816
                         . '" />';
817 817
         EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
819 819
             $args
820 820
         );
821 821
     }
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
         $this->_set_shortcodes();
831 831
         $args['shortcodes'] = $this->_shortcodes;
832 832
         EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
834 834
             $args
835 835
         );
836 836
     }
@@ -838,16 +838,16 @@  discard block
 block discarded – undo
838 838
 
839 839
     public function preview_message_help_tab()
840 840
     {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
842 842
     }
843 843
 
844 844
 
845 845
     public function settings_help_tab()
846 846
     {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
847
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
848
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
849
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
850
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
851 851
         $args['img3'] = '<div class="switch">'
852 852
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853 853
                         . ' type="checkbox" checked="checked">'
@@ -858,25 +858,25 @@  discard block
 block discarded – undo
858 858
                         . ' type="checkbox">'
859 859
                         . '<label for="ee-on-off-toggle-on"></label>'
860 860
                         . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
862 862
     }
863 863
 
864 864
 
865 865
     public function load_scripts_styles()
866 866
     {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868 868
         wp_enqueue_style('espresso_ee_msg');
869 869
 
870 870
         wp_register_script(
871 871
             'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
873 873
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
874 874
             EVENT_ESPRESSO_VERSION,
875 875
             true
876 876
         );
877 877
         wp_register_script(
878 878
             'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
880 880
             ['ee-dialog'],
881 881
             EVENT_ESPRESSO_VERSION
882 882
         );
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 
920 920
         $this->_set_shortcodes();
921 921
 
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
923 923
             esc_html__(
924 924
                 'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925 925
                 'event_espresso'
@@ -931,14 +931,14 @@  discard block
 block discarded – undo
931 931
             'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932 932
             'event_espresso'
933 933
         );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
935 935
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936 936
             'event_espresso'
937 937
         );
938 938
 
939 939
         wp_register_script(
940 940
             'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
942 942
             ['jquery'],
943 943
             EVENT_ESPRESSO_VERSION
944 944
         );
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
     {
982 982
         wp_register_style(
983 983
             'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
985 985
             [],
986 986
             EVENT_ESPRESSO_VERSION
987 987
         );
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
             }
1068 1068
             $status_bulk_actions = $common_bulk_actions;
1069 1069
             // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1070
+            if ( ! empty($status_bulk_actions)) {
1071 1071
                 switch ($status) {
1072 1072
                     case EEM_Message::status_idle:
1073 1073
                     case EEM_Message::status_resend:
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
                 continue;
1097 1097
             }
1098 1098
 
1099
-            $this->_views[ strtolower($status) ] = [
1099
+            $this->_views[strtolower($status)] = [
1100 1100
                 'slug'        => strtolower($status),
1101 1101
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102 1102
                 'count'       => 0,
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
             if ($action_item === 'see_notifications_for') {
1146 1146
                 continue;
1147 1147
             }
1148
-            $action_items[ $action_item ] = [
1148
+            $action_items[$action_item] = [
1149 1149
                 'class' => $action_details['css_class'],
1150 1150
                 'desc'  => $action_details['label'],
1151 1151
             ];
@@ -1154,37 +1154,37 @@  discard block
 block discarded – undo
1154 1154
         /** @var array $status_items status legend setup */
1155 1155
         $status_items = [
1156 1156
             'sent_status'                => [
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1157
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1158 1158
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159 1159
             ],
1160 1160
             'idle_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1161
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1162 1162
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163 1163
             ],
1164 1164
             'failed_status'              => [
1165
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1165
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1166 1166
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167 1167
             ],
1168 1168
             'messenger_executing_status' => [
1169
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1169
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1170 1170
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171 1171
             ],
1172 1172
             'resend_status'              => [
1173
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1173
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1174 1174
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175 1175
             ],
1176 1176
             'incomplete_status'          => [
1177
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1177
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1178 1178
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179 1179
             ],
1180 1180
             'retry_status'               => [
1181
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1181
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1182 1182
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183 1183
             ],
1184 1184
         ];
1185 1185
         if (EEM_Message::debug()) {
1186 1186
             $status_items['debug_only_status'] = [
1187
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1187
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1188 1188
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189 1189
             ];
1190 1190
         }
@@ -1199,11 +1199,11 @@  discard block
 block discarded – undo
1199 1199
     protected function _custom_mtps_preview()
1200 1200
     {
1201 1201
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
-                                                . ' alt="' . esc_attr__(
1202
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1203
+                                                . ' alt="'.esc_attr__(
1204 1204
                                                     'Preview Custom Message Templates screenshot',
1205 1205
                                                     'event_espresso'
1206
-                                                ) . '" />';
1206
+                                                ).'" />';
1207 1207
         $this->_template_args['preview_text'] = '<strong>'
1208 1208
                                                 . esc_html__(
1209 1209
                                                     'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
@@ -1279,7 +1279,7 @@  discard block
 block discarded – undo
1279 1279
         $installed               = [];
1280 1280
 
1281 1281
         foreach ($installed_message_types as $message_type) {
1282
-            $installed[ $message_type->name ] = $message_type;
1282
+            $installed[$message_type->name] = $message_type;
1283 1283
         }
1284 1284
 
1285 1285
         return $installed;
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
         // we need to assemble the title from Various details
1406 1406
         $context_label = sprintf(
1407 1407
             esc_html__('(%s %s)', 'event_espresso'),
1408
-            $c_config[ $context ]['label'],
1408
+            $c_config[$context]['label'],
1409 1409
             ucwords($c_label['label'])
1410 1410
         );
1411 1411
 
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
             $message_template_group->message_type()
1428 1428
         );
1429 1429
 
1430
-        if (! $template_field_structure) {
1430
+        if ( ! $template_field_structure) {
1431 1431
             $template_field_structure = false;
1432 1432
             $template_fields          = esc_html__(
1433 1433
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1441,21 +1441,21 @@  discard block
 block discarded – undo
1441 1441
 
1442 1442
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443 1443
         // will get handled in the "extra" array.
1444
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
-                unset($template_field_structure[ $context ][ $reference_field ]);
1444
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1445
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1446
+                unset($template_field_structure[$context][$reference_field]);
1447 1447
             }
1448 1448
         }
1449 1449
 
1450 1450
         // let's loop through the template_field_structure and actually assemble the input fields!
1451
-        if (! empty($template_field_structure)) {
1452
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1451
+        if ( ! empty($template_field_structure)) {
1452
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1453 1453
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454 1454
                 // the extra array and reset them.
1455 1455
                 if ($template_field === 'extra') {
1456 1456
                     $this->_template_args['is_extra_fields'] = true;
1457 1457
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1458
+                        $message_template = $message_templates[$context][$reference_field];
1459 1459
                         $content          = $message_template instanceof EE_Message_Template
1460 1460
                             ? $message_template->get('MTP_content')
1461 1461
                             : '';
@@ -1464,7 +1464,7 @@  discard block
 block discarded – undo
1464 1464
                             $continue = false;
1465 1465
                             if (isset($extra_array['shortcodes_required'])) {
1466 1466
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1468 1468
                                         $continue = true;
1469 1469
                                     }
1470 1470
                                 }
@@ -1473,53 +1473,53 @@  discard block
 block discarded – undo
1473 1473
                                 }
1474 1474
                             }
1475 1475
 
1476
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1476
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1477 1477
 
1478
-                            $template_form_fields[ $field_id ]         = $extra_array;
1479
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1478
+                            $template_form_fields[$field_id]         = $extra_array;
1479
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1480 1480
                                                                          . $reference_field
1481 1481
                                                                          . '][content]['
1482
-                                                                         . $extra_field . ']';
1483
-                            $css_class                                 = isset($extra_array['css_class'])
1482
+                                                                         . $extra_field.']';
1483
+                            $css_class = isset($extra_array['css_class'])
1484 1484
                                 ? $extra_array['css_class']
1485 1485
                                 : '';
1486 1486
 
1487
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1488 1488
                                                                               && in_array($extra_field, $v_fields, true)
1489 1489
                                                                               && (
1490
-                                                                                  is_array($validators[ $extra_field ])
1491
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1490
+                                                                                  is_array($validators[$extra_field])
1491
+                                                                                  && isset($validators[$extra_field]['msg'])
1492 1492
                                                                               )
1493
-                                ? 'validate-error ' . $css_class
1493
+                                ? 'validate-error '.$css_class
1494 1494
                                 : $css_class;
1495 1495
 
1496
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
-                                                                          && isset($content[ $extra_field ])
1498
-                                ? $content[ $extra_field ]
1496
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1497
+                                                                          && isset($content[$extra_field])
1498
+                                ? $content[$extra_field]
1499 1499
                                 : '';
1500 1500
 
1501 1501
                             // do we have a validation error?  if we do then let's use that value instead
1502
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
-                                ? $validators[ $extra_field ]['value']
1504
-                                : $template_form_fields[ $field_id ]['value'];
1502
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1503
+                                ? $validators[$extra_field]['value']
1504
+                                : $template_form_fields[$field_id]['value'];
1505 1505
 
1506 1506
 
1507
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1508 1508
 
1509 1509
                             // shortcode selector
1510 1510
                             $field_name_to_use                                   = $extra_field === 'main'
1511 1511
                                 ? 'content'
1512 1512
                                 : $extra_field;
1513
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1514 1514
                                 $field_name_to_use,
1515 1515
                                 $field_id
1516 1516
                             );
1517 1517
                         }
1518
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
-                        $template_field_template_name_id = $reference_field . '-name';
1518
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1519
+                        $template_field_template_name_id = $reference_field.'-name';
1520 1520
 
1521
-                        $template_form_fields[ $template_field_MTP_id ] = [
1522
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1521
+                        $template_form_fields[$template_field_MTP_id] = [
1522
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1523 1523
                             'label'      => null,
1524 1524
                             'input'      => 'hidden',
1525 1525
                             'type'       => 'int',
@@ -1531,8 +1531,8 @@  discard block
 block discarded – undo
1531 1531
                             'db-col'     => 'MTP_ID',
1532 1532
                         ];
1533 1533
 
1534
-                        $template_form_fields[ $template_field_template_name_id ] = [
1535
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1534
+                        $template_form_fields[$template_field_template_name_id] = [
1535
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1536 1536
                             'label'      => null,
1537 1537
                             'input'      => 'hidden',
1538 1538
                             'type'       => 'string',
@@ -1546,38 +1546,38 @@  discard block
 block discarded – undo
1546 1546
                     }
1547 1547
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548 1548
                 } else {
1549
-                    $field_id                                   = $template_field . '-content';
1550
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1551
-                    $template_form_fields[ $field_id ]['name']  =
1552
-                        'MTP_template_fields[' . $template_field . '][content]';
1549
+                    $field_id                                   = $template_field.'-content';
1550
+                    $template_form_fields[$field_id]          = $field_setup_array;
1551
+                    $template_form_fields[$field_id]['name']  =
1552
+                        'MTP_template_fields['.$template_field.'][content]';
1553 1553
                     $message_template                           =
1554
-                        isset($message_templates[ $context ][ $template_field ])
1555
-                            ? $message_templates[ $context ][ $template_field ]
1554
+                        isset($message_templates[$context][$template_field])
1555
+                            ? $message_templates[$context][$template_field]
1556 1556
                             : null;
1557
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
-                                                                  && is_array($message_templates[ $context ])
1557
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1558
+                                                                  && is_array($message_templates[$context])
1559 1559
                                                                   && $message_template instanceof EE_Message_Template
1560 1560
                         ? $message_template->get('MTP_content')
1561 1561
                         : '';
1562 1562
 
1563 1563
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1564
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
-                        ? $validators[ $template_field ]['value']
1566
-                        : $template_form_fields[ $field_id ]['value'];
1564
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1565
+                        ? $validators[$template_field]['value']
1566
+                        : $template_form_fields[$field_id]['value'];
1567 1567
 
1568 1568
 
1569
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1570 1570
                     $css_class                                      = isset($field_setup_array['css_class'])
1571 1571
                         ? $field_setup_array['css_class']
1572 1572
                         : '';
1573
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1574 1574
                                                                       && in_array($template_field, $v_fields, true)
1575
-                                                                      && isset($validators[ $template_field ]['msg'])
1576
-                        ? 'validate-error ' . $css_class
1575
+                                                                      && isset($validators[$template_field]['msg'])
1576
+                        ? 'validate-error '.$css_class
1577 1577
                         : $css_class;
1578 1578
 
1579 1579
                     // shortcode selector
1580
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1581 1581
                         $template_field,
1582 1582
                         $field_id
1583 1583
                     );
@@ -1585,12 +1585,12 @@  discard block
 block discarded – undo
1585 1585
 
1586 1586
                 // k took care of content field(s) now let's take care of others.
1587 1587
 
1588
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
-                $template_field_field_template_name_id = $template_field . '-name';
1588
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1589
+                $template_field_field_template_name_id = $template_field.'-name';
1590 1590
 
1591 1591
                 // foreach template field there are actually two form fields created
1592
-                $template_form_fields[ $template_field_MTP_id ] = [
1593
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1592
+                $template_form_fields[$template_field_MTP_id] = [
1593
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1594 1594
                     'label'      => null,
1595 1595
                     'input'      => 'hidden',
1596 1596
                     'type'       => 'int',
@@ -1602,8 +1602,8 @@  discard block
 block discarded – undo
1602 1602
                     'db-col'     => 'MTP_ID',
1603 1603
                 ];
1604 1604
 
1605
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1606
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1605
+                $template_form_fields[$template_field_field_template_name_id] = [
1606
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1607 1607
                     'label'      => null,
1608 1608
                     'input'      => 'hidden',
1609 1609
                     'type'       => 'string',
@@ -1720,7 +1720,7 @@  discard block
 block discarded – undo
1720 1720
                 'format'     => '%d',
1721 1721
                 'db-col'     => 'MTP_deleted',
1722 1722
             ];
1723
-            $sidebar_form_fields['ee-msg-author']  = [
1723
+            $sidebar_form_fields['ee-msg-author'] = [
1724 1724
                 'name'       => 'MTP_user_id',
1725 1725
                 'label'      => esc_html__('Author', 'event_espresso'),
1726 1726
                 'input'      => 'hidden',
@@ -1739,17 +1739,17 @@  discard block
 block discarded – undo
1739 1739
                 'value' => $action,
1740 1740
             ];
1741 1741
 
1742
-            $sidebar_form_fields['ee-msg-id']        = [
1742
+            $sidebar_form_fields['ee-msg-id'] = [
1743 1743
                 'name'  => 'id',
1744 1744
                 'input' => 'hidden',
1745 1745
                 'type'  => 'int',
1746 1746
                 'value' => $GRP_ID,
1747 1747
             ];
1748 1748
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
-                'name'  => $action . '_nonce',
1749
+                'name'  => $action.'_nonce',
1750 1750
                 'input' => 'hidden',
1751 1751
                 'type'  => 'string',
1752
-                'value' => wp_create_nonce($action . '_nonce'),
1752
+                'value' => wp_create_nonce($action.'_nonce'),
1753 1753
             ];
1754 1754
 
1755 1755
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1780,7 +1780,7 @@  discard block
 block discarded – undo
1780 1780
         );
1781 1781
 
1782 1782
         // add preview button
1783
-        $preview_url    = parent::add_query_args_and_nonce(
1783
+        $preview_url = parent::add_query_args_and_nonce(
1784 1784
             [
1785 1785
                 'message_type' => $message_template_group->message_type(),
1786 1786
                 'messenger'    => $message_template_group->messenger(),
@@ -1791,7 +1791,7 @@  discard block
 block discarded – undo
1791 1791
             ],
1792 1792
             $this->_admin_base_url
1793 1793
         );
1794
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1794
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1795 1795
                           . esc_html__('Preview', 'event_espresso')
1796 1796
                           . '</a>';
1797 1797
 
@@ -1827,11 +1827,11 @@  discard block
 block discarded – undo
1827 1827
             $context_label
1828 1828
         );
1829 1829
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1830
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1831 1831
 
1832 1832
         $this->_template_path = $this->_template_args['GRP_ID']
1833 1833
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1834
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1835 1835
 
1836 1836
         // send along EE_Message_Template_Group object for further template use.
1837 1837
         $this->_template_args['MTP'] = $message_template_group;
@@ -1887,7 +1887,7 @@  discard block
 block discarded – undo
1887 1887
     ) {
1888 1888
         $template_args = [
1889 1889
             'context'                   => $context,
1890
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1891 1891
             'is_active'                 => $message_template_group->is_context_active($context),
1892 1892
             'on_off_action'             => $message_template_group->is_context_active($context)
1893 1893
                 ? 'context-off'
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
             'message_template_group_id' => $message_template_group->ID(),
1897 1897
         ];
1898 1898
         return EEH_Template::display_template(
1899
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1899
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1900 1900
             $template_args,
1901 1901
             true
1902 1902
         );
@@ -1953,7 +1953,7 @@  discard block
 block discarded – undo
1953 1953
         }
1954 1954
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955 1955
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1956
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1957 1957
             EE_Error::add_error(
1958 1958
                 sprintf(
1959 1959
                     esc_html__(
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
         $messenger    = $this->request->getRequestParam('msgr');
2085 2085
         $message_type = $this->request->getRequestParam('mt');
2086 2086
         // we need to make sure we've got the info we need.
2087
-        if (! ($GRP_ID && $messenger && $message_type)) {
2087
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2088 2088
             EE_Error::add_error(
2089 2089
                 esc_html__(
2090 2090
                     'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
@@ -2121,7 +2121,7 @@  discard block
 block discarded – undo
2121 2121
         }
2122 2122
 
2123 2123
         // any error messages?
2124
-        if (! $success) {
2124
+        if ( ! $success) {
2125 2125
             EE_Error::add_error(
2126 2126
                 esc_html__(
2127 2127
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2170,7 +2170,7 @@  discard block
 block discarded – undo
2170 2170
     {
2171 2171
         // first make sure we've got the necessary parameters
2172 2172
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174 2174
             EE_Error::add_error(
2175 2175
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176 2176
                 __FILE__,
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197 2197
 
2198 2198
         // let's add a button to go back to the edit view
2199
-        $query_args             = [
2199
+        $query_args = [
2200 2200
             'id'      => $GRP_ID,
2201 2201
             'evt_id'  => $EVT_ID,
2202 2202
             'context' => $context,
@@ -2217,7 +2217,7 @@  discard block
 block discarded – undo
2217 2217
         $preview_title = sprintf(
2218 2218
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219 2219
             $active_messenger_label,
2220
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2220
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2221 2221
         );
2222 2222
         if (empty($preview)) {
2223 2223
             $this->noEventsErrorMessage();
@@ -2225,7 +2225,7 @@  discard block
 block discarded – undo
2225 2225
         // setup display of preview.
2226 2226
         $this->_admin_page_title                    = $preview_title;
2227 2227
         $this->_template_args['admin_page_title']   = $preview_title;
2228
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2228
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2229 2229
         $this->_template_args['data']['force_json'] = true;
2230 2230
 
2231 2231
         return '';
@@ -2246,7 +2246,7 @@  discard block
 block discarded – undo
2246 2246
             ],
2247 2247
             admin_url('admin.php')
2248 2248
         );
2249
-        $message    = $test_send
2249
+        $message = $test_send
2250 2250
             ? esc_html__(
2251 2251
                 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252 2252
                 'event_espresso'
@@ -2339,10 +2339,10 @@  discard block
 block discarded – undo
2339 2339
             // only include template packs that support this messenger and message type!
2340 2340
             $supports = $tp->get_supports();
2341 2341
             if (
2342
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2342
+                ! isset($supports[$this->_message_template_group->messenger()])
2343 2343
                 || ! in_array(
2344 2344
                     $this->_message_template_group->message_type(),
2345
-                    $supports[ $this->_message_template_group->messenger() ],
2345
+                    $supports[$this->_message_template_group->messenger()],
2346 2346
                     true
2347 2347
                 )
2348 2348
             ) {
@@ -2366,7 +2366,7 @@  discard block
 block discarded – undo
2366 2366
         }
2367 2367
 
2368 2368
         // setup variation select values for the currently selected template.
2369
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2369
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2370 2370
             $this->_message_template_group->messenger(),
2371 2371
             $this->_message_template_group->message_type()
2372 2372
         );
@@ -2380,12 +2380,12 @@  discard block
 block discarded – undo
2380 2380
 
2381 2381
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382 2382
 
2383
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2383
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2384 2384
             'MTP_template_pack',
2385 2385
             $tp_select_values,
2386 2386
             $this->_message_template_group->get_template_pack_name()
2387 2387
         );
2388
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2388
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2389 2389
             'MTP_template_variation',
2390 2390
             $variations_select_values,
2391 2391
             $this->_message_template_group->get_template_pack_variation()
@@ -2395,7 +2395,7 @@  discard block
 block discarded – undo
2395 2395
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396 2396
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397 2397
 
2398
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2398
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2399 2399
 
2400 2400
         EEH_Template::display_template($template, $template_args);
2401 2401
     }
@@ -2421,33 +2421,33 @@  discard block
 block discarded – undo
2421 2421
         // first we need to see if there are any fields
2422 2422
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423 2423
 
2424
-        if (! empty($fields)) {
2424
+        if ( ! empty($fields)) {
2425 2425
             // yup there be fields
2426 2426
             foreach ($fields as $field => $config) {
2427
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2427
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2428 2428
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429 2429
                 $default  = isset($config['default']) ? $config['default'] : '';
2430 2430
                 $default  = isset($config['value']) ? $config['value'] : $default;
2431 2431
 
2432 2432
                 // if type is hidden and the value is empty
2433 2433
                 // something may have gone wrong so let's correct with the defaults
2434
-                $fix                = $config['input'] === 'hidden'
2435
-                                      && isset($existing[ $field ])
2436
-                                      && empty($existing[ $field ])
2434
+                $fix = $config['input'] === 'hidden'
2435
+                                      && isset($existing[$field])
2436
+                                      && empty($existing[$field])
2437 2437
                     ? $default
2438 2438
                     : '';
2439
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
-                    ? $existing[ $field ]
2439
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2440
+                    ? $existing[$field]
2441 2441
                     : $fix;
2442 2442
 
2443
-                $template_form_fields[ $field_id ] = [
2444
-                    'name'       => 'test_settings_fld[' . $field . ']',
2443
+                $template_form_fields[$field_id] = [
2444
+                    'name'       => 'test_settings_fld['.$field.']',
2445 2445
                     'label'      => $config['label'],
2446 2446
                     'input'      => $config['input'],
2447 2447
                     'type'       => $config['type'],
2448 2448
                     'required'   => $config['required'],
2449 2449
                     'validation' => $config['validation'],
2450
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2450
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2451 2451
                     'css_class'  => $config['css_class'],
2452 2452
                     'options'    => isset($config['options']) ? $config['options'] : [],
2453 2453
                     'default'    => $default,
@@ -2461,7 +2461,7 @@  discard block
 block discarded – undo
2461 2461
             : '';
2462 2462
 
2463 2463
         // print out $test_settings_fields
2464
-        if (! empty($test_settings_html)) {
2464
+        if ( ! empty($test_settings_html)) {
2465 2465
             $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466 2466
             $test_settings_html .= 'name="test_button" value="';
2467 2467
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2507,7 +2507,7 @@  discard block
 block discarded – undo
2507 2507
         ];
2508 2508
 
2509 2509
         return EEH_Template::display_template(
2510
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2510
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2511 2511
             $template_args,
2512 2512
             true
2513 2513
         );
@@ -2533,7 +2533,7 @@  discard block
 block discarded – undo
2533 2533
         // $messenger = $this->_message_template_group->messenger_obj();
2534 2534
         // now let's set the content depending on the status of the shortcodes array
2535 2535
         if (empty($shortcodes)) {
2536
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2536
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2537 2537
             return;
2538 2538
         }
2539 2539
         ?>
@@ -2569,7 +2569,7 @@  discard block
 block discarded – undo
2569 2569
     {
2570 2570
 
2571 2571
         // no need to run this if the property is already set
2572
-        if (! empty($this->_shortcodes)) {
2572
+        if ( ! empty($this->_shortcodes)) {
2573 2573
             return;
2574 2574
         }
2575 2575
 
@@ -2624,7 +2624,7 @@  discard block
 block discarded – undo
2624 2624
     protected function _set_message_template_group()
2625 2625
     {
2626 2626
         // get out if this is already set.
2627
-        if (! empty($this->_message_template_group)) {
2627
+        if ( ! empty($this->_message_template_group)) {
2628 2628
             return;
2629 2629
         }
2630 2630
 
@@ -2670,8 +2670,8 @@  discard block
 block discarded – undo
2670 2670
                     <?php
2671 2671
                 }
2672 2672
                 // setup nonce_url
2673
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2673
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2674
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2675 2675
                 ?>
2676 2676
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2677 2677
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2684,7 +2684,7 @@  discard block
 block discarded – undo
2684 2684
                             $checked = ($context === $args['context']) ? 'selected' : '';
2685 2685
                             ?>
2686 2686
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2687
-                                <?php echo esc_html($context_details[ $context ]['label']); ?>
2687
+                                <?php echo esc_html($context_details[$context]['label']); ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690 2690
                     endif; ?>
@@ -3076,7 +3076,7 @@  discard block
 block discarded – undo
3076 3076
     {
3077 3077
         if (is_array($content)) {
3078 3078
             foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3079
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3080 3080
             }
3081 3081
             return $content;
3082 3082
         }
@@ -3114,7 +3114,7 @@  discard block
 block discarded – undo
3114 3114
 
3115 3115
         $context   = ucwords(str_replace('_', ' ', $context));
3116 3116
         $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3117
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3118 3118
             : '';
3119 3119
         $item_desc .= 'Message Template';
3120 3120
         return $item_desc;
@@ -3266,7 +3266,7 @@  discard block
 block discarded – undo
3266 3266
         if ($all) {
3267 3267
             // Checkboxes
3268 3268
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3269
+            if ( ! empty($checkboxes)) {
3270 3270
                 // if array has more than one element then success message should be plural.
3271 3271
                 // todo: what about nonce?
3272 3272
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3276,18 +3276,18 @@  discard block
 block discarded – undo
3276 3276
                     $trashed_or_restored = $trash
3277 3277
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278 3278
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3279
+                    if ( ! $trashed_or_restored) {
3280 3280
                         $success = 0;
3281 3281
                     }
3282 3282
                 }
3283 3283
             } else {
3284 3284
                 // grab single GRP_ID and handle
3285 3285
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3286
+                if ( ! empty($GRP_ID)) {
3287 3287
                     $trashed_or_restored = $trash
3288 3288
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289 3289
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3290
+                    if ( ! $trashed_or_restored) {
3291 3291
                         $success = 0;
3292 3292
                     }
3293 3293
                 } else {
@@ -3335,7 +3335,7 @@  discard block
 block discarded – undo
3335 3335
 
3336 3336
         // checkboxes
3337 3337
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3338
+        if ( ! empty($checkboxes)) {
3339 3339
             // if array has more than one element then success message should be plural
3340 3340
             $success = count($checkboxes) > 1 ? 2 : 1;
3341 3341
 
@@ -3439,7 +3439,7 @@  discard block
 block discarded – undo
3439 3439
     protected function _set_m_mt_settings()
3440 3440
     {
3441 3441
         // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3442
+        if ( ! empty($this->_m_mt_settings)) {
3443 3443
             return;
3444 3444
         }
3445 3445
 
@@ -3451,7 +3451,7 @@  discard block
 block discarded – undo
3451 3451
         // assemble the array for the _tab_text_links helper
3452 3452
 
3453 3453
         foreach ($messengers as $messenger) {
3454
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3454
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3455 3455
                 'label' => ucwords($messenger->label['singular']),
3456 3456
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457 3457
                     ? 'messenger-active'
@@ -3468,7 +3468,7 @@  discard block
 block discarded – undo
3468 3468
             foreach ($message_types as $message_type) {
3469 3469
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470 3470
                 // it shouldn't show in either the inactive OR active metabox.
3471
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3471
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3472 3472
                     continue;
3473 3473
                 }
3474 3474
 
@@ -3479,12 +3479,12 @@  discard block
 block discarded – undo
3479 3479
                     ? 'active'
3480 3480
                     : 'inactive';
3481 3481
 
3482
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3482
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3483 3483
                     'label'    => ucwords($message_type->label['singular']),
3484
-                    'class'    => 'message-type-' . $a_or_i,
3485
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3484
+                    'class'    => 'message-type-'.$a_or_i,
3485
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3486
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3487
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3488 3488
                     'title'    => $a_or_i === 'active'
3489 3489
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490 3490
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3515,25 +3515,25 @@  discard block
 block discarded – undo
3515 3515
         $fields                                         = $message_type->get_admin_settings_fields();
3516 3516
         $settings_template_args['template_form_fields'] = '';
3517 3517
 
3518
-        if (! empty($fields) && $active) {
3518
+        if ( ! empty($fields) && $active) {
3519 3519
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520 3520
             foreach ($fields as $fldname => $fldprops) {
3521
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
-                $template_form_field[ $field_id ] = [
3523
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3521
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3522
+                $template_form_field[$field_id] = [
3523
+                    'name'       => 'message_type_settings['.$fldname.']',
3524 3524
                     'label'      => $fldprops['label'],
3525 3525
                     'input'      => $fldprops['field_type'],
3526 3526
                     'type'       => $fldprops['value_type'],
3527 3527
                     'required'   => $fldprops['required'],
3528 3528
                     'validation' => $fldprops['validation'],
3529
-                    'value'      => isset($existing_settings[ $fldname ])
3530
-                        ? $existing_settings[ $fldname ]
3529
+                    'value'      => isset($existing_settings[$fldname])
3530
+                        ? $existing_settings[$fldname]
3531 3531
                         : $fldprops['default'],
3532 3532
                     'options'    => isset($fldprops['options'])
3533 3533
                         ? $fldprops['options']
3534 3534
                         : [],
3535
-                    'default'    => isset($existing_settings[ $fldname ])
3536
-                        ? $existing_settings[ $fldname ]
3535
+                    'default'    => isset($existing_settings[$fldname])
3536
+                        ? $existing_settings[$fldname]
3537 3537
                         : $fldprops['default'],
3538 3538
                     'css_class'  => 'no-drag',
3539 3539
                     'format'     => $fldprops['format'],
@@ -3553,15 +3553,15 @@  discard block
 block discarded – undo
3553 3553
         $settings_template_args['description'] = $message_type->description;
3554 3554
         // we also need some hidden fields
3555 3555
         $hidden_fields = [
3556
-            'message_type_settings[messenger]' . $message_type->name    => [
3556
+            'message_type_settings[messenger]'.$message_type->name    => [
3557 3557
                 'type'  => 'hidden',
3558 3558
                 'value' => $messenger->name,
3559 3559
             ],
3560
-            'message_type_settings[message_type]' . $message_type->name => [
3560
+            'message_type_settings[message_type]'.$message_type->name => [
3561 3561
                 'type'  => 'hidden',
3562 3562
                 'value' => $message_type->name,
3563 3563
             ],
3564
-            'type' . $message_type->name                                => [
3564
+            'type'.$message_type->name                                => [
3565 3565
                 'type'  => 'hidden',
3566 3566
                 'value' => 'message_type',
3567 3567
             ],
@@ -3571,12 +3571,12 @@  discard block
 block discarded – undo
3571 3571
             $hidden_fields,
3572 3572
             'array'
3573 3573
         );
3574
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3574
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3575 3575
             ? ' hidden'
3576 3576
             : '';
3577 3577
 
3578 3578
 
3579
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3579
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3580 3580
         return EEH_Template::display_template($template, $settings_template_args, true);
3581 3581
     }
3582 3582
 
@@ -3604,21 +3604,21 @@  discard block
 block discarded – undo
3604 3604
 
3605 3605
                 // messenger meta boxes
3606 3606
                 $active         = $selected_messenger === $messenger;
3607
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3607
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3608
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3609 3609
                     : '';
3610 3610
 
3611
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3611
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3612 3612
                     esc_html__('%s Settings', 'event_espresso'),
3613 3613
                     $tab_array['label']
3614 3614
                 );
3615 3615
 
3616
-                $m_template_args[ $messenger . '_a_box' ] = [
3616
+                $m_template_args[$messenger.'_a_box'] = [
3617 3617
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618 3618
                     'inactive_message_types' => isset(
3619
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3619
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3620 3620
                     )
3621
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3621
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3622 3622
                         : '',
3623 3623
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624 3624
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3630,13 +3630,13 @@  discard block
 block discarded – undo
3630 3630
                 // message type meta boxes
3631 3631
                 // (which is really just the inactive container for each messenger
3632 3632
                 // showing inactive message types for that messenger)
3633
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
-                $mt_template_args[ $messenger . '_i_box' ] = [
3633
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3634
+                $mt_template_args[$messenger.'_i_box'] = [
3635 3635
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636 3636
                     'inactive_message_types' => isset(
3637
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3637
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3638 3638
                     )
3639
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3639
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3640 3640
                         : '',
3641 3641
                     'hidden'                 => $active ? '' : ' hidden',
3642 3642
                     'hide_on_message'        => $hide_on_message,
@@ -3649,14 +3649,14 @@  discard block
 block discarded – undo
3649 3649
 
3650 3650
 
3651 3651
         // register messenger metaboxes
3652
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3652
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3653 3653
         foreach ($m_boxes as $box => $label) {
3654
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3654
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3655 3655
             $msgr          = str_replace('_a_box', '', $box);
3656 3656
             add_meta_box(
3657
-                'espresso_' . $msgr . '_settings',
3657
+                'espresso_'.$msgr.'_settings',
3658 3658
                 $label,
3659
-                function ($post, $metabox) {
3659
+                function($post, $metabox) {
3660 3660
                     EEH_Template::display_template(
3661 3661
                         $metabox['args']['template_path'],
3662 3662
                         $metabox['args']['template_args']
@@ -3670,17 +3670,17 @@  discard block
 block discarded – undo
3670 3670
         }
3671 3671
 
3672 3672
         // register message type metaboxes
3673
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3673
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3674 3674
         foreach ($mt_boxes as $box => $label) {
3675 3675
             $callback_args = [
3676 3676
                 'template_path' => $mt_template_path,
3677
-                'template_args' => $mt_template_args[ $box ],
3677
+                'template_args' => $mt_template_args[$box],
3678 3678
             ];
3679
-            $mt            = str_replace('_i_box', '', $box);
3679
+            $mt = str_replace('_i_box', '', $box);
3680 3680
             add_meta_box(
3681
-                'espresso_' . $mt . '_inactive_mts',
3681
+                'espresso_'.$mt.'_inactive_mts',
3682 3682
                 $label,
3683
-                function ($post, $metabox) {
3683
+                function($post, $metabox) {
3684 3684
                     EEH_Template::display_template(
3685 3685
                         $metabox['args']['template_path'],
3686 3686
                         $metabox['args']['template_args']
@@ -3824,7 +3824,7 @@  discard block
 block discarded – undo
3824 3824
             if ($form->is_valid()) {
3825 3825
                 $valid_data = $form->valid_data();
3826 3826
                 foreach ($valid_data as $property => $value) {
3827
-                    $setter = 'set_' . $property;
3827
+                    $setter = 'set_'.$property;
3828 3828
                     if (method_exists($network_config, $setter)) {
3829 3829
                         $network_config->{$setter}($value);
3830 3830
                     } elseif (
@@ -3860,7 +3860,7 @@  discard block
 block discarded – undo
3860 3860
     protected function _get_mt_tabs($tab_array)
3861 3861
     {
3862 3862
         $tab_array = (array) $tab_array;
3863
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3863
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3864 3864
         $tabs      = '';
3865 3865
 
3866 3866
         foreach ($tab_array as $tab) {
@@ -3888,20 +3888,20 @@  discard block
 block discarded – undo
3888 3888
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3889 3889
 
3890 3890
 
3891
-        if (! empty($fields)) {
3891
+        if ( ! empty($fields)) {
3892 3892
             $existing_settings = $messenger->get_existing_admin_settings();
3893 3893
 
3894 3894
             foreach ($fields as $fldname => $fldprops) {
3895
-                $field_id                         = $messenger->name . '-' . $fldname;
3896
-                $template_form_field[ $field_id ] = [
3897
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3895
+                $field_id                         = $messenger->name.'-'.$fldname;
3896
+                $template_form_field[$field_id] = [
3897
+                    'name'       => 'messenger_settings['.$field_id.']',
3898 3898
                     'label'      => $fldprops['label'],
3899 3899
                     'input'      => $fldprops['field_type'],
3900 3900
                     'type'       => $fldprops['value_type'],
3901 3901
                     'required'   => $fldprops['required'],
3902 3902
                     'validation' => $fldprops['validation'],
3903
-                    'value'      => isset($existing_settings[ $field_id ])
3904
-                        ? $existing_settings[ $field_id ]
3903
+                    'value'      => isset($existing_settings[$field_id])
3904
+                        ? $existing_settings[$field_id]
3905 3905
                         : $fldprops['default'],
3906 3906
                     'css_class'  => '',
3907 3907
                     'format'     => $fldprops['format'],
@@ -3916,20 +3916,20 @@  discard block
 block discarded – undo
3916 3916
 
3917 3917
         // we also need some hidden fields
3918 3918
         $settings_template_args['hidden_fields'] = [
3919
-            'messenger_settings[messenger]' . $messenger->name => [
3919
+            'messenger_settings[messenger]'.$messenger->name => [
3920 3920
                 'type'  => 'hidden',
3921 3921
                 'value' => $messenger->name,
3922 3922
             ],
3923
-            'type' . $messenger->name                          => [
3923
+            'type'.$messenger->name                          => [
3924 3924
                 'type'  => 'hidden',
3925 3925
                 'value' => 'messenger',
3926 3926
             ],
3927 3927
         ];
3928 3928
 
3929 3929
         // make sure any active message types that are existing are included in the hidden fields
3930
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3931
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3932
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3930
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3931
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3932
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3933 3933
                     'type'  => 'hidden',
3934 3934
                     'value' => $mt,
3935 3935
                 ];
@@ -3939,7 +3939,7 @@  discard block
 block discarded – undo
3939 3939
             $settings_template_args['hidden_fields'],
3940 3940
             'array'
3941 3941
         );
3942
-        $active                                  =
3942
+        $active =
3943 3943
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3944 3944
 
3945 3945
         $settings_template_args['messenger']           = $messenger->name;
@@ -3959,9 +3959,9 @@  discard block
 block discarded – undo
3959 3959
 
3960 3960
 
3961 3961
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3962
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3962
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3963 3963
         $settings_template_args['on_off_status'] = $active;
3964
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3964
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3965 3965
         return EEH_Template::display_template(
3966 3966
             $template,
3967 3967
             $settings_template_args,
@@ -3986,7 +3986,7 @@  discard block
 block discarded – undo
3986 3986
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3987 3987
         // let's check that we have required data
3988 3988
 
3989
-        if (! $this->_active_messenger_name) {
3989
+        if ( ! $this->_active_messenger_name) {
3990 3990
             EE_Error::add_error(
3991 3991
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3992 3992
                 __FILE__,
@@ -4004,7 +4004,7 @@  discard block
 block discarded – undo
4004 4004
 
4005 4005
 
4006 4006
         $status = $this->request->getRequestParam('status');
4007
-        if (! $status) {
4007
+        if ( ! $status) {
4008 4008
             EE_Error::add_error(
4009 4009
                 esc_html__(
4010 4010
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4061,7 +4061,7 @@  discard block
 block discarded – undo
4061 4061
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4062 4062
 
4063 4063
         // let's make sure we have the necessary data
4064
-        if (! $this->_active_message_type_name) {
4064
+        if ( ! $this->_active_message_type_name) {
4065 4065
             EE_Error::add_error(
4066 4066
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4067 4067
                 __FILE__,
@@ -4071,7 +4071,7 @@  discard block
 block discarded – undo
4071 4071
             $success = false;
4072 4072
         }
4073 4073
 
4074
-        if (! $this->_active_messenger_name) {
4074
+        if ( ! $this->_active_messenger_name) {
4075 4075
             EE_Error::add_error(
4076 4076
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4077 4077
                 __FILE__,
@@ -4082,7 +4082,7 @@  discard block
 block discarded – undo
4082 4082
         }
4083 4083
 
4084 4084
         $status = $this->request->getRequestParam('status');
4085
-        if (! $status) {
4085
+        if ( ! $status) {
4086 4086
             EE_Error::add_error(
4087 4087
                 esc_html__(
4088 4088
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4294,7 +4294,7 @@  discard block
 block discarded – undo
4294 4294
         EE_Message_Type $message_type = null
4295 4295
     ) {
4296 4296
         // if $messenger isn't a valid messenger object then get out.
4297
-        if (! $messenger instanceof EE_Messenger) {
4297
+        if ( ! $messenger instanceof EE_Messenger) {
4298 4298
             EE_Error::add_error(
4299 4299
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4300 4300
                 __FILE__,
@@ -4348,7 +4348,7 @@  discard block
 block discarded – undo
4348 4348
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4349 4349
             // in which case we just give a success message for the messenger being successfully activated.
4350 4350
         } else {
4351
-            if (! $messenger->get_default_message_types()) {
4351
+            if ( ! $messenger->get_default_message_types()) {
4352 4352
                 // messenger doesn't have any default message types so still a success.
4353 4353
                 EE_Error::add_success(
4354 4354
                     sprintf(
@@ -4404,7 +4404,7 @@  discard block
 block discarded – undo
4404 4404
         EE_Error::overwrite_success();
4405 4405
 
4406 4406
         // if $messenger isn't a valid messenger object then get out.
4407
-        if (! $messenger instanceof EE_Messenger) {
4407
+        if ( ! $messenger instanceof EE_Messenger) {
4408 4408
             EE_Error::add_error(
4409 4409
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4410 4410
                 __FILE__,
@@ -4474,7 +4474,7 @@  discard block
 block discarded – undo
4474 4474
      */
4475 4475
     public function update_mt_form()
4476 4476
     {
4477
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4477
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4478 4478
             EE_Error::add_error(
4479 4479
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4480 4480
                 __FILE__,
@@ -4485,7 +4485,7 @@  discard block
 block discarded – undo
4485 4485
         }
4486 4486
 
4487 4487
         $message_types = $this->get_installed_message_types();
4488
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4488
+        $message_type  = $message_types[$this->_active_message_type_name];
4489 4489
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4490 4490
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4491 4491
 
@@ -4504,7 +4504,7 @@  discard block
 block discarded – undo
4504 4504
     public function save_settings()
4505 4505
     {
4506 4506
         $type = $this->request->getRequestParam('type');
4507
-        if (! $type) {
4507
+        if ( ! $type) {
4508 4508
             EE_Error::add_error(
4509 4509
                 esc_html__(
4510 4510
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
Indentation   +4640 added lines, -4640 removed lines patch added patch discarded remove patch
@@ -17,2682 +17,2682 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Messages_Admin_Page extends EE_Admin_Page
19 19
 {
20
-    /**
21
-     * @var EEM_Message
22
-     */
23
-    private $MSG_MODEL;
24
-
25
-    /**
26
-     * @var EEM_Message_Template
27
-     */
28
-    private $MTP_MODEL;
29
-
30
-    /**
31
-     * @var EEM_Message_Template_Group
32
-     */
33
-    private $MTG_MODEL;
34
-
35
-    /**
36
-     * @var EE_Message_Resource_Manager $_message_resource_manager
37
-     */
38
-    protected $_message_resource_manager;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $_active_message_type_name = '';
44
-
45
-    /**
46
-     * @var string
47
-     */
48
-    protected $_active_messenger_name = '';
49
-
50
-    /**
51
-     * @var EE_messenger $_active_messenger
52
-     */
53
-    protected $_active_messenger;
54
-
55
-    protected $_activate_meta_box_type;
56
-
57
-    protected $_current_message_meta_box;
58
-
59
-    protected $_current_message_meta_box_object;
60
-
61
-    protected $_context_switcher;
62
-
63
-    protected $_shortcodes           = [];
64
-
65
-    protected $_active_messengers    = [];
66
-
67
-    protected $_active_message_types = [];
68
-
69
-    /**
70
-     * @var EE_Message_Template_Group $_message_template_group
71
-     */
72
-    protected $_message_template_group;
73
-
74
-    protected $_m_mt_settings = [];
75
-
76
-
77
-    /**
78
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
-     * IF there is no group then it gets automatically set to the Default template pack.
80
-     *
81
-     * @since 4.5.0
82
-     *
83
-     * @var EE_Messages_Template_Pack
84
-     */
85
-    protected $_template_pack;
86
-
87
-
88
-    /**
89
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
-     * group is.  If there is no group then it automatically gets set to default.
91
-     *
92
-     * @since 4.5.0
93
-     *
94
-     * @var string
95
-     */
96
-    protected $_variation;
97
-
98
-
99
-    /**
100
-     * @param bool $routing
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    public function __construct($routing = true)
105
-    {
106
-        // make sure messages autoloader is running
107
-        EED_Messages::set_autoloaders();
108
-        parent::__construct($routing);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Message
114
-     * @throws EE_Error
115
-     */
116
-    public function getMsgModel()
117
-    {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
119
-            $this->MSG_MODEL = EEM_Message::instance();
120
-        }
121
-        return $this->MSG_MODEL;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return EEM_Message_Template
127
-     * @throws EE_Error
128
-     */
129
-    public function getMtpModel()
130
-    {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
-            $this->MTP_MODEL = EEM_Message_Template::instance();
133
-        }
134
-        return $this->MTP_MODEL;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return EEM_Message_Template_Group
140
-     * @throws EE_Error
141
-     */
142
-    public function getMtgModel()
143
-    {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
-        }
147
-        return $this->MTG_MODEL;
148
-    }
149
-
150
-
151
-    /**
152
-     * @throws EE_Error
153
-     * @throws ReflectionException
154
-     */
155
-    protected function _init_page_props()
156
-    {
157
-        $this->page_slug        = EE_MSG_PG_SLUG;
158
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
-        $this->_admin_base_path = EE_MSG_ADMIN;
161
-
162
-        $messenger    = $this->request->getRequestParam('messenger', '');
163
-        $message_type = $this->request->getRequestParam('message_type', '');
164
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
-
167
-        $this->_load_message_resource_manager();
168
-    }
169
-
170
-
171
-    /**
172
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
-     *
174
-     * @throws EE_Error
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     * @throws InvalidArgumentException
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _load_message_resource_manager()
181
-    {
182
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
-    }
184
-
185
-
186
-    /**
187
-     * @return array
188
-     * @throws EE_Error
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     * @deprecated 4.9.9.rc.014
193
-     */
194
-    public function get_messengers_for_list_table()
195
-    {
196
-        EE_Error::doing_it_wrong(
197
-            __METHOD__,
198
-            sprintf(
199
-                esc_html__(
200
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
-                    'event_espresso'
202
-                ),
203
-                'Messages_Admin_Page::get_messengers_select_input()'
204
-            ),
205
-            '4.9.9.rc.014'
206
-        );
207
-
208
-        $m_values          = [];
209
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
-        // setup messengers for selects
211
-        $i = 1;
212
-        foreach ($active_messengers as $active_messenger) {
213
-            if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
-                $i++;
217
-            }
218
-        }
219
-
220
-        return $m_values;
221
-    }
222
-
223
-
224
-    /**
225
-     * @return array
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @deprecated 4.9.9.rc.014
231
-     */
232
-    public function get_message_types_for_list_table()
233
-    {
234
-        EE_Error::doing_it_wrong(
235
-            __METHOD__,
236
-            sprintf(
237
-                esc_html__(
238
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
-                    'event_espresso'
240
-                ),
241
-                'Messages_Admin_Page::get_message_types_select_input()'
242
-            ),
243
-            '4.9.9.rc.014'
244
-        );
245
-
246
-        $mt_values       = [];
247
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
-        $i               = 1;
249
-        foreach ($active_messages as $active_message) {
250
-            if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
-                $i++;
254
-            }
255
-        }
256
-
257
-        return $mt_values;
258
-    }
259
-
260
-
261
-    /**
262
-     * @return array
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @deprecated 4.9.9.rc.014
268
-     */
269
-    public function get_contexts_for_message_types_for_list_table()
270
-    {
271
-        EE_Error::doing_it_wrong(
272
-            __METHOD__,
273
-            sprintf(
274
-                esc_html__(
275
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
-                    'event_espresso'
277
-                ),
278
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
-            ),
280
-            '4.9.9.rc.014'
281
-        );
282
-
283
-        $contexts                = [];
284
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
-        foreach ($active_message_contexts as $active_message) {
286
-            if ($active_message instanceof EE_Message) {
287
-                $message_type = $active_message->message_type_object();
288
-                if ($message_type instanceof EE_message_type) {
289
-                    $message_type_contexts = $message_type->get_contexts();
290
-                    foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
292
-                    }
293
-                }
294
-            }
295
-        }
296
-
297
-        return $contexts;
298
-    }
299
-
300
-
301
-    /**
302
-     * Generate select input with provided messenger options array.
303
-     *
304
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
-     *                                 labels.
306
-     * @return string
307
-     * @throws EE_Error
308
-     */
309
-    public function get_messengers_select_input($messenger_options)
310
-    {
311
-        // if empty or just one value then just return an empty string
312
-        if (
313
-            empty($messenger_options)
314
-            || ! is_array($messenger_options)
315
-            || count($messenger_options) === 1
316
-        ) {
317
-            return '';
318
-        }
319
-        // merge in default
320
-        $messenger_options = array_merge(
321
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
-            $messenger_options
323
-        );
324
-        $input             = new EE_Select_Input(
325
-            $messenger_options,
326
-            [
327
-                'html_name'  => 'ee_messenger_filter_by',
328
-                'html_id'    => 'ee_messenger_filter_by',
329
-                'html_class' => 'wide',
330
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
-            ]
332
-        );
333
-
334
-        return $input->get_html_for_input();
335
-    }
336
-
337
-
338
-    /**
339
-     * Generate select input with provided message type options array.
340
-     *
341
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
-     *                                    message type labels
343
-     * @return string
344
-     * @throws EE_Error
345
-     */
346
-    public function get_message_types_select_input($message_type_options)
347
-    {
348
-        // if empty or count of options is 1 then just return an empty string
349
-        if (
350
-            empty($message_type_options)
351
-            || ! is_array($message_type_options)
352
-            || count($message_type_options) === 1
353
-        ) {
354
-            return '';
355
-        }
356
-        // merge in default
357
-        $message_type_options = array_merge(
358
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
-            $message_type_options
360
-        );
361
-        $input                = new EE_Select_Input(
362
-            $message_type_options,
363
-            [
364
-                'html_name'  => 'ee_message_type_filter_by',
365
-                'html_id'    => 'ee_message_type_filter_by',
366
-                'html_class' => 'wide',
367
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
-            ]
369
-        );
370
-
371
-        return $input->get_html_for_input();
372
-    }
373
-
374
-
375
-    /**
376
-     * Generate select input with provide message type contexts array.
377
-     *
378
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
-     *                               context label.
380
-     * @return string
381
-     * @throws EE_Error
382
-     */
383
-    public function get_contexts_for_message_types_select_input($context_options)
384
-    {
385
-        // if empty or count of options is one then just return empty string
386
-        if (
387
-            empty($context_options)
388
-            || ! is_array($context_options)
389
-            || count($context_options) === 1
390
-        ) {
391
-            return '';
392
-        }
393
-        // merge in default
394
-        $context_options = array_merge(
395
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
-            $context_options
397
-        );
398
-        $input           = new EE_Select_Input(
399
-            $context_options,
400
-            [
401
-                'html_name'  => 'ee_context_filter_by',
402
-                'html_id'    => 'ee_context_filter_by',
403
-                'html_class' => 'wide',
404
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
-            ]
406
-        );
407
-
408
-        return $input->get_html_for_input();
409
-    }
410
-
411
-
412
-    protected function _ajax_hooks()
413
-    {
414
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
-    }
421
-
422
-
423
-    protected function _define_page_props()
424
-    {
425
-        $this->_admin_page_title = $this->page_label;
426
-        $this->_labels           = [
427
-            'buttons'    => [
428
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
-            ],
432
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
-        ];
434
-    }
435
-
436
-
437
-    /**
438
-     *        an array for storing key => value pairs of request actions and their corresponding methods
439
-     *
440
-     * @access protected
441
-     * @return void
442
-     */
443
-    protected function _set_page_routes()
444
-    {
445
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
-
449
-        $this->_page_routes = [
450
-            'default'                          => [
451
-                'func'       => '_message_queue_list_table',
452
-                'capability' => 'ee_read_global_messages',
453
-            ],
454
-            'global_mtps'                      => [
455
-                'func'       => '_ee_default_messages_overview_list_table',
456
-                'capability' => 'ee_read_global_messages',
457
-            ],
458
-            'custom_mtps'                      => [
459
-                'func'       => '_custom_mtps_preview',
460
-                'capability' => 'ee_read_messages',
461
-            ],
462
-            'add_new_message_template'         => [
463
-                'func'       => 'add_message_template',
464
-                'capability' => 'ee_edit_messages',
465
-                'noheader'   => true,
466
-            ],
467
-            'edit_message_template'            => [
468
-                'func'       => '_edit_message_template',
469
-                'capability' => 'ee_edit_message',
470
-                'obj_id'     => $GRP_ID,
471
-            ],
472
-            'preview_message'                  => [
473
-                'func'               => '_preview_message',
474
-                'capability'         => 'ee_read_message',
475
-                'obj_id'             => $GRP_ID,
476
-                'noheader'           => true,
477
-                'headers_sent_route' => 'display_preview_message',
478
-            ],
479
-            'display_preview_message'          => [
480
-                'func'       => '_display_preview_message',
481
-                'capability' => 'ee_read_message',
482
-                'obj_id'     => $GRP_ID,
483
-            ],
484
-            'insert_message_template'          => [
485
-                'func'       => '_insert_or_update_message_template',
486
-                'capability' => 'ee_edit_messages',
487
-                'args'       => ['new' => true],
488
-                'noheader'   => true,
489
-            ],
490
-            'update_message_template'          => [
491
-                'func'       => '_insert_or_update_message_template',
492
-                'capability' => 'ee_edit_message',
493
-                'obj_id'     => $GRP_ID,
494
-                'args'       => ['new' => false],
495
-                'noheader'   => true,
496
-            ],
497
-            'trash_message_template'           => [
498
-                'func'       => '_trash_or_restore_message_template',
499
-                'capability' => 'ee_delete_message',
500
-                'obj_id'     => $GRP_ID,
501
-                'args'       => ['trash' => true, 'all' => true],
502
-                'noheader'   => true,
503
-            ],
504
-            'trash_message_template_context'   => [
505
-                'func'       => '_trash_or_restore_message_template',
506
-                'capability' => 'ee_delete_message',
507
-                'obj_id'     => $GRP_ID,
508
-                'args'       => ['trash' => true],
509
-                'noheader'   => true,
510
-            ],
511
-            'restore_message_template'         => [
512
-                'func'       => '_trash_or_restore_message_template',
513
-                'capability' => 'ee_delete_message',
514
-                'obj_id'     => $GRP_ID,
515
-                'args'       => ['trash' => false, 'all' => true],
516
-                'noheader'   => true,
517
-            ],
518
-            'restore_message_template_context' => [
519
-                'func'       => '_trash_or_restore_message_template',
520
-                'capability' => 'ee_delete_message',
521
-                'obj_id'     => $GRP_ID,
522
-                'args'       => ['trash' => false],
523
-                'noheader'   => true,
524
-            ],
525
-            'delete_message_template'          => [
526
-                'func'       => '_delete_message_template',
527
-                'capability' => 'ee_delete_message',
528
-                'obj_id'     => $GRP_ID,
529
-                'noheader'   => true,
530
-            ],
531
-            'reset_to_default'                 => [
532
-                'func'       => '_reset_to_default_template',
533
-                'capability' => 'ee_edit_message',
534
-                'obj_id'     => $GRP_ID,
535
-                'noheader'   => true,
536
-            ],
537
-            'settings'                         => [
538
-                'func'       => '_settings',
539
-                'capability' => 'manage_options',
540
-            ],
541
-            'update_global_settings'           => [
542
-                'func'       => '_update_global_settings',
543
-                'capability' => 'manage_options',
544
-                'noheader'   => true,
545
-            ],
546
-            'generate_now'                     => [
547
-                'func'       => '_generate_now',
548
-                'capability' => 'ee_send_message',
549
-                'noheader'   => true,
550
-            ],
551
-            'generate_and_send_now'            => [
552
-                'func'       => '_generate_and_send_now',
553
-                'capability' => 'ee_send_message',
554
-                'noheader'   => true,
555
-            ],
556
-            'queue_for_resending'              => [
557
-                'func'       => '_queue_for_resending',
558
-                'capability' => 'ee_send_message',
559
-                'noheader'   => true,
560
-            ],
561
-            'send_now'                         => [
562
-                'func'       => '_send_now',
563
-                'capability' => 'ee_send_message',
564
-                'noheader'   => true,
565
-            ],
566
-            'delete_ee_message'                => [
567
-                'func'       => '_delete_ee_messages',
568
-                'capability' => 'ee_delete_messages',
569
-                'noheader'   => true,
570
-            ],
571
-            'delete_ee_messages'               => [
572
-                'func'       => '_delete_ee_messages',
573
-                'capability' => 'ee_delete_messages',
574
-                'noheader'   => true,
575
-                'obj_id'     => $MSG_ID,
576
-            ],
577
-        ];
578
-    }
579
-
580
-
581
-    protected function _set_page_config()
582
-    {
583
-        $this->_page_config = [
584
-            'default'                  => [
585
-                'nav'           => [
586
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
587
-                    'order' => 10,
588
-                ],
589
-                'list_table'    => 'EE_Message_List_Table',
590
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
-                'require_nonce' => false,
592
-            ],
593
-            'global_mtps'              => [
594
-                'nav'           => [
595
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
-                    'order' => 20,
597
-                ],
598
-                'list_table'    => 'Messages_Template_List_Table',
599
-                'help_tabs'     => [
600
-                    'messages_overview_help_tab'                                => [
601
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
-                        'filename' => 'messages_overview',
603
-                    ],
604
-                    'messages_overview_messages_table_column_headings_help_tab' => [
605
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
-                        'filename' => 'messages_overview_table_column_headings',
607
-                    ],
608
-                    'messages_overview_messages_filters_help_tab'               => [
609
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
610
-                        'filename' => 'messages_overview_filters',
611
-                    ],
612
-                    'messages_overview_messages_views_help_tab'                 => [
613
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
614
-                        'filename' => 'messages_overview_views',
615
-                    ],
616
-                    'message_overview_message_types_help_tab'                   => [
617
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
618
-                        'filename' => 'messages_overview_types',
619
-                    ],
620
-                    'messages_overview_messengers_help_tab'                     => [
621
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
622
-                        'filename' => 'messages_overview_messengers',
623
-                    ],
624
-                ],
625
-                'require_nonce' => false,
626
-            ],
627
-            'custom_mtps'              => [
628
-                'nav'           => [
629
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
-                    'order' => 30,
631
-                ],
632
-                'help_tabs'     => [],
633
-                'require_nonce' => false,
634
-            ],
635
-            'add_new_message_template' => [
636
-                'nav'           => [
637
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
-                    'order'      => 5,
639
-                    'persistent' => false,
640
-                ],
641
-                'require_nonce' => false,
642
-            ],
643
-            'edit_message_template'    => [
644
-                'labels'        => [
645
-                    'buttons'    => [
646
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
-                    ],
648
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
-                ],
650
-                'nav'           => [
651
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
-                    'order'      => 5,
653
-                    'persistent' => false,
654
-                    'url'        => '',
655
-                ],
656
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
-                'has_metaboxes' => true,
658
-                'help_tabs'     => [
659
-                    'edit_message_template'            => [
660
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
-                        'callback' => 'edit_message_template_help_tab',
662
-                    ],
663
-                    'message_templates_help_tab'       => [
664
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
665
-                        'filename' => 'messages_templates',
666
-                    ],
667
-                    'message_template_shortcodes'      => [
668
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
-                        'callback' => 'message_template_shortcodes_help_tab',
670
-                    ],
671
-                    'message_preview_help_tab'         => [
672
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
673
-                        'filename' => 'messages_preview',
674
-                    ],
675
-                    'messages_overview_other_help_tab' => [
676
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
677
-                        'filename' => 'messages_overview_other',
678
-                    ],
679
-                ],
680
-                'require_nonce' => false,
681
-            ],
682
-            'display_preview_message'  => [
683
-                'nav'           => [
684
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
685
-                    'order'      => 5,
686
-                    'url'        => '',
687
-                    'persistent' => false,
688
-                ],
689
-                'help_tabs'     => [
690
-                    'preview_message' => [
691
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
692
-                        'callback' => 'preview_message_help_tab',
693
-                    ],
694
-                ],
695
-                'require_nonce' => false,
696
-            ],
697
-            'settings'                 => [
698
-                'nav'           => [
699
-                    'label' => esc_html__('Settings', 'event_espresso'),
700
-                    'order' => 40,
701
-                ],
702
-                'metaboxes'     => ['_messages_settings_metaboxes'],
703
-                'help_tabs'     => [
704
-                    'messages_settings_help_tab'               => [
705
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
-                        'filename' => 'messages_settings',
707
-                    ],
708
-                    'messages_settings_message_types_help_tab' => [
709
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
-                        'filename' => 'messages_settings_message_types',
711
-                    ],
712
-                    'messages_settings_messengers_help_tab'    => [
713
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
-                        'filename' => 'messages_settings_messengers',
715
-                    ],
716
-                ],
717
-                'require_nonce' => false,
718
-            ],
719
-        ];
720
-    }
721
-
722
-
723
-    protected function _add_screen_options()
724
-    {
725
-        // todo
726
-    }
727
-
728
-
729
-    protected function _add_screen_options_global_mtps()
730
-    {
731
-        /**
732
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
734
-         */
735
-        $page_title              = $this->_admin_page_title;
736
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
-        $this->_per_page_screen_option();
738
-        $this->_admin_page_title = $page_title;
739
-    }
740
-
741
-
742
-    protected function _add_screen_options_default()
743
-    {
744
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
-        $this->_per_page_screen_option();
746
-    }
747
-
748
-
749
-    // none of the below group are currently used for Messages
750
-    protected function _add_feature_pointers()
751
-    {
752
-    }
753
-
754
-
755
-    public function admin_init()
756
-    {
757
-    }
758
-
759
-
760
-    public function admin_notices()
761
-    {
762
-    }
763
-
764
-
765
-    public function admin_footer_scripts()
766
-    {
767
-    }
768
-
769
-
770
-    public function messages_help_tab()
771
-    {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
-    }
774
-
775
-
776
-    public function messengers_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
-    }
780
-
781
-
782
-    public function message_types_help_tab()
783
-    {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
-    }
786
-
787
-
788
-    public function messages_overview_help_tab()
789
-    {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
-    }
792
-
793
-
794
-    public function message_templates_help_tab()
795
-    {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
-    }
798
-
799
-
800
-    public function edit_message_template_help_tab()
801
-    {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
-                        . esc_attr__('Editor Title', 'event_espresso')
804
-                        . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
807
-                        . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
810
-                        . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
813
-                        . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
-                        . esc_attr__('Publish Metabox', 'event_espresso')
816
-                        . '" />';
817
-        EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
-            $args
820
-        );
821
-    }
822
-
823
-
824
-    /**
825
-     * @throws ReflectionException
826
-     * @throws EE_Error
827
-     */
828
-    public function message_template_shortcodes_help_tab()
829
-    {
830
-        $this->_set_shortcodes();
831
-        $args['shortcodes'] = $this->_shortcodes;
832
-        EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
-            $args
835
-        );
836
-    }
837
-
838
-
839
-    public function preview_message_help_tab()
840
-    {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
-    }
843
-
844
-
845
-    public function settings_help_tab()
846
-    {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
-        $args['img3'] = '<div class="switch">'
852
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
-                        . ' type="checkbox" checked="checked">'
854
-                        . '<label for="ee-on-off-toggle-on"></label>'
855
-                        . '</div>';
856
-        $args['img4'] = '<div class="switch">'
857
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
-                        . ' type="checkbox">'
859
-                        . '<label for="ee-on-off-toggle-on"></label>'
860
-                        . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
-    }
863
-
864
-
865
-    public function load_scripts_styles()
866
-    {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
-        wp_enqueue_style('espresso_ee_msg');
869
-
870
-        wp_register_script(
871
-            'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
874
-            EVENT_ESPRESSO_VERSION,
875
-            true
876
-        );
877
-        wp_register_script(
878
-            'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
-            ['ee-dialog'],
881
-            EVENT_ESPRESSO_VERSION
882
-        );
883
-    }
884
-
885
-
886
-    public function load_scripts_styles_default()
887
-    {
888
-        wp_enqueue_script('ee-msg-list-table-js');
889
-    }
890
-
891
-
892
-    public function wp_editor_css($mce_css)
893
-    {
894
-        // if we're on the edit_message_template route
895
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
-            $message_type_name = $this->_active_message_type_name;
897
-
898
-            // we're going to REPLACE the existing mce css
899
-            // we need to get the css file location from the active messenger
900
-            $mce_css = $this->_active_messenger->get_variation(
901
-                $this->_template_pack,
902
-                $message_type_name,
903
-                true,
904
-                'wpeditor',
905
-                $this->_variation
906
-            );
907
-        }
908
-
909
-        return $mce_css;
910
-    }
911
-
912
-
913
-    /**
914
-     * @throws EE_Error
915
-     * @throws ReflectionException
916
-     */
917
-    public function load_scripts_styles_edit_message_template()
918
-    {
919
-
920
-        $this->_set_shortcodes();
921
-
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
-            esc_html__(
924
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
-                'event_espresso'
926
-            ),
927
-            $this->_message_template_group->messenger_obj()->label['singular'],
928
-            $this->_message_template_group->message_type_obj()->label['singular']
929
-        );
930
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
-            'event_espresso'
933
-        );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
-            'event_espresso'
937
-        );
938
-
939
-        wp_register_script(
940
-            'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
-            ['jquery'],
943
-            EVENT_ESPRESSO_VERSION
944
-        );
945
-
946
-        wp_enqueue_script('ee_admin_js');
947
-        wp_enqueue_script('ee_msgs_edit_js');
948
-
949
-        // add in special css for tiny_mce
950
-        add_filter('mce_css', [$this, 'wp_editor_css']);
951
-    }
952
-
953
-
954
-    /**
955
-     * @throws EE_Error
956
-     * @throws ReflectionException
957
-     */
958
-    public function load_scripts_styles_display_preview_message()
959
-    {
960
-        $this->_set_message_template_group();
961
-        if ($this->_active_messenger_name) {
962
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
-                $this->_active_messenger_name
964
-            );
965
-        }
966
-
967
-        wp_enqueue_style(
968
-            'espresso_preview_css',
969
-            $this->_active_messenger->get_variation(
970
-                $this->_template_pack,
971
-                $this->_active_message_type_name,
972
-                true,
973
-                'preview',
974
-                $this->_variation
975
-            )
976
-        );
977
-    }
978
-
979
-
980
-    public function load_scripts_styles_settings()
981
-    {
982
-        wp_register_style(
983
-            'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
-            [],
986
-            EVENT_ESPRESSO_VERSION
987
-        );
988
-        wp_enqueue_style('ee-text-links');
989
-        wp_enqueue_style('ee-message-settings');
990
-        wp_enqueue_script('ee-messages-settings');
991
-    }
992
-
993
-
994
-    /**
995
-     * set views array for List Table
996
-     */
997
-    public function _set_list_table_views_global_mtps()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'  => 'in_use',
1002
-                'label' => esc_html__('In Use', 'event_espresso'),
1003
-                'count' => 0,
1004
-            ],
1005
-        ];
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Set views array for the Custom Template List Table
1011
-     */
1012
-    public function _set_list_table_views_custom_mtps()
1013
-    {
1014
-        $this->_set_list_table_views_global_mtps();
1015
-        $this->_views['in_use']['bulk_action'] = [
1016
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
-        ];
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * set views array for message queue list table
1023
-     *
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidInterfaceException
1026
-     * @throws InvalidArgumentException
1027
-     * @throws EE_Error
1028
-     * @throws ReflectionException
1029
-     */
1030
-    public function _set_list_table_views_default()
1031
-    {
1032
-        EE_Registry::instance()->load_helper('Template');
1033
-
1034
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
-            'ee_send_message',
1036
-            'message_list_table_bulk_actions'
1037
-        )
1038
-            ? [
1039
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
-            ]
1044
-            : [];
1045
-
1046
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_delete_messages',
1048
-            'message_list_table_bulk_actions'
1049
-        )
1050
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
-            : [];
1052
-
1053
-
1054
-        $this->_views = [
1055
-            'all' => [
1056
-                'slug'        => 'all',
1057
-                'label'       => esc_html__('All', 'event_espresso'),
1058
-                'count'       => 0,
1059
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
-            ],
1061
-        ];
1062
-
1063
-
1064
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
-                continue;
1067
-            }
1068
-            $status_bulk_actions = $common_bulk_actions;
1069
-            // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1071
-                switch ($status) {
1072
-                    case EEM_Message::status_idle:
1073
-                    case EEM_Message::status_resend:
1074
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
-                        break;
1076
-
1077
-                    case EEM_Message::status_failed:
1078
-                    case EEM_Message::status_debug_only:
1079
-                    case EEM_Message::status_messenger_executing:
1080
-                        $status_bulk_actions = [];
1081
-                        break;
1082
-
1083
-                    case EEM_Message::status_incomplete:
1084
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
-                        break;
1086
-
1087
-                    case EEM_Message::status_retry:
1088
-                    case EEM_Message::status_sent:
1089
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
-                        break;
1091
-                }
1092
-            }
1093
-
1094
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1095
-            if ($status === EEM_Message::status_messenger_executing) {
1096
-                continue;
1097
-            }
1098
-
1099
-            $this->_views[ strtolower($status) ] = [
1100
-                'slug'        => strtolower($status),
1101
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
-                'count'       => 0,
1103
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
-            ];
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * @throws EE_Error
1111
-     */
1112
-    protected function _ee_default_messages_overview_list_table()
1113
-    {
1114
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * @throws EE_Error
1121
-     * @throws ReflectionException
1122
-     */
1123
-    protected function _message_queue_list_table()
1124
-    {
1125
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
-        $this->_template_args['per_column']        = 6;
1127
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
-        $this->_template_args['before_list_table'] = '<h3>'
1129
-                                                     . $this->getMsgModel()->get_pretty_label_for_results()
1130
-                                                     . '</h3>';
1131
-        $this->display_admin_list_table_page_with_no_sidebar();
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * @throws EE_Error
1137
-     */
1138
-    protected function _message_legend_items()
1139
-    {
1140
-
1141
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
-        $action_items       = [];
1143
-
1144
-        foreach ($action_css_classes as $action_item => $action_details) {
1145
-            if ($action_item === 'see_notifications_for') {
1146
-                continue;
1147
-            }
1148
-            $action_items[ $action_item ] = [
1149
-                'class' => $action_details['css_class'],
1150
-                'desc'  => $action_details['label'],
1151
-            ];
1152
-        }
1153
-
1154
-        /** @var array $status_items status legend setup */
1155
-        $status_items = [
1156
-            'sent_status'                => [
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
-            ],
1160
-            'idle_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
-            ],
1164
-            'failed_status'              => [
1165
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
-            ],
1168
-            'messenger_executing_status' => [
1169
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
-            ],
1172
-            'resend_status'              => [
1173
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
-            ],
1176
-            'incomplete_status'          => [
1177
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
-            ],
1180
-            'retry_status'               => [
1181
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
-            ],
1184
-        ];
1185
-        if (EEM_Message::debug()) {
1186
-            $status_items['debug_only_status'] = [
1187
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
-            ];
1190
-        }
1191
-
1192
-        return array_merge($action_items, $status_items);
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * @throws EE_Error
1198
-     */
1199
-    protected function _custom_mtps_preview()
1200
-    {
1201
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
-                                                . ' alt="' . esc_attr__(
1204
-                                                    'Preview Custom Message Templates screenshot',
1205
-                                                    'event_espresso'
1206
-                                                ) . '" />';
1207
-        $this->_template_args['preview_text'] = '<strong>'
1208
-                                                . esc_html__(
1209
-                                                    'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1210
-                                                    'event_espresso'
1211
-                                                )
1212
-                                                . '</strong>';
1213
-
1214
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * get_message_templates
1220
-     * This gets all the message templates for listing on the overview list.
1221
-     *
1222
-     * @access public
1223
-     * @param int    $per_page the amount of templates groups to show per page
1224
-     * @param string $type     the current _view we're getting templates for
1225
-     * @param bool   $count    return count?
1226
-     * @param bool   $all      disregard any paging info (get all data);
1227
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     * @throws InvalidArgumentException
1231
-     * @throws InvalidDataTypeException
1232
-     * @throws InvalidInterfaceException
1233
-     */
1234
-    public function get_message_templates(
1235
-        $per_page = 10,
1236
-        $type = 'in_use',
1237
-        $count = false,
1238
-        $all = false,
1239
-        $global = true
1240
-    ) {
1241
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
-        $this->request->setRequestParam('orderby', $orderby);
1243
-
1244
-        $order        = $this->request->getRequestParam('order', 'ASC');
1245
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
-
1248
-        $offset = ($current_page - 1) * $per_page;
1249
-        $limit  = $all ? null : [$offset, $per_page];
1250
-
1251
-        // options will match what is in the _views array property
1252
-        return $type === 'in_use'
1253
-            ? $this->getMtgModel()->get_all_active_message_templates(
1254
-                $orderby,
1255
-                $order,
1256
-                $limit,
1257
-                $count,
1258
-                $global,
1259
-                true
1260
-            )
1261
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
-                $orderby,
1263
-                $order,
1264
-                $limit,
1265
-                $count,
1266
-                $global
1267
-            );
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     * filters etc might need a list of installed message_types
1273
-     *
1274
-     * @return array an array of message type objects
1275
-     */
1276
-    public function get_installed_message_types()
1277
-    {
1278
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
-        $installed               = [];
1280
-
1281
-        foreach ($installed_message_types as $message_type) {
1282
-            $installed[ $message_type->name ] = $message_type;
1283
-        }
1284
-
1285
-        return $installed;
1286
-    }
1287
-
1288
-
1289
-    /**
1290
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1291
-     *
1292
-     * @param string $message_type
1293
-     * @param string $messenger
1294
-     * @param string $GRP_ID
1295
-     *
1296
-     * @throws EE_error
1297
-     * @throws ReflectionException
1298
-     */
1299
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
-    {
1301
-        // set values override any request data
1302
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
-
1306
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
-        if (empty($message_type) || empty($messenger)) {
1308
-            throw new EE_Error(
1309
-                esc_html__(
1310
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
-                    'event_espresso'
1312
-                )
1313
-            );
1314
-        }
1315
-
1316
-        // we need the GRP_ID for the template being used as the base for the new template
1317
-        if (empty($GRP_ID)) {
1318
-            throw new EE_Error(
1319
-                esc_html__(
1320
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
-                    'event_espresso'
1322
-                )
1323
-            );
1324
-        }
1325
-
1326
-        // let's just make sure the template gets generated!
1327
-
1328
-        // we need to reassign some variables for what the insert is expecting
1329
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1330
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1331
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
-
1333
-        $this->_insert_or_update_message_template(true);
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * @param string $message_type     message type slug
1339
-     * @param string $messenger        messenger slug
1340
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
-     *                                 off of.
1342
-     * @throws EE_error
1343
-     * @throws ReflectionException
1344
-     * @deprecated 4.10.29.p
1345
-     */
1346
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
-    {
1348
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1349
-    }
1350
-
1351
-
1352
-    /**
1353
-     * _edit_message_template
1354
-     *
1355
-     * @access protected
1356
-     * @return void
1357
-     * @throws InvalidIdentifierException
1358
-     * @throws DomainException
1359
-     * @throws EE_Error
1360
-     * @throws InvalidArgumentException
1361
-     * @throws ReflectionException
1362
-     * @throws InvalidDataTypeException
1363
-     * @throws InvalidInterfaceException
1364
-     */
1365
-    protected function _edit_message_template()
1366
-    {
1367
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
-        $template_fields = '';
1369
-        $sidebar_fields  = '';
1370
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
-        // valid html in the templates.
1372
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
-
1374
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
-
1377
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1378
-        $message_template_group = $this->_message_template_group;
1379
-        $c_label                = $message_template_group->context_label();
1380
-        $c_config               = $message_template_group->contexts_config();
1381
-
1382
-        reset($c_config);
1383
-        $context = $this->request->getRequestParam('context', key($c_config));
1384
-        $context = strtolower($context);
1385
-
1386
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
-
1388
-        $edit_message_template_form_url = add_query_arg(
1389
-            ['action' => $action, 'noheader' => true],
1390
-            EE_MSG_ADMIN_URL
1391
-        );
1392
-
1393
-        // set active messenger for this view
1394
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
-            $message_template_group->messenger()
1396
-        );
1397
-        $this->_active_message_type_name = $message_template_group->message_type();
1398
-
1399
-
1400
-        // Do we have any validation errors?
1401
-        $validators = $this->_get_transient();
1402
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
-
1404
-
1405
-        // we need to assemble the title from Various details
1406
-        $context_label = sprintf(
1407
-            esc_html__('(%s %s)', 'event_espresso'),
1408
-            $c_config[ $context ]['label'],
1409
-            ucwords($c_label['label'])
1410
-        );
1411
-
1412
-        $title = sprintf(
1413
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1414
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1415
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1416
-            $context_label
1417
-        );
1418
-
1419
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1420
-        $this->_template_args['message_template'] = $message_template_group;
1421
-        $this->_template_args['is_extra_fields']  = false;
1422
-
1423
-
1424
-        // let's get EEH_MSG_Template so we can get template form fields
1425
-        $template_field_structure = EEH_MSG_Template::get_fields(
1426
-            $message_template_group->messenger(),
1427
-            $message_template_group->message_type()
1428
-        );
1429
-
1430
-        if (! $template_field_structure) {
1431
-            $template_field_structure = false;
1432
-            $template_fields          = esc_html__(
1433
-                'There was an error in assembling the fields for this display (you should see an error message)',
1434
-                'event_espresso'
1435
-            );
1436
-        }
1437
-
1438
-
1439
-        $message_templates = $message_template_group->context_templates();
1440
-
1441
-
1442
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
-        // will get handled in the "extra" array.
1444
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
-                unset($template_field_structure[ $context ][ $reference_field ]);
1447
-            }
1448
-        }
1449
-
1450
-        // let's loop through the template_field_structure and actually assemble the input fields!
1451
-        if (! empty($template_field_structure)) {
1452
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
-                // the extra array and reset them.
1455
-                if ($template_field === 'extra') {
1456
-                    $this->_template_args['is_extra_fields'] = true;
1457
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1459
-                        $content          = $message_template instanceof EE_Message_Template
1460
-                            ? $message_template->get('MTP_content')
1461
-                            : '';
1462
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1463
-                            // let's verify if we need this extra field via the shortcodes parameter.
1464
-                            $continue = false;
1465
-                            if (isset($extra_array['shortcodes_required'])) {
1466
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
-                                        $continue = true;
1469
-                                    }
1470
-                                }
1471
-                                if ($continue) {
1472
-                                    continue;
1473
-                                }
1474
-                            }
1475
-
1476
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1477
-
1478
-                            $template_form_fields[ $field_id ]         = $extra_array;
1479
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
-                                                                         . $reference_field
1481
-                                                                         . '][content]['
1482
-                                                                         . $extra_field . ']';
1483
-                            $css_class                                 = isset($extra_array['css_class'])
1484
-                                ? $extra_array['css_class']
1485
-                                : '';
1486
-
1487
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
-                                                                              && in_array($extra_field, $v_fields, true)
1489
-                                                                              && (
1490
-                                                                                  is_array($validators[ $extra_field ])
1491
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1492
-                                                                              )
1493
-                                ? 'validate-error ' . $css_class
1494
-                                : $css_class;
1495
-
1496
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
-                                                                          && isset($content[ $extra_field ])
1498
-                                ? $content[ $extra_field ]
1499
-                                : '';
1500
-
1501
-                            // do we have a validation error?  if we do then let's use that value instead
1502
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
-                                ? $validators[ $extra_field ]['value']
1504
-                                : $template_form_fields[ $field_id ]['value'];
1505
-
1506
-
1507
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
-
1509
-                            // shortcode selector
1510
-                            $field_name_to_use                                   = $extra_field === 'main'
1511
-                                ? 'content'
1512
-                                : $extra_field;
1513
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
-                                $field_name_to_use,
1515
-                                $field_id
1516
-                            );
1517
-                        }
1518
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
-                        $template_field_template_name_id = $reference_field . '-name';
1520
-
1521
-                        $template_form_fields[ $template_field_MTP_id ] = [
1522
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
-                            'label'      => null,
1524
-                            'input'      => 'hidden',
1525
-                            'type'       => 'int',
1526
-                            'required'   => false,
1527
-                            'validation' => false,
1528
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
-                            'css_class'  => '',
1530
-                            'format'     => '%d',
1531
-                            'db-col'     => 'MTP_ID',
1532
-                        ];
1533
-
1534
-                        $template_form_fields[ $template_field_template_name_id ] = [
1535
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
-                            'label'      => null,
1537
-                            'input'      => 'hidden',
1538
-                            'type'       => 'string',
1539
-                            'required'   => false,
1540
-                            'validation' => true,
1541
-                            'value'      => $reference_field,
1542
-                            'css_class'  => '',
1543
-                            'format'     => '%s',
1544
-                            'db-col'     => 'MTP_template_field',
1545
-                        ];
1546
-                    }
1547
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
-                } else {
1549
-                    $field_id                                   = $template_field . '-content';
1550
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1551
-                    $template_form_fields[ $field_id ]['name']  =
1552
-                        'MTP_template_fields[' . $template_field . '][content]';
1553
-                    $message_template                           =
1554
-                        isset($message_templates[ $context ][ $template_field ])
1555
-                            ? $message_templates[ $context ][ $template_field ]
1556
-                            : null;
1557
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
-                                                                  && is_array($message_templates[ $context ])
1559
-                                                                  && $message_template instanceof EE_Message_Template
1560
-                        ? $message_template->get('MTP_content')
1561
-                        : '';
1562
-
1563
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1564
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
-                        ? $validators[ $template_field ]['value']
1566
-                        : $template_form_fields[ $field_id ]['value'];
1567
-
1568
-
1569
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
-                    $css_class                                      = isset($field_setup_array['css_class'])
1571
-                        ? $field_setup_array['css_class']
1572
-                        : '';
1573
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
-                                                                      && in_array($template_field, $v_fields, true)
1575
-                                                                      && isset($validators[ $template_field ]['msg'])
1576
-                        ? 'validate-error ' . $css_class
1577
-                        : $css_class;
1578
-
1579
-                    // shortcode selector
1580
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
-                        $template_field,
1582
-                        $field_id
1583
-                    );
1584
-                }
1585
-
1586
-                // k took care of content field(s) now let's take care of others.
1587
-
1588
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
-                $template_field_field_template_name_id = $template_field . '-name';
1590
-
1591
-                // foreach template field there are actually two form fields created
1592
-                $template_form_fields[ $template_field_MTP_id ] = [
1593
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
-                    'label'      => null,
1595
-                    'input'      => 'hidden',
1596
-                    'type'       => 'int',
1597
-                    'required'   => false,
1598
-                    'validation' => true,
1599
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
-                    'css_class'  => '',
1601
-                    'format'     => '%d',
1602
-                    'db-col'     => 'MTP_ID',
1603
-                ];
1604
-
1605
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1606
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
-                    'label'      => null,
1608
-                    'input'      => 'hidden',
1609
-                    'type'       => 'string',
1610
-                    'required'   => false,
1611
-                    'validation' => true,
1612
-                    'value'      => $template_field,
1613
-                    'css_class'  => '',
1614
-                    'format'     => '%s',
1615
-                    'db-col'     => 'MTP_template_field',
1616
-                ];
1617
-            }
1618
-
1619
-            // add other fields
1620
-            $template_form_fields['ee-msg-current-context'] = [
1621
-                'name'       => 'MTP_context',
1622
-                'label'      => null,
1623
-                'input'      => 'hidden',
1624
-                'type'       => 'string',
1625
-                'required'   => false,
1626
-                'validation' => true,
1627
-                'value'      => $context,
1628
-                'css_class'  => '',
1629
-                'format'     => '%s',
1630
-                'db-col'     => 'MTP_context',
1631
-            ];
1632
-
1633
-            $template_form_fields['ee-msg-grp-id'] = [
1634
-                'name'       => 'GRP_ID',
1635
-                'label'      => null,
1636
-                'input'      => 'hidden',
1637
-                'type'       => 'int',
1638
-                'required'   => false,
1639
-                'validation' => true,
1640
-                'value'      => $GRP_ID,
1641
-                'css_class'  => '',
1642
-                'format'     => '%d',
1643
-                'db-col'     => 'GRP_ID',
1644
-            ];
1645
-
1646
-            $template_form_fields['ee-msg-messenger'] = [
1647
-                'name'       => 'MTP_messenger',
1648
-                'label'      => null,
1649
-                'input'      => 'hidden',
1650
-                'type'       => 'string',
1651
-                'required'   => false,
1652
-                'validation' => true,
1653
-                'value'      => $message_template_group->messenger(),
1654
-                'css_class'  => '',
1655
-                'format'     => '%s',
1656
-                'db-col'     => 'MTP_messenger',
1657
-            ];
1658
-
1659
-            $template_form_fields['ee-msg-message-type'] = [
1660
-                'name'       => 'MTP_message_type',
1661
-                'label'      => null,
1662
-                'input'      => 'hidden',
1663
-                'type'       => 'string',
1664
-                'required'   => false,
1665
-                'validation' => true,
1666
-                'value'      => $message_template_group->message_type(),
1667
-                'css_class'  => '',
1668
-                'format'     => '%s',
1669
-                'db-col'     => 'MTP_message_type',
1670
-            ];
1671
-
1672
-            $sidebar_form_fields['ee-msg-is-global'] = [
1673
-                'name'       => 'MTP_is_global',
1674
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1675
-                'input'      => 'hidden',
1676
-                'type'       => 'int',
1677
-                'required'   => false,
1678
-                'validation' => true,
1679
-                'value'      => $message_template_group->get('MTP_is_global'),
1680
-                'css_class'  => '',
1681
-                'format'     => '%d',
1682
-                'db-col'     => 'MTP_is_global',
1683
-            ];
1684
-
1685
-            $sidebar_form_fields['ee-msg-is-override'] = [
1686
-                'name'       => 'MTP_is_override',
1687
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
-                'type'       => 'int',
1690
-                'required'   => false,
1691
-                'validation' => true,
1692
-                'value'      => $message_template_group->get('MTP_is_override'),
1693
-                'css_class'  => '',
1694
-                'format'     => '%d',
1695
-                'db-col'     => 'MTP_is_override',
1696
-            ];
1697
-
1698
-            $sidebar_form_fields['ee-msg-is-active'] = [
1699
-                'name'       => 'MTP_is_active',
1700
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1701
-                'input'      => 'hidden',
1702
-                'type'       => 'int',
1703
-                'required'   => false,
1704
-                'validation' => true,
1705
-                'value'      => $message_template_group->is_active(),
1706
-                'css_class'  => '',
1707
-                'format'     => '%d',
1708
-                'db-col'     => 'MTP_is_active',
1709
-            ];
1710
-
1711
-            $sidebar_form_fields['ee-msg-deleted'] = [
1712
-                'name'       => 'MTP_deleted',
1713
-                'label'      => null,
1714
-                'input'      => 'hidden',
1715
-                'type'       => 'int',
1716
-                'required'   => false,
1717
-                'validation' => true,
1718
-                'value'      => $message_template_group->get('MTP_deleted'),
1719
-                'css_class'  => '',
1720
-                'format'     => '%d',
1721
-                'db-col'     => 'MTP_deleted',
1722
-            ];
1723
-            $sidebar_form_fields['ee-msg-author']  = [
1724
-                'name'       => 'MTP_user_id',
1725
-                'label'      => esc_html__('Author', 'event_espresso'),
1726
-                'input'      => 'hidden',
1727
-                'type'       => 'int',
1728
-                'required'   => false,
1729
-                'validation' => false,
1730
-                'value'      => $message_template_group->user(),
1731
-                'format'     => '%d',
1732
-                'db-col'     => 'MTP_user_id',
1733
-            ];
1734
-
1735
-            $sidebar_form_fields['ee-msg-route'] = [
1736
-                'name'  => 'action',
1737
-                'input' => 'hidden',
1738
-                'type'  => 'string',
1739
-                'value' => $action,
1740
-            ];
1741
-
1742
-            $sidebar_form_fields['ee-msg-id']        = [
1743
-                'name'  => 'id',
1744
-                'input' => 'hidden',
1745
-                'type'  => 'int',
1746
-                'value' => $GRP_ID,
1747
-            ];
1748
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
-                'name'  => $action . '_nonce',
1750
-                'input' => 'hidden',
1751
-                'type'  => 'string',
1752
-                'value' => wp_create_nonce($action . '_nonce'),
1753
-            ];
1754
-
1755
-            $template_switch = $this->request->getRequestParam('template_switch');
1756
-            if ($template_switch) {
1757
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1758
-                    'name'  => 'template_switch',
1759
-                    'input' => 'hidden',
1760
-                    'type'  => 'int',
1761
-                    'value' => 1,
1762
-                ];
1763
-            }
1764
-
1765
-
1766
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
-        } //end if ( !empty($template_field_structure) )
1769
-
1770
-        // set extra content for publish box
1771
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
-        $this->_set_publish_post_box_vars(
1773
-            'id',
1774
-            $GRP_ID,
1775
-            false,
1776
-            add_query_arg(
1777
-                ['action' => 'global_mtps'],
1778
-                $this->_admin_base_url
1779
-            )
1780
-        );
1781
-
1782
-        // add preview button
1783
-        $preview_url    = parent::add_query_args_and_nonce(
1784
-            [
1785
-                'message_type' => $message_template_group->message_type(),
1786
-                'messenger'    => $message_template_group->messenger(),
1787
-                'context'      => $context,
1788
-                'GRP_ID'       => $GRP_ID,
1789
-                'evt_id'       => $EVT_ID ?: false,
1790
-                'action'       => 'preview_message',
1791
-            ],
1792
-            $this->_admin_base_url
1793
-        );
1794
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
-                          . esc_html__('Preview', 'event_espresso')
1796
-                          . '</a>';
1797
-
1798
-
1799
-        // setup context switcher
1800
-        $this->_set_context_switcher(
1801
-            $message_template_group,
1802
-            [
1803
-                'page'    => 'espresso_messages',
1804
-                'action'  => 'edit_message_template',
1805
-                'id'      => $GRP_ID,
1806
-                'evt_id'  => $EVT_ID,
1807
-                'context' => $context,
1808
-                'extra'   => $preview_button,
1809
-            ]
1810
-        );
1811
-
1812
-
1813
-        // main box
1814
-        $this->_template_args['template_fields']                         = $template_fields;
1815
-        $this->_template_args['sidebar_box_id']                          = 'details';
1816
-        $this->_template_args['action']                                  = $action;
1817
-        $this->_template_args['context']                                 = $context;
1818
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
-        $this->_template_args['learn_more_about_message_templates_link'] =
1820
-            $this->_learn_more_about_message_templates_link();
1821
-
1822
-
1823
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
-            $message_template_group,
1826
-            $context,
1827
-            $context_label
1828
-        );
1829
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
-
1832
-        $this->_template_path = $this->_template_args['GRP_ID']
1833
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
-
1836
-        // send along EE_Message_Template_Group object for further template use.
1837
-        $this->_template_args['MTP'] = $message_template_group;
1838
-
1839
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
-            $this->_template_path,
1841
-            $this->_template_args,
1842
-            true
1843
-        );
1844
-
1845
-
1846
-        // finally, let's set the admin_page title
1847
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
-
1849
-
1850
-        // we need to take care of setting the shortcodes property for use elsewhere.
1851
-        $this->_set_shortcodes();
1852
-
1853
-
1854
-        // final template wrapper
1855
-        $this->display_admin_page_with_sidebar();
1856
-    }
1857
-
1858
-
1859
-    public function filter_tinymce_init($mceInit, $editor_id)
1860
-    {
1861
-        return $mceInit;
1862
-    }
1863
-
1864
-
1865
-    public function add_context_switcher()
1866
-    {
1867
-        return $this->_context_switcher;
1868
-    }
1869
-
1870
-
1871
-    /**
1872
-     * Adds the activation/deactivation toggle for the message template context.
1873
-     *
1874
-     * @param EE_Message_Template_Group $message_template_group
1875
-     * @param string                    $context
1876
-     * @param string                    $context_label
1877
-     * @return string
1878
-     * @throws DomainException
1879
-     * @throws EE_Error
1880
-     * @throws InvalidIdentifierException
1881
-     * @throws ReflectionException
1882
-     */
1883
-    protected function add_active_context_element(
1884
-        EE_Message_Template_Group $message_template_group,
1885
-        $context,
1886
-        $context_label
1887
-    ) {
1888
-        $template_args = [
1889
-            'context'                   => $context,
1890
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
-            'is_active'                 => $message_template_group->is_context_active($context),
1892
-            'on_off_action'             => $message_template_group->is_context_active($context)
1893
-                ? 'context-off'
1894
-                : 'context-on',
1895
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
-            'message_template_group_id' => $message_template_group->ID(),
1897
-        ];
1898
-        return EEH_Template::display_template(
1899
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
-            $template_args,
1901
-            true
1902
-        );
1903
-    }
1904
-
1905
-
1906
-    /**
1907
-     * Ajax callback for `toggle_context_template` ajax action.
1908
-     * Handles toggling the message context on or off.
1909
-     *
1910
-     * @throws EE_Error
1911
-     * @throws InvalidArgumentException
1912
-     * @throws InvalidDataTypeException
1913
-     * @throws InvalidIdentifierException
1914
-     * @throws InvalidInterfaceException
1915
-     */
1916
-    public function toggle_context_template()
1917
-    {
1918
-        $success = true;
1919
-        // check for required data
1920
-        if (
1921
-            ! (
1922
-                $this->request->requestParamIsSet('message_template_group_id')
1923
-                && $this->request->requestParamIsSet('context')
1924
-                && $this->request->requestParamIsSet('status')
1925
-            )
1926
-        ) {
1927
-            EE_Error::add_error(
1928
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
-                __FILE__,
1930
-                __FUNCTION__,
1931
-                __LINE__
1932
-            );
1933
-            $success = false;
1934
-        }
1935
-
1936
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
-        $context = $this->request->getRequestParam('context', '');
1938
-        $status  = $this->request->getRequestParam('status', '');
1939
-
1940
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
-
1942
-        if ($status !== 'off' && $status !== 'on') {
1943
-            EE_Error::add_error(
1944
-                sprintf(
1945
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
-                    $status
1947
-                ),
1948
-                __FILE__,
1949
-                __FUNCTION__,
1950
-                __LINE__
1951
-            );
1952
-            $success = false;
1953
-        }
1954
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
-            EE_Error::add_error(
1958
-                sprintf(
1959
-                    esc_html__(
1960
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
-                        'event_espresso'
1962
-                    ),
1963
-                    $message_template_group_id,
1964
-                    'EE_Message_Template_Group'
1965
-                ),
1966
-                __FILE__,
1967
-                __FUNCTION__,
1968
-                __LINE__
1969
-            );
1970
-            $success = false;
1971
-        }
1972
-        if ($success) {
1973
-            $success = $status === 'off'
1974
-                ? $message_template_group->deactivate_context($context)
1975
-                : $message_template_group->activate_context($context);
1976
-        }
1977
-        $this->_template_args['success'] = $success;
1978
-        $this->_return_json();
1979
-    }
1980
-
1981
-
1982
-    public function _add_form_element_before()
1983
-    {
1984
-        return '<form method="post" action="'
1985
-               . $this->_template_args['edit_message_template_form_url']
1986
-               . '" id="ee-msg-edit-frm">';
1987
-    }
1988
-
1989
-
1990
-    public function _add_form_element_after()
1991
-    {
1992
-        return '</form>';
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * This executes switching the template pack for a message template.
1998
-     *
1999
-     * @throws EE_Error
2000
-     * @throws InvalidDataTypeException
2001
-     * @throws InvalidInterfaceException
2002
-     * @throws InvalidArgumentException
2003
-     * @throws ReflectionException
2004
-     * @since 4.5.0
2005
-     */
2006
-    public function switch_template_pack()
2007
-    {
2008
-
2009
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2011
-
2012
-        // verify we have needed values.
2013
-        if (empty($GRP_ID) || empty($template_pack)) {
2014
-            $this->_template_args['error'] = true;
2015
-            EE_Error::add_error(
2016
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
-                __FILE__,
2018
-                __FUNCTION__,
2019
-                __LINE__
2020
-            );
2021
-        } else {
2022
-            // get template, set the new template_pack and then reset to default
2023
-            /** @var EE_Message_Template_Group $message_template_group */
2024
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
-
2026
-            $message_template_group->set_template_pack_name($template_pack);
2027
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2029
-
2030
-            $query_args = $this->_reset_to_default_template();
2031
-
2032
-            if (empty($query_args['id'])) {
2033
-                EE_Error::add_error(
2034
-                    esc_html__(
2035
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
-                        'event_espresso'
2037
-                    ),
2038
-                    __FILE__,
2039
-                    __FUNCTION__,
2040
-                    __LINE__
2041
-                );
2042
-                $this->_template_args['error'] = true;
2043
-            } else {
2044
-                $template_label       = $message_template_group->get_template_pack()->label;
2045
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
-                EE_Error::add_success(
2047
-                    sprintf(
2048
-                        esc_html__(
2049
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
-                            'event_espresso'
2051
-                        ),
2052
-                        $template_label,
2053
-                        $template_pack_labels->template_pack
2054
-                    )
2055
-                );
2056
-                // generate the redirect url for js.
2057
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
-
2059
-                $this->_template_args['data']['redirect_url'] = $url;
2060
-                $this->_template_args['success']              = true;
2061
-            }
2062
-
2063
-            $this->_return_json();
2064
-        }
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
-     * they want.
2071
-     *
2072
-     * @access protected
2073
-     * @return array|void
2074
-     * @throws EE_Error
2075
-     * @throws InvalidArgumentException
2076
-     * @throws InvalidDataTypeException
2077
-     * @throws InvalidInterfaceException
2078
-     * @throws ReflectionException
2079
-     */
2080
-    protected function _reset_to_default_template()
2081
-    {
2082
-        $templates    = [];
2083
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
-        $messenger    = $this->request->getRequestParam('msgr');
2085
-        $message_type = $this->request->getRequestParam('mt');
2086
-        // we need to make sure we've got the info we need.
2087
-        if (! ($GRP_ID && $messenger && $message_type)) {
2088
-            EE_Error::add_error(
2089
-                esc_html__(
2090
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2091
-                    'event_espresso'
2092
-                ),
2093
-                __FILE__,
2094
-                __FUNCTION__,
2095
-                __LINE__
2096
-            );
2097
-        }
2098
-
2099
-        // all templates will be reset to whatever the defaults are
2100
-        // for the global template matching the messenger and message type.
2101
-        $success = ! empty($GRP_ID);
2102
-
2103
-        if ($success) {
2104
-            // let's first determine if the incoming template is a global template,
2105
-            // if it isn't then we need to get the global template matching messenger and message type.
2106
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
-
2108
-
2109
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
-
2112
-            if ($success) {
2113
-                // if successfully deleted, lets generate the new ones.
2114
-                // Note. We set GLOBAL to true, because resets on ANY template
2115
-                // will use the related global template defaults for regeneration.
2116
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2117
-                // HOWEVER, we DO keep the template pack and template variation set
2118
-                // for the current custom template when resetting.
2119
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
-            }
2121
-        }
2122
-
2123
-        // any error messages?
2124
-        if (! $success) {
2125
-            EE_Error::add_error(
2126
-                esc_html__(
2127
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2128
-                    'event_espresso'
2129
-                ),
2130
-                __FILE__,
2131
-                __FUNCTION__,
2132
-                __LINE__
2133
-            );
2134
-        }
2135
-
2136
-        // all good, let's add a success message!
2137
-        if ($success && ! empty($templates)) {
2138
-            // the info for the template we generated is the first element in the returned array
2139
-            EE_Error::overwrite_success();
2140
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
-        }
2142
-
2143
-
2144
-        $query_args = [
2145
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
-        ];
2149
-
2150
-        // if called via ajax then we return query args otherwise redirect
2151
-        if ($this->request->isAjax()) {
2152
-            return $query_args;
2153
-        }
2154
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2155
-    }
2156
-
2157
-
2158
-    /**
2159
-     * Retrieve and set the message preview for display.
2160
-     *
2161
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
-     * @return string
2163
-     * @throws ReflectionException
2164
-     * @throws EE_Error
2165
-     * @throws InvalidArgumentException
2166
-     * @throws InvalidDataTypeException
2167
-     * @throws InvalidInterfaceException
2168
-     */
2169
-    public function _preview_message($send = false)
2170
-    {
2171
-        // first make sure we've got the necessary parameters
2172
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
-            EE_Error::add_error(
2175
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
-                __FILE__,
2177
-                __FUNCTION__,
2178
-                __LINE__
2179
-            );
2180
-        }
2181
-
2182
-        $context = $this->request->getRequestParam('context');
2183
-        // get the preview!
2184
-        $preview = EED_Messages::preview_message(
2185
-            $this->_active_message_type_name,
2186
-            $context,
2187
-            $this->_active_messenger_name,
2188
-            $send
2189
-        );
2190
-
2191
-        if ($send) {
2192
-            return $preview;
2193
-        }
2194
-
2195
-        // if we have an evt_id set on the request, use it.
2196
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
-
2198
-        // let's add a button to go back to the edit view
2199
-        $query_args             = [
2200
-            'id'      => $GRP_ID,
2201
-            'evt_id'  => $EVT_ID,
2202
-            'context' => $context,
2203
-            'action'  => 'edit_message_template',
2204
-        ];
2205
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
-        $preview_button         = '<a href="'
2207
-                                  . $go_back_url
2208
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2209
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2210
-                                  . '</a>';
2211
-        $message_types          = $this->get_installed_message_types();
2212
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2214
-            ? ucwords($active_messenger->label['singular'])
2215
-            : esc_html__('Unknown Messenger', 'event_espresso');
2216
-        // let's provide a helpful title for context
2217
-        $preview_title = sprintf(
2218
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
-            $active_messenger_label,
2220
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
-        );
2222
-        if (empty($preview)) {
2223
-            $this->noEventsErrorMessage();
2224
-        }
2225
-        // setup display of preview.
2226
-        $this->_admin_page_title                    = $preview_title;
2227
-        $this->_template_args['admin_page_title']   = $preview_title;
2228
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
-        $this->_template_args['data']['force_json'] = true;
2230
-
2231
-        return '';
2232
-    }
2233
-
2234
-
2235
-    /**
2236
-     * Used to set an error if there are no events available for generating a preview/test send.
2237
-     *
2238
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
-     */
2240
-    protected function noEventsErrorMessage($test_send = false)
2241
-    {
2242
-        $events_url = parent::add_query_args_and_nonce(
2243
-            [
2244
-                'action' => 'default',
2245
-                'page'   => 'espresso_events',
2246
-            ],
2247
-            admin_url('admin.php')
2248
-        );
2249
-        $message    = $test_send
2250
-            ? esc_html__(
2251
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
-                'event_espresso'
2253
-            )
2254
-            : esc_html__(
2255
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
-                'event_espresso'
2257
-            );
2258
-
2259
-        EE_Error::add_attention(
2260
-            sprintf(
2261
-                $message,
2262
-                "<a href='{$events_url}'>",
2263
-                '</a>'
2264
-            )
2265
-        );
2266
-    }
2267
-
2268
-
2269
-    /**
2270
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
-     * gets called automatically.
2272
-     *
2273
-     * @return void
2274
-     * @throws EE_Error
2275
-     * @since 4.5.0
2276
-     *
2277
-     */
2278
-    protected function _display_preview_message()
2279
-    {
2280
-        $this->display_admin_page_with_no_sidebar();
2281
-    }
2282
-
2283
-
2284
-    /**
2285
-     * registers metaboxes that should show up on the "edit_message_template" page
2286
-     *
2287
-     * @access protected
2288
-     * @return void
2289
-     */
2290
-    protected function _register_edit_meta_boxes()
2291
-    {
2292
-        add_meta_box(
2293
-            'mtp_valid_shortcodes',
2294
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2295
-            [$this, 'shortcode_meta_box'],
2296
-            $this->_current_screen->id,
2297
-            'side'
2298
-        );
2299
-        add_meta_box(
2300
-            'mtp_extra_actions',
2301
-            esc_html__('Extra Actions', 'event_espresso'),
2302
-            [$this, 'extra_actions_meta_box'],
2303
-            $this->_current_screen->id,
2304
-            'side',
2305
-            'high'
2306
-        );
2307
-        add_meta_box(
2308
-            'mtp_templates',
2309
-            esc_html__('Template Styles', 'event_espresso'),
2310
-            [$this, 'template_pack_meta_box'],
2311
-            $this->_current_screen->id,
2312
-            'side',
2313
-            'high'
2314
-        );
2315
-    }
2316
-
2317
-
2318
-    /**
2319
-     * metabox content for all template pack and variation selection.
2320
-     *
2321
-     * @return void
2322
-     * @throws DomainException
2323
-     * @throws EE_Error
2324
-     * @throws InvalidArgumentException
2325
-     * @throws ReflectionException
2326
-     * @throws InvalidDataTypeException
2327
-     * @throws InvalidInterfaceException
2328
-     * @since 4.5.0
2329
-     */
2330
-    public function template_pack_meta_box()
2331
-    {
2332
-        $this->_set_message_template_group();
2333
-
2334
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
-
2336
-        $tp_select_values = [];
2337
-
2338
-        foreach ($tp_collection as $tp) {
2339
-            // only include template packs that support this messenger and message type!
2340
-            $supports = $tp->get_supports();
2341
-            if (
2342
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2343
-                || ! in_array(
2344
-                    $this->_message_template_group->message_type(),
2345
-                    $supports[ $this->_message_template_group->messenger() ],
2346
-                    true
2347
-                )
2348
-            ) {
2349
-                // not supported
2350
-                continue;
2351
-            }
2352
-
2353
-            $tp_select_values[] = [
2354
-                'text' => $tp->label,
2355
-                'id'   => $tp->dbref,
2356
-            ];
2357
-        }
2358
-
2359
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
-        // the default template pack.  This still allows for the odd template pack to override.
2361
-        if (empty($tp_select_values)) {
2362
-            $tp_select_values[] = [
2363
-                'text' => esc_html__('Default', 'event_espresso'),
2364
-                'id'   => 'default',
2365
-            ];
2366
-        }
2367
-
2368
-        // setup variation select values for the currently selected template.
2369
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
-            $this->_message_template_group->messenger(),
2371
-            $this->_message_template_group->message_type()
2372
-        );
2373
-        $variations_select_values = [];
2374
-        foreach ($variations as $variation => $label) {
2375
-            $variations_select_values[] = [
2376
-                'text' => $label,
2377
-                'id'   => $variation,
2378
-            ];
2379
-        }
2380
-
2381
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
-
2383
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
-            'MTP_template_pack',
2385
-            $tp_select_values,
2386
-            $this->_message_template_group->get_template_pack_name()
2387
-        );
2388
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
-            'MTP_template_variation',
2390
-            $variations_select_values,
2391
-            $this->_message_template_group->get_template_pack_variation()
2392
-        );
2393
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
-
2398
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
-
2400
-        EEH_Template::display_template($template, $template_args);
2401
-    }
2402
-
2403
-
2404
-    /**
2405
-     * This meta box holds any extra actions related to Message Templates
2406
-     * For now, this includes Resetting templates to defaults and sending a test email.
2407
-     *
2408
-     * @access  public
2409
-     * @return void
2410
-     * @throws EE_Error
2411
-     */
2412
-    public function extra_actions_meta_box()
2413
-    {
2414
-        $template_form_fields = [];
2415
-
2416
-        $extra_args = [
2417
-            'msgr'   => $this->_message_template_group->messenger(),
2418
-            'mt'     => $this->_message_template_group->message_type(),
2419
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
-        ];
2421
-        // first we need to see if there are any fields
2422
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
-
2424
-        if (! empty($fields)) {
2425
-            // yup there be fields
2426
-            foreach ($fields as $field => $config) {
2427
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
-                $default  = isset($config['default']) ? $config['default'] : '';
2430
-                $default  = isset($config['value']) ? $config['value'] : $default;
2431
-
2432
-                // if type is hidden and the value is empty
2433
-                // something may have gone wrong so let's correct with the defaults
2434
-                $fix                = $config['input'] === 'hidden'
2435
-                                      && isset($existing[ $field ])
2436
-                                      && empty($existing[ $field ])
2437
-                    ? $default
2438
-                    : '';
2439
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
-                    ? $existing[ $field ]
2441
-                    : $fix;
2442
-
2443
-                $template_form_fields[ $field_id ] = [
2444
-                    'name'       => 'test_settings_fld[' . $field . ']',
2445
-                    'label'      => $config['label'],
2446
-                    'input'      => $config['input'],
2447
-                    'type'       => $config['type'],
2448
-                    'required'   => $config['required'],
2449
-                    'validation' => $config['validation'],
2450
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
-                    'css_class'  => $config['css_class'],
2452
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2453
-                    'default'    => $default,
2454
-                    'format'     => $config['format'],
2455
-                ];
2456
-            }
2457
-        }
2458
-
2459
-        $test_settings_html = ! empty($template_form_fields)
2460
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
-            : '';
2462
-
2463
-        // print out $test_settings_fields
2464
-        if (! empty($test_settings_html)) {
2465
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
-            $test_settings_html .= 'name="test_button" value="';
2467
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2469
-        }
2470
-
2471
-        // and button
2472
-        $test_settings_html .= '<p>';
2473
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
-        $test_settings_html .= '</p>';
2475
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
-        $test_settings_html .= $this->get_action_link_or_button(
2477
-            'reset_to_default',
2478
-            'reset',
2479
-            $extra_args,
2480
-            'button-primary reset-default-button'
2481
-        );
2482
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2483
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
-    }
2485
-
2486
-
2487
-    /**
2488
-     * This returns the shortcode selector skeleton for a given context and field.
2489
-     *
2490
-     * @param string $field           The name of the field retrieving shortcodes for.
2491
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
-     * @return string
2493
-     * @throws DomainException
2494
-     * @throws EE_Error
2495
-     * @throws InvalidArgumentException
2496
-     * @throws ReflectionException
2497
-     * @throws InvalidDataTypeException
2498
-     * @throws InvalidInterfaceException
2499
-     * @since 4.9.rc.000
2500
-     */
2501
-    protected function _get_shortcode_selector($field, $linked_input_id)
2502
-    {
2503
-        $template_args = [
2504
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2505
-            'fieldname'       => $field,
2506
-            'linked_input_id' => $linked_input_id,
2507
-        ];
2508
-
2509
-        return EEH_Template::display_template(
2510
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
-            $template_args,
2512
-            true
2513
-        );
2514
-    }
2515
-
2516
-
2517
-    /**
2518
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
-     * page)
2520
-     *
2521
-     * @access public
2522
-     * @return void
2523
-     * @throws EE_Error
2524
-     * @throws InvalidArgumentException
2525
-     * @throws ReflectionException
2526
-     * @throws InvalidDataTypeException
2527
-     * @throws InvalidInterfaceException
2528
-     */
2529
-    public function shortcode_meta_box()
2530
-    {
2531
-        $shortcodes = $this->_get_shortcodes([], false);
2532
-        // just make sure the shortcodes property is set
2533
-        // $messenger = $this->_message_template_group->messenger_obj();
2534
-        // now let's set the content depending on the status of the shortcodes array
2535
-        if (empty($shortcodes)) {
2536
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
-            return;
2538
-        }
2539
-        ?>
20
+	/**
21
+	 * @var EEM_Message
22
+	 */
23
+	private $MSG_MODEL;
24
+
25
+	/**
26
+	 * @var EEM_Message_Template
27
+	 */
28
+	private $MTP_MODEL;
29
+
30
+	/**
31
+	 * @var EEM_Message_Template_Group
32
+	 */
33
+	private $MTG_MODEL;
34
+
35
+	/**
36
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
37
+	 */
38
+	protected $_message_resource_manager;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $_active_message_type_name = '';
44
+
45
+	/**
46
+	 * @var string
47
+	 */
48
+	protected $_active_messenger_name = '';
49
+
50
+	/**
51
+	 * @var EE_messenger $_active_messenger
52
+	 */
53
+	protected $_active_messenger;
54
+
55
+	protected $_activate_meta_box_type;
56
+
57
+	protected $_current_message_meta_box;
58
+
59
+	protected $_current_message_meta_box_object;
60
+
61
+	protected $_context_switcher;
62
+
63
+	protected $_shortcodes           = [];
64
+
65
+	protected $_active_messengers    = [];
66
+
67
+	protected $_active_message_types = [];
68
+
69
+	/**
70
+	 * @var EE_Message_Template_Group $_message_template_group
71
+	 */
72
+	protected $_message_template_group;
73
+
74
+	protected $_m_mt_settings = [];
75
+
76
+
77
+	/**
78
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
+	 * IF there is no group then it gets automatically set to the Default template pack.
80
+	 *
81
+	 * @since 4.5.0
82
+	 *
83
+	 * @var EE_Messages_Template_Pack
84
+	 */
85
+	protected $_template_pack;
86
+
87
+
88
+	/**
89
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
+	 * group is.  If there is no group then it automatically gets set to default.
91
+	 *
92
+	 * @since 4.5.0
93
+	 *
94
+	 * @var string
95
+	 */
96
+	protected $_variation;
97
+
98
+
99
+	/**
100
+	 * @param bool $routing
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	public function __construct($routing = true)
105
+	{
106
+		// make sure messages autoloader is running
107
+		EED_Messages::set_autoloaders();
108
+		parent::__construct($routing);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Message
114
+	 * @throws EE_Error
115
+	 */
116
+	public function getMsgModel()
117
+	{
118
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
119
+			$this->MSG_MODEL = EEM_Message::instance();
120
+		}
121
+		return $this->MSG_MODEL;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return EEM_Message_Template
127
+	 * @throws EE_Error
128
+	 */
129
+	public function getMtpModel()
130
+	{
131
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
+			$this->MTP_MODEL = EEM_Message_Template::instance();
133
+		}
134
+		return $this->MTP_MODEL;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return EEM_Message_Template_Group
140
+	 * @throws EE_Error
141
+	 */
142
+	public function getMtgModel()
143
+	{
144
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
+		}
147
+		return $this->MTG_MODEL;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	protected function _init_page_props()
156
+	{
157
+		$this->page_slug        = EE_MSG_PG_SLUG;
158
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
+		$this->_admin_base_path = EE_MSG_ADMIN;
161
+
162
+		$messenger    = $this->request->getRequestParam('messenger', '');
163
+		$message_type = $this->request->getRequestParam('message_type', '');
164
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
+
167
+		$this->_load_message_resource_manager();
168
+	}
169
+
170
+
171
+	/**
172
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
+	 *
174
+	 * @throws EE_Error
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _load_message_resource_manager()
181
+	{
182
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return array
188
+	 * @throws EE_Error
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 * @deprecated 4.9.9.rc.014
193
+	 */
194
+	public function get_messengers_for_list_table()
195
+	{
196
+		EE_Error::doing_it_wrong(
197
+			__METHOD__,
198
+			sprintf(
199
+				esc_html__(
200
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
+					'event_espresso'
202
+				),
203
+				'Messages_Admin_Page::get_messengers_select_input()'
204
+			),
205
+			'4.9.9.rc.014'
206
+		);
207
+
208
+		$m_values          = [];
209
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
+		// setup messengers for selects
211
+		$i = 1;
212
+		foreach ($active_messengers as $active_messenger) {
213
+			if ($active_messenger instanceof EE_Message) {
214
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
215
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
+				$i++;
217
+			}
218
+		}
219
+
220
+		return $m_values;
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return array
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @deprecated 4.9.9.rc.014
231
+	 */
232
+	public function get_message_types_for_list_table()
233
+	{
234
+		EE_Error::doing_it_wrong(
235
+			__METHOD__,
236
+			sprintf(
237
+				esc_html__(
238
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
+					'event_espresso'
240
+				),
241
+				'Messages_Admin_Page::get_message_types_select_input()'
242
+			),
243
+			'4.9.9.rc.014'
244
+		);
245
+
246
+		$mt_values       = [];
247
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
+		$i               = 1;
249
+		foreach ($active_messages as $active_message) {
250
+			if ($active_message instanceof EE_Message) {
251
+				$mt_values[ $i ]['id']   = $active_message->message_type();
252
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
+				$i++;
254
+			}
255
+		}
256
+
257
+		return $mt_values;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @deprecated 4.9.9.rc.014
268
+	 */
269
+	public function get_contexts_for_message_types_for_list_table()
270
+	{
271
+		EE_Error::doing_it_wrong(
272
+			__METHOD__,
273
+			sprintf(
274
+				esc_html__(
275
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
+					'event_espresso'
277
+				),
278
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
+			),
280
+			'4.9.9.rc.014'
281
+		);
282
+
283
+		$contexts                = [];
284
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
+		foreach ($active_message_contexts as $active_message) {
286
+			if ($active_message instanceof EE_Message) {
287
+				$message_type = $active_message->message_type_object();
288
+				if ($message_type instanceof EE_message_type) {
289
+					$message_type_contexts = $message_type->get_contexts();
290
+					foreach ($message_type_contexts as $context => $context_details) {
291
+						$contexts[ $context ] = $context_details['label'];
292
+					}
293
+				}
294
+			}
295
+		}
296
+
297
+		return $contexts;
298
+	}
299
+
300
+
301
+	/**
302
+	 * Generate select input with provided messenger options array.
303
+	 *
304
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
+	 *                                 labels.
306
+	 * @return string
307
+	 * @throws EE_Error
308
+	 */
309
+	public function get_messengers_select_input($messenger_options)
310
+	{
311
+		// if empty or just one value then just return an empty string
312
+		if (
313
+			empty($messenger_options)
314
+			|| ! is_array($messenger_options)
315
+			|| count($messenger_options) === 1
316
+		) {
317
+			return '';
318
+		}
319
+		// merge in default
320
+		$messenger_options = array_merge(
321
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
+			$messenger_options
323
+		);
324
+		$input             = new EE_Select_Input(
325
+			$messenger_options,
326
+			[
327
+				'html_name'  => 'ee_messenger_filter_by',
328
+				'html_id'    => 'ee_messenger_filter_by',
329
+				'html_class' => 'wide',
330
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
+			]
332
+		);
333
+
334
+		return $input->get_html_for_input();
335
+	}
336
+
337
+
338
+	/**
339
+	 * Generate select input with provided message type options array.
340
+	 *
341
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
+	 *                                    message type labels
343
+	 * @return string
344
+	 * @throws EE_Error
345
+	 */
346
+	public function get_message_types_select_input($message_type_options)
347
+	{
348
+		// if empty or count of options is 1 then just return an empty string
349
+		if (
350
+			empty($message_type_options)
351
+			|| ! is_array($message_type_options)
352
+			|| count($message_type_options) === 1
353
+		) {
354
+			return '';
355
+		}
356
+		// merge in default
357
+		$message_type_options = array_merge(
358
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
+			$message_type_options
360
+		);
361
+		$input                = new EE_Select_Input(
362
+			$message_type_options,
363
+			[
364
+				'html_name'  => 'ee_message_type_filter_by',
365
+				'html_id'    => 'ee_message_type_filter_by',
366
+				'html_class' => 'wide',
367
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
+			]
369
+		);
370
+
371
+		return $input->get_html_for_input();
372
+	}
373
+
374
+
375
+	/**
376
+	 * Generate select input with provide message type contexts array.
377
+	 *
378
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
+	 *                               context label.
380
+	 * @return string
381
+	 * @throws EE_Error
382
+	 */
383
+	public function get_contexts_for_message_types_select_input($context_options)
384
+	{
385
+		// if empty or count of options is one then just return empty string
386
+		if (
387
+			empty($context_options)
388
+			|| ! is_array($context_options)
389
+			|| count($context_options) === 1
390
+		) {
391
+			return '';
392
+		}
393
+		// merge in default
394
+		$context_options = array_merge(
395
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
+			$context_options
397
+		);
398
+		$input           = new EE_Select_Input(
399
+			$context_options,
400
+			[
401
+				'html_name'  => 'ee_context_filter_by',
402
+				'html_id'    => 'ee_context_filter_by',
403
+				'html_class' => 'wide',
404
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
+			]
406
+		);
407
+
408
+		return $input->get_html_for_input();
409
+	}
410
+
411
+
412
+	protected function _ajax_hooks()
413
+	{
414
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
+	}
421
+
422
+
423
+	protected function _define_page_props()
424
+	{
425
+		$this->_admin_page_title = $this->page_label;
426
+		$this->_labels           = [
427
+			'buttons'    => [
428
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
+			],
432
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
+		];
434
+	}
435
+
436
+
437
+	/**
438
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
439
+	 *
440
+	 * @access protected
441
+	 * @return void
442
+	 */
443
+	protected function _set_page_routes()
444
+	{
445
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
+
449
+		$this->_page_routes = [
450
+			'default'                          => [
451
+				'func'       => '_message_queue_list_table',
452
+				'capability' => 'ee_read_global_messages',
453
+			],
454
+			'global_mtps'                      => [
455
+				'func'       => '_ee_default_messages_overview_list_table',
456
+				'capability' => 'ee_read_global_messages',
457
+			],
458
+			'custom_mtps'                      => [
459
+				'func'       => '_custom_mtps_preview',
460
+				'capability' => 'ee_read_messages',
461
+			],
462
+			'add_new_message_template'         => [
463
+				'func'       => 'add_message_template',
464
+				'capability' => 'ee_edit_messages',
465
+				'noheader'   => true,
466
+			],
467
+			'edit_message_template'            => [
468
+				'func'       => '_edit_message_template',
469
+				'capability' => 'ee_edit_message',
470
+				'obj_id'     => $GRP_ID,
471
+			],
472
+			'preview_message'                  => [
473
+				'func'               => '_preview_message',
474
+				'capability'         => 'ee_read_message',
475
+				'obj_id'             => $GRP_ID,
476
+				'noheader'           => true,
477
+				'headers_sent_route' => 'display_preview_message',
478
+			],
479
+			'display_preview_message'          => [
480
+				'func'       => '_display_preview_message',
481
+				'capability' => 'ee_read_message',
482
+				'obj_id'     => $GRP_ID,
483
+			],
484
+			'insert_message_template'          => [
485
+				'func'       => '_insert_or_update_message_template',
486
+				'capability' => 'ee_edit_messages',
487
+				'args'       => ['new' => true],
488
+				'noheader'   => true,
489
+			],
490
+			'update_message_template'          => [
491
+				'func'       => '_insert_or_update_message_template',
492
+				'capability' => 'ee_edit_message',
493
+				'obj_id'     => $GRP_ID,
494
+				'args'       => ['new' => false],
495
+				'noheader'   => true,
496
+			],
497
+			'trash_message_template'           => [
498
+				'func'       => '_trash_or_restore_message_template',
499
+				'capability' => 'ee_delete_message',
500
+				'obj_id'     => $GRP_ID,
501
+				'args'       => ['trash' => true, 'all' => true],
502
+				'noheader'   => true,
503
+			],
504
+			'trash_message_template_context'   => [
505
+				'func'       => '_trash_or_restore_message_template',
506
+				'capability' => 'ee_delete_message',
507
+				'obj_id'     => $GRP_ID,
508
+				'args'       => ['trash' => true],
509
+				'noheader'   => true,
510
+			],
511
+			'restore_message_template'         => [
512
+				'func'       => '_trash_or_restore_message_template',
513
+				'capability' => 'ee_delete_message',
514
+				'obj_id'     => $GRP_ID,
515
+				'args'       => ['trash' => false, 'all' => true],
516
+				'noheader'   => true,
517
+			],
518
+			'restore_message_template_context' => [
519
+				'func'       => '_trash_or_restore_message_template',
520
+				'capability' => 'ee_delete_message',
521
+				'obj_id'     => $GRP_ID,
522
+				'args'       => ['trash' => false],
523
+				'noheader'   => true,
524
+			],
525
+			'delete_message_template'          => [
526
+				'func'       => '_delete_message_template',
527
+				'capability' => 'ee_delete_message',
528
+				'obj_id'     => $GRP_ID,
529
+				'noheader'   => true,
530
+			],
531
+			'reset_to_default'                 => [
532
+				'func'       => '_reset_to_default_template',
533
+				'capability' => 'ee_edit_message',
534
+				'obj_id'     => $GRP_ID,
535
+				'noheader'   => true,
536
+			],
537
+			'settings'                         => [
538
+				'func'       => '_settings',
539
+				'capability' => 'manage_options',
540
+			],
541
+			'update_global_settings'           => [
542
+				'func'       => '_update_global_settings',
543
+				'capability' => 'manage_options',
544
+				'noheader'   => true,
545
+			],
546
+			'generate_now'                     => [
547
+				'func'       => '_generate_now',
548
+				'capability' => 'ee_send_message',
549
+				'noheader'   => true,
550
+			],
551
+			'generate_and_send_now'            => [
552
+				'func'       => '_generate_and_send_now',
553
+				'capability' => 'ee_send_message',
554
+				'noheader'   => true,
555
+			],
556
+			'queue_for_resending'              => [
557
+				'func'       => '_queue_for_resending',
558
+				'capability' => 'ee_send_message',
559
+				'noheader'   => true,
560
+			],
561
+			'send_now'                         => [
562
+				'func'       => '_send_now',
563
+				'capability' => 'ee_send_message',
564
+				'noheader'   => true,
565
+			],
566
+			'delete_ee_message'                => [
567
+				'func'       => '_delete_ee_messages',
568
+				'capability' => 'ee_delete_messages',
569
+				'noheader'   => true,
570
+			],
571
+			'delete_ee_messages'               => [
572
+				'func'       => '_delete_ee_messages',
573
+				'capability' => 'ee_delete_messages',
574
+				'noheader'   => true,
575
+				'obj_id'     => $MSG_ID,
576
+			],
577
+		];
578
+	}
579
+
580
+
581
+	protected function _set_page_config()
582
+	{
583
+		$this->_page_config = [
584
+			'default'                  => [
585
+				'nav'           => [
586
+					'label' => esc_html__('Message Activity', 'event_espresso'),
587
+					'order' => 10,
588
+				],
589
+				'list_table'    => 'EE_Message_List_Table',
590
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
+				'require_nonce' => false,
592
+			],
593
+			'global_mtps'              => [
594
+				'nav'           => [
595
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
+					'order' => 20,
597
+				],
598
+				'list_table'    => 'Messages_Template_List_Table',
599
+				'help_tabs'     => [
600
+					'messages_overview_help_tab'                                => [
601
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
+						'filename' => 'messages_overview',
603
+					],
604
+					'messages_overview_messages_table_column_headings_help_tab' => [
605
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
+						'filename' => 'messages_overview_table_column_headings',
607
+					],
608
+					'messages_overview_messages_filters_help_tab'               => [
609
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
610
+						'filename' => 'messages_overview_filters',
611
+					],
612
+					'messages_overview_messages_views_help_tab'                 => [
613
+						'title'    => esc_html__('Message Views', 'event_espresso'),
614
+						'filename' => 'messages_overview_views',
615
+					],
616
+					'message_overview_message_types_help_tab'                   => [
617
+						'title'    => esc_html__('Message Types', 'event_espresso'),
618
+						'filename' => 'messages_overview_types',
619
+					],
620
+					'messages_overview_messengers_help_tab'                     => [
621
+						'title'    => esc_html__('Messengers', 'event_espresso'),
622
+						'filename' => 'messages_overview_messengers',
623
+					],
624
+				],
625
+				'require_nonce' => false,
626
+			],
627
+			'custom_mtps'              => [
628
+				'nav'           => [
629
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
+					'order' => 30,
631
+				],
632
+				'help_tabs'     => [],
633
+				'require_nonce' => false,
634
+			],
635
+			'add_new_message_template' => [
636
+				'nav'           => [
637
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
+					'order'      => 5,
639
+					'persistent' => false,
640
+				],
641
+				'require_nonce' => false,
642
+			],
643
+			'edit_message_template'    => [
644
+				'labels'        => [
645
+					'buttons'    => [
646
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
+					],
648
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
+				],
650
+				'nav'           => [
651
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
+					'order'      => 5,
653
+					'persistent' => false,
654
+					'url'        => '',
655
+				],
656
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
+				'has_metaboxes' => true,
658
+				'help_tabs'     => [
659
+					'edit_message_template'            => [
660
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
+						'callback' => 'edit_message_template_help_tab',
662
+					],
663
+					'message_templates_help_tab'       => [
664
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
665
+						'filename' => 'messages_templates',
666
+					],
667
+					'message_template_shortcodes'      => [
668
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
+						'callback' => 'message_template_shortcodes_help_tab',
670
+					],
671
+					'message_preview_help_tab'         => [
672
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
673
+						'filename' => 'messages_preview',
674
+					],
675
+					'messages_overview_other_help_tab' => [
676
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
677
+						'filename' => 'messages_overview_other',
678
+					],
679
+				],
680
+				'require_nonce' => false,
681
+			],
682
+			'display_preview_message'  => [
683
+				'nav'           => [
684
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
685
+					'order'      => 5,
686
+					'url'        => '',
687
+					'persistent' => false,
688
+				],
689
+				'help_tabs'     => [
690
+					'preview_message' => [
691
+						'title'    => esc_html__('About Previews', 'event_espresso'),
692
+						'callback' => 'preview_message_help_tab',
693
+					],
694
+				],
695
+				'require_nonce' => false,
696
+			],
697
+			'settings'                 => [
698
+				'nav'           => [
699
+					'label' => esc_html__('Settings', 'event_espresso'),
700
+					'order' => 40,
701
+				],
702
+				'metaboxes'     => ['_messages_settings_metaboxes'],
703
+				'help_tabs'     => [
704
+					'messages_settings_help_tab'               => [
705
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
+						'filename' => 'messages_settings',
707
+					],
708
+					'messages_settings_message_types_help_tab' => [
709
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
+						'filename' => 'messages_settings_message_types',
711
+					],
712
+					'messages_settings_messengers_help_tab'    => [
713
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
+						'filename' => 'messages_settings_messengers',
715
+					],
716
+				],
717
+				'require_nonce' => false,
718
+			],
719
+		];
720
+	}
721
+
722
+
723
+	protected function _add_screen_options()
724
+	{
725
+		// todo
726
+	}
727
+
728
+
729
+	protected function _add_screen_options_global_mtps()
730
+	{
731
+		/**
732
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
734
+		 */
735
+		$page_title              = $this->_admin_page_title;
736
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
+		$this->_per_page_screen_option();
738
+		$this->_admin_page_title = $page_title;
739
+	}
740
+
741
+
742
+	protected function _add_screen_options_default()
743
+	{
744
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
+		$this->_per_page_screen_option();
746
+	}
747
+
748
+
749
+	// none of the below group are currently used for Messages
750
+	protected function _add_feature_pointers()
751
+	{
752
+	}
753
+
754
+
755
+	public function admin_init()
756
+	{
757
+	}
758
+
759
+
760
+	public function admin_notices()
761
+	{
762
+	}
763
+
764
+
765
+	public function admin_footer_scripts()
766
+	{
767
+	}
768
+
769
+
770
+	public function messages_help_tab()
771
+	{
772
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
+	}
774
+
775
+
776
+	public function messengers_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
+	}
780
+
781
+
782
+	public function message_types_help_tab()
783
+	{
784
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
+	}
786
+
787
+
788
+	public function messages_overview_help_tab()
789
+	{
790
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
+	}
792
+
793
+
794
+	public function message_templates_help_tab()
795
+	{
796
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
+	}
798
+
799
+
800
+	public function edit_message_template_help_tab()
801
+	{
802
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
+						. esc_attr__('Editor Title', 'event_espresso')
804
+						. '" />';
805
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
807
+						. '" />';
808
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
810
+						. '" />';
811
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
813
+						. '" />';
814
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
+						. esc_attr__('Publish Metabox', 'event_espresso')
816
+						. '" />';
817
+		EEH_Template::display_template(
818
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
+			$args
820
+		);
821
+	}
822
+
823
+
824
+	/**
825
+	 * @throws ReflectionException
826
+	 * @throws EE_Error
827
+	 */
828
+	public function message_template_shortcodes_help_tab()
829
+	{
830
+		$this->_set_shortcodes();
831
+		$args['shortcodes'] = $this->_shortcodes;
832
+		EEH_Template::display_template(
833
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
+			$args
835
+		);
836
+	}
837
+
838
+
839
+	public function preview_message_help_tab()
840
+	{
841
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
+	}
843
+
844
+
845
+	public function settings_help_tab()
846
+	{
847
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
+		$args['img3'] = '<div class="switch">'
852
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
+						. ' type="checkbox" checked="checked">'
854
+						. '<label for="ee-on-off-toggle-on"></label>'
855
+						. '</div>';
856
+		$args['img4'] = '<div class="switch">'
857
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
+						. ' type="checkbox">'
859
+						. '<label for="ee-on-off-toggle-on"></label>'
860
+						. '</div>';
861
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
+	}
863
+
864
+
865
+	public function load_scripts_styles()
866
+	{
867
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
+		wp_enqueue_style('espresso_ee_msg');
869
+
870
+		wp_register_script(
871
+			'ee-messages-settings',
872
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
874
+			EVENT_ESPRESSO_VERSION,
875
+			true
876
+		);
877
+		wp_register_script(
878
+			'ee-msg-list-table-js',
879
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
+			['ee-dialog'],
881
+			EVENT_ESPRESSO_VERSION
882
+		);
883
+	}
884
+
885
+
886
+	public function load_scripts_styles_default()
887
+	{
888
+		wp_enqueue_script('ee-msg-list-table-js');
889
+	}
890
+
891
+
892
+	public function wp_editor_css($mce_css)
893
+	{
894
+		// if we're on the edit_message_template route
895
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
+			$message_type_name = $this->_active_message_type_name;
897
+
898
+			// we're going to REPLACE the existing mce css
899
+			// we need to get the css file location from the active messenger
900
+			$mce_css = $this->_active_messenger->get_variation(
901
+				$this->_template_pack,
902
+				$message_type_name,
903
+				true,
904
+				'wpeditor',
905
+				$this->_variation
906
+			);
907
+		}
908
+
909
+		return $mce_css;
910
+	}
911
+
912
+
913
+	/**
914
+	 * @throws EE_Error
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function load_scripts_styles_edit_message_template()
918
+	{
919
+
920
+		$this->_set_shortcodes();
921
+
922
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
+			esc_html__(
924
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
+				'event_espresso'
926
+			),
927
+			$this->_message_template_group->messenger_obj()->label['singular'],
928
+			$this->_message_template_group->message_type_obj()->label['singular']
929
+		);
930
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
+			'event_espresso'
933
+		);
934
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
+			'event_espresso'
937
+		);
938
+
939
+		wp_register_script(
940
+			'ee_msgs_edit_js',
941
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
+			['jquery'],
943
+			EVENT_ESPRESSO_VERSION
944
+		);
945
+
946
+		wp_enqueue_script('ee_admin_js');
947
+		wp_enqueue_script('ee_msgs_edit_js');
948
+
949
+		// add in special css for tiny_mce
950
+		add_filter('mce_css', [$this, 'wp_editor_css']);
951
+	}
952
+
953
+
954
+	/**
955
+	 * @throws EE_Error
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function load_scripts_styles_display_preview_message()
959
+	{
960
+		$this->_set_message_template_group();
961
+		if ($this->_active_messenger_name) {
962
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
+				$this->_active_messenger_name
964
+			);
965
+		}
966
+
967
+		wp_enqueue_style(
968
+			'espresso_preview_css',
969
+			$this->_active_messenger->get_variation(
970
+				$this->_template_pack,
971
+				$this->_active_message_type_name,
972
+				true,
973
+				'preview',
974
+				$this->_variation
975
+			)
976
+		);
977
+	}
978
+
979
+
980
+	public function load_scripts_styles_settings()
981
+	{
982
+		wp_register_style(
983
+			'ee-message-settings',
984
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
+			[],
986
+			EVENT_ESPRESSO_VERSION
987
+		);
988
+		wp_enqueue_style('ee-text-links');
989
+		wp_enqueue_style('ee-message-settings');
990
+		wp_enqueue_script('ee-messages-settings');
991
+	}
992
+
993
+
994
+	/**
995
+	 * set views array for List Table
996
+	 */
997
+	public function _set_list_table_views_global_mtps()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'  => 'in_use',
1002
+				'label' => esc_html__('In Use', 'event_espresso'),
1003
+				'count' => 0,
1004
+			],
1005
+		];
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Set views array for the Custom Template List Table
1011
+	 */
1012
+	public function _set_list_table_views_custom_mtps()
1013
+	{
1014
+		$this->_set_list_table_views_global_mtps();
1015
+		$this->_views['in_use']['bulk_action'] = [
1016
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
+		];
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * set views array for message queue list table
1023
+	 *
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidInterfaceException
1026
+	 * @throws InvalidArgumentException
1027
+	 * @throws EE_Error
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	public function _set_list_table_views_default()
1031
+	{
1032
+		EE_Registry::instance()->load_helper('Template');
1033
+
1034
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
+			'ee_send_message',
1036
+			'message_list_table_bulk_actions'
1037
+		)
1038
+			? [
1039
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
+			]
1044
+			: [];
1045
+
1046
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_delete_messages',
1048
+			'message_list_table_bulk_actions'
1049
+		)
1050
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
+			: [];
1052
+
1053
+
1054
+		$this->_views = [
1055
+			'all' => [
1056
+				'slug'        => 'all',
1057
+				'label'       => esc_html__('All', 'event_espresso'),
1058
+				'count'       => 0,
1059
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
+			],
1061
+		];
1062
+
1063
+
1064
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
+				continue;
1067
+			}
1068
+			$status_bulk_actions = $common_bulk_actions;
1069
+			// unset bulk actions not applying to status
1070
+			if (! empty($status_bulk_actions)) {
1071
+				switch ($status) {
1072
+					case EEM_Message::status_idle:
1073
+					case EEM_Message::status_resend:
1074
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
+						break;
1076
+
1077
+					case EEM_Message::status_failed:
1078
+					case EEM_Message::status_debug_only:
1079
+					case EEM_Message::status_messenger_executing:
1080
+						$status_bulk_actions = [];
1081
+						break;
1082
+
1083
+					case EEM_Message::status_incomplete:
1084
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
+						break;
1086
+
1087
+					case EEM_Message::status_retry:
1088
+					case EEM_Message::status_sent:
1089
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
+						break;
1091
+				}
1092
+			}
1093
+
1094
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1095
+			if ($status === EEM_Message::status_messenger_executing) {
1096
+				continue;
1097
+			}
1098
+
1099
+			$this->_views[ strtolower($status) ] = [
1100
+				'slug'        => strtolower($status),
1101
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
+				'count'       => 0,
1103
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
+			];
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	protected function _ee_default_messages_overview_list_table()
1113
+	{
1114
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * @throws EE_Error
1121
+	 * @throws ReflectionException
1122
+	 */
1123
+	protected function _message_queue_list_table()
1124
+	{
1125
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
+		$this->_template_args['per_column']        = 6;
1127
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
+		$this->_template_args['before_list_table'] = '<h3>'
1129
+													 . $this->getMsgModel()->get_pretty_label_for_results()
1130
+													 . '</h3>';
1131
+		$this->display_admin_list_table_page_with_no_sidebar();
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * @throws EE_Error
1137
+	 */
1138
+	protected function _message_legend_items()
1139
+	{
1140
+
1141
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
+		$action_items       = [];
1143
+
1144
+		foreach ($action_css_classes as $action_item => $action_details) {
1145
+			if ($action_item === 'see_notifications_for') {
1146
+				continue;
1147
+			}
1148
+			$action_items[ $action_item ] = [
1149
+				'class' => $action_details['css_class'],
1150
+				'desc'  => $action_details['label'],
1151
+			];
1152
+		}
1153
+
1154
+		/** @var array $status_items status legend setup */
1155
+		$status_items = [
1156
+			'sent_status'                => [
1157
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
+			],
1160
+			'idle_status'                => [
1161
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
+			],
1164
+			'failed_status'              => [
1165
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
+			],
1168
+			'messenger_executing_status' => [
1169
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
+			],
1172
+			'resend_status'              => [
1173
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
+			],
1176
+			'incomplete_status'          => [
1177
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
+			],
1180
+			'retry_status'               => [
1181
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
+			],
1184
+		];
1185
+		if (EEM_Message::debug()) {
1186
+			$status_items['debug_only_status'] = [
1187
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
+			];
1190
+		}
1191
+
1192
+		return array_merge($action_items, $status_items);
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * @throws EE_Error
1198
+	 */
1199
+	protected function _custom_mtps_preview()
1200
+	{
1201
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
+												. ' alt="' . esc_attr__(
1204
+													'Preview Custom Message Templates screenshot',
1205
+													'event_espresso'
1206
+												) . '" />';
1207
+		$this->_template_args['preview_text'] = '<strong>'
1208
+												. esc_html__(
1209
+													'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1210
+													'event_espresso'
1211
+												)
1212
+												. '</strong>';
1213
+
1214
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * get_message_templates
1220
+	 * This gets all the message templates for listing on the overview list.
1221
+	 *
1222
+	 * @access public
1223
+	 * @param int    $per_page the amount of templates groups to show per page
1224
+	 * @param string $type     the current _view we're getting templates for
1225
+	 * @param bool   $count    return count?
1226
+	 * @param bool   $all      disregard any paging info (get all data);
1227
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 * @throws InvalidArgumentException
1231
+	 * @throws InvalidDataTypeException
1232
+	 * @throws InvalidInterfaceException
1233
+	 */
1234
+	public function get_message_templates(
1235
+		$per_page = 10,
1236
+		$type = 'in_use',
1237
+		$count = false,
1238
+		$all = false,
1239
+		$global = true
1240
+	) {
1241
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
+		$this->request->setRequestParam('orderby', $orderby);
1243
+
1244
+		$order        = $this->request->getRequestParam('order', 'ASC');
1245
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
+
1248
+		$offset = ($current_page - 1) * $per_page;
1249
+		$limit  = $all ? null : [$offset, $per_page];
1250
+
1251
+		// options will match what is in the _views array property
1252
+		return $type === 'in_use'
1253
+			? $this->getMtgModel()->get_all_active_message_templates(
1254
+				$orderby,
1255
+				$order,
1256
+				$limit,
1257
+				$count,
1258
+				$global,
1259
+				true
1260
+			)
1261
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
+				$orderby,
1263
+				$order,
1264
+				$limit,
1265
+				$count,
1266
+				$global
1267
+			);
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 * filters etc might need a list of installed message_types
1273
+	 *
1274
+	 * @return array an array of message type objects
1275
+	 */
1276
+	public function get_installed_message_types()
1277
+	{
1278
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
+		$installed               = [];
1280
+
1281
+		foreach ($installed_message_types as $message_type) {
1282
+			$installed[ $message_type->name ] = $message_type;
1283
+		}
1284
+
1285
+		return $installed;
1286
+	}
1287
+
1288
+
1289
+	/**
1290
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1291
+	 *
1292
+	 * @param string $message_type
1293
+	 * @param string $messenger
1294
+	 * @param string $GRP_ID
1295
+	 *
1296
+	 * @throws EE_error
1297
+	 * @throws ReflectionException
1298
+	 */
1299
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
+	{
1301
+		// set values override any request data
1302
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
+
1306
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
+		if (empty($message_type) || empty($messenger)) {
1308
+			throw new EE_Error(
1309
+				esc_html__(
1310
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
+					'event_espresso'
1312
+				)
1313
+			);
1314
+		}
1315
+
1316
+		// we need the GRP_ID for the template being used as the base for the new template
1317
+		if (empty($GRP_ID)) {
1318
+			throw new EE_Error(
1319
+				esc_html__(
1320
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
+					'event_espresso'
1322
+				)
1323
+			);
1324
+		}
1325
+
1326
+		// let's just make sure the template gets generated!
1327
+
1328
+		// we need to reassign some variables for what the insert is expecting
1329
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1330
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1331
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
+
1333
+		$this->_insert_or_update_message_template(true);
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * @param string $message_type     message type slug
1339
+	 * @param string $messenger        messenger slug
1340
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
+	 *                                 off of.
1342
+	 * @throws EE_error
1343
+	 * @throws ReflectionException
1344
+	 * @deprecated 4.10.29.p
1345
+	 */
1346
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
+	{
1348
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1349
+	}
1350
+
1351
+
1352
+	/**
1353
+	 * _edit_message_template
1354
+	 *
1355
+	 * @access protected
1356
+	 * @return void
1357
+	 * @throws InvalidIdentifierException
1358
+	 * @throws DomainException
1359
+	 * @throws EE_Error
1360
+	 * @throws InvalidArgumentException
1361
+	 * @throws ReflectionException
1362
+	 * @throws InvalidDataTypeException
1363
+	 * @throws InvalidInterfaceException
1364
+	 */
1365
+	protected function _edit_message_template()
1366
+	{
1367
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
+		$template_fields = '';
1369
+		$sidebar_fields  = '';
1370
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
+		// valid html in the templates.
1372
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
+
1374
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
+
1377
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1378
+		$message_template_group = $this->_message_template_group;
1379
+		$c_label                = $message_template_group->context_label();
1380
+		$c_config               = $message_template_group->contexts_config();
1381
+
1382
+		reset($c_config);
1383
+		$context = $this->request->getRequestParam('context', key($c_config));
1384
+		$context = strtolower($context);
1385
+
1386
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
+
1388
+		$edit_message_template_form_url = add_query_arg(
1389
+			['action' => $action, 'noheader' => true],
1390
+			EE_MSG_ADMIN_URL
1391
+		);
1392
+
1393
+		// set active messenger for this view
1394
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
+			$message_template_group->messenger()
1396
+		);
1397
+		$this->_active_message_type_name = $message_template_group->message_type();
1398
+
1399
+
1400
+		// Do we have any validation errors?
1401
+		$validators = $this->_get_transient();
1402
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
+
1404
+
1405
+		// we need to assemble the title from Various details
1406
+		$context_label = sprintf(
1407
+			esc_html__('(%s %s)', 'event_espresso'),
1408
+			$c_config[ $context ]['label'],
1409
+			ucwords($c_label['label'])
1410
+		);
1411
+
1412
+		$title = sprintf(
1413
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1414
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1415
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1416
+			$context_label
1417
+		);
1418
+
1419
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1420
+		$this->_template_args['message_template'] = $message_template_group;
1421
+		$this->_template_args['is_extra_fields']  = false;
1422
+
1423
+
1424
+		// let's get EEH_MSG_Template so we can get template form fields
1425
+		$template_field_structure = EEH_MSG_Template::get_fields(
1426
+			$message_template_group->messenger(),
1427
+			$message_template_group->message_type()
1428
+		);
1429
+
1430
+		if (! $template_field_structure) {
1431
+			$template_field_structure = false;
1432
+			$template_fields          = esc_html__(
1433
+				'There was an error in assembling the fields for this display (you should see an error message)',
1434
+				'event_espresso'
1435
+			);
1436
+		}
1437
+
1438
+
1439
+		$message_templates = $message_template_group->context_templates();
1440
+
1441
+
1442
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
+		// will get handled in the "extra" array.
1444
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
+				unset($template_field_structure[ $context ][ $reference_field ]);
1447
+			}
1448
+		}
1449
+
1450
+		// let's loop through the template_field_structure and actually assemble the input fields!
1451
+		if (! empty($template_field_structure)) {
1452
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
+				// the extra array and reset them.
1455
+				if ($template_field === 'extra') {
1456
+					$this->_template_args['is_extra_fields'] = true;
1457
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
+						$message_template = $message_templates[ $context ][ $reference_field ];
1459
+						$content          = $message_template instanceof EE_Message_Template
1460
+							? $message_template->get('MTP_content')
1461
+							: '';
1462
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1463
+							// let's verify if we need this extra field via the shortcodes parameter.
1464
+							$continue = false;
1465
+							if (isset($extra_array['shortcodes_required'])) {
1466
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
+										$continue = true;
1469
+									}
1470
+								}
1471
+								if ($continue) {
1472
+									continue;
1473
+								}
1474
+							}
1475
+
1476
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1477
+
1478
+							$template_form_fields[ $field_id ]         = $extra_array;
1479
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
+																		 . $reference_field
1481
+																		 . '][content]['
1482
+																		 . $extra_field . ']';
1483
+							$css_class                                 = isset($extra_array['css_class'])
1484
+								? $extra_array['css_class']
1485
+								: '';
1486
+
1487
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
+																			  && in_array($extra_field, $v_fields, true)
1489
+																			  && (
1490
+																				  is_array($validators[ $extra_field ])
1491
+																				  && isset($validators[ $extra_field ]['msg'])
1492
+																			  )
1493
+								? 'validate-error ' . $css_class
1494
+								: $css_class;
1495
+
1496
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
+																		  && isset($content[ $extra_field ])
1498
+								? $content[ $extra_field ]
1499
+								: '';
1500
+
1501
+							// do we have a validation error?  if we do then let's use that value instead
1502
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
+								? $validators[ $extra_field ]['value']
1504
+								: $template_form_fields[ $field_id ]['value'];
1505
+
1506
+
1507
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
+
1509
+							// shortcode selector
1510
+							$field_name_to_use                                   = $extra_field === 'main'
1511
+								? 'content'
1512
+								: $extra_field;
1513
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
+								$field_name_to_use,
1515
+								$field_id
1516
+							);
1517
+						}
1518
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
+						$template_field_template_name_id = $reference_field . '-name';
1520
+
1521
+						$template_form_fields[ $template_field_MTP_id ] = [
1522
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
+							'label'      => null,
1524
+							'input'      => 'hidden',
1525
+							'type'       => 'int',
1526
+							'required'   => false,
1527
+							'validation' => false,
1528
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
+							'css_class'  => '',
1530
+							'format'     => '%d',
1531
+							'db-col'     => 'MTP_ID',
1532
+						];
1533
+
1534
+						$template_form_fields[ $template_field_template_name_id ] = [
1535
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
+							'label'      => null,
1537
+							'input'      => 'hidden',
1538
+							'type'       => 'string',
1539
+							'required'   => false,
1540
+							'validation' => true,
1541
+							'value'      => $reference_field,
1542
+							'css_class'  => '',
1543
+							'format'     => '%s',
1544
+							'db-col'     => 'MTP_template_field',
1545
+						];
1546
+					}
1547
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
+				} else {
1549
+					$field_id                                   = $template_field . '-content';
1550
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1551
+					$template_form_fields[ $field_id ]['name']  =
1552
+						'MTP_template_fields[' . $template_field . '][content]';
1553
+					$message_template                           =
1554
+						isset($message_templates[ $context ][ $template_field ])
1555
+							? $message_templates[ $context ][ $template_field ]
1556
+							: null;
1557
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
+																  && is_array($message_templates[ $context ])
1559
+																  && $message_template instanceof EE_Message_Template
1560
+						? $message_template->get('MTP_content')
1561
+						: '';
1562
+
1563
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1564
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
+						? $validators[ $template_field ]['value']
1566
+						: $template_form_fields[ $field_id ]['value'];
1567
+
1568
+
1569
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
+					$css_class                                      = isset($field_setup_array['css_class'])
1571
+						? $field_setup_array['css_class']
1572
+						: '';
1573
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
+																	  && in_array($template_field, $v_fields, true)
1575
+																	  && isset($validators[ $template_field ]['msg'])
1576
+						? 'validate-error ' . $css_class
1577
+						: $css_class;
1578
+
1579
+					// shortcode selector
1580
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
+						$template_field,
1582
+						$field_id
1583
+					);
1584
+				}
1585
+
1586
+				// k took care of content field(s) now let's take care of others.
1587
+
1588
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
+				$template_field_field_template_name_id = $template_field . '-name';
1590
+
1591
+				// foreach template field there are actually two form fields created
1592
+				$template_form_fields[ $template_field_MTP_id ] = [
1593
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
+					'label'      => null,
1595
+					'input'      => 'hidden',
1596
+					'type'       => 'int',
1597
+					'required'   => false,
1598
+					'validation' => true,
1599
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
+					'css_class'  => '',
1601
+					'format'     => '%d',
1602
+					'db-col'     => 'MTP_ID',
1603
+				];
1604
+
1605
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1606
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
+					'label'      => null,
1608
+					'input'      => 'hidden',
1609
+					'type'       => 'string',
1610
+					'required'   => false,
1611
+					'validation' => true,
1612
+					'value'      => $template_field,
1613
+					'css_class'  => '',
1614
+					'format'     => '%s',
1615
+					'db-col'     => 'MTP_template_field',
1616
+				];
1617
+			}
1618
+
1619
+			// add other fields
1620
+			$template_form_fields['ee-msg-current-context'] = [
1621
+				'name'       => 'MTP_context',
1622
+				'label'      => null,
1623
+				'input'      => 'hidden',
1624
+				'type'       => 'string',
1625
+				'required'   => false,
1626
+				'validation' => true,
1627
+				'value'      => $context,
1628
+				'css_class'  => '',
1629
+				'format'     => '%s',
1630
+				'db-col'     => 'MTP_context',
1631
+			];
1632
+
1633
+			$template_form_fields['ee-msg-grp-id'] = [
1634
+				'name'       => 'GRP_ID',
1635
+				'label'      => null,
1636
+				'input'      => 'hidden',
1637
+				'type'       => 'int',
1638
+				'required'   => false,
1639
+				'validation' => true,
1640
+				'value'      => $GRP_ID,
1641
+				'css_class'  => '',
1642
+				'format'     => '%d',
1643
+				'db-col'     => 'GRP_ID',
1644
+			];
1645
+
1646
+			$template_form_fields['ee-msg-messenger'] = [
1647
+				'name'       => 'MTP_messenger',
1648
+				'label'      => null,
1649
+				'input'      => 'hidden',
1650
+				'type'       => 'string',
1651
+				'required'   => false,
1652
+				'validation' => true,
1653
+				'value'      => $message_template_group->messenger(),
1654
+				'css_class'  => '',
1655
+				'format'     => '%s',
1656
+				'db-col'     => 'MTP_messenger',
1657
+			];
1658
+
1659
+			$template_form_fields['ee-msg-message-type'] = [
1660
+				'name'       => 'MTP_message_type',
1661
+				'label'      => null,
1662
+				'input'      => 'hidden',
1663
+				'type'       => 'string',
1664
+				'required'   => false,
1665
+				'validation' => true,
1666
+				'value'      => $message_template_group->message_type(),
1667
+				'css_class'  => '',
1668
+				'format'     => '%s',
1669
+				'db-col'     => 'MTP_message_type',
1670
+			];
1671
+
1672
+			$sidebar_form_fields['ee-msg-is-global'] = [
1673
+				'name'       => 'MTP_is_global',
1674
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1675
+				'input'      => 'hidden',
1676
+				'type'       => 'int',
1677
+				'required'   => false,
1678
+				'validation' => true,
1679
+				'value'      => $message_template_group->get('MTP_is_global'),
1680
+				'css_class'  => '',
1681
+				'format'     => '%d',
1682
+				'db-col'     => 'MTP_is_global',
1683
+			];
1684
+
1685
+			$sidebar_form_fields['ee-msg-is-override'] = [
1686
+				'name'       => 'MTP_is_override',
1687
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
+				'type'       => 'int',
1690
+				'required'   => false,
1691
+				'validation' => true,
1692
+				'value'      => $message_template_group->get('MTP_is_override'),
1693
+				'css_class'  => '',
1694
+				'format'     => '%d',
1695
+				'db-col'     => 'MTP_is_override',
1696
+			];
1697
+
1698
+			$sidebar_form_fields['ee-msg-is-active'] = [
1699
+				'name'       => 'MTP_is_active',
1700
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1701
+				'input'      => 'hidden',
1702
+				'type'       => 'int',
1703
+				'required'   => false,
1704
+				'validation' => true,
1705
+				'value'      => $message_template_group->is_active(),
1706
+				'css_class'  => '',
1707
+				'format'     => '%d',
1708
+				'db-col'     => 'MTP_is_active',
1709
+			];
1710
+
1711
+			$sidebar_form_fields['ee-msg-deleted'] = [
1712
+				'name'       => 'MTP_deleted',
1713
+				'label'      => null,
1714
+				'input'      => 'hidden',
1715
+				'type'       => 'int',
1716
+				'required'   => false,
1717
+				'validation' => true,
1718
+				'value'      => $message_template_group->get('MTP_deleted'),
1719
+				'css_class'  => '',
1720
+				'format'     => '%d',
1721
+				'db-col'     => 'MTP_deleted',
1722
+			];
1723
+			$sidebar_form_fields['ee-msg-author']  = [
1724
+				'name'       => 'MTP_user_id',
1725
+				'label'      => esc_html__('Author', 'event_espresso'),
1726
+				'input'      => 'hidden',
1727
+				'type'       => 'int',
1728
+				'required'   => false,
1729
+				'validation' => false,
1730
+				'value'      => $message_template_group->user(),
1731
+				'format'     => '%d',
1732
+				'db-col'     => 'MTP_user_id',
1733
+			];
1734
+
1735
+			$sidebar_form_fields['ee-msg-route'] = [
1736
+				'name'  => 'action',
1737
+				'input' => 'hidden',
1738
+				'type'  => 'string',
1739
+				'value' => $action,
1740
+			];
1741
+
1742
+			$sidebar_form_fields['ee-msg-id']        = [
1743
+				'name'  => 'id',
1744
+				'input' => 'hidden',
1745
+				'type'  => 'int',
1746
+				'value' => $GRP_ID,
1747
+			];
1748
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
+				'name'  => $action . '_nonce',
1750
+				'input' => 'hidden',
1751
+				'type'  => 'string',
1752
+				'value' => wp_create_nonce($action . '_nonce'),
1753
+			];
1754
+
1755
+			$template_switch = $this->request->getRequestParam('template_switch');
1756
+			if ($template_switch) {
1757
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1758
+					'name'  => 'template_switch',
1759
+					'input' => 'hidden',
1760
+					'type'  => 'int',
1761
+					'value' => 1,
1762
+				];
1763
+			}
1764
+
1765
+
1766
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
+		} //end if ( !empty($template_field_structure) )
1769
+
1770
+		// set extra content for publish box
1771
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
+		$this->_set_publish_post_box_vars(
1773
+			'id',
1774
+			$GRP_ID,
1775
+			false,
1776
+			add_query_arg(
1777
+				['action' => 'global_mtps'],
1778
+				$this->_admin_base_url
1779
+			)
1780
+		);
1781
+
1782
+		// add preview button
1783
+		$preview_url    = parent::add_query_args_and_nonce(
1784
+			[
1785
+				'message_type' => $message_template_group->message_type(),
1786
+				'messenger'    => $message_template_group->messenger(),
1787
+				'context'      => $context,
1788
+				'GRP_ID'       => $GRP_ID,
1789
+				'evt_id'       => $EVT_ID ?: false,
1790
+				'action'       => 'preview_message',
1791
+			],
1792
+			$this->_admin_base_url
1793
+		);
1794
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
+						  . esc_html__('Preview', 'event_espresso')
1796
+						  . '</a>';
1797
+
1798
+
1799
+		// setup context switcher
1800
+		$this->_set_context_switcher(
1801
+			$message_template_group,
1802
+			[
1803
+				'page'    => 'espresso_messages',
1804
+				'action'  => 'edit_message_template',
1805
+				'id'      => $GRP_ID,
1806
+				'evt_id'  => $EVT_ID,
1807
+				'context' => $context,
1808
+				'extra'   => $preview_button,
1809
+			]
1810
+		);
1811
+
1812
+
1813
+		// main box
1814
+		$this->_template_args['template_fields']                         = $template_fields;
1815
+		$this->_template_args['sidebar_box_id']                          = 'details';
1816
+		$this->_template_args['action']                                  = $action;
1817
+		$this->_template_args['context']                                 = $context;
1818
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
+		$this->_template_args['learn_more_about_message_templates_link'] =
1820
+			$this->_learn_more_about_message_templates_link();
1821
+
1822
+
1823
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
+			$message_template_group,
1826
+			$context,
1827
+			$context_label
1828
+		);
1829
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
+
1832
+		$this->_template_path = $this->_template_args['GRP_ID']
1833
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
+
1836
+		// send along EE_Message_Template_Group object for further template use.
1837
+		$this->_template_args['MTP'] = $message_template_group;
1838
+
1839
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
+			$this->_template_path,
1841
+			$this->_template_args,
1842
+			true
1843
+		);
1844
+
1845
+
1846
+		// finally, let's set the admin_page title
1847
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
+
1849
+
1850
+		// we need to take care of setting the shortcodes property for use elsewhere.
1851
+		$this->_set_shortcodes();
1852
+
1853
+
1854
+		// final template wrapper
1855
+		$this->display_admin_page_with_sidebar();
1856
+	}
1857
+
1858
+
1859
+	public function filter_tinymce_init($mceInit, $editor_id)
1860
+	{
1861
+		return $mceInit;
1862
+	}
1863
+
1864
+
1865
+	public function add_context_switcher()
1866
+	{
1867
+		return $this->_context_switcher;
1868
+	}
1869
+
1870
+
1871
+	/**
1872
+	 * Adds the activation/deactivation toggle for the message template context.
1873
+	 *
1874
+	 * @param EE_Message_Template_Group $message_template_group
1875
+	 * @param string                    $context
1876
+	 * @param string                    $context_label
1877
+	 * @return string
1878
+	 * @throws DomainException
1879
+	 * @throws EE_Error
1880
+	 * @throws InvalidIdentifierException
1881
+	 * @throws ReflectionException
1882
+	 */
1883
+	protected function add_active_context_element(
1884
+		EE_Message_Template_Group $message_template_group,
1885
+		$context,
1886
+		$context_label
1887
+	) {
1888
+		$template_args = [
1889
+			'context'                   => $context,
1890
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
+			'is_active'                 => $message_template_group->is_context_active($context),
1892
+			'on_off_action'             => $message_template_group->is_context_active($context)
1893
+				? 'context-off'
1894
+				: 'context-on',
1895
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
+			'message_template_group_id' => $message_template_group->ID(),
1897
+		];
1898
+		return EEH_Template::display_template(
1899
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
+			$template_args,
1901
+			true
1902
+		);
1903
+	}
1904
+
1905
+
1906
+	/**
1907
+	 * Ajax callback for `toggle_context_template` ajax action.
1908
+	 * Handles toggling the message context on or off.
1909
+	 *
1910
+	 * @throws EE_Error
1911
+	 * @throws InvalidArgumentException
1912
+	 * @throws InvalidDataTypeException
1913
+	 * @throws InvalidIdentifierException
1914
+	 * @throws InvalidInterfaceException
1915
+	 */
1916
+	public function toggle_context_template()
1917
+	{
1918
+		$success = true;
1919
+		// check for required data
1920
+		if (
1921
+			! (
1922
+				$this->request->requestParamIsSet('message_template_group_id')
1923
+				&& $this->request->requestParamIsSet('context')
1924
+				&& $this->request->requestParamIsSet('status')
1925
+			)
1926
+		) {
1927
+			EE_Error::add_error(
1928
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
+				__FILE__,
1930
+				__FUNCTION__,
1931
+				__LINE__
1932
+			);
1933
+			$success = false;
1934
+		}
1935
+
1936
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
+		$context = $this->request->getRequestParam('context', '');
1938
+		$status  = $this->request->getRequestParam('status', '');
1939
+
1940
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
+
1942
+		if ($status !== 'off' && $status !== 'on') {
1943
+			EE_Error::add_error(
1944
+				sprintf(
1945
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
+					$status
1947
+				),
1948
+				__FILE__,
1949
+				__FUNCTION__,
1950
+				__LINE__
1951
+			);
1952
+			$success = false;
1953
+		}
1954
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
+			EE_Error::add_error(
1958
+				sprintf(
1959
+					esc_html__(
1960
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
+						'event_espresso'
1962
+					),
1963
+					$message_template_group_id,
1964
+					'EE_Message_Template_Group'
1965
+				),
1966
+				__FILE__,
1967
+				__FUNCTION__,
1968
+				__LINE__
1969
+			);
1970
+			$success = false;
1971
+		}
1972
+		if ($success) {
1973
+			$success = $status === 'off'
1974
+				? $message_template_group->deactivate_context($context)
1975
+				: $message_template_group->activate_context($context);
1976
+		}
1977
+		$this->_template_args['success'] = $success;
1978
+		$this->_return_json();
1979
+	}
1980
+
1981
+
1982
+	public function _add_form_element_before()
1983
+	{
1984
+		return '<form method="post" action="'
1985
+			   . $this->_template_args['edit_message_template_form_url']
1986
+			   . '" id="ee-msg-edit-frm">';
1987
+	}
1988
+
1989
+
1990
+	public function _add_form_element_after()
1991
+	{
1992
+		return '</form>';
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * This executes switching the template pack for a message template.
1998
+	 *
1999
+	 * @throws EE_Error
2000
+	 * @throws InvalidDataTypeException
2001
+	 * @throws InvalidInterfaceException
2002
+	 * @throws InvalidArgumentException
2003
+	 * @throws ReflectionException
2004
+	 * @since 4.5.0
2005
+	 */
2006
+	public function switch_template_pack()
2007
+	{
2008
+
2009
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2011
+
2012
+		// verify we have needed values.
2013
+		if (empty($GRP_ID) || empty($template_pack)) {
2014
+			$this->_template_args['error'] = true;
2015
+			EE_Error::add_error(
2016
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
+				__FILE__,
2018
+				__FUNCTION__,
2019
+				__LINE__
2020
+			);
2021
+		} else {
2022
+			// get template, set the new template_pack and then reset to default
2023
+			/** @var EE_Message_Template_Group $message_template_group */
2024
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
+
2026
+			$message_template_group->set_template_pack_name($template_pack);
2027
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2029
+
2030
+			$query_args = $this->_reset_to_default_template();
2031
+
2032
+			if (empty($query_args['id'])) {
2033
+				EE_Error::add_error(
2034
+					esc_html__(
2035
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
+						'event_espresso'
2037
+					),
2038
+					__FILE__,
2039
+					__FUNCTION__,
2040
+					__LINE__
2041
+				);
2042
+				$this->_template_args['error'] = true;
2043
+			} else {
2044
+				$template_label       = $message_template_group->get_template_pack()->label;
2045
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
+				EE_Error::add_success(
2047
+					sprintf(
2048
+						esc_html__(
2049
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
+							'event_espresso'
2051
+						),
2052
+						$template_label,
2053
+						$template_pack_labels->template_pack
2054
+					)
2055
+				);
2056
+				// generate the redirect url for js.
2057
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
+
2059
+				$this->_template_args['data']['redirect_url'] = $url;
2060
+				$this->_template_args['success']              = true;
2061
+			}
2062
+
2063
+			$this->_return_json();
2064
+		}
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
+	 * they want.
2071
+	 *
2072
+	 * @access protected
2073
+	 * @return array|void
2074
+	 * @throws EE_Error
2075
+	 * @throws InvalidArgumentException
2076
+	 * @throws InvalidDataTypeException
2077
+	 * @throws InvalidInterfaceException
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	protected function _reset_to_default_template()
2081
+	{
2082
+		$templates    = [];
2083
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
+		$messenger    = $this->request->getRequestParam('msgr');
2085
+		$message_type = $this->request->getRequestParam('mt');
2086
+		// we need to make sure we've got the info we need.
2087
+		if (! ($GRP_ID && $messenger && $message_type)) {
2088
+			EE_Error::add_error(
2089
+				esc_html__(
2090
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2091
+					'event_espresso'
2092
+				),
2093
+				__FILE__,
2094
+				__FUNCTION__,
2095
+				__LINE__
2096
+			);
2097
+		}
2098
+
2099
+		// all templates will be reset to whatever the defaults are
2100
+		// for the global template matching the messenger and message type.
2101
+		$success = ! empty($GRP_ID);
2102
+
2103
+		if ($success) {
2104
+			// let's first determine if the incoming template is a global template,
2105
+			// if it isn't then we need to get the global template matching messenger and message type.
2106
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
+
2108
+
2109
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
+
2112
+			if ($success) {
2113
+				// if successfully deleted, lets generate the new ones.
2114
+				// Note. We set GLOBAL to true, because resets on ANY template
2115
+				// will use the related global template defaults for regeneration.
2116
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2117
+				// HOWEVER, we DO keep the template pack and template variation set
2118
+				// for the current custom template when resetting.
2119
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
+			}
2121
+		}
2122
+
2123
+		// any error messages?
2124
+		if (! $success) {
2125
+			EE_Error::add_error(
2126
+				esc_html__(
2127
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2128
+					'event_espresso'
2129
+				),
2130
+				__FILE__,
2131
+				__FUNCTION__,
2132
+				__LINE__
2133
+			);
2134
+		}
2135
+
2136
+		// all good, let's add a success message!
2137
+		if ($success && ! empty($templates)) {
2138
+			// the info for the template we generated is the first element in the returned array
2139
+			EE_Error::overwrite_success();
2140
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
+		}
2142
+
2143
+
2144
+		$query_args = [
2145
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
+		];
2149
+
2150
+		// if called via ajax then we return query args otherwise redirect
2151
+		if ($this->request->isAjax()) {
2152
+			return $query_args;
2153
+		}
2154
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2155
+	}
2156
+
2157
+
2158
+	/**
2159
+	 * Retrieve and set the message preview for display.
2160
+	 *
2161
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
+	 * @return string
2163
+	 * @throws ReflectionException
2164
+	 * @throws EE_Error
2165
+	 * @throws InvalidArgumentException
2166
+	 * @throws InvalidDataTypeException
2167
+	 * @throws InvalidInterfaceException
2168
+	 */
2169
+	public function _preview_message($send = false)
2170
+	{
2171
+		// first make sure we've got the necessary parameters
2172
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
+			EE_Error::add_error(
2175
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
+				__FILE__,
2177
+				__FUNCTION__,
2178
+				__LINE__
2179
+			);
2180
+		}
2181
+
2182
+		$context = $this->request->getRequestParam('context');
2183
+		// get the preview!
2184
+		$preview = EED_Messages::preview_message(
2185
+			$this->_active_message_type_name,
2186
+			$context,
2187
+			$this->_active_messenger_name,
2188
+			$send
2189
+		);
2190
+
2191
+		if ($send) {
2192
+			return $preview;
2193
+		}
2194
+
2195
+		// if we have an evt_id set on the request, use it.
2196
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
+
2198
+		// let's add a button to go back to the edit view
2199
+		$query_args             = [
2200
+			'id'      => $GRP_ID,
2201
+			'evt_id'  => $EVT_ID,
2202
+			'context' => $context,
2203
+			'action'  => 'edit_message_template',
2204
+		];
2205
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
+		$preview_button         = '<a href="'
2207
+								  . $go_back_url
2208
+								  . '" class="button-secondary messages-preview-go-back-button">'
2209
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2210
+								  . '</a>';
2211
+		$message_types          = $this->get_installed_message_types();
2212
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2214
+			? ucwords($active_messenger->label['singular'])
2215
+			: esc_html__('Unknown Messenger', 'event_espresso');
2216
+		// let's provide a helpful title for context
2217
+		$preview_title = sprintf(
2218
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
+			$active_messenger_label,
2220
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
+		);
2222
+		if (empty($preview)) {
2223
+			$this->noEventsErrorMessage();
2224
+		}
2225
+		// setup display of preview.
2226
+		$this->_admin_page_title                    = $preview_title;
2227
+		$this->_template_args['admin_page_title']   = $preview_title;
2228
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
+		$this->_template_args['data']['force_json'] = true;
2230
+
2231
+		return '';
2232
+	}
2233
+
2234
+
2235
+	/**
2236
+	 * Used to set an error if there are no events available for generating a preview/test send.
2237
+	 *
2238
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
+	 */
2240
+	protected function noEventsErrorMessage($test_send = false)
2241
+	{
2242
+		$events_url = parent::add_query_args_and_nonce(
2243
+			[
2244
+				'action' => 'default',
2245
+				'page'   => 'espresso_events',
2246
+			],
2247
+			admin_url('admin.php')
2248
+		);
2249
+		$message    = $test_send
2250
+			? esc_html__(
2251
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
+				'event_espresso'
2253
+			)
2254
+			: esc_html__(
2255
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
+				'event_espresso'
2257
+			);
2258
+
2259
+		EE_Error::add_attention(
2260
+			sprintf(
2261
+				$message,
2262
+				"<a href='{$events_url}'>",
2263
+				'</a>'
2264
+			)
2265
+		);
2266
+	}
2267
+
2268
+
2269
+	/**
2270
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
+	 * gets called automatically.
2272
+	 *
2273
+	 * @return void
2274
+	 * @throws EE_Error
2275
+	 * @since 4.5.0
2276
+	 *
2277
+	 */
2278
+	protected function _display_preview_message()
2279
+	{
2280
+		$this->display_admin_page_with_no_sidebar();
2281
+	}
2282
+
2283
+
2284
+	/**
2285
+	 * registers metaboxes that should show up on the "edit_message_template" page
2286
+	 *
2287
+	 * @access protected
2288
+	 * @return void
2289
+	 */
2290
+	protected function _register_edit_meta_boxes()
2291
+	{
2292
+		add_meta_box(
2293
+			'mtp_valid_shortcodes',
2294
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2295
+			[$this, 'shortcode_meta_box'],
2296
+			$this->_current_screen->id,
2297
+			'side'
2298
+		);
2299
+		add_meta_box(
2300
+			'mtp_extra_actions',
2301
+			esc_html__('Extra Actions', 'event_espresso'),
2302
+			[$this, 'extra_actions_meta_box'],
2303
+			$this->_current_screen->id,
2304
+			'side',
2305
+			'high'
2306
+		);
2307
+		add_meta_box(
2308
+			'mtp_templates',
2309
+			esc_html__('Template Styles', 'event_espresso'),
2310
+			[$this, 'template_pack_meta_box'],
2311
+			$this->_current_screen->id,
2312
+			'side',
2313
+			'high'
2314
+		);
2315
+	}
2316
+
2317
+
2318
+	/**
2319
+	 * metabox content for all template pack and variation selection.
2320
+	 *
2321
+	 * @return void
2322
+	 * @throws DomainException
2323
+	 * @throws EE_Error
2324
+	 * @throws InvalidArgumentException
2325
+	 * @throws ReflectionException
2326
+	 * @throws InvalidDataTypeException
2327
+	 * @throws InvalidInterfaceException
2328
+	 * @since 4.5.0
2329
+	 */
2330
+	public function template_pack_meta_box()
2331
+	{
2332
+		$this->_set_message_template_group();
2333
+
2334
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
+
2336
+		$tp_select_values = [];
2337
+
2338
+		foreach ($tp_collection as $tp) {
2339
+			// only include template packs that support this messenger and message type!
2340
+			$supports = $tp->get_supports();
2341
+			if (
2342
+				! isset($supports[ $this->_message_template_group->messenger() ])
2343
+				|| ! in_array(
2344
+					$this->_message_template_group->message_type(),
2345
+					$supports[ $this->_message_template_group->messenger() ],
2346
+					true
2347
+				)
2348
+			) {
2349
+				// not supported
2350
+				continue;
2351
+			}
2352
+
2353
+			$tp_select_values[] = [
2354
+				'text' => $tp->label,
2355
+				'id'   => $tp->dbref,
2356
+			];
2357
+		}
2358
+
2359
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
+		// the default template pack.  This still allows for the odd template pack to override.
2361
+		if (empty($tp_select_values)) {
2362
+			$tp_select_values[] = [
2363
+				'text' => esc_html__('Default', 'event_espresso'),
2364
+				'id'   => 'default',
2365
+			];
2366
+		}
2367
+
2368
+		// setup variation select values for the currently selected template.
2369
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
+			$this->_message_template_group->messenger(),
2371
+			$this->_message_template_group->message_type()
2372
+		);
2373
+		$variations_select_values = [];
2374
+		foreach ($variations as $variation => $label) {
2375
+			$variations_select_values[] = [
2376
+				'text' => $label,
2377
+				'id'   => $variation,
2378
+			];
2379
+		}
2380
+
2381
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
+
2383
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
+			'MTP_template_pack',
2385
+			$tp_select_values,
2386
+			$this->_message_template_group->get_template_pack_name()
2387
+		);
2388
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
+			'MTP_template_variation',
2390
+			$variations_select_values,
2391
+			$this->_message_template_group->get_template_pack_variation()
2392
+		);
2393
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
+
2398
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
+
2400
+		EEH_Template::display_template($template, $template_args);
2401
+	}
2402
+
2403
+
2404
+	/**
2405
+	 * This meta box holds any extra actions related to Message Templates
2406
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2407
+	 *
2408
+	 * @access  public
2409
+	 * @return void
2410
+	 * @throws EE_Error
2411
+	 */
2412
+	public function extra_actions_meta_box()
2413
+	{
2414
+		$template_form_fields = [];
2415
+
2416
+		$extra_args = [
2417
+			'msgr'   => $this->_message_template_group->messenger(),
2418
+			'mt'     => $this->_message_template_group->message_type(),
2419
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
+		];
2421
+		// first we need to see if there are any fields
2422
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
+
2424
+		if (! empty($fields)) {
2425
+			// yup there be fields
2426
+			foreach ($fields as $field => $config) {
2427
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
+				$default  = isset($config['default']) ? $config['default'] : '';
2430
+				$default  = isset($config['value']) ? $config['value'] : $default;
2431
+
2432
+				// if type is hidden and the value is empty
2433
+				// something may have gone wrong so let's correct with the defaults
2434
+				$fix                = $config['input'] === 'hidden'
2435
+									  && isset($existing[ $field ])
2436
+									  && empty($existing[ $field ])
2437
+					? $default
2438
+					: '';
2439
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
+					? $existing[ $field ]
2441
+					: $fix;
2442
+
2443
+				$template_form_fields[ $field_id ] = [
2444
+					'name'       => 'test_settings_fld[' . $field . ']',
2445
+					'label'      => $config['label'],
2446
+					'input'      => $config['input'],
2447
+					'type'       => $config['type'],
2448
+					'required'   => $config['required'],
2449
+					'validation' => $config['validation'],
2450
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
+					'css_class'  => $config['css_class'],
2452
+					'options'    => isset($config['options']) ? $config['options'] : [],
2453
+					'default'    => $default,
2454
+					'format'     => $config['format'],
2455
+				];
2456
+			}
2457
+		}
2458
+
2459
+		$test_settings_html = ! empty($template_form_fields)
2460
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
+			: '';
2462
+
2463
+		// print out $test_settings_fields
2464
+		if (! empty($test_settings_html)) {
2465
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
+			$test_settings_html .= 'name="test_button" value="';
2467
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2469
+		}
2470
+
2471
+		// and button
2472
+		$test_settings_html .= '<p>';
2473
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
+		$test_settings_html .= '</p>';
2475
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
+		$test_settings_html .= $this->get_action_link_or_button(
2477
+			'reset_to_default',
2478
+			'reset',
2479
+			$extra_args,
2480
+			'button-primary reset-default-button'
2481
+		);
2482
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2483
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
+	}
2485
+
2486
+
2487
+	/**
2488
+	 * This returns the shortcode selector skeleton for a given context and field.
2489
+	 *
2490
+	 * @param string $field           The name of the field retrieving shortcodes for.
2491
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
+	 * @return string
2493
+	 * @throws DomainException
2494
+	 * @throws EE_Error
2495
+	 * @throws InvalidArgumentException
2496
+	 * @throws ReflectionException
2497
+	 * @throws InvalidDataTypeException
2498
+	 * @throws InvalidInterfaceException
2499
+	 * @since 4.9.rc.000
2500
+	 */
2501
+	protected function _get_shortcode_selector($field, $linked_input_id)
2502
+	{
2503
+		$template_args = [
2504
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2505
+			'fieldname'       => $field,
2506
+			'linked_input_id' => $linked_input_id,
2507
+		];
2508
+
2509
+		return EEH_Template::display_template(
2510
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
+			$template_args,
2512
+			true
2513
+		);
2514
+	}
2515
+
2516
+
2517
+	/**
2518
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
+	 * page)
2520
+	 *
2521
+	 * @access public
2522
+	 * @return void
2523
+	 * @throws EE_Error
2524
+	 * @throws InvalidArgumentException
2525
+	 * @throws ReflectionException
2526
+	 * @throws InvalidDataTypeException
2527
+	 * @throws InvalidInterfaceException
2528
+	 */
2529
+	public function shortcode_meta_box()
2530
+	{
2531
+		$shortcodes = $this->_get_shortcodes([], false);
2532
+		// just make sure the shortcodes property is set
2533
+		// $messenger = $this->_message_template_group->messenger_obj();
2534
+		// now let's set the content depending on the status of the shortcodes array
2535
+		if (empty($shortcodes)) {
2536
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
+			return;
2538
+		}
2539
+		?>
2540 2540
         <div style="float:right; margin-top:10px">
2541 2541
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2542
-            ?>
2542
+			?>
2543 2543
         </div>
2544 2544
         <p class="small-text">
2545 2545
             <?php printf(
2546
-                esc_html__(
2547
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
-                    'event_espresso'
2549
-                ),
2550
-                '<span class="dashicons dashicons-menu"></span>'
2551
-            ); ?>
2546
+				esc_html__(
2547
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
+					'event_espresso'
2549
+				),
2550
+				'<span class="dashicons dashicons-menu"></span>'
2551
+			); ?>
2552 2552
         </p>
2553 2553
         <?php
2554
-    }
2555
-
2556
-
2557
-    /**
2558
-     * used to set the $_shortcodes property for when its needed elsewhere.
2559
-     *
2560
-     * @access protected
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     * @throws InvalidArgumentException
2564
-     * @throws ReflectionException
2565
-     * @throws InvalidDataTypeException
2566
-     * @throws InvalidInterfaceException
2567
-     */
2568
-    protected function _set_shortcodes()
2569
-    {
2570
-
2571
-        // no need to run this if the property is already set
2572
-        if (! empty($this->_shortcodes)) {
2573
-            return;
2574
-        }
2575
-
2576
-        $this->_shortcodes = $this->_get_shortcodes();
2577
-    }
2578
-
2579
-
2580
-    /**
2581
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
-     * property)
2583
-     *
2584
-     * @access  protected
2585
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
-     *                         for. Defaults to all (for the given context)
2587
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
-     *                         true just an array of shortcode/label pairs.
2590
-     * @throws EE_Error
2591
-     * @throws InvalidArgumentException
2592
-     * @throws ReflectionException
2593
-     * @throws InvalidDataTypeException
2594
-     * @throws InvalidInterfaceException
2595
-     */
2596
-    protected function _get_shortcodes($fields = [], $merged = true)
2597
-    {
2598
-        $this->_set_message_template_group();
2599
-
2600
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2601
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
-        if (empty($GRP_ID)) {
2603
-            return [];
2604
-        }
2605
-        $context = $this->request->getRequestParam(
2606
-            'messenger',
2607
-            key($this->_message_template_group->contexts_config())
2608
-        );
2609
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
-    }
2611
-
2612
-
2613
-    /**
2614
-     * This sets the _message_template property (containing the called message_template object)
2615
-     *
2616
-     * @access protected
2617
-     * @return void
2618
-     * @throws EE_Error
2619
-     * @throws InvalidArgumentException
2620
-     * @throws ReflectionException
2621
-     * @throws InvalidDataTypeException
2622
-     * @throws InvalidInterfaceException
2623
-     */
2624
-    protected function _set_message_template_group()
2625
-    {
2626
-        // get out if this is already set.
2627
-        if (! empty($this->_message_template_group)) {
2628
-            return;
2629
-        }
2630
-
2631
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
-
2634
-        // let's get the message templates
2635
-        $this->_message_template_group = ! empty($GRP_ID)
2636
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
-            : $this->getMtgModel()->create_default_object();
2638
-
2639
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2640
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * sets up a context switcher for edit forms
2646
-     *
2647
-     * @access  protected
2648
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
-     * @param array                     $args                  various things the context switcher needs.
2650
-     * @throws EE_Error
2651
-     */
2652
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
-    {
2654
-        $context_details = $template_group_object->contexts_config();
2655
-        $context_label   = $template_group_object->context_label();
2656
-        ob_start();
2657
-        ?>
2554
+	}
2555
+
2556
+
2557
+	/**
2558
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2559
+	 *
2560
+	 * @access protected
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 * @throws InvalidArgumentException
2564
+	 * @throws ReflectionException
2565
+	 * @throws InvalidDataTypeException
2566
+	 * @throws InvalidInterfaceException
2567
+	 */
2568
+	protected function _set_shortcodes()
2569
+	{
2570
+
2571
+		// no need to run this if the property is already set
2572
+		if (! empty($this->_shortcodes)) {
2573
+			return;
2574
+		}
2575
+
2576
+		$this->_shortcodes = $this->_get_shortcodes();
2577
+	}
2578
+
2579
+
2580
+	/**
2581
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
+	 * property)
2583
+	 *
2584
+	 * @access  protected
2585
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
+	 *                         for. Defaults to all (for the given context)
2587
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
+	 *                         true just an array of shortcode/label pairs.
2590
+	 * @throws EE_Error
2591
+	 * @throws InvalidArgumentException
2592
+	 * @throws ReflectionException
2593
+	 * @throws InvalidDataTypeException
2594
+	 * @throws InvalidInterfaceException
2595
+	 */
2596
+	protected function _get_shortcodes($fields = [], $merged = true)
2597
+	{
2598
+		$this->_set_message_template_group();
2599
+
2600
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2601
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
+		if (empty($GRP_ID)) {
2603
+			return [];
2604
+		}
2605
+		$context = $this->request->getRequestParam(
2606
+			'messenger',
2607
+			key($this->_message_template_group->contexts_config())
2608
+		);
2609
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
+	}
2611
+
2612
+
2613
+	/**
2614
+	 * This sets the _message_template property (containing the called message_template object)
2615
+	 *
2616
+	 * @access protected
2617
+	 * @return void
2618
+	 * @throws EE_Error
2619
+	 * @throws InvalidArgumentException
2620
+	 * @throws ReflectionException
2621
+	 * @throws InvalidDataTypeException
2622
+	 * @throws InvalidInterfaceException
2623
+	 */
2624
+	protected function _set_message_template_group()
2625
+	{
2626
+		// get out if this is already set.
2627
+		if (! empty($this->_message_template_group)) {
2628
+			return;
2629
+		}
2630
+
2631
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
+
2634
+		// let's get the message templates
2635
+		$this->_message_template_group = ! empty($GRP_ID)
2636
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
+			: $this->getMtgModel()->create_default_object();
2638
+
2639
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2640
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * sets up a context switcher for edit forms
2646
+	 *
2647
+	 * @access  protected
2648
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
+	 * @param array                     $args                  various things the context switcher needs.
2650
+	 * @throws EE_Error
2651
+	 */
2652
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
+	{
2654
+		$context_details = $template_group_object->contexts_config();
2655
+		$context_label   = $template_group_object->context_label();
2656
+		ob_start();
2657
+		?>
2658 2658
         <div class="ee-msg-switcher-container">
2659 2659
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2660 2660
                 <?php
2661
-                foreach ($args as $name => $value) {
2662
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2663
-                        continue;
2664
-                    }
2665
-                    ?>
2661
+				foreach ($args as $name => $value) {
2662
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2663
+						continue;
2664
+					}
2665
+					?>
2666 2666
                     <input type="hidden"
2667 2667
                            name="<?php echo esc_attr($name); ?>"
2668 2668
                            value="<?php echo esc_attr($value); ?>"
2669 2669
                     />
2670 2670
                     <?php
2671
-                }
2672
-                // setup nonce_url
2673
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
-                ?>
2671
+				}
2672
+				// setup nonce_url
2673
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
+				?>
2676 2676
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2677 2677
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2678 2678
                 </label>
2679 2679
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2680 2680
                     <?php
2681
-                    $context_templates = $template_group_object->context_templates();
2682
-                    if (is_array($context_templates)) :
2683
-                        foreach ($context_templates as $context => $template_fields) :
2684
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2685
-                            ?>
2681
+					$context_templates = $template_group_object->context_templates();
2682
+					if (is_array($context_templates)) :
2683
+						foreach ($context_templates as $context => $template_fields) :
2684
+							$checked = ($context === $args['context']) ? 'selected' : '';
2685
+							?>
2686 2686
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2687 2687
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690
-                    endif; ?>
2690
+					endif; ?>
2691 2691
                 </select>
2692 2692
                 <?php $button_text = sprintf(
2693
-                    esc_html__('Switch %s', 'event_espresso'),
2694
-                    ucwords($context_label['label'])
2695
-                ); ?>
2693
+					esc_html__('Switch %s', 'event_espresso'),
2694
+					ucwords($context_label['label'])
2695
+				); ?>
2696 2696
                 <input class='button-secondary'
2697 2697
                        id="submit-msg-context-switcher-sbmt"
2698 2698
                        type="submit"
@@ -2702,1994 +2702,1994 @@  discard block
 block discarded – undo
2702 2702
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2703 2703
         </div> <!-- end .ee-msg-switcher-container -->
2704 2704
         <?php
2705
-        $this->_context_switcher = ob_get_clean();
2706
-    }
2707
-
2708
-
2709
-    /**
2710
-     * @param bool $new
2711
-     * @throws EE_Error
2712
-     * @throws ReflectionException
2713
-     */
2714
-    protected function _insert_or_update_message_template($new = false)
2715
-    {
2716
-        $form_data    = $this->getMessageTemplateFormData();
2717
-        $GRP_ID       = $form_data['GRP_ID'];
2718
-        $messenger    = $form_data['MTP_messenger'];
2719
-        $message_type = $form_data['MTP_message_type'];
2720
-        $context      = $form_data['MTP_context'];
2721
-
2722
-        // if this is "new" then we need to generate the default contexts
2723
-        // for the selected messenger/message_type for user to edit.
2724
-        list($success, $query_args) = $new
2725
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
-
2728
-        $success     = $success ? 1 : 0;
2729
-        $action_desc = $new ? 'created' : 'updated';
2730
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
-
2733
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * retrieve and sanitize form data
2739
-     *
2740
-     * @return array
2741
-     * @since 4.10.29.p
2742
-     */
2743
-    protected function getMessageTemplateFormData()
2744
-    {
2745
-        return [
2746
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
-        ];
2756
-    }
2757
-
2758
-
2759
-    /**
2760
-     * @param int    $GRP_ID
2761
-     * @param string $messenger
2762
-     * @param string $message_type
2763
-     * @return array no return on AJAX requests
2764
-     * @throws EE_Error
2765
-     * @throws ReflectionException
2766
-     * @since 4.10.29.p
2767
-     */
2768
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
-    {
2770
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
-        $success       = ! empty($new_templates);
2772
-
2773
-        // we return things differently if doing ajax
2774
-        if ($this->request->isAjax()) {
2775
-            $this->_template_args['success'] = $success;
2776
-            $this->_template_args['error']   = ! $success;
2777
-            $this->_template_args['content'] = '';
2778
-            $this->_template_args['data']    = [
2779
-                'grpID'        => $new_templates['GRP_ID'],
2780
-                'templateName' => $new_templates['template_name'],
2781
-            ];
2782
-            if ($success) {
2783
-                EE_Error::overwrite_success();
2784
-                EE_Error::add_success(
2785
-                    esc_html__(
2786
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2787
-                        'event_espresso'
2788
-                    )
2789
-                );
2790
-            }
2791
-            $this->_return_json();
2792
-        }
2793
-        return [
2794
-            $success,
2795
-            // 'query_args'
2796
-            [
2797
-                'id'      => $new_templates['GRP_ID'],
2798
-                'context' => $new_templates['MTP_context'],
2799
-                'action'  => 'edit_message_template',
2800
-            ],
2801
-        ];
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * @param int    $GRP_ID
2807
-     * @param string $messenger
2808
-     * @param string $message_type
2809
-     * @param string $context
2810
-     * @param array  $form_data
2811
-     * @return array
2812
-     * @throws EE_Error
2813
-     * @since 4.10.29.p
2814
-     */
2815
-    private function updateExistingTemplates(
2816
-        $GRP_ID,
2817
-        $messenger,
2818
-        $message_type,
2819
-        $context,
2820
-        array $form_data
2821
-    ) {
2822
-        $success         = false;
2823
-        $template_fields = $this->getTemplateFields();
2824
-        if ($template_fields) {
2825
-            // if field data is valid, then success will be true
2826
-            $success = $this->validateTemplateFields(
2827
-                $messenger,
2828
-                $message_type,
2829
-                $context,
2830
-                $template_fields
2831
-            );
2832
-            if ($success) {
2833
-                $field_data = [];
2834
-                foreach ($template_fields as $template_field => $content) {
2835
-                    // combine top-level form data with content for this field
2836
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
-                }
2839
-                // we can use the last set_column_values for the MTPG update
2840
-                // (because its the same for all of these specific MTPs)
2841
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
-            }
2843
-        }
2844
-
2845
-        return [
2846
-            $success,
2847
-            // 'query_args'
2848
-            [
2849
-                'id'      => $GRP_ID,
2850
-                'context' => $context,
2851
-                'action'  => 'edit_message_template',
2852
-            ],
2853
-        ];
2854
-    }
2855
-
2856
-
2857
-    /**
2858
-     * @return array
2859
-     * @since 4.10.29.p
2860
-     */
2861
-    private function getTemplateFields()
2862
-    {
2863
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
-        if (empty($template_fields)) {
2865
-            EE_Error::add_error(
2866
-                esc_html__(
2867
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
-                    'event_espresso'
2869
-                ),
2870
-                __FILE__,
2871
-                __FUNCTION__,
2872
-                __LINE__
2873
-            );
2874
-            return null;
2875
-        }
2876
-        // messages content is expected to be escaped
2877
-        return EEH_Array::addSlashesRecursively($template_fields);
2878
-    }
2879
-
2880
-
2881
-    /**
2882
-     * @param string $messenger
2883
-     * @param string $message_type
2884
-     * @param string $context
2885
-     * @param array  $template_fields
2886
-     * @return bool
2887
-     * @throws EE_Error
2888
-     * @since   4.10.29.p
2889
-     */
2890
-    private function validateTemplateFields(
2891
-        $messenger,
2892
-        $message_type,
2893
-        $context,
2894
-        array $template_fields
2895
-    ) {
2896
-        // first validate all fields!
2897
-        // this filter allows client code to add its own validation to the template fields as well.
2898
-        // returning an empty array means everything passed validation.
2899
-        // errors in validation should be represented in an array with the following shape:
2900
-        // array(
2901
-        //   'fieldname' => array(
2902
-        //          'msg' => 'error message'
2903
-        //          'value' => 'value for field producing error'
2904
-        // )
2905
-        $custom_validation = (array) apply_filters(
2906
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
-            [],
2908
-            $template_fields,
2909
-            $context,
2910
-            $messenger,
2911
-            $message_type
2912
-        );
2913
-
2914
-        $system_validation = $this->getMtgModel()->validate(
2915
-            $template_fields,
2916
-            $context,
2917
-            $messenger,
2918
-            $message_type
2919
-        );
2920
-
2921
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
-        $validates         = array_merge($custom_validation, $system_validation);
2923
-
2924
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
-        //  WE need to make sure there is no actual error messages in validates.
2927
-        if (empty($validates)) {
2928
-            return true;
2929
-        }
2930
-
2931
-        // add the transient so when the form loads we know which fields to highlight
2932
-        $this->_add_transient('edit_message_template', $validates);
2933
-        // setup notices
2934
-        foreach ($validates as $error) {
2935
-            if (isset($error['msg'])) {
2936
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
-            }
2938
-        }
2939
-        return false;
2940
-    }
2941
-
2942
-
2943
-    /**
2944
-     * @param array $field_data
2945
-     * @param array $form_data
2946
-     * @return array
2947
-     * @since   4.10.29.p
2948
-     */
2949
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
-    {
2951
-        return $form_data + [
2952
-                'MTP_ID'             => $field_data['MTP_ID'],
2953
-                'MTP_template_field' => $field_data['name'],
2954
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2956
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
-                    : $field_data['content'],
2958
-            ];
2959
-    }
2960
-
2961
-
2962
-    /**
2963
-     * @param string $template_field
2964
-     * @param array  $form_data
2965
-     * @return bool
2966
-     * @throws EE_Error
2967
-     * @since 4.10.29.p
2968
-     */
2969
-    private function updateMessageTemplates($template_field, array $form_data)
2970
-    {
2971
-        $MTP_ID                  = $form_data['MTP_ID'];
2972
-        $message_template_fields = [
2973
-            'GRP_ID'             => $form_data['GRP_ID'],
2974
-            'MTP_template_field' => $form_data['MTP_template_field'],
2975
-            'MTP_context'        => $form_data['MTP_context'],
2976
-            'MTP_content'        => $form_data['MTP_content'],
2977
-        ];
2978
-
2979
-        $hasMtpID = ! empty($MTP_ID);
2980
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2981
-        // this has already been through the template field validator and sanitized, so it will be
2982
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
-        // message template field in a messenger/message type and existing users don't have the
2984
-        // default setup for it.
2985
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
-        $updated = $hasMtpID
2987
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
-            : $this->getMtpModel()->insert($message_template_fields);
2989
-
2990
-        $insert_failed = ! $hasMtpID && ! $updated;
2991
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
-        $update_failed = $hasMtpID && $updated === false;
2994
-
2995
-        if ($insert_failed || $update_failed) {
2996
-            EE_Error::add_error(
2997
-                sprintf(
2998
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
-                    $template_field
3000
-                ),
3001
-                __FILE__,
3002
-                __FUNCTION__,
3003
-                __LINE__
3004
-            );
3005
-            return false;
3006
-        }
3007
-        return true;
3008
-    }
3009
-
3010
-
3011
-    /**
3012
-     * @param array $form_data
3013
-     * @return bool
3014
-     * @throws EE_Error
3015
-     * @since 4.10.29.p
3016
-     */
3017
-    private function updateMessageTemplateGroup(array $form_data)
3018
-    {
3019
-        $GRP_ID  = $form_data['GRP_ID'];
3020
-        $updated = $this->getMtgModel()->update(
3021
-        // fields and values
3022
-            [
3023
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3024
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3025
-                'MTP_message_type' => $form_data['MTP_message_type'],
3026
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3027
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3028
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3029
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3030
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
-                'MTP_description'  => $this->request->getRequestParam(
3032
-                    'ee_msg_non_global_fields[MTP_description]',
3033
-                    ''
3034
-                ),
3035
-            ],
3036
-            // where
3037
-            [['GRP_ID' => $GRP_ID]]
3038
-        );
3039
-
3040
-        if ($updated === false) {
3041
-            EE_Error::add_error(
3042
-                sprintf(
3043
-                    esc_html__(
3044
-                        'The Message Template Group (%d) was NOT updated for some reason',
3045
-                        'event_espresso'
3046
-                    ),
3047
-                    $form_data['GRP_ID']
3048
-                ),
3049
-                __FILE__,
3050
-                __FUNCTION__,
3051
-                __LINE__
3052
-            );
3053
-            return false;
3054
-        }
3055
-        // k now we need to ensure the template_pack and template_variation fields are set.
3056
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
-
3059
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3061
-            $message_template_group->set_template_pack_name($template_pack);
3062
-            $message_template_group->set_template_pack_variation($template_variation);
3063
-        }
3064
-        return true;
3065
-    }
3066
-
3067
-
3068
-    /**
3069
-     * recursively runs wp_kses() on message template content in a model safe manner
3070
-     *
3071
-     * @param array|string $content
3072
-     * @return array|string
3073
-     * @since   4.10.29.p
3074
-     */
3075
-    private function sanitizeMessageTemplateContent($content)
3076
-    {
3077
-        if (is_array($content)) {
3078
-            foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
-            }
3081
-            return $content;
3082
-        }
3083
-        // remove slashes so wp_kses() works properly
3084
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3085
-        // so attributes using single quotes always appear invalid.
3086
-        $content = stripslashes($content);
3087
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3088
-        // But currently the models expect slashed data, so after wp_kses()
3089
-        // runs we need to re-slash the data. Sheesh.
3090
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
-        return addslashes($content);
3092
-    }
3093
-
3094
-
3095
-    /**
3096
-     * @param string $messenger
3097
-     * @param string $message_type
3098
-     * @param string $context
3099
-     * @return string
3100
-     * @since 4.10.29.p
3101
-     */
3102
-    private function generateUpdateDescription($messenger, $message_type, $context)
3103
-    {
3104
-        // need the message type and messenger objects to be able to use the labels for the notices
3105
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
-        $messenger_label  = $messenger_object instanceof EE_messenger
3107
-            ? ucwords($messenger_object->label['singular'])
3108
-            : '';
3109
-
3110
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
-        $message_type_label  = $message_type_object instanceof EE_message_type
3112
-            ? ucwords($message_type_object->label['singular'])
3113
-            : '';
3114
-
3115
-        $context   = ucwords(str_replace('_', ' ', $context));
3116
-        $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
-            : '';
3119
-        $item_desc .= 'Message Template';
3120
-        return $item_desc;
3121
-    }
3122
-
3123
-
3124
-    /**
3125
-     * @param string $messenger
3126
-     * @param string $message_type
3127
-     * @param string $context
3128
-     * @return bool
3129
-     * @throws EE_Error
3130
-     * @throws ReflectionException
3131
-     * @since 4.10.29.p
3132
-     */
3133
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
-    {
3135
-        // was a test send triggered?
3136
-        if ($this->request->requestParamIsSet('test_button')) {
3137
-            EE_Error::overwrite_success();
3138
-            $this->_do_test_send($context, $messenger, $message_type);
3139
-            return true;
3140
-        }
3141
-        return false;
3142
-    }
3143
-
3144
-
3145
-    /**
3146
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
-     *
3148
-     * @param string $context      what context being tested
3149
-     * @param string $messenger    messenger being tested
3150
-     * @param string $message_type message type being tested
3151
-     * @throws EE_Error
3152
-     * @throws InvalidArgumentException
3153
-     * @throws InvalidDataTypeException
3154
-     * @throws InvalidInterfaceException
3155
-     * @throws ReflectionException
3156
-     */
3157
-    protected function _do_test_send($context, $messenger, $message_type)
3158
-    {
3159
-        // set things up for preview
3160
-        $this->request->setRequestParam('messenger', $messenger);
3161
-        $this->request->setRequestParam('message_type', $message_type);
3162
-        $this->request->setRequestParam('context', $context);
3163
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
-
3166
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
-
3169
-        // let's save any existing fields that might be required by the messenger
3170
-        if (
3171
-            ! empty($test_settings_fld)
3172
-            && $active_messenger instanceof EE_messenger
3173
-            && apply_filters(
3174
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
-                true,
3176
-                $test_settings_fld,
3177
-                $active_messenger
3178
-            )
3179
-        ) {
3180
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3181
-        }
3182
-
3183
-        /**
3184
-         * Use filter to add additional controls on whether message can send or not
3185
-         */
3186
-        if (
3187
-            apply_filters(
3188
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
-                true,
3190
-                $context,
3191
-                $this->request->requestParams(),
3192
-                $messenger,
3193
-                $message_type
3194
-            )
3195
-        ) {
3196
-            if (EEM_Event::instance()->count() > 0) {
3197
-                $success = $this->_preview_message(true);
3198
-                if ($success) {
3199
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
-                } else {
3201
-                    EE_Error::add_error(
3202
-                        esc_html__('The test message was not sent', 'event_espresso'),
3203
-                        __FILE__,
3204
-                        __FUNCTION__,
3205
-                        __LINE__
3206
-                    );
3207
-                }
3208
-            } else {
3209
-                $this->noEventsErrorMessage(true);
3210
-            }
3211
-        }
3212
-    }
3213
-
3214
-
3215
-    /**
3216
-     * _generate_new_templates
3217
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
-     * for the event.
3220
-     *
3221
-     *
3222
-     * @param string $messenger      the messenger we are generating templates for
3223
-     * @param array  $message_types  array of message types that the templates are generated for.
3224
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
-     *                               indicate the message_template_group being used as the base.
3226
-     *
3227
-     * @param bool   $global
3228
-     *
3229
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
-     *                               encountering problems.
3231
-     * @throws EE_Error
3232
-     * @throws ReflectionException
3233
-     */
3234
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
-    {
3236
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
-        // just don't generate any templates.
3238
-        if (empty($message_types)) {
3239
-            return [];
3240
-        }
3241
-
3242
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
-        return $templates[0];
3244
-    }
3245
-
3246
-
3247
-    /**
3248
-     * [_trash_or_restore_message_template]
3249
-     *
3250
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
-     *                        an individual context (FALSE).
3253
-     * @return void
3254
-     * @throws EE_Error
3255
-     * @throws InvalidArgumentException
3256
-     * @throws InvalidDataTypeException
3257
-     * @throws InvalidInterfaceException
3258
-     */
3259
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
-    {
3261
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
-
3263
-        $success = 1;
3264
-
3265
-        // incoming GRP_IDs
3266
-        if ($all) {
3267
-            // Checkboxes
3268
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3270
-                // if array has more than one element then success message should be plural.
3271
-                // todo: what about nonce?
3272
-                $success = count($checkboxes) > 1 ? 2 : 1;
3273
-
3274
-                // cycle through checkboxes
3275
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3276
-                    $trashed_or_restored = $trash
3277
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3280
-                        $success = 0;
3281
-                    }
3282
-                }
3283
-            } else {
3284
-                // grab single GRP_ID and handle
3285
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3287
-                    $trashed_or_restored = $trash
3288
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3291
-                        $success = 0;
3292
-                    }
3293
-                } else {
3294
-                    $success = 0;
3295
-                }
3296
-            }
3297
-        }
3298
-
3299
-        $action_desc = $trash
3300
-            ? esc_html__('moved to the trash', 'event_espresso')
3301
-            : esc_html__('restored', 'event_espresso');
3302
-
3303
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
-
3306
-        $item_desc = $all ? _n(
3307
-            'Message Template Group',
3308
-            'Message Template Groups',
3309
-            $success,
3310
-            'event_espresso'
3311
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
-
3313
-        $item_desc = $template_switch
3314
-            ? _n('template', 'templates', $success, 'event_espresso')
3315
-            : $item_desc;
3316
-
3317
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
-    }
3319
-
3320
-
3321
-    /**
3322
-     * [_delete_message_template]
3323
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
-     *
3325
-     * @return void
3326
-     * @throws EE_Error
3327
-     * @throws InvalidArgumentException
3328
-     * @throws InvalidDataTypeException
3329
-     * @throws InvalidInterfaceException
3330
-     * @throws ReflectionException
3331
-     */
3332
-    protected function _delete_message_template()
3333
-    {
3334
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
-
3336
-        // checkboxes
3337
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3339
-            // if array has more than one element then success message should be plural
3340
-            $success = count($checkboxes) > 1 ? 2 : 1;
3341
-
3342
-            // cycle through bulk action checkboxes
3343
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3344
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
-            }
3346
-        } else {
3347
-            // grab single grp_id and delete
3348
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3350
-        }
3351
-
3352
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
-    }
3354
-
3355
-
3356
-    /**
3357
-     * helper for permanently deleting a mtP group and all related message_templates
3358
-     *
3359
-     * @param int  $GRP_ID        The group being deleted
3360
-     * @param bool $include_group whether to delete the Message Template Group as well.
3361
-     * @return bool boolean to indicate the success of the deletes or not.
3362
-     * @throws EE_Error
3363
-     * @throws InvalidArgumentException
3364
-     * @throws InvalidDataTypeException
3365
-     * @throws InvalidInterfaceException
3366
-     * @throws ReflectionException
3367
-     * @throws ReflectionException
3368
-     */
3369
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
-    {
3371
-        $success = true;
3372
-        // first let's GET this group
3373
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
-        // then delete permanently all the related Message Templates
3375
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3376
-
3377
-        if ($deleted === 0) {
3378
-            $success = false;
3379
-        }
3380
-
3381
-        // now delete permanently this particular group
3382
-
3383
-        if ($include_group && ! $MTG->delete_permanently()) {
3384
-            $success = false;
3385
-        }
3386
-
3387
-        return $success;
3388
-    }
3389
-
3390
-
3391
-    /**
3392
-     *    _learn_more_about_message_templates_link
3393
-     *
3394
-     * @access protected
3395
-     * @return string
3396
-     */
3397
-    protected function _learn_more_about_message_templates_link()
3398
-    {
3399
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3401
-               . '</a>';
3402
-    }
3403
-
3404
-
3405
-    /**
3406
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
-     * ajax and other routes.
3408
-     *
3409
-     * @return void
3410
-     * @throws DomainException
3411
-     * @throws EE_Error
3412
-     */
3413
-    protected function _settings()
3414
-    {
3415
-        $this->_set_m_mt_settings();
3416
-
3417
-        // let's setup the messenger tabs
3418
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
-            $this->_m_mt_settings['messenger_tabs'],
3420
-            'messenger_links',
3421
-            '|',
3422
-            $this->request->getRequestParam('selected_messenger', 'email')
3423
-        );
3424
-
3425
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
-
3428
-        $this->display_admin_page_with_sidebar();
3429
-    }
3430
-
3431
-
3432
-    /**
3433
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
-     *
3435
-     * @access protected
3436
-     * @return void
3437
-     * @throws DomainException
3438
-     */
3439
-    protected function _set_m_mt_settings()
3440
-    {
3441
-        // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3443
-            return;
3444
-        }
3445
-
3446
-        // get all installed messengers and message_types
3447
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3448
-        $message_types = $this->_message_resource_manager->installed_message_types();
3449
-
3450
-
3451
-        // assemble the array for the _tab_text_links helper
3452
-
3453
-        foreach ($messengers as $messenger) {
3454
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
-                'label' => ucwords($messenger->label['singular']),
3456
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
-                    ? 'messenger-active'
3458
-                    : '',
3459
-                'href'  => $messenger->name,
3460
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
-                'slug'  => $messenger->name,
3462
-                'obj'   => $messenger,
3463
-            ];
3464
-
3465
-
3466
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3467
-
3468
-            foreach ($message_types as $message_type) {
3469
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
-                // it shouldn't show in either the inactive OR active metabox.
3471
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
-                    continue;
3473
-                }
3474
-
3475
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
-                    $messenger->name,
3477
-                    $message_type->name
3478
-                )
3479
-                    ? 'active'
3480
-                    : 'inactive';
3481
-
3482
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
-                    'label'    => ucwords($message_type->label['singular']),
3484
-                    'class'    => 'message-type-' . $a_or_i,
3485
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
-                    'title'    => $a_or_i === 'active'
3489
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
-                    'content'  => $a_or_i === 'active'
3492
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3493
-                        : $this->_message_type_settings_content($message_type, $messenger),
3494
-                    'slug'     => $message_type->name,
3495
-                    'active'   => $a_or_i === 'active',
3496
-                    'obj'      => $message_type,
3497
-                ];
3498
-            }
3499
-        }
3500
-    }
3501
-
3502
-
3503
-    /**
3504
-     * This just prepares the content for the message type settings
3505
-     *
3506
-     * @param EE_message_type $message_type The message type object
3507
-     * @param EE_messenger    $messenger    The messenger object
3508
-     * @param boolean         $active       Whether the message type is active or not
3509
-     * @return string html output for the content
3510
-     * @throws DomainException
3511
-     */
3512
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
-    {
3514
-        // get message type fields
3515
-        $fields                                         = $message_type->get_admin_settings_fields();
3516
-        $settings_template_args['template_form_fields'] = '';
3517
-
3518
-        if (! empty($fields) && $active) {
3519
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
-            foreach ($fields as $fldname => $fldprops) {
3521
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
-                $template_form_field[ $field_id ] = [
3523
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3524
-                    'label'      => $fldprops['label'],
3525
-                    'input'      => $fldprops['field_type'],
3526
-                    'type'       => $fldprops['value_type'],
3527
-                    'required'   => $fldprops['required'],
3528
-                    'validation' => $fldprops['validation'],
3529
-                    'value'      => isset($existing_settings[ $fldname ])
3530
-                        ? $existing_settings[ $fldname ]
3531
-                        : $fldprops['default'],
3532
-                    'options'    => isset($fldprops['options'])
3533
-                        ? $fldprops['options']
3534
-                        : [],
3535
-                    'default'    => isset($existing_settings[ $fldname ])
3536
-                        ? $existing_settings[ $fldname ]
3537
-                        : $fldprops['default'],
3538
-                    'css_class'  => 'no-drag',
3539
-                    'format'     => $fldprops['format'],
3540
-                ];
3541
-            }
3542
-
3543
-
3544
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
-                ? $this->_generate_admin_form_fields(
3546
-                    $template_form_field,
3547
-                    'string',
3548
-                    'ee_mt_activate_form'
3549
-                )
3550
-                : '';
3551
-        }
3552
-
3553
-        $settings_template_args['description'] = $message_type->description;
3554
-        // we also need some hidden fields
3555
-        $hidden_fields = [
3556
-            'message_type_settings[messenger]' . $message_type->name    => [
3557
-                'type'  => 'hidden',
3558
-                'value' => $messenger->name,
3559
-            ],
3560
-            'message_type_settings[message_type]' . $message_type->name => [
3561
-                'type'  => 'hidden',
3562
-                'value' => $message_type->name,
3563
-            ],
3564
-            'type' . $message_type->name                                => [
3565
-                'type'  => 'hidden',
3566
-                'value' => 'message_type',
3567
-            ],
3568
-        ];
3569
-
3570
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
-            $hidden_fields,
3572
-            'array'
3573
-        );
3574
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
-            ? ' hidden'
3576
-            : '';
3577
-
3578
-
3579
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
-        return EEH_Template::display_template($template, $settings_template_args, true);
3581
-    }
3582
-
3583
-
3584
-    /**
3585
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
-     *
3587
-     * @access protected
3588
-     * @return void
3589
-     * @throws DomainException
3590
-     */
3591
-    protected function _messages_settings_metaboxes()
3592
-    {
3593
-        $this->_set_m_mt_settings();
3594
-        $m_boxes         = $mt_boxes = [];
3595
-        $m_template_args = $mt_template_args = [];
3596
-
3597
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
-
3599
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
-
3605
-                // messenger meta boxes
3606
-                $active         = $selected_messenger === $messenger;
3607
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
-                    : '';
3610
-
3611
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
-                    esc_html__('%s Settings', 'event_espresso'),
3613
-                    $tab_array['label']
3614
-                );
3615
-
3616
-                $m_template_args[ $messenger . '_a_box' ] = [
3617
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
-                    'inactive_message_types' => isset(
3619
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
-                    )
3621
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
-                        : '',
3623
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
-                    'hidden'                 => $active ? '' : ' hidden',
3625
-                    'hide_on_message'        => $hide_on_message,
3626
-                    'messenger'              => $messenger,
3627
-                    'active'                 => $active,
3628
-                ];
3629
-
3630
-                // message type meta boxes
3631
-                // (which is really just the inactive container for each messenger
3632
-                // showing inactive message types for that messenger)
3633
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
-                $mt_template_args[ $messenger . '_i_box' ] = [
3635
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
-                    'inactive_message_types' => isset(
3637
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
-                    )
3639
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
-                        : '',
3641
-                    'hidden'                 => $active ? '' : ' hidden',
3642
-                    'hide_on_message'        => $hide_on_message,
3643
-                    'hide_off_message'       => $hide_off_message,
3644
-                    'messenger'              => $messenger,
3645
-                    'active'                 => $active,
3646
-                ];
3647
-            }
3648
-        }
3649
-
3650
-
3651
-        // register messenger metaboxes
3652
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
-        foreach ($m_boxes as $box => $label) {
3654
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
-            $msgr          = str_replace('_a_box', '', $box);
3656
-            add_meta_box(
3657
-                'espresso_' . $msgr . '_settings',
3658
-                $label,
3659
-                function ($post, $metabox) {
3660
-                    EEH_Template::display_template(
3661
-                        $metabox['args']['template_path'],
3662
-                        $metabox['args']['template_args']
3663
-                    );
3664
-                },
3665
-                $this->_current_screen->id,
3666
-                'normal',
3667
-                'high',
3668
-                $callback_args
3669
-            );
3670
-        }
3671
-
3672
-        // register message type metaboxes
3673
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
-        foreach ($mt_boxes as $box => $label) {
3675
-            $callback_args = [
3676
-                'template_path' => $mt_template_path,
3677
-                'template_args' => $mt_template_args[ $box ],
3678
-            ];
3679
-            $mt            = str_replace('_i_box', '', $box);
3680
-            add_meta_box(
3681
-                'espresso_' . $mt . '_inactive_mts',
3682
-                $label,
3683
-                function ($post, $metabox) {
3684
-                    EEH_Template::display_template(
3685
-                        $metabox['args']['template_path'],
3686
-                        $metabox['args']['template_args']
3687
-                    );
3688
-                },
3689
-                $this->_current_screen->id,
3690
-                'side',
3691
-                'high',
3692
-                $callback_args
3693
-            );
3694
-        }
3695
-
3696
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3697
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
-        if (is_main_site()) {
3699
-            add_meta_box(
3700
-                'espresso_global_message_settings',
3701
-                esc_html__('Global Message Settings', 'event_espresso'),
3702
-                [$this, 'global_messages_settings_metabox_content'],
3703
-                $this->_current_screen->id,
3704
-                'normal',
3705
-                'low',
3706
-                []
3707
-            );
3708
-        }
3709
-    }
3710
-
3711
-
3712
-    /**
3713
-     *  This generates the content for the global messages settings metabox.
3714
-     *
3715
-     * @return void
3716
-     * @throws EE_Error
3717
-     * @throws InvalidArgumentException
3718
-     * @throws ReflectionException
3719
-     * @throws InvalidDataTypeException
3720
-     * @throws InvalidInterfaceException
3721
-     */
3722
-    public function global_messages_settings_metabox_content()
3723
-    {
3724
-        $form = $this->_generate_global_settings_form();
3725
-        echo wp_kses(
3726
-            $form->form_open(
3727
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
-                'POST'
3729
-            ),
3730
-            AllowedTags::getWithFormTags()
3731
-        );
3732
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
-    }
3735
-
3736
-
3737
-    /**
3738
-     * This generates and returns the form object for the global messages settings.
3739
-     *
3740
-     * @return EE_Form_Section_Proper
3741
-     * @throws EE_Error
3742
-     * @throws InvalidArgumentException
3743
-     * @throws ReflectionException
3744
-     * @throws InvalidDataTypeException
3745
-     * @throws InvalidInterfaceException
3746
-     */
3747
-    protected function _generate_global_settings_form()
3748
-    {
3749
-        /** @var EE_Network_Core_Config $network_config */
3750
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3751
-
3752
-        return new EE_Form_Section_Proper(
3753
-            [
3754
-                'name'            => 'global_messages_settings',
3755
-                'html_id'         => 'global_messages_settings',
3756
-                'html_class'      => 'form-table',
3757
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
-                'subsections'     => apply_filters(
3759
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
-                    [
3761
-                        'do_messages_on_same_request' => new EE_Select_Input(
3762
-                            [
3763
-                                true  => esc_html__('On the same request', 'event_espresso'),
3764
-                                false => esc_html__('On a separate request', 'event_espresso'),
3765
-                            ],
3766
-                            [
3767
-                                'default'         => $network_config->do_messages_on_same_request,
3768
-                                'html_label_text' => esc_html__(
3769
-                                    'Generate and send all messages:',
3770
-                                    'event_espresso'
3771
-                                ),
3772
-                                'html_help_text'  => esc_html__(
3773
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3774
-                                    'event_espresso'
3775
-                                ),
3776
-                            ]
3777
-                        ),
3778
-                        'delete_threshold'            => new EE_Select_Input(
3779
-                            [
3780
-                                0  => esc_html__('Forever', 'event_espresso'),
3781
-                                3  => esc_html__('3 Months', 'event_espresso'),
3782
-                                6  => esc_html__('6 Months', 'event_espresso'),
3783
-                                9  => esc_html__('9 Months', 'event_espresso'),
3784
-                                12 => esc_html__('12 Months', 'event_espresso'),
3785
-                                24 => esc_html__('24 Months', 'event_espresso'),
3786
-                                36 => esc_html__('36 Months', 'event_espresso'),
3787
-                            ],
3788
-                            [
3789
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
-                                'html_help_text'  => esc_html__(
3792
-                                    'You can control how long a record of processed messages is kept via this option.',
3793
-                                    'event_espresso'
3794
-                                ),
3795
-                            ]
3796
-                        ),
3797
-                        'update_settings'             => new EE_Submit_Input(
3798
-                            [
3799
-                                'default'         => esc_html__('Update', 'event_espresso'),
3800
-                                'html_label_text' => '',
3801
-                            ]
3802
-                        ),
3803
-                    ]
3804
-                ),
3805
-            ]
3806
-        );
3807
-    }
3808
-
3809
-
3810
-    /**
3811
-     * This handles updating the global settings set on the admin page.
3812
-     *
3813
-     * @throws EE_Error
3814
-     * @throws InvalidDataTypeException
3815
-     * @throws InvalidInterfaceException
3816
-     * @throws InvalidArgumentException
3817
-     * @throws ReflectionException
3818
-     */
3819
-    protected function _update_global_settings()
3820
-    {
3821
-        /** @var EE_Network_Core_Config $network_config */
3822
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3823
-        $messages_config = EE_Registry::instance()->CFG->messages;
3824
-        $form            = $this->_generate_global_settings_form();
3825
-        if ($form->was_submitted()) {
3826
-            $form->receive_form_submission();
3827
-            if ($form->is_valid()) {
3828
-                $valid_data = $form->valid_data();
3829
-                foreach ($valid_data as $property => $value) {
3830
-                    $setter = 'set_' . $property;
3831
-                    if (method_exists($network_config, $setter)) {
3832
-                        $network_config->{$setter}($value);
3833
-                    } elseif (
3834
-                        property_exists($network_config, $property)
3835
-                        && $network_config->{$property} !== $value
3836
-                    ) {
3837
-                        $network_config->{$property} = $value;
3838
-                    } elseif (
3839
-                        property_exists($messages_config, $property)
3840
-                        && $messages_config->{$property} !== $value
3841
-                    ) {
3842
-                        $messages_config->{$property} = $value;
3843
-                    }
3844
-                }
3845
-                // only update if the form submission was valid!
3846
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
-                EE_Registry::instance()->CFG->update_espresso_config();
3848
-                EE_Error::overwrite_success();
3849
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
-            }
3851
-        }
3852
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
-    }
3854
-
3855
-
3856
-    /**
3857
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
-     *
3859
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
-     * @return string html formatted tabs
3861
-     * @throws DomainException
3862
-     */
3863
-    protected function _get_mt_tabs($tab_array)
3864
-    {
3865
-        $tab_array = (array) $tab_array;
3866
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
-        $tabs      = '';
3868
-
3869
-        foreach ($tab_array as $tab) {
3870
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3871
-        }
3872
-
3873
-        return $tabs;
3874
-    }
3875
-
3876
-
3877
-    /**
3878
-     * This prepares the content of the messenger meta box admin settings
3879
-     *
3880
-     * @param EE_messenger $messenger The messenger we're setting up content for
3881
-     * @return string html formatted content
3882
-     * @throws DomainException
3883
-     */
3884
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3885
-    {
3886
-
3887
-        $fields                                         = $messenger->get_admin_settings_fields();
3888
-        $settings_template_args['template_form_fields'] = '';
3889
-
3890
-        // is $messenger active?
3891
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
-
3893
-
3894
-        if (! empty($fields)) {
3895
-            $existing_settings = $messenger->get_existing_admin_settings();
3896
-
3897
-            foreach ($fields as $fldname => $fldprops) {
3898
-                $field_id                         = $messenger->name . '-' . $fldname;
3899
-                $template_form_field[ $field_id ] = [
3900
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3901
-                    'label'      => $fldprops['label'],
3902
-                    'input'      => $fldprops['field_type'],
3903
-                    'type'       => $fldprops['value_type'],
3904
-                    'required'   => $fldprops['required'],
3905
-                    'validation' => $fldprops['validation'],
3906
-                    'value'      => isset($existing_settings[ $field_id ])
3907
-                        ? $existing_settings[ $field_id ]
3908
-                        : $fldprops['default'],
3909
-                    'css_class'  => '',
3910
-                    'format'     => $fldprops['format'],
3911
-                ];
3912
-            }
3913
-
3914
-
3915
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
-                : '';
3918
-        }
3919
-
3920
-        // we also need some hidden fields
3921
-        $settings_template_args['hidden_fields'] = [
3922
-            'messenger_settings[messenger]' . $messenger->name => [
3923
-                'type'  => 'hidden',
3924
-                'value' => $messenger->name,
3925
-            ],
3926
-            'type' . $messenger->name                          => [
3927
-                'type'  => 'hidden',
3928
-                'value' => 'messenger',
3929
-            ],
3930
-        ];
3931
-
3932
-        // make sure any active message types that are existing are included in the hidden fields
3933
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
-                    'type'  => 'hidden',
3937
-                    'value' => $mt,
3938
-                ];
3939
-            }
3940
-        }
3941
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
-            $settings_template_args['hidden_fields'],
3943
-            'array'
3944
-        );
3945
-        $active                                  =
3946
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3947
-
3948
-        $settings_template_args['messenger']           = $messenger->name;
3949
-        $settings_template_args['description']         = $messenger->description;
3950
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
-
3952
-
3953
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
-            $messenger->name
3955
-        )
3956
-            ? $settings_template_args['show_hide_edit_form']
3957
-            : ' hidden';
3958
-
3959
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
-            ? ' hidden'
3961
-            : $settings_template_args['show_hide_edit_form'];
3962
-
3963
-
3964
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
-        $settings_template_args['on_off_status'] = $active;
3967
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
-        return EEH_Template::display_template(
3969
-            $template,
3970
-            $settings_template_args,
3971
-            true
3972
-        );
3973
-    }
3974
-
3975
-
3976
-    /**
3977
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3978
-     *
3979
-     * @throws DomainException
3980
-     * @throws EE_Error
3981
-     * @throws InvalidDataTypeException
3982
-     * @throws InvalidInterfaceException
3983
-     * @throws InvalidArgumentException
3984
-     * @throws ReflectionException
3985
-     */
3986
-    public function activate_messenger_toggle()
3987
-    {
3988
-        $success = true;
3989
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
-        // let's check that we have required data
3991
-
3992
-        if (! $this->_active_messenger_name) {
3993
-            EE_Error::add_error(
3994
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
-                __FILE__,
3996
-                __FUNCTION__,
3997
-                __LINE__
3998
-            );
3999
-            $success = false;
4000
-        }
4001
-
4002
-        // do a nonce check here since we're not arriving via a normal route
4003
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
-
4006
-        $this->_verify_nonce($nonce, $nonce_ref);
4007
-
4008
-
4009
-        $status = $this->request->getRequestParam('status');
4010
-        if (! $status) {
4011
-            EE_Error::add_error(
4012
-                esc_html__(
4013
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
-                    'event_espresso'
4015
-                ),
4016
-                __FILE__,
4017
-                __FUNCTION__,
4018
-                __LINE__
4019
-            );
4020
-            $success = false;
4021
-        }
4022
-
4023
-        // do check to verify we have a valid status.
4024
-        if ($status !== 'off' && $status !== 'on') {
4025
-            EE_Error::add_error(
4026
-                sprintf(
4027
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
-                    $status
4029
-                ),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4034
-            $success = false;
4035
-        }
4036
-
4037
-        if ($success) {
4038
-            // made it here?  Stop dawdling then!!
4039
-            $success = $status === 'off'
4040
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4041
-                : $this->_activate_messenger($this->_active_messenger_name);
4042
-        }
4043
-
4044
-        $this->_template_args['success'] = $success;
4045
-
4046
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
-        $this->_return_json();
4048
-    }
4049
-
4050
-
4051
-    /**
4052
-     * used by ajax from the messages settings page to activate|deactivate a message type
4053
-     *
4054
-     * @throws DomainException
4055
-     * @throws EE_Error
4056
-     * @throws ReflectionException
4057
-     * @throws InvalidDataTypeException
4058
-     * @throws InvalidInterfaceException
4059
-     * @throws InvalidArgumentException
4060
-     */
4061
-    public function activate_mt_toggle()
4062
-    {
4063
-        $success = true;
4064
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
-
4066
-        // let's make sure we have the necessary data
4067
-        if (! $this->_active_message_type_name) {
4068
-            EE_Error::add_error(
4069
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
-                __FILE__,
4071
-                __FUNCTION__,
4072
-                __LINE__
4073
-            );
4074
-            $success = false;
4075
-        }
4076
-
4077
-        if (! $this->_active_messenger_name) {
4078
-            EE_Error::add_error(
4079
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
-                __FILE__,
4081
-                __FUNCTION__,
4082
-                __LINE__
4083
-            );
4084
-            $success = false;
4085
-        }
4086
-
4087
-        $status = $this->request->getRequestParam('status');
4088
-        if (! $status) {
4089
-            EE_Error::add_error(
4090
-                esc_html__(
4091
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
-                    'event_espresso'
4093
-                ),
4094
-                __FILE__,
4095
-                __FUNCTION__,
4096
-                __LINE__
4097
-            );
4098
-            $success = false;
4099
-        }
4100
-
4101
-
4102
-        // do check to verify we have a valid status.
4103
-        if ($status !== 'activate' && $status !== 'deactivate') {
4104
-            EE_Error::add_error(
4105
-                sprintf(
4106
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
-                    $status
4108
-                ),
4109
-                __FILE__,
4110
-                __FUNCTION__,
4111
-                __LINE__
4112
-            );
4113
-            $success = false;
4114
-        }
4115
-
4116
-
4117
-        // do a nonce check here since we're not arriving via a normal route
4118
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4119
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
-
4121
-        if ($success) {
4122
-            // made it here? um, what are you waiting for then?
4123
-            $success = $status === 'deactivate'
4124
-                ? $this->_deactivate_message_type_for_messenger(
4125
-                    $this->_active_messenger_name,
4126
-                    $this->_active_message_type_name
4127
-                )
4128
-                : $this->_activate_message_type_for_messenger(
4129
-                    $this->_active_messenger_name,
4130
-                    $this->_active_message_type_name
4131
-                );
4132
-        }
4133
-
4134
-        $this->_template_args['success'] = $success;
4135
-        $this->_return_json();
4136
-    }
4137
-
4138
-
4139
-    /**
4140
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4141
-     *
4142
-     * @param string $messenger_name The name of the messenger being activated
4143
-     * @return bool
4144
-     * @throws DomainException
4145
-     * @throws EE_Error
4146
-     * @throws InvalidArgumentException
4147
-     * @throws ReflectionException
4148
-     * @throws InvalidDataTypeException
4149
-     * @throws InvalidInterfaceException
4150
-     */
4151
-    protected function _activate_messenger($messenger_name)
4152
-    {
4153
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
-            ? $active_messenger->get_default_message_types()
4156
-            : [];
4157
-
4158
-        // ensure is active
4159
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
-
4161
-        // set response_data for reload
4162
-        foreach ($message_types_to_activate as $message_type_name) {
4163
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
-            if (
4165
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4166
-                    $messenger_name,
4167
-                    $message_type_name
4168
-                )
4169
-                && $message_type instanceof EE_message_type
4170
-            ) {
4171
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4172
-                if ($message_type->get_admin_settings_fields()) {
4173
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
-                }
4175
-            }
4176
-        }
4177
-
4178
-        // add success message for activating messenger
4179
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
-    }
4181
-
4182
-
4183
-    /**
4184
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
-     *
4186
-     * @param string $messenger_name The name of the messenger being activated
4187
-     * @return bool
4188
-     * @throws DomainException
4189
-     * @throws EE_Error
4190
-     * @throws InvalidArgumentException
4191
-     * @throws ReflectionException
4192
-     * @throws InvalidDataTypeException
4193
-     * @throws InvalidInterfaceException
4194
-     */
4195
-    protected function _deactivate_messenger($messenger_name)
4196
-    {
4197
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
-
4200
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
-    }
4202
-
4203
-
4204
-    /**
4205
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
-     *
4207
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
-     * @param string $message_type_name The name of the message type being activated for the messenger
4209
-     * @return bool
4210
-     * @throws DomainException
4211
-     * @throws EE_Error
4212
-     * @throws InvalidArgumentException
4213
-     * @throws ReflectionException
4214
-     * @throws InvalidDataTypeException
4215
-     * @throws InvalidInterfaceException
4216
-     */
4217
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
-    {
4219
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
-
4222
-        // ensure is active
4223
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
-
4225
-        // set response for load
4226
-        if (
4227
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4228
-                $messenger_name,
4229
-                $message_type_name
4230
-            )
4231
-        ) {
4232
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4233
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4234
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
-            }
4236
-        }
4237
-
4238
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
-            $active_messenger,
4240
-            $message_type_to_activate
4241
-        );
4242
-    }
4243
-
4244
-
4245
-    /**
4246
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
-     *
4248
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
-     * @return bool
4251
-     * @throws DomainException
4252
-     * @throws EE_Error
4253
-     * @throws InvalidArgumentException
4254
-     * @throws ReflectionException
4255
-     * @throws InvalidDataTypeException
4256
-     * @throws InvalidInterfaceException
4257
-     */
4258
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
-    {
4260
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
-
4265
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
-            $active_messenger,
4267
-            $message_type_to_deactivate
4268
-        );
4269
-    }
4270
-
4271
-
4272
-    /**
4273
-     * This just initializes the defaults for activating messenger and message type responses.
4274
-     */
4275
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
-    {
4277
-        $this->_template_args['data']['active_mts'] = [];
4278
-        $this->_template_args['data']['mt_reload']  = [];
4279
-    }
4280
-
4281
-
4282
-    /**
4283
-     * Setup appropriate response for activating a messenger and/or message types
4284
-     *
4285
-     * @param EE_messenger         $messenger
4286
-     * @param EE_message_type|null $message_type
4287
-     * @return bool
4288
-     * @throws DomainException
4289
-     * @throws EE_Error
4290
-     * @throws InvalidArgumentException
4291
-     * @throws ReflectionException
4292
-     * @throws InvalidDataTypeException
4293
-     * @throws InvalidInterfaceException
4294
-     */
4295
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
-        $messenger,
4297
-        EE_Message_Type $message_type = null
4298
-    ) {
4299
-        // if $messenger isn't a valid messenger object then get out.
4300
-        if (! $messenger instanceof EE_Messenger) {
4301
-            EE_Error::add_error(
4302
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
-                __FILE__,
4304
-                __FUNCTION__,
4305
-                __LINE__
4306
-            );
4307
-            return false;
4308
-        }
4309
-        // activated
4310
-        if ($this->_template_args['data']['active_mts']) {
4311
-            EE_Error::overwrite_success();
4312
-            // activated a message type with the messenger
4313
-            if ($message_type instanceof EE_message_type) {
4314
-                EE_Error::add_success(
4315
-                    sprintf(
4316
-                        esc_html__(
4317
-                            '%s message type has been successfully activated with the %s messenger',
4318
-                            'event_espresso'
4319
-                        ),
4320
-                        ucwords($message_type->label['singular']),
4321
-                        ucwords($messenger->label['singular'])
4322
-                    )
4323
-                );
4324
-
4325
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4326
-                if ($message_type->name === 'invoice') {
4327
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
-                    if ($pm instanceof EE_Payment_Method) {
4330
-                        EE_Error::add_attention(
4331
-                            esc_html__(
4332
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4333
-                                'event_espresso'
4334
-                            )
4335
-                        );
4336
-                    }
4337
-                }
4338
-                // just toggles the entire messenger
4339
-            } else {
4340
-                EE_Error::add_success(
4341
-                    sprintf(
4342
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
-                        ucwords($messenger->label['singular'])
4344
-                    )
4345
-                );
4346
-            }
4347
-
4348
-            return true;
4349
-
4350
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
-            // in which case we just give a success message for the messenger being successfully activated.
4353
-        } else {
4354
-            if (! $messenger->get_default_message_types()) {
4355
-                // messenger doesn't have any default message types so still a success.
4356
-                EE_Error::add_success(
4357
-                    sprintf(
4358
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
-                        ucwords($messenger->label['singular'])
4360
-                    )
4361
-                );
4362
-
4363
-                return true;
4364
-            } else {
4365
-                EE_Error::add_error(
4366
-                    $message_type instanceof EE_message_type
4367
-                    ? sprintf(
4368
-                        esc_html__(
4369
-                            '%s message type was not successfully activated with the %s messenger',
4370
-                            'event_espresso'
4371
-                        ),
4372
-                        ucwords($message_type->label['singular']),
4373
-                        ucwords($messenger->label['singular'])
4374
-                    )
4375
-                    : sprintf(
4376
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
-                        ucwords($messenger->label['singular'])
4378
-                    ),
4379
-                    __FILE__,
4380
-                    __FUNCTION__,
4381
-                    __LINE__
4382
-                );
4383
-
4384
-                return false;
4385
-            }
4386
-        }
4387
-    }
4388
-
4389
-
4390
-    /**
4391
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
-     *
4393
-     * @param EE_messenger         $messenger
4394
-     * @param EE_message_type|null $message_type
4395
-     * @return bool
4396
-     * @throws DomainException
4397
-     * @throws EE_Error
4398
-     * @throws InvalidArgumentException
4399
-     * @throws ReflectionException
4400
-     * @throws InvalidDataTypeException
4401
-     * @throws InvalidInterfaceException
4402
-     */
4403
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
-        $messenger,
4405
-        EE_message_type $message_type = null
4406
-    ) {
4407
-        EE_Error::overwrite_success();
4408
-
4409
-        // if $messenger isn't a valid messenger object then get out.
4410
-        if (! $messenger instanceof EE_Messenger) {
4411
-            EE_Error::add_error(
4412
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
-                __FILE__,
4414
-                __FUNCTION__,
4415
-                __LINE__
4416
-            );
4417
-
4418
-            return false;
4419
-        }
4420
-
4421
-        if ($message_type instanceof EE_message_type) {
4422
-            $message_type_name = $message_type->name;
4423
-            EE_Error::add_success(
4424
-                sprintf(
4425
-                    esc_html__(
4426
-                        '%s message type has been successfully deactivated for the %s messenger.',
4427
-                        'event_espresso'
4428
-                    ),
4429
-                    ucwords($message_type->label['singular']),
4430
-                    ucwords($messenger->label['singular'])
4431
-                )
4432
-            );
4433
-        } else {
4434
-            $message_type_name = '';
4435
-            EE_Error::add_success(
4436
-                sprintf(
4437
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
-                    ucwords($messenger->label['singular'])
4439
-                )
4440
-            );
4441
-        }
4442
-
4443
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
-        if (
4445
-            $messenger->name === 'html'
4446
-            && (
4447
-                is_null($message_type)
4448
-                || $message_type_name === 'invoice'
4449
-            )
4450
-        ) {
4451
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
-            if ($count_updated > 0) {
4454
-                $msg = $message_type_name === 'invoice'
4455
-                    ? esc_html__(
4456
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4457
-                        'event_espresso'
4458
-                    )
4459
-                    : esc_html__(
4460
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4461
-                        'event_espresso'
4462
-                    );
4463
-                EE_Error::add_attention($msg);
4464
-            }
4465
-        }
4466
-
4467
-        return true;
4468
-    }
4469
-
4470
-
4471
-    /**
4472
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
-     *
4474
-     * @throws DomainException
4475
-     * @throws EE_Error
4476
-     * @throws EE_Error
4477
-     */
4478
-    public function update_mt_form()
4479
-    {
4480
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
-            EE_Error::add_error(
4482
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
-                __FILE__,
4484
-                __FUNCTION__,
4485
-                __LINE__
4486
-            );
4487
-            $this->_return_json();
4488
-        }
4489
-
4490
-        $message_types = $this->get_installed_message_types();
4491
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4492
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
-
4495
-        $this->_template_args['success'] = true;
4496
-        $this->_template_args['content'] = $content;
4497
-        $this->_return_json();
4498
-    }
4499
-
4500
-
4501
-    /**
4502
-     * this handles saving the settings for a messenger or message type
4503
-     *
4504
-     * @throws EE_Error
4505
-     * @throws EE_Error
4506
-     */
4507
-    public function save_settings()
4508
-    {
4509
-        $type = $this->request->getRequestParam('type');
4510
-        if (! $type) {
4511
-            EE_Error::add_error(
4512
-                esc_html__(
4513
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
-                    'event_espresso'
4515
-                ),
4516
-                __FILE__,
4517
-                __FUNCTION__,
4518
-                __LINE__
4519
-            );
4520
-            $this->_template_args['error'] = true;
4521
-            $this->_return_json();
4522
-        }
4523
-
4524
-
4525
-        if ($type === 'messenger') {
4526
-            // this should be an array.
4527
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
-            $messenger = $settings['messenger'];
4529
-            // remove messenger and message_types from settings array
4530
-            unset($settings['messenger'], $settings['message_types']);
4531
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
-        } elseif ($type === 'message_type') {
4533
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
-            $messenger    = $settings['messenger'];
4535
-            $message_type = $settings['message_type'];
4536
-            // remove messenger and message_types from settings array
4537
-            unset($settings['messenger'], $settings['message_types']);
4538
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
-        }
4540
-
4541
-        // okay we should have the data all setup.  Now we just update!
4542
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4543
-
4544
-        if ($success) {
4545
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
-        } else {
4547
-            EE_Error::add_error(
4548
-                esc_html__('Settings did not get updated', 'event_espresso'),
4549
-                __FILE__,
4550
-                __FUNCTION__,
4551
-                __LINE__
4552
-            );
4553
-        }
4554
-
4555
-        $this->_template_args['success'] = $success;
4556
-        $this->_return_json();
4557
-    }
4558
-
4559
-
4560
-
4561
-
4562
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4563
-
4564
-
4565
-    /**
4566
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
-     * However, this does not send immediately, it just queues for sending.
4568
-     *
4569
-     * @throws EE_Error
4570
-     * @throws InvalidDataTypeException
4571
-     * @throws InvalidInterfaceException
4572
-     * @throws InvalidArgumentException
4573
-     * @throws ReflectionException
4574
-     * @since 4.9.0
4575
-     */
4576
-    protected function _generate_now()
4577
-    {
4578
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
-        $this->_redirect_after_action(false, '', '', [], true);
4580
-    }
4581
-
4582
-
4583
-    /**
4584
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4586
-     *
4587
-     * @throws EE_Error
4588
-     * @throws InvalidDataTypeException
4589
-     * @throws InvalidInterfaceException
4590
-     * @throws InvalidArgumentException
4591
-     * @throws ReflectionException
4592
-     * @since 4.9.0
4593
-     */
4594
-    protected function _generate_and_send_now()
4595
-    {
4596
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
-        $this->_redirect_after_action(false, '', '', [], true);
4598
-    }
4599
-
4600
-
4601
-    /**
4602
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
-     *
4604
-     * @throws EE_Error
4605
-     * @throws InvalidDataTypeException
4606
-     * @throws InvalidInterfaceException
4607
-     * @throws InvalidArgumentException
4608
-     * @throws ReflectionException
4609
-     * @since 4.9.0
4610
-     */
4611
-    protected function _queue_for_resending()
4612
-    {
4613
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
-        $this->_redirect_after_action(false, '', '', [], true);
4615
-    }
4616
-
4617
-
4618
-    /**
4619
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
-     *
4621
-     * @throws EE_Error
4622
-     * @throws InvalidDataTypeException
4623
-     * @throws InvalidInterfaceException
4624
-     * @throws InvalidArgumentException
4625
-     * @throws ReflectionException
4626
-     * @since 4.9.0
4627
-     */
4628
-    protected function _send_now()
4629
-    {
4630
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
-        $this->_redirect_after_action(false, '', '', [], true);
4632
-    }
4633
-
4634
-
4635
-    /**
4636
-     * Deletes EE_messages for IDs in the request.
4637
-     *
4638
-     * @throws EE_Error
4639
-     * @throws InvalidDataTypeException
4640
-     * @throws InvalidInterfaceException
4641
-     * @throws InvalidArgumentException
4642
-     * @since 4.9.0
4643
-     */
4644
-    protected function _delete_ee_messages()
4645
-    {
4646
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4647
-        $deleted_count = 0;
4648
-        foreach ($MSG_IDs as $MSG_ID) {
4649
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
-                $deleted_count++;
4651
-            }
4652
-        }
4653
-        if ($deleted_count) {
4654
-            EE_Error::add_success(
4655
-                esc_html(
4656
-                    _n(
4657
-                        'Message successfully deleted',
4658
-                        'Messages successfully deleted',
4659
-                        $deleted_count,
4660
-                        'event_espresso'
4661
-                    )
4662
-                )
4663
-            );
4664
-        } else {
4665
-            EE_Error::add_error(
4666
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
-                __FILE__,
4668
-                __FUNCTION__,
4669
-                __LINE__
4670
-            );
4671
-        }
4672
-        $this->_redirect_after_action(false, '', '', [], true);
4673
-    }
4674
-
4675
-
4676
-    /**
4677
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
-     *
4679
-     * @return array
4680
-     * @since 4.9.0
4681
-     */
4682
-    protected function _get_msg_ids_from_request()
4683
-    {
4684
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
-        if (empty($MSG_IDs)) {
4686
-            return [];
4687
-        }
4688
-        // if 'MSG_ID' was just a single ID (not an array)
4689
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
-            ? $MSG_IDs
4693
-            : array_keys($MSG_IDs);
4694
-    }
2705
+		$this->_context_switcher = ob_get_clean();
2706
+	}
2707
+
2708
+
2709
+	/**
2710
+	 * @param bool $new
2711
+	 * @throws EE_Error
2712
+	 * @throws ReflectionException
2713
+	 */
2714
+	protected function _insert_or_update_message_template($new = false)
2715
+	{
2716
+		$form_data    = $this->getMessageTemplateFormData();
2717
+		$GRP_ID       = $form_data['GRP_ID'];
2718
+		$messenger    = $form_data['MTP_messenger'];
2719
+		$message_type = $form_data['MTP_message_type'];
2720
+		$context      = $form_data['MTP_context'];
2721
+
2722
+		// if this is "new" then we need to generate the default contexts
2723
+		// for the selected messenger/message_type for user to edit.
2724
+		list($success, $query_args) = $new
2725
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
+
2728
+		$success     = $success ? 1 : 0;
2729
+		$action_desc = $new ? 'created' : 'updated';
2730
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
+
2733
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * retrieve and sanitize form data
2739
+	 *
2740
+	 * @return array
2741
+	 * @since 4.10.29.p
2742
+	 */
2743
+	protected function getMessageTemplateFormData()
2744
+	{
2745
+		return [
2746
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
+		];
2756
+	}
2757
+
2758
+
2759
+	/**
2760
+	 * @param int    $GRP_ID
2761
+	 * @param string $messenger
2762
+	 * @param string $message_type
2763
+	 * @return array no return on AJAX requests
2764
+	 * @throws EE_Error
2765
+	 * @throws ReflectionException
2766
+	 * @since 4.10.29.p
2767
+	 */
2768
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
+	{
2770
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
+		$success       = ! empty($new_templates);
2772
+
2773
+		// we return things differently if doing ajax
2774
+		if ($this->request->isAjax()) {
2775
+			$this->_template_args['success'] = $success;
2776
+			$this->_template_args['error']   = ! $success;
2777
+			$this->_template_args['content'] = '';
2778
+			$this->_template_args['data']    = [
2779
+				'grpID'        => $new_templates['GRP_ID'],
2780
+				'templateName' => $new_templates['template_name'],
2781
+			];
2782
+			if ($success) {
2783
+				EE_Error::overwrite_success();
2784
+				EE_Error::add_success(
2785
+					esc_html__(
2786
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2787
+						'event_espresso'
2788
+					)
2789
+				);
2790
+			}
2791
+			$this->_return_json();
2792
+		}
2793
+		return [
2794
+			$success,
2795
+			// 'query_args'
2796
+			[
2797
+				'id'      => $new_templates['GRP_ID'],
2798
+				'context' => $new_templates['MTP_context'],
2799
+				'action'  => 'edit_message_template',
2800
+			],
2801
+		];
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * @param int    $GRP_ID
2807
+	 * @param string $messenger
2808
+	 * @param string $message_type
2809
+	 * @param string $context
2810
+	 * @param array  $form_data
2811
+	 * @return array
2812
+	 * @throws EE_Error
2813
+	 * @since 4.10.29.p
2814
+	 */
2815
+	private function updateExistingTemplates(
2816
+		$GRP_ID,
2817
+		$messenger,
2818
+		$message_type,
2819
+		$context,
2820
+		array $form_data
2821
+	) {
2822
+		$success         = false;
2823
+		$template_fields = $this->getTemplateFields();
2824
+		if ($template_fields) {
2825
+			// if field data is valid, then success will be true
2826
+			$success = $this->validateTemplateFields(
2827
+				$messenger,
2828
+				$message_type,
2829
+				$context,
2830
+				$template_fields
2831
+			);
2832
+			if ($success) {
2833
+				$field_data = [];
2834
+				foreach ($template_fields as $template_field => $content) {
2835
+					// combine top-level form data with content for this field
2836
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
+				}
2839
+				// we can use the last set_column_values for the MTPG update
2840
+				// (because its the same for all of these specific MTPs)
2841
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
+			}
2843
+		}
2844
+
2845
+		return [
2846
+			$success,
2847
+			// 'query_args'
2848
+			[
2849
+				'id'      => $GRP_ID,
2850
+				'context' => $context,
2851
+				'action'  => 'edit_message_template',
2852
+			],
2853
+		];
2854
+	}
2855
+
2856
+
2857
+	/**
2858
+	 * @return array
2859
+	 * @since 4.10.29.p
2860
+	 */
2861
+	private function getTemplateFields()
2862
+	{
2863
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
+		if (empty($template_fields)) {
2865
+			EE_Error::add_error(
2866
+				esc_html__(
2867
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
+					'event_espresso'
2869
+				),
2870
+				__FILE__,
2871
+				__FUNCTION__,
2872
+				__LINE__
2873
+			);
2874
+			return null;
2875
+		}
2876
+		// messages content is expected to be escaped
2877
+		return EEH_Array::addSlashesRecursively($template_fields);
2878
+	}
2879
+
2880
+
2881
+	/**
2882
+	 * @param string $messenger
2883
+	 * @param string $message_type
2884
+	 * @param string $context
2885
+	 * @param array  $template_fields
2886
+	 * @return bool
2887
+	 * @throws EE_Error
2888
+	 * @since   4.10.29.p
2889
+	 */
2890
+	private function validateTemplateFields(
2891
+		$messenger,
2892
+		$message_type,
2893
+		$context,
2894
+		array $template_fields
2895
+	) {
2896
+		// first validate all fields!
2897
+		// this filter allows client code to add its own validation to the template fields as well.
2898
+		// returning an empty array means everything passed validation.
2899
+		// errors in validation should be represented in an array with the following shape:
2900
+		// array(
2901
+		//   'fieldname' => array(
2902
+		//          'msg' => 'error message'
2903
+		//          'value' => 'value for field producing error'
2904
+		// )
2905
+		$custom_validation = (array) apply_filters(
2906
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
+			[],
2908
+			$template_fields,
2909
+			$context,
2910
+			$messenger,
2911
+			$message_type
2912
+		);
2913
+
2914
+		$system_validation = $this->getMtgModel()->validate(
2915
+			$template_fields,
2916
+			$context,
2917
+			$messenger,
2918
+			$message_type
2919
+		);
2920
+
2921
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
+		$validates         = array_merge($custom_validation, $system_validation);
2923
+
2924
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
+		//  WE need to make sure there is no actual error messages in validates.
2927
+		if (empty($validates)) {
2928
+			return true;
2929
+		}
2930
+
2931
+		// add the transient so when the form loads we know which fields to highlight
2932
+		$this->_add_transient('edit_message_template', $validates);
2933
+		// setup notices
2934
+		foreach ($validates as $error) {
2935
+			if (isset($error['msg'])) {
2936
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
+			}
2938
+		}
2939
+		return false;
2940
+	}
2941
+
2942
+
2943
+	/**
2944
+	 * @param array $field_data
2945
+	 * @param array $form_data
2946
+	 * @return array
2947
+	 * @since   4.10.29.p
2948
+	 */
2949
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
+	{
2951
+		return $form_data + [
2952
+				'MTP_ID'             => $field_data['MTP_ID'],
2953
+				'MTP_template_field' => $field_data['name'],
2954
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2956
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
+					: $field_data['content'],
2958
+			];
2959
+	}
2960
+
2961
+
2962
+	/**
2963
+	 * @param string $template_field
2964
+	 * @param array  $form_data
2965
+	 * @return bool
2966
+	 * @throws EE_Error
2967
+	 * @since 4.10.29.p
2968
+	 */
2969
+	private function updateMessageTemplates($template_field, array $form_data)
2970
+	{
2971
+		$MTP_ID                  = $form_data['MTP_ID'];
2972
+		$message_template_fields = [
2973
+			'GRP_ID'             => $form_data['GRP_ID'],
2974
+			'MTP_template_field' => $form_data['MTP_template_field'],
2975
+			'MTP_context'        => $form_data['MTP_context'],
2976
+			'MTP_content'        => $form_data['MTP_content'],
2977
+		];
2978
+
2979
+		$hasMtpID = ! empty($MTP_ID);
2980
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2981
+		// this has already been through the template field validator and sanitized, so it will be
2982
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
+		// message template field in a messenger/message type and existing users don't have the
2984
+		// default setup for it.
2985
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
+		$updated = $hasMtpID
2987
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
+			: $this->getMtpModel()->insert($message_template_fields);
2989
+
2990
+		$insert_failed = ! $hasMtpID && ! $updated;
2991
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
+		$update_failed = $hasMtpID && $updated === false;
2994
+
2995
+		if ($insert_failed || $update_failed) {
2996
+			EE_Error::add_error(
2997
+				sprintf(
2998
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
+					$template_field
3000
+				),
3001
+				__FILE__,
3002
+				__FUNCTION__,
3003
+				__LINE__
3004
+			);
3005
+			return false;
3006
+		}
3007
+		return true;
3008
+	}
3009
+
3010
+
3011
+	/**
3012
+	 * @param array $form_data
3013
+	 * @return bool
3014
+	 * @throws EE_Error
3015
+	 * @since 4.10.29.p
3016
+	 */
3017
+	private function updateMessageTemplateGroup(array $form_data)
3018
+	{
3019
+		$GRP_ID  = $form_data['GRP_ID'];
3020
+		$updated = $this->getMtgModel()->update(
3021
+		// fields and values
3022
+			[
3023
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3024
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3025
+				'MTP_message_type' => $form_data['MTP_message_type'],
3026
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3027
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3028
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3029
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3030
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
+				'MTP_description'  => $this->request->getRequestParam(
3032
+					'ee_msg_non_global_fields[MTP_description]',
3033
+					''
3034
+				),
3035
+			],
3036
+			// where
3037
+			[['GRP_ID' => $GRP_ID]]
3038
+		);
3039
+
3040
+		if ($updated === false) {
3041
+			EE_Error::add_error(
3042
+				sprintf(
3043
+					esc_html__(
3044
+						'The Message Template Group (%d) was NOT updated for some reason',
3045
+						'event_espresso'
3046
+					),
3047
+					$form_data['GRP_ID']
3048
+				),
3049
+				__FILE__,
3050
+				__FUNCTION__,
3051
+				__LINE__
3052
+			);
3053
+			return false;
3054
+		}
3055
+		// k now we need to ensure the template_pack and template_variation fields are set.
3056
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
+
3059
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3061
+			$message_template_group->set_template_pack_name($template_pack);
3062
+			$message_template_group->set_template_pack_variation($template_variation);
3063
+		}
3064
+		return true;
3065
+	}
3066
+
3067
+
3068
+	/**
3069
+	 * recursively runs wp_kses() on message template content in a model safe manner
3070
+	 *
3071
+	 * @param array|string $content
3072
+	 * @return array|string
3073
+	 * @since   4.10.29.p
3074
+	 */
3075
+	private function sanitizeMessageTemplateContent($content)
3076
+	{
3077
+		if (is_array($content)) {
3078
+			foreach ($content as $key => $value) {
3079
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
+			}
3081
+			return $content;
3082
+		}
3083
+		// remove slashes so wp_kses() works properly
3084
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3085
+		// so attributes using single quotes always appear invalid.
3086
+		$content = stripslashes($content);
3087
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3088
+		// But currently the models expect slashed data, so after wp_kses()
3089
+		// runs we need to re-slash the data. Sheesh.
3090
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
+		return addslashes($content);
3092
+	}
3093
+
3094
+
3095
+	/**
3096
+	 * @param string $messenger
3097
+	 * @param string $message_type
3098
+	 * @param string $context
3099
+	 * @return string
3100
+	 * @since 4.10.29.p
3101
+	 */
3102
+	private function generateUpdateDescription($messenger, $message_type, $context)
3103
+	{
3104
+		// need the message type and messenger objects to be able to use the labels for the notices
3105
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
+		$messenger_label  = $messenger_object instanceof EE_messenger
3107
+			? ucwords($messenger_object->label['singular'])
3108
+			: '';
3109
+
3110
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
+		$message_type_label  = $message_type_object instanceof EE_message_type
3112
+			? ucwords($message_type_object->label['singular'])
3113
+			: '';
3114
+
3115
+		$context   = ucwords(str_replace('_', ' ', $context));
3116
+		$item_desc = $messenger_label && $message_type_label
3117
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
+			: '';
3119
+		$item_desc .= 'Message Template';
3120
+		return $item_desc;
3121
+	}
3122
+
3123
+
3124
+	/**
3125
+	 * @param string $messenger
3126
+	 * @param string $message_type
3127
+	 * @param string $context
3128
+	 * @return bool
3129
+	 * @throws EE_Error
3130
+	 * @throws ReflectionException
3131
+	 * @since 4.10.29.p
3132
+	 */
3133
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
+	{
3135
+		// was a test send triggered?
3136
+		if ($this->request->requestParamIsSet('test_button')) {
3137
+			EE_Error::overwrite_success();
3138
+			$this->_do_test_send($context, $messenger, $message_type);
3139
+			return true;
3140
+		}
3141
+		return false;
3142
+	}
3143
+
3144
+
3145
+	/**
3146
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
+	 *
3148
+	 * @param string $context      what context being tested
3149
+	 * @param string $messenger    messenger being tested
3150
+	 * @param string $message_type message type being tested
3151
+	 * @throws EE_Error
3152
+	 * @throws InvalidArgumentException
3153
+	 * @throws InvalidDataTypeException
3154
+	 * @throws InvalidInterfaceException
3155
+	 * @throws ReflectionException
3156
+	 */
3157
+	protected function _do_test_send($context, $messenger, $message_type)
3158
+	{
3159
+		// set things up for preview
3160
+		$this->request->setRequestParam('messenger', $messenger);
3161
+		$this->request->setRequestParam('message_type', $message_type);
3162
+		$this->request->setRequestParam('context', $context);
3163
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
+
3166
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
+
3169
+		// let's save any existing fields that might be required by the messenger
3170
+		if (
3171
+			! empty($test_settings_fld)
3172
+			&& $active_messenger instanceof EE_messenger
3173
+			&& apply_filters(
3174
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
+				true,
3176
+				$test_settings_fld,
3177
+				$active_messenger
3178
+			)
3179
+		) {
3180
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3181
+		}
3182
+
3183
+		/**
3184
+		 * Use filter to add additional controls on whether message can send or not
3185
+		 */
3186
+		if (
3187
+			apply_filters(
3188
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
+				true,
3190
+				$context,
3191
+				$this->request->requestParams(),
3192
+				$messenger,
3193
+				$message_type
3194
+			)
3195
+		) {
3196
+			if (EEM_Event::instance()->count() > 0) {
3197
+				$success = $this->_preview_message(true);
3198
+				if ($success) {
3199
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
+				} else {
3201
+					EE_Error::add_error(
3202
+						esc_html__('The test message was not sent', 'event_espresso'),
3203
+						__FILE__,
3204
+						__FUNCTION__,
3205
+						__LINE__
3206
+					);
3207
+				}
3208
+			} else {
3209
+				$this->noEventsErrorMessage(true);
3210
+			}
3211
+		}
3212
+	}
3213
+
3214
+
3215
+	/**
3216
+	 * _generate_new_templates
3217
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
+	 * for the event.
3220
+	 *
3221
+	 *
3222
+	 * @param string $messenger      the messenger we are generating templates for
3223
+	 * @param array  $message_types  array of message types that the templates are generated for.
3224
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
+	 *                               indicate the message_template_group being used as the base.
3226
+	 *
3227
+	 * @param bool   $global
3228
+	 *
3229
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
+	 *                               encountering problems.
3231
+	 * @throws EE_Error
3232
+	 * @throws ReflectionException
3233
+	 */
3234
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
+	{
3236
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
+		// just don't generate any templates.
3238
+		if (empty($message_types)) {
3239
+			return [];
3240
+		}
3241
+
3242
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
+		return $templates[0];
3244
+	}
3245
+
3246
+
3247
+	/**
3248
+	 * [_trash_or_restore_message_template]
3249
+	 *
3250
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
+	 *                        an individual context (FALSE).
3253
+	 * @return void
3254
+	 * @throws EE_Error
3255
+	 * @throws InvalidArgumentException
3256
+	 * @throws InvalidDataTypeException
3257
+	 * @throws InvalidInterfaceException
3258
+	 */
3259
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
+	{
3261
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
+
3263
+		$success = 1;
3264
+
3265
+		// incoming GRP_IDs
3266
+		if ($all) {
3267
+			// Checkboxes
3268
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
+			if (! empty($checkboxes)) {
3270
+				// if array has more than one element then success message should be plural.
3271
+				// todo: what about nonce?
3272
+				$success = count($checkboxes) > 1 ? 2 : 1;
3273
+
3274
+				// cycle through checkboxes
3275
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3276
+					$trashed_or_restored = $trash
3277
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
+					if (! $trashed_or_restored) {
3280
+						$success = 0;
3281
+					}
3282
+				}
3283
+			} else {
3284
+				// grab single GRP_ID and handle
3285
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
+				if (! empty($GRP_ID)) {
3287
+					$trashed_or_restored = $trash
3288
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
+					if (! $trashed_or_restored) {
3291
+						$success = 0;
3292
+					}
3293
+				} else {
3294
+					$success = 0;
3295
+				}
3296
+			}
3297
+		}
3298
+
3299
+		$action_desc = $trash
3300
+			? esc_html__('moved to the trash', 'event_espresso')
3301
+			: esc_html__('restored', 'event_espresso');
3302
+
3303
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
+
3306
+		$item_desc = $all ? _n(
3307
+			'Message Template Group',
3308
+			'Message Template Groups',
3309
+			$success,
3310
+			'event_espresso'
3311
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
+
3313
+		$item_desc = $template_switch
3314
+			? _n('template', 'templates', $success, 'event_espresso')
3315
+			: $item_desc;
3316
+
3317
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
+	}
3319
+
3320
+
3321
+	/**
3322
+	 * [_delete_message_template]
3323
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
+	 *
3325
+	 * @return void
3326
+	 * @throws EE_Error
3327
+	 * @throws InvalidArgumentException
3328
+	 * @throws InvalidDataTypeException
3329
+	 * @throws InvalidInterfaceException
3330
+	 * @throws ReflectionException
3331
+	 */
3332
+	protected function _delete_message_template()
3333
+	{
3334
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
+
3336
+		// checkboxes
3337
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
+		if (! empty($checkboxes)) {
3339
+			// if array has more than one element then success message should be plural
3340
+			$success = count($checkboxes) > 1 ? 2 : 1;
3341
+
3342
+			// cycle through bulk action checkboxes
3343
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3344
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
+			}
3346
+		} else {
3347
+			// grab single grp_id and delete
3348
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3350
+		}
3351
+
3352
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
+	}
3354
+
3355
+
3356
+	/**
3357
+	 * helper for permanently deleting a mtP group and all related message_templates
3358
+	 *
3359
+	 * @param int  $GRP_ID        The group being deleted
3360
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3361
+	 * @return bool boolean to indicate the success of the deletes or not.
3362
+	 * @throws EE_Error
3363
+	 * @throws InvalidArgumentException
3364
+	 * @throws InvalidDataTypeException
3365
+	 * @throws InvalidInterfaceException
3366
+	 * @throws ReflectionException
3367
+	 * @throws ReflectionException
3368
+	 */
3369
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
+	{
3371
+		$success = true;
3372
+		// first let's GET this group
3373
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
+		// then delete permanently all the related Message Templates
3375
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3376
+
3377
+		if ($deleted === 0) {
3378
+			$success = false;
3379
+		}
3380
+
3381
+		// now delete permanently this particular group
3382
+
3383
+		if ($include_group && ! $MTG->delete_permanently()) {
3384
+			$success = false;
3385
+		}
3386
+
3387
+		return $success;
3388
+	}
3389
+
3390
+
3391
+	/**
3392
+	 *    _learn_more_about_message_templates_link
3393
+	 *
3394
+	 * @access protected
3395
+	 * @return string
3396
+	 */
3397
+	protected function _learn_more_about_message_templates_link()
3398
+	{
3399
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3401
+			   . '</a>';
3402
+	}
3403
+
3404
+
3405
+	/**
3406
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
+	 * ajax and other routes.
3408
+	 *
3409
+	 * @return void
3410
+	 * @throws DomainException
3411
+	 * @throws EE_Error
3412
+	 */
3413
+	protected function _settings()
3414
+	{
3415
+		$this->_set_m_mt_settings();
3416
+
3417
+		// let's setup the messenger tabs
3418
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
+			$this->_m_mt_settings['messenger_tabs'],
3420
+			'messenger_links',
3421
+			'|',
3422
+			$this->request->getRequestParam('selected_messenger', 'email')
3423
+		);
3424
+
3425
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
+
3428
+		$this->display_admin_page_with_sidebar();
3429
+	}
3430
+
3431
+
3432
+	/**
3433
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
+	 *
3435
+	 * @access protected
3436
+	 * @return void
3437
+	 * @throws DomainException
3438
+	 */
3439
+	protected function _set_m_mt_settings()
3440
+	{
3441
+		// first if this is already set then lets get out no need to regenerate data.
3442
+		if (! empty($this->_m_mt_settings)) {
3443
+			return;
3444
+		}
3445
+
3446
+		// get all installed messengers and message_types
3447
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3448
+		$message_types = $this->_message_resource_manager->installed_message_types();
3449
+
3450
+
3451
+		// assemble the array for the _tab_text_links helper
3452
+
3453
+		foreach ($messengers as $messenger) {
3454
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+				'label' => ucwords($messenger->label['singular']),
3456
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
+					? 'messenger-active'
3458
+					: '',
3459
+				'href'  => $messenger->name,
3460
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
+				'slug'  => $messenger->name,
3462
+				'obj'   => $messenger,
3463
+			];
3464
+
3465
+
3466
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3467
+
3468
+			foreach ($message_types as $message_type) {
3469
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
+				// it shouldn't show in either the inactive OR active metabox.
3471
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
+					continue;
3473
+				}
3474
+
3475
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
+					$messenger->name,
3477
+					$message_type->name
3478
+				)
3479
+					? 'active'
3480
+					: 'inactive';
3481
+
3482
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
+					'label'    => ucwords($message_type->label['singular']),
3484
+					'class'    => 'message-type-' . $a_or_i,
3485
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
+					'title'    => $a_or_i === 'active'
3489
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
+					'content'  => $a_or_i === 'active'
3492
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3493
+						: $this->_message_type_settings_content($message_type, $messenger),
3494
+					'slug'     => $message_type->name,
3495
+					'active'   => $a_or_i === 'active',
3496
+					'obj'      => $message_type,
3497
+				];
3498
+			}
3499
+		}
3500
+	}
3501
+
3502
+
3503
+	/**
3504
+	 * This just prepares the content for the message type settings
3505
+	 *
3506
+	 * @param EE_message_type $message_type The message type object
3507
+	 * @param EE_messenger    $messenger    The messenger object
3508
+	 * @param boolean         $active       Whether the message type is active or not
3509
+	 * @return string html output for the content
3510
+	 * @throws DomainException
3511
+	 */
3512
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
+	{
3514
+		// get message type fields
3515
+		$fields                                         = $message_type->get_admin_settings_fields();
3516
+		$settings_template_args['template_form_fields'] = '';
3517
+
3518
+		if (! empty($fields) && $active) {
3519
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
+			foreach ($fields as $fldname => $fldprops) {
3521
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
+				$template_form_field[ $field_id ] = [
3523
+					'name'       => 'message_type_settings[' . $fldname . ']',
3524
+					'label'      => $fldprops['label'],
3525
+					'input'      => $fldprops['field_type'],
3526
+					'type'       => $fldprops['value_type'],
3527
+					'required'   => $fldprops['required'],
3528
+					'validation' => $fldprops['validation'],
3529
+					'value'      => isset($existing_settings[ $fldname ])
3530
+						? $existing_settings[ $fldname ]
3531
+						: $fldprops['default'],
3532
+					'options'    => isset($fldprops['options'])
3533
+						? $fldprops['options']
3534
+						: [],
3535
+					'default'    => isset($existing_settings[ $fldname ])
3536
+						? $existing_settings[ $fldname ]
3537
+						: $fldprops['default'],
3538
+					'css_class'  => 'no-drag',
3539
+					'format'     => $fldprops['format'],
3540
+				];
3541
+			}
3542
+
3543
+
3544
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
+				? $this->_generate_admin_form_fields(
3546
+					$template_form_field,
3547
+					'string',
3548
+					'ee_mt_activate_form'
3549
+				)
3550
+				: '';
3551
+		}
3552
+
3553
+		$settings_template_args['description'] = $message_type->description;
3554
+		// we also need some hidden fields
3555
+		$hidden_fields = [
3556
+			'message_type_settings[messenger]' . $message_type->name    => [
3557
+				'type'  => 'hidden',
3558
+				'value' => $messenger->name,
3559
+			],
3560
+			'message_type_settings[message_type]' . $message_type->name => [
3561
+				'type'  => 'hidden',
3562
+				'value' => $message_type->name,
3563
+			],
3564
+			'type' . $message_type->name                                => [
3565
+				'type'  => 'hidden',
3566
+				'value' => 'message_type',
3567
+			],
3568
+		];
3569
+
3570
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
+			$hidden_fields,
3572
+			'array'
3573
+		);
3574
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
+			? ' hidden'
3576
+			: '';
3577
+
3578
+
3579
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
+		return EEH_Template::display_template($template, $settings_template_args, true);
3581
+	}
3582
+
3583
+
3584
+	/**
3585
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
+	 *
3587
+	 * @access protected
3588
+	 * @return void
3589
+	 * @throws DomainException
3590
+	 */
3591
+	protected function _messages_settings_metaboxes()
3592
+	{
3593
+		$this->_set_m_mt_settings();
3594
+		$m_boxes         = $mt_boxes = [];
3595
+		$m_template_args = $mt_template_args = [];
3596
+
3597
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
+
3599
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
+
3605
+				// messenger meta boxes
3606
+				$active         = $selected_messenger === $messenger;
3607
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
+					: '';
3610
+
3611
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
+					esc_html__('%s Settings', 'event_espresso'),
3613
+					$tab_array['label']
3614
+				);
3615
+
3616
+				$m_template_args[ $messenger . '_a_box' ] = [
3617
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
+					'inactive_message_types' => isset(
3619
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
+					)
3621
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
+						: '',
3623
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
+					'hidden'                 => $active ? '' : ' hidden',
3625
+					'hide_on_message'        => $hide_on_message,
3626
+					'messenger'              => $messenger,
3627
+					'active'                 => $active,
3628
+				];
3629
+
3630
+				// message type meta boxes
3631
+				// (which is really just the inactive container for each messenger
3632
+				// showing inactive message types for that messenger)
3633
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
+				$mt_template_args[ $messenger . '_i_box' ] = [
3635
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
+					'inactive_message_types' => isset(
3637
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
+					)
3639
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
+						: '',
3641
+					'hidden'                 => $active ? '' : ' hidden',
3642
+					'hide_on_message'        => $hide_on_message,
3643
+					'hide_off_message'       => $hide_off_message,
3644
+					'messenger'              => $messenger,
3645
+					'active'                 => $active,
3646
+				];
3647
+			}
3648
+		}
3649
+
3650
+
3651
+		// register messenger metaboxes
3652
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
+		foreach ($m_boxes as $box => $label) {
3654
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
+			$msgr          = str_replace('_a_box', '', $box);
3656
+			add_meta_box(
3657
+				'espresso_' . $msgr . '_settings',
3658
+				$label,
3659
+				function ($post, $metabox) {
3660
+					EEH_Template::display_template(
3661
+						$metabox['args']['template_path'],
3662
+						$metabox['args']['template_args']
3663
+					);
3664
+				},
3665
+				$this->_current_screen->id,
3666
+				'normal',
3667
+				'high',
3668
+				$callback_args
3669
+			);
3670
+		}
3671
+
3672
+		// register message type metaboxes
3673
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
+		foreach ($mt_boxes as $box => $label) {
3675
+			$callback_args = [
3676
+				'template_path' => $mt_template_path,
3677
+				'template_args' => $mt_template_args[ $box ],
3678
+			];
3679
+			$mt            = str_replace('_i_box', '', $box);
3680
+			add_meta_box(
3681
+				'espresso_' . $mt . '_inactive_mts',
3682
+				$label,
3683
+				function ($post, $metabox) {
3684
+					EEH_Template::display_template(
3685
+						$metabox['args']['template_path'],
3686
+						$metabox['args']['template_args']
3687
+					);
3688
+				},
3689
+				$this->_current_screen->id,
3690
+				'side',
3691
+				'high',
3692
+				$callback_args
3693
+			);
3694
+		}
3695
+
3696
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3697
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
+		if (is_main_site()) {
3699
+			add_meta_box(
3700
+				'espresso_global_message_settings',
3701
+				esc_html__('Global Message Settings', 'event_espresso'),
3702
+				[$this, 'global_messages_settings_metabox_content'],
3703
+				$this->_current_screen->id,
3704
+				'normal',
3705
+				'low',
3706
+				[]
3707
+			);
3708
+		}
3709
+	}
3710
+
3711
+
3712
+	/**
3713
+	 *  This generates the content for the global messages settings metabox.
3714
+	 *
3715
+	 * @return void
3716
+	 * @throws EE_Error
3717
+	 * @throws InvalidArgumentException
3718
+	 * @throws ReflectionException
3719
+	 * @throws InvalidDataTypeException
3720
+	 * @throws InvalidInterfaceException
3721
+	 */
3722
+	public function global_messages_settings_metabox_content()
3723
+	{
3724
+		$form = $this->_generate_global_settings_form();
3725
+		echo wp_kses(
3726
+			$form->form_open(
3727
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
+				'POST'
3729
+			),
3730
+			AllowedTags::getWithFormTags()
3731
+		);
3732
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
+	}
3735
+
3736
+
3737
+	/**
3738
+	 * This generates and returns the form object for the global messages settings.
3739
+	 *
3740
+	 * @return EE_Form_Section_Proper
3741
+	 * @throws EE_Error
3742
+	 * @throws InvalidArgumentException
3743
+	 * @throws ReflectionException
3744
+	 * @throws InvalidDataTypeException
3745
+	 * @throws InvalidInterfaceException
3746
+	 */
3747
+	protected function _generate_global_settings_form()
3748
+	{
3749
+		/** @var EE_Network_Core_Config $network_config */
3750
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3751
+
3752
+		return new EE_Form_Section_Proper(
3753
+			[
3754
+				'name'            => 'global_messages_settings',
3755
+				'html_id'         => 'global_messages_settings',
3756
+				'html_class'      => 'form-table',
3757
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
+				'subsections'     => apply_filters(
3759
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
+					[
3761
+						'do_messages_on_same_request' => new EE_Select_Input(
3762
+							[
3763
+								true  => esc_html__('On the same request', 'event_espresso'),
3764
+								false => esc_html__('On a separate request', 'event_espresso'),
3765
+							],
3766
+							[
3767
+								'default'         => $network_config->do_messages_on_same_request,
3768
+								'html_label_text' => esc_html__(
3769
+									'Generate and send all messages:',
3770
+									'event_espresso'
3771
+								),
3772
+								'html_help_text'  => esc_html__(
3773
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3774
+									'event_espresso'
3775
+								),
3776
+							]
3777
+						),
3778
+						'delete_threshold'            => new EE_Select_Input(
3779
+							[
3780
+								0  => esc_html__('Forever', 'event_espresso'),
3781
+								3  => esc_html__('3 Months', 'event_espresso'),
3782
+								6  => esc_html__('6 Months', 'event_espresso'),
3783
+								9  => esc_html__('9 Months', 'event_espresso'),
3784
+								12 => esc_html__('12 Months', 'event_espresso'),
3785
+								24 => esc_html__('24 Months', 'event_espresso'),
3786
+								36 => esc_html__('36 Months', 'event_espresso'),
3787
+							],
3788
+							[
3789
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
+								'html_help_text'  => esc_html__(
3792
+									'You can control how long a record of processed messages is kept via this option.',
3793
+									'event_espresso'
3794
+								),
3795
+							]
3796
+						),
3797
+						'update_settings'             => new EE_Submit_Input(
3798
+							[
3799
+								'default'         => esc_html__('Update', 'event_espresso'),
3800
+								'html_label_text' => '',
3801
+							]
3802
+						),
3803
+					]
3804
+				),
3805
+			]
3806
+		);
3807
+	}
3808
+
3809
+
3810
+	/**
3811
+	 * This handles updating the global settings set on the admin page.
3812
+	 *
3813
+	 * @throws EE_Error
3814
+	 * @throws InvalidDataTypeException
3815
+	 * @throws InvalidInterfaceException
3816
+	 * @throws InvalidArgumentException
3817
+	 * @throws ReflectionException
3818
+	 */
3819
+	protected function _update_global_settings()
3820
+	{
3821
+		/** @var EE_Network_Core_Config $network_config */
3822
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3823
+		$messages_config = EE_Registry::instance()->CFG->messages;
3824
+		$form            = $this->_generate_global_settings_form();
3825
+		if ($form->was_submitted()) {
3826
+			$form->receive_form_submission();
3827
+			if ($form->is_valid()) {
3828
+				$valid_data = $form->valid_data();
3829
+				foreach ($valid_data as $property => $value) {
3830
+					$setter = 'set_' . $property;
3831
+					if (method_exists($network_config, $setter)) {
3832
+						$network_config->{$setter}($value);
3833
+					} elseif (
3834
+						property_exists($network_config, $property)
3835
+						&& $network_config->{$property} !== $value
3836
+					) {
3837
+						$network_config->{$property} = $value;
3838
+					} elseif (
3839
+						property_exists($messages_config, $property)
3840
+						&& $messages_config->{$property} !== $value
3841
+					) {
3842
+						$messages_config->{$property} = $value;
3843
+					}
3844
+				}
3845
+				// only update if the form submission was valid!
3846
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
+				EE_Registry::instance()->CFG->update_espresso_config();
3848
+				EE_Error::overwrite_success();
3849
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
+			}
3851
+		}
3852
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
+	}
3854
+
3855
+
3856
+	/**
3857
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
+	 *
3859
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
+	 * @return string html formatted tabs
3861
+	 * @throws DomainException
3862
+	 */
3863
+	protected function _get_mt_tabs($tab_array)
3864
+	{
3865
+		$tab_array = (array) $tab_array;
3866
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
+		$tabs      = '';
3868
+
3869
+		foreach ($tab_array as $tab) {
3870
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3871
+		}
3872
+
3873
+		return $tabs;
3874
+	}
3875
+
3876
+
3877
+	/**
3878
+	 * This prepares the content of the messenger meta box admin settings
3879
+	 *
3880
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3881
+	 * @return string html formatted content
3882
+	 * @throws DomainException
3883
+	 */
3884
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3885
+	{
3886
+
3887
+		$fields                                         = $messenger->get_admin_settings_fields();
3888
+		$settings_template_args['template_form_fields'] = '';
3889
+
3890
+		// is $messenger active?
3891
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
+
3893
+
3894
+		if (! empty($fields)) {
3895
+			$existing_settings = $messenger->get_existing_admin_settings();
3896
+
3897
+			foreach ($fields as $fldname => $fldprops) {
3898
+				$field_id                         = $messenger->name . '-' . $fldname;
3899
+				$template_form_field[ $field_id ] = [
3900
+					'name'       => 'messenger_settings[' . $field_id . ']',
3901
+					'label'      => $fldprops['label'],
3902
+					'input'      => $fldprops['field_type'],
3903
+					'type'       => $fldprops['value_type'],
3904
+					'required'   => $fldprops['required'],
3905
+					'validation' => $fldprops['validation'],
3906
+					'value'      => isset($existing_settings[ $field_id ])
3907
+						? $existing_settings[ $field_id ]
3908
+						: $fldprops['default'],
3909
+					'css_class'  => '',
3910
+					'format'     => $fldprops['format'],
3911
+				];
3912
+			}
3913
+
3914
+
3915
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
+				: '';
3918
+		}
3919
+
3920
+		// we also need some hidden fields
3921
+		$settings_template_args['hidden_fields'] = [
3922
+			'messenger_settings[messenger]' . $messenger->name => [
3923
+				'type'  => 'hidden',
3924
+				'value' => $messenger->name,
3925
+			],
3926
+			'type' . $messenger->name                          => [
3927
+				'type'  => 'hidden',
3928
+				'value' => 'messenger',
3929
+			],
3930
+		];
3931
+
3932
+		// make sure any active message types that are existing are included in the hidden fields
3933
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
+					'type'  => 'hidden',
3937
+					'value' => $mt,
3938
+				];
3939
+			}
3940
+		}
3941
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
+			$settings_template_args['hidden_fields'],
3943
+			'array'
3944
+		);
3945
+		$active                                  =
3946
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3947
+
3948
+		$settings_template_args['messenger']           = $messenger->name;
3949
+		$settings_template_args['description']         = $messenger->description;
3950
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
+
3952
+
3953
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
+			$messenger->name
3955
+		)
3956
+			? $settings_template_args['show_hide_edit_form']
3957
+			: ' hidden';
3958
+
3959
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
+			? ' hidden'
3961
+			: $settings_template_args['show_hide_edit_form'];
3962
+
3963
+
3964
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
+		$settings_template_args['on_off_status'] = $active;
3967
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
+		return EEH_Template::display_template(
3969
+			$template,
3970
+			$settings_template_args,
3971
+			true
3972
+		);
3973
+	}
3974
+
3975
+
3976
+	/**
3977
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3978
+	 *
3979
+	 * @throws DomainException
3980
+	 * @throws EE_Error
3981
+	 * @throws InvalidDataTypeException
3982
+	 * @throws InvalidInterfaceException
3983
+	 * @throws InvalidArgumentException
3984
+	 * @throws ReflectionException
3985
+	 */
3986
+	public function activate_messenger_toggle()
3987
+	{
3988
+		$success = true;
3989
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
+		// let's check that we have required data
3991
+
3992
+		if (! $this->_active_messenger_name) {
3993
+			EE_Error::add_error(
3994
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
+				__FILE__,
3996
+				__FUNCTION__,
3997
+				__LINE__
3998
+			);
3999
+			$success = false;
4000
+		}
4001
+
4002
+		// do a nonce check here since we're not arriving via a normal route
4003
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
+
4006
+		$this->_verify_nonce($nonce, $nonce_ref);
4007
+
4008
+
4009
+		$status = $this->request->getRequestParam('status');
4010
+		if (! $status) {
4011
+			EE_Error::add_error(
4012
+				esc_html__(
4013
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
+					'event_espresso'
4015
+				),
4016
+				__FILE__,
4017
+				__FUNCTION__,
4018
+				__LINE__
4019
+			);
4020
+			$success = false;
4021
+		}
4022
+
4023
+		// do check to verify we have a valid status.
4024
+		if ($status !== 'off' && $status !== 'on') {
4025
+			EE_Error::add_error(
4026
+				sprintf(
4027
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
+					$status
4029
+				),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034
+			$success = false;
4035
+		}
4036
+
4037
+		if ($success) {
4038
+			// made it here?  Stop dawdling then!!
4039
+			$success = $status === 'off'
4040
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4041
+				: $this->_activate_messenger($this->_active_messenger_name);
4042
+		}
4043
+
4044
+		$this->_template_args['success'] = $success;
4045
+
4046
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
+		$this->_return_json();
4048
+	}
4049
+
4050
+
4051
+	/**
4052
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4053
+	 *
4054
+	 * @throws DomainException
4055
+	 * @throws EE_Error
4056
+	 * @throws ReflectionException
4057
+	 * @throws InvalidDataTypeException
4058
+	 * @throws InvalidInterfaceException
4059
+	 * @throws InvalidArgumentException
4060
+	 */
4061
+	public function activate_mt_toggle()
4062
+	{
4063
+		$success = true;
4064
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
+
4066
+		// let's make sure we have the necessary data
4067
+		if (! $this->_active_message_type_name) {
4068
+			EE_Error::add_error(
4069
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
+				__FILE__,
4071
+				__FUNCTION__,
4072
+				__LINE__
4073
+			);
4074
+			$success = false;
4075
+		}
4076
+
4077
+		if (! $this->_active_messenger_name) {
4078
+			EE_Error::add_error(
4079
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
+				__FILE__,
4081
+				__FUNCTION__,
4082
+				__LINE__
4083
+			);
4084
+			$success = false;
4085
+		}
4086
+
4087
+		$status = $this->request->getRequestParam('status');
4088
+		if (! $status) {
4089
+			EE_Error::add_error(
4090
+				esc_html__(
4091
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
+					'event_espresso'
4093
+				),
4094
+				__FILE__,
4095
+				__FUNCTION__,
4096
+				__LINE__
4097
+			);
4098
+			$success = false;
4099
+		}
4100
+
4101
+
4102
+		// do check to verify we have a valid status.
4103
+		if ($status !== 'activate' && $status !== 'deactivate') {
4104
+			EE_Error::add_error(
4105
+				sprintf(
4106
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
+					$status
4108
+				),
4109
+				__FILE__,
4110
+				__FUNCTION__,
4111
+				__LINE__
4112
+			);
4113
+			$success = false;
4114
+		}
4115
+
4116
+
4117
+		// do a nonce check here since we're not arriving via a normal route
4118
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4119
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
+
4121
+		if ($success) {
4122
+			// made it here? um, what are you waiting for then?
4123
+			$success = $status === 'deactivate'
4124
+				? $this->_deactivate_message_type_for_messenger(
4125
+					$this->_active_messenger_name,
4126
+					$this->_active_message_type_name
4127
+				)
4128
+				: $this->_activate_message_type_for_messenger(
4129
+					$this->_active_messenger_name,
4130
+					$this->_active_message_type_name
4131
+				);
4132
+		}
4133
+
4134
+		$this->_template_args['success'] = $success;
4135
+		$this->_return_json();
4136
+	}
4137
+
4138
+
4139
+	/**
4140
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4141
+	 *
4142
+	 * @param string $messenger_name The name of the messenger being activated
4143
+	 * @return bool
4144
+	 * @throws DomainException
4145
+	 * @throws EE_Error
4146
+	 * @throws InvalidArgumentException
4147
+	 * @throws ReflectionException
4148
+	 * @throws InvalidDataTypeException
4149
+	 * @throws InvalidInterfaceException
4150
+	 */
4151
+	protected function _activate_messenger($messenger_name)
4152
+	{
4153
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
+			? $active_messenger->get_default_message_types()
4156
+			: [];
4157
+
4158
+		// ensure is active
4159
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
+
4161
+		// set response_data for reload
4162
+		foreach ($message_types_to_activate as $message_type_name) {
4163
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
+			if (
4165
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4166
+					$messenger_name,
4167
+					$message_type_name
4168
+				)
4169
+				&& $message_type instanceof EE_message_type
4170
+			) {
4171
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4172
+				if ($message_type->get_admin_settings_fields()) {
4173
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
+				}
4175
+			}
4176
+		}
4177
+
4178
+		// add success message for activating messenger
4179
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
+	}
4181
+
4182
+
4183
+	/**
4184
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
+	 *
4186
+	 * @param string $messenger_name The name of the messenger being activated
4187
+	 * @return bool
4188
+	 * @throws DomainException
4189
+	 * @throws EE_Error
4190
+	 * @throws InvalidArgumentException
4191
+	 * @throws ReflectionException
4192
+	 * @throws InvalidDataTypeException
4193
+	 * @throws InvalidInterfaceException
4194
+	 */
4195
+	protected function _deactivate_messenger($messenger_name)
4196
+	{
4197
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
+
4200
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
+	}
4202
+
4203
+
4204
+	/**
4205
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
+	 *
4207
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4209
+	 * @return bool
4210
+	 * @throws DomainException
4211
+	 * @throws EE_Error
4212
+	 * @throws InvalidArgumentException
4213
+	 * @throws ReflectionException
4214
+	 * @throws InvalidDataTypeException
4215
+	 * @throws InvalidInterfaceException
4216
+	 */
4217
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
+	{
4219
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
+
4222
+		// ensure is active
4223
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
+
4225
+		// set response for load
4226
+		if (
4227
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4228
+				$messenger_name,
4229
+				$message_type_name
4230
+			)
4231
+		) {
4232
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4233
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4234
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
+			}
4236
+		}
4237
+
4238
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
+			$active_messenger,
4240
+			$message_type_to_activate
4241
+		);
4242
+	}
4243
+
4244
+
4245
+	/**
4246
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
+	 *
4248
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
+	 * @return bool
4251
+	 * @throws DomainException
4252
+	 * @throws EE_Error
4253
+	 * @throws InvalidArgumentException
4254
+	 * @throws ReflectionException
4255
+	 * @throws InvalidDataTypeException
4256
+	 * @throws InvalidInterfaceException
4257
+	 */
4258
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
+	{
4260
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
+
4265
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
+			$active_messenger,
4267
+			$message_type_to_deactivate
4268
+		);
4269
+	}
4270
+
4271
+
4272
+	/**
4273
+	 * This just initializes the defaults for activating messenger and message type responses.
4274
+	 */
4275
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
+	{
4277
+		$this->_template_args['data']['active_mts'] = [];
4278
+		$this->_template_args['data']['mt_reload']  = [];
4279
+	}
4280
+
4281
+
4282
+	/**
4283
+	 * Setup appropriate response for activating a messenger and/or message types
4284
+	 *
4285
+	 * @param EE_messenger         $messenger
4286
+	 * @param EE_message_type|null $message_type
4287
+	 * @return bool
4288
+	 * @throws DomainException
4289
+	 * @throws EE_Error
4290
+	 * @throws InvalidArgumentException
4291
+	 * @throws ReflectionException
4292
+	 * @throws InvalidDataTypeException
4293
+	 * @throws InvalidInterfaceException
4294
+	 */
4295
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
+		$messenger,
4297
+		EE_Message_Type $message_type = null
4298
+	) {
4299
+		// if $messenger isn't a valid messenger object then get out.
4300
+		if (! $messenger instanceof EE_Messenger) {
4301
+			EE_Error::add_error(
4302
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
+				__FILE__,
4304
+				__FUNCTION__,
4305
+				__LINE__
4306
+			);
4307
+			return false;
4308
+		}
4309
+		// activated
4310
+		if ($this->_template_args['data']['active_mts']) {
4311
+			EE_Error::overwrite_success();
4312
+			// activated a message type with the messenger
4313
+			if ($message_type instanceof EE_message_type) {
4314
+				EE_Error::add_success(
4315
+					sprintf(
4316
+						esc_html__(
4317
+							'%s message type has been successfully activated with the %s messenger',
4318
+							'event_espresso'
4319
+						),
4320
+						ucwords($message_type->label['singular']),
4321
+						ucwords($messenger->label['singular'])
4322
+					)
4323
+				);
4324
+
4325
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4326
+				if ($message_type->name === 'invoice') {
4327
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
+					if ($pm instanceof EE_Payment_Method) {
4330
+						EE_Error::add_attention(
4331
+							esc_html__(
4332
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4333
+								'event_espresso'
4334
+							)
4335
+						);
4336
+					}
4337
+				}
4338
+				// just toggles the entire messenger
4339
+			} else {
4340
+				EE_Error::add_success(
4341
+					sprintf(
4342
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
+						ucwords($messenger->label['singular'])
4344
+					)
4345
+				);
4346
+			}
4347
+
4348
+			return true;
4349
+
4350
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
+			// in which case we just give a success message for the messenger being successfully activated.
4353
+		} else {
4354
+			if (! $messenger->get_default_message_types()) {
4355
+				// messenger doesn't have any default message types so still a success.
4356
+				EE_Error::add_success(
4357
+					sprintf(
4358
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
+						ucwords($messenger->label['singular'])
4360
+					)
4361
+				);
4362
+
4363
+				return true;
4364
+			} else {
4365
+				EE_Error::add_error(
4366
+					$message_type instanceof EE_message_type
4367
+					? sprintf(
4368
+						esc_html__(
4369
+							'%s message type was not successfully activated with the %s messenger',
4370
+							'event_espresso'
4371
+						),
4372
+						ucwords($message_type->label['singular']),
4373
+						ucwords($messenger->label['singular'])
4374
+					)
4375
+					: sprintf(
4376
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
+						ucwords($messenger->label['singular'])
4378
+					),
4379
+					__FILE__,
4380
+					__FUNCTION__,
4381
+					__LINE__
4382
+				);
4383
+
4384
+				return false;
4385
+			}
4386
+		}
4387
+	}
4388
+
4389
+
4390
+	/**
4391
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
+	 *
4393
+	 * @param EE_messenger         $messenger
4394
+	 * @param EE_message_type|null $message_type
4395
+	 * @return bool
4396
+	 * @throws DomainException
4397
+	 * @throws EE_Error
4398
+	 * @throws InvalidArgumentException
4399
+	 * @throws ReflectionException
4400
+	 * @throws InvalidDataTypeException
4401
+	 * @throws InvalidInterfaceException
4402
+	 */
4403
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
+		$messenger,
4405
+		EE_message_type $message_type = null
4406
+	) {
4407
+		EE_Error::overwrite_success();
4408
+
4409
+		// if $messenger isn't a valid messenger object then get out.
4410
+		if (! $messenger instanceof EE_Messenger) {
4411
+			EE_Error::add_error(
4412
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
+				__FILE__,
4414
+				__FUNCTION__,
4415
+				__LINE__
4416
+			);
4417
+
4418
+			return false;
4419
+		}
4420
+
4421
+		if ($message_type instanceof EE_message_type) {
4422
+			$message_type_name = $message_type->name;
4423
+			EE_Error::add_success(
4424
+				sprintf(
4425
+					esc_html__(
4426
+						'%s message type has been successfully deactivated for the %s messenger.',
4427
+						'event_espresso'
4428
+					),
4429
+					ucwords($message_type->label['singular']),
4430
+					ucwords($messenger->label['singular'])
4431
+				)
4432
+			);
4433
+		} else {
4434
+			$message_type_name = '';
4435
+			EE_Error::add_success(
4436
+				sprintf(
4437
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
+					ucwords($messenger->label['singular'])
4439
+				)
4440
+			);
4441
+		}
4442
+
4443
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
+		if (
4445
+			$messenger->name === 'html'
4446
+			&& (
4447
+				is_null($message_type)
4448
+				|| $message_type_name === 'invoice'
4449
+			)
4450
+		) {
4451
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
+			if ($count_updated > 0) {
4454
+				$msg = $message_type_name === 'invoice'
4455
+					? esc_html__(
4456
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4457
+						'event_espresso'
4458
+					)
4459
+					: esc_html__(
4460
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4461
+						'event_espresso'
4462
+					);
4463
+				EE_Error::add_attention($msg);
4464
+			}
4465
+		}
4466
+
4467
+		return true;
4468
+	}
4469
+
4470
+
4471
+	/**
4472
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
+	 *
4474
+	 * @throws DomainException
4475
+	 * @throws EE_Error
4476
+	 * @throws EE_Error
4477
+	 */
4478
+	public function update_mt_form()
4479
+	{
4480
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
+			EE_Error::add_error(
4482
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
+				__FILE__,
4484
+				__FUNCTION__,
4485
+				__LINE__
4486
+			);
4487
+			$this->_return_json();
4488
+		}
4489
+
4490
+		$message_types = $this->get_installed_message_types();
4491
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4492
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
+
4495
+		$this->_template_args['success'] = true;
4496
+		$this->_template_args['content'] = $content;
4497
+		$this->_return_json();
4498
+	}
4499
+
4500
+
4501
+	/**
4502
+	 * this handles saving the settings for a messenger or message type
4503
+	 *
4504
+	 * @throws EE_Error
4505
+	 * @throws EE_Error
4506
+	 */
4507
+	public function save_settings()
4508
+	{
4509
+		$type = $this->request->getRequestParam('type');
4510
+		if (! $type) {
4511
+			EE_Error::add_error(
4512
+				esc_html__(
4513
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
+					'event_espresso'
4515
+				),
4516
+				__FILE__,
4517
+				__FUNCTION__,
4518
+				__LINE__
4519
+			);
4520
+			$this->_template_args['error'] = true;
4521
+			$this->_return_json();
4522
+		}
4523
+
4524
+
4525
+		if ($type === 'messenger') {
4526
+			// this should be an array.
4527
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
+			$messenger = $settings['messenger'];
4529
+			// remove messenger and message_types from settings array
4530
+			unset($settings['messenger'], $settings['message_types']);
4531
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
+		} elseif ($type === 'message_type') {
4533
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
+			$messenger    = $settings['messenger'];
4535
+			$message_type = $settings['message_type'];
4536
+			// remove messenger and message_types from settings array
4537
+			unset($settings['messenger'], $settings['message_types']);
4538
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
+		}
4540
+
4541
+		// okay we should have the data all setup.  Now we just update!
4542
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4543
+
4544
+		if ($success) {
4545
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
+		} else {
4547
+			EE_Error::add_error(
4548
+				esc_html__('Settings did not get updated', 'event_espresso'),
4549
+				__FILE__,
4550
+				__FUNCTION__,
4551
+				__LINE__
4552
+			);
4553
+		}
4554
+
4555
+		$this->_template_args['success'] = $success;
4556
+		$this->_return_json();
4557
+	}
4558
+
4559
+
4560
+
4561
+
4562
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4563
+
4564
+
4565
+	/**
4566
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
+	 * However, this does not send immediately, it just queues for sending.
4568
+	 *
4569
+	 * @throws EE_Error
4570
+	 * @throws InvalidDataTypeException
4571
+	 * @throws InvalidInterfaceException
4572
+	 * @throws InvalidArgumentException
4573
+	 * @throws ReflectionException
4574
+	 * @since 4.9.0
4575
+	 */
4576
+	protected function _generate_now()
4577
+	{
4578
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
+		$this->_redirect_after_action(false, '', '', [], true);
4580
+	}
4581
+
4582
+
4583
+	/**
4584
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4586
+	 *
4587
+	 * @throws EE_Error
4588
+	 * @throws InvalidDataTypeException
4589
+	 * @throws InvalidInterfaceException
4590
+	 * @throws InvalidArgumentException
4591
+	 * @throws ReflectionException
4592
+	 * @since 4.9.0
4593
+	 */
4594
+	protected function _generate_and_send_now()
4595
+	{
4596
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
+		$this->_redirect_after_action(false, '', '', [], true);
4598
+	}
4599
+
4600
+
4601
+	/**
4602
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
+	 *
4604
+	 * @throws EE_Error
4605
+	 * @throws InvalidDataTypeException
4606
+	 * @throws InvalidInterfaceException
4607
+	 * @throws InvalidArgumentException
4608
+	 * @throws ReflectionException
4609
+	 * @since 4.9.0
4610
+	 */
4611
+	protected function _queue_for_resending()
4612
+	{
4613
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
+		$this->_redirect_after_action(false, '', '', [], true);
4615
+	}
4616
+
4617
+
4618
+	/**
4619
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
+	 *
4621
+	 * @throws EE_Error
4622
+	 * @throws InvalidDataTypeException
4623
+	 * @throws InvalidInterfaceException
4624
+	 * @throws InvalidArgumentException
4625
+	 * @throws ReflectionException
4626
+	 * @since 4.9.0
4627
+	 */
4628
+	protected function _send_now()
4629
+	{
4630
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
+		$this->_redirect_after_action(false, '', '', [], true);
4632
+	}
4633
+
4634
+
4635
+	/**
4636
+	 * Deletes EE_messages for IDs in the request.
4637
+	 *
4638
+	 * @throws EE_Error
4639
+	 * @throws InvalidDataTypeException
4640
+	 * @throws InvalidInterfaceException
4641
+	 * @throws InvalidArgumentException
4642
+	 * @since 4.9.0
4643
+	 */
4644
+	protected function _delete_ee_messages()
4645
+	{
4646
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4647
+		$deleted_count = 0;
4648
+		foreach ($MSG_IDs as $MSG_ID) {
4649
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
+				$deleted_count++;
4651
+			}
4652
+		}
4653
+		if ($deleted_count) {
4654
+			EE_Error::add_success(
4655
+				esc_html(
4656
+					_n(
4657
+						'Message successfully deleted',
4658
+						'Messages successfully deleted',
4659
+						$deleted_count,
4660
+						'event_espresso'
4661
+					)
4662
+				)
4663
+			);
4664
+		} else {
4665
+			EE_Error::add_error(
4666
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
+				__FILE__,
4668
+				__FUNCTION__,
4669
+				__LINE__
4670
+			);
4671
+		}
4672
+		$this->_redirect_after_action(false, '', '', [], true);
4673
+	}
4674
+
4675
+
4676
+	/**
4677
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
+	 *
4679
+	 * @return array
4680
+	 * @since 4.9.0
4681
+	 */
4682
+	protected function _get_msg_ids_from_request()
4683
+	{
4684
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
+		if (empty($MSG_IDs)) {
4686
+			return [];
4687
+		}
4688
+		// if 'MSG_ID' was just a single ID (not an array)
4689
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
+			? $MSG_IDs
4693
+			: array_keys($MSG_IDs);
4694
+	}
4695 4695
 }
Please login to merge, or discard this patch.
admin/extend/messages/espresso_events_Messages_Hooks_Extend.class.php 2 patches
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -16,282 +16,282 @@
 block discarded – undo
16 16
 class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks
17 17
 {
18 18
 
19
-    /**
20
-     * @var Messages_Admin_Page
21
-     */
22
-    protected $_page_object;
23
-
24
-
25
-    /**
26
-     * espresso_events_Messages_Hooks_Extend constructor.
27
-     *
28
-     * @param EE_Admin_Page $admin_page
29
-     * @throws EE_Error
30
-     */
31
-    public function __construct(EE_Admin_Page $admin_page)
32
-    {
33
-        /**
34
-         * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
35
-         */
36
-        if (
37
-            ! EE_Registry::instance()->CAP->current_user_can(
38
-                'ee_edit_messages',
39
-                'messages_events_editor_metabox'
40
-            )
41
-        ) {
42
-            return;
43
-        }
44
-        add_filter(
45
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
46
-            [$this, 'caf_updates'],
47
-            10
48
-        );
49
-        add_action(
50
-            'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
51
-            [$this, 'duplicate_custom_message_settings'],
52
-            10,
53
-            2
54
-        );
55
-        parent::__construct($admin_page);
56
-    }
57
-
58
-
59
-    /**
60
-     * extending the properties set in espresso_events_Messages_Hooks
61
-     *
62
-     * @access protected
63
-     * @return void
64
-     */
65
-    protected function _extend_properties()
66
-    {
67
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
68
-        $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
69
-        $this->_metaboxes = [
70
-            0 => [
71
-                'page_route' => ['edit', 'create_new'],
72
-                'func'       => 'messages_metabox',
73
-                'label'      => esc_html__('Notifications', 'event_espresso'),
74
-                'priority'   => 'high',
75
-            ],
76
-        ];
77
-
78
-        // see explanation for layout in EE_Admin_Hooks
79
-        $this->_scripts_styles = [
80
-            'registers' => [
81
-                'events_msg_admin'     => [
82
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
83
-                    'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
84
-                ],
85
-                'events_msg_admin_css' => [
86
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
87
-                    'type' => 'css',
88
-                ],
89
-            ],
90
-            'enqueues'  => [
91
-                'events_msg_admin'     => ['edit', 'create_new'],
92
-                'events_msg_admin_css' => ['edit', 'create_new'],
93
-            ],
94
-        ];
95
-    }
96
-
97
-
98
-    public function caf_updates($update_callbacks)
99
-    {
100
-        $update_callbacks[] = [$this, 'attach_evt_message_templates'];
101
-        return $update_callbacks;
102
-    }
103
-
104
-
105
-    /**
106
-     * Handles attaching Message Templates to the Event on save.
107
-     *
108
-     * @param EE_Event $event EE event object
109
-     * @param array    $data  The request data from the form
110
-     * @return bool success or fail
111
-     * @throws EE_Error
112
-     * @throws ReflectionException
113
-     */
114
-    public function attach_evt_message_templates($event, $data)
115
-    {
116
-        // first we remove all existing relations on the Event for message types.
117
-        $event->_remove_relations('Message_Template_Group');
118
-        // now let's just loop through the selected templates and add relations!
119
-        if (isset($data['event_message_templates_relation'])) {
120
-            foreach ($data['event_message_templates_relation'] as $grp_ID) {
121
-                $event->_add_relation_to($grp_ID, 'Message_Template_Group');
122
-            }
123
-        }
124
-        // now save
125
-        return $event->save();
126
-    }
127
-
128
-
129
-    /**
130
-     * @param $event
131
-     * @param $callback_args
132
-     * @return string
133
-     * @throws EE_Error
134
-     * @throws ReflectionException
135
-     */
136
-    public function messages_metabox($event, $callback_args)
137
-    {
138
-        // convert 'evt_id' to 'EVT_ID'
139
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
140
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
141
-        $EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int');
142
-        $this->request->setRequestParam('EVT_ID', $EVT_ID);
143
-
144
-        // get the active messengers (b/c messenger objects have the active message templates)
145
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
146
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
147
-        $active_messengers        = $message_resource_manager->active_messengers();
148
-        $tabs                     = [];
149
-
150
-        // empty messengers?
151
-        // Note message types will always have at least one available because every messenger has a default message type
152
-        // associated with it (payment) if no other message types are selected.
153
-        if (empty($active_messengers)) {
154
-            $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
155
-                ['action' => 'settings'],
156
-                EE_MSG_ADMIN_URL
157
-            );
158
-            $error_msg        = sprintf(
159
-                esc_html__(
160
-                    'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
161
-                    'event_espresso'
162
-                ),
163
-                '<strong>',
164
-                '</strong>',
165
-                '<a href="' . esc_url_raw($msg_activate_url) . '">',
166
-                '</a>'
167
-            );
168
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
169
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
170
-
171
-            echo wp_kses($error_content, AllowedTags::getAllowedTags());
172
-            echo wp_kses($internal_content, AllowedTags::getAllowedTags());
173
-            return '';
174
-        }
175
-
176
-        // get content for active messengers
177
-        foreach ($active_messengers as $name => $messenger) {
178
-            // first check if there are any active message types for this messenger.
179
-            $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
180
-            if (empty($active_mts)) {
181
-                continue;
182
-            }
183
-
184
-            $tab_content = $messenger->get_messenger_admin_page_content(
185
-                'events',
186
-                'edit',
187
-                ['event' => $EVT_ID]
188
-            );
189
-
190
-            if (! empty($tab_content)) {
191
-                $tabs[ $name ] = $tab_content;
192
-            }
193
-        }
194
-
195
-        // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
196
-        $tabbed_content = EEH_Tabbed_Content::display($tabs);
197
-        if ($tabbed_content instanceof WP_Error) {
198
-            $tabbed_content = $tabbed_content->get_error_message();
199
-        }
200
-
201
-        $notices = '
19
+	/**
20
+	 * @var Messages_Admin_Page
21
+	 */
22
+	protected $_page_object;
23
+
24
+
25
+	/**
26
+	 * espresso_events_Messages_Hooks_Extend constructor.
27
+	 *
28
+	 * @param EE_Admin_Page $admin_page
29
+	 * @throws EE_Error
30
+	 */
31
+	public function __construct(EE_Admin_Page $admin_page)
32
+	{
33
+		/**
34
+		 * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
35
+		 */
36
+		if (
37
+			! EE_Registry::instance()->CAP->current_user_can(
38
+				'ee_edit_messages',
39
+				'messages_events_editor_metabox'
40
+			)
41
+		) {
42
+			return;
43
+		}
44
+		add_filter(
45
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
46
+			[$this, 'caf_updates'],
47
+			10
48
+		);
49
+		add_action(
50
+			'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
51
+			[$this, 'duplicate_custom_message_settings'],
52
+			10,
53
+			2
54
+		);
55
+		parent::__construct($admin_page);
56
+	}
57
+
58
+
59
+	/**
60
+	 * extending the properties set in espresso_events_Messages_Hooks
61
+	 *
62
+	 * @access protected
63
+	 * @return void
64
+	 */
65
+	protected function _extend_properties()
66
+	{
67
+		define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
68
+		$this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
69
+		$this->_metaboxes = [
70
+			0 => [
71
+				'page_route' => ['edit', 'create_new'],
72
+				'func'       => 'messages_metabox',
73
+				'label'      => esc_html__('Notifications', 'event_espresso'),
74
+				'priority'   => 'high',
75
+			],
76
+		];
77
+
78
+		// see explanation for layout in EE_Admin_Hooks
79
+		$this->_scripts_styles = [
80
+			'registers' => [
81
+				'events_msg_admin'     => [
82
+					'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
83
+					'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
84
+				],
85
+				'events_msg_admin_css' => [
86
+					'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
87
+					'type' => 'css',
88
+				],
89
+			],
90
+			'enqueues'  => [
91
+				'events_msg_admin'     => ['edit', 'create_new'],
92
+				'events_msg_admin_css' => ['edit', 'create_new'],
93
+			],
94
+		];
95
+	}
96
+
97
+
98
+	public function caf_updates($update_callbacks)
99
+	{
100
+		$update_callbacks[] = [$this, 'attach_evt_message_templates'];
101
+		return $update_callbacks;
102
+	}
103
+
104
+
105
+	/**
106
+	 * Handles attaching Message Templates to the Event on save.
107
+	 *
108
+	 * @param EE_Event $event EE event object
109
+	 * @param array    $data  The request data from the form
110
+	 * @return bool success or fail
111
+	 * @throws EE_Error
112
+	 * @throws ReflectionException
113
+	 */
114
+	public function attach_evt_message_templates($event, $data)
115
+	{
116
+		// first we remove all existing relations on the Event for message types.
117
+		$event->_remove_relations('Message_Template_Group');
118
+		// now let's just loop through the selected templates and add relations!
119
+		if (isset($data['event_message_templates_relation'])) {
120
+			foreach ($data['event_message_templates_relation'] as $grp_ID) {
121
+				$event->_add_relation_to($grp_ID, 'Message_Template_Group');
122
+			}
123
+		}
124
+		// now save
125
+		return $event->save();
126
+	}
127
+
128
+
129
+	/**
130
+	 * @param $event
131
+	 * @param $callback_args
132
+	 * @return string
133
+	 * @throws EE_Error
134
+	 * @throws ReflectionException
135
+	 */
136
+	public function messages_metabox($event, $callback_args)
137
+	{
138
+		// convert 'evt_id' to 'EVT_ID'
139
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
140
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
141
+		$EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int');
142
+		$this->request->setRequestParam('EVT_ID', $EVT_ID);
143
+
144
+		// get the active messengers (b/c messenger objects have the active message templates)
145
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
146
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
147
+		$active_messengers        = $message_resource_manager->active_messengers();
148
+		$tabs                     = [];
149
+
150
+		// empty messengers?
151
+		// Note message types will always have at least one available because every messenger has a default message type
152
+		// associated with it (payment) if no other message types are selected.
153
+		if (empty($active_messengers)) {
154
+			$msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
155
+				['action' => 'settings'],
156
+				EE_MSG_ADMIN_URL
157
+			);
158
+			$error_msg        = sprintf(
159
+				esc_html__(
160
+					'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
161
+					'event_espresso'
162
+				),
163
+				'<strong>',
164
+				'</strong>',
165
+				'<a href="' . esc_url_raw($msg_activate_url) . '">',
166
+				'</a>'
167
+			);
168
+			$error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
169
+			$internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
170
+
171
+			echo wp_kses($error_content, AllowedTags::getAllowedTags());
172
+			echo wp_kses($internal_content, AllowedTags::getAllowedTags());
173
+			return '';
174
+		}
175
+
176
+		// get content for active messengers
177
+		foreach ($active_messengers as $name => $messenger) {
178
+			// first check if there are any active message types for this messenger.
179
+			$active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
180
+			if (empty($active_mts)) {
181
+				continue;
182
+			}
183
+
184
+			$tab_content = $messenger->get_messenger_admin_page_content(
185
+				'events',
186
+				'edit',
187
+				['event' => $EVT_ID]
188
+			);
189
+
190
+			if (! empty($tab_content)) {
191
+				$tabs[ $name ] = $tab_content;
192
+			}
193
+		}
194
+
195
+		// we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
196
+		$tabbed_content = EEH_Tabbed_Content::display($tabs);
197
+		if ($tabbed_content instanceof WP_Error) {
198
+			$tabbed_content = $tabbed_content->get_error_message();
199
+		}
200
+
201
+		$notices = '
202 202
         <div id="espresso-ajax-loading" class="ajax-loader-grey">
203 203
             <span class="ee-spinner ee-spin"></span>
204 204
             <span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span>
205 205
         </div>
206 206
         <div class="ee-notices"></div>';
207 207
 
208
-        if (defined('DOING_AJAX')) {
209
-            return $tabbed_content;
210
-        }
211
-
212
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
213
-        echo wp_kses($notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>', AllowedTags::getWithFormTags());
214
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
215
-        return '';
216
-    }
217
-
218
-
219
-    /**
220
-     * Ajax callback for ee_msgs_create_new_custom ajax request.
221
-     * Takes incoming GRP_ID and name and description values from ajax request
222
-     * to create a new custom template based off of the incoming GRP_ID.
223
-     *
224
-     * @access public
225
-     * @return void
226
-     * @throws EE_Error
227
-     * @throws ReflectionException
228
-     */
229
-    public function create_new_custom()
230
-    {
231
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
232
-            wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
233
-        }
234
-
235
-        /** @var RequestInterface $request */
236
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
237
-
238
-        // let's clean up the request data a bit for downstream usage of name and description.
239
-        $templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', '');
240
-        $request->setRequestParam('templateName', $templateName);
241
-        $templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', '');
242
-        $request->setRequestParam('templateDescription', $templateDescription);
243
-
244
-        // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
245
-        $this->_set_page_object();
246
-
247
-        // is this a template switch if so EE_Admin_Page child needs this object
248
-        $this->_page_object->set_hook_object($this);
249
-
250
-        $this->_page_object->add_message_template(
251
-            $this->request->getRequestParam('messageType', ''),
252
-            $this->request->getRequestParam('messenger', ''),
253
-            $this->request->getRequestParam('group_ID', 0, 'int')
254
-        );
255
-    }
256
-
257
-
258
-    public function create_new_admin_footer()
259
-    {
260
-        $this->edit_admin_footer();
261
-    }
262
-
263
-
264
-    /**
265
-     * This is the dynamic method for this class
266
-     * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
267
-     *
268
-     * @return void
269
-     * @throws DomainException
270
-     */
271
-    public function edit_admin_footer()
272
-    {
273
-        EEH_Template::display_template(
274
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
275
-        );
276
-    }
277
-
278
-
279
-    /**
280
-     * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
281
-     * the assigned custom message templates.
282
-     *
283
-     * @param EE_Event $new_event
284
-     * @param EE_Event $original_event
285
-     * @throws EE_Error
286
-     * @throws ReflectionException
287
-     */
288
-    public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
289
-    {
290
-        $message_template_groups = $original_event->get_many_related('Message_Template_Group');
291
-        foreach ($message_template_groups as $message_template_group) {
292
-            $new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
293
-        }
294
-        // save new event
295
-        $new_event->save();
296
-    }
208
+		if (defined('DOING_AJAX')) {
209
+			return $tabbed_content;
210
+		}
211
+
212
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
213
+		echo wp_kses($notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>', AllowedTags::getWithFormTags());
214
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
215
+		return '';
216
+	}
217
+
218
+
219
+	/**
220
+	 * Ajax callback for ee_msgs_create_new_custom ajax request.
221
+	 * Takes incoming GRP_ID and name and description values from ajax request
222
+	 * to create a new custom template based off of the incoming GRP_ID.
223
+	 *
224
+	 * @access public
225
+	 * @return void
226
+	 * @throws EE_Error
227
+	 * @throws ReflectionException
228
+	 */
229
+	public function create_new_custom()
230
+	{
231
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
232
+			wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
233
+		}
234
+
235
+		/** @var RequestInterface $request */
236
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
237
+
238
+		// let's clean up the request data a bit for downstream usage of name and description.
239
+		$templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', '');
240
+		$request->setRequestParam('templateName', $templateName);
241
+		$templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', '');
242
+		$request->setRequestParam('templateDescription', $templateDescription);
243
+
244
+		// set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
245
+		$this->_set_page_object();
246
+
247
+		// is this a template switch if so EE_Admin_Page child needs this object
248
+		$this->_page_object->set_hook_object($this);
249
+
250
+		$this->_page_object->add_message_template(
251
+			$this->request->getRequestParam('messageType', ''),
252
+			$this->request->getRequestParam('messenger', ''),
253
+			$this->request->getRequestParam('group_ID', 0, 'int')
254
+		);
255
+	}
256
+
257
+
258
+	public function create_new_admin_footer()
259
+	{
260
+		$this->edit_admin_footer();
261
+	}
262
+
263
+
264
+	/**
265
+	 * This is the dynamic method for this class
266
+	 * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
267
+	 *
268
+	 * @return void
269
+	 * @throws DomainException
270
+	 */
271
+	public function edit_admin_footer()
272
+	{
273
+		EEH_Template::display_template(
274
+			EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
275
+		);
276
+	}
277
+
278
+
279
+	/**
280
+	 * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
281
+	 * the assigned custom message templates.
282
+	 *
283
+	 * @param EE_Event $new_event
284
+	 * @param EE_Event $original_event
285
+	 * @throws EE_Error
286
+	 * @throws ReflectionException
287
+	 */
288
+	public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
289
+	{
290
+		$message_template_groups = $original_event->get_many_related('Message_Template_Group');
291
+		foreach ($message_template_groups as $message_template_group) {
292
+			$new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
293
+		}
294
+		// save new event
295
+		$new_event->save();
296
+	}
297 297
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      */
65 65
     protected function _extend_properties()
66 66
     {
67
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
67
+        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/');
68 68
         $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
69 69
         $this->_metaboxes = [
70 70
             0 => [
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
         $this->_scripts_styles = [
80 80
             'registers' => [
81 81
                 'events_msg_admin'     => [
82
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
82
+                    'url'     => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js',
83 83
                     'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
84 84
                 ],
85 85
                 'events_msg_admin_css' => [
86
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
86
+                    'url'  => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css',
87 87
                     'type' => 'css',
88 88
                 ],
89 89
             ],
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
                 ['action' => 'settings'],
156 156
                 EE_MSG_ADMIN_URL
157 157
             );
158
-            $error_msg        = sprintf(
158
+            $error_msg = sprintf(
159 159
                 esc_html__(
160 160
                     'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
161 161
                     'event_espresso'
162 162
                 ),
163 163
                 '<strong>',
164 164
                 '</strong>',
165
-                '<a href="' . esc_url_raw($msg_activate_url) . '">',
165
+                '<a href="'.esc_url_raw($msg_activate_url).'">',
166 166
                 '</a>'
167 167
             );
168
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
169
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
168
+            $error_content    = '<div class="error"><p>'.$error_msg.'</p></div>';
169
+            $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>';
170 170
 
171 171
             echo wp_kses($error_content, AllowedTags::getAllowedTags());
172 172
             echo wp_kses($internal_content, AllowedTags::getAllowedTags());
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
                 ['event' => $EVT_ID]
188 188
             );
189 189
 
190
-            if (! empty($tab_content)) {
191
-                $tabs[ $name ] = $tab_content;
190
+            if ( ! empty($tab_content)) {
191
+                $tabs[$name] = $tab_content;
192 192
             }
193 193
         }
194 194
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         $notices = '
202 202
         <div id="espresso-ajax-loading" class="ajax-loader-grey">
203 203
             <span class="ee-spinner ee-spin"></span>
204
-            <span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span>
204
+            <span class="hidden">' . esc_html__('loading...', 'event_espresso').'</span>
205 205
         </div>
206 206
         <div class="ee-notices"></div>';
207 207
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         }
211 211
 
212 212
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
213
-        echo wp_kses($notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>', AllowedTags::getWithFormTags());
213
+        echo wp_kses($notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>', AllowedTags::getWithFormTags());
214 214
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
215 215
         return '';
216 216
     }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function create_new_custom()
230 230
     {
231
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
231
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
232 232
             wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
233 233
         }
234 234
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
     public function edit_admin_footer()
272 272
     {
273 273
         EEH_Template::display_template(
274
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
274
+            EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php'
275 275
         );
276 276
     }
277 277
 
Please login to merge, or discard this patch.
messages/templates/ee_msg_details_main_add_meta_box.template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
         </select>
59 59
 
60 60
         <!-- events if we don't have an EVENT_ID -->
61
-        <?php if (! empty($active_events)) : ?>
61
+        <?php if ( ! empty($active_events)) : ?>
62 62
             <label for="EVT_ID_select"><?php esc_html_e('Select Event', 'event_espresso'); ?></label>
63 63
             <select name="EVT_ID" id="EVT_ID_select">
64 64
                 <?php foreach ($active_events as $event) : ?>
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 
19 19
     <h4 class="admin-primary-mbox-h4">
20 20
         <?php
21
-        echo ($event_name
22
-            ? sprintf(
23
-            /* translators: %s: event name */
24
-                esc_html__('%1$s Custom Template', 'event_espresso'),
25
-                $event_name
26
-            )
27
-            : '');
28
-        ?>
21
+		echo ($event_name
22
+			? sprintf(
23
+			/* translators: %s: event name */
24
+				esc_html__('%1$s Custom Template', 'event_espresso'),
25
+				$event_name
26
+			)
27
+			: '');
28
+		?>
29 29
     </h4>
30 30
     <p><?php echo wp_kses($action_message, AllowedTags::getWithFormTags()); ?></p>
31 31
 
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
     >
36 36
         <input type="hidden" id="evt_id" name="EVT_ID" value="<?php echo absint($EVT_ID) ?: ''; ?>" />
37 37
         <?php
38
-        if (isset($hidden_fields)) {
39
-            echo wp_kses($hidden_fields, AllowedTags::getWithFormTags());
40
-        } ?>
38
+		if (isset($hidden_fields)) {
39
+			echo wp_kses($hidden_fields, AllowedTags::getWithFormTags());
40
+		} ?>
41 41
         <!--active_messengers -->
42 42
         <label for="MTP-messenger"><?php esc_html_e('Select Messenger', 'event_espresso'); ?></label>
43 43
         <select name="MTP_messenger" id="MTP-messenger">
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.30.rc.008');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.30.rc.008');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.