Completed
Branch dev (22bd0c)
by
unknown
24:44 queued 18:15
created
admin_pages/maintenance/templates/ee_migration_page.template.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -36,55 +36,55 @@  discard block
 block discarded – undo
36 36
             <h3 class="espresso-header ee-status-bg--info">
37 37
                 <span class="dashicons dashicons-flag ee-icon-size-22"></span>
38 38
                 <?php
39
-                echo esc_html(
40
-                    apply_filters(
41
-                        'FHEE__ee_migration_page__header',
42
-                        sprintf(
43
-                            __("Your Event Espresso data needs to be updated.", "event_espresso"),
44
-                            $current_db_state,
45
-                            $next_db_state
46
-                        ),
47
-                        $current_db_state,
48
-                        $next_db_state
49
-                    )
50
-                );
51
-                ?>
39
+				echo esc_html(
40
+					apply_filters(
41
+						'FHEE__ee_migration_page__header',
42
+						sprintf(
43
+							__("Your Event Espresso data needs to be updated.", "event_espresso"),
44
+							$current_db_state,
45
+							$next_db_state
46
+						),
47
+						$current_db_state,
48
+						$next_db_state
49
+					)
50
+				);
51
+				?>
52 52
             </h3>
53 53
         <?php } elseif ($show_most_recent_migration) { ?>
54 54
             <h3 class="espresso-header ee-status-bg--info">
55 55
                 <span class="dashicons dashicons-awards ee-icon-size-22"></span>
56 56
                 <?php echo esc_html(
57
-                    apply_filters(
58
-                        'FHEE__ee_migration_page__done_migration_header',
59
-                        sprintf(
60
-                            __(
61
-                                'Congratulations! Your database is "up-to-date" and you are ready to begin using %s',
62
-                                "event_espresso"
63
-                            ),
64
-                            $ultimate_db_state
65
-                        )
66
-                    )
67
-                ); ?>
57
+					apply_filters(
58
+						'FHEE__ee_migration_page__done_migration_header',
59
+						sprintf(
60
+							__(
61
+								'Congratulations! Your database is "up-to-date" and you are ready to begin using %s',
62
+								"event_espresso"
63
+							),
64
+							$ultimate_db_state
65
+						)
66
+					)
67
+				); ?>
68 68
             </h3>
69 69
             <p>
70 70
                 <?php echo esc_html(
71
-                    apply_filters(
72
-                        'FHEE__ee_migration_page__p_after_done_migration_header',
73
-                        sprintf(
74
-                            __(
75
-                                "Time to find out about all the great new features %s has to offer.",
76
-                                "event_espresso"
77
-                            ),
78
-                            $ultimate_db_state
79
-                        )
80
-                    )
81
-                ); ?> &nbsp;
71
+					apply_filters(
72
+						'FHEE__ee_migration_page__p_after_done_migration_header',
73
+						sprintf(
74
+							__(
75
+								"Time to find out about all the great new features %s has to offer.",
76
+								"event_espresso"
77
+							),
78
+							$ultimate_db_state
79
+						)
80
+					)
81
+				); ?> &nbsp;
82 82
                 <b>
83 83
                     <a class="button--primary"
84 84
                        id='get-started-after-migrate'
85 85
                        href="<?php
86
-                        echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php')));
87
-                        ?>"
86
+						echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php')));
87
+						?>"
88 88
                     >
89 89
                         <?php esc_html_e("Let's Get Started", "event_espresso"); ?>&nbsp;
90 90
                         <span class="dashicons dashicons-arrow-right ee-icon-size-22" style="margin:0;"></span>
@@ -95,46 +95,46 @@  discard block
 block discarded – undo
95 95
 
96 96
 
97 97
         <?php
98
-        if ($show_backup_db_text) {
99
-            echo wp_kses($migration_options_html, AllowedTags::getAllowedTags());
100
-        } ?>
98
+		if ($show_backup_db_text) {
99
+			echo wp_kses($migration_options_html, AllowedTags::getAllowedTags());
100
+		} ?>
101 101
 
102 102
         <?php
103
-        if ($show_most_recent_migration) {
104
-            if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) {
105
-                if ($most_recent_migration->can_continue()) {
106
-                    // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?>
103
+		if ($show_most_recent_migration) {
104
+			if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) {
105
+				if ($most_recent_migration->can_continue()) {
106
+					// tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?>
107 107
                     <h3 class="espresso-header ee-status-bg--info">
108 108
                         <span class="dashicons dashicons-star-half ee-icon-size-22"></span>
109 109
                         <?php printf(
110
-                            esc_html__(
111
-                                "It appears that your previous Database Update (%s) is incomplete, and should be resumed",
112
-                                "event_espresso"
113
-                            ),
114
-                            $most_recent_migration->pretty_name()
115
-                        ); ?>
110
+							esc_html__(
111
+								"It appears that your previous Database Update (%s) is incomplete, and should be resumed",
112
+								"event_espresso"
113
+							),
114
+							$most_recent_migration->pretty_name()
115
+						); ?>
116 116
                     </h3>
117 117
                     <?php
118
-                } elseif ($most_recent_migration->is_broken()) {
119
-                    // tell the user the migration failed, and they should notify EE?>
118
+				} elseif ($most_recent_migration->is_broken()) {
119
+					// tell the user the migration failed, and they should notify EE?>
120 120
                     <h3 class="espresso-header ee-status-bg--info">
121 121
                         <span class="dashicons dashicons-no ee-icon-size-22"></span>
122 122
                         <?php echo esc_html($most_recent_migration->get_feedback_message()) ?>
123 123
                     </h3>
124 124
                     <?php
125
-                }
126
-                // display errors or not of the most recent migration ran
127
-                if ($most_recent_migration->get_errors()) {
128
-                    ?>
125
+				}
126
+				// display errors or not of the most recent migration ran
127
+				if ($most_recent_migration->get_errors()) {
128
+					?>
129 129
                     <div class="ee-attention">
130 130
                         <strong>
131 131
                             <?php printf(
132
-                                esc_html__(
133
-                                    "Warnings occurred during your last Database Update (%s):",
134
-                                    'event_espresso'
135
-                                ),
136
-                                $most_recent_migration->pretty_name()
137
-                            ); ?>
132
+								esc_html__(
133
+									"Warnings occurred during your last Database Update (%s):",
134
+									'event_espresso'
135
+								),
136
+								$most_recent_migration->pretty_name()
137
+							); ?>
138 138
                         </strong>
139 139
                         <a id="show-hide-migration-warnings" class="display-the-hidden">
140 140
                             <?php esc_html_e("Show Warnings", 'event_espresso'); ?>
@@ -146,32 +146,32 @@  discard block
 block discarded – undo
146 146
                         </ul>
147 147
                     </div>
148 148
                     <?php
149
-                } else {
150
-                    // there were no errors during the last migration, just say so?>
149
+				} else {
150
+					// there were no errors during the last migration, just say so?>
151 151
                     <h2>
152 152
                         <?php printf(
153
-                            esc_html__(
154
-                                "The last Database Update (%s) ran successfully without errors.",
155
-                                "event_espresso"
156
-                            ),
157
-                            $most_recent_migration->pretty_name()
158
-                        ); ?>
153
+							esc_html__(
154
+								"The last Database Update (%s) ran successfully without errors.",
155
+								"event_espresso"
156
+							),
157
+							$most_recent_migration->pretty_name()
158
+						); ?>
159 159
                     </h2>
160 160
                     <?php
161
-                }
162
-            }
163
-        }
164
-        // end of: if ( $show_most_recent_migration )
165
-        ?>
161
+				}
162
+			}
163
+		}
164
+		// end of: if ( $show_most_recent_migration )
165
+		?>
166 166
 
167 167
     </div>
168 168
     <!--end of #migration-prep-->
169 169
 
170 170
     <?php
171
-    if ($show_migration_progress) { ?>
171
+	if ($show_migration_progress) { ?>
172 172
         <div id='migration-monitor' <?php echo ($show_backup_db_text ? "style='display:none'" : ''); ?>>
173 173
             <?php
174
-            if ($show_backup_db_text) { ?>
174
+			if ($show_backup_db_text) { ?>
175 175
                 <p>
176 176
                     <a class="toggle-migration-monitor small-text" style="cursor: pointer;">
177 177
                         <span class="dashicons dashicons-arrow-left-alt2" style="top:0;"></span>
@@ -181,19 +181,19 @@  discard block
 block discarded – undo
181 181
 
182 182
                 </p>
183 183
                 <?php
184
-            } ?>
184
+			} ?>
185 185
             <div id='progress-area'>
186 186
                 <h3 class="espresso-header ee-status-bg--info">
187 187
                     <?php
188
-                    echo sprintf(
189
-                        _n(
190
-                            "The following task needs to be performed:",
191
-                            "The following %s tasks need to be performed:",
192
-                            count($script_names),
193
-                            "event_espresso"
194
-                        ),
195
-                        count($script_names)
196
-                    ); ?>
188
+					echo sprintf(
189
+						_n(
190
+							"The following task needs to be performed:",
191
+							"The following %s tasks need to be performed:",
192
+							count($script_names),
193
+							"event_espresso"
194
+						),
195
+						count($script_names)
196
+					); ?>
197 197
                 </h3>
198 198
                 <ul style="list-style: inside;">
199 199
                     <?php foreach ($script_names as $script_name) { ?>
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
                 <?php if (count($script_names) > 1) { ?>
205 205
                     <p>
206 206
                         <?php esc_html_e(
207
-                            "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.",
208
-                            "event_espresso"
209
-                        ); ?>
207
+							"Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.",
208
+							"event_espresso"
209
+						); ?>
210 210
                     </p>
211 211
                 <?php } ?>
212 212
 
@@ -217,19 +217,19 @@  discard block
 block discarded – undo
217 217
                         </span>
218 218
                         <br />
219 219
                         <?php esc_html_e(
220
-                            "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.",
221
-                            "event_espresso"
222
-                        ); ?>
220
+							"Depending on the number of events and the complexity of the information in your database, this could take a few minutes.",
221
+							"event_espresso"
222
+						); ?>
223 223
                     </p>
224 224
                     <p>
225 225
                         <?php printf(
226
-                            esc_html__(
227
-                                "%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.",
228
-                                "event_espresso"
229
-                            ),
230
-                            '<strong>',
231
-                            '</strong>'
232
-                        ); ?>
226
+							esc_html__(
227
+								"%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.",
228
+								"event_espresso"
229
+							),
230
+							'<strong>',
231
+							'</strong>'
232
+						); ?>
233 233
                     </p>
234 234
                     <p>
235 235
                         <?php esc_html_e("Click the button below to begin the migration process.", "event_espresso") ?>
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 
246 246
                 <button id='start-migration' class='button button--primary'>
247 247
                     <?php echo ($show_continue_current_migration_script
248
-                        ? esc_html__("Continue Database Update", "event_espresso")
249
-                        : esc_html__("Begin Database Update", "event_espresso")); ?>
248
+						? esc_html__("Continue Database Update", "event_espresso")
249
+						: esc_html__("Begin Database Update", "event_espresso")); ?>
250 250
                 </button>
251 251
                 <br class="clear" />
252 252
 
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
         </div>
263 263
 
264 264
         <?php
265
-    }
266
-    if ($show_maintenance_switch) {
267
-        ?>
265
+	}
266
+	if ($show_maintenance_switch) {
267
+		?>
268 268
         <h2>
269 269
             <span class="dashicons dashicons-admin-tools"></span>
270 270
             <?php esc_html_e('Set Event Espresso Maintenance Mode', 'event_espresso'); ?>
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
                                    type='radio'
280 280
                                    value="0"
281 281
                                 <?php echo ($mMode_level === EE_Maintenance_Mode::level_0_not_in_maintenance
282
-                                    ? 'checked'
283
-                                    : '');
284
-                                ?>
282
+									? 'checked'
283
+									: '');
284
+								?>
285 285
                             />
286 286
                         </td>
287 287
                         <th align="left">
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
                             </label>
291 291
                             <p class='description' style="font-weight: normal;">
292 292
                                 <?php esc_html_e(
293
-                                    "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.",
294
-                                    "event_espresso"
295
-                                ); ?>
293
+									"This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.",
294
+									"event_espresso"
295
+								); ?>
296 296
                             </p>
297 297
                         </th>
298 298
                     </tr>
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
                                    type='radio'
304 304
                                    value="1"
305 305
                                 <?php echo ($mMode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance
306
-                                    ? 'checked'
307
-                                    : '');
308
-                                ?>
306
+									? 'checked'
307
+									: '');
308
+								?>
309 309
                             />
310 310
                         </td>
311 311
                         <th align="left">
@@ -314,9 +314,9 @@  discard block
 block discarded – undo
314 314
                             </label>
315 315
                             <p class='description' style="font-weight: normal;">
316 316
                                 <?php esc_html_e(
317
-                                    "This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.",
318
-                                    "event_espresso"
319
-                                ); ?>
317
+									"This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.",
318
+									"event_espresso"
319
+								); ?>
320 320
                             </p>
321 321
                         </th>
322 322
                     </tr>
@@ -330,6 +330,6 @@  discard block
 block discarded – undo
330 330
             </p>
331 331
         </form>
332 332
         <?php
333
-    } ?>
333
+	} ?>
334 334
 
335 335
 </div>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4643 added lines, -4643 removed lines patch added patch discarded remove patch
@@ -17,2683 +17,2683 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Messages_Admin_Page extends EE_Admin_Page
19 19
 {
20
-    /**
21
-     * @var EEM_Message
22
-     */
23
-    private $MSG_MODEL;
24
-
25
-    /**
26
-     * @var EEM_Message_Template
27
-     */
28
-    private $MTP_MODEL;
29
-
30
-    /**
31
-     * @var EEM_Message_Template_Group
32
-     */
33
-    private $MTG_MODEL;
34
-
35
-    /**
36
-     * @var EE_Message_Resource_Manager $_message_resource_manager
37
-     */
38
-    protected $_message_resource_manager;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $_active_message_type_name = '';
44
-
45
-    /**
46
-     * @var string
47
-     */
48
-    protected $_active_messenger_name = '';
49
-
50
-    /**
51
-     * @var EE_messenger $_active_messenger
52
-     */
53
-    protected $_active_messenger;
54
-
55
-    protected $_activate_meta_box_type;
56
-
57
-    protected $_current_message_meta_box;
58
-
59
-    protected $_current_message_meta_box_object;
60
-
61
-    protected $_context_switcher;
62
-
63
-    protected $_shortcodes           = [];
64
-
65
-    protected $_active_messengers    = [];
66
-
67
-    protected $_active_message_types = [];
68
-
69
-    /**
70
-     * @var EE_Message_Template_Group $_message_template_group
71
-     */
72
-    protected $_message_template_group;
73
-
74
-    protected $_m_mt_settings = [];
75
-
76
-
77
-    /**
78
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
-     * IF there is no group then it gets automatically set to the Default template pack.
80
-     *
81
-     * @since 4.5.0
82
-     *
83
-     * @var EE_Messages_Template_Pack
84
-     */
85
-    protected $_template_pack;
86
-
87
-
88
-    /**
89
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
-     * group is.  If there is no group then it automatically gets set to default.
91
-     *
92
-     * @since 4.5.0
93
-     *
94
-     * @var string
95
-     */
96
-    protected $_variation;
97
-
98
-
99
-    /**
100
-     * @param bool $routing
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    public function __construct($routing = true)
105
-    {
106
-        // make sure messages autoloader is running
107
-        EED_Messages::set_autoloaders();
108
-        parent::__construct($routing);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Message
114
-     * @throws EE_Error
115
-     */
116
-    public function getMsgModel()
117
-    {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
119
-            $this->MSG_MODEL = EEM_Message::instance();
120
-        }
121
-        return $this->MSG_MODEL;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return EEM_Message_Template
127
-     * @throws EE_Error
128
-     */
129
-    public function getMtpModel()
130
-    {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
-            $this->MTP_MODEL = EEM_Message_Template::instance();
133
-        }
134
-        return $this->MTP_MODEL;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return EEM_Message_Template_Group
140
-     * @throws EE_Error
141
-     */
142
-    public function getMtgModel()
143
-    {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
-        }
147
-        return $this->MTG_MODEL;
148
-    }
149
-
150
-
151
-    /**
152
-     * @throws EE_Error
153
-     * @throws ReflectionException
154
-     */
155
-    protected function _init_page_props()
156
-    {
157
-        $this->page_slug        = EE_MSG_PG_SLUG;
158
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
-        $this->_admin_base_path = EE_MSG_ADMIN;
161
-
162
-        $messenger    = $this->request->getRequestParam('messenger', '');
163
-        $message_type = $this->request->getRequestParam('message_type', '');
164
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
-
167
-        $this->_load_message_resource_manager();
168
-    }
169
-
170
-
171
-    /**
172
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
-     *
174
-     * @throws EE_Error
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     * @throws InvalidArgumentException
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _load_message_resource_manager()
181
-    {
182
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
-    }
184
-
185
-
186
-    /**
187
-     * @return array
188
-     * @throws EE_Error
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     * @deprecated 4.9.9.rc.014
193
-     */
194
-    public function get_messengers_for_list_table()
195
-    {
196
-        EE_Error::doing_it_wrong(
197
-            __METHOD__,
198
-            sprintf(
199
-                esc_html__(
200
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
-                    'event_espresso'
202
-                ),
203
-                'Messages_Admin_Page::get_messengers_select_input()'
204
-            ),
205
-            '4.9.9.rc.014'
206
-        );
207
-
208
-        $m_values          = [];
209
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
-        // setup messengers for selects
211
-        $i = 1;
212
-        foreach ($active_messengers as $active_messenger) {
213
-            if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
-                $i++;
217
-            }
218
-        }
219
-
220
-        return $m_values;
221
-    }
222
-
223
-
224
-    /**
225
-     * @return array
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @deprecated 4.9.9.rc.014
231
-     */
232
-    public function get_message_types_for_list_table()
233
-    {
234
-        EE_Error::doing_it_wrong(
235
-            __METHOD__,
236
-            sprintf(
237
-                esc_html__(
238
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
-                    'event_espresso'
240
-                ),
241
-                'Messages_Admin_Page::get_message_types_select_input()'
242
-            ),
243
-            '4.9.9.rc.014'
244
-        );
245
-
246
-        $mt_values       = [];
247
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
-        $i               = 1;
249
-        foreach ($active_messages as $active_message) {
250
-            if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
-                $i++;
254
-            }
255
-        }
256
-
257
-        return $mt_values;
258
-    }
259
-
260
-
261
-    /**
262
-     * @return array
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @deprecated 4.9.9.rc.014
268
-     */
269
-    public function get_contexts_for_message_types_for_list_table()
270
-    {
271
-        EE_Error::doing_it_wrong(
272
-            __METHOD__,
273
-            sprintf(
274
-                esc_html__(
275
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
-                    'event_espresso'
277
-                ),
278
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
-            ),
280
-            '4.9.9.rc.014'
281
-        );
282
-
283
-        $contexts                = [];
284
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
-        foreach ($active_message_contexts as $active_message) {
286
-            if ($active_message instanceof EE_Message) {
287
-                $message_type = $active_message->message_type_object();
288
-                if ($message_type instanceof EE_message_type) {
289
-                    $message_type_contexts = $message_type->get_contexts();
290
-                    foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
292
-                    }
293
-                }
294
-            }
295
-        }
296
-
297
-        return $contexts;
298
-    }
299
-
300
-
301
-    /**
302
-     * Generate select input with provided messenger options array.
303
-     *
304
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
-     *                                 labels.
306
-     * @return string
307
-     * @throws EE_Error
308
-     */
309
-    public function get_messengers_select_input($messenger_options)
310
-    {
311
-        // if empty or just one value then just return an empty string
312
-        if (
313
-            empty($messenger_options)
314
-            || ! is_array($messenger_options)
315
-            || count($messenger_options) === 1
316
-        ) {
317
-            return '';
318
-        }
319
-        // merge in default
320
-        $messenger_options = array_merge(
321
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
-            $messenger_options
323
-        );
324
-        $input             = new EE_Select_Input(
325
-            $messenger_options,
326
-            [
327
-                'html_name'  => 'ee_messenger_filter_by',
328
-                'html_id'    => 'ee_messenger_filter_by',
329
-                'html_class' => 'wide',
330
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
-            ]
332
-        );
333
-
334
-        return $input->get_html_for_input();
335
-    }
336
-
337
-
338
-    /**
339
-     * Generate select input with provided message type options array.
340
-     *
341
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
-     *                                    message type labels
343
-     * @return string
344
-     * @throws EE_Error
345
-     */
346
-    public function get_message_types_select_input($message_type_options)
347
-    {
348
-        // if empty or count of options is 1 then just return an empty string
349
-        if (
350
-            empty($message_type_options)
351
-            || ! is_array($message_type_options)
352
-            || count($message_type_options) === 1
353
-        ) {
354
-            return '';
355
-        }
356
-        // merge in default
357
-        $message_type_options = array_merge(
358
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
-            $message_type_options
360
-        );
361
-        $input                = new EE_Select_Input(
362
-            $message_type_options,
363
-            [
364
-                'html_name'  => 'ee_message_type_filter_by',
365
-                'html_id'    => 'ee_message_type_filter_by',
366
-                'html_class' => 'wide',
367
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
-            ]
369
-        );
370
-
371
-        return $input->get_html_for_input();
372
-    }
373
-
374
-
375
-    /**
376
-     * Generate select input with provide message type contexts array.
377
-     *
378
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
-     *                               context label.
380
-     * @return string
381
-     * @throws EE_Error
382
-     */
383
-    public function get_contexts_for_message_types_select_input($context_options)
384
-    {
385
-        // if empty or count of options is one then just return empty string
386
-        if (
387
-            empty($context_options)
388
-            || ! is_array($context_options)
389
-            || count($context_options) === 1
390
-        ) {
391
-            return '';
392
-        }
393
-        // merge in default
394
-        $context_options = array_merge(
395
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
-            $context_options
397
-        );
398
-        $input           = new EE_Select_Input(
399
-            $context_options,
400
-            [
401
-                'html_name'  => 'ee_context_filter_by',
402
-                'html_id'    => 'ee_context_filter_by',
403
-                'html_class' => 'wide',
404
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
-            ]
406
-        );
407
-
408
-        return $input->get_html_for_input();
409
-    }
410
-
411
-
412
-    protected function _ajax_hooks()
413
-    {
414
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
-    }
421
-
422
-
423
-    protected function _define_page_props()
424
-    {
425
-        $this->_admin_page_title = $this->page_label;
426
-        $this->_labels           = [
427
-            'buttons'    => [
428
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
-            ],
432
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
-        ];
434
-    }
435
-
436
-
437
-    /**
438
-     *        an array for storing key => value pairs of request actions and their corresponding methods
439
-     *
440
-     * @access protected
441
-     * @return void
442
-     */
443
-    protected function _set_page_routes()
444
-    {
445
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
-
449
-        $this->_page_routes = [
450
-            'default'                          => [
451
-                'func'       => '_message_queue_list_table',
452
-                'capability' => 'ee_read_global_messages',
453
-            ],
454
-            'global_mtps'                      => [
455
-                'func'       => '_ee_default_messages_overview_list_table',
456
-                'capability' => 'ee_read_global_messages',
457
-            ],
458
-            'custom_mtps'                      => [
459
-                'func'       => '_custom_mtps_preview',
460
-                'capability' => 'ee_read_messages',
461
-            ],
462
-            'add_new_message_template'         => [
463
-                'func'       => 'add_message_template',
464
-                'capability' => 'ee_edit_messages',
465
-                'noheader'   => true,
466
-            ],
467
-            'edit_message_template'            => [
468
-                'func'       => '_edit_message_template',
469
-                'capability' => 'ee_edit_message',
470
-                'obj_id'     => $GRP_ID,
471
-            ],
472
-            'preview_message'                  => [
473
-                'func'               => '_preview_message',
474
-                'capability'         => 'ee_read_message',
475
-                'obj_id'             => $GRP_ID,
476
-                'noheader'           => true,
477
-                'headers_sent_route' => 'display_preview_message',
478
-            ],
479
-            'display_preview_message'          => [
480
-                'func'       => '_display_preview_message',
481
-                'capability' => 'ee_read_message',
482
-                'obj_id'     => $GRP_ID,
483
-            ],
484
-            'insert_message_template'          => [
485
-                'func'       => '_insert_or_update_message_template',
486
-                'capability' => 'ee_edit_messages',
487
-                'args'       => ['new' => true],
488
-                'noheader'   => true,
489
-            ],
490
-            'update_message_template'          => [
491
-                'func'       => '_insert_or_update_message_template',
492
-                'capability' => 'ee_edit_message',
493
-                'obj_id'     => $GRP_ID,
494
-                'args'       => ['new' => false],
495
-                'noheader'   => true,
496
-            ],
497
-            'trash_message_template'           => [
498
-                'func'       => '_trash_or_restore_message_template',
499
-                'capability' => 'ee_delete_message',
500
-                'obj_id'     => $GRP_ID,
501
-                'args'       => ['trash' => true, 'all' => true],
502
-                'noheader'   => true,
503
-            ],
504
-            'trash_message_template_context'   => [
505
-                'func'       => '_trash_or_restore_message_template',
506
-                'capability' => 'ee_delete_message',
507
-                'obj_id'     => $GRP_ID,
508
-                'args'       => ['trash' => true],
509
-                'noheader'   => true,
510
-            ],
511
-            'restore_message_template'         => [
512
-                'func'       => '_trash_or_restore_message_template',
513
-                'capability' => 'ee_delete_message',
514
-                'obj_id'     => $GRP_ID,
515
-                'args'       => ['trash' => false, 'all' => true],
516
-                'noheader'   => true,
517
-            ],
518
-            'restore_message_template_context' => [
519
-                'func'       => '_trash_or_restore_message_template',
520
-                'capability' => 'ee_delete_message',
521
-                'obj_id'     => $GRP_ID,
522
-                'args'       => ['trash' => false],
523
-                'noheader'   => true,
524
-            ],
525
-            'delete_message_template'          => [
526
-                'func'       => '_delete_message_template',
527
-                'capability' => 'ee_delete_message',
528
-                'obj_id'     => $GRP_ID,
529
-                'noheader'   => true,
530
-            ],
531
-            'reset_to_default'                 => [
532
-                'func'       => '_reset_to_default_template',
533
-                'capability' => 'ee_edit_message',
534
-                'obj_id'     => $GRP_ID,
535
-                'noheader'   => true,
536
-            ],
537
-            'settings'                         => [
538
-                'func'       => '_settings',
539
-                'capability' => 'manage_options',
540
-            ],
541
-            'update_global_settings'           => [
542
-                'func'       => '_update_global_settings',
543
-                'capability' => 'manage_options',
544
-                'noheader'   => true,
545
-            ],
546
-            'generate_now'                     => [
547
-                'func'       => '_generate_now',
548
-                'capability' => 'ee_send_message',
549
-                'noheader'   => true,
550
-            ],
551
-            'generate_and_send_now'            => [
552
-                'func'       => '_generate_and_send_now',
553
-                'capability' => 'ee_send_message',
554
-                'noheader'   => true,
555
-            ],
556
-            'queue_for_resending'              => [
557
-                'func'       => '_queue_for_resending',
558
-                'capability' => 'ee_send_message',
559
-                'noheader'   => true,
560
-            ],
561
-            'send_now'                         => [
562
-                'func'       => '_send_now',
563
-                'capability' => 'ee_send_message',
564
-                'noheader'   => true,
565
-            ],
566
-            'delete_ee_message'                => [
567
-                'func'       => '_delete_ee_messages',
568
-                'capability' => 'ee_delete_messages',
569
-                'noheader'   => true,
570
-            ],
571
-            'delete_ee_messages'               => [
572
-                'func'       => '_delete_ee_messages',
573
-                'capability' => 'ee_delete_messages',
574
-                'noheader'   => true,
575
-                'obj_id'     => $MSG_ID,
576
-            ],
577
-        ];
578
-    }
579
-
580
-
581
-    protected function _set_page_config()
582
-    {
583
-        $this->_page_config = [
584
-            'default'                  => [
585
-                'nav'           => [
586
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
587
-                    'order' => 10,
588
-                ],
589
-                'list_table'    => 'EE_Message_List_Table',
590
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
-                'require_nonce' => false,
592
-            ],
593
-            'global_mtps'              => [
594
-                'nav'           => [
595
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
-                    'order' => 20,
597
-                ],
598
-                'list_table'    => 'Messages_Template_List_Table',
599
-                'help_tabs'     => [
600
-                    'messages_overview_help_tab'                                => [
601
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
-                        'filename' => 'messages_overview',
603
-                    ],
604
-                    'messages_overview_messages_table_column_headings_help_tab' => [
605
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
-                        'filename' => 'messages_overview_table_column_headings',
607
-                    ],
608
-                    'messages_overview_messages_filters_help_tab'               => [
609
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
610
-                        'filename' => 'messages_overview_filters',
611
-                    ],
612
-                    'messages_overview_messages_views_help_tab'                 => [
613
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
614
-                        'filename' => 'messages_overview_views',
615
-                    ],
616
-                    'message_overview_message_types_help_tab'                   => [
617
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
618
-                        'filename' => 'messages_overview_types',
619
-                    ],
620
-                    'messages_overview_messengers_help_tab'                     => [
621
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
622
-                        'filename' => 'messages_overview_messengers',
623
-                    ],
624
-                ],
625
-                'require_nonce' => false,
626
-            ],
627
-            'custom_mtps'              => [
628
-                'nav'           => [
629
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
-                    'order' => 30,
631
-                ],
632
-                'help_tabs'     => [],
633
-                'require_nonce' => false,
634
-            ],
635
-            'add_new_message_template' => [
636
-                'nav'           => [
637
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
-                    'order'      => 5,
639
-                    'persistent' => false,
640
-                ],
641
-                'require_nonce' => false,
642
-            ],
643
-            'edit_message_template'    => [
644
-                'labels'        => [
645
-                    'buttons'    => [
646
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
-                    ],
648
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
-                ],
650
-                'nav'           => [
651
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
-                    'order'      => 5,
653
-                    'persistent' => false,
654
-                    'url'        => '',
655
-                ],
656
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
-                'has_metaboxes' => true,
658
-                'help_tabs'     => [
659
-                    'edit_message_template'            => [
660
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
-                        'callback' => 'edit_message_template_help_tab',
662
-                    ],
663
-                    'message_templates_help_tab'       => [
664
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
665
-                        'filename' => 'messages_templates',
666
-                    ],
667
-                    'message_template_shortcodes'      => [
668
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
-                        'callback' => 'message_template_shortcodes_help_tab',
670
-                    ],
671
-                    'message_preview_help_tab'         => [
672
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
673
-                        'filename' => 'messages_preview',
674
-                    ],
675
-                    'messages_overview_other_help_tab' => [
676
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
677
-                        'filename' => 'messages_overview_other',
678
-                    ],
679
-                ],
680
-                'require_nonce' => false,
681
-            ],
682
-            'display_preview_message'  => [
683
-                'nav'           => [
684
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
685
-                    'order'      => 5,
686
-                    'url'        => '',
687
-                    'persistent' => false,
688
-                ],
689
-                'help_tabs'     => [
690
-                    'preview_message' => [
691
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
692
-                        'callback' => 'preview_message_help_tab',
693
-                    ],
694
-                ],
695
-                'require_nonce' => false,
696
-            ],
697
-            'settings'                 => [
698
-                'nav'           => [
699
-                    'label' => esc_html__('Settings', 'event_espresso'),
700
-                    'order' => 40,
701
-                ],
702
-                'metaboxes'     => ['_messages_settings_metaboxes'],
703
-                'help_tabs'     => [
704
-                    'messages_settings_help_tab'               => [
705
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
-                        'filename' => 'messages_settings',
707
-                    ],
708
-                    'messages_settings_message_types_help_tab' => [
709
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
-                        'filename' => 'messages_settings_message_types',
711
-                    ],
712
-                    'messages_settings_messengers_help_tab'    => [
713
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
-                        'filename' => 'messages_settings_messengers',
715
-                    ],
716
-                ],
717
-                'require_nonce' => false,
718
-            ],
719
-        ];
720
-    }
721
-
722
-
723
-    protected function _add_screen_options()
724
-    {
725
-        // todo
726
-    }
727
-
728
-
729
-    protected function _add_screen_options_global_mtps()
730
-    {
731
-        /**
732
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
734
-         */
735
-        $page_title              = $this->_admin_page_title;
736
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
-        $this->_per_page_screen_option();
738
-        $this->_admin_page_title = $page_title;
739
-    }
740
-
741
-
742
-    protected function _add_screen_options_default()
743
-    {
744
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
-        $this->_per_page_screen_option();
746
-    }
747
-
748
-
749
-    // none of the below group are currently used for Messages
750
-    protected function _add_feature_pointers()
751
-    {
752
-    }
753
-
754
-
755
-    public function admin_init()
756
-    {
757
-    }
758
-
759
-
760
-    public function admin_notices()
761
-    {
762
-    }
763
-
764
-
765
-    public function admin_footer_scripts()
766
-    {
767
-    }
768
-
769
-
770
-    public function messages_help_tab()
771
-    {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
-    }
774
-
775
-
776
-    public function messengers_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
-    }
780
-
781
-
782
-    public function message_types_help_tab()
783
-    {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
-    }
786
-
787
-
788
-    public function messages_overview_help_tab()
789
-    {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
-    }
792
-
793
-
794
-    public function message_templates_help_tab()
795
-    {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
-    }
798
-
799
-
800
-    public function edit_message_template_help_tab()
801
-    {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
-                        . esc_attr__('Editor Title', 'event_espresso')
804
-                        . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
807
-                        . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
810
-                        . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
813
-                        . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
-                        . esc_attr__('Publish Metabox', 'event_espresso')
816
-                        . '" />';
817
-        EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
-            $args
820
-        );
821
-    }
822
-
823
-
824
-    /**
825
-     * @throws ReflectionException
826
-     * @throws EE_Error
827
-     */
828
-    public function message_template_shortcodes_help_tab()
829
-    {
830
-        $this->_set_shortcodes();
831
-        $args['shortcodes'] = $this->_shortcodes;
832
-        EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
-            $args
835
-        );
836
-    }
837
-
838
-
839
-    public function preview_message_help_tab()
840
-    {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
-    }
843
-
844
-
845
-    public function settings_help_tab()
846
-    {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
-        $args['img3'] = '<div class="switch">'
852
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
-                        . ' type="checkbox" checked>'
854
-                        . '<label for="ee-on-off-toggle-on"></label>'
855
-                        . '</div>';
856
-        $args['img4'] = '<div class="switch">'
857
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
-                        . ' type="checkbox">'
859
-                        . '<label for="ee-on-off-toggle-on"></label>'
860
-                        . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
-    }
863
-
864
-
865
-    public function load_scripts_styles()
866
-    {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
-        wp_enqueue_style('espresso_ee_msg');
869
-
870
-        wp_register_script(
871
-            'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
874
-            EVENT_ESPRESSO_VERSION,
875
-            true
876
-        );
877
-        wp_register_script(
878
-            'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
-            ['ee-dialog'],
881
-            EVENT_ESPRESSO_VERSION
882
-        );
883
-    }
884
-
885
-
886
-    public function load_scripts_styles_default()
887
-    {
888
-        wp_enqueue_script('ee-msg-list-table-js');
889
-    }
890
-
891
-
892
-    public function wp_editor_css($mce_css)
893
-    {
894
-        // if we're on the edit_message_template route
895
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
-            $message_type_name = $this->_active_message_type_name;
897
-
898
-            // we're going to REPLACE the existing mce css
899
-            // we need to get the css file location from the active messenger
900
-            $mce_css = $this->_active_messenger->get_variation(
901
-                $this->_template_pack,
902
-                $message_type_name,
903
-                true,
904
-                'wpeditor',
905
-                $this->_variation
906
-            );
907
-        }
908
-
909
-        return $mce_css;
910
-    }
911
-
912
-
913
-    /**
914
-     * @throws EE_Error
915
-     * @throws ReflectionException
916
-     */
917
-    public function load_scripts_styles_edit_message_template()
918
-    {
919
-
920
-        $this->_set_shortcodes();
921
-
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
-            esc_html__(
924
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
-                'event_espresso'
926
-            ),
927
-            $this->_message_template_group->messenger_obj()->label['singular'],
928
-            $this->_message_template_group->message_type_obj()->label['singular']
929
-        );
930
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
-            'event_espresso'
933
-        );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
-            'event_espresso'
937
-        );
938
-
939
-        wp_register_script(
940
-            'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
-            ['jquery'],
943
-            EVENT_ESPRESSO_VERSION
944
-        );
945
-
946
-        wp_enqueue_script('ee_admin_js');
947
-        wp_enqueue_script('ee_msgs_edit_js');
948
-
949
-        // add in special css for tiny_mce
950
-        add_filter('mce_css', [$this, 'wp_editor_css']);
951
-    }
952
-
953
-
954
-    /**
955
-     * @throws EE_Error
956
-     * @throws ReflectionException
957
-     */
958
-    public function load_scripts_styles_display_preview_message()
959
-    {
960
-        $this->_set_message_template_group();
961
-        if ($this->_active_messenger_name) {
962
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
-                $this->_active_messenger_name
964
-            );
965
-        }
966
-
967
-        wp_enqueue_style(
968
-            'espresso_preview_css',
969
-            $this->_active_messenger->get_variation(
970
-                $this->_template_pack,
971
-                $this->_active_message_type_name,
972
-                true,
973
-                'preview',
974
-                $this->_variation
975
-            )
976
-        );
977
-    }
978
-
979
-
980
-    public function load_scripts_styles_settings()
981
-    {
982
-        wp_register_style(
983
-            'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
-            [],
986
-            EVENT_ESPRESSO_VERSION
987
-        );
988
-        wp_enqueue_style('ee-text-links');
989
-        wp_enqueue_style('ee-message-settings');
990
-        wp_enqueue_script('ee-messages-settings');
991
-    }
992
-
993
-
994
-    /**
995
-     * set views array for List Table
996
-     */
997
-    public function _set_list_table_views_global_mtps()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'  => 'in_use',
1002
-                'label' => esc_html__('In Use', 'event_espresso'),
1003
-                'count' => 0,
1004
-            ],
1005
-        ];
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Set views array for the Custom Template List Table
1011
-     */
1012
-    public function _set_list_table_views_custom_mtps()
1013
-    {
1014
-        $this->_set_list_table_views_global_mtps();
1015
-        $this->_views['in_use']['bulk_action'] = [
1016
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
-        ];
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * set views array for message queue list table
1023
-     *
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidInterfaceException
1026
-     * @throws InvalidArgumentException
1027
-     * @throws EE_Error
1028
-     * @throws ReflectionException
1029
-     */
1030
-    public function _set_list_table_views_default()
1031
-    {
1032
-        EE_Registry::instance()->load_helper('Template');
1033
-
1034
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
-            'ee_send_message',
1036
-            'message_list_table_bulk_actions'
1037
-        )
1038
-            ? [
1039
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
-            ]
1044
-            : [];
1045
-
1046
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_delete_messages',
1048
-            'message_list_table_bulk_actions'
1049
-        )
1050
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
-            : [];
1052
-
1053
-
1054
-        $this->_views = [
1055
-            'all' => [
1056
-                'slug'        => 'all',
1057
-                'label'       => esc_html__('All', 'event_espresso'),
1058
-                'count'       => 0,
1059
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
-            ],
1061
-        ];
1062
-
1063
-
1064
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
-                continue;
1067
-            }
1068
-            $status_bulk_actions = $common_bulk_actions;
1069
-            // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1071
-                switch ($status) {
1072
-                    case EEM_Message::status_idle:
1073
-                    case EEM_Message::status_resend:
1074
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
-                        break;
1076
-
1077
-                    case EEM_Message::status_failed:
1078
-                    case EEM_Message::status_debug_only:
1079
-                    case EEM_Message::status_messenger_executing:
1080
-                        $status_bulk_actions = [];
1081
-                        break;
1082
-
1083
-                    case EEM_Message::status_incomplete:
1084
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
-                        break;
1086
-
1087
-                    case EEM_Message::status_retry:
1088
-                    case EEM_Message::status_sent:
1089
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
-                        break;
1091
-                }
1092
-            }
1093
-
1094
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1095
-            if ($status === EEM_Message::status_messenger_executing) {
1096
-                continue;
1097
-            }
1098
-
1099
-            $this->_views[ strtolower($status) ] = [
1100
-                'slug'        => strtolower($status),
1101
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
-                'count'       => 0,
1103
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
-            ];
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * @throws EE_Error
1111
-     */
1112
-    protected function _ee_default_messages_overview_list_table()
1113
-    {
1114
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * @throws EE_Error
1121
-     * @throws ReflectionException
1122
-     */
1123
-    protected function _message_queue_list_table()
1124
-    {
1125
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
-        $this->_template_args['per_column']        = 6;
1127
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
-        $message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1129
-        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1130
-        $this->display_admin_list_table_page_with_no_sidebar();
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * @throws EE_Error
1136
-     */
1137
-    protected function _message_legend_items()
1138
-    {
1139
-
1140
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
-        $action_items       = [];
1142
-
1143
-        foreach ($action_css_classes as $action_item => $action_details) {
1144
-            if ($action_item === 'see_notifications_for') {
1145
-                continue;
1146
-            }
1147
-            $action_items[ $action_item ] = [
1148
-                'class' => $action_details['css_class'],
1149
-                'desc'  => $action_details['label'],
1150
-            ];
1151
-        }
1152
-
1153
-        /** @var array $status_items status legend setup */
1154
-        $status_items = [
1155
-            'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1157
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
-            ],
1159
-            'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1161
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
-            ],
1163
-            'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1165
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
-            ],
1167
-            'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1169
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
-            ],
1171
-            'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1173
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
-            ],
1175
-            'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1177
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
-            ],
1179
-            'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1181
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
-            ],
1183
-        ];
1184
-        if (EEM_Message::debug()) {
1185
-            $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1187
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
-            ];
1189
-        }
1190
-
1191
-        return array_merge($action_items, $status_items);
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * @throws EE_Error
1197
-     */
1198
-    protected function _custom_mtps_preview()
1199
-    {
1200
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1203
-                                                    'Preview Custom Message Templates screenshot',
1204
-                                                    'event_espresso'
1205
-                                                ) . '" />';
1206
-        $this->_template_args['preview_text'] = '<strong>'
1207
-                                                . esc_html__(
1208
-                                                    'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1209
-                                                    'event_espresso'
1210
-                                                )
1211
-                                                . '</strong>';
1212
-
1213
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * get_message_templates
1219
-     * This gets all the message templates for listing on the overview list.
1220
-     *
1221
-     * @access public
1222
-     * @param int    $per_page the amount of templates groups to show per page
1223
-     * @param string $type     the current _view we're getting templates for
1224
-     * @param bool   $count    return count?
1225
-     * @param bool   $all      disregard any paging info (get all data);
1226
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
-     * @return array
1228
-     * @throws EE_Error
1229
-     * @throws InvalidArgumentException
1230
-     * @throws InvalidDataTypeException
1231
-     * @throws InvalidInterfaceException
1232
-     */
1233
-    public function get_message_templates(
1234
-        $per_page = 10,
1235
-        $type = 'in_use',
1236
-        $count = false,
1237
-        $all = false,
1238
-        $global = true
1239
-    ) {
1240
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
-        $this->request->setRequestParam('orderby', $orderby);
1242
-
1243
-        $order        = $this->request->getRequestParam('order', 'ASC');
1244
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
-
1247
-        $offset = ($current_page - 1) * $per_page;
1248
-        $limit  = $all ? null : [$offset, $per_page];
1249
-
1250
-        // options will match what is in the _views array property
1251
-        return $type === 'in_use'
1252
-            ? $this->getMtgModel()->get_all_active_message_templates(
1253
-                $orderby,
1254
-                $order,
1255
-                $limit,
1256
-                $count,
1257
-                $global,
1258
-                true
1259
-            )
1260
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
-                $orderby,
1262
-                $order,
1263
-                $limit,
1264
-                $count,
1265
-                $global
1266
-            );
1267
-    }
1268
-
1269
-
1270
-    /**
1271
-     * filters etc might need a list of installed message_types
1272
-     *
1273
-     * @return array an array of message type objects
1274
-     */
1275
-    public function get_installed_message_types()
1276
-    {
1277
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
-        $installed               = [];
1279
-
1280
-        foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1282
-        }
1283
-
1284
-        return $installed;
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1290
-     *
1291
-     * @param string $message_type
1292
-     * @param string $messenger
1293
-     * @param string $GRP_ID
1294
-     *
1295
-     * @throws EE_error
1296
-     * @throws ReflectionException
1297
-     */
1298
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
-    {
1300
-        // set values override any request data
1301
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
-
1305
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
-        if (empty($message_type) || empty($messenger)) {
1307
-            throw new EE_Error(
1308
-                esc_html__(
1309
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
-                    'event_espresso'
1311
-                )
1312
-            );
1313
-        }
1314
-
1315
-        // we need the GRP_ID for the template being used as the base for the new template
1316
-        if (empty($GRP_ID)) {
1317
-            throw new EE_Error(
1318
-                esc_html__(
1319
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
-                    'event_espresso'
1321
-                )
1322
-            );
1323
-        }
1324
-
1325
-        // let's just make sure the template gets generated!
1326
-
1327
-        // we need to reassign some variables for what the insert is expecting
1328
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1329
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1330
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
-
1332
-        $this->_insert_or_update_message_template(true);
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * @param string $message_type     message type slug
1338
-     * @param string $messenger        messenger slug
1339
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
-     *                                 off of.
1341
-     * @throws EE_error
1342
-     * @throws ReflectionException
1343
-     * @deprecated 4.10.29.p
1344
-     */
1345
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
-    {
1347
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * _edit_message_template
1353
-     *
1354
-     * @access protected
1355
-     * @return void
1356
-     * @throws InvalidIdentifierException
1357
-     * @throws DomainException
1358
-     * @throws EE_Error
1359
-     * @throws InvalidArgumentException
1360
-     * @throws ReflectionException
1361
-     * @throws InvalidDataTypeException
1362
-     * @throws InvalidInterfaceException
1363
-     */
1364
-    protected function _edit_message_template()
1365
-    {
1366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
-        $template_fields = '';
1368
-        $sidebar_fields  = '';
1369
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
-        // valid html in the templates.
1371
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
-
1373
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
-
1376
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1377
-        $message_template_group = $this->_message_template_group;
1378
-        $c_label                = $message_template_group->context_label();
1379
-        $c_config               = $message_template_group->contexts_config();
1380
-
1381
-        reset($c_config);
1382
-        $context = $this->request->getRequestParam('context', key($c_config));
1383
-        $context = strtolower($context);
1384
-
1385
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
-
1387
-        $edit_message_template_form_url = add_query_arg(
1388
-            ['action' => $action, 'noheader' => true],
1389
-            EE_MSG_ADMIN_URL
1390
-        );
1391
-
1392
-        // set active messenger for this view
1393
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
-            $message_template_group->messenger()
1395
-        );
1396
-        $this->_active_message_type_name = $message_template_group->message_type();
1397
-
1398
-
1399
-        // Do we have any validation errors?
1400
-        $validators = $this->_get_transient();
1401
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
-
1403
-
1404
-        // we need to assemble the title from Various details
1405
-        $context_label = sprintf(
1406
-            esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1408
-            ucwords($c_label['label'])
1409
-        );
1410
-
1411
-        $title = sprintf(
1412
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1413
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1414
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1415
-            $context_label
1416
-        );
1417
-
1418
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1419
-        $this->_template_args['message_template'] = $message_template_group;
1420
-        $this->_template_args['is_extra_fields']  = false;
1421
-
1422
-
1423
-        // let's get EEH_MSG_Template so we can get template form fields
1424
-        $template_field_structure = EEH_MSG_Template::get_fields(
1425
-            $message_template_group->messenger(),
1426
-            $message_template_group->message_type()
1427
-        );
1428
-
1429
-        if (! $template_field_structure) {
1430
-            $template_field_structure = false;
1431
-            $template_fields          = esc_html__(
1432
-                'There was an error in assembling the fields for this display (you should see an error message)',
1433
-                'event_espresso'
1434
-            );
1435
-        }
1436
-
1437
-
1438
-        $message_templates = $message_template_group->context_templates();
1439
-
1440
-
1441
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
-        // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1446
-            }
1447
-        }
1448
-
1449
-        // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
-                // the extra array and reset them.
1454
-                if ($template_field === 'extra') {
1455
-                    $this->_template_args['is_extra_fields'] = true;
1456
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1458
-                        $content          = $message_template instanceof EE_Message_Template
1459
-                            ? $message_template->get('MTP_content')
1460
-                            : '';
1461
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1462
-                            // let's verify if we need this extra field via the shortcodes parameter.
1463
-                            $continue = false;
1464
-                            if (isset($extra_array['shortcodes_required'])) {
1465
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
-                                        $continue = true;
1468
-                                    }
1469
-                                }
1470
-                                if ($continue) {
1471
-                                    continue;
1472
-                                }
1473
-                            }
1474
-
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1476
-
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
-                                                                         . $reference_field
1480
-                                                                         . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1483
-                                ? $extra_array['css_class']
1484
-                                : '';
1485
-
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
-                                                                              && in_array($extra_field, $v_fields, true)
1488
-                                                                              && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1491
-                                                                              )
1492
-                                ? 'validate-error ' . $css_class
1493
-                                : $css_class;
1494
-
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1498
-                                : '';
1499
-
1500
-                            // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1504
-
1505
-
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
-
1508
-                            // shortcode selector
1509
-                            $field_name_to_use                                   = $extra_field === 'main'
1510
-                                ? 'content'
1511
-                                : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
-                                $field_name_to_use,
1514
-                                $field_id
1515
-                            );
1516
-                        }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1519
-
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
-                            'label'      => null,
1523
-                            'input'      => 'hidden',
1524
-                            'type'       => 'int',
1525
-                            'required'   => false,
1526
-                            'validation' => false,
1527
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
-                            'css_class'  => '',
1529
-                            'format'     => '%d',
1530
-                            'db-col'     => 'MTP_ID',
1531
-                        ];
1532
-
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
-                            'label'      => null,
1536
-                            'input'      => 'hidden',
1537
-                            'type'       => 'string',
1538
-                            'required'   => false,
1539
-                            'validation' => true,
1540
-                            'value'      => $reference_field,
1541
-                            'css_class'  => '',
1542
-                            'format'     => '%s',
1543
-                            'db-col'     => 'MTP_template_field',
1544
-                        ];
1545
-                    }
1546
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
-                } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1552
-                    $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1555
-                            : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1558
-                                                                  && $message_template instanceof EE_Message_Template
1559
-                        ? $message_template->get('MTP_content')
1560
-                        : '';
1561
-
1562
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1566
-
1567
-
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
-                    $css_class                                      = isset($field_setup_array['css_class'])
1570
-                        ? $field_setup_array['css_class']
1571
-                        : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
-                                                                      && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1576
-                        : $css_class;
1577
-
1578
-                    // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
-                        $template_field,
1581
-                        $field_id
1582
-                    );
1583
-                }
1584
-
1585
-                // k took care of content field(s) now let's take care of others.
1586
-
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1589
-
1590
-                // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
-                    'label'      => null,
1594
-                    'input'      => 'hidden',
1595
-                    'type'       => 'int',
1596
-                    'required'   => false,
1597
-                    'validation' => true,
1598
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
-                    'css_class'  => '',
1600
-                    'format'     => '%d',
1601
-                    'db-col'     => 'MTP_ID',
1602
-                ];
1603
-
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
-                    'label'      => null,
1607
-                    'input'      => 'hidden',
1608
-                    'type'       => 'string',
1609
-                    'required'   => false,
1610
-                    'validation' => true,
1611
-                    'value'      => $template_field,
1612
-                    'css_class'  => '',
1613
-                    'format'     => '%s',
1614
-                    'db-col'     => 'MTP_template_field',
1615
-                ];
1616
-            }
1617
-
1618
-            // add other fields
1619
-            $template_form_fields['ee-msg-current-context'] = [
1620
-                'name'       => 'MTP_context',
1621
-                'label'      => null,
1622
-                'input'      => 'hidden',
1623
-                'type'       => 'string',
1624
-                'required'   => false,
1625
-                'validation' => true,
1626
-                'value'      => $context,
1627
-                'css_class'  => '',
1628
-                'format'     => '%s',
1629
-                'db-col'     => 'MTP_context',
1630
-            ];
1631
-
1632
-            $template_form_fields['ee-msg-grp-id'] = [
1633
-                'name'       => 'GRP_ID',
1634
-                'label'      => null,
1635
-                'input'      => 'hidden',
1636
-                'type'       => 'int',
1637
-                'required'   => false,
1638
-                'validation' => true,
1639
-                'value'      => $GRP_ID,
1640
-                'css_class'  => '',
1641
-                'format'     => '%d',
1642
-                'db-col'     => 'GRP_ID',
1643
-            ];
1644
-
1645
-            $template_form_fields['ee-msg-messenger'] = [
1646
-                'name'       => 'MTP_messenger',
1647
-                'label'      => null,
1648
-                'input'      => 'hidden',
1649
-                'type'       => 'string',
1650
-                'required'   => false,
1651
-                'validation' => true,
1652
-                'value'      => $message_template_group->messenger(),
1653
-                'css_class'  => '',
1654
-                'format'     => '%s',
1655
-                'db-col'     => 'MTP_messenger',
1656
-            ];
1657
-
1658
-            $template_form_fields['ee-msg-message-type'] = [
1659
-                'name'       => 'MTP_message_type',
1660
-                'label'      => null,
1661
-                'input'      => 'hidden',
1662
-                'type'       => 'string',
1663
-                'required'   => false,
1664
-                'validation' => true,
1665
-                'value'      => $message_template_group->message_type(),
1666
-                'css_class'  => '',
1667
-                'format'     => '%s',
1668
-                'db-col'     => 'MTP_message_type',
1669
-            ];
1670
-
1671
-            $sidebar_form_fields['ee-msg-is-global'] = [
1672
-                'name'       => 'MTP_is_global',
1673
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1674
-                'input'      => 'hidden',
1675
-                'type'       => 'int',
1676
-                'required'   => false,
1677
-                'validation' => true,
1678
-                'value'      => $message_template_group->get('MTP_is_global'),
1679
-                'css_class'  => '',
1680
-                'format'     => '%d',
1681
-                'db-col'     => 'MTP_is_global',
1682
-            ];
1683
-
1684
-            $sidebar_form_fields['ee-msg-is-override'] = [
1685
-                'name'       => 'MTP_is_override',
1686
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
-                'type'       => 'int',
1689
-                'required'   => false,
1690
-                'validation' => true,
1691
-                'value'      => $message_template_group->get('MTP_is_override'),
1692
-                'css_class'  => '',
1693
-                'format'     => '%d',
1694
-                'db-col'     => 'MTP_is_override',
1695
-            ];
1696
-
1697
-            $sidebar_form_fields['ee-msg-is-active'] = [
1698
-                'name'       => 'MTP_is_active',
1699
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1700
-                'input'      => 'hidden',
1701
-                'type'       => 'int',
1702
-                'required'   => false,
1703
-                'validation' => true,
1704
-                'value'      => $message_template_group->is_active(),
1705
-                'css_class'  => '',
1706
-                'format'     => '%d',
1707
-                'db-col'     => 'MTP_is_active',
1708
-            ];
1709
-
1710
-            $sidebar_form_fields['ee-msg-deleted'] = [
1711
-                'name'       => 'MTP_deleted',
1712
-                'label'      => null,
1713
-                'input'      => 'hidden',
1714
-                'type'       => 'int',
1715
-                'required'   => false,
1716
-                'validation' => true,
1717
-                'value'      => $message_template_group->get('MTP_deleted'),
1718
-                'css_class'  => '',
1719
-                'format'     => '%d',
1720
-                'db-col'     => 'MTP_deleted',
1721
-            ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1723
-                'name'       => 'MTP_user_id',
1724
-                'label'      => esc_html__('Author', 'event_espresso'),
1725
-                'input'      => 'hidden',
1726
-                'type'       => 'int',
1727
-                'required'   => false,
1728
-                'validation' => false,
1729
-                'value'      => $message_template_group->user(),
1730
-                'format'     => '%d',
1731
-                'db-col'     => 'MTP_user_id',
1732
-            ];
1733
-
1734
-            $sidebar_form_fields['ee-msg-route'] = [
1735
-                'name'  => 'action',
1736
-                'input' => 'hidden',
1737
-                'type'  => 'string',
1738
-                'value' => $action,
1739
-            ];
1740
-
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1742
-                'name'  => 'id',
1743
-                'input' => 'hidden',
1744
-                'type'  => 'int',
1745
-                'value' => $GRP_ID,
1746
-            ];
1747
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1749
-                'input' => 'hidden',
1750
-                'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1752
-            ];
1753
-
1754
-            $template_switch = $this->request->getRequestParam('template_switch');
1755
-            if ($template_switch) {
1756
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1757
-                    'name'  => 'template_switch',
1758
-                    'input' => 'hidden',
1759
-                    'type'  => 'int',
1760
-                    'value' => 1,
1761
-                ];
1762
-            }
1763
-
1764
-
1765
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
-        } //end if ( !empty($template_field_structure) )
1768
-
1769
-        // set extra content for publish box
1770
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
-        $this->_set_publish_post_box_vars(
1772
-            'id',
1773
-            $GRP_ID,
1774
-            false,
1775
-            add_query_arg(
1776
-                ['action' => 'global_mtps'],
1777
-                $this->_admin_base_url
1778
-            )
1779
-        );
1780
-
1781
-        // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1783
-            [
1784
-                'message_type' => $message_template_group->message_type(),
1785
-                'messenger'    => $message_template_group->messenger(),
1786
-                'context'      => $context,
1787
-                'GRP_ID'       => $GRP_ID,
1788
-                'evt_id'       => $EVT_ID ?: false,
1789
-                'action'       => 'preview_message',
1790
-            ],
1791
-            $this->_admin_base_url
1792
-        );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1794
-                          . esc_html__('Preview', 'event_espresso')
1795
-                          . '</a>';
1796
-
1797
-
1798
-        // setup context switcher
1799
-        $this->_set_context_switcher(
1800
-            $message_template_group,
1801
-            [
1802
-                'page'    => 'espresso_messages',
1803
-                'action'  => 'edit_message_template',
1804
-                'id'      => $GRP_ID,
1805
-                'evt_id'  => $EVT_ID,
1806
-                'context' => $context,
1807
-                'extra'   => $preview_button,
1808
-            ]
1809
-        );
1810
-
1811
-
1812
-        // main box
1813
-        $this->_template_args['template_fields']                         = $template_fields;
1814
-        $this->_template_args['sidebar_box_id']                          = 'details';
1815
-        $this->_template_args['action']                                  = $action;
1816
-        $this->_template_args['context']                                 = $context;
1817
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
-        $this->_template_args['learn_more_about_message_templates_link'] =
1819
-            $this->_learn_more_about_message_templates_link();
1820
-
1821
-
1822
-        $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1823
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
-            $message_template_group,
1825
-            $context,
1826
-            $context_label
1827
-        );
1828
-        $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1829
-        $this->_template_args['before_admin_page_content'] .= '</div>';
1830
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1831
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1832
-
1833
-        $this->_template_path = $this->_template_args['GRP_ID']
1834
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1835
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1836
-
1837
-        // send along EE_Message_Template_Group object for further template use.
1838
-        $this->_template_args['MTP'] = $message_template_group;
1839
-
1840
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1841
-            $this->_template_path,
1842
-            $this->_template_args,
1843
-            true
1844
-        );
1845
-
1846
-
1847
-        // finally, let's set the admin_page title
1848
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1849
-
1850
-
1851
-        // we need to take care of setting the shortcodes property for use elsewhere.
1852
-        $this->_set_shortcodes();
1853
-
1854
-
1855
-        // final template wrapper
1856
-        $this->display_admin_page_with_sidebar();
1857
-    }
1858
-
1859
-
1860
-    public function filter_tinymce_init($mceInit, $editor_id)
1861
-    {
1862
-        return $mceInit;
1863
-    }
1864
-
1865
-
1866
-    public function add_context_switcher()
1867
-    {
1868
-        return $this->_context_switcher;
1869
-    }
1870
-
1871
-
1872
-    /**
1873
-     * Adds the activation/deactivation toggle for the message template context.
1874
-     *
1875
-     * @param EE_Message_Template_Group $message_template_group
1876
-     * @param string                    $context
1877
-     * @param string                    $context_label
1878
-     * @return string
1879
-     * @throws DomainException
1880
-     * @throws EE_Error
1881
-     * @throws InvalidIdentifierException
1882
-     * @throws ReflectionException
1883
-     */
1884
-    protected function add_active_context_element(
1885
-        EE_Message_Template_Group $message_template_group,
1886
-        $context,
1887
-        $context_label
1888
-    ) {
1889
-        $template_args = [
1890
-            'context'                   => $context,
1891
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1892
-            'is_active'                 => $message_template_group->is_context_active($context),
1893
-            'on_off_action'             => $message_template_group->is_context_active($context)
1894
-                ? 'context-off'
1895
-                : 'context-on',
1896
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1897
-            'message_template_group_id' => $message_template_group->ID(),
1898
-        ];
1899
-        return EEH_Template::display_template(
1900
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1901
-            $template_args,
1902
-            true
1903
-        );
1904
-    }
1905
-
1906
-
1907
-    /**
1908
-     * Ajax callback for `toggle_context_template` ajax action.
1909
-     * Handles toggling the message context on or off.
1910
-     *
1911
-     * @throws EE_Error
1912
-     * @throws InvalidArgumentException
1913
-     * @throws InvalidDataTypeException
1914
-     * @throws InvalidIdentifierException
1915
-     * @throws InvalidInterfaceException
1916
-     */
1917
-    public function toggle_context_template()
1918
-    {
1919
-        $success = true;
1920
-        // check for required data
1921
-        if (
1922
-            ! (
1923
-                $this->request->requestParamIsSet('message_template_group_id')
1924
-                && $this->request->requestParamIsSet('context')
1925
-                && $this->request->requestParamIsSet('status')
1926
-            )
1927
-        ) {
1928
-            EE_Error::add_error(
1929
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1930
-                __FILE__,
1931
-                __FUNCTION__,
1932
-                __LINE__
1933
-            );
1934
-            $success = false;
1935
-        }
1936
-
1937
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1938
-        $context = $this->request->getRequestParam('context', '');
1939
-        $status  = $this->request->getRequestParam('status', '');
1940
-
1941
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1942
-
1943
-        if ($status !== 'off' && $status !== 'on') {
1944
-            EE_Error::add_error(
1945
-                sprintf(
1946
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1947
-                    $status
1948
-                ),
1949
-                __FILE__,
1950
-                __FUNCTION__,
1951
-                __LINE__
1952
-            );
1953
-            $success = false;
1954
-        }
1955
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1956
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1957
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1958
-            EE_Error::add_error(
1959
-                sprintf(
1960
-                    esc_html__(
1961
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1962
-                        'event_espresso'
1963
-                    ),
1964
-                    $message_template_group_id,
1965
-                    'EE_Message_Template_Group'
1966
-                ),
1967
-                __FILE__,
1968
-                __FUNCTION__,
1969
-                __LINE__
1970
-            );
1971
-            $success = false;
1972
-        }
1973
-        if ($success) {
1974
-            $success = $status === 'off'
1975
-                ? $message_template_group->deactivate_context($context)
1976
-                : $message_template_group->activate_context($context);
1977
-        }
1978
-        $this->_template_args['success'] = $success;
1979
-        $this->_return_json();
1980
-    }
1981
-
1982
-
1983
-    public function _add_form_element_before()
1984
-    {
1985
-        return '<form method="post" action="'
1986
-               . $this->_template_args['edit_message_template_form_url']
1987
-               . '" id="ee-msg-edit-frm">';
1988
-    }
1989
-
1990
-
1991
-    public function _add_form_element_after()
1992
-    {
1993
-        return '</form>';
1994
-    }
1995
-
1996
-
1997
-    /**
1998
-     * This executes switching the template pack for a message template.
1999
-     *
2000
-     * @throws EE_Error
2001
-     * @throws InvalidDataTypeException
2002
-     * @throws InvalidInterfaceException
2003
-     * @throws InvalidArgumentException
2004
-     * @throws ReflectionException
2005
-     * @since 4.5.0
2006
-     */
2007
-    public function switch_template_pack()
2008
-    {
2009
-
2010
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2011
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2012
-
2013
-        // verify we have needed values.
2014
-        if (empty($GRP_ID) || empty($template_pack)) {
2015
-            $this->_template_args['error'] = true;
2016
-            EE_Error::add_error(
2017
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2018
-                __FILE__,
2019
-                __FUNCTION__,
2020
-                __LINE__
2021
-            );
2022
-        } else {
2023
-            // get template, set the new template_pack and then reset to default
2024
-            /** @var EE_Message_Template_Group $message_template_group */
2025
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2026
-
2027
-            $message_template_group->set_template_pack_name($template_pack);
2028
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2029
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2030
-
2031
-            $query_args = $this->_reset_to_default_template();
2032
-
2033
-            if (empty($query_args['id'])) {
2034
-                EE_Error::add_error(
2035
-                    esc_html__(
2036
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2037
-                        'event_espresso'
2038
-                    ),
2039
-                    __FILE__,
2040
-                    __FUNCTION__,
2041
-                    __LINE__
2042
-                );
2043
-                $this->_template_args['error'] = true;
2044
-            } else {
2045
-                $template_label       = $message_template_group->get_template_pack()->label;
2046
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2047
-                EE_Error::add_success(
2048
-                    sprintf(
2049
-                        esc_html__(
2050
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2051
-                            'event_espresso'
2052
-                        ),
2053
-                        $template_label,
2054
-                        $template_pack_labels->template_pack
2055
-                    )
2056
-                );
2057
-                // generate the redirect url for js.
2058
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2059
-
2060
-                $this->_template_args['data']['redirect_url'] = $url;
2061
-                $this->_template_args['success']              = true;
2062
-            }
2063
-
2064
-            $this->_return_json();
2065
-        }
2066
-    }
2067
-
2068
-
2069
-    /**
2070
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2071
-     * they want.
2072
-     *
2073
-     * @access protected
2074
-     * @return array|void
2075
-     * @throws EE_Error
2076
-     * @throws InvalidArgumentException
2077
-     * @throws InvalidDataTypeException
2078
-     * @throws InvalidInterfaceException
2079
-     * @throws ReflectionException
2080
-     */
2081
-    protected function _reset_to_default_template()
2082
-    {
2083
-        $templates    = [];
2084
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2085
-        $messenger    = $this->request->getRequestParam('msgr');
2086
-        $message_type = $this->request->getRequestParam('mt');
2087
-        // we need to make sure we've got the info we need.
2088
-        if (! ($GRP_ID && $messenger && $message_type)) {
2089
-            EE_Error::add_error(
2090
-                esc_html__(
2091
-                    '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.',
2092
-                    'event_espresso'
2093
-                ),
2094
-                __FILE__,
2095
-                __FUNCTION__,
2096
-                __LINE__
2097
-            );
2098
-        }
2099
-
2100
-        // all templates will be reset to whatever the defaults are
2101
-        // for the global template matching the messenger and message type.
2102
-        $success = ! empty($GRP_ID);
2103
-
2104
-        if ($success) {
2105
-            // let's first determine if the incoming template is a global template,
2106
-            // if it isn't then we need to get the global template matching messenger and message type.
2107
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2108
-
2109
-
2110
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2111
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2112
-
2113
-            if ($success) {
2114
-                // if successfully deleted, lets generate the new ones.
2115
-                // Note. We set GLOBAL to true, because resets on ANY template
2116
-                // will use the related global template defaults for regeneration.
2117
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2118
-                // HOWEVER, we DO keep the template pack and template variation set
2119
-                // for the current custom template when resetting.
2120
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2121
-            }
2122
-        }
2123
-
2124
-        // any error messages?
2125
-        if (! $success) {
2126
-            EE_Error::add_error(
2127
-                esc_html__(
2128
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2129
-                    'event_espresso'
2130
-                ),
2131
-                __FILE__,
2132
-                __FUNCTION__,
2133
-                __LINE__
2134
-            );
2135
-        }
2136
-
2137
-        // all good, let's add a success message!
2138
-        if ($success && ! empty($templates)) {
2139
-            // the info for the template we generated is the first element in the returned array
2140
-            EE_Error::overwrite_success();
2141
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2142
-        }
2143
-
2144
-
2145
-        $query_args = [
2146
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2147
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2148
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2149
-        ];
2150
-
2151
-        // if called via ajax then we return query args otherwise redirect
2152
-        if ($this->request->isAjax()) {
2153
-            return $query_args;
2154
-        }
2155
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2156
-    }
2157
-
2158
-
2159
-    /**
2160
-     * Retrieve and set the message preview for display.
2161
-     *
2162
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2163
-     * @return string
2164
-     * @throws ReflectionException
2165
-     * @throws EE_Error
2166
-     * @throws InvalidArgumentException
2167
-     * @throws InvalidDataTypeException
2168
-     * @throws InvalidInterfaceException
2169
-     */
2170
-    public function _preview_message($send = false)
2171
-    {
2172
-        // first make sure we've got the necessary parameters
2173
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2174
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2175
-            EE_Error::add_error(
2176
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2177
-                __FILE__,
2178
-                __FUNCTION__,
2179
-                __LINE__
2180
-            );
2181
-        }
2182
-
2183
-        $context = $this->request->getRequestParam('context');
2184
-        // get the preview!
2185
-        $preview = EED_Messages::preview_message(
2186
-            $this->_active_message_type_name,
2187
-            $context,
2188
-            $this->_active_messenger_name,
2189
-            $send
2190
-        );
2191
-
2192
-        if ($send) {
2193
-            return $preview;
2194
-        }
2195
-
2196
-        // if we have an evt_id set on the request, use it.
2197
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2198
-
2199
-        // let's add a button to go back to the edit view
2200
-        $query_args             = [
2201
-            'id'      => $GRP_ID,
2202
-            'evt_id'  => $EVT_ID,
2203
-            'context' => $context,
2204
-            'action'  => 'edit_message_template',
2205
-        ];
2206
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2207
-        $preview_button         = '<a href="'
2208
-                                  . $go_back_url
2209
-                                  . '" class="button--secondary messages-preview-go-back-button">'
2210
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2211
-                                  . '</a>';
2212
-        $message_types          = $this->get_installed_message_types();
2213
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2214
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2215
-            ? ucwords($active_messenger->label['singular'])
2216
-            : esc_html__('Unknown Messenger', 'event_espresso');
2217
-        // let's provide a helpful title for context
2218
-        $preview_title = sprintf(
2219
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2220
-            $active_messenger_label,
2221
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2222
-        );
2223
-        if (empty($preview)) {
2224
-            $this->noEventsErrorMessage();
2225
-        }
2226
-        // setup display of preview.
2227
-        $this->_admin_page_title                    = $preview_title;
2228
-        $this->_template_args['admin_page_title']   = $preview_title;
2229
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2230
-        $this->_template_args['data']['force_json'] = true;
2231
-
2232
-        return '';
2233
-    }
2234
-
2235
-
2236
-    /**
2237
-     * Used to set an error if there are no events available for generating a preview/test send.
2238
-     *
2239
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2240
-     */
2241
-    protected function noEventsErrorMessage($test_send = false)
2242
-    {
2243
-        $events_url = parent::add_query_args_and_nonce(
2244
-            [
2245
-                'action' => 'default',
2246
-                'page'   => 'espresso_events',
2247
-            ],
2248
-            admin_url('admin.php')
2249
-        );
2250
-        $message    = $test_send
2251
-            ? esc_html__(
2252
-                '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!',
2253
-                'event_espresso'
2254
-            )
2255
-            : esc_html__(
2256
-                '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!',
2257
-                'event_espresso'
2258
-            );
2259
-
2260
-        EE_Error::add_attention(
2261
-            sprintf(
2262
-                $message,
2263
-                "<a href='{$events_url}'>",
2264
-                '</a>'
2265
-            )
2266
-        );
2267
-    }
2268
-
2269
-
2270
-    /**
2271
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2272
-     * gets called automatically.
2273
-     *
2274
-     * @return void
2275
-     * @throws EE_Error
2276
-     * @since 4.5.0
2277
-     *
2278
-     */
2279
-    protected function _display_preview_message()
2280
-    {
2281
-        $this->display_admin_page_with_no_sidebar();
2282
-    }
2283
-
2284
-
2285
-    /**
2286
-     * registers metaboxes that should show up on the "edit_message_template" page
2287
-     *
2288
-     * @access protected
2289
-     * @return void
2290
-     */
2291
-    protected function _register_edit_meta_boxes()
2292
-    {
2293
-        $this->addMetaBox(
2294
-            'mtp_valid_shortcodes',
2295
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2296
-            [$this, 'shortcode_meta_box'],
2297
-            $this->_current_screen->id,
2298
-            'side'
2299
-        );
2300
-        $this->addMetaBox(
2301
-            'mtp_extra_actions',
2302
-            esc_html__('Extra Actions', 'event_espresso'),
2303
-            [$this, 'extra_actions_meta_box'],
2304
-            $this->_current_screen->id,
2305
-            'side',
2306
-            'high'
2307
-        );
2308
-        $this->addMetaBox(
2309
-            'mtp_templates',
2310
-            esc_html__('Template Styles', 'event_espresso'),
2311
-            [$this, 'template_pack_meta_box'],
2312
-            $this->_current_screen->id,
2313
-            'side',
2314
-            'high'
2315
-        );
2316
-    }
2317
-
2318
-
2319
-    /**
2320
-     * metabox content for all template pack and variation selection.
2321
-     *
2322
-     * @return void
2323
-     * @throws DomainException
2324
-     * @throws EE_Error
2325
-     * @throws InvalidArgumentException
2326
-     * @throws ReflectionException
2327
-     * @throws InvalidDataTypeException
2328
-     * @throws InvalidInterfaceException
2329
-     * @since 4.5.0
2330
-     */
2331
-    public function template_pack_meta_box()
2332
-    {
2333
-        $this->_set_message_template_group();
2334
-
2335
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2336
-
2337
-        $tp_select_values = [];
2338
-
2339
-        foreach ($tp_collection as $tp) {
2340
-            // only include template packs that support this messenger and message type!
2341
-            $supports = $tp->get_supports();
2342
-            if (
2343
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2344
-                || ! in_array(
2345
-                    $this->_message_template_group->message_type(),
2346
-                    $supports[ $this->_message_template_group->messenger() ],
2347
-                    true
2348
-                )
2349
-            ) {
2350
-                // not supported
2351
-                continue;
2352
-            }
2353
-
2354
-            $tp_select_values[] = [
2355
-                'text' => $tp->label,
2356
-                'id'   => $tp->dbref,
2357
-            ];
2358
-        }
2359
-
2360
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2361
-        // the default template pack.  This still allows for the odd template pack to override.
2362
-        if (empty($tp_select_values)) {
2363
-            $tp_select_values[] = [
2364
-                'text' => esc_html__('Default', 'event_espresso'),
2365
-                'id'   => 'default',
2366
-            ];
2367
-        }
2368
-
2369
-        // setup variation select values for the currently selected template.
2370
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2371
-            $this->_message_template_group->messenger(),
2372
-            $this->_message_template_group->message_type()
2373
-        );
2374
-        $variations_select_values = [];
2375
-        foreach ($variations as $variation => $label) {
2376
-            $variations_select_values[] = [
2377
-                'text' => $label,
2378
-                'id'   => $variation,
2379
-            ];
2380
-        }
2381
-
2382
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2383
-
2384
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2385
-            'MTP_template_pack',
2386
-            $tp_select_values,
2387
-            $this->_message_template_group->get_template_pack_name()
2388
-        );
2389
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2390
-            'MTP_template_variation',
2391
-            $variations_select_values,
2392
-            $this->_message_template_group->get_template_pack_variation()
2393
-        );
2394
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2395
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2396
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2397
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2398
-
2399
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2400
-
2401
-        EEH_Template::display_template($template, $template_args);
2402
-    }
2403
-
2404
-
2405
-    /**
2406
-     * This meta box holds any extra actions related to Message Templates
2407
-     * For now, this includes Resetting templates to defaults and sending a test email.
2408
-     *
2409
-     * @access  public
2410
-     * @return void
2411
-     * @throws EE_Error
2412
-     */
2413
-    public function extra_actions_meta_box()
2414
-    {
2415
-        $template_form_fields = [];
2416
-
2417
-        $extra_args = [
2418
-            'msgr'   => $this->_message_template_group->messenger(),
2419
-            'mt'     => $this->_message_template_group->message_type(),
2420
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2421
-        ];
2422
-        // first we need to see if there are any fields
2423
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2424
-
2425
-        if (! empty($fields)) {
2426
-            // yup there be fields
2427
-            foreach ($fields as $field => $config) {
2428
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2429
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2430
-                $default  = isset($config['default']) ? $config['default'] : '';
2431
-                $default  = isset($config['value']) ? $config['value'] : $default;
2432
-
2433
-                // if type is hidden and the value is empty
2434
-                // something may have gone wrong so let's correct with the defaults
2435
-                $fix                = $config['input'] === 'hidden'
2436
-                                      && isset($existing[ $field ])
2437
-                                      && empty($existing[ $field ])
2438
-                    ? $default
2439
-                    : '';
2440
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2441
-                    ? $existing[ $field ]
2442
-                    : $fix;
2443
-
2444
-                $template_form_fields[ $field_id ] = [
2445
-                    'name'       => 'test_settings_fld[' . $field . ']',
2446
-                    'label'      => $config['label'],
2447
-                    'input'      => $config['input'],
2448
-                    'type'       => $config['type'],
2449
-                    'required'   => $config['required'],
2450
-                    'validation' => $config['validation'],
2451
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2452
-                    'css_class'  => $config['css_class'],
2453
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2454
-                    'default'    => $default,
2455
-                    'format'     => $config['format'],
2456
-                ];
2457
-            }
2458
-        }
2459
-
2460
-        $test_settings_html = ! empty($template_form_fields)
2461
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2462
-            : '';
2463
-
2464
-        // print out $test_settings_fields
2465
-        if (! empty($test_settings_html)) {
2466
-            $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2467
-            $test_settings_html .= 'name="test_button" value="';
2468
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2469
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2470
-        }
2471
-
2472
-        // and button
2473
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2474
-        $test_settings_html .= '<p>';
2475
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2476
-        $test_settings_html .= '</p>';
2477
-        $test_settings_html .= $this->get_action_link_or_button(
2478
-            'reset_to_default',
2479
-            'reset',
2480
-            $extra_args,
2481
-            'button--primary reset-default-button'
2482
-        );
2483
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2484
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2485
-    }
2486
-
2487
-
2488
-    /**
2489
-     * This returns the shortcode selector skeleton for a given context and field.
2490
-     *
2491
-     * @param string $field           The name of the field retrieving shortcodes for.
2492
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2493
-     * @return string
2494
-     * @throws DomainException
2495
-     * @throws EE_Error
2496
-     * @throws InvalidArgumentException
2497
-     * @throws ReflectionException
2498
-     * @throws InvalidDataTypeException
2499
-     * @throws InvalidInterfaceException
2500
-     * @since 4.9.rc.000
2501
-     */
2502
-    protected function _get_shortcode_selector($field, $linked_input_id)
2503
-    {
2504
-        $template_args = [
2505
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2506
-            'fieldname'       => $field,
2507
-            'linked_input_id' => $linked_input_id,
2508
-        ];
2509
-
2510
-        return EEH_Template::display_template(
2511
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2512
-            $template_args,
2513
-            true
2514
-        );
2515
-    }
2516
-
2517
-
2518
-    /**
2519
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2520
-     * page)
2521
-     *
2522
-     * @access public
2523
-     * @return void
2524
-     * @throws EE_Error
2525
-     * @throws InvalidArgumentException
2526
-     * @throws ReflectionException
2527
-     * @throws InvalidDataTypeException
2528
-     * @throws InvalidInterfaceException
2529
-     */
2530
-    public function shortcode_meta_box()
2531
-    {
2532
-        $shortcodes = $this->_get_shortcodes([], false);
2533
-        // just make sure the shortcodes property is set
2534
-        // $messenger = $this->_message_template_group->messenger_obj();
2535
-        // now let's set the content depending on the status of the shortcodes array
2536
-        if (empty($shortcodes)) {
2537
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2538
-            return;
2539
-        }
2540
-        ?>
20
+	/**
21
+	 * @var EEM_Message
22
+	 */
23
+	private $MSG_MODEL;
24
+
25
+	/**
26
+	 * @var EEM_Message_Template
27
+	 */
28
+	private $MTP_MODEL;
29
+
30
+	/**
31
+	 * @var EEM_Message_Template_Group
32
+	 */
33
+	private $MTG_MODEL;
34
+
35
+	/**
36
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
37
+	 */
38
+	protected $_message_resource_manager;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $_active_message_type_name = '';
44
+
45
+	/**
46
+	 * @var string
47
+	 */
48
+	protected $_active_messenger_name = '';
49
+
50
+	/**
51
+	 * @var EE_messenger $_active_messenger
52
+	 */
53
+	protected $_active_messenger;
54
+
55
+	protected $_activate_meta_box_type;
56
+
57
+	protected $_current_message_meta_box;
58
+
59
+	protected $_current_message_meta_box_object;
60
+
61
+	protected $_context_switcher;
62
+
63
+	protected $_shortcodes           = [];
64
+
65
+	protected $_active_messengers    = [];
66
+
67
+	protected $_active_message_types = [];
68
+
69
+	/**
70
+	 * @var EE_Message_Template_Group $_message_template_group
71
+	 */
72
+	protected $_message_template_group;
73
+
74
+	protected $_m_mt_settings = [];
75
+
76
+
77
+	/**
78
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
+	 * IF there is no group then it gets automatically set to the Default template pack.
80
+	 *
81
+	 * @since 4.5.0
82
+	 *
83
+	 * @var EE_Messages_Template_Pack
84
+	 */
85
+	protected $_template_pack;
86
+
87
+
88
+	/**
89
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
+	 * group is.  If there is no group then it automatically gets set to default.
91
+	 *
92
+	 * @since 4.5.0
93
+	 *
94
+	 * @var string
95
+	 */
96
+	protected $_variation;
97
+
98
+
99
+	/**
100
+	 * @param bool $routing
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	public function __construct($routing = true)
105
+	{
106
+		// make sure messages autoloader is running
107
+		EED_Messages::set_autoloaders();
108
+		parent::__construct($routing);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Message
114
+	 * @throws EE_Error
115
+	 */
116
+	public function getMsgModel()
117
+	{
118
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
119
+			$this->MSG_MODEL = EEM_Message::instance();
120
+		}
121
+		return $this->MSG_MODEL;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return EEM_Message_Template
127
+	 * @throws EE_Error
128
+	 */
129
+	public function getMtpModel()
130
+	{
131
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
+			$this->MTP_MODEL = EEM_Message_Template::instance();
133
+		}
134
+		return $this->MTP_MODEL;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return EEM_Message_Template_Group
140
+	 * @throws EE_Error
141
+	 */
142
+	public function getMtgModel()
143
+	{
144
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
+		}
147
+		return $this->MTG_MODEL;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	protected function _init_page_props()
156
+	{
157
+		$this->page_slug        = EE_MSG_PG_SLUG;
158
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
+		$this->_admin_base_path = EE_MSG_ADMIN;
161
+
162
+		$messenger    = $this->request->getRequestParam('messenger', '');
163
+		$message_type = $this->request->getRequestParam('message_type', '');
164
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
+
167
+		$this->_load_message_resource_manager();
168
+	}
169
+
170
+
171
+	/**
172
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
+	 *
174
+	 * @throws EE_Error
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _load_message_resource_manager()
181
+	{
182
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return array
188
+	 * @throws EE_Error
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 * @deprecated 4.9.9.rc.014
193
+	 */
194
+	public function get_messengers_for_list_table()
195
+	{
196
+		EE_Error::doing_it_wrong(
197
+			__METHOD__,
198
+			sprintf(
199
+				esc_html__(
200
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
+					'event_espresso'
202
+				),
203
+				'Messages_Admin_Page::get_messengers_select_input()'
204
+			),
205
+			'4.9.9.rc.014'
206
+		);
207
+
208
+		$m_values          = [];
209
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
+		// setup messengers for selects
211
+		$i = 1;
212
+		foreach ($active_messengers as $active_messenger) {
213
+			if ($active_messenger instanceof EE_Message) {
214
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
215
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
+				$i++;
217
+			}
218
+		}
219
+
220
+		return $m_values;
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return array
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @deprecated 4.9.9.rc.014
231
+	 */
232
+	public function get_message_types_for_list_table()
233
+	{
234
+		EE_Error::doing_it_wrong(
235
+			__METHOD__,
236
+			sprintf(
237
+				esc_html__(
238
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
+					'event_espresso'
240
+				),
241
+				'Messages_Admin_Page::get_message_types_select_input()'
242
+			),
243
+			'4.9.9.rc.014'
244
+		);
245
+
246
+		$mt_values       = [];
247
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
+		$i               = 1;
249
+		foreach ($active_messages as $active_message) {
250
+			if ($active_message instanceof EE_Message) {
251
+				$mt_values[ $i ]['id']   = $active_message->message_type();
252
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
+				$i++;
254
+			}
255
+		}
256
+
257
+		return $mt_values;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @deprecated 4.9.9.rc.014
268
+	 */
269
+	public function get_contexts_for_message_types_for_list_table()
270
+	{
271
+		EE_Error::doing_it_wrong(
272
+			__METHOD__,
273
+			sprintf(
274
+				esc_html__(
275
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
+					'event_espresso'
277
+				),
278
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
+			),
280
+			'4.9.9.rc.014'
281
+		);
282
+
283
+		$contexts                = [];
284
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
+		foreach ($active_message_contexts as $active_message) {
286
+			if ($active_message instanceof EE_Message) {
287
+				$message_type = $active_message->message_type_object();
288
+				if ($message_type instanceof EE_message_type) {
289
+					$message_type_contexts = $message_type->get_contexts();
290
+					foreach ($message_type_contexts as $context => $context_details) {
291
+						$contexts[ $context ] = $context_details['label'];
292
+					}
293
+				}
294
+			}
295
+		}
296
+
297
+		return $contexts;
298
+	}
299
+
300
+
301
+	/**
302
+	 * Generate select input with provided messenger options array.
303
+	 *
304
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
+	 *                                 labels.
306
+	 * @return string
307
+	 * @throws EE_Error
308
+	 */
309
+	public function get_messengers_select_input($messenger_options)
310
+	{
311
+		// if empty or just one value then just return an empty string
312
+		if (
313
+			empty($messenger_options)
314
+			|| ! is_array($messenger_options)
315
+			|| count($messenger_options) === 1
316
+		) {
317
+			return '';
318
+		}
319
+		// merge in default
320
+		$messenger_options = array_merge(
321
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
+			$messenger_options
323
+		);
324
+		$input             = new EE_Select_Input(
325
+			$messenger_options,
326
+			[
327
+				'html_name'  => 'ee_messenger_filter_by',
328
+				'html_id'    => 'ee_messenger_filter_by',
329
+				'html_class' => 'wide',
330
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
+			]
332
+		);
333
+
334
+		return $input->get_html_for_input();
335
+	}
336
+
337
+
338
+	/**
339
+	 * Generate select input with provided message type options array.
340
+	 *
341
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
+	 *                                    message type labels
343
+	 * @return string
344
+	 * @throws EE_Error
345
+	 */
346
+	public function get_message_types_select_input($message_type_options)
347
+	{
348
+		// if empty or count of options is 1 then just return an empty string
349
+		if (
350
+			empty($message_type_options)
351
+			|| ! is_array($message_type_options)
352
+			|| count($message_type_options) === 1
353
+		) {
354
+			return '';
355
+		}
356
+		// merge in default
357
+		$message_type_options = array_merge(
358
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
+			$message_type_options
360
+		);
361
+		$input                = new EE_Select_Input(
362
+			$message_type_options,
363
+			[
364
+				'html_name'  => 'ee_message_type_filter_by',
365
+				'html_id'    => 'ee_message_type_filter_by',
366
+				'html_class' => 'wide',
367
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
+			]
369
+		);
370
+
371
+		return $input->get_html_for_input();
372
+	}
373
+
374
+
375
+	/**
376
+	 * Generate select input with provide message type contexts array.
377
+	 *
378
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
+	 *                               context label.
380
+	 * @return string
381
+	 * @throws EE_Error
382
+	 */
383
+	public function get_contexts_for_message_types_select_input($context_options)
384
+	{
385
+		// if empty or count of options is one then just return empty string
386
+		if (
387
+			empty($context_options)
388
+			|| ! is_array($context_options)
389
+			|| count($context_options) === 1
390
+		) {
391
+			return '';
392
+		}
393
+		// merge in default
394
+		$context_options = array_merge(
395
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
+			$context_options
397
+		);
398
+		$input           = new EE_Select_Input(
399
+			$context_options,
400
+			[
401
+				'html_name'  => 'ee_context_filter_by',
402
+				'html_id'    => 'ee_context_filter_by',
403
+				'html_class' => 'wide',
404
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
+			]
406
+		);
407
+
408
+		return $input->get_html_for_input();
409
+	}
410
+
411
+
412
+	protected function _ajax_hooks()
413
+	{
414
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
+	}
421
+
422
+
423
+	protected function _define_page_props()
424
+	{
425
+		$this->_admin_page_title = $this->page_label;
426
+		$this->_labels           = [
427
+			'buttons'    => [
428
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
+			],
432
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
+		];
434
+	}
435
+
436
+
437
+	/**
438
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
439
+	 *
440
+	 * @access protected
441
+	 * @return void
442
+	 */
443
+	protected function _set_page_routes()
444
+	{
445
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
+
449
+		$this->_page_routes = [
450
+			'default'                          => [
451
+				'func'       => '_message_queue_list_table',
452
+				'capability' => 'ee_read_global_messages',
453
+			],
454
+			'global_mtps'                      => [
455
+				'func'       => '_ee_default_messages_overview_list_table',
456
+				'capability' => 'ee_read_global_messages',
457
+			],
458
+			'custom_mtps'                      => [
459
+				'func'       => '_custom_mtps_preview',
460
+				'capability' => 'ee_read_messages',
461
+			],
462
+			'add_new_message_template'         => [
463
+				'func'       => 'add_message_template',
464
+				'capability' => 'ee_edit_messages',
465
+				'noheader'   => true,
466
+			],
467
+			'edit_message_template'            => [
468
+				'func'       => '_edit_message_template',
469
+				'capability' => 'ee_edit_message',
470
+				'obj_id'     => $GRP_ID,
471
+			],
472
+			'preview_message'                  => [
473
+				'func'               => '_preview_message',
474
+				'capability'         => 'ee_read_message',
475
+				'obj_id'             => $GRP_ID,
476
+				'noheader'           => true,
477
+				'headers_sent_route' => 'display_preview_message',
478
+			],
479
+			'display_preview_message'          => [
480
+				'func'       => '_display_preview_message',
481
+				'capability' => 'ee_read_message',
482
+				'obj_id'     => $GRP_ID,
483
+			],
484
+			'insert_message_template'          => [
485
+				'func'       => '_insert_or_update_message_template',
486
+				'capability' => 'ee_edit_messages',
487
+				'args'       => ['new' => true],
488
+				'noheader'   => true,
489
+			],
490
+			'update_message_template'          => [
491
+				'func'       => '_insert_or_update_message_template',
492
+				'capability' => 'ee_edit_message',
493
+				'obj_id'     => $GRP_ID,
494
+				'args'       => ['new' => false],
495
+				'noheader'   => true,
496
+			],
497
+			'trash_message_template'           => [
498
+				'func'       => '_trash_or_restore_message_template',
499
+				'capability' => 'ee_delete_message',
500
+				'obj_id'     => $GRP_ID,
501
+				'args'       => ['trash' => true, 'all' => true],
502
+				'noheader'   => true,
503
+			],
504
+			'trash_message_template_context'   => [
505
+				'func'       => '_trash_or_restore_message_template',
506
+				'capability' => 'ee_delete_message',
507
+				'obj_id'     => $GRP_ID,
508
+				'args'       => ['trash' => true],
509
+				'noheader'   => true,
510
+			],
511
+			'restore_message_template'         => [
512
+				'func'       => '_trash_or_restore_message_template',
513
+				'capability' => 'ee_delete_message',
514
+				'obj_id'     => $GRP_ID,
515
+				'args'       => ['trash' => false, 'all' => true],
516
+				'noheader'   => true,
517
+			],
518
+			'restore_message_template_context' => [
519
+				'func'       => '_trash_or_restore_message_template',
520
+				'capability' => 'ee_delete_message',
521
+				'obj_id'     => $GRP_ID,
522
+				'args'       => ['trash' => false],
523
+				'noheader'   => true,
524
+			],
525
+			'delete_message_template'          => [
526
+				'func'       => '_delete_message_template',
527
+				'capability' => 'ee_delete_message',
528
+				'obj_id'     => $GRP_ID,
529
+				'noheader'   => true,
530
+			],
531
+			'reset_to_default'                 => [
532
+				'func'       => '_reset_to_default_template',
533
+				'capability' => 'ee_edit_message',
534
+				'obj_id'     => $GRP_ID,
535
+				'noheader'   => true,
536
+			],
537
+			'settings'                         => [
538
+				'func'       => '_settings',
539
+				'capability' => 'manage_options',
540
+			],
541
+			'update_global_settings'           => [
542
+				'func'       => '_update_global_settings',
543
+				'capability' => 'manage_options',
544
+				'noheader'   => true,
545
+			],
546
+			'generate_now'                     => [
547
+				'func'       => '_generate_now',
548
+				'capability' => 'ee_send_message',
549
+				'noheader'   => true,
550
+			],
551
+			'generate_and_send_now'            => [
552
+				'func'       => '_generate_and_send_now',
553
+				'capability' => 'ee_send_message',
554
+				'noheader'   => true,
555
+			],
556
+			'queue_for_resending'              => [
557
+				'func'       => '_queue_for_resending',
558
+				'capability' => 'ee_send_message',
559
+				'noheader'   => true,
560
+			],
561
+			'send_now'                         => [
562
+				'func'       => '_send_now',
563
+				'capability' => 'ee_send_message',
564
+				'noheader'   => true,
565
+			],
566
+			'delete_ee_message'                => [
567
+				'func'       => '_delete_ee_messages',
568
+				'capability' => 'ee_delete_messages',
569
+				'noheader'   => true,
570
+			],
571
+			'delete_ee_messages'               => [
572
+				'func'       => '_delete_ee_messages',
573
+				'capability' => 'ee_delete_messages',
574
+				'noheader'   => true,
575
+				'obj_id'     => $MSG_ID,
576
+			],
577
+		];
578
+	}
579
+
580
+
581
+	protected function _set_page_config()
582
+	{
583
+		$this->_page_config = [
584
+			'default'                  => [
585
+				'nav'           => [
586
+					'label' => esc_html__('Message Activity', 'event_espresso'),
587
+					'order' => 10,
588
+				],
589
+				'list_table'    => 'EE_Message_List_Table',
590
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
+				'require_nonce' => false,
592
+			],
593
+			'global_mtps'              => [
594
+				'nav'           => [
595
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
+					'order' => 20,
597
+				],
598
+				'list_table'    => 'Messages_Template_List_Table',
599
+				'help_tabs'     => [
600
+					'messages_overview_help_tab'                                => [
601
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
+						'filename' => 'messages_overview',
603
+					],
604
+					'messages_overview_messages_table_column_headings_help_tab' => [
605
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
+						'filename' => 'messages_overview_table_column_headings',
607
+					],
608
+					'messages_overview_messages_filters_help_tab'               => [
609
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
610
+						'filename' => 'messages_overview_filters',
611
+					],
612
+					'messages_overview_messages_views_help_tab'                 => [
613
+						'title'    => esc_html__('Message Views', 'event_espresso'),
614
+						'filename' => 'messages_overview_views',
615
+					],
616
+					'message_overview_message_types_help_tab'                   => [
617
+						'title'    => esc_html__('Message Types', 'event_espresso'),
618
+						'filename' => 'messages_overview_types',
619
+					],
620
+					'messages_overview_messengers_help_tab'                     => [
621
+						'title'    => esc_html__('Messengers', 'event_espresso'),
622
+						'filename' => 'messages_overview_messengers',
623
+					],
624
+				],
625
+				'require_nonce' => false,
626
+			],
627
+			'custom_mtps'              => [
628
+				'nav'           => [
629
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
+					'order' => 30,
631
+				],
632
+				'help_tabs'     => [],
633
+				'require_nonce' => false,
634
+			],
635
+			'add_new_message_template' => [
636
+				'nav'           => [
637
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
+					'order'      => 5,
639
+					'persistent' => false,
640
+				],
641
+				'require_nonce' => false,
642
+			],
643
+			'edit_message_template'    => [
644
+				'labels'        => [
645
+					'buttons'    => [
646
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
+					],
648
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
+				],
650
+				'nav'           => [
651
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
+					'order'      => 5,
653
+					'persistent' => false,
654
+					'url'        => '',
655
+				],
656
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
+				'has_metaboxes' => true,
658
+				'help_tabs'     => [
659
+					'edit_message_template'            => [
660
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
+						'callback' => 'edit_message_template_help_tab',
662
+					],
663
+					'message_templates_help_tab'       => [
664
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
665
+						'filename' => 'messages_templates',
666
+					],
667
+					'message_template_shortcodes'      => [
668
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
+						'callback' => 'message_template_shortcodes_help_tab',
670
+					],
671
+					'message_preview_help_tab'         => [
672
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
673
+						'filename' => 'messages_preview',
674
+					],
675
+					'messages_overview_other_help_tab' => [
676
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
677
+						'filename' => 'messages_overview_other',
678
+					],
679
+				],
680
+				'require_nonce' => false,
681
+			],
682
+			'display_preview_message'  => [
683
+				'nav'           => [
684
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
685
+					'order'      => 5,
686
+					'url'        => '',
687
+					'persistent' => false,
688
+				],
689
+				'help_tabs'     => [
690
+					'preview_message' => [
691
+						'title'    => esc_html__('About Previews', 'event_espresso'),
692
+						'callback' => 'preview_message_help_tab',
693
+					],
694
+				],
695
+				'require_nonce' => false,
696
+			],
697
+			'settings'                 => [
698
+				'nav'           => [
699
+					'label' => esc_html__('Settings', 'event_espresso'),
700
+					'order' => 40,
701
+				],
702
+				'metaboxes'     => ['_messages_settings_metaboxes'],
703
+				'help_tabs'     => [
704
+					'messages_settings_help_tab'               => [
705
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
+						'filename' => 'messages_settings',
707
+					],
708
+					'messages_settings_message_types_help_tab' => [
709
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
+						'filename' => 'messages_settings_message_types',
711
+					],
712
+					'messages_settings_messengers_help_tab'    => [
713
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
+						'filename' => 'messages_settings_messengers',
715
+					],
716
+				],
717
+				'require_nonce' => false,
718
+			],
719
+		];
720
+	}
721
+
722
+
723
+	protected function _add_screen_options()
724
+	{
725
+		// todo
726
+	}
727
+
728
+
729
+	protected function _add_screen_options_global_mtps()
730
+	{
731
+		/**
732
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
734
+		 */
735
+		$page_title              = $this->_admin_page_title;
736
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
+		$this->_per_page_screen_option();
738
+		$this->_admin_page_title = $page_title;
739
+	}
740
+
741
+
742
+	protected function _add_screen_options_default()
743
+	{
744
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
+		$this->_per_page_screen_option();
746
+	}
747
+
748
+
749
+	// none of the below group are currently used for Messages
750
+	protected function _add_feature_pointers()
751
+	{
752
+	}
753
+
754
+
755
+	public function admin_init()
756
+	{
757
+	}
758
+
759
+
760
+	public function admin_notices()
761
+	{
762
+	}
763
+
764
+
765
+	public function admin_footer_scripts()
766
+	{
767
+	}
768
+
769
+
770
+	public function messages_help_tab()
771
+	{
772
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
+	}
774
+
775
+
776
+	public function messengers_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
+	}
780
+
781
+
782
+	public function message_types_help_tab()
783
+	{
784
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
+	}
786
+
787
+
788
+	public function messages_overview_help_tab()
789
+	{
790
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
+	}
792
+
793
+
794
+	public function message_templates_help_tab()
795
+	{
796
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
+	}
798
+
799
+
800
+	public function edit_message_template_help_tab()
801
+	{
802
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
+						. esc_attr__('Editor Title', 'event_espresso')
804
+						. '" />';
805
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
807
+						. '" />';
808
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
810
+						. '" />';
811
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
813
+						. '" />';
814
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
+						. esc_attr__('Publish Metabox', 'event_espresso')
816
+						. '" />';
817
+		EEH_Template::display_template(
818
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
+			$args
820
+		);
821
+	}
822
+
823
+
824
+	/**
825
+	 * @throws ReflectionException
826
+	 * @throws EE_Error
827
+	 */
828
+	public function message_template_shortcodes_help_tab()
829
+	{
830
+		$this->_set_shortcodes();
831
+		$args['shortcodes'] = $this->_shortcodes;
832
+		EEH_Template::display_template(
833
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
+			$args
835
+		);
836
+	}
837
+
838
+
839
+	public function preview_message_help_tab()
840
+	{
841
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
+	}
843
+
844
+
845
+	public function settings_help_tab()
846
+	{
847
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
+		$args['img3'] = '<div class="switch">'
852
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
+						. ' type="checkbox" checked>'
854
+						. '<label for="ee-on-off-toggle-on"></label>'
855
+						. '</div>';
856
+		$args['img4'] = '<div class="switch">'
857
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
+						. ' type="checkbox">'
859
+						. '<label for="ee-on-off-toggle-on"></label>'
860
+						. '</div>';
861
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
+	}
863
+
864
+
865
+	public function load_scripts_styles()
866
+	{
867
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
+		wp_enqueue_style('espresso_ee_msg');
869
+
870
+		wp_register_script(
871
+			'ee-messages-settings',
872
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
874
+			EVENT_ESPRESSO_VERSION,
875
+			true
876
+		);
877
+		wp_register_script(
878
+			'ee-msg-list-table-js',
879
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
+			['ee-dialog'],
881
+			EVENT_ESPRESSO_VERSION
882
+		);
883
+	}
884
+
885
+
886
+	public function load_scripts_styles_default()
887
+	{
888
+		wp_enqueue_script('ee-msg-list-table-js');
889
+	}
890
+
891
+
892
+	public function wp_editor_css($mce_css)
893
+	{
894
+		// if we're on the edit_message_template route
895
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
+			$message_type_name = $this->_active_message_type_name;
897
+
898
+			// we're going to REPLACE the existing mce css
899
+			// we need to get the css file location from the active messenger
900
+			$mce_css = $this->_active_messenger->get_variation(
901
+				$this->_template_pack,
902
+				$message_type_name,
903
+				true,
904
+				'wpeditor',
905
+				$this->_variation
906
+			);
907
+		}
908
+
909
+		return $mce_css;
910
+	}
911
+
912
+
913
+	/**
914
+	 * @throws EE_Error
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function load_scripts_styles_edit_message_template()
918
+	{
919
+
920
+		$this->_set_shortcodes();
921
+
922
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
+			esc_html__(
924
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
+				'event_espresso'
926
+			),
927
+			$this->_message_template_group->messenger_obj()->label['singular'],
928
+			$this->_message_template_group->message_type_obj()->label['singular']
929
+		);
930
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
+			'event_espresso'
933
+		);
934
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
+			'event_espresso'
937
+		);
938
+
939
+		wp_register_script(
940
+			'ee_msgs_edit_js',
941
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
+			['jquery'],
943
+			EVENT_ESPRESSO_VERSION
944
+		);
945
+
946
+		wp_enqueue_script('ee_admin_js');
947
+		wp_enqueue_script('ee_msgs_edit_js');
948
+
949
+		// add in special css for tiny_mce
950
+		add_filter('mce_css', [$this, 'wp_editor_css']);
951
+	}
952
+
953
+
954
+	/**
955
+	 * @throws EE_Error
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function load_scripts_styles_display_preview_message()
959
+	{
960
+		$this->_set_message_template_group();
961
+		if ($this->_active_messenger_name) {
962
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
+				$this->_active_messenger_name
964
+			);
965
+		}
966
+
967
+		wp_enqueue_style(
968
+			'espresso_preview_css',
969
+			$this->_active_messenger->get_variation(
970
+				$this->_template_pack,
971
+				$this->_active_message_type_name,
972
+				true,
973
+				'preview',
974
+				$this->_variation
975
+			)
976
+		);
977
+	}
978
+
979
+
980
+	public function load_scripts_styles_settings()
981
+	{
982
+		wp_register_style(
983
+			'ee-message-settings',
984
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
+			[],
986
+			EVENT_ESPRESSO_VERSION
987
+		);
988
+		wp_enqueue_style('ee-text-links');
989
+		wp_enqueue_style('ee-message-settings');
990
+		wp_enqueue_script('ee-messages-settings');
991
+	}
992
+
993
+
994
+	/**
995
+	 * set views array for List Table
996
+	 */
997
+	public function _set_list_table_views_global_mtps()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'  => 'in_use',
1002
+				'label' => esc_html__('In Use', 'event_espresso'),
1003
+				'count' => 0,
1004
+			],
1005
+		];
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Set views array for the Custom Template List Table
1011
+	 */
1012
+	public function _set_list_table_views_custom_mtps()
1013
+	{
1014
+		$this->_set_list_table_views_global_mtps();
1015
+		$this->_views['in_use']['bulk_action'] = [
1016
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
+		];
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * set views array for message queue list table
1023
+	 *
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidInterfaceException
1026
+	 * @throws InvalidArgumentException
1027
+	 * @throws EE_Error
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	public function _set_list_table_views_default()
1031
+	{
1032
+		EE_Registry::instance()->load_helper('Template');
1033
+
1034
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
+			'ee_send_message',
1036
+			'message_list_table_bulk_actions'
1037
+		)
1038
+			? [
1039
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
+			]
1044
+			: [];
1045
+
1046
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_delete_messages',
1048
+			'message_list_table_bulk_actions'
1049
+		)
1050
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
+			: [];
1052
+
1053
+
1054
+		$this->_views = [
1055
+			'all' => [
1056
+				'slug'        => 'all',
1057
+				'label'       => esc_html__('All', 'event_espresso'),
1058
+				'count'       => 0,
1059
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
+			],
1061
+		];
1062
+
1063
+
1064
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
+				continue;
1067
+			}
1068
+			$status_bulk_actions = $common_bulk_actions;
1069
+			// unset bulk actions not applying to status
1070
+			if (! empty($status_bulk_actions)) {
1071
+				switch ($status) {
1072
+					case EEM_Message::status_idle:
1073
+					case EEM_Message::status_resend:
1074
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
+						break;
1076
+
1077
+					case EEM_Message::status_failed:
1078
+					case EEM_Message::status_debug_only:
1079
+					case EEM_Message::status_messenger_executing:
1080
+						$status_bulk_actions = [];
1081
+						break;
1082
+
1083
+					case EEM_Message::status_incomplete:
1084
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
+						break;
1086
+
1087
+					case EEM_Message::status_retry:
1088
+					case EEM_Message::status_sent:
1089
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
+						break;
1091
+				}
1092
+			}
1093
+
1094
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1095
+			if ($status === EEM_Message::status_messenger_executing) {
1096
+				continue;
1097
+			}
1098
+
1099
+			$this->_views[ strtolower($status) ] = [
1100
+				'slug'        => strtolower($status),
1101
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
+				'count'       => 0,
1103
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
+			];
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	protected function _ee_default_messages_overview_list_table()
1113
+	{
1114
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * @throws EE_Error
1121
+	 * @throws ReflectionException
1122
+	 */
1123
+	protected function _message_queue_list_table()
1124
+	{
1125
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
+		$this->_template_args['per_column']        = 6;
1127
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
+		$message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1129
+		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1130
+		$this->display_admin_list_table_page_with_no_sidebar();
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * @throws EE_Error
1136
+	 */
1137
+	protected function _message_legend_items()
1138
+	{
1139
+
1140
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
+		$action_items       = [];
1142
+
1143
+		foreach ($action_css_classes as $action_item => $action_details) {
1144
+			if ($action_item === 'see_notifications_for') {
1145
+				continue;
1146
+			}
1147
+			$action_items[ $action_item ] = [
1148
+				'class' => $action_details['css_class'],
1149
+				'desc'  => $action_details['label'],
1150
+			];
1151
+		}
1152
+
1153
+		/** @var array $status_items status legend setup */
1154
+		$status_items = [
1155
+			'sent_status'                => [
1156
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1157
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
+			],
1159
+			'idle_status'                => [
1160
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1161
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
+			],
1163
+			'failed_status'              => [
1164
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1165
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
+			],
1167
+			'messenger_executing_status' => [
1168
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1169
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
+			],
1171
+			'resend_status'              => [
1172
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1173
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
+			],
1175
+			'incomplete_status'          => [
1176
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1177
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
+			],
1179
+			'retry_status'               => [
1180
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1181
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
+			],
1183
+		];
1184
+		if (EEM_Message::debug()) {
1185
+			$status_items['debug_only_status'] = [
1186
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1187
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
+			];
1189
+		}
1190
+
1191
+		return array_merge($action_items, $status_items);
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * @throws EE_Error
1197
+	 */
1198
+	protected function _custom_mtps_preview()
1199
+	{
1200
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
+												. ' alt="' . esc_attr__(
1203
+													'Preview Custom Message Templates screenshot',
1204
+													'event_espresso'
1205
+												) . '" />';
1206
+		$this->_template_args['preview_text'] = '<strong>'
1207
+												. esc_html__(
1208
+													'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1209
+													'event_espresso'
1210
+												)
1211
+												. '</strong>';
1212
+
1213
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * get_message_templates
1219
+	 * This gets all the message templates for listing on the overview list.
1220
+	 *
1221
+	 * @access public
1222
+	 * @param int    $per_page the amount of templates groups to show per page
1223
+	 * @param string $type     the current _view we're getting templates for
1224
+	 * @param bool   $count    return count?
1225
+	 * @param bool   $all      disregard any paging info (get all data);
1226
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
+	 * @return array
1228
+	 * @throws EE_Error
1229
+	 * @throws InvalidArgumentException
1230
+	 * @throws InvalidDataTypeException
1231
+	 * @throws InvalidInterfaceException
1232
+	 */
1233
+	public function get_message_templates(
1234
+		$per_page = 10,
1235
+		$type = 'in_use',
1236
+		$count = false,
1237
+		$all = false,
1238
+		$global = true
1239
+	) {
1240
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
+		$this->request->setRequestParam('orderby', $orderby);
1242
+
1243
+		$order        = $this->request->getRequestParam('order', 'ASC');
1244
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
+
1247
+		$offset = ($current_page - 1) * $per_page;
1248
+		$limit  = $all ? null : [$offset, $per_page];
1249
+
1250
+		// options will match what is in the _views array property
1251
+		return $type === 'in_use'
1252
+			? $this->getMtgModel()->get_all_active_message_templates(
1253
+				$orderby,
1254
+				$order,
1255
+				$limit,
1256
+				$count,
1257
+				$global,
1258
+				true
1259
+			)
1260
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
+				$orderby,
1262
+				$order,
1263
+				$limit,
1264
+				$count,
1265
+				$global
1266
+			);
1267
+	}
1268
+
1269
+
1270
+	/**
1271
+	 * filters etc might need a list of installed message_types
1272
+	 *
1273
+	 * @return array an array of message type objects
1274
+	 */
1275
+	public function get_installed_message_types()
1276
+	{
1277
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
+		$installed               = [];
1279
+
1280
+		foreach ($installed_message_types as $message_type) {
1281
+			$installed[ $message_type->name ] = $message_type;
1282
+		}
1283
+
1284
+		return $installed;
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1290
+	 *
1291
+	 * @param string $message_type
1292
+	 * @param string $messenger
1293
+	 * @param string $GRP_ID
1294
+	 *
1295
+	 * @throws EE_error
1296
+	 * @throws ReflectionException
1297
+	 */
1298
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
+	{
1300
+		// set values override any request data
1301
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
+
1305
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
+		if (empty($message_type) || empty($messenger)) {
1307
+			throw new EE_Error(
1308
+				esc_html__(
1309
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
+					'event_espresso'
1311
+				)
1312
+			);
1313
+		}
1314
+
1315
+		// we need the GRP_ID for the template being used as the base for the new template
1316
+		if (empty($GRP_ID)) {
1317
+			throw new EE_Error(
1318
+				esc_html__(
1319
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
+					'event_espresso'
1321
+				)
1322
+			);
1323
+		}
1324
+
1325
+		// let's just make sure the template gets generated!
1326
+
1327
+		// we need to reassign some variables for what the insert is expecting
1328
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1329
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1330
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
+
1332
+		$this->_insert_or_update_message_template(true);
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * @param string $message_type     message type slug
1338
+	 * @param string $messenger        messenger slug
1339
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
+	 *                                 off of.
1341
+	 * @throws EE_error
1342
+	 * @throws ReflectionException
1343
+	 * @deprecated 4.10.29.p
1344
+	 */
1345
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
+	{
1347
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * _edit_message_template
1353
+	 *
1354
+	 * @access protected
1355
+	 * @return void
1356
+	 * @throws InvalidIdentifierException
1357
+	 * @throws DomainException
1358
+	 * @throws EE_Error
1359
+	 * @throws InvalidArgumentException
1360
+	 * @throws ReflectionException
1361
+	 * @throws InvalidDataTypeException
1362
+	 * @throws InvalidInterfaceException
1363
+	 */
1364
+	protected function _edit_message_template()
1365
+	{
1366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
+		$template_fields = '';
1368
+		$sidebar_fields  = '';
1369
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
+		// valid html in the templates.
1371
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
+
1373
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
+
1376
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1377
+		$message_template_group = $this->_message_template_group;
1378
+		$c_label                = $message_template_group->context_label();
1379
+		$c_config               = $message_template_group->contexts_config();
1380
+
1381
+		reset($c_config);
1382
+		$context = $this->request->getRequestParam('context', key($c_config));
1383
+		$context = strtolower($context);
1384
+
1385
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
+
1387
+		$edit_message_template_form_url = add_query_arg(
1388
+			['action' => $action, 'noheader' => true],
1389
+			EE_MSG_ADMIN_URL
1390
+		);
1391
+
1392
+		// set active messenger for this view
1393
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
+			$message_template_group->messenger()
1395
+		);
1396
+		$this->_active_message_type_name = $message_template_group->message_type();
1397
+
1398
+
1399
+		// Do we have any validation errors?
1400
+		$validators = $this->_get_transient();
1401
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
+
1403
+
1404
+		// we need to assemble the title from Various details
1405
+		$context_label = sprintf(
1406
+			esc_html__('(%s %s)', 'event_espresso'),
1407
+			$c_config[ $context ]['label'],
1408
+			ucwords($c_label['label'])
1409
+		);
1410
+
1411
+		$title = sprintf(
1412
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1413
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1414
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1415
+			$context_label
1416
+		);
1417
+
1418
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1419
+		$this->_template_args['message_template'] = $message_template_group;
1420
+		$this->_template_args['is_extra_fields']  = false;
1421
+
1422
+
1423
+		// let's get EEH_MSG_Template so we can get template form fields
1424
+		$template_field_structure = EEH_MSG_Template::get_fields(
1425
+			$message_template_group->messenger(),
1426
+			$message_template_group->message_type()
1427
+		);
1428
+
1429
+		if (! $template_field_structure) {
1430
+			$template_field_structure = false;
1431
+			$template_fields          = esc_html__(
1432
+				'There was an error in assembling the fields for this display (you should see an error message)',
1433
+				'event_espresso'
1434
+			);
1435
+		}
1436
+
1437
+
1438
+		$message_templates = $message_template_group->context_templates();
1439
+
1440
+
1441
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
+		// will get handled in the "extra" array.
1443
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
+				unset($template_field_structure[ $context ][ $reference_field ]);
1446
+			}
1447
+		}
1448
+
1449
+		// let's loop through the template_field_structure and actually assemble the input fields!
1450
+		if (! empty($template_field_structure)) {
1451
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
+				// the extra array and reset them.
1454
+				if ($template_field === 'extra') {
1455
+					$this->_template_args['is_extra_fields'] = true;
1456
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
+						$message_template = $message_templates[ $context ][ $reference_field ];
1458
+						$content          = $message_template instanceof EE_Message_Template
1459
+							? $message_template->get('MTP_content')
1460
+							: '';
1461
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1462
+							// let's verify if we need this extra field via the shortcodes parameter.
1463
+							$continue = false;
1464
+							if (isset($extra_array['shortcodes_required'])) {
1465
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
+										$continue = true;
1468
+									}
1469
+								}
1470
+								if ($continue) {
1471
+									continue;
1472
+								}
1473
+							}
1474
+
1475
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1476
+
1477
+							$template_form_fields[ $field_id ]         = $extra_array;
1478
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
+																		 . $reference_field
1480
+																		 . '][content]['
1481
+																		 . $extra_field . ']';
1482
+							$css_class                                 = isset($extra_array['css_class'])
1483
+								? $extra_array['css_class']
1484
+								: '';
1485
+
1486
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
+																			  && in_array($extra_field, $v_fields, true)
1488
+																			  && (
1489
+																				  is_array($validators[ $extra_field ])
1490
+																				  && isset($validators[ $extra_field ]['msg'])
1491
+																			  )
1492
+								? 'validate-error ' . $css_class
1493
+								: $css_class;
1494
+
1495
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
+																		  && isset($content[ $extra_field ])
1497
+								? $content[ $extra_field ]
1498
+								: '';
1499
+
1500
+							// do we have a validation error?  if we do then let's use that value instead
1501
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
+								? $validators[ $extra_field ]['value']
1503
+								: $template_form_fields[ $field_id ]['value'];
1504
+
1505
+
1506
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
+
1508
+							// shortcode selector
1509
+							$field_name_to_use                                   = $extra_field === 'main'
1510
+								? 'content'
1511
+								: $extra_field;
1512
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
+								$field_name_to_use,
1514
+								$field_id
1515
+							);
1516
+						}
1517
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
+						$template_field_template_name_id = $reference_field . '-name';
1519
+
1520
+						$template_form_fields[ $template_field_MTP_id ] = [
1521
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
+							'label'      => null,
1523
+							'input'      => 'hidden',
1524
+							'type'       => 'int',
1525
+							'required'   => false,
1526
+							'validation' => false,
1527
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
+							'css_class'  => '',
1529
+							'format'     => '%d',
1530
+							'db-col'     => 'MTP_ID',
1531
+						];
1532
+
1533
+						$template_form_fields[ $template_field_template_name_id ] = [
1534
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
+							'label'      => null,
1536
+							'input'      => 'hidden',
1537
+							'type'       => 'string',
1538
+							'required'   => false,
1539
+							'validation' => true,
1540
+							'value'      => $reference_field,
1541
+							'css_class'  => '',
1542
+							'format'     => '%s',
1543
+							'db-col'     => 'MTP_template_field',
1544
+						];
1545
+					}
1546
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
+				} else {
1548
+					$field_id                                   = $template_field . '-content';
1549
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1550
+					$template_form_fields[ $field_id ]['name']  =
1551
+						'MTP_template_fields[' . $template_field . '][content]';
1552
+					$message_template                           =
1553
+						isset($message_templates[ $context ][ $template_field ])
1554
+							? $message_templates[ $context ][ $template_field ]
1555
+							: null;
1556
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
+																  && is_array($message_templates[ $context ])
1558
+																  && $message_template instanceof EE_Message_Template
1559
+						? $message_template->get('MTP_content')
1560
+						: '';
1561
+
1562
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1563
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
+						? $validators[ $template_field ]['value']
1565
+						: $template_form_fields[ $field_id ]['value'];
1566
+
1567
+
1568
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
+					$css_class                                      = isset($field_setup_array['css_class'])
1570
+						? $field_setup_array['css_class']
1571
+						: '';
1572
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
+																	  && in_array($template_field, $v_fields, true)
1574
+																	  && isset($validators[ $template_field ]['msg'])
1575
+						? 'validate-error ' . $css_class
1576
+						: $css_class;
1577
+
1578
+					// shortcode selector
1579
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
+						$template_field,
1581
+						$field_id
1582
+					);
1583
+				}
1584
+
1585
+				// k took care of content field(s) now let's take care of others.
1586
+
1587
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
+				$template_field_field_template_name_id = $template_field . '-name';
1589
+
1590
+				// foreach template field there are actually two form fields created
1591
+				$template_form_fields[ $template_field_MTP_id ] = [
1592
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
+					'label'      => null,
1594
+					'input'      => 'hidden',
1595
+					'type'       => 'int',
1596
+					'required'   => false,
1597
+					'validation' => true,
1598
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
+					'css_class'  => '',
1600
+					'format'     => '%d',
1601
+					'db-col'     => 'MTP_ID',
1602
+				];
1603
+
1604
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1605
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
+					'label'      => null,
1607
+					'input'      => 'hidden',
1608
+					'type'       => 'string',
1609
+					'required'   => false,
1610
+					'validation' => true,
1611
+					'value'      => $template_field,
1612
+					'css_class'  => '',
1613
+					'format'     => '%s',
1614
+					'db-col'     => 'MTP_template_field',
1615
+				];
1616
+			}
1617
+
1618
+			// add other fields
1619
+			$template_form_fields['ee-msg-current-context'] = [
1620
+				'name'       => 'MTP_context',
1621
+				'label'      => null,
1622
+				'input'      => 'hidden',
1623
+				'type'       => 'string',
1624
+				'required'   => false,
1625
+				'validation' => true,
1626
+				'value'      => $context,
1627
+				'css_class'  => '',
1628
+				'format'     => '%s',
1629
+				'db-col'     => 'MTP_context',
1630
+			];
1631
+
1632
+			$template_form_fields['ee-msg-grp-id'] = [
1633
+				'name'       => 'GRP_ID',
1634
+				'label'      => null,
1635
+				'input'      => 'hidden',
1636
+				'type'       => 'int',
1637
+				'required'   => false,
1638
+				'validation' => true,
1639
+				'value'      => $GRP_ID,
1640
+				'css_class'  => '',
1641
+				'format'     => '%d',
1642
+				'db-col'     => 'GRP_ID',
1643
+			];
1644
+
1645
+			$template_form_fields['ee-msg-messenger'] = [
1646
+				'name'       => 'MTP_messenger',
1647
+				'label'      => null,
1648
+				'input'      => 'hidden',
1649
+				'type'       => 'string',
1650
+				'required'   => false,
1651
+				'validation' => true,
1652
+				'value'      => $message_template_group->messenger(),
1653
+				'css_class'  => '',
1654
+				'format'     => '%s',
1655
+				'db-col'     => 'MTP_messenger',
1656
+			];
1657
+
1658
+			$template_form_fields['ee-msg-message-type'] = [
1659
+				'name'       => 'MTP_message_type',
1660
+				'label'      => null,
1661
+				'input'      => 'hidden',
1662
+				'type'       => 'string',
1663
+				'required'   => false,
1664
+				'validation' => true,
1665
+				'value'      => $message_template_group->message_type(),
1666
+				'css_class'  => '',
1667
+				'format'     => '%s',
1668
+				'db-col'     => 'MTP_message_type',
1669
+			];
1670
+
1671
+			$sidebar_form_fields['ee-msg-is-global'] = [
1672
+				'name'       => 'MTP_is_global',
1673
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1674
+				'input'      => 'hidden',
1675
+				'type'       => 'int',
1676
+				'required'   => false,
1677
+				'validation' => true,
1678
+				'value'      => $message_template_group->get('MTP_is_global'),
1679
+				'css_class'  => '',
1680
+				'format'     => '%d',
1681
+				'db-col'     => 'MTP_is_global',
1682
+			];
1683
+
1684
+			$sidebar_form_fields['ee-msg-is-override'] = [
1685
+				'name'       => 'MTP_is_override',
1686
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
+				'type'       => 'int',
1689
+				'required'   => false,
1690
+				'validation' => true,
1691
+				'value'      => $message_template_group->get('MTP_is_override'),
1692
+				'css_class'  => '',
1693
+				'format'     => '%d',
1694
+				'db-col'     => 'MTP_is_override',
1695
+			];
1696
+
1697
+			$sidebar_form_fields['ee-msg-is-active'] = [
1698
+				'name'       => 'MTP_is_active',
1699
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1700
+				'input'      => 'hidden',
1701
+				'type'       => 'int',
1702
+				'required'   => false,
1703
+				'validation' => true,
1704
+				'value'      => $message_template_group->is_active(),
1705
+				'css_class'  => '',
1706
+				'format'     => '%d',
1707
+				'db-col'     => 'MTP_is_active',
1708
+			];
1709
+
1710
+			$sidebar_form_fields['ee-msg-deleted'] = [
1711
+				'name'       => 'MTP_deleted',
1712
+				'label'      => null,
1713
+				'input'      => 'hidden',
1714
+				'type'       => 'int',
1715
+				'required'   => false,
1716
+				'validation' => true,
1717
+				'value'      => $message_template_group->get('MTP_deleted'),
1718
+				'css_class'  => '',
1719
+				'format'     => '%d',
1720
+				'db-col'     => 'MTP_deleted',
1721
+			];
1722
+			$sidebar_form_fields['ee-msg-author']  = [
1723
+				'name'       => 'MTP_user_id',
1724
+				'label'      => esc_html__('Author', 'event_espresso'),
1725
+				'input'      => 'hidden',
1726
+				'type'       => 'int',
1727
+				'required'   => false,
1728
+				'validation' => false,
1729
+				'value'      => $message_template_group->user(),
1730
+				'format'     => '%d',
1731
+				'db-col'     => 'MTP_user_id',
1732
+			];
1733
+
1734
+			$sidebar_form_fields['ee-msg-route'] = [
1735
+				'name'  => 'action',
1736
+				'input' => 'hidden',
1737
+				'type'  => 'string',
1738
+				'value' => $action,
1739
+			];
1740
+
1741
+			$sidebar_form_fields['ee-msg-id']        = [
1742
+				'name'  => 'id',
1743
+				'input' => 'hidden',
1744
+				'type'  => 'int',
1745
+				'value' => $GRP_ID,
1746
+			];
1747
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
+				'name'  => $action . '_nonce',
1749
+				'input' => 'hidden',
1750
+				'type'  => 'string',
1751
+				'value' => wp_create_nonce($action . '_nonce'),
1752
+			];
1753
+
1754
+			$template_switch = $this->request->getRequestParam('template_switch');
1755
+			if ($template_switch) {
1756
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1757
+					'name'  => 'template_switch',
1758
+					'input' => 'hidden',
1759
+					'type'  => 'int',
1760
+					'value' => 1,
1761
+				];
1762
+			}
1763
+
1764
+
1765
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
+		} //end if ( !empty($template_field_structure) )
1768
+
1769
+		// set extra content for publish box
1770
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
+		$this->_set_publish_post_box_vars(
1772
+			'id',
1773
+			$GRP_ID,
1774
+			false,
1775
+			add_query_arg(
1776
+				['action' => 'global_mtps'],
1777
+				$this->_admin_base_url
1778
+			)
1779
+		);
1780
+
1781
+		// add preview button
1782
+		$preview_url    = parent::add_query_args_and_nonce(
1783
+			[
1784
+				'message_type' => $message_template_group->message_type(),
1785
+				'messenger'    => $message_template_group->messenger(),
1786
+				'context'      => $context,
1787
+				'GRP_ID'       => $GRP_ID,
1788
+				'evt_id'       => $EVT_ID ?: false,
1789
+				'action'       => 'preview_message',
1790
+			],
1791
+			$this->_admin_base_url
1792
+		);
1793
+		$preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1794
+						  . esc_html__('Preview', 'event_espresso')
1795
+						  . '</a>';
1796
+
1797
+
1798
+		// setup context switcher
1799
+		$this->_set_context_switcher(
1800
+			$message_template_group,
1801
+			[
1802
+				'page'    => 'espresso_messages',
1803
+				'action'  => 'edit_message_template',
1804
+				'id'      => $GRP_ID,
1805
+				'evt_id'  => $EVT_ID,
1806
+				'context' => $context,
1807
+				'extra'   => $preview_button,
1808
+			]
1809
+		);
1810
+
1811
+
1812
+		// main box
1813
+		$this->_template_args['template_fields']                         = $template_fields;
1814
+		$this->_template_args['sidebar_box_id']                          = 'details';
1815
+		$this->_template_args['action']                                  = $action;
1816
+		$this->_template_args['context']                                 = $context;
1817
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
+		$this->_template_args['learn_more_about_message_templates_link'] =
1819
+			$this->_learn_more_about_message_templates_link();
1820
+
1821
+
1822
+		$this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1823
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
+			$message_template_group,
1825
+			$context,
1826
+			$context_label
1827
+		);
1828
+		$this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1829
+		$this->_template_args['before_admin_page_content'] .= '</div>';
1830
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1831
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1832
+
1833
+		$this->_template_path = $this->_template_args['GRP_ID']
1834
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1835
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1836
+
1837
+		// send along EE_Message_Template_Group object for further template use.
1838
+		$this->_template_args['MTP'] = $message_template_group;
1839
+
1840
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1841
+			$this->_template_path,
1842
+			$this->_template_args,
1843
+			true
1844
+		);
1845
+
1846
+
1847
+		// finally, let's set the admin_page title
1848
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1849
+
1850
+
1851
+		// we need to take care of setting the shortcodes property for use elsewhere.
1852
+		$this->_set_shortcodes();
1853
+
1854
+
1855
+		// final template wrapper
1856
+		$this->display_admin_page_with_sidebar();
1857
+	}
1858
+
1859
+
1860
+	public function filter_tinymce_init($mceInit, $editor_id)
1861
+	{
1862
+		return $mceInit;
1863
+	}
1864
+
1865
+
1866
+	public function add_context_switcher()
1867
+	{
1868
+		return $this->_context_switcher;
1869
+	}
1870
+
1871
+
1872
+	/**
1873
+	 * Adds the activation/deactivation toggle for the message template context.
1874
+	 *
1875
+	 * @param EE_Message_Template_Group $message_template_group
1876
+	 * @param string                    $context
1877
+	 * @param string                    $context_label
1878
+	 * @return string
1879
+	 * @throws DomainException
1880
+	 * @throws EE_Error
1881
+	 * @throws InvalidIdentifierException
1882
+	 * @throws ReflectionException
1883
+	 */
1884
+	protected function add_active_context_element(
1885
+		EE_Message_Template_Group $message_template_group,
1886
+		$context,
1887
+		$context_label
1888
+	) {
1889
+		$template_args = [
1890
+			'context'                   => $context,
1891
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1892
+			'is_active'                 => $message_template_group->is_context_active($context),
1893
+			'on_off_action'             => $message_template_group->is_context_active($context)
1894
+				? 'context-off'
1895
+				: 'context-on',
1896
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1897
+			'message_template_group_id' => $message_template_group->ID(),
1898
+		];
1899
+		return EEH_Template::display_template(
1900
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1901
+			$template_args,
1902
+			true
1903
+		);
1904
+	}
1905
+
1906
+
1907
+	/**
1908
+	 * Ajax callback for `toggle_context_template` ajax action.
1909
+	 * Handles toggling the message context on or off.
1910
+	 *
1911
+	 * @throws EE_Error
1912
+	 * @throws InvalidArgumentException
1913
+	 * @throws InvalidDataTypeException
1914
+	 * @throws InvalidIdentifierException
1915
+	 * @throws InvalidInterfaceException
1916
+	 */
1917
+	public function toggle_context_template()
1918
+	{
1919
+		$success = true;
1920
+		// check for required data
1921
+		if (
1922
+			! (
1923
+				$this->request->requestParamIsSet('message_template_group_id')
1924
+				&& $this->request->requestParamIsSet('context')
1925
+				&& $this->request->requestParamIsSet('status')
1926
+			)
1927
+		) {
1928
+			EE_Error::add_error(
1929
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1930
+				__FILE__,
1931
+				__FUNCTION__,
1932
+				__LINE__
1933
+			);
1934
+			$success = false;
1935
+		}
1936
+
1937
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1938
+		$context = $this->request->getRequestParam('context', '');
1939
+		$status  = $this->request->getRequestParam('status', '');
1940
+
1941
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1942
+
1943
+		if ($status !== 'off' && $status !== 'on') {
1944
+			EE_Error::add_error(
1945
+				sprintf(
1946
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1947
+					$status
1948
+				),
1949
+				__FILE__,
1950
+				__FUNCTION__,
1951
+				__LINE__
1952
+			);
1953
+			$success = false;
1954
+		}
1955
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1956
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1957
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1958
+			EE_Error::add_error(
1959
+				sprintf(
1960
+					esc_html__(
1961
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1962
+						'event_espresso'
1963
+					),
1964
+					$message_template_group_id,
1965
+					'EE_Message_Template_Group'
1966
+				),
1967
+				__FILE__,
1968
+				__FUNCTION__,
1969
+				__LINE__
1970
+			);
1971
+			$success = false;
1972
+		}
1973
+		if ($success) {
1974
+			$success = $status === 'off'
1975
+				? $message_template_group->deactivate_context($context)
1976
+				: $message_template_group->activate_context($context);
1977
+		}
1978
+		$this->_template_args['success'] = $success;
1979
+		$this->_return_json();
1980
+	}
1981
+
1982
+
1983
+	public function _add_form_element_before()
1984
+	{
1985
+		return '<form method="post" action="'
1986
+			   . $this->_template_args['edit_message_template_form_url']
1987
+			   . '" id="ee-msg-edit-frm">';
1988
+	}
1989
+
1990
+
1991
+	public function _add_form_element_after()
1992
+	{
1993
+		return '</form>';
1994
+	}
1995
+
1996
+
1997
+	/**
1998
+	 * This executes switching the template pack for a message template.
1999
+	 *
2000
+	 * @throws EE_Error
2001
+	 * @throws InvalidDataTypeException
2002
+	 * @throws InvalidInterfaceException
2003
+	 * @throws InvalidArgumentException
2004
+	 * @throws ReflectionException
2005
+	 * @since 4.5.0
2006
+	 */
2007
+	public function switch_template_pack()
2008
+	{
2009
+
2010
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2011
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2012
+
2013
+		// verify we have needed values.
2014
+		if (empty($GRP_ID) || empty($template_pack)) {
2015
+			$this->_template_args['error'] = true;
2016
+			EE_Error::add_error(
2017
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2018
+				__FILE__,
2019
+				__FUNCTION__,
2020
+				__LINE__
2021
+			);
2022
+		} else {
2023
+			// get template, set the new template_pack and then reset to default
2024
+			/** @var EE_Message_Template_Group $message_template_group */
2025
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2026
+
2027
+			$message_template_group->set_template_pack_name($template_pack);
2028
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2029
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2030
+
2031
+			$query_args = $this->_reset_to_default_template();
2032
+
2033
+			if (empty($query_args['id'])) {
2034
+				EE_Error::add_error(
2035
+					esc_html__(
2036
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2037
+						'event_espresso'
2038
+					),
2039
+					__FILE__,
2040
+					__FUNCTION__,
2041
+					__LINE__
2042
+				);
2043
+				$this->_template_args['error'] = true;
2044
+			} else {
2045
+				$template_label       = $message_template_group->get_template_pack()->label;
2046
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2047
+				EE_Error::add_success(
2048
+					sprintf(
2049
+						esc_html__(
2050
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2051
+							'event_espresso'
2052
+						),
2053
+						$template_label,
2054
+						$template_pack_labels->template_pack
2055
+					)
2056
+				);
2057
+				// generate the redirect url for js.
2058
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2059
+
2060
+				$this->_template_args['data']['redirect_url'] = $url;
2061
+				$this->_template_args['success']              = true;
2062
+			}
2063
+
2064
+			$this->_return_json();
2065
+		}
2066
+	}
2067
+
2068
+
2069
+	/**
2070
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2071
+	 * they want.
2072
+	 *
2073
+	 * @access protected
2074
+	 * @return array|void
2075
+	 * @throws EE_Error
2076
+	 * @throws InvalidArgumentException
2077
+	 * @throws InvalidDataTypeException
2078
+	 * @throws InvalidInterfaceException
2079
+	 * @throws ReflectionException
2080
+	 */
2081
+	protected function _reset_to_default_template()
2082
+	{
2083
+		$templates    = [];
2084
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2085
+		$messenger    = $this->request->getRequestParam('msgr');
2086
+		$message_type = $this->request->getRequestParam('mt');
2087
+		// we need to make sure we've got the info we need.
2088
+		if (! ($GRP_ID && $messenger && $message_type)) {
2089
+			EE_Error::add_error(
2090
+				esc_html__(
2091
+					'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.',
2092
+					'event_espresso'
2093
+				),
2094
+				__FILE__,
2095
+				__FUNCTION__,
2096
+				__LINE__
2097
+			);
2098
+		}
2099
+
2100
+		// all templates will be reset to whatever the defaults are
2101
+		// for the global template matching the messenger and message type.
2102
+		$success = ! empty($GRP_ID);
2103
+
2104
+		if ($success) {
2105
+			// let's first determine if the incoming template is a global template,
2106
+			// if it isn't then we need to get the global template matching messenger and message type.
2107
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2108
+
2109
+
2110
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2111
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2112
+
2113
+			if ($success) {
2114
+				// if successfully deleted, lets generate the new ones.
2115
+				// Note. We set GLOBAL to true, because resets on ANY template
2116
+				// will use the related global template defaults for regeneration.
2117
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2118
+				// HOWEVER, we DO keep the template pack and template variation set
2119
+				// for the current custom template when resetting.
2120
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2121
+			}
2122
+		}
2123
+
2124
+		// any error messages?
2125
+		if (! $success) {
2126
+			EE_Error::add_error(
2127
+				esc_html__(
2128
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2129
+					'event_espresso'
2130
+				),
2131
+				__FILE__,
2132
+				__FUNCTION__,
2133
+				__LINE__
2134
+			);
2135
+		}
2136
+
2137
+		// all good, let's add a success message!
2138
+		if ($success && ! empty($templates)) {
2139
+			// the info for the template we generated is the first element in the returned array
2140
+			EE_Error::overwrite_success();
2141
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2142
+		}
2143
+
2144
+
2145
+		$query_args = [
2146
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2147
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2148
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2149
+		];
2150
+
2151
+		// if called via ajax then we return query args otherwise redirect
2152
+		if ($this->request->isAjax()) {
2153
+			return $query_args;
2154
+		}
2155
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2156
+	}
2157
+
2158
+
2159
+	/**
2160
+	 * Retrieve and set the message preview for display.
2161
+	 *
2162
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2163
+	 * @return string
2164
+	 * @throws ReflectionException
2165
+	 * @throws EE_Error
2166
+	 * @throws InvalidArgumentException
2167
+	 * @throws InvalidDataTypeException
2168
+	 * @throws InvalidInterfaceException
2169
+	 */
2170
+	public function _preview_message($send = false)
2171
+	{
2172
+		// first make sure we've got the necessary parameters
2173
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2174
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2175
+			EE_Error::add_error(
2176
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2177
+				__FILE__,
2178
+				__FUNCTION__,
2179
+				__LINE__
2180
+			);
2181
+		}
2182
+
2183
+		$context = $this->request->getRequestParam('context');
2184
+		// get the preview!
2185
+		$preview = EED_Messages::preview_message(
2186
+			$this->_active_message_type_name,
2187
+			$context,
2188
+			$this->_active_messenger_name,
2189
+			$send
2190
+		);
2191
+
2192
+		if ($send) {
2193
+			return $preview;
2194
+		}
2195
+
2196
+		// if we have an evt_id set on the request, use it.
2197
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2198
+
2199
+		// let's add a button to go back to the edit view
2200
+		$query_args             = [
2201
+			'id'      => $GRP_ID,
2202
+			'evt_id'  => $EVT_ID,
2203
+			'context' => $context,
2204
+			'action'  => 'edit_message_template',
2205
+		];
2206
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2207
+		$preview_button         = '<a href="'
2208
+								  . $go_back_url
2209
+								  . '" class="button--secondary messages-preview-go-back-button">'
2210
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2211
+								  . '</a>';
2212
+		$message_types          = $this->get_installed_message_types();
2213
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2214
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2215
+			? ucwords($active_messenger->label['singular'])
2216
+			: esc_html__('Unknown Messenger', 'event_espresso');
2217
+		// let's provide a helpful title for context
2218
+		$preview_title = sprintf(
2219
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2220
+			$active_messenger_label,
2221
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2222
+		);
2223
+		if (empty($preview)) {
2224
+			$this->noEventsErrorMessage();
2225
+		}
2226
+		// setup display of preview.
2227
+		$this->_admin_page_title                    = $preview_title;
2228
+		$this->_template_args['admin_page_title']   = $preview_title;
2229
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2230
+		$this->_template_args['data']['force_json'] = true;
2231
+
2232
+		return '';
2233
+	}
2234
+
2235
+
2236
+	/**
2237
+	 * Used to set an error if there are no events available for generating a preview/test send.
2238
+	 *
2239
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2240
+	 */
2241
+	protected function noEventsErrorMessage($test_send = false)
2242
+	{
2243
+		$events_url = parent::add_query_args_and_nonce(
2244
+			[
2245
+				'action' => 'default',
2246
+				'page'   => 'espresso_events',
2247
+			],
2248
+			admin_url('admin.php')
2249
+		);
2250
+		$message    = $test_send
2251
+			? esc_html__(
2252
+				'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!',
2253
+				'event_espresso'
2254
+			)
2255
+			: esc_html__(
2256
+				'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!',
2257
+				'event_espresso'
2258
+			);
2259
+
2260
+		EE_Error::add_attention(
2261
+			sprintf(
2262
+				$message,
2263
+				"<a href='{$events_url}'>",
2264
+				'</a>'
2265
+			)
2266
+		);
2267
+	}
2268
+
2269
+
2270
+	/**
2271
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2272
+	 * gets called automatically.
2273
+	 *
2274
+	 * @return void
2275
+	 * @throws EE_Error
2276
+	 * @since 4.5.0
2277
+	 *
2278
+	 */
2279
+	protected function _display_preview_message()
2280
+	{
2281
+		$this->display_admin_page_with_no_sidebar();
2282
+	}
2283
+
2284
+
2285
+	/**
2286
+	 * registers metaboxes that should show up on the "edit_message_template" page
2287
+	 *
2288
+	 * @access protected
2289
+	 * @return void
2290
+	 */
2291
+	protected function _register_edit_meta_boxes()
2292
+	{
2293
+		$this->addMetaBox(
2294
+			'mtp_valid_shortcodes',
2295
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2296
+			[$this, 'shortcode_meta_box'],
2297
+			$this->_current_screen->id,
2298
+			'side'
2299
+		);
2300
+		$this->addMetaBox(
2301
+			'mtp_extra_actions',
2302
+			esc_html__('Extra Actions', 'event_espresso'),
2303
+			[$this, 'extra_actions_meta_box'],
2304
+			$this->_current_screen->id,
2305
+			'side',
2306
+			'high'
2307
+		);
2308
+		$this->addMetaBox(
2309
+			'mtp_templates',
2310
+			esc_html__('Template Styles', 'event_espresso'),
2311
+			[$this, 'template_pack_meta_box'],
2312
+			$this->_current_screen->id,
2313
+			'side',
2314
+			'high'
2315
+		);
2316
+	}
2317
+
2318
+
2319
+	/**
2320
+	 * metabox content for all template pack and variation selection.
2321
+	 *
2322
+	 * @return void
2323
+	 * @throws DomainException
2324
+	 * @throws EE_Error
2325
+	 * @throws InvalidArgumentException
2326
+	 * @throws ReflectionException
2327
+	 * @throws InvalidDataTypeException
2328
+	 * @throws InvalidInterfaceException
2329
+	 * @since 4.5.0
2330
+	 */
2331
+	public function template_pack_meta_box()
2332
+	{
2333
+		$this->_set_message_template_group();
2334
+
2335
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2336
+
2337
+		$tp_select_values = [];
2338
+
2339
+		foreach ($tp_collection as $tp) {
2340
+			// only include template packs that support this messenger and message type!
2341
+			$supports = $tp->get_supports();
2342
+			if (
2343
+				! isset($supports[ $this->_message_template_group->messenger() ])
2344
+				|| ! in_array(
2345
+					$this->_message_template_group->message_type(),
2346
+					$supports[ $this->_message_template_group->messenger() ],
2347
+					true
2348
+				)
2349
+			) {
2350
+				// not supported
2351
+				continue;
2352
+			}
2353
+
2354
+			$tp_select_values[] = [
2355
+				'text' => $tp->label,
2356
+				'id'   => $tp->dbref,
2357
+			];
2358
+		}
2359
+
2360
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2361
+		// the default template pack.  This still allows for the odd template pack to override.
2362
+		if (empty($tp_select_values)) {
2363
+			$tp_select_values[] = [
2364
+				'text' => esc_html__('Default', 'event_espresso'),
2365
+				'id'   => 'default',
2366
+			];
2367
+		}
2368
+
2369
+		// setup variation select values for the currently selected template.
2370
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2371
+			$this->_message_template_group->messenger(),
2372
+			$this->_message_template_group->message_type()
2373
+		);
2374
+		$variations_select_values = [];
2375
+		foreach ($variations as $variation => $label) {
2376
+			$variations_select_values[] = [
2377
+				'text' => $label,
2378
+				'id'   => $variation,
2379
+			];
2380
+		}
2381
+
2382
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2383
+
2384
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2385
+			'MTP_template_pack',
2386
+			$tp_select_values,
2387
+			$this->_message_template_group->get_template_pack_name()
2388
+		);
2389
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2390
+			'MTP_template_variation',
2391
+			$variations_select_values,
2392
+			$this->_message_template_group->get_template_pack_variation()
2393
+		);
2394
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2395
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2396
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2397
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2398
+
2399
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2400
+
2401
+		EEH_Template::display_template($template, $template_args);
2402
+	}
2403
+
2404
+
2405
+	/**
2406
+	 * This meta box holds any extra actions related to Message Templates
2407
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2408
+	 *
2409
+	 * @access  public
2410
+	 * @return void
2411
+	 * @throws EE_Error
2412
+	 */
2413
+	public function extra_actions_meta_box()
2414
+	{
2415
+		$template_form_fields = [];
2416
+
2417
+		$extra_args = [
2418
+			'msgr'   => $this->_message_template_group->messenger(),
2419
+			'mt'     => $this->_message_template_group->message_type(),
2420
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2421
+		];
2422
+		// first we need to see if there are any fields
2423
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2424
+
2425
+		if (! empty($fields)) {
2426
+			// yup there be fields
2427
+			foreach ($fields as $field => $config) {
2428
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2429
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2430
+				$default  = isset($config['default']) ? $config['default'] : '';
2431
+				$default  = isset($config['value']) ? $config['value'] : $default;
2432
+
2433
+				// if type is hidden and the value is empty
2434
+				// something may have gone wrong so let's correct with the defaults
2435
+				$fix                = $config['input'] === 'hidden'
2436
+									  && isset($existing[ $field ])
2437
+									  && empty($existing[ $field ])
2438
+					? $default
2439
+					: '';
2440
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2441
+					? $existing[ $field ]
2442
+					: $fix;
2443
+
2444
+				$template_form_fields[ $field_id ] = [
2445
+					'name'       => 'test_settings_fld[' . $field . ']',
2446
+					'label'      => $config['label'],
2447
+					'input'      => $config['input'],
2448
+					'type'       => $config['type'],
2449
+					'required'   => $config['required'],
2450
+					'validation' => $config['validation'],
2451
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2452
+					'css_class'  => $config['css_class'],
2453
+					'options'    => isset($config['options']) ? $config['options'] : [],
2454
+					'default'    => $default,
2455
+					'format'     => $config['format'],
2456
+				];
2457
+			}
2458
+		}
2459
+
2460
+		$test_settings_html = ! empty($template_form_fields)
2461
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2462
+			: '';
2463
+
2464
+		// print out $test_settings_fields
2465
+		if (! empty($test_settings_html)) {
2466
+			$test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2467
+			$test_settings_html .= 'name="test_button" value="';
2468
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2469
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2470
+		}
2471
+
2472
+		// and button
2473
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2474
+		$test_settings_html .= '<p>';
2475
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2476
+		$test_settings_html .= '</p>';
2477
+		$test_settings_html .= $this->get_action_link_or_button(
2478
+			'reset_to_default',
2479
+			'reset',
2480
+			$extra_args,
2481
+			'button--primary reset-default-button'
2482
+		);
2483
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2484
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2485
+	}
2486
+
2487
+
2488
+	/**
2489
+	 * This returns the shortcode selector skeleton for a given context and field.
2490
+	 *
2491
+	 * @param string $field           The name of the field retrieving shortcodes for.
2492
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2493
+	 * @return string
2494
+	 * @throws DomainException
2495
+	 * @throws EE_Error
2496
+	 * @throws InvalidArgumentException
2497
+	 * @throws ReflectionException
2498
+	 * @throws InvalidDataTypeException
2499
+	 * @throws InvalidInterfaceException
2500
+	 * @since 4.9.rc.000
2501
+	 */
2502
+	protected function _get_shortcode_selector($field, $linked_input_id)
2503
+	{
2504
+		$template_args = [
2505
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2506
+			'fieldname'       => $field,
2507
+			'linked_input_id' => $linked_input_id,
2508
+		];
2509
+
2510
+		return EEH_Template::display_template(
2511
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2512
+			$template_args,
2513
+			true
2514
+		);
2515
+	}
2516
+
2517
+
2518
+	/**
2519
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2520
+	 * page)
2521
+	 *
2522
+	 * @access public
2523
+	 * @return void
2524
+	 * @throws EE_Error
2525
+	 * @throws InvalidArgumentException
2526
+	 * @throws ReflectionException
2527
+	 * @throws InvalidDataTypeException
2528
+	 * @throws InvalidInterfaceException
2529
+	 */
2530
+	public function shortcode_meta_box()
2531
+	{
2532
+		$shortcodes = $this->_get_shortcodes([], false);
2533
+		// just make sure the shortcodes property is set
2534
+		// $messenger = $this->_message_template_group->messenger_obj();
2535
+		// now let's set the content depending on the status of the shortcodes array
2536
+		if (empty($shortcodes)) {
2537
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2538
+			return;
2539
+		}
2540
+		?>
2541 2541
         <div style="float:right; margin-top:10px">
2542 2542
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2543
-            ?>
2543
+			?>
2544 2544
         </div>
2545 2545
         <p class="small-text">
2546 2546
             <?php printf(
2547
-                esc_html__(
2548
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2549
-                    'event_espresso'
2550
-                ),
2551
-                '<span class="dashicons dashicons-shortcode"></span>'
2552
-            ); ?>
2547
+				esc_html__(
2548
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2549
+					'event_espresso'
2550
+				),
2551
+				'<span class="dashicons dashicons-shortcode"></span>'
2552
+			); ?>
2553 2553
         </p>
2554 2554
         <?php
2555
-    }
2556
-
2557
-
2558
-    /**
2559
-     * used to set the $_shortcodes property for when its needed elsewhere.
2560
-     *
2561
-     * @access protected
2562
-     * @return void
2563
-     * @throws EE_Error
2564
-     * @throws InvalidArgumentException
2565
-     * @throws ReflectionException
2566
-     * @throws InvalidDataTypeException
2567
-     * @throws InvalidInterfaceException
2568
-     */
2569
-    protected function _set_shortcodes()
2570
-    {
2571
-
2572
-        // no need to run this if the property is already set
2573
-        if (! empty($this->_shortcodes)) {
2574
-            return;
2575
-        }
2576
-
2577
-        $this->_shortcodes = $this->_get_shortcodes();
2578
-    }
2579
-
2580
-
2581
-    /**
2582
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2583
-     * property)
2584
-     *
2585
-     * @access  protected
2586
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2587
-     *                         for. Defaults to all (for the given context)
2588
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2589
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2590
-     *                         true just an array of shortcode/label pairs.
2591
-     * @throws EE_Error
2592
-     * @throws InvalidArgumentException
2593
-     * @throws ReflectionException
2594
-     * @throws InvalidDataTypeException
2595
-     * @throws InvalidInterfaceException
2596
-     */
2597
-    protected function _get_shortcodes($fields = [], $merged = true)
2598
-    {
2599
-        $this->_set_message_template_group();
2600
-
2601
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2602
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2603
-        if (empty($GRP_ID)) {
2604
-            return [];
2605
-        }
2606
-        $context = $this->request->getRequestParam(
2607
-            'messenger',
2608
-            key($this->_message_template_group->contexts_config())
2609
-        );
2610
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2611
-    }
2612
-
2613
-
2614
-    /**
2615
-     * This sets the _message_template property (containing the called message_template object)
2616
-     *
2617
-     * @access protected
2618
-     * @return void
2619
-     * @throws EE_Error
2620
-     * @throws InvalidArgumentException
2621
-     * @throws ReflectionException
2622
-     * @throws InvalidDataTypeException
2623
-     * @throws InvalidInterfaceException
2624
-     */
2625
-    protected function _set_message_template_group()
2626
-    {
2627
-        // get out if this is already set.
2628
-        if (! empty($this->_message_template_group)) {
2629
-            return;
2630
-        }
2631
-
2632
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2633
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2634
-
2635
-        // let's get the message templates
2636
-        $this->_message_template_group = ! empty($GRP_ID)
2637
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2638
-            : $this->getMtgModel()->create_default_object();
2639
-
2640
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2641
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2642
-    }
2643
-
2644
-
2645
-    /**
2646
-     * sets up a context switcher for edit forms
2647
-     *
2648
-     * @access  protected
2649
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2650
-     * @param array                     $args                  various things the context switcher needs.
2651
-     * @throws EE_Error
2652
-     */
2653
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2654
-    {
2655
-        $context_details = $template_group_object->contexts_config();
2656
-        $context_label   = $template_group_object->context_label();
2657
-        ob_start();
2658
-        ?>
2555
+	}
2556
+
2557
+
2558
+	/**
2559
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2560
+	 *
2561
+	 * @access protected
2562
+	 * @return void
2563
+	 * @throws EE_Error
2564
+	 * @throws InvalidArgumentException
2565
+	 * @throws ReflectionException
2566
+	 * @throws InvalidDataTypeException
2567
+	 * @throws InvalidInterfaceException
2568
+	 */
2569
+	protected function _set_shortcodes()
2570
+	{
2571
+
2572
+		// no need to run this if the property is already set
2573
+		if (! empty($this->_shortcodes)) {
2574
+			return;
2575
+		}
2576
+
2577
+		$this->_shortcodes = $this->_get_shortcodes();
2578
+	}
2579
+
2580
+
2581
+	/**
2582
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2583
+	 * property)
2584
+	 *
2585
+	 * @access  protected
2586
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2587
+	 *                         for. Defaults to all (for the given context)
2588
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2589
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2590
+	 *                         true just an array of shortcode/label pairs.
2591
+	 * @throws EE_Error
2592
+	 * @throws InvalidArgumentException
2593
+	 * @throws ReflectionException
2594
+	 * @throws InvalidDataTypeException
2595
+	 * @throws InvalidInterfaceException
2596
+	 */
2597
+	protected function _get_shortcodes($fields = [], $merged = true)
2598
+	{
2599
+		$this->_set_message_template_group();
2600
+
2601
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2602
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2603
+		if (empty($GRP_ID)) {
2604
+			return [];
2605
+		}
2606
+		$context = $this->request->getRequestParam(
2607
+			'messenger',
2608
+			key($this->_message_template_group->contexts_config())
2609
+		);
2610
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2611
+	}
2612
+
2613
+
2614
+	/**
2615
+	 * This sets the _message_template property (containing the called message_template object)
2616
+	 *
2617
+	 * @access protected
2618
+	 * @return void
2619
+	 * @throws EE_Error
2620
+	 * @throws InvalidArgumentException
2621
+	 * @throws ReflectionException
2622
+	 * @throws InvalidDataTypeException
2623
+	 * @throws InvalidInterfaceException
2624
+	 */
2625
+	protected function _set_message_template_group()
2626
+	{
2627
+		// get out if this is already set.
2628
+		if (! empty($this->_message_template_group)) {
2629
+			return;
2630
+		}
2631
+
2632
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2633
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2634
+
2635
+		// let's get the message templates
2636
+		$this->_message_template_group = ! empty($GRP_ID)
2637
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2638
+			: $this->getMtgModel()->create_default_object();
2639
+
2640
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2641
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2642
+	}
2643
+
2644
+
2645
+	/**
2646
+	 * sets up a context switcher for edit forms
2647
+	 *
2648
+	 * @access  protected
2649
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2650
+	 * @param array                     $args                  various things the context switcher needs.
2651
+	 * @throws EE_Error
2652
+	 */
2653
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2654
+	{
2655
+		$context_details = $template_group_object->contexts_config();
2656
+		$context_label   = $template_group_object->context_label();
2657
+		ob_start();
2658
+		?>
2659 2659
         <div class="ee-msg-switcher-container">
2660 2660
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2661 2661
                 <?php
2662
-                foreach ($args as $name => $value) {
2663
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2664
-                        continue;
2665
-                    }
2666
-                    ?>
2662
+				foreach ($args as $name => $value) {
2663
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2664
+						continue;
2665
+					}
2666
+					?>
2667 2667
                     <input type="hidden"
2668 2668
                            name="<?php echo esc_attr($name); ?>"
2669 2669
                            value="<?php echo esc_attr($value); ?>"
2670 2670
                     />
2671 2671
                     <?php
2672
-                }
2673
-                // setup nonce_url
2674
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2675
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2676
-                ?>
2672
+				}
2673
+				// setup nonce_url
2674
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2675
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2676
+				?>
2677 2677
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2678 2678
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2679 2679
                 </label>
2680 2680
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2681 2681
                     <?php
2682
-                    $context_templates = $template_group_object->context_templates();
2683
-                    if (is_array($context_templates)) :
2684
-                        foreach ($context_templates as $context => $template_fields) :
2685
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2686
-                            ?>
2682
+					$context_templates = $template_group_object->context_templates();
2683
+					if (is_array($context_templates)) :
2684
+						foreach ($context_templates as $context => $template_fields) :
2685
+							$checked = ($context === $args['context']) ? 'selected' : '';
2686
+							?>
2687 2687
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2688 2688
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2689 2689
                             </option>
2690 2690
                         <?php endforeach;
2691
-                    endif; ?>
2691
+					endif; ?>
2692 2692
                 </select>
2693 2693
                 <?php $button_text = sprintf(
2694
-                    esc_html__('Switch %s', 'event_espresso'),
2695
-                    ucwords($context_label['label'])
2696
-                ); ?>
2694
+					esc_html__('Switch %s', 'event_espresso'),
2695
+					ucwords($context_label['label'])
2696
+				); ?>
2697 2697
                 <input class='button--secondary'
2698 2698
                        id="submit-msg-context-switcher-sbmt"
2699 2699
                        type="submit"
@@ -2703,1996 +2703,1996 @@  discard block
 block discarded – undo
2703 2703
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2704 2704
         </div> <!-- end .ee-msg-switcher-container -->
2705 2705
         <?php $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
-        [$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
-            $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3455
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3456
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3457
-                'label' => ucwords($messenger->label['singular']),
3458
-                'class' => $active ? "{$class} messenger-active" : $class,
3459
-                'href'  => $messenger->name,
3460
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
-                'slug'  => $messenger->name,
3462
-                'obj'   => $messenger,
3463
-                'icon' => $active
3464
-                    ? '<span class="dashicons dashicons-yes-alt"></span>'
3465
-                    : '<span class="dashicons dashicons-remove"></span>',
3466
-            ];
3467
-
3468
-
3469
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3470
-
3471
-            foreach ($message_types as $message_type) {
3472
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3473
-                // it shouldn't show in either the inactive OR active metabox.
3474
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3475
-                    continue;
3476
-                }
3477
-
3478
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3479
-                    $messenger->name,
3480
-                    $message_type->name
3481
-                )
3482
-                    ? 'active'
3483
-                    : 'inactive';
3484
-
3485
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3486
-                    'label'    => ucwords($message_type->label['singular']),
3487
-                    'class'    => 'message-type-' . $a_or_i,
3488
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3489
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3490
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3491
-                    'title'    => $a_or_i === 'active'
3492
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3493
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3494
-                    'content'  => $a_or_i === 'active'
3495
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3496
-                        : $this->_message_type_settings_content($message_type, $messenger),
3497
-                    'slug'     => $message_type->name,
3498
-                    'active'   => $a_or_i === 'active',
3499
-                    'obj'      => $message_type,
3500
-                ];
3501
-            }
3502
-        }
3503
-    }
3504
-
3505
-
3506
-    /**
3507
-     * This just prepares the content for the message type settings
3508
-     *
3509
-     * @param EE_message_type $message_type The message type object
3510
-     * @param EE_messenger    $messenger    The messenger object
3511
-     * @param boolean         $active       Whether the message type is active or not
3512
-     * @return string html output for the content
3513
-     * @throws DomainException
3514
-     */
3515
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3516
-    {
3517
-        // get message type fields
3518
-        $fields                                         = $message_type->get_admin_settings_fields();
3519
-        $settings_template_args['template_form_fields'] = '';
3520
-
3521
-        if (! empty($fields) && $active) {
3522
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3523
-            foreach ($fields as $fldname => $fldprops) {
3524
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3525
-                $template_form_field[ $field_id ] = [
3526
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3527
-                    'label'      => $fldprops['label'],
3528
-                    'input'      => $fldprops['field_type'],
3529
-                    'type'       => $fldprops['value_type'],
3530
-                    'required'   => $fldprops['required'],
3531
-                    'validation' => $fldprops['validation'],
3532
-                    'value'      => isset($existing_settings[ $fldname ])
3533
-                        ? $existing_settings[ $fldname ]
3534
-                        : $fldprops['default'],
3535
-                    'options'    => isset($fldprops['options'])
3536
-                        ? $fldprops['options']
3537
-                        : [],
3538
-                    'default'    => isset($existing_settings[ $fldname ])
3539
-                        ? $existing_settings[ $fldname ]
3540
-                        : $fldprops['default'],
3541
-                    'css_class'  => 'no-drag',
3542
-                    'format'     => $fldprops['format'],
3543
-                ];
3544
-            }
3545
-
3546
-
3547
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3548
-                ? $this->_generate_admin_form_fields(
3549
-                    $template_form_field,
3550
-                    'string',
3551
-                    'ee_mt_activate_form'
3552
-                )
3553
-                : '';
3554
-        }
3555
-
3556
-        $settings_template_args['description'] = $message_type->description;
3557
-        // we also need some hidden fields
3558
-        $hidden_fields = [
3559
-            'message_type_settings[messenger]' . $message_type->name    => [
3560
-                'type'  => 'hidden',
3561
-                'value' => $messenger->name,
3562
-            ],
3563
-            'message_type_settings[message_type]' . $message_type->name => [
3564
-                'type'  => 'hidden',
3565
-                'value' => $message_type->name,
3566
-            ],
3567
-            'type' . $message_type->name                                => [
3568
-                'type'  => 'hidden',
3569
-                'value' => 'message_type',
3570
-            ],
3571
-        ];
3572
-
3573
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3574
-            $hidden_fields,
3575
-            'array'
3576
-        );
3577
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3578
-            ? ' hidden'
3579
-            : '';
3580
-
3581
-
3582
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3583
-        return EEH_Template::display_template($template, $settings_template_args, true);
3584
-    }
3585
-
3586
-
3587
-    /**
3588
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3589
-     *
3590
-     * @access protected
3591
-     * @return void
3592
-     * @throws DomainException
3593
-     */
3594
-    protected function _messages_settings_metaboxes()
3595
-    {
3596
-        $this->_set_m_mt_settings();
3597
-        $m_boxes         = $mt_boxes = [];
3598
-        $m_template_args = $mt_template_args = [];
3599
-
3600
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3601
-
3602
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3603
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3604
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3605
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3606
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3607
-
3608
-                // messenger meta boxes
3609
-                $active         = $selected_messenger === $messenger;
3610
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3611
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3612
-                    : '';
3613
-
3614
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3615
-                    esc_html__('%s Settings', 'event_espresso'),
3616
-                    $tab_array['label']
3617
-                );
3618
-
3619
-                $m_template_args[ $messenger . '_a_box' ] = [
3620
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3621
-                    'inactive_message_types' => isset(
3622
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3623
-                    )
3624
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3625
-                        : '',
3626
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3627
-                    'hidden'                 => $active ? '' : ' hidden',
3628
-                    'hide_on_message'        => $hide_on_message,
3629
-                    'messenger'              => $messenger,
3630
-                    'active'                 => $active,
3631
-                ];
3632
-
3633
-                // message type meta boxes
3634
-                // (which is really just the inactive container for each messenger
3635
-                // showing inactive message types for that messenger)
3636
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3637
-                $mt_template_args[ $messenger . '_i_box' ] = [
3638
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3639
-                    'inactive_message_types' => isset(
3640
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3641
-                    )
3642
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3643
-                        : '',
3644
-                    'hidden'                 => $active ? '' : ' hidden',
3645
-                    'hide_on_message'        => $hide_on_message,
3646
-                    'hide_off_message'       => $hide_off_message,
3647
-                    'messenger'              => $messenger,
3648
-                    'active'                 => $active,
3649
-                ];
3650
-            }
3651
-        }
3652
-
3653
-
3654
-        // register messenger metaboxes
3655
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3656
-        foreach ($m_boxes as $box => $label) {
3657
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3658
-            $msgr          = str_replace('_a_box', '', $box);
3659
-            $this->addMetaBox(
3660
-                'espresso_' . $msgr . '_settings',
3661
-                $label,
3662
-                function ($post, $metabox) {
3663
-                    EEH_Template::display_template(
3664
-                        $metabox['args']['template_path'],
3665
-                        $metabox['args']['template_args']
3666
-                    );
3667
-                },
3668
-                $this->_current_screen->id,
3669
-                'normal',
3670
-                'high',
3671
-                $callback_args
3672
-            );
3673
-        }
3674
-
3675
-        // register message type metaboxes
3676
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3677
-        foreach ($mt_boxes as $box => $label) {
3678
-            $callback_args = [
3679
-                'template_path' => $mt_template_path,
3680
-                'template_args' => $mt_template_args[ $box ],
3681
-            ];
3682
-            $mt            = str_replace('_i_box', '', $box);
3683
-            $this->addMetaBox(
3684
-                'espresso_' . $mt . '_inactive_mts',
3685
-                $label,
3686
-                function ($post, $metabox) {
3687
-                    EEH_Template::display_template(
3688
-                        $metabox['args']['template_path'],
3689
-                        $metabox['args']['template_args']
3690
-                    );
3691
-                },
3692
-                $this->_current_screen->id,
3693
-                'side',
3694
-                'high',
3695
-                $callback_args
3696
-            );
3697
-        }
3698
-
3699
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3700
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3701
-        if (is_main_site()) {
3702
-            $this->addMetaBox(
3703
-                'espresso_global_message_settings',
3704
-                esc_html__('Global Message Settings', 'event_espresso'),
3705
-                [$this, 'global_messages_settings_metabox_content'],
3706
-                $this->_current_screen->id,
3707
-                'normal',
3708
-                'low',
3709
-                []
3710
-            );
3711
-        }
3712
-    }
3713
-
3714
-
3715
-    /**
3716
-     *  This generates the content for the global messages settings metabox.
3717
-     *
3718
-     * @return void
3719
-     * @throws EE_Error
3720
-     * @throws InvalidArgumentException
3721
-     * @throws ReflectionException
3722
-     * @throws InvalidDataTypeException
3723
-     * @throws InvalidInterfaceException
3724
-     */
3725
-    public function global_messages_settings_metabox_content()
3726
-    {
3727
-        $form = $this->_generate_global_settings_form();
3728
-        echo wp_kses(
3729
-            $form->form_open(
3730
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3731
-                'POST'
3732
-            ),
3733
-            AllowedTags::getWithFormTags()
3734
-        );
3735
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3736
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3737
-    }
3738
-
3739
-
3740
-    /**
3741
-     * This generates and returns the form object for the global messages settings.
3742
-     *
3743
-     * @return EE_Form_Section_Proper
3744
-     * @throws EE_Error
3745
-     * @throws InvalidArgumentException
3746
-     * @throws ReflectionException
3747
-     * @throws InvalidDataTypeException
3748
-     * @throws InvalidInterfaceException
3749
-     */
3750
-    protected function _generate_global_settings_form()
3751
-    {
3752
-        /** @var EE_Network_Core_Config $network_config */
3753
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3754
-
3755
-        return new EE_Form_Section_Proper(
3756
-            [
3757
-                'name'            => 'global_messages_settings',
3758
-                'html_id'         => 'global_messages_settings',
3759
-                'html_class'      => 'form-table',
3760
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3761
-                'subsections'     => apply_filters(
3762
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3763
-                    [
3764
-                        'do_messages_on_same_request' => new EE_Select_Input(
3765
-                            [
3766
-                                true  => esc_html__('On the same request', 'event_espresso'),
3767
-                                false => esc_html__('On a separate request', 'event_espresso'),
3768
-                            ],
3769
-                            [
3770
-                                'default'         => $network_config->do_messages_on_same_request,
3771
-                                'html_label_text' => esc_html__(
3772
-                                    'Generate and send all messages:',
3773
-                                    'event_espresso'
3774
-                                ),
3775
-                                'html_help_text'  => esc_html__(
3776
-                                    '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.',
3777
-                                    'event_espresso'
3778
-                                ),
3779
-                            ]
3780
-                        ),
3781
-                        'delete_threshold'            => new EE_Select_Input(
3782
-                            [
3783
-                                0  => esc_html__('Forever', 'event_espresso'),
3784
-                                3  => esc_html__('3 Months', 'event_espresso'),
3785
-                                6  => esc_html__('6 Months', 'event_espresso'),
3786
-                                9  => esc_html__('9 Months', 'event_espresso'),
3787
-                                12 => esc_html__('12 Months', 'event_espresso'),
3788
-                                24 => esc_html__('24 Months', 'event_espresso'),
3789
-                                36 => esc_html__('36 Months', 'event_espresso'),
3790
-                            ],
3791
-                            [
3792
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3793
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3794
-                                'html_help_text'  => esc_html__(
3795
-                                    'You can control how long a record of processed messages is kept via this option.',
3796
-                                    'event_espresso'
3797
-                                ),
3798
-                            ]
3799
-                        ),
3800
-                        'update_settings'             => new EE_Submit_Input(
3801
-                            [
3802
-                                'default'         => esc_html__('Update', 'event_espresso'),
3803
-                                'html_label_text' => '',
3804
-                            ]
3805
-                        ),
3806
-                    ]
3807
-                ),
3808
-            ]
3809
-        );
3810
-    }
3811
-
3812
-
3813
-    /**
3814
-     * This handles updating the global settings set on the admin page.
3815
-     *
3816
-     * @throws EE_Error
3817
-     * @throws InvalidDataTypeException
3818
-     * @throws InvalidInterfaceException
3819
-     * @throws InvalidArgumentException
3820
-     * @throws ReflectionException
3821
-     */
3822
-    protected function _update_global_settings()
3823
-    {
3824
-        /** @var EE_Network_Core_Config $network_config */
3825
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3826
-        $messages_config = EE_Registry::instance()->CFG->messages;
3827
-        $form            = $this->_generate_global_settings_form();
3828
-        if ($form->was_submitted()) {
3829
-            $form->receive_form_submission();
3830
-            if ($form->is_valid()) {
3831
-                $valid_data = $form->valid_data();
3832
-                foreach ($valid_data as $property => $value) {
3833
-                    $setter = 'set_' . $property;
3834
-                    if (method_exists($network_config, $setter)) {
3835
-                        $network_config->{$setter}($value);
3836
-                    } elseif (
3837
-                        property_exists($network_config, $property)
3838
-                        && $network_config->{$property} !== $value
3839
-                    ) {
3840
-                        $network_config->{$property} = $value;
3841
-                    } elseif (
3842
-                        property_exists($messages_config, $property)
3843
-                        && $messages_config->{$property} !== $value
3844
-                    ) {
3845
-                        $messages_config->{$property} = $value;
3846
-                    }
3847
-                }
3848
-                // only update if the form submission was valid!
3849
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3850
-                EE_Registry::instance()->CFG->update_espresso_config();
3851
-                EE_Error::overwrite_success();
3852
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3853
-            }
3854
-        }
3855
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3856
-    }
3857
-
3858
-
3859
-    /**
3860
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3861
-     *
3862
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3863
-     * @return string html formatted tabs
3864
-     * @throws DomainException
3865
-     */
3866
-    protected function _get_mt_tabs($tab_array)
3867
-    {
3868
-        $tab_array = (array) $tab_array;
3869
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3870
-        $tabs      = '';
3871
-
3872
-        foreach ($tab_array as $tab) {
3873
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3874
-        }
3875
-
3876
-        return $tabs;
3877
-    }
3878
-
3879
-
3880
-    /**
3881
-     * This prepares the content of the messenger meta box admin settings
3882
-     *
3883
-     * @param EE_messenger $messenger The messenger we're setting up content for
3884
-     * @return string html formatted content
3885
-     * @throws DomainException
3886
-     */
3887
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3888
-    {
3889
-
3890
-        $fields                                         = $messenger->get_admin_settings_fields();
3891
-        $settings_template_args['template_form_fields'] = '';
3892
-
3893
-        // is $messenger active?
3894
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3895
-
3896
-
3897
-        if (! empty($fields)) {
3898
-            $existing_settings = $messenger->get_existing_admin_settings();
3899
-
3900
-            foreach ($fields as $fldname => $fldprops) {
3901
-                $field_id                         = $messenger->name . '-' . $fldname;
3902
-                $template_form_field[ $field_id ] = [
3903
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3904
-                    'label'      => $fldprops['label'],
3905
-                    'input'      => $fldprops['field_type'],
3906
-                    'type'       => $fldprops['value_type'],
3907
-                    'required'   => $fldprops['required'],
3908
-                    'validation' => $fldprops['validation'],
3909
-                    'value'      => isset($existing_settings[ $field_id ])
3910
-                        ? $existing_settings[ $field_id ]
3911
-                        : $fldprops['default'],
3912
-                    'css_class'  => '',
3913
-                    'format'     => $fldprops['format'],
3914
-                ];
3915
-            }
3916
-
3917
-
3918
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3919
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3920
-                : '';
3921
-        }
3922
-
3923
-        // we also need some hidden fields
3924
-        $settings_template_args['hidden_fields'] = [
3925
-            'messenger_settings[messenger]' . $messenger->name => [
3926
-                'type'  => 'hidden',
3927
-                'value' => $messenger->name,
3928
-            ],
3929
-            'type' . $messenger->name                          => [
3930
-                'type'  => 'hidden',
3931
-                'value' => 'messenger',
3932
-            ],
3933
-        ];
3934
-
3935
-        // make sure any active message types that are existing are included in the hidden fields
3936
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3937
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3938
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3939
-                    'type'  => 'hidden',
3940
-                    'value' => $mt,
3941
-                ];
3942
-            }
3943
-        }
3944
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3945
-            $settings_template_args['hidden_fields'],
3946
-            'array'
3947
-        );
3948
-        $active                                  =
3949
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3950
-
3951
-        $settings_template_args['messenger']           = $messenger->name;
3952
-        $settings_template_args['description']         = $messenger->description;
3953
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3954
-
3955
-
3956
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3957
-            $messenger->name
3958
-        )
3959
-            ? $settings_template_args['show_hide_edit_form']
3960
-            : ' hidden';
3961
-
3962
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3963
-            ? ' hidden'
3964
-            : $settings_template_args['show_hide_edit_form'];
3965
-
3966
-
3967
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3968
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3969
-        $settings_template_args['on_off_status'] = $active;
3970
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3971
-        return EEH_Template::display_template(
3972
-            $template,
3973
-            $settings_template_args,
3974
-            true
3975
-        );
3976
-    }
3977
-
3978
-
3979
-    /**
3980
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3981
-     *
3982
-     * @throws DomainException
3983
-     * @throws EE_Error
3984
-     * @throws InvalidDataTypeException
3985
-     * @throws InvalidInterfaceException
3986
-     * @throws InvalidArgumentException
3987
-     * @throws ReflectionException
3988
-     */
3989
-    public function activate_messenger_toggle()
3990
-    {
3991
-        $success = true;
3992
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3993
-        // let's check that we have required data
3994
-
3995
-        if (! $this->_active_messenger_name) {
3996
-            EE_Error::add_error(
3997
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3998
-                __FILE__,
3999
-                __FUNCTION__,
4000
-                __LINE__
4001
-            );
4002
-            $success = false;
4003
-        }
4004
-
4005
-        // do a nonce check here since we're not arriving via a normal route
4006
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4007
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4008
-
4009
-        $this->_verify_nonce($nonce, $nonce_ref);
4010
-
4011
-
4012
-        $status = $this->request->getRequestParam('status');
4013
-        if (! $status) {
4014
-            EE_Error::add_error(
4015
-                esc_html__(
4016
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4017
-                    'event_espresso'
4018
-                ),
4019
-                __FILE__,
4020
-                __FUNCTION__,
4021
-                __LINE__
4022
-            );
4023
-            $success = false;
4024
-        }
4025
-
4026
-        // do check to verify we have a valid status.
4027
-        if ($status !== 'off' && $status !== 'on') {
4028
-            EE_Error::add_error(
4029
-                sprintf(
4030
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4031
-                    $status
4032
-                ),
4033
-                __FILE__,
4034
-                __FUNCTION__,
4035
-                __LINE__
4036
-            );
4037
-            $success = false;
4038
-        }
4039
-
4040
-        if ($success) {
4041
-            // made it here?  Stop dawdling then!!
4042
-            $success = $status === 'off'
4043
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4044
-                : $this->_activate_messenger($this->_active_messenger_name);
4045
-        }
4046
-
4047
-        $this->_template_args['success'] = $success;
4048
-
4049
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4050
-        $this->_return_json();
4051
-    }
4052
-
4053
-
4054
-    /**
4055
-     * used by ajax from the messages settings page to activate|deactivate a message type
4056
-     *
4057
-     * @throws DomainException
4058
-     * @throws EE_Error
4059
-     * @throws ReflectionException
4060
-     * @throws InvalidDataTypeException
4061
-     * @throws InvalidInterfaceException
4062
-     * @throws InvalidArgumentException
4063
-     */
4064
-    public function activate_mt_toggle()
4065
-    {
4066
-        $success = true;
4067
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4068
-
4069
-        // let's make sure we have the necessary data
4070
-        if (! $this->_active_message_type_name) {
4071
-            EE_Error::add_error(
4072
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4073
-                __FILE__,
4074
-                __FUNCTION__,
4075
-                __LINE__
4076
-            );
4077
-            $success = false;
4078
-        }
4079
-
4080
-        if (! $this->_active_messenger_name) {
4081
-            EE_Error::add_error(
4082
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4083
-                __FILE__,
4084
-                __FUNCTION__,
4085
-                __LINE__
4086
-            );
4087
-            $success = false;
4088
-        }
4089
-
4090
-        $status = $this->request->getRequestParam('status');
4091
-        if (! $status) {
4092
-            EE_Error::add_error(
4093
-                esc_html__(
4094
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4095
-                    'event_espresso'
4096
-                ),
4097
-                __FILE__,
4098
-                __FUNCTION__,
4099
-                __LINE__
4100
-            );
4101
-            $success = false;
4102
-        }
4103
-
4104
-
4105
-        // do check to verify we have a valid status.
4106
-        if ($status !== 'activate' && $status !== 'deactivate') {
4107
-            EE_Error::add_error(
4108
-                sprintf(
4109
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4110
-                    $status
4111
-                ),
4112
-                __FILE__,
4113
-                __FUNCTION__,
4114
-                __LINE__
4115
-            );
4116
-            $success = false;
4117
-        }
4118
-
4119
-
4120
-        // do a nonce check here since we're not arriving via a normal route
4121
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4122
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4123
-
4124
-        if ($success) {
4125
-            // made it here? um, what are you waiting for then?
4126
-            $success = $status === 'deactivate'
4127
-                ? $this->_deactivate_message_type_for_messenger(
4128
-                    $this->_active_messenger_name,
4129
-                    $this->_active_message_type_name
4130
-                )
4131
-                : $this->_activate_message_type_for_messenger(
4132
-                    $this->_active_messenger_name,
4133
-                    $this->_active_message_type_name
4134
-                );
4135
-        }
4136
-
4137
-        $this->_template_args['success'] = $success;
4138
-        $this->_return_json();
4139
-    }
4140
-
4141
-
4142
-    /**
4143
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4144
-     *
4145
-     * @param string $messenger_name The name of the messenger being activated
4146
-     * @return bool
4147
-     * @throws DomainException
4148
-     * @throws EE_Error
4149
-     * @throws InvalidArgumentException
4150
-     * @throws ReflectionException
4151
-     * @throws InvalidDataTypeException
4152
-     * @throws InvalidInterfaceException
4153
-     */
4154
-    protected function _activate_messenger($messenger_name)
4155
-    {
4156
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4157
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4158
-            ? $active_messenger->get_default_message_types()
4159
-            : [];
4160
-
4161
-        // ensure is active
4162
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4163
-
4164
-        // set response_data for reload
4165
-        foreach ($message_types_to_activate as $message_type_name) {
4166
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4167
-            if (
4168
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4169
-                    $messenger_name,
4170
-                    $message_type_name
4171
-                )
4172
-                && $message_type instanceof EE_message_type
4173
-            ) {
4174
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4175
-                if ($message_type->get_admin_settings_fields()) {
4176
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4177
-                }
4178
-            }
4179
-        }
4180
-
4181
-        // add success message for activating messenger
4182
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4183
-    }
4184
-
4185
-
4186
-    /**
4187
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4188
-     *
4189
-     * @param string $messenger_name The name of the messenger being activated
4190
-     * @return bool
4191
-     * @throws DomainException
4192
-     * @throws EE_Error
4193
-     * @throws InvalidArgumentException
4194
-     * @throws ReflectionException
4195
-     * @throws InvalidDataTypeException
4196
-     * @throws InvalidInterfaceException
4197
-     */
4198
-    protected function _deactivate_messenger($messenger_name)
4199
-    {
4200
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4201
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4202
-
4203
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4204
-    }
4205
-
4206
-
4207
-    /**
4208
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4209
-     *
4210
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4211
-     * @param string $message_type_name The name of the message type being activated for the messenger
4212
-     * @return bool
4213
-     * @throws DomainException
4214
-     * @throws EE_Error
4215
-     * @throws InvalidArgumentException
4216
-     * @throws ReflectionException
4217
-     * @throws InvalidDataTypeException
4218
-     * @throws InvalidInterfaceException
4219
-     */
4220
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4221
-    {
4222
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4223
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4224
-
4225
-        // ensure is active
4226
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4227
-
4228
-        // set response for load
4229
-        if (
4230
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4231
-                $messenger_name,
4232
-                $message_type_name
4233
-            )
4234
-        ) {
4235
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4236
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4237
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4238
-            }
4239
-        }
4240
-
4241
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4242
-            $active_messenger,
4243
-            $message_type_to_activate
4244
-        );
4245
-    }
4246
-
4247
-
4248
-    /**
4249
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4250
-     *
4251
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4252
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4253
-     * @return bool
4254
-     * @throws DomainException
4255
-     * @throws EE_Error
4256
-     * @throws InvalidArgumentException
4257
-     * @throws ReflectionException
4258
-     * @throws InvalidDataTypeException
4259
-     * @throws InvalidInterfaceException
4260
-     */
4261
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4262
-    {
4263
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4264
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4265
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4266
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4267
-
4268
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4269
-            $active_messenger,
4270
-            $message_type_to_deactivate
4271
-        );
4272
-    }
4273
-
4274
-
4275
-    /**
4276
-     * This just initializes the defaults for activating messenger and message type responses.
4277
-     */
4278
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4279
-    {
4280
-        $this->_template_args['data']['active_mts'] = [];
4281
-        $this->_template_args['data']['mt_reload']  = [];
4282
-    }
4283
-
4284
-
4285
-    /**
4286
-     * Setup appropriate response for activating a messenger and/or message types
4287
-     *
4288
-     * @param EE_messenger         $messenger
4289
-     * @param EE_message_type|null $message_type
4290
-     * @return bool
4291
-     * @throws DomainException
4292
-     * @throws EE_Error
4293
-     * @throws InvalidArgumentException
4294
-     * @throws ReflectionException
4295
-     * @throws InvalidDataTypeException
4296
-     * @throws InvalidInterfaceException
4297
-     */
4298
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4299
-        $messenger,
4300
-        EE_Message_Type $message_type = null
4301
-    ) {
4302
-        // if $messenger isn't a valid messenger object then get out.
4303
-        if (! $messenger instanceof EE_Messenger) {
4304
-            EE_Error::add_error(
4305
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4306
-                __FILE__,
4307
-                __FUNCTION__,
4308
-                __LINE__
4309
-            );
4310
-            return false;
4311
-        }
4312
-        // activated
4313
-        if ($this->_template_args['data']['active_mts']) {
4314
-            EE_Error::overwrite_success();
4315
-            // activated a message type with the messenger
4316
-            if ($message_type instanceof EE_message_type) {
4317
-                EE_Error::add_success(
4318
-                    sprintf(
4319
-                        esc_html__(
4320
-                            '%s message type has been successfully activated with the %s messenger',
4321
-                            'event_espresso'
4322
-                        ),
4323
-                        ucwords($message_type->label['singular']),
4324
-                        ucwords($messenger->label['singular'])
4325
-                    )
4326
-                );
4327
-
4328
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4329
-                if ($message_type->name === 'invoice') {
4330
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4331
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4332
-                    if ($pm instanceof EE_Payment_Method) {
4333
-                        EE_Error::add_attention(
4334
-                            esc_html__(
4335
-                                '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.',
4336
-                                'event_espresso'
4337
-                            )
4338
-                        );
4339
-                    }
4340
-                }
4341
-                // just toggles the entire messenger
4342
-            } else {
4343
-                EE_Error::add_success(
4344
-                    sprintf(
4345
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4346
-                        ucwords($messenger->label['singular'])
4347
-                    )
4348
-                );
4349
-            }
4350
-
4351
-            return true;
4352
-
4353
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4354
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4355
-            // in which case we just give a success message for the messenger being successfully activated.
4356
-        } else {
4357
-            if (! $messenger->get_default_message_types()) {
4358
-                // messenger doesn't have any default message types so still a success.
4359
-                EE_Error::add_success(
4360
-                    sprintf(
4361
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4362
-                        ucwords($messenger->label['singular'])
4363
-                    )
4364
-                );
4365
-
4366
-                return true;
4367
-            } else {
4368
-                EE_Error::add_error(
4369
-                    $message_type instanceof EE_message_type
4370
-                    ? sprintf(
4371
-                        esc_html__(
4372
-                            '%s message type was not successfully activated with the %s messenger',
4373
-                            'event_espresso'
4374
-                        ),
4375
-                        ucwords($message_type->label['singular']),
4376
-                        ucwords($messenger->label['singular'])
4377
-                    )
4378
-                    : sprintf(
4379
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4380
-                        ucwords($messenger->label['singular'])
4381
-                    ),
4382
-                    __FILE__,
4383
-                    __FUNCTION__,
4384
-                    __LINE__
4385
-                );
4386
-
4387
-                return false;
4388
-            }
4389
-        }
4390
-    }
4391
-
4392
-
4393
-    /**
4394
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4395
-     *
4396
-     * @param EE_messenger         $messenger
4397
-     * @param EE_message_type|null $message_type
4398
-     * @return bool
4399
-     * @throws DomainException
4400
-     * @throws EE_Error
4401
-     * @throws InvalidArgumentException
4402
-     * @throws ReflectionException
4403
-     * @throws InvalidDataTypeException
4404
-     * @throws InvalidInterfaceException
4405
-     */
4406
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4407
-        $messenger,
4408
-        EE_message_type $message_type = null
4409
-    ) {
4410
-        EE_Error::overwrite_success();
4411
-
4412
-        // if $messenger isn't a valid messenger object then get out.
4413
-        if (! $messenger instanceof EE_Messenger) {
4414
-            EE_Error::add_error(
4415
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4416
-                __FILE__,
4417
-                __FUNCTION__,
4418
-                __LINE__
4419
-            );
4420
-
4421
-            return false;
4422
-        }
4423
-
4424
-        if ($message_type instanceof EE_message_type) {
4425
-            $message_type_name = $message_type->name;
4426
-            EE_Error::add_success(
4427
-                sprintf(
4428
-                    esc_html__(
4429
-                        '%s message type has been successfully deactivated for the %s messenger.',
4430
-                        'event_espresso'
4431
-                    ),
4432
-                    ucwords($message_type->label['singular']),
4433
-                    ucwords($messenger->label['singular'])
4434
-                )
4435
-            );
4436
-        } else {
4437
-            $message_type_name = '';
4438
-            EE_Error::add_success(
4439
-                sprintf(
4440
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4441
-                    ucwords($messenger->label['singular'])
4442
-                )
4443
-            );
4444
-        }
4445
-
4446
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4447
-        if (
4448
-            $messenger->name === 'html'
4449
-            && (
4450
-                is_null($message_type)
4451
-                || $message_type_name === 'invoice'
4452
-            )
4453
-        ) {
4454
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4455
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4456
-            if ($count_updated > 0) {
4457
-                $msg = $message_type_name === 'invoice'
4458
-                    ? esc_html__(
4459
-                        '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.',
4460
-                        'event_espresso'
4461
-                    )
4462
-                    : esc_html__(
4463
-                        '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.',
4464
-                        'event_espresso'
4465
-                    );
4466
-                EE_Error::add_attention($msg);
4467
-            }
4468
-        }
4469
-
4470
-        return true;
4471
-    }
4472
-
4473
-
4474
-    /**
4475
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4476
-     *
4477
-     * @throws DomainException
4478
-     * @throws EE_Error
4479
-     * @throws EE_Error
4480
-     */
4481
-    public function update_mt_form()
4482
-    {
4483
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4484
-            EE_Error::add_error(
4485
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4486
-                __FILE__,
4487
-                __FUNCTION__,
4488
-                __LINE__
4489
-            );
4490
-            $this->_return_json();
4491
-        }
4492
-
4493
-        $message_types = $this->get_installed_message_types();
4494
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4495
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4496
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4497
-
4498
-        $this->_template_args['success'] = true;
4499
-        $this->_template_args['content'] = $content;
4500
-        $this->_return_json();
4501
-    }
4502
-
4503
-
4504
-    /**
4505
-     * this handles saving the settings for a messenger or message type
4506
-     *
4507
-     * @throws EE_Error
4508
-     * @throws EE_Error
4509
-     */
4510
-    public function save_settings()
4511
-    {
4512
-        $type = $this->request->getRequestParam('type');
4513
-        if (! $type) {
4514
-            EE_Error::add_error(
4515
-                esc_html__(
4516
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4517
-                    'event_espresso'
4518
-                ),
4519
-                __FILE__,
4520
-                __FUNCTION__,
4521
-                __LINE__
4522
-            );
4523
-            $this->_template_args['error'] = true;
4524
-            $this->_return_json();
4525
-        }
4526
-
4527
-
4528
-        if ($type === 'messenger') {
4529
-            // this should be an array.
4530
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4531
-            $messenger = $settings['messenger'];
4532
-            // remove messenger and message_types from settings array
4533
-            unset($settings['messenger'], $settings['message_types']);
4534
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4535
-        } elseif ($type === 'message_type') {
4536
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4537
-            $messenger    = $settings['messenger'];
4538
-            $message_type = $settings['message_type'];
4539
-            // remove messenger and message_types from settings array
4540
-            unset($settings['messenger'], $settings['message_types']);
4541
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4542
-        }
4543
-
4544
-        // okay we should have the data all setup.  Now we just update!
4545
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4546
-
4547
-        if ($success) {
4548
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4549
-        } else {
4550
-            EE_Error::add_error(
4551
-                esc_html__('Settings did not get updated', 'event_espresso'),
4552
-                __FILE__,
4553
-                __FUNCTION__,
4554
-                __LINE__
4555
-            );
4556
-        }
4557
-
4558
-        $this->_template_args['success'] = $success;
4559
-        $this->_return_json();
4560
-    }
4561
-
4562
-
4563
-
4564
-
4565
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4566
-
4567
-
4568
-    /**
4569
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4570
-     * However, this does not send immediately, it just queues for sending.
4571
-     *
4572
-     * @throws EE_Error
4573
-     * @throws InvalidDataTypeException
4574
-     * @throws InvalidInterfaceException
4575
-     * @throws InvalidArgumentException
4576
-     * @throws ReflectionException
4577
-     * @since 4.9.0
4578
-     */
4579
-    protected function _generate_now()
4580
-    {
4581
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4582
-        $this->_redirect_after_action(false, '', '', [], true);
4583
-    }
4584
-
4585
-
4586
-    /**
4587
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4588
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4589
-     *
4590
-     * @throws EE_Error
4591
-     * @throws InvalidDataTypeException
4592
-     * @throws InvalidInterfaceException
4593
-     * @throws InvalidArgumentException
4594
-     * @throws ReflectionException
4595
-     * @since 4.9.0
4596
-     */
4597
-    protected function _generate_and_send_now()
4598
-    {
4599
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4600
-        $this->_redirect_after_action(false, '', '', [], true);
4601
-    }
4602
-
4603
-
4604
-    /**
4605
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4606
-     *
4607
-     * @throws EE_Error
4608
-     * @throws InvalidDataTypeException
4609
-     * @throws InvalidInterfaceException
4610
-     * @throws InvalidArgumentException
4611
-     * @throws ReflectionException
4612
-     * @since 4.9.0
4613
-     */
4614
-    protected function _queue_for_resending()
4615
-    {
4616
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4617
-        $this->_redirect_after_action(false, '', '', [], true);
4618
-    }
4619
-
4620
-
4621
-    /**
4622
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4623
-     *
4624
-     * @throws EE_Error
4625
-     * @throws InvalidDataTypeException
4626
-     * @throws InvalidInterfaceException
4627
-     * @throws InvalidArgumentException
4628
-     * @throws ReflectionException
4629
-     * @since 4.9.0
4630
-     */
4631
-    protected function _send_now()
4632
-    {
4633
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4634
-        $this->_redirect_after_action(false, '', '', [], true);
4635
-    }
4636
-
4637
-
4638
-    /**
4639
-     * Deletes EE_messages for IDs in the request.
4640
-     *
4641
-     * @throws EE_Error
4642
-     * @throws InvalidDataTypeException
4643
-     * @throws InvalidInterfaceException
4644
-     * @throws InvalidArgumentException
4645
-     * @since 4.9.0
4646
-     */
4647
-    protected function _delete_ee_messages()
4648
-    {
4649
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4650
-        $deleted_count = 0;
4651
-        foreach ($MSG_IDs as $MSG_ID) {
4652
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4653
-                $deleted_count++;
4654
-            }
4655
-        }
4656
-        if ($deleted_count) {
4657
-            EE_Error::add_success(
4658
-                esc_html(
4659
-                    _n(
4660
-                        'Message successfully deleted',
4661
-                        'Messages successfully deleted',
4662
-                        $deleted_count,
4663
-                        'event_espresso'
4664
-                    )
4665
-                )
4666
-            );
4667
-        } else {
4668
-            EE_Error::add_error(
4669
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4670
-                __FILE__,
4671
-                __FUNCTION__,
4672
-                __LINE__
4673
-            );
4674
-        }
4675
-        $this->_redirect_after_action(false, '', '', [], true);
4676
-    }
4677
-
4678
-
4679
-    /**
4680
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4681
-     *
4682
-     * @return array
4683
-     * @since 4.9.0
4684
-     */
4685
-    protected function _get_msg_ids_from_request()
4686
-    {
4687
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4688
-        if (empty($MSG_IDs)) {
4689
-            return [];
4690
-        }
4691
-        // if 'MSG_ID' was just a single ID (not an array)
4692
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4693
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4694
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4695
-            ? $MSG_IDs
4696
-            : array_keys($MSG_IDs);
4697
-    }
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
+		[$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
+			$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3455
+			$class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3456
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3457
+				'label' => ucwords($messenger->label['singular']),
3458
+				'class' => $active ? "{$class} messenger-active" : $class,
3459
+				'href'  => $messenger->name,
3460
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
+				'slug'  => $messenger->name,
3462
+				'obj'   => $messenger,
3463
+				'icon' => $active
3464
+					? '<span class="dashicons dashicons-yes-alt"></span>'
3465
+					: '<span class="dashicons dashicons-remove"></span>',
3466
+			];
3467
+
3468
+
3469
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3470
+
3471
+			foreach ($message_types as $message_type) {
3472
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3473
+				// it shouldn't show in either the inactive OR active metabox.
3474
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3475
+					continue;
3476
+				}
3477
+
3478
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3479
+					$messenger->name,
3480
+					$message_type->name
3481
+				)
3482
+					? 'active'
3483
+					: 'inactive';
3484
+
3485
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3486
+					'label'    => ucwords($message_type->label['singular']),
3487
+					'class'    => 'message-type-' . $a_or_i,
3488
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3489
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3490
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3491
+					'title'    => $a_or_i === 'active'
3492
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3493
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3494
+					'content'  => $a_or_i === 'active'
3495
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3496
+						: $this->_message_type_settings_content($message_type, $messenger),
3497
+					'slug'     => $message_type->name,
3498
+					'active'   => $a_or_i === 'active',
3499
+					'obj'      => $message_type,
3500
+				];
3501
+			}
3502
+		}
3503
+	}
3504
+
3505
+
3506
+	/**
3507
+	 * This just prepares the content for the message type settings
3508
+	 *
3509
+	 * @param EE_message_type $message_type The message type object
3510
+	 * @param EE_messenger    $messenger    The messenger object
3511
+	 * @param boolean         $active       Whether the message type is active or not
3512
+	 * @return string html output for the content
3513
+	 * @throws DomainException
3514
+	 */
3515
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3516
+	{
3517
+		// get message type fields
3518
+		$fields                                         = $message_type->get_admin_settings_fields();
3519
+		$settings_template_args['template_form_fields'] = '';
3520
+
3521
+		if (! empty($fields) && $active) {
3522
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3523
+			foreach ($fields as $fldname => $fldprops) {
3524
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3525
+				$template_form_field[ $field_id ] = [
3526
+					'name'       => 'message_type_settings[' . $fldname . ']',
3527
+					'label'      => $fldprops['label'],
3528
+					'input'      => $fldprops['field_type'],
3529
+					'type'       => $fldprops['value_type'],
3530
+					'required'   => $fldprops['required'],
3531
+					'validation' => $fldprops['validation'],
3532
+					'value'      => isset($existing_settings[ $fldname ])
3533
+						? $existing_settings[ $fldname ]
3534
+						: $fldprops['default'],
3535
+					'options'    => isset($fldprops['options'])
3536
+						? $fldprops['options']
3537
+						: [],
3538
+					'default'    => isset($existing_settings[ $fldname ])
3539
+						? $existing_settings[ $fldname ]
3540
+						: $fldprops['default'],
3541
+					'css_class'  => 'no-drag',
3542
+					'format'     => $fldprops['format'],
3543
+				];
3544
+			}
3545
+
3546
+
3547
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3548
+				? $this->_generate_admin_form_fields(
3549
+					$template_form_field,
3550
+					'string',
3551
+					'ee_mt_activate_form'
3552
+				)
3553
+				: '';
3554
+		}
3555
+
3556
+		$settings_template_args['description'] = $message_type->description;
3557
+		// we also need some hidden fields
3558
+		$hidden_fields = [
3559
+			'message_type_settings[messenger]' . $message_type->name    => [
3560
+				'type'  => 'hidden',
3561
+				'value' => $messenger->name,
3562
+			],
3563
+			'message_type_settings[message_type]' . $message_type->name => [
3564
+				'type'  => 'hidden',
3565
+				'value' => $message_type->name,
3566
+			],
3567
+			'type' . $message_type->name                                => [
3568
+				'type'  => 'hidden',
3569
+				'value' => 'message_type',
3570
+			],
3571
+		];
3572
+
3573
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3574
+			$hidden_fields,
3575
+			'array'
3576
+		);
3577
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3578
+			? ' hidden'
3579
+			: '';
3580
+
3581
+
3582
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3583
+		return EEH_Template::display_template($template, $settings_template_args, true);
3584
+	}
3585
+
3586
+
3587
+	/**
3588
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3589
+	 *
3590
+	 * @access protected
3591
+	 * @return void
3592
+	 * @throws DomainException
3593
+	 */
3594
+	protected function _messages_settings_metaboxes()
3595
+	{
3596
+		$this->_set_m_mt_settings();
3597
+		$m_boxes         = $mt_boxes = [];
3598
+		$m_template_args = $mt_template_args = [];
3599
+
3600
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3601
+
3602
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3603
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3604
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3605
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3606
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3607
+
3608
+				// messenger meta boxes
3609
+				$active         = $selected_messenger === $messenger;
3610
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3611
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3612
+					: '';
3613
+
3614
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3615
+					esc_html__('%s Settings', 'event_espresso'),
3616
+					$tab_array['label']
3617
+				);
3618
+
3619
+				$m_template_args[ $messenger . '_a_box' ] = [
3620
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3621
+					'inactive_message_types' => isset(
3622
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3623
+					)
3624
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3625
+						: '',
3626
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3627
+					'hidden'                 => $active ? '' : ' hidden',
3628
+					'hide_on_message'        => $hide_on_message,
3629
+					'messenger'              => $messenger,
3630
+					'active'                 => $active,
3631
+				];
3632
+
3633
+				// message type meta boxes
3634
+				// (which is really just the inactive container for each messenger
3635
+				// showing inactive message types for that messenger)
3636
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3637
+				$mt_template_args[ $messenger . '_i_box' ] = [
3638
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3639
+					'inactive_message_types' => isset(
3640
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3641
+					)
3642
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3643
+						: '',
3644
+					'hidden'                 => $active ? '' : ' hidden',
3645
+					'hide_on_message'        => $hide_on_message,
3646
+					'hide_off_message'       => $hide_off_message,
3647
+					'messenger'              => $messenger,
3648
+					'active'                 => $active,
3649
+				];
3650
+			}
3651
+		}
3652
+
3653
+
3654
+		// register messenger metaboxes
3655
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3656
+		foreach ($m_boxes as $box => $label) {
3657
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3658
+			$msgr          = str_replace('_a_box', '', $box);
3659
+			$this->addMetaBox(
3660
+				'espresso_' . $msgr . '_settings',
3661
+				$label,
3662
+				function ($post, $metabox) {
3663
+					EEH_Template::display_template(
3664
+						$metabox['args']['template_path'],
3665
+						$metabox['args']['template_args']
3666
+					);
3667
+				},
3668
+				$this->_current_screen->id,
3669
+				'normal',
3670
+				'high',
3671
+				$callback_args
3672
+			);
3673
+		}
3674
+
3675
+		// register message type metaboxes
3676
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3677
+		foreach ($mt_boxes as $box => $label) {
3678
+			$callback_args = [
3679
+				'template_path' => $mt_template_path,
3680
+				'template_args' => $mt_template_args[ $box ],
3681
+			];
3682
+			$mt            = str_replace('_i_box', '', $box);
3683
+			$this->addMetaBox(
3684
+				'espresso_' . $mt . '_inactive_mts',
3685
+				$label,
3686
+				function ($post, $metabox) {
3687
+					EEH_Template::display_template(
3688
+						$metabox['args']['template_path'],
3689
+						$metabox['args']['template_args']
3690
+					);
3691
+				},
3692
+				$this->_current_screen->id,
3693
+				'side',
3694
+				'high',
3695
+				$callback_args
3696
+			);
3697
+		}
3698
+
3699
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3700
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3701
+		if (is_main_site()) {
3702
+			$this->addMetaBox(
3703
+				'espresso_global_message_settings',
3704
+				esc_html__('Global Message Settings', 'event_espresso'),
3705
+				[$this, 'global_messages_settings_metabox_content'],
3706
+				$this->_current_screen->id,
3707
+				'normal',
3708
+				'low',
3709
+				[]
3710
+			);
3711
+		}
3712
+	}
3713
+
3714
+
3715
+	/**
3716
+	 *  This generates the content for the global messages settings metabox.
3717
+	 *
3718
+	 * @return void
3719
+	 * @throws EE_Error
3720
+	 * @throws InvalidArgumentException
3721
+	 * @throws ReflectionException
3722
+	 * @throws InvalidDataTypeException
3723
+	 * @throws InvalidInterfaceException
3724
+	 */
3725
+	public function global_messages_settings_metabox_content()
3726
+	{
3727
+		$form = $this->_generate_global_settings_form();
3728
+		echo wp_kses(
3729
+			$form->form_open(
3730
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3731
+				'POST'
3732
+			),
3733
+			AllowedTags::getWithFormTags()
3734
+		);
3735
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3736
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3737
+	}
3738
+
3739
+
3740
+	/**
3741
+	 * This generates and returns the form object for the global messages settings.
3742
+	 *
3743
+	 * @return EE_Form_Section_Proper
3744
+	 * @throws EE_Error
3745
+	 * @throws InvalidArgumentException
3746
+	 * @throws ReflectionException
3747
+	 * @throws InvalidDataTypeException
3748
+	 * @throws InvalidInterfaceException
3749
+	 */
3750
+	protected function _generate_global_settings_form()
3751
+	{
3752
+		/** @var EE_Network_Core_Config $network_config */
3753
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3754
+
3755
+		return new EE_Form_Section_Proper(
3756
+			[
3757
+				'name'            => 'global_messages_settings',
3758
+				'html_id'         => 'global_messages_settings',
3759
+				'html_class'      => 'form-table',
3760
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3761
+				'subsections'     => apply_filters(
3762
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3763
+					[
3764
+						'do_messages_on_same_request' => new EE_Select_Input(
3765
+							[
3766
+								true  => esc_html__('On the same request', 'event_espresso'),
3767
+								false => esc_html__('On a separate request', 'event_espresso'),
3768
+							],
3769
+							[
3770
+								'default'         => $network_config->do_messages_on_same_request,
3771
+								'html_label_text' => esc_html__(
3772
+									'Generate and send all messages:',
3773
+									'event_espresso'
3774
+								),
3775
+								'html_help_text'  => esc_html__(
3776
+									'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.',
3777
+									'event_espresso'
3778
+								),
3779
+							]
3780
+						),
3781
+						'delete_threshold'            => new EE_Select_Input(
3782
+							[
3783
+								0  => esc_html__('Forever', 'event_espresso'),
3784
+								3  => esc_html__('3 Months', 'event_espresso'),
3785
+								6  => esc_html__('6 Months', 'event_espresso'),
3786
+								9  => esc_html__('9 Months', 'event_espresso'),
3787
+								12 => esc_html__('12 Months', 'event_espresso'),
3788
+								24 => esc_html__('24 Months', 'event_espresso'),
3789
+								36 => esc_html__('36 Months', 'event_espresso'),
3790
+							],
3791
+							[
3792
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3793
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3794
+								'html_help_text'  => esc_html__(
3795
+									'You can control how long a record of processed messages is kept via this option.',
3796
+									'event_espresso'
3797
+								),
3798
+							]
3799
+						),
3800
+						'update_settings'             => new EE_Submit_Input(
3801
+							[
3802
+								'default'         => esc_html__('Update', 'event_espresso'),
3803
+								'html_label_text' => '',
3804
+							]
3805
+						),
3806
+					]
3807
+				),
3808
+			]
3809
+		);
3810
+	}
3811
+
3812
+
3813
+	/**
3814
+	 * This handles updating the global settings set on the admin page.
3815
+	 *
3816
+	 * @throws EE_Error
3817
+	 * @throws InvalidDataTypeException
3818
+	 * @throws InvalidInterfaceException
3819
+	 * @throws InvalidArgumentException
3820
+	 * @throws ReflectionException
3821
+	 */
3822
+	protected function _update_global_settings()
3823
+	{
3824
+		/** @var EE_Network_Core_Config $network_config */
3825
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3826
+		$messages_config = EE_Registry::instance()->CFG->messages;
3827
+		$form            = $this->_generate_global_settings_form();
3828
+		if ($form->was_submitted()) {
3829
+			$form->receive_form_submission();
3830
+			if ($form->is_valid()) {
3831
+				$valid_data = $form->valid_data();
3832
+				foreach ($valid_data as $property => $value) {
3833
+					$setter = 'set_' . $property;
3834
+					if (method_exists($network_config, $setter)) {
3835
+						$network_config->{$setter}($value);
3836
+					} elseif (
3837
+						property_exists($network_config, $property)
3838
+						&& $network_config->{$property} !== $value
3839
+					) {
3840
+						$network_config->{$property} = $value;
3841
+					} elseif (
3842
+						property_exists($messages_config, $property)
3843
+						&& $messages_config->{$property} !== $value
3844
+					) {
3845
+						$messages_config->{$property} = $value;
3846
+					}
3847
+				}
3848
+				// only update if the form submission was valid!
3849
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3850
+				EE_Registry::instance()->CFG->update_espresso_config();
3851
+				EE_Error::overwrite_success();
3852
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3853
+			}
3854
+		}
3855
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3856
+	}
3857
+
3858
+
3859
+	/**
3860
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3861
+	 *
3862
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3863
+	 * @return string html formatted tabs
3864
+	 * @throws DomainException
3865
+	 */
3866
+	protected function _get_mt_tabs($tab_array)
3867
+	{
3868
+		$tab_array = (array) $tab_array;
3869
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3870
+		$tabs      = '';
3871
+
3872
+		foreach ($tab_array as $tab) {
3873
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3874
+		}
3875
+
3876
+		return $tabs;
3877
+	}
3878
+
3879
+
3880
+	/**
3881
+	 * This prepares the content of the messenger meta box admin settings
3882
+	 *
3883
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3884
+	 * @return string html formatted content
3885
+	 * @throws DomainException
3886
+	 */
3887
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3888
+	{
3889
+
3890
+		$fields                                         = $messenger->get_admin_settings_fields();
3891
+		$settings_template_args['template_form_fields'] = '';
3892
+
3893
+		// is $messenger active?
3894
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3895
+
3896
+
3897
+		if (! empty($fields)) {
3898
+			$existing_settings = $messenger->get_existing_admin_settings();
3899
+
3900
+			foreach ($fields as $fldname => $fldprops) {
3901
+				$field_id                         = $messenger->name . '-' . $fldname;
3902
+				$template_form_field[ $field_id ] = [
3903
+					'name'       => 'messenger_settings[' . $field_id . ']',
3904
+					'label'      => $fldprops['label'],
3905
+					'input'      => $fldprops['field_type'],
3906
+					'type'       => $fldprops['value_type'],
3907
+					'required'   => $fldprops['required'],
3908
+					'validation' => $fldprops['validation'],
3909
+					'value'      => isset($existing_settings[ $field_id ])
3910
+						? $existing_settings[ $field_id ]
3911
+						: $fldprops['default'],
3912
+					'css_class'  => '',
3913
+					'format'     => $fldprops['format'],
3914
+				];
3915
+			}
3916
+
3917
+
3918
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3919
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3920
+				: '';
3921
+		}
3922
+
3923
+		// we also need some hidden fields
3924
+		$settings_template_args['hidden_fields'] = [
3925
+			'messenger_settings[messenger]' . $messenger->name => [
3926
+				'type'  => 'hidden',
3927
+				'value' => $messenger->name,
3928
+			],
3929
+			'type' . $messenger->name                          => [
3930
+				'type'  => 'hidden',
3931
+				'value' => 'messenger',
3932
+			],
3933
+		];
3934
+
3935
+		// make sure any active message types that are existing are included in the hidden fields
3936
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3937
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3938
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3939
+					'type'  => 'hidden',
3940
+					'value' => $mt,
3941
+				];
3942
+			}
3943
+		}
3944
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3945
+			$settings_template_args['hidden_fields'],
3946
+			'array'
3947
+		);
3948
+		$active                                  =
3949
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3950
+
3951
+		$settings_template_args['messenger']           = $messenger->name;
3952
+		$settings_template_args['description']         = $messenger->description;
3953
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3954
+
3955
+
3956
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3957
+			$messenger->name
3958
+		)
3959
+			? $settings_template_args['show_hide_edit_form']
3960
+			: ' hidden';
3961
+
3962
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3963
+			? ' hidden'
3964
+			: $settings_template_args['show_hide_edit_form'];
3965
+
3966
+
3967
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3968
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3969
+		$settings_template_args['on_off_status'] = $active;
3970
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3971
+		return EEH_Template::display_template(
3972
+			$template,
3973
+			$settings_template_args,
3974
+			true
3975
+		);
3976
+	}
3977
+
3978
+
3979
+	/**
3980
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3981
+	 *
3982
+	 * @throws DomainException
3983
+	 * @throws EE_Error
3984
+	 * @throws InvalidDataTypeException
3985
+	 * @throws InvalidInterfaceException
3986
+	 * @throws InvalidArgumentException
3987
+	 * @throws ReflectionException
3988
+	 */
3989
+	public function activate_messenger_toggle()
3990
+	{
3991
+		$success = true;
3992
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3993
+		// let's check that we have required data
3994
+
3995
+		if (! $this->_active_messenger_name) {
3996
+			EE_Error::add_error(
3997
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3998
+				__FILE__,
3999
+				__FUNCTION__,
4000
+				__LINE__
4001
+			);
4002
+			$success = false;
4003
+		}
4004
+
4005
+		// do a nonce check here since we're not arriving via a normal route
4006
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4007
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4008
+
4009
+		$this->_verify_nonce($nonce, $nonce_ref);
4010
+
4011
+
4012
+		$status = $this->request->getRequestParam('status');
4013
+		if (! $status) {
4014
+			EE_Error::add_error(
4015
+				esc_html__(
4016
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4017
+					'event_espresso'
4018
+				),
4019
+				__FILE__,
4020
+				__FUNCTION__,
4021
+				__LINE__
4022
+			);
4023
+			$success = false;
4024
+		}
4025
+
4026
+		// do check to verify we have a valid status.
4027
+		if ($status !== 'off' && $status !== 'on') {
4028
+			EE_Error::add_error(
4029
+				sprintf(
4030
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4031
+					$status
4032
+				),
4033
+				__FILE__,
4034
+				__FUNCTION__,
4035
+				__LINE__
4036
+			);
4037
+			$success = false;
4038
+		}
4039
+
4040
+		if ($success) {
4041
+			// made it here?  Stop dawdling then!!
4042
+			$success = $status === 'off'
4043
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4044
+				: $this->_activate_messenger($this->_active_messenger_name);
4045
+		}
4046
+
4047
+		$this->_template_args['success'] = $success;
4048
+
4049
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4050
+		$this->_return_json();
4051
+	}
4052
+
4053
+
4054
+	/**
4055
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4056
+	 *
4057
+	 * @throws DomainException
4058
+	 * @throws EE_Error
4059
+	 * @throws ReflectionException
4060
+	 * @throws InvalidDataTypeException
4061
+	 * @throws InvalidInterfaceException
4062
+	 * @throws InvalidArgumentException
4063
+	 */
4064
+	public function activate_mt_toggle()
4065
+	{
4066
+		$success = true;
4067
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4068
+
4069
+		// let's make sure we have the necessary data
4070
+		if (! $this->_active_message_type_name) {
4071
+			EE_Error::add_error(
4072
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4073
+				__FILE__,
4074
+				__FUNCTION__,
4075
+				__LINE__
4076
+			);
4077
+			$success = false;
4078
+		}
4079
+
4080
+		if (! $this->_active_messenger_name) {
4081
+			EE_Error::add_error(
4082
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4083
+				__FILE__,
4084
+				__FUNCTION__,
4085
+				__LINE__
4086
+			);
4087
+			$success = false;
4088
+		}
4089
+
4090
+		$status = $this->request->getRequestParam('status');
4091
+		if (! $status) {
4092
+			EE_Error::add_error(
4093
+				esc_html__(
4094
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4095
+					'event_espresso'
4096
+				),
4097
+				__FILE__,
4098
+				__FUNCTION__,
4099
+				__LINE__
4100
+			);
4101
+			$success = false;
4102
+		}
4103
+
4104
+
4105
+		// do check to verify we have a valid status.
4106
+		if ($status !== 'activate' && $status !== 'deactivate') {
4107
+			EE_Error::add_error(
4108
+				sprintf(
4109
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4110
+					$status
4111
+				),
4112
+				__FILE__,
4113
+				__FUNCTION__,
4114
+				__LINE__
4115
+			);
4116
+			$success = false;
4117
+		}
4118
+
4119
+
4120
+		// do a nonce check here since we're not arriving via a normal route
4121
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4122
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4123
+
4124
+		if ($success) {
4125
+			// made it here? um, what are you waiting for then?
4126
+			$success = $status === 'deactivate'
4127
+				? $this->_deactivate_message_type_for_messenger(
4128
+					$this->_active_messenger_name,
4129
+					$this->_active_message_type_name
4130
+				)
4131
+				: $this->_activate_message_type_for_messenger(
4132
+					$this->_active_messenger_name,
4133
+					$this->_active_message_type_name
4134
+				);
4135
+		}
4136
+
4137
+		$this->_template_args['success'] = $success;
4138
+		$this->_return_json();
4139
+	}
4140
+
4141
+
4142
+	/**
4143
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4144
+	 *
4145
+	 * @param string $messenger_name The name of the messenger being activated
4146
+	 * @return bool
4147
+	 * @throws DomainException
4148
+	 * @throws EE_Error
4149
+	 * @throws InvalidArgumentException
4150
+	 * @throws ReflectionException
4151
+	 * @throws InvalidDataTypeException
4152
+	 * @throws InvalidInterfaceException
4153
+	 */
4154
+	protected function _activate_messenger($messenger_name)
4155
+	{
4156
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4157
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4158
+			? $active_messenger->get_default_message_types()
4159
+			: [];
4160
+
4161
+		// ensure is active
4162
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4163
+
4164
+		// set response_data for reload
4165
+		foreach ($message_types_to_activate as $message_type_name) {
4166
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4167
+			if (
4168
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4169
+					$messenger_name,
4170
+					$message_type_name
4171
+				)
4172
+				&& $message_type instanceof EE_message_type
4173
+			) {
4174
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4175
+				if ($message_type->get_admin_settings_fields()) {
4176
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4177
+				}
4178
+			}
4179
+		}
4180
+
4181
+		// add success message for activating messenger
4182
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4183
+	}
4184
+
4185
+
4186
+	/**
4187
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4188
+	 *
4189
+	 * @param string $messenger_name The name of the messenger being activated
4190
+	 * @return bool
4191
+	 * @throws DomainException
4192
+	 * @throws EE_Error
4193
+	 * @throws InvalidArgumentException
4194
+	 * @throws ReflectionException
4195
+	 * @throws InvalidDataTypeException
4196
+	 * @throws InvalidInterfaceException
4197
+	 */
4198
+	protected function _deactivate_messenger($messenger_name)
4199
+	{
4200
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4201
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4202
+
4203
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4204
+	}
4205
+
4206
+
4207
+	/**
4208
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4209
+	 *
4210
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4211
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4212
+	 * @return bool
4213
+	 * @throws DomainException
4214
+	 * @throws EE_Error
4215
+	 * @throws InvalidArgumentException
4216
+	 * @throws ReflectionException
4217
+	 * @throws InvalidDataTypeException
4218
+	 * @throws InvalidInterfaceException
4219
+	 */
4220
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4221
+	{
4222
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4223
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4224
+
4225
+		// ensure is active
4226
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4227
+
4228
+		// set response for load
4229
+		if (
4230
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4231
+				$messenger_name,
4232
+				$message_type_name
4233
+			)
4234
+		) {
4235
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4236
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4237
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4238
+			}
4239
+		}
4240
+
4241
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4242
+			$active_messenger,
4243
+			$message_type_to_activate
4244
+		);
4245
+	}
4246
+
4247
+
4248
+	/**
4249
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4250
+	 *
4251
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4252
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4253
+	 * @return bool
4254
+	 * @throws DomainException
4255
+	 * @throws EE_Error
4256
+	 * @throws InvalidArgumentException
4257
+	 * @throws ReflectionException
4258
+	 * @throws InvalidDataTypeException
4259
+	 * @throws InvalidInterfaceException
4260
+	 */
4261
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4262
+	{
4263
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4264
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4265
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4266
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4267
+
4268
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4269
+			$active_messenger,
4270
+			$message_type_to_deactivate
4271
+		);
4272
+	}
4273
+
4274
+
4275
+	/**
4276
+	 * This just initializes the defaults for activating messenger and message type responses.
4277
+	 */
4278
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4279
+	{
4280
+		$this->_template_args['data']['active_mts'] = [];
4281
+		$this->_template_args['data']['mt_reload']  = [];
4282
+	}
4283
+
4284
+
4285
+	/**
4286
+	 * Setup appropriate response for activating a messenger and/or message types
4287
+	 *
4288
+	 * @param EE_messenger         $messenger
4289
+	 * @param EE_message_type|null $message_type
4290
+	 * @return bool
4291
+	 * @throws DomainException
4292
+	 * @throws EE_Error
4293
+	 * @throws InvalidArgumentException
4294
+	 * @throws ReflectionException
4295
+	 * @throws InvalidDataTypeException
4296
+	 * @throws InvalidInterfaceException
4297
+	 */
4298
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4299
+		$messenger,
4300
+		EE_Message_Type $message_type = null
4301
+	) {
4302
+		// if $messenger isn't a valid messenger object then get out.
4303
+		if (! $messenger instanceof EE_Messenger) {
4304
+			EE_Error::add_error(
4305
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4306
+				__FILE__,
4307
+				__FUNCTION__,
4308
+				__LINE__
4309
+			);
4310
+			return false;
4311
+		}
4312
+		// activated
4313
+		if ($this->_template_args['data']['active_mts']) {
4314
+			EE_Error::overwrite_success();
4315
+			// activated a message type with the messenger
4316
+			if ($message_type instanceof EE_message_type) {
4317
+				EE_Error::add_success(
4318
+					sprintf(
4319
+						esc_html__(
4320
+							'%s message type has been successfully activated with the %s messenger',
4321
+							'event_espresso'
4322
+						),
4323
+						ucwords($message_type->label['singular']),
4324
+						ucwords($messenger->label['singular'])
4325
+					)
4326
+				);
4327
+
4328
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4329
+				if ($message_type->name === 'invoice') {
4330
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4331
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4332
+					if ($pm instanceof EE_Payment_Method) {
4333
+						EE_Error::add_attention(
4334
+							esc_html__(
4335
+								'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.',
4336
+								'event_espresso'
4337
+							)
4338
+						);
4339
+					}
4340
+				}
4341
+				// just toggles the entire messenger
4342
+			} else {
4343
+				EE_Error::add_success(
4344
+					sprintf(
4345
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4346
+						ucwords($messenger->label['singular'])
4347
+					)
4348
+				);
4349
+			}
4350
+
4351
+			return true;
4352
+
4353
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4354
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4355
+			// in which case we just give a success message for the messenger being successfully activated.
4356
+		} else {
4357
+			if (! $messenger->get_default_message_types()) {
4358
+				// messenger doesn't have any default message types so still a success.
4359
+				EE_Error::add_success(
4360
+					sprintf(
4361
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4362
+						ucwords($messenger->label['singular'])
4363
+					)
4364
+				);
4365
+
4366
+				return true;
4367
+			} else {
4368
+				EE_Error::add_error(
4369
+					$message_type instanceof EE_message_type
4370
+					? sprintf(
4371
+						esc_html__(
4372
+							'%s message type was not successfully activated with the %s messenger',
4373
+							'event_espresso'
4374
+						),
4375
+						ucwords($message_type->label['singular']),
4376
+						ucwords($messenger->label['singular'])
4377
+					)
4378
+					: sprintf(
4379
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4380
+						ucwords($messenger->label['singular'])
4381
+					),
4382
+					__FILE__,
4383
+					__FUNCTION__,
4384
+					__LINE__
4385
+				);
4386
+
4387
+				return false;
4388
+			}
4389
+		}
4390
+	}
4391
+
4392
+
4393
+	/**
4394
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4395
+	 *
4396
+	 * @param EE_messenger         $messenger
4397
+	 * @param EE_message_type|null $message_type
4398
+	 * @return bool
4399
+	 * @throws DomainException
4400
+	 * @throws EE_Error
4401
+	 * @throws InvalidArgumentException
4402
+	 * @throws ReflectionException
4403
+	 * @throws InvalidDataTypeException
4404
+	 * @throws InvalidInterfaceException
4405
+	 */
4406
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4407
+		$messenger,
4408
+		EE_message_type $message_type = null
4409
+	) {
4410
+		EE_Error::overwrite_success();
4411
+
4412
+		// if $messenger isn't a valid messenger object then get out.
4413
+		if (! $messenger instanceof EE_Messenger) {
4414
+			EE_Error::add_error(
4415
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4416
+				__FILE__,
4417
+				__FUNCTION__,
4418
+				__LINE__
4419
+			);
4420
+
4421
+			return false;
4422
+		}
4423
+
4424
+		if ($message_type instanceof EE_message_type) {
4425
+			$message_type_name = $message_type->name;
4426
+			EE_Error::add_success(
4427
+				sprintf(
4428
+					esc_html__(
4429
+						'%s message type has been successfully deactivated for the %s messenger.',
4430
+						'event_espresso'
4431
+					),
4432
+					ucwords($message_type->label['singular']),
4433
+					ucwords($messenger->label['singular'])
4434
+				)
4435
+			);
4436
+		} else {
4437
+			$message_type_name = '';
4438
+			EE_Error::add_success(
4439
+				sprintf(
4440
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4441
+					ucwords($messenger->label['singular'])
4442
+				)
4443
+			);
4444
+		}
4445
+
4446
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4447
+		if (
4448
+			$messenger->name === 'html'
4449
+			&& (
4450
+				is_null($message_type)
4451
+				|| $message_type_name === 'invoice'
4452
+			)
4453
+		) {
4454
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4455
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4456
+			if ($count_updated > 0) {
4457
+				$msg = $message_type_name === 'invoice'
4458
+					? esc_html__(
4459
+						'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.',
4460
+						'event_espresso'
4461
+					)
4462
+					: esc_html__(
4463
+						'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.',
4464
+						'event_espresso'
4465
+					);
4466
+				EE_Error::add_attention($msg);
4467
+			}
4468
+		}
4469
+
4470
+		return true;
4471
+	}
4472
+
4473
+
4474
+	/**
4475
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4476
+	 *
4477
+	 * @throws DomainException
4478
+	 * @throws EE_Error
4479
+	 * @throws EE_Error
4480
+	 */
4481
+	public function update_mt_form()
4482
+	{
4483
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4484
+			EE_Error::add_error(
4485
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4486
+				__FILE__,
4487
+				__FUNCTION__,
4488
+				__LINE__
4489
+			);
4490
+			$this->_return_json();
4491
+		}
4492
+
4493
+		$message_types = $this->get_installed_message_types();
4494
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4495
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4496
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4497
+
4498
+		$this->_template_args['success'] = true;
4499
+		$this->_template_args['content'] = $content;
4500
+		$this->_return_json();
4501
+	}
4502
+
4503
+
4504
+	/**
4505
+	 * this handles saving the settings for a messenger or message type
4506
+	 *
4507
+	 * @throws EE_Error
4508
+	 * @throws EE_Error
4509
+	 */
4510
+	public function save_settings()
4511
+	{
4512
+		$type = $this->request->getRequestParam('type');
4513
+		if (! $type) {
4514
+			EE_Error::add_error(
4515
+				esc_html__(
4516
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4517
+					'event_espresso'
4518
+				),
4519
+				__FILE__,
4520
+				__FUNCTION__,
4521
+				__LINE__
4522
+			);
4523
+			$this->_template_args['error'] = true;
4524
+			$this->_return_json();
4525
+		}
4526
+
4527
+
4528
+		if ($type === 'messenger') {
4529
+			// this should be an array.
4530
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4531
+			$messenger = $settings['messenger'];
4532
+			// remove messenger and message_types from settings array
4533
+			unset($settings['messenger'], $settings['message_types']);
4534
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4535
+		} elseif ($type === 'message_type') {
4536
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4537
+			$messenger    = $settings['messenger'];
4538
+			$message_type = $settings['message_type'];
4539
+			// remove messenger and message_types from settings array
4540
+			unset($settings['messenger'], $settings['message_types']);
4541
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4542
+		}
4543
+
4544
+		// okay we should have the data all setup.  Now we just update!
4545
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4546
+
4547
+		if ($success) {
4548
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4549
+		} else {
4550
+			EE_Error::add_error(
4551
+				esc_html__('Settings did not get updated', 'event_espresso'),
4552
+				__FILE__,
4553
+				__FUNCTION__,
4554
+				__LINE__
4555
+			);
4556
+		}
4557
+
4558
+		$this->_template_args['success'] = $success;
4559
+		$this->_return_json();
4560
+	}
4561
+
4562
+
4563
+
4564
+
4565
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4566
+
4567
+
4568
+	/**
4569
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4570
+	 * However, this does not send immediately, it just queues for sending.
4571
+	 *
4572
+	 * @throws EE_Error
4573
+	 * @throws InvalidDataTypeException
4574
+	 * @throws InvalidInterfaceException
4575
+	 * @throws InvalidArgumentException
4576
+	 * @throws ReflectionException
4577
+	 * @since 4.9.0
4578
+	 */
4579
+	protected function _generate_now()
4580
+	{
4581
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4582
+		$this->_redirect_after_action(false, '', '', [], true);
4583
+	}
4584
+
4585
+
4586
+	/**
4587
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4588
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4589
+	 *
4590
+	 * @throws EE_Error
4591
+	 * @throws InvalidDataTypeException
4592
+	 * @throws InvalidInterfaceException
4593
+	 * @throws InvalidArgumentException
4594
+	 * @throws ReflectionException
4595
+	 * @since 4.9.0
4596
+	 */
4597
+	protected function _generate_and_send_now()
4598
+	{
4599
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4600
+		$this->_redirect_after_action(false, '', '', [], true);
4601
+	}
4602
+
4603
+
4604
+	/**
4605
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4606
+	 *
4607
+	 * @throws EE_Error
4608
+	 * @throws InvalidDataTypeException
4609
+	 * @throws InvalidInterfaceException
4610
+	 * @throws InvalidArgumentException
4611
+	 * @throws ReflectionException
4612
+	 * @since 4.9.0
4613
+	 */
4614
+	protected function _queue_for_resending()
4615
+	{
4616
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4617
+		$this->_redirect_after_action(false, '', '', [], true);
4618
+	}
4619
+
4620
+
4621
+	/**
4622
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4623
+	 *
4624
+	 * @throws EE_Error
4625
+	 * @throws InvalidDataTypeException
4626
+	 * @throws InvalidInterfaceException
4627
+	 * @throws InvalidArgumentException
4628
+	 * @throws ReflectionException
4629
+	 * @since 4.9.0
4630
+	 */
4631
+	protected function _send_now()
4632
+	{
4633
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4634
+		$this->_redirect_after_action(false, '', '', [], true);
4635
+	}
4636
+
4637
+
4638
+	/**
4639
+	 * Deletes EE_messages for IDs in the request.
4640
+	 *
4641
+	 * @throws EE_Error
4642
+	 * @throws InvalidDataTypeException
4643
+	 * @throws InvalidInterfaceException
4644
+	 * @throws InvalidArgumentException
4645
+	 * @since 4.9.0
4646
+	 */
4647
+	protected function _delete_ee_messages()
4648
+	{
4649
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4650
+		$deleted_count = 0;
4651
+		foreach ($MSG_IDs as $MSG_ID) {
4652
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4653
+				$deleted_count++;
4654
+			}
4655
+		}
4656
+		if ($deleted_count) {
4657
+			EE_Error::add_success(
4658
+				esc_html(
4659
+					_n(
4660
+						'Message successfully deleted',
4661
+						'Messages successfully deleted',
4662
+						$deleted_count,
4663
+						'event_espresso'
4664
+					)
4665
+				)
4666
+			);
4667
+		} else {
4668
+			EE_Error::add_error(
4669
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4670
+				__FILE__,
4671
+				__FUNCTION__,
4672
+				__LINE__
4673
+			);
4674
+		}
4675
+		$this->_redirect_after_action(false, '', '', [], true);
4676
+	}
4677
+
4678
+
4679
+	/**
4680
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4681
+	 *
4682
+	 * @return array
4683
+	 * @since 4.9.0
4684
+	 */
4685
+	protected function _get_msg_ids_from_request()
4686
+	{
4687
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4688
+		if (empty($MSG_IDs)) {
4689
+			return [];
4690
+		}
4691
+		// if 'MSG_ID' was just a single ID (not an array)
4692
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4693
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4694
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4695
+			? $MSG_IDs
4696
+			: array_keys($MSG_IDs);
4697
+	}
4698 4698
 }
Please login to merge, or discard this patch.
Spacing   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function getMsgModel()
117 117
     {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
119 119
             $this->MSG_MODEL = EEM_Message::instance();
120 120
         }
121 121
         return $this->MSG_MODEL;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function getMtpModel()
130 130
     {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
132 132
             $this->MTP_MODEL = EEM_Message_Template::instance();
133 133
         }
134 134
         return $this->MTP_MODEL;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function getMtgModel()
143 143
     {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145 145
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146 146
         }
147 147
         return $this->MTG_MODEL;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
         $i = 1;
212 212
         foreach ($active_messengers as $active_messenger) {
213 213
             if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
214
+                $m_values[$i]['id']   = $active_messenger->messenger();
215
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
216 216
                 $i++;
217 217
             }
218 218
         }
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
         $i               = 1;
249 249
         foreach ($active_messages as $active_message) {
250 250
             if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
251
+                $mt_values[$i]['id']   = $active_message->message_type();
252
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
253 253
                 $i++;
254 254
             }
255 255
         }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 if ($message_type instanceof EE_message_type) {
289 289
                     $message_type_contexts = $message_type->get_contexts();
290 290
                     foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
291
+                        $contexts[$context] = $context_details['label'];
292 292
                     }
293 293
                 }
294 294
             }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322 322
             $messenger_options
323 323
         );
324
-        $input             = new EE_Select_Input(
324
+        $input = new EE_Select_Input(
325 325
             $messenger_options,
326 326
             [
327 327
                 'html_name'  => 'ee_messenger_filter_by',
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359 359
             $message_type_options
360 360
         );
361
-        $input                = new EE_Select_Input(
361
+        $input = new EE_Select_Input(
362 362
             $message_type_options,
363 363
             [
364 364
                 'html_name'  => 'ee_message_type_filter_by',
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396 396
             $context_options
397 397
         );
398
-        $input           = new EE_Select_Input(
398
+        $input = new EE_Select_Input(
399 399
             $context_options,
400 400
             [
401 401
                 'html_name'  => 'ee_context_filter_by',
@@ -769,53 +769,53 @@  discard block
 block discarded – undo
769 769
 
770 770
     public function messages_help_tab()
771 771
     {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
773 773
     }
774 774
 
775 775
 
776 776
     public function messengers_help_tab()
777 777
     {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
779 779
     }
780 780
 
781 781
 
782 782
     public function message_types_help_tab()
783 783
     {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
785 785
     }
786 786
 
787 787
 
788 788
     public function messages_overview_help_tab()
789 789
     {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
791 791
     }
792 792
 
793 793
 
794 794
     public function message_templates_help_tab()
795 795
     {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
797 797
     }
798 798
 
799 799
 
800 800
     public function edit_message_template_help_tab()
801 801
     {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
803 803
                         . esc_attr__('Editor Title', 'event_espresso')
804 804
                         . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
806 806
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
807 807
                         . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
809 809
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
810 810
                         . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
812 812
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
813 813
                         . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
815 815
                         . esc_attr__('Publish Metabox', 'event_espresso')
816 816
                         . '" />';
817 817
         EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
819 819
             $args
820 820
         );
821 821
     }
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
         $this->_set_shortcodes();
831 831
         $args['shortcodes'] = $this->_shortcodes;
832 832
         EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
834 834
             $args
835 835
         );
836 836
     }
@@ -838,16 +838,16 @@  discard block
 block discarded – undo
838 838
 
839 839
     public function preview_message_help_tab()
840 840
     {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
842 842
     }
843 843
 
844 844
 
845 845
     public function settings_help_tab()
846 846
     {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
847
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
848
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
849
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
850
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
851 851
         $args['img3'] = '<div class="switch">'
852 852
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853 853
                         . ' type="checkbox" checked>'
@@ -858,25 +858,25 @@  discard block
 block discarded – undo
858 858
                         . ' type="checkbox">'
859 859
                         . '<label for="ee-on-off-toggle-on"></label>'
860 860
                         . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
862 862
     }
863 863
 
864 864
 
865 865
     public function load_scripts_styles()
866 866
     {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868 868
         wp_enqueue_style('espresso_ee_msg');
869 869
 
870 870
         wp_register_script(
871 871
             'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
873 873
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
874 874
             EVENT_ESPRESSO_VERSION,
875 875
             true
876 876
         );
877 877
         wp_register_script(
878 878
             'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
880 880
             ['ee-dialog'],
881 881
             EVENT_ESPRESSO_VERSION
882 882
         );
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 
920 920
         $this->_set_shortcodes();
921 921
 
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
923 923
             esc_html__(
924 924
                 'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925 925
                 'event_espresso'
@@ -931,14 +931,14 @@  discard block
 block discarded – undo
931 931
             'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932 932
             'event_espresso'
933 933
         );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
935 935
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936 936
             'event_espresso'
937 937
         );
938 938
 
939 939
         wp_register_script(
940 940
             'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
942 942
             ['jquery'],
943 943
             EVENT_ESPRESSO_VERSION
944 944
         );
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
     {
982 982
         wp_register_style(
983 983
             'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
985 985
             [],
986 986
             EVENT_ESPRESSO_VERSION
987 987
         );
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
             }
1068 1068
             $status_bulk_actions = $common_bulk_actions;
1069 1069
             // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1070
+            if ( ! empty($status_bulk_actions)) {
1071 1071
                 switch ($status) {
1072 1072
                     case EEM_Message::status_idle:
1073 1073
                     case EEM_Message::status_resend:
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
                 continue;
1097 1097
             }
1098 1098
 
1099
-            $this->_views[ strtolower($status) ] = [
1099
+            $this->_views[strtolower($status)] = [
1100 1100
                 'slug'        => strtolower($status),
1101 1101
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102 1102
                 'count'       => 0,
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
             if ($action_item === 'see_notifications_for') {
1145 1145
                 continue;
1146 1146
             }
1147
-            $action_items[ $action_item ] = [
1147
+            $action_items[$action_item] = [
1148 1148
                 'class' => $action_details['css_class'],
1149 1149
                 'desc'  => $action_details['label'],
1150 1150
             ];
@@ -1153,37 +1153,37 @@  discard block
 block discarded – undo
1153 1153
         /** @var array $status_items status legend setup */
1154 1154
         $status_items = [
1155 1155
             'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1156
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_sent,
1157 1157
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158 1158
             ],
1159 1159
             'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1160
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_idle,
1161 1161
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162 1162
             ],
1163 1163
             'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1164
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_failed,
1165 1165
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166 1166
             ],
1167 1167
             'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1168
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_messenger_executing,
1169 1169
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170 1170
             ],
1171 1171
             'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1172
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_resend,
1173 1173
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174 1174
             ],
1175 1175
             'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1176
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_incomplete,
1177 1177
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178 1178
             ],
1179 1179
             'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1180
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_retry,
1181 1181
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182 1182
             ],
1183 1183
         ];
1184 1184
         if (EEM_Message::debug()) {
1185 1185
             $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1186
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_debug_only,
1187 1187
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188 1188
             ];
1189 1189
         }
@@ -1198,11 +1198,11 @@  discard block
 block discarded – undo
1198 1198
     protected function _custom_mtps_preview()
1199 1199
     {
1200 1200
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1201
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1202
+                                                . ' alt="'.esc_attr__(
1203 1203
                                                     'Preview Custom Message Templates screenshot',
1204 1204
                                                     'event_espresso'
1205
-                                                ) . '" />';
1205
+                                                ).'" />';
1206 1206
         $this->_template_args['preview_text'] = '<strong>'
1207 1207
                                                 . esc_html__(
1208 1208
                                                     'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
@@ -1278,7 +1278,7 @@  discard block
 block discarded – undo
1278 1278
         $installed               = [];
1279 1279
 
1280 1280
         foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1281
+            $installed[$message_type->name] = $message_type;
1282 1282
         }
1283 1283
 
1284 1284
         return $installed;
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
         // we need to assemble the title from Various details
1405 1405
         $context_label = sprintf(
1406 1406
             esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1407
+            $c_config[$context]['label'],
1408 1408
             ucwords($c_label['label'])
1409 1409
         );
1410 1410
 
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
             $message_template_group->message_type()
1427 1427
         );
1428 1428
 
1429
-        if (! $template_field_structure) {
1429
+        if ( ! $template_field_structure) {
1430 1430
             $template_field_structure = false;
1431 1431
             $template_fields          = esc_html__(
1432 1432
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1440,21 +1440,21 @@  discard block
 block discarded – undo
1440 1440
 
1441 1441
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442 1442
         // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1443
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1444
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1445
+                unset($template_field_structure[$context][$reference_field]);
1446 1446
             }
1447 1447
         }
1448 1448
 
1449 1449
         // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1450
+        if ( ! empty($template_field_structure)) {
1451
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1452 1452
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453 1453
                 // the extra array and reset them.
1454 1454
                 if ($template_field === 'extra') {
1455 1455
                     $this->_template_args['is_extra_fields'] = true;
1456 1456
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1457
+                        $message_template = $message_templates[$context][$reference_field];
1458 1458
                         $content          = $message_template instanceof EE_Message_Template
1459 1459
                             ? $message_template->get('MTP_content')
1460 1460
                             : '';
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
                             $continue = false;
1464 1464
                             if (isset($extra_array['shortcodes_required'])) {
1465 1465
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1466
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1467 1467
                                         $continue = true;
1468 1468
                                     }
1469 1469
                                 }
@@ -1472,53 +1472,53 @@  discard block
 block discarded – undo
1472 1472
                                 }
1473 1473
                             }
1474 1474
 
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1475
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1476 1476
 
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1477
+                            $template_form_fields[$field_id]         = $extra_array;
1478
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1479 1479
                                                                          . $reference_field
1480 1480
                                                                          . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1481
+                                                                         . $extra_field.']';
1482
+                            $css_class = isset($extra_array['css_class'])
1483 1483
                                 ? $extra_array['css_class']
1484 1484
                                 : '';
1485 1485
 
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1486
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1487 1487
                                                                               && in_array($extra_field, $v_fields, true)
1488 1488
                                                                               && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1489
+                                                                                  is_array($validators[$extra_field])
1490
+                                                                                  && isset($validators[$extra_field]['msg'])
1491 1491
                                                                               )
1492
-                                ? 'validate-error ' . $css_class
1492
+                                ? 'validate-error '.$css_class
1493 1493
                                 : $css_class;
1494 1494
 
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1495
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
+                                                                          && isset($content[$extra_field])
1497
+                                ? $content[$extra_field]
1498 1498
                                 : '';
1499 1499
 
1500 1500
                             // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1501
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1502
+                                ? $validators[$extra_field]['value']
1503
+                                : $template_form_fields[$field_id]['value'];
1504 1504
 
1505 1505
 
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1506
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1507 1507
 
1508 1508
                             // shortcode selector
1509 1509
                             $field_name_to_use                                   = $extra_field === 'main'
1510 1510
                                 ? 'content'
1511 1511
                                 : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1512
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1513 1513
                                 $field_name_to_use,
1514 1514
                                 $field_id
1515 1515
                             );
1516 1516
                         }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1517
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1518
+                        $template_field_template_name_id = $reference_field.'-name';
1519 1519
 
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1520
+                        $template_form_fields[$template_field_MTP_id] = [
1521
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1522 1522
                             'label'      => null,
1523 1523
                             'input'      => 'hidden',
1524 1524
                             'type'       => 'int',
@@ -1530,8 +1530,8 @@  discard block
 block discarded – undo
1530 1530
                             'db-col'     => 'MTP_ID',
1531 1531
                         ];
1532 1532
 
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1533
+                        $template_form_fields[$template_field_template_name_id] = [
1534
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1535 1535
                             'label'      => null,
1536 1536
                             'input'      => 'hidden',
1537 1537
                             'type'       => 'string',
@@ -1545,38 +1545,38 @@  discard block
 block discarded – undo
1545 1545
                     }
1546 1546
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547 1547
                 } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1548
+                    $field_id                                   = $template_field.'-content';
1549
+                    $template_form_fields[$field_id]          = $field_setup_array;
1550
+                    $template_form_fields[$field_id]['name']  =
1551
+                        'MTP_template_fields['.$template_field.'][content]';
1552 1552
                     $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1553
+                        isset($message_templates[$context][$template_field])
1554
+                            ? $message_templates[$context][$template_field]
1555 1555
                             : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1556
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1557
+                                                                  && is_array($message_templates[$context])
1558 1558
                                                                   && $message_template instanceof EE_Message_Template
1559 1559
                         ? $message_template->get('MTP_content')
1560 1560
                         : '';
1561 1561
 
1562 1562
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1563
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1564
+                        ? $validators[$template_field]['value']
1565
+                        : $template_form_fields[$field_id]['value'];
1566 1566
 
1567 1567
 
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1568
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1569 1569
                     $css_class                                      = isset($field_setup_array['css_class'])
1570 1570
                         ? $field_setup_array['css_class']
1571 1571
                         : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1572
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1573 1573
                                                                       && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1574
+                                                                      && isset($validators[$template_field]['msg'])
1575
+                        ? 'validate-error '.$css_class
1576 1576
                         : $css_class;
1577 1577
 
1578 1578
                     // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1579
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1580 1580
                         $template_field,
1581 1581
                         $field_id
1582 1582
                     );
@@ -1584,12 +1584,12 @@  discard block
 block discarded – undo
1584 1584
 
1585 1585
                 // k took care of content field(s) now let's take care of others.
1586 1586
 
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1587
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1588
+                $template_field_field_template_name_id = $template_field.'-name';
1589 1589
 
1590 1590
                 // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1591
+                $template_form_fields[$template_field_MTP_id] = [
1592
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1593 1593
                     'label'      => null,
1594 1594
                     'input'      => 'hidden',
1595 1595
                     'type'       => 'int',
@@ -1601,8 +1601,8 @@  discard block
 block discarded – undo
1601 1601
                     'db-col'     => 'MTP_ID',
1602 1602
                 ];
1603 1603
 
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1604
+                $template_form_fields[$template_field_field_template_name_id] = [
1605
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1606 1606
                     'label'      => null,
1607 1607
                     'input'      => 'hidden',
1608 1608
                     'type'       => 'string',
@@ -1719,7 +1719,7 @@  discard block
 block discarded – undo
1719 1719
                 'format'     => '%d',
1720 1720
                 'db-col'     => 'MTP_deleted',
1721 1721
             ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1722
+            $sidebar_form_fields['ee-msg-author'] = [
1723 1723
                 'name'       => 'MTP_user_id',
1724 1724
                 'label'      => esc_html__('Author', 'event_espresso'),
1725 1725
                 'input'      => 'hidden',
@@ -1738,17 +1738,17 @@  discard block
 block discarded – undo
1738 1738
                 'value' => $action,
1739 1739
             ];
1740 1740
 
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1741
+            $sidebar_form_fields['ee-msg-id'] = [
1742 1742
                 'name'  => 'id',
1743 1743
                 'input' => 'hidden',
1744 1744
                 'type'  => 'int',
1745 1745
                 'value' => $GRP_ID,
1746 1746
             ];
1747 1747
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1748
+                'name'  => $action.'_nonce',
1749 1749
                 'input' => 'hidden',
1750 1750
                 'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1751
+                'value' => wp_create_nonce($action.'_nonce'),
1752 1752
             ];
1753 1753
 
1754 1754
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1779,7 +1779,7 @@  discard block
 block discarded – undo
1779 1779
         );
1780 1780
 
1781 1781
         // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1782
+        $preview_url = parent::add_query_args_and_nonce(
1783 1783
             [
1784 1784
                 'message_type' => $message_template_group->message_type(),
1785 1785
                 'messenger'    => $message_template_group->messenger(),
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
             ],
1791 1791
             $this->_admin_base_url
1792 1792
         );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1793
+        $preview_button = '<a href="'.$preview_url.'" class="button--secondary messages-preview-button">'
1794 1794
                           . esc_html__('Preview', 'event_espresso')
1795 1795
                           . '</a>';
1796 1796
 
@@ -1828,11 +1828,11 @@  discard block
 block discarded – undo
1828 1828
         $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1829 1829
         $this->_template_args['before_admin_page_content'] .= '</div>';
1830 1830
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1831
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1832 1832
 
1833 1833
         $this->_template_path = $this->_template_args['GRP_ID']
1834 1834
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1835
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1836 1836
 
1837 1837
         // send along EE_Message_Template_Group object for further template use.
1838 1838
         $this->_template_args['MTP'] = $message_template_group;
@@ -1888,7 +1888,7 @@  discard block
 block discarded – undo
1888 1888
     ) {
1889 1889
         $template_args = [
1890 1890
             'context'                   => $context,
1891
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1892 1892
             'is_active'                 => $message_template_group->is_context_active($context),
1893 1893
             'on_off_action'             => $message_template_group->is_context_active($context)
1894 1894
                 ? 'context-off'
@@ -1897,7 +1897,7 @@  discard block
 block discarded – undo
1897 1897
             'message_template_group_id' => $message_template_group->ID(),
1898 1898
         ];
1899 1899
         return EEH_Template::display_template(
1900
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1901 1901
             $template_args,
1902 1902
             true
1903 1903
         );
@@ -1954,7 +1954,7 @@  discard block
 block discarded – undo
1954 1954
         }
1955 1955
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1956 1956
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1957
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1958 1958
             EE_Error::add_error(
1959 1959
                 sprintf(
1960 1960
                     esc_html__(
@@ -2085,7 +2085,7 @@  discard block
 block discarded – undo
2085 2085
         $messenger    = $this->request->getRequestParam('msgr');
2086 2086
         $message_type = $this->request->getRequestParam('mt');
2087 2087
         // we need to make sure we've got the info we need.
2088
-        if (! ($GRP_ID && $messenger && $message_type)) {
2088
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2089 2089
             EE_Error::add_error(
2090 2090
                 esc_html__(
2091 2091
                     '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.',
@@ -2122,7 +2122,7 @@  discard block
 block discarded – undo
2122 2122
         }
2123 2123
 
2124 2124
         // any error messages?
2125
-        if (! $success) {
2125
+        if ( ! $success) {
2126 2126
             EE_Error::add_error(
2127 2127
                 esc_html__(
2128 2128
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2171,7 +2171,7 @@  discard block
 block discarded – undo
2171 2171
     {
2172 2172
         // first make sure we've got the necessary parameters
2173 2173
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2174
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2175 2175
             EE_Error::add_error(
2176 2176
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2177 2177
                 __FILE__,
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2198 2198
 
2199 2199
         // let's add a button to go back to the edit view
2200
-        $query_args             = [
2200
+        $query_args = [
2201 2201
             'id'      => $GRP_ID,
2202 2202
             'evt_id'  => $EVT_ID,
2203 2203
             'context' => $context,
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
         $preview_title = sprintf(
2219 2219
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2220 2220
             $active_messenger_label,
2221
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2222 2222
         );
2223 2223
         if (empty($preview)) {
2224 2224
             $this->noEventsErrorMessage();
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
         // setup display of preview.
2227 2227
         $this->_admin_page_title                    = $preview_title;
2228 2228
         $this->_template_args['admin_page_title']   = $preview_title;
2229
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2230 2230
         $this->_template_args['data']['force_json'] = true;
2231 2231
 
2232 2232
         return '';
@@ -2247,7 +2247,7 @@  discard block
 block discarded – undo
2247 2247
             ],
2248 2248
             admin_url('admin.php')
2249 2249
         );
2250
-        $message    = $test_send
2250
+        $message = $test_send
2251 2251
             ? esc_html__(
2252 2252
                 '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!',
2253 2253
                 'event_espresso'
@@ -2340,10 +2340,10 @@  discard block
 block discarded – undo
2340 2340
             // only include template packs that support this messenger and message type!
2341 2341
             $supports = $tp->get_supports();
2342 2342
             if (
2343
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2343
+                ! isset($supports[$this->_message_template_group->messenger()])
2344 2344
                 || ! in_array(
2345 2345
                     $this->_message_template_group->message_type(),
2346
-                    $supports[ $this->_message_template_group->messenger() ],
2346
+                    $supports[$this->_message_template_group->messenger()],
2347 2347
                     true
2348 2348
                 )
2349 2349
             ) {
@@ -2367,7 +2367,7 @@  discard block
 block discarded – undo
2367 2367
         }
2368 2368
 
2369 2369
         // setup variation select values for the currently selected template.
2370
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2371 2371
             $this->_message_template_group->messenger(),
2372 2372
             $this->_message_template_group->message_type()
2373 2373
         );
@@ -2381,12 +2381,12 @@  discard block
 block discarded – undo
2381 2381
 
2382 2382
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2383 2383
 
2384
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2385 2385
             'MTP_template_pack',
2386 2386
             $tp_select_values,
2387 2387
             $this->_message_template_group->get_template_pack_name()
2388 2388
         );
2389
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2390 2390
             'MTP_template_variation',
2391 2391
             $variations_select_values,
2392 2392
             $this->_message_template_group->get_template_pack_variation()
@@ -2396,7 +2396,7 @@  discard block
 block discarded – undo
2396 2396
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2397 2397
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2398 2398
 
2399
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2400 2400
 
2401 2401
         EEH_Template::display_template($template, $template_args);
2402 2402
     }
@@ -2422,33 +2422,33 @@  discard block
 block discarded – undo
2422 2422
         // first we need to see if there are any fields
2423 2423
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2424 2424
 
2425
-        if (! empty($fields)) {
2425
+        if ( ! empty($fields)) {
2426 2426
             // yup there be fields
2427 2427
             foreach ($fields as $field => $config) {
2428
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2429 2429
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2430 2430
                 $default  = isset($config['default']) ? $config['default'] : '';
2431 2431
                 $default  = isset($config['value']) ? $config['value'] : $default;
2432 2432
 
2433 2433
                 // if type is hidden and the value is empty
2434 2434
                 // something may have gone wrong so let's correct with the defaults
2435
-                $fix                = $config['input'] === 'hidden'
2436
-                                      && isset($existing[ $field ])
2437
-                                      && empty($existing[ $field ])
2435
+                $fix = $config['input'] === 'hidden'
2436
+                                      && isset($existing[$field])
2437
+                                      && empty($existing[$field])
2438 2438
                     ? $default
2439 2439
                     : '';
2440
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2441
-                    ? $existing[ $field ]
2440
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2441
+                    ? $existing[$field]
2442 2442
                     : $fix;
2443 2443
 
2444
-                $template_form_fields[ $field_id ] = [
2445
-                    'name'       => 'test_settings_fld[' . $field . ']',
2444
+                $template_form_fields[$field_id] = [
2445
+                    'name'       => 'test_settings_fld['.$field.']',
2446 2446
                     'label'      => $config['label'],
2447 2447
                     'input'      => $config['input'],
2448 2448
                     'type'       => $config['type'],
2449 2449
                     'required'   => $config['required'],
2450 2450
                     'validation' => $config['validation'],
2451
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2452 2452
                     'css_class'  => $config['css_class'],
2453 2453
                     'options'    => isset($config['options']) ? $config['options'] : [],
2454 2454
                     'default'    => $default,
@@ -2462,7 +2462,7 @@  discard block
 block discarded – undo
2462 2462
             : '';
2463 2463
 
2464 2464
         // print out $test_settings_fields
2465
-        if (! empty($test_settings_html)) {
2465
+        if ( ! empty($test_settings_html)) {
2466 2466
             $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2467 2467
             $test_settings_html .= 'name="test_button" value="';
2468 2468
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2508,7 +2508,7 @@  discard block
 block discarded – undo
2508 2508
         ];
2509 2509
 
2510 2510
         return EEH_Template::display_template(
2511
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2512 2512
             $template_args,
2513 2513
             true
2514 2514
         );
@@ -2534,7 +2534,7 @@  discard block
 block discarded – undo
2534 2534
         // $messenger = $this->_message_template_group->messenger_obj();
2535 2535
         // now let's set the content depending on the status of the shortcodes array
2536 2536
         if (empty($shortcodes)) {
2537
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2538 2538
             return;
2539 2539
         }
2540 2540
         ?>
@@ -2570,7 +2570,7 @@  discard block
 block discarded – undo
2570 2570
     {
2571 2571
 
2572 2572
         // no need to run this if the property is already set
2573
-        if (! empty($this->_shortcodes)) {
2573
+        if ( ! empty($this->_shortcodes)) {
2574 2574
             return;
2575 2575
         }
2576 2576
 
@@ -2625,7 +2625,7 @@  discard block
 block discarded – undo
2625 2625
     protected function _set_message_template_group()
2626 2626
     {
2627 2627
         // get out if this is already set.
2628
-        if (! empty($this->_message_template_group)) {
2628
+        if ( ! empty($this->_message_template_group)) {
2629 2629
             return;
2630 2630
         }
2631 2631
 
@@ -2671,8 +2671,8 @@  discard block
 block discarded – undo
2671 2671
                     <?php
2672 2672
                 }
2673 2673
                 // setup nonce_url
2674
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2675
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2674
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2675
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2676 2676
                 ?>
2677 2677
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2678 2678
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2685,7 +2685,7 @@  discard block
 block discarded – undo
2685 2685
                             $checked = ($context === $args['context']) ? 'selected' : '';
2686 2686
                             ?>
2687 2687
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2688
-                                <?php echo esc_html($context_details[ $context ]['label']); ?>
2688
+                                <?php echo esc_html($context_details[$context]['label']); ?>
2689 2689
                             </option>
2690 2690
                         <?php endforeach;
2691 2691
                     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
 
@@ -3452,8 +3452,8 @@  discard block
 block discarded – undo
3452 3452
 
3453 3453
         foreach ($messengers as $messenger) {
3454 3454
             $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3455
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3456
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+            $class = 'ee-messenger-'.sanitize_key($messenger->label['singular']);
3456
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3457 3457
                 'label' => ucwords($messenger->label['singular']),
3458 3458
                 'class' => $active ? "{$class} messenger-active" : $class,
3459 3459
                 'href'  => $messenger->name,
@@ -3471,7 +3471,7 @@  discard block
 block discarded – undo
3471 3471
             foreach ($message_types as $message_type) {
3472 3472
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3473 3473
                 // it shouldn't show in either the inactive OR active metabox.
3474
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3474
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3475 3475
                     continue;
3476 3476
                 }
3477 3477
 
@@ -3482,12 +3482,12 @@  discard block
 block discarded – undo
3482 3482
                     ? 'active'
3483 3483
                     : 'inactive';
3484 3484
 
3485
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3485
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3486 3486
                     'label'    => ucwords($message_type->label['singular']),
3487
-                    'class'    => 'message-type-' . $a_or_i,
3488
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3489
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3490
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3487
+                    'class'    => 'message-type-'.$a_or_i,
3488
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3489
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3490
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3491 3491
                     'title'    => $a_or_i === 'active'
3492 3492
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3493 3493
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3518,25 +3518,25 @@  discard block
 block discarded – undo
3518 3518
         $fields                                         = $message_type->get_admin_settings_fields();
3519 3519
         $settings_template_args['template_form_fields'] = '';
3520 3520
 
3521
-        if (! empty($fields) && $active) {
3521
+        if ( ! empty($fields) && $active) {
3522 3522
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3523 3523
             foreach ($fields as $fldname => $fldprops) {
3524
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3525
-                $template_form_field[ $field_id ] = [
3526
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3524
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3525
+                $template_form_field[$field_id] = [
3526
+                    'name'       => 'message_type_settings['.$fldname.']',
3527 3527
                     'label'      => $fldprops['label'],
3528 3528
                     'input'      => $fldprops['field_type'],
3529 3529
                     'type'       => $fldprops['value_type'],
3530 3530
                     'required'   => $fldprops['required'],
3531 3531
                     'validation' => $fldprops['validation'],
3532
-                    'value'      => isset($existing_settings[ $fldname ])
3533
-                        ? $existing_settings[ $fldname ]
3532
+                    'value'      => isset($existing_settings[$fldname])
3533
+                        ? $existing_settings[$fldname]
3534 3534
                         : $fldprops['default'],
3535 3535
                     'options'    => isset($fldprops['options'])
3536 3536
                         ? $fldprops['options']
3537 3537
                         : [],
3538
-                    'default'    => isset($existing_settings[ $fldname ])
3539
-                        ? $existing_settings[ $fldname ]
3538
+                    'default'    => isset($existing_settings[$fldname])
3539
+                        ? $existing_settings[$fldname]
3540 3540
                         : $fldprops['default'],
3541 3541
                     'css_class'  => 'no-drag',
3542 3542
                     'format'     => $fldprops['format'],
@@ -3556,15 +3556,15 @@  discard block
 block discarded – undo
3556 3556
         $settings_template_args['description'] = $message_type->description;
3557 3557
         // we also need some hidden fields
3558 3558
         $hidden_fields = [
3559
-            'message_type_settings[messenger]' . $message_type->name    => [
3559
+            'message_type_settings[messenger]'.$message_type->name    => [
3560 3560
                 'type'  => 'hidden',
3561 3561
                 'value' => $messenger->name,
3562 3562
             ],
3563
-            'message_type_settings[message_type]' . $message_type->name => [
3563
+            'message_type_settings[message_type]'.$message_type->name => [
3564 3564
                 'type'  => 'hidden',
3565 3565
                 'value' => $message_type->name,
3566 3566
             ],
3567
-            'type' . $message_type->name                                => [
3567
+            'type'.$message_type->name                                => [
3568 3568
                 'type'  => 'hidden',
3569 3569
                 'value' => 'message_type',
3570 3570
             ],
@@ -3574,12 +3574,12 @@  discard block
 block discarded – undo
3574 3574
             $hidden_fields,
3575 3575
             'array'
3576 3576
         );
3577
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3577
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3578 3578
             ? ' hidden'
3579 3579
             : '';
3580 3580
 
3581 3581
 
3582
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3582
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3583 3583
         return EEH_Template::display_template($template, $settings_template_args, true);
3584 3584
     }
3585 3585
 
@@ -3607,21 +3607,21 @@  discard block
 block discarded – undo
3607 3607
 
3608 3608
                 // messenger meta boxes
3609 3609
                 $active         = $selected_messenger === $messenger;
3610
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3611
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3610
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3611
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3612 3612
                     : '';
3613 3613
 
3614
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3614
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3615 3615
                     esc_html__('%s Settings', 'event_espresso'),
3616 3616
                     $tab_array['label']
3617 3617
                 );
3618 3618
 
3619
-                $m_template_args[ $messenger . '_a_box' ] = [
3619
+                $m_template_args[$messenger.'_a_box'] = [
3620 3620
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3621 3621
                     'inactive_message_types' => isset(
3622
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3622
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3623 3623
                     )
3624
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3624
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3625 3625
                         : '',
3626 3626
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3627 3627
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3633,13 +3633,13 @@  discard block
 block discarded – undo
3633 3633
                 // message type meta boxes
3634 3634
                 // (which is really just the inactive container for each messenger
3635 3635
                 // showing inactive message types for that messenger)
3636
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3637
-                $mt_template_args[ $messenger . '_i_box' ] = [
3636
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3637
+                $mt_template_args[$messenger.'_i_box'] = [
3638 3638
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3639 3639
                     'inactive_message_types' => isset(
3640
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3640
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3641 3641
                     )
3642
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3642
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3643 3643
                         : '',
3644 3644
                     'hidden'                 => $active ? '' : ' hidden',
3645 3645
                     'hide_on_message'        => $hide_on_message,
@@ -3652,14 +3652,14 @@  discard block
 block discarded – undo
3652 3652
 
3653 3653
 
3654 3654
         // register messenger metaboxes
3655
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3655
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3656 3656
         foreach ($m_boxes as $box => $label) {
3657
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3657
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3658 3658
             $msgr          = str_replace('_a_box', '', $box);
3659 3659
             $this->addMetaBox(
3660
-                'espresso_' . $msgr . '_settings',
3660
+                'espresso_'.$msgr.'_settings',
3661 3661
                 $label,
3662
-                function ($post, $metabox) {
3662
+                function($post, $metabox) {
3663 3663
                     EEH_Template::display_template(
3664 3664
                         $metabox['args']['template_path'],
3665 3665
                         $metabox['args']['template_args']
@@ -3673,17 +3673,17 @@  discard block
 block discarded – undo
3673 3673
         }
3674 3674
 
3675 3675
         // register message type metaboxes
3676
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3676
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3677 3677
         foreach ($mt_boxes as $box => $label) {
3678 3678
             $callback_args = [
3679 3679
                 'template_path' => $mt_template_path,
3680
-                'template_args' => $mt_template_args[ $box ],
3680
+                'template_args' => $mt_template_args[$box],
3681 3681
             ];
3682
-            $mt            = str_replace('_i_box', '', $box);
3682
+            $mt = str_replace('_i_box', '', $box);
3683 3683
             $this->addMetaBox(
3684
-                'espresso_' . $mt . '_inactive_mts',
3684
+                'espresso_'.$mt.'_inactive_mts',
3685 3685
                 $label,
3686
-                function ($post, $metabox) {
3686
+                function($post, $metabox) {
3687 3687
                     EEH_Template::display_template(
3688 3688
                         $metabox['args']['template_path'],
3689 3689
                         $metabox['args']['template_args']
@@ -3830,7 +3830,7 @@  discard block
 block discarded – undo
3830 3830
             if ($form->is_valid()) {
3831 3831
                 $valid_data = $form->valid_data();
3832 3832
                 foreach ($valid_data as $property => $value) {
3833
-                    $setter = 'set_' . $property;
3833
+                    $setter = 'set_'.$property;
3834 3834
                     if (method_exists($network_config, $setter)) {
3835 3835
                         $network_config->{$setter}($value);
3836 3836
                     } elseif (
@@ -3866,7 +3866,7 @@  discard block
 block discarded – undo
3866 3866
     protected function _get_mt_tabs($tab_array)
3867 3867
     {
3868 3868
         $tab_array = (array) $tab_array;
3869
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3869
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3870 3870
         $tabs      = '';
3871 3871
 
3872 3872
         foreach ($tab_array as $tab) {
@@ -3894,20 +3894,20 @@  discard block
 block discarded – undo
3894 3894
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3895 3895
 
3896 3896
 
3897
-        if (! empty($fields)) {
3897
+        if ( ! empty($fields)) {
3898 3898
             $existing_settings = $messenger->get_existing_admin_settings();
3899 3899
 
3900 3900
             foreach ($fields as $fldname => $fldprops) {
3901
-                $field_id                         = $messenger->name . '-' . $fldname;
3902
-                $template_form_field[ $field_id ] = [
3903
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3901
+                $field_id                         = $messenger->name.'-'.$fldname;
3902
+                $template_form_field[$field_id] = [
3903
+                    'name'       => 'messenger_settings['.$field_id.']',
3904 3904
                     'label'      => $fldprops['label'],
3905 3905
                     'input'      => $fldprops['field_type'],
3906 3906
                     'type'       => $fldprops['value_type'],
3907 3907
                     'required'   => $fldprops['required'],
3908 3908
                     'validation' => $fldprops['validation'],
3909
-                    'value'      => isset($existing_settings[ $field_id ])
3910
-                        ? $existing_settings[ $field_id ]
3909
+                    'value'      => isset($existing_settings[$field_id])
3910
+                        ? $existing_settings[$field_id]
3911 3911
                         : $fldprops['default'],
3912 3912
                     'css_class'  => '',
3913 3913
                     'format'     => $fldprops['format'],
@@ -3922,20 +3922,20 @@  discard block
 block discarded – undo
3922 3922
 
3923 3923
         // we also need some hidden fields
3924 3924
         $settings_template_args['hidden_fields'] = [
3925
-            'messenger_settings[messenger]' . $messenger->name => [
3925
+            'messenger_settings[messenger]'.$messenger->name => [
3926 3926
                 'type'  => 'hidden',
3927 3927
                 'value' => $messenger->name,
3928 3928
             ],
3929
-            'type' . $messenger->name                          => [
3929
+            'type'.$messenger->name                          => [
3930 3930
                 'type'  => 'hidden',
3931 3931
                 'value' => 'messenger',
3932 3932
             ],
3933 3933
         ];
3934 3934
 
3935 3935
         // make sure any active message types that are existing are included in the hidden fields
3936
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3937
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3938
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3937
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3938
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3939 3939
                     'type'  => 'hidden',
3940 3940
                     'value' => $mt,
3941 3941
                 ];
@@ -3945,7 +3945,7 @@  discard block
 block discarded – undo
3945 3945
             $settings_template_args['hidden_fields'],
3946 3946
             'array'
3947 3947
         );
3948
-        $active                                  =
3948
+        $active =
3949 3949
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3950 3950
 
3951 3951
         $settings_template_args['messenger']           = $messenger->name;
@@ -3965,9 +3965,9 @@  discard block
 block discarded – undo
3965 3965
 
3966 3966
 
3967 3967
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3968
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3968
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3969 3969
         $settings_template_args['on_off_status'] = $active;
3970
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3970
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3971 3971
         return EEH_Template::display_template(
3972 3972
             $template,
3973 3973
             $settings_template_args,
@@ -3992,7 +3992,7 @@  discard block
 block discarded – undo
3992 3992
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3993 3993
         // let's check that we have required data
3994 3994
 
3995
-        if (! $this->_active_messenger_name) {
3995
+        if ( ! $this->_active_messenger_name) {
3996 3996
             EE_Error::add_error(
3997 3997
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3998 3998
                 __FILE__,
@@ -4010,7 +4010,7 @@  discard block
 block discarded – undo
4010 4010
 
4011 4011
 
4012 4012
         $status = $this->request->getRequestParam('status');
4013
-        if (! $status) {
4013
+        if ( ! $status) {
4014 4014
             EE_Error::add_error(
4015 4015
                 esc_html__(
4016 4016
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4067,7 +4067,7 @@  discard block
 block discarded – undo
4067 4067
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4068 4068
 
4069 4069
         // let's make sure we have the necessary data
4070
-        if (! $this->_active_message_type_name) {
4070
+        if ( ! $this->_active_message_type_name) {
4071 4071
             EE_Error::add_error(
4072 4072
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4073 4073
                 __FILE__,
@@ -4077,7 +4077,7 @@  discard block
 block discarded – undo
4077 4077
             $success = false;
4078 4078
         }
4079 4079
 
4080
-        if (! $this->_active_messenger_name) {
4080
+        if ( ! $this->_active_messenger_name) {
4081 4081
             EE_Error::add_error(
4082 4082
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4083 4083
                 __FILE__,
@@ -4088,7 +4088,7 @@  discard block
 block discarded – undo
4088 4088
         }
4089 4089
 
4090 4090
         $status = $this->request->getRequestParam('status');
4091
-        if (! $status) {
4091
+        if ( ! $status) {
4092 4092
             EE_Error::add_error(
4093 4093
                 esc_html__(
4094 4094
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4300,7 +4300,7 @@  discard block
 block discarded – undo
4300 4300
         EE_Message_Type $message_type = null
4301 4301
     ) {
4302 4302
         // if $messenger isn't a valid messenger object then get out.
4303
-        if (! $messenger instanceof EE_Messenger) {
4303
+        if ( ! $messenger instanceof EE_Messenger) {
4304 4304
             EE_Error::add_error(
4305 4305
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4306 4306
                 __FILE__,
@@ -4354,7 +4354,7 @@  discard block
 block discarded – undo
4354 4354
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4355 4355
             // in which case we just give a success message for the messenger being successfully activated.
4356 4356
         } else {
4357
-            if (! $messenger->get_default_message_types()) {
4357
+            if ( ! $messenger->get_default_message_types()) {
4358 4358
                 // messenger doesn't have any default message types so still a success.
4359 4359
                 EE_Error::add_success(
4360 4360
                     sprintf(
@@ -4410,7 +4410,7 @@  discard block
 block discarded – undo
4410 4410
         EE_Error::overwrite_success();
4411 4411
 
4412 4412
         // if $messenger isn't a valid messenger object then get out.
4413
-        if (! $messenger instanceof EE_Messenger) {
4413
+        if ( ! $messenger instanceof EE_Messenger) {
4414 4414
             EE_Error::add_error(
4415 4415
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4416 4416
                 __FILE__,
@@ -4480,7 +4480,7 @@  discard block
 block discarded – undo
4480 4480
      */
4481 4481
     public function update_mt_form()
4482 4482
     {
4483
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4483
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4484 4484
             EE_Error::add_error(
4485 4485
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4486 4486
                 __FILE__,
@@ -4491,7 +4491,7 @@  discard block
 block discarded – undo
4491 4491
         }
4492 4492
 
4493 4493
         $message_types = $this->get_installed_message_types();
4494
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4494
+        $message_type  = $message_types[$this->_active_message_type_name];
4495 4495
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4496 4496
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4497 4497
 
@@ -4510,7 +4510,7 @@  discard block
 block discarded – undo
4510 4510
     public function save_settings()
4511 4511
     {
4512 4512
         $type = $this->request->getRequestParam('type');
4513
-        if (! $type) {
4513
+        if ( ! $type) {
4514 4514
             EE_Error::add_error(
4515 4515
                 esc_html__(
4516 4516
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
admin_pages/payments/templates/payment_log_details.template.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -35,14 +35,14 @@  discard block
 block discarded – undo
35 35
                 </th>
36 36
                 <td>
37 37
                     <?php
38
-                    if ($payment_log->object() instanceof EE_Transaction) {
39
-                        esc_html_e('Unknown', 'event_espresso');
40
-                    } else {
41
-                        echo ($payment_method
42
-                            ? esc_html($payment_method->admin_name())
43
-                            : esc_html__("No Longer Exists", 'event_espresso'));
44
-                    }
45
-                    ?>
38
+					if ($payment_log->object() instanceof EE_Transaction) {
39
+						esc_html_e('Unknown', 'event_espresso');
40
+					} else {
41
+						echo ($payment_method
42
+							? esc_html($payment_method->admin_name())
43
+							: esc_html__("No Longer Exists", 'event_espresso'));
44
+					}
45
+					?>
46 46
                 </td>
47 47
             </tr>
48 48
             <tr>
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
                 </th>
54 54
                 <td>
55 55
                     <?php echo ($$transaction instanceof EE_Transaction
56
-                        ? absint($transaction->ID())
57
-                        : esc_html__('Could not be determined', 'event_espresso')); ?>
56
+						? absint($transaction->ID())
57
+						: esc_html__('Could not be determined', 'event_espresso')); ?>
58 58
                 </td>
59 59
             </tr>
60 60
             <tr>
Please login to merge, or discard this patch.
admin_pages/payments/Payments_Admin_Page.core.php 2 patches
Indentation   +1202 added lines, -1202 removed lines patch added patch discarded remove patch
@@ -16,1206 +16,1206 @@
 block discarded – undo
16 16
  */
17 17
 class Payments_Admin_Page extends EE_Admin_Page
18 18
 {
19
-    /**
20
-     * Variables used for when we're re-sorting the logs results,
21
-     * in case we needed to do two queries, and we need to resort
22
-     *
23
-     * @var string
24
-     */
25
-    private $_sort_logs_again_direction;
26
-
27
-
28
-    /**
29
-     * @Constructor
30
-     * @access public
31
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
32
-     * @throws EE_Error
33
-     * @throws InvalidArgumentException
34
-     * @throws InvalidDataTypeException
35
-     * @throws InvalidInterfaceException
36
-     * @throws ReflectionException
37
-     */
38
-    public function __construct($routing = true)
39
-    {
40
-        parent::__construct($routing);
41
-    }
42
-
43
-
44
-    protected function _init_page_props()
45
-    {
46
-        $this->page_slug = EE_PAYMENTS_PG_SLUG;
47
-        $this->page_label = esc_html__('Payment Methods', 'event_espresso');
48
-        $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
49
-        $this->_admin_base_path = EE_PAYMENTS_ADMIN;
50
-    }
51
-
52
-
53
-    protected function _ajax_hooks()
54
-    {
55
-        // todo: all hooks for ajax goes here.
56
-    }
57
-
58
-
59
-    protected function _define_page_props()
60
-    {
61
-        $this->_admin_page_title = $this->page_label;
62
-        $this->_labels = array(
63
-            'publishbox' => esc_html__('Update Settings', 'event_espresso'),
64
-        );
65
-    }
66
-
67
-
68
-    protected function _set_page_routes()
69
-    {
70
-        /**
71
-         * note that with payment method capabilities, although we've implemented
72
-         * capability mapping which will be used for accessing payment methods owned by
73
-         * other users.  This is not fully implemented yet in the payment method ui.
74
-         * Currently, only the "plural" caps are in active use.
75
-         * When cap mapping is implemented, some routes will need to use the singular form of
76
-         * capability method and also include the $id of the payment method for the route.
77
-         **/
78
-        $this->_page_routes = array(
79
-            'default'                   => array(
80
-                'func'       => '_payment_methods_list',
81
-                'capability' => 'ee_edit_payment_methods',
82
-            ),
83
-            'payment_settings'          => array(
84
-                'func'       => '_payment_settings',
85
-                'capability' => 'ee_manage_gateways',
86
-            ),
87
-            'activate_payment_method'   => array(
88
-                'func'       => '_activate_payment_method',
89
-                'noheader'   => true,
90
-                'capability' => 'ee_edit_payment_methods',
91
-            ),
92
-            'deactivate_payment_method' => array(
93
-                'func'       => '_deactivate_payment_method',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_delete_payment_methods',
96
-            ),
97
-            'update_payment_method'     => array(
98
-                'func'               => '_update_payment_method',
99
-                'noheader'           => true,
100
-                'headers_sent_route' => 'default',
101
-                'capability'         => 'ee_edit_payment_methods',
102
-            ),
103
-            'update_payment_settings'   => array(
104
-                'func'       => '_update_payment_settings',
105
-                'noheader'   => true,
106
-                'capability' => 'ee_manage_gateways',
107
-            ),
108
-            'payment_log'               => array(
109
-                'func'       => '_payment_log_overview_list_table',
110
-                'capability' => 'ee_read_payment_methods',
111
-            ),
112
-            'payment_log_details'       => array(
113
-                'func'       => '_payment_log_details',
114
-                'capability' => 'ee_read_payment_methods',
115
-            ),
116
-        );
117
-    }
118
-
119
-
120
-    /**
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    protected function _set_page_config()
125
-    {
126
-        $payment_method_list_config = array(
127
-            'nav'           => array(
128
-                'label' => esc_html__('Payment Methods', 'event_espresso'),
129
-                'order' => 10,
130
-            ),
131
-            'metaboxes'     => $this->_default_espresso_metaboxes,
132
-            'help_tabs'     => array_merge(
133
-                array(
134
-                    'payment_methods_overview_help_tab' => array(
135
-                        'title'    => esc_html__('Payment Methods Overview', 'event_espresso'),
136
-                        'filename' => 'payment_methods_overview',
137
-                    ),
138
-                ),
139
-                $this->_add_payment_method_help_tabs()
140
-            ),
141
-            'require_nonce' => false,
142
-        );
143
-        $this->_page_config = array(
144
-            'default'          => $payment_method_list_config,
145
-            'payment_settings' => array(
146
-                'nav'           => array(
147
-                    'label' => esc_html__('Settings', 'event_espresso'),
148
-                    'order' => 20,
149
-                ),
150
-                'help_tabs'     => array(
151
-                    'payment_methods_settings_help_tab' => array(
152
-                        'title'    => esc_html__('Payment Method Settings', 'event_espresso'),
153
-                        'filename' => 'payment_methods_settings',
154
-                    ),
155
-                ),
156
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
157
-                'require_nonce' => false,
158
-            ),
159
-            'payment_log'      => array(
160
-                'nav'           => array(
161
-                    'label' => esc_html__("Logs", 'event_espresso'),
162
-                    'order' => 30,
163
-                ),
164
-                'list_table'    => 'Payment_Log_Admin_List_Table',
165
-                'metaboxes'     => $this->_default_espresso_metaboxes,
166
-                'require_nonce' => false,
167
-            ),
168
-        );
169
-    }
170
-
171
-
172
-    /**
173
-     * @return array
174
-     * @throws DomainException
175
-     * @throws EE_Error
176
-     * @throws InvalidArgumentException
177
-     * @throws InvalidDataTypeException
178
-     * @throws InvalidInterfaceException
179
-     * @throws ReflectionException
180
-     */
181
-    protected function _add_payment_method_help_tabs()
182
-    {
183
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
184
-        $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
185
-        $all_pmt_help_tabs_config = array();
186
-        foreach ($payment_method_types as $payment_method_type) {
187
-            if (
188
-                ! EE_Registry::instance()->CAP->current_user_can(
189
-                    $payment_method_type->cap_name(),
190
-                    'specific_payment_method_type_access'
191
-                )
192
-            ) {
193
-                continue;
194
-            }
195
-            foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
196
-                $template_args = isset($config['template_args']) ? $config['template_args'] : array();
197
-                $template_args['admin_page_obj'] = $this;
198
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
199
-                    'title'   => $config['title'],
200
-                    'content' => EEH_Template::display_template(
201
-                        $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
202
-                        $template_args,
203
-                        true
204
-                    ),
205
-                );
206
-            }
207
-        }
208
-        return $all_pmt_help_tabs_config;
209
-    }
210
-
211
-
212
-    // none of the below group are currently used for Gateway Settings
213
-    protected function _add_screen_options()
214
-    {
215
-    }
216
-
217
-
218
-    protected function _add_feature_pointers()
219
-    {
220
-    }
221
-
222
-
223
-    public function admin_init()
224
-    {
225
-    }
226
-
227
-
228
-    public function admin_notices()
229
-    {
230
-    }
231
-
232
-
233
-    public function admin_footer_scripts()
234
-    {
235
-    }
236
-
237
-
238
-    public function load_scripts_styles()
239
-    {
240
-        // styles
241
-        wp_enqueue_style('espresso-ui-theme');
242
-        wp_register_style(
243
-            'espresso_payments',
244
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
245
-            [],
246
-            EVENT_ESPRESSO_VERSION
247
-        );
248
-        // scripts
249
-        wp_enqueue_script('ee_admin_js');
250
-        wp_enqueue_script('ee-text-links');
251
-        wp_enqueue_script(
252
-            'espresso_payments',
253
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
254
-            ['ee-datepicker'],
255
-            EVENT_ESPRESSO_VERSION,
256
-            true
257
-        );
258
-    }
259
-
260
-
261
-    public function load_scripts_styles_default()
262
-    {
263
-        wp_enqueue_style('espresso_payments');
264
-        wp_enqueue_style('ee-text-links');
265
-    }
266
-
267
-
268
-    public function load_scripts_styles_payment_log_details()
269
-    {
270
-        wp_enqueue_style('espresso_payments');
271
-    }
272
-
273
-
274
-    /**
275
-     * @throws EE_Error
276
-     * @throws ReflectionException
277
-     */
278
-    protected function _payment_methods_list()
279
-    {
280
-        /**
281
-         * first let's ensure payment methods have been set up.
282
-         * We do this here because when people activate a payment method for the first time (as an addon),
283
-         * it may not set up its capabilities or get registered correctly due to the loading process.
284
-         * However, people MUST set up the details for the payment method,
285
-         * so it's safe to do a recheck here.
286
-         */
287
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
288
-        EEM_Payment_Method::instance()->verify_button_urls();
289
-        // set up tabs, one for each payment method type
290
-        $tabs = array();
291
-        $payment_methods = array();
292
-        foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
293
-            // we don't want to show admin-only PMTs for now
294
-            if ($pmt_obj instanceof EE_PMT_Admin_Only) {
295
-                continue;
296
-            }
297
-            // check access
298
-            if (
299
-                ! EE_Registry::instance()->CAP->current_user_can(
300
-                    $pmt_obj->cap_name(),
301
-                    'specific_payment_method_type_access'
302
-                )
303
-            ) {
304
-                continue;
305
-            }
306
-            // check for any active pms of that type
307
-            $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
308
-            if (! $payment_method instanceof EE_Payment_Method) {
309
-                $payment_method = EE_Payment_Method::new_instance(
310
-                    array(
311
-                        'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
312
-                        'PMD_type'       => $pmt_obj->system_name(),
313
-                        'PMD_name'       => $pmt_obj->pretty_name(),
314
-                        'PMD_admin_name' => $pmt_obj->pretty_name(),
315
-                    )
316
-                );
317
-            }
318
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
319
-        }
320
-        $payment_methods = apply_filters(
321
-            'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
322
-            $payment_methods
323
-        );
324
-        foreach ($payment_methods as $payment_method) {
325
-            if ($payment_method instanceof EE_Payment_Method) {
326
-                $this->addMetaBox(
327
-                    // html id
328
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
329
-                    // title
330
-                    sprintf(esc_html__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
331
-                    // callback
332
-                    array($this, 'payment_method_settings_meta_box'),
333
-                    // post type
334
-                    null,
335
-                    // context
336
-                    'normal',
337
-                    // priority
338
-                    'default',
339
-                    // callback args
340
-                    array('payment_method' => $payment_method)
341
-                );
342
-                // setup for tabbed content
343
-                $tabs[ $payment_method->slug() ] = array(
344
-                    'label' => $payment_method->admin_name(),
345
-                    'class' => $payment_method->active() ? 'gateway-active' : '',
346
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
347
-                    'title' => esc_html__('Modify this Payment Method', 'event_espresso'),
348
-                    'slug'  => $payment_method->slug(),
349
-                    'icon'  => $payment_method->active()
350
-                        ? '<span class="dashicons dashicons-yes-alt"></span>'
351
-                        : '<span class="dashicons dashicons-remove"></span>',
352
-                );
353
-            }
354
-        }
355
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
356
-            $tabs,
357
-            'payment_method_links',
358
-            '',
359
-            $this->_get_active_payment_method_slug()
360
-        );
361
-        $this->display_admin_page_with_sidebar();
362
-    }
363
-
364
-
365
-    /**
366
-     *   _get_active_payment_method_slug
367
-     *
368
-     * @return string
369
-     * @throws EE_Error
370
-     */
371
-    protected function _get_active_payment_method_slug()
372
-    {
373
-        $payment_method_slug = false;
374
-        // decide which payment method tab to open first, as dictated by the request's 'payment_method'
375
-        if (isset($this->_req_data['payment_method'])) {
376
-            // if they provided the current payment method, use it
377
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
378
-        }
379
-        /** @var EE_Payment_Method $payment_method */
380
-        $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
381
-        // if that didn't work or wasn't provided, find another way to select the current pm
382
-        if (! $this->_verify_payment_method($payment_method)) {
383
-            // like, looking for an active one
384
-            $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
385
-            // test that one as well
386
-            if ($this->_verify_payment_method($payment_method)) {
387
-                $payment_method_slug = $payment_method->slug();
388
-            } else {
389
-                $payment_method_slug = 'paypal_standard';
390
-            }
391
-        }
392
-        return $payment_method_slug;
393
-    }
394
-
395
-
396
-    /**
397
-     *    payment_method_settings_meta_box
398
-     *    returns TRUE if the passed payment method is properly constructed and the logged-in user has the correct
399
-     *    capabilities to access it
400
-     *
401
-     * @param EE_Payment_Method $payment_method
402
-     * @return boolean
403
-     * @throws EE_Error
404
-     */
405
-    protected function _verify_payment_method($payment_method)
406
-    {
407
-        if (
408
-            $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
409
-            && EE_Registry::instance()->CAP->current_user_can(
410
-                $payment_method->type_obj()->cap_name(),
411
-                'specific_payment_method_type_access'
412
-            )
413
-        ) {
414
-            return true;
415
-        }
416
-        return false;
417
-    }
418
-
419
-
420
-    /**
421
-     *    payment_method_settings_meta_box
422
-     *
423
-     * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
424
-     * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
425
-     *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
426
-     * @return void
427
-     * @throws EE_Error
428
-     * @throws ReflectionException
429
-     */
430
-    public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
431
-    {
432
-        $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
433
-            ? $metabox['args']['payment_method'] : null;
434
-        if (! $payment_method instanceof EE_Payment_Method) {
435
-            throw new EE_Error(
436
-                esc_html__(
437
-                    'Payment method metabox setup incorrectly. No Payment method object was supplied',
438
-                    'event_espresso'
439
-                )
440
-            );
441
-        }
442
-        $payment_method_scopes = $payment_method->active();
443
-        // if the payment method really exists show its form, otherwise the activation template
444
-        if ($payment_method->ID() && ! empty($payment_method_scopes)) {
445
-            $form = $this->_generate_payment_method_settings_form($payment_method);
446
-            if ($form->form_data_present_in($this->_req_data)) {
447
-                $form->receive_form_submission($this->_req_data);
448
-            }
449
-            echo wp_kses($form->form_open() . $form->get_html_and_js() . $form->form_close(), AllowedTags::getWithFormTags());
450
-        } else {
451
-            echo wp_kses($this->_activate_payment_method_button($payment_method)->get_html_and_js(), AllowedTags::getWithFormTags());
452
-        }
453
-    }
454
-
455
-
456
-    /**
457
-     * Gets the form for all the settings related to this payment method type
458
-     *
459
-     * @access protected
460
-     * @param EE_Payment_Method $payment_method
461
-     * @return EE_Form_Section_Proper
462
-     * @throws EE_Error
463
-     */
464
-    protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method = null)
465
-    {
466
-        if (! $payment_method instanceof EE_Payment_Method) {
467
-            return new EE_Form_Section_Proper();
468
-        }
469
-        return new EE_Form_Section_Proper(
470
-            array(
471
-                'name'            => $payment_method->slug() . '_settings_form',
472
-                'html_id'         => $payment_method->slug() . '_settings_form',
473
-                'action'          => EE_Admin_Page::add_query_args_and_nonce(
474
-                    array(
475
-                        'action'         => 'update_payment_method',
476
-                        'payment_method' => $payment_method->slug(),
477
-                    ),
478
-                    EE_PAYMENTS_ADMIN_URL
479
-                ),
480
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
481
-                'subsections'     => apply_filters(
482
-                    'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
483
-                    array(
484
-                        'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
485
-                        'currency_support'        => $this->_currency_support($payment_method),
486
-                        'payment_method_settings' => $this->_payment_method_settings($payment_method),
487
-                        'update'                  => $this->_update_payment_method_button($payment_method),
488
-                        'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
489
-                        'fine_print'              => $this->_fine_print(),
490
-                    ),
491
-                    $payment_method
492
-                ),
493
-            )
494
-        );
495
-    }
496
-
497
-
498
-    /**
499
-     * _pci_dss_compliance
500
-     *
501
-     * @access protected
502
-     * @param EE_Payment_Method $payment_method
503
-     * @return EE_Form_Section_HTML
504
-     * @throws EE_Error
505
-     */
506
-    protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
507
-    {
508
-        if ($payment_method->type_obj()->requires_https()) {
509
-            return new EE_Form_Section_HTML(
510
-                EEH_HTML::table(
511
-                    EEH_HTML::tr(
512
-                        EEH_HTML::th(
513
-                            EEH_HTML::label(
514
-                                EEH_HTML::strong(
515
-                                    esc_html__('IMPORTANT', 'event_espresso'),
516
-                                    '',
517
-                                    'important-notice'
518
-                                )
519
-                            )
520
-                        ) .
521
-                        EEH_HTML::td(
522
-                            EEH_HTML::strong(
523
-                                esc_html__(
524
-                                    'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
525
-                                    'event_espresso'
526
-                                )
527
-                            )
528
-                            .
529
-                            EEH_HTML::br()
530
-                            .
531
-                            esc_html__('Learn more about ', 'event_espresso')
532
-                            . EEH_HTML::link(
533
-                                'https://www.pcisecuritystandards.org/merchants/index.php',
534
-                                esc_html__('PCI DSS compliance', 'event_espresso')
535
-                            )
536
-                        )
537
-                    )
538
-                )
539
-            );
540
-        }
541
-        return new EE_Form_Section_HTML('');
542
-    }
543
-
544
-
545
-    /**
546
-     * _currency_support
547
-     *
548
-     * @access protected
549
-     * @param EE_Payment_Method $payment_method
550
-     * @return EE_Form_Section_HTML
551
-     * @throws EE_Error
552
-     */
553
-    protected function _currency_support(EE_Payment_Method $payment_method)
554
-    {
555
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
556
-            return new EE_Form_Section_HTML(
557
-                EEH_HTML::table(
558
-                    EEH_HTML::tr(
559
-                        EEH_HTML::th(
560
-                            EEH_HTML::label(
561
-                                EEH_HTML::strong(
562
-                                    esc_html__('IMPORTANT', 'event_espresso'),
563
-                                    '',
564
-                                    'important-notice'
565
-                                )
566
-                            )
567
-                        ) .
568
-                        EEH_HTML::td(
569
-                            EEH_HTML::strong(
570
-                                sprintf(
571
-                                    esc_html__(
572
-                                        'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
573
-                                        'event_espresso'
574
-                                    ),
575
-                                    EE_Config::instance()->currency->code
576
-                                )
577
-                            )
578
-                        )
579
-                    )
580
-                )
581
-            );
582
-        }
583
-        return new EE_Form_Section_HTML('');
584
-    }
585
-
586
-
587
-    /**
588
-     * _update_payment_method_button
589
-     *
590
-     * @access protected
591
-     * @param EE_Payment_Method $payment_method
592
-     * @return EE_Payment_Method_Form
593
-     * @throws EE_Error
594
-     */
595
-    protected function _payment_method_settings(EE_Payment_Method $payment_method)
596
-    {
597
-        // modify the form, so we only have/show fields that will be implemented for this version
598
-        return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
599
-    }
600
-
601
-
602
-    /**
603
-     * Simplifies the form to merely reproduce 4.1's gateway settings functionality
604
-     *
605
-     * @param EE_Form_Section_Proper $form_section
606
-     * @param string                 $payment_method_name
607
-     * @return EE_Payment_Method_Form
608
-     * @throws EE_Error
609
-     */
610
-    protected function _simplify_form($form_section, $payment_method_name = '')
611
-    {
612
-        if ($form_section instanceof EE_Payment_Method_Form) {
613
-            $form_section->exclude(
614
-                array(
615
-                    'PMD_type', // don't want them changing the type
616
-                    'PMD_slug', // or the slug (probably never)
617
-                    'PMD_wp_user', // or the user's ID
618
-                    'Currency' // or the currency, until the rest of EE supports simultaneous currencies
619
-                )
620
-            );
621
-            return $form_section;
622
-        } else {
623
-            throw new EE_Error(
624
-                sprintf(
625
-                    esc_html__(
626
-                        'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
627
-                        'event_espresso'
628
-                    ),
629
-                    $payment_method_name
630
-                )
631
-            );
632
-        }
633
-    }
634
-
635
-
636
-    /**
637
-     * _update_payment_method_button
638
-     *
639
-     * @access protected
640
-     * @param EE_Payment_Method $payment_method
641
-     * @return EE_Form_Section_HTML
642
-     * @throws EE_Error
643
-     */
644
-    protected function _update_payment_method_button(EE_Payment_Method $payment_method)
645
-    {
646
-        $update_button = new EE_Submit_Input(
647
-            array(
648
-                'name'       => 'submit',
649
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
650
-                'default'    => sprintf(
651
-                    esc_html__('Update %s Payment Settings', 'event_espresso'),
652
-                    $payment_method->admin_name()
653
-                ),
654
-                'html_label' => EEH_HTML::nbsp(),
655
-            )
656
-        );
657
-        return new EE_Form_Section_HTML(
658
-            EEH_HTML::table(
659
-                EEH_HTML::no_row(EEH_HTML::br(2)) .
660
-                EEH_HTML::tr(
661
-                    EEH_HTML::th(esc_html__('Update Settings', 'event_espresso')) .
662
-                    EEH_HTML::td(
663
-                        $update_button->get_html_for_input()
664
-                    )
665
-                )
666
-            )
667
-        );
668
-    }
669
-
670
-
671
-    /**
672
-     * _deactivate_payment_method_button
673
-     *
674
-     * @access protected
675
-     * @param EE_Payment_Method $payment_method
676
-     * @return EE_Form_Section_HTML
677
-     */
678
-    protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
679
-    {
680
-        $link_text_and_title = sprintf(
681
-            esc_html__('Deactivate %1$s Payments?', 'event_espresso'),
682
-            $payment_method->admin_name()
683
-        );
684
-        return new EE_Form_Section_HTML(
685
-            EEH_HTML::table(
686
-                EEH_HTML::tr(
687
-                    EEH_HTML::th(esc_html__('Deactivate Payment Method', 'event_espresso')) .
688
-                    EEH_HTML::td(
689
-                        EEH_HTML::link(
690
-                            EE_Admin_Page::add_query_args_and_nonce(
691
-                                array(
692
-                                    'action'         => 'deactivate_payment_method',
693
-                                    'payment_method' => $payment_method->slug(),
694
-                                ),
695
-                                EE_PAYMENTS_ADMIN_URL
696
-                            ),
697
-                            $link_text_and_title,
698
-                            $link_text_and_title,
699
-                            'deactivate_' . $payment_method->slug(),
700
-                            'button button--secondary'
701
-                        )
702
-                    )
703
-                )
704
-            )
705
-        );
706
-    }
707
-
708
-
709
-    /**
710
-     * _activate_payment_method_button
711
-     *
712
-     * @access protected
713
-     * @param EE_Payment_Method $payment_method
714
-     * @return EE_Form_Section_Proper
715
-     * @throws EE_Error
716
-     */
717
-    protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
718
-    {
719
-        $link_text_and_title = sprintf(
720
-            esc_html__('Activate %1$s Payment Method?', 'event_espresso'),
721
-            $payment_method->admin_name()
722
-        );
723
-        return new EE_Form_Section_Proper(
724
-            array(
725
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
726
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
727
-                'action'          => '#',
728
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
729
-                'subsections'     => apply_filters(
730
-                    'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
731
-                    array(
732
-                        new EE_Form_Section_HTML(
733
-                            EEH_HTML::table(
734
-                                EEH_HTML::tr(
735
-                                    EEH_HTML::td(
736
-                                        $payment_method->type_obj()->introductory_html(),
737
-                                        '',
738
-                                        '',
739
-                                        '',
740
-                                        'colspan="2"'
741
-                                    )
742
-                                ) .
743
-                                EEH_HTML::tr(
744
-                                    EEH_HTML::th(
745
-                                        EEH_HTML::label(esc_html__('Click to Activate ', 'event_espresso'))
746
-                                    ) .
747
-                                    EEH_HTML::td(
748
-                                        EEH_HTML::link(
749
-                                            EE_Admin_Page::add_query_args_and_nonce(
750
-                                                array(
751
-                                                    'action'              => 'activate_payment_method',
752
-                                                    'payment_method_type' => $payment_method->type(),
753
-                                                ),
754
-                                                EE_PAYMENTS_ADMIN_URL
755
-                                            ),
756
-                                            $link_text_and_title,
757
-                                            $link_text_and_title,
758
-                                            'activate_' . $payment_method->slug(),
759
-                                            'button button--primary-alt'
760
-                                        )
761
-                                    )
762
-                                )
763
-                            )
764
-                        ),
765
-                    ),
766
-                    $payment_method
767
-                ),
768
-            )
769
-        );
770
-    }
771
-
772
-
773
-    /**
774
-     * _fine_print
775
-     *
776
-     * @access protected
777
-     * @return EE_Form_Section_HTML
778
-     */
779
-    protected function _fine_print()
780
-    {
781
-        return new EE_Form_Section_HTML(
782
-            EEH_HTML::table(
783
-                EEH_HTML::tr(
784
-                    EEH_HTML::th() .
785
-                    EEH_HTML::td(
786
-                        EEH_HTML::p(esc_html__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
787
-                    )
788
-                )
789
-            )
790
-        );
791
-    }
792
-
793
-
794
-    /**
795
-     * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
796
-     *
797
-     * @throws EE_Error
798
-     * @throws ReflectionException
799
-     * @global WP_User $current_user
800
-     */
801
-    protected function _activate_payment_method()
802
-    {
803
-        if (isset($this->_req_data['payment_method_type'])) {
804
-            $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
805
-            // see if one exists
806
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
807
-            $payment_method = EE_Payment_Method_Manager::instance()
808
-                                                       ->activate_a_payment_method_of_type($payment_method_type);
809
-            $this->_redirect_after_action(
810
-                1,
811
-                'Payment Method',
812
-                'activated',
813
-                array('action' => 'default', 'payment_method' => $payment_method->slug())
814
-            );
815
-        } else {
816
-            $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
817
-        }
818
-    }
819
-
820
-
821
-    /**
822
-     * @throws EE_Error
823
-     * @throws ReflectionException
824
-     */
825
-    protected function _deactivate_payment_method()
826
-    {
827
-        if (isset($this->_req_data['payment_method'])) {
828
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
829
-            // deactivate it
830
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
831
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
832
-            $this->_redirect_after_action(
833
-                $count_updated,
834
-                'Payment Method',
835
-                'deactivated',
836
-                array('action' => 'default', 'payment_method' => $payment_method_slug)
837
-            );
838
-        } else {
839
-            $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
840
-        }
841
-    }
842
-
843
-
844
-    /**
845
-     * Processes the payment method form that was submitted. This is slightly trickier than usual form
846
-     * processing because we first need to identify WHICH form was processed and which payment method
847
-     * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
848
-     * form's data is saved, and we redirect to the default payment methods page, setting the updated payment method
849
-     * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
850
-     * subsequently called 'headers_sent_func' which is _payment_methods_list)
851
-     *
852
-     * @return void
853
-     * @throws EE_Error
854
-     * @throws ReflectionException
855
-     */
856
-    protected function _update_payment_method()
857
-    {
858
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
859
-            // ok let's find which gateway form to use based on the form input
860
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
861
-            /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
862
-            $correct_pmt_form_to_use = null;
863
-            $payment_method = null;
864
-            foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
865
-                if ($payment_method instanceof EE_Payment_Method) {
866
-                    // get the form and simplify it, like what we do when we display it
867
-                    $pmt_form = $this->_generate_payment_method_settings_form($payment_method);
868
-                    if ($pmt_form->form_data_present_in($this->_req_data)) {
869
-                        $correct_pmt_form_to_use = $pmt_form;
870
-                        break;
871
-                    }
872
-                }
873
-            }
874
-            // if we couldn't find the correct payment method type...
875
-            if (! $correct_pmt_form_to_use) {
876
-                EE_Error::add_error(
877
-                    esc_html__(
878
-                        "We could not find which payment method type your form submission related to. Please contact support",
879
-                        'event_espresso'
880
-                    ),
881
-                    __FILE__,
882
-                    __FUNCTION__,
883
-                    __LINE__
884
-                );
885
-                $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
886
-            }
887
-            $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
888
-            if ($correct_pmt_form_to_use->is_valid()) {
889
-                $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
890
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
891
-                    throw new EE_Error(
892
-                        sprintf(
893
-                            esc_html__(
894
-                                'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
895
-                                'event_espresso'
896
-                            ),
897
-                            'payment_method_settings'
898
-                        )
899
-                    );
900
-                }
901
-                $payment_settings_subform->save();
902
-                /** @var $pm EE_Payment_Method */
903
-                $this->_redirect_after_action(
904
-                    true,
905
-                    'Payment Method',
906
-                    'updated',
907
-                    array('action' => 'default', 'payment_method' => $payment_method->slug())
908
-                );
909
-            } else {
910
-                EE_Error::add_error(
911
-                    sprintf(
912
-                        esc_html__(
913
-                            'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
914
-                            'event_espresso'
915
-                        ),
916
-                        $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
917
-                            : esc_html__('"(unknown)"', 'event_espresso')
918
-                    ),
919
-                    __FILE__,
920
-                    __FUNCTION__,
921
-                    __LINE__
922
-                );
923
-            }
924
-        }
925
-    }
926
-
927
-
928
-    /**
929
-     * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
930
-     * @throws DomainException
931
-     * @throws EE_Error
932
-     * @throws InvalidArgumentException
933
-     * @throws InvalidDataTypeException
934
-     * @throws InvalidInterfaceException
935
-     */
936
-    protected function _payment_settings()
937
-    {
938
-        $form = $this->getPaymentSettingsForm();
939
-        $this->_set_add_edit_form_tags('update_payment_settings');
940
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
941
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
942
-            $form->get_html_and_js(),
943
-            '',
944
-            'padding'
945
-        );
946
-        $this->display_admin_page_with_sidebar();
947
-    }
948
-
949
-
950
-    /**
951
-     *        _update_payment_settings
952
-     *
953
-     * @access protected
954
-     * @return void
955
-     * @throws EE_Error
956
-     * @throws InvalidArgumentException
957
-     * @throws InvalidDataTypeException
958
-     * @throws InvalidInterfaceException
959
-     */
960
-    protected function _update_payment_settings()
961
-    {
962
-        $form = $this->getPaymentSettingsForm();
963
-        if ($form->was_submitted($this->_req_data)) {
964
-            $form->receive_form_submission($this->_req_data);
965
-            if ($form->is_valid()) {
966
-                /**
967
-                 * @var $reg_config EE_Registration_Config
968
-                 */
969
-                $loader = LoaderFactory::getLoader();
970
-                $reg_config = $loader->getShared('EE_Registration_Config');
971
-                $valid_data = $form->valid_data();
972
-                $reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
973
-                $reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
974
-            }
975
-        }
976
-        EE_Registry::instance()->CFG = apply_filters(
977
-            'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
978
-            EE_Registry::instance()->CFG
979
-        );
980
-
981
-        $what = esc_html__('Payment Settings', 'event_espresso');
982
-        $success = $this->_update_espresso_configuration(
983
-            $what,
984
-            EE_Registry::instance()->CFG,
985
-            __FILE__,
986
-            __FUNCTION__,
987
-            __LINE__
988
-        );
989
-        $this->_redirect_after_action(
990
-            $success,
991
-            $what,
992
-            esc_html__('updated', 'event_espresso'),
993
-            array('action' => 'payment_settings')
994
-        );
995
-    }
996
-
997
-
998
-    /**
999
-     * Gets the form used for updating payment settings
1000
-     *
1001
-     * @return EE_Form_Section_Proper
1002
-     * @throws EE_Error
1003
-     * @throws InvalidArgumentException
1004
-     * @throws InvalidDataTypeException
1005
-     * @throws InvalidInterfaceException
1006
-     */
1007
-    protected function getPaymentSettingsForm()
1008
-    {
1009
-        /**
1010
-         * @var $reg_config EE_Registration_Config
1011
-         */
1012
-        $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
1013
-        return new EE_Form_Section_Proper(
1014
-            array(
1015
-                'name' => 'payment-settings',
1016
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1017
-                'subsections' => array(
1018
-                    'show_pending_payment_options' => new EE_Yes_No_Input(
1019
-                        array(
1020
-                            'html_name' => 'show_pending_payment_options',
1021
-                            'default' => $reg_config->show_pending_payment_options,
1022
-                            'html_help_text' => esc_html__(
1023
-                                "If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ",
1024
-                                'event_espresso'
1025
-                            )
1026
-                        )
1027
-                    ),
1028
-                    'gateway_log_lifespan' => new EE_Select_Input(
1029
-                        $reg_config->gatewayLogLifespanOptions(),
1030
-                        array(
1031
-                            'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
1032
-                            'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'),
1033
-                            'default' => $reg_config->gateway_log_lifespan,
1034
-                        )
1035
-                    )
1036
-                )
1037
-            )
1038
-        );
1039
-    }
1040
-
1041
-
1042
-    /**
1043
-     * @throws EE_Error
1044
-     */
1045
-    protected function _payment_log_overview_list_table()
1046
-    {
1047
-        $this->display_admin_list_table_page_with_sidebar();
1048
-    }
1049
-
1050
-
1051
-    protected function _set_list_table_views_payment_log()
1052
-    {
1053
-        $this->_views = array(
1054
-            'all' => array(
1055
-                'slug'  => 'all',
1056
-                'label' => esc_html__('View All Logs', 'event_espresso'),
1057
-                'count' => 0,
1058
-            ),
1059
-        );
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     * @param int  $per_page
1065
-     * @param int  $current_page
1066
-     * @param bool $count
1067
-     * @return array|int
1068
-     * @throws EE_Error
1069
-     * @throws ReflectionException
1070
-     */
1071
-    public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1072
-    {
1073
-        EE_Registry::instance()->load_model('Change_Log');
1074
-        // we may need to do multiple queries (joining differently), so we actually want an array of query params
1075
-        $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1076
-        // check if they've selected a specific payment method
1077
-        if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1078
-            $query_params[0]['OR*pm_or_pay_pm'] = array(
1079
-                'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1080
-                'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1081
-            );
1082
-        }
1083
-        // take into account search
1084
-        if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1085
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1086
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1087
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1088
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1089
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1090
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1091
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1092
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1093
-            $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1094
-            $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1095
-            $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1096
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1097
-        }
1098
-        if (
1099
-            isset($this->_req_data['payment-filter-start-date'])
1100
-            && isset($this->_req_data['payment-filter-end-date'])
1101
-        ) {
1102
-            // add date
1103
-            $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1104
-            $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1105
-            // make sure our timestamps start and end right at the boundaries for each day
1106
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1107
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1108
-            // convert to timestamps
1109
-            $start_date = strtotime($start_date);
1110
-            $end_date = strtotime($end_date);
1111
-            // makes sure start date is the lowest value and vice versa
1112
-            $start_date = min($start_date, $end_date);
1113
-            $end_date = max($start_date, $end_date);
1114
-            // convert for query
1115
-            $start_date = EEM_Change_Log::instance()->convert_datetime_for_query(
1116
-                'LOG_time',
1117
-                date('Y-m-d H:i:s', $start_date),
1118
-                'Y-m-d H:i:s'
1119
-            );
1120
-            $end_date   = EEM_Change_Log::instance()->convert_datetime_for_query(
1121
-                'LOG_time',
1122
-                date('Y-m-d H:i:s', $end_date),
1123
-                'Y-m-d H:i:s'
1124
-            );
1125
-            $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1126
-        }
1127
-        if ($count) {
1128
-            return EEM_Change_Log::instance()->count($query_params);
1129
-        }
1130
-        if (isset($this->_req_data['order'])) {
1131
-            $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1132
-                ? $this->_req_data['order']
1133
-                : 'DESC';
1134
-            $query_params['order_by'] = array('LOG_time' => $sort);
1135
-        } else {
1136
-            $query_params['order_by'] = array('LOG_time' => 'DESC');
1137
-        }
1138
-        $offset = ($current_page - 1) * $per_page;
1139
-        if (! isset($this->_req_data['download_results'])) {
1140
-            $query_params['limit'] = array($offset, $per_page);
1141
-        }
1142
-        // now they've requested to instead just download the file instead of viewing it.
1143
-        if (isset($this->_req_data['download_results'])) {
1144
-            $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1145
-            header('Content-Disposition: attachment');
1146
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1147
-            echo '<h1> '
1148
-                . sprintf(
1149
-                    esc_html__('Payment Logs for %1$s', 'event_espresso'),
1150
-                    esc_url_raw(site_url())
1151
-                )
1152
-                . '</h1 >';
1153
-            echo '<h3>' . esc_html__('Query:', 'event_espresso') . '</h3>';
1154
-            echo esc_html(var_export($query_params, true));
1155
-            echo '<h3>' . esc_html__('Results:', 'event_espresso') . '</h3>';
1156
-            echo esc_html(var_export($wpdb_results, true));
1157
-            die;
1158
-        }
1159
-        return EEM_Change_Log::instance()->get_all($query_params);
1160
-    }
1161
-
1162
-
1163
-    /**
1164
-     * Used by usort to RE-sort log query results, because we lose the ordering
1165
-     * because we're possibly combining the results from two queries
1166
-     *
1167
-     * @param EE_Change_Log $logA
1168
-     * @param EE_Change_Log $logB
1169
-     * @return int
1170
-     * @throws EE_Error
1171
-     * @throws ReflectionException
1172
-     */
1173
-    protected function _sort_logs_again($logA, $logB)
1174
-    {
1175
-        $timeA = $logA->get_raw('LOG_time');
1176
-        $timeB = $logB->get_raw('LOG_time');
1177
-        if ($timeA == $timeB) {
1178
-            return 0;
1179
-        }
1180
-        $comparison = $timeA < $timeB ? -1 : 1;
1181
-        if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1182
-            return $comparison * -1;
1183
-        }
1184
-        return $comparison;
1185
-    }
1186
-
1187
-
1188
-    /**
1189
-     * @throws EE_Error
1190
-     * @throws ReflectionException
1191
-     */
1192
-    protected function _payment_log_details()
1193
-    {
1194
-        EE_Registry::instance()->load_model('Change_Log');
1195
-        /** @var $payment_log EE_Change_Log */
1196
-        $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1197
-        $payment_method = null;
1198
-        $transaction = null;
1199
-        if ($payment_log instanceof EE_Change_Log) {
1200
-            if ($payment_log->object() instanceof EE_Payment) {
1201
-                $payment_method = $payment_log->object()->payment_method();
1202
-                $transaction = $payment_log->object()->transaction();
1203
-            } elseif ($payment_log->object() instanceof EE_Payment_Method) {
1204
-                $payment_method = $payment_log->object();
1205
-            } elseif ($payment_log->object() instanceof EE_Transaction) {
1206
-                $transaction = $payment_log->object();
1207
-                $payment_method = $transaction->payment_method();
1208
-            }
1209
-        }
1210
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1211
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1212
-            array(
1213
-                'payment_log'    => $payment_log,
1214
-                'payment_method' => $payment_method,
1215
-                'transaction'    => $transaction,
1216
-            ),
1217
-            true
1218
-        );
1219
-        $this->display_admin_page_with_no_sidebar();
1220
-    }
19
+	/**
20
+	 * Variables used for when we're re-sorting the logs results,
21
+	 * in case we needed to do two queries, and we need to resort
22
+	 *
23
+	 * @var string
24
+	 */
25
+	private $_sort_logs_again_direction;
26
+
27
+
28
+	/**
29
+	 * @Constructor
30
+	 * @access public
31
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
32
+	 * @throws EE_Error
33
+	 * @throws InvalidArgumentException
34
+	 * @throws InvalidDataTypeException
35
+	 * @throws InvalidInterfaceException
36
+	 * @throws ReflectionException
37
+	 */
38
+	public function __construct($routing = true)
39
+	{
40
+		parent::__construct($routing);
41
+	}
42
+
43
+
44
+	protected function _init_page_props()
45
+	{
46
+		$this->page_slug = EE_PAYMENTS_PG_SLUG;
47
+		$this->page_label = esc_html__('Payment Methods', 'event_espresso');
48
+		$this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
49
+		$this->_admin_base_path = EE_PAYMENTS_ADMIN;
50
+	}
51
+
52
+
53
+	protected function _ajax_hooks()
54
+	{
55
+		// todo: all hooks for ajax goes here.
56
+	}
57
+
58
+
59
+	protected function _define_page_props()
60
+	{
61
+		$this->_admin_page_title = $this->page_label;
62
+		$this->_labels = array(
63
+			'publishbox' => esc_html__('Update Settings', 'event_espresso'),
64
+		);
65
+	}
66
+
67
+
68
+	protected function _set_page_routes()
69
+	{
70
+		/**
71
+		 * note that with payment method capabilities, although we've implemented
72
+		 * capability mapping which will be used for accessing payment methods owned by
73
+		 * other users.  This is not fully implemented yet in the payment method ui.
74
+		 * Currently, only the "plural" caps are in active use.
75
+		 * When cap mapping is implemented, some routes will need to use the singular form of
76
+		 * capability method and also include the $id of the payment method for the route.
77
+		 **/
78
+		$this->_page_routes = array(
79
+			'default'                   => array(
80
+				'func'       => '_payment_methods_list',
81
+				'capability' => 'ee_edit_payment_methods',
82
+			),
83
+			'payment_settings'          => array(
84
+				'func'       => '_payment_settings',
85
+				'capability' => 'ee_manage_gateways',
86
+			),
87
+			'activate_payment_method'   => array(
88
+				'func'       => '_activate_payment_method',
89
+				'noheader'   => true,
90
+				'capability' => 'ee_edit_payment_methods',
91
+			),
92
+			'deactivate_payment_method' => array(
93
+				'func'       => '_deactivate_payment_method',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_delete_payment_methods',
96
+			),
97
+			'update_payment_method'     => array(
98
+				'func'               => '_update_payment_method',
99
+				'noheader'           => true,
100
+				'headers_sent_route' => 'default',
101
+				'capability'         => 'ee_edit_payment_methods',
102
+			),
103
+			'update_payment_settings'   => array(
104
+				'func'       => '_update_payment_settings',
105
+				'noheader'   => true,
106
+				'capability' => 'ee_manage_gateways',
107
+			),
108
+			'payment_log'               => array(
109
+				'func'       => '_payment_log_overview_list_table',
110
+				'capability' => 'ee_read_payment_methods',
111
+			),
112
+			'payment_log_details'       => array(
113
+				'func'       => '_payment_log_details',
114
+				'capability' => 'ee_read_payment_methods',
115
+			),
116
+		);
117
+	}
118
+
119
+
120
+	/**
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	protected function _set_page_config()
125
+	{
126
+		$payment_method_list_config = array(
127
+			'nav'           => array(
128
+				'label' => esc_html__('Payment Methods', 'event_espresso'),
129
+				'order' => 10,
130
+			),
131
+			'metaboxes'     => $this->_default_espresso_metaboxes,
132
+			'help_tabs'     => array_merge(
133
+				array(
134
+					'payment_methods_overview_help_tab' => array(
135
+						'title'    => esc_html__('Payment Methods Overview', 'event_espresso'),
136
+						'filename' => 'payment_methods_overview',
137
+					),
138
+				),
139
+				$this->_add_payment_method_help_tabs()
140
+			),
141
+			'require_nonce' => false,
142
+		);
143
+		$this->_page_config = array(
144
+			'default'          => $payment_method_list_config,
145
+			'payment_settings' => array(
146
+				'nav'           => array(
147
+					'label' => esc_html__('Settings', 'event_espresso'),
148
+					'order' => 20,
149
+				),
150
+				'help_tabs'     => array(
151
+					'payment_methods_settings_help_tab' => array(
152
+						'title'    => esc_html__('Payment Method Settings', 'event_espresso'),
153
+						'filename' => 'payment_methods_settings',
154
+					),
155
+				),
156
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
157
+				'require_nonce' => false,
158
+			),
159
+			'payment_log'      => array(
160
+				'nav'           => array(
161
+					'label' => esc_html__("Logs", 'event_espresso'),
162
+					'order' => 30,
163
+				),
164
+				'list_table'    => 'Payment_Log_Admin_List_Table',
165
+				'metaboxes'     => $this->_default_espresso_metaboxes,
166
+				'require_nonce' => false,
167
+			),
168
+		);
169
+	}
170
+
171
+
172
+	/**
173
+	 * @return array
174
+	 * @throws DomainException
175
+	 * @throws EE_Error
176
+	 * @throws InvalidArgumentException
177
+	 * @throws InvalidDataTypeException
178
+	 * @throws InvalidInterfaceException
179
+	 * @throws ReflectionException
180
+	 */
181
+	protected function _add_payment_method_help_tabs()
182
+	{
183
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
184
+		$payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
185
+		$all_pmt_help_tabs_config = array();
186
+		foreach ($payment_method_types as $payment_method_type) {
187
+			if (
188
+				! EE_Registry::instance()->CAP->current_user_can(
189
+					$payment_method_type->cap_name(),
190
+					'specific_payment_method_type_access'
191
+				)
192
+			) {
193
+				continue;
194
+			}
195
+			foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
196
+				$template_args = isset($config['template_args']) ? $config['template_args'] : array();
197
+				$template_args['admin_page_obj'] = $this;
198
+				$all_pmt_help_tabs_config[ $help_tab_name ] = array(
199
+					'title'   => $config['title'],
200
+					'content' => EEH_Template::display_template(
201
+						$payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
202
+						$template_args,
203
+						true
204
+					),
205
+				);
206
+			}
207
+		}
208
+		return $all_pmt_help_tabs_config;
209
+	}
210
+
211
+
212
+	// none of the below group are currently used for Gateway Settings
213
+	protected function _add_screen_options()
214
+	{
215
+	}
216
+
217
+
218
+	protected function _add_feature_pointers()
219
+	{
220
+	}
221
+
222
+
223
+	public function admin_init()
224
+	{
225
+	}
226
+
227
+
228
+	public function admin_notices()
229
+	{
230
+	}
231
+
232
+
233
+	public function admin_footer_scripts()
234
+	{
235
+	}
236
+
237
+
238
+	public function load_scripts_styles()
239
+	{
240
+		// styles
241
+		wp_enqueue_style('espresso-ui-theme');
242
+		wp_register_style(
243
+			'espresso_payments',
244
+			EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
245
+			[],
246
+			EVENT_ESPRESSO_VERSION
247
+		);
248
+		// scripts
249
+		wp_enqueue_script('ee_admin_js');
250
+		wp_enqueue_script('ee-text-links');
251
+		wp_enqueue_script(
252
+			'espresso_payments',
253
+			EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
254
+			['ee-datepicker'],
255
+			EVENT_ESPRESSO_VERSION,
256
+			true
257
+		);
258
+	}
259
+
260
+
261
+	public function load_scripts_styles_default()
262
+	{
263
+		wp_enqueue_style('espresso_payments');
264
+		wp_enqueue_style('ee-text-links');
265
+	}
266
+
267
+
268
+	public function load_scripts_styles_payment_log_details()
269
+	{
270
+		wp_enqueue_style('espresso_payments');
271
+	}
272
+
273
+
274
+	/**
275
+	 * @throws EE_Error
276
+	 * @throws ReflectionException
277
+	 */
278
+	protected function _payment_methods_list()
279
+	{
280
+		/**
281
+		 * first let's ensure payment methods have been set up.
282
+		 * We do this here because when people activate a payment method for the first time (as an addon),
283
+		 * it may not set up its capabilities or get registered correctly due to the loading process.
284
+		 * However, people MUST set up the details for the payment method,
285
+		 * so it's safe to do a recheck here.
286
+		 */
287
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
288
+		EEM_Payment_Method::instance()->verify_button_urls();
289
+		// set up tabs, one for each payment method type
290
+		$tabs = array();
291
+		$payment_methods = array();
292
+		foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
293
+			// we don't want to show admin-only PMTs for now
294
+			if ($pmt_obj instanceof EE_PMT_Admin_Only) {
295
+				continue;
296
+			}
297
+			// check access
298
+			if (
299
+				! EE_Registry::instance()->CAP->current_user_can(
300
+					$pmt_obj->cap_name(),
301
+					'specific_payment_method_type_access'
302
+				)
303
+			) {
304
+				continue;
305
+			}
306
+			// check for any active pms of that type
307
+			$payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
308
+			if (! $payment_method instanceof EE_Payment_Method) {
309
+				$payment_method = EE_Payment_Method::new_instance(
310
+					array(
311
+						'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
312
+						'PMD_type'       => $pmt_obj->system_name(),
313
+						'PMD_name'       => $pmt_obj->pretty_name(),
314
+						'PMD_admin_name' => $pmt_obj->pretty_name(),
315
+					)
316
+				);
317
+			}
318
+			$payment_methods[ $payment_method->slug() ] = $payment_method;
319
+		}
320
+		$payment_methods = apply_filters(
321
+			'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
322
+			$payment_methods
323
+		);
324
+		foreach ($payment_methods as $payment_method) {
325
+			if ($payment_method instanceof EE_Payment_Method) {
326
+				$this->addMetaBox(
327
+					// html id
328
+					'espresso_' . $payment_method->slug() . '_payment_settings',
329
+					// title
330
+					sprintf(esc_html__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
331
+					// callback
332
+					array($this, 'payment_method_settings_meta_box'),
333
+					// post type
334
+					null,
335
+					// context
336
+					'normal',
337
+					// priority
338
+					'default',
339
+					// callback args
340
+					array('payment_method' => $payment_method)
341
+				);
342
+				// setup for tabbed content
343
+				$tabs[ $payment_method->slug() ] = array(
344
+					'label' => $payment_method->admin_name(),
345
+					'class' => $payment_method->active() ? 'gateway-active' : '',
346
+					'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
347
+					'title' => esc_html__('Modify this Payment Method', 'event_espresso'),
348
+					'slug'  => $payment_method->slug(),
349
+					'icon'  => $payment_method->active()
350
+						? '<span class="dashicons dashicons-yes-alt"></span>'
351
+						: '<span class="dashicons dashicons-remove"></span>',
352
+				);
353
+			}
354
+		}
355
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
356
+			$tabs,
357
+			'payment_method_links',
358
+			'',
359
+			$this->_get_active_payment_method_slug()
360
+		);
361
+		$this->display_admin_page_with_sidebar();
362
+	}
363
+
364
+
365
+	/**
366
+	 *   _get_active_payment_method_slug
367
+	 *
368
+	 * @return string
369
+	 * @throws EE_Error
370
+	 */
371
+	protected function _get_active_payment_method_slug()
372
+	{
373
+		$payment_method_slug = false;
374
+		// decide which payment method tab to open first, as dictated by the request's 'payment_method'
375
+		if (isset($this->_req_data['payment_method'])) {
376
+			// if they provided the current payment method, use it
377
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
378
+		}
379
+		/** @var EE_Payment_Method $payment_method */
380
+		$payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
381
+		// if that didn't work or wasn't provided, find another way to select the current pm
382
+		if (! $this->_verify_payment_method($payment_method)) {
383
+			// like, looking for an active one
384
+			$payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
385
+			// test that one as well
386
+			if ($this->_verify_payment_method($payment_method)) {
387
+				$payment_method_slug = $payment_method->slug();
388
+			} else {
389
+				$payment_method_slug = 'paypal_standard';
390
+			}
391
+		}
392
+		return $payment_method_slug;
393
+	}
394
+
395
+
396
+	/**
397
+	 *    payment_method_settings_meta_box
398
+	 *    returns TRUE if the passed payment method is properly constructed and the logged-in user has the correct
399
+	 *    capabilities to access it
400
+	 *
401
+	 * @param EE_Payment_Method $payment_method
402
+	 * @return boolean
403
+	 * @throws EE_Error
404
+	 */
405
+	protected function _verify_payment_method($payment_method)
406
+	{
407
+		if (
408
+			$payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
409
+			&& EE_Registry::instance()->CAP->current_user_can(
410
+				$payment_method->type_obj()->cap_name(),
411
+				'specific_payment_method_type_access'
412
+			)
413
+		) {
414
+			return true;
415
+		}
416
+		return false;
417
+	}
418
+
419
+
420
+	/**
421
+	 *    payment_method_settings_meta_box
422
+	 *
423
+	 * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
424
+	 * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
425
+	 *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
426
+	 * @return void
427
+	 * @throws EE_Error
428
+	 * @throws ReflectionException
429
+	 */
430
+	public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
431
+	{
432
+		$payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
433
+			? $metabox['args']['payment_method'] : null;
434
+		if (! $payment_method instanceof EE_Payment_Method) {
435
+			throw new EE_Error(
436
+				esc_html__(
437
+					'Payment method metabox setup incorrectly. No Payment method object was supplied',
438
+					'event_espresso'
439
+				)
440
+			);
441
+		}
442
+		$payment_method_scopes = $payment_method->active();
443
+		// if the payment method really exists show its form, otherwise the activation template
444
+		if ($payment_method->ID() && ! empty($payment_method_scopes)) {
445
+			$form = $this->_generate_payment_method_settings_form($payment_method);
446
+			if ($form->form_data_present_in($this->_req_data)) {
447
+				$form->receive_form_submission($this->_req_data);
448
+			}
449
+			echo wp_kses($form->form_open() . $form->get_html_and_js() . $form->form_close(), AllowedTags::getWithFormTags());
450
+		} else {
451
+			echo wp_kses($this->_activate_payment_method_button($payment_method)->get_html_and_js(), AllowedTags::getWithFormTags());
452
+		}
453
+	}
454
+
455
+
456
+	/**
457
+	 * Gets the form for all the settings related to this payment method type
458
+	 *
459
+	 * @access protected
460
+	 * @param EE_Payment_Method $payment_method
461
+	 * @return EE_Form_Section_Proper
462
+	 * @throws EE_Error
463
+	 */
464
+	protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method = null)
465
+	{
466
+		if (! $payment_method instanceof EE_Payment_Method) {
467
+			return new EE_Form_Section_Proper();
468
+		}
469
+		return new EE_Form_Section_Proper(
470
+			array(
471
+				'name'            => $payment_method->slug() . '_settings_form',
472
+				'html_id'         => $payment_method->slug() . '_settings_form',
473
+				'action'          => EE_Admin_Page::add_query_args_and_nonce(
474
+					array(
475
+						'action'         => 'update_payment_method',
476
+						'payment_method' => $payment_method->slug(),
477
+					),
478
+					EE_PAYMENTS_ADMIN_URL
479
+				),
480
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
481
+				'subsections'     => apply_filters(
482
+					'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
483
+					array(
484
+						'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
485
+						'currency_support'        => $this->_currency_support($payment_method),
486
+						'payment_method_settings' => $this->_payment_method_settings($payment_method),
487
+						'update'                  => $this->_update_payment_method_button($payment_method),
488
+						'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
489
+						'fine_print'              => $this->_fine_print(),
490
+					),
491
+					$payment_method
492
+				),
493
+			)
494
+		);
495
+	}
496
+
497
+
498
+	/**
499
+	 * _pci_dss_compliance
500
+	 *
501
+	 * @access protected
502
+	 * @param EE_Payment_Method $payment_method
503
+	 * @return EE_Form_Section_HTML
504
+	 * @throws EE_Error
505
+	 */
506
+	protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
507
+	{
508
+		if ($payment_method->type_obj()->requires_https()) {
509
+			return new EE_Form_Section_HTML(
510
+				EEH_HTML::table(
511
+					EEH_HTML::tr(
512
+						EEH_HTML::th(
513
+							EEH_HTML::label(
514
+								EEH_HTML::strong(
515
+									esc_html__('IMPORTANT', 'event_espresso'),
516
+									'',
517
+									'important-notice'
518
+								)
519
+							)
520
+						) .
521
+						EEH_HTML::td(
522
+							EEH_HTML::strong(
523
+								esc_html__(
524
+									'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
525
+									'event_espresso'
526
+								)
527
+							)
528
+							.
529
+							EEH_HTML::br()
530
+							.
531
+							esc_html__('Learn more about ', 'event_espresso')
532
+							. EEH_HTML::link(
533
+								'https://www.pcisecuritystandards.org/merchants/index.php',
534
+								esc_html__('PCI DSS compliance', 'event_espresso')
535
+							)
536
+						)
537
+					)
538
+				)
539
+			);
540
+		}
541
+		return new EE_Form_Section_HTML('');
542
+	}
543
+
544
+
545
+	/**
546
+	 * _currency_support
547
+	 *
548
+	 * @access protected
549
+	 * @param EE_Payment_Method $payment_method
550
+	 * @return EE_Form_Section_HTML
551
+	 * @throws EE_Error
552
+	 */
553
+	protected function _currency_support(EE_Payment_Method $payment_method)
554
+	{
555
+		if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
556
+			return new EE_Form_Section_HTML(
557
+				EEH_HTML::table(
558
+					EEH_HTML::tr(
559
+						EEH_HTML::th(
560
+							EEH_HTML::label(
561
+								EEH_HTML::strong(
562
+									esc_html__('IMPORTANT', 'event_espresso'),
563
+									'',
564
+									'important-notice'
565
+								)
566
+							)
567
+						) .
568
+						EEH_HTML::td(
569
+							EEH_HTML::strong(
570
+								sprintf(
571
+									esc_html__(
572
+										'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
573
+										'event_espresso'
574
+									),
575
+									EE_Config::instance()->currency->code
576
+								)
577
+							)
578
+						)
579
+					)
580
+				)
581
+			);
582
+		}
583
+		return new EE_Form_Section_HTML('');
584
+	}
585
+
586
+
587
+	/**
588
+	 * _update_payment_method_button
589
+	 *
590
+	 * @access protected
591
+	 * @param EE_Payment_Method $payment_method
592
+	 * @return EE_Payment_Method_Form
593
+	 * @throws EE_Error
594
+	 */
595
+	protected function _payment_method_settings(EE_Payment_Method $payment_method)
596
+	{
597
+		// modify the form, so we only have/show fields that will be implemented for this version
598
+		return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
599
+	}
600
+
601
+
602
+	/**
603
+	 * Simplifies the form to merely reproduce 4.1's gateway settings functionality
604
+	 *
605
+	 * @param EE_Form_Section_Proper $form_section
606
+	 * @param string                 $payment_method_name
607
+	 * @return EE_Payment_Method_Form
608
+	 * @throws EE_Error
609
+	 */
610
+	protected function _simplify_form($form_section, $payment_method_name = '')
611
+	{
612
+		if ($form_section instanceof EE_Payment_Method_Form) {
613
+			$form_section->exclude(
614
+				array(
615
+					'PMD_type', // don't want them changing the type
616
+					'PMD_slug', // or the slug (probably never)
617
+					'PMD_wp_user', // or the user's ID
618
+					'Currency' // or the currency, until the rest of EE supports simultaneous currencies
619
+				)
620
+			);
621
+			return $form_section;
622
+		} else {
623
+			throw new EE_Error(
624
+				sprintf(
625
+					esc_html__(
626
+						'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
627
+						'event_espresso'
628
+					),
629
+					$payment_method_name
630
+				)
631
+			);
632
+		}
633
+	}
634
+
635
+
636
+	/**
637
+	 * _update_payment_method_button
638
+	 *
639
+	 * @access protected
640
+	 * @param EE_Payment_Method $payment_method
641
+	 * @return EE_Form_Section_HTML
642
+	 * @throws EE_Error
643
+	 */
644
+	protected function _update_payment_method_button(EE_Payment_Method $payment_method)
645
+	{
646
+		$update_button = new EE_Submit_Input(
647
+			array(
648
+				'name'       => 'submit',
649
+				'html_id'    => 'save_' . $payment_method->slug() . '_settings',
650
+				'default'    => sprintf(
651
+					esc_html__('Update %s Payment Settings', 'event_espresso'),
652
+					$payment_method->admin_name()
653
+				),
654
+				'html_label' => EEH_HTML::nbsp(),
655
+			)
656
+		);
657
+		return new EE_Form_Section_HTML(
658
+			EEH_HTML::table(
659
+				EEH_HTML::no_row(EEH_HTML::br(2)) .
660
+				EEH_HTML::tr(
661
+					EEH_HTML::th(esc_html__('Update Settings', 'event_espresso')) .
662
+					EEH_HTML::td(
663
+						$update_button->get_html_for_input()
664
+					)
665
+				)
666
+			)
667
+		);
668
+	}
669
+
670
+
671
+	/**
672
+	 * _deactivate_payment_method_button
673
+	 *
674
+	 * @access protected
675
+	 * @param EE_Payment_Method $payment_method
676
+	 * @return EE_Form_Section_HTML
677
+	 */
678
+	protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
679
+	{
680
+		$link_text_and_title = sprintf(
681
+			esc_html__('Deactivate %1$s Payments?', 'event_espresso'),
682
+			$payment_method->admin_name()
683
+		);
684
+		return new EE_Form_Section_HTML(
685
+			EEH_HTML::table(
686
+				EEH_HTML::tr(
687
+					EEH_HTML::th(esc_html__('Deactivate Payment Method', 'event_espresso')) .
688
+					EEH_HTML::td(
689
+						EEH_HTML::link(
690
+							EE_Admin_Page::add_query_args_and_nonce(
691
+								array(
692
+									'action'         => 'deactivate_payment_method',
693
+									'payment_method' => $payment_method->slug(),
694
+								),
695
+								EE_PAYMENTS_ADMIN_URL
696
+							),
697
+							$link_text_and_title,
698
+							$link_text_and_title,
699
+							'deactivate_' . $payment_method->slug(),
700
+							'button button--secondary'
701
+						)
702
+					)
703
+				)
704
+			)
705
+		);
706
+	}
707
+
708
+
709
+	/**
710
+	 * _activate_payment_method_button
711
+	 *
712
+	 * @access protected
713
+	 * @param EE_Payment_Method $payment_method
714
+	 * @return EE_Form_Section_Proper
715
+	 * @throws EE_Error
716
+	 */
717
+	protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
718
+	{
719
+		$link_text_and_title = sprintf(
720
+			esc_html__('Activate %1$s Payment Method?', 'event_espresso'),
721
+			$payment_method->admin_name()
722
+		);
723
+		return new EE_Form_Section_Proper(
724
+			array(
725
+				'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
726
+				'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
727
+				'action'          => '#',
728
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
729
+				'subsections'     => apply_filters(
730
+					'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
731
+					array(
732
+						new EE_Form_Section_HTML(
733
+							EEH_HTML::table(
734
+								EEH_HTML::tr(
735
+									EEH_HTML::td(
736
+										$payment_method->type_obj()->introductory_html(),
737
+										'',
738
+										'',
739
+										'',
740
+										'colspan="2"'
741
+									)
742
+								) .
743
+								EEH_HTML::tr(
744
+									EEH_HTML::th(
745
+										EEH_HTML::label(esc_html__('Click to Activate ', 'event_espresso'))
746
+									) .
747
+									EEH_HTML::td(
748
+										EEH_HTML::link(
749
+											EE_Admin_Page::add_query_args_and_nonce(
750
+												array(
751
+													'action'              => 'activate_payment_method',
752
+													'payment_method_type' => $payment_method->type(),
753
+												),
754
+												EE_PAYMENTS_ADMIN_URL
755
+											),
756
+											$link_text_and_title,
757
+											$link_text_and_title,
758
+											'activate_' . $payment_method->slug(),
759
+											'button button--primary-alt'
760
+										)
761
+									)
762
+								)
763
+							)
764
+						),
765
+					),
766
+					$payment_method
767
+				),
768
+			)
769
+		);
770
+	}
771
+
772
+
773
+	/**
774
+	 * _fine_print
775
+	 *
776
+	 * @access protected
777
+	 * @return EE_Form_Section_HTML
778
+	 */
779
+	protected function _fine_print()
780
+	{
781
+		return new EE_Form_Section_HTML(
782
+			EEH_HTML::table(
783
+				EEH_HTML::tr(
784
+					EEH_HTML::th() .
785
+					EEH_HTML::td(
786
+						EEH_HTML::p(esc_html__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
787
+					)
788
+				)
789
+			)
790
+		);
791
+	}
792
+
793
+
794
+	/**
795
+	 * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
796
+	 *
797
+	 * @throws EE_Error
798
+	 * @throws ReflectionException
799
+	 * @global WP_User $current_user
800
+	 */
801
+	protected function _activate_payment_method()
802
+	{
803
+		if (isset($this->_req_data['payment_method_type'])) {
804
+			$payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
805
+			// see if one exists
806
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
807
+			$payment_method = EE_Payment_Method_Manager::instance()
808
+													   ->activate_a_payment_method_of_type($payment_method_type);
809
+			$this->_redirect_after_action(
810
+				1,
811
+				'Payment Method',
812
+				'activated',
813
+				array('action' => 'default', 'payment_method' => $payment_method->slug())
814
+			);
815
+		} else {
816
+			$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
817
+		}
818
+	}
819
+
820
+
821
+	/**
822
+	 * @throws EE_Error
823
+	 * @throws ReflectionException
824
+	 */
825
+	protected function _deactivate_payment_method()
826
+	{
827
+		if (isset($this->_req_data['payment_method'])) {
828
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
829
+			// deactivate it
830
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
831
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
832
+			$this->_redirect_after_action(
833
+				$count_updated,
834
+				'Payment Method',
835
+				'deactivated',
836
+				array('action' => 'default', 'payment_method' => $payment_method_slug)
837
+			);
838
+		} else {
839
+			$this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
840
+		}
841
+	}
842
+
843
+
844
+	/**
845
+	 * Processes the payment method form that was submitted. This is slightly trickier than usual form
846
+	 * processing because we first need to identify WHICH form was processed and which payment method
847
+	 * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
848
+	 * form's data is saved, and we redirect to the default payment methods page, setting the updated payment method
849
+	 * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
850
+	 * subsequently called 'headers_sent_func' which is _payment_methods_list)
851
+	 *
852
+	 * @return void
853
+	 * @throws EE_Error
854
+	 * @throws ReflectionException
855
+	 */
856
+	protected function _update_payment_method()
857
+	{
858
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
859
+			// ok let's find which gateway form to use based on the form input
860
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
861
+			/** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
862
+			$correct_pmt_form_to_use = null;
863
+			$payment_method = null;
864
+			foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
865
+				if ($payment_method instanceof EE_Payment_Method) {
866
+					// get the form and simplify it, like what we do when we display it
867
+					$pmt_form = $this->_generate_payment_method_settings_form($payment_method);
868
+					if ($pmt_form->form_data_present_in($this->_req_data)) {
869
+						$correct_pmt_form_to_use = $pmt_form;
870
+						break;
871
+					}
872
+				}
873
+			}
874
+			// if we couldn't find the correct payment method type...
875
+			if (! $correct_pmt_form_to_use) {
876
+				EE_Error::add_error(
877
+					esc_html__(
878
+						"We could not find which payment method type your form submission related to. Please contact support",
879
+						'event_espresso'
880
+					),
881
+					__FILE__,
882
+					__FUNCTION__,
883
+					__LINE__
884
+				);
885
+				$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
886
+			}
887
+			$correct_pmt_form_to_use->receive_form_submission($this->_req_data);
888
+			if ($correct_pmt_form_to_use->is_valid()) {
889
+				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
890
+				if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
891
+					throw new EE_Error(
892
+						sprintf(
893
+							esc_html__(
894
+								'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
895
+								'event_espresso'
896
+							),
897
+							'payment_method_settings'
898
+						)
899
+					);
900
+				}
901
+				$payment_settings_subform->save();
902
+				/** @var $pm EE_Payment_Method */
903
+				$this->_redirect_after_action(
904
+					true,
905
+					'Payment Method',
906
+					'updated',
907
+					array('action' => 'default', 'payment_method' => $payment_method->slug())
908
+				);
909
+			} else {
910
+				EE_Error::add_error(
911
+					sprintf(
912
+						esc_html__(
913
+							'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
914
+							'event_espresso'
915
+						),
916
+						$payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
917
+							: esc_html__('"(unknown)"', 'event_espresso')
918
+					),
919
+					__FILE__,
920
+					__FUNCTION__,
921
+					__LINE__
922
+				);
923
+			}
924
+		}
925
+	}
926
+
927
+
928
+	/**
929
+	 * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
930
+	 * @throws DomainException
931
+	 * @throws EE_Error
932
+	 * @throws InvalidArgumentException
933
+	 * @throws InvalidDataTypeException
934
+	 * @throws InvalidInterfaceException
935
+	 */
936
+	protected function _payment_settings()
937
+	{
938
+		$form = $this->getPaymentSettingsForm();
939
+		$this->_set_add_edit_form_tags('update_payment_settings');
940
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
941
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
942
+			$form->get_html_and_js(),
943
+			'',
944
+			'padding'
945
+		);
946
+		$this->display_admin_page_with_sidebar();
947
+	}
948
+
949
+
950
+	/**
951
+	 *        _update_payment_settings
952
+	 *
953
+	 * @access protected
954
+	 * @return void
955
+	 * @throws EE_Error
956
+	 * @throws InvalidArgumentException
957
+	 * @throws InvalidDataTypeException
958
+	 * @throws InvalidInterfaceException
959
+	 */
960
+	protected function _update_payment_settings()
961
+	{
962
+		$form = $this->getPaymentSettingsForm();
963
+		if ($form->was_submitted($this->_req_data)) {
964
+			$form->receive_form_submission($this->_req_data);
965
+			if ($form->is_valid()) {
966
+				/**
967
+				 * @var $reg_config EE_Registration_Config
968
+				 */
969
+				$loader = LoaderFactory::getLoader();
970
+				$reg_config = $loader->getShared('EE_Registration_Config');
971
+				$valid_data = $form->valid_data();
972
+				$reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
973
+				$reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
974
+			}
975
+		}
976
+		EE_Registry::instance()->CFG = apply_filters(
977
+			'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
978
+			EE_Registry::instance()->CFG
979
+		);
980
+
981
+		$what = esc_html__('Payment Settings', 'event_espresso');
982
+		$success = $this->_update_espresso_configuration(
983
+			$what,
984
+			EE_Registry::instance()->CFG,
985
+			__FILE__,
986
+			__FUNCTION__,
987
+			__LINE__
988
+		);
989
+		$this->_redirect_after_action(
990
+			$success,
991
+			$what,
992
+			esc_html__('updated', 'event_espresso'),
993
+			array('action' => 'payment_settings')
994
+		);
995
+	}
996
+
997
+
998
+	/**
999
+	 * Gets the form used for updating payment settings
1000
+	 *
1001
+	 * @return EE_Form_Section_Proper
1002
+	 * @throws EE_Error
1003
+	 * @throws InvalidArgumentException
1004
+	 * @throws InvalidDataTypeException
1005
+	 * @throws InvalidInterfaceException
1006
+	 */
1007
+	protected function getPaymentSettingsForm()
1008
+	{
1009
+		/**
1010
+		 * @var $reg_config EE_Registration_Config
1011
+		 */
1012
+		$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
1013
+		return new EE_Form_Section_Proper(
1014
+			array(
1015
+				'name' => 'payment-settings',
1016
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1017
+				'subsections' => array(
1018
+					'show_pending_payment_options' => new EE_Yes_No_Input(
1019
+						array(
1020
+							'html_name' => 'show_pending_payment_options',
1021
+							'default' => $reg_config->show_pending_payment_options,
1022
+							'html_help_text' => esc_html__(
1023
+								"If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ",
1024
+								'event_espresso'
1025
+							)
1026
+						)
1027
+					),
1028
+					'gateway_log_lifespan' => new EE_Select_Input(
1029
+						$reg_config->gatewayLogLifespanOptions(),
1030
+						array(
1031
+							'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
1032
+							'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'),
1033
+							'default' => $reg_config->gateway_log_lifespan,
1034
+						)
1035
+					)
1036
+				)
1037
+			)
1038
+		);
1039
+	}
1040
+
1041
+
1042
+	/**
1043
+	 * @throws EE_Error
1044
+	 */
1045
+	protected function _payment_log_overview_list_table()
1046
+	{
1047
+		$this->display_admin_list_table_page_with_sidebar();
1048
+	}
1049
+
1050
+
1051
+	protected function _set_list_table_views_payment_log()
1052
+	{
1053
+		$this->_views = array(
1054
+			'all' => array(
1055
+				'slug'  => 'all',
1056
+				'label' => esc_html__('View All Logs', 'event_espresso'),
1057
+				'count' => 0,
1058
+			),
1059
+		);
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 * @param int  $per_page
1065
+	 * @param int  $current_page
1066
+	 * @param bool $count
1067
+	 * @return array|int
1068
+	 * @throws EE_Error
1069
+	 * @throws ReflectionException
1070
+	 */
1071
+	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1072
+	{
1073
+		EE_Registry::instance()->load_model('Change_Log');
1074
+		// we may need to do multiple queries (joining differently), so we actually want an array of query params
1075
+		$query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1076
+		// check if they've selected a specific payment method
1077
+		if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1078
+			$query_params[0]['OR*pm_or_pay_pm'] = array(
1079
+				'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1080
+				'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1081
+			);
1082
+		}
1083
+		// take into account search
1084
+		if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1085
+			$similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1086
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1087
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1088
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1089
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1090
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1091
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1092
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1093
+			$query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1094
+			$query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1095
+			$query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1096
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1097
+		}
1098
+		if (
1099
+			isset($this->_req_data['payment-filter-start-date'])
1100
+			&& isset($this->_req_data['payment-filter-end-date'])
1101
+		) {
1102
+			// add date
1103
+			$start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1104
+			$end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1105
+			// make sure our timestamps start and end right at the boundaries for each day
1106
+			$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1107
+			$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1108
+			// convert to timestamps
1109
+			$start_date = strtotime($start_date);
1110
+			$end_date = strtotime($end_date);
1111
+			// makes sure start date is the lowest value and vice versa
1112
+			$start_date = min($start_date, $end_date);
1113
+			$end_date = max($start_date, $end_date);
1114
+			// convert for query
1115
+			$start_date = EEM_Change_Log::instance()->convert_datetime_for_query(
1116
+				'LOG_time',
1117
+				date('Y-m-d H:i:s', $start_date),
1118
+				'Y-m-d H:i:s'
1119
+			);
1120
+			$end_date   = EEM_Change_Log::instance()->convert_datetime_for_query(
1121
+				'LOG_time',
1122
+				date('Y-m-d H:i:s', $end_date),
1123
+				'Y-m-d H:i:s'
1124
+			);
1125
+			$query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1126
+		}
1127
+		if ($count) {
1128
+			return EEM_Change_Log::instance()->count($query_params);
1129
+		}
1130
+		if (isset($this->_req_data['order'])) {
1131
+			$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1132
+				? $this->_req_data['order']
1133
+				: 'DESC';
1134
+			$query_params['order_by'] = array('LOG_time' => $sort);
1135
+		} else {
1136
+			$query_params['order_by'] = array('LOG_time' => 'DESC');
1137
+		}
1138
+		$offset = ($current_page - 1) * $per_page;
1139
+		if (! isset($this->_req_data['download_results'])) {
1140
+			$query_params['limit'] = array($offset, $per_page);
1141
+		}
1142
+		// now they've requested to instead just download the file instead of viewing it.
1143
+		if (isset($this->_req_data['download_results'])) {
1144
+			$wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1145
+			header('Content-Disposition: attachment');
1146
+			header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1147
+			echo '<h1> '
1148
+				. sprintf(
1149
+					esc_html__('Payment Logs for %1$s', 'event_espresso'),
1150
+					esc_url_raw(site_url())
1151
+				)
1152
+				. '</h1 >';
1153
+			echo '<h3>' . esc_html__('Query:', 'event_espresso') . '</h3>';
1154
+			echo esc_html(var_export($query_params, true));
1155
+			echo '<h3>' . esc_html__('Results:', 'event_espresso') . '</h3>';
1156
+			echo esc_html(var_export($wpdb_results, true));
1157
+			die;
1158
+		}
1159
+		return EEM_Change_Log::instance()->get_all($query_params);
1160
+	}
1161
+
1162
+
1163
+	/**
1164
+	 * Used by usort to RE-sort log query results, because we lose the ordering
1165
+	 * because we're possibly combining the results from two queries
1166
+	 *
1167
+	 * @param EE_Change_Log $logA
1168
+	 * @param EE_Change_Log $logB
1169
+	 * @return int
1170
+	 * @throws EE_Error
1171
+	 * @throws ReflectionException
1172
+	 */
1173
+	protected function _sort_logs_again($logA, $logB)
1174
+	{
1175
+		$timeA = $logA->get_raw('LOG_time');
1176
+		$timeB = $logB->get_raw('LOG_time');
1177
+		if ($timeA == $timeB) {
1178
+			return 0;
1179
+		}
1180
+		$comparison = $timeA < $timeB ? -1 : 1;
1181
+		if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1182
+			return $comparison * -1;
1183
+		}
1184
+		return $comparison;
1185
+	}
1186
+
1187
+
1188
+	/**
1189
+	 * @throws EE_Error
1190
+	 * @throws ReflectionException
1191
+	 */
1192
+	protected function _payment_log_details()
1193
+	{
1194
+		EE_Registry::instance()->load_model('Change_Log');
1195
+		/** @var $payment_log EE_Change_Log */
1196
+		$payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1197
+		$payment_method = null;
1198
+		$transaction = null;
1199
+		if ($payment_log instanceof EE_Change_Log) {
1200
+			if ($payment_log->object() instanceof EE_Payment) {
1201
+				$payment_method = $payment_log->object()->payment_method();
1202
+				$transaction = $payment_log->object()->transaction();
1203
+			} elseif ($payment_log->object() instanceof EE_Payment_Method) {
1204
+				$payment_method = $payment_log->object();
1205
+			} elseif ($payment_log->object() instanceof EE_Transaction) {
1206
+				$transaction = $payment_log->object();
1207
+				$payment_method = $transaction->payment_method();
1208
+			}
1209
+		}
1210
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1211
+			EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1212
+			array(
1213
+				'payment_log'    => $payment_log,
1214
+				'payment_method' => $payment_method,
1215
+				'transaction'    => $transaction,
1216
+			),
1217
+			true
1218
+		);
1219
+		$this->display_admin_page_with_no_sidebar();
1220
+	}
1221 1221
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
             foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
196 196
                 $template_args = isset($config['template_args']) ? $config['template_args'] : array();
197 197
                 $template_args['admin_page_obj'] = $this;
198
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
198
+                $all_pmt_help_tabs_config[$help_tab_name] = array(
199 199
                     'title'   => $config['title'],
200 200
                     'content' => EEH_Template::display_template(
201
-                        $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
201
+                        $payment_method_type->file_folder().'help_tabs/'.$config['filename'].'.help_tab.php',
202 202
                         $template_args,
203 203
                         true
204 204
                     ),
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         wp_enqueue_style('espresso-ui-theme');
242 242
         wp_register_style(
243 243
             'espresso_payments',
244
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
244
+            EE_PAYMENTS_ASSETS_URL.'ee-payments.css',
245 245
             [],
246 246
             EVENT_ESPRESSO_VERSION
247 247
         );
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         wp_enqueue_script('ee-text-links');
251 251
         wp_enqueue_script(
252 252
             'espresso_payments',
253
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
253
+            EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js',
254 254
             ['ee-datepicker'],
255 255
             EVENT_ESPRESSO_VERSION,
256 256
             true
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
             }
306 306
             // check for any active pms of that type
307 307
             $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
308
-            if (! $payment_method instanceof EE_Payment_Method) {
308
+            if ( ! $payment_method instanceof EE_Payment_Method) {
309 309
                 $payment_method = EE_Payment_Method::new_instance(
310 310
                     array(
311 311
                         'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
                     )
316 316
                 );
317 317
             }
318
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
318
+            $payment_methods[$payment_method->slug()] = $payment_method;
319 319
         }
320 320
         $payment_methods = apply_filters(
321 321
             'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
             if ($payment_method instanceof EE_Payment_Method) {
326 326
                 $this->addMetaBox(
327 327
                     // html id
328
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
328
+                    'espresso_'.$payment_method->slug().'_payment_settings',
329 329
                     // title
330 330
                     sprintf(esc_html__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
331 331
                     // callback
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
                     array('payment_method' => $payment_method)
341 341
                 );
342 342
                 // setup for tabbed content
343
-                $tabs[ $payment_method->slug() ] = array(
343
+                $tabs[$payment_method->slug()] = array(
344 344
                     'label' => $payment_method->admin_name(),
345 345
                     'class' => $payment_method->active() ? 'gateway-active' : '',
346
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
346
+                    'href'  => 'espresso_'.$payment_method->slug().'_payment_settings',
347 347
                     'title' => esc_html__('Modify this Payment Method', 'event_espresso'),
348 348
                     'slug'  => $payment_method->slug(),
349 349
                     'icon'  => $payment_method->active()
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
         /** @var EE_Payment_Method $payment_method */
380 380
         $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
381 381
         // if that didn't work or wasn't provided, find another way to select the current pm
382
-        if (! $this->_verify_payment_method($payment_method)) {
382
+        if ( ! $this->_verify_payment_method($payment_method)) {
383 383
             // like, looking for an active one
384 384
             $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
385 385
             // test that one as well
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
     {
432 432
         $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
433 433
             ? $metabox['args']['payment_method'] : null;
434
-        if (! $payment_method instanceof EE_Payment_Method) {
434
+        if ( ! $payment_method instanceof EE_Payment_Method) {
435 435
             throw new EE_Error(
436 436
                 esc_html__(
437 437
                     'Payment method metabox setup incorrectly. No Payment method object was supplied',
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
             if ($form->form_data_present_in($this->_req_data)) {
447 447
                 $form->receive_form_submission($this->_req_data);
448 448
             }
449
-            echo wp_kses($form->form_open() . $form->get_html_and_js() . $form->form_close(), AllowedTags::getWithFormTags());
449
+            echo wp_kses($form->form_open().$form->get_html_and_js().$form->form_close(), AllowedTags::getWithFormTags());
450 450
         } else {
451 451
             echo wp_kses($this->_activate_payment_method_button($payment_method)->get_html_and_js(), AllowedTags::getWithFormTags());
452 452
         }
@@ -463,13 +463,13 @@  discard block
 block discarded – undo
463 463
      */
464 464
     protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method = null)
465 465
     {
466
-        if (! $payment_method instanceof EE_Payment_Method) {
466
+        if ( ! $payment_method instanceof EE_Payment_Method) {
467 467
             return new EE_Form_Section_Proper();
468 468
         }
469 469
         return new EE_Form_Section_Proper(
470 470
             array(
471
-                'name'            => $payment_method->slug() . '_settings_form',
472
-                'html_id'         => $payment_method->slug() . '_settings_form',
471
+                'name'            => $payment_method->slug().'_settings_form',
472
+                'html_id'         => $payment_method->slug().'_settings_form',
473 473
                 'action'          => EE_Admin_Page::add_query_args_and_nonce(
474 474
                     array(
475 475
                         'action'         => 'update_payment_method',
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
                                     'important-notice'
518 518
                                 )
519 519
                             )
520
-                        ) .
520
+                        ).
521 521
                         EEH_HTML::td(
522 522
                             EEH_HTML::strong(
523 523
                                 esc_html__(
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
      */
553 553
     protected function _currency_support(EE_Payment_Method $payment_method)
554 554
     {
555
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
555
+        if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
556 556
             return new EE_Form_Section_HTML(
557 557
                 EEH_HTML::table(
558 558
                     EEH_HTML::tr(
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                                     'important-notice'
565 565
                                 )
566 566
                             )
567
-                        ) .
567
+                        ).
568 568
                         EEH_HTML::td(
569 569
                             EEH_HTML::strong(
570 570
                                 sprintf(
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
         $update_button = new EE_Submit_Input(
647 647
             array(
648 648
                 'name'       => 'submit',
649
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
649
+                'html_id'    => 'save_'.$payment_method->slug().'_settings',
650 650
                 'default'    => sprintf(
651 651
                     esc_html__('Update %s Payment Settings', 'event_espresso'),
652 652
                     $payment_method->admin_name()
@@ -656,9 +656,9 @@  discard block
 block discarded – undo
656 656
         );
657 657
         return new EE_Form_Section_HTML(
658 658
             EEH_HTML::table(
659
-                EEH_HTML::no_row(EEH_HTML::br(2)) .
659
+                EEH_HTML::no_row(EEH_HTML::br(2)).
660 660
                 EEH_HTML::tr(
661
-                    EEH_HTML::th(esc_html__('Update Settings', 'event_espresso')) .
661
+                    EEH_HTML::th(esc_html__('Update Settings', 'event_espresso')).
662 662
                     EEH_HTML::td(
663 663
                         $update_button->get_html_for_input()
664 664
                     )
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
         return new EE_Form_Section_HTML(
685 685
             EEH_HTML::table(
686 686
                 EEH_HTML::tr(
687
-                    EEH_HTML::th(esc_html__('Deactivate Payment Method', 'event_espresso')) .
687
+                    EEH_HTML::th(esc_html__('Deactivate Payment Method', 'event_espresso')).
688 688
                     EEH_HTML::td(
689 689
                         EEH_HTML::link(
690 690
                             EE_Admin_Page::add_query_args_and_nonce(
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
                             ),
697 697
                             $link_text_and_title,
698 698
                             $link_text_and_title,
699
-                            'deactivate_' . $payment_method->slug(),
699
+                            'deactivate_'.$payment_method->slug(),
700 700
                             'button button--secondary'
701 701
                         )
702 702
                     )
@@ -722,8 +722,8 @@  discard block
 block discarded – undo
722 722
         );
723 723
         return new EE_Form_Section_Proper(
724 724
             array(
725
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
726
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
725
+                'name'            => 'activate_'.$payment_method->slug().'_settings_form',
726
+                'html_id'         => 'activate_'.$payment_method->slug().'_settings_form',
727 727
                 'action'          => '#',
728 728
                 'layout_strategy' => new EE_Admin_Two_Column_Layout(),
729 729
                 'subsections'     => apply_filters(
@@ -739,11 +739,11 @@  discard block
 block discarded – undo
739 739
                                         '',
740 740
                                         'colspan="2"'
741 741
                                     )
742
-                                ) .
742
+                                ).
743 743
                                 EEH_HTML::tr(
744 744
                                     EEH_HTML::th(
745 745
                                         EEH_HTML::label(esc_html__('Click to Activate ', 'event_espresso'))
746
-                                    ) .
746
+                                    ).
747 747
                                     EEH_HTML::td(
748 748
                                         EEH_HTML::link(
749 749
                                             EE_Admin_Page::add_query_args_and_nonce(
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
                                             ),
756 756
                                             $link_text_and_title,
757 757
                                             $link_text_and_title,
758
-                                            'activate_' . $payment_method->slug(),
758
+                                            'activate_'.$payment_method->slug(),
759 759
                                             'button button--primary-alt'
760 760
                                         )
761 761
                                     )
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
         return new EE_Form_Section_HTML(
782 782
             EEH_HTML::table(
783 783
                 EEH_HTML::tr(
784
-                    EEH_HTML::th() .
784
+                    EEH_HTML::th().
785 785
                     EEH_HTML::td(
786 786
                         EEH_HTML::p(esc_html__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
787 787
                     )
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
                 }
873 873
             }
874 874
             // if we couldn't find the correct payment method type...
875
-            if (! $correct_pmt_form_to_use) {
875
+            if ( ! $correct_pmt_form_to_use) {
876 876
                 EE_Error::add_error(
877 877
                     esc_html__(
878 878
                         "We could not find which payment method type your form submission related to. Please contact support",
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
             $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
888 888
             if ($correct_pmt_form_to_use->is_valid()) {
889 889
                 $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
890
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
890
+                if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) {
891 891
                     throw new EE_Error(
892 892
                         sprintf(
893 893
                             esc_html__(
@@ -1082,7 +1082,7 @@  discard block
 block discarded – undo
1082 1082
         }
1083 1083
         // take into account search
1084 1084
         if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1085
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1085
+            $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%');
1086 1086
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1087 1087
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1088 1088
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
@@ -1103,8 +1103,8 @@  discard block
 block discarded – undo
1103 1103
             $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1104 1104
             $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1105 1105
             // make sure our timestamps start and end right at the boundaries for each day
1106
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1107
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1106
+            $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
1107
+            $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59';
1108 1108
             // convert to timestamps
1109 1109
             $start_date = strtotime($start_date);
1110 1110
             $end_date = strtotime($end_date);
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
                 date('Y-m-d H:i:s', $start_date),
1118 1118
                 'Y-m-d H:i:s'
1119 1119
             );
1120
-            $end_date   = EEM_Change_Log::instance()->convert_datetime_for_query(
1120
+            $end_date = EEM_Change_Log::instance()->convert_datetime_for_query(
1121 1121
                 'LOG_time',
1122 1122
                 date('Y-m-d H:i:s', $end_date),
1123 1123
                 'Y-m-d H:i:s'
@@ -1136,23 +1136,23 @@  discard block
 block discarded – undo
1136 1136
             $query_params['order_by'] = array('LOG_time' => 'DESC');
1137 1137
         }
1138 1138
         $offset = ($current_page - 1) * $per_page;
1139
-        if (! isset($this->_req_data['download_results'])) {
1139
+        if ( ! isset($this->_req_data['download_results'])) {
1140 1140
             $query_params['limit'] = array($offset, $per_page);
1141 1141
         }
1142 1142
         // now they've requested to instead just download the file instead of viewing it.
1143 1143
         if (isset($this->_req_data['download_results'])) {
1144 1144
             $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1145 1145
             header('Content-Disposition: attachment');
1146
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1146
+            header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url()));
1147 1147
             echo '<h1> '
1148 1148
                 . sprintf(
1149 1149
                     esc_html__('Payment Logs for %1$s', 'event_espresso'),
1150 1150
                     esc_url_raw(site_url())
1151 1151
                 )
1152 1152
                 . '</h1 >';
1153
-            echo '<h3>' . esc_html__('Query:', 'event_espresso') . '</h3>';
1153
+            echo '<h3>'.esc_html__('Query:', 'event_espresso').'</h3>';
1154 1154
             echo esc_html(var_export($query_params, true));
1155
-            echo '<h3>' . esc_html__('Results:', 'event_espresso') . '</h3>';
1155
+            echo '<h3>'.esc_html__('Results:', 'event_espresso').'</h3>';
1156 1156
             echo esc_html(var_export($wpdb_results, true));
1157 1157
             die;
1158 1158
         }
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
             }
1209 1209
         }
1210 1210
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1211
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1211
+            EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php',
1212 1212
             array(
1213 1213
                 'payment_log'    => $payment_log,
1214 1214
                 'payment_method' => $payment_method,
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/templates/receipt_body.template.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -64,16 +64,16 @@  discard block
 block discarded – undo
64 64
             <h3 class="section-title event-name">
65 65
                 <img class="icon" src="<?php echo EE_IMAGES_URL . 'calendar_year-24x24.png'; ?>">
66 66
                 <?php
67
-                esc_html_e(
68
-                    "Event Name:",
69
-                    "event_espresso"
70
-                ) ?>
67
+				esc_html_e(
68
+					"Event Name:",
69
+					"event_espresso"
70
+				) ?>
71 71
                 <span class="plain-text"><?php echo wp_kses($event->name(), AllowedTags::getAllowedTags()); ?></span>
72 72
                 <span class="small-text link">
73 73
                 [ <a href='<?php echo esc_url_raw($event->get_permalink()) ?>'><?php esc_html_e(
74
-                    'view',
75
-                    'event_espresso'
76
-                ); ?></a> ]
74
+					'view',
75
+					'event_espresso'
76
+				); ?></a> ]
77 77
             </span>
78 78
             </h3>
79 79
             <?php if (strlen($event->description() > 1)) { ?>
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
             <?php } ?>
82 82
             <ul class="tickets-per-event">
83 83
                 <?php
84
-                foreach ($ticket_line_items_per_event[ $event_id ] as $line_item_id => $line_item) {
85
-                    $ticket       = $line_item->ticket();
86
-                    $taxable_html = $ticket->taxable()
87
-                        ? '*'
88
-                        : '';
89
-                    $subitems     = $line_item->children();
90
-                    $ticket_uses  = $ticket->get_pretty('TKT_uses', esc_html__("any", "event_espresso"));
91
-                    ?>
84
+				foreach ($ticket_line_items_per_event[ $event_id ] as $line_item_id => $line_item) {
85
+					$ticket       = $line_item->ticket();
86
+					$taxable_html = $ticket->taxable()
87
+						? '*'
88
+						: '';
89
+					$subitems     = $line_item->children();
90
+					$ticket_uses  = $ticket->get_pretty('TKT_uses', esc_html__("any", "event_espresso"));
91
+					?>
92 92
                     <li class="event-ticket">
93 93
                         <div class="ticket-details">
94 94
                             <table class="invoice-amount">
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
                                         <th class="name-column"><?php esc_html_e("Ticket", "event_espresso"); ?></th>
98 98
                                         <th colspan="2" class="desc-column">
99 99
                                             <?php
100
-                                            esc_html_e("Description", 'event_espresso'); ?>
100
+											esc_html_e("Description", 'event_espresso'); ?>
101 101
                                         </th>
102 102
                                         <th class="number-column item_r">
103 103
                                             <?php esc_html_e("Quantity", "event_espresso"); ?>
@@ -112,20 +112,20 @@  discard block
 block discarded – undo
112 112
                                 </thead>
113 113
                                 <tbody>
114 114
                                     <?php
115
-                                    if (count($subitems) < 2) { ?>
115
+									if (count($subitems) < 2) { ?>
116 116
                                         <tr class="item">
117 117
                                             <td><?php echo esc_html($line_item->name() . $taxable_html); ?></td>
118 118
                                             <td colspan="2">
119 119
                                                 <?php echo esc_html($line_item->desc()); ?>
120 120
                                                 <p class="ticket-note">
121 121
                                                     <?php
122
-                                                    echo sprintf(
123
-                                                        esc_html__(
124
-                                                            'This ticket can be used once at %s of the dates/times below.',
125
-                                                            'event_espresso'
126
-                                                        ),
127
-                                                        $ticket_uses
128
-                                                    ); ?>
122
+													echo sprintf(
123
+														esc_html__(
124
+															'This ticket can be used once at %s of the dates/times below.',
125
+															'event_espresso'
126
+														),
127
+														$ticket_uses
128
+													); ?>
129 129
                                                 </p>
130 130
                                             </td>
131 131
                                             <td class="item_r">
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                                             </td>
140 140
                                         </tr>
141 141
                                         <?php
142
-                                    } else { ?>
142
+									} else { ?>
143 143
                                         <tr class="item">
144 144
                                             <td class="aln-left">
145 145
                                                 <?php echo esc_html($line_item->name() . $taxable_html); ?>
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
                                                 <?php echo esc_html($line_item->desc()); ?>
149 149
                                                 <p class="ticket-note">
150 150
                                                     <?php
151
-                                                    echo sprintf(
152
-                                                        esc_html__(
153
-                                                            'This ticket can be used once at %s of the dates/times below.',
154
-                                                            'event_espresso'
155
-                                                        ),
156
-                                                        $ticket_uses
157
-                                                    ); ?>
151
+													echo sprintf(
152
+														esc_html__(
153
+															'This ticket can be used once at %s of the dates/times below.',
154
+															'event_espresso'
155
+														),
156
+														$ticket_uses
157
+													); ?>
158 158
                                                 </p>
159 159
                                             </td>
160 160
                                             <td class="item_c">
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
                                             </td>
169 169
                                         </tr>
170 170
                                         <?php
171
-                                        foreach ($subitems as $sub_line_item) {
172
-                                            $is_percent = $sub_line_item->is_percent(); ?>
171
+										foreach ($subitems as $sub_line_item) {
172
+											$is_percent = $sub_line_item->is_percent(); ?>
173 173
                                             <tr class="subitem-row">
174 174
                                                 <td class="subitem">
175 175
                                                     <?php echo esc_html($sub_line_item->name()); ?>
@@ -182,15 +182,15 @@  discard block
 block discarded – undo
182 182
                                                 </td>
183 183
                                                 <td class="item_c">
184 184
                                                     <?php echo ($is_percent
185
-                                                        ? $sub_line_item->percent() . "%"
186
-                                                        : $sub_line_item->unit_price_no_code()); ?>
185
+														? $sub_line_item->percent() . "%"
186
+														: $sub_line_item->unit_price_no_code()); ?>
187 187
                                                 </td>
188 188
                                                 <td class="item_r">
189 189
                                                     <?php echo wp_kses($sub_line_item->total_no_code(), AllowedTags::getAllowedTags()); ?>
190 190
                                                 </td>
191 191
                                             </tr>
192 192
                                             <?php
193
-                                        } ?>
193
+										} ?>
194 194
                                         <tr class="total_tr odd">
195 195
                                             <td colspan="4"></td>
196 196
                                             <td class="total" nowrap="nowrap">
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                                             </td>
202 202
                                         </tr>
203 203
                                         <?php
204
-                                    } ?>
204
+									} ?>
205 205
                                 </tbody>
206 206
                             </table>
207 207
 
@@ -214,50 +214,50 @@  discard block
 block discarded – undo
214 214
                                              src="<?php echo esc_url_raw(EE_IMAGES_URL . 'clock-16x16.png'); ?>"
215 215
                                         >
216 216
                                         <?php
217
-                                        echo _n(
218
-                                            "Date/Time:",
219
-                                            "Dates/Times:",
220
-                                            count($ticket->datetimes()),
221
-                                            'event_espresso'
222
-                                        ); ?></h4>
217
+										echo _n(
218
+											"Date/Time:",
219
+											"Dates/Times:",
220
+											count($ticket->datetimes()),
221
+											'event_espresso'
222
+										); ?></h4>
223 223
                                     <ul class="event-dates">
224 224
                                         <?php
225
-                                        foreach ($ticket->datetimes_ordered() as $datetime) {
226
-                                            /* @var $datetime EE_Datetime */ ?>
225
+										foreach ($ticket->datetimes_ordered() as $datetime) {
226
+											/* @var $datetime EE_Datetime */ ?>
227 227
                                             <li><?php
228
-                                                echo ($datetime->name()
229
-                                                    ? '<b>' . esc_html($datetime->name()) . ' </b>'
230
-                                                    : '');
231
-                                                echo sprintf(
232
-                                                    esc_html__("%s - %s (%s)", "event_espresso"),
233
-                                                    $datetime->start_date_and_time(),
234
-                                                    $datetime->end_date_and_time(),
235
-                                                    $datetime->get_timezone()
236
-                                                );
237
-                                                echo ($datetime->description()
238
-                                                    ? '<p class="ticket-note">' . wp_kses($datetime->description(), AllowedTags::getAllowedTags()) . '</p>'
239
-                                                    : ''); ?></li>
228
+												echo ($datetime->name()
229
+													? '<b>' . esc_html($datetime->name()) . ' </b>'
230
+													: '');
231
+												echo sprintf(
232
+													esc_html__("%s - %s (%s)", "event_espresso"),
233
+													$datetime->start_date_and_time(),
234
+													$datetime->end_date_and_time(),
235
+													$datetime->get_timezone()
236
+												);
237
+												echo ($datetime->description()
238
+													? '<p class="ticket-note">' . wp_kses($datetime->description(), AllowedTags::getAllowedTags()) . '</p>'
239
+													: ''); ?></li>
240 240
                                             <?php
241
-                                        } ?>
241
+										} ?>
242 242
                                     </ul>
243 243
                                 </div>
244 244
                                 <?php
245
-                                if ($event->venues()) { ?>
245
+								if ($event->venues()) { ?>
246 246
                                     <div class="ticket-place-details">
247 247
                                         <h4 class="sub-section-title no-bottom-margin">
248 248
                                             <img class="icon" src="<?php
249
-                                            echo esc_url_raw(EE_IMAGES_URL . 'location-pin-16x16.png'); ?>"
249
+											echo esc_url_raw(EE_IMAGES_URL . 'location-pin-16x16.png'); ?>"
250 250
                                             >
251 251
                                             <?php
252
-                                            echo _n(
253
-                                                "Venue:",
254
-                                                "Venues:",
255
-                                                count($event->venues()),
256
-                                                'event_espresso'
257
-                                            ); ?></h4>
252
+											echo _n(
253
+												"Venue:",
254
+												"Venues:",
255
+												count($event->venues()),
256
+												'event_espresso'
257
+											); ?></h4>
258 258
                                         <ul class="event-venues">
259 259
                                             <?php
260
-                                            foreach ($event->venues() as $venue) { ?>
260
+											foreach ($event->venues() as $venue) { ?>
261 261
                                                 <li>
262 262
                                                     <?php echo esc_html($venue->name()) ?>
263 263
                                                     <span class="small-text">
@@ -272,15 +272,15 @@  discard block
 block discarded – undo
272 272
                                         </ul>
273 273
                                     </div>
274 274
                                     <?php
275
-                                } ?>
275
+								} ?>
276 276
                             </div>
277 277
                             <div class="ticket-registrations-area">
278 278
                                 <h4 class="sub-section-title">
279 279
                                     <img class="icon" src="<?php
280
-                                    echo esc_url_raw(EE_IMAGES_URL . 'users-16x16.png'); ?>"
280
+									echo esc_url_raw(EE_IMAGES_URL . 'users-16x16.png'); ?>"
281 281
                                     >
282 282
                                     <?php
283
-                                    echo esc_html__("Registration Details", "event_espresso"); ?>
283
+									echo esc_html__("Registration Details", "event_espresso"); ?>
284 284
                                     <span class="small-text link">[
285 285
                                 <a class="print_button noPrint" href="<?php echo esc_url_raw($edit_reg_info_url); ?>">
286 286
                                     <?php esc_html_e('edit', 'event_espresso'); ?>
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
                                 </h4>
291 291
                                 <ul class="ticket-registrations-list">
292 292
                                     <?php
293
-                                    foreach ($registrations_per_line_item[ $line_item_id ] as $registration) {
294
-                                        /* @var $registration EE_Registration */
295
-                                        $attendee = $registration->attendee();
296
-                                        $answers  = $registration->answers(
297
-                                            ['order_by' => ['Question.Question_Group_Question.QGQ_order' => 'ASC']]
298
-                                        ); ?>
293
+									foreach ($registrations_per_line_item[ $line_item_id ] as $registration) {
294
+										/* @var $registration EE_Registration */
295
+										$attendee = $registration->attendee();
296
+										$answers  = $registration->answers(
297
+											['order_by' => ['Question.Question_Group_Question.QGQ_order' => 'ASC']]
298
+										); ?>
299 299
                                         <li class="ticket-registration">
300 300
                                             <table class="registration-details">
301 301
                                                 <tr class="odd">
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                                                     </td>
311 311
                                                 </tr>
312 312
                                                 <?php
313
-                                                foreach ($event->question_groups() as $question_group) { ?>
313
+												foreach ($event->question_groups() as $question_group) { ?>
314 314
                                                     <tr>
315 315
                                                         <th>
316 316
                                                             <?php $question_group->e('QSG_name'); ?>
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
                                                         <td></td>
319 319
                                                     </tr>
320 320
                                                     <?php $has_personal_info = false;
321
-                                                    foreach ($question_group->questions() as $question) {
322
-                                                        if (in_array($question->system_ID(), $questions_to_skip)) {
323
-                                                            $has_personal_info = true;
324
-                                                            continue;
325
-                                                        }
326
-                                                        ?>
321
+													foreach ($question_group->questions() as $question) {
322
+														if (in_array($question->system_ID(), $questions_to_skip)) {
323
+															$has_personal_info = true;
324
+															continue;
325
+														}
326
+														?>
327 327
                                                         <tr>
328 328
                                                             <th>
329 329
                                                                 <?php echo wp_kses($question->display_text(), AllowedTags::getAllowedTags()); ?>
@@ -333,26 +333,26 @@  discard block
 block discarded – undo
333 333
                                                             </td>
334 334
                                                         </tr>
335 335
                                                     <?php }
336
-                                                    if ($has_personal_info) { ?>
336
+													if ($has_personal_info) { ?>
337 337
                                                         <tr>
338 338
                                                             <th><?php esc_html_e('Attendee', 'event_espresso'); ?></th>
339 339
                                                             <td>
340 340
                                                                 <?php
341
-                                                                echo sprintf(
342
-                                                                    esc_html__('%s (%s)', "event_espresso"),
343
-                                                                    esc_html($attendee->full_name()),
344
-                                                                    sanitize_email($attendee->email())
345
-                                                                ) ?>
341
+																echo sprintf(
342
+																	esc_html__('%s (%s)', "event_espresso"),
343
+																	esc_html($attendee->full_name()),
344
+																	sanitize_email($attendee->email())
345
+																) ?>
346 346
                                                             </td>
347 347
                                                         </tr>
348 348
                                                         <?php
349
-                                                    }
350
-                                                }
351
-                                                ?>
349
+													}
350
+												}
351
+												?>
352 352
                                             </table>
353 353
                                         </li>
354 354
                                         <?php
355
-                                    } ?>
355
+									} ?>
356 356
                                 </ul>
357 357
                             </div>
358 358
                         </div>
@@ -400,10 +400,10 @@  discard block
 block discarded – undo
400 400
     <div class="grand-total-dv">
401 401
         <h2 class="grand-total">
402 402
             <?php
403
-            printf(
404
-                esc_html__("Grand Total: %s", "event_espresso"),
405
-                EEH_Template::format_currency($total_cost)
406
-            ); ?>
403
+			printf(
404
+				esc_html__("Grand Total: %s", "event_espresso"),
405
+				EEH_Template::format_currency($total_cost)
406
+			); ?>
407 407
         </h2>
408 408
     </div>
409 409
     <div class="payment-dv">
@@ -422,13 +422,13 @@  discard block
 block discarded – undo
422 422
             </thead>
423 423
             <tbody>
424 424
                 <?php
425
-                $c = false;
426
-                if (! empty($payments)) {
427
-                    foreach ($payments as $payment) {
428
-                        /* @var $payment EE_Payment */ ?>
425
+				$c = false;
426
+				if (! empty($payments)) {
427
+					foreach ($payments as $payment) {
428
+						/* @var $payment EE_Payment */ ?>
429 429
                         <tr class='item <?php echo(($c = ! $c)
430
-                            ? ' odd'
431
-                            : '') ?>'
430
+							? ' odd'
431
+							: '') ?>'
432 432
                         >
433 433
                             <td><?php $payment->e('PAY_gateway') ?></td>
434 434
                             <td><?php echo esc_html($payment->timestamp()); ?></td>
@@ -440,14 +440,14 @@  discard block
 block discarded – undo
440 440
                             </td>
441 441
                         </tr>
442 442
                     <?php }
443
-                } else { ?>
443
+				} else { ?>
444 444
                     <tr class='item'>
445 445
                         <td class='aln-cntr' colspan="6">
446 446
                             <?php
447
-                            esc_html_e(
448
-                                "No approved payments have been received.",
449
-                                'event_espresso'
450
-                            ) ?>
447
+							esc_html_e(
448
+								"No approved payments have been received.",
449
+								'event_espresso'
450
+							) ?>
451 451
                         </td>
452 452
                     </tr>
453 453
                 <?php } ?>
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
             <?php if ($venues_for_events) { ?>
485 485
                 <h2>
486 486
                     <?php
487
-                    echo _n("Venue Details:", "Venues Details:", count($venues_for_events), "event_espresso"); ?>
487
+					echo _n("Venue Details:", "Venues Details:", count($venues_for_events), "event_espresso"); ?>
488 488
                 </h2>
489 489
                 <table class="venue-list">
490 490
                     <?php foreach ($venues_for_events as $venue) { ?>
@@ -501,9 +501,9 @@  discard block
 block discarded – undo
501 501
                             <?php if ($venue->enable_for_gmap()) { ?>
502 502
                                 <td class="venue-details-part venue-image-dv">
503 503
                                     <?php echo wp_kses(
504
-                                        EEH_Venue_View::espresso_google_static_map($venue),
505
-                                        AllowedTags::getAllowedTags()
506
-                                    ); ?>
504
+										EEH_Venue_View::espresso_google_static_map($venue),
505
+										AllowedTags::getAllowedTags()
506
+									); ?>
507 507
                                 </td>
508 508
                             <?php } ?>
509 509
                         </tr>
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     <div class="events">
63 63
         <?php foreach ($events_for_txn as $event_id => $event) { ?>
64 64
             <h3 class="section-title event-name">
65
-                <img class="icon" src="<?php echo EE_IMAGES_URL . 'calendar_year-24x24.png'; ?>">
65
+                <img class="icon" src="<?php echo EE_IMAGES_URL.'calendar_year-24x24.png'; ?>">
66 66
                 <?php
67 67
                 esc_html_e(
68 68
                     "Event Name:",
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             <?php } ?>
82 82
             <ul class="tickets-per-event">
83 83
                 <?php
84
-                foreach ($ticket_line_items_per_event[ $event_id ] as $line_item_id => $line_item) {
84
+                foreach ($ticket_line_items_per_event[$event_id] as $line_item_id => $line_item) {
85 85
                     $ticket       = $line_item->ticket();
86 86
                     $taxable_html = $ticket->taxable()
87 87
                         ? '*'
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
                                     <?php
115 115
                                     if (count($subitems) < 2) { ?>
116 116
                                         <tr class="item">
117
-                                            <td><?php echo esc_html($line_item->name() . $taxable_html); ?></td>
117
+                                            <td><?php echo esc_html($line_item->name().$taxable_html); ?></td>
118 118
                                             <td colspan="2">
119 119
                                                 <?php echo esc_html($line_item->desc()); ?>
120 120
                                                 <p class="ticket-note">
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
                                                 <?php echo wp_kses($line_item->unit_price_no_code(), AllowedTags::getAllowedTags()); ?>
136 136
                                             </td>
137 137
                                             <td class="item_r">
138
-                                                <?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags());  ?>
138
+                                                <?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags()); ?>
139 139
                                             </td>
140 140
                                         </tr>
141 141
                                         <?php
142 142
                                     } else { ?>
143 143
                                         <tr class="item">
144 144
                                             <td class="aln-left">
145
-                                                <?php echo esc_html($line_item->name() . $taxable_html); ?>
145
+                                                <?php echo esc_html($line_item->name().$taxable_html); ?>
146 146
                                             </td>
147 147
                                             <td colspan="2">
148 148
                                                 <?php echo esc_html($line_item->desc()); ?>
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                                                 </td>
183 183
                                                 <td class="item_c">
184 184
                                                     <?php echo ($is_percent
185
-                                                        ? $sub_line_item->percent() . "%"
185
+                                                        ? $sub_line_item->percent()."%"
186 186
                                                         : $sub_line_item->unit_price_no_code()); ?>
187 187
                                                 </td>
188 188
                                                 <td class="item_r">
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
                                 <div class="ticket-time-details">
212 212
                                     <h4 class="sub-section-title no-bottom-margin">
213 213
                                         <img class="icon"
214
-                                             src="<?php echo esc_url_raw(EE_IMAGES_URL . 'clock-16x16.png'); ?>"
214
+                                             src="<?php echo esc_url_raw(EE_IMAGES_URL.'clock-16x16.png'); ?>"
215 215
                                         >
216 216
                                         <?php
217 217
                                         echo _n(
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                                             /* @var $datetime EE_Datetime */ ?>
227 227
                                             <li><?php
228 228
                                                 echo ($datetime->name()
229
-                                                    ? '<b>' . esc_html($datetime->name()) . ' </b>'
229
+                                                    ? '<b>'.esc_html($datetime->name()).' </b>'
230 230
                                                     : '');
231 231
                                                 echo sprintf(
232 232
                                                     esc_html__("%s - %s (%s)", "event_espresso"),
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
                                                     $datetime->get_timezone()
236 236
                                                 );
237 237
                                                 echo ($datetime->description()
238
-                                                    ? '<p class="ticket-note">' . wp_kses($datetime->description(), AllowedTags::getAllowedTags()) . '</p>'
238
+                                                    ? '<p class="ticket-note">'.wp_kses($datetime->description(), AllowedTags::getAllowedTags()).'</p>'
239 239
                                                     : ''); ?></li>
240 240
                                             <?php
241 241
                                         } ?>
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
                                     <div class="ticket-place-details">
247 247
                                         <h4 class="sub-section-title no-bottom-margin">
248 248
                                             <img class="icon" src="<?php
249
-                                            echo esc_url_raw(EE_IMAGES_URL . 'location-pin-16x16.png'); ?>"
249
+                                            echo esc_url_raw(EE_IMAGES_URL.'location-pin-16x16.png'); ?>"
250 250
                                             >
251 251
                                             <?php
252 252
                                             echo _n(
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                             <div class="ticket-registrations-area">
278 278
                                 <h4 class="sub-section-title">
279 279
                                     <img class="icon" src="<?php
280
-                                    echo esc_url_raw(EE_IMAGES_URL . 'users-16x16.png'); ?>"
280
+                                    echo esc_url_raw(EE_IMAGES_URL.'users-16x16.png'); ?>"
281 281
                                     >
282 282
                                     <?php
283 283
                                     echo esc_html__("Registration Details", "event_espresso"); ?>
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
                                 </h4>
291 291
                                 <ul class="ticket-registrations-list">
292 292
                                     <?php
293
-                                    foreach ($registrations_per_line_item[ $line_item_id ] as $registration) {
293
+                                    foreach ($registrations_per_line_item[$line_item_id] as $registration) {
294 294
                                         /* @var $registration EE_Registration */
295 295
                                         $attendee = $registration->attendee();
296 296
                                         $answers  = $registration->answers(
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
             <tbody>
424 424
                 <?php
425 425
                 $c = false;
426
-                if (! empty($payments)) {
426
+                if ( ! empty($payments)) {
427 427
                     foreach ($payments as $payment) {
428 428
                         /* @var $payment EE_Payment */ ?>
429 429
                         <tr class='item <?php echo(($c = ! $c)
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowStandard.php 1 patch
Indentation   +364 added lines, -364 removed lines patch added patch discarded remove patch
@@ -19,368 +19,368 @@
 block discarded – undo
19 19
  */
20 20
 class TicketSelectorRowStandard extends TicketSelectorRow
21 21
 {
22
-    /**
23
-     * @var TicketDetails
24
-     */
25
-    protected $ticket_details;
26
-
27
-    /**
28
-     * @var EE_Ticket_Selector_Config
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var EE_Tax_Config
34
-     */
35
-    protected $tax_settings;
36
-
37
-    /**
38
-     * @var boolean
39
-     */
40
-    protected $prices_displayed_including_taxes;
41
-
42
-    /**
43
-     * @var int
44
-     */
45
-    protected $row;
46
-
47
-    /**
48
-     * @var int
49
-     */
50
-    protected $cols;
51
-
52
-    /**
53
-     * @var boolean
54
-     */
55
-    protected $hidden_input_qty = false;
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $ticket_datetime_classes;
61
-
62
-
63
-    /**
64
-     * TicketDetails constructor.
65
-     *
66
-     * @param TicketDetails $ticket_details
67
-     * @param EE_Tax_Config $tax_settings
68
-     * @param int           $total_tickets
69
-     * @param int           $max_attendees
70
-     * @param int           $row
71
-     * @param int           $cols
72
-     * @param boolean       $required_ticket_sold_out
73
-     * @param string        $event_status
74
-     * @param string        $ticket_datetime_classes
75
-     * @throws EE_Error
76
-     * @throws UnexpectedEntityException
77
-     */
78
-    public function __construct(
79
-        TicketDetails $ticket_details,
80
-        EE_Tax_Config $tax_settings,
81
-        $total_tickets,
82
-        $max_attendees,
83
-        $row,
84
-        $cols,
85
-        $required_ticket_sold_out,
86
-        $event_status,
87
-        $ticket_datetime_classes
88
-    ) {
89
-        $this->ticket_details = $ticket_details;
90
-        $this->template_settings = $ticket_details->getTemplateSettings();
91
-        $this->tax_settings = $tax_settings;
92
-        $this->row = $row;
93
-        $this->cols = $cols;
94
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
95
-        parent::__construct(
96
-            $ticket_details->getTicket(),
97
-            $max_attendees,
98
-            $ticket_details->getDateFormat(),
99
-            $event_status,
100
-            $required_ticket_sold_out,
101
-            $total_tickets
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     * other ticket rows will need to know if a required ticket is sold out,
108
-     * so that they are not offered for sale
109
-     *
110
-     * @return boolean
111
-     */
112
-    public function getRequiredTicketSoldOut()
113
-    {
114
-        return $this->required_ticket_sold_out;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getCols()
122
-    {
123
-        return $this->cols;
124
-    }
125
-
126
-
127
-    /**
128
-     * getHtml
129
-     *
130
-     * @return string
131
-     * @throws EE_Error
132
-     * @throws ReflectionException
133
-     */
134
-    public function getHtml()
135
-    {
136
-        $this->min = 0;
137
-        $this->max = $this->ticket->max();
138
-        $remaining = $this->ticket->remaining();
139
-        $this->setTicketMinAndMax($remaining);
140
-        // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
141
-        $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
142
-            ? $this->ticket->start_date()
143
-            : $this->required_ticket_sold_out;
144
-        $this->setTicketPriceDetails();
145
-        $this->setTicketStatusClasses($remaining);
146
-        $filtered_row_html = $this->getFilteredRowHtml();
147
-        if ($filtered_row_html !== false) {
148
-            return $filtered_row_html;
149
-        }
150
-        $ticket_selector_row_html = EEH_HTML::tr(
151
-            '',
152
-            '',
153
-            "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} "
154
-            . espresso_get_object_css_class($this->ticket)
155
-        );
156
-        $filtered_row_content = $this->getFilteredRowContents();
157
-        if ($filtered_row_content !== false) {
158
-            if ($this->max_attendees === 1) {
159
-                return $ticket_selector_row_html
160
-                       . $filtered_row_content
161
-                       . $this->ticketQtyAndIdHiddenInputs()
162
-                       . EEH_HTML::trx();
163
-            }
164
-            return $ticket_selector_row_html
165
-                   . $filtered_row_content
166
-                   . EEH_HTML::trx();
167
-        }
168
-        $this->hidden_input_qty = $this->max_attendees > 1;
169
-
170
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
171
-        $ticket_selector_row_html .= $this->ticketPriceTableCell();
172
-        $ticket_selector_row_html .= EEH_HTML::td(
173
-            '',
174
-            '',
175
-            'tckt-slctr-tbl-td-qty cntr',
176
-            '',
177
-            'headers="quantity-' . $this->EVT_ID . '"'
178
-        );
179
-        $this->setTicketStatusDisplay($remaining);
180
-        if (empty($this->ticket_status_display)) {
181
-            if ($this->max_attendees === 1) {
182
-                // only ONE attendee is allowed to register at a time
183
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
184
-            } elseif ($this->max > 0) {
185
-                $ticket_selector_row_html .= $this->ticketQuantitySelector();
186
-            }
187
-        }
188
-        $ticket_selector_row_html .= $this->ticket_status_display;
189
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
190
-        $ticket_selector_row_html .= $this->ticket_details->display(
191
-            $this->ticket_price,
192
-            $remaining,
193
-            $this->cols
194
-        );
195
-        $ticket_selector_row_html .= EEH_HTML::tdx();
196
-        $ticket_selector_row_html .= EEH_HTML::trx();
197
-
198
-
199
-        $this->row++;
200
-        return $ticket_selector_row_html;
201
-    }
202
-
203
-
204
-    /**
205
-     * getTicketPriceDetails
206
-     *
207
-     * @return void
208
-     * @throws EE_Error
209
-     */
210
-    protected function setTicketPriceDetails()
211
-    {
212
-        $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes
213
-            ? $this->ticket->get_ticket_total_with_taxes()
214
-            : $this->ticket->get_ticket_subtotal();
215
-        $this->ticket_bundle = false;
216
-        $ticket_min = $this->ticket->min();
217
-        // for ticket bundles, set min and max qty the same
218
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
219
-            $this->ticket_price *= $ticket_min;
220
-            $this->ticket_bundle = true;
221
-        }
222
-        $this->ticket_price = apply_filters(
223
-            'FHEE__ticket_selector_chart_template__ticket_price',
224
-            $this->ticket_price,
225
-            $this->ticket
226
-        );
227
-    }
228
-
229
-
230
-    /**
231
-     * ticketNameTableCell
232
-     *
233
-     * @return string
234
-     * @throws EE_Error
235
-     * @throws ReflectionException
236
-     */
237
-    protected function ticketNameTableCell()
238
-    {
239
-        $html = EEH_HTML::td(
240
-            '',
241
-            '',
242
-            'tckt-slctr-tbl-td-name',
243
-            '',
244
-            'headers="details-' . $this->EVT_ID . '"'
245
-        );
246
-        $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
247
-        $html .= $this->ticket_details->getShowHideLinks();
248
-        if ($this->ticket->required()) {
249
-            $html .= EEH_HTML::p(
250
-                apply_filters(
251
-                    'FHEE__ticket_selector_chart_template__ticket_required_message',
252
-                    esc_html__('This ticket is required and must be purchased.', 'event_espresso')
253
-                ),
254
-                '',
255
-                'ticket-required-pg'
256
-            );
257
-        }
258
-        $html .= EEH_HTML::tdx();
259
-        return $html;
260
-    }
261
-
262
-
263
-    /**
264
-     * ticketPriceTableCell
265
-     *
266
-     * @return string
267
-     * @throws EE_Error
268
-     */
269
-    protected function ticketPriceTableCell()
270
-    {
271
-        $html = '';
272
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
273
-            $html .= EEH_HTML::td(
274
-                '',
275
-                '',
276
-                'tckt-slctr-tbl-td-price jst-rght',
277
-                '',
278
-                'headers="price-' . $this->EVT_ID . '"'
279
-            );
280
-            $html .= EEH_HTML::span(
281
-                EEH_Template::format_currency($this->ticket_price),
282
-                '',
283
-                'tckt-price--nowrap'
284
-            );
285
-            $html .= $this->ticket->taxable()
286
-                ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text')
287
-                : '';
288
-            $html .= '&nbsp;';
289
-            // phpcs:disable WordPress.WP.I18n.NoEmptyStrings
290
-            $html .= EEH_HTML::span(
291
-                $this->ticket_bundle
292
-                    ? apply_filters(
293
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
294
-                        esc_html__(' / bundle', 'event_espresso')
295
-                    )
296
-                    : apply_filters(
297
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
298
-                        esc_html__('', 'event_espresso')
299
-                    ),
300
-                '',
301
-                'smaller-text no-bold'
302
-            );
303
-            $html .= '&nbsp;';
304
-            $html .= EEH_HTML::tdx();
305
-            $this->cols++;
306
-        }
307
-        return $html;
308
-    }
309
-
310
-
311
-    /**
312
-     * onlyOneAttendeeCanRegister
313
-     *
314
-     * @return string
315
-     * @throws EE_Error
316
-     */
317
-    protected function onlyOneAttendeeCanRegister()
318
-    {
319
-        $this->hidden_input_qty = false;
320
-        // display submit button since we have tickets available
321
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
322
-
323
-        $TKT   = $this->ticket->ID();
324
-        $label = esc_html__('Select this ticket', 'event_espresso');
325
-        $name  = "tkt-slctr-qty-{$this->EVT_ID}";
326
-        $class = "ticket-selector-tbl-qty-slct";
327
-        $id    = "{$class}-{$this->EVT_ID}-{$this->row}";
328
-        $checked = $this->total_tickets === 1 ? ' checked' : '';
329
-
330
-        $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
331
-        $html .= "<input type='radio'{$checked} name='{$name}' id='{$id}' class='{$class}' value='{$TKT}-1' title='' />";
332
-        return $html;
333
-    }
334
-
335
-
336
-    /**
337
-     * ticketQuantitySelector
338
-     *
339
-     * @return string
340
-     * @throws EE_Error
341
-     */
342
-    protected function ticketQuantitySelector()
343
-    {
344
-        $this->hidden_input_qty = false;
345
-        // display submit button since we have tickets available
346
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
347
-
348
-        $TKT = $this->ticket->ID();
349
-        $label = esc_html__('Quantity', 'event_espresso');
350
-        $class = 'ticket-selector-tbl-qty-slct';
351
-        $id = "{$class}-{$this->EVT_ID}-{$this->row}";
352
-
353
-        $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
354
-        $html .= "<select name='tkt-slctr-qty-{$this->EVT_ID}[{$TKT}]' id='{$id}' class='{$class}'>";
355
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
356
-        if ($this->min !== 0 && ! $this->ticket->required()) {
357
-            $html .= "<option value='0'>&nbsp;0&nbsp;</option>";
358
-        }
359
-        // offer ticket quantities from the min to the max
360
-        for ($i = $this->min; $i <= $this->max; $i++) {
361
-            $html .= "<option value='{$i}'>&nbsp;{$i}&nbsp;</option>";
362
-        }
363
-        $html .= "</select>";
364
-        return $html;
365
-    }
366
-
367
-
368
-    /**
369
-     * getHiddenInputs
370
-     *
371
-     * @return string
372
-     * @throws EE_Error
373
-     */
374
-    protected function ticketQtyAndIdHiddenInputs()
375
-    {
376
-        $html = '';
377
-        $EVT = $this->EVT_ID;
378
-        $TKT = $this->ticket->ID();
379
-        // depending on group reg we need to change the format for qty
380
-        if ($this->hidden_input_qty) {
381
-            $html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />";
382
-        }
383
-        $html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />";
384
-        return $html;
385
-    }
22
+	/**
23
+	 * @var TicketDetails
24
+	 */
25
+	protected $ticket_details;
26
+
27
+	/**
28
+	 * @var EE_Ticket_Selector_Config
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var EE_Tax_Config
34
+	 */
35
+	protected $tax_settings;
36
+
37
+	/**
38
+	 * @var boolean
39
+	 */
40
+	protected $prices_displayed_including_taxes;
41
+
42
+	/**
43
+	 * @var int
44
+	 */
45
+	protected $row;
46
+
47
+	/**
48
+	 * @var int
49
+	 */
50
+	protected $cols;
51
+
52
+	/**
53
+	 * @var boolean
54
+	 */
55
+	protected $hidden_input_qty = false;
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	protected $ticket_datetime_classes;
61
+
62
+
63
+	/**
64
+	 * TicketDetails constructor.
65
+	 *
66
+	 * @param TicketDetails $ticket_details
67
+	 * @param EE_Tax_Config $tax_settings
68
+	 * @param int           $total_tickets
69
+	 * @param int           $max_attendees
70
+	 * @param int           $row
71
+	 * @param int           $cols
72
+	 * @param boolean       $required_ticket_sold_out
73
+	 * @param string        $event_status
74
+	 * @param string        $ticket_datetime_classes
75
+	 * @throws EE_Error
76
+	 * @throws UnexpectedEntityException
77
+	 */
78
+	public function __construct(
79
+		TicketDetails $ticket_details,
80
+		EE_Tax_Config $tax_settings,
81
+		$total_tickets,
82
+		$max_attendees,
83
+		$row,
84
+		$cols,
85
+		$required_ticket_sold_out,
86
+		$event_status,
87
+		$ticket_datetime_classes
88
+	) {
89
+		$this->ticket_details = $ticket_details;
90
+		$this->template_settings = $ticket_details->getTemplateSettings();
91
+		$this->tax_settings = $tax_settings;
92
+		$this->row = $row;
93
+		$this->cols = $cols;
94
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
95
+		parent::__construct(
96
+			$ticket_details->getTicket(),
97
+			$max_attendees,
98
+			$ticket_details->getDateFormat(),
99
+			$event_status,
100
+			$required_ticket_sold_out,
101
+			$total_tickets
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 * other ticket rows will need to know if a required ticket is sold out,
108
+	 * so that they are not offered for sale
109
+	 *
110
+	 * @return boolean
111
+	 */
112
+	public function getRequiredTicketSoldOut()
113
+	{
114
+		return $this->required_ticket_sold_out;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getCols()
122
+	{
123
+		return $this->cols;
124
+	}
125
+
126
+
127
+	/**
128
+	 * getHtml
129
+	 *
130
+	 * @return string
131
+	 * @throws EE_Error
132
+	 * @throws ReflectionException
133
+	 */
134
+	public function getHtml()
135
+	{
136
+		$this->min = 0;
137
+		$this->max = $this->ticket->max();
138
+		$remaining = $this->ticket->remaining();
139
+		$this->setTicketMinAndMax($remaining);
140
+		// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
141
+		$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
142
+			? $this->ticket->start_date()
143
+			: $this->required_ticket_sold_out;
144
+		$this->setTicketPriceDetails();
145
+		$this->setTicketStatusClasses($remaining);
146
+		$filtered_row_html = $this->getFilteredRowHtml();
147
+		if ($filtered_row_html !== false) {
148
+			return $filtered_row_html;
149
+		}
150
+		$ticket_selector_row_html = EEH_HTML::tr(
151
+			'',
152
+			'',
153
+			"tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} "
154
+			. espresso_get_object_css_class($this->ticket)
155
+		);
156
+		$filtered_row_content = $this->getFilteredRowContents();
157
+		if ($filtered_row_content !== false) {
158
+			if ($this->max_attendees === 1) {
159
+				return $ticket_selector_row_html
160
+					   . $filtered_row_content
161
+					   . $this->ticketQtyAndIdHiddenInputs()
162
+					   . EEH_HTML::trx();
163
+			}
164
+			return $ticket_selector_row_html
165
+				   . $filtered_row_content
166
+				   . EEH_HTML::trx();
167
+		}
168
+		$this->hidden_input_qty = $this->max_attendees > 1;
169
+
170
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
171
+		$ticket_selector_row_html .= $this->ticketPriceTableCell();
172
+		$ticket_selector_row_html .= EEH_HTML::td(
173
+			'',
174
+			'',
175
+			'tckt-slctr-tbl-td-qty cntr',
176
+			'',
177
+			'headers="quantity-' . $this->EVT_ID . '"'
178
+		);
179
+		$this->setTicketStatusDisplay($remaining);
180
+		if (empty($this->ticket_status_display)) {
181
+			if ($this->max_attendees === 1) {
182
+				// only ONE attendee is allowed to register at a time
183
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
184
+			} elseif ($this->max > 0) {
185
+				$ticket_selector_row_html .= $this->ticketQuantitySelector();
186
+			}
187
+		}
188
+		$ticket_selector_row_html .= $this->ticket_status_display;
189
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
190
+		$ticket_selector_row_html .= $this->ticket_details->display(
191
+			$this->ticket_price,
192
+			$remaining,
193
+			$this->cols
194
+		);
195
+		$ticket_selector_row_html .= EEH_HTML::tdx();
196
+		$ticket_selector_row_html .= EEH_HTML::trx();
197
+
198
+
199
+		$this->row++;
200
+		return $ticket_selector_row_html;
201
+	}
202
+
203
+
204
+	/**
205
+	 * getTicketPriceDetails
206
+	 *
207
+	 * @return void
208
+	 * @throws EE_Error
209
+	 */
210
+	protected function setTicketPriceDetails()
211
+	{
212
+		$this->ticket_price = $this->tax_settings->prices_displayed_including_taxes
213
+			? $this->ticket->get_ticket_total_with_taxes()
214
+			: $this->ticket->get_ticket_subtotal();
215
+		$this->ticket_bundle = false;
216
+		$ticket_min = $this->ticket->min();
217
+		// for ticket bundles, set min and max qty the same
218
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
219
+			$this->ticket_price *= $ticket_min;
220
+			$this->ticket_bundle = true;
221
+		}
222
+		$this->ticket_price = apply_filters(
223
+			'FHEE__ticket_selector_chart_template__ticket_price',
224
+			$this->ticket_price,
225
+			$this->ticket
226
+		);
227
+	}
228
+
229
+
230
+	/**
231
+	 * ticketNameTableCell
232
+	 *
233
+	 * @return string
234
+	 * @throws EE_Error
235
+	 * @throws ReflectionException
236
+	 */
237
+	protected function ticketNameTableCell()
238
+	{
239
+		$html = EEH_HTML::td(
240
+			'',
241
+			'',
242
+			'tckt-slctr-tbl-td-name',
243
+			'',
244
+			'headers="details-' . $this->EVT_ID . '"'
245
+		);
246
+		$html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
247
+		$html .= $this->ticket_details->getShowHideLinks();
248
+		if ($this->ticket->required()) {
249
+			$html .= EEH_HTML::p(
250
+				apply_filters(
251
+					'FHEE__ticket_selector_chart_template__ticket_required_message',
252
+					esc_html__('This ticket is required and must be purchased.', 'event_espresso')
253
+				),
254
+				'',
255
+				'ticket-required-pg'
256
+			);
257
+		}
258
+		$html .= EEH_HTML::tdx();
259
+		return $html;
260
+	}
261
+
262
+
263
+	/**
264
+	 * ticketPriceTableCell
265
+	 *
266
+	 * @return string
267
+	 * @throws EE_Error
268
+	 */
269
+	protected function ticketPriceTableCell()
270
+	{
271
+		$html = '';
272
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
273
+			$html .= EEH_HTML::td(
274
+				'',
275
+				'',
276
+				'tckt-slctr-tbl-td-price jst-rght',
277
+				'',
278
+				'headers="price-' . $this->EVT_ID . '"'
279
+			);
280
+			$html .= EEH_HTML::span(
281
+				EEH_Template::format_currency($this->ticket_price),
282
+				'',
283
+				'tckt-price--nowrap'
284
+			);
285
+			$html .= $this->ticket->taxable()
286
+				? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text')
287
+				: '';
288
+			$html .= '&nbsp;';
289
+			// phpcs:disable WordPress.WP.I18n.NoEmptyStrings
290
+			$html .= EEH_HTML::span(
291
+				$this->ticket_bundle
292
+					? apply_filters(
293
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
294
+						esc_html__(' / bundle', 'event_espresso')
295
+					)
296
+					: apply_filters(
297
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
298
+						esc_html__('', 'event_espresso')
299
+					),
300
+				'',
301
+				'smaller-text no-bold'
302
+			);
303
+			$html .= '&nbsp;';
304
+			$html .= EEH_HTML::tdx();
305
+			$this->cols++;
306
+		}
307
+		return $html;
308
+	}
309
+
310
+
311
+	/**
312
+	 * onlyOneAttendeeCanRegister
313
+	 *
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 */
317
+	protected function onlyOneAttendeeCanRegister()
318
+	{
319
+		$this->hidden_input_qty = false;
320
+		// display submit button since we have tickets available
321
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
322
+
323
+		$TKT   = $this->ticket->ID();
324
+		$label = esc_html__('Select this ticket', 'event_espresso');
325
+		$name  = "tkt-slctr-qty-{$this->EVT_ID}";
326
+		$class = "ticket-selector-tbl-qty-slct";
327
+		$id    = "{$class}-{$this->EVT_ID}-{$this->row}";
328
+		$checked = $this->total_tickets === 1 ? ' checked' : '';
329
+
330
+		$html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
331
+		$html .= "<input type='radio'{$checked} name='{$name}' id='{$id}' class='{$class}' value='{$TKT}-1' title='' />";
332
+		return $html;
333
+	}
334
+
335
+
336
+	/**
337
+	 * ticketQuantitySelector
338
+	 *
339
+	 * @return string
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function ticketQuantitySelector()
343
+	{
344
+		$this->hidden_input_qty = false;
345
+		// display submit button since we have tickets available
346
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
347
+
348
+		$TKT = $this->ticket->ID();
349
+		$label = esc_html__('Quantity', 'event_espresso');
350
+		$class = 'ticket-selector-tbl-qty-slct';
351
+		$id = "{$class}-{$this->EVT_ID}-{$this->row}";
352
+
353
+		$html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
354
+		$html .= "<select name='tkt-slctr-qty-{$this->EVT_ID}[{$TKT}]' id='{$id}' class='{$class}'>";
355
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
356
+		if ($this->min !== 0 && ! $this->ticket->required()) {
357
+			$html .= "<option value='0'>&nbsp;0&nbsp;</option>";
358
+		}
359
+		// offer ticket quantities from the min to the max
360
+		for ($i = $this->min; $i <= $this->max; $i++) {
361
+			$html .= "<option value='{$i}'>&nbsp;{$i}&nbsp;</option>";
362
+		}
363
+		$html .= "</select>";
364
+		return $html;
365
+	}
366
+
367
+
368
+	/**
369
+	 * getHiddenInputs
370
+	 *
371
+	 * @return string
372
+	 * @throws EE_Error
373
+	 */
374
+	protected function ticketQtyAndIdHiddenInputs()
375
+	{
376
+		$html = '';
377
+		$EVT = $this->EVT_ID;
378
+		$TKT = $this->ticket->ID();
379
+		// depending on group reg we need to change the format for qty
380
+		if ($this->hidden_input_qty) {
381
+			$html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />";
382
+		}
383
+		$html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />";
384
+		return $html;
385
+	}
386 386
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_SPCO_JSON_Response.php 1 patch
Indentation   +399 added lines, -399 removed lines patch added patch discarded remove patch
@@ -14,403 +14,403 @@
 block discarded – undo
14 14
  */
15 15
 class EE_SPCO_JSON_Response
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected $_errors = '';
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $_unexpected_errors = '';
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    protected $_attention = '';
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $_success = '';
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected $_plz_select_method_of_payment = '';
41
-
42
-    /**
43
-     * @var string
44
-     */
45
-    protected $_redirect_url = '';
46
-
47
-    /**
48
-     * @var string
49
-     */
50
-    protected $_registration_time_limit = '';
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    protected $_redirect_form = '';
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $_reg_step_html = '';
61
-
62
-    /**
63
-     * @var string
64
-     */
65
-    protected $_method_of_payment = '';
66
-
67
-    /**
68
-     * @var float
69
-     */
70
-    protected $_payment_amount;
71
-
72
-    /**
73
-     * @var array
74
-     */
75
-    protected $_return_data = array();
76
-
77
-
78
-    /**
79
-     * @var array
80
-     */
81
-    protected $_validation_rules = array();
82
-
83
-
84
-    /**
85
-     *    class constructor
86
-     */
87
-    public function __construct()
88
-    {
89
-    }
90
-
91
-
92
-    /**
93
-     *    __toString
94
-     *
95
-     *        allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a  JSON encoded string
96
-     *        ie: $json_response = new EE_SPCO_JSON_Response();
97
-     *        echo $json_response;
98
-     *
99
-     * @access    public
100
-     * @return    string
101
-     */
102
-    public function __toString()
103
-    {
104
-        $JSON_response = array();
105
-        // grab notices
106
-        $notices = EE_Error::get_notices(false);
107
-        $this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
108
-        $this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
109
-        $this->set_success(isset($notices['success']) ? $notices['success'] : '');
110
-        // add notices to JSON response, but only if they exist
111
-        if ($this->attention()) {
112
-            $JSON_response['attention'] = $this->attention();
113
-        }
114
-        if ($this->errors()) {
115
-            $JSON_response['errors'] = $this->errors();
116
-        }
117
-        if ($this->unexpected_errors()) {
118
-            $JSON_response['unexpected_errors'] = $this->unexpected_errors();
119
-        }
120
-        if ($this->success()) {
121
-            $JSON_response['success'] = $this->success();
122
-        }
123
-        // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
124
-        if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
125
-            $JSON_response['success'] = null;
126
-        }
127
-        // set redirect_url, IF it exists
128
-        if ($this->redirect_url()) {
129
-            $JSON_response['redirect_url'] = $this->redirect_url();
130
-        }
131
-        // set registration_time_limit, IF it exists
132
-        if ($this->registration_time_limit()) {
133
-            $JSON_response['registration_time_limit'] = $this->registration_time_limit();
134
-        }
135
-        // set payment_amount, IF it exists
136
-        if ($this->payment_amount() !== null) {
137
-            $JSON_response['payment_amount'] = $this->payment_amount();
138
-        }
139
-        // grab generic return data
140
-        $return_data = $this->return_data();
141
-        // add billing form validation rules
142
-        if ($this->validation_rules()) {
143
-            $return_data['validation_rules'] = $this->validation_rules();
144
-        }
145
-        // set reg_step_html, IF it exists
146
-        if ($this->reg_step_html()) {
147
-            $return_data['reg_step_html'] = $this->reg_step_html();
148
-        }
149
-        // set method of payment, IF it exists
150
-        if ($this->method_of_payment()) {
151
-            $return_data['method_of_payment'] = $this->method_of_payment();
152
-        }
153
-        // set "plz_select_method_of_payment" message, IF it exists
154
-        if ($this->plz_select_method_of_payment()) {
155
-            $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
156
-        }
157
-        // set redirect_form, IF it exists
158
-        if ($this->redirect_form()) {
159
-            $return_data['redirect_form'] = $this->redirect_form();
160
-        }
161
-        // and finally, add return_data array to main JSON response array, IF it contains anything
162
-        // why did we add some of the above properties to the return data array?
163
-        // because it is easier and cleaner in the Javascript to deal with this way
164
-        if (! empty($return_data)) {
165
-            $JSON_response['return_data'] = $return_data;
166
-        }
167
-        // filter final array
168
-        $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
169
-        // return encoded array
170
-        return (string) wp_json_encode($JSON_response);
171
-    }
172
-
173
-
174
-    /**
175
-     * @param string $attention
176
-     */
177
-    public function set_attention($attention)
178
-    {
179
-        $this->_attention = $attention;
180
-    }
181
-
182
-
183
-    /**
184
-     * @return string
185
-     */
186
-    public function attention()
187
-    {
188
-        return $this->_attention;
189
-    }
190
-
191
-
192
-    /**
193
-     * @param string $errors
194
-     */
195
-    public function set_errors($errors)
196
-    {
197
-        $this->_errors = $errors;
198
-    }
199
-
200
-
201
-    /**
202
-     * @return string
203
-     */
204
-    public function errors()
205
-    {
206
-        return $this->_errors;
207
-    }
208
-
209
-
210
-    /**
211
-     * @return string
212
-     */
213
-    public function unexpected_errors()
214
-    {
215
-        return $this->_unexpected_errors;
216
-    }
217
-
218
-
219
-    /**
220
-     * @param string $unexpected_errors
221
-     */
222
-    public function set_unexpected_errors($unexpected_errors)
223
-    {
224
-        $this->_unexpected_errors = $unexpected_errors;
225
-    }
226
-
227
-
228
-    /**
229
-     * @param string $success
230
-     */
231
-    public function set_success($success)
232
-    {
233
-        $this->_success = $success;
234
-    }
235
-
236
-
237
-    /**
238
-     * @return string
239
-     */
240
-    public function success()
241
-    {
242
-        return $this->_success;
243
-    }
244
-
245
-
246
-    /**
247
-     * @param string $method_of_payment
248
-     */
249
-    public function set_method_of_payment($method_of_payment)
250
-    {
251
-        $this->_method_of_payment = $method_of_payment;
252
-    }
253
-
254
-
255
-    /**
256
-     * @return string
257
-     */
258
-    public function method_of_payment()
259
-    {
260
-        return $this->_method_of_payment;
261
-    }
262
-
263
-
264
-    /**
265
-     * @return float
266
-     */
267
-    public function payment_amount()
268
-    {
269
-        return $this->_payment_amount;
270
-    }
271
-
272
-
273
-    /**
274
-     * @param float $payment_amount
275
-     * @throws EE_Error
276
-     */
277
-    public function set_payment_amount($payment_amount)
278
-    {
279
-        $this->_payment_amount = (float) $payment_amount;
280
-    }
281
-
282
-
283
-    /**
284
-     * @param string $next_step_html
285
-     */
286
-    public function set_reg_step_html($next_step_html)
287
-    {
288
-        $this->_reg_step_html = $next_step_html;
289
-    }
290
-
291
-
292
-    /**
293
-     * @return string
294
-     */
295
-    public function reg_step_html()
296
-    {
297
-        return $this->_reg_step_html;
298
-    }
299
-
300
-
301
-    /**
302
-     * @param string $redirect_form
303
-     */
304
-    public function set_redirect_form($redirect_form)
305
-    {
306
-        $this->_redirect_form = $redirect_form;
307
-    }
308
-
309
-
310
-    /**
311
-     * @return string
312
-     */
313
-    public function redirect_form()
314
-    {
315
-        return ! empty($this->_redirect_form) ? $this->_redirect_form : false;
316
-    }
317
-
318
-
319
-    /**
320
-     * @param string $plz_select_method_of_payment
321
-     */
322
-    public function set_plz_select_method_of_payment($plz_select_method_of_payment)
323
-    {
324
-        $this->_plz_select_method_of_payment = $plz_select_method_of_payment;
325
-    }
326
-
327
-
328
-    /**
329
-     * @return string
330
-     */
331
-    public function plz_select_method_of_payment()
332
-    {
333
-        return $this->_plz_select_method_of_payment;
334
-    }
335
-
336
-
337
-    /**
338
-     * @param string $redirect_url
339
-     */
340
-    public function set_redirect_url($redirect_url)
341
-    {
342
-        $this->_redirect_url = $redirect_url;
343
-    }
344
-
345
-
346
-    /**
347
-     * @return string
348
-     */
349
-    public function redirect_url()
350
-    {
351
-        return $this->_redirect_url;
352
-    }
353
-
354
-
355
-    /**
356
-     * @return string
357
-     */
358
-    public function registration_time_limit()
359
-    {
360
-        return $this->_registration_time_limit;
361
-    }
362
-
363
-
364
-    /**
365
-     * @param string $registration_time_limit
366
-     */
367
-    public function set_registration_time_limit($registration_time_limit)
368
-    {
369
-        $this->_registration_time_limit = $registration_time_limit;
370
-    }
371
-
372
-
373
-    /**
374
-     * @param array $return_data
375
-     */
376
-    public function set_return_data($return_data)
377
-    {
378
-        $this->_return_data = array_merge($this->_return_data, $return_data);
379
-    }
380
-
381
-
382
-    /**
383
-     * @return array
384
-     */
385
-    public function return_data()
386
-    {
387
-        return $this->_return_data;
388
-    }
389
-
390
-
391
-    /**
392
-     * @param array $validation_rules
393
-     */
394
-    public function add_validation_rules(array $validation_rules = array())
395
-    {
396
-        if (is_array($validation_rules) && ! empty($validation_rules)) {
397
-            $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
398
-        }
399
-    }
400
-
401
-
402
-    /**
403
-     * @return array | bool
404
-     */
405
-    public function validation_rules()
406
-    {
407
-        return ! empty($this->_validation_rules) ? $this->_validation_rules : false;
408
-    }
409
-
410
-
411
-    public function echoAndExit()
412
-    {
413
-        echo $this;
414
-        exit();
415
-    }
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected $_errors = '';
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $_unexpected_errors = '';
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	protected $_attention = '';
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $_success = '';
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected $_plz_select_method_of_payment = '';
41
+
42
+	/**
43
+	 * @var string
44
+	 */
45
+	protected $_redirect_url = '';
46
+
47
+	/**
48
+	 * @var string
49
+	 */
50
+	protected $_registration_time_limit = '';
51
+
52
+	/**
53
+	 * @var string
54
+	 */
55
+	protected $_redirect_form = '';
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	protected $_reg_step_html = '';
61
+
62
+	/**
63
+	 * @var string
64
+	 */
65
+	protected $_method_of_payment = '';
66
+
67
+	/**
68
+	 * @var float
69
+	 */
70
+	protected $_payment_amount;
71
+
72
+	/**
73
+	 * @var array
74
+	 */
75
+	protected $_return_data = array();
76
+
77
+
78
+	/**
79
+	 * @var array
80
+	 */
81
+	protected $_validation_rules = array();
82
+
83
+
84
+	/**
85
+	 *    class constructor
86
+	 */
87
+	public function __construct()
88
+	{
89
+	}
90
+
91
+
92
+	/**
93
+	 *    __toString
94
+	 *
95
+	 *        allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a  JSON encoded string
96
+	 *        ie: $json_response = new EE_SPCO_JSON_Response();
97
+	 *        echo $json_response;
98
+	 *
99
+	 * @access    public
100
+	 * @return    string
101
+	 */
102
+	public function __toString()
103
+	{
104
+		$JSON_response = array();
105
+		// grab notices
106
+		$notices = EE_Error::get_notices(false);
107
+		$this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
108
+		$this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
109
+		$this->set_success(isset($notices['success']) ? $notices['success'] : '');
110
+		// add notices to JSON response, but only if they exist
111
+		if ($this->attention()) {
112
+			$JSON_response['attention'] = $this->attention();
113
+		}
114
+		if ($this->errors()) {
115
+			$JSON_response['errors'] = $this->errors();
116
+		}
117
+		if ($this->unexpected_errors()) {
118
+			$JSON_response['unexpected_errors'] = $this->unexpected_errors();
119
+		}
120
+		if ($this->success()) {
121
+			$JSON_response['success'] = $this->success();
122
+		}
123
+		// but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
124
+		if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
125
+			$JSON_response['success'] = null;
126
+		}
127
+		// set redirect_url, IF it exists
128
+		if ($this->redirect_url()) {
129
+			$JSON_response['redirect_url'] = $this->redirect_url();
130
+		}
131
+		// set registration_time_limit, IF it exists
132
+		if ($this->registration_time_limit()) {
133
+			$JSON_response['registration_time_limit'] = $this->registration_time_limit();
134
+		}
135
+		// set payment_amount, IF it exists
136
+		if ($this->payment_amount() !== null) {
137
+			$JSON_response['payment_amount'] = $this->payment_amount();
138
+		}
139
+		// grab generic return data
140
+		$return_data = $this->return_data();
141
+		// add billing form validation rules
142
+		if ($this->validation_rules()) {
143
+			$return_data['validation_rules'] = $this->validation_rules();
144
+		}
145
+		// set reg_step_html, IF it exists
146
+		if ($this->reg_step_html()) {
147
+			$return_data['reg_step_html'] = $this->reg_step_html();
148
+		}
149
+		// set method of payment, IF it exists
150
+		if ($this->method_of_payment()) {
151
+			$return_data['method_of_payment'] = $this->method_of_payment();
152
+		}
153
+		// set "plz_select_method_of_payment" message, IF it exists
154
+		if ($this->plz_select_method_of_payment()) {
155
+			$return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
156
+		}
157
+		// set redirect_form, IF it exists
158
+		if ($this->redirect_form()) {
159
+			$return_data['redirect_form'] = $this->redirect_form();
160
+		}
161
+		// and finally, add return_data array to main JSON response array, IF it contains anything
162
+		// why did we add some of the above properties to the return data array?
163
+		// because it is easier and cleaner in the Javascript to deal with this way
164
+		if (! empty($return_data)) {
165
+			$JSON_response['return_data'] = $return_data;
166
+		}
167
+		// filter final array
168
+		$JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
169
+		// return encoded array
170
+		return (string) wp_json_encode($JSON_response);
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param string $attention
176
+	 */
177
+	public function set_attention($attention)
178
+	{
179
+		$this->_attention = $attention;
180
+	}
181
+
182
+
183
+	/**
184
+	 * @return string
185
+	 */
186
+	public function attention()
187
+	{
188
+		return $this->_attention;
189
+	}
190
+
191
+
192
+	/**
193
+	 * @param string $errors
194
+	 */
195
+	public function set_errors($errors)
196
+	{
197
+		$this->_errors = $errors;
198
+	}
199
+
200
+
201
+	/**
202
+	 * @return string
203
+	 */
204
+	public function errors()
205
+	{
206
+		return $this->_errors;
207
+	}
208
+
209
+
210
+	/**
211
+	 * @return string
212
+	 */
213
+	public function unexpected_errors()
214
+	{
215
+		return $this->_unexpected_errors;
216
+	}
217
+
218
+
219
+	/**
220
+	 * @param string $unexpected_errors
221
+	 */
222
+	public function set_unexpected_errors($unexpected_errors)
223
+	{
224
+		$this->_unexpected_errors = $unexpected_errors;
225
+	}
226
+
227
+
228
+	/**
229
+	 * @param string $success
230
+	 */
231
+	public function set_success($success)
232
+	{
233
+		$this->_success = $success;
234
+	}
235
+
236
+
237
+	/**
238
+	 * @return string
239
+	 */
240
+	public function success()
241
+	{
242
+		return $this->_success;
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param string $method_of_payment
248
+	 */
249
+	public function set_method_of_payment($method_of_payment)
250
+	{
251
+		$this->_method_of_payment = $method_of_payment;
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return string
257
+	 */
258
+	public function method_of_payment()
259
+	{
260
+		return $this->_method_of_payment;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @return float
266
+	 */
267
+	public function payment_amount()
268
+	{
269
+		return $this->_payment_amount;
270
+	}
271
+
272
+
273
+	/**
274
+	 * @param float $payment_amount
275
+	 * @throws EE_Error
276
+	 */
277
+	public function set_payment_amount($payment_amount)
278
+	{
279
+		$this->_payment_amount = (float) $payment_amount;
280
+	}
281
+
282
+
283
+	/**
284
+	 * @param string $next_step_html
285
+	 */
286
+	public function set_reg_step_html($next_step_html)
287
+	{
288
+		$this->_reg_step_html = $next_step_html;
289
+	}
290
+
291
+
292
+	/**
293
+	 * @return string
294
+	 */
295
+	public function reg_step_html()
296
+	{
297
+		return $this->_reg_step_html;
298
+	}
299
+
300
+
301
+	/**
302
+	 * @param string $redirect_form
303
+	 */
304
+	public function set_redirect_form($redirect_form)
305
+	{
306
+		$this->_redirect_form = $redirect_form;
307
+	}
308
+
309
+
310
+	/**
311
+	 * @return string
312
+	 */
313
+	public function redirect_form()
314
+	{
315
+		return ! empty($this->_redirect_form) ? $this->_redirect_form : false;
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param string $plz_select_method_of_payment
321
+	 */
322
+	public function set_plz_select_method_of_payment($plz_select_method_of_payment)
323
+	{
324
+		$this->_plz_select_method_of_payment = $plz_select_method_of_payment;
325
+	}
326
+
327
+
328
+	/**
329
+	 * @return string
330
+	 */
331
+	public function plz_select_method_of_payment()
332
+	{
333
+		return $this->_plz_select_method_of_payment;
334
+	}
335
+
336
+
337
+	/**
338
+	 * @param string $redirect_url
339
+	 */
340
+	public function set_redirect_url($redirect_url)
341
+	{
342
+		$this->_redirect_url = $redirect_url;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @return string
348
+	 */
349
+	public function redirect_url()
350
+	{
351
+		return $this->_redirect_url;
352
+	}
353
+
354
+
355
+	/**
356
+	 * @return string
357
+	 */
358
+	public function registration_time_limit()
359
+	{
360
+		return $this->_registration_time_limit;
361
+	}
362
+
363
+
364
+	/**
365
+	 * @param string $registration_time_limit
366
+	 */
367
+	public function set_registration_time_limit($registration_time_limit)
368
+	{
369
+		$this->_registration_time_limit = $registration_time_limit;
370
+	}
371
+
372
+
373
+	/**
374
+	 * @param array $return_data
375
+	 */
376
+	public function set_return_data($return_data)
377
+	{
378
+		$this->_return_data = array_merge($this->_return_data, $return_data);
379
+	}
380
+
381
+
382
+	/**
383
+	 * @return array
384
+	 */
385
+	public function return_data()
386
+	{
387
+		return $this->_return_data;
388
+	}
389
+
390
+
391
+	/**
392
+	 * @param array $validation_rules
393
+	 */
394
+	public function add_validation_rules(array $validation_rules = array())
395
+	{
396
+		if (is_array($validation_rules) && ! empty($validation_rules)) {
397
+			$this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
398
+		}
399
+	}
400
+
401
+
402
+	/**
403
+	 * @return array | bool
404
+	 */
405
+	public function validation_rules()
406
+	{
407
+		return ! empty($this->_validation_rules) ? $this->_validation_rules : false;
408
+	}
409
+
410
+
411
+	public function echoAndExit()
412
+	{
413
+		echo $this;
414
+		exit();
415
+	}
416 416
 }
Please login to merge, or discard this patch.
modules/invalid_checkout_access/EED_Invalid_Checkout_Access.module.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -13,84 +13,84 @@
 block discarded – undo
13 13
  */
14 14
 class EED_Invalid_Checkout_Access extends EED_Module
15 15
 {
16
-    /**
17
-     * @var InvalidCheckoutAccess $invalid_checkout_access_form
18
-     */
19
-    private static $invalid_checkout_access_form;
16
+	/**
17
+	 * @var InvalidCheckoutAccess $invalid_checkout_access_form
18
+	 */
19
+	private static $invalid_checkout_access_form;
20 20
 
21
-    /**
22
-     * set_hooks - for hooking into EE Core, other modules, etc
23
-     */
24
-    public static function set_hooks()
25
-    {
26
-    }
21
+	/**
22
+	 * set_hooks - for hooking into EE Core, other modules, etc
23
+	 */
24
+	public static function set_hooks()
25
+	{
26
+	}
27 27
 
28 28
 
29
-    /**
30
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
31
-     */
32
-    public static function set_hooks_admin()
33
-    {
34
-        add_action(
35
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
36
-            array('EED_Invalid_Checkout_Access', 'display_invalid_checkout_access_form'),
37
-            15
38
-        );
39
-        add_filter(
40
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
41
-            array('EED_Invalid_Checkout_Access', 'process_invalid_checkout_access_form')
42
-        );
43
-    }
29
+	/**
30
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
31
+	 */
32
+	public static function set_hooks_admin()
33
+	{
34
+		add_action(
35
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
36
+			array('EED_Invalid_Checkout_Access', 'display_invalid_checkout_access_form'),
37
+			15
38
+		);
39
+		add_filter(
40
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
41
+			array('EED_Invalid_Checkout_Access', 'process_invalid_checkout_access_form')
42
+		);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * run - initial module setup
48
-     * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
49
-     *
50
-     * @var WP $WP
51
-     */
52
-    public function run($WP)
53
-    {
54
-        // TODO: Implement run() method.
55
-    }
46
+	/**
47
+	 * run - initial module setup
48
+	 * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
49
+	 *
50
+	 * @var WP $WP
51
+	 */
52
+	public function run($WP)
53
+	{
54
+		// TODO: Implement run() method.
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * @return InvalidCheckoutAccess
60
-     */
61
-    public static function getInvalidCheckoutAccess()
62
-    {
63
-        if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) {
64
-            self::$invalid_checkout_access_form = new InvalidCheckoutAccess();
65
-        }
66
-        return self::$invalid_checkout_access_form;
67
-    }
58
+	/**
59
+	 * @return InvalidCheckoutAccess
60
+	 */
61
+	public static function getInvalidCheckoutAccess()
62
+	{
63
+		if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) {
64
+			self::$invalid_checkout_access_form = new InvalidCheckoutAccess();
65
+		}
66
+		return self::$invalid_checkout_access_form;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * email_validation_settings_form
72
-     *
73
-     * @return    void
74
-     * @throws EE_Error
75
-     */
76
-    public static function display_invalid_checkout_access_form()
77
-    {
78
-        $invalid_checkout_access_form = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
79
-        echo wp_kses($invalid_checkout_access_form->getForm()->get_html(), AllowedTags::getWithFormTags());
80
-    }
70
+	/**
71
+	 * email_validation_settings_form
72
+	 *
73
+	 * @return    void
74
+	 * @throws EE_Error
75
+	 */
76
+	public static function display_invalid_checkout_access_form()
77
+	{
78
+		$invalid_checkout_access_form = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
79
+		echo wp_kses($invalid_checkout_access_form->getForm()->get_html(), AllowedTags::getWithFormTags());
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * email_validation_settings_form
85
-     *
86
-     * @param EE_Registration_Config $EE_Registration_Config
87
-     * @return EE_Registration_Config
88
-     * @throws EE_Error
89
-     * @throws ReflectionException
90
-     */
91
-    public static function process_invalid_checkout_access_form(EE_Registration_Config $EE_Registration_Config)
92
-    {
93
-        $invalid_checkout_access_form = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
94
-        return $invalid_checkout_access_form->processForm($EE_Registration_Config);
95
-    }
83
+	/**
84
+	 * email_validation_settings_form
85
+	 *
86
+	 * @param EE_Registration_Config $EE_Registration_Config
87
+	 * @return EE_Registration_Config
88
+	 * @throws EE_Error
89
+	 * @throws ReflectionException
90
+	 */
91
+	public static function process_invalid_checkout_access_form(EE_Registration_Config $EE_Registration_Config)
92
+	{
93
+		$invalid_checkout_access_form = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
94
+		return $invalid_checkout_access_form->processForm($EE_Registration_Config);
95
+	}
96 96
 }
Please login to merge, or discard this patch.
thank_you_page/templates/thank-you-page-registration-details.template.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -14,24 +14,24 @@  discard block
 block discarded – undo
14 14
 
15 15
 <div class="ee-registration-details-dv">
16 16
     <?php
17
-    $registrations = $transaction->registrations();
18
-    $registrations = is_array($registrations) ? $registrations : [];
19
-    $reg_count     = count($registrations);
20
-    $reg_cntr      = 0;
21
-    $event_name    = '';
22
-    $wait_list     = false;
23
-    foreach ($registrations as $registration) {
24
-        if (! $registration instanceof EE_Registration) {
25
-            continue;
26
-        }
27
-        if ($event_name != $registration->event_name() && ! empty($event_name)) { ?>
17
+	$registrations = $transaction->registrations();
18
+	$registrations = is_array($registrations) ? $registrations : [];
19
+	$reg_count     = count($registrations);
20
+	$reg_cntr      = 0;
21
+	$event_name    = '';
22
+	$wait_list     = false;
23
+	foreach ($registrations as $registration) {
24
+		if (! $registration instanceof EE_Registration) {
25
+			continue;
26
+		}
27
+		if ($event_name != $registration->event_name() && ! empty($event_name)) { ?>
28 28
             </tbody>
29 29
             </table>
30 30
             <?php
31
-        }
32
-        $reg_cntr++;
33
-        if ($event_name != $registration->event_name()) {
34
-            ?>
31
+		}
32
+		$reg_cntr++;
33
+		if ($event_name != $registration->event_name()) {
34
+			?>
35 35
             <h5>
36 36
                 <span class="smaller-text grey-text">
37 37
                     <?php esc_html_e('for', 'event_espresso'); ?> :
@@ -54,23 +54,23 @@  discard block
 block discarded – undo
54 54
             </thead>
55 55
             <tbody>
56 56
             <?php
57
-        }
58
-        if ($is_primary || (! $is_primary && $reg_url_link == $registration->reg_url_link())) { ?>
57
+		}
58
+		if ($is_primary || (! $is_primary && $reg_url_link == $registration->reg_url_link())) { ?>
59 59
             <tr>
60 60
                 <td width="40%">
61 61
                     <?php
62
-                    if ($registration->attendee() instanceof EE_Attendee) {
63
-                        echo esc_html($registration->attendee()->full_name(true));
64
-                    }
65
-                    ?>
62
+					if ($registration->attendee() instanceof EE_Attendee) {
63
+						echo esc_html($registration->attendee()->full_name(true));
64
+					}
65
+					?>
66 66
                     <p class="tiny-text" style="margin: .75em 0 0;">
67 67
                         <?php if ($registration->count_question_groups()) { ?>
68 68
                             <a class="ee-icon-only-lnk"
69 69
                                href="<?php echo esc_url_raw($registration->edit_attendee_information_url()); ?>"
70 70
                                title="<?php esc_attr_e(
71
-                                   'Click here to edit Attendee Information',
72
-                                   'event_espresso'
73
-                               ); ?>"
71
+								   'Click here to edit Attendee Information',
72
+								   'event_espresso'
73
+							   ); ?>"
74 74
                             >
75 75
                                 <span class="dashicons dashicons-groups"></span>
76 76
                                 <?php esc_html_e('edit info', 'event_espresso'); ?>
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
                         <?php } ?>
79 79
                         <a class="ee-resend-reg-confirmation-email ee-icon-only-lnk"
80 80
                            href="<?php echo esc_url_raw(
81
-                               add_query_arg(
82
-                                   ['token' => $registration->reg_url_link(), 'resend_reg_confirmation' => 'true'],
83
-                                   EE_Registry::instance()->CFG->core->thank_you_page_url()
84
-                               )
85
-                           ); ?>"
81
+							   add_query_arg(
82
+								   ['token' => $registration->reg_url_link(), 'resend_reg_confirmation' => 'true'],
83
+								   EE_Registry::instance()->CFG->core->thank_you_page_url()
84
+							   )
85
+						   ); ?>"
86 86
                            title="<?php esc_attr_e(
87
-                               'Click here to resend the Registration Confirmation email',
88
-                               'event_espresso'
89
-                           ); ?>"
87
+							   'Click here to resend the Registration Confirmation email',
88
+							   'event_espresso'
89
+						   ); ?>"
90 90
                            rel="<?php echo esc_attr($registration->reg_url_link()); ?>"
91 91
                         >
92 92
                             <span class="dashicons dashicons-email-alt"></span>
@@ -100,27 +100,27 @@  discard block
 block discarded – undo
100 100
                 <td width="35%" class="jst-left">
101 101
                     <?php $registration->e_pretty_status(true) ?>
102 102
                     <?php
103
-                    if ($registration->status_ID() === EEM_Registration::status_id_wait_list) {
104
-                        $wait_list = true;
105
-                    }
106
-                    ?>
103
+					if ($registration->status_ID() === EEM_Registration::status_id_wait_list) {
104
+						$wait_list = true;
105
+					}
106
+					?>
107 107
                 </td>
108 108
             </tr>
109 109
             <?php do_action(
110
-                'AHEE__thank_you_page_registration_details_template__after_registration_table_row',
111
-                $registration
112
-            ); ?>
110
+				'AHEE__thank_you_page_registration_details_template__after_registration_table_row',
111
+				$registration
112
+			); ?>
113 113
             <?php
114
-            $event_name = $registration->event_name();
115
-        }
116
-        if ($reg_cntr >= $reg_count) {
117
-            ?>
114
+			$event_name = $registration->event_name();
115
+		}
116
+		if ($reg_cntr >= $reg_count) {
117
+			?>
118 118
             </tbody>
119 119
             </table>
120 120
             <?php
121
-        }
122
-    }
123
-    ?>
121
+		}
122
+	}
123
+	?>
124 124
     <?php if ($is_primary && $SPCO_attendee_information_url) { ?>
125 125
         <p class="small-text jst-rght">
126 126
             <a href='<?php echo esc_url_raw($SPCO_attendee_information_url) ?>'>
@@ -129,22 +129,22 @@  discard block
 block discarded – undo
129 129
         </p>
130 130
     <?php } ?>
131 131
     <?php
132
-    if ($wait_list) {
133
-        echo apply_filters(
134
-            'AFEE__thank_you_page_registration_details_template__wait_list_notice',
135
-            sprintf(
136
-                esc_html__(
137
-                    '%1$sre: Wait List Registrations%2$sPlease note that the total cost listed below in the Transaction Details is for ALL registrations, including those that are on the wait list, even though they can not be currently paid for. If any spaces become available however, you may be notified by the Event admin and have the opportunity to secure the remaining tickets by making a payment for them.%3$s',
138
-                    'event_espresso'
139
-                ),
140
-                '<h6 class="" style="margin-bottom:.25em;"><span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>',
141
-                '</h6 ><p class="ee-wait-list-notice">',
142
-                '</p ><br />'
143
-            )
144
-        );
145
-    }
146
-    do_action('AHEE__thank_you_page_registration_details_template__after_registration_details');
147
-    ?>
132
+	if ($wait_list) {
133
+		echo apply_filters(
134
+			'AFEE__thank_you_page_registration_details_template__wait_list_notice',
135
+			sprintf(
136
+				esc_html__(
137
+					'%1$sre: Wait List Registrations%2$sPlease note that the total cost listed below in the Transaction Details is for ALL registrations, including those that are on the wait list, even though they can not be currently paid for. If any spaces become available however, you may be notified by the Event admin and have the opportunity to secure the remaining tickets by making a payment for them.%3$s',
138
+					'event_espresso'
139
+				),
140
+				'<h6 class="" style="margin-bottom:.25em;"><span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>',
141
+				'</h6 ><p class="ee-wait-list-notice">',
142
+				'</p ><br />'
143
+			)
144
+		);
145
+	}
146
+	do_action('AHEE__thank_you_page_registration_details_template__after_registration_details');
147
+	?>
148 148
 
149 149
 </div>
150 150
 <!-- end of .registration-details -->
Please login to merge, or discard this patch.