Completed
Branch BUG-10489-non-trashed-regs-onl... (88cd38)
by
unknown
41:42 queued 30:24
created
messages/templates/ee_msg_editor_active_context_element.template.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@  discard block
 block discarded – undo
10 10
  * @var int    $message_template_group_id The ID for the message template group this context belongs to.
11 11
  */
12 12
 $active_message = sprintf(
13
-    esc_html__(
14
-        'The template for %1$s is currently %2$sactive%3$s.',
15
-        'event_espresso'
16
-    ),
17
-    $context_label,
18
-    '<strong>',
19
-    '</strong>'
13
+	esc_html__(
14
+		'The template for %1$s is currently %2$sactive%3$s.',
15
+		'event_espresso'
16
+	),
17
+	$context_label,
18
+	'<strong>',
19
+	'</strong>'
20 20
 );
21 21
 $inactive_message = sprintf(
22
-    esc_html__(
23
-        'The template for %1$s is currently %2$sinactive%3$s.',
24
-        'event_espresso'
25
-    ),
26
-    $context_label,
27
-    '<strong>',
28
-    '</strong>'
22
+	esc_html__(
23
+		'The template for %1$s is currently %2$sinactive%3$s.',
24
+		'event_espresso'
25
+	),
26
+	$context_label,
27
+	'<strong>',
28
+	'</strong>'
29 29
 );
30 30
 ?>
31 31
 <div class="context-active-control-container">
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
         <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span>
35 35
         <span class="ee-on-off-toggle-label">
36 36
             <?php
37
-            echo $is_active ? $active_message : $inactive_message;
38
-            ?>
37
+			echo $is_active ? $active_message : $inactive_message;
38
+			?>
39 39
         </span>
40 40
         <div class="hidden js-data">
41 41
             <span class="ee-active-message"><?php echo $active_message; ?></span>
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
         </div>
44 44
         <div class="switch">
45 45
             <?php
46
-            $checked = $is_active ? ' checked="checked"' : '';
47
-            ?>
46
+			$checked = $is_active ? ' checked="checked"' : '';
47
+			?>
48 48
             <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>">
49 49
             <label for="ee-on-off-toggle-<?php echo $context; ?>"></label>
50 50
         </div>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Template_List_Table.class.php 2 patches
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -13,373 +13,373 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @return Messages_Admin_Page
18
-     */
19
-    public function get_admin_page()
20
-    {
21
-        return $this->_admin_page;
22
-    }
23
-
24
-
25
-    /**
26
-     * Setup data object
27
-     */
28
-    protected function _setup_data()
29
-    {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
31
-            $this->_per_page,
32
-            $this->_view,
33
-            false
34
-        );
35
-        $this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
-            $this->_per_page,
37
-            $this->_view,
38
-            true,
39
-            true
40
-        );
41
-    }
42
-
43
-
44
-    /**
45
-     * Set internal properties
46
-     */
47
-    protected function _set_properties()
48
-    {
49
-        $this->_wp_list_args = array(
50
-            'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
-            'plural'   => esc_html__('Message Template', 'event_espresso'),
52
-            'ajax'     => true, //for now,
53
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
-        );
55
-        $this->_columns      = array(
56
-            //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
-            'message_type' => esc_html__('Message Type', 'event_espresso'),
58
-            'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
-            'description'  => esc_html__('Description', 'event_espresso'),
60
-        );
61
-
62
-        $this->_sortable_columns = array(
63
-            'messenger' => array('MTP_messenger' => true),
64
-        );
65
-
66
-        $this->_hidden_columns = array();
67
-    }
68
-
69
-
70
-    /**
71
-     * Overriding the single_row method from parent to verify whether the $item has an accessible
72
-     * message_type or messenger object before generating the row.
73
-     *
74
-     * @param EE_Message_Template_Group $item
75
-     * @return string
76
-     * @throws EE_Error
77
-     */
78
-    public function single_row($item)
79
-    {
80
-        $message_type = $item->message_type_obj();
81
-        $messenger    = $item->messenger_obj();
82
-
83
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84
-            echo '';
85
-            return;
86
-        }
87
-
88
-        parent::single_row($item);
89
-    }
90
-
91
-
92
-    /**
93
-     * @return array
94
-     * @throws EE_Error
95
-     */
96
-    protected function _get_table_filters()
97
-    {
98
-        $filters = array();
99
-
100
-        //get select inputs
101
-        $select_inputs = array(
102
-            $this->_get_messengers_dropdown_filter(),
103
-            $this->_get_message_types_dropdown_filter(),
104
-        );
105
-
106
-        //set filters to select inputs if they aren't empty
107
-        foreach ($select_inputs as $select_input) {
108
-            if ($select_input) {
109
-                $filters[] = $select_input;
110
-            }
111
-        }
112
-        return $filters;
113
-    }
114
-
115
-    /**
116
-     * We're just removing the search box for message templates, not needed.
117
-     *
118
-     * @param string $text
119
-     * @param string $input_id
120
-     * @return string ;
121
-     */
122
-    public function search_box($text, $input_id)
123
-    {
124
-        return '';
125
-    }
126
-
127
-
128
-    /**
129
-     * Add counts to the _views property
130
-     */
131
-    protected function _add_view_counts()
132
-    {
133
-        foreach ($this->_views as $view => $args) {
134
-            $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
135
-                $this->_per_page,
136
-                $view,
137
-                true,
138
-                true
139
-            );
140
-        }
141
-    }
142
-
143
-
144
-    /**
145
-     * @param EE_Message_Template_Group $item
146
-     * @return string
147
-     */
148
-    public function column_cb($item)
149
-    {
150
-        return '';
151
-    }
152
-
153
-
154
-    /**
155
-     * @param EE_Message_Template_Group $item
156
-     * @return string
157
-     * @throws EE_Error
158
-     */
159
-    public function column_description($item)
160
-    {
161
-        return '<p>' . $item->message_type_obj()->description . '</p>';
162
-    }
163
-
164
-
165
-    /**
166
-     * @param EE_Message_Template_Group $item
167
-     * @return string
168
-     * @throws EE_Error
169
-     */
170
-    public function column_messenger($item)
171
-    {
172
-        //Return the name contents
173
-        return sprintf(
174
-            '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
175
-            /* $1%s */
176
-            $this->_get_name_link_for_messenger($item),
177
-            /* $2%s */
178
-            $item->GRP_ID(),
179
-            /* %4$s */
180
-            $this->_get_context_links($item),
181
-            /* $3%s */
182
-            $this->row_actions($this->_get_actions_for_messenger_column($item))
183
-        );
184
-    }
185
-
186
-    /**
187
-     * column_message_type
188
-     *
189
-     * @param  EE_Message_Template_Group $item message info for the row
190
-     * @return string message_type name
191
-     * @throws EE_Error
192
-     */
193
-    public function column_message_type($item)
194
-    {
195
-        return ucwords($item->message_type_obj()->label['singular']);
196
-    }
197
-
198
-
199
-    /**
200
-     * Generate dropdown filter select input for messengers
201
-     *
202
-     * @param bool $global
203
-     * @return string
204
-     * @throws EE_Error
205
-     */
206
-    protected function _get_messengers_dropdown_filter($global = true)
207
-    {
208
-        $messenger_options                                   = array();
209
-        $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
210
-            array(
211
-                array(
212
-                    'MTP_is_active' => true,
213
-                    'MTP_is_global' => $global,
214
-                ),
215
-                'group_by' => 'MTP_messenger',
216
-            )
217
-        );
218
-
219
-        foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
220
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
221
-                $messenger                          = $active_message_template_group->messenger_obj();
222
-                $messenger_label                    = $messenger instanceof EE_messenger
223
-                    ? $messenger->label['singular']
224
-                    : $active_message_template_group->messenger();
225
-                $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
226
-            }
227
-        }
228
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
229
-    }
230
-
231
-
232
-    /**
233
-     * Generate dropdown filter select input for message types
234
-     *
235
-     * @param bool $global
236
-     * @return string
237
-     * @throws EE_Error
238
-     */
239
-    protected function _get_message_types_dropdown_filter($global = true)
240
-    {
241
-        $message_type_options                                   = array();
242
-        $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
243
-            array(
244
-                array(
245
-                    'MTP_is_active' => true,
246
-                    'MTP_is_global' => true,
247
-                ),
248
-                'group_by' => 'MTP_message_type',
249
-            )
250
-        );
251
-
252
-        foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
253
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
254
-                $message_type               = $active_message_template_group->message_type_obj();
255
-                $message_type_label         = $message_type instanceof EE_message_type
256
-                    ? $message_type->label['singular']
257
-                    : $active_message_template_group->message_type();
258
-                $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
259
-            }
260
-        }
261
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
262
-    }
263
-
264
-
265
-    /**
266
-     * Return the edit url for the message template group.
267
-     * @param EE_Message_Template_Group $item
268
-     * @return string
269
-     * @throws EE_Error
270
-     */
271
-    protected function _get_edit_url(EE_Message_Template_Group $item)
272
-    {
273
-        $edit_url = '';
274
-        // edit link but only if item isn't trashed.
275
-        if (! $item->get('MTP_deleted')
276
-            && EE_Registry::instance()->CAP->current_user_can(
277
-                'ee_edit_message',
278
-                'espresso_messages_edit_message_template',
279
-                $item->ID()
280
-            )) {
281
-            $edit_url = EE_Admin_Page::add_query_args_and_nonce(
282
-                array(
283
-                    'action' => 'edit_message_template',
284
-                    'id'     => $item->GRP_ID(),
285
-                ),
286
-                EE_MSG_ADMIN_URL
287
-            );
288
-        }
289
-        return $edit_url;
290
-    }
291
-
292
-
293
-    /**
294
-     * Get the context link string for the messenger column.
295
-     * @param EE_Message_Template_Group $item
296
-     * @return string
297
-     * @throws EE_Error
298
-     */
299
-    protected function _get_context_links(EE_Message_Template_Group $item)
300
-    {
301
-        //first check if we even show the context links or not.
302
-        if (! EE_Registry::instance()->CAP->current_user_can(
303
-            'ee_edit_message',
304
-            'espresso_messages_edit_message_template',
305
-            $item->ID()
306
-        )
307
-            || $item->get('MTP_deleted')
308
-        ) {
309
-            return '';
310
-        }
311
-        //we want to display the contexts in here so we need to set them up
312
-        $c_label           = $item->context_label();
313
-        $c_configs         = $item->contexts_config();
314
-        $ctxt              = array();
315
-        $context_templates = $item->context_templates();
316
-        foreach ($context_templates as $context => $template_fields) {
317
-            $mtp_to        = ! empty($context_templates[$context]['to'])
318
-                             && $context_templates[$context]['to'] instanceof EE_Message_Template
319
-                ? $context_templates[$context]['to']->get('MTP_content')
320
-                : null;
321
-            $inactive_class      = (
322
-                empty($mtp_to)
323
-                && ! empty($context_templates[$context]['to'])
324
-            )
325
-            || ! $item->is_context_active($context)
326
-                ? ' mtp-inactive'
327
-                : '';
328
-            $context_title = ucwords($c_configs[$context]['label']);
329
-            $edit_link     = EE_Admin_Page::add_query_args_and_nonce(array(
330
-                'action'  => 'edit_message_template',
331
-                'id'      => $item->GRP_ID(),
332
-                'context' => $context,
333
-            ), EE_MSG_ADMIN_URL);
334
-            $ctxt[]        =  '<a'
335
-                  . ' href="' . $edit_link . '"'
336
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
338
-                  . $context_title
339
-                  . '</a>';
340
-        }
341
-
342
-        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
343
-    }
344
-
345
-
346
-    /**
347
-     * Get the Name string from the messenger column (linked to edit if the context allows for that).
348
-     * @param EE_Message_Template_Group $item
349
-     * @return string
350
-     * @throws EE_Error
351
-     */
352
-    protected function _get_name_link_for_messenger(EE_Message_Template_Group $item)
353
-    {
354
-        $edit_url = $this->_get_edit_url($item);
355
-        return $edit_url
356
-            ? '<a href="' . $edit_url . '"'
357
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
358
-              . ucwords($item->messenger_obj()->label['singular'])
359
-              . '</a>'
360
-            : ucwords($item->messenger_obj()->label['singular']);
361
-    }
362
-
363
-
364
-    /**
365
-     * Return the actions array for the messenger column.
366
-     * @param EE_Message_Template_Group $item
367
-     * @return array
368
-     * @throws EE_Error
369
-     */
370
-    protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item)
371
-    {
372
-        $actions = array();
373
-        if ($edit_url = $this->_get_edit_url($item)) {
374
-            $actions = array(
375
-                'edit' => '<a href="' . $edit_url . '"'
376
-                          . ' class="' . $item->message_type() . '-edit-link"'
377
-                          . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
378
-                          . esc_html__('Edit', 'event_espresso')
379
-                          . '</a>'
380
-            );
381
-        }
382
-        return $actions;
383
-    }
16
+	/**
17
+	 * @return Messages_Admin_Page
18
+	 */
19
+	public function get_admin_page()
20
+	{
21
+		return $this->_admin_page;
22
+	}
23
+
24
+
25
+	/**
26
+	 * Setup data object
27
+	 */
28
+	protected function _setup_data()
29
+	{
30
+		$this->_data           = $this->get_admin_page()->get_message_templates(
31
+			$this->_per_page,
32
+			$this->_view,
33
+			false
34
+		);
35
+		$this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
+			$this->_per_page,
37
+			$this->_view,
38
+			true,
39
+			true
40
+		);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Set internal properties
46
+	 */
47
+	protected function _set_properties()
48
+	{
49
+		$this->_wp_list_args = array(
50
+			'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
+			'plural'   => esc_html__('Message Template', 'event_espresso'),
52
+			'ajax'     => true, //for now,
53
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
+		);
55
+		$this->_columns      = array(
56
+			//'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
+			'message_type' => esc_html__('Message Type', 'event_espresso'),
58
+			'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
+			'description'  => esc_html__('Description', 'event_espresso'),
60
+		);
61
+
62
+		$this->_sortable_columns = array(
63
+			'messenger' => array('MTP_messenger' => true),
64
+		);
65
+
66
+		$this->_hidden_columns = array();
67
+	}
68
+
69
+
70
+	/**
71
+	 * Overriding the single_row method from parent to verify whether the $item has an accessible
72
+	 * message_type or messenger object before generating the row.
73
+	 *
74
+	 * @param EE_Message_Template_Group $item
75
+	 * @return string
76
+	 * @throws EE_Error
77
+	 */
78
+	public function single_row($item)
79
+	{
80
+		$message_type = $item->message_type_obj();
81
+		$messenger    = $item->messenger_obj();
82
+
83
+		if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84
+			echo '';
85
+			return;
86
+		}
87
+
88
+		parent::single_row($item);
89
+	}
90
+
91
+
92
+	/**
93
+	 * @return array
94
+	 * @throws EE_Error
95
+	 */
96
+	protected function _get_table_filters()
97
+	{
98
+		$filters = array();
99
+
100
+		//get select inputs
101
+		$select_inputs = array(
102
+			$this->_get_messengers_dropdown_filter(),
103
+			$this->_get_message_types_dropdown_filter(),
104
+		);
105
+
106
+		//set filters to select inputs if they aren't empty
107
+		foreach ($select_inputs as $select_input) {
108
+			if ($select_input) {
109
+				$filters[] = $select_input;
110
+			}
111
+		}
112
+		return $filters;
113
+	}
114
+
115
+	/**
116
+	 * We're just removing the search box for message templates, not needed.
117
+	 *
118
+	 * @param string $text
119
+	 * @param string $input_id
120
+	 * @return string ;
121
+	 */
122
+	public function search_box($text, $input_id)
123
+	{
124
+		return '';
125
+	}
126
+
127
+
128
+	/**
129
+	 * Add counts to the _views property
130
+	 */
131
+	protected function _add_view_counts()
132
+	{
133
+		foreach ($this->_views as $view => $args) {
134
+			$this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
135
+				$this->_per_page,
136
+				$view,
137
+				true,
138
+				true
139
+			);
140
+		}
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param EE_Message_Template_Group $item
146
+	 * @return string
147
+	 */
148
+	public function column_cb($item)
149
+	{
150
+		return '';
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param EE_Message_Template_Group $item
156
+	 * @return string
157
+	 * @throws EE_Error
158
+	 */
159
+	public function column_description($item)
160
+	{
161
+		return '<p>' . $item->message_type_obj()->description . '</p>';
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param EE_Message_Template_Group $item
167
+	 * @return string
168
+	 * @throws EE_Error
169
+	 */
170
+	public function column_messenger($item)
171
+	{
172
+		//Return the name contents
173
+		return sprintf(
174
+			'%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
175
+			/* $1%s */
176
+			$this->_get_name_link_for_messenger($item),
177
+			/* $2%s */
178
+			$item->GRP_ID(),
179
+			/* %4$s */
180
+			$this->_get_context_links($item),
181
+			/* $3%s */
182
+			$this->row_actions($this->_get_actions_for_messenger_column($item))
183
+		);
184
+	}
185
+
186
+	/**
187
+	 * column_message_type
188
+	 *
189
+	 * @param  EE_Message_Template_Group $item message info for the row
190
+	 * @return string message_type name
191
+	 * @throws EE_Error
192
+	 */
193
+	public function column_message_type($item)
194
+	{
195
+		return ucwords($item->message_type_obj()->label['singular']);
196
+	}
197
+
198
+
199
+	/**
200
+	 * Generate dropdown filter select input for messengers
201
+	 *
202
+	 * @param bool $global
203
+	 * @return string
204
+	 * @throws EE_Error
205
+	 */
206
+	protected function _get_messengers_dropdown_filter($global = true)
207
+	{
208
+		$messenger_options                                   = array();
209
+		$active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
210
+			array(
211
+				array(
212
+					'MTP_is_active' => true,
213
+					'MTP_is_global' => $global,
214
+				),
215
+				'group_by' => 'MTP_messenger',
216
+			)
217
+		);
218
+
219
+		foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
220
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
221
+				$messenger                          = $active_message_template_group->messenger_obj();
222
+				$messenger_label                    = $messenger instanceof EE_messenger
223
+					? $messenger->label['singular']
224
+					: $active_message_template_group->messenger();
225
+				$messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
226
+			}
227
+		}
228
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
229
+	}
230
+
231
+
232
+	/**
233
+	 * Generate dropdown filter select input for message types
234
+	 *
235
+	 * @param bool $global
236
+	 * @return string
237
+	 * @throws EE_Error
238
+	 */
239
+	protected function _get_message_types_dropdown_filter($global = true)
240
+	{
241
+		$message_type_options                                   = array();
242
+		$active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
243
+			array(
244
+				array(
245
+					'MTP_is_active' => true,
246
+					'MTP_is_global' => true,
247
+				),
248
+				'group_by' => 'MTP_message_type',
249
+			)
250
+		);
251
+
252
+		foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
253
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
254
+				$message_type               = $active_message_template_group->message_type_obj();
255
+				$message_type_label         = $message_type instanceof EE_message_type
256
+					? $message_type->label['singular']
257
+					: $active_message_template_group->message_type();
258
+				$message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
259
+			}
260
+		}
261
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
262
+	}
263
+
264
+
265
+	/**
266
+	 * Return the edit url for the message template group.
267
+	 * @param EE_Message_Template_Group $item
268
+	 * @return string
269
+	 * @throws EE_Error
270
+	 */
271
+	protected function _get_edit_url(EE_Message_Template_Group $item)
272
+	{
273
+		$edit_url = '';
274
+		// edit link but only if item isn't trashed.
275
+		if (! $item->get('MTP_deleted')
276
+			&& EE_Registry::instance()->CAP->current_user_can(
277
+				'ee_edit_message',
278
+				'espresso_messages_edit_message_template',
279
+				$item->ID()
280
+			)) {
281
+			$edit_url = EE_Admin_Page::add_query_args_and_nonce(
282
+				array(
283
+					'action' => 'edit_message_template',
284
+					'id'     => $item->GRP_ID(),
285
+				),
286
+				EE_MSG_ADMIN_URL
287
+			);
288
+		}
289
+		return $edit_url;
290
+	}
291
+
292
+
293
+	/**
294
+	 * Get the context link string for the messenger column.
295
+	 * @param EE_Message_Template_Group $item
296
+	 * @return string
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function _get_context_links(EE_Message_Template_Group $item)
300
+	{
301
+		//first check if we even show the context links or not.
302
+		if (! EE_Registry::instance()->CAP->current_user_can(
303
+			'ee_edit_message',
304
+			'espresso_messages_edit_message_template',
305
+			$item->ID()
306
+		)
307
+			|| $item->get('MTP_deleted')
308
+		) {
309
+			return '';
310
+		}
311
+		//we want to display the contexts in here so we need to set them up
312
+		$c_label           = $item->context_label();
313
+		$c_configs         = $item->contexts_config();
314
+		$ctxt              = array();
315
+		$context_templates = $item->context_templates();
316
+		foreach ($context_templates as $context => $template_fields) {
317
+			$mtp_to        = ! empty($context_templates[$context]['to'])
318
+							 && $context_templates[$context]['to'] instanceof EE_Message_Template
319
+				? $context_templates[$context]['to']->get('MTP_content')
320
+				: null;
321
+			$inactive_class      = (
322
+				empty($mtp_to)
323
+				&& ! empty($context_templates[$context]['to'])
324
+			)
325
+			|| ! $item->is_context_active($context)
326
+				? ' mtp-inactive'
327
+				: '';
328
+			$context_title = ucwords($c_configs[$context]['label']);
329
+			$edit_link     = EE_Admin_Page::add_query_args_and_nonce(array(
330
+				'action'  => 'edit_message_template',
331
+				'id'      => $item->GRP_ID(),
332
+				'context' => $context,
333
+			), EE_MSG_ADMIN_URL);
334
+			$ctxt[]        =  '<a'
335
+				  . ' href="' . $edit_link . '"'
336
+				  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
+				  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
338
+				  . $context_title
339
+				  . '</a>';
340
+		}
341
+
342
+		return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
343
+	}
344
+
345
+
346
+	/**
347
+	 * Get the Name string from the messenger column (linked to edit if the context allows for that).
348
+	 * @param EE_Message_Template_Group $item
349
+	 * @return string
350
+	 * @throws EE_Error
351
+	 */
352
+	protected function _get_name_link_for_messenger(EE_Message_Template_Group $item)
353
+	{
354
+		$edit_url = $this->_get_edit_url($item);
355
+		return $edit_url
356
+			? '<a href="' . $edit_url . '"'
357
+			  . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
358
+			  . ucwords($item->messenger_obj()->label['singular'])
359
+			  . '</a>'
360
+			: ucwords($item->messenger_obj()->label['singular']);
361
+	}
362
+
363
+
364
+	/**
365
+	 * Return the actions array for the messenger column.
366
+	 * @param EE_Message_Template_Group $item
367
+	 * @return array
368
+	 * @throws EE_Error
369
+	 */
370
+	protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item)
371
+	{
372
+		$actions = array();
373
+		if ($edit_url = $this->_get_edit_url($item)) {
374
+			$actions = array(
375
+				'edit' => '<a href="' . $edit_url . '"'
376
+						  . ' class="' . $item->message_type() . '-edit-link"'
377
+						  . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
378
+						  . esc_html__('Edit', 'event_espresso')
379
+						  . '</a>'
380
+			);
381
+		}
382
+		return $actions;
383
+	}
384 384
 }
385 385
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      */
28 28
     protected function _setup_data()
29 29
     {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
30
+        $this->_data = $this->get_admin_page()->get_message_templates(
31 31
             $this->_per_page,
32 32
             $this->_view,
33 33
             false
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             'ajax'     => true, //for now,
53 53
             'screen'   => $this->get_admin_page()->get_current_screen()->id,
54 54
         );
55
-        $this->_columns      = array(
55
+        $this->_columns = array(
56 56
             //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57 57
             'message_type' => esc_html__('Message Type', 'event_espresso'),
58 58
             'messenger'    => esc_html__('Messenger', 'event_espresso'),
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $message_type = $item->message_type_obj();
81 81
         $messenger    = $item->messenger_obj();
82 82
 
83
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
83
+        if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84 84
             echo '';
85 85
             return;
86 86
         }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public function column_description($item)
160 160
     {
161
-        return '<p>' . $item->message_type_obj()->description . '</p>';
161
+        return '<p>'.$item->message_type_obj()->description.'</p>';
162 162
     }
163 163
 
164 164
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     {
273 273
         $edit_url = '';
274 274
         // edit link but only if item isn't trashed.
275
-        if (! $item->get('MTP_deleted')
275
+        if ( ! $item->get('MTP_deleted')
276 276
             && EE_Registry::instance()->CAP->current_user_can(
277 277
                 'ee_edit_message',
278 278
                 'espresso_messages_edit_message_template',
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     protected function _get_context_links(EE_Message_Template_Group $item)
300 300
     {
301 301
         //first check if we even show the context links or not.
302
-        if (! EE_Registry::instance()->CAP->current_user_can(
302
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
303 303
             'ee_edit_message',
304 304
             'espresso_messages_edit_message_template',
305 305
             $item->ID()
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
                              && $context_templates[$context]['to'] instanceof EE_Message_Template
319 319
                 ? $context_templates[$context]['to']->get('MTP_content')
320 320
                 : null;
321
-            $inactive_class      = (
321
+            $inactive_class = (
322 322
                 empty($mtp_to)
323 323
                 && ! empty($context_templates[$context]['to'])
324 324
             )
@@ -331,15 +331,15 @@  discard block
 block discarded – undo
331 331
                 'id'      => $item->GRP_ID(),
332 332
                 'context' => $context,
333 333
             ), EE_MSG_ADMIN_URL);
334
-            $ctxt[]        =  '<a'
335
-                  . ' href="' . $edit_link . '"'
336
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
334
+            $ctxt[] = '<a'
335
+                  . ' href="'.$edit_link.'"'
336
+                  . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"'
337
+                  . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">'
338 338
                   . $context_title
339 339
                   . '</a>';
340 340
         }
341 341
 
342
-        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
342
+        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt);
343 343
     }
344 344
 
345 345
 
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
     {
354 354
         $edit_url = $this->_get_edit_url($item);
355 355
         return $edit_url
356
-            ? '<a href="' . $edit_url . '"'
357
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
356
+            ? '<a href="'.$edit_url.'"'
357
+              . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
358 358
               . ucwords($item->messenger_obj()->label['singular'])
359 359
               . '</a>'
360 360
             : ucwords($item->messenger_obj()->label['singular']);
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
         $actions = array();
373 373
         if ($edit_url = $this->_get_edit_url($item)) {
374 374
             $actions = array(
375
-                'edit' => '<a href="' . $edit_url . '"'
376
-                          . ' class="' . $item->message_type() . '-edit-link"'
377
-                          . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
375
+                'edit' => '<a href="'.$edit_url.'"'
376
+                          . ' class="'.$item->message_type().'-edit-link"'
377
+                          . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
378 378
                           . esc_html__('Edit', 'event_espresso')
379 379
                           . '</a>'
380 380
             );
Please login to merge, or discard this patch.
acceptance_tests/tests/e-TestContextActivationToggleCept.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 $event_label = 'Testing Context Deactivation';
9 9
 
10 10
 $I->wantTo(
11
-    'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
-    . ' expected'
11
+	'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
+	. ' expected'
13 13
 );
14 14
 
15 15
 $I->loginAsAdmin();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 $I->see('The template for Primary Registrant Recipient is currently inactive.');
35 35
 
36 36
 $I->amGoingTo(
37
-    'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
37
+	'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
38 38
 );
39 39
 $I->amOnDefaultEventsListTablePage();
40 40
 $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR);
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR);
45 45
 $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR);
46 46
 $test_registration_details = array(
47
-    'fname' => 'ContextTestGuy',
48
-    'lname' => 'ContextTestDude',
49
-    'email' => '[email protected]',
47
+	'fname' => 'ContextTestGuy',
48
+	'lname' => 'ContextTestDude',
49
+	'email' => '[email protected]',
50 50
 );
51 51
 $I->logOut();
52 52
 $I->amOnUrl($event_link);
@@ -63,48 +63,48 @@  discard block
 block discarded – undo
63 63
 $I->amOnMessagesActivityListTablePage();
64 64
 //verify registrant context
65 65
 $I->see(
66
-    $test_registration_details['email'],
67
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
-        'to',
69
-        'Registration Approved',
70
-        MessagesAdmin::MESSAGE_STATUS_SENT,
71
-        '',
72
-        'Registrant'
73
-    )
66
+	$test_registration_details['email'],
67
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
+		'to',
69
+		'Registration Approved',
70
+		MessagesAdmin::MESSAGE_STATUS_SENT,
71
+		'',
72
+		'Registrant'
73
+	)
74 74
 );
75 75
 $I->deleteMessageInMessagesListTableFor(
76
-    'Registration Approved',
77
-    MessagesAdmin::MESSAGE_STATUS_SENT,
78
-    'Email',
79
-    'Registrant'
76
+	'Registration Approved',
77
+	MessagesAdmin::MESSAGE_STATUS_SENT,
78
+	'Email',
79
+	'Registrant'
80 80
 );
81 81
 //verify admin context
82 82
 $I->see(
83
-    '[email protected]',
84
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
-        'to',
86
-        'Registration Approved',
87
-        MessagesAdmin::MESSAGE_STATUS_SENT
88
-    )
83
+	'[email protected]',
84
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
+		'to',
86
+		'Registration Approved',
87
+		MessagesAdmin::MESSAGE_STATUS_SENT
88
+	)
89 89
 );
90 90
 $I->deleteMessageInMessagesListTableFor(
91
-    'Registration Approved'
91
+	'Registration Approved'
92 92
 );
93 93
 //verify primary registrant context is NOT present.
94 94
 $I->dontSee(
95
-    $test_registration_details['email'],
96
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
-        'to',
98
-        'Registration Approved',
99
-        MessagesAdmin::MESSAGE_STATUS_SENT,
100
-        '',
101
-        'Primary Registrant'
102
-    )
95
+	$test_registration_details['email'],
96
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
+		'to',
98
+		'Registration Approved',
99
+		MessagesAdmin::MESSAGE_STATUS_SENT,
100
+		'',
101
+		'Primary Registrant'
102
+	)
103 103
 );
104 104
 
105 105
 $I->amGoingTo(
106
-    'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
-    . ' field to an empty string to verify the message does not send for that context.'
106
+	'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
+	. ' field to an empty string to verify the message does not send for that context.'
108 108
 );
109 109
 $I->amOnDefaultMessageTemplateListTablePage();
110 110
 $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee');
@@ -128,41 +128,41 @@  discard block
 block discarded – undo
128 128
 $I->amOnMessagesActivityListTablePage();
129 129
 //verify registrant context
130 130
 $I->see(
131
-    $test_registration_details['email'],
132
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
-        'to',
134
-        'Registration Approved',
135
-        MessagesAdmin::MESSAGE_STATUS_SENT,
136
-        '',
137
-        'Registrant'
138
-    )
131
+	$test_registration_details['email'],
132
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
+		'to',
134
+		'Registration Approved',
135
+		MessagesAdmin::MESSAGE_STATUS_SENT,
136
+		'',
137
+		'Registrant'
138
+	)
139 139
 );
140 140
 $I->deleteMessageInMessagesListTableFor(
141
-    'Registration Approved',
142
-    MessagesAdmin::MESSAGE_STATUS_SENT,
143
-    'Email',
144
-    'Registrant'
141
+	'Registration Approved',
142
+	MessagesAdmin::MESSAGE_STATUS_SENT,
143
+	'Email',
144
+	'Registrant'
145 145
 );
146 146
 //verify admin context
147 147
 $I->see(
148
-    '[email protected]',
149
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
-        'to',
151
-        'Registration Approved',
152
-        MessagesAdmin::MESSAGE_STATUS_SENT
153
-    )
148
+	'[email protected]',
149
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
+		'to',
151
+		'Registration Approved',
152
+		MessagesAdmin::MESSAGE_STATUS_SENT
153
+	)
154 154
 );
155 155
 $I->deleteMessageInMessagesListTableFor(
156
-    'Registration Approved'
156
+	'Registration Approved'
157 157
 );
158 158
 //verify primary registrant context is NOT present.
159 159
 $I->dontSee(
160
-    $test_registration_details['email'],
161
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
-        'to',
163
-        'Registration Approved',
164
-        MessagesAdmin::MESSAGE_STATUS_SENT,
165
-        '',
166
-        'Primary Registrant'
167
-    )
160
+	$test_registration_details['email'],
161
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
+		'to',
163
+		'Registration Approved',
164
+		MessagesAdmin::MESSAGE_STATUS_SENT,
165
+		'',
166
+		'Primary Registrant'
167
+	)
168 168
 );
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Indentation   +784 added lines, -784 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\orm\ModelFieldFactory;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
7 7
 
@@ -18,789 +18,789 @@  discard block
 block discarded – undo
18 18
 class EEM_Event extends EEM_CPT_Base
19 19
 {
20 20
 
21
-    /**
22
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
23
-     * event
24
-     */
25
-    const sold_out = 'sold_out';
26
-
27
-    /**
28
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
29
-     * date)
30
-     */
31
-    const postponed = 'postponed';
32
-
33
-    /**
34
-     * constant used by status(), indicating that the event will no longer occur
35
-     */
36
-    const cancelled = 'cancelled';
37
-
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    protected static $_default_reg_status;
43
-
44
-
45
-    /**
46
-     * This is the default for the additional limit field.
47
-     * @var int
48
-     */
49
-    protected static $_default_additional_limit = 10;
50
-
51
-
52
-    /**
53
-     * private instance of the Event object
54
-     *
55
-     * @var EEM_Event
56
-     */
57
-    protected static $_instance;
58
-
59
-
60
-
61
-
62
-    /**
63
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
64
-     *
65
-     * @param string $timezone
66
-     * @throws \EE_Error
67
-     */
68
-    protected function __construct($timezone = null)
69
-    {
70
-        EE_Registry::instance()->load_model('Registration');
71
-        $this->singular_item = esc_html__('Event', 'event_espresso');
72
-        $this->plural_item = esc_html__('Events', 'event_espresso');
73
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
74
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
75
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
76
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
77
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
78
-        //	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
79
-        $this->_custom_stati = apply_filters(
80
-            'AFEE__EEM_Event__construct___custom_stati',
81
-            array(
82
-                EEM_Event::cancelled => array(
83
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
84
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
85
-                ),
86
-                EEM_Event::postponed => array(
87
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
88
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
89
-                ),
90
-                EEM_Event::sold_out  => array(
91
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
92
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
93
-                ),
94
-            )
95
-        );
96
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
97
-            : self::$_default_reg_status;
98
-        $this->_tables = array(
99
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
100
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
101
-        );
102
-        $this->_fields = array(
103
-            'Event_CPT'  => array(
104
-                'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
105
-                    esc_html__('Post ID for Event', 'event_espresso')),
106
-                'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
107
-                    false,
108
-                    ''),
109
-                'EVT_desc'       => new EE_Post_Content_Field('post_content',
110
-                    esc_html__('Event Description', 'event_espresso'),
111
-                    false, ''),
112
-                'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
113
-                    ''),
114
-                'EVT_created'    => new EE_Datetime_Field('post_date',
115
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
116
-                    false, EE_Datetime_Field::now),
117
-                'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
118
-                    esc_html__('Event Short Description', 'event_espresso'), false, ''),
119
-                'EVT_modified'   => new EE_Datetime_Field('post_modified',
120
-                    esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
121
-                'EVT_wp_user'    => new EE_WP_User_Field('post_author',
122
-                    esc_html__('Event Creator ID', 'event_espresso'),
123
-                    false),
124
-                'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
125
-                    false,
126
-                    0),
127
-                'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
128
-                    false,
129
-                    1),
130
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
131
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
132
-                'status'         => new EE_WP_Post_Status_Field('post_status',
133
-                    esc_html__('Event Status', 'event_espresso'),
134
-                    false, 'draft', $this->_custom_stati),
135
-            ),
136
-            'Event_Meta' => array(
137
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
138
-                    esc_html__('Event Meta Row ID', 'event_espresso'), false),
139
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
140
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
141
-                'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
142
-                    esc_html__('Display Description Flag', 'event_espresso'), false, 1),
143
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
144
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
145
-                'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
146
-                    esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
147
-                'EVT_additional_limit'            => new EE_Integer_Field(
148
-                    'EVT_additional_limit',
149
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
150
-                    true,
151
-                    self::$_default_additional_limit
152
-                ),
153
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
154
-                    'EVT_default_registration_status',
155
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
156
-                    EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
157
-                ),
158
-                'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
159
-                    esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
160
-                'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
161
-                    esc_html__('Event Phone Number', 'event_espresso'), false,''),
162
-                'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
163
-                    esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
164
-                'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
165
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''),
166
-                'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
167
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
168
-                'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
169
-                    esc_html__('Accept Donations?', 'event_espresso'), false, false),
170
-            ),
171
-        );
172
-        $this->_model_relations = array(
173
-            'Registration'           => new EE_Has_Many_Relation(),
174
-            'Datetime'               => new EE_Has_Many_Relation(),
175
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
176
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
177
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
178
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
179
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
180
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
181
-            'WP_User'                => new EE_Belongs_To_Relation(),
182
-        );
183
-        //this model is generally available for reading
184
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
185
-        parent::__construct($timezone);
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * @param string $default_reg_status
192
-     */
193
-    public static function set_default_reg_status($default_reg_status)
194
-    {
195
-        self::$_default_reg_status = $default_reg_status;
196
-        // if EEM_Event has already been instantiated,
197
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
198
-        if (self::$_instance instanceof EEM_Event) {
199
-            $default_reg_status = new EE_Enum_Text_Field(
200
-                'EVT_default_registration_status',
201
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
202
-                false,
203
-                $default_reg_status,
204
-                EEM_Registration::reg_status_array()
205
-            );
206
-            $default_reg_status->_construct_finalize(
207
-                'Event_Meta',
208
-                'EVT_default_registration_status',
209
-                'EEM_Event'
210
-            );
211
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
212
-        }
213
-    }
214
-
215
-
216
-    /**
217
-     * Used to override the default for the additional limit field.
218
-     * @param $additional_limit
219
-     */
220
-    public static function set_default_additional_limit($additional_limit)
221
-    {
222
-        self::$_default_additional_limit = (int) $additional_limit;
223
-        if (self::$_instance instanceof EEM_Event) {
224
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
225
-                'EVT_additional_limit',
226
-                __('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
227
-                true,
228
-                self::$_default_additional_limit
229
-            );
230
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
231
-                'Event_Meta',
232
-                'EVT_additional_limit',
233
-                'EEM_Event'
234
-            );
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * Return what is currently set as the default additional limit for the event.
241
-     * @return int
242
-     */
243
-    public static function get_default_additional_limit()
244
-    {
245
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
246
-    }
247
-
248
-
249
-    /**
250
-     * get_question_groups
251
-     *
252
-     * @return array
253
-     * @throws \EE_Error
254
-     */
255
-    public function get_all_question_groups()
256
-    {
257
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
258
-            array(
259
-                array('QSG_deleted' => false),
260
-                'order_by' => array('QSG_order' => 'ASC'),
261
-            )
262
-        );
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * get_question_groups
269
-     *
270
-     * @param int $EVT_ID
271
-     * @return array|bool
272
-     * @throws \EE_Error
273
-     */
274
-    public function get_all_event_question_groups($EVT_ID = 0)
275
-    {
276
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
277
-            EE_Error::add_error(
278
-                esc_html__(
279
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
280
-                    'event_espresso'
281
-                ),
282
-                __FILE__, __FUNCTION__, __LINE__
283
-            );
284
-            return false;
285
-        }
286
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
287
-            array(
288
-                array('EVT_ID' => $EVT_ID),
289
-            )
290
-        );
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * get_question_groups
297
-     *
298
-     * @param int     $EVT_ID
299
-     * @param boolean $for_primary_attendee
300
-     * @return array|bool
301
-     * @throws \EE_Error
302
-     */
303
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
304
-    {
305
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
306
-            EE_Error::add_error(
307
-                esc_html__(
308
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
309
-                    'event_espresso'
310
-                ),
311
-                __FILE__, __FUNCTION__, __LINE__
312
-            );
313
-            return false;
314
-        }
315
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
316
-            array(
317
-                array(
318
-                    'EVT_ID'      => $EVT_ID,
319
-                    'EQG_primary' => $for_primary_attendee,
320
-                ),
321
-            )
322
-        );
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * get_question_groups
329
-     *
330
-     * @param int             $EVT_ID
331
-     * @param EE_Registration $registration
332
-     * @return array|bool
333
-     * @throws \EE_Error
334
-     */
335
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
336
-    {
337
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
338
-            EE_Error::add_error(
339
-                esc_html__(
340
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
341
-                    'event_espresso'
342
-                ),
343
-                __FILE__, __FUNCTION__, __LINE__
344
-            );
345
-            return false;
346
-        }
347
-        $where_params = array(
348
-            'Event_Question_Group.EVT_ID'      => $EVT_ID,
349
-            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
350
-            'QSG_deleted'                      => false,
351
-        );
352
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
-            array(
354
-                $where_params,
355
-                'order_by' => array('QSG_order' => 'ASC'),
356
-            )
357
-        );
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * get_question_target_db_column
364
-     *
365
-     * @param string $QSG_IDs csv list of $QSG IDs
366
-     * @return array|bool
367
-     * @throws \EE_Error
368
-     */
369
-    public function get_questions_in_groups($QSG_IDs = '')
370
-    {
371
-        if (empty($QSG_IDs)) {
372
-            EE_Error::add_error(
373
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
374
-                __FILE__, __FUNCTION__, __LINE__
375
-            );
376
-            return false;
377
-        }
378
-        return EE_Registry::instance()->load_model('Question')->get_all(
379
-            array(
380
-                array(
381
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
382
-                    'QST_deleted'           => false,
383
-                    'QST_admin_only'        => is_admin(),
384
-                ),
385
-                'order_by' => 'QST_order',
386
-            )
387
-        );
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * get_options_for_question
394
-     *
395
-     * @param string $QST_IDs csv list of $QST IDs
396
-     * @return array|bool
397
-     * @throws \EE_Error
398
-     */
399
-    public function get_options_for_question($QST_IDs)
400
-    {
401
-        if (empty($QST_IDs)) {
402
-            EE_Error::add_error(
403
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
404
-                __FILE__, __FUNCTION__, __LINE__
405
-            );
406
-            return false;
407
-        }
408
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
409
-            array(
410
-                array(
411
-                    'Question.QST_ID' => array('IN', $QST_IDs),
412
-                    'QSO_deleted'     => false,
413
-                ),
414
-                'order_by' => 'QSO_ID',
415
-            )
416
-        );
417
-    }
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-    /**
426
-     * Gets all events that are published
427
-     * and have event start time earlier than now and an event end time later than now
428
-     *
429
-     * @param  array $query_params An array of query params to further filter on
430
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
431
-     * @param bool   $count        whether to return the count or not (default FALSE)
432
-     * @return EE_Event[]|int
433
-     * @throws \EE_Error
434
-     */
435
-    public function get_active_events($query_params, $count = false)
436
-    {
437
-        if (array_key_exists(0, $query_params)) {
438
-            $where_params = $query_params[0];
439
-            unset($query_params[0]);
440
-        } else {
441
-            $where_params = array();
442
-        }
443
-        // if we have count make sure we don't include group by
444
-        if ($count && isset($query_params['group_by'])) {
445
-            unset($query_params['group_by']);
446
-        }
447
-        // let's add specific query_params for active_events
448
-        // keep in mind this will override any sent status in the query AND any date queries.
449
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
450
-        //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
451
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
452
-            $where_params['Datetime.DTT_EVT_start******'] = array(
453
-                '<',
454
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
455
-            );
456
-        } else {
457
-            $where_params['Datetime.DTT_EVT_start'] = array(
458
-                '<',
459
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
460
-            );
461
-        }
462
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
463
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
464
-                '>',
465
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
466
-            );
467
-        } else {
468
-            $where_params['Datetime.DTT_EVT_end'] = array(
469
-                '>',
470
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
471
-            );
472
-        }
473
-        $query_params[0] = $where_params;
474
-        // don't use $query_params with count()
475
-        // because we don't want to include additional query clauses like "GROUP BY"
476
-        return $count
477
-            ? $this->count(array($where_params), 'EVT_ID', true)
478
-            : $this->get_all($query_params);
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * get all events that are published and have an event start time later than now
485
-     *
486
-     * @param  array $query_params An array of query params to further filter on
487
-     *                             (Note that status and DTT_EVT_start will be overridden)
488
-     * @param bool   $count        whether to return the count or not (default FALSE)
489
-     * @return EE_Event[]|int
490
-     * @throws \EE_Error
491
-     */
492
-    public function get_upcoming_events($query_params, $count = false)
493
-    {
494
-        if (array_key_exists(0, $query_params)) {
495
-            $where_params = $query_params[0];
496
-            unset($query_params[0]);
497
-        } else {
498
-            $where_params = array();
499
-        }
500
-        // if we have count make sure we don't include group by
501
-        if ($count && isset($query_params['group_by'])) {
502
-            unset($query_params['group_by']);
503
-        }
504
-        // let's add specific query_params for active_events
505
-        // keep in mind this will override any sent status in the query AND any date queries.
506
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
507
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
508
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
509
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
510
-                '>',
511
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
512
-            );
513
-        } else {
514
-            $where_params['Datetime.DTT_EVT_start'] = array(
515
-                '>',
516
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
517
-            );
518
-        }
519
-        $query_params[0] = $where_params;
520
-        // don't use $query_params with count()
521
-        // because we don't want to include additional query clauses like "GROUP BY"
522
-        return $count
523
-            ? $this->count(array($where_params), 'EVT_ID', true)
524
-            : $this->get_all($query_params);
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * Gets all events that are published
531
-     * and have an event end time later than now
532
-     *
533
-     * @param  array $query_params An array of query params to further filter on
534
-     *                             (note that status and DTT_EVT_end will be overridden)
535
-     * @param bool   $count        whether to return the count or not (default FALSE)
536
-     * @return EE_Event[]|int
537
-     * @throws \EE_Error
538
-     */
539
-    public function get_active_and_upcoming_events($query_params, $count = false)
540
-    {
541
-        if (array_key_exists(0, $query_params)) {
542
-            $where_params = $query_params[0];
543
-            unset($query_params[0]);
544
-        } else {
545
-            $where_params = array();
546
-        }
547
-        // if we have count make sure we don't include group by
548
-        if ($count && isset($query_params['group_by'])) {
549
-            unset($query_params['group_by']);
550
-        }
551
-        // let's add specific query_params for active_events
552
-        // keep in mind this will override any sent status in the query AND any date queries.
553
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
554
-        // add where params for DTT_EVT_end
555
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
556
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
557
-                '>',
558
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
559
-            );
560
-        } else {
561
-            $where_params['Datetime.DTT_EVT_end'] = array(
562
-                '>',
563
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
564
-            );
565
-        }
566
-        $query_params[0] = $where_params;
567
-        // don't use $query_params with count()
568
-        // because we don't want to include additional query clauses like "GROUP BY"
569
-        return $count
570
-            ? $this->count(array($where_params), 'EVT_ID', true)
571
-            : $this->get_all($query_params);
572
-    }
573
-
574
-
575
-
576
-    /**
577
-     * This only returns events that are expired.
578
-     * They may still be published but all their datetimes have expired.
579
-     *
580
-     * @param  array $query_params An array of query params to further filter on
581
-     *                             (note that status and DTT_EVT_end will be overridden)
582
-     * @param bool   $count        whether to return the count or not (default FALSE)
583
-     * @return EE_Event[]|int
584
-     * @throws \EE_Error
585
-     */
586
-    public function get_expired_events($query_params, $count = false)
587
-    {
588
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
589
-        // if we have count make sure we don't include group by
590
-        if ($count && isset($query_params['group_by'])) {
591
-            unset($query_params['group_by']);
592
-        }
593
-        // let's add specific query_params for active_events
594
-        // keep in mind this will override any sent status in the query AND any date queries.
595
-        if (isset($where_params['status'])) {
596
-            unset($where_params['status']);
597
-        }
598
-        $exclude_query = $query_params;
599
-        if (isset($exclude_query[0])) {
600
-            unset($exclude_query[0]);
601
-        }
602
-        $exclude_query[0] = array(
603
-            'Datetime.DTT_EVT_end' => array(
604
-                '>',
605
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
606
-            ),
607
-        );
608
-        // first get all events that have datetimes where its not expired.
609
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
610
-        $event_ids = array_keys($event_ids);
611
-        // if we have any additional query_params, let's add them to the 'AND' condition
612
-        $and_condition = array(
613
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
614
-            'EVT_ID'               => array('NOT IN', $event_ids),
615
-        );
616
-        if (isset($where_params['OR'])) {
617
-            $and_condition['OR'] = $where_params['OR'];
618
-            unset($where_params['OR']);
619
-        }
620
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
621
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
622
-            unset($where_params['Datetime.DTT_EVT_end']);
623
-        }
624
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
625
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
626
-            unset($where_params['Datetime.DTT_EVT_start']);
627
-        }
628
-        // merge remaining $where params with the and conditions.
629
-        $where_params['AND'] = array_merge($and_condition, $where_params);
630
-        $query_params[0] = $where_params;
631
-        // don't use $query_params with count()
632
-        // because we don't want to include additional query clauses like "GROUP BY"
633
-        return $count
634
-            ? $this->count(array($where_params), 'EVT_ID', true)
635
-            : $this->get_all($query_params);
636
-    }
637
-
638
-
639
-
640
-    /**
641
-     * This basically just returns the events that do not have the publish status.
642
-     *
643
-     * @param  array   $query_params An array of query params to further filter on
644
-     *                               (note that status will be overwritten)
645
-     * @param  boolean $count        whether to return the count or not (default FALSE)
646
-     * @return EE_Event[]|int
647
-     * @throws \EE_Error
648
-     */
649
-    public function get_inactive_events($query_params, $count = false)
650
-    {
651
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
652
-        // let's add in specific query_params for inactive events.
653
-        if (isset($where_params['status'])) {
654
-            unset($where_params['status']);
655
-        }
656
-        // if we have count make sure we don't include group by
657
-        if ($count && isset($query_params['group_by'])) {
658
-            unset($query_params['group_by']);
659
-        }
660
-        // if we have any additional query_params, let's add them to the 'AND' condition
661
-        $where_params['AND']['status'] = array('!=', 'publish');
662
-        if (isset($where_params['OR'])) {
663
-            $where_params['AND']['OR'] = $where_params['OR'];
664
-            unset($where_params['OR']);
665
-        }
666
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
667
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
668
-            unset($where_params['Datetime.DTT_EVT_end']);
669
-        }
670
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
671
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
672
-            unset($where_params['Datetime.DTT_EVT_start']);
673
-        }
674
-        $query_params[0] = $where_params;
675
-        // don't use $query_params with count()
676
-        // because we don't want to include additional query clauses like "GROUP BY"
677
-        return $count
678
-            ? $this->count(array($where_params), 'EVT_ID', true)
679
-            : $this->get_all($query_params);
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
686
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
687
-     * attached to the event. See parent for param descriptions
688
-     *
689
-     * @param        $id_or_obj
690
-     * @param        $other_model_id_or_obj
691
-     * @param string $relationName
692
-     * @param array  $where_query
693
-     * @return EE_Base_Class
694
-     * @throws EE_Error
695
-     */
696
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
697
-    {
698
-        if ($relationName === 'Price') {
699
-            //let's get the PRC object for the given ID to make sure that we aren't dealing with a default
700
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
701
-            //if EVT_ID = 0, then this is a default
702
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
703
-                //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
704
-                $prc_chk->set('PRC_ID', 0);
705
-            }
706
-            //run parent
707
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
708
-        }
709
-        //otherwise carry on as normal
710
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
711
-    }
712
-
713
-
714
-
715
-    /******************** DEPRECATED METHODS ********************/
716
-
717
-
718
-
719
-    /**
720
-     * _get_question_target_db_column
721
-     *
722
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
723
-     *             EE_Registration_Custom_Questions_Form located in
724
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
725
-     * @access     public
726
-     * @param    EE_Registration $registration (so existing answers for registration are included)
727
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
728
-     *                                         registration).
729
-     * @throws EE_Error
730
-     * @return    array
731
-     */
732
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
733
-    {
734
-        if (empty($EVT_ID)) {
735
-            throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
736
-                'event_espresso'));
737
-        }
738
-        $questions = array();
739
-        // get all question groups for event
740
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
741
-        if (! empty($qgs)) {
742
-            foreach ($qgs as $qg) {
743
-                $qsts = $qg->questions();
744
-                $questions[$qg->ID()] = $qg->model_field_array();
745
-                $questions[$qg->ID()]['QSG_questions'] = array();
746
-                foreach ($qsts as $qst) {
747
-                    if ($qst->is_system_question()) {
748
-                        continue;
749
-                    }
750
-                    $answer = EEM_Answer::instance()->get_one(array(
751
-                        array(
752
-                            'QST_ID' => $qst->ID(),
753
-                            'REG_ID' => $registration->ID(),
754
-                        ),
755
-                    ));
756
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
757
-                    $qst_name = $qstn_id = $qst->ID();
758
-                    $ans_id = $answer->ID();
759
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
760
-                    $input_name = '';
761
-                    $input_id = sanitize_key($qst->display_text());
762
-                    $input_class = '';
763
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
764
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
765
-                                                                                           . $input_name
766
-                                                                                           . $qst_name;
767
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
768
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
769
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
770
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
771
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
772
-                    //leave responses as-is, don't convert stuff into html entities please!
773
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
774
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
775
-                        $QSOs = $qst->options(true, $answer->value());
776
-                        if (is_array($QSOs)) {
777
-                            foreach ($QSOs as $QSO_ID => $QSO) {
778
-                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
779
-                            }
780
-                        }
781
-                    }
782
-                }
783
-            }
784
-        }
785
-        return $questions;
786
-    }
787
-
788
-
789
-    /**
790
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
791
-     *                             or an stdClass where each property is the name of a column,
792
-     * @return EE_Base_Class
793
-     * @throws \EE_Error
794
-     */
795
-    public function instantiate_class_from_array_or_object($cols_n_values)
796
-    {
797
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
798
-        if($classInstance instanceof EE_Event) {
799
-            //events have their timezone defined in the DB, so use it immediately
800
-            $this->set_timezone($classInstance->get_timezone());
801
-        }
802
-        return $classInstance;
803
-    }
21
+	/**
22
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
23
+	 * event
24
+	 */
25
+	const sold_out = 'sold_out';
26
+
27
+	/**
28
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
29
+	 * date)
30
+	 */
31
+	const postponed = 'postponed';
32
+
33
+	/**
34
+	 * constant used by status(), indicating that the event will no longer occur
35
+	 */
36
+	const cancelled = 'cancelled';
37
+
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	protected static $_default_reg_status;
43
+
44
+
45
+	/**
46
+	 * This is the default for the additional limit field.
47
+	 * @var int
48
+	 */
49
+	protected static $_default_additional_limit = 10;
50
+
51
+
52
+	/**
53
+	 * private instance of the Event object
54
+	 *
55
+	 * @var EEM_Event
56
+	 */
57
+	protected static $_instance;
58
+
59
+
60
+
61
+
62
+	/**
63
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
64
+	 *
65
+	 * @param string $timezone
66
+	 * @throws \EE_Error
67
+	 */
68
+	protected function __construct($timezone = null)
69
+	{
70
+		EE_Registry::instance()->load_model('Registration');
71
+		$this->singular_item = esc_html__('Event', 'event_espresso');
72
+		$this->plural_item = esc_html__('Events', 'event_espresso');
73
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
74
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
75
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
76
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
77
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
78
+		//	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
79
+		$this->_custom_stati = apply_filters(
80
+			'AFEE__EEM_Event__construct___custom_stati',
81
+			array(
82
+				EEM_Event::cancelled => array(
83
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
84
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
85
+				),
86
+				EEM_Event::postponed => array(
87
+					'label'  => esc_html__('Postponed', 'event_espresso'),
88
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
89
+				),
90
+				EEM_Event::sold_out  => array(
91
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
92
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
93
+				),
94
+			)
95
+		);
96
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
97
+			: self::$_default_reg_status;
98
+		$this->_tables = array(
99
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
100
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
101
+		);
102
+		$this->_fields = array(
103
+			'Event_CPT'  => array(
104
+				'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
105
+					esc_html__('Post ID for Event', 'event_espresso')),
106
+				'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
107
+					false,
108
+					''),
109
+				'EVT_desc'       => new EE_Post_Content_Field('post_content',
110
+					esc_html__('Event Description', 'event_espresso'),
111
+					false, ''),
112
+				'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
113
+					''),
114
+				'EVT_created'    => new EE_Datetime_Field('post_date',
115
+					esc_html__('Date/Time Event Created', 'event_espresso'),
116
+					false, EE_Datetime_Field::now),
117
+				'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
118
+					esc_html__('Event Short Description', 'event_espresso'), false, ''),
119
+				'EVT_modified'   => new EE_Datetime_Field('post_modified',
120
+					esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
121
+				'EVT_wp_user'    => new EE_WP_User_Field('post_author',
122
+					esc_html__('Event Creator ID', 'event_espresso'),
123
+					false),
124
+				'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
125
+					false,
126
+					0),
127
+				'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
128
+					false,
129
+					1),
130
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
131
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
132
+				'status'         => new EE_WP_Post_Status_Field('post_status',
133
+					esc_html__('Event Status', 'event_espresso'),
134
+					false, 'draft', $this->_custom_stati),
135
+			),
136
+			'Event_Meta' => array(
137
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
138
+					esc_html__('Event Meta Row ID', 'event_espresso'), false),
139
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
140
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
141
+				'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
142
+					esc_html__('Display Description Flag', 'event_espresso'), false, 1),
143
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
144
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
145
+				'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
146
+					esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
147
+				'EVT_additional_limit'            => new EE_Integer_Field(
148
+					'EVT_additional_limit',
149
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
150
+					true,
151
+					self::$_default_additional_limit
152
+				),
153
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
154
+					'EVT_default_registration_status',
155
+					esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
156
+					EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
157
+				),
158
+				'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
159
+					esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
160
+				'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
161
+					esc_html__('Event Phone Number', 'event_espresso'), false,''),
162
+				'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
163
+					esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
164
+				'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
165
+					esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''),
166
+				'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
167
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
168
+				'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
169
+					esc_html__('Accept Donations?', 'event_espresso'), false, false),
170
+			),
171
+		);
172
+		$this->_model_relations = array(
173
+			'Registration'           => new EE_Has_Many_Relation(),
174
+			'Datetime'               => new EE_Has_Many_Relation(),
175
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
176
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
177
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
178
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
179
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
180
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
181
+			'WP_User'                => new EE_Belongs_To_Relation(),
182
+		);
183
+		//this model is generally available for reading
184
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
185
+		parent::__construct($timezone);
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * @param string $default_reg_status
192
+	 */
193
+	public static function set_default_reg_status($default_reg_status)
194
+	{
195
+		self::$_default_reg_status = $default_reg_status;
196
+		// if EEM_Event has already been instantiated,
197
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
198
+		if (self::$_instance instanceof EEM_Event) {
199
+			$default_reg_status = new EE_Enum_Text_Field(
200
+				'EVT_default_registration_status',
201
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
202
+				false,
203
+				$default_reg_status,
204
+				EEM_Registration::reg_status_array()
205
+			);
206
+			$default_reg_status->_construct_finalize(
207
+				'Event_Meta',
208
+				'EVT_default_registration_status',
209
+				'EEM_Event'
210
+			);
211
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
212
+		}
213
+	}
214
+
215
+
216
+	/**
217
+	 * Used to override the default for the additional limit field.
218
+	 * @param $additional_limit
219
+	 */
220
+	public static function set_default_additional_limit($additional_limit)
221
+	{
222
+		self::$_default_additional_limit = (int) $additional_limit;
223
+		if (self::$_instance instanceof EEM_Event) {
224
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
225
+				'EVT_additional_limit',
226
+				__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
227
+				true,
228
+				self::$_default_additional_limit
229
+			);
230
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
231
+				'Event_Meta',
232
+				'EVT_additional_limit',
233
+				'EEM_Event'
234
+			);
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * Return what is currently set as the default additional limit for the event.
241
+	 * @return int
242
+	 */
243
+	public static function get_default_additional_limit()
244
+	{
245
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
246
+	}
247
+
248
+
249
+	/**
250
+	 * get_question_groups
251
+	 *
252
+	 * @return array
253
+	 * @throws \EE_Error
254
+	 */
255
+	public function get_all_question_groups()
256
+	{
257
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
258
+			array(
259
+				array('QSG_deleted' => false),
260
+				'order_by' => array('QSG_order' => 'ASC'),
261
+			)
262
+		);
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * get_question_groups
269
+	 *
270
+	 * @param int $EVT_ID
271
+	 * @return array|bool
272
+	 * @throws \EE_Error
273
+	 */
274
+	public function get_all_event_question_groups($EVT_ID = 0)
275
+	{
276
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
277
+			EE_Error::add_error(
278
+				esc_html__(
279
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
280
+					'event_espresso'
281
+				),
282
+				__FILE__, __FUNCTION__, __LINE__
283
+			);
284
+			return false;
285
+		}
286
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
287
+			array(
288
+				array('EVT_ID' => $EVT_ID),
289
+			)
290
+		);
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * get_question_groups
297
+	 *
298
+	 * @param int     $EVT_ID
299
+	 * @param boolean $for_primary_attendee
300
+	 * @return array|bool
301
+	 * @throws \EE_Error
302
+	 */
303
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
304
+	{
305
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
306
+			EE_Error::add_error(
307
+				esc_html__(
308
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
309
+					'event_espresso'
310
+				),
311
+				__FILE__, __FUNCTION__, __LINE__
312
+			);
313
+			return false;
314
+		}
315
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
316
+			array(
317
+				array(
318
+					'EVT_ID'      => $EVT_ID,
319
+					'EQG_primary' => $for_primary_attendee,
320
+				),
321
+			)
322
+		);
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * get_question_groups
329
+	 *
330
+	 * @param int             $EVT_ID
331
+	 * @param EE_Registration $registration
332
+	 * @return array|bool
333
+	 * @throws \EE_Error
334
+	 */
335
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
336
+	{
337
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
338
+			EE_Error::add_error(
339
+				esc_html__(
340
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
341
+					'event_espresso'
342
+				),
343
+				__FILE__, __FUNCTION__, __LINE__
344
+			);
345
+			return false;
346
+		}
347
+		$where_params = array(
348
+			'Event_Question_Group.EVT_ID'      => $EVT_ID,
349
+			'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
350
+			'QSG_deleted'                      => false,
351
+		);
352
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
+			array(
354
+				$where_params,
355
+				'order_by' => array('QSG_order' => 'ASC'),
356
+			)
357
+		);
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * get_question_target_db_column
364
+	 *
365
+	 * @param string $QSG_IDs csv list of $QSG IDs
366
+	 * @return array|bool
367
+	 * @throws \EE_Error
368
+	 */
369
+	public function get_questions_in_groups($QSG_IDs = '')
370
+	{
371
+		if (empty($QSG_IDs)) {
372
+			EE_Error::add_error(
373
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
374
+				__FILE__, __FUNCTION__, __LINE__
375
+			);
376
+			return false;
377
+		}
378
+		return EE_Registry::instance()->load_model('Question')->get_all(
379
+			array(
380
+				array(
381
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
382
+					'QST_deleted'           => false,
383
+					'QST_admin_only'        => is_admin(),
384
+				),
385
+				'order_by' => 'QST_order',
386
+			)
387
+		);
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * get_options_for_question
394
+	 *
395
+	 * @param string $QST_IDs csv list of $QST IDs
396
+	 * @return array|bool
397
+	 * @throws \EE_Error
398
+	 */
399
+	public function get_options_for_question($QST_IDs)
400
+	{
401
+		if (empty($QST_IDs)) {
402
+			EE_Error::add_error(
403
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
404
+				__FILE__, __FUNCTION__, __LINE__
405
+			);
406
+			return false;
407
+		}
408
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
409
+			array(
410
+				array(
411
+					'Question.QST_ID' => array('IN', $QST_IDs),
412
+					'QSO_deleted'     => false,
413
+				),
414
+				'order_by' => 'QSO_ID',
415
+			)
416
+		);
417
+	}
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+	/**
426
+	 * Gets all events that are published
427
+	 * and have event start time earlier than now and an event end time later than now
428
+	 *
429
+	 * @param  array $query_params An array of query params to further filter on
430
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
431
+	 * @param bool   $count        whether to return the count or not (default FALSE)
432
+	 * @return EE_Event[]|int
433
+	 * @throws \EE_Error
434
+	 */
435
+	public function get_active_events($query_params, $count = false)
436
+	{
437
+		if (array_key_exists(0, $query_params)) {
438
+			$where_params = $query_params[0];
439
+			unset($query_params[0]);
440
+		} else {
441
+			$where_params = array();
442
+		}
443
+		// if we have count make sure we don't include group by
444
+		if ($count && isset($query_params['group_by'])) {
445
+			unset($query_params['group_by']);
446
+		}
447
+		// let's add specific query_params for active_events
448
+		// keep in mind this will override any sent status in the query AND any date queries.
449
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
450
+		//if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
451
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
452
+			$where_params['Datetime.DTT_EVT_start******'] = array(
453
+				'<',
454
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
455
+			);
456
+		} else {
457
+			$where_params['Datetime.DTT_EVT_start'] = array(
458
+				'<',
459
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
460
+			);
461
+		}
462
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
463
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
464
+				'>',
465
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
466
+			);
467
+		} else {
468
+			$where_params['Datetime.DTT_EVT_end'] = array(
469
+				'>',
470
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
471
+			);
472
+		}
473
+		$query_params[0] = $where_params;
474
+		// don't use $query_params with count()
475
+		// because we don't want to include additional query clauses like "GROUP BY"
476
+		return $count
477
+			? $this->count(array($where_params), 'EVT_ID', true)
478
+			: $this->get_all($query_params);
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * get all events that are published and have an event start time later than now
485
+	 *
486
+	 * @param  array $query_params An array of query params to further filter on
487
+	 *                             (Note that status and DTT_EVT_start will be overridden)
488
+	 * @param bool   $count        whether to return the count or not (default FALSE)
489
+	 * @return EE_Event[]|int
490
+	 * @throws \EE_Error
491
+	 */
492
+	public function get_upcoming_events($query_params, $count = false)
493
+	{
494
+		if (array_key_exists(0, $query_params)) {
495
+			$where_params = $query_params[0];
496
+			unset($query_params[0]);
497
+		} else {
498
+			$where_params = array();
499
+		}
500
+		// if we have count make sure we don't include group by
501
+		if ($count && isset($query_params['group_by'])) {
502
+			unset($query_params['group_by']);
503
+		}
504
+		// let's add specific query_params for active_events
505
+		// keep in mind this will override any sent status in the query AND any date queries.
506
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
507
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
508
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
509
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
510
+				'>',
511
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
512
+			);
513
+		} else {
514
+			$where_params['Datetime.DTT_EVT_start'] = array(
515
+				'>',
516
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
517
+			);
518
+		}
519
+		$query_params[0] = $where_params;
520
+		// don't use $query_params with count()
521
+		// because we don't want to include additional query clauses like "GROUP BY"
522
+		return $count
523
+			? $this->count(array($where_params), 'EVT_ID', true)
524
+			: $this->get_all($query_params);
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * Gets all events that are published
531
+	 * and have an event end time later than now
532
+	 *
533
+	 * @param  array $query_params An array of query params to further filter on
534
+	 *                             (note that status and DTT_EVT_end will be overridden)
535
+	 * @param bool   $count        whether to return the count or not (default FALSE)
536
+	 * @return EE_Event[]|int
537
+	 * @throws \EE_Error
538
+	 */
539
+	public function get_active_and_upcoming_events($query_params, $count = false)
540
+	{
541
+		if (array_key_exists(0, $query_params)) {
542
+			$where_params = $query_params[0];
543
+			unset($query_params[0]);
544
+		} else {
545
+			$where_params = array();
546
+		}
547
+		// if we have count make sure we don't include group by
548
+		if ($count && isset($query_params['group_by'])) {
549
+			unset($query_params['group_by']);
550
+		}
551
+		// let's add specific query_params for active_events
552
+		// keep in mind this will override any sent status in the query AND any date queries.
553
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
554
+		// add where params for DTT_EVT_end
555
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
556
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
557
+				'>',
558
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
559
+			);
560
+		} else {
561
+			$where_params['Datetime.DTT_EVT_end'] = array(
562
+				'>',
563
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
564
+			);
565
+		}
566
+		$query_params[0] = $where_params;
567
+		// don't use $query_params with count()
568
+		// because we don't want to include additional query clauses like "GROUP BY"
569
+		return $count
570
+			? $this->count(array($where_params), 'EVT_ID', true)
571
+			: $this->get_all($query_params);
572
+	}
573
+
574
+
575
+
576
+	/**
577
+	 * This only returns events that are expired.
578
+	 * They may still be published but all their datetimes have expired.
579
+	 *
580
+	 * @param  array $query_params An array of query params to further filter on
581
+	 *                             (note that status and DTT_EVT_end will be overridden)
582
+	 * @param bool   $count        whether to return the count or not (default FALSE)
583
+	 * @return EE_Event[]|int
584
+	 * @throws \EE_Error
585
+	 */
586
+	public function get_expired_events($query_params, $count = false)
587
+	{
588
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
589
+		// if we have count make sure we don't include group by
590
+		if ($count && isset($query_params['group_by'])) {
591
+			unset($query_params['group_by']);
592
+		}
593
+		// let's add specific query_params for active_events
594
+		// keep in mind this will override any sent status in the query AND any date queries.
595
+		if (isset($where_params['status'])) {
596
+			unset($where_params['status']);
597
+		}
598
+		$exclude_query = $query_params;
599
+		if (isset($exclude_query[0])) {
600
+			unset($exclude_query[0]);
601
+		}
602
+		$exclude_query[0] = array(
603
+			'Datetime.DTT_EVT_end' => array(
604
+				'>',
605
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
606
+			),
607
+		);
608
+		// first get all events that have datetimes where its not expired.
609
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
610
+		$event_ids = array_keys($event_ids);
611
+		// if we have any additional query_params, let's add them to the 'AND' condition
612
+		$and_condition = array(
613
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
614
+			'EVT_ID'               => array('NOT IN', $event_ids),
615
+		);
616
+		if (isset($where_params['OR'])) {
617
+			$and_condition['OR'] = $where_params['OR'];
618
+			unset($where_params['OR']);
619
+		}
620
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
621
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
622
+			unset($where_params['Datetime.DTT_EVT_end']);
623
+		}
624
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
625
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
626
+			unset($where_params['Datetime.DTT_EVT_start']);
627
+		}
628
+		// merge remaining $where params with the and conditions.
629
+		$where_params['AND'] = array_merge($and_condition, $where_params);
630
+		$query_params[0] = $where_params;
631
+		// don't use $query_params with count()
632
+		// because we don't want to include additional query clauses like "GROUP BY"
633
+		return $count
634
+			? $this->count(array($where_params), 'EVT_ID', true)
635
+			: $this->get_all($query_params);
636
+	}
637
+
638
+
639
+
640
+	/**
641
+	 * This basically just returns the events that do not have the publish status.
642
+	 *
643
+	 * @param  array   $query_params An array of query params to further filter on
644
+	 *                               (note that status will be overwritten)
645
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
646
+	 * @return EE_Event[]|int
647
+	 * @throws \EE_Error
648
+	 */
649
+	public function get_inactive_events($query_params, $count = false)
650
+	{
651
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
652
+		// let's add in specific query_params for inactive events.
653
+		if (isset($where_params['status'])) {
654
+			unset($where_params['status']);
655
+		}
656
+		// if we have count make sure we don't include group by
657
+		if ($count && isset($query_params['group_by'])) {
658
+			unset($query_params['group_by']);
659
+		}
660
+		// if we have any additional query_params, let's add them to the 'AND' condition
661
+		$where_params['AND']['status'] = array('!=', 'publish');
662
+		if (isset($where_params['OR'])) {
663
+			$where_params['AND']['OR'] = $where_params['OR'];
664
+			unset($where_params['OR']);
665
+		}
666
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
667
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
668
+			unset($where_params['Datetime.DTT_EVT_end']);
669
+		}
670
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
671
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
672
+			unset($where_params['Datetime.DTT_EVT_start']);
673
+		}
674
+		$query_params[0] = $where_params;
675
+		// don't use $query_params with count()
676
+		// because we don't want to include additional query clauses like "GROUP BY"
677
+		return $count
678
+			? $this->count(array($where_params), 'EVT_ID', true)
679
+			: $this->get_all($query_params);
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
686
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
687
+	 * attached to the event. See parent for param descriptions
688
+	 *
689
+	 * @param        $id_or_obj
690
+	 * @param        $other_model_id_or_obj
691
+	 * @param string $relationName
692
+	 * @param array  $where_query
693
+	 * @return EE_Base_Class
694
+	 * @throws EE_Error
695
+	 */
696
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
697
+	{
698
+		if ($relationName === 'Price') {
699
+			//let's get the PRC object for the given ID to make sure that we aren't dealing with a default
700
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
701
+			//if EVT_ID = 0, then this is a default
702
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
703
+				//let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
704
+				$prc_chk->set('PRC_ID', 0);
705
+			}
706
+			//run parent
707
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
708
+		}
709
+		//otherwise carry on as normal
710
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
711
+	}
712
+
713
+
714
+
715
+	/******************** DEPRECATED METHODS ********************/
716
+
717
+
718
+
719
+	/**
720
+	 * _get_question_target_db_column
721
+	 *
722
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
723
+	 *             EE_Registration_Custom_Questions_Form located in
724
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
725
+	 * @access     public
726
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
727
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
728
+	 *                                         registration).
729
+	 * @throws EE_Error
730
+	 * @return    array
731
+	 */
732
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
733
+	{
734
+		if (empty($EVT_ID)) {
735
+			throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
736
+				'event_espresso'));
737
+		}
738
+		$questions = array();
739
+		// get all question groups for event
740
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
741
+		if (! empty($qgs)) {
742
+			foreach ($qgs as $qg) {
743
+				$qsts = $qg->questions();
744
+				$questions[$qg->ID()] = $qg->model_field_array();
745
+				$questions[$qg->ID()]['QSG_questions'] = array();
746
+				foreach ($qsts as $qst) {
747
+					if ($qst->is_system_question()) {
748
+						continue;
749
+					}
750
+					$answer = EEM_Answer::instance()->get_one(array(
751
+						array(
752
+							'QST_ID' => $qst->ID(),
753
+							'REG_ID' => $registration->ID(),
754
+						),
755
+					));
756
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
757
+					$qst_name = $qstn_id = $qst->ID();
758
+					$ans_id = $answer->ID();
759
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
760
+					$input_name = '';
761
+					$input_id = sanitize_key($qst->display_text());
762
+					$input_class = '';
763
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
764
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
765
+																						   . $input_name
766
+																						   . $qst_name;
767
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
768
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
769
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
770
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
771
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
772
+					//leave responses as-is, don't convert stuff into html entities please!
773
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
774
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
775
+						$QSOs = $qst->options(true, $answer->value());
776
+						if (is_array($QSOs)) {
777
+							foreach ($QSOs as $QSO_ID => $QSO) {
778
+								$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
779
+							}
780
+						}
781
+					}
782
+				}
783
+			}
784
+		}
785
+		return $questions;
786
+	}
787
+
788
+
789
+	/**
790
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
791
+	 *                             or an stdClass where each property is the name of a column,
792
+	 * @return EE_Base_Class
793
+	 * @throws \EE_Error
794
+	 */
795
+	public function instantiate_class_from_array_or_object($cols_n_values)
796
+	{
797
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
798
+		if($classInstance instanceof EE_Event) {
799
+			//events have their timezone defined in the DB, so use it immediately
800
+			$this->set_timezone($classInstance->get_timezone());
801
+		}
802
+		return $classInstance;
803
+	}
804 804
 }
805 805
 // End of file EEM_Event.model.php
806 806
 // Location: /includes/models/EEM_Event.model.php
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\orm\ModelFieldFactory;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6
-require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
6
+require_once(EE_MODELS.'EEM_CPT_Base.model.php');
7 7
 
8 8
 
9 9
 
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
                 'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
159 159
                     esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
160 160
                 'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
161
-                    esc_html__('Event Phone Number', 'event_espresso'), false,''),
161
+                    esc_html__('Event Phone Number', 'event_espresso'), false, ''),
162 162
                 'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
163 163
                     esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
164 164
                 'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
165
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''),
165
+                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false, ''),
166 166
                 'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
167 167
                     esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
168 168
                 'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      */
274 274
     public function get_all_event_question_groups($EVT_ID = 0)
275 275
     {
276
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
276
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
277 277
             EE_Error::add_error(
278 278
                 esc_html__(
279 279
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      */
303 303
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
304 304
     {
305
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
305
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
306 306
             EE_Error::add_error(
307 307
                 esc_html__(
308 308
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
      */
335 335
     public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
336 336
     {
337
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
337
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
338 338
             EE_Error::add_error(
339 339
                 esc_html__(
340 340
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
         $questions = array();
739 739
         // get all question groups for event
740 740
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
741
-        if (! empty($qgs)) {
741
+        if ( ! empty($qgs)) {
742 742
             foreach ($qgs as $qg) {
743 743
                 $qsts = $qg->questions();
744 744
                 $questions[$qg->ID()] = $qg->model_field_array();
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
757 757
                     $qst_name = $qstn_id = $qst->ID();
758 758
                     $ans_id = $answer->ID();
759
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
759
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
760 760
                     $input_name = '';
761 761
                     $input_id = sanitize_key($qst->display_text());
762 762
                     $input_class = '';
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
765 765
                                                                                            . $input_name
766 766
                                                                                            . $qst_name;
767
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
767
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
768 768
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
769 769
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
770 770
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
     public function instantiate_class_from_array_or_object($cols_n_values)
796 796
     {
797 797
         $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
798
-        if($classInstance instanceof EE_Event) {
798
+        if ($classInstance instanceof EE_Event) {
799 799
             //events have their timezone defined in the DB, so use it immediately
800 800
             $this->set_timezone($classInstance->get_timezone());
801 801
         }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3065,7 +3065,7 @@
 block discarded – undo
3065 3065
      *
3066 3066
      * @param  int  $GRP_ID        The group being deleted
3067 3067
      * @param  bool $include_group whether to delete the Message Template Group as well.
3068
-     * @return bool boolean to indicate the success of the deletes or not.
3068
+     * @return integer boolean to indicate the success of the deletes or not.
3069 3069
      * @throws EE_Error
3070 3070
      * @throws InvalidArgumentException
3071 3071
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         $this->_admin_base_url  = EE_MSG_ADMIN_URL;
94 94
         $this->_admin_base_path = EE_MSG_ADMIN;
95 95
         
96
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
96
+        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array();
97 97
         
98 98
         $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
99 99
         $this->_load_message_resource_manager();
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
             array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
253 253
             $messenger_options
254 254
         );
255
-        $input             = new EE_Select_Input(
255
+        $input = new EE_Select_Input(
256 256
             $messenger_options,
257 257
             array(
258 258
                 'html_name'  => 'ee_messenger_filter_by',
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
             array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291 291
             $message_type_options
292 292
         );
293
-        $input                = new EE_Select_Input(
293
+        $input = new EE_Select_Input(
294 294
             $message_type_options,
295 295
             array(
296 296
                 'html_name'  => 'ee_message_type_filter_by',
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
329 329
             $context_options
330 330
         );
331
-        $input           = new EE_Select_Input(
331
+        $input = new EE_Select_Input(
332 332
             $context_options,
333 333
             array(
334 334
                 'html_name'  => 'ee_context_filter_by',
@@ -710,53 +710,53 @@  discard block
 block discarded – undo
710 710
     
711 711
     public function messages_help_tab()
712 712
     {
713
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
713
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
714 714
     }
715 715
     
716 716
     
717 717
     public function messengers_help_tab()
718 718
     {
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
719
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
720 720
     }
721 721
     
722 722
     
723 723
     public function message_types_help_tab()
724 724
     {
725
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
725
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
726 726
     }
727 727
     
728 728
     
729 729
     public function messages_overview_help_tab()
730 730
     {
731
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
731
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
732 732
     }
733 733
     
734 734
     
735 735
     public function message_templates_help_tab()
736 736
     {
737
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
737
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
738 738
     }
739 739
     
740 740
     
741 741
     public function edit_message_template_help_tab()
742 742
     {
743
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
743
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
744 744
                         . esc_attr__('Editor Title', 'event_espresso')
745 745
                         . '" />';
746
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
746
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
747 747
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
748 748
                         . '" />';
749
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
749
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
750 750
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
751 751
                         . '" />';
752
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
752
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
753 753
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
754 754
                         . '" />';
755
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
755
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
756 756
                         . esc_attr__('Publish Metabox', 'event_espresso')
757 757
                         . '" />';
758 758
         EEH_Template::display_template(
759
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
759
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
760 760
             $args
761 761
         );
762 762
     }
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
         $this->_set_shortcodes();
768 768
         $args['shortcodes'] = $this->_shortcodes;
769 769
         EEH_Template::display_template(
770
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
770
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
771 771
             $args
772 772
         );
773 773
     }
@@ -775,16 +775,16 @@  discard block
 block discarded – undo
775 775
     
776 776
     public function preview_message_help_tab()
777 777
     {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
778
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
779 779
     }
780 780
     
781 781
     
782 782
     public function settings_help_tab()
783 783
     {
784
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
785
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
786
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
787
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
784
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
785
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
786
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
787
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
788 788
         $args['img3'] = '<div class="switch">'
789 789
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
790 790
                         . ' type="checkbox" checked="checked">'
@@ -795,18 +795,18 @@  discard block
 block discarded – undo
795 795
                         . ' type="checkbox">'
796 796
                         . '<label for="ee-on-off-toggle-on"></label>'
797 797
                         . '</div>';
798
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
798
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
799 799
     }
800 800
     
801 801
     
802 802
     public function load_scripts_styles()
803 803
     {
804
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
804
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
805 805
         wp_enqueue_style('espresso_ee_msg');
806 806
         
807
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
807
+        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js',
808 808
             array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
809
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
809
+        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
810 810
             array('ee-dialog'), EVENT_ESPRESSO_VERSION);
811 811
     }
812 812
     
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
         
839 839
         $this->_set_shortcodes();
840 840
         
841
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
841
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
842 842
             esc_html__(
843 843
                 '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.',
844 844
                 'event_espresso'
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
         
854 854
         wp_register_script(
855 855
             'ee_msgs_edit_js',
856
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
856
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
857 857
             array('jquery'),
858 858
             EVENT_ESPRESSO_VERSION
859 859
         );
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
     {
897 897
         wp_register_style(
898 898
             'ee-message-settings',
899
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
899
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
900 900
             array(),
901 901
             EVENT_ESPRESSO_VERSION
902 902
         );
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
             }
983 983
             $status_bulk_actions = $common_bulk_actions;
984 984
             //unset bulk actions not applying to status
985
-            if (! empty($status_bulk_actions)) {
985
+            if ( ! empty($status_bulk_actions)) {
986 986
                 switch ($status) {
987 987
                     case EEM_Message::status_idle:
988 988
                     case EEM_Message::status_resend:
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
             }
1008 1008
 
1009 1009
             //skip adding messenger executing status to views because it will be included with the Failed view.
1010
-            if ( $status === EEM_Message::status_messenger_executing ) {
1010
+            if ($status === EEM_Message::status_messenger_executing) {
1011 1011
                 continue;
1012 1012
             }
1013 1013
             
@@ -1059,37 +1059,37 @@  discard block
 block discarded – undo
1059 1059
         /** @type array $status_items status legend setup */
1060 1060
         $status_items = array(
1061 1061
             'sent_status'       => array(
1062
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1062
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1063 1063
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1064 1064
             ),
1065 1065
             'idle_status'       => array(
1066
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1066
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1067 1067
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1068 1068
             ),
1069 1069
             'failed_status'     => array(
1070
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1070
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1071 1071
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1072 1072
             ),
1073 1073
             'messenger_executing_status' => array(
1074
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1074
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1075 1075
                 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1076 1076
             ),
1077 1077
             'resend_status'     => array(
1078
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1078
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1079 1079
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1080 1080
             ),
1081 1081
             'incomplete_status' => array(
1082
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1082
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1083 1083
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1084 1084
             ),
1085 1085
             'retry_status'      => array(
1086
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1086
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1087 1087
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1088 1088
             )
1089 1089
         );
1090 1090
         if (EEM_Message::debug()) {
1091 1091
             $status_items['debug_only_status'] = array(
1092
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1092
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1093 1093
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1094 1094
             );
1095 1095
         }
@@ -1101,8 +1101,8 @@  discard block
 block discarded – undo
1101 1101
     protected function _custom_mtps_preview()
1102 1102
     {
1103 1103
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1104
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1105
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1104
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1105
+            . ' alt="'.esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso').'" />';
1106 1106
         $this->_template_args['preview_text'] = '<strong>'
1107 1107
             . esc_html__(
1108 1108
                 '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.',
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
                             //let's verify if we need this extra field via the shortcodes parameter.
1385 1385
                             $continue = false;
1386 1386
                             if (isset($extra_array['shortcodes_required'])) {
1387
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1387
+                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1388 1388
                                     if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1389 1389
                                         $continue = true;
1390 1390
                                     }
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
                                 }
1395 1395
                             }
1396 1396
                             
1397
-                            $field_id                                = $reference_field
1397
+                            $field_id = $reference_field
1398 1398
                                                                        . '-'
1399 1399
                                                                        . $extra_field
1400 1400
                                                                        . '-content';
@@ -1402,8 +1402,8 @@  discard block
 block discarded – undo
1402 1402
                             $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1403 1403
                                                                        . $reference_field
1404 1404
                                                                        . '][content]['
1405
-                                                                       . $extra_field . ']';
1406
-                            $css_class                               = isset($extra_array['css_class'])
1405
+                                                                       . $extra_field.']';
1406
+                            $css_class = isset($extra_array['css_class'])
1407 1407
                                 ? $extra_array['css_class']
1408 1408
                                 : '';
1409 1409
                             
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
                                     is_array($validators[$extra_field])
1415 1415
                                     && isset($validators[$extra_field]['msg'])
1416 1416
                                 )
1417
-                                ? 'validate-error ' . $css_class
1417
+                                ? 'validate-error '.$css_class
1418 1418
                                 : $css_class;
1419 1419
                             
1420 1420
                             $template_form_fields[$field_id]['value'] = ! empty($message_templates)
@@ -1450,11 +1450,11 @@  discard block
 block discarded – undo
1450 1450
                                 
1451 1451
                             }/**/
1452 1452
                         }
1453
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1454
-                        $templatefield_templatename_id = $reference_field . '-name';
1453
+                        $templatefield_MTP_id          = $reference_field.'-MTP_ID';
1454
+                        $templatefield_templatename_id = $reference_field.'-name';
1455 1455
                         
1456 1456
                         $template_form_fields[$templatefield_MTP_id] = array(
1457
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1457
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1458 1458
                             'label'      => null,
1459 1459
                             'input'      => 'hidden',
1460 1460
                             'type'       => 'int',
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
                         );
1468 1468
                         
1469 1469
                         $template_form_fields[$templatefield_templatename_id] = array(
1470
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1470
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1471 1471
                             'label'      => null,
1472 1472
                             'input'      => 'hidden',
1473 1473
                             'type'       => 'string',
@@ -1481,9 +1481,9 @@  discard block
 block discarded – undo
1481 1481
                     }
1482 1482
                     continue; //skip the next stuff, we got the necessary fields here for this dataset.
1483 1483
                 } else {
1484
-                    $field_id                                 = $template_field . '-content';
1484
+                    $field_id                                 = $template_field.'-content';
1485 1485
                     $template_form_fields[$field_id]          = $field_setup_array;
1486
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1486
+                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields['.$template_field.'][content]';
1487 1487
                     $message_template                         = isset($message_templates[$context][$template_field])
1488 1488
                         ? $message_templates[$context][$template_field]
1489 1489
                         : null;
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
                     $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1507 1507
                                                                     && in_array($template_field, $v_fields, true)
1508 1508
                                                                     && isset($validators[$template_field]['msg'])
1509
-                        ? 'validate-error ' . $css_class
1509
+                        ? 'validate-error '.$css_class
1510 1510
                         : $css_class;
1511 1511
                     
1512 1512
                     //shortcode selector
@@ -1517,12 +1517,12 @@  discard block
 block discarded – undo
1517 1517
                 
1518 1518
                 //k took care of content field(s) now let's take care of others.
1519 1519
                 
1520
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1521
-                $templatefield_field_templatename_id = $template_field . '-name';
1520
+                $templatefield_MTP_id                = $template_field.'-MTP_ID';
1521
+                $templatefield_field_templatename_id = $template_field.'-name';
1522 1522
                 
1523 1523
                 //foreach template field there are actually two form fields created
1524 1524
                 $template_form_fields[$templatefield_MTP_id] = array(
1525
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1525
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1526 1526
                     'label'      => null,
1527 1527
                     'input'      => 'hidden',
1528 1528
                     'type'       => 'int',
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
                 );
1536 1536
                 
1537 1537
                 $template_form_fields[$templatefield_field_templatename_id] = array(
1538
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1538
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1539 1539
                     'label'      => null,
1540 1540
                     'input'      => 'hidden',
1541 1541
                     'type'       => 'string',
@@ -1653,7 +1653,7 @@  discard block
 block discarded – undo
1653 1653
                 'format'     => '%d',
1654 1654
                 'db-col'     => 'MTP_deleted'
1655 1655
             );
1656
-            $sidebar_form_fields['ee-msg-author']  = array(
1656
+            $sidebar_form_fields['ee-msg-author'] = array(
1657 1657
                 'name'       => 'MTP_user_id',
1658 1658
                 'label'      => esc_html__('Author', 'event_espresso'),
1659 1659
                 'input'      => 'hidden',
@@ -1672,17 +1672,17 @@  discard block
 block discarded – undo
1672 1672
                 'value' => $action
1673 1673
             );
1674 1674
             
1675
-            $sidebar_form_fields['ee-msg-id']        = array(
1675
+            $sidebar_form_fields['ee-msg-id'] = array(
1676 1676
                 'name'  => 'id',
1677 1677
                 'input' => 'hidden',
1678 1678
                 'type'  => 'int',
1679 1679
                 'value' => $GRP_ID
1680 1680
             );
1681 1681
             $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1682
-                'name'  => $action . '_nonce',
1682
+                'name'  => $action.'_nonce',
1683 1683
                 'input' => 'hidden',
1684 1684
                 'type'  => 'string',
1685
-                'value' => wp_create_nonce($action . '_nonce')
1685
+                'value' => wp_create_nonce($action.'_nonce')
1686 1686
             );
1687 1687
             
1688 1688
             if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
@@ -1714,7 +1714,7 @@  discard block
 block discarded – undo
1714 1714
         );
1715 1715
         
1716 1716
         //add preview button
1717
-        $preview_url    = parent::add_query_args_and_nonce(
1717
+        $preview_url = parent::add_query_args_and_nonce(
1718 1718
             array(
1719 1719
                 'message_type' => $message_template_group->message_type(),
1720 1720
                 'messenger'    => $message_template_group->messenger(),
@@ -1724,7 +1724,7 @@  discard block
 block discarded – undo
1724 1724
             ),
1725 1725
             $this->_admin_base_url
1726 1726
         );
1727
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1727
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1728 1728
                           . esc_html__('Preview', 'event_espresso')
1729 1729
                           . '</a>';
1730 1730
         
@@ -1761,7 +1761,7 @@  discard block
 block discarded – undo
1761 1761
         
1762 1762
         $this->_template_path = $this->_template_args['GRP_ID']
1763 1763
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1764
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1764
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1765 1765
         
1766 1766
         //send along EE_Message_Template_Group object for further template use.
1767 1767
         $this->_template_args['MTP'] = $message_template_group;
@@ -1816,7 +1816,7 @@  discard block
 block discarded – undo
1816 1816
     ) {
1817 1817
         $template_args = array(
1818 1818
             'context' => $context,
1819
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1819
+            'nonce' => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1820 1820
             'is_active' => $message_template_group->is_context_active($context),
1821 1821
             'on_off_action' => $message_template_group->is_context_active($context)
1822 1822
                 ? 'context-off'
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
             'message_template_group_id' => $message_template_group->ID()
1826 1826
         );
1827 1827
         return EEH_Template::display_template(
1828
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1828
+          EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1829 1829
           $template_args,
1830 1830
           true
1831 1831
         );
@@ -1845,7 +1845,7 @@  discard block
 block discarded – undo
1845 1845
     {
1846 1846
         $success = true;
1847 1847
         //check for required data
1848
-        if (!isset(
1848
+        if ( ! isset(
1849 1849
             $this->_req_data['message_template_group_id'],
1850 1850
             $this->_req_data['context'],
1851 1851
             $this->_req_data['status']
@@ -1862,10 +1862,10 @@  discard block
 block discarded – undo
1862 1862
         $nonce = isset($this->_req_data['toggle_context_nonce'])
1863 1863
             ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1864 1864
             : '';
1865
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1865
+        $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce';
1866 1866
         $this->_verify_nonce($nonce, $nonce_ref);
1867 1867
         $status = $this->_req_data['status'];
1868
-        if ($status !== 'off' && $status !=='on') {
1868
+        if ($status !== 'off' && $status !== 'on') {
1869 1869
             EE_Error::add_error(
1870 1870
                 sprintf(
1871 1871
                     esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
@@ -1880,7 +1880,7 @@  discard block
 block discarded – undo
1880 1880
         $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1881 1881
             $this->_req_data['message_template_group_id']
1882 1882
         );
1883
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1883
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1884 1884
             EE_Error::add_error(
1885 1885
                 sprintf(
1886 1886
                     esc_html__(
@@ -2124,7 +2124,7 @@  discard block
 block discarded – undo
2124 2124
         }
2125 2125
         
2126 2126
         //let's add a button to go back to the edit view
2127
-        $query_args             = array(
2127
+        $query_args = array(
2128 2128
             'id'      => $this->_req_data['GRP_ID'],
2129 2129
             'context' => $this->_req_data['context'],
2130 2130
             'action'  => 'edit_message_template'
@@ -2150,7 +2150,7 @@  discard block
 block discarded – undo
2150 2150
         );
2151 2151
         //setup display of preview.
2152 2152
         $this->_admin_page_title                    = $preview_title;
2153
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2153
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview);
2154 2154
         $this->_template_args['data']['force_json'] = true;
2155 2155
         
2156 2156
         return '';
@@ -2256,7 +2256,7 @@  discard block
 block discarded – undo
2256 2256
         }
2257 2257
         
2258 2258
         //setup variation select values for the currently selected template.
2259
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2259
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2260 2260
             $this->_message_template_group->messenger(),
2261 2261
             $this->_message_template_group->message_type()
2262 2262
         );
@@ -2270,12 +2270,12 @@  discard block
 block discarded – undo
2270 2270
         
2271 2271
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2272 2272
         
2273
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2273
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2274 2274
             'MTP_template_pack',
2275 2275
             $tp_select_values,
2276 2276
             $this->_message_template_group->get_template_pack_name()
2277 2277
         );
2278
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2278
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2279 2279
             'MTP_template_variation',
2280 2280
             $variations_select_values,
2281 2281
             $this->_message_template_group->get_template_pack_variation()
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2286 2286
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2287 2287
         
2288
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2288
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2289 2289
         
2290 2290
         EEH_Template::display_template($template, $template_args);
2291 2291
     }
@@ -2314,14 +2314,14 @@  discard block
 block discarded – undo
2314 2314
         if ( ! empty($fields)) {
2315 2315
             //yup there be fields
2316 2316
             foreach ($fields as $field => $config) {
2317
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2317
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2318 2318
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2319 2319
                 $default  = isset($config['default']) ? $config['default'] : '';
2320 2320
                 $default  = isset($config['value']) ? $config['value'] : $default;
2321 2321
                 
2322 2322
                 // if type is hidden and the value is empty
2323 2323
                 // something may have gone wrong so let's correct with the defaults
2324
-                $fix              = $config['input'] === 'hidden'
2324
+                $fix = $config['input'] === 'hidden'
2325 2325
                                     && isset($existing[$field])
2326 2326
                                     && empty($existing[$field])
2327 2327
                     ? $default
@@ -2331,7 +2331,7 @@  discard block
 block discarded – undo
2331 2331
                     : $fix;
2332 2332
                 
2333 2333
                 $template_form_fields[$field_id] = array(
2334
-                    'name'       => 'test_settings_fld[' . $field . ']',
2334
+                    'name'       => 'test_settings_fld['.$field.']',
2335 2335
                     'label'      => $config['label'],
2336 2336
                     'input'      => $config['input'],
2337 2337
                     'type'       => $config['type'],
@@ -2399,7 +2399,7 @@  discard block
 block discarded – undo
2399 2399
         );
2400 2400
         
2401 2401
         return EEH_Template::display_template(
2402
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2402
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2403 2403
             $template_args,
2404 2404
             true
2405 2405
         );
@@ -2424,7 +2424,7 @@  discard block
 block discarded – undo
2424 2424
         //$messenger = $this->_message_template_group->messenger_obj();
2425 2425
         //now let's set the content depending on the status of the shortcodes array
2426 2426
         if (empty($shortcodes)) {
2427
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2427
+            $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2428 2428
             echo $content;
2429 2429
         } else {
2430 2430
             //$alt = 0;
@@ -2561,7 +2561,7 @@  discard block
 block discarded – undo
2561 2561
                     <?php
2562 2562
                 }
2563 2563
                 //setup nonce_url
2564
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2564
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2565 2565
                 ?>
2566 2566
                 <select name="context">
2567 2567
                     <?php
@@ -2662,7 +2662,7 @@  discard block
 block discarded – undo
2662 2662
         $context      = ucwords(str_replace('_', ' ', $context_slug));
2663 2663
         
2664 2664
         $item_desc = $messenger_label && $message_type_label
2665
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2665
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2666 2666
             : '';
2667 2667
         $item_desc .= 'Message Template';
2668 2668
         $query_args  = array();
@@ -2764,7 +2764,7 @@  discard block
 block discarded – undo
2764 2764
                                 //default setup for it.
2765 2765
                                 //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2766 2766
                                 $updated = $MTP->insert($message_template_fields);
2767
-                                if (! $updated || is_wp_error($updated)) {
2767
+                                if ( ! $updated || is_wp_error($updated)) {
2768 2768
                                     EE_Error::add_error(
2769 2769
                                         sprintf(
2770 2770
                                             esc_html__('%s field could not be updated.', 'event_espresso'),
@@ -3125,7 +3125,7 @@  discard block
 block discarded – undo
3125 3125
             : 'email';
3126 3126
         
3127 3127
         //let's setup the messenger tabs
3128
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3128
+        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3129 3129
             $this->_m_mt_settings['messenger_tabs'],
3130 3130
             'messenger_links',
3131 3131
             '|',
@@ -3193,10 +3193,10 @@  discard block
 block discarded – undo
3193 3193
                 
3194 3194
                 $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3195 3195
                     'label'    => ucwords($message_type->label['singular']),
3196
-                    'class'    => 'message-type-' . $a_or_i,
3197
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3198
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3199
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3196
+                    'class'    => 'message-type-'.$a_or_i,
3197
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3198
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3199
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3200 3200
                     'title'    => $a_or_i === 'active'
3201 3201
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3202 3202
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3232,9 +3232,9 @@  discard block
 block discarded – undo
3232 3232
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3233 3233
             
3234 3234
             foreach ($fields as $fldname => $fldprops) {
3235
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3235
+                $field_id                       = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3236 3236
                 $template_form_field[$field_id] = array(
3237
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3237
+                    'name'       => 'message_type_settings['.$fldname.']',
3238 3238
                     'label'      => $fldprops['label'],
3239 3239
                     'input'      => $fldprops['field_type'],
3240 3240
                     'type'       => $fldprops['value_type'],
@@ -3285,12 +3285,12 @@  discard block
 block discarded – undo
3285 3285
             $settings_template_args['hidden_fields'],
3286 3286
             'array'
3287 3287
         );
3288
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3288
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3289 3289
             ? ' hidden'
3290 3290
             : '';
3291 3291
         
3292 3292
         
3293
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3293
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3294 3294
         $content  = EEH_Template::display_template($template, $settings_template_args, true);
3295 3295
         
3296 3296
         return $content;
@@ -3325,11 +3325,11 @@  discard block
 block discarded – undo
3325 3325
                 )
3326 3326
                     ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3327 3327
                     : '';
3328
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3328
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3329 3329
                     esc_html__('%s Settings', 'event_espresso'),
3330 3330
                     $tab_array['label']
3331 3331
                 );
3332
-                $m_template_args[$messenger . '_a_box'] = array(
3332
+                $m_template_args[$messenger.'_a_box'] = array(
3333 3333
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3334 3334
                     'inactive_message_types' => isset(
3335 3335
                         $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
@@ -3345,8 +3345,8 @@  discard block
 block discarded – undo
3345 3345
                 // message type meta boxes
3346 3346
                 // (which is really just the inactive container for each messenger
3347 3347
                 // showing inactive message types for that messenger)
3348
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3349
-                $mt_template_args[$messenger . '_i_box'] = array(
3348
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3349
+                $mt_template_args[$messenger.'_i_box'] = array(
3350 3350
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3351 3351
                     'inactive_message_types' => isset(
3352 3352
                         $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
@@ -3364,14 +3364,14 @@  discard block
 block discarded – undo
3364 3364
         
3365 3365
         
3366 3366
         //register messenger metaboxes
3367
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3367
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3368 3368
         foreach ($m_boxes as $box => $label) {
3369 3369
             $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3370 3370
             $msgr          = str_replace('_a_box', '', $box);
3371 3371
             add_meta_box(
3372
-                'espresso_' . $msgr . '_settings',
3372
+                'espresso_'.$msgr.'_settings',
3373 3373
                 $label,
3374
-                function ($post, $metabox) {
3374
+                function($post, $metabox) {
3375 3375
                     echo EEH_Template::display_template(
3376 3376
                             $metabox["args"]["template_path"],
3377 3377
                             $metabox["args"]["template_args"],
@@ -3386,17 +3386,17 @@  discard block
 block discarded – undo
3386 3386
         }
3387 3387
         
3388 3388
         //register message type metaboxes
3389
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3389
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3390 3390
         foreach ($mt_boxes as $box => $label) {
3391 3391
             $callback_args = array(
3392 3392
                 'template_path' => $mt_template_path,
3393 3393
                 'template_args' => $mt_template_args[$box]
3394 3394
             );
3395
-            $mt            = str_replace('_i_box', '', $box);
3395
+            $mt = str_replace('_i_box', '', $box);
3396 3396
             add_meta_box(
3397
-                'espresso_' . $mt . '_inactive_mts',
3397
+                'espresso_'.$mt.'_inactive_mts',
3398 3398
                 $label,
3399
-                function ($post, $metabox) {
3399
+                function($post, $metabox) {
3400 3400
                     echo EEH_Template::display_template(
3401 3401
                             $metabox["args"]["template_path"],
3402 3402
                             $metabox["args"]["template_args"],
@@ -3543,7 +3543,7 @@  discard block
 block discarded – undo
3543 3543
             if ($form->is_valid()) {
3544 3544
                 $valid_data = $form->valid_data();
3545 3545
                 foreach ($valid_data as $property => $value) {
3546
-                    $setter = 'set_' . $property;
3546
+                    $setter = 'set_'.$property;
3547 3547
                     if (method_exists($network_config, $setter)) {
3548 3548
                         $network_config->{$setter}($value);
3549 3549
                     } else if (
@@ -3578,8 +3578,8 @@  discard block
 block discarded – undo
3578 3578
      */
3579 3579
     protected function _get_mt_tabs($tab_array)
3580 3580
     {
3581
-        $tab_array = (array)$tab_array;
3582
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3581
+        $tab_array = (array) $tab_array;
3582
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3583 3583
         $tabs      = '';
3584 3584
         
3585 3585
         foreach ($tab_array as $tab) {
@@ -3612,9 +3612,9 @@  discard block
 block discarded – undo
3612 3612
             $existing_settings = $messenger->get_existing_admin_settings();
3613 3613
             
3614 3614
             foreach ($fields as $fldname => $fldprops) {
3615
-                $field_id                       = $messenger->name . '-' . $fldname;
3615
+                $field_id                       = $messenger->name.'-'.$fldname;
3616 3616
                 $template_form_field[$field_id] = array(
3617
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3617
+                    'name'       => 'messenger_settings['.$field_id.']',
3618 3618
                     'label'      => $fldprops['label'],
3619 3619
                     'input'      => $fldprops['field_type'],
3620 3620
                     'type'       => $fldprops['value_type'],
@@ -3649,7 +3649,7 @@  discard block
 block discarded – undo
3649 3649
         //make sure any active message types that are existing are included in the hidden fields
3650 3650
         if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3651 3651
             foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3652
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3652
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(
3653 3653
                     'type'  => 'hidden',
3654 3654
                     'value' => $mt
3655 3655
                 );
@@ -3678,9 +3678,9 @@  discard block
 block discarded – undo
3678 3678
         
3679 3679
         
3680 3680
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3681
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3681
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3682 3682
         $settings_template_args['on_off_status'] = $active ? true : false;
3683
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3683
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3684 3684
         $content                                 = EEH_Template::display_template(
3685 3685
             $template,
3686 3686
             $settings_template_args,
@@ -3720,7 +3720,7 @@  discard block
 block discarded – undo
3720 3720
         $nonce     = isset($this->_req_data['activate_nonce'])
3721 3721
             ? sanitize_text_field($this->_req_data['activate_nonce'])
3722 3722
             : '';
3723
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3723
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3724 3724
         
3725 3725
         $this->_verify_nonce($nonce, $nonce_ref);
3726 3726
         
@@ -3836,7 +3836,7 @@  discard block
 block discarded – undo
3836 3836
         
3837 3837
         //do a nonce check here since we're not arriving via a normal route
3838 3838
         $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3839
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3839
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
3840 3840
         
3841 3841
         $this->_verify_nonce($nonce, $nonce_ref);
3842 3842
         
@@ -4197,7 +4197,7 @@  discard block
 block discarded – undo
4197 4197
         $message_type = $message_types[$this->_req_data['message_type']];
4198 4198
         $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4199 4199
         
4200
-        $content                         = $this->_message_type_settings_content(
4200
+        $content = $this->_message_type_settings_content(
4201 4201
             $message_type,
4202 4202
             $messenger,
4203 4203
             true
Please login to merge, or discard this patch.
Indentation   +4043 added lines, -4043 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidInterfaceException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('NO direct script access allowed');
8
+	exit('NO direct script access allowed');
9 9
 }
10 10
 
11 11
 /**
@@ -23,2557 +23,2557 @@  discard block
 block discarded – undo
23 23
 class Messages_Admin_Page extends EE_Admin_Page
24 24
 {
25 25
     
26
-    /**
27
-     * @type EE_Message_Resource_Manager $_message_resource_manager
28
-     */
29
-    protected $_message_resource_manager;
26
+	/**
27
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
28
+	 */
29
+	protected $_message_resource_manager;
30 30
     
31
-    /**
32
-     * @type string $_active_message_type_name
33
-     */
34
-    protected $_active_message_type_name = '';
31
+	/**
32
+	 * @type string $_active_message_type_name
33
+	 */
34
+	protected $_active_message_type_name = '';
35 35
     
36
-    /**
37
-     * @type EE_messenger $_active_messenger
38
-     */
39
-    protected $_active_messenger;
40
-    protected $_activate_state;
41
-    protected $_activate_meta_box_type;
42
-    protected $_current_message_meta_box;
43
-    protected $_current_message_meta_box_object;
44
-    protected $_context_switcher;
45
-    protected $_shortcodes = array();
46
-    protected $_active_messengers = array();
47
-    protected $_active_message_types = array();
36
+	/**
37
+	 * @type EE_messenger $_active_messenger
38
+	 */
39
+	protected $_active_messenger;
40
+	protected $_activate_state;
41
+	protected $_activate_meta_box_type;
42
+	protected $_current_message_meta_box;
43
+	protected $_current_message_meta_box_object;
44
+	protected $_context_switcher;
45
+	protected $_shortcodes = array();
46
+	protected $_active_messengers = array();
47
+	protected $_active_message_types = array();
48 48
     
49
-    /**
50
-     * @var EE_Message_Template_Group $_message_template_group
51
-     */
52
-    protected $_message_template_group;
53
-    protected $_m_mt_settings = array();
49
+	/**
50
+	 * @var EE_Message_Template_Group $_message_template_group
51
+	 */
52
+	protected $_message_template_group;
53
+	protected $_m_mt_settings = array();
54 54
     
55 55
     
56
-    /**
57
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
-     * IF there is no group then it gets automatically set to the Default template pack.
59
-     *
60
-     * @since 4.5.0
61
-     *
62
-     * @var EE_Messages_Template_Pack
63
-     */
64
-    protected $_template_pack;
56
+	/**
57
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
+	 * IF there is no group then it gets automatically set to the Default template pack.
59
+	 *
60
+	 * @since 4.5.0
61
+	 *
62
+	 * @var EE_Messages_Template_Pack
63
+	 */
64
+	protected $_template_pack;
65 65
     
66 66
     
67
-    /**
68
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
-     * group is.  If there is no group then it automatically gets set to default.
70
-     *
71
-     * @since 4.5.0
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_variation;
67
+	/**
68
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
+	 * group is.  If there is no group then it automatically gets set to default.
70
+	 *
71
+	 * @since 4.5.0
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_variation;
76 76
     
77 77
     
78
-    /**
79
-     * @param bool $routing
80
-     */
81
-    public function __construct($routing = true)
82
-    {
83
-        //make sure messages autoloader is running
84
-        EED_Messages::set_autoloaders();
85
-        parent::__construct($routing);
86
-    }
78
+	/**
79
+	 * @param bool $routing
80
+	 */
81
+	public function __construct($routing = true)
82
+	{
83
+		//make sure messages autoloader is running
84
+		EED_Messages::set_autoloaders();
85
+		parent::__construct($routing);
86
+	}
87 87
     
88 88
     
89
-    protected function _init_page_props()
90
-    {
91
-        $this->page_slug        = EE_MSG_PG_SLUG;
92
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
93
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
94
-        $this->_admin_base_path = EE_MSG_ADMIN;
95
-        
96
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
97
-        
98
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
99
-        $this->_load_message_resource_manager();
100
-    }
89
+	protected function _init_page_props()
90
+	{
91
+		$this->page_slug        = EE_MSG_PG_SLUG;
92
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
93
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
94
+		$this->_admin_base_path = EE_MSG_ADMIN;
95
+        
96
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
97
+        
98
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
99
+		$this->_load_message_resource_manager();
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
105
-     *
106
-     * @throws EE_Error
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     * @throws InvalidArgumentException
110
-     * @throws ReflectionException
111
-     */
112
-    protected function _load_message_resource_manager()
113
-    {
114
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
115
-    }
103
+	/**
104
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
105
+	 *
106
+	 * @throws EE_Error
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 * @throws InvalidArgumentException
110
+	 * @throws ReflectionException
111
+	 */
112
+	protected function _load_message_resource_manager()
113
+	{
114
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * @deprecated 4.9.9.rc.014
120
-     * @return array
121
-     * @throws EE_Error
122
-     * @throws InvalidArgumentException
123
-     * @throws InvalidDataTypeException
124
-     * @throws InvalidInterfaceException
125
-     */
126
-    public function get_messengers_for_list_table()
127
-    {
128
-        EE_Error::doing_it_wrong(
129
-            __METHOD__,
130
-            sprintf(
131
-                esc_html__(
132
-                    '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',
133
-                    'event_espresso'
134
-                ),
135
-                'Messages_Admin_Page::get_messengers_select_input()'
136
-            ),
137
-            '4.9.9.rc.014'
138
-        );
139
-        
140
-        $m_values          = array();
141
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
142
-        //setup messengers for selects
143
-        $i = 1;
144
-        foreach ($active_messengers as $active_messenger) {
145
-            if ($active_messenger instanceof EE_Message) {
146
-                $m_values[$i]['id']   = $active_messenger->messenger();
147
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
148
-                $i++;
149
-            }
150
-        }
151
-        
152
-        return $m_values;
153
-    }
118
+	/**
119
+	 * @deprecated 4.9.9.rc.014
120
+	 * @return array
121
+	 * @throws EE_Error
122
+	 * @throws InvalidArgumentException
123
+	 * @throws InvalidDataTypeException
124
+	 * @throws InvalidInterfaceException
125
+	 */
126
+	public function get_messengers_for_list_table()
127
+	{
128
+		EE_Error::doing_it_wrong(
129
+			__METHOD__,
130
+			sprintf(
131
+				esc_html__(
132
+					'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',
133
+					'event_espresso'
134
+				),
135
+				'Messages_Admin_Page::get_messengers_select_input()'
136
+			),
137
+			'4.9.9.rc.014'
138
+		);
139
+        
140
+		$m_values          = array();
141
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
142
+		//setup messengers for selects
143
+		$i = 1;
144
+		foreach ($active_messengers as $active_messenger) {
145
+			if ($active_messenger instanceof EE_Message) {
146
+				$m_values[$i]['id']   = $active_messenger->messenger();
147
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
148
+				$i++;
149
+			}
150
+		}
151
+        
152
+		return $m_values;
153
+	}
154 154
 
155 155
 
156
-    /**
157
-     * @deprecated 4.9.9.rc.014
158
-     * @return array
159
-     * @throws EE_Error
160
-     * @throws InvalidArgumentException
161
-     * @throws InvalidDataTypeException
162
-     * @throws InvalidInterfaceException
163
-     */
164
-    public function get_message_types_for_list_table()
165
-    {
166
-        EE_Error::doing_it_wrong(
167
-            __METHOD__,
168
-            sprintf(
169
-                esc_html__(
170
-                    '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',
171
-                    'event_espresso'
172
-                ),
173
-                'Messages_Admin_Page::get_message_types_select_input()'
174
-            ),
175
-            '4.9.9.rc.014'
176
-        );
177
-        
178
-        $mt_values       = array();
179
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
180
-        $i               = 1;
181
-        foreach ($active_messages as $active_message) {
182
-            if ($active_message instanceof EE_Message) {
183
-                $mt_values[$i]['id']   = $active_message->message_type();
184
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
185
-                $i++;
186
-            }
187
-        }
188
-        
189
-        return $mt_values;
190
-    }
156
+	/**
157
+	 * @deprecated 4.9.9.rc.014
158
+	 * @return array
159
+	 * @throws EE_Error
160
+	 * @throws InvalidArgumentException
161
+	 * @throws InvalidDataTypeException
162
+	 * @throws InvalidInterfaceException
163
+	 */
164
+	public function get_message_types_for_list_table()
165
+	{
166
+		EE_Error::doing_it_wrong(
167
+			__METHOD__,
168
+			sprintf(
169
+				esc_html__(
170
+					'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',
171
+					'event_espresso'
172
+				),
173
+				'Messages_Admin_Page::get_message_types_select_input()'
174
+			),
175
+			'4.9.9.rc.014'
176
+		);
177
+        
178
+		$mt_values       = array();
179
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
180
+		$i               = 1;
181
+		foreach ($active_messages as $active_message) {
182
+			if ($active_message instanceof EE_Message) {
183
+				$mt_values[$i]['id']   = $active_message->message_type();
184
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
185
+				$i++;
186
+			}
187
+		}
188
+        
189
+		return $mt_values;
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * @deprecated 4.9.9.rc.014
195
-     * @return array
196
-     * @throws EE_Error
197
-     * @throws InvalidArgumentException
198
-     * @throws InvalidDataTypeException
199
-     * @throws InvalidInterfaceException
200
-     */
201
-    public function get_contexts_for_message_types_for_list_table()
202
-    {
203
-        EE_Error::doing_it_wrong(
204
-            __METHOD__,
205
-            sprintf(
206
-                esc_html__(
207
-                    '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',
208
-                    'event_espresso'
209
-                ),
210
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
211
-            ),
212
-            '4.9.9.rc.014'
213
-        );
214
-        
215
-        $contexts                = array();
216
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
217
-        foreach ($active_message_contexts as $active_message) {
218
-            if ($active_message instanceof EE_Message) {
219
-                $message_type = $active_message->message_type_object();
220
-                if ($message_type instanceof EE_message_type) {
221
-                    $message_type_contexts = $message_type->get_contexts();
222
-                    foreach ($message_type_contexts as $context => $context_details) {
223
-                        $contexts[$context] = $context_details['label'];
224
-                    }
225
-                }
226
-            }
227
-        }
228
-        
229
-        return $contexts;
230
-    }
193
+	/**
194
+	 * @deprecated 4.9.9.rc.014
195
+	 * @return array
196
+	 * @throws EE_Error
197
+	 * @throws InvalidArgumentException
198
+	 * @throws InvalidDataTypeException
199
+	 * @throws InvalidInterfaceException
200
+	 */
201
+	public function get_contexts_for_message_types_for_list_table()
202
+	{
203
+		EE_Error::doing_it_wrong(
204
+			__METHOD__,
205
+			sprintf(
206
+				esc_html__(
207
+					'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',
208
+					'event_espresso'
209
+				),
210
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
211
+			),
212
+			'4.9.9.rc.014'
213
+		);
214
+        
215
+		$contexts                = array();
216
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
217
+		foreach ($active_message_contexts as $active_message) {
218
+			if ($active_message instanceof EE_Message) {
219
+				$message_type = $active_message->message_type_object();
220
+				if ($message_type instanceof EE_message_type) {
221
+					$message_type_contexts = $message_type->get_contexts();
222
+					foreach ($message_type_contexts as $context => $context_details) {
223
+						$contexts[$context] = $context_details['label'];
224
+					}
225
+				}
226
+			}
227
+		}
228
+        
229
+		return $contexts;
230
+	}
231 231
 
232 232
 
233
-    /**
234
-     * Generate select input with provided messenger options array.
235
-     *
236
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
237
-     *                                 labels.
238
-     * @return string
239
-     * @throws EE_Error
240
-     */
241
-    public function get_messengers_select_input($messenger_options)
242
-    {
243
-        //if empty or just one value then just return an empty string
244
-        if (empty($messenger_options)
245
-            || ! is_array($messenger_options)
246
-            || count($messenger_options) === 1
247
-        ) {
248
-            return '';
249
-        }
250
-        //merge in default
251
-        $messenger_options = array_merge(
252
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
253
-            $messenger_options
254
-        );
255
-        $input             = new EE_Select_Input(
256
-            $messenger_options,
257
-            array(
258
-                'html_name'  => 'ee_messenger_filter_by',
259
-                'html_id'    => 'ee_messenger_filter_by',
260
-                'html_class' => 'wide',
261
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
262
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
263
-                    : 'none_selected'
264
-            )
265
-        );
266
-        
267
-        return $input->get_html_for_input();
268
-    }
233
+	/**
234
+	 * Generate select input with provided messenger options array.
235
+	 *
236
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
237
+	 *                                 labels.
238
+	 * @return string
239
+	 * @throws EE_Error
240
+	 */
241
+	public function get_messengers_select_input($messenger_options)
242
+	{
243
+		//if empty or just one value then just return an empty string
244
+		if (empty($messenger_options)
245
+			|| ! is_array($messenger_options)
246
+			|| count($messenger_options) === 1
247
+		) {
248
+			return '';
249
+		}
250
+		//merge in default
251
+		$messenger_options = array_merge(
252
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
253
+			$messenger_options
254
+		);
255
+		$input             = new EE_Select_Input(
256
+			$messenger_options,
257
+			array(
258
+				'html_name'  => 'ee_messenger_filter_by',
259
+				'html_id'    => 'ee_messenger_filter_by',
260
+				'html_class' => 'wide',
261
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
262
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
263
+					: 'none_selected'
264
+			)
265
+		);
266
+        
267
+		return $input->get_html_for_input();
268
+	}
269 269
 
270 270
 
271
-    /**
272
-     * Generate select input with provided message type options array.
273
-     *
274
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
275
-     *                                    message type labels
276
-     * @return string
277
-     * @throws EE_Error
278
-     */
279
-    public function get_message_types_select_input($message_type_options)
280
-    {
281
-        //if empty or count of options is 1 then just return an empty string
282
-        if (empty($message_type_options)
283
-            || ! is_array($message_type_options)
284
-            || count($message_type_options) === 1
285
-        ) {
286
-            return '';
287
-        }
288
-        //merge in default
289
-        $message_type_options = array_merge(
290
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
-            $message_type_options
292
-        );
293
-        $input                = new EE_Select_Input(
294
-            $message_type_options,
295
-            array(
296
-                'html_name'  => 'ee_message_type_filter_by',
297
-                'html_id'    => 'ee_message_type_filter_by',
298
-                'html_class' => 'wide',
299
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
-                    : 'none_selected',
302
-            )
303
-        );
304
-        
305
-        return $input->get_html_for_input();
306
-    }
271
+	/**
272
+	 * Generate select input with provided message type options array.
273
+	 *
274
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
275
+	 *                                    message type labels
276
+	 * @return string
277
+	 * @throws EE_Error
278
+	 */
279
+	public function get_message_types_select_input($message_type_options)
280
+	{
281
+		//if empty or count of options is 1 then just return an empty string
282
+		if (empty($message_type_options)
283
+			|| ! is_array($message_type_options)
284
+			|| count($message_type_options) === 1
285
+		) {
286
+			return '';
287
+		}
288
+		//merge in default
289
+		$message_type_options = array_merge(
290
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
+			$message_type_options
292
+		);
293
+		$input                = new EE_Select_Input(
294
+			$message_type_options,
295
+			array(
296
+				'html_name'  => 'ee_message_type_filter_by',
297
+				'html_id'    => 'ee_message_type_filter_by',
298
+				'html_class' => 'wide',
299
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
+					: 'none_selected',
302
+			)
303
+		);
304
+        
305
+		return $input->get_html_for_input();
306
+	}
307 307
 
308 308
 
309
-    /**
310
-     * Generate select input with provide message type contexts array.
311
-     *
312
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
-     *                               context label.
314
-     * @return string
315
-     * @throws EE_Error
316
-     */
317
-    public function get_contexts_for_message_types_select_input($context_options)
318
-    {
319
-        //if empty or count of options is one then just return empty string
320
-        if (empty($context_options)
321
-            || ! is_array($context_options)
322
-            || count($context_options) === 1
323
-        ) {
324
-            return '';
325
-        }
326
-        //merge in default
327
-        $context_options = array_merge(
328
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
329
-            $context_options
330
-        );
331
-        $input           = new EE_Select_Input(
332
-            $context_options,
333
-            array(
334
-                'html_name'  => 'ee_context_filter_by',
335
-                'html_id'    => 'ee_context_filter_by',
336
-                'html_class' => 'wide',
337
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
338
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
339
-                    : 'none_selected',
340
-            )
341
-        );
342
-        
343
-        return $input->get_html_for_input();
344
-    }
309
+	/**
310
+	 * Generate select input with provide message type contexts array.
311
+	 *
312
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
+	 *                               context label.
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 */
317
+	public function get_contexts_for_message_types_select_input($context_options)
318
+	{
319
+		//if empty or count of options is one then just return empty string
320
+		if (empty($context_options)
321
+			|| ! is_array($context_options)
322
+			|| count($context_options) === 1
323
+		) {
324
+			return '';
325
+		}
326
+		//merge in default
327
+		$context_options = array_merge(
328
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
329
+			$context_options
330
+		);
331
+		$input           = new EE_Select_Input(
332
+			$context_options,
333
+			array(
334
+				'html_name'  => 'ee_context_filter_by',
335
+				'html_id'    => 'ee_context_filter_by',
336
+				'html_class' => 'wide',
337
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
338
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
339
+					: 'none_selected',
340
+			)
341
+		);
342
+        
343
+		return $input->get_html_for_input();
344
+	}
345 345
     
346 346
     
347
-    protected function _ajax_hooks()
348
-    {
349
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
350
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
351
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
352
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
353
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
354
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
355
-    }
347
+	protected function _ajax_hooks()
348
+	{
349
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
350
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
351
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
352
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
353
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
354
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
355
+	}
356 356
     
357 357
     
358
-    protected function _define_page_props()
359
-    {
360
-        $this->_admin_page_title = $this->page_label;
361
-        $this->_labels           = array(
362
-            'buttons'    => array(
363
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
364
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
365
-                'delete' => esc_html__('Delete Message Template', 'event_espresso')
366
-            ),
367
-            'publishbox' => esc_html__('Update Actions', 'event_espresso')
368
-        );
369
-    }
358
+	protected function _define_page_props()
359
+	{
360
+		$this->_admin_page_title = $this->page_label;
361
+		$this->_labels           = array(
362
+			'buttons'    => array(
363
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
364
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
365
+				'delete' => esc_html__('Delete Message Template', 'event_espresso')
366
+			),
367
+			'publishbox' => esc_html__('Update Actions', 'event_espresso')
368
+		);
369
+	}
370 370
     
371 371
     
372
-    /**
373
-     *        an array for storing key => value pairs of request actions and their corresponding methods
374
-     * @access protected
375
-     * @return void
376
-     */
377
-    protected function _set_page_routes()
378
-    {
379
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
380
-            ? $this->_req_data['GRP_ID']
381
-            : 0;
382
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
383
-            ? $this->_req_data['id']
384
-            : $grp_id;
385
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
386
-            ? $this->_req_data['MSG_ID']
387
-            : 0;
388
-        
389
-        $this->_page_routes = array(
390
-            'default'                          => array(
391
-                'func'       => '_message_queue_list_table',
392
-                'capability' => 'ee_read_global_messages'
393
-            ),
394
-            'global_mtps'                      => array(
395
-                'func'       => '_ee_default_messages_overview_list_table',
396
-                'capability' => 'ee_read_global_messages'
397
-            ),
398
-            'custom_mtps'                      => array(
399
-                'func'       => '_custom_mtps_preview',
400
-                'capability' => 'ee_read_messages'
401
-            ),
402
-            'add_new_message_template'         => array(
403
-                'func'       => '_add_message_template',
404
-                'capability' => 'ee_edit_messages',
405
-                'noheader'   => true
406
-            ),
407
-            'edit_message_template'            => array(
408
-                'func'       => '_edit_message_template',
409
-                'capability' => 'ee_edit_message',
410
-                'obj_id'     => $grp_id
411
-            ),
412
-            'preview_message'                  => array(
413
-                'func'               => '_preview_message',
414
-                'capability'         => 'ee_read_message',
415
-                'obj_id'             => $grp_id,
416
-                'noheader'           => true,
417
-                'headers_sent_route' => 'display_preview_message'
418
-            ),
419
-            'display_preview_message'          => array(
420
-                'func'       => '_display_preview_message',
421
-                'capability' => 'ee_read_message',
422
-                'obj_id'     => $grp_id
423
-            ),
424
-            'insert_message_template'          => array(
425
-                'func'       => '_insert_or_update_message_template',
426
-                'capability' => 'ee_edit_messages',
427
-                'args'       => array('new_template' => true),
428
-                'noheader'   => true
429
-            ),
430
-            'update_message_template'          => array(
431
-                'func'       => '_insert_or_update_message_template',
432
-                'capability' => 'ee_edit_message',
433
-                'obj_id'     => $grp_id,
434
-                'args'       => array('new_template' => false),
435
-                'noheader'   => true
436
-            ),
437
-            'trash_message_template'           => array(
438
-                'func'       => '_trash_or_restore_message_template',
439
-                'capability' => 'ee_delete_message',
440
-                'obj_id'     => $grp_id,
441
-                'args'       => array('trash' => true, 'all' => true),
442
-                'noheader'   => true
443
-            ),
444
-            'trash_message_template_context'   => array(
445
-                'func'       => '_trash_or_restore_message_template',
446
-                'capability' => 'ee_delete_message',
447
-                'obj_id'     => $grp_id,
448
-                'args'       => array('trash' => true),
449
-                'noheader'   => true
450
-            ),
451
-            'restore_message_template'         => array(
452
-                'func'       => '_trash_or_restore_message_template',
453
-                'capability' => 'ee_delete_message',
454
-                'obj_id'     => $grp_id,
455
-                'args'       => array('trash' => false, 'all' => true),
456
-                'noheader'   => true
457
-            ),
458
-            'restore_message_template_context' => array(
459
-                'func'       => '_trash_or_restore_message_template',
460
-                'capability' => 'ee_delete_message',
461
-                'obj_id'     => $grp_id,
462
-                'args'       => array('trash' => false),
463
-                'noheader'   => true
464
-            ),
465
-            'delete_message_template'          => array(
466
-                'func'       => '_delete_message_template',
467
-                'capability' => 'ee_delete_message',
468
-                'obj_id'     => $grp_id,
469
-                'noheader'   => true
470
-            ),
471
-            'reset_to_default'                 => array(
472
-                'func'       => '_reset_to_default_template',
473
-                'capability' => 'ee_edit_message',
474
-                'obj_id'     => $grp_id,
475
-                'noheader'   => true
476
-            ),
477
-            'settings'                         => array(
478
-                'func'       => '_settings',
479
-                'capability' => 'manage_options'
480
-            ),
481
-            'update_global_settings'           => array(
482
-                'func'       => '_update_global_settings',
483
-                'capability' => 'manage_options',
484
-                'noheader'   => true
485
-            ),
486
-            'generate_now'                     => array(
487
-                'func'       => '_generate_now',
488
-                'capability' => 'ee_send_message',
489
-                'noheader'   => true
490
-            ),
491
-            'generate_and_send_now'            => array(
492
-                'func'       => '_generate_and_send_now',
493
-                'capability' => 'ee_send_message',
494
-                'noheader'   => true
495
-            ),
496
-            'queue_for_resending'              => array(
497
-                'func'       => '_queue_for_resending',
498
-                'capability' => 'ee_send_message',
499
-                'noheader'   => true
500
-            ),
501
-            'send_now'                         => array(
502
-                'func'       => '_send_now',
503
-                'capability' => 'ee_send_message',
504
-                'noheader'   => true
505
-            ),
506
-            'delete_ee_message'                => array(
507
-                'func'       => '_delete_ee_messages',
508
-                'capability' => 'ee_delete_messages',
509
-                'noheader'   => true
510
-            ),
511
-            'delete_ee_messages'               => array(
512
-                'func'       => '_delete_ee_messages',
513
-                'capability' => 'ee_delete_messages',
514
-                'noheader'   => true,
515
-                'obj_id'     => $msg_id
516
-            )
517
-        );
518
-    }
372
+	/**
373
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
374
+	 * @access protected
375
+	 * @return void
376
+	 */
377
+	protected function _set_page_routes()
378
+	{
379
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
380
+			? $this->_req_data['GRP_ID']
381
+			: 0;
382
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
383
+			? $this->_req_data['id']
384
+			: $grp_id;
385
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
386
+			? $this->_req_data['MSG_ID']
387
+			: 0;
388
+        
389
+		$this->_page_routes = array(
390
+			'default'                          => array(
391
+				'func'       => '_message_queue_list_table',
392
+				'capability' => 'ee_read_global_messages'
393
+			),
394
+			'global_mtps'                      => array(
395
+				'func'       => '_ee_default_messages_overview_list_table',
396
+				'capability' => 'ee_read_global_messages'
397
+			),
398
+			'custom_mtps'                      => array(
399
+				'func'       => '_custom_mtps_preview',
400
+				'capability' => 'ee_read_messages'
401
+			),
402
+			'add_new_message_template'         => array(
403
+				'func'       => '_add_message_template',
404
+				'capability' => 'ee_edit_messages',
405
+				'noheader'   => true
406
+			),
407
+			'edit_message_template'            => array(
408
+				'func'       => '_edit_message_template',
409
+				'capability' => 'ee_edit_message',
410
+				'obj_id'     => $grp_id
411
+			),
412
+			'preview_message'                  => array(
413
+				'func'               => '_preview_message',
414
+				'capability'         => 'ee_read_message',
415
+				'obj_id'             => $grp_id,
416
+				'noheader'           => true,
417
+				'headers_sent_route' => 'display_preview_message'
418
+			),
419
+			'display_preview_message'          => array(
420
+				'func'       => '_display_preview_message',
421
+				'capability' => 'ee_read_message',
422
+				'obj_id'     => $grp_id
423
+			),
424
+			'insert_message_template'          => array(
425
+				'func'       => '_insert_or_update_message_template',
426
+				'capability' => 'ee_edit_messages',
427
+				'args'       => array('new_template' => true),
428
+				'noheader'   => true
429
+			),
430
+			'update_message_template'          => array(
431
+				'func'       => '_insert_or_update_message_template',
432
+				'capability' => 'ee_edit_message',
433
+				'obj_id'     => $grp_id,
434
+				'args'       => array('new_template' => false),
435
+				'noheader'   => true
436
+			),
437
+			'trash_message_template'           => array(
438
+				'func'       => '_trash_or_restore_message_template',
439
+				'capability' => 'ee_delete_message',
440
+				'obj_id'     => $grp_id,
441
+				'args'       => array('trash' => true, 'all' => true),
442
+				'noheader'   => true
443
+			),
444
+			'trash_message_template_context'   => array(
445
+				'func'       => '_trash_or_restore_message_template',
446
+				'capability' => 'ee_delete_message',
447
+				'obj_id'     => $grp_id,
448
+				'args'       => array('trash' => true),
449
+				'noheader'   => true
450
+			),
451
+			'restore_message_template'         => array(
452
+				'func'       => '_trash_or_restore_message_template',
453
+				'capability' => 'ee_delete_message',
454
+				'obj_id'     => $grp_id,
455
+				'args'       => array('trash' => false, 'all' => true),
456
+				'noheader'   => true
457
+			),
458
+			'restore_message_template_context' => array(
459
+				'func'       => '_trash_or_restore_message_template',
460
+				'capability' => 'ee_delete_message',
461
+				'obj_id'     => $grp_id,
462
+				'args'       => array('trash' => false),
463
+				'noheader'   => true
464
+			),
465
+			'delete_message_template'          => array(
466
+				'func'       => '_delete_message_template',
467
+				'capability' => 'ee_delete_message',
468
+				'obj_id'     => $grp_id,
469
+				'noheader'   => true
470
+			),
471
+			'reset_to_default'                 => array(
472
+				'func'       => '_reset_to_default_template',
473
+				'capability' => 'ee_edit_message',
474
+				'obj_id'     => $grp_id,
475
+				'noheader'   => true
476
+			),
477
+			'settings'                         => array(
478
+				'func'       => '_settings',
479
+				'capability' => 'manage_options'
480
+			),
481
+			'update_global_settings'           => array(
482
+				'func'       => '_update_global_settings',
483
+				'capability' => 'manage_options',
484
+				'noheader'   => true
485
+			),
486
+			'generate_now'                     => array(
487
+				'func'       => '_generate_now',
488
+				'capability' => 'ee_send_message',
489
+				'noheader'   => true
490
+			),
491
+			'generate_and_send_now'            => array(
492
+				'func'       => '_generate_and_send_now',
493
+				'capability' => 'ee_send_message',
494
+				'noheader'   => true
495
+			),
496
+			'queue_for_resending'              => array(
497
+				'func'       => '_queue_for_resending',
498
+				'capability' => 'ee_send_message',
499
+				'noheader'   => true
500
+			),
501
+			'send_now'                         => array(
502
+				'func'       => '_send_now',
503
+				'capability' => 'ee_send_message',
504
+				'noheader'   => true
505
+			),
506
+			'delete_ee_message'                => array(
507
+				'func'       => '_delete_ee_messages',
508
+				'capability' => 'ee_delete_messages',
509
+				'noheader'   => true
510
+			),
511
+			'delete_ee_messages'               => array(
512
+				'func'       => '_delete_ee_messages',
513
+				'capability' => 'ee_delete_messages',
514
+				'noheader'   => true,
515
+				'obj_id'     => $msg_id
516
+			)
517
+		);
518
+	}
519 519
     
520 520
     
521
-    protected function _set_page_config()
522
-    {
523
-        $this->_page_config = array(
524
-            'default'                  => array(
525
-                'nav'           => array(
526
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
527
-                    'order' => 10
528
-                ),
529
-                'list_table'    => 'EE_Message_List_Table',
530
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
531
-                'require_nonce' => false
532
-            ),
533
-            'global_mtps'              => array(
534
-                'nav'           => array(
535
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
536
-                    'order' => 20
537
-                ),
538
-                'list_table'    => 'Messages_Template_List_Table',
539
-                'help_tabs'     => array(
540
-                    'messages_overview_help_tab'                                => array(
541
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
542
-                        'filename' => 'messages_overview'
543
-                    ),
544
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
545
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
546
-                        'filename' => 'messages_overview_table_column_headings'
547
-                    ),
548
-                    'messages_overview_messages_filters_help_tab'               => array(
549
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
550
-                        'filename' => 'messages_overview_filters'
551
-                    ),
552
-                    'messages_overview_messages_views_help_tab'                 => array(
553
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
554
-                        'filename' => 'messages_overview_views'
555
-                    ),
556
-                    'message_overview_message_types_help_tab'                   => array(
557
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
558
-                        'filename' => 'messages_overview_types'
559
-                    ),
560
-                    'messages_overview_messengers_help_tab'                     => array(
561
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
562
-                        'filename' => 'messages_overview_messengers',
563
-                    ),
564
-                ),
565
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
566
-                'require_nonce' => false
567
-            ),
568
-            'custom_mtps'              => array(
569
-                'nav'           => array(
570
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
571
-                    'order' => 30
572
-                ),
573
-                'help_tabs'     => array(),
574
-                'help_tour'     => array(),
575
-                'require_nonce' => false
576
-            ),
577
-            'add_new_message_template' => array(
578
-                'nav'           => array(
579
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
580
-                    'order'      => 5,
581
-                    'persistent' => false
582
-                ),
583
-                'require_nonce' => false
584
-            ),
585
-            'edit_message_template'    => array(
586
-                'labels'        => array(
587
-                    'buttons'    => array(
588
-                        'reset' => esc_html__('Reset Templates'),
589
-                    ),
590
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso')
591
-                ),
592
-                'nav'           => array(
593
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
594
-                    'order'      => 5,
595
-                    'persistent' => false,
596
-                    'url'        => ''
597
-                ),
598
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
599
-                'has_metaboxes' => true,
600
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
601
-                'help_tabs'     => array(
602
-                    'edit_message_template'       => array(
603
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
604
-                        'callback' => 'edit_message_template_help_tab'
605
-                    ),
606
-                    'message_templates_help_tab'  => array(
607
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
608
-                        'filename' => 'messages_templates'
609
-                    ),
610
-                    'message_template_shortcodes' => array(
611
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
612
-                        'callback' => 'message_template_shortcodes_help_tab'
613
-                    ),
614
-                    'message_preview_help_tab'    => array(
615
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
616
-                        'filename' => 'messages_preview'
617
-                    ),
618
-                    'messages_overview_other_help_tab'                          => array(
619
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
620
-                        'filename' => 'messages_overview_other',
621
-                    ),
622
-                ),
623
-                'require_nonce' => false
624
-            ),
625
-            'display_preview_message'  => array(
626
-                'nav'           => array(
627
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
628
-                    'order'      => 5,
629
-                    'url'        => '',
630
-                    'persistent' => false
631
-                ),
632
-                'help_tabs'     => array(
633
-                    'preview_message' => array(
634
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
635
-                        'callback' => 'preview_message_help_tab'
636
-                    )
637
-                ),
638
-                'require_nonce' => false
639
-            ),
640
-            'settings'                 => array(
641
-                'nav'           => array(
642
-                    'label' => esc_html__('Settings', 'event_espresso'),
643
-                    'order' => 40
644
-                ),
645
-                'metaboxes'     => array('_messages_settings_metaboxes'),
646
-                'help_tabs'     => array(
647
-                    'messages_settings_help_tab'               => array(
648
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
649
-                        'filename' => 'messages_settings'
650
-                    ),
651
-                    'messages_settings_message_types_help_tab' => array(
652
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
653
-                        'filename' => 'messages_settings_message_types'
654
-                    ),
655
-                    'messages_settings_messengers_help_tab'    => array(
656
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
657
-                        'filename' => 'messages_settings_messengers'
658
-                    ),
659
-                ),
660
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
661
-                'require_nonce' => false
662
-            )
663
-        );
664
-    }
521
+	protected function _set_page_config()
522
+	{
523
+		$this->_page_config = array(
524
+			'default'                  => array(
525
+				'nav'           => array(
526
+					'label' => esc_html__('Message Activity', 'event_espresso'),
527
+					'order' => 10
528
+				),
529
+				'list_table'    => 'EE_Message_List_Table',
530
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
531
+				'require_nonce' => false
532
+			),
533
+			'global_mtps'              => array(
534
+				'nav'           => array(
535
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
536
+					'order' => 20
537
+				),
538
+				'list_table'    => 'Messages_Template_List_Table',
539
+				'help_tabs'     => array(
540
+					'messages_overview_help_tab'                                => array(
541
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
542
+						'filename' => 'messages_overview'
543
+					),
544
+					'messages_overview_messages_table_column_headings_help_tab' => array(
545
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
546
+						'filename' => 'messages_overview_table_column_headings'
547
+					),
548
+					'messages_overview_messages_filters_help_tab'               => array(
549
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
550
+						'filename' => 'messages_overview_filters'
551
+					),
552
+					'messages_overview_messages_views_help_tab'                 => array(
553
+						'title'    => esc_html__('Message Views', 'event_espresso'),
554
+						'filename' => 'messages_overview_views'
555
+					),
556
+					'message_overview_message_types_help_tab'                   => array(
557
+						'title'    => esc_html__('Message Types', 'event_espresso'),
558
+						'filename' => 'messages_overview_types'
559
+					),
560
+					'messages_overview_messengers_help_tab'                     => array(
561
+						'title'    => esc_html__('Messengers', 'event_espresso'),
562
+						'filename' => 'messages_overview_messengers',
563
+					),
564
+				),
565
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
566
+				'require_nonce' => false
567
+			),
568
+			'custom_mtps'              => array(
569
+				'nav'           => array(
570
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
571
+					'order' => 30
572
+				),
573
+				'help_tabs'     => array(),
574
+				'help_tour'     => array(),
575
+				'require_nonce' => false
576
+			),
577
+			'add_new_message_template' => array(
578
+				'nav'           => array(
579
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
580
+					'order'      => 5,
581
+					'persistent' => false
582
+				),
583
+				'require_nonce' => false
584
+			),
585
+			'edit_message_template'    => array(
586
+				'labels'        => array(
587
+					'buttons'    => array(
588
+						'reset' => esc_html__('Reset Templates'),
589
+					),
590
+					'publishbox' => esc_html__('Update Actions', 'event_espresso')
591
+				),
592
+				'nav'           => array(
593
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
594
+					'order'      => 5,
595
+					'persistent' => false,
596
+					'url'        => ''
597
+				),
598
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
599
+				'has_metaboxes' => true,
600
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
601
+				'help_tabs'     => array(
602
+					'edit_message_template'       => array(
603
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
604
+						'callback' => 'edit_message_template_help_tab'
605
+					),
606
+					'message_templates_help_tab'  => array(
607
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
608
+						'filename' => 'messages_templates'
609
+					),
610
+					'message_template_shortcodes' => array(
611
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
612
+						'callback' => 'message_template_shortcodes_help_tab'
613
+					),
614
+					'message_preview_help_tab'    => array(
615
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
616
+						'filename' => 'messages_preview'
617
+					),
618
+					'messages_overview_other_help_tab'                          => array(
619
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
620
+						'filename' => 'messages_overview_other',
621
+					),
622
+				),
623
+				'require_nonce' => false
624
+			),
625
+			'display_preview_message'  => array(
626
+				'nav'           => array(
627
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
628
+					'order'      => 5,
629
+					'url'        => '',
630
+					'persistent' => false
631
+				),
632
+				'help_tabs'     => array(
633
+					'preview_message' => array(
634
+						'title'    => esc_html__('About Previews', 'event_espresso'),
635
+						'callback' => 'preview_message_help_tab'
636
+					)
637
+				),
638
+				'require_nonce' => false
639
+			),
640
+			'settings'                 => array(
641
+				'nav'           => array(
642
+					'label' => esc_html__('Settings', 'event_espresso'),
643
+					'order' => 40
644
+				),
645
+				'metaboxes'     => array('_messages_settings_metaboxes'),
646
+				'help_tabs'     => array(
647
+					'messages_settings_help_tab'               => array(
648
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
649
+						'filename' => 'messages_settings'
650
+					),
651
+					'messages_settings_message_types_help_tab' => array(
652
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
653
+						'filename' => 'messages_settings_message_types'
654
+					),
655
+					'messages_settings_messengers_help_tab'    => array(
656
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
657
+						'filename' => 'messages_settings_messengers'
658
+					),
659
+				),
660
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
661
+				'require_nonce' => false
662
+			)
663
+		);
664
+	}
665 665
     
666 666
     
667
-    protected function _add_screen_options()
668
-    {
669
-        //todo
670
-    }
667
+	protected function _add_screen_options()
668
+	{
669
+		//todo
670
+	}
671 671
     
672 672
     
673
-    protected function _add_screen_options_global_mtps()
674
-    {
675
-        /**
676
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
677
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
678
-         */
679
-        $page_title              = $this->_admin_page_title;
680
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
681
-        $this->_per_page_screen_option();
682
-        $this->_admin_page_title = $page_title;
683
-    }
673
+	protected function _add_screen_options_global_mtps()
674
+	{
675
+		/**
676
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
677
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
678
+		 */
679
+		$page_title              = $this->_admin_page_title;
680
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
681
+		$this->_per_page_screen_option();
682
+		$this->_admin_page_title = $page_title;
683
+	}
684 684
     
685 685
     
686
-    protected function _add_screen_options_default()
687
-    {
688
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
689
-        $this->_per_page_screen_option();
690
-    }
686
+	protected function _add_screen_options_default()
687
+	{
688
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
689
+		$this->_per_page_screen_option();
690
+	}
691 691
     
692 692
     
693
-    //none of the below group are currently used for Messages
694
-    protected function _add_feature_pointers()
695
-    {
696
-    }
693
+	//none of the below group are currently used for Messages
694
+	protected function _add_feature_pointers()
695
+	{
696
+	}
697 697
     
698
-    public function admin_init()
699
-    {
700
-    }
698
+	public function admin_init()
699
+	{
700
+	}
701 701
     
702
-    public function admin_notices()
703
-    {
704
-    }
702
+	public function admin_notices()
703
+	{
704
+	}
705 705
     
706
-    public function admin_footer_scripts()
707
-    {
708
-    }
706
+	public function admin_footer_scripts()
707
+	{
708
+	}
709 709
     
710 710
     
711
-    public function messages_help_tab()
712
-    {
713
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
714
-    }
711
+	public function messages_help_tab()
712
+	{
713
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
714
+	}
715 715
     
716 716
     
717
-    public function messengers_help_tab()
718
-    {
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
720
-    }
717
+	public function messengers_help_tab()
718
+	{
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
720
+	}
721 721
     
722 722
     
723
-    public function message_types_help_tab()
724
-    {
725
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
726
-    }
723
+	public function message_types_help_tab()
724
+	{
725
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
726
+	}
727 727
     
728 728
     
729
-    public function messages_overview_help_tab()
730
-    {
731
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
732
-    }
729
+	public function messages_overview_help_tab()
730
+	{
731
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
732
+	}
733 733
     
734 734
     
735
-    public function message_templates_help_tab()
736
-    {
737
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
738
-    }
735
+	public function message_templates_help_tab()
736
+	{
737
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
738
+	}
739 739
     
740 740
     
741
-    public function edit_message_template_help_tab()
742
-    {
743
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
744
-                        . esc_attr__('Editor Title', 'event_espresso')
745
-                        . '" />';
746
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
747
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
748
-                        . '" />';
749
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
750
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
751
-                        . '" />';
752
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
753
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
754
-                        . '" />';
755
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
756
-                        . esc_attr__('Publish Metabox', 'event_espresso')
757
-                        . '" />';
758
-        EEH_Template::display_template(
759
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
760
-            $args
761
-        );
762
-    }
741
+	public function edit_message_template_help_tab()
742
+	{
743
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
744
+						. esc_attr__('Editor Title', 'event_espresso')
745
+						. '" />';
746
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
747
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
748
+						. '" />';
749
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
750
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
751
+						. '" />';
752
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
753
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
754
+						. '" />';
755
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
756
+						. esc_attr__('Publish Metabox', 'event_espresso')
757
+						. '" />';
758
+		EEH_Template::display_template(
759
+			EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
760
+			$args
761
+		);
762
+	}
763 763
     
764 764
     
765
-    public function message_template_shortcodes_help_tab()
766
-    {
767
-        $this->_set_shortcodes();
768
-        $args['shortcodes'] = $this->_shortcodes;
769
-        EEH_Template::display_template(
770
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
771
-            $args
772
-        );
773
-    }
765
+	public function message_template_shortcodes_help_tab()
766
+	{
767
+		$this->_set_shortcodes();
768
+		$args['shortcodes'] = $this->_shortcodes;
769
+		EEH_Template::display_template(
770
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
771
+			$args
772
+		);
773
+	}
774 774
     
775 775
     
776
-    public function preview_message_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
779
-    }
776
+	public function preview_message_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
779
+	}
780 780
     
781 781
     
782
-    public function settings_help_tab()
783
-    {
784
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
785
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
786
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
787
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
788
-        $args['img3'] = '<div class="switch">'
789
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
790
-                        . ' type="checkbox" checked="checked">'
791
-                        . '<label for="ee-on-off-toggle-on"></label>'
792
-                        . '</div>';
793
-        $args['img4'] = '<div class="switch">'
794
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
795
-                        . ' type="checkbox">'
796
-                        . '<label for="ee-on-off-toggle-on"></label>'
797
-                        . '</div>';
798
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
799
-    }
782
+	public function settings_help_tab()
783
+	{
784
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
785
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
786
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
787
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
788
+		$args['img3'] = '<div class="switch">'
789
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
790
+						. ' type="checkbox" checked="checked">'
791
+						. '<label for="ee-on-off-toggle-on"></label>'
792
+						. '</div>';
793
+		$args['img4'] = '<div class="switch">'
794
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
795
+						. ' type="checkbox">'
796
+						. '<label for="ee-on-off-toggle-on"></label>'
797
+						. '</div>';
798
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
799
+	}
800 800
     
801 801
     
802
-    public function load_scripts_styles()
803
-    {
804
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
805
-        wp_enqueue_style('espresso_ee_msg');
806
-        
807
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
808
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
809
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
810
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
811
-    }
802
+	public function load_scripts_styles()
803
+	{
804
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
805
+		wp_enqueue_style('espresso_ee_msg');
806
+        
807
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
808
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
809
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
810
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
811
+	}
812 812
     
813 813
     
814
-    public function load_scripts_styles_default()
815
-    {
816
-        wp_enqueue_script('ee-msg-list-table-js');
817
-    }
814
+	public function load_scripts_styles_default()
815
+	{
816
+		wp_enqueue_script('ee-msg-list-table-js');
817
+	}
818 818
     
819 819
     
820
-    public function wp_editor_css($mce_css)
821
-    {
822
-        //if we're on the edit_message_template route
823
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
824
-            $message_type_name = $this->_active_message_type_name;
820
+	public function wp_editor_css($mce_css)
821
+	{
822
+		//if we're on the edit_message_template route
823
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
824
+			$message_type_name = $this->_active_message_type_name;
825 825
             
826
-            //we're going to REPLACE the existing mce css
827
-            //we need to get the css file location from the active messenger
828
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
829
-                'wpeditor', $this->_variation);
830
-        }
831
-        
832
-        return $mce_css;
833
-    }
826
+			//we're going to REPLACE the existing mce css
827
+			//we need to get the css file location from the active messenger
828
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
829
+				'wpeditor', $this->_variation);
830
+		}
831
+        
832
+		return $mce_css;
833
+	}
834 834
     
835 835
     
836
-    public function load_scripts_styles_edit_message_template()
837
-    {
838
-        
839
-        $this->_set_shortcodes();
840
-        
841
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
842
-            esc_html__(
843
-                '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.',
844
-                'event_espresso'
845
-            ),
846
-            $this->_message_template_group->messenger_obj()->label['singular'],
847
-            $this->_message_template_group->message_type_obj()->label['singular']
848
-        );
849
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
850
-            '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?',
851
-            'event_espresso'
852
-        );
853
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
854
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
855
-            'event_espresso'
856
-        );
857
-        
858
-        wp_register_script(
859
-            'ee_msgs_edit_js',
860
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
861
-            array('jquery'),
862
-            EVENT_ESPRESSO_VERSION
863
-        );
864
-        
865
-        wp_enqueue_script('ee_admin_js');
866
-        wp_enqueue_script('ee_msgs_edit_js');
867
-        
868
-        //add in special css for tiny_mce
869
-        add_filter('mce_css', array($this, 'wp_editor_css'));
870
-    }
836
+	public function load_scripts_styles_edit_message_template()
837
+	{
838
+        
839
+		$this->_set_shortcodes();
840
+        
841
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
842
+			esc_html__(
843
+				'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.',
844
+				'event_espresso'
845
+			),
846
+			$this->_message_template_group->messenger_obj()->label['singular'],
847
+			$this->_message_template_group->message_type_obj()->label['singular']
848
+		);
849
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
850
+			'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?',
851
+			'event_espresso'
852
+		);
853
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
854
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
855
+			'event_espresso'
856
+		);
857
+        
858
+		wp_register_script(
859
+			'ee_msgs_edit_js',
860
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
861
+			array('jquery'),
862
+			EVENT_ESPRESSO_VERSION
863
+		);
864
+        
865
+		wp_enqueue_script('ee_admin_js');
866
+		wp_enqueue_script('ee_msgs_edit_js');
867
+        
868
+		//add in special css for tiny_mce
869
+		add_filter('mce_css', array($this, 'wp_editor_css'));
870
+	}
871 871
     
872 872
     
873
-    public function load_scripts_styles_display_preview_message()
874
-    {
875
-        
876
-        $this->_set_message_template_group();
877
-        
878
-        if (isset($this->_req_data['messenger'])) {
879
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
880
-                $this->_req_data['messenger']
881
-            );
882
-        }
883
-        
884
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
885
-        
886
-        
887
-        wp_enqueue_style('espresso_preview_css',
888
-            $this->_active_messenger->get_variation(
889
-                $this->_template_pack,
890
-                $message_type_name,
891
-                true,
892
-                'preview',
893
-                $this->_variation
894
-            )
895
-        );
896
-    }
873
+	public function load_scripts_styles_display_preview_message()
874
+	{
875
+        
876
+		$this->_set_message_template_group();
877
+        
878
+		if (isset($this->_req_data['messenger'])) {
879
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
880
+				$this->_req_data['messenger']
881
+			);
882
+		}
883
+        
884
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
885
+        
886
+        
887
+		wp_enqueue_style('espresso_preview_css',
888
+			$this->_active_messenger->get_variation(
889
+				$this->_template_pack,
890
+				$message_type_name,
891
+				true,
892
+				'preview',
893
+				$this->_variation
894
+			)
895
+		);
896
+	}
897 897
     
898 898
     
899
-    public function load_scripts_styles_settings()
900
-    {
901
-        wp_register_style(
902
-            'ee-message-settings',
903
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
904
-            array(),
905
-            EVENT_ESPRESSO_VERSION
906
-        );
907
-        wp_enqueue_style('ee-text-links');
908
-        wp_enqueue_style('ee-message-settings');
909
-        wp_enqueue_script('ee-messages-settings');
910
-    }
899
+	public function load_scripts_styles_settings()
900
+	{
901
+		wp_register_style(
902
+			'ee-message-settings',
903
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
904
+			array(),
905
+			EVENT_ESPRESSO_VERSION
906
+		);
907
+		wp_enqueue_style('ee-text-links');
908
+		wp_enqueue_style('ee-message-settings');
909
+		wp_enqueue_script('ee-messages-settings');
910
+	}
911 911
     
912 912
     
913
-    /**
914
-     * set views array for List Table
915
-     */
916
-    public function _set_list_table_views_global_mtps()
917
-    {
918
-        $this->_views = array(
919
-            'in_use' => array(
920
-                'slug'        => 'in_use',
921
-                'label'       => esc_html__('In Use', 'event_espresso'),
922
-                'count'       => 0,
923
-            )
924
-        );
925
-    }
913
+	/**
914
+	 * set views array for List Table
915
+	 */
916
+	public function _set_list_table_views_global_mtps()
917
+	{
918
+		$this->_views = array(
919
+			'in_use' => array(
920
+				'slug'        => 'in_use',
921
+				'label'       => esc_html__('In Use', 'event_espresso'),
922
+				'count'       => 0,
923
+			)
924
+		);
925
+	}
926 926
 
927 927
 
928
-    /**
929
-     * Set views array for the Custom Template List Table
930
-     */
931
-    public function _set_list_table_views_custom_mtps()
932
-    {
933
-        $this->_set_list_table_views_global_mtps();
934
-        $this->_views['in_use']['bulk_action'] = array(
935
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
936
-        );
937
-    }
928
+	/**
929
+	 * Set views array for the Custom Template List Table
930
+	 */
931
+	public function _set_list_table_views_custom_mtps()
932
+	{
933
+		$this->_set_list_table_views_global_mtps();
934
+		$this->_views['in_use']['bulk_action'] = array(
935
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
936
+		);
937
+	}
938 938
 
939 939
 
940
-    /**
941
-     * set views array for message queue list table
942
-     *
943
-     * @throws InvalidDataTypeException
944
-     * @throws InvalidInterfaceException
945
-     * @throws InvalidArgumentException
946
-     * @throws EE_Error
947
-     * @throws ReflectionException
948
-     */
949
-    public function _set_list_table_views_default()
950
-    {
951
-        EE_Registry::instance()->load_helper('Template');
952
-        
953
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
954
-            'ee_send_message',
955
-            'message_list_table_bulk_actions'
956
-        )
957
-            ? array(
958
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
959
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
960
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
961
-                'send_now'              => esc_html__('Send Now', 'event_espresso')
962
-            )
963
-            : array();
964
-        
965
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
966
-            'ee_delete_messages',
967
-            'message_list_table_bulk_actions'
968
-        )
969
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
970
-            : array();
971
-        
972
-        
973
-        $this->_views = array(
974
-            'all' => array(
975
-                'slug'        => 'all',
976
-                'label'       => esc_html__('All', 'event_espresso'),
977
-                'count'       => 0,
978
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
979
-            )
980
-        );
981
-        
982
-        
983
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
984
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
985
-                continue;
986
-            }
987
-            $status_bulk_actions = $common_bulk_actions;
988
-            //unset bulk actions not applying to status
989
-            if (! empty($status_bulk_actions)) {
990
-                switch ($status) {
991
-                    case EEM_Message::status_idle:
992
-                    case EEM_Message::status_resend:
993
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
994
-                        break;
940
+	/**
941
+	 * set views array for message queue list table
942
+	 *
943
+	 * @throws InvalidDataTypeException
944
+	 * @throws InvalidInterfaceException
945
+	 * @throws InvalidArgumentException
946
+	 * @throws EE_Error
947
+	 * @throws ReflectionException
948
+	 */
949
+	public function _set_list_table_views_default()
950
+	{
951
+		EE_Registry::instance()->load_helper('Template');
952
+        
953
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
954
+			'ee_send_message',
955
+			'message_list_table_bulk_actions'
956
+		)
957
+			? array(
958
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
959
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
960
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
961
+				'send_now'              => esc_html__('Send Now', 'event_espresso')
962
+			)
963
+			: array();
964
+        
965
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
966
+			'ee_delete_messages',
967
+			'message_list_table_bulk_actions'
968
+		)
969
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
970
+			: array();
971
+        
972
+        
973
+		$this->_views = array(
974
+			'all' => array(
975
+				'slug'        => 'all',
976
+				'label'       => esc_html__('All', 'event_espresso'),
977
+				'count'       => 0,
978
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
979
+			)
980
+		);
981
+        
982
+        
983
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
984
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
985
+				continue;
986
+			}
987
+			$status_bulk_actions = $common_bulk_actions;
988
+			//unset bulk actions not applying to status
989
+			if (! empty($status_bulk_actions)) {
990
+				switch ($status) {
991
+					case EEM_Message::status_idle:
992
+					case EEM_Message::status_resend:
993
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
994
+						break;
995 995
                     
996
-                    case EEM_Message::status_failed:
997
-                    case EEM_Message::status_debug_only:
998
-                    case EEM_Message::status_messenger_executing:
999
-                        $status_bulk_actions = array();
1000
-                        break;
996
+					case EEM_Message::status_failed:
997
+					case EEM_Message::status_debug_only:
998
+					case EEM_Message::status_messenger_executing:
999
+						$status_bulk_actions = array();
1000
+						break;
1001 1001
                     
1002
-                    case EEM_Message::status_incomplete:
1003
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1004
-                        break;
1002
+					case EEM_Message::status_incomplete:
1003
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1004
+						break;
1005 1005
                     
1006
-                    case EEM_Message::status_retry:
1007
-                    case EEM_Message::status_sent:
1008
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1009
-                        break;
1010
-                }
1011
-            }
1006
+					case EEM_Message::status_retry:
1007
+					case EEM_Message::status_sent:
1008
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1009
+						break;
1010
+				}
1011
+			}
1012 1012
 
1013
-            //skip adding messenger executing status to views because it will be included with the Failed view.
1014
-            if ( $status === EEM_Message::status_messenger_executing ) {
1015
-                continue;
1016
-            }
1013
+			//skip adding messenger executing status to views because it will be included with the Failed view.
1014
+			if ( $status === EEM_Message::status_messenger_executing ) {
1015
+				continue;
1016
+			}
1017 1017
             
1018
-            $this->_views[strtolower($status)] = array(
1019
-                'slug'        => strtolower($status),
1020
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1021
-                'count'       => 0,
1022
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1023
-            );
1024
-        }
1025
-    }
1018
+			$this->_views[strtolower($status)] = array(
1019
+				'slug'        => strtolower($status),
1020
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1021
+				'count'       => 0,
1022
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1023
+			);
1024
+		}
1025
+	}
1026 1026
     
1027 1027
     
1028
-    protected function _ee_default_messages_overview_list_table()
1029
-    {
1030
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1031
-        $this->display_admin_list_table_page_with_no_sidebar();
1032
-    }
1028
+	protected function _ee_default_messages_overview_list_table()
1029
+	{
1030
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1031
+		$this->display_admin_list_table_page_with_no_sidebar();
1032
+	}
1033 1033
     
1034 1034
     
1035
-    protected function _message_queue_list_table()
1036
-    {
1037
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1038
-        $this->_template_args['per_column']        = 6;
1039
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1040
-        $this->_template_args['before_list_table'] = '<h3>'
1041
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1042
-                                                     . '</h3>';
1043
-        $this->display_admin_list_table_page_with_no_sidebar();
1044
-    }
1035
+	protected function _message_queue_list_table()
1036
+	{
1037
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1038
+		$this->_template_args['per_column']        = 6;
1039
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1040
+		$this->_template_args['before_list_table'] = '<h3>'
1041
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1042
+													 . '</h3>';
1043
+		$this->display_admin_list_table_page_with_no_sidebar();
1044
+	}
1045 1045
     
1046 1046
     
1047
-    protected function _message_legend_items()
1048
-    {
1049
-        
1050
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1051
-        $action_items       = array();
1052
-        
1053
-        foreach ($action_css_classes as $action_item => $action_details) {
1054
-            if ($action_item === 'see_notifications_for') {
1055
-                continue;
1056
-            }
1057
-            $action_items[$action_item] = array(
1058
-                'class' => $action_details['css_class'],
1059
-                'desc'  => $action_details['label']
1060
-            );
1061
-        }
1062
-        
1063
-        /** @type array $status_items status legend setup */
1064
-        $status_items = array(
1065
-            'sent_status'       => array(
1066
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1067
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1068
-            ),
1069
-            'idle_status'       => array(
1070
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1071
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1072
-            ),
1073
-            'failed_status'     => array(
1074
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1075
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1076
-            ),
1077
-            'messenger_executing_status' => array(
1078
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1079
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1080
-            ),
1081
-            'resend_status'     => array(
1082
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1083
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1084
-            ),
1085
-            'incomplete_status' => array(
1086
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1087
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1088
-            ),
1089
-            'retry_status'      => array(
1090
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1091
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1092
-            )
1093
-        );
1094
-        if (EEM_Message::debug()) {
1095
-            $status_items['debug_only_status'] = array(
1096
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1097
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1098
-            );
1099
-        }
1100
-        
1101
-        return array_merge($action_items, $status_items);
1102
-    }
1047
+	protected function _message_legend_items()
1048
+	{
1049
+        
1050
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1051
+		$action_items       = array();
1052
+        
1053
+		foreach ($action_css_classes as $action_item => $action_details) {
1054
+			if ($action_item === 'see_notifications_for') {
1055
+				continue;
1056
+			}
1057
+			$action_items[$action_item] = array(
1058
+				'class' => $action_details['css_class'],
1059
+				'desc'  => $action_details['label']
1060
+			);
1061
+		}
1062
+        
1063
+		/** @type array $status_items status legend setup */
1064
+		$status_items = array(
1065
+			'sent_status'       => array(
1066
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1067
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1068
+			),
1069
+			'idle_status'       => array(
1070
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1071
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1072
+			),
1073
+			'failed_status'     => array(
1074
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1075
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1076
+			),
1077
+			'messenger_executing_status' => array(
1078
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1079
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1080
+			),
1081
+			'resend_status'     => array(
1082
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1083
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1084
+			),
1085
+			'incomplete_status' => array(
1086
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1087
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1088
+			),
1089
+			'retry_status'      => array(
1090
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1091
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1092
+			)
1093
+		);
1094
+		if (EEM_Message::debug()) {
1095
+			$status_items['debug_only_status'] = array(
1096
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1097
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1098
+			);
1099
+		}
1100
+        
1101
+		return array_merge($action_items, $status_items);
1102
+	}
1103 1103
     
1104 1104
     
1105
-    protected function _custom_mtps_preview()
1106
-    {
1107
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1108
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1109
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1110
-        $this->_template_args['preview_text'] = '<strong>'
1111
-            . esc_html__(
1112
-                '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.',
1113
-                'event_espresso'
1114
-            )
1115
-            . '</strong>';
1105
+	protected function _custom_mtps_preview()
1106
+	{
1107
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1108
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1109
+			. ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1110
+		$this->_template_args['preview_text'] = '<strong>'
1111
+			. esc_html__(
1112
+				'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.',
1113
+				'event_espresso'
1114
+			)
1115
+			. '</strong>';
1116 1116
 
1117
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1118
-    }
1117
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1118
+	}
1119 1119
 
1120 1120
 
1121
-    /**
1122
-     * get_message_templates
1123
-     * This gets all the message templates for listing on the overview list.
1124
-     *
1125
-     * @access public
1126
-     * @param int    $perpage the amount of templates groups to show per page
1127
-     * @param string $type    the current _view we're getting templates for
1128
-     * @param bool   $count   return count?
1129
-     * @param bool   $all     disregard any paging info (get all data);
1130
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1131
-     * @return array
1132
-     * @throws EE_Error
1133
-     * @throws InvalidArgumentException
1134
-     * @throws InvalidDataTypeException
1135
-     * @throws InvalidInterfaceException
1136
-     */
1137
-    public function get_message_templates(
1138
-        $perpage = 10,
1139
-        $type = 'in_use',
1140
-        $count = false,
1141
-        $all = false,
1142
-        $global = true)
1143
-    {
1144
-        
1145
-        $MTP = EEM_Message_Template_Group::instance();
1146
-        
1147
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1148
-        $orderby                    = $this->_req_data['orderby'];
1149
-        
1150
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1151
-            ? $this->_req_data['order']
1152
-            : 'ASC';
1153
-        
1154
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1155
-            ? $this->_req_data['paged']
1156
-            : 1;
1157
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1158
-            ? $this->_req_data['perpage']
1159
-            : $perpage;
1160
-        
1161
-        $offset = ($current_page - 1) * $per_page;
1162
-        $limit  = $all ? null : array($offset, $per_page);
1163
-        
1164
-        
1165
-        //options will match what is in the _views array property
1166
-        switch ($type) {
1167
-            case 'in_use':
1168
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1169
-                break;
1170
-            default:
1171
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1172
-        }
1173
-        
1174
-        return $templates;
1175
-    }
1121
+	/**
1122
+	 * get_message_templates
1123
+	 * This gets all the message templates for listing on the overview list.
1124
+	 *
1125
+	 * @access public
1126
+	 * @param int    $perpage the amount of templates groups to show per page
1127
+	 * @param string $type    the current _view we're getting templates for
1128
+	 * @param bool   $count   return count?
1129
+	 * @param bool   $all     disregard any paging info (get all data);
1130
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1131
+	 * @return array
1132
+	 * @throws EE_Error
1133
+	 * @throws InvalidArgumentException
1134
+	 * @throws InvalidDataTypeException
1135
+	 * @throws InvalidInterfaceException
1136
+	 */
1137
+	public function get_message_templates(
1138
+		$perpage = 10,
1139
+		$type = 'in_use',
1140
+		$count = false,
1141
+		$all = false,
1142
+		$global = true)
1143
+	{
1144
+        
1145
+		$MTP = EEM_Message_Template_Group::instance();
1146
+        
1147
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1148
+		$orderby                    = $this->_req_data['orderby'];
1149
+        
1150
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1151
+			? $this->_req_data['order']
1152
+			: 'ASC';
1153
+        
1154
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1155
+			? $this->_req_data['paged']
1156
+			: 1;
1157
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1158
+			? $this->_req_data['perpage']
1159
+			: $perpage;
1160
+        
1161
+		$offset = ($current_page - 1) * $per_page;
1162
+		$limit  = $all ? null : array($offset, $per_page);
1163
+        
1164
+        
1165
+		//options will match what is in the _views array property
1166
+		switch ($type) {
1167
+			case 'in_use':
1168
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1169
+				break;
1170
+			default:
1171
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1172
+		}
1173
+        
1174
+		return $templates;
1175
+	}
1176 1176
     
1177 1177
     
1178
-    /**
1179
-     * filters etc might need a list of installed message_types
1180
-     * @return array an array of message type objects
1181
-     */
1182
-    public function get_installed_message_types()
1183
-    {
1184
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1185
-        $installed               = array();
1186
-        
1187
-        foreach ($installed_message_types as $message_type) {
1188
-            $installed[$message_type->name] = $message_type;
1189
-        }
1190
-        
1191
-        return $installed;
1192
-    }
1178
+	/**
1179
+	 * filters etc might need a list of installed message_types
1180
+	 * @return array an array of message type objects
1181
+	 */
1182
+	public function get_installed_message_types()
1183
+	{
1184
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1185
+		$installed               = array();
1186
+        
1187
+		foreach ($installed_message_types as $message_type) {
1188
+			$installed[$message_type->name] = $message_type;
1189
+		}
1190
+        
1191
+		return $installed;
1192
+	}
1193 1193
     
1194 1194
     
1195
-    /**
1196
-     * _add_message_template
1197
-     *
1198
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1199
-     *
1200
-     * @param string $message_type
1201
-     * @param string $messenger
1202
-     * @param string $GRP_ID
1203
-     *
1204
-     * @throws EE_error
1205
-     */
1206
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1207
-    {
1208
-        //set values override any request data
1209
-        $message_type = ! empty($message_type) ? $message_type : '';
1210
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1211
-            ? $this->_req_data['message_type']
1212
-            : $message_type;
1213
-        
1214
-        $messenger = ! empty($messenger) ? $messenger : '';
1215
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1216
-            ? $this->_req_data['messenger']
1217
-            : $messenger;
1218
-        
1219
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1220
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1221
-        
1222
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1223
-        if (empty($message_type) || empty($messenger)) {
1224
-            throw new EE_Error(
1225
-                esc_html__(
1226
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1227
-                    'event_espresso'
1228
-                )
1229
-            );
1230
-        }
1231
-        
1232
-        //we need the GRP_ID for the template being used as the base for the new template
1233
-        if (empty($GRP_ID)) {
1234
-            throw new EE_Error(
1235
-                esc_html__(
1236
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1237
-                    'event_espresso'
1238
-                )
1239
-            );
1240
-        }
1241
-        
1242
-        //let's just make sure the template gets generated!
1243
-        
1244
-        //we need to reassign some variables for what the insert is expecting
1245
-        $this->_req_data['MTP_messenger']    = $messenger;
1246
-        $this->_req_data['MTP_message_type'] = $message_type;
1247
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1248
-        $this->_insert_or_update_message_template(true);
1249
-    }
1195
+	/**
1196
+	 * _add_message_template
1197
+	 *
1198
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1199
+	 *
1200
+	 * @param string $message_type
1201
+	 * @param string $messenger
1202
+	 * @param string $GRP_ID
1203
+	 *
1204
+	 * @throws EE_error
1205
+	 */
1206
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1207
+	{
1208
+		//set values override any request data
1209
+		$message_type = ! empty($message_type) ? $message_type : '';
1210
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1211
+			? $this->_req_data['message_type']
1212
+			: $message_type;
1213
+        
1214
+		$messenger = ! empty($messenger) ? $messenger : '';
1215
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1216
+			? $this->_req_data['messenger']
1217
+			: $messenger;
1218
+        
1219
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1220
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1221
+        
1222
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1223
+		if (empty($message_type) || empty($messenger)) {
1224
+			throw new EE_Error(
1225
+				esc_html__(
1226
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1227
+					'event_espresso'
1228
+				)
1229
+			);
1230
+		}
1231
+        
1232
+		//we need the GRP_ID for the template being used as the base for the new template
1233
+		if (empty($GRP_ID)) {
1234
+			throw new EE_Error(
1235
+				esc_html__(
1236
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1237
+					'event_espresso'
1238
+				)
1239
+			);
1240
+		}
1241
+        
1242
+		//let's just make sure the template gets generated!
1243
+        
1244
+		//we need to reassign some variables for what the insert is expecting
1245
+		$this->_req_data['MTP_messenger']    = $messenger;
1246
+		$this->_req_data['MTP_message_type'] = $message_type;
1247
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1248
+		$this->_insert_or_update_message_template(true);
1249
+	}
1250 1250
 
1251 1251
 
1252
-    /**
1253
-     * public wrapper for the _add_message_template method
1254
-     *
1255
-     * @param string $message_type     message type slug
1256
-     * @param string $messenger        messenger slug
1257
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1258
-     *                                 off of.
1259
-     * @throws EE_error
1260
-     */
1261
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1262
-    {
1263
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1264
-    }
1252
+	/**
1253
+	 * public wrapper for the _add_message_template method
1254
+	 *
1255
+	 * @param string $message_type     message type slug
1256
+	 * @param string $messenger        messenger slug
1257
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1258
+	 *                                 off of.
1259
+	 * @throws EE_error
1260
+	 */
1261
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1262
+	{
1263
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1264
+	}
1265 1265
 
1266 1266
 
1267
-    /**
1268
-     * _edit_message_template
1269
-     *
1270
-     * @access protected
1271
-     * @return void
1272
-     * @throws InvalidIdentifierException
1273
-     * @throws DomainException
1274
-     * @throws EE_Error
1275
-     * @throws InvalidArgumentException
1276
-     * @throws ReflectionException
1277
-     * @throws InvalidDataTypeException
1278
-     * @throws InvalidInterfaceException
1279
-     */
1280
-    protected function _edit_message_template()
1281
-    {
1282
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1283
-        $template_fields = '';
1284
-        $sidebar_fields  = '';
1285
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1286
-        // valid html in the templates.
1287
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1288
-        
1289
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1290
-            ? absint($this->_req_data['id'])
1291
-            : false;
1292
-        
1293
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1294
-        $message_template_group = $this->_message_template_group;
1295
-        $c_label                = $message_template_group->context_label();
1296
-        $c_config               = $message_template_group->contexts_config();
1297
-        
1298
-        reset($c_config);
1299
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1300
-            ? strtolower($this->_req_data['context'])
1301
-            : key($c_config);
1302
-        
1303
-        
1304
-        if (empty($GRP_ID)) {
1305
-            $action = 'insert_message_template';
1306
-            $edit_message_template_form_url = add_query_arg(
1307
-                array('action' => $action, 'noheader' => true),
1308
-                EE_MSG_ADMIN_URL
1309
-            );
1310
-        } else {
1311
-            $action = 'update_message_template';
1312
-            $edit_message_template_form_url = add_query_arg(
1313
-                array('action' => $action, 'noheader' => true),
1314
-                EE_MSG_ADMIN_URL
1315
-            );
1316
-        }
1317
-        
1318
-        //set active messenger for this view
1319
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1320
-            $message_template_group->messenger()
1321
-        );
1322
-        $this->_active_message_type_name = $message_template_group->message_type();
1323
-        
1324
-        
1325
-        //Do we have any validation errors?
1326
-        $validators = $this->_get_transient();
1327
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1328
-        
1329
-        
1330
-        //we need to assemble the title from Various details
1331
-        $context_label = sprintf(
1332
-            esc_html__('(%s %s)', 'event_espresso'),
1333
-            $c_config[$context]['label'],
1334
-            ucwords($c_label['label'])
1335
-        );
1336
-        
1337
-        $title = sprintf(
1338
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1339
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1340
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1341
-            $context_label
1342
-        );
1343
-        
1344
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1345
-        $this->_template_args['message_template'] = $message_template_group;
1346
-        $this->_template_args['is_extra_fields']  = false;
1347
-        
1348
-        
1349
-        //let's get EEH_MSG_Template so we can get template form fields
1350
-        $template_field_structure = EEH_MSG_Template::get_fields(
1351
-            $message_template_group->messenger(),
1352
-            $message_template_group->message_type()
1353
-        );
1354
-        
1355
-        if ( ! $template_field_structure) {
1356
-            $template_field_structure = false;
1357
-            $template_fields          = esc_html__(
1358
-                'There was an error in assembling the fields for this display (you should see an error message)',
1359
-                'event_espresso'
1360
-            );
1361
-        }
1362
-        
1363
-        
1364
-        $message_templates = $message_template_group->context_templates();
1365
-        
1366
-        
1367
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1368
-        // will get handled in the "extra" array.
1369
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1370
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1371
-                unset($template_field_structure[$context][$reference_field]);
1372
-            }
1373
-        }
1374
-        
1375
-        //let's loop through the template_field_structure and actually assemble the input fields!
1376
-        if ( ! empty($template_field_structure)) {
1377
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1378
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1379
-                // the extra array and reset them.
1380
-                if ($template_field === 'extra') {
1381
-                    $this->_template_args['is_extra_fields'] = true;
1382
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1383
-                        $message_template = $message_templates[$context][$reference_field];
1384
-                        $content          = $message_template instanceof EE_Message_Template
1385
-                            ? $message_template->get('MTP_content')
1386
-                            : '';
1387
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1388
-                            //let's verify if we need this extra field via the shortcodes parameter.
1389
-                            $continue = false;
1390
-                            if (isset($extra_array['shortcodes_required'])) {
1391
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1392
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1393
-                                        $continue = true;
1394
-                                    }
1395
-                                }
1396
-                                if ($continue) {
1397
-                                    continue;
1398
-                                }
1399
-                            }
1267
+	/**
1268
+	 * _edit_message_template
1269
+	 *
1270
+	 * @access protected
1271
+	 * @return void
1272
+	 * @throws InvalidIdentifierException
1273
+	 * @throws DomainException
1274
+	 * @throws EE_Error
1275
+	 * @throws InvalidArgumentException
1276
+	 * @throws ReflectionException
1277
+	 * @throws InvalidDataTypeException
1278
+	 * @throws InvalidInterfaceException
1279
+	 */
1280
+	protected function _edit_message_template()
1281
+	{
1282
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1283
+		$template_fields = '';
1284
+		$sidebar_fields  = '';
1285
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1286
+		// valid html in the templates.
1287
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1288
+        
1289
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1290
+			? absint($this->_req_data['id'])
1291
+			: false;
1292
+        
1293
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1294
+		$message_template_group = $this->_message_template_group;
1295
+		$c_label                = $message_template_group->context_label();
1296
+		$c_config               = $message_template_group->contexts_config();
1297
+        
1298
+		reset($c_config);
1299
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1300
+			? strtolower($this->_req_data['context'])
1301
+			: key($c_config);
1302
+        
1303
+        
1304
+		if (empty($GRP_ID)) {
1305
+			$action = 'insert_message_template';
1306
+			$edit_message_template_form_url = add_query_arg(
1307
+				array('action' => $action, 'noheader' => true),
1308
+				EE_MSG_ADMIN_URL
1309
+			);
1310
+		} else {
1311
+			$action = 'update_message_template';
1312
+			$edit_message_template_form_url = add_query_arg(
1313
+				array('action' => $action, 'noheader' => true),
1314
+				EE_MSG_ADMIN_URL
1315
+			);
1316
+		}
1317
+        
1318
+		//set active messenger for this view
1319
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1320
+			$message_template_group->messenger()
1321
+		);
1322
+		$this->_active_message_type_name = $message_template_group->message_type();
1323
+        
1324
+        
1325
+		//Do we have any validation errors?
1326
+		$validators = $this->_get_transient();
1327
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1328
+        
1329
+        
1330
+		//we need to assemble the title from Various details
1331
+		$context_label = sprintf(
1332
+			esc_html__('(%s %s)', 'event_espresso'),
1333
+			$c_config[$context]['label'],
1334
+			ucwords($c_label['label'])
1335
+		);
1336
+        
1337
+		$title = sprintf(
1338
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1339
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1340
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1341
+			$context_label
1342
+		);
1343
+        
1344
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1345
+		$this->_template_args['message_template'] = $message_template_group;
1346
+		$this->_template_args['is_extra_fields']  = false;
1347
+        
1348
+        
1349
+		//let's get EEH_MSG_Template so we can get template form fields
1350
+		$template_field_structure = EEH_MSG_Template::get_fields(
1351
+			$message_template_group->messenger(),
1352
+			$message_template_group->message_type()
1353
+		);
1354
+        
1355
+		if ( ! $template_field_structure) {
1356
+			$template_field_structure = false;
1357
+			$template_fields          = esc_html__(
1358
+				'There was an error in assembling the fields for this display (you should see an error message)',
1359
+				'event_espresso'
1360
+			);
1361
+		}
1362
+        
1363
+        
1364
+		$message_templates = $message_template_group->context_templates();
1365
+        
1366
+        
1367
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1368
+		// will get handled in the "extra" array.
1369
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1370
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1371
+				unset($template_field_structure[$context][$reference_field]);
1372
+			}
1373
+		}
1374
+        
1375
+		//let's loop through the template_field_structure and actually assemble the input fields!
1376
+		if ( ! empty($template_field_structure)) {
1377
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1378
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1379
+				// the extra array and reset them.
1380
+				if ($template_field === 'extra') {
1381
+					$this->_template_args['is_extra_fields'] = true;
1382
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1383
+						$message_template = $message_templates[$context][$reference_field];
1384
+						$content          = $message_template instanceof EE_Message_Template
1385
+							? $message_template->get('MTP_content')
1386
+							: '';
1387
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1388
+							//let's verify if we need this extra field via the shortcodes parameter.
1389
+							$continue = false;
1390
+							if (isset($extra_array['shortcodes_required'])) {
1391
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1392
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1393
+										$continue = true;
1394
+									}
1395
+								}
1396
+								if ($continue) {
1397
+									continue;
1398
+								}
1399
+							}
1400 1400
                             
1401
-                            $field_id                                = $reference_field
1402
-                                                                       . '-'
1403
-                                                                       . $extra_field
1404
-                                                                       . '-content';
1405
-                            $template_form_fields[$field_id]         = $extra_array;
1406
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1407
-                                                                       . $reference_field
1408
-                                                                       . '][content]['
1409
-                                                                       . $extra_field . ']';
1410
-                            $css_class                               = isset($extra_array['css_class'])
1411
-                                ? $extra_array['css_class']
1412
-                                : '';
1401
+							$field_id                                = $reference_field
1402
+																	   . '-'
1403
+																	   . $extra_field
1404
+																	   . '-content';
1405
+							$template_form_fields[$field_id]         = $extra_array;
1406
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1407
+																	   . $reference_field
1408
+																	   . '][content]['
1409
+																	   . $extra_field . ']';
1410
+							$css_class                               = isset($extra_array['css_class'])
1411
+								? $extra_array['css_class']
1412
+								: '';
1413 1413
                             
1414
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1415
-                                && in_array($extra_field, $v_fields, true)
1416
-                                &&
1417
-                                (
1418
-                                    is_array($validators[$extra_field])
1419
-                                    && isset($validators[$extra_field]['msg'])
1420
-                                )
1421
-                                ? 'validate-error ' . $css_class
1422
-                                : $css_class;
1414
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1415
+								&& in_array($extra_field, $v_fields, true)
1416
+								&&
1417
+								(
1418
+									is_array($validators[$extra_field])
1419
+									&& isset($validators[$extra_field]['msg'])
1420
+								)
1421
+								? 'validate-error ' . $css_class
1422
+								: $css_class;
1423 1423
                             
1424
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1425
-                                                                        && isset($content[$extra_field])
1426
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1427
-                                : '';
1424
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1425
+																		&& isset($content[$extra_field])
1426
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1427
+								: '';
1428 1428
                             
1429
-                            //do we have a validation error?  if we do then let's use that value instead
1430
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1431
-                                ? $validators[$extra_field]['value']
1432
-                                : $template_form_fields[$field_id]['value'];
1429
+							//do we have a validation error?  if we do then let's use that value instead
1430
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1431
+								? $validators[$extra_field]['value']
1432
+								: $template_form_fields[$field_id]['value'];
1433 1433
                             
1434 1434
                             
1435
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1435
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1436 1436
                             
1437
-                            //shortcode selector
1438
-                            $field_name_to_use                                 = $extra_field === 'main'
1439
-                                ? 'content'
1440
-                                : $extra_field;
1441
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1442
-                                $field_name_to_use,
1443
-                                $field_id
1444
-                            );
1437
+							//shortcode selector
1438
+							$field_name_to_use                                 = $extra_field === 'main'
1439
+								? 'content'
1440
+								: $extra_field;
1441
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1442
+								$field_name_to_use,
1443
+								$field_id
1444
+							);
1445 1445
                             
1446
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1447
-                                //we want to decode the entities
1448
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1449
-                                    html_entity_decode(
1450
-                                        $template_form_fields[$field_id]['value'],
1451
-                                        ENT_QUOTES,
1452
-                                        "UTF-8")
1453
-                                );
1446
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1447
+								//we want to decode the entities
1448
+								$template_form_fields[$field_id]['value'] = stripslashes(
1449
+									html_entity_decode(
1450
+										$template_form_fields[$field_id]['value'],
1451
+										ENT_QUOTES,
1452
+										"UTF-8")
1453
+								);
1454 1454
                                 
1455
-                            }/**/
1456
-                        }
1457
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1458
-                        $templatefield_templatename_id = $reference_field . '-name';
1455
+							}/**/
1456
+						}
1457
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1458
+						$templatefield_templatename_id = $reference_field . '-name';
1459 1459
                         
1460
-                        $template_form_fields[$templatefield_MTP_id] = array(
1461
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1462
-                            'label'      => null,
1463
-                            'input'      => 'hidden',
1464
-                            'type'       => 'int',
1465
-                            'required'   => false,
1466
-                            'validation' => false,
1467
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1468
-                            'css_class'  => '',
1469
-                            'format'     => '%d',
1470
-                            'db-col'     => 'MTP_ID'
1471
-                        );
1460
+						$template_form_fields[$templatefield_MTP_id] = array(
1461
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1462
+							'label'      => null,
1463
+							'input'      => 'hidden',
1464
+							'type'       => 'int',
1465
+							'required'   => false,
1466
+							'validation' => false,
1467
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1468
+							'css_class'  => '',
1469
+							'format'     => '%d',
1470
+							'db-col'     => 'MTP_ID'
1471
+						);
1472 1472
                         
1473
-                        $template_form_fields[$templatefield_templatename_id] = array(
1474
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1475
-                            'label'      => null,
1476
-                            'input'      => 'hidden',
1477
-                            'type'       => 'string',
1478
-                            'required'   => false,
1479
-                            'validation' => true,
1480
-                            'value'      => $reference_field,
1481
-                            'css_class'  => '',
1482
-                            'format'     => '%s',
1483
-                            'db-col'     => 'MTP_template_field'
1484
-                        );
1485
-                    }
1486
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1487
-                } else {
1488
-                    $field_id                                 = $template_field . '-content';
1489
-                    $template_form_fields[$field_id]          = $field_setup_array;
1490
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1491
-                    $message_template                         = isset($message_templates[$context][$template_field])
1492
-                        ? $message_templates[$context][$template_field]
1493
-                        : null;
1494
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1495
-                                                                && is_array($message_templates[$context])
1496
-                                                                && $message_template instanceof EE_Message_Template
1497
-                        ? $message_template->get('MTP_content')
1498
-                        : '';
1473
+						$template_form_fields[$templatefield_templatename_id] = array(
1474
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1475
+							'label'      => null,
1476
+							'input'      => 'hidden',
1477
+							'type'       => 'string',
1478
+							'required'   => false,
1479
+							'validation' => true,
1480
+							'value'      => $reference_field,
1481
+							'css_class'  => '',
1482
+							'format'     => '%s',
1483
+							'db-col'     => 'MTP_template_field'
1484
+						);
1485
+					}
1486
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1487
+				} else {
1488
+					$field_id                                 = $template_field . '-content';
1489
+					$template_form_fields[$field_id]          = $field_setup_array;
1490
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1491
+					$message_template                         = isset($message_templates[$context][$template_field])
1492
+						? $message_templates[$context][$template_field]
1493
+						: null;
1494
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1495
+																&& is_array($message_templates[$context])
1496
+																&& $message_template instanceof EE_Message_Template
1497
+						? $message_template->get('MTP_content')
1498
+						: '';
1499 1499
                     
1500
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1501
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1502
-                        ? $validators[$template_field]['value']
1503
-                        : $template_form_fields[$field_id]['value'];
1500
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1501
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1502
+						? $validators[$template_field]['value']
1503
+						: $template_form_fields[$field_id]['value'];
1504 1504
                     
1505 1505
                     
1506
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1507
-                    $css_class                                    = isset($field_setup_array['css_class'])
1508
-                        ? $field_setup_array['css_class']
1509
-                        : '';
1510
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1511
-                                                                    && in_array($template_field, $v_fields, true)
1512
-                                                                    && isset($validators[$template_field]['msg'])
1513
-                        ? 'validate-error ' . $css_class
1514
-                        : $css_class;
1506
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1507
+					$css_class                                    = isset($field_setup_array['css_class'])
1508
+						? $field_setup_array['css_class']
1509
+						: '';
1510
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1511
+																	&& in_array($template_field, $v_fields, true)
1512
+																	&& isset($validators[$template_field]['msg'])
1513
+						? 'validate-error ' . $css_class
1514
+						: $css_class;
1515 1515
                     
1516
-                    //shortcode selector
1517
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1518
-                        $template_field, $field_id
1519
-                    );
1520
-                }
1516
+					//shortcode selector
1517
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1518
+						$template_field, $field_id
1519
+					);
1520
+				}
1521 1521
                 
1522
-                //k took care of content field(s) now let's take care of others.
1522
+				//k took care of content field(s) now let's take care of others.
1523 1523
                 
1524
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1525
-                $templatefield_field_templatename_id = $template_field . '-name';
1524
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1525
+				$templatefield_field_templatename_id = $template_field . '-name';
1526 1526
                 
1527
-                //foreach template field there are actually two form fields created
1528
-                $template_form_fields[$templatefield_MTP_id] = array(
1529
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1530
-                    'label'      => null,
1531
-                    'input'      => 'hidden',
1532
-                    'type'       => 'int',
1533
-                    'required'   => false,
1534
-                    'validation' => true,
1535
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1536
-                    'css_class'  => '',
1537
-                    'format'     => '%d',
1538
-                    'db-col'     => 'MTP_ID'
1539
-                );
1527
+				//foreach template field there are actually two form fields created
1528
+				$template_form_fields[$templatefield_MTP_id] = array(
1529
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1530
+					'label'      => null,
1531
+					'input'      => 'hidden',
1532
+					'type'       => 'int',
1533
+					'required'   => false,
1534
+					'validation' => true,
1535
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1536
+					'css_class'  => '',
1537
+					'format'     => '%d',
1538
+					'db-col'     => 'MTP_ID'
1539
+				);
1540 1540
                 
1541
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1542
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1543
-                    'label'      => null,
1544
-                    'input'      => 'hidden',
1545
-                    'type'       => 'string',
1546
-                    'required'   => false,
1547
-                    'validation' => true,
1548
-                    'value'      => $template_field,
1549
-                    'css_class'  => '',
1550
-                    'format'     => '%s',
1551
-                    'db-col'     => 'MTP_template_field'
1552
-                );
1541
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1542
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1543
+					'label'      => null,
1544
+					'input'      => 'hidden',
1545
+					'type'       => 'string',
1546
+					'required'   => false,
1547
+					'validation' => true,
1548
+					'value'      => $template_field,
1549
+					'css_class'  => '',
1550
+					'format'     => '%s',
1551
+					'db-col'     => 'MTP_template_field'
1552
+				);
1553 1553
                 
1554
-            }
1554
+			}
1555 1555
             
1556
-            //add other fields
1557
-            $template_form_fields['ee-msg-current-context'] = array(
1558
-                'name'       => 'MTP_context',
1559
-                'label'      => null,
1560
-                'input'      => 'hidden',
1561
-                'type'       => 'string',
1562
-                'required'   => false,
1563
-                'validation' => true,
1564
-                'value'      => $context,
1565
-                'css_class'  => '',
1566
-                'format'     => '%s',
1567
-                'db-col'     => 'MTP_context'
1568
-            );
1556
+			//add other fields
1557
+			$template_form_fields['ee-msg-current-context'] = array(
1558
+				'name'       => 'MTP_context',
1559
+				'label'      => null,
1560
+				'input'      => 'hidden',
1561
+				'type'       => 'string',
1562
+				'required'   => false,
1563
+				'validation' => true,
1564
+				'value'      => $context,
1565
+				'css_class'  => '',
1566
+				'format'     => '%s',
1567
+				'db-col'     => 'MTP_context'
1568
+			);
1569 1569
             
1570
-            $template_form_fields['ee-msg-grp-id'] = array(
1571
-                'name'       => 'GRP_ID',
1572
-                'label'      => null,
1573
-                'input'      => 'hidden',
1574
-                'type'       => 'int',
1575
-                'required'   => false,
1576
-                'validation' => true,
1577
-                'value'      => $GRP_ID,
1578
-                'css_class'  => '',
1579
-                'format'     => '%d',
1580
-                'db-col'     => 'GRP_ID'
1581
-            );
1570
+			$template_form_fields['ee-msg-grp-id'] = array(
1571
+				'name'       => 'GRP_ID',
1572
+				'label'      => null,
1573
+				'input'      => 'hidden',
1574
+				'type'       => 'int',
1575
+				'required'   => false,
1576
+				'validation' => true,
1577
+				'value'      => $GRP_ID,
1578
+				'css_class'  => '',
1579
+				'format'     => '%d',
1580
+				'db-col'     => 'GRP_ID'
1581
+			);
1582 1582
             
1583
-            $template_form_fields['ee-msg-messenger'] = array(
1584
-                'name'       => 'MTP_messenger',
1585
-                'label'      => null,
1586
-                'input'      => 'hidden',
1587
-                'type'       => 'string',
1588
-                'required'   => false,
1589
-                'validation' => true,
1590
-                'value'      => $message_template_group->messenger(),
1591
-                'css_class'  => '',
1592
-                'format'     => '%s',
1593
-                'db-col'     => 'MTP_messenger'
1594
-            );
1583
+			$template_form_fields['ee-msg-messenger'] = array(
1584
+				'name'       => 'MTP_messenger',
1585
+				'label'      => null,
1586
+				'input'      => 'hidden',
1587
+				'type'       => 'string',
1588
+				'required'   => false,
1589
+				'validation' => true,
1590
+				'value'      => $message_template_group->messenger(),
1591
+				'css_class'  => '',
1592
+				'format'     => '%s',
1593
+				'db-col'     => 'MTP_messenger'
1594
+			);
1595 1595
             
1596
-            $template_form_fields['ee-msg-message-type'] = array(
1597
-                'name'       => 'MTP_message_type',
1598
-                'label'      => null,
1599
-                'input'      => 'hidden',
1600
-                'type'       => 'string',
1601
-                'required'   => false,
1602
-                'validation' => true,
1603
-                'value'      => $message_template_group->message_type(),
1604
-                'css_class'  => '',
1605
-                'format'     => '%s',
1606
-                'db-col'     => 'MTP_message_type'
1607
-            );
1596
+			$template_form_fields['ee-msg-message-type'] = array(
1597
+				'name'       => 'MTP_message_type',
1598
+				'label'      => null,
1599
+				'input'      => 'hidden',
1600
+				'type'       => 'string',
1601
+				'required'   => false,
1602
+				'validation' => true,
1603
+				'value'      => $message_template_group->message_type(),
1604
+				'css_class'  => '',
1605
+				'format'     => '%s',
1606
+				'db-col'     => 'MTP_message_type'
1607
+			);
1608 1608
             
1609
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1610
-                'name'       => 'MTP_is_global',
1611
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1612
-                'input'      => 'hidden',
1613
-                'type'       => 'int',
1614
-                'required'   => false,
1615
-                'validation' => true,
1616
-                'value'      => $message_template_group->get('MTP_is_global'),
1617
-                'css_class'  => '',
1618
-                'format'     => '%d',
1619
-                'db-col'     => 'MTP_is_global'
1620
-            );
1609
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1610
+				'name'       => 'MTP_is_global',
1611
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1612
+				'input'      => 'hidden',
1613
+				'type'       => 'int',
1614
+				'required'   => false,
1615
+				'validation' => true,
1616
+				'value'      => $message_template_group->get('MTP_is_global'),
1617
+				'css_class'  => '',
1618
+				'format'     => '%d',
1619
+				'db-col'     => 'MTP_is_global'
1620
+			);
1621 1621
             
1622
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1623
-                'name'       => 'MTP_is_override',
1624
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1625
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1626
-                'type'       => 'int',
1627
-                'required'   => false,
1628
-                'validation' => true,
1629
-                'value'      => $message_template_group->get('MTP_is_override'),
1630
-                'css_class'  => '',
1631
-                'format'     => '%d',
1632
-                'db-col'     => 'MTP_is_override'
1633
-            );
1622
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1623
+				'name'       => 'MTP_is_override',
1624
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1625
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1626
+				'type'       => 'int',
1627
+				'required'   => false,
1628
+				'validation' => true,
1629
+				'value'      => $message_template_group->get('MTP_is_override'),
1630
+				'css_class'  => '',
1631
+				'format'     => '%d',
1632
+				'db-col'     => 'MTP_is_override'
1633
+			);
1634 1634
             
1635
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1636
-                'name'       => 'MTP_is_active',
1637
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1638
-                'input'      => 'hidden',
1639
-                'type'       => 'int',
1640
-                'required'   => false,
1641
-                'validation' => true,
1642
-                'value'      => $message_template_group->is_active(),
1643
-                'css_class'  => '',
1644
-                'format'     => '%d',
1645
-                'db-col'     => 'MTP_is_active'
1646
-            );
1635
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1636
+				'name'       => 'MTP_is_active',
1637
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1638
+				'input'      => 'hidden',
1639
+				'type'       => 'int',
1640
+				'required'   => false,
1641
+				'validation' => true,
1642
+				'value'      => $message_template_group->is_active(),
1643
+				'css_class'  => '',
1644
+				'format'     => '%d',
1645
+				'db-col'     => 'MTP_is_active'
1646
+			);
1647 1647
             
1648
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1649
-                'name'       => 'MTP_deleted',
1650
-                'label'      => null,
1651
-                'input'      => 'hidden',
1652
-                'type'       => 'int',
1653
-                'required'   => false,
1654
-                'validation' => true,
1655
-                'value'      => $message_template_group->get('MTP_deleted'),
1656
-                'css_class'  => '',
1657
-                'format'     => '%d',
1658
-                'db-col'     => 'MTP_deleted'
1659
-            );
1660
-            $sidebar_form_fields['ee-msg-author']  = array(
1661
-                'name'       => 'MTP_user_id',
1662
-                'label'      => esc_html__('Author', 'event_espresso'),
1663
-                'input'      => 'hidden',
1664
-                'type'       => 'int',
1665
-                'required'   => false,
1666
-                'validation' => false,
1667
-                'value'      => $message_template_group->user(),
1668
-                'format'     => '%d',
1669
-                'db-col'     => 'MTP_user_id'
1670
-            );
1648
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1649
+				'name'       => 'MTP_deleted',
1650
+				'label'      => null,
1651
+				'input'      => 'hidden',
1652
+				'type'       => 'int',
1653
+				'required'   => false,
1654
+				'validation' => true,
1655
+				'value'      => $message_template_group->get('MTP_deleted'),
1656
+				'css_class'  => '',
1657
+				'format'     => '%d',
1658
+				'db-col'     => 'MTP_deleted'
1659
+			);
1660
+			$sidebar_form_fields['ee-msg-author']  = array(
1661
+				'name'       => 'MTP_user_id',
1662
+				'label'      => esc_html__('Author', 'event_espresso'),
1663
+				'input'      => 'hidden',
1664
+				'type'       => 'int',
1665
+				'required'   => false,
1666
+				'validation' => false,
1667
+				'value'      => $message_template_group->user(),
1668
+				'format'     => '%d',
1669
+				'db-col'     => 'MTP_user_id'
1670
+			);
1671 1671
             
1672
-            $sidebar_form_fields['ee-msg-route'] = array(
1673
-                'name'  => 'action',
1674
-                'input' => 'hidden',
1675
-                'type'  => 'string',
1676
-                'value' => $action
1677
-            );
1672
+			$sidebar_form_fields['ee-msg-route'] = array(
1673
+				'name'  => 'action',
1674
+				'input' => 'hidden',
1675
+				'type'  => 'string',
1676
+				'value' => $action
1677
+			);
1678 1678
             
1679
-            $sidebar_form_fields['ee-msg-id']        = array(
1680
-                'name'  => 'id',
1681
-                'input' => 'hidden',
1682
-                'type'  => 'int',
1683
-                'value' => $GRP_ID
1684
-            );
1685
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1686
-                'name'  => $action . '_nonce',
1687
-                'input' => 'hidden',
1688
-                'type'  => 'string',
1689
-                'value' => wp_create_nonce($action . '_nonce')
1690
-            );
1679
+			$sidebar_form_fields['ee-msg-id']        = array(
1680
+				'name'  => 'id',
1681
+				'input' => 'hidden',
1682
+				'type'  => 'int',
1683
+				'value' => $GRP_ID
1684
+			);
1685
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1686
+				'name'  => $action . '_nonce',
1687
+				'input' => 'hidden',
1688
+				'type'  => 'string',
1689
+				'value' => wp_create_nonce($action . '_nonce')
1690
+			);
1691 1691
             
1692
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1693
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1694
-                    'name'  => 'template_switch',
1695
-                    'input' => 'hidden',
1696
-                    'type'  => 'int',
1697
-                    'value' => 1
1698
-                );
1699
-            }
1692
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1693
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1694
+					'name'  => 'template_switch',
1695
+					'input' => 'hidden',
1696
+					'type'  => 'int',
1697
+					'value' => 1
1698
+				);
1699
+			}
1700 1700
             
1701 1701
             
1702
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1703
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1702
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1703
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1704 1704
             
1705 1705
             
1706
-        } //end if ( !empty($template_field_structure) )
1707
-        
1708
-        //set extra content for publish box
1709
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1710
-        $this->_set_publish_post_box_vars(
1711
-            'id',
1712
-            $GRP_ID,
1713
-            false,
1714
-            add_query_arg(
1715
-                array('action' => 'global_mtps'),
1716
-                $this->_admin_base_url
1717
-            )
1718
-        );
1719
-        
1720
-        //add preview button
1721
-        $preview_url    = parent::add_query_args_and_nonce(
1722
-            array(
1723
-                'message_type' => $message_template_group->message_type(),
1724
-                'messenger'    => $message_template_group->messenger(),
1725
-                'context'      => $context,
1726
-                'GRP_ID'       => $GRP_ID,
1727
-                'action'       => 'preview_message'
1728
-            ),
1729
-            $this->_admin_base_url
1730
-        );
1731
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1732
-                          . esc_html__('Preview', 'event_espresso')
1733
-                          . '</a>';
1734
-        
1735
-        
1736
-        //setup context switcher
1737
-        $context_switcher_args = array(
1738
-            'page'    => 'espresso_messages',
1739
-            'action'  => 'edit_message_template',
1740
-            'id'      => $GRP_ID,
1741
-            'context' => $context,
1742
-            'extra'   => $preview_button
1743
-        );
1744
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1745
-        
1746
-        
1747
-        //main box
1748
-        $this->_template_args['template_fields']                         = $template_fields;
1749
-        $this->_template_args['sidebar_box_id']                          = 'details';
1750
-        $this->_template_args['action']                                  = $action;
1751
-        $this->_template_args['context']                                 = $context;
1752
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1753
-        $this->_template_args['learn_more_about_message_templates_link'] =
1754
-            $this->_learn_more_about_message_templates_link();
1755
-        
1756
-        
1757
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1758
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1759
-            $message_template_group,
1760
-            $context,
1761
-            $context_label
1762
-        );
1763
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1764
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1765
-        
1766
-        $this->_template_path = $this->_template_args['GRP_ID']
1767
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1768
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1769
-        
1770
-        //send along EE_Message_Template_Group object for further template use.
1771
-        $this->_template_args['MTP'] = $message_template_group;
1772
-        
1773
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1774
-            $this->_template_path,
1775
-            $this->_template_args,
1776
-            true
1777
-        );
1778
-        
1779
-        
1780
-        //finally, let's set the admin_page title
1781
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1782
-        
1783
-        
1784
-        //we need to take care of setting the shortcodes property for use elsewhere.
1785
-        $this->_set_shortcodes();
1786
-        
1787
-        
1788
-        //final template wrapper
1789
-        $this->display_admin_page_with_sidebar();
1790
-    }
1706
+		} //end if ( !empty($template_field_structure) )
1707
+        
1708
+		//set extra content for publish box
1709
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1710
+		$this->_set_publish_post_box_vars(
1711
+			'id',
1712
+			$GRP_ID,
1713
+			false,
1714
+			add_query_arg(
1715
+				array('action' => 'global_mtps'),
1716
+				$this->_admin_base_url
1717
+			)
1718
+		);
1719
+        
1720
+		//add preview button
1721
+		$preview_url    = parent::add_query_args_and_nonce(
1722
+			array(
1723
+				'message_type' => $message_template_group->message_type(),
1724
+				'messenger'    => $message_template_group->messenger(),
1725
+				'context'      => $context,
1726
+				'GRP_ID'       => $GRP_ID,
1727
+				'action'       => 'preview_message'
1728
+			),
1729
+			$this->_admin_base_url
1730
+		);
1731
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1732
+						  . esc_html__('Preview', 'event_espresso')
1733
+						  . '</a>';
1734
+        
1735
+        
1736
+		//setup context switcher
1737
+		$context_switcher_args = array(
1738
+			'page'    => 'espresso_messages',
1739
+			'action'  => 'edit_message_template',
1740
+			'id'      => $GRP_ID,
1741
+			'context' => $context,
1742
+			'extra'   => $preview_button
1743
+		);
1744
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1745
+        
1746
+        
1747
+		//main box
1748
+		$this->_template_args['template_fields']                         = $template_fields;
1749
+		$this->_template_args['sidebar_box_id']                          = 'details';
1750
+		$this->_template_args['action']                                  = $action;
1751
+		$this->_template_args['context']                                 = $context;
1752
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1753
+		$this->_template_args['learn_more_about_message_templates_link'] =
1754
+			$this->_learn_more_about_message_templates_link();
1755
+        
1756
+        
1757
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1758
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1759
+			$message_template_group,
1760
+			$context,
1761
+			$context_label
1762
+		);
1763
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1764
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1765
+        
1766
+		$this->_template_path = $this->_template_args['GRP_ID']
1767
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1768
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1769
+        
1770
+		//send along EE_Message_Template_Group object for further template use.
1771
+		$this->_template_args['MTP'] = $message_template_group;
1772
+        
1773
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1774
+			$this->_template_path,
1775
+			$this->_template_args,
1776
+			true
1777
+		);
1778
+        
1779
+        
1780
+		//finally, let's set the admin_page title
1781
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1782
+        
1783
+        
1784
+		//we need to take care of setting the shortcodes property for use elsewhere.
1785
+		$this->_set_shortcodes();
1786
+        
1787
+        
1788
+		//final template wrapper
1789
+		$this->display_admin_page_with_sidebar();
1790
+	}
1791 1791
     
1792 1792
     
1793
-    public function filter_tinymce_init($mceInit, $editor_id)
1794
-    {
1795
-        return $mceInit;
1796
-    }
1793
+	public function filter_tinymce_init($mceInit, $editor_id)
1794
+	{
1795
+		return $mceInit;
1796
+	}
1797 1797
     
1798 1798
     
1799
-    public function add_context_switcher()
1800
-    {
1801
-        return $this->_context_switcher;
1802
-    }
1799
+	public function add_context_switcher()
1800
+	{
1801
+		return $this->_context_switcher;
1802
+	}
1803 1803
 
1804 1804
 
1805
-    /**
1806
-     * Adds the activation/deactivation toggle for the message template context.
1807
-     *
1808
-     * @param EE_Message_Template_Group $message_template_group
1809
-     * @param string                    $context
1810
-     * @param string                    $context_label
1811
-     * @return string
1812
-     * @throws DomainException
1813
-     * @throws EE_Error
1814
-     * @throws InvalidIdentifierException
1815
-     */
1816
-    protected function add_active_context_element(
1817
-        EE_Message_Template_Group $message_template_group,
1818
-        $context,
1819
-        $context_label
1820
-    ) {
1821
-        $template_args = array(
1822
-            'context' => $context,
1823
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1824
-            'is_active' => $message_template_group->is_context_active($context),
1825
-            'on_off_action' => $message_template_group->is_context_active($context)
1826
-                ? 'context-off'
1827
-                : 'context-on',
1828
-            'context_label' => str_replace(array('(', ')'), '', $context_label),
1829
-            'message_template_group_id' => $message_template_group->ID()
1830
-        );
1831
-        return EEH_Template::display_template(
1832
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1833
-          $template_args,
1834
-          true
1835
-        );
1836
-    }
1805
+	/**
1806
+	 * Adds the activation/deactivation toggle for the message template context.
1807
+	 *
1808
+	 * @param EE_Message_Template_Group $message_template_group
1809
+	 * @param string                    $context
1810
+	 * @param string                    $context_label
1811
+	 * @return string
1812
+	 * @throws DomainException
1813
+	 * @throws EE_Error
1814
+	 * @throws InvalidIdentifierException
1815
+	 */
1816
+	protected function add_active_context_element(
1817
+		EE_Message_Template_Group $message_template_group,
1818
+		$context,
1819
+		$context_label
1820
+	) {
1821
+		$template_args = array(
1822
+			'context' => $context,
1823
+			'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1824
+			'is_active' => $message_template_group->is_context_active($context),
1825
+			'on_off_action' => $message_template_group->is_context_active($context)
1826
+				? 'context-off'
1827
+				: 'context-on',
1828
+			'context_label' => str_replace(array('(', ')'), '', $context_label),
1829
+			'message_template_group_id' => $message_template_group->ID()
1830
+		);
1831
+		return EEH_Template::display_template(
1832
+		  EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1833
+		  $template_args,
1834
+		  true
1835
+		);
1836
+	}
1837 1837
 
1838 1838
 
1839
-    /**
1840
-     * Ajax callback for `toggle_context_template` ajax action.
1841
-     * Handles toggling the message context on or off.
1842
-     * @throws EE_Error
1843
-     * @throws InvalidArgumentException
1844
-     * @throws InvalidDataTypeException
1845
-     * @throws InvalidIdentifierException
1846
-     * @throws InvalidInterfaceException
1847
-     */
1848
-    public function toggle_context_template()
1849
-    {
1850
-        $success = true;
1851
-        //check for required data
1852
-        if (!isset(
1853
-            $this->_req_data['message_template_group_id'],
1854
-            $this->_req_data['context'],
1855
-            $this->_req_data['status']
1856
-        )) {
1857
-            EE_Error::add_error(
1858
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1859
-                __FILE__,
1860
-                __FUNCTION__,
1861
-                __LINE__
1862
-            );
1863
-            $success = false;
1864
-        }
1839
+	/**
1840
+	 * Ajax callback for `toggle_context_template` ajax action.
1841
+	 * Handles toggling the message context on or off.
1842
+	 * @throws EE_Error
1843
+	 * @throws InvalidArgumentException
1844
+	 * @throws InvalidDataTypeException
1845
+	 * @throws InvalidIdentifierException
1846
+	 * @throws InvalidInterfaceException
1847
+	 */
1848
+	public function toggle_context_template()
1849
+	{
1850
+		$success = true;
1851
+		//check for required data
1852
+		if (!isset(
1853
+			$this->_req_data['message_template_group_id'],
1854
+			$this->_req_data['context'],
1855
+			$this->_req_data['status']
1856
+		)) {
1857
+			EE_Error::add_error(
1858
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1859
+				__FILE__,
1860
+				__FUNCTION__,
1861
+				__LINE__
1862
+			);
1863
+			$success = false;
1864
+		}
1865 1865
 
1866
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1867
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1868
-            : '';
1869
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1870
-        $this->_verify_nonce($nonce, $nonce_ref);
1871
-        $status = $this->_req_data['status'];
1872
-        if ($status !== 'off' && $status !=='on') {
1873
-            EE_Error::add_error(
1874
-                sprintf(
1875
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1876
-                    $this->_req_data['status']
1877
-                ),
1878
-                __FILE__,
1879
-                __FUNCTION__,
1880
-                __LINE__
1881
-            );
1882
-            $success = false;
1883
-        }
1884
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1885
-            $this->_req_data['message_template_group_id']
1886
-        );
1887
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1888
-            EE_Error::add_error(
1889
-                sprintf(
1890
-                    esc_html__(
1891
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1892
-                        'event_espresso'
1893
-                    ),
1894
-                    $this->_req_data['message_template_group_id'],
1895
-                    'EE_Message_Template_Group'
1896
-                ),
1897
-                __FILE__,
1898
-                __FUNCTION__,
1899
-                __LINE__
1900
-            );
1901
-            $success = false;
1902
-        }
1903
-        if ($success) {
1904
-            $success = $status === 'off'
1905
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1906
-                : $message_template_group->activate_context($this->_req_data['context']);
1907
-        }
1908
-        $this->_template_args['success'] = $success;
1909
-        $this->_return_json();
1910
-    }
1866
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1867
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1868
+			: '';
1869
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1870
+		$this->_verify_nonce($nonce, $nonce_ref);
1871
+		$status = $this->_req_data['status'];
1872
+		if ($status !== 'off' && $status !=='on') {
1873
+			EE_Error::add_error(
1874
+				sprintf(
1875
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1876
+					$this->_req_data['status']
1877
+				),
1878
+				__FILE__,
1879
+				__FUNCTION__,
1880
+				__LINE__
1881
+			);
1882
+			$success = false;
1883
+		}
1884
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1885
+			$this->_req_data['message_template_group_id']
1886
+		);
1887
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1888
+			EE_Error::add_error(
1889
+				sprintf(
1890
+					esc_html__(
1891
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1892
+						'event_espresso'
1893
+					),
1894
+					$this->_req_data['message_template_group_id'],
1895
+					'EE_Message_Template_Group'
1896
+				),
1897
+				__FILE__,
1898
+				__FUNCTION__,
1899
+				__LINE__
1900
+			);
1901
+			$success = false;
1902
+		}
1903
+		if ($success) {
1904
+			$success = $status === 'off'
1905
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1906
+				: $message_template_group->activate_context($this->_req_data['context']);
1907
+		}
1908
+		$this->_template_args['success'] = $success;
1909
+		$this->_return_json();
1910
+	}
1911 1911
 
1912 1912
 
1913 1913
     
1914
-    public function _add_form_element_before()
1915
-    {
1916
-        return '<form method="post" action="'
1917
-               . $this->_template_args["edit_message_template_form_url"]
1918
-               . '" id="ee-msg-edit-frm">';
1919
-    }
1914
+	public function _add_form_element_before()
1915
+	{
1916
+		return '<form method="post" action="'
1917
+			   . $this->_template_args["edit_message_template_form_url"]
1918
+			   . '" id="ee-msg-edit-frm">';
1919
+	}
1920 1920
     
1921
-    public function _add_form_element_after()
1922
-    {
1923
-        return '</form>';
1924
-    }
1921
+	public function _add_form_element_after()
1922
+	{
1923
+		return '</form>';
1924
+	}
1925 1925
 
1926 1926
 
1927
-    /**
1928
-     * This executes switching the template pack for a message template.
1929
-     *
1930
-     * @since 4.5.0
1931
-     * @throws EE_Error
1932
-     * @throws InvalidDataTypeException
1933
-     * @throws InvalidInterfaceException
1934
-     * @throws InvalidArgumentException
1935
-     * @throws ReflectionException
1936
-     */
1937
-    public function switch_template_pack()
1938
-    {
1939
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1940
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1941
-        
1942
-        //verify we have needed values.
1943
-        if (empty($GRP_ID) || empty($template_pack)) {
1944
-            $this->_template_args['error'] = true;
1945
-            EE_Error::add_error(
1946
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1947
-                __FILE__,
1948
-                __FUNCTION__,
1949
-                __LINE__
1950
-            );
1951
-        } else {
1952
-            //get template, set the new template_pack and then reset to default
1953
-            /** @type EE_Message_Template_Group $message_template_group */
1954
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1927
+	/**
1928
+	 * This executes switching the template pack for a message template.
1929
+	 *
1930
+	 * @since 4.5.0
1931
+	 * @throws EE_Error
1932
+	 * @throws InvalidDataTypeException
1933
+	 * @throws InvalidInterfaceException
1934
+	 * @throws InvalidArgumentException
1935
+	 * @throws ReflectionException
1936
+	 */
1937
+	public function switch_template_pack()
1938
+	{
1939
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1940
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1941
+        
1942
+		//verify we have needed values.
1943
+		if (empty($GRP_ID) || empty($template_pack)) {
1944
+			$this->_template_args['error'] = true;
1945
+			EE_Error::add_error(
1946
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1947
+				__FILE__,
1948
+				__FUNCTION__,
1949
+				__LINE__
1950
+			);
1951
+		} else {
1952
+			//get template, set the new template_pack and then reset to default
1953
+			/** @type EE_Message_Template_Group $message_template_group */
1954
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1955 1955
             
1956
-            $message_template_group->set_template_pack_name($template_pack);
1957
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1958
-            $this->_req_data['mt']   = $message_template_group->message_type();
1956
+			$message_template_group->set_template_pack_name($template_pack);
1957
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1958
+			$this->_req_data['mt']   = $message_template_group->message_type();
1959 1959
             
1960
-            $query_args = $this->_reset_to_default_template();
1960
+			$query_args = $this->_reset_to_default_template();
1961 1961
             
1962
-            if (empty($query_args['id'])) {
1963
-                EE_Error::add_error(
1964
-                    esc_html__(
1965
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1966
-                        'event_espresso'
1967
-                    ),
1968
-                    __FILE__,
1969
-                    __FUNCTION__,
1970
-                    __LINE__
1971
-                );
1972
-                $this->_template_args['error'] = true;
1973
-            } else {
1974
-                $template_label       = $message_template_group->get_template_pack()->label;
1975
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1976
-                EE_Error::add_success(
1977
-                    sprintf(
1978
-                        esc_html__(
1979
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1980
-                            'event_espresso'
1981
-                        ),
1982
-                        $template_label,
1983
-                        $template_pack_labels->template_pack
1984
-                    )
1985
-                );
1986
-                //generate the redirect url for js.
1987
-                $url                                          = self::add_query_args_and_nonce($query_args,
1988
-                    $this->_admin_base_url);
1989
-                $this->_template_args['data']['redirect_url'] = $url;
1990
-                $this->_template_args['success']              = true;
1991
-            }
1962
+			if (empty($query_args['id'])) {
1963
+				EE_Error::add_error(
1964
+					esc_html__(
1965
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1966
+						'event_espresso'
1967
+					),
1968
+					__FILE__,
1969
+					__FUNCTION__,
1970
+					__LINE__
1971
+				);
1972
+				$this->_template_args['error'] = true;
1973
+			} else {
1974
+				$template_label       = $message_template_group->get_template_pack()->label;
1975
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1976
+				EE_Error::add_success(
1977
+					sprintf(
1978
+						esc_html__(
1979
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1980
+							'event_espresso'
1981
+						),
1982
+						$template_label,
1983
+						$template_pack_labels->template_pack
1984
+					)
1985
+				);
1986
+				//generate the redirect url for js.
1987
+				$url                                          = self::add_query_args_and_nonce($query_args,
1988
+					$this->_admin_base_url);
1989
+				$this->_template_args['data']['redirect_url'] = $url;
1990
+				$this->_template_args['success']              = true;
1991
+			}
1992 1992
             
1993
-            $this->_return_json();
1993
+			$this->_return_json();
1994 1994
             
1995
-        }
1996
-    }
1995
+		}
1996
+	}
1997 1997
 
1998 1998
 
1999
-    /**
2000
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2001
-     * they want.
2002
-     *
2003
-     * @access protected
2004
-     * @return array|null
2005
-     * @throws EE_Error
2006
-     * @throws InvalidArgumentException
2007
-     * @throws InvalidDataTypeException
2008
-     * @throws InvalidInterfaceException
2009
-     */
2010
-    protected function _reset_to_default_template()
2011
-    {
2012
-        
2013
-        $templates = array();
2014
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2015
-        //we need to make sure we've got the info we need.
2016
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2017
-            EE_Error::add_error(
2018
-                esc_html__(
2019
-                    '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.',
2020
-                    'event_espresso'
2021
-                ),
2022
-                __FILE__, __FUNCTION__, __LINE__
2023
-            );
2024
-        }
2025
-        
2026
-        // all templates will be reset to whatever the defaults are
2027
-        // for the global template matching the messenger and message type.
2028
-        $success = ! empty($GRP_ID) ? true : false;
2029
-        
2030
-        if ($success) {
1999
+	/**
2000
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2001
+	 * they want.
2002
+	 *
2003
+	 * @access protected
2004
+	 * @return array|null
2005
+	 * @throws EE_Error
2006
+	 * @throws InvalidArgumentException
2007
+	 * @throws InvalidDataTypeException
2008
+	 * @throws InvalidInterfaceException
2009
+	 */
2010
+	protected function _reset_to_default_template()
2011
+	{
2012
+        
2013
+		$templates = array();
2014
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2015
+		//we need to make sure we've got the info we need.
2016
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2017
+			EE_Error::add_error(
2018
+				esc_html__(
2019
+					'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.',
2020
+					'event_espresso'
2021
+				),
2022
+				__FILE__, __FUNCTION__, __LINE__
2023
+			);
2024
+		}
2025
+        
2026
+		// all templates will be reset to whatever the defaults are
2027
+		// for the global template matching the messenger and message type.
2028
+		$success = ! empty($GRP_ID) ? true : false;
2029
+        
2030
+		if ($success) {
2031 2031
             
2032
-            //let's first determine if the incoming template is a global template,
2033
-            // if it isn't then we need to get the global template matching messenger and message type.
2034
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2032
+			//let's first determine if the incoming template is a global template,
2033
+			// if it isn't then we need to get the global template matching messenger and message type.
2034
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2035 2035
             
2036 2036
             
2037
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2038
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2037
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2038
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2039 2039
             
2040
-            if ($success) {
2041
-                // if successfully deleted, lets generate the new ones.
2042
-                // Note. We set GLOBAL to true, because resets on ANY template
2043
-                // will use the related global template defaults for regeneration.
2044
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2045
-                // HOWEVER, we DO keep the template pack and template variation set
2046
-                // for the current custom template when resetting.
2047
-                $templates = $this->_generate_new_templates(
2048
-                    $this->_req_data['msgr'],
2049
-                    $this->_req_data['mt'],
2050
-                    $GRP_ID,
2051
-                    true
2052
-                );
2053
-            }
2040
+			if ($success) {
2041
+				// if successfully deleted, lets generate the new ones.
2042
+				// Note. We set GLOBAL to true, because resets on ANY template
2043
+				// will use the related global template defaults for regeneration.
2044
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2045
+				// HOWEVER, we DO keep the template pack and template variation set
2046
+				// for the current custom template when resetting.
2047
+				$templates = $this->_generate_new_templates(
2048
+					$this->_req_data['msgr'],
2049
+					$this->_req_data['mt'],
2050
+					$GRP_ID,
2051
+					true
2052
+				);
2053
+			}
2054 2054
             
2055
-        }
2056
-        
2057
-        //any error messages?
2058
-        if ( ! $success) {
2059
-            EE_Error::add_error(
2060
-                esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2061
-                    'event_espresso'),
2062
-                __FILE__, __FUNCTION__, __LINE__
2063
-            );
2064
-        }
2065
-        
2066
-        //all good, let's add a success message!
2067
-        if ($success && ! empty($templates)) {
2068
-            //the info for the template we generated is the first element in the returned array
2069
-            // $templates = $templates[0];
2070
-            EE_Error::overwrite_success();
2071
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2072
-        }
2073
-        
2074
-        
2075
-        $query_args = array(
2076
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2077
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2078
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2079
-        );
2080
-        
2081
-        //if called via ajax then we return query args otherwise redirect
2082
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2083
-            return $query_args;
2084
-        } else {
2085
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2055
+		}
2056
+        
2057
+		//any error messages?
2058
+		if ( ! $success) {
2059
+			EE_Error::add_error(
2060
+				esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2061
+					'event_espresso'),
2062
+				__FILE__, __FUNCTION__, __LINE__
2063
+			);
2064
+		}
2065
+        
2066
+		//all good, let's add a success message!
2067
+		if ($success && ! empty($templates)) {
2068
+			//the info for the template we generated is the first element in the returned array
2069
+			// $templates = $templates[0];
2070
+			EE_Error::overwrite_success();
2071
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2072
+		}
2073
+        
2074
+        
2075
+		$query_args = array(
2076
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2077
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2078
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2079
+		);
2080
+        
2081
+		//if called via ajax then we return query args otherwise redirect
2082
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2083
+			return $query_args;
2084
+		} else {
2085
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2086 2086
 
2087
-            return null;
2088
-        }
2089
-    }
2087
+			return null;
2088
+		}
2089
+	}
2090 2090
 
2091 2091
 
2092
-    /**
2093
-     * Retrieve and set the message preview for display.
2094
-     *
2095
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2096
-     * @return string
2097
-     * @throws EE_Error
2098
-     * @throws InvalidArgumentException
2099
-     * @throws InvalidDataTypeException
2100
-     * @throws InvalidInterfaceException
2101
-     */
2102
-    public function _preview_message($send = false)
2103
-    {
2104
-        //first make sure we've got the necessary parameters
2105
-        if (
2106
-        ! isset(
2107
-            $this->_req_data['message_type'],
2108
-            $this->_req_data['messenger'],
2109
-            $this->_req_data['messenger'],
2110
-            $this->_req_data['GRP_ID']
2111
-        )
2112
-        ) {
2113
-            EE_Error::add_error(
2114
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2115
-                __FILE__, __FUNCTION__, __LINE__
2116
-            );
2117
-        }
2118
-        
2119
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2120
-        
2121
-        
2122
-        //get the preview!
2123
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2124
-            $this->_req_data['messenger'], $send);
2125
-        
2126
-        if ($send) {
2127
-            return $preview;
2128
-        }
2129
-        
2130
-        //let's add a button to go back to the edit view
2131
-        $query_args             = array(
2132
-            'id'      => $this->_req_data['GRP_ID'],
2133
-            'context' => $this->_req_data['context'],
2134
-            'action'  => 'edit_message_template'
2135
-        );
2136
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2137
-        $preview_button         = '<a href="'
2138
-                                  . $go_back_url
2139
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2140
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2141
-                                  . '</a>';
2142
-        $message_types          = $this->get_installed_message_types();
2143
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger(
2144
-                $this->_req_data['messenger']
2145
-        );
2146
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2147
-            ? ucwords($active_messenger->label['singular'])
2148
-            : esc_html__('Unknown Messenger', 'event_espresso');
2149
-        //let's provide a helpful title for context
2150
-        $preview_title = sprintf(
2151
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2152
-            $active_messenger_label,
2153
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2154
-        );
2155
-        //setup display of preview.
2156
-        $this->_admin_page_title                    = $preview_title;
2157
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2158
-        $this->_template_args['data']['force_json'] = true;
2159
-        
2160
-        return '';
2161
-    }
2092
+	/**
2093
+	 * Retrieve and set the message preview for display.
2094
+	 *
2095
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2096
+	 * @return string
2097
+	 * @throws EE_Error
2098
+	 * @throws InvalidArgumentException
2099
+	 * @throws InvalidDataTypeException
2100
+	 * @throws InvalidInterfaceException
2101
+	 */
2102
+	public function _preview_message($send = false)
2103
+	{
2104
+		//first make sure we've got the necessary parameters
2105
+		if (
2106
+		! isset(
2107
+			$this->_req_data['message_type'],
2108
+			$this->_req_data['messenger'],
2109
+			$this->_req_data['messenger'],
2110
+			$this->_req_data['GRP_ID']
2111
+		)
2112
+		) {
2113
+			EE_Error::add_error(
2114
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2115
+				__FILE__, __FUNCTION__, __LINE__
2116
+			);
2117
+		}
2118
+        
2119
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2120
+        
2121
+        
2122
+		//get the preview!
2123
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2124
+			$this->_req_data['messenger'], $send);
2125
+        
2126
+		if ($send) {
2127
+			return $preview;
2128
+		}
2129
+        
2130
+		//let's add a button to go back to the edit view
2131
+		$query_args             = array(
2132
+			'id'      => $this->_req_data['GRP_ID'],
2133
+			'context' => $this->_req_data['context'],
2134
+			'action'  => 'edit_message_template'
2135
+		);
2136
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2137
+		$preview_button         = '<a href="'
2138
+								  . $go_back_url
2139
+								  . '" class="button-secondary messages-preview-go-back-button">'
2140
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2141
+								  . '</a>';
2142
+		$message_types          = $this->get_installed_message_types();
2143
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger(
2144
+				$this->_req_data['messenger']
2145
+		);
2146
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2147
+			? ucwords($active_messenger->label['singular'])
2148
+			: esc_html__('Unknown Messenger', 'event_espresso');
2149
+		//let's provide a helpful title for context
2150
+		$preview_title = sprintf(
2151
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2152
+			$active_messenger_label,
2153
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2154
+		);
2155
+		//setup display of preview.
2156
+		$this->_admin_page_title                    = $preview_title;
2157
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2158
+		$this->_template_args['data']['force_json'] = true;
2159
+        
2160
+		return '';
2161
+	}
2162 2162
     
2163 2163
     
2164
-    /**
2165
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2166
-     * gets called automatically.
2167
-     *
2168
-     * @since 4.5.0
2169
-     *
2170
-     * @return string
2171
-     */
2172
-    protected function _display_preview_message()
2173
-    {
2174
-        $this->display_admin_page_with_no_sidebar();
2175
-    }
2164
+	/**
2165
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2166
+	 * gets called automatically.
2167
+	 *
2168
+	 * @since 4.5.0
2169
+	 *
2170
+	 * @return string
2171
+	 */
2172
+	protected function _display_preview_message()
2173
+	{
2174
+		$this->display_admin_page_with_no_sidebar();
2175
+	}
2176 2176
     
2177 2177
     
2178
-    /**
2179
-     * registers metaboxes that should show up on the "edit_message_template" page
2180
-     *
2181
-     * @access protected
2182
-     * @return void
2183
-     */
2184
-    protected function _register_edit_meta_boxes()
2185
-    {
2186
-        add_meta_box(
2187
-            'mtp_valid_shortcodes',
2188
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2189
-            array($this, 'shortcode_meta_box'),
2190
-            $this->_current_screen->id,
2191
-            'side',
2192
-            'default');
2193
-        add_meta_box(
2194
-            'mtp_extra_actions',
2195
-            esc_html__('Extra Actions', 'event_espresso'),
2196
-            array($this, 'extra_actions_meta_box'),
2197
-            $this->_current_screen->id,
2198
-            'side',
2199
-            'high'
2200
-        );
2201
-        add_meta_box(
2202
-            'mtp_templates',
2203
-            esc_html__('Template Styles', 'event_espresso'),
2204
-            array($this, 'template_pack_meta_box'),
2205
-            $this->_current_screen->id,
2206
-            'side',
2207
-            'high'
2208
-        );
2209
-    }
2178
+	/**
2179
+	 * registers metaboxes that should show up on the "edit_message_template" page
2180
+	 *
2181
+	 * @access protected
2182
+	 * @return void
2183
+	 */
2184
+	protected function _register_edit_meta_boxes()
2185
+	{
2186
+		add_meta_box(
2187
+			'mtp_valid_shortcodes',
2188
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2189
+			array($this, 'shortcode_meta_box'),
2190
+			$this->_current_screen->id,
2191
+			'side',
2192
+			'default');
2193
+		add_meta_box(
2194
+			'mtp_extra_actions',
2195
+			esc_html__('Extra Actions', 'event_espresso'),
2196
+			array($this, 'extra_actions_meta_box'),
2197
+			$this->_current_screen->id,
2198
+			'side',
2199
+			'high'
2200
+		);
2201
+		add_meta_box(
2202
+			'mtp_templates',
2203
+			esc_html__('Template Styles', 'event_espresso'),
2204
+			array($this, 'template_pack_meta_box'),
2205
+			$this->_current_screen->id,
2206
+			'side',
2207
+			'high'
2208
+		);
2209
+	}
2210 2210
 
2211 2211
 
2212
-    /**
2213
-     * metabox content for all template pack and variation selection.
2214
-     *
2215
-     * @since 4.5.0
2216
-     * @return string
2217
-     * @throws DomainException
2218
-     * @throws EE_Error
2219
-     * @throws InvalidArgumentException
2220
-     * @throws ReflectionException
2221
-     * @throws InvalidDataTypeException
2222
-     * @throws InvalidInterfaceException
2223
-     */
2224
-    public function template_pack_meta_box()
2225
-    {
2226
-        $this->_set_message_template_group();
2227
-        
2228
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2229
-        
2230
-        $tp_select_values = array();
2231
-        
2232
-        foreach ($tp_collection as $tp) {
2233
-            //only include template packs that support this messenger and message type!
2234
-            $supports = $tp->get_supports();
2235
-            if (
2236
-                ! isset($supports[$this->_message_template_group->messenger()])
2237
-                || ! in_array(
2238
-                    $this->_message_template_group->message_type(),
2239
-                    $supports[$this->_message_template_group->messenger()],
2240
-                    true
2241
-                )
2242
-            ) {
2243
-                //not supported
2244
-                continue;
2245
-            }
2212
+	/**
2213
+	 * metabox content for all template pack and variation selection.
2214
+	 *
2215
+	 * @since 4.5.0
2216
+	 * @return string
2217
+	 * @throws DomainException
2218
+	 * @throws EE_Error
2219
+	 * @throws InvalidArgumentException
2220
+	 * @throws ReflectionException
2221
+	 * @throws InvalidDataTypeException
2222
+	 * @throws InvalidInterfaceException
2223
+	 */
2224
+	public function template_pack_meta_box()
2225
+	{
2226
+		$this->_set_message_template_group();
2227
+        
2228
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2229
+        
2230
+		$tp_select_values = array();
2231
+        
2232
+		foreach ($tp_collection as $tp) {
2233
+			//only include template packs that support this messenger and message type!
2234
+			$supports = $tp->get_supports();
2235
+			if (
2236
+				! isset($supports[$this->_message_template_group->messenger()])
2237
+				|| ! in_array(
2238
+					$this->_message_template_group->message_type(),
2239
+					$supports[$this->_message_template_group->messenger()],
2240
+					true
2241
+				)
2242
+			) {
2243
+				//not supported
2244
+				continue;
2245
+			}
2246 2246
             
2247
-            $tp_select_values[] = array(
2248
-                'text' => $tp->label,
2249
-                'id'   => $tp->dbref
2250
-            );
2251
-        }
2252
-        
2253
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2254
-        // the default template pack.  This still allows for the odd template pack to override.
2255
-        if (empty($tp_select_values)) {
2256
-            $tp_select_values[] = array(
2257
-                'text' => esc_html__('Default', 'event_espresso'),
2258
-                'id'   => 'default'
2259
-            );
2260
-        }
2261
-        
2262
-        //setup variation select values for the currently selected template.
2263
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2264
-            $this->_message_template_group->messenger(),
2265
-            $this->_message_template_group->message_type()
2266
-        );
2267
-        $variations_select_values = array();
2268
-        foreach ($variations as $variation => $label) {
2269
-            $variations_select_values[] = array(
2270
-                'text' => $label,
2271
-                'id'   => $variation
2272
-            );
2273
-        }
2274
-        
2275
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2276
-        
2277
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2278
-            'MTP_template_pack',
2279
-            $tp_select_values,
2280
-            $this->_message_template_group->get_template_pack_name()
2281
-        );
2282
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2283
-            'MTP_template_variation',
2284
-            $variations_select_values,
2285
-            $this->_message_template_group->get_template_pack_variation()
2286
-        );
2287
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2288
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2289
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2290
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2291
-        
2292
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2293
-        
2294
-        EEH_Template::display_template($template, $template_args);
2295
-    }
2247
+			$tp_select_values[] = array(
2248
+				'text' => $tp->label,
2249
+				'id'   => $tp->dbref
2250
+			);
2251
+		}
2252
+        
2253
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2254
+		// the default template pack.  This still allows for the odd template pack to override.
2255
+		if (empty($tp_select_values)) {
2256
+			$tp_select_values[] = array(
2257
+				'text' => esc_html__('Default', 'event_espresso'),
2258
+				'id'   => 'default'
2259
+			);
2260
+		}
2261
+        
2262
+		//setup variation select values for the currently selected template.
2263
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2264
+			$this->_message_template_group->messenger(),
2265
+			$this->_message_template_group->message_type()
2266
+		);
2267
+		$variations_select_values = array();
2268
+		foreach ($variations as $variation => $label) {
2269
+			$variations_select_values[] = array(
2270
+				'text' => $label,
2271
+				'id'   => $variation
2272
+			);
2273
+		}
2274
+        
2275
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2276
+        
2277
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2278
+			'MTP_template_pack',
2279
+			$tp_select_values,
2280
+			$this->_message_template_group->get_template_pack_name()
2281
+		);
2282
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2283
+			'MTP_template_variation',
2284
+			$variations_select_values,
2285
+			$this->_message_template_group->get_template_pack_variation()
2286
+		);
2287
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2288
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2289
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2290
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2291
+        
2292
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2293
+        
2294
+		EEH_Template::display_template($template, $template_args);
2295
+	}
2296 2296
     
2297 2297
     
2298
-    /**
2299
-     * This meta box holds any extra actions related to Message Templates
2300
-     * For now, this includes Resetting templates to defaults and sending a test email.
2301
-     *
2302
-     * @access  public
2303
-     * @return void
2304
-     * @throws EE_Error
2305
-     */
2306
-    public function extra_actions_meta_box()
2307
-    {
2308
-        $template_form_fields = array();
2309
-        
2310
-        $extra_args = array(
2311
-            'msgr'   => $this->_message_template_group->messenger(),
2312
-            'mt'     => $this->_message_template_group->message_type(),
2313
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2314
-        );
2315
-        //first we need to see if there are any fields
2316
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2317
-        
2318
-        if ( ! empty($fields)) {
2319
-            //yup there be fields
2320
-            foreach ($fields as $field => $config) {
2321
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2322
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2323
-                $default  = isset($config['default']) ? $config['default'] : '';
2324
-                $default  = isset($config['value']) ? $config['value'] : $default;
2298
+	/**
2299
+	 * This meta box holds any extra actions related to Message Templates
2300
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2301
+	 *
2302
+	 * @access  public
2303
+	 * @return void
2304
+	 * @throws EE_Error
2305
+	 */
2306
+	public function extra_actions_meta_box()
2307
+	{
2308
+		$template_form_fields = array();
2309
+        
2310
+		$extra_args = array(
2311
+			'msgr'   => $this->_message_template_group->messenger(),
2312
+			'mt'     => $this->_message_template_group->message_type(),
2313
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2314
+		);
2315
+		//first we need to see if there are any fields
2316
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2317
+        
2318
+		if ( ! empty($fields)) {
2319
+			//yup there be fields
2320
+			foreach ($fields as $field => $config) {
2321
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2322
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2323
+				$default  = isset($config['default']) ? $config['default'] : '';
2324
+				$default  = isset($config['value']) ? $config['value'] : $default;
2325 2325
                 
2326
-                // if type is hidden and the value is empty
2327
-                // something may have gone wrong so let's correct with the defaults
2328
-                $fix              = $config['input'] === 'hidden'
2329
-                                    && isset($existing[$field])
2330
-                                    && empty($existing[$field])
2331
-                    ? $default
2332
-                    : '';
2333
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2334
-                    ? $existing[$field]
2335
-                    : $fix;
2326
+				// if type is hidden and the value is empty
2327
+				// something may have gone wrong so let's correct with the defaults
2328
+				$fix              = $config['input'] === 'hidden'
2329
+									&& isset($existing[$field])
2330
+									&& empty($existing[$field])
2331
+					? $default
2332
+					: '';
2333
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2334
+					? $existing[$field]
2335
+					: $fix;
2336 2336
                 
2337
-                $template_form_fields[$field_id] = array(
2338
-                    'name'       => 'test_settings_fld[' . $field . ']',
2339
-                    'label'      => $config['label'],
2340
-                    'input'      => $config['input'],
2341
-                    'type'       => $config['type'],
2342
-                    'required'   => $config['required'],
2343
-                    'validation' => $config['validation'],
2344
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2345
-                    'css_class'  => $config['css_class'],
2346
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2347
-                    'default'    => $default,
2348
-                    'format'     => $config['format']
2349
-                );
2350
-            }
2351
-        }
2352
-        
2353
-        $test_settings_fields = ! empty($template_form_fields)
2354
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2355
-            : '';
2356
-        
2357
-        $test_settings_html = '';
2358
-        //print out $test_settings_fields
2359
-        if ( ! empty($test_settings_fields)) {
2360
-            echo $test_settings_fields;
2361
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2362
-            $test_settings_html .= 'name="test_button" value="';
2363
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2364
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2365
-        }
2366
-        
2367
-        //and button
2368
-        $test_settings_html .= '<p>'
2369
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2370
-                               . '</p>';
2371
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2372
-        $test_settings_html .= $this->get_action_link_or_button(
2373
-            'reset_to_default',
2374
-            'reset',
2375
-            $extra_args,
2376
-            'button-primary reset-default-button'
2377
-        );
2378
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2379
-        echo $test_settings_html;
2380
-    }
2337
+				$template_form_fields[$field_id] = array(
2338
+					'name'       => 'test_settings_fld[' . $field . ']',
2339
+					'label'      => $config['label'],
2340
+					'input'      => $config['input'],
2341
+					'type'       => $config['type'],
2342
+					'required'   => $config['required'],
2343
+					'validation' => $config['validation'],
2344
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2345
+					'css_class'  => $config['css_class'],
2346
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2347
+					'default'    => $default,
2348
+					'format'     => $config['format']
2349
+				);
2350
+			}
2351
+		}
2352
+        
2353
+		$test_settings_fields = ! empty($template_form_fields)
2354
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2355
+			: '';
2356
+        
2357
+		$test_settings_html = '';
2358
+		//print out $test_settings_fields
2359
+		if ( ! empty($test_settings_fields)) {
2360
+			echo $test_settings_fields;
2361
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2362
+			$test_settings_html .= 'name="test_button" value="';
2363
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2364
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2365
+		}
2366
+        
2367
+		//and button
2368
+		$test_settings_html .= '<p>'
2369
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2370
+							   . '</p>';
2371
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2372
+		$test_settings_html .= $this->get_action_link_or_button(
2373
+			'reset_to_default',
2374
+			'reset',
2375
+			$extra_args,
2376
+			'button-primary reset-default-button'
2377
+		);
2378
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2379
+		echo $test_settings_html;
2380
+	}
2381 2381
 
2382 2382
 
2383
-    /**
2384
-     * This returns the shortcode selector skeleton for a given context and field.
2385
-     *
2386
-     * @since 4.9.rc.000
2387
-     * @param string $field           The name of the field retrieving shortcodes for.
2388
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2389
-     * @return string
2390
-     * @throws DomainException
2391
-     * @throws EE_Error
2392
-     * @throws InvalidArgumentException
2393
-     * @throws ReflectionException
2394
-     * @throws InvalidDataTypeException
2395
-     * @throws InvalidInterfaceException
2396
-     */
2397
-    protected function _get_shortcode_selector($field, $linked_input_id)
2398
-    {
2399
-        $template_args = array(
2400
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2401
-            'fieldname'       => $field,
2402
-            'linked_input_id' => $linked_input_id
2403
-        );
2404
-        
2405
-        return EEH_Template::display_template(
2406
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2407
-            $template_args,
2408
-            true
2409
-        );
2410
-    }
2383
+	/**
2384
+	 * This returns the shortcode selector skeleton for a given context and field.
2385
+	 *
2386
+	 * @since 4.9.rc.000
2387
+	 * @param string $field           The name of the field retrieving shortcodes for.
2388
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2389
+	 * @return string
2390
+	 * @throws DomainException
2391
+	 * @throws EE_Error
2392
+	 * @throws InvalidArgumentException
2393
+	 * @throws ReflectionException
2394
+	 * @throws InvalidDataTypeException
2395
+	 * @throws InvalidInterfaceException
2396
+	 */
2397
+	protected function _get_shortcode_selector($field, $linked_input_id)
2398
+	{
2399
+		$template_args = array(
2400
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2401
+			'fieldname'       => $field,
2402
+			'linked_input_id' => $linked_input_id
2403
+		);
2404
+        
2405
+		return EEH_Template::display_template(
2406
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2407
+			$template_args,
2408
+			true
2409
+		);
2410
+	}
2411 2411
 
2412 2412
 
2413
-    /**
2414
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2415
-     * page)
2416
-     *
2417
-     * @access public
2418
-     * @return void
2419
-     * @throws EE_Error
2420
-     * @throws InvalidArgumentException
2421
-     * @throws ReflectionException
2422
-     * @throws InvalidDataTypeException
2423
-     * @throws InvalidInterfaceException
2424
-     */
2425
-    public function shortcode_meta_box()
2426
-    {
2427
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2428
-        //$messenger = $this->_message_template_group->messenger_obj();
2429
-        //now let's set the content depending on the status of the shortcodes array
2430
-        if (empty($shortcodes)) {
2431
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2432
-            echo $content;
2433
-        } else {
2434
-            //$alt = 0;
2435
-            ?>
2413
+	/**
2414
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2415
+	 * page)
2416
+	 *
2417
+	 * @access public
2418
+	 * @return void
2419
+	 * @throws EE_Error
2420
+	 * @throws InvalidArgumentException
2421
+	 * @throws ReflectionException
2422
+	 * @throws InvalidDataTypeException
2423
+	 * @throws InvalidInterfaceException
2424
+	 */
2425
+	public function shortcode_meta_box()
2426
+	{
2427
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2428
+		//$messenger = $this->_message_template_group->messenger_obj();
2429
+		//now let's set the content depending on the status of the shortcodes array
2430
+		if (empty($shortcodes)) {
2431
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2432
+			echo $content;
2433
+		} else {
2434
+			//$alt = 0;
2435
+			?>
2436 2436
             <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2437 2437
             <p class="small-text"><?php printf(
2438
-                    esc_html__(
2439
-                        'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2440
-                        'event_espresso'
2441
-                    ),
2442
-                    '<span class="dashicons dashicons-menu"></span>'
2443
-                ); ?></p>
2438
+					esc_html__(
2439
+						'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2440
+						'event_espresso'
2441
+					),
2442
+					'<span class="dashicons dashicons-menu"></span>'
2443
+				); ?></p>
2444 2444
             <?php
2445
-        }
2445
+		}
2446 2446
         
2447 2447
         
2448
-    }
2448
+	}
2449 2449
 
2450 2450
 
2451
-    /**
2452
-     * used to set the $_shortcodes property for when its needed elsewhere.
2453
-     *
2454
-     * @access protected
2455
-     * @return void
2456
-     * @throws EE_Error
2457
-     * @throws InvalidArgumentException
2458
-     * @throws ReflectionException
2459
-     * @throws InvalidDataTypeException
2460
-     * @throws InvalidInterfaceException
2461
-     */
2462
-    protected function _set_shortcodes()
2463
-    {
2464
-        
2465
-        //no need to run this if the property is already set
2466
-        if ( ! empty($this->_shortcodes)) {
2467
-            return;
2468
-        }
2469
-        
2470
-        $this->_shortcodes = $this->_get_shortcodes();
2471
-    }
2451
+	/**
2452
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2453
+	 *
2454
+	 * @access protected
2455
+	 * @return void
2456
+	 * @throws EE_Error
2457
+	 * @throws InvalidArgumentException
2458
+	 * @throws ReflectionException
2459
+	 * @throws InvalidDataTypeException
2460
+	 * @throws InvalidInterfaceException
2461
+	 */
2462
+	protected function _set_shortcodes()
2463
+	{
2464
+        
2465
+		//no need to run this if the property is already set
2466
+		if ( ! empty($this->_shortcodes)) {
2467
+			return;
2468
+		}
2469
+        
2470
+		$this->_shortcodes = $this->_get_shortcodes();
2471
+	}
2472 2472
 
2473 2473
 
2474
-    /**
2475
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2476
-     * property)
2477
-     *
2478
-     * @access  protected
2479
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2480
-     *                         for. Defaults to all (for the given context)
2481
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2482
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2483
-     *                         true just an array of shortcode/label pairs.
2484
-     * @throws EE_Error
2485
-     * @throws InvalidArgumentException
2486
-     * @throws ReflectionException
2487
-     * @throws InvalidDataTypeException
2488
-     * @throws InvalidInterfaceException
2489
-     */
2490
-    protected function _get_shortcodes($fields = array(), $merged = true)
2491
-    {
2492
-        $this->_set_message_template_group();
2493
-        
2494
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2495
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2496
-            ? absint($this->_req_data['id'])
2497
-            : false;
2498
-        $context = isset($this->_req_data['context'])
2499
-            ? $this->_req_data['context']
2500
-            : key($this->_message_template_group->contexts_config());
2501
-        
2502
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2503
-    }
2474
+	/**
2475
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2476
+	 * property)
2477
+	 *
2478
+	 * @access  protected
2479
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2480
+	 *                         for. Defaults to all (for the given context)
2481
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2482
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2483
+	 *                         true just an array of shortcode/label pairs.
2484
+	 * @throws EE_Error
2485
+	 * @throws InvalidArgumentException
2486
+	 * @throws ReflectionException
2487
+	 * @throws InvalidDataTypeException
2488
+	 * @throws InvalidInterfaceException
2489
+	 */
2490
+	protected function _get_shortcodes($fields = array(), $merged = true)
2491
+	{
2492
+		$this->_set_message_template_group();
2493
+        
2494
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2495
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2496
+			? absint($this->_req_data['id'])
2497
+			: false;
2498
+		$context = isset($this->_req_data['context'])
2499
+			? $this->_req_data['context']
2500
+			: key($this->_message_template_group->contexts_config());
2501
+        
2502
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2503
+	}
2504 2504
 
2505 2505
 
2506
-    /**
2507
-     * This sets the _message_template property (containing the called message_template object)
2508
-     *
2509
-     * @access protected
2510
-     * @return void
2511
-     * @throws EE_Error
2512
-     * @throws InvalidArgumentException
2513
-     * @throws ReflectionException
2514
-     * @throws InvalidDataTypeException
2515
-     * @throws InvalidInterfaceException
2516
-     */
2517
-    protected function _set_message_template_group()
2518
-    {
2519
-        
2520
-        if ( ! empty($this->_message_template_group)) {
2521
-            return;
2522
-        } //get out if this is already set.
2523
-        
2524
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2525
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2526
-        
2527
-        //let's get the message templates
2528
-        $MTP = EEM_Message_Template_Group::instance();
2529
-        
2530
-        if (empty($GRP_ID)) {
2531
-            $this->_message_template_group = $MTP->create_default_object();
2532
-        } else {
2533
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2534
-        }
2535
-        
2536
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2537
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2538
-        
2539
-    }
2506
+	/**
2507
+	 * This sets the _message_template property (containing the called message_template object)
2508
+	 *
2509
+	 * @access protected
2510
+	 * @return void
2511
+	 * @throws EE_Error
2512
+	 * @throws InvalidArgumentException
2513
+	 * @throws ReflectionException
2514
+	 * @throws InvalidDataTypeException
2515
+	 * @throws InvalidInterfaceException
2516
+	 */
2517
+	protected function _set_message_template_group()
2518
+	{
2519
+        
2520
+		if ( ! empty($this->_message_template_group)) {
2521
+			return;
2522
+		} //get out if this is already set.
2523
+        
2524
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2525
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2526
+        
2527
+		//let's get the message templates
2528
+		$MTP = EEM_Message_Template_Group::instance();
2529
+        
2530
+		if (empty($GRP_ID)) {
2531
+			$this->_message_template_group = $MTP->create_default_object();
2532
+		} else {
2533
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2534
+		}
2535
+        
2536
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2537
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2538
+        
2539
+	}
2540 2540
 
2541 2541
 
2542
-    /**
2543
-     * sets up a context switcher for edit forms
2544
-     *
2545
-     * @access  protected
2546
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2547
-     * @param array                      $args                  various things the context switcher needs.
2548
-     * @throws EE_Error
2549
-     */
2550
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2551
-    {
2552
-        $context_details = $template_group_object->contexts_config();
2553
-        $context_label   = $template_group_object->context_label();
2554
-        ob_start();
2555
-        ?>
2542
+	/**
2543
+	 * sets up a context switcher for edit forms
2544
+	 *
2545
+	 * @access  protected
2546
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2547
+	 * @param array                      $args                  various things the context switcher needs.
2548
+	 * @throws EE_Error
2549
+	 */
2550
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2551
+	{
2552
+		$context_details = $template_group_object->contexts_config();
2553
+		$context_label   = $template_group_object->context_label();
2554
+		ob_start();
2555
+		?>
2556 2556
         <div class="ee-msg-switcher-container">
2557 2557
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2558 2558
                 <?php
2559
-                foreach ($args as $name => $value) {
2560
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2561
-                        continue;
2562
-                    }
2563
-                    ?>
2559
+				foreach ($args as $name => $value) {
2560
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2561
+						continue;
2562
+					}
2563
+					?>
2564 2564
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2565 2565
                     <?php
2566
-                }
2567
-                //setup nonce_url
2568
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2569
-                ?>
2566
+				}
2567
+				//setup nonce_url
2568
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2569
+				?>
2570 2570
                 <select name="context">
2571 2571
                     <?php
2572
-                    $context_templates = $template_group_object->context_templates();
2573
-                    if (is_array($context_templates)) :
2574
-                        foreach ($context_templates as $context => $template_fields) :
2575
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2576
-                            ?>
2572
+					$context_templates = $template_group_object->context_templates();
2573
+					if (is_array($context_templates)) :
2574
+						foreach ($context_templates as $context => $template_fields) :
2575
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2576
+							?>
2577 2577
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2578 2578
                                 <?php echo $context_details[$context]['label']; ?>
2579 2579
                             </option>
@@ -2586,1823 +2586,1823 @@  discard block
 block discarded – undo
2586 2586
             <?php echo $args['extra']; ?>
2587 2587
         </div> <!-- end .ee-msg-switcher-container -->
2588 2588
         <?php
2589
-        $output = ob_get_contents();
2590
-        ob_clean();
2591
-        $this->_context_switcher = $output;
2592
-    }
2589
+		$output = ob_get_contents();
2590
+		ob_clean();
2591
+		$this->_context_switcher = $output;
2592
+	}
2593 2593
     
2594 2594
     
2595
-    /**
2596
-     * utility for sanitizing new values coming in.
2597
-     * Note: this is only used when updating a context.
2598
-     *
2599
-     * @access protected
2600
-     *
2601
-     * @param int $index This helps us know which template field to select from the request array.
2602
-     *
2603
-     * @return array
2604
-     */
2605
-    protected function _set_message_template_column_values($index)
2606
-    {
2607
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2608
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2609
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2610
-            }
2611
-        }
2612
-        
2613
-        
2614
-        $set_column_values = array(
2615
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2616
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2617
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2618
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2619
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2620
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2621
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2622
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2623
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2624
-                ? absint($this->_req_data['MTP_is_global'])
2625
-                : 0,
2626
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2627
-                ? absint($this->_req_data['MTP_is_override'])
2628
-                : 0,
2629
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2630
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2631
-        );
2632
-        
2633
-        
2634
-        return $set_column_values;
2635
-    }
2595
+	/**
2596
+	 * utility for sanitizing new values coming in.
2597
+	 * Note: this is only used when updating a context.
2598
+	 *
2599
+	 * @access protected
2600
+	 *
2601
+	 * @param int $index This helps us know which template field to select from the request array.
2602
+	 *
2603
+	 * @return array
2604
+	 */
2605
+	protected function _set_message_template_column_values($index)
2606
+	{
2607
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2608
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2609
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2610
+			}
2611
+		}
2612
+        
2613
+        
2614
+		$set_column_values = array(
2615
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2616
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2617
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2618
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2619
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2620
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2621
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2622
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2623
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2624
+				? absint($this->_req_data['MTP_is_global'])
2625
+				: 0,
2626
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2627
+				? absint($this->_req_data['MTP_is_override'])
2628
+				: 0,
2629
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2630
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2631
+		);
2632
+        
2633
+        
2634
+		return $set_column_values;
2635
+	}
2636 2636
     
2637 2637
     
2638
-    protected function _insert_or_update_message_template($new = false)
2639
-    {
2640
-        
2641
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2642
-        $success  = 0;
2643
-        $override = false;
2644
-        
2645
-        //setup notices description
2646
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2647
-        
2648
-        //need the message type and messenger objects to be able to use the labels for the notices
2649
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2650
-        $messenger_label  = $messenger_object instanceof EE_messenger
2651
-            ? ucwords($messenger_object->label['singular'])
2652
-            : '';
2653
-        
2654
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2655
-            ? $this->_req_data['MTP_message_type']
2656
-            : '';
2657
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2658
-        
2659
-        $message_type_label = $message_type_object instanceof EE_message_type
2660
-            ? ucwords($message_type_object->label['singular'])
2661
-            : '';
2662
-        
2663
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2664
-            ? $this->_req_data['MTP_context']
2665
-            : '';
2666
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2667
-        
2668
-        $item_desc = $messenger_label && $message_type_label
2669
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2670
-            : '';
2671
-        $item_desc .= 'Message Template';
2672
-        $query_args  = array();
2673
-        $edit_array  = array();
2674
-        $action_desc = '';
2675
-        
2676
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2677
-        // user to edit.
2678
-        if ($new) {
2679
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2680
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2681
-                if (empty($edit_array)) {
2682
-                    $success = 0;
2683
-                } else {
2684
-                    $success    = 1;
2685
-                    $edit_array = $edit_array[0];
2686
-                    $query_args = array(
2687
-                        'id'      => $edit_array['GRP_ID'],
2688
-                        'context' => $edit_array['MTP_context'],
2689
-                        'action'  => 'edit_message_template'
2690
-                    );
2691
-                }
2692
-            }
2693
-            $action_desc = 'created';
2694
-        } else {
2695
-            $MTPG = EEM_Message_Template_Group::instance();
2696
-            $MTP  = EEM_Message_Template::instance();
2638
+	protected function _insert_or_update_message_template($new = false)
2639
+	{
2640
+        
2641
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2642
+		$success  = 0;
2643
+		$override = false;
2644
+        
2645
+		//setup notices description
2646
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2647
+        
2648
+		//need the message type and messenger objects to be able to use the labels for the notices
2649
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2650
+		$messenger_label  = $messenger_object instanceof EE_messenger
2651
+			? ucwords($messenger_object->label['singular'])
2652
+			: '';
2653
+        
2654
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2655
+			? $this->_req_data['MTP_message_type']
2656
+			: '';
2657
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2658
+        
2659
+		$message_type_label = $message_type_object instanceof EE_message_type
2660
+			? ucwords($message_type_object->label['singular'])
2661
+			: '';
2662
+        
2663
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2664
+			? $this->_req_data['MTP_context']
2665
+			: '';
2666
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2667
+        
2668
+		$item_desc = $messenger_label && $message_type_label
2669
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2670
+			: '';
2671
+		$item_desc .= 'Message Template';
2672
+		$query_args  = array();
2673
+		$edit_array  = array();
2674
+		$action_desc = '';
2675
+        
2676
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2677
+		// user to edit.
2678
+		if ($new) {
2679
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2680
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2681
+				if (empty($edit_array)) {
2682
+					$success = 0;
2683
+				} else {
2684
+					$success    = 1;
2685
+					$edit_array = $edit_array[0];
2686
+					$query_args = array(
2687
+						'id'      => $edit_array['GRP_ID'],
2688
+						'context' => $edit_array['MTP_context'],
2689
+						'action'  => 'edit_message_template'
2690
+					);
2691
+				}
2692
+			}
2693
+			$action_desc = 'created';
2694
+		} else {
2695
+			$MTPG = EEM_Message_Template_Group::instance();
2696
+			$MTP  = EEM_Message_Template::instance();
2697 2697
             
2698 2698
             
2699
-            //run update for each template field in displayed context
2700
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2701
-                EE_Error::add_error(
2702
-                    esc_html__(
2703
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2704
-                        'event_espresso'
2705
-                    ),
2706
-                    __FILE__,
2707
-                    __FUNCTION__,
2708
-                    __LINE__
2709
-                );
2710
-                $success = 0;
2699
+			//run update for each template field in displayed context
2700
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2701
+				EE_Error::add_error(
2702
+					esc_html__(
2703
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2704
+						'event_espresso'
2705
+					),
2706
+					__FILE__,
2707
+					__FUNCTION__,
2708
+					__LINE__
2709
+				);
2710
+				$success = 0;
2711 2711
                 
2712
-            } else {
2713
-                //first validate all fields!
2714
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2715
-                    $message_type_slug);
2712
+			} else {
2713
+				//first validate all fields!
2714
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2715
+					$message_type_slug);
2716 2716
                 
2717
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2718
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2719
-                //  WE need to make sure there is no actual error messages in validates.
2720
-                if (is_array($validates) && ! empty($validates)) {
2721
-                    //add the transient so when the form loads we know which fields to highlight
2722
-                    $this->_add_transient('edit_message_template', $validates);
2717
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2718
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2719
+				//  WE need to make sure there is no actual error messages in validates.
2720
+				if (is_array($validates) && ! empty($validates)) {
2721
+					//add the transient so when the form loads we know which fields to highlight
2722
+					$this->_add_transient('edit_message_template', $validates);
2723 2723
                     
2724
-                    $success = 0;
2724
+					$success = 0;
2725 2725
                     
2726
-                    //setup notices
2727
-                    foreach ($validates as $field => $error) {
2728
-                        if (isset($error['msg'])) {
2729
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2730
-                        }
2731
-                    }
2726
+					//setup notices
2727
+					foreach ($validates as $field => $error) {
2728
+						if (isset($error['msg'])) {
2729
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2730
+						}
2731
+					}
2732 2732
                     
2733
-                } else {
2734
-                    $set_column_values = array();
2735
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2736
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2733
+				} else {
2734
+					$set_column_values = array();
2735
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2736
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2737 2737
                         
2738
-                        $where_cols_n_values = array(
2739
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2740
-                        );
2738
+						$where_cols_n_values = array(
2739
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2740
+						);
2741 2741
                         
2742
-                        $message_template_fields = array(
2743
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2744
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2745
-                            'MTP_context'        => $set_column_values['MTP_context'],
2746
-                            'MTP_content'        => $set_column_values['MTP_content']
2747
-                        );
2748
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2749
-                            if ($updated === false) {
2750
-                                EE_Error::add_error(
2751
-                                    sprintf(
2752
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2753
-                                        $template_field
2754
-                                    ),
2755
-                                    __FILE__,
2756
-                                    __FUNCTION__,
2757
-                                    __LINE__
2758
-                                );
2759
-                            } else {
2760
-                                $success = 1;
2761
-                            }
2762
-                        } else {
2763
-                            //only do this logic if we don't have a MTP_ID for this field
2764
-                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2765
-                                //this has already been through the template field validator and sanitized, so it will be
2766
-                                //safe to insert this field.  Why insert?  This typically happens when we introduce a new
2767
-                                //message template field in a messenger/message type and existing users don't have the
2768
-                                //default setup for it.
2769
-                                //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2770
-                                $updated = $MTP->insert($message_template_fields);
2771
-                                if (! $updated || is_wp_error($updated)) {
2772
-                                    EE_Error::add_error(
2773
-                                        sprintf(
2774
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2775
-                                            $template_field
2776
-                                        ),
2777
-                                        __FILE__,
2778
-                                        __FUNCTION__,
2779
-                                        __LINE__
2780
-                                    );
2781
-                                    $success = 0;
2782
-                                } else {
2783
-                                    $success = 1;
2784
-                                }
2785
-                            }
2786
-                        }
2787
-                        $action_desc = 'updated';
2788
-                    }
2742
+						$message_template_fields = array(
2743
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2744
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2745
+							'MTP_context'        => $set_column_values['MTP_context'],
2746
+							'MTP_content'        => $set_column_values['MTP_content']
2747
+						);
2748
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2749
+							if ($updated === false) {
2750
+								EE_Error::add_error(
2751
+									sprintf(
2752
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2753
+										$template_field
2754
+									),
2755
+									__FILE__,
2756
+									__FUNCTION__,
2757
+									__LINE__
2758
+								);
2759
+							} else {
2760
+								$success = 1;
2761
+							}
2762
+						} else {
2763
+							//only do this logic if we don't have a MTP_ID for this field
2764
+							if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2765
+								//this has already been through the template field validator and sanitized, so it will be
2766
+								//safe to insert this field.  Why insert?  This typically happens when we introduce a new
2767
+								//message template field in a messenger/message type and existing users don't have the
2768
+								//default setup for it.
2769
+								//@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2770
+								$updated = $MTP->insert($message_template_fields);
2771
+								if (! $updated || is_wp_error($updated)) {
2772
+									EE_Error::add_error(
2773
+										sprintf(
2774
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2775
+											$template_field
2776
+										),
2777
+										__FILE__,
2778
+										__FUNCTION__,
2779
+										__LINE__
2780
+									);
2781
+									$success = 0;
2782
+								} else {
2783
+									$success = 1;
2784
+								}
2785
+							}
2786
+						}
2787
+						$action_desc = 'updated';
2788
+					}
2789 2789
                     
2790
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2791
-                    $mtpg_fields = array(
2792
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2793
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2794
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2795
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2796
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2797
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2798
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2799
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2800
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2801
-                            : '',
2802
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2803
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2804
-                            : ''
2805
-                    );
2790
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2791
+					$mtpg_fields = array(
2792
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2793
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2794
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2795
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2796
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2797
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2798
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2799
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2800
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2801
+							: '',
2802
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2803
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2804
+							: ''
2805
+					);
2806 2806
                     
2807
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2808
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2807
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2808
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2809 2809
                     
2810
-                    if ($updated === false) {
2811
-                        EE_Error::add_error(
2812
-                            sprintf(
2813
-                                esc_html__(
2814
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2815
-                                    'event_espresso'
2816
-                                ),
2817
-                                $set_column_values['GRP_ID']
2818
-                            ),
2819
-                            __FILE__,
2820
-                            __FUNCTION__,
2821
-                            __LINE__
2822
-                        );
2823
-                    } else {
2824
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2825
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2826
-                            ? $this->_req_data['MTP_template_pack']
2827
-                            : 'default';
2810
+					if ($updated === false) {
2811
+						EE_Error::add_error(
2812
+							sprintf(
2813
+								esc_html__(
2814
+									'The Message Template Group (%d) was NOT updated for some reason',
2815
+									'event_espresso'
2816
+								),
2817
+								$set_column_values['GRP_ID']
2818
+							),
2819
+							__FILE__,
2820
+							__FUNCTION__,
2821
+							__LINE__
2822
+						);
2823
+					} else {
2824
+						//k now we need to ensure the template_pack and template_variation fields are set.
2825
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2826
+							? $this->_req_data['MTP_template_pack']
2827
+							: 'default';
2828 2828
                         
2829
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2830
-                            ? $this->_req_data['MTP_template_variation']
2831
-                            : 'default';
2829
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2830
+							? $this->_req_data['MTP_template_variation']
2831
+							: 'default';
2832 2832
                         
2833
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2834
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2835
-                            $mtpg_obj->set_template_pack_name($template_pack);
2836
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2837
-                        }
2838
-                        $success = 1;
2839
-                    }
2840
-                }
2841
-            }
2833
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2834
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2835
+							$mtpg_obj->set_template_pack_name($template_pack);
2836
+							$mtpg_obj->set_template_pack_variation($template_variation);
2837
+						}
2838
+						$success = 1;
2839
+					}
2840
+				}
2841
+			}
2842 2842
             
2843
-        }
2844
-        
2845
-        //we return things differently if doing ajax
2846
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2847
-            $this->_template_args['success'] = $success;
2848
-            $this->_template_args['error']   = ! $success ? true : false;
2849
-            $this->_template_args['content'] = '';
2850
-            $this->_template_args['data']    = array(
2851
-                'grpID'        => $edit_array['GRP_ID'],
2852
-                'templateName' => $edit_array['template_name']
2853
-            );
2854
-            if ($success) {
2855
-                EE_Error::overwrite_success();
2856
-                EE_Error::add_success(
2857
-                    esc_html__(
2858
-                        '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.',
2859
-                        'event_espresso'
2860
-                    )
2861
-                );
2862
-            }
2843
+		}
2844
+        
2845
+		//we return things differently if doing ajax
2846
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2847
+			$this->_template_args['success'] = $success;
2848
+			$this->_template_args['error']   = ! $success ? true : false;
2849
+			$this->_template_args['content'] = '';
2850
+			$this->_template_args['data']    = array(
2851
+				'grpID'        => $edit_array['GRP_ID'],
2852
+				'templateName' => $edit_array['template_name']
2853
+			);
2854
+			if ($success) {
2855
+				EE_Error::overwrite_success();
2856
+				EE_Error::add_success(
2857
+					esc_html__(
2858
+						'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.',
2859
+						'event_espresso'
2860
+					)
2861
+				);
2862
+			}
2863 2863
             
2864
-            $this->_return_json();
2865
-        }
2866
-        
2867
-        
2868
-        //was a test send triggered?
2869
-        if (isset($this->_req_data['test_button'])) {
2870
-            EE_Error::overwrite_success();
2871
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2872
-            $override = true;
2873
-        }
2874
-        
2875
-        if (empty($query_args)) {
2876
-            $query_args = array(
2877
-                'id'      => $this->_req_data['GRP_ID'],
2878
-                'context' => $context_slug,
2879
-                'action'  => 'edit_message_template'
2880
-            );
2881
-        }
2882
-        
2883
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2884
-    }
2864
+			$this->_return_json();
2865
+		}
2866
+        
2867
+        
2868
+		//was a test send triggered?
2869
+		if (isset($this->_req_data['test_button'])) {
2870
+			EE_Error::overwrite_success();
2871
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2872
+			$override = true;
2873
+		}
2874
+        
2875
+		if (empty($query_args)) {
2876
+			$query_args = array(
2877
+				'id'      => $this->_req_data['GRP_ID'],
2878
+				'context' => $context_slug,
2879
+				'action'  => 'edit_message_template'
2880
+			);
2881
+		}
2882
+        
2883
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2884
+	}
2885 2885
 
2886 2886
 
2887
-    /**
2888
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2889
-     *
2890
-     * @param  string $context      what context being tested
2891
-     * @param  string $messenger    messenger being tested
2892
-     * @param  string $message_type message type being tested
2893
-     * @throws EE_Error
2894
-     * @throws InvalidArgumentException
2895
-     * @throws InvalidDataTypeException
2896
-     * @throws InvalidInterfaceException
2897
-     */
2898
-    protected function _do_test_send($context, $messenger, $message_type)
2899
-    {
2900
-        //set things up for preview
2901
-        $this->_req_data['messenger']    = $messenger;
2902
-        $this->_req_data['message_type'] = $message_type;
2903
-        $this->_req_data['context']      = $context;
2904
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2905
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2906
-        
2907
-        //let's save any existing fields that might be required by the messenger
2908
-        if (
2909
-            isset($this->_req_data['test_settings_fld'])
2910
-            && $active_messenger instanceof EE_messenger
2911
-            && apply_filters(
2912
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2913
-                true,
2914
-                $this->_req_data['test_settings_fld'],
2915
-                $active_messenger
2916
-            )
2917
-        ) {
2918
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2919
-        }
2920
-        
2921
-        $success = $this->_preview_message(true);
2922
-        
2923
-        if ($success) {
2924
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2925
-        } else {
2926
-            EE_Error::add_error(
2927
-                esc_html__('The test message was not sent', 'event_espresso'),
2928
-                __FILE__,
2929
-                __FUNCTION__,
2930
-                __LINE__
2931
-            );
2932
-        }
2933
-    }
2887
+	/**
2888
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2889
+	 *
2890
+	 * @param  string $context      what context being tested
2891
+	 * @param  string $messenger    messenger being tested
2892
+	 * @param  string $message_type message type being tested
2893
+	 * @throws EE_Error
2894
+	 * @throws InvalidArgumentException
2895
+	 * @throws InvalidDataTypeException
2896
+	 * @throws InvalidInterfaceException
2897
+	 */
2898
+	protected function _do_test_send($context, $messenger, $message_type)
2899
+	{
2900
+		//set things up for preview
2901
+		$this->_req_data['messenger']    = $messenger;
2902
+		$this->_req_data['message_type'] = $message_type;
2903
+		$this->_req_data['context']      = $context;
2904
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2905
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2906
+        
2907
+		//let's save any existing fields that might be required by the messenger
2908
+		if (
2909
+			isset($this->_req_data['test_settings_fld'])
2910
+			&& $active_messenger instanceof EE_messenger
2911
+			&& apply_filters(
2912
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2913
+				true,
2914
+				$this->_req_data['test_settings_fld'],
2915
+				$active_messenger
2916
+			)
2917
+		) {
2918
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2919
+		}
2920
+        
2921
+		$success = $this->_preview_message(true);
2922
+        
2923
+		if ($success) {
2924
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2925
+		} else {
2926
+			EE_Error::add_error(
2927
+				esc_html__('The test message was not sent', 'event_espresso'),
2928
+				__FILE__,
2929
+				__FUNCTION__,
2930
+				__LINE__
2931
+			);
2932
+		}
2933
+	}
2934 2934
     
2935 2935
     
2936
-    /**
2937
-     * _generate_new_templates
2938
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2939
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2940
-     * for the event.
2941
-     *
2942
-     *
2943
-     * @param  string $messenger     the messenger we are generating templates for
2944
-     * @param array   $message_types array of message types that the templates are generated for.
2945
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2946
-     *                               indicate the message_template_group being used as the base.
2947
-     *
2948
-     * @param bool    $global
2949
-     *
2950
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2951
-     *                               encountering problems.
2952
-     * @throws EE_Error
2953
-     */
2954
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2955
-    {
2956
-        
2957
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2958
-        // just don't generate any templates.
2959
-        if (empty($message_types)) {
2960
-            return true;
2961
-        }
2962
-        
2963
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2964
-    }
2936
+	/**
2937
+	 * _generate_new_templates
2938
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2939
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2940
+	 * for the event.
2941
+	 *
2942
+	 *
2943
+	 * @param  string $messenger     the messenger we are generating templates for
2944
+	 * @param array   $message_types array of message types that the templates are generated for.
2945
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2946
+	 *                               indicate the message_template_group being used as the base.
2947
+	 *
2948
+	 * @param bool    $global
2949
+	 *
2950
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2951
+	 *                               encountering problems.
2952
+	 * @throws EE_Error
2953
+	 */
2954
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2955
+	{
2956
+        
2957
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2958
+		// just don't generate any templates.
2959
+		if (empty($message_types)) {
2960
+			return true;
2961
+		}
2962
+        
2963
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2964
+	}
2965 2965
 
2966 2966
 
2967
-    /**
2968
-     * [_trash_or_restore_message_template]
2969
-     *
2970
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2971
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2972
-     *                        an individual context (FALSE).
2973
-     * @return void
2974
-     * @throws EE_Error
2975
-     * @throws InvalidArgumentException
2976
-     * @throws InvalidDataTypeException
2977
-     * @throws InvalidInterfaceException
2978
-     */
2979
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2980
-    {
2981
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2982
-        $MTP = EEM_Message_Template_Group::instance();
2983
-        
2984
-        $success = 1;
2985
-        
2986
-        //incoming GRP_IDs
2987
-        if ($all) {
2988
-            //Checkboxes
2989
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2990
-                //if array has more than one element then success message should be plural.
2991
-                //todo: what about nonce?
2992
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2967
+	/**
2968
+	 * [_trash_or_restore_message_template]
2969
+	 *
2970
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2971
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2972
+	 *                        an individual context (FALSE).
2973
+	 * @return void
2974
+	 * @throws EE_Error
2975
+	 * @throws InvalidArgumentException
2976
+	 * @throws InvalidDataTypeException
2977
+	 * @throws InvalidInterfaceException
2978
+	 */
2979
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2980
+	{
2981
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2982
+		$MTP = EEM_Message_Template_Group::instance();
2983
+        
2984
+		$success = 1;
2985
+        
2986
+		//incoming GRP_IDs
2987
+		if ($all) {
2988
+			//Checkboxes
2989
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2990
+				//if array has more than one element then success message should be plural.
2991
+				//todo: what about nonce?
2992
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2993 2993
                 
2994
-                //cycle through checkboxes
2995
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2996
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2997
-                    if ( ! $trashed_or_restored) {
2998
-                        $success = 0;
2999
-                    }
3000
-                }
3001
-            } else {
3002
-                //grab single GRP_ID and handle
3003
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3004
-                if ( ! empty($GRP_ID)) {
3005
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3006
-                    if ( ! $trashed_or_restored) {
3007
-                        $success = 0;
3008
-                    }
3009
-                } else {
3010
-                    $success = 0;
3011
-                }
3012
-            }
2994
+				//cycle through checkboxes
2995
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2996
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2997
+					if ( ! $trashed_or_restored) {
2998
+						$success = 0;
2999
+					}
3000
+				}
3001
+			} else {
3002
+				//grab single GRP_ID and handle
3003
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3004
+				if ( ! empty($GRP_ID)) {
3005
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3006
+					if ( ! $trashed_or_restored) {
3007
+						$success = 0;
3008
+					}
3009
+				} else {
3010
+					$success = 0;
3011
+				}
3012
+			}
3013 3013
             
3014
-        }
3014
+		}
3015 3015
         
3016
-        $action_desc = $trash
3017
-            ? esc_html__('moved to the trash', 'event_espresso')
3018
-            : esc_html__('restored', 'event_espresso');
3016
+		$action_desc = $trash
3017
+			? esc_html__('moved to the trash', 'event_espresso')
3018
+			: esc_html__('restored', 'event_espresso');
3019 3019
         
3020
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3020
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3021 3021
         
3022
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3023
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3022
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3023
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3024 3024
         
3025
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3026
-            'event_espresso') : $item_desc;
3025
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3026
+			'event_espresso') : $item_desc;
3027 3027
         
3028
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3028
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3029 3029
         
3030
-    }
3030
+	}
3031 3031
 
3032 3032
 
3033
-    /**
3034
-     * [_delete_message_template]
3035
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3036
-     *
3037
-     * @return void
3038
-     * @throws EE_Error
3039
-     * @throws InvalidArgumentException
3040
-     * @throws InvalidDataTypeException
3041
-     * @throws InvalidInterfaceException
3042
-     */
3043
-    protected function _delete_message_template()
3044
-    {
3045
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3046
-        
3047
-        //checkboxes
3048
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3049
-            //if array has more than one element then success message should be plural
3050
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3033
+	/**
3034
+	 * [_delete_message_template]
3035
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3036
+	 *
3037
+	 * @return void
3038
+	 * @throws EE_Error
3039
+	 * @throws InvalidArgumentException
3040
+	 * @throws InvalidDataTypeException
3041
+	 * @throws InvalidInterfaceException
3042
+	 */
3043
+	protected function _delete_message_template()
3044
+	{
3045
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3046
+        
3047
+		//checkboxes
3048
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3049
+			//if array has more than one element then success message should be plural
3050
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3051 3051
             
3052
-            //cycle through bulk action checkboxes
3053
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3054
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3055
-            }
3056
-        } else {
3057
-            //grab single grp_id and delete
3058
-            $GRP_ID  = absint($this->_req_data['id']);
3059
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3060
-        }
3061
-        
3062
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3063
-        
3064
-    }
3052
+			//cycle through bulk action checkboxes
3053
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3054
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3055
+			}
3056
+		} else {
3057
+			//grab single grp_id and delete
3058
+			$GRP_ID  = absint($this->_req_data['id']);
3059
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3060
+		}
3061
+        
3062
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3063
+        
3064
+	}
3065 3065
 
3066 3066
 
3067
-    /**
3068
-     * helper for permanently deleting a mtP group and all related message_templates
3069
-     *
3070
-     * @param  int  $GRP_ID        The group being deleted
3071
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3072
-     * @return bool boolean to indicate the success of the deletes or not.
3073
-     * @throws EE_Error
3074
-     * @throws InvalidArgumentException
3075
-     * @throws InvalidDataTypeException
3076
-     * @throws InvalidInterfaceException
3077
-     */
3078
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3079
-    {
3080
-        $success = 1;
3081
-        $MTPG    = EEM_Message_Template_Group::instance();
3082
-        //first let's GET this group
3083
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3084
-        //then delete permanently all the related Message Templates
3085
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3086
-        
3087
-        if ($deleted === 0) {
3088
-            $success = 0;
3089
-        }
3090
-        
3091
-        //now delete permanently this particular group
3092
-        
3093
-        if ($include_group && ! $MTG->delete_permanently()) {
3094
-            $success = 0;
3095
-        }
3096
-        
3097
-        return $success;
3098
-    }
3067
+	/**
3068
+	 * helper for permanently deleting a mtP group and all related message_templates
3069
+	 *
3070
+	 * @param  int  $GRP_ID        The group being deleted
3071
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3072
+	 * @return bool boolean to indicate the success of the deletes or not.
3073
+	 * @throws EE_Error
3074
+	 * @throws InvalidArgumentException
3075
+	 * @throws InvalidDataTypeException
3076
+	 * @throws InvalidInterfaceException
3077
+	 */
3078
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3079
+	{
3080
+		$success = 1;
3081
+		$MTPG    = EEM_Message_Template_Group::instance();
3082
+		//first let's GET this group
3083
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3084
+		//then delete permanently all the related Message Templates
3085
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3086
+        
3087
+		if ($deleted === 0) {
3088
+			$success = 0;
3089
+		}
3090
+        
3091
+		//now delete permanently this particular group
3092
+        
3093
+		if ($include_group && ! $MTG->delete_permanently()) {
3094
+			$success = 0;
3095
+		}
3096
+        
3097
+		return $success;
3098
+	}
3099 3099
     
3100 3100
     
3101
-    /**
3102
-     *    _learn_more_about_message_templates_link
3103
-     * @access protected
3104
-     * @return string
3105
-     */
3106
-    protected function _learn_more_about_message_templates_link()
3107
-    {
3108
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3109
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3110
-               . '</a>';
3111
-    }
3101
+	/**
3102
+	 *    _learn_more_about_message_templates_link
3103
+	 * @access protected
3104
+	 * @return string
3105
+	 */
3106
+	protected function _learn_more_about_message_templates_link()
3107
+	{
3108
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3109
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3110
+			   . '</a>';
3111
+	}
3112 3112
 
3113 3113
 
3114
-    /**
3115
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3116
-     * ajax and other routes.
3117
-     *
3118
-     * @return void
3119
-     * @throws DomainException
3120
-     */
3121
-    protected function _settings()
3122
-    {
3123
-        
3124
-        
3125
-        $this->_set_m_mt_settings();
3126
-        
3127
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3128
-            ? $this->_req_data['selected_messenger']
3129
-            : 'email';
3130
-        
3131
-        //let's setup the messenger tabs
3132
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3133
-            $this->_m_mt_settings['messenger_tabs'],
3134
-            'messenger_links',
3135
-            '|',
3136
-            $selected_messenger
3137
-        );
3138
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3139
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3140
-        
3141
-        $this->display_admin_page_with_sidebar();
3142
-        
3143
-    }
3114
+	/**
3115
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3116
+	 * ajax and other routes.
3117
+	 *
3118
+	 * @return void
3119
+	 * @throws DomainException
3120
+	 */
3121
+	protected function _settings()
3122
+	{
3123
+        
3124
+        
3125
+		$this->_set_m_mt_settings();
3126
+        
3127
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3128
+			? $this->_req_data['selected_messenger']
3129
+			: 'email';
3130
+        
3131
+		//let's setup the messenger tabs
3132
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3133
+			$this->_m_mt_settings['messenger_tabs'],
3134
+			'messenger_links',
3135
+			'|',
3136
+			$selected_messenger
3137
+		);
3138
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3139
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3140
+        
3141
+		$this->display_admin_page_with_sidebar();
3142
+        
3143
+	}
3144 3144
 
3145 3145
 
3146
-    /**
3147
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3148
-     *
3149
-     * @access protected
3150
-     * @return void
3151
-     * @throws DomainException
3152
-     */
3153
-    protected function _set_m_mt_settings()
3154
-    {
3155
-        //first if this is already set then lets get out no need to regenerate data.
3156
-        if ( ! empty($this->_m_mt_settings)) {
3157
-            return;
3158
-        }
3159
-        
3160
-        //get all installed messengers and message_types
3161
-        /** @type EE_messenger[] $messengers */
3162
-        $messengers = $this->_message_resource_manager->installed_messengers();
3163
-        /** @type EE_message_type[] $message_types */
3164
-        $message_types = $this->_message_resource_manager->installed_message_types();
3165
-        
3166
-        
3167
-        //assemble the array for the _tab_text_links helper
3168
-        
3169
-        foreach ($messengers as $messenger) {
3170
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3171
-                'label' => ucwords($messenger->label['singular']),
3172
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3173
-                    ? 'messenger-active'
3174
-                    : '',
3175
-                'href'  => $messenger->name,
3176
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3177
-                'slug'  => $messenger->name,
3178
-                'obj'   => $messenger
3179
-            );
3146
+	/**
3147
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3148
+	 *
3149
+	 * @access protected
3150
+	 * @return void
3151
+	 * @throws DomainException
3152
+	 */
3153
+	protected function _set_m_mt_settings()
3154
+	{
3155
+		//first if this is already set then lets get out no need to regenerate data.
3156
+		if ( ! empty($this->_m_mt_settings)) {
3157
+			return;
3158
+		}
3159
+        
3160
+		//get all installed messengers and message_types
3161
+		/** @type EE_messenger[] $messengers */
3162
+		$messengers = $this->_message_resource_manager->installed_messengers();
3163
+		/** @type EE_message_type[] $message_types */
3164
+		$message_types = $this->_message_resource_manager->installed_message_types();
3165
+        
3166
+        
3167
+		//assemble the array for the _tab_text_links helper
3168
+        
3169
+		foreach ($messengers as $messenger) {
3170
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3171
+				'label' => ucwords($messenger->label['singular']),
3172
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3173
+					? 'messenger-active'
3174
+					: '',
3175
+				'href'  => $messenger->name,
3176
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3177
+				'slug'  => $messenger->name,
3178
+				'obj'   => $messenger
3179
+			);
3180 3180
             
3181 3181
             
3182
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3182
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3183 3183
             
3184
-            foreach ($message_types as $message_type) {
3185
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3186
-                // it shouldn't show in either the inactive OR active metabox.
3187
-                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3188
-                    continue;
3189
-                }
3184
+			foreach ($message_types as $message_type) {
3185
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3186
+				// it shouldn't show in either the inactive OR active metabox.
3187
+				if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3188
+					continue;
3189
+				}
3190 3190
                 
3191
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3192
-                    $messenger->name,
3193
-                    $message_type->name
3194
-                )
3195
-                    ? 'active'
3196
-                    : 'inactive';
3191
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3192
+					$messenger->name,
3193
+					$message_type->name
3194
+				)
3195
+					? 'active'
3196
+					: 'inactive';
3197 3197
                 
3198
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3199
-                    'label'    => ucwords($message_type->label['singular']),
3200
-                    'class'    => 'message-type-' . $a_or_i,
3201
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3202
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3203
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3204
-                    'title'    => $a_or_i === 'active'
3205
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3206
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3207
-                    'content'  => $a_or_i === 'active'
3208
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3209
-                        : $this->_message_type_settings_content($message_type, $messenger),
3210
-                    'slug'     => $message_type->name,
3211
-                    'active'   => $a_or_i === 'active',
3212
-                    'obj'      => $message_type
3213
-                );
3214
-            }
3215
-        }
3216
-    }
3198
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3199
+					'label'    => ucwords($message_type->label['singular']),
3200
+					'class'    => 'message-type-' . $a_or_i,
3201
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3202
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3203
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3204
+					'title'    => $a_or_i === 'active'
3205
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3206
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3207
+					'content'  => $a_or_i === 'active'
3208
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3209
+						: $this->_message_type_settings_content($message_type, $messenger),
3210
+					'slug'     => $message_type->name,
3211
+					'active'   => $a_or_i === 'active',
3212
+					'obj'      => $message_type
3213
+				);
3214
+			}
3215
+		}
3216
+	}
3217 3217
 
3218 3218
 
3219
-    /**
3220
-     * This just prepares the content for the message type settings
3221
-     *
3222
-     * @param  EE_message_type  $message_type The message type object
3223
-     * @param  EE_messenger  $messenger    The messenger object
3224
-     * @param  boolean $active       Whether the message type is active or not
3225
-     * @return string html output for the content
3226
-     * @throws DomainException
3227
-     */
3228
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3229
-    {
3230
-        //get message type fields
3231
-        $fields                                         = $message_type->get_admin_settings_fields();
3232
-        $settings_template_args['template_form_fields'] = '';
3233
-        
3234
-        if ( ! empty($fields) && $active) {
3219
+	/**
3220
+	 * This just prepares the content for the message type settings
3221
+	 *
3222
+	 * @param  EE_message_type  $message_type The message type object
3223
+	 * @param  EE_messenger  $messenger    The messenger object
3224
+	 * @param  boolean $active       Whether the message type is active or not
3225
+	 * @return string html output for the content
3226
+	 * @throws DomainException
3227
+	 */
3228
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3229
+	{
3230
+		//get message type fields
3231
+		$fields                                         = $message_type->get_admin_settings_fields();
3232
+		$settings_template_args['template_form_fields'] = '';
3233
+        
3234
+		if ( ! empty($fields) && $active) {
3235 3235
             
3236
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3236
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3237 3237
             
3238
-            foreach ($fields as $fldname => $fldprops) {
3239
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3240
-                $template_form_field[$field_id] = array(
3241
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3242
-                    'label'      => $fldprops['label'],
3243
-                    'input'      => $fldprops['field_type'],
3244
-                    'type'       => $fldprops['value_type'],
3245
-                    'required'   => $fldprops['required'],
3246
-                    'validation' => $fldprops['validation'],
3247
-                    'value'      => isset($existing_settings[$fldname])
3248
-                        ? $existing_settings[$fldname]
3249
-                        : $fldprops['default'],
3250
-                    'options'    => isset($fldprops['options'])
3251
-                        ? $fldprops['options']
3252
-                        : array(),
3253
-                    'default'    => isset($existing_settings[$fldname])
3254
-                        ? $existing_settings[$fldname]
3255
-                        : $fldprops['default'],
3256
-                    'css_class'  => 'no-drag',
3257
-                    'format'     => $fldprops['format']
3258
-                );
3259
-            }
3238
+			foreach ($fields as $fldname => $fldprops) {
3239
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3240
+				$template_form_field[$field_id] = array(
3241
+					'name'       => 'message_type_settings[' . $fldname . ']',
3242
+					'label'      => $fldprops['label'],
3243
+					'input'      => $fldprops['field_type'],
3244
+					'type'       => $fldprops['value_type'],
3245
+					'required'   => $fldprops['required'],
3246
+					'validation' => $fldprops['validation'],
3247
+					'value'      => isset($existing_settings[$fldname])
3248
+						? $existing_settings[$fldname]
3249
+						: $fldprops['default'],
3250
+					'options'    => isset($fldprops['options'])
3251
+						? $fldprops['options']
3252
+						: array(),
3253
+					'default'    => isset($existing_settings[$fldname])
3254
+						? $existing_settings[$fldname]
3255
+						: $fldprops['default'],
3256
+					'css_class'  => 'no-drag',
3257
+					'format'     => $fldprops['format']
3258
+				);
3259
+			}
3260 3260
             
3261 3261
             
3262
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3263
-                ? $this->_generate_admin_form_fields(
3264
-                    $template_form_field,
3265
-                    'string',
3266
-                    'ee_mt_activate_form'
3267
-                )
3268
-                : '';
3269
-        }
3270
-        
3271
-        $settings_template_args['description'] = $message_type->description;
3272
-        //we also need some hidden fields
3273
-        $settings_template_args['hidden_fields'] = array(
3274
-            'message_type_settings[messenger]'    => array(
3275
-                'type'  => 'hidden',
3276
-                'value' => $messenger->name
3277
-            ),
3278
-            'message_type_settings[message_type]' => array(
3279
-                'type'  => 'hidden',
3280
-                'value' => $message_type->name
3281
-            ),
3282
-            'type'                                => array(
3283
-                'type'  => 'hidden',
3284
-                'value' => 'message_type'
3285
-            )
3286
-        );
3287
-        
3288
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3289
-            $settings_template_args['hidden_fields'],
3290
-            'array'
3291
-        );
3292
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3293
-            ? ' hidden'
3294
-            : '';
3295
-        
3296
-        
3297
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3298
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
3299
-        
3300
-        return $content;
3301
-    }
3262
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3263
+				? $this->_generate_admin_form_fields(
3264
+					$template_form_field,
3265
+					'string',
3266
+					'ee_mt_activate_form'
3267
+				)
3268
+				: '';
3269
+		}
3270
+        
3271
+		$settings_template_args['description'] = $message_type->description;
3272
+		//we also need some hidden fields
3273
+		$settings_template_args['hidden_fields'] = array(
3274
+			'message_type_settings[messenger]'    => array(
3275
+				'type'  => 'hidden',
3276
+				'value' => $messenger->name
3277
+			),
3278
+			'message_type_settings[message_type]' => array(
3279
+				'type'  => 'hidden',
3280
+				'value' => $message_type->name
3281
+			),
3282
+			'type'                                => array(
3283
+				'type'  => 'hidden',
3284
+				'value' => 'message_type'
3285
+			)
3286
+		);
3287
+        
3288
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3289
+			$settings_template_args['hidden_fields'],
3290
+			'array'
3291
+		);
3292
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3293
+			? ' hidden'
3294
+			: '';
3295
+        
3296
+        
3297
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3298
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
3299
+        
3300
+		return $content;
3301
+	}
3302 3302
 
3303 3303
 
3304
-    /**
3305
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3306
-     *
3307
-     * @access protected
3308
-     * @return void
3309
-     * @throws DomainException
3310
-     */
3311
-    protected function _messages_settings_metaboxes()
3312
-    {
3313
-        $this->_set_m_mt_settings();
3314
-        $m_boxes         = $mt_boxes = array();
3315
-        $m_template_args = $mt_template_args = array();
3316
-        
3317
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3318
-            ? $this->_req_data['selected_messenger']
3319
-            : 'email';
3320
-        
3321
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3322
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3323
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3324
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3325
-                //messenger meta boxes
3326
-                $active                                 = $selected_messenger === $messenger;
3327
-                $active_mt_tabs                         = isset(
3328
-                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3329
-                )
3330
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
-                    : '';
3332
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3333
-                    esc_html__('%s Settings', 'event_espresso'),
3334
-                    $tab_array['label']
3335
-                );
3336
-                $m_template_args[$messenger . '_a_box'] = array(
3337
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3338
-                    'inactive_message_types' => isset(
3339
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3340
-                    )
3341
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3342
-                        : '',
3343
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3344
-                    'hidden'                 => $active ? '' : ' hidden',
3345
-                    'hide_on_message'        => $hide_on_message,
3346
-                    'messenger'              => $messenger,
3347
-                    'active'                 => $active
3348
-                );
3349
-                // message type meta boxes
3350
-                // (which is really just the inactive container for each messenger
3351
-                // showing inactive message types for that messenger)
3352
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3353
-                $mt_template_args[$messenger . '_i_box'] = array(
3354
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3355
-                    'inactive_message_types' => isset(
3356
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3357
-                    )
3358
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3359
-                        : '',
3360
-                    'hidden'                 => $active ? '' : ' hidden',
3361
-                    'hide_on_message'        => $hide_on_message,
3362
-                    'hide_off_message'       => $hide_off_message,
3363
-                    'messenger'              => $messenger,
3364
-                    'active'                 => $active
3365
-                );
3366
-            }
3367
-        }
3368
-        
3369
-        
3370
-        //register messenger metaboxes
3371
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3372
-        foreach ($m_boxes as $box => $label) {
3373
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3374
-            $msgr          = str_replace('_a_box', '', $box);
3375
-            add_meta_box(
3376
-                'espresso_' . $msgr . '_settings',
3377
-                $label,
3378
-                function ($post, $metabox) {
3379
-                    echo EEH_Template::display_template(
3380
-                            $metabox["args"]["template_path"],
3381
-                            $metabox["args"]["template_args"],
3382
-                            true
3383
-                    );
3384
-                },
3385
-                $this->_current_screen->id,
3386
-                'normal',
3387
-                'high',
3388
-                $callback_args
3389
-            );
3390
-        }
3391
-        
3392
-        //register message type metaboxes
3393
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3394
-        foreach ($mt_boxes as $box => $label) {
3395
-            $callback_args = array(
3396
-                'template_path' => $mt_template_path,
3397
-                'template_args' => $mt_template_args[$box]
3398
-            );
3399
-            $mt            = str_replace('_i_box', '', $box);
3400
-            add_meta_box(
3401
-                'espresso_' . $mt . '_inactive_mts',
3402
-                $label,
3403
-                function ($post, $metabox) {
3404
-                    echo EEH_Template::display_template(
3405
-                            $metabox["args"]["template_path"],
3406
-                            $metabox["args"]["template_args"],
3407
-                            true
3408
-                    );
3409
-                },
3410
-                $this->_current_screen->id,
3411
-                'side',
3412
-                'high',
3413
-                $callback_args
3414
-            );
3415
-        }
3416
-        
3417
-        //register metabox for global messages settings but only when on the main site.  On single site installs this
3418
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3419
-        if (is_main_site()) {
3420
-            add_meta_box(
3421
-                'espresso_global_message_settings',
3422
-                esc_html__('Global Message Settings', 'event_espresso'),
3423
-                array($this, 'global_messages_settings_metabox_content'),
3424
-                $this->_current_screen->id,
3425
-                'normal',
3426
-                'low',
3427
-                array()
3428
-            );
3429
-        }
3430
-        
3431
-    }
3304
+	/**
3305
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3306
+	 *
3307
+	 * @access protected
3308
+	 * @return void
3309
+	 * @throws DomainException
3310
+	 */
3311
+	protected function _messages_settings_metaboxes()
3312
+	{
3313
+		$this->_set_m_mt_settings();
3314
+		$m_boxes         = $mt_boxes = array();
3315
+		$m_template_args = $mt_template_args = array();
3316
+        
3317
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3318
+			? $this->_req_data['selected_messenger']
3319
+			: 'email';
3320
+        
3321
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3322
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3323
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3324
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3325
+				//messenger meta boxes
3326
+				$active                                 = $selected_messenger === $messenger;
3327
+				$active_mt_tabs                         = isset(
3328
+					$this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3329
+				)
3330
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
+					: '';
3332
+				$m_boxes[$messenger . '_a_box']         = sprintf(
3333
+					esc_html__('%s Settings', 'event_espresso'),
3334
+					$tab_array['label']
3335
+				);
3336
+				$m_template_args[$messenger . '_a_box'] = array(
3337
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3338
+					'inactive_message_types' => isset(
3339
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3340
+					)
3341
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3342
+						: '',
3343
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3344
+					'hidden'                 => $active ? '' : ' hidden',
3345
+					'hide_on_message'        => $hide_on_message,
3346
+					'messenger'              => $messenger,
3347
+					'active'                 => $active
3348
+				);
3349
+				// message type meta boxes
3350
+				// (which is really just the inactive container for each messenger
3351
+				// showing inactive message types for that messenger)
3352
+				$mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3353
+				$mt_template_args[$messenger . '_i_box'] = array(
3354
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3355
+					'inactive_message_types' => isset(
3356
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3357
+					)
3358
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3359
+						: '',
3360
+					'hidden'                 => $active ? '' : ' hidden',
3361
+					'hide_on_message'        => $hide_on_message,
3362
+					'hide_off_message'       => $hide_off_message,
3363
+					'messenger'              => $messenger,
3364
+					'active'                 => $active
3365
+				);
3366
+			}
3367
+		}
3368
+        
3369
+        
3370
+		//register messenger metaboxes
3371
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3372
+		foreach ($m_boxes as $box => $label) {
3373
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3374
+			$msgr          = str_replace('_a_box', '', $box);
3375
+			add_meta_box(
3376
+				'espresso_' . $msgr . '_settings',
3377
+				$label,
3378
+				function ($post, $metabox) {
3379
+					echo EEH_Template::display_template(
3380
+							$metabox["args"]["template_path"],
3381
+							$metabox["args"]["template_args"],
3382
+							true
3383
+					);
3384
+				},
3385
+				$this->_current_screen->id,
3386
+				'normal',
3387
+				'high',
3388
+				$callback_args
3389
+			);
3390
+		}
3391
+        
3392
+		//register message type metaboxes
3393
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3394
+		foreach ($mt_boxes as $box => $label) {
3395
+			$callback_args = array(
3396
+				'template_path' => $mt_template_path,
3397
+				'template_args' => $mt_template_args[$box]
3398
+			);
3399
+			$mt            = str_replace('_i_box', '', $box);
3400
+			add_meta_box(
3401
+				'espresso_' . $mt . '_inactive_mts',
3402
+				$label,
3403
+				function ($post, $metabox) {
3404
+					echo EEH_Template::display_template(
3405
+							$metabox["args"]["template_path"],
3406
+							$metabox["args"]["template_args"],
3407
+							true
3408
+					);
3409
+				},
3410
+				$this->_current_screen->id,
3411
+				'side',
3412
+				'high',
3413
+				$callback_args
3414
+			);
3415
+		}
3416
+        
3417
+		//register metabox for global messages settings but only when on the main site.  On single site installs this
3418
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3419
+		if (is_main_site()) {
3420
+			add_meta_box(
3421
+				'espresso_global_message_settings',
3422
+				esc_html__('Global Message Settings', 'event_espresso'),
3423
+				array($this, 'global_messages_settings_metabox_content'),
3424
+				$this->_current_screen->id,
3425
+				'normal',
3426
+				'low',
3427
+				array()
3428
+			);
3429
+		}
3430
+        
3431
+	}
3432 3432
 
3433 3433
 
3434
-    /**
3435
-     *  This generates the content for the global messages settings metabox.
3436
-     *
3437
-     * @return string
3438
-     * @throws EE_Error
3439
-     * @throws InvalidArgumentException
3440
-     * @throws ReflectionException
3441
-     * @throws InvalidDataTypeException
3442
-     * @throws InvalidInterfaceException
3443
-     */
3444
-    public function global_messages_settings_metabox_content()
3445
-    {
3446
-        $form = $this->_generate_global_settings_form();
3447
-        echo $form->form_open(
3448
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3449
-                'POST'
3450
-            )
3451
-             . $form->get_html()
3452
-             . $form->form_close();
3453
-    }
3434
+	/**
3435
+	 *  This generates the content for the global messages settings metabox.
3436
+	 *
3437
+	 * @return string
3438
+	 * @throws EE_Error
3439
+	 * @throws InvalidArgumentException
3440
+	 * @throws ReflectionException
3441
+	 * @throws InvalidDataTypeException
3442
+	 * @throws InvalidInterfaceException
3443
+	 */
3444
+	public function global_messages_settings_metabox_content()
3445
+	{
3446
+		$form = $this->_generate_global_settings_form();
3447
+		echo $form->form_open(
3448
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3449
+				'POST'
3450
+			)
3451
+			 . $form->get_html()
3452
+			 . $form->form_close();
3453
+	}
3454 3454
 
3455 3455
 
3456
-    /**
3457
-     * This generates and returns the form object for the global messages settings.
3458
-     *
3459
-     * @return EE_Form_Section_Proper
3460
-     * @throws EE_Error
3461
-     * @throws InvalidArgumentException
3462
-     * @throws ReflectionException
3463
-     * @throws InvalidDataTypeException
3464
-     * @throws InvalidInterfaceException
3465
-     */
3466
-    protected function _generate_global_settings_form()
3467
-    {
3468
-        EE_Registry::instance()->load_helper('HTML');
3469
-        /** @var EE_Network_Core_Config $network_config */
3470
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3471
-        
3472
-        return new EE_Form_Section_Proper(
3473
-            array(
3474
-                'name'            => 'global_messages_settings',
3475
-                'html_id'         => 'global_messages_settings',
3476
-                'html_class'      => 'form-table',
3477
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3478
-                'subsections'     => apply_filters(
3479
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3480
-                    array(
3481
-                        'do_messages_on_same_request' => new EE_Select_Input(
3482
-                            array(
3483
-                                true  => esc_html__("On the same request", "event_espresso"),
3484
-                                false => esc_html__("On a separate request", "event_espresso")
3485
-                            ),
3486
-                            array(
3487
-                                'default'         => $network_config->do_messages_on_same_request,
3488
-                                'html_label_text' => esc_html__(
3489
-                                    'Generate and send all messages:',
3490
-                                    'event_espresso'
3491
-                                ),
3492
-                                'html_help_text'  => esc_html__(
3493
-                                    '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.',
3494
-                                    'event_espresso'
3495
-                                ),
3496
-                            )
3497
-                        ),
3498
-                        'delete_threshold' => new EE_Select_Input(
3499
-                            array(
3500
-                                0 => esc_html__('Forever', 'event_espresso'),
3501
-                                3 => esc_html__('3 Months', 'event_espresso'),
3502
-                                6 => esc_html__('6 Months', 'event_espresso'),
3503
-                                9 => esc_html__('9 Months', 'event_espresso'),
3504
-                                12 => esc_html__('12 Months', 'event_espresso'),
3505
-                                24 => esc_html__('24 Months', 'event_espresso'),
3506
-                                36 => esc_html__('36 Months', 'event_espresso')
3507
-                            ),
3508
-                            array(
3509
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3510
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3511
-                                'html_help_text' => esc_html__(
3512
-                                    'You can control how long a record of processed messages is kept via this option.',
3513
-                                    'event_espresso'
3514
-                                ),
3515
-                            )
3516
-                        ),
3517
-                        'update_settings'             => new EE_Submit_Input(
3518
-                            array(
3519
-                                'default'         => esc_html__('Update', 'event_espresso'),
3520
-                                'html_label_text' => '&nbsp'
3521
-                            )
3522
-                        )
3523
-                    )
3524
-                )
3525
-            )
3526
-        );
3527
-    }
3456
+	/**
3457
+	 * This generates and returns the form object for the global messages settings.
3458
+	 *
3459
+	 * @return EE_Form_Section_Proper
3460
+	 * @throws EE_Error
3461
+	 * @throws InvalidArgumentException
3462
+	 * @throws ReflectionException
3463
+	 * @throws InvalidDataTypeException
3464
+	 * @throws InvalidInterfaceException
3465
+	 */
3466
+	protected function _generate_global_settings_form()
3467
+	{
3468
+		EE_Registry::instance()->load_helper('HTML');
3469
+		/** @var EE_Network_Core_Config $network_config */
3470
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3471
+        
3472
+		return new EE_Form_Section_Proper(
3473
+			array(
3474
+				'name'            => 'global_messages_settings',
3475
+				'html_id'         => 'global_messages_settings',
3476
+				'html_class'      => 'form-table',
3477
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3478
+				'subsections'     => apply_filters(
3479
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3480
+					array(
3481
+						'do_messages_on_same_request' => new EE_Select_Input(
3482
+							array(
3483
+								true  => esc_html__("On the same request", "event_espresso"),
3484
+								false => esc_html__("On a separate request", "event_espresso")
3485
+							),
3486
+							array(
3487
+								'default'         => $network_config->do_messages_on_same_request,
3488
+								'html_label_text' => esc_html__(
3489
+									'Generate and send all messages:',
3490
+									'event_espresso'
3491
+								),
3492
+								'html_help_text'  => esc_html__(
3493
+									'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.',
3494
+									'event_espresso'
3495
+								),
3496
+							)
3497
+						),
3498
+						'delete_threshold' => new EE_Select_Input(
3499
+							array(
3500
+								0 => esc_html__('Forever', 'event_espresso'),
3501
+								3 => esc_html__('3 Months', 'event_espresso'),
3502
+								6 => esc_html__('6 Months', 'event_espresso'),
3503
+								9 => esc_html__('9 Months', 'event_espresso'),
3504
+								12 => esc_html__('12 Months', 'event_espresso'),
3505
+								24 => esc_html__('24 Months', 'event_espresso'),
3506
+								36 => esc_html__('36 Months', 'event_espresso')
3507
+							),
3508
+							array(
3509
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3510
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3511
+								'html_help_text' => esc_html__(
3512
+									'You can control how long a record of processed messages is kept via this option.',
3513
+									'event_espresso'
3514
+								),
3515
+							)
3516
+						),
3517
+						'update_settings'             => new EE_Submit_Input(
3518
+							array(
3519
+								'default'         => esc_html__('Update', 'event_espresso'),
3520
+								'html_label_text' => '&nbsp'
3521
+							)
3522
+						)
3523
+					)
3524
+				)
3525
+			)
3526
+		);
3527
+	}
3528 3528
 
3529 3529
 
3530
-    /**
3531
-     * This handles updating the global settings set on the admin page.
3532
-     *
3533
-     * @throws EE_Error
3534
-     * @throws InvalidDataTypeException
3535
-     * @throws InvalidInterfaceException
3536
-     * @throws InvalidArgumentException
3537
-     * @throws ReflectionException
3538
-     */
3539
-    protected function _update_global_settings()
3540
-    {
3541
-        /** @var EE_Network_Core_Config $network_config */
3542
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3543
-        $messages_config = EE_Registry::instance()->CFG->messages;
3544
-        $form           = $this->_generate_global_settings_form();
3545
-        if ($form->was_submitted()) {
3546
-            $form->receive_form_submission();
3547
-            if ($form->is_valid()) {
3548
-                $valid_data = $form->valid_data();
3549
-                foreach ($valid_data as $property => $value) {
3550
-                    $setter = 'set_' . $property;
3551
-                    if (method_exists($network_config, $setter)) {
3552
-                        $network_config->{$setter}($value);
3553
-                    } else if (
3554
-                        property_exists($network_config, $property)
3555
-                        && $network_config->{$property} !== $value
3556
-                    ) {
3557
-                        $network_config->{$property} = $value;
3558
-                    } else if (
3559
-                        property_exists($messages_config, $property)
3560
-                        && $messages_config->{$property} !== $value
3561
-                    ) {
3562
-                        $messages_config->{$property} = $value;
3563
-                    }
3564
-                }
3565
-                //only update if the form submission was valid!
3566
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3567
-                EE_Registry::instance()->CFG->update_espresso_config();
3568
-                EE_Error::overwrite_success();
3569
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3570
-            }
3571
-        }
3572
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3573
-    }
3530
+	/**
3531
+	 * This handles updating the global settings set on the admin page.
3532
+	 *
3533
+	 * @throws EE_Error
3534
+	 * @throws InvalidDataTypeException
3535
+	 * @throws InvalidInterfaceException
3536
+	 * @throws InvalidArgumentException
3537
+	 * @throws ReflectionException
3538
+	 */
3539
+	protected function _update_global_settings()
3540
+	{
3541
+		/** @var EE_Network_Core_Config $network_config */
3542
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3543
+		$messages_config = EE_Registry::instance()->CFG->messages;
3544
+		$form           = $this->_generate_global_settings_form();
3545
+		if ($form->was_submitted()) {
3546
+			$form->receive_form_submission();
3547
+			if ($form->is_valid()) {
3548
+				$valid_data = $form->valid_data();
3549
+				foreach ($valid_data as $property => $value) {
3550
+					$setter = 'set_' . $property;
3551
+					if (method_exists($network_config, $setter)) {
3552
+						$network_config->{$setter}($value);
3553
+					} else if (
3554
+						property_exists($network_config, $property)
3555
+						&& $network_config->{$property} !== $value
3556
+					) {
3557
+						$network_config->{$property} = $value;
3558
+					} else if (
3559
+						property_exists($messages_config, $property)
3560
+						&& $messages_config->{$property} !== $value
3561
+					) {
3562
+						$messages_config->{$property} = $value;
3563
+					}
3564
+				}
3565
+				//only update if the form submission was valid!
3566
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3567
+				EE_Registry::instance()->CFG->update_espresso_config();
3568
+				EE_Error::overwrite_success();
3569
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3570
+			}
3571
+		}
3572
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3573
+	}
3574 3574
 
3575 3575
 
3576
-    /**
3577
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3578
-     *
3579
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3580
-     * @return string html formatted tabs
3581
-     * @throws DomainException
3582
-     */
3583
-    protected function _get_mt_tabs($tab_array)
3584
-    {
3585
-        $tab_array = (array)$tab_array;
3586
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3587
-        $tabs      = '';
3588
-        
3589
-        foreach ($tab_array as $tab) {
3590
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3591
-        }
3592
-        
3593
-        return $tabs;
3594
-    }
3576
+	/**
3577
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3578
+	 *
3579
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3580
+	 * @return string html formatted tabs
3581
+	 * @throws DomainException
3582
+	 */
3583
+	protected function _get_mt_tabs($tab_array)
3584
+	{
3585
+		$tab_array = (array)$tab_array;
3586
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3587
+		$tabs      = '';
3588
+        
3589
+		foreach ($tab_array as $tab) {
3590
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3591
+		}
3592
+        
3593
+		return $tabs;
3594
+	}
3595 3595
 
3596 3596
 
3597
-    /**
3598
-     * This prepares the content of the messenger meta box admin settings
3599
-     *
3600
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3601
-     * @return string html formatted content
3602
-     * @throws DomainException
3603
-     */
3604
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3605
-    {
3597
+	/**
3598
+	 * This prepares the content of the messenger meta box admin settings
3599
+	 *
3600
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3601
+	 * @return string html formatted content
3602
+	 * @throws DomainException
3603
+	 */
3604
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3605
+	{
3606 3606
         
3607
-        $fields                                         = $messenger->get_admin_settings_fields();
3608
-        $settings_template_args['template_form_fields'] = '';
3607
+		$fields                                         = $messenger->get_admin_settings_fields();
3608
+		$settings_template_args['template_form_fields'] = '';
3609 3609
         
3610
-        //is $messenger active?
3611
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3610
+		//is $messenger active?
3611
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3612 3612
         
3613 3613
         
3614
-        if ( ! empty($fields)) {
3614
+		if ( ! empty($fields)) {
3615 3615
             
3616
-            $existing_settings = $messenger->get_existing_admin_settings();
3616
+			$existing_settings = $messenger->get_existing_admin_settings();
3617 3617
             
3618
-            foreach ($fields as $fldname => $fldprops) {
3619
-                $field_id                       = $messenger->name . '-' . $fldname;
3620
-                $template_form_field[$field_id] = array(
3621
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3622
-                    'label'      => $fldprops['label'],
3623
-                    'input'      => $fldprops['field_type'],
3624
-                    'type'       => $fldprops['value_type'],
3625
-                    'required'   => $fldprops['required'],
3626
-                    'validation' => $fldprops['validation'],
3627
-                    'value'      => isset($existing_settings[$field_id])
3628
-                        ? $existing_settings[$field_id]
3629
-                        : $fldprops['default'],
3630
-                    'css_class'  => '',
3631
-                    'format'     => $fldprops['format']
3632
-                );
3633
-            }
3618
+			foreach ($fields as $fldname => $fldprops) {
3619
+				$field_id                       = $messenger->name . '-' . $fldname;
3620
+				$template_form_field[$field_id] = array(
3621
+					'name'       => 'messenger_settings[' . $field_id . ']',
3622
+					'label'      => $fldprops['label'],
3623
+					'input'      => $fldprops['field_type'],
3624
+					'type'       => $fldprops['value_type'],
3625
+					'required'   => $fldprops['required'],
3626
+					'validation' => $fldprops['validation'],
3627
+					'value'      => isset($existing_settings[$field_id])
3628
+						? $existing_settings[$field_id]
3629
+						: $fldprops['default'],
3630
+					'css_class'  => '',
3631
+					'format'     => $fldprops['format']
3632
+				);
3633
+			}
3634 3634
             
3635 3635
             
3636
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3637
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3638
-                : '';
3639
-        }
3640
-        
3641
-        //we also need some hidden fields
3642
-        $settings_template_args['hidden_fields'] = array(
3643
-            'messenger_settings[messenger]' => array(
3644
-                'type'  => 'hidden',
3645
-                'value' => $messenger->name
3646
-            ),
3647
-            'type'                          => array(
3648
-                'type'  => 'hidden',
3649
-                'value' => 'messenger'
3650
-            )
3651
-        );
3652
-        
3653
-        //make sure any active message types that are existing are included in the hidden fields
3654
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3655
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3656
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3657
-                    'type'  => 'hidden',
3658
-                    'value' => $mt
3659
-                );
3660
-            }
3661
-        }
3662
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3663
-            $settings_template_args['hidden_fields'],
3664
-            'array'
3665
-        );
3666
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3667
-        
3668
-        $settings_template_args['messenger']           = $messenger->name;
3669
-        $settings_template_args['description']         = $messenger->description;
3670
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3671
-        
3672
-        
3673
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3674
-            $messenger->name
3675
-        )
3676
-            ? $settings_template_args['show_hide_edit_form']
3677
-            : ' hidden';
3678
-        
3679
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3680
-            ? ' hidden'
3681
-            : $settings_template_args['show_hide_edit_form'];
3682
-        
3683
-        
3684
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3685
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3686
-        $settings_template_args['on_off_status'] = $active ? true : false;
3687
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3688
-        $content                                 = EEH_Template::display_template(
3689
-            $template,
3690
-            $settings_template_args,
3691
-            true
3692
-        );
3693
-        
3694
-        return $content;
3695
-    }
3636
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3637
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3638
+				: '';
3639
+		}
3640
+        
3641
+		//we also need some hidden fields
3642
+		$settings_template_args['hidden_fields'] = array(
3643
+			'messenger_settings[messenger]' => array(
3644
+				'type'  => 'hidden',
3645
+				'value' => $messenger->name
3646
+			),
3647
+			'type'                          => array(
3648
+				'type'  => 'hidden',
3649
+				'value' => 'messenger'
3650
+			)
3651
+		);
3652
+        
3653
+		//make sure any active message types that are existing are included in the hidden fields
3654
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3655
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3656
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3657
+					'type'  => 'hidden',
3658
+					'value' => $mt
3659
+				);
3660
+			}
3661
+		}
3662
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3663
+			$settings_template_args['hidden_fields'],
3664
+			'array'
3665
+		);
3666
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3667
+        
3668
+		$settings_template_args['messenger']           = $messenger->name;
3669
+		$settings_template_args['description']         = $messenger->description;
3670
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3671
+        
3672
+        
3673
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3674
+			$messenger->name
3675
+		)
3676
+			? $settings_template_args['show_hide_edit_form']
3677
+			: ' hidden';
3678
+        
3679
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3680
+			? ' hidden'
3681
+			: $settings_template_args['show_hide_edit_form'];
3682
+        
3683
+        
3684
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3685
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3686
+		$settings_template_args['on_off_status'] = $active ? true : false;
3687
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3688
+		$content                                 = EEH_Template::display_template(
3689
+			$template,
3690
+			$settings_template_args,
3691
+			true
3692
+		);
3693
+        
3694
+		return $content;
3695
+	}
3696 3696
 
3697 3697
 
3698
-    /**
3699
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3700
-     *
3701
-     * @throws DomainException
3702
-     * @throws EE_Error
3703
-     * @throws InvalidDataTypeException
3704
-     * @throws InvalidInterfaceException
3705
-     * @throws InvalidArgumentException
3706
-     * @throws ReflectionException
3707
-     */
3708
-    public function activate_messenger_toggle()
3709
-    {
3710
-        $success = true;
3711
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3712
-        //let's check that we have required data
3713
-        if ( ! isset($this->_req_data['messenger'])) {
3714
-            EE_Error::add_error(
3715
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3716
-                __FILE__,
3717
-                __FUNCTION__,
3718
-                __LINE__
3719
-            );
3720
-            $success = false;
3721
-        }
3722
-        
3723
-        //do a nonce check here since we're not arriving via a normal route
3724
-        $nonce     = isset($this->_req_data['activate_nonce'])
3725
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3726
-            : '';
3727
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3728
-        
3729
-        $this->_verify_nonce($nonce, $nonce_ref);
3730
-        
3731
-        
3732
-        if ( ! isset($this->_req_data['status'])) {
3733
-            EE_Error::add_error(
3734
-                esc_html__(
3735
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3736
-                    'event_espresso'
3737
-                ),
3738
-                __FILE__,
3739
-                __FUNCTION__,
3740
-                __LINE__
3741
-            );
3742
-            $success = false;
3743
-        }
3744
-        
3745
-        //do check to verify we have a valid status.
3746
-        $status = $this->_req_data['status'];
3747
-        
3748
-        if ($status !== 'off' && $status !== 'on') {
3749
-            EE_Error::add_error(
3750
-                sprintf(
3751
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3752
-                    $this->_req_data['status']
3753
-                ),
3754
-                __FILE__,
3755
-                __FUNCTION__,
3756
-                __LINE__
3757
-            );
3758
-            $success = false;
3759
-        }
3760
-        
3761
-        if ($success) {
3762
-            //made it here?  Stop dawdling then!!
3763
-            $success = $status === 'off'
3764
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3765
-                : $this->_activate_messenger($this->_req_data['messenger']);
3766
-        }
3767
-        
3768
-        $this->_template_args['success'] = $success;
3769
-        
3770
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3771
-        $this->_return_json();
3772
-        
3773
-    }
3698
+	/**
3699
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3700
+	 *
3701
+	 * @throws DomainException
3702
+	 * @throws EE_Error
3703
+	 * @throws InvalidDataTypeException
3704
+	 * @throws InvalidInterfaceException
3705
+	 * @throws InvalidArgumentException
3706
+	 * @throws ReflectionException
3707
+	 */
3708
+	public function activate_messenger_toggle()
3709
+	{
3710
+		$success = true;
3711
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3712
+		//let's check that we have required data
3713
+		if ( ! isset($this->_req_data['messenger'])) {
3714
+			EE_Error::add_error(
3715
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3716
+				__FILE__,
3717
+				__FUNCTION__,
3718
+				__LINE__
3719
+			);
3720
+			$success = false;
3721
+		}
3722
+        
3723
+		//do a nonce check here since we're not arriving via a normal route
3724
+		$nonce     = isset($this->_req_data['activate_nonce'])
3725
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3726
+			: '';
3727
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3728
+        
3729
+		$this->_verify_nonce($nonce, $nonce_ref);
3730
+        
3731
+        
3732
+		if ( ! isset($this->_req_data['status'])) {
3733
+			EE_Error::add_error(
3734
+				esc_html__(
3735
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3736
+					'event_espresso'
3737
+				),
3738
+				__FILE__,
3739
+				__FUNCTION__,
3740
+				__LINE__
3741
+			);
3742
+			$success = false;
3743
+		}
3744
+        
3745
+		//do check to verify we have a valid status.
3746
+		$status = $this->_req_data['status'];
3747
+        
3748
+		if ($status !== 'off' && $status !== 'on') {
3749
+			EE_Error::add_error(
3750
+				sprintf(
3751
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3752
+					$this->_req_data['status']
3753
+				),
3754
+				__FILE__,
3755
+				__FUNCTION__,
3756
+				__LINE__
3757
+			);
3758
+			$success = false;
3759
+		}
3760
+        
3761
+		if ($success) {
3762
+			//made it here?  Stop dawdling then!!
3763
+			$success = $status === 'off'
3764
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3765
+				: $this->_activate_messenger($this->_req_data['messenger']);
3766
+		}
3767
+        
3768
+		$this->_template_args['success'] = $success;
3769
+        
3770
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3771
+		$this->_return_json();
3772
+        
3773
+	}
3774 3774
 
3775 3775
 
3776
-    /**
3777
-     * used by ajax from the messages settings page to activate|deactivate a message type
3778
-     *
3779
-     * @throws DomainException
3780
-     * @throws EE_Error
3781
-     * @throws ReflectionException
3782
-     * @throws InvalidDataTypeException
3783
-     * @throws InvalidInterfaceException
3784
-     * @throws InvalidArgumentException
3785
-     */
3786
-    public function activate_mt_toggle()
3787
-    {
3788
-        $success = true;
3789
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3790
-        
3791
-        //let's make sure we have the necessary data
3792
-        if ( ! isset($this->_req_data['message_type'])) {
3793
-            EE_Error::add_error(
3794
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3795
-                __FILE__,
3796
-                __FUNCTION__,
3797
-                __LINE__
3798
-            );
3799
-            $success = false;
3800
-        }
3801
-        
3802
-        if ( ! isset($this->_req_data['messenger'])) {
3803
-            EE_Error::add_error(
3804
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3805
-                __FILE__,
3806
-                __FUNCTION__,
3807
-                __LINE__
3808
-            );
3809
-            $success = false;
3810
-        }
3811
-        
3812
-        if ( ! isset($this->_req_data['status'])) {
3813
-            EE_Error::add_error(
3814
-                esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3815
-                    'event_espresso'),
3816
-                __FILE__,
3817
-                __FUNCTION__,
3818
-                __LINE__
3819
-            );
3820
-            $success = false;
3821
-        }
3822
-        
3823
-        
3824
-        //do check to verify we have a valid status.
3825
-        $status = $this->_req_data['status'];
3826
-        
3827
-        if ($status !== 'activate' && $status !== 'deactivate') {
3828
-            EE_Error::add_error(
3829
-                sprintf(
3830
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3831
-                    $this->_req_data['status']
3832
-                ),
3833
-                __FILE__,
3834
-                __FUNCTION__,
3835
-                __LINE__
3836
-            );
3837
-            $success = false;
3838
-        }
3839
-        
3840
-        
3841
-        //do a nonce check here since we're not arriving via a normal route
3842
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3843
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3844
-        
3845
-        $this->_verify_nonce($nonce, $nonce_ref);
3846
-        
3847
-        if ($success) {
3848
-            //made it here? um, what are you waiting for then?
3849
-            $success = $status === 'deactivate'
3850
-                ? $this->_deactivate_message_type_for_messenger(
3851
-                    $this->_req_data['messenger'],
3852
-                    $this->_req_data['message_type']
3853
-                )
3854
-                : $this->_activate_message_type_for_messenger(
3855
-                    $this->_req_data['messenger'],
3856
-                    $this->_req_data['message_type']
3857
-                );
3858
-        }
3859
-        
3860
-        $this->_template_args['success'] = $success;
3861
-        $this->_return_json();
3862
-    }
3776
+	/**
3777
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3778
+	 *
3779
+	 * @throws DomainException
3780
+	 * @throws EE_Error
3781
+	 * @throws ReflectionException
3782
+	 * @throws InvalidDataTypeException
3783
+	 * @throws InvalidInterfaceException
3784
+	 * @throws InvalidArgumentException
3785
+	 */
3786
+	public function activate_mt_toggle()
3787
+	{
3788
+		$success = true;
3789
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3790
+        
3791
+		//let's make sure we have the necessary data
3792
+		if ( ! isset($this->_req_data['message_type'])) {
3793
+			EE_Error::add_error(
3794
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3795
+				__FILE__,
3796
+				__FUNCTION__,
3797
+				__LINE__
3798
+			);
3799
+			$success = false;
3800
+		}
3801
+        
3802
+		if ( ! isset($this->_req_data['messenger'])) {
3803
+			EE_Error::add_error(
3804
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3805
+				__FILE__,
3806
+				__FUNCTION__,
3807
+				__LINE__
3808
+			);
3809
+			$success = false;
3810
+		}
3811
+        
3812
+		if ( ! isset($this->_req_data['status'])) {
3813
+			EE_Error::add_error(
3814
+				esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3815
+					'event_espresso'),
3816
+				__FILE__,
3817
+				__FUNCTION__,
3818
+				__LINE__
3819
+			);
3820
+			$success = false;
3821
+		}
3822
+        
3823
+        
3824
+		//do check to verify we have a valid status.
3825
+		$status = $this->_req_data['status'];
3826
+        
3827
+		if ($status !== 'activate' && $status !== 'deactivate') {
3828
+			EE_Error::add_error(
3829
+				sprintf(
3830
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3831
+					$this->_req_data['status']
3832
+				),
3833
+				__FILE__,
3834
+				__FUNCTION__,
3835
+				__LINE__
3836
+			);
3837
+			$success = false;
3838
+		}
3839
+        
3840
+        
3841
+		//do a nonce check here since we're not arriving via a normal route
3842
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3843
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3844
+        
3845
+		$this->_verify_nonce($nonce, $nonce_ref);
3846
+        
3847
+		if ($success) {
3848
+			//made it here? um, what are you waiting for then?
3849
+			$success = $status === 'deactivate'
3850
+				? $this->_deactivate_message_type_for_messenger(
3851
+					$this->_req_data['messenger'],
3852
+					$this->_req_data['message_type']
3853
+				)
3854
+				: $this->_activate_message_type_for_messenger(
3855
+					$this->_req_data['messenger'],
3856
+					$this->_req_data['message_type']
3857
+				);
3858
+		}
3859
+        
3860
+		$this->_template_args['success'] = $success;
3861
+		$this->_return_json();
3862
+	}
3863 3863
 
3864 3864
 
3865
-    /**
3866
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3867
-     *
3868
-     * @param string $messenger_name The name of the messenger being activated
3869
-     * @return bool
3870
-     * @throws DomainException
3871
-     * @throws EE_Error
3872
-     * @throws InvalidArgumentException
3873
-     * @throws ReflectionException
3874
-     * @throws InvalidDataTypeException
3875
-     * @throws InvalidInterfaceException
3876
-     */
3877
-    protected function _activate_messenger($messenger_name)
3878
-    {
3879
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3880
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3881
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3882
-            ? $active_messenger->get_default_message_types()
3883
-            : array();
3884
-        
3885
-        //ensure is active
3886
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3887
-        
3888
-        //set response_data for reload
3889
-        foreach ($message_types_to_activate as $message_type_name) {
3890
-            /** @var EE_message_type $message_type */
3891
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3892
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3893
-                    $messenger_name,
3894
-                    $message_type_name
3895
-                )
3896
-                && $message_type instanceof EE_message_type
3897
-            ) {
3898
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3899
-                if ($message_type->get_admin_settings_fields()) {
3900
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3901
-                }
3902
-            }
3903
-        }
3904
-        
3905
-        //add success message for activating messenger
3906
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3907
-        
3908
-    }
3865
+	/**
3866
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3867
+	 *
3868
+	 * @param string $messenger_name The name of the messenger being activated
3869
+	 * @return bool
3870
+	 * @throws DomainException
3871
+	 * @throws EE_Error
3872
+	 * @throws InvalidArgumentException
3873
+	 * @throws ReflectionException
3874
+	 * @throws InvalidDataTypeException
3875
+	 * @throws InvalidInterfaceException
3876
+	 */
3877
+	protected function _activate_messenger($messenger_name)
3878
+	{
3879
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3880
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3881
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3882
+			? $active_messenger->get_default_message_types()
3883
+			: array();
3884
+        
3885
+		//ensure is active
3886
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3887
+        
3888
+		//set response_data for reload
3889
+		foreach ($message_types_to_activate as $message_type_name) {
3890
+			/** @var EE_message_type $message_type */
3891
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3892
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3893
+					$messenger_name,
3894
+					$message_type_name
3895
+				)
3896
+				&& $message_type instanceof EE_message_type
3897
+			) {
3898
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3899
+				if ($message_type->get_admin_settings_fields()) {
3900
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3901
+				}
3902
+			}
3903
+		}
3904
+        
3905
+		//add success message for activating messenger
3906
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3907
+        
3908
+	}
3909 3909
 
3910 3910
 
3911
-    /**
3912
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3913
-     *
3914
-     * @param string $messenger_name The name of the messenger being activated
3915
-     * @return bool
3916
-     * @throws DomainException
3917
-     * @throws EE_Error
3918
-     * @throws InvalidArgumentException
3919
-     * @throws ReflectionException
3920
-     * @throws InvalidDataTypeException
3921
-     * @throws InvalidInterfaceException
3922
-     */
3923
-    protected function _deactivate_messenger($messenger_name)
3924
-    {
3925
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3926
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3927
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3928
-        
3929
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3930
-    }
3911
+	/**
3912
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3913
+	 *
3914
+	 * @param string $messenger_name The name of the messenger being activated
3915
+	 * @return bool
3916
+	 * @throws DomainException
3917
+	 * @throws EE_Error
3918
+	 * @throws InvalidArgumentException
3919
+	 * @throws ReflectionException
3920
+	 * @throws InvalidDataTypeException
3921
+	 * @throws InvalidInterfaceException
3922
+	 */
3923
+	protected function _deactivate_messenger($messenger_name)
3924
+	{
3925
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3926
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3927
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3928
+        
3929
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3930
+	}
3931 3931
 
3932 3932
 
3933
-    /**
3934
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3935
-     *
3936
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3937
-     * @param string $message_type_name The name of the message type being activated for the messenger
3938
-     * @return bool
3939
-     * @throws DomainException
3940
-     * @throws EE_Error
3941
-     * @throws InvalidArgumentException
3942
-     * @throws ReflectionException
3943
-     * @throws InvalidDataTypeException
3944
-     * @throws InvalidInterfaceException
3945
-     */
3946
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3947
-    {
3948
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3949
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3950
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3951
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3952
-        
3953
-        //ensure is active
3954
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3955
-        
3956
-        //set response for load
3957
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3958
-            $message_type_name)
3959
-        ) {
3960
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3961
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3962
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3963
-            }
3964
-        }
3965
-        
3966
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3967
-            $message_type_to_activate);
3968
-    }
3933
+	/**
3934
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3935
+	 *
3936
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3937
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3938
+	 * @return bool
3939
+	 * @throws DomainException
3940
+	 * @throws EE_Error
3941
+	 * @throws InvalidArgumentException
3942
+	 * @throws ReflectionException
3943
+	 * @throws InvalidDataTypeException
3944
+	 * @throws InvalidInterfaceException
3945
+	 */
3946
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3947
+	{
3948
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3949
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3950
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3951
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3952
+        
3953
+		//ensure is active
3954
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3955
+        
3956
+		//set response for load
3957
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3958
+			$message_type_name)
3959
+		) {
3960
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3961
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3962
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3963
+			}
3964
+		}
3965
+        
3966
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3967
+			$message_type_to_activate);
3968
+	}
3969 3969
 
3970 3970
 
3971
-    /**
3972
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3973
-     *
3974
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3975
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3976
-     * @return bool
3977
-     * @throws DomainException
3978
-     * @throws EE_Error
3979
-     * @throws InvalidArgumentException
3980
-     * @throws ReflectionException
3981
-     * @throws InvalidDataTypeException
3982
-     * @throws InvalidInterfaceException
3983
-     */
3984
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3985
-    {
3986
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3987
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3988
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3989
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3990
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3991
-        
3992
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3993
-            $message_type_to_deactivate);
3994
-    }
3971
+	/**
3972
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3973
+	 *
3974
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3975
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3976
+	 * @return bool
3977
+	 * @throws DomainException
3978
+	 * @throws EE_Error
3979
+	 * @throws InvalidArgumentException
3980
+	 * @throws ReflectionException
3981
+	 * @throws InvalidDataTypeException
3982
+	 * @throws InvalidInterfaceException
3983
+	 */
3984
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3985
+	{
3986
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3987
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3988
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3989
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3990
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3991
+        
3992
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3993
+			$message_type_to_deactivate);
3994
+	}
3995 3995
     
3996 3996
     
3997
-    /**
3998
-     * This just initializes the defaults for activating messenger and message type responses.
3999
-     */
4000
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4001
-    {
4002
-        $this->_template_args['data']['active_mts'] = array();
4003
-        $this->_template_args['data']['mt_reload']  = array();
4004
-    }
3997
+	/**
3998
+	 * This just initializes the defaults for activating messenger and message type responses.
3999
+	 */
4000
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4001
+	{
4002
+		$this->_template_args['data']['active_mts'] = array();
4003
+		$this->_template_args['data']['mt_reload']  = array();
4004
+	}
4005 4005
 
4006 4006
 
4007
-    /**
4008
-     * Setup appropriate response for activating a messenger and/or message types
4009
-     *
4010
-     * @param EE_messenger         $messenger
4011
-     * @param EE_message_type|null $message_type
4012
-     * @return bool
4013
-     * @throws DomainException
4014
-     * @throws EE_Error
4015
-     * @throws InvalidArgumentException
4016
-     * @throws ReflectionException
4017
-     * @throws InvalidDataTypeException
4018
-     * @throws InvalidInterfaceException
4019
-     */
4020
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4021
-        $messenger,
4022
-        EE_Message_Type $message_type = null
4023
-    ) {
4024
-        //if $messenger isn't a valid messenger object then get out.
4025
-        if ( ! $messenger instanceof EE_Messenger) {
4026
-            EE_Error::add_error(
4027
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4028
-                __FILE__,
4029
-                __FUNCTION__,
4030
-                __LINE__
4031
-            );
4007
+	/**
4008
+	 * Setup appropriate response for activating a messenger and/or message types
4009
+	 *
4010
+	 * @param EE_messenger         $messenger
4011
+	 * @param EE_message_type|null $message_type
4012
+	 * @return bool
4013
+	 * @throws DomainException
4014
+	 * @throws EE_Error
4015
+	 * @throws InvalidArgumentException
4016
+	 * @throws ReflectionException
4017
+	 * @throws InvalidDataTypeException
4018
+	 * @throws InvalidInterfaceException
4019
+	 */
4020
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4021
+		$messenger,
4022
+		EE_Message_Type $message_type = null
4023
+	) {
4024
+		//if $messenger isn't a valid messenger object then get out.
4025
+		if ( ! $messenger instanceof EE_Messenger) {
4026
+			EE_Error::add_error(
4027
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4028
+				__FILE__,
4029
+				__FUNCTION__,
4030
+				__LINE__
4031
+			);
4032 4032
             
4033
-            return false;
4034
-        }
4035
-        //activated
4036
-        if ($this->_template_args['data']['active_mts']) {
4037
-            EE_Error::overwrite_success();
4038
-            //activated a message type with the messenger
4039
-            if ($message_type instanceof EE_message_type) {
4040
-                EE_Error::add_success(
4041
-                    sprintf(
4042
-                        esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4043
-                        ucwords($message_type->label['singular']),
4044
-                        ucwords($messenger->label['singular'])
4045
-                    )
4046
-                );
4033
+			return false;
4034
+		}
4035
+		//activated
4036
+		if ($this->_template_args['data']['active_mts']) {
4037
+			EE_Error::overwrite_success();
4038
+			//activated a message type with the messenger
4039
+			if ($message_type instanceof EE_message_type) {
4040
+				EE_Error::add_success(
4041
+					sprintf(
4042
+						esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4043
+						ucwords($message_type->label['singular']),
4044
+						ucwords($messenger->label['singular'])
4045
+					)
4046
+				);
4047 4047
                 
4048
-                //if message type was invoice then let's make sure we activate the invoice payment method.
4049
-                if ($message_type->name === 'invoice') {
4050
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4051
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4052
-                    if ($pm instanceof EE_Payment_Method) {
4053
-                        EE_Error::add_attention(
4054
-                            esc_html__(
4055
-                                '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.',
4056
-                                'event_espresso'
4057
-                            )
4058
-                        );
4059
-                    }
4060
-                }
4061
-                //just toggles the entire messenger
4062
-            } else {
4063
-                EE_Error::add_success(
4064
-                    sprintf(
4065
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4066
-                        ucwords($messenger->label['singular'])
4067
-                    )
4068
-                );
4069
-            }
4048
+				//if message type was invoice then let's make sure we activate the invoice payment method.
4049
+				if ($message_type->name === 'invoice') {
4050
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4051
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4052
+					if ($pm instanceof EE_Payment_Method) {
4053
+						EE_Error::add_attention(
4054
+							esc_html__(
4055
+								'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.',
4056
+								'event_espresso'
4057
+							)
4058
+						);
4059
+					}
4060
+				}
4061
+				//just toggles the entire messenger
4062
+			} else {
4063
+				EE_Error::add_success(
4064
+					sprintf(
4065
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4066
+						ucwords($messenger->label['singular'])
4067
+					)
4068
+				);
4069
+			}
4070 4070
             
4071
-            return true;
4071
+			return true;
4072 4072
             
4073
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4074
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4075
-            //in which case we just give a success message for the messenger being successfully activated.
4076
-        } else {
4077
-            if ( ! $messenger->get_default_message_types()) {
4078
-                //messenger doesn't have any default message types so still a success.
4079
-                EE_Error::add_success(
4080
-                    sprintf(
4081
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4082
-                        ucwords($messenger->label['singular'])
4083
-                    )
4084
-                );
4073
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4074
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4075
+			//in which case we just give a success message for the messenger being successfully activated.
4076
+		} else {
4077
+			if ( ! $messenger->get_default_message_types()) {
4078
+				//messenger doesn't have any default message types so still a success.
4079
+				EE_Error::add_success(
4080
+					sprintf(
4081
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4082
+						ucwords($messenger->label['singular'])
4083
+					)
4084
+				);
4085 4085
                 
4086
-                return true;
4087
-            } else {
4088
-                EE_Error::add_error(
4089
-                    $message_type instanceof EE_message_type
4090
-                        ? sprintf(
4091
-                        esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4092
-                        ucwords($message_type->label['singular']),
4093
-                        ucwords($messenger->label['singular'])
4094
-                    )
4095
-                        : sprintf(
4096
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4097
-                        ucwords($messenger->label['singular'])
4098
-                    ),
4099
-                    __FILE__,
4100
-                    __FUNCTION__,
4101
-                    __LINE__
4102
-                );
4086
+				return true;
4087
+			} else {
4088
+				EE_Error::add_error(
4089
+					$message_type instanceof EE_message_type
4090
+						? sprintf(
4091
+						esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4092
+						ucwords($message_type->label['singular']),
4093
+						ucwords($messenger->label['singular'])
4094
+					)
4095
+						: sprintf(
4096
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4097
+						ucwords($messenger->label['singular'])
4098
+					),
4099
+					__FILE__,
4100
+					__FUNCTION__,
4101
+					__LINE__
4102
+				);
4103 4103
                 
4104
-                return false;
4105
-            }
4106
-        }
4107
-    }
4104
+				return false;
4105
+			}
4106
+		}
4107
+	}
4108 4108
 
4109 4109
 
4110
-    /**
4111
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4112
-     *
4113
-     * @param EE_messenger         $messenger
4114
-     * @param EE_message_type|null $message_type
4115
-     * @return bool
4116
-     * @throws DomainException
4117
-     * @throws EE_Error
4118
-     * @throws InvalidArgumentException
4119
-     * @throws ReflectionException
4120
-     * @throws InvalidDataTypeException
4121
-     * @throws InvalidInterfaceException
4122
-     */
4123
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4124
-        $messenger,
4125
-        EE_message_type $message_type = null
4126
-    ) {
4127
-        EE_Error::overwrite_success();
4128
-        
4129
-        //if $messenger isn't a valid messenger object then get out.
4130
-        if ( ! $messenger instanceof EE_Messenger) {
4131
-            EE_Error::add_error(
4132
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4133
-                __FILE__,
4134
-                __FUNCTION__,
4135
-                __LINE__
4136
-            );
4110
+	/**
4111
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4112
+	 *
4113
+	 * @param EE_messenger         $messenger
4114
+	 * @param EE_message_type|null $message_type
4115
+	 * @return bool
4116
+	 * @throws DomainException
4117
+	 * @throws EE_Error
4118
+	 * @throws InvalidArgumentException
4119
+	 * @throws ReflectionException
4120
+	 * @throws InvalidDataTypeException
4121
+	 * @throws InvalidInterfaceException
4122
+	 */
4123
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4124
+		$messenger,
4125
+		EE_message_type $message_type = null
4126
+	) {
4127
+		EE_Error::overwrite_success();
4128
+        
4129
+		//if $messenger isn't a valid messenger object then get out.
4130
+		if ( ! $messenger instanceof EE_Messenger) {
4131
+			EE_Error::add_error(
4132
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4133
+				__FILE__,
4134
+				__FUNCTION__,
4135
+				__LINE__
4136
+			);
4137 4137
             
4138
-            return false;
4139
-        }
4140
-        
4141
-        if ($message_type instanceof EE_message_type) {
4142
-            $message_type_name = $message_type->name;
4143
-            EE_Error::add_success(
4144
-                sprintf(
4145
-                    esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4146
-                    ucwords($message_type->label['singular']),
4147
-                    ucwords($messenger->label['singular'])
4148
-                )
4149
-            );
4150
-        } else {
4151
-            $message_type_name = '';
4152
-            EE_Error::add_success(
4153
-                sprintf(
4154
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4155
-                    ucwords($messenger->label['singular'])
4156
-                )
4157
-            );
4158
-        }
4159
-        
4160
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4161
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4162
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4163
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4164
-            if ($count_updated > 0) {
4165
-                $msg = $message_type_name === 'invoice'
4166
-                    ? esc_html__(
4167
-                        '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.',
4168
-                        'event_espresso'
4169
-                    )
4170
-                    : esc_html__(
4171
-                        '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.',
4172
-                        'event_espresso'
4173
-                    );
4174
-                EE_Error::add_attention($msg);
4175
-            }
4176
-        }
4177
-        
4178
-        return true;
4179
-    }
4138
+			return false;
4139
+		}
4140
+        
4141
+		if ($message_type instanceof EE_message_type) {
4142
+			$message_type_name = $message_type->name;
4143
+			EE_Error::add_success(
4144
+				sprintf(
4145
+					esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4146
+					ucwords($message_type->label['singular']),
4147
+					ucwords($messenger->label['singular'])
4148
+				)
4149
+			);
4150
+		} else {
4151
+			$message_type_name = '';
4152
+			EE_Error::add_success(
4153
+				sprintf(
4154
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4155
+					ucwords($messenger->label['singular'])
4156
+				)
4157
+			);
4158
+		}
4159
+        
4160
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4161
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4162
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4163
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4164
+			if ($count_updated > 0) {
4165
+				$msg = $message_type_name === 'invoice'
4166
+					? esc_html__(
4167
+						'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.',
4168
+						'event_espresso'
4169
+					)
4170
+					: esc_html__(
4171
+						'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.',
4172
+						'event_espresso'
4173
+					);
4174
+				EE_Error::add_attention($msg);
4175
+			}
4176
+		}
4177
+        
4178
+		return true;
4179
+	}
4180 4180
 
4181 4181
 
4182
-    /**
4183
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4184
-     *
4185
-     * @throws DomainException
4186
-     */
4187
-    public function update_mt_form()
4188
-    {
4189
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4190
-            EE_Error::add_error(
4191
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4192
-                __FILE__,
4193
-                __FUNCTION__,
4194
-                __LINE__
4195
-            );
4196
-            $this->_return_json();
4197
-        }
4198
-        
4199
-        $message_types = $this->get_installed_message_types();
4200
-        
4201
-        $message_type = $message_types[$this->_req_data['message_type']];
4202
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4203
-        
4204
-        $content                         = $this->_message_type_settings_content(
4205
-            $message_type,
4206
-            $messenger,
4207
-            true
4208
-        );
4209
-        $this->_template_args['success'] = true;
4210
-        $this->_template_args['content'] = $content;
4211
-        $this->_return_json();
4212
-    }
4182
+	/**
4183
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4184
+	 *
4185
+	 * @throws DomainException
4186
+	 */
4187
+	public function update_mt_form()
4188
+	{
4189
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4190
+			EE_Error::add_error(
4191
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4192
+				__FILE__,
4193
+				__FUNCTION__,
4194
+				__LINE__
4195
+			);
4196
+			$this->_return_json();
4197
+		}
4198
+        
4199
+		$message_types = $this->get_installed_message_types();
4200
+        
4201
+		$message_type = $message_types[$this->_req_data['message_type']];
4202
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4203
+        
4204
+		$content                         = $this->_message_type_settings_content(
4205
+			$message_type,
4206
+			$messenger,
4207
+			true
4208
+		);
4209
+		$this->_template_args['success'] = true;
4210
+		$this->_template_args['content'] = $content;
4211
+		$this->_return_json();
4212
+	}
4213 4213
     
4214 4214
     
4215
-    /**
4216
-     * this handles saving the settings for a messenger or message type
4217
-     *
4218
-     */
4219
-    public function save_settings()
4220
-    {
4221
-        if ( ! isset($this->_req_data['type'])) {
4222
-            EE_Error::add_error(
4223
-                esc_html__(
4224
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4225
-                    'event_espresso'
4226
-                ),
4227
-                __FILE__,
4228
-                __FUNCTION__,
4229
-                __LINE__
4230
-            );
4231
-            $this->_template_args['error'] = true;
4232
-            $this->_return_json();
4233
-        }
4234
-        
4235
-        
4236
-        if ($this->_req_data['type'] === 'messenger') {
4237
-            //this should be an array.
4238
-            $settings  = $this->_req_data['messenger_settings'];
4239
-            $messenger = $settings['messenger'];
4240
-            //let's setup the settings data
4241
-            foreach ($settings as $key => $value) {
4242
-                switch ($key) {
4243
-                    case 'messenger' :
4244
-                        unset($settings['messenger']);
4245
-                        break;
4246
-                    case 'message_types' :
4247
-                        unset($settings['message_types']);
4248
-                        break;
4249
-                    default :
4250
-                        $settings[$key] = $value;
4251
-                        break;
4252
-                }
4253
-            }
4254
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4255
-        } elseif ($this->_req_data['type'] === 'message_type') {
4256
-            $settings     = $this->_req_data['message_type_settings'];
4257
-            $messenger    = $settings['messenger'];
4258
-            $message_type = $settings['message_type'];
4215
+	/**
4216
+	 * this handles saving the settings for a messenger or message type
4217
+	 *
4218
+	 */
4219
+	public function save_settings()
4220
+	{
4221
+		if ( ! isset($this->_req_data['type'])) {
4222
+			EE_Error::add_error(
4223
+				esc_html__(
4224
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4225
+					'event_espresso'
4226
+				),
4227
+				__FILE__,
4228
+				__FUNCTION__,
4229
+				__LINE__
4230
+			);
4231
+			$this->_template_args['error'] = true;
4232
+			$this->_return_json();
4233
+		}
4234
+        
4235
+        
4236
+		if ($this->_req_data['type'] === 'messenger') {
4237
+			//this should be an array.
4238
+			$settings  = $this->_req_data['messenger_settings'];
4239
+			$messenger = $settings['messenger'];
4240
+			//let's setup the settings data
4241
+			foreach ($settings as $key => $value) {
4242
+				switch ($key) {
4243
+					case 'messenger' :
4244
+						unset($settings['messenger']);
4245
+						break;
4246
+					case 'message_types' :
4247
+						unset($settings['message_types']);
4248
+						break;
4249
+					default :
4250
+						$settings[$key] = $value;
4251
+						break;
4252
+				}
4253
+			}
4254
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4255
+		} elseif ($this->_req_data['type'] === 'message_type') {
4256
+			$settings     = $this->_req_data['message_type_settings'];
4257
+			$messenger    = $settings['messenger'];
4258
+			$message_type = $settings['message_type'];
4259 4259
             
4260
-            foreach ($settings as $key => $value) {
4261
-                switch ($key) {
4262
-                    case 'messenger' :
4263
-                        unset($settings['messenger']);
4264
-                        break;
4265
-                    case 'message_type' :
4266
-                        unset($settings['message_type']);
4267
-                        break;
4268
-                    default :
4269
-                        $settings[$key] = $value;
4270
-                        break;
4271
-                }
4272
-            }
4260
+			foreach ($settings as $key => $value) {
4261
+				switch ($key) {
4262
+					case 'messenger' :
4263
+						unset($settings['messenger']);
4264
+						break;
4265
+					case 'message_type' :
4266
+						unset($settings['message_type']);
4267
+						break;
4268
+					default :
4269
+						$settings[$key] = $value;
4270
+						break;
4271
+				}
4272
+			}
4273 4273
             
4274
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4275
-        }
4276
-        
4277
-        //okay we should have the data all setup.  Now we just update!
4278
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4279
-        
4280
-        if ($success) {
4281
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4282
-        } else {
4283
-            EE_Error::add_error(
4284
-                esc_html__(
4285
-                    'Settings did not get updated',
4286
-                    'event_espresso'
4287
-                ),
4288
-                __FILE__,
4289
-                __FUNCTION__,
4290
-                __LINE__
4291
-            );
4292
-        }
4293
-        
4294
-        $this->_template_args['success'] = $success;
4295
-        $this->_return_json();
4296
-    }
4274
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4275
+		}
4276
+        
4277
+		//okay we should have the data all setup.  Now we just update!
4278
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4279
+        
4280
+		if ($success) {
4281
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4282
+		} else {
4283
+			EE_Error::add_error(
4284
+				esc_html__(
4285
+					'Settings did not get updated',
4286
+					'event_espresso'
4287
+				),
4288
+				__FILE__,
4289
+				__FUNCTION__,
4290
+				__LINE__
4291
+			);
4292
+		}
4293
+        
4294
+		$this->_template_args['success'] = $success;
4295
+		$this->_return_json();
4296
+	}
4297 4297
     
4298 4298
     
4299 4299
     
4300 4300
     
4301
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4301
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4302 4302
     
4303 4303
     
4304
-    /**
4305
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4306
-     * However, this does not send immediately, it just queues for sending.
4307
-     *
4308
-     * @since 4.9.0
4309
-     */
4310
-    protected function _generate_now()
4311
-    {
4312
-        $msg_ids = $this->_get_msg_ids_from_request();
4313
-        EED_Messages::generate_now($msg_ids);
4314
-        $this->_redirect_after_action(false, '', '', array(), true);
4315
-    }
4304
+	/**
4305
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4306
+	 * However, this does not send immediately, it just queues for sending.
4307
+	 *
4308
+	 * @since 4.9.0
4309
+	 */
4310
+	protected function _generate_now()
4311
+	{
4312
+		$msg_ids = $this->_get_msg_ids_from_request();
4313
+		EED_Messages::generate_now($msg_ids);
4314
+		$this->_redirect_after_action(false, '', '', array(), true);
4315
+	}
4316 4316
     
4317 4317
     
4318
-    /**
4319
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4320
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4321
-     *
4322
-     * @since 4.9.0
4323
-     *
4324
-     */
4325
-    protected function _generate_and_send_now()
4326
-    {
4327
-        $this->_generate_now();
4328
-        $this->_send_now();
4329
-        $this->_redirect_after_action(false, '', '', array(), true);
4330
-    }
4318
+	/**
4319
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4320
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4321
+	 *
4322
+	 * @since 4.9.0
4323
+	 *
4324
+	 */
4325
+	protected function _generate_and_send_now()
4326
+	{
4327
+		$this->_generate_now();
4328
+		$this->_send_now();
4329
+		$this->_redirect_after_action(false, '', '', array(), true);
4330
+	}
4331 4331
     
4332 4332
     
4333
-    /**
4334
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4335
-     *
4336
-     * @since 4.9.0
4337
-     */
4338
-    protected function _queue_for_resending()
4339
-    {
4340
-        $msg_ids = $this->_get_msg_ids_from_request();
4341
-        EED_Messages::queue_for_resending($msg_ids);
4342
-        $this->_redirect_after_action(false, '', '', array(), true);
4343
-    }
4333
+	/**
4334
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4335
+	 *
4336
+	 * @since 4.9.0
4337
+	 */
4338
+	protected function _queue_for_resending()
4339
+	{
4340
+		$msg_ids = $this->_get_msg_ids_from_request();
4341
+		EED_Messages::queue_for_resending($msg_ids);
4342
+		$this->_redirect_after_action(false, '', '', array(), true);
4343
+	}
4344 4344
     
4345 4345
     
4346
-    /**
4347
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4348
-     *
4349
-     * @since 4.9.0
4350
-     */
4351
-    protected function _send_now()
4352
-    {
4353
-        $msg_ids = $this->_get_msg_ids_from_request();
4354
-        EED_Messages::send_now($msg_ids);
4355
-        $this->_redirect_after_action(false, '', '', array(), true);
4356
-    }
4346
+	/**
4347
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4348
+	 *
4349
+	 * @since 4.9.0
4350
+	 */
4351
+	protected function _send_now()
4352
+	{
4353
+		$msg_ids = $this->_get_msg_ids_from_request();
4354
+		EED_Messages::send_now($msg_ids);
4355
+		$this->_redirect_after_action(false, '', '', array(), true);
4356
+	}
4357 4357
 
4358 4358
 
4359
-    /**
4360
-     * Deletes EE_messages for IDs in the request.
4361
-     *
4362
-     * @since 4.9.0
4363
-     * @throws EE_Error
4364
-     * @throws InvalidDataTypeException
4365
-     * @throws InvalidInterfaceException
4366
-     * @throws InvalidArgumentException
4367
-     */
4368
-    protected function _delete_ee_messages()
4369
-    {
4370
-        $msg_ids       = $this->_get_msg_ids_from_request();
4371
-        $deleted_count = 0;
4372
-        foreach ($msg_ids as $msg_id) {
4373
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4374
-                $deleted_count++;
4375
-            }
4376
-        }
4377
-        if ($deleted_count) {
4378
-            $this->_redirect_after_action(
4379
-                true,
4380
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
4381
-                esc_html__('deleted', 'event_espresso')
4382
-            );
4383
-        } else {
4384
-            EE_Error::add_error(
4385
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4386
-                __FILE__, __FUNCTION__, __LINE__
4387
-            );
4388
-            $this->_redirect_after_action(false, '', '', array(), true);
4389
-        }
4390
-    }
4359
+	/**
4360
+	 * Deletes EE_messages for IDs in the request.
4361
+	 *
4362
+	 * @since 4.9.0
4363
+	 * @throws EE_Error
4364
+	 * @throws InvalidDataTypeException
4365
+	 * @throws InvalidInterfaceException
4366
+	 * @throws InvalidArgumentException
4367
+	 */
4368
+	protected function _delete_ee_messages()
4369
+	{
4370
+		$msg_ids       = $this->_get_msg_ids_from_request();
4371
+		$deleted_count = 0;
4372
+		foreach ($msg_ids as $msg_id) {
4373
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4374
+				$deleted_count++;
4375
+			}
4376
+		}
4377
+		if ($deleted_count) {
4378
+			$this->_redirect_after_action(
4379
+				true,
4380
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
4381
+				esc_html__('deleted', 'event_espresso')
4382
+			);
4383
+		} else {
4384
+			EE_Error::add_error(
4385
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4386
+				__FILE__, __FUNCTION__, __LINE__
4387
+			);
4388
+			$this->_redirect_after_action(false, '', '', array(), true);
4389
+		}
4390
+	}
4391 4391
     
4392 4392
     
4393
-    /**
4394
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4395
-     * @since 4.9.0
4396
-     * @return array
4397
-     */
4398
-    protected function _get_msg_ids_from_request()
4399
-    {
4400
-        if ( ! isset($this->_req_data['MSG_ID'])) {
4401
-            return array();
4402
-        }
4403
-        
4404
-        return is_array($this->_req_data['MSG_ID'])
4405
-            ? array_keys($this->_req_data['MSG_ID'])
4406
-            : array($this->_req_data['MSG_ID']);
4407
-    }
4393
+	/**
4394
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4395
+	 * @since 4.9.0
4396
+	 * @return array
4397
+	 */
4398
+	protected function _get_msg_ids_from_request()
4399
+	{
4400
+		if ( ! isset($this->_req_data['MSG_ID'])) {
4401
+			return array();
4402
+		}
4403
+        
4404
+		return is_array($this->_req_data['MSG_ID'])
4405
+			? array_keys($this->_req_data['MSG_ID'])
4406
+			: array($this->_req_data['MSG_ID']);
4407
+	}
4408 4408
 }
Please login to merge, or discard this patch.
admin_pages/messages/help_tabs/messages_settings_messengers.help_tab.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,79 +3,79 @@
 block discarded – undo
3 3
 </p>
4 4
 <p>
5 5
     <?php esc_html_e(
6
-        'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
-        'event_espresso'
8
-    ); ?>
6
+		'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
+		'event_espresso'
8
+	); ?>
9 9
 </p>
10 10
 <p>
11 11
     <?php esc_html_e(
12
-        'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
-        'event_espresso'
14
-    ); ?>
12
+		'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
+		'event_espresso'
14
+	); ?>
15 15
 </p>
16 16
 <p>
17 17
     <?php printf(
18
-        esc_html__(
19
-            'The green colored gear %s indicates that this messenger is currently active.',
20
-            'event_espresso'
21
-        ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
-    );
25
-    printf(
26
-        esc_html__(
27
-            ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
-            'event_espresso'
29
-        ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
-    ); ?>
18
+		esc_html__(
19
+			'The green colored gear %s indicates that this messenger is currently active.',
20
+			'event_espresso'
21
+		),
22
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
+		. ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
+	);
25
+	printf(
26
+		esc_html__(
27
+			' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
+			'event_espresso'
29
+		),
30
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
+		. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
+	); ?>
33 33
 </p>
34 34
 <p>
35 35
     <?php esc_html_e(
36
-        'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
-        'event_espresso'
38
-    ); ?>
36
+		'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
+		'event_espresso'
38
+	); ?>
39 39
 </p>
40 40
 <p>
41 41
     <?php printf(
42
-        esc_html__(
43
-            '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
-            'event_espresso'
45
-        ),
46
-        '<div class="switch">'
47
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
-            . '<label for="ee-on-off-toggle-on"></label>'
49
-        . '</div>',
50
-        '<div class="switch">'
51
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
-            . '<label for="ee-on-off-toggle-on"></label>'
53
-        . '</div>'
54
-    ); ?>
42
+		esc_html__(
43
+			'%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
+			'event_espresso'
45
+		),
46
+		'<div class="switch">'
47
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
+			. '<label for="ee-on-off-toggle-on"></label>'
49
+		. '</div>',
50
+		'<div class="switch">'
51
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
+			. '<label for="ee-on-off-toggle-on"></label>'
53
+		. '</div>'
54
+	); ?>
55 55
 </p>
56 56
 <p>
57 57
     <?php
58
-        esc_html_e(
59
-            'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
-            'event_espresso'
61
-        ); ?>
58
+		esc_html_e(
59
+			'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
+			'event_espresso'
61
+		); ?>
62 62
 </p>
63 63
 <p>
64 64
     <?php esc_html_e(
65
-        'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
-        'event_espresso'
67
-    ); ?>
65
+		'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
+		'event_espresso'
67
+	); ?>
68 68
 </p>
69 69
 <p>
70 70
     <?php esc_html_e(
71
-        'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
-        'event_espresso'
73
-    ); ?>
71
+		'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
+		'event_espresso'
73
+	); ?>
74 74
 </p>
75 75
 <p>
76 76
     <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/>
77 77
     <?php esc_html_e(
78
-        'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
-        'event_espresso'
80
-    ); ?>
78
+		'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
+		'event_espresso'
80
+	); ?>
81 81
 </p>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@
 block discarded – undo
19 19
             'The green colored gear %s indicates that this messenger is currently active.',
20 20
             'event_espresso'
21 21
         ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
22
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"'
23
+        . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'
24 24
     );
25 25
     printf(
26 26
         esc_html__(
27 27
             ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28 28
             'event_espresso'
29 29
         ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
30
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
31
+        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'
32 32
     ); ?>
33 33
 </p>
34 34
 <p>
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Venue_Shortcodes.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
     /**
177 177
      * This retrieves the EE_Venue from the available data object.
178 178
      *
179
-     * @return EE_Venue|null
179
+     * @return EE_Base_Class|null
180 180
      * @throws EE_Error
181 181
      * @throws EntityNotFoundException
182 182
      */
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     {
91 91
         $this->_venue = $this->_get_venue();
92 92
         //If there is no venue object by now then get out.
93
-        if (! $this->_venue instanceof EE_Venue) {
93
+        if ( ! $this->_venue instanceof EE_Venue) {
94 94
             return '';
95 95
         }
96 96
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
         //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
190 190
         // reg_obj instead.
191
-        if (! $this->_event instanceof EE_Event) {
191
+        if ( ! $this->_event instanceof EE_Event) {
192 192
             $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
193 193
             $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
194 194
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 
206 206
             //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
207 207
             // and use that.
208
-            $this->_event       = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
208
+            $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
209 209
                 ? reset($aee->events)
210 210
                 : $this->_event;
211 211
         }
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
     private function _venue($field)
230 230
     {
231 231
 
232
-        if (! $this->_venue instanceof EE_Venue) {
232
+        if ( ! $this->_venue instanceof EE_Venue) {
233 233
             return '';
234 234
         } //no venue so get out.
235 235
 
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
                 break;
253 253
 
254 254
             case 'image':
255
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
256
-                       . '" alt="' . sprintf(
255
+                return '<img src="'.$this->_venue->feature_image_url(array(200, 200,))
256
+                       . '" alt="'.sprintf(
257 257
                            esc_attr__('%s Feature Image', 'event_espresso'),
258 258
                            $this->_venue->get('VNU_name')
259
-                       ) . '" />';
259
+                       ).'" />';
260 260
                 break;
261 261
 
262 262
             case 'phone':
Please login to merge, or discard this patch.
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -19,317 +19,317 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * Will hold the EE_Event if available
24
-     *
25
-     * @var EE_Event
26
-     */
27
-    protected $_event;
28
-
29
-    /**
30
-     * Will hold the EE_Venue if available
31
-     *
32
-     * @var EE_Venue
33
-     */
34
-    protected $_venue;
35
-
36
-
37
-    /**
38
-     * Initialize properties
39
-     */
40
-    protected function _init_props()
41
-    {
42
-        $this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
43
-        $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
44
-        $this->_shortcodes = array(
45
-            '[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
46
-            '[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
47
-            '[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
48
-            '[VENUE_DETAILS_URL]'       => sprintf(
49
-                esc_html__(
50
-                    'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.',
51
-                    'event_espresso'
52
-                ),
53
-                '[VENUE_URL]'
54
-            ),
55
-            '[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
56
-            '[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
57
-            '[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
58
-            '[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
59
-            '[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
60
-            '[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
61
-            '[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
62
-            '[VENUE_FORMATTED_ADDRESS]' => esc_html__(
63
-                'This just outputs the venue address in a semantic address format.',
64
-                'event_espresso'
65
-            ),
66
-            '[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
67
-            '[VENUE_META_*]'            => esc_html__(
68
-                'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.',
69
-                'event_espresso'
70
-            ),
71
-            '[GOOGLE_MAP_URL]'          => esc_html__(
72
-                'URL for the google map associated with the venue.',
73
-                'event_espresso'
74
-            ),
75
-            '[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
76
-            '[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
77
-        );
78
-    }
79
-
80
-
81
-    /**
82
-     * Parse incoming shortcode
83
-     *
84
-     * @param string $shortcode
85
-     * @return string
86
-     * @throws EE_Error
87
-     * @throws EntityNotFoundException
88
-     */
89
-    protected function _parser($shortcode)
90
-    {
91
-        $this->_venue = $this->_get_venue();
92
-        //If there is no venue object by now then get out.
93
-        if (! $this->_venue instanceof EE_Venue) {
94
-            return '';
95
-        }
96
-
97
-        switch ($shortcode) {
98
-            case '[VENUE_TITLE]':
99
-                return $this->_venue('title');
100
-                break;
101
-
102
-            case '[VENUE_DESCRIPTION]':
103
-                return $this->_venue('description');
104
-                break;
105
-
106
-            case '[VENUE_URL]':
107
-                return $this->_venue('url');
108
-                break;
109
-
110
-            case '[VENUE_IMAGE]':
111
-                return $this->_venue('image');
112
-                break;
113
-
114
-            case '[VENUE_PHONE]':
115
-                return $this->_venue('phone');
116
-                break;
117
-
118
-            case '[VENUE_ADDRESS]':
119
-                return $this->_venue('address');
120
-                break;
121
-
122
-            case '[VENUE_ADDRESS2]':
123
-                return $this->_venue('address2');
124
-                break;
125
-
126
-            case '[VENUE_CITY]':
127
-                return $this->_venue('city');
128
-                break;
129
-
130
-            case '[VENUE_COUNTRY]':
131
-                return $this->_venue('country');
132
-                break;
133
-
134
-            case '[VENUE_STATE]':
135
-                return $this->_venue('state');
136
-                break;
137
-
138
-            case '[VENUE_ZIP]':
139
-                return $this->_venue('zip');
140
-                break;
141
-
142
-            case '[VENUE_FORMATTED_ADDRESS]':
143
-                return $this->_venue('formatted_address');
144
-                break;
145
-
146
-            case '[GOOGLE_MAP_URL]':
147
-                return $this->_venue('gmap_url');
148
-                break;
149
-
150
-            case '[GOOGLE_MAP_LINK]':
151
-                return $this->_venue('gmap_link');
152
-                break;
153
-
154
-            case '[GOOGLE_MAP_IMAGE]':
155
-                return $this->_venue('gmap_link_img');
156
-                break;
157
-
158
-            case '[VENUE_DETAILS_URL]':
159
-                return $this->_venue('permalink');
160
-                break;
161
-
162
-        }
163
-
164
-        if (strpos($shortcode, '[VENUE_META_*') !== false) {
165
-            $shortcode = str_replace('[VENUE_META_*', '', $shortcode);
166
-            $shortcode = trim(str_replace(']', '', $shortcode));
167
-
168
-            //pull the meta value from the venue post
169
-            $venue_meta = $this->_venue->get_post_meta($shortcode, true);
170
-
171
-            return ! empty($venue_meta) ? $venue_meta : '';
172
-
173
-        }
174
-    }
175
-
176
-    /**
177
-     * This retrieves the EE_Venue from the available data object.
178
-     *
179
-     * @return EE_Venue|null
180
-     * @throws EE_Error
181
-     * @throws EntityNotFoundException
182
-     */
183
-    private function _get_venue()
184
-    {
185
-
186
-        //we need the EE_Event object to get the venue.
187
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
188
-
189
-        //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
190
-        // reg_obj instead.
191
-        if (! $this->_event instanceof EE_Event) {
192
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
193
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
194
-
195
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
196
-                ? $aee->reg_obj->event()
197
-                : null;
198
-
199
-            //if still empty do we have a ticket data item?
200
-            $this->_event = ! $this->_event instanceof EE_Event
201
-                            && $this->_data instanceof EE_Ticket
202
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
203
-                ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
204
-                : $this->_event;
205
-
206
-            //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
207
-            // and use that.
208
-            $this->_event       = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
209
-                ? reset($aee->events)
210
-                : $this->_event;
211
-        }
212
-
213
-        //If we have an event object use it to pull the venue.
214
-        if ($this->_event instanceof EE_Event) {
215
-            return $this->_event->get_first_related('Venue');
216
-        }
217
-
218
-        return null;
219
-    }
220
-
221
-    /**
222
-     * This retrieves the specified venue information
223
-     *
224
-     * @param string $field What Venue field to retrieve
225
-     * @return string What was retrieved!
226
-     * @throws EE_Error
227
-     * @throws EntityNotFoundException
228
-     */
229
-    private function _venue($field)
230
-    {
231
-
232
-        if (! $this->_venue instanceof EE_Venue) {
233
-            return '';
234
-        } //no venue so get out.
235
-
236
-        switch ($field) {
237
-            case 'title':
238
-                return $this->_venue->get('VNU_name');
239
-                break;
240
-
241
-            case 'description':
242
-                return $this->_venue->get('VNU_desc');
243
-                break;
244
-
245
-            case 'url':
246
-                $url = $this->_venue->get('VNU_url');
247
-                return empty($url) ? $this->_venue->get_permalink() : $url;
248
-                break;
249
-
250
-            case 'permalink':
251
-                return $this->_venue->get_permalink();
252
-                break;
253
-
254
-            case 'image':
255
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
256
-                       . '" alt="' . sprintf(
257
-                           esc_attr__('%s Feature Image', 'event_espresso'),
258
-                           $this->_venue->get('VNU_name')
259
-                       ) . '" />';
260
-                break;
261
-
262
-            case 'phone':
263
-                return $this->_venue->get('VNU_phone');
264
-                break;
265
-
266
-            case 'address':
267
-                return $this->_venue->get('VNU_address');
268
-                break;
269
-
270
-            case 'address2':
271
-                return $this->_venue->get('VNU_address2');
272
-                break;
273
-
274
-            case 'city':
275
-                return $this->_venue->get('VNU_city');
276
-                break;
277
-
278
-            case 'state':
279
-                $state = $this->_venue->state_obj();
280
-                return is_object($state) ? $state->get('STA_name') : '';
281
-                break;
282
-
283
-            case 'country':
284
-                $country = $this->_venue->country_obj();
285
-                return is_object($country) ? $country->get('CNT_name') : '';
286
-                break;
287
-
288
-            case 'zip':
289
-                return $this->_venue->get('VNU_zip');
290
-                break;
291
-
292
-            case 'formatted_address':
293
-                return EEH_Address::format($this->_venue);
294
-                break;
295
-
296
-            case 'gmap_link':
297
-            case 'gmap_url':
298
-            case 'gmap_link_img':
299
-                $atts = $this->get_map_attributes($this->_venue, $field);
300
-                return EEH_Maps::google_map_link($atts);
301
-                break;
302
-        }
303
-        return '';
304
-    }
305
-
306
-
307
-    /**
308
-     * Generates the attributes for retrieving a google_map artifact.
309
-     *
310
-     * @param EE_Venue $venue
311
-     * @param string   $field
312
-     * @return array
313
-     * @throws EE_Error
314
-     */
315
-    protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
316
-    {
317
-        $state   = $venue->state_obj();
318
-        $country = $venue->country_obj();
319
-        $atts    = array(
320
-            'id'      => $venue->ID(),
321
-            'address' => $venue->get('VNU_address'),
322
-            'city'    => $venue->get('VNU_city'),
323
-            'state'   => is_object($state) ? $state->get('STA_name') : '',
324
-            'zip'     => $venue->get('VNU_zip'),
325
-            'country' => is_object($country) ? $country->get('CNT_name') : '',
326
-            'type'    => $field === 'gmap_link' ? 'url' : 'map',
327
-            'map_w'   => 200,
328
-            'map_h'   => 200,
329
-        );
330
-        if ($field === 'gmap_url') {
331
-            $atts['type'] = 'url_only';
332
-        }
333
-        return $atts;
334
-    }
22
+	/**
23
+	 * Will hold the EE_Event if available
24
+	 *
25
+	 * @var EE_Event
26
+	 */
27
+	protected $_event;
28
+
29
+	/**
30
+	 * Will hold the EE_Venue if available
31
+	 *
32
+	 * @var EE_Venue
33
+	 */
34
+	protected $_venue;
35
+
36
+
37
+	/**
38
+	 * Initialize properties
39
+	 */
40
+	protected function _init_props()
41
+	{
42
+		$this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
43
+		$this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
44
+		$this->_shortcodes = array(
45
+			'[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
46
+			'[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
47
+			'[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
48
+			'[VENUE_DETAILS_URL]'       => sprintf(
49
+				esc_html__(
50
+					'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.',
51
+					'event_espresso'
52
+				),
53
+				'[VENUE_URL]'
54
+			),
55
+			'[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
56
+			'[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
57
+			'[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
58
+			'[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
59
+			'[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
60
+			'[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
61
+			'[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
62
+			'[VENUE_FORMATTED_ADDRESS]' => esc_html__(
63
+				'This just outputs the venue address in a semantic address format.',
64
+				'event_espresso'
65
+			),
66
+			'[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
67
+			'[VENUE_META_*]'            => esc_html__(
68
+				'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.',
69
+				'event_espresso'
70
+			),
71
+			'[GOOGLE_MAP_URL]'          => esc_html__(
72
+				'URL for the google map associated with the venue.',
73
+				'event_espresso'
74
+			),
75
+			'[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
76
+			'[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
77
+		);
78
+	}
79
+
80
+
81
+	/**
82
+	 * Parse incoming shortcode
83
+	 *
84
+	 * @param string $shortcode
85
+	 * @return string
86
+	 * @throws EE_Error
87
+	 * @throws EntityNotFoundException
88
+	 */
89
+	protected function _parser($shortcode)
90
+	{
91
+		$this->_venue = $this->_get_venue();
92
+		//If there is no venue object by now then get out.
93
+		if (! $this->_venue instanceof EE_Venue) {
94
+			return '';
95
+		}
96
+
97
+		switch ($shortcode) {
98
+			case '[VENUE_TITLE]':
99
+				return $this->_venue('title');
100
+				break;
101
+
102
+			case '[VENUE_DESCRIPTION]':
103
+				return $this->_venue('description');
104
+				break;
105
+
106
+			case '[VENUE_URL]':
107
+				return $this->_venue('url');
108
+				break;
109
+
110
+			case '[VENUE_IMAGE]':
111
+				return $this->_venue('image');
112
+				break;
113
+
114
+			case '[VENUE_PHONE]':
115
+				return $this->_venue('phone');
116
+				break;
117
+
118
+			case '[VENUE_ADDRESS]':
119
+				return $this->_venue('address');
120
+				break;
121
+
122
+			case '[VENUE_ADDRESS2]':
123
+				return $this->_venue('address2');
124
+				break;
125
+
126
+			case '[VENUE_CITY]':
127
+				return $this->_venue('city');
128
+				break;
129
+
130
+			case '[VENUE_COUNTRY]':
131
+				return $this->_venue('country');
132
+				break;
133
+
134
+			case '[VENUE_STATE]':
135
+				return $this->_venue('state');
136
+				break;
137
+
138
+			case '[VENUE_ZIP]':
139
+				return $this->_venue('zip');
140
+				break;
141
+
142
+			case '[VENUE_FORMATTED_ADDRESS]':
143
+				return $this->_venue('formatted_address');
144
+				break;
145
+
146
+			case '[GOOGLE_MAP_URL]':
147
+				return $this->_venue('gmap_url');
148
+				break;
149
+
150
+			case '[GOOGLE_MAP_LINK]':
151
+				return $this->_venue('gmap_link');
152
+				break;
153
+
154
+			case '[GOOGLE_MAP_IMAGE]':
155
+				return $this->_venue('gmap_link_img');
156
+				break;
157
+
158
+			case '[VENUE_DETAILS_URL]':
159
+				return $this->_venue('permalink');
160
+				break;
161
+
162
+		}
163
+
164
+		if (strpos($shortcode, '[VENUE_META_*') !== false) {
165
+			$shortcode = str_replace('[VENUE_META_*', '', $shortcode);
166
+			$shortcode = trim(str_replace(']', '', $shortcode));
167
+
168
+			//pull the meta value from the venue post
169
+			$venue_meta = $this->_venue->get_post_meta($shortcode, true);
170
+
171
+			return ! empty($venue_meta) ? $venue_meta : '';
172
+
173
+		}
174
+	}
175
+
176
+	/**
177
+	 * This retrieves the EE_Venue from the available data object.
178
+	 *
179
+	 * @return EE_Venue|null
180
+	 * @throws EE_Error
181
+	 * @throws EntityNotFoundException
182
+	 */
183
+	private function _get_venue()
184
+	{
185
+
186
+		//we need the EE_Event object to get the venue.
187
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
188
+
189
+		//if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
190
+		// reg_obj instead.
191
+		if (! $this->_event instanceof EE_Event) {
192
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
193
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
194
+
195
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
196
+				? $aee->reg_obj->event()
197
+				: null;
198
+
199
+			//if still empty do we have a ticket data item?
200
+			$this->_event = ! $this->_event instanceof EE_Event
201
+							&& $this->_data instanceof EE_Ticket
202
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
203
+				? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
204
+				: $this->_event;
205
+
206
+			//if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
207
+			// and use that.
208
+			$this->_event       = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
209
+				? reset($aee->events)
210
+				: $this->_event;
211
+		}
212
+
213
+		//If we have an event object use it to pull the venue.
214
+		if ($this->_event instanceof EE_Event) {
215
+			return $this->_event->get_first_related('Venue');
216
+		}
217
+
218
+		return null;
219
+	}
220
+
221
+	/**
222
+	 * This retrieves the specified venue information
223
+	 *
224
+	 * @param string $field What Venue field to retrieve
225
+	 * @return string What was retrieved!
226
+	 * @throws EE_Error
227
+	 * @throws EntityNotFoundException
228
+	 */
229
+	private function _venue($field)
230
+	{
231
+
232
+		if (! $this->_venue instanceof EE_Venue) {
233
+			return '';
234
+		} //no venue so get out.
235
+
236
+		switch ($field) {
237
+			case 'title':
238
+				return $this->_venue->get('VNU_name');
239
+				break;
240
+
241
+			case 'description':
242
+				return $this->_venue->get('VNU_desc');
243
+				break;
244
+
245
+			case 'url':
246
+				$url = $this->_venue->get('VNU_url');
247
+				return empty($url) ? $this->_venue->get_permalink() : $url;
248
+				break;
249
+
250
+			case 'permalink':
251
+				return $this->_venue->get_permalink();
252
+				break;
253
+
254
+			case 'image':
255
+				return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
256
+					   . '" alt="' . sprintf(
257
+						   esc_attr__('%s Feature Image', 'event_espresso'),
258
+						   $this->_venue->get('VNU_name')
259
+					   ) . '" />';
260
+				break;
261
+
262
+			case 'phone':
263
+				return $this->_venue->get('VNU_phone');
264
+				break;
265
+
266
+			case 'address':
267
+				return $this->_venue->get('VNU_address');
268
+				break;
269
+
270
+			case 'address2':
271
+				return $this->_venue->get('VNU_address2');
272
+				break;
273
+
274
+			case 'city':
275
+				return $this->_venue->get('VNU_city');
276
+				break;
277
+
278
+			case 'state':
279
+				$state = $this->_venue->state_obj();
280
+				return is_object($state) ? $state->get('STA_name') : '';
281
+				break;
282
+
283
+			case 'country':
284
+				$country = $this->_venue->country_obj();
285
+				return is_object($country) ? $country->get('CNT_name') : '';
286
+				break;
287
+
288
+			case 'zip':
289
+				return $this->_venue->get('VNU_zip');
290
+				break;
291
+
292
+			case 'formatted_address':
293
+				return EEH_Address::format($this->_venue);
294
+				break;
295
+
296
+			case 'gmap_link':
297
+			case 'gmap_url':
298
+			case 'gmap_link_img':
299
+				$atts = $this->get_map_attributes($this->_venue, $field);
300
+				return EEH_Maps::google_map_link($atts);
301
+				break;
302
+		}
303
+		return '';
304
+	}
305
+
306
+
307
+	/**
308
+	 * Generates the attributes for retrieving a google_map artifact.
309
+	 *
310
+	 * @param EE_Venue $venue
311
+	 * @param string   $field
312
+	 * @return array
313
+	 * @throws EE_Error
314
+	 */
315
+	protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
316
+	{
317
+		$state   = $venue->state_obj();
318
+		$country = $venue->country_obj();
319
+		$atts    = array(
320
+			'id'      => $venue->ID(),
321
+			'address' => $venue->get('VNU_address'),
322
+			'city'    => $venue->get('VNU_city'),
323
+			'state'   => is_object($state) ? $state->get('STA_name') : '',
324
+			'zip'     => $venue->get('VNU_zip'),
325
+			'country' => is_object($country) ? $country->get('CNT_name') : '',
326
+			'type'    => $field === 'gmap_link' ? 'url' : 'map',
327
+			'map_w'   => 200,
328
+			'map_h'   => 200,
329
+		);
330
+		if ($field === 'gmap_url') {
331
+			$atts['type'] = 'url_only';
332
+		}
333
+		return $atts;
334
+	}
335 335
 }
Please login to merge, or discard this patch.
core/EE_Maintenance_Mode.core.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -17,362 +17,362 @@
 block discarded – undo
17 17
 class EE_Maintenance_Mode implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
22
-     * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
23
-     */
24
-    const level_0_not_in_maintenance = 0;
25
-
26
-    /**
27
-     * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
28
-     * but the admin backend should be running as normal. Maybe an admin can view the frontend though
29
-     */
30
-    const level_1_frontend_only_maintenance = 1;
31
-
32
-    /**
33
-     * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
34
-     * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
35
-     * migration scripts before taking the site out of maintenance mode
36
-     */
37
-    const level_2_complete_maintenance = 2;
38
-
39
-    /**
40
-     * the name of the option which stores the current level of maintenance mode
41
-     */
42
-    const option_name_maintenance_mode = 'ee_maintenance_mode';
43
-
44
-
45
-    /**
46
-     * @var EE_Maintenance_Mode $_instance
47
-     */
48
-    private static $_instance;
49
-
50
-    /**
51
-     * @var EE_Registry $EE
52
-     */
53
-    protected $EE;
54
-
55
-
56
-
57
-    /**
58
-     * @singleton method used to instantiate class object
59
-     * @return EE_Maintenance_Mode
60
-     */
61
-    public static function instance()
62
-    {
63
-        // check if class object is instantiated
64
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
65
-            self::$_instance = new self();
66
-        }
67
-        return self::$_instance;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
74
-     *
75
-     * @return EE_Maintenance_Mode
76
-     */
77
-    public static function reset()
78
-    {
79
-        self::instance()->set_maintenance_mode_if_db_old();
80
-        return self::instance();
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     *private constructor to prevent direct creation
87
-     */
88
-    private function __construct()
89
-    {
90
-        // if M-Mode level 2 is engaged, we still need basic assets loaded
91
-        add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
92
-        // shut 'er down down for maintenance ?
93
-        add_filter('the_content', array($this, 'the_content'), 2);
94
-        // add powered by EE msg
95
-        add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * retrieves the maintenance mode option value from the db
102
-     *
103
-     * @return int
104
-     */
105
-    public function real_level()
106
-    {
107
-        return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Returns whether or not the models reportedly are able to run queries or not
114
-     * (ie, if the system thinks their tables are present and up-to-date).
115
-     *
116
-     * @return boolean
117
-     */
118
-    public function models_can_query()
119
-    {
120
-        return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * Determines whether or not we're in maintenance mode and what level. However, while the site
127
-     * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
128
-     * to them as if teh site isn't in maintenance mode.
129
-     * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
130
-     * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
131
-     * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
132
-     *
133
-     * @return int
134
-     */
135
-    public function level()
136
-    {
137
-        $maintenance_mode_level = $this->real_level();
138
-        // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
139
-        if (
140
-            $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
141
-            && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
142
-            && current_user_can('administrator') // when the user is an admin
143
-        ) {
144
-            $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
145
-        }
146
-        return $maintenance_mode_level;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * Determines if we need to put EE in maintenance mode because the database needs updating
153
-     *
154
-     * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
155
-     */
156
-    public function set_maintenance_mode_if_db_old()
157
-    {
158
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
159
-        if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
160
-            update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
161
-            return true;
162
-        }
163
-        if ($this->level() === self::level_2_complete_maintenance) {
164
-            //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
165
-            //then we shouldn't be in mm2. (Maybe an addon got deactivated?)
166
-            update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
167
-            return false;
168
-        }
169
-        return false;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Updates the maintenance level on the site
176
-     *
177
-     * @param int $level
178
-     * @return void
179
-     */
180
-    public function set_maintenance_level($level)
181
-    {
182
-        do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
183
-        update_option(self::option_name_maintenance_mode, (int)$level);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * returns TRUE if M-Mode is engaged and the current request is not for the admin
190
-     *
191
-     * @return    string
192
-     */
193
-    public static function disable_frontend_for_maintenance()
194
-    {
195
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @return void
202
-     */
203
-    public function load_assets_required_for_m_mode()
204
-    {
205
-        if (
206
-            $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
207
-            && ! wp_script_is('espresso_core')
208
-        ) {
209
-            wp_register_style(
210
-                'espresso_default',
211
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
212
-                array('dashicons'),
213
-                EVENT_ESPRESSO_VERSION
214
-            );
215
-            wp_enqueue_style('espresso_default');
216
-            wp_register_script(
217
-                'espresso_core',
218
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
219
-                array('jquery'),
220
-                EVENT_ESPRESSO_VERSION,
221
-                true
222
-            );
223
-            wp_enqueue_script('espresso_core');
224
-        }
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * replacement EE CPT template that displays message notifying site visitors
231
-     * that EE has been temporarily placed into maintenance mode
232
-     * does NOT get called on non-EE-CPT requests
233
-     *
234
-     * @return    string
235
-     */
236
-    public static function template_include()
237
-    {
238
-        // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
239
-        return get_template_directory() . '/index.php';
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * displays message notifying site visitors that EE has been temporarily
246
-     * placed into maintenance mode when post_type != EE CPT
247
-     *
248
-     * @param string $the_content
249
-     * @return string
250
-     */
251
-    public function the_content($the_content)
252
-    {
253
-        // check if M-mode is engaged and for EE shortcode
254
-        if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
255
-            // this can eventually be moved to a template, or edited via admin. But for now...
256
-            $the_content = sprintf(
257
-                esc_html__(
258
-                    '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
259
-                    'event_espresso'
260
-                ),
261
-                '<h3>',
262
-                '</h3><p>',
263
-                '</p>'
264
-            );
265
-        }
266
-        return $the_content;
267
-    }
20
+	/**
21
+	 * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
22
+	 * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
23
+	 */
24
+	const level_0_not_in_maintenance = 0;
25
+
26
+	/**
27
+	 * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
28
+	 * but the admin backend should be running as normal. Maybe an admin can view the frontend though
29
+	 */
30
+	const level_1_frontend_only_maintenance = 1;
31
+
32
+	/**
33
+	 * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
34
+	 * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
35
+	 * migration scripts before taking the site out of maintenance mode
36
+	 */
37
+	const level_2_complete_maintenance = 2;
38
+
39
+	/**
40
+	 * the name of the option which stores the current level of maintenance mode
41
+	 */
42
+	const option_name_maintenance_mode = 'ee_maintenance_mode';
43
+
44
+
45
+	/**
46
+	 * @var EE_Maintenance_Mode $_instance
47
+	 */
48
+	private static $_instance;
49
+
50
+	/**
51
+	 * @var EE_Registry $EE
52
+	 */
53
+	protected $EE;
54
+
55
+
56
+
57
+	/**
58
+	 * @singleton method used to instantiate class object
59
+	 * @return EE_Maintenance_Mode
60
+	 */
61
+	public static function instance()
62
+	{
63
+		// check if class object is instantiated
64
+		if (! self::$_instance instanceof EE_Maintenance_Mode) {
65
+			self::$_instance = new self();
66
+		}
67
+		return self::$_instance;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
74
+	 *
75
+	 * @return EE_Maintenance_Mode
76
+	 */
77
+	public static function reset()
78
+	{
79
+		self::instance()->set_maintenance_mode_if_db_old();
80
+		return self::instance();
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 *private constructor to prevent direct creation
87
+	 */
88
+	private function __construct()
89
+	{
90
+		// if M-Mode level 2 is engaged, we still need basic assets loaded
91
+		add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
92
+		// shut 'er down down for maintenance ?
93
+		add_filter('the_content', array($this, 'the_content'), 2);
94
+		// add powered by EE msg
95
+		add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * retrieves the maintenance mode option value from the db
102
+	 *
103
+	 * @return int
104
+	 */
105
+	public function real_level()
106
+	{
107
+		return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Returns whether or not the models reportedly are able to run queries or not
114
+	 * (ie, if the system thinks their tables are present and up-to-date).
115
+	 *
116
+	 * @return boolean
117
+	 */
118
+	public function models_can_query()
119
+	{
120
+		return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * Determines whether or not we're in maintenance mode and what level. However, while the site
127
+	 * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
128
+	 * to them as if teh site isn't in maintenance mode.
129
+	 * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
130
+	 * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
131
+	 * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
132
+	 *
133
+	 * @return int
134
+	 */
135
+	public function level()
136
+	{
137
+		$maintenance_mode_level = $this->real_level();
138
+		// if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
139
+		if (
140
+			$maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
141
+			&& ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
142
+			&& current_user_can('administrator') // when the user is an admin
143
+		) {
144
+			$maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
145
+		}
146
+		return $maintenance_mode_level;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * Determines if we need to put EE in maintenance mode because the database needs updating
153
+	 *
154
+	 * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
155
+	 */
156
+	public function set_maintenance_mode_if_db_old()
157
+	{
158
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
159
+		if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
160
+			update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
161
+			return true;
162
+		}
163
+		if ($this->level() === self::level_2_complete_maintenance) {
164
+			//we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
165
+			//then we shouldn't be in mm2. (Maybe an addon got deactivated?)
166
+			update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
167
+			return false;
168
+		}
169
+		return false;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Updates the maintenance level on the site
176
+	 *
177
+	 * @param int $level
178
+	 * @return void
179
+	 */
180
+	public function set_maintenance_level($level)
181
+	{
182
+		do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
183
+		update_option(self::option_name_maintenance_mode, (int)$level);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * returns TRUE if M-Mode is engaged and the current request is not for the admin
190
+	 *
191
+	 * @return    string
192
+	 */
193
+	public static function disable_frontend_for_maintenance()
194
+	{
195
+		return (! is_admin() && EE_Maintenance_Mode::instance()->level());
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @return void
202
+	 */
203
+	public function load_assets_required_for_m_mode()
204
+	{
205
+		if (
206
+			$this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
207
+			&& ! wp_script_is('espresso_core')
208
+		) {
209
+			wp_register_style(
210
+				'espresso_default',
211
+				EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
212
+				array('dashicons'),
213
+				EVENT_ESPRESSO_VERSION
214
+			);
215
+			wp_enqueue_style('espresso_default');
216
+			wp_register_script(
217
+				'espresso_core',
218
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
219
+				array('jquery'),
220
+				EVENT_ESPRESSO_VERSION,
221
+				true
222
+			);
223
+			wp_enqueue_script('espresso_core');
224
+		}
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * replacement EE CPT template that displays message notifying site visitors
231
+	 * that EE has been temporarily placed into maintenance mode
232
+	 * does NOT get called on non-EE-CPT requests
233
+	 *
234
+	 * @return    string
235
+	 */
236
+	public static function template_include()
237
+	{
238
+		// shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
239
+		return get_template_directory() . '/index.php';
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * displays message notifying site visitors that EE has been temporarily
246
+	 * placed into maintenance mode when post_type != EE CPT
247
+	 *
248
+	 * @param string $the_content
249
+	 * @return string
250
+	 */
251
+	public function the_content($the_content)
252
+	{
253
+		// check if M-mode is engaged and for EE shortcode
254
+		if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
255
+			// this can eventually be moved to a template, or edited via admin. But for now...
256
+			$the_content = sprintf(
257
+				esc_html__(
258
+					'%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
259
+					'event_espresso'
260
+				),
261
+				'<h3>',
262
+				'</h3><p>',
263
+				'</p>'
264
+			);
265
+		}
266
+		return $the_content;
267
+	}
268 268
 
269 269
 
270 270
 
271
-    /**
272
-     * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
273
-     */
274
-    public function display_maintenance_mode_notice()
275
-    {
276
-        // check if M-mode is engaged and for EE shortcode
277
-        if (
278
-            ! (defined('DOING_AJAX') && DOING_AJAX)
279
-            && $this->real_level()
280
-            && ! is_admin()
281
-            && current_user_can('administrator')
282
-            && EE_Registry::instance()->REQ->is_espresso_page()
283
-        ) {
284
-            printf(
285
-                esc_html__(
286
-                    '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
287
-                    'event_espresso'
288
-                ),
289
-                '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
290
-                '"><span class="dashicons dashicons-no"></span></a><p>',
291
-                ' &raquo; <a href="' . add_query_arg(
292
-                    array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')
293
-                ) . '">',
294
-                '</a></p></div>'
295
-            );
296
-        }
297
-    }
298
-    // espresso-notices important-notice ee-attention
271
+	/**
272
+	 * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
273
+	 */
274
+	public function display_maintenance_mode_notice()
275
+	{
276
+		// check if M-mode is engaged and for EE shortcode
277
+		if (
278
+			! (defined('DOING_AJAX') && DOING_AJAX)
279
+			&& $this->real_level()
280
+			&& ! is_admin()
281
+			&& current_user_can('administrator')
282
+			&& EE_Registry::instance()->REQ->is_espresso_page()
283
+		) {
284
+			printf(
285
+				esc_html__(
286
+					'%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
287
+					'event_espresso'
288
+				),
289
+				'<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
290
+				'"><span class="dashicons dashicons-no"></span></a><p>',
291
+				' &raquo; <a href="' . add_query_arg(
292
+					array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')
293
+				) . '">',
294
+				'</a></p></div>'
295
+			);
296
+		}
297
+	}
298
+	// espresso-notices important-notice ee-attention
299 299
 
300 300
 
301 301
 
302
-    /**
303
-     * override magic methods
304
-     */
305
-    final public function __destruct()
306
-    {
307
-    }
302
+	/**
303
+	 * override magic methods
304
+	 */
305
+	final public function __destruct()
306
+	{
307
+	}
308 308
 
309 309
 
310 310
 
311
-    final public function __call($a, $b)
312
-    {
313
-    }
311
+	final public function __call($a, $b)
312
+	{
313
+	}
314 314
 
315 315
 
316 316
 
317
-    final public function __get($a)
318
-    {
319
-    }
317
+	final public function __get($a)
318
+	{
319
+	}
320 320
 
321 321
 
322 322
 
323
-    final public function __set($a, $b)
324
-    {
325
-    }
323
+	final public function __set($a, $b)
324
+	{
325
+	}
326 326
 
327 327
 
328 328
 
329
-    final public function __isset($a)
330
-    {
331
-    }
329
+	final public function __isset($a)
330
+	{
331
+	}
332 332
 
333 333
 
334 334
 
335
-    final public function __unset($a)
336
-    {
337
-    }
335
+	final public function __unset($a)
336
+	{
337
+	}
338 338
 
339 339
 
340 340
 
341
-    final public function __sleep()
342
-    {
343
-        return array();
344
-    }
341
+	final public function __sleep()
342
+	{
343
+		return array();
344
+	}
345 345
 
346 346
 
347 347
 
348
-    final public function __wakeup()
349
-    {
350
-    }
348
+	final public function __wakeup()
349
+	{
350
+	}
351 351
 
352 352
 
353 353
 
354
-    final public function __invoke()
355
-    {
356
-    }
354
+	final public function __invoke()
355
+	{
356
+	}
357 357
 
358 358
 
359 359
 
360
-    final public static function __set_state($a = null)
361
-    {
362
-        return EE_Maintenance_Mode::instance();
363
-    }
360
+	final public static function __set_state($a = null)
361
+	{
362
+		return EE_Maintenance_Mode::instance();
363
+	}
364 364
 
365 365
 
366 366
 
367
-    final public function __clone()
368
-    {
369
-    }
367
+	final public function __clone()
368
+	{
369
+	}
370 370
 
371 371
 
372 372
 
373
-    final public static function __callStatic($a, $b)
374
-    {
375
-    }
373
+	final public static function __callStatic($a, $b)
374
+	{
375
+	}
376 376
 
377 377
 }
378 378
 // End of file EE_Maintenance_Mode.core.php
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -698,7 +698,7 @@
 block discarded – undo
698 698
 
699 699
     /**
700 700
      * @param EE_State[] $state_options
701
-     * @return array
701
+     * @return EE_State[]
702 702
      * @throws EE_Error
703 703
      * @throws InvalidArgumentException
704 704
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +724 added lines, -724 removed lines patch added patch discarded remove patch
@@ -19,730 +19,730 @@
 block discarded – undo
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     * @return EED_Module|EED_Add_New_State
24
-     */
25
-    public static function instance()
26
-    {
27
-        return parent::get_instance(__CLASS__);
28
-    }
29
-
30
-
31
-
32
-    /**
33
-     * set_hooks - for hooking into EE Core, other modules, etc
34
-     *
35
-     * @return void
36
-     */
37
-    public static function set_hooks()
38
-    {
39
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
40
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
41
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
42
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
44
-        add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
45
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
46
-        add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
47
-            array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
48
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
49
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
50
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
51
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
52
-        add_filter('FHEE__EE_State_Select_Input____construct__state_options',
53
-            array('EED_Add_New_State', 'state_options'), 10, 1);
54
-        add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
55
-            array('EED_Add_New_State', 'country_options'), 10, 1);
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
62
-     *
63
-     * @return void
64
-     */
65
-    public static function set_hooks_admin()
66
-    {
67
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
68
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
69
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
70
-        add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
71
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
72
-        add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
73
-        add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
74
-        add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
75
-            array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
76
-        add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
77
-            array('EED_Add_New_State', 'update_country_settings'), 10, 3);
78
-        add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
79
-            array('EED_Add_New_State', 'update_country_settings'), 10, 3);
80
-        add_filter('FHEE__EE_State_Select_Input____construct__state_options',
81
-            array('EED_Add_New_State', 'state_options'), 10, 1);
82
-        add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
83
-            array('EED_Add_New_State', 'country_options'), 10, 1);
84
-        add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
85
-            array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1);
86
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
87
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
88
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
89
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * @return void
96
-     */
97
-    public static function set_definitions()
98
-    {
99
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
100
-        define('ANS_TEMPLATES_PATH', str_replace(
101
-                                         '\\',
102
-                                         DS,
103
-                                         plugin_dir_path(__FILE__)) . 'templates' . DS
104
-        );
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @param WP $WP
111
-     * @return void
112
-     */
113
-    public function run($WP)
114
-    {
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * @return void
121
-     */
122
-    public static function translate_js_strings()
123
-    {
124
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
125
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
126
-            'event_espresso'
127
-        );
128
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
129
-            'In order to proceed, you need to enter the name of your State/Province.',
130
-            'event_espresso'
131
-        );
132
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
133
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
134
-            'event_espresso'
135
-        );
136
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
137
-            'The new state was successfully saved to the database.',
138
-            'event_espresso'
139
-        );
140
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
141
-            'An unknown error has occurred on the server while saving the new state to the database.',
142
-            'event_espresso'
143
-        );
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @return void
150
-     */
151
-    public static function wp_enqueue_scripts()
152
-    {
153
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
154
-            wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
155
-                array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
156
-            wp_enqueue_script('add_new_state');
157
-        }
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * display_add_new_state_micro_form
164
-     *
165
-     * @param EE_Form_Section_Proper $question_group_reg_form
166
-     * @return string
167
-     * @throws EE_Error
168
-     * @throws InvalidArgumentException
169
-     * @throws InvalidDataTypeException
170
-     * @throws InvalidInterfaceException
171
-     */
172
-    //	public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){
173
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
174
-    {
175
-        // only add the 'new_state_micro_form' when displaying reg forms,
176
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
177
-        $action = EE_Registry::instance()->REQ->get('action', '');
178
-        // is the "state" question in this form section?
179
-        $input = $question_group_reg_form->get_subsection('state');
180
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
181
-            //ok then all we need to do is make sure the input's HTML name is consistent
182
-            //by forcing it to set it now, like it did while getting the form for display
183
-            if ($input instanceof EE_State_Select_Input) {
184
-                $input->html_name();
185
-            }
186
-            return $question_group_reg_form;
187
-        }
188
-        // we're only doing this for state select inputs
189
-        if ($input instanceof EE_State_Select_Input) {
190
-            // grab any set values from the request
191
-            $country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
192
-            $state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
193
-            $abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
194
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
195
-            $country_options     = array();
196
-            $countries           = EEM_Country::instance()->get_all_countries();
197
-            if (! empty($countries)) {
198
-                foreach ($countries as $country) {
199
-                    if ($country instanceof EE_Country) {
200
-                        $country_options[$country->ID()] = $country->name();
201
-                    }
202
-                }
203
-            }
204
-            $new_state_micro_form = new EE_Form_Section_Proper(
205
-                array(
206
-                    'name'            => 'new_state_micro_form',
207
-                    'html_id'         => 'new_state_micro_form',
208
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
209
-                    'subsections'     => array(
210
-                        // add hidden input to indicate that a new state is being added
211
-                        'add_new_state'               => new EE_Hidden_Input(
212
-                            array(
213
-                                'html_name' => str_replace(
214
-                                    'state',
215
-                                    'nsmf_add_new_state',
216
-                                    $input->html_name()
217
-                                ),
218
-                                'html_id'   => str_replace(
219
-                                    'state',
220
-                                    'nsmf_add_new_state',
221
-                                    $input->html_id()
222
-                                ),
223
-                                'default'   => 0,
224
-                            )
225
-                        ),
226
-                        // add link for displaying hidden container
227
-                        'click_here_link'             => new EE_Form_Section_HTML(
228
-                            apply_filters(
229
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
230
-                                EEH_HTML::link(
231
-                                    '',
232
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
233
-                                    '',
234
-                                    'display-' . $input->html_id(),
235
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
236
-                                    '',
237
-                                    'data-target="' . $input->html_id() . '"'
238
-                                )
239
-                            )
240
-                        ),
241
-                        // add initial html for hidden container
242
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
243
-                            apply_filters(
244
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
245
-                                EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
246
-                                    'display: none;') .
247
-                                EEH_HTML::h6(
248
-                                    esc_html__(
249
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
250
-                                        'event_espresso'
251
-                                    )
252
-                                ) .
253
-                                EEH_HTML::ul() .
254
-                                EEH_HTML::li(
255
-                                    esc_html__(
256
-                                        'first select the Country that your State/Province belongs to',
257
-                                        'event_espresso'
258
-                                    )
259
-                                ) .
260
-                                EEH_HTML::li(
261
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
262
-                                ) .
263
-                                EEH_HTML::li(
264
-                                    esc_html__(
265
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
266
-                                        'event_espresso'
267
-                                    )
268
-                                ) .
269
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
270
-                                EEH_HTML::ulx()
271
-                            )
272
-                        ),
273
-                        // NEW STATE COUNTRY
274
-                        'new_state_country'           => new EE_Country_Select_Input(
275
-                            $country_options,
276
-                            array(
277
-                                'html_name'       => $country_name,
278
-                                'html_id'         => str_replace(
279
-                                    'state',
280
-                                    'nsmf_new_state_country', $input->html_id()
281
-                                ),
282
-                                'html_class'      => $input->html_class() . ' new-state-country',
283
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
284
-                                'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
285
-                                'required'        => false,
286
-                            )
287
-                        ),
288
-                        // NEW STATE NAME
289
-                        'new_state_name'              => new EE_Text_Input(
290
-                            array(
291
-                                'html_name'       => $state_name,
292
-                                'html_id'         => str_replace(
293
-                                    'state',
294
-                                    'nsmf_new_state_name', $input->html_id()
295
-                                ),
296
-                                'html_class'      => $input->html_class() . ' new-state-state',
297
-                                'html_label_text' => esc_html__('New State/Province Name',
298
-                                    'event_espresso'),
299
-                                'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
300
-                                'required'        => false,
301
-                            )
302
-                        ),
303
-                        'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
304
-                        // NEW STATE NAME
305
-                        'new_state_abbrv'             => new EE_Text_Input(
306
-                            array(
307
-                                'html_name'             => $abbrv_name,
308
-                                'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
309
-                                    $input->html_id()),
310
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
311
-                                'html_label_text'       => esc_html__(
312
-                                                               'New State/Province Abbreviation',
313
-                                                               'event_espresso'
314
-                                                           ) . ' *',
315
-                                'html_other_attributes' => 'size="24"',
316
-                                'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
317
-                                'required'              => false,
318
-                            )
319
-                        ),
320
-                        // "submit" button
321
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
322
-                            apply_filters(
323
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
324
-                                EEH_HTML::nbsp(3) .
325
-                                EEH_HTML::link(
326
-                                    '',
327
-                                    esc_html__('ADD', 'event_espresso'),
328
-                                    '',
329
-                                    'submit-' . $new_state_submit_id,
330
-                                    'ee-form-add-new-state-submit button button-secondary',
331
-                                    '',
332
-                                    'data-target="' . $new_state_submit_id . '"'
333
-                                )
334
-                            )
335
-                        ),
336
-                        // extra info
337
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
338
-                            apply_filters(
339
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
340
-                                EEH_HTML::br(2)
341
-                                .
342
-                                EEH_HTML::div('', '', 'small-text')
343
-                                .
344
-                                EEH_HTML::strong(
345
-                                    '* ' .
346
-                                    esc_html__(
347
-                                        'Don\'t know your State/Province Abbreviation?',
348
-                                        'event_espresso'
349
-                                    )
350
-                                )
351
-                                .
352
-                                EEH_HTML::br()
353
-                                .
354
-                                sprintf(
355
-                                    esc_html__(
356
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
357
-                                        'event_espresso'
358
-                                    ),
359
-                                    EEH_HTML::link(
360
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
361
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
362
-                                        '',
363
-                                        '',
364
-                                        'ee-form-add-new-state-wiki-lnk',
365
-                                        '',
366
-                                        'target="_blank"'
367
-                                    )
368
-                                )
369
-                                .
370
-                                EEH_HTML::divx()
371
-                                .
372
-                                EEH_HTML::br()
373
-                                .
374
-                                EEH_HTML::link(
375
-                                    '',
376
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
377
-                                    '',
378
-                                    'hide-' . $input->html_id(),
379
-                                    'ee-form-cancel-new-state-lnk smaller-text',
380
-                                    '',
381
-                                    'data-target="' . $input->html_id() . '"'
382
-                                )
383
-                                .
384
-                                EEH_HTML::divx()
385
-                                .
386
-                                EEH_HTML::br()
387
-                            )
388
-                        ),
389
-                    ),
390
-                )
391
-            );
392
-            $question_group_reg_form->add_subsections(
393
-                array('new_state_micro_form' => $new_state_micro_form),
394
-                'state',
395
-                false
396
-            );
397
-        }
398
-        return $question_group_reg_form;
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * set_new_state_input_width
405
-     *
406
-     * @return int|string
407
-     * @throws EE_Error
408
-     * @throws InvalidArgumentException
409
-     * @throws InvalidDataTypeException
410
-     * @throws InvalidInterfaceException
411
-     * @throws ReflectionException
412
-     */
413
-    public static function add_new_state()
414
-    {
415
-        $REQ = EE_Registry::instance()->load_core('Request_Handler');
416
-        if (absint($REQ->get('nsmf_add_new_state')) === 1) {
417
-            EE_Registry::instance()->load_model('State');
418
-            // grab country ISO code, new state name, and new state abbreviation
419
-            $state_country = $REQ->is_set('nsmf_new_state_country')
420
-                ? sanitize_text_field($REQ->get('nsmf_new_state_country'))
421
-                : false;
422
-            $state_name    = $REQ->is_set('nsmf_new_state_name')
423
-                ? sanitize_text_field($REQ->get('nsmf_new_state_name'))
424
-                : false;
425
-            $state_abbr    = $REQ->is_set('nsmf_new_state_abbrv')
426
-                ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
427
-                : false;
428
-            if ($state_country && $state_name && $state_abbr) {
429
-                $new_state = EED_Add_New_State::save_new_state_to_db(array(
430
-                    'CNT_ISO'    => strtoupper($state_country),
431
-                    'STA_abbrev' => strtoupper($state_abbr),
432
-                    'STA_name'   => ucwords($state_name),
433
-                    'STA_active' => false,
434
-                ));
435
-                if ($new_state instanceof EE_State) {
436
-                    // clean house
437
-                    EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
438
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
439
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
440
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
441
-                    // get any existing new states
442
-                    $new_states                   = EE_Registry::instance()->SSN->get_session_data(
443
-                        'nsmf_new_states'
444
-                    );
445
-                    $new_states[$new_state->ID()] = $new_state;
446
-                    EE_Registry::instance()->SSN->set_session_data(
447
-                        array('nsmf_new_states' => $new_states)
448
-                    );
449
-                    if (EE_Registry::instance()->REQ->ajax) {
450
-                        echo wp_json_encode(array(
451
-                            'success'      => true,
452
-                            'id'           => $new_state->ID(),
453
-                            'name'         => $new_state->name(),
454
-                            'abbrev'       => $new_state->abbrev(),
455
-                            'country_iso'  => $new_state->country_iso(),
456
-                            'country_name' => $new_state->country()->name(),
457
-                        ));
458
-                        exit();
459
-                    }
460
-                    return $new_state->ID();
461
-                }
462
-            } else {
463
-                $error = esc_html__(
464
-                    'A new State/Province could not be added because invalid or missing data was received.',
465
-                    'event_espresso'
466
-                );
467
-                if (EE_Registry::instance()->REQ->ajax) {
468
-                    echo wp_json_encode(array('error' => $error));
469
-                    exit();
470
-                }
471
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
472
-            }
473
-        }
474
-        return false;
475
-    }
476
-
477
-
478
-
479
-    /**
480
-     * recursively drills down through request params to remove any that were added by this module
481
-     *
482
-     * @param array $request_params
483
-     * @return array
484
-     */
485
-    public static function filter_checkout_request_params($request_params)
486
-    {
487
-        foreach ($request_params as $form_section) {
488
-            if (is_array($form_section)) {
489
-                EED_Add_New_State::unset_new_state_request_params($form_section);
490
-                EED_Add_New_State::filter_checkout_request_params($form_section);
491
-            }
492
-        }
493
-        return $request_params;
494
-    }
495
-
496
-
497
-
498
-    /**
499
-     * @param array $request_params
500
-     * @return array
501
-     */
502
-    public static function unset_new_state_request_params($request_params)
503
-    {
504
-        unset(
505
-            $request_params['new_state_micro_form'],
506
-            $request_params['new_state_micro_add_new_state'],
507
-            $request_params['new_state_micro_new_state_country'],
508
-            $request_params['new_state_micro_new_state_name'],
509
-            $request_params['new_state_micro_new_state_abbrv']
510
-        );
511
-        return $request_params;
512
-    }
513
-
514
-
515
-
516
-    /**
517
-     * @param array $props_n_values
518
-     * @return bool
519
-     * @throws EE_Error
520
-     * @throws InvalidArgumentException
521
-     * @throws InvalidDataTypeException
522
-     * @throws InvalidInterfaceException
523
-     */
524
-    public static function save_new_state_to_db($props_n_values = array())
525
-    {
526
-        $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
527
-        if (! empty($existing_state)) {
528
-            return array_pop($existing_state);
529
-        }
530
-        $new_state = EE_State::new_instance($props_n_values);
531
-        if ($new_state instanceof EE_State) {
532
-            // if not non-ajax admin
533
-            $new_state_key    = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
534
-            $new_state_notice = sprintf(
535
-                esc_html__(
536
-                    'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
537
-                    'event_espresso'
538
-                ),
539
-                '<b>' . $new_state->name() . '</b>',
540
-                '<b>' . $new_state->abbrev() . '</b>',
541
-                '<b>' . $new_state->country()->name() . '</b>',
542
-                '<a href="' . add_query_arg(array(
543
-                    'page'    => 'espresso_general_settings',
544
-                    'action'  => 'country_settings',
545
-                    'country' => $new_state->country_iso(),
546
-                ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
547
-                    'event_espresso') . '</a>',
548
-                '<br />'
549
-            );
550
-            EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
551
-            $new_state->save();
552
-            EEM_State::instance()->reset_cached_states();
553
-            return $new_state;
554
-        }
555
-        return false;
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     * @param string $CNT_ISO
562
-     * @param string $STA_ID
563
-     * @param array  $cols_n_values
564
-     * @return void
565
-     * @throws EE_Error
566
-     * @throws InvalidArgumentException
567
-     * @throws InvalidDataTypeException
568
-     * @throws InvalidInterfaceException
569
-     */
570
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
571
-    {
572
-        if (! $CNT_ISO) {
573
-            EE_Error::add_error(
574
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
575
-                __FILE__,
576
-                __FUNCTION__,
577
-                __LINE__
578
-            );
579
-        }
580
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
581
-            : false;
582
-        if (! $STA_abbrev && ! empty($STA_ID)) {
583
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
584
-            if ($state instanceof EE_State) {
585
-                $STA_abbrev = $state->abbrev();
586
-            }
587
-        }
588
-        if (! $STA_abbrev) {
589
-            EE_Error::add_error(
590
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
591
-                __FILE__,
592
-                __FUNCTION__,
593
-                __LINE__
594
-            );
595
-        }
596
-        EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
597
-    }
598
-
599
-
600
-
601
-    /**
602
-     * @param EE_State[]                            $state_options
603
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
604
-     * @param EE_Registration                       $registration
605
-     * @param EE_Question                           $question
606
-     * @param                                       $answer
607
-     * @return array
608
-     * @throws EE_Error
609
-     * @throws InvalidArgumentException
610
-     * @throws InvalidDataTypeException
611
-     * @throws InvalidInterfaceException
612
-     */
613
-    public static function inject_new_reg_state_into_options(
614
-        $state_options = array(),
615
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
616
-        EE_Registration $registration,
617
-        EE_Question $question,
618
-        $answer
619
-    ) {
620
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
621
-            && $question->type() === EEM_Question::QST_type_state
622
-        ) {
623
-            $STA_ID = $answer->value();
624
-            if (! empty($STA_ID)) {
625
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
626
-                if ($state instanceof EE_State) {
627
-                    $country = $state->country();
628
-                    if ($country instanceof EE_Country) {
629
-                        if (! isset($state_options[$country->name()])) {
630
-                            $state_options[$country->name()] = array();
631
-                        }
632
-                        if (! isset($state_options[$country->name()][$STA_ID])) {
633
-                            $state_options[$country->name()][$STA_ID] = $state->name();
634
-                        }
635
-                    }
636
-                }
637
-            }
638
-        }
639
-        return $state_options;
640
-    }
641
-
642
-
643
-
644
-    /**
645
-     * @param EE_Country[]                          $country_options
646
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
647
-     * @param EE_Registration                       $registration
648
-     * @param EE_Question                           $question
649
-     * @param                                       $answer
650
-     * @return array
651
-     * @throws EE_Error
652
-     * @throws InvalidArgumentException
653
-     * @throws InvalidDataTypeException
654
-     * @throws InvalidInterfaceException
655
-     */
656
-    public static function inject_new_reg_country_into_options(
657
-        $country_options = array(),
658
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
659
-        EE_Registration $registration,
660
-        EE_Question $question,
661
-        $answer
662
-    ) {
663
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
664
-            && $question->type()
665
-               === EEM_Question::QST_type_country
666
-        ) {
667
-            $CNT_ISO = $answer->value();
668
-            if (! empty($CNT_ISO)) {
669
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
670
-                if ($country instanceof EE_Country) {
671
-                    if (! isset($country_options[$CNT_ISO])) {
672
-                        $country_options[$CNT_ISO] = $country->name();
673
-                    }
674
-                }
675
-            }
676
-        }
677
-        return $country_options;
678
-    }
679
-
680
-
681
-
682
-    /**
683
-     * @param EE_State[] $state_options
684
-     * @return array
685
-     * @throws EE_Error
686
-     * @throws InvalidArgumentException
687
-     * @throws InvalidDataTypeException
688
-     * @throws InvalidInterfaceException
689
-     */
690
-    public static function state_options($state_options = array())
691
-    {
692
-        $new_states = EED_Add_New_State::_get_new_states();
693
-        foreach ($new_states as $new_state) {
694
-            if (
695
-                $new_state instanceof EE_State
696
-                && $new_state->country() instanceof EE_Country
697
-            ) {
698
-                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
699
-            }
700
-        }
701
-        return $state_options;
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     * @return array
708
-     * @throws InvalidArgumentException
709
-     * @throws InvalidDataTypeException
710
-     * @throws InvalidInterfaceException
711
-     */
712
-    protected static function _get_new_states()
713
-    {
714
-        $new_states = array();
715
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
716
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
717
-                'nsmf_new_states'
718
-            );
719
-        }
720
-        return is_array($new_states) ? $new_states : array();
721
-    }
722
-
723
-
724
-
725
-    /**
726
-     * @param EE_Country[] $country_options
727
-     * @return array
728
-     * @throws EE_Error
729
-     * @throws InvalidArgumentException
730
-     * @throws InvalidDataTypeException
731
-     * @throws InvalidInterfaceException
732
-     */
733
-    public static function country_options($country_options = array())
734
-    {
735
-        $new_states = EED_Add_New_State::_get_new_states();
736
-        foreach ($new_states as $new_state) {
737
-            if (
738
-                $new_state instanceof EE_State
739
-                && $new_state->country() instanceof EE_Country
740
-            ) {
741
-                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
742
-            }
743
-        }
744
-        return $country_options;
745
-    }
22
+	/**
23
+	 * @return EED_Module|EED_Add_New_State
24
+	 */
25
+	public static function instance()
26
+	{
27
+		return parent::get_instance(__CLASS__);
28
+	}
29
+
30
+
31
+
32
+	/**
33
+	 * set_hooks - for hooking into EE Core, other modules, etc
34
+	 *
35
+	 * @return void
36
+	 */
37
+	public static function set_hooks()
38
+	{
39
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
40
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
41
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
42
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
44
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
45
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
46
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
47
+			array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
48
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
49
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
50
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
51
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
52
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options',
53
+			array('EED_Add_New_State', 'state_options'), 10, 1);
54
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
55
+			array('EED_Add_New_State', 'country_options'), 10, 1);
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
62
+	 *
63
+	 * @return void
64
+	 */
65
+	public static function set_hooks_admin()
66
+	{
67
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
68
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
69
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
70
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
71
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
72
+		add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
73
+		add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
74
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
75
+			array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
76
+		add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
77
+			array('EED_Add_New_State', 'update_country_settings'), 10, 3);
78
+		add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
79
+			array('EED_Add_New_State', 'update_country_settings'), 10, 3);
80
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options',
81
+			array('EED_Add_New_State', 'state_options'), 10, 1);
82
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
83
+			array('EED_Add_New_State', 'country_options'), 10, 1);
84
+		add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
85
+			array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1);
86
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
87
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
88
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
89
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * @return void
96
+	 */
97
+	public static function set_definitions()
98
+	{
99
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
100
+		define('ANS_TEMPLATES_PATH', str_replace(
101
+										 '\\',
102
+										 DS,
103
+										 plugin_dir_path(__FILE__)) . 'templates' . DS
104
+		);
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @param WP $WP
111
+	 * @return void
112
+	 */
113
+	public function run($WP)
114
+	{
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * @return void
121
+	 */
122
+	public static function translate_js_strings()
123
+	{
124
+		EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
125
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
126
+			'event_espresso'
127
+		);
128
+		EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
129
+			'In order to proceed, you need to enter the name of your State/Province.',
130
+			'event_espresso'
131
+		);
132
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
133
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
134
+			'event_espresso'
135
+		);
136
+		EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
137
+			'The new state was successfully saved to the database.',
138
+			'event_espresso'
139
+		);
140
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
141
+			'An unknown error has occurred on the server while saving the new state to the database.',
142
+			'event_espresso'
143
+		);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @return void
150
+	 */
151
+	public static function wp_enqueue_scripts()
152
+	{
153
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
154
+			wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
155
+				array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
156
+			wp_enqueue_script('add_new_state');
157
+		}
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * display_add_new_state_micro_form
164
+	 *
165
+	 * @param EE_Form_Section_Proper $question_group_reg_form
166
+	 * @return string
167
+	 * @throws EE_Error
168
+	 * @throws InvalidArgumentException
169
+	 * @throws InvalidDataTypeException
170
+	 * @throws InvalidInterfaceException
171
+	 */
172
+	//	public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){
173
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
174
+	{
175
+		// only add the 'new_state_micro_form' when displaying reg forms,
176
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
177
+		$action = EE_Registry::instance()->REQ->get('action', '');
178
+		// is the "state" question in this form section?
179
+		$input = $question_group_reg_form->get_subsection('state');
180
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
181
+			//ok then all we need to do is make sure the input's HTML name is consistent
182
+			//by forcing it to set it now, like it did while getting the form for display
183
+			if ($input instanceof EE_State_Select_Input) {
184
+				$input->html_name();
185
+			}
186
+			return $question_group_reg_form;
187
+		}
188
+		// we're only doing this for state select inputs
189
+		if ($input instanceof EE_State_Select_Input) {
190
+			// grab any set values from the request
191
+			$country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
192
+			$state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
193
+			$abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
194
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
195
+			$country_options     = array();
196
+			$countries           = EEM_Country::instance()->get_all_countries();
197
+			if (! empty($countries)) {
198
+				foreach ($countries as $country) {
199
+					if ($country instanceof EE_Country) {
200
+						$country_options[$country->ID()] = $country->name();
201
+					}
202
+				}
203
+			}
204
+			$new_state_micro_form = new EE_Form_Section_Proper(
205
+				array(
206
+					'name'            => 'new_state_micro_form',
207
+					'html_id'         => 'new_state_micro_form',
208
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
209
+					'subsections'     => array(
210
+						// add hidden input to indicate that a new state is being added
211
+						'add_new_state'               => new EE_Hidden_Input(
212
+							array(
213
+								'html_name' => str_replace(
214
+									'state',
215
+									'nsmf_add_new_state',
216
+									$input->html_name()
217
+								),
218
+								'html_id'   => str_replace(
219
+									'state',
220
+									'nsmf_add_new_state',
221
+									$input->html_id()
222
+								),
223
+								'default'   => 0,
224
+							)
225
+						),
226
+						// add link for displaying hidden container
227
+						'click_here_link'             => new EE_Form_Section_HTML(
228
+							apply_filters(
229
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
230
+								EEH_HTML::link(
231
+									'',
232
+									esc_html__('click here to add a new state/province', 'event_espresso'),
233
+									'',
234
+									'display-' . $input->html_id(),
235
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
236
+									'',
237
+									'data-target="' . $input->html_id() . '"'
238
+								)
239
+							)
240
+						),
241
+						// add initial html for hidden container
242
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
243
+							apply_filters(
244
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
245
+								EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
246
+									'display: none;') .
247
+								EEH_HTML::h6(
248
+									esc_html__(
249
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
250
+										'event_espresso'
251
+									)
252
+								) .
253
+								EEH_HTML::ul() .
254
+								EEH_HTML::li(
255
+									esc_html__(
256
+										'first select the Country that your State/Province belongs to',
257
+										'event_espresso'
258
+									)
259
+								) .
260
+								EEH_HTML::li(
261
+									esc_html__('enter the name of your State/Province', 'event_espresso')
262
+								) .
263
+								EEH_HTML::li(
264
+									esc_html__(
265
+										'enter a two to six letter abbreviation for the name of your State/Province',
266
+										'event_espresso'
267
+									)
268
+								) .
269
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
270
+								EEH_HTML::ulx()
271
+							)
272
+						),
273
+						// NEW STATE COUNTRY
274
+						'new_state_country'           => new EE_Country_Select_Input(
275
+							$country_options,
276
+							array(
277
+								'html_name'       => $country_name,
278
+								'html_id'         => str_replace(
279
+									'state',
280
+									'nsmf_new_state_country', $input->html_id()
281
+								),
282
+								'html_class'      => $input->html_class() . ' new-state-country',
283
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
284
+								'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
285
+								'required'        => false,
286
+							)
287
+						),
288
+						// NEW STATE NAME
289
+						'new_state_name'              => new EE_Text_Input(
290
+							array(
291
+								'html_name'       => $state_name,
292
+								'html_id'         => str_replace(
293
+									'state',
294
+									'nsmf_new_state_name', $input->html_id()
295
+								),
296
+								'html_class'      => $input->html_class() . ' new-state-state',
297
+								'html_label_text' => esc_html__('New State/Province Name',
298
+									'event_espresso'),
299
+								'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
300
+								'required'        => false,
301
+							)
302
+						),
303
+						'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
304
+						// NEW STATE NAME
305
+						'new_state_abbrv'             => new EE_Text_Input(
306
+							array(
307
+								'html_name'             => $abbrv_name,
308
+								'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
309
+									$input->html_id()),
310
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
311
+								'html_label_text'       => esc_html__(
312
+															   'New State/Province Abbreviation',
313
+															   'event_espresso'
314
+														   ) . ' *',
315
+								'html_other_attributes' => 'size="24"',
316
+								'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
317
+								'required'              => false,
318
+							)
319
+						),
320
+						// "submit" button
321
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
322
+							apply_filters(
323
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
324
+								EEH_HTML::nbsp(3) .
325
+								EEH_HTML::link(
326
+									'',
327
+									esc_html__('ADD', 'event_espresso'),
328
+									'',
329
+									'submit-' . $new_state_submit_id,
330
+									'ee-form-add-new-state-submit button button-secondary',
331
+									'',
332
+									'data-target="' . $new_state_submit_id . '"'
333
+								)
334
+							)
335
+						),
336
+						// extra info
337
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
338
+							apply_filters(
339
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
340
+								EEH_HTML::br(2)
341
+								.
342
+								EEH_HTML::div('', '', 'small-text')
343
+								.
344
+								EEH_HTML::strong(
345
+									'* ' .
346
+									esc_html__(
347
+										'Don\'t know your State/Province Abbreviation?',
348
+										'event_espresso'
349
+									)
350
+								)
351
+								.
352
+								EEH_HTML::br()
353
+								.
354
+								sprintf(
355
+									esc_html__(
356
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
357
+										'event_espresso'
358
+									),
359
+									EEH_HTML::link(
360
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
361
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
362
+										'',
363
+										'',
364
+										'ee-form-add-new-state-wiki-lnk',
365
+										'',
366
+										'target="_blank"'
367
+									)
368
+								)
369
+								.
370
+								EEH_HTML::divx()
371
+								.
372
+								EEH_HTML::br()
373
+								.
374
+								EEH_HTML::link(
375
+									'',
376
+									esc_html__('cancel new State/Province', 'event_espresso'),
377
+									'',
378
+									'hide-' . $input->html_id(),
379
+									'ee-form-cancel-new-state-lnk smaller-text',
380
+									'',
381
+									'data-target="' . $input->html_id() . '"'
382
+								)
383
+								.
384
+								EEH_HTML::divx()
385
+								.
386
+								EEH_HTML::br()
387
+							)
388
+						),
389
+					),
390
+				)
391
+			);
392
+			$question_group_reg_form->add_subsections(
393
+				array('new_state_micro_form' => $new_state_micro_form),
394
+				'state',
395
+				false
396
+			);
397
+		}
398
+		return $question_group_reg_form;
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * set_new_state_input_width
405
+	 *
406
+	 * @return int|string
407
+	 * @throws EE_Error
408
+	 * @throws InvalidArgumentException
409
+	 * @throws InvalidDataTypeException
410
+	 * @throws InvalidInterfaceException
411
+	 * @throws ReflectionException
412
+	 */
413
+	public static function add_new_state()
414
+	{
415
+		$REQ = EE_Registry::instance()->load_core('Request_Handler');
416
+		if (absint($REQ->get('nsmf_add_new_state')) === 1) {
417
+			EE_Registry::instance()->load_model('State');
418
+			// grab country ISO code, new state name, and new state abbreviation
419
+			$state_country = $REQ->is_set('nsmf_new_state_country')
420
+				? sanitize_text_field($REQ->get('nsmf_new_state_country'))
421
+				: false;
422
+			$state_name    = $REQ->is_set('nsmf_new_state_name')
423
+				? sanitize_text_field($REQ->get('nsmf_new_state_name'))
424
+				: false;
425
+			$state_abbr    = $REQ->is_set('nsmf_new_state_abbrv')
426
+				? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
427
+				: false;
428
+			if ($state_country && $state_name && $state_abbr) {
429
+				$new_state = EED_Add_New_State::save_new_state_to_db(array(
430
+					'CNT_ISO'    => strtoupper($state_country),
431
+					'STA_abbrev' => strtoupper($state_abbr),
432
+					'STA_name'   => ucwords($state_name),
433
+					'STA_active' => false,
434
+				));
435
+				if ($new_state instanceof EE_State) {
436
+					// clean house
437
+					EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
438
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
439
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
440
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
441
+					// get any existing new states
442
+					$new_states                   = EE_Registry::instance()->SSN->get_session_data(
443
+						'nsmf_new_states'
444
+					);
445
+					$new_states[$new_state->ID()] = $new_state;
446
+					EE_Registry::instance()->SSN->set_session_data(
447
+						array('nsmf_new_states' => $new_states)
448
+					);
449
+					if (EE_Registry::instance()->REQ->ajax) {
450
+						echo wp_json_encode(array(
451
+							'success'      => true,
452
+							'id'           => $new_state->ID(),
453
+							'name'         => $new_state->name(),
454
+							'abbrev'       => $new_state->abbrev(),
455
+							'country_iso'  => $new_state->country_iso(),
456
+							'country_name' => $new_state->country()->name(),
457
+						));
458
+						exit();
459
+					}
460
+					return $new_state->ID();
461
+				}
462
+			} else {
463
+				$error = esc_html__(
464
+					'A new State/Province could not be added because invalid or missing data was received.',
465
+					'event_espresso'
466
+				);
467
+				if (EE_Registry::instance()->REQ->ajax) {
468
+					echo wp_json_encode(array('error' => $error));
469
+					exit();
470
+				}
471
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
472
+			}
473
+		}
474
+		return false;
475
+	}
476
+
477
+
478
+
479
+	/**
480
+	 * recursively drills down through request params to remove any that were added by this module
481
+	 *
482
+	 * @param array $request_params
483
+	 * @return array
484
+	 */
485
+	public static function filter_checkout_request_params($request_params)
486
+	{
487
+		foreach ($request_params as $form_section) {
488
+			if (is_array($form_section)) {
489
+				EED_Add_New_State::unset_new_state_request_params($form_section);
490
+				EED_Add_New_State::filter_checkout_request_params($form_section);
491
+			}
492
+		}
493
+		return $request_params;
494
+	}
495
+
496
+
497
+
498
+	/**
499
+	 * @param array $request_params
500
+	 * @return array
501
+	 */
502
+	public static function unset_new_state_request_params($request_params)
503
+	{
504
+		unset(
505
+			$request_params['new_state_micro_form'],
506
+			$request_params['new_state_micro_add_new_state'],
507
+			$request_params['new_state_micro_new_state_country'],
508
+			$request_params['new_state_micro_new_state_name'],
509
+			$request_params['new_state_micro_new_state_abbrv']
510
+		);
511
+		return $request_params;
512
+	}
513
+
514
+
515
+
516
+	/**
517
+	 * @param array $props_n_values
518
+	 * @return bool
519
+	 * @throws EE_Error
520
+	 * @throws InvalidArgumentException
521
+	 * @throws InvalidDataTypeException
522
+	 * @throws InvalidInterfaceException
523
+	 */
524
+	public static function save_new_state_to_db($props_n_values = array())
525
+	{
526
+		$existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
527
+		if (! empty($existing_state)) {
528
+			return array_pop($existing_state);
529
+		}
530
+		$new_state = EE_State::new_instance($props_n_values);
531
+		if ($new_state instanceof EE_State) {
532
+			// if not non-ajax admin
533
+			$new_state_key    = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
534
+			$new_state_notice = sprintf(
535
+				esc_html__(
536
+					'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
537
+					'event_espresso'
538
+				),
539
+				'<b>' . $new_state->name() . '</b>',
540
+				'<b>' . $new_state->abbrev() . '</b>',
541
+				'<b>' . $new_state->country()->name() . '</b>',
542
+				'<a href="' . add_query_arg(array(
543
+					'page'    => 'espresso_general_settings',
544
+					'action'  => 'country_settings',
545
+					'country' => $new_state->country_iso(),
546
+				), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
547
+					'event_espresso') . '</a>',
548
+				'<br />'
549
+			);
550
+			EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
551
+			$new_state->save();
552
+			EEM_State::instance()->reset_cached_states();
553
+			return $new_state;
554
+		}
555
+		return false;
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 * @param string $CNT_ISO
562
+	 * @param string $STA_ID
563
+	 * @param array  $cols_n_values
564
+	 * @return void
565
+	 * @throws EE_Error
566
+	 * @throws InvalidArgumentException
567
+	 * @throws InvalidDataTypeException
568
+	 * @throws InvalidInterfaceException
569
+	 */
570
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
571
+	{
572
+		if (! $CNT_ISO) {
573
+			EE_Error::add_error(
574
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
575
+				__FILE__,
576
+				__FUNCTION__,
577
+				__LINE__
578
+			);
579
+		}
580
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
581
+			: false;
582
+		if (! $STA_abbrev && ! empty($STA_ID)) {
583
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
584
+			if ($state instanceof EE_State) {
585
+				$STA_abbrev = $state->abbrev();
586
+			}
587
+		}
588
+		if (! $STA_abbrev) {
589
+			EE_Error::add_error(
590
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
591
+				__FILE__,
592
+				__FUNCTION__,
593
+				__LINE__
594
+			);
595
+		}
596
+		EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
597
+	}
598
+
599
+
600
+
601
+	/**
602
+	 * @param EE_State[]                            $state_options
603
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
604
+	 * @param EE_Registration                       $registration
605
+	 * @param EE_Question                           $question
606
+	 * @param                                       $answer
607
+	 * @return array
608
+	 * @throws EE_Error
609
+	 * @throws InvalidArgumentException
610
+	 * @throws InvalidDataTypeException
611
+	 * @throws InvalidInterfaceException
612
+	 */
613
+	public static function inject_new_reg_state_into_options(
614
+		$state_options = array(),
615
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
616
+		EE_Registration $registration,
617
+		EE_Question $question,
618
+		$answer
619
+	) {
620
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
621
+			&& $question->type() === EEM_Question::QST_type_state
622
+		) {
623
+			$STA_ID = $answer->value();
624
+			if (! empty($STA_ID)) {
625
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
626
+				if ($state instanceof EE_State) {
627
+					$country = $state->country();
628
+					if ($country instanceof EE_Country) {
629
+						if (! isset($state_options[$country->name()])) {
630
+							$state_options[$country->name()] = array();
631
+						}
632
+						if (! isset($state_options[$country->name()][$STA_ID])) {
633
+							$state_options[$country->name()][$STA_ID] = $state->name();
634
+						}
635
+					}
636
+				}
637
+			}
638
+		}
639
+		return $state_options;
640
+	}
641
+
642
+
643
+
644
+	/**
645
+	 * @param EE_Country[]                          $country_options
646
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
647
+	 * @param EE_Registration                       $registration
648
+	 * @param EE_Question                           $question
649
+	 * @param                                       $answer
650
+	 * @return array
651
+	 * @throws EE_Error
652
+	 * @throws InvalidArgumentException
653
+	 * @throws InvalidDataTypeException
654
+	 * @throws InvalidInterfaceException
655
+	 */
656
+	public static function inject_new_reg_country_into_options(
657
+		$country_options = array(),
658
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
659
+		EE_Registration $registration,
660
+		EE_Question $question,
661
+		$answer
662
+	) {
663
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
664
+			&& $question->type()
665
+			   === EEM_Question::QST_type_country
666
+		) {
667
+			$CNT_ISO = $answer->value();
668
+			if (! empty($CNT_ISO)) {
669
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
670
+				if ($country instanceof EE_Country) {
671
+					if (! isset($country_options[$CNT_ISO])) {
672
+						$country_options[$CNT_ISO] = $country->name();
673
+					}
674
+				}
675
+			}
676
+		}
677
+		return $country_options;
678
+	}
679
+
680
+
681
+
682
+	/**
683
+	 * @param EE_State[] $state_options
684
+	 * @return array
685
+	 * @throws EE_Error
686
+	 * @throws InvalidArgumentException
687
+	 * @throws InvalidDataTypeException
688
+	 * @throws InvalidInterfaceException
689
+	 */
690
+	public static function state_options($state_options = array())
691
+	{
692
+		$new_states = EED_Add_New_State::_get_new_states();
693
+		foreach ($new_states as $new_state) {
694
+			if (
695
+				$new_state instanceof EE_State
696
+				&& $new_state->country() instanceof EE_Country
697
+			) {
698
+				$state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
699
+			}
700
+		}
701
+		return $state_options;
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 * @return array
708
+	 * @throws InvalidArgumentException
709
+	 * @throws InvalidDataTypeException
710
+	 * @throws InvalidInterfaceException
711
+	 */
712
+	protected static function _get_new_states()
713
+	{
714
+		$new_states = array();
715
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
716
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
717
+				'nsmf_new_states'
718
+			);
719
+		}
720
+		return is_array($new_states) ? $new_states : array();
721
+	}
722
+
723
+
724
+
725
+	/**
726
+	 * @param EE_Country[] $country_options
727
+	 * @return array
728
+	 * @throws EE_Error
729
+	 * @throws InvalidArgumentException
730
+	 * @throws InvalidDataTypeException
731
+	 * @throws InvalidInterfaceException
732
+	 */
733
+	public static function country_options($country_options = array())
734
+	{
735
+		$new_states = EED_Add_New_State::_get_new_states();
736
+		foreach ($new_states as $new_state) {
737
+			if (
738
+				$new_state instanceof EE_State
739
+				&& $new_state->country() instanceof EE_Country
740
+			) {
741
+				$country_options[$new_state->country()->ID()] = $new_state->country()->name();
742
+			}
743
+		}
744
+		return $country_options;
745
+	}
746 746
 
747 747
 
748 748
 
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public static function set_definitions()
98 98
     {
99
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
99
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
100 100
         define('ANS_TEMPLATES_PATH', str_replace(
101 101
                                          '\\',
102 102
                                          DS,
103
-                                         plugin_dir_path(__FILE__)) . 'templates' . DS
103
+                                         plugin_dir_path(__FILE__)).'templates'.DS
104 104
         );
105 105
     }
106 106
 
@@ -121,19 +121,19 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public static function translate_js_strings()
123 123
     {
124
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
124
+        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
125 125
             'In order to proceed, you need to select the Country that your State/Province belongs to.',
126 126
             'event_espresso'
127 127
         );
128
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
128
+        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
129 129
             'In order to proceed, you need to enter the name of your State/Province.',
130 130
             'event_espresso'
131 131
         );
132
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
132
+        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
133 133
             'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
134 134
             'event_espresso'
135 135
         );
136
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
136
+        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
137 137
             'The new state was successfully saved to the database.',
138 138
             'event_espresso'
139 139
         );
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     public static function wp_enqueue_scripts()
152 152
     {
153 153
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
154
-            wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
154
+            wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js',
155 155
                 array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
156 156
             wp_enqueue_script('add_new_state');
157 157
         }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
195 195
             $country_options     = array();
196 196
             $countries           = EEM_Country::instance()->get_all_countries();
197
-            if (! empty($countries)) {
197
+            if ( ! empty($countries)) {
198 198
                 foreach ($countries as $country) {
199 199
                     if ($country instanceof EE_Country) {
200 200
                         $country_options[$country->ID()] = $country->name();
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
                                     '',
232 232
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
233 233
                                     '',
234
-                                    'display-' . $input->html_id(),
234
+                                    'display-'.$input->html_id(),
235 235
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
236 236
                                     '',
237
-                                    'data-target="' . $input->html_id() . '"'
237
+                                    'data-target="'.$input->html_id().'"'
238 238
                                 )
239 239
                             )
240 240
                         ),
@@ -242,31 +242,31 @@  discard block
 block discarded – undo
242 242
                         'add_new_state_micro_form'    => new EE_Form_Section_HTML(
243 243
                             apply_filters(
244 244
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
245
-                                EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
246
-                                    'display: none;') .
245
+                                EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv',
246
+                                    'display: none;').
247 247
                                 EEH_HTML::h6(
248 248
                                     esc_html__(
249 249
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
250 250
                                         'event_espresso'
251 251
                                     )
252
-                                ) .
253
-                                EEH_HTML::ul() .
252
+                                ).
253
+                                EEH_HTML::ul().
254 254
                                 EEH_HTML::li(
255 255
                                     esc_html__(
256 256
                                         'first select the Country that your State/Province belongs to',
257 257
                                         'event_espresso'
258 258
                                     )
259
-                                ) .
259
+                                ).
260 260
                                 EEH_HTML::li(
261 261
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
262
-                                ) .
262
+                                ).
263 263
                                 EEH_HTML::li(
264 264
                                     esc_html__(
265 265
                                         'enter a two to six letter abbreviation for the name of your State/Province',
266 266
                                         'event_espresso'
267 267
                                     )
268
-                                ) .
269
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
268
+                                ).
269
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
270 270
                                 EEH_HTML::ulx()
271 271
                             )
272 272
                         ),
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                                     'state',
280 280
                                     'nsmf_new_state_country', $input->html_id()
281 281
                                 ),
282
-                                'html_class'      => $input->html_class() . ' new-state-country',
282
+                                'html_class'      => $input->html_class().' new-state-country',
283 283
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
284 284
                                 'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
285 285
                                 'required'        => false,
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
                                     'state',
294 294
                                     'nsmf_new_state_name', $input->html_id()
295 295
                                 ),
296
-                                'html_class'      => $input->html_class() . ' new-state-state',
296
+                                'html_class'      => $input->html_class().' new-state-state',
297 297
                                 'html_label_text' => esc_html__('New State/Province Name',
298 298
                                     'event_espresso'),
299 299
                                 'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
@@ -307,11 +307,11 @@  discard block
 block discarded – undo
307 307
                                 'html_name'             => $abbrv_name,
308 308
                                 'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
309 309
                                     $input->html_id()),
310
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
310
+                                'html_class'            => $input->html_class().' new-state-abbrv',
311 311
                                 'html_label_text'       => esc_html__(
312 312
                                                                'New State/Province Abbreviation',
313 313
                                                                'event_espresso'
314
-                                                           ) . ' *',
314
+                                                           ).' *',
315 315
                                 'html_other_attributes' => 'size="24"',
316 316
                                 'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
317 317
                                 'required'              => false,
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
                         'add_new_state_submit_button' => new EE_Form_Section_HTML(
322 322
                             apply_filters(
323 323
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
324
-                                EEH_HTML::nbsp(3) .
324
+                                EEH_HTML::nbsp(3).
325 325
                                 EEH_HTML::link(
326 326
                                     '',
327 327
                                     esc_html__('ADD', 'event_espresso'),
328 328
                                     '',
329
-                                    'submit-' . $new_state_submit_id,
329
+                                    'submit-'.$new_state_submit_id,
330 330
                                     'ee-form-add-new-state-submit button button-secondary',
331 331
                                     '',
332
-                                    'data-target="' . $new_state_submit_id . '"'
332
+                                    'data-target="'.$new_state_submit_id.'"'
333 333
                                 )
334 334
                             )
335 335
                         ),
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                                 EEH_HTML::div('', '', 'small-text')
343 343
                                 .
344 344
                                 EEH_HTML::strong(
345
-                                    '* ' .
345
+                                    '* '.
346 346
                                     esc_html__(
347 347
                                         'Don\'t know your State/Province Abbreviation?',
348 348
                                         'event_espresso'
@@ -375,10 +375,10 @@  discard block
 block discarded – undo
375 375
                                     '',
376 376
                                     esc_html__('cancel new State/Province', 'event_espresso'),
377 377
                                     '',
378
-                                    'hide-' . $input->html_id(),
378
+                                    'hide-'.$input->html_id(),
379 379
                                     'ee-form-cancel-new-state-lnk smaller-text',
380 380
                                     '',
381
-                                    'data-target="' . $input->html_id() . '"'
381
+                                    'data-target="'.$input->html_id().'"'
382 382
                                 )
383 383
                                 .
384 384
                                 EEH_HTML::divx()
@@ -524,27 +524,27 @@  discard block
 block discarded – undo
524 524
     public static function save_new_state_to_db($props_n_values = array())
525 525
     {
526 526
         $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
527
-        if (! empty($existing_state)) {
527
+        if ( ! empty($existing_state)) {
528 528
             return array_pop($existing_state);
529 529
         }
530 530
         $new_state = EE_State::new_instance($props_n_values);
531 531
         if ($new_state instanceof EE_State) {
532 532
             // if not non-ajax admin
533
-            $new_state_key    = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
533
+            $new_state_key    = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev();
534 534
             $new_state_notice = sprintf(
535 535
                 esc_html__(
536 536
                     'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
537 537
                     'event_espresso'
538 538
                 ),
539
-                '<b>' . $new_state->name() . '</b>',
540
-                '<b>' . $new_state->abbrev() . '</b>',
541
-                '<b>' . $new_state->country()->name() . '</b>',
542
-                '<a href="' . add_query_arg(array(
539
+                '<b>'.$new_state->name().'</b>',
540
+                '<b>'.$new_state->abbrev().'</b>',
541
+                '<b>'.$new_state->country()->name().'</b>',
542
+                '<a href="'.add_query_arg(array(
543 543
                     'page'    => 'espresso_general_settings',
544 544
                     'action'  => 'country_settings',
545 545
                     'country' => $new_state->country_iso(),
546
-                ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
547
-                    'event_espresso') . '</a>',
546
+                ), admin_url('admin.php')).'">'.esc_html__('Event Espresso - General Settings > Countries Tab',
547
+                    'event_espresso').'</a>',
548 548
                 '<br />'
549 549
             );
550 550
             EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
      */
570 570
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
571 571
     {
572
-        if (! $CNT_ISO) {
572
+        if ( ! $CNT_ISO) {
573 573
             EE_Error::add_error(
574 574
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
575 575
                 __FILE__,
@@ -579,13 +579,13 @@  discard block
 block discarded – undo
579 579
         }
580 580
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
581 581
             : false;
582
-        if (! $STA_abbrev && ! empty($STA_ID)) {
582
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
583 583
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
584 584
             if ($state instanceof EE_State) {
585 585
                 $STA_abbrev = $state->abbrev();
586 586
             }
587 587
         }
588
-        if (! $STA_abbrev) {
588
+        if ( ! $STA_abbrev) {
589 589
             EE_Error::add_error(
590 590
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
591 591
                 __FILE__,
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
                 __LINE__
594 594
             );
595 595
         }
596
-        EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
596
+        EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true);
597 597
     }
598 598
 
599 599
 
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
             && $question->type() === EEM_Question::QST_type_state
622 622
         ) {
623 623
             $STA_ID = $answer->value();
624
-            if (! empty($STA_ID)) {
624
+            if ( ! empty($STA_ID)) {
625 625
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
626 626
                 if ($state instanceof EE_State) {
627 627
                     $country = $state->country();
628 628
                     if ($country instanceof EE_Country) {
629
-                        if (! isset($state_options[$country->name()])) {
629
+                        if ( ! isset($state_options[$country->name()])) {
630 630
                             $state_options[$country->name()] = array();
631 631
                         }
632
-                        if (! isset($state_options[$country->name()][$STA_ID])) {
632
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
633 633
                             $state_options[$country->name()][$STA_ID] = $state->name();
634 634
                         }
635 635
                     }
@@ -665,10 +665,10 @@  discard block
 block discarded – undo
665 665
                === EEM_Question::QST_type_country
666 666
         ) {
667 667
             $CNT_ISO = $answer->value();
668
-            if (! empty($CNT_ISO)) {
668
+            if ( ! empty($CNT_ISO)) {
669 669
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
670 670
                 if ($country instanceof EE_Country) {
671
-                    if (! isset($country_options[$CNT_ISO])) {
671
+                    if ( ! isset($country_options[$CNT_ISO])) {
672 672
                         $country_options[$CNT_ISO] = $country->name();
673 673
                     }
674 674
                 }
Please login to merge, or discard this patch.