Completed
Branch BUG/11211/html-entities-being-... (812cda)
by
unknown
43:24 queued 33:00
created
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4071 added lines, -4071 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,2554 +23,2554 @@  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
-     * @throws EE_Error
81
-     */
82
-    public function __construct($routing = true)
83
-    {
84
-        //make sure messages autoloader is running
85
-        EED_Messages::set_autoloaders();
86
-        parent::__construct($routing);
87
-    }
78
+	/**
79
+	 * @param bool $routing
80
+	 * @throws EE_Error
81
+	 */
82
+	public function __construct($routing = true)
83
+	{
84
+		//make sure messages autoloader is running
85
+		EED_Messages::set_autoloaders();
86
+		parent::__construct($routing);
87
+	}
88 88
     
89 89
     
90
-    protected function _init_page_props()
91
-    {
92
-        $this->page_slug        = EE_MSG_PG_SLUG;
93
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
-        $this->_admin_base_path = EE_MSG_ADMIN;
96
-        
97
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
-        
99
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
-        $this->_load_message_resource_manager();
101
-    }
90
+	protected function _init_page_props()
91
+	{
92
+		$this->page_slug        = EE_MSG_PG_SLUG;
93
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
+		$this->_admin_base_path = EE_MSG_ADMIN;
96
+        
97
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
+        
99
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
+		$this->_load_message_resource_manager();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
-     *
107
-     * @throws EE_Error
108
-     * @throws InvalidDataTypeException
109
-     * @throws InvalidInterfaceException
110
-     * @throws InvalidArgumentException
111
-     * @throws ReflectionException
112
-     */
113
-    protected function _load_message_resource_manager()
114
-    {
115
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
-    }
104
+	/**
105
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
+	 *
107
+	 * @throws EE_Error
108
+	 * @throws InvalidDataTypeException
109
+	 * @throws InvalidInterfaceException
110
+	 * @throws InvalidArgumentException
111
+	 * @throws ReflectionException
112
+	 */
113
+	protected function _load_message_resource_manager()
114
+	{
115
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * @deprecated 4.9.9.rc.014
121
-     * @return array
122
-     * @throws EE_Error
123
-     * @throws InvalidArgumentException
124
-     * @throws InvalidDataTypeException
125
-     * @throws InvalidInterfaceException
126
-     */
127
-    public function get_messengers_for_list_table()
128
-    {
129
-        EE_Error::doing_it_wrong(
130
-            __METHOD__,
131
-            sprintf(
132
-                esc_html__(
133
-                    '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',
134
-                    'event_espresso'
135
-                ),
136
-                'Messages_Admin_Page::get_messengers_select_input()'
137
-            ),
138
-            '4.9.9.rc.014'
139
-        );
140
-        
141
-        $m_values          = array();
142
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
-        //setup messengers for selects
144
-        $i = 1;
145
-        foreach ($active_messengers as $active_messenger) {
146
-            if ($active_messenger instanceof EE_Message) {
147
-                $m_values[$i]['id']   = $active_messenger->messenger();
148
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
-                $i++;
150
-            }
151
-        }
152
-        
153
-        return $m_values;
154
-    }
119
+	/**
120
+	 * @deprecated 4.9.9.rc.014
121
+	 * @return array
122
+	 * @throws EE_Error
123
+	 * @throws InvalidArgumentException
124
+	 * @throws InvalidDataTypeException
125
+	 * @throws InvalidInterfaceException
126
+	 */
127
+	public function get_messengers_for_list_table()
128
+	{
129
+		EE_Error::doing_it_wrong(
130
+			__METHOD__,
131
+			sprintf(
132
+				esc_html__(
133
+					'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',
134
+					'event_espresso'
135
+				),
136
+				'Messages_Admin_Page::get_messengers_select_input()'
137
+			),
138
+			'4.9.9.rc.014'
139
+		);
140
+        
141
+		$m_values          = array();
142
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
+		//setup messengers for selects
144
+		$i = 1;
145
+		foreach ($active_messengers as $active_messenger) {
146
+			if ($active_messenger instanceof EE_Message) {
147
+				$m_values[$i]['id']   = $active_messenger->messenger();
148
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
+				$i++;
150
+			}
151
+		}
152
+        
153
+		return $m_values;
154
+	}
155 155
 
156 156
 
157
-    /**
158
-     * @deprecated 4.9.9.rc.014
159
-     * @return array
160
-     * @throws EE_Error
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     */
165
-    public function get_message_types_for_list_table()
166
-    {
167
-        EE_Error::doing_it_wrong(
168
-            __METHOD__,
169
-            sprintf(
170
-                esc_html__(
171
-                    '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',
172
-                    'event_espresso'
173
-                ),
174
-                'Messages_Admin_Page::get_message_types_select_input()'
175
-            ),
176
-            '4.9.9.rc.014'
177
-        );
178
-        
179
-        $mt_values       = array();
180
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
-        $i               = 1;
182
-        foreach ($active_messages as $active_message) {
183
-            if ($active_message instanceof EE_Message) {
184
-                $mt_values[$i]['id']   = $active_message->message_type();
185
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
-                $i++;
187
-            }
188
-        }
189
-        
190
-        return $mt_values;
191
-    }
157
+	/**
158
+	 * @deprecated 4.9.9.rc.014
159
+	 * @return array
160
+	 * @throws EE_Error
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 */
165
+	public function get_message_types_for_list_table()
166
+	{
167
+		EE_Error::doing_it_wrong(
168
+			__METHOD__,
169
+			sprintf(
170
+				esc_html__(
171
+					'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',
172
+					'event_espresso'
173
+				),
174
+				'Messages_Admin_Page::get_message_types_select_input()'
175
+			),
176
+			'4.9.9.rc.014'
177
+		);
178
+        
179
+		$mt_values       = array();
180
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
+		$i               = 1;
182
+		foreach ($active_messages as $active_message) {
183
+			if ($active_message instanceof EE_Message) {
184
+				$mt_values[$i]['id']   = $active_message->message_type();
185
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
+				$i++;
187
+			}
188
+		}
189
+        
190
+		return $mt_values;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * @deprecated 4.9.9.rc.014
196
-     * @return array
197
-     * @throws EE_Error
198
-     * @throws InvalidArgumentException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     */
202
-    public function get_contexts_for_message_types_for_list_table()
203
-    {
204
-        EE_Error::doing_it_wrong(
205
-            __METHOD__,
206
-            sprintf(
207
-                esc_html__(
208
-                    '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',
209
-                    'event_espresso'
210
-                ),
211
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
-            ),
213
-            '4.9.9.rc.014'
214
-        );
215
-        
216
-        $contexts                = array();
217
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
-        foreach ($active_message_contexts as $active_message) {
219
-            if ($active_message instanceof EE_Message) {
220
-                $message_type = $active_message->message_type_object();
221
-                if ($message_type instanceof EE_message_type) {
222
-                    $message_type_contexts = $message_type->get_contexts();
223
-                    foreach ($message_type_contexts as $context => $context_details) {
224
-                        $contexts[$context] = $context_details['label'];
225
-                    }
226
-                }
227
-            }
228
-        }
229
-        
230
-        return $contexts;
231
-    }
194
+	/**
195
+	 * @deprecated 4.9.9.rc.014
196
+	 * @return array
197
+	 * @throws EE_Error
198
+	 * @throws InvalidArgumentException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 */
202
+	public function get_contexts_for_message_types_for_list_table()
203
+	{
204
+		EE_Error::doing_it_wrong(
205
+			__METHOD__,
206
+			sprintf(
207
+				esc_html__(
208
+					'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',
209
+					'event_espresso'
210
+				),
211
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
+			),
213
+			'4.9.9.rc.014'
214
+		);
215
+        
216
+		$contexts                = array();
217
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
+		foreach ($active_message_contexts as $active_message) {
219
+			if ($active_message instanceof EE_Message) {
220
+				$message_type = $active_message->message_type_object();
221
+				if ($message_type instanceof EE_message_type) {
222
+					$message_type_contexts = $message_type->get_contexts();
223
+					foreach ($message_type_contexts as $context => $context_details) {
224
+						$contexts[$context] = $context_details['label'];
225
+					}
226
+				}
227
+			}
228
+		}
229
+        
230
+		return $contexts;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * Generate select input with provided messenger options array.
236
-     *
237
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
-     *                                 labels.
239
-     * @return string
240
-     * @throws EE_Error
241
-     */
242
-    public function get_messengers_select_input($messenger_options)
243
-    {
244
-        //if empty or just one value then just return an empty string
245
-        if (empty($messenger_options)
246
-            || ! is_array($messenger_options)
247
-            || count($messenger_options) === 1
248
-        ) {
249
-            return '';
250
-        }
251
-        //merge in default
252
-        $messenger_options = array_merge(
253
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
-            $messenger_options
255
-        );
256
-        $input             = new EE_Select_Input(
257
-            $messenger_options,
258
-            array(
259
-                'html_name'  => 'ee_messenger_filter_by',
260
-                'html_id'    => 'ee_messenger_filter_by',
261
-                'html_class' => 'wide',
262
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
-                    : 'none_selected'
265
-            )
266
-        );
267
-        
268
-        return $input->get_html_for_input();
269
-    }
234
+	/**
235
+	 * Generate select input with provided messenger options array.
236
+	 *
237
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
+	 *                                 labels.
239
+	 * @return string
240
+	 * @throws EE_Error
241
+	 */
242
+	public function get_messengers_select_input($messenger_options)
243
+	{
244
+		//if empty or just one value then just return an empty string
245
+		if (empty($messenger_options)
246
+			|| ! is_array($messenger_options)
247
+			|| count($messenger_options) === 1
248
+		) {
249
+			return '';
250
+		}
251
+		//merge in default
252
+		$messenger_options = array_merge(
253
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
+			$messenger_options
255
+		);
256
+		$input             = new EE_Select_Input(
257
+			$messenger_options,
258
+			array(
259
+				'html_name'  => 'ee_messenger_filter_by',
260
+				'html_id'    => 'ee_messenger_filter_by',
261
+				'html_class' => 'wide',
262
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
+					: 'none_selected'
265
+			)
266
+		);
267
+        
268
+		return $input->get_html_for_input();
269
+	}
270 270
 
271 271
 
272
-    /**
273
-     * Generate select input with provided message type options array.
274
-     *
275
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
-     *                                    message type labels
277
-     * @return string
278
-     * @throws EE_Error
279
-     */
280
-    public function get_message_types_select_input($message_type_options)
281
-    {
282
-        //if empty or count of options is 1 then just return an empty string
283
-        if (empty($message_type_options)
284
-            || ! is_array($message_type_options)
285
-            || count($message_type_options) === 1
286
-        ) {
287
-            return '';
288
-        }
289
-        //merge in default
290
-        $message_type_options = array_merge(
291
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
-            $message_type_options
293
-        );
294
-        $input                = new EE_Select_Input(
295
-            $message_type_options,
296
-            array(
297
-                'html_name'  => 'ee_message_type_filter_by',
298
-                'html_id'    => 'ee_message_type_filter_by',
299
-                'html_class' => 'wide',
300
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
-                    : 'none_selected',
303
-            )
304
-        );
305
-        
306
-        return $input->get_html_for_input();
307
-    }
272
+	/**
273
+	 * Generate select input with provided message type options array.
274
+	 *
275
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
+	 *                                    message type labels
277
+	 * @return string
278
+	 * @throws EE_Error
279
+	 */
280
+	public function get_message_types_select_input($message_type_options)
281
+	{
282
+		//if empty or count of options is 1 then just return an empty string
283
+		if (empty($message_type_options)
284
+			|| ! is_array($message_type_options)
285
+			|| count($message_type_options) === 1
286
+		) {
287
+			return '';
288
+		}
289
+		//merge in default
290
+		$message_type_options = array_merge(
291
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
+			$message_type_options
293
+		);
294
+		$input                = new EE_Select_Input(
295
+			$message_type_options,
296
+			array(
297
+				'html_name'  => 'ee_message_type_filter_by',
298
+				'html_id'    => 'ee_message_type_filter_by',
299
+				'html_class' => 'wide',
300
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
+					: 'none_selected',
303
+			)
304
+		);
305
+        
306
+		return $input->get_html_for_input();
307
+	}
308 308
 
309 309
 
310
-    /**
311
-     * Generate select input with provide message type contexts array.
312
-     *
313
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
-     *                               context label.
315
-     * @return string
316
-     * @throws EE_Error
317
-     */
318
-    public function get_contexts_for_message_types_select_input($context_options)
319
-    {
320
-        //if empty or count of options is one then just return empty string
321
-        if (empty($context_options)
322
-            || ! is_array($context_options)
323
-            || count($context_options) === 1
324
-        ) {
325
-            return '';
326
-        }
327
-        //merge in default
328
-        $context_options = array_merge(
329
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
-            $context_options
331
-        );
332
-        $input           = new EE_Select_Input(
333
-            $context_options,
334
-            array(
335
-                'html_name'  => 'ee_context_filter_by',
336
-                'html_id'    => 'ee_context_filter_by',
337
-                'html_class' => 'wide',
338
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
339
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
340
-                    : 'none_selected',
341
-            )
342
-        );
343
-        
344
-        return $input->get_html_for_input();
345
-    }
310
+	/**
311
+	 * Generate select input with provide message type contexts array.
312
+	 *
313
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
+	 *                               context label.
315
+	 * @return string
316
+	 * @throws EE_Error
317
+	 */
318
+	public function get_contexts_for_message_types_select_input($context_options)
319
+	{
320
+		//if empty or count of options is one then just return empty string
321
+		if (empty($context_options)
322
+			|| ! is_array($context_options)
323
+			|| count($context_options) === 1
324
+		) {
325
+			return '';
326
+		}
327
+		//merge in default
328
+		$context_options = array_merge(
329
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
+			$context_options
331
+		);
332
+		$input           = new EE_Select_Input(
333
+			$context_options,
334
+			array(
335
+				'html_name'  => 'ee_context_filter_by',
336
+				'html_id'    => 'ee_context_filter_by',
337
+				'html_class' => 'wide',
338
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
339
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
340
+					: 'none_selected',
341
+			)
342
+		);
343
+        
344
+		return $input->get_html_for_input();
345
+	}
346 346
     
347 347
     
348
-    protected function _ajax_hooks()
349
-    {
350
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
-    }
348
+	protected function _ajax_hooks()
349
+	{
350
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
+	}
357 357
     
358 358
     
359
-    protected function _define_page_props()
360
-    {
361
-        $this->_admin_page_title = $this->page_label;
362
-        $this->_labels           = array(
363
-            'buttons'    => array(
364
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
-                'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
-            ),
368
-            'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
-        );
370
-    }
359
+	protected function _define_page_props()
360
+	{
361
+		$this->_admin_page_title = $this->page_label;
362
+		$this->_labels           = array(
363
+			'buttons'    => array(
364
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
+				'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
+			),
368
+			'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
+		);
370
+	}
371 371
     
372 372
     
373
-    /**
374
-     *        an array for storing key => value pairs of request actions and their corresponding methods
375
-     * @access protected
376
-     * @return void
377
-     */
378
-    protected function _set_page_routes()
379
-    {
380
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
-            ? $this->_req_data['GRP_ID']
382
-            : 0;
383
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
-            ? $this->_req_data['id']
385
-            : $grp_id;
386
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
-            ? $this->_req_data['MSG_ID']
388
-            : 0;
389
-        
390
-        $this->_page_routes = array(
391
-            'default'                          => array(
392
-                'func'       => '_message_queue_list_table',
393
-                'capability' => 'ee_read_global_messages'
394
-            ),
395
-            'global_mtps'                      => array(
396
-                'func'       => '_ee_default_messages_overview_list_table',
397
-                'capability' => 'ee_read_global_messages'
398
-            ),
399
-            'custom_mtps'                      => array(
400
-                'func'       => '_custom_mtps_preview',
401
-                'capability' => 'ee_read_messages'
402
-            ),
403
-            'add_new_message_template'         => array(
404
-                'func'       => '_add_message_template',
405
-                'capability' => 'ee_edit_messages',
406
-                'noheader'   => true
407
-            ),
408
-            'edit_message_template'            => array(
409
-                'func'       => '_edit_message_template',
410
-                'capability' => 'ee_edit_message',
411
-                'obj_id'     => $grp_id
412
-            ),
413
-            'preview_message'                  => array(
414
-                'func'               => '_preview_message',
415
-                'capability'         => 'ee_read_message',
416
-                'obj_id'             => $grp_id,
417
-                'noheader'           => true,
418
-                'headers_sent_route' => 'display_preview_message'
419
-            ),
420
-            'display_preview_message'          => array(
421
-                'func'       => '_display_preview_message',
422
-                'capability' => 'ee_read_message',
423
-                'obj_id'     => $grp_id
424
-            ),
425
-            'insert_message_template'          => array(
426
-                'func'       => '_insert_or_update_message_template',
427
-                'capability' => 'ee_edit_messages',
428
-                'args'       => array('new_template' => true),
429
-                'noheader'   => true
430
-            ),
431
-            'update_message_template'          => array(
432
-                'func'       => '_insert_or_update_message_template',
433
-                'capability' => 'ee_edit_message',
434
-                'obj_id'     => $grp_id,
435
-                'args'       => array('new_template' => false),
436
-                'noheader'   => true
437
-            ),
438
-            'trash_message_template'           => array(
439
-                'func'       => '_trash_or_restore_message_template',
440
-                'capability' => 'ee_delete_message',
441
-                'obj_id'     => $grp_id,
442
-                'args'       => array('trash' => true, 'all' => true),
443
-                'noheader'   => true
444
-            ),
445
-            'trash_message_template_context'   => array(
446
-                'func'       => '_trash_or_restore_message_template',
447
-                'capability' => 'ee_delete_message',
448
-                'obj_id'     => $grp_id,
449
-                'args'       => array('trash' => true),
450
-                'noheader'   => true
451
-            ),
452
-            'restore_message_template'         => array(
453
-                'func'       => '_trash_or_restore_message_template',
454
-                'capability' => 'ee_delete_message',
455
-                'obj_id'     => $grp_id,
456
-                'args'       => array('trash' => false, 'all' => true),
457
-                'noheader'   => true
458
-            ),
459
-            'restore_message_template_context' => array(
460
-                'func'       => '_trash_or_restore_message_template',
461
-                'capability' => 'ee_delete_message',
462
-                'obj_id'     => $grp_id,
463
-                'args'       => array('trash' => false),
464
-                'noheader'   => true
465
-            ),
466
-            'delete_message_template'          => array(
467
-                'func'       => '_delete_message_template',
468
-                'capability' => 'ee_delete_message',
469
-                'obj_id'     => $grp_id,
470
-                'noheader'   => true
471
-            ),
472
-            'reset_to_default'                 => array(
473
-                'func'       => '_reset_to_default_template',
474
-                'capability' => 'ee_edit_message',
475
-                'obj_id'     => $grp_id,
476
-                'noheader'   => true
477
-            ),
478
-            'settings'                         => array(
479
-                'func'       => '_settings',
480
-                'capability' => 'manage_options'
481
-            ),
482
-            'update_global_settings'           => array(
483
-                'func'       => '_update_global_settings',
484
-                'capability' => 'manage_options',
485
-                'noheader'   => true
486
-            ),
487
-            'generate_now'                     => array(
488
-                'func'       => '_generate_now',
489
-                'capability' => 'ee_send_message',
490
-                'noheader'   => true
491
-            ),
492
-            'generate_and_send_now'            => array(
493
-                'func'       => '_generate_and_send_now',
494
-                'capability' => 'ee_send_message',
495
-                'noheader'   => true
496
-            ),
497
-            'queue_for_resending'              => array(
498
-                'func'       => '_queue_for_resending',
499
-                'capability' => 'ee_send_message',
500
-                'noheader'   => true
501
-            ),
502
-            'send_now'                         => array(
503
-                'func'       => '_send_now',
504
-                'capability' => 'ee_send_message',
505
-                'noheader'   => true
506
-            ),
507
-            'delete_ee_message'                => array(
508
-                'func'       => '_delete_ee_messages',
509
-                'capability' => 'ee_delete_messages',
510
-                'noheader'   => true
511
-            ),
512
-            'delete_ee_messages'               => array(
513
-                'func'       => '_delete_ee_messages',
514
-                'capability' => 'ee_delete_messages',
515
-                'noheader'   => true,
516
-                'obj_id'     => $msg_id
517
-            )
518
-        );
519
-    }
373
+	/**
374
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
375
+	 * @access protected
376
+	 * @return void
377
+	 */
378
+	protected function _set_page_routes()
379
+	{
380
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
+			? $this->_req_data['GRP_ID']
382
+			: 0;
383
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
+			? $this->_req_data['id']
385
+			: $grp_id;
386
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
+			? $this->_req_data['MSG_ID']
388
+			: 0;
389
+        
390
+		$this->_page_routes = array(
391
+			'default'                          => array(
392
+				'func'       => '_message_queue_list_table',
393
+				'capability' => 'ee_read_global_messages'
394
+			),
395
+			'global_mtps'                      => array(
396
+				'func'       => '_ee_default_messages_overview_list_table',
397
+				'capability' => 'ee_read_global_messages'
398
+			),
399
+			'custom_mtps'                      => array(
400
+				'func'       => '_custom_mtps_preview',
401
+				'capability' => 'ee_read_messages'
402
+			),
403
+			'add_new_message_template'         => array(
404
+				'func'       => '_add_message_template',
405
+				'capability' => 'ee_edit_messages',
406
+				'noheader'   => true
407
+			),
408
+			'edit_message_template'            => array(
409
+				'func'       => '_edit_message_template',
410
+				'capability' => 'ee_edit_message',
411
+				'obj_id'     => $grp_id
412
+			),
413
+			'preview_message'                  => array(
414
+				'func'               => '_preview_message',
415
+				'capability'         => 'ee_read_message',
416
+				'obj_id'             => $grp_id,
417
+				'noheader'           => true,
418
+				'headers_sent_route' => 'display_preview_message'
419
+			),
420
+			'display_preview_message'          => array(
421
+				'func'       => '_display_preview_message',
422
+				'capability' => 'ee_read_message',
423
+				'obj_id'     => $grp_id
424
+			),
425
+			'insert_message_template'          => array(
426
+				'func'       => '_insert_or_update_message_template',
427
+				'capability' => 'ee_edit_messages',
428
+				'args'       => array('new_template' => true),
429
+				'noheader'   => true
430
+			),
431
+			'update_message_template'          => array(
432
+				'func'       => '_insert_or_update_message_template',
433
+				'capability' => 'ee_edit_message',
434
+				'obj_id'     => $grp_id,
435
+				'args'       => array('new_template' => false),
436
+				'noheader'   => true
437
+			),
438
+			'trash_message_template'           => array(
439
+				'func'       => '_trash_or_restore_message_template',
440
+				'capability' => 'ee_delete_message',
441
+				'obj_id'     => $grp_id,
442
+				'args'       => array('trash' => true, 'all' => true),
443
+				'noheader'   => true
444
+			),
445
+			'trash_message_template_context'   => array(
446
+				'func'       => '_trash_or_restore_message_template',
447
+				'capability' => 'ee_delete_message',
448
+				'obj_id'     => $grp_id,
449
+				'args'       => array('trash' => true),
450
+				'noheader'   => true
451
+			),
452
+			'restore_message_template'         => array(
453
+				'func'       => '_trash_or_restore_message_template',
454
+				'capability' => 'ee_delete_message',
455
+				'obj_id'     => $grp_id,
456
+				'args'       => array('trash' => false, 'all' => true),
457
+				'noheader'   => true
458
+			),
459
+			'restore_message_template_context' => array(
460
+				'func'       => '_trash_or_restore_message_template',
461
+				'capability' => 'ee_delete_message',
462
+				'obj_id'     => $grp_id,
463
+				'args'       => array('trash' => false),
464
+				'noheader'   => true
465
+			),
466
+			'delete_message_template'          => array(
467
+				'func'       => '_delete_message_template',
468
+				'capability' => 'ee_delete_message',
469
+				'obj_id'     => $grp_id,
470
+				'noheader'   => true
471
+			),
472
+			'reset_to_default'                 => array(
473
+				'func'       => '_reset_to_default_template',
474
+				'capability' => 'ee_edit_message',
475
+				'obj_id'     => $grp_id,
476
+				'noheader'   => true
477
+			),
478
+			'settings'                         => array(
479
+				'func'       => '_settings',
480
+				'capability' => 'manage_options'
481
+			),
482
+			'update_global_settings'           => array(
483
+				'func'       => '_update_global_settings',
484
+				'capability' => 'manage_options',
485
+				'noheader'   => true
486
+			),
487
+			'generate_now'                     => array(
488
+				'func'       => '_generate_now',
489
+				'capability' => 'ee_send_message',
490
+				'noheader'   => true
491
+			),
492
+			'generate_and_send_now'            => array(
493
+				'func'       => '_generate_and_send_now',
494
+				'capability' => 'ee_send_message',
495
+				'noheader'   => true
496
+			),
497
+			'queue_for_resending'              => array(
498
+				'func'       => '_queue_for_resending',
499
+				'capability' => 'ee_send_message',
500
+				'noheader'   => true
501
+			),
502
+			'send_now'                         => array(
503
+				'func'       => '_send_now',
504
+				'capability' => 'ee_send_message',
505
+				'noheader'   => true
506
+			),
507
+			'delete_ee_message'                => array(
508
+				'func'       => '_delete_ee_messages',
509
+				'capability' => 'ee_delete_messages',
510
+				'noheader'   => true
511
+			),
512
+			'delete_ee_messages'               => array(
513
+				'func'       => '_delete_ee_messages',
514
+				'capability' => 'ee_delete_messages',
515
+				'noheader'   => true,
516
+				'obj_id'     => $msg_id
517
+			)
518
+		);
519
+	}
520 520
     
521 521
     
522
-    protected function _set_page_config()
523
-    {
524
-        $this->_page_config = array(
525
-            'default'                  => array(
526
-                'nav'           => array(
527
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
528
-                    'order' => 10
529
-                ),
530
-                'list_table'    => 'EE_Message_List_Table',
531
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
-                'require_nonce' => false
533
-            ),
534
-            'global_mtps'              => array(
535
-                'nav'           => array(
536
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
-                    'order' => 20
538
-                ),
539
-                'list_table'    => 'Messages_Template_List_Table',
540
-                'help_tabs'     => array(
541
-                    'messages_overview_help_tab'                                => array(
542
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
-                        'filename' => 'messages_overview'
544
-                    ),
545
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
546
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
-                        'filename' => 'messages_overview_table_column_headings'
548
-                    ),
549
-                    'messages_overview_messages_filters_help_tab'               => array(
550
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
551
-                        'filename' => 'messages_overview_filters'
552
-                    ),
553
-                    'messages_overview_messages_views_help_tab'                 => array(
554
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
555
-                        'filename' => 'messages_overview_views'
556
-                    ),
557
-                    'message_overview_message_types_help_tab'                   => array(
558
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
559
-                        'filename' => 'messages_overview_types'
560
-                    ),
561
-                    'messages_overview_messengers_help_tab'                     => array(
562
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
563
-                        'filename' => 'messages_overview_messengers',
564
-                    ),
565
-                ),
566
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
567
-                'require_nonce' => false
568
-            ),
569
-            'custom_mtps'              => array(
570
-                'nav'           => array(
571
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
-                    'order' => 30
573
-                ),
574
-                'help_tabs'     => array(),
575
-                'help_tour'     => array(),
576
-                'require_nonce' => false
577
-            ),
578
-            'add_new_message_template' => array(
579
-                'nav'           => array(
580
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
-                    'order'      => 5,
582
-                    'persistent' => false
583
-                ),
584
-                'require_nonce' => false
585
-            ),
586
-            'edit_message_template'    => array(
587
-                'labels'        => array(
588
-                    'buttons'    => array(
589
-                        'reset' => esc_html__('Reset Templates'),
590
-                    ),
591
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
-                ),
593
-                'nav'           => array(
594
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
-                    'order'      => 5,
596
-                    'persistent' => false,
597
-                    'url'        => ''
598
-                ),
599
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
-                'has_metaboxes' => true,
601
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
-                'help_tabs'     => array(
603
-                    'edit_message_template'       => array(
604
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
-                        'callback' => 'edit_message_template_help_tab'
606
-                    ),
607
-                    'message_templates_help_tab'  => array(
608
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
609
-                        'filename' => 'messages_templates'
610
-                    ),
611
-                    'message_template_shortcodes' => array(
612
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
-                        'callback' => 'message_template_shortcodes_help_tab'
614
-                    ),
615
-                    'message_preview_help_tab'    => array(
616
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
617
-                        'filename' => 'messages_preview'
618
-                    ),
619
-                    'messages_overview_other_help_tab'                          => array(
620
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
621
-                        'filename' => 'messages_overview_other',
622
-                    ),
623
-                ),
624
-                'require_nonce' => false
625
-            ),
626
-            'display_preview_message'  => array(
627
-                'nav'           => array(
628
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
629
-                    'order'      => 5,
630
-                    'url'        => '',
631
-                    'persistent' => false
632
-                ),
633
-                'help_tabs'     => array(
634
-                    'preview_message' => array(
635
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
636
-                        'callback' => 'preview_message_help_tab'
637
-                    )
638
-                ),
639
-                'require_nonce' => false
640
-            ),
641
-            'settings'                 => array(
642
-                'nav'           => array(
643
-                    'label' => esc_html__('Settings', 'event_espresso'),
644
-                    'order' => 40
645
-                ),
646
-                'metaboxes'     => array('_messages_settings_metaboxes'),
647
-                'help_tabs'     => array(
648
-                    'messages_settings_help_tab'               => array(
649
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
-                        'filename' => 'messages_settings'
651
-                    ),
652
-                    'messages_settings_message_types_help_tab' => array(
653
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
-                        'filename' => 'messages_settings_message_types'
655
-                    ),
656
-                    'messages_settings_messengers_help_tab'    => array(
657
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
-                        'filename' => 'messages_settings_messengers'
659
-                    ),
660
-                ),
661
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
662
-                'require_nonce' => false
663
-            )
664
-        );
665
-    }
522
+	protected function _set_page_config()
523
+	{
524
+		$this->_page_config = array(
525
+			'default'                  => array(
526
+				'nav'           => array(
527
+					'label' => esc_html__('Message Activity', 'event_espresso'),
528
+					'order' => 10
529
+				),
530
+				'list_table'    => 'EE_Message_List_Table',
531
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
+				'require_nonce' => false
533
+			),
534
+			'global_mtps'              => array(
535
+				'nav'           => array(
536
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
+					'order' => 20
538
+				),
539
+				'list_table'    => 'Messages_Template_List_Table',
540
+				'help_tabs'     => array(
541
+					'messages_overview_help_tab'                                => array(
542
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
+						'filename' => 'messages_overview'
544
+					),
545
+					'messages_overview_messages_table_column_headings_help_tab' => array(
546
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
+						'filename' => 'messages_overview_table_column_headings'
548
+					),
549
+					'messages_overview_messages_filters_help_tab'               => array(
550
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
551
+						'filename' => 'messages_overview_filters'
552
+					),
553
+					'messages_overview_messages_views_help_tab'                 => array(
554
+						'title'    => esc_html__('Message Views', 'event_espresso'),
555
+						'filename' => 'messages_overview_views'
556
+					),
557
+					'message_overview_message_types_help_tab'                   => array(
558
+						'title'    => esc_html__('Message Types', 'event_espresso'),
559
+						'filename' => 'messages_overview_types'
560
+					),
561
+					'messages_overview_messengers_help_tab'                     => array(
562
+						'title'    => esc_html__('Messengers', 'event_espresso'),
563
+						'filename' => 'messages_overview_messengers',
564
+					),
565
+				),
566
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
567
+				'require_nonce' => false
568
+			),
569
+			'custom_mtps'              => array(
570
+				'nav'           => array(
571
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
+					'order' => 30
573
+				),
574
+				'help_tabs'     => array(),
575
+				'help_tour'     => array(),
576
+				'require_nonce' => false
577
+			),
578
+			'add_new_message_template' => array(
579
+				'nav'           => array(
580
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
+					'order'      => 5,
582
+					'persistent' => false
583
+				),
584
+				'require_nonce' => false
585
+			),
586
+			'edit_message_template'    => array(
587
+				'labels'        => array(
588
+					'buttons'    => array(
589
+						'reset' => esc_html__('Reset Templates'),
590
+					),
591
+					'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
+				),
593
+				'nav'           => array(
594
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
+					'order'      => 5,
596
+					'persistent' => false,
597
+					'url'        => ''
598
+				),
599
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
+				'has_metaboxes' => true,
601
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
+				'help_tabs'     => array(
603
+					'edit_message_template'       => array(
604
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
+						'callback' => 'edit_message_template_help_tab'
606
+					),
607
+					'message_templates_help_tab'  => array(
608
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
609
+						'filename' => 'messages_templates'
610
+					),
611
+					'message_template_shortcodes' => array(
612
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
+						'callback' => 'message_template_shortcodes_help_tab'
614
+					),
615
+					'message_preview_help_tab'    => array(
616
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
617
+						'filename' => 'messages_preview'
618
+					),
619
+					'messages_overview_other_help_tab'                          => array(
620
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
621
+						'filename' => 'messages_overview_other',
622
+					),
623
+				),
624
+				'require_nonce' => false
625
+			),
626
+			'display_preview_message'  => array(
627
+				'nav'           => array(
628
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
629
+					'order'      => 5,
630
+					'url'        => '',
631
+					'persistent' => false
632
+				),
633
+				'help_tabs'     => array(
634
+					'preview_message' => array(
635
+						'title'    => esc_html__('About Previews', 'event_espresso'),
636
+						'callback' => 'preview_message_help_tab'
637
+					)
638
+				),
639
+				'require_nonce' => false
640
+			),
641
+			'settings'                 => array(
642
+				'nav'           => array(
643
+					'label' => esc_html__('Settings', 'event_espresso'),
644
+					'order' => 40
645
+				),
646
+				'metaboxes'     => array('_messages_settings_metaboxes'),
647
+				'help_tabs'     => array(
648
+					'messages_settings_help_tab'               => array(
649
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
+						'filename' => 'messages_settings'
651
+					),
652
+					'messages_settings_message_types_help_tab' => array(
653
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
+						'filename' => 'messages_settings_message_types'
655
+					),
656
+					'messages_settings_messengers_help_tab'    => array(
657
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
+						'filename' => 'messages_settings_messengers'
659
+					),
660
+				),
661
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
662
+				'require_nonce' => false
663
+			)
664
+		);
665
+	}
666 666
     
667 667
     
668
-    protected function _add_screen_options()
669
-    {
670
-        //todo
671
-    }
668
+	protected function _add_screen_options()
669
+	{
670
+		//todo
671
+	}
672 672
     
673 673
     
674
-    protected function _add_screen_options_global_mtps()
675
-    {
676
-        /**
677
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
679
-         */
680
-        $page_title              = $this->_admin_page_title;
681
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
-        $this->_per_page_screen_option();
683
-        $this->_admin_page_title = $page_title;
684
-    }
674
+	protected function _add_screen_options_global_mtps()
675
+	{
676
+		/**
677
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
679
+		 */
680
+		$page_title              = $this->_admin_page_title;
681
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
+		$this->_per_page_screen_option();
683
+		$this->_admin_page_title = $page_title;
684
+	}
685 685
     
686 686
     
687
-    protected function _add_screen_options_default()
688
-    {
689
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
-        $this->_per_page_screen_option();
691
-    }
687
+	protected function _add_screen_options_default()
688
+	{
689
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
+		$this->_per_page_screen_option();
691
+	}
692 692
     
693 693
     
694
-    //none of the below group are currently used for Messages
695
-    protected function _add_feature_pointers()
696
-    {
697
-    }
694
+	//none of the below group are currently used for Messages
695
+	protected function _add_feature_pointers()
696
+	{
697
+	}
698 698
     
699
-    public function admin_init()
700
-    {
701
-    }
699
+	public function admin_init()
700
+	{
701
+	}
702 702
     
703
-    public function admin_notices()
704
-    {
705
-    }
703
+	public function admin_notices()
704
+	{
705
+	}
706 706
     
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710 710
     
711 711
     
712
-    public function messages_help_tab()
713
-    {
714
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
-    }
712
+	public function messages_help_tab()
713
+	{
714
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
+	}
716 716
     
717 717
     
718
-    public function messengers_help_tab()
719
-    {
720
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
-    }
718
+	public function messengers_help_tab()
719
+	{
720
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
+	}
722 722
     
723 723
     
724
-    public function message_types_help_tab()
725
-    {
726
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
-    }
724
+	public function message_types_help_tab()
725
+	{
726
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
+	}
728 728
     
729 729
     
730
-    public function messages_overview_help_tab()
731
-    {
732
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
-    }
730
+	public function messages_overview_help_tab()
731
+	{
732
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
+	}
734 734
     
735 735
     
736
-    public function message_templates_help_tab()
737
-    {
738
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
-    }
736
+	public function message_templates_help_tab()
737
+	{
738
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
+	}
740 740
     
741 741
     
742
-    public function edit_message_template_help_tab()
743
-    {
744
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
-                        . esc_attr__('Editor Title', 'event_espresso')
746
-                        . '" />';
747
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
749
-                        . '" />';
750
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
752
-                        . '" />';
753
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
755
-                        . '" />';
756
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
-                        . esc_attr__('Publish Metabox', 'event_espresso')
758
-                        . '" />';
759
-        EEH_Template::display_template(
760
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
-            $args
762
-        );
763
-    }
742
+	public function edit_message_template_help_tab()
743
+	{
744
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
+						. esc_attr__('Editor Title', 'event_espresso')
746
+						. '" />';
747
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
749
+						. '" />';
750
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
752
+						. '" />';
753
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
755
+						. '" />';
756
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
+						. esc_attr__('Publish Metabox', 'event_espresso')
758
+						. '" />';
759
+		EEH_Template::display_template(
760
+			EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
+			$args
762
+		);
763
+	}
764 764
     
765 765
     
766
-    public function message_template_shortcodes_help_tab()
767
-    {
768
-        $this->_set_shortcodes();
769
-        $args['shortcodes'] = $this->_shortcodes;
770
-        EEH_Template::display_template(
771
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
-            $args
773
-        );
774
-    }
766
+	public function message_template_shortcodes_help_tab()
767
+	{
768
+		$this->_set_shortcodes();
769
+		$args['shortcodes'] = $this->_shortcodes;
770
+		EEH_Template::display_template(
771
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
+			$args
773
+		);
774
+	}
775 775
     
776 776
     
777
-    public function preview_message_help_tab()
778
-    {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
-    }
777
+	public function preview_message_help_tab()
778
+	{
779
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
+	}
781 781
     
782 782
     
783
-    public function settings_help_tab()
784
-    {
785
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
-        $args['img3'] = '<div class="switch">'
790
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
-                        . ' type="checkbox" checked="checked">'
792
-                        . '<label for="ee-on-off-toggle-on"></label>'
793
-                        . '</div>';
794
-        $args['img4'] = '<div class="switch">'
795
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
-                        . ' type="checkbox">'
797
-                        . '<label for="ee-on-off-toggle-on"></label>'
798
-                        . '</div>';
799
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
-    }
783
+	public function settings_help_tab()
784
+	{
785
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
+		$args['img3'] = '<div class="switch">'
790
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
+						. ' type="checkbox" checked="checked">'
792
+						. '<label for="ee-on-off-toggle-on"></label>'
793
+						. '</div>';
794
+		$args['img4'] = '<div class="switch">'
795
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
+						. ' type="checkbox">'
797
+						. '<label for="ee-on-off-toggle-on"></label>'
798
+						. '</div>';
799
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
+	}
801 801
     
802 802
     
803
-    public function load_scripts_styles()
804
-    {
805
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
-        wp_enqueue_style('espresso_ee_msg');
807
-        
808
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
-    }
803
+	public function load_scripts_styles()
804
+	{
805
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
+		wp_enqueue_style('espresso_ee_msg');
807
+        
808
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
+	}
813 813
     
814 814
     
815
-    public function load_scripts_styles_default()
816
-    {
817
-        wp_enqueue_script('ee-msg-list-table-js');
818
-    }
815
+	public function load_scripts_styles_default()
816
+	{
817
+		wp_enqueue_script('ee-msg-list-table-js');
818
+	}
819 819
     
820 820
     
821
-    public function wp_editor_css($mce_css)
822
-    {
823
-        //if we're on the edit_message_template route
824
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
-            $message_type_name = $this->_active_message_type_name;
821
+	public function wp_editor_css($mce_css)
822
+	{
823
+		//if we're on the edit_message_template route
824
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
+			$message_type_name = $this->_active_message_type_name;
826 826
             
827
-            //we're going to REPLACE the existing mce css
828
-            //we need to get the css file location from the active messenger
829
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
-                'wpeditor', $this->_variation);
831
-        }
832
-        
833
-        return $mce_css;
834
-    }
827
+			//we're going to REPLACE the existing mce css
828
+			//we need to get the css file location from the active messenger
829
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
+				'wpeditor', $this->_variation);
831
+		}
832
+        
833
+		return $mce_css;
834
+	}
835 835
     
836 836
     
837
-    public function load_scripts_styles_edit_message_template()
838
-    {
839
-        
840
-        $this->_set_shortcodes();
841
-        
842
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
-            esc_html__(
844
-                '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.',
845
-                'event_espresso'
846
-            ),
847
-            $this->_message_template_group->messenger_obj()->label['singular'],
848
-            $this->_message_template_group->message_type_obj()->label['singular']
849
-        );
850
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
-            '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?',
852
-            'event_espresso'
853
-        );
854
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
-            'event_espresso'
857
-        );
858
-        
859
-        wp_register_script(
860
-            'ee_msgs_edit_js',
861
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
-            array('jquery'),
863
-            EVENT_ESPRESSO_VERSION
864
-        );
865
-        
866
-        wp_enqueue_script('ee_admin_js');
867
-        wp_enqueue_script('ee_msgs_edit_js');
868
-        
869
-        //add in special css for tiny_mce
870
-        add_filter('mce_css', array($this, 'wp_editor_css'));
871
-    }
837
+	public function load_scripts_styles_edit_message_template()
838
+	{
839
+        
840
+		$this->_set_shortcodes();
841
+        
842
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
+			esc_html__(
844
+				'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.',
845
+				'event_espresso'
846
+			),
847
+			$this->_message_template_group->messenger_obj()->label['singular'],
848
+			$this->_message_template_group->message_type_obj()->label['singular']
849
+		);
850
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
+			'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?',
852
+			'event_espresso'
853
+		);
854
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
+			'event_espresso'
857
+		);
858
+        
859
+		wp_register_script(
860
+			'ee_msgs_edit_js',
861
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
+			array('jquery'),
863
+			EVENT_ESPRESSO_VERSION
864
+		);
865
+        
866
+		wp_enqueue_script('ee_admin_js');
867
+		wp_enqueue_script('ee_msgs_edit_js');
868
+        
869
+		//add in special css for tiny_mce
870
+		add_filter('mce_css', array($this, 'wp_editor_css'));
871
+	}
872 872
     
873 873
     
874
-    public function load_scripts_styles_display_preview_message()
875
-    {
876
-        
877
-        $this->_set_message_template_group();
878
-        
879
-        if (isset($this->_req_data['messenger'])) {
880
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
-                $this->_req_data['messenger']
882
-            );
883
-        }
884
-        
885
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
-        
887
-        
888
-        wp_enqueue_style('espresso_preview_css',
889
-            $this->_active_messenger->get_variation(
890
-                $this->_template_pack,
891
-                $message_type_name,
892
-                true,
893
-                'preview',
894
-                $this->_variation
895
-            )
896
-        );
897
-    }
874
+	public function load_scripts_styles_display_preview_message()
875
+	{
876
+        
877
+		$this->_set_message_template_group();
878
+        
879
+		if (isset($this->_req_data['messenger'])) {
880
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
+				$this->_req_data['messenger']
882
+			);
883
+		}
884
+        
885
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
+        
887
+        
888
+		wp_enqueue_style('espresso_preview_css',
889
+			$this->_active_messenger->get_variation(
890
+				$this->_template_pack,
891
+				$message_type_name,
892
+				true,
893
+				'preview',
894
+				$this->_variation
895
+			)
896
+		);
897
+	}
898 898
     
899 899
     
900
-    public function load_scripts_styles_settings()
901
-    {
902
-        wp_register_style(
903
-            'ee-message-settings',
904
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
-            array(),
906
-            EVENT_ESPRESSO_VERSION
907
-        );
908
-        wp_enqueue_style('ee-text-links');
909
-        wp_enqueue_style('ee-message-settings');
910
-        wp_enqueue_script('ee-messages-settings');
911
-    }
900
+	public function load_scripts_styles_settings()
901
+	{
902
+		wp_register_style(
903
+			'ee-message-settings',
904
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
+			array(),
906
+			EVENT_ESPRESSO_VERSION
907
+		);
908
+		wp_enqueue_style('ee-text-links');
909
+		wp_enqueue_style('ee-message-settings');
910
+		wp_enqueue_script('ee-messages-settings');
911
+	}
912 912
     
913 913
     
914
-    /**
915
-     * set views array for List Table
916
-     */
917
-    public function _set_list_table_views_global_mtps()
918
-    {
919
-        $this->_views = array(
920
-            'in_use' => array(
921
-                'slug'        => 'in_use',
922
-                'label'       => esc_html__('In Use', 'event_espresso'),
923
-                'count'       => 0,
924
-            )
925
-        );
926
-    }
914
+	/**
915
+	 * set views array for List Table
916
+	 */
917
+	public function _set_list_table_views_global_mtps()
918
+	{
919
+		$this->_views = array(
920
+			'in_use' => array(
921
+				'slug'        => 'in_use',
922
+				'label'       => esc_html__('In Use', 'event_espresso'),
923
+				'count'       => 0,
924
+			)
925
+		);
926
+	}
927 927
 
928 928
 
929
-    /**
930
-     * Set views array for the Custom Template List Table
931
-     */
932
-    public function _set_list_table_views_custom_mtps()
933
-    {
934
-        $this->_set_list_table_views_global_mtps();
935
-        $this->_views['in_use']['bulk_action'] = array(
936
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
-        );
938
-    }
929
+	/**
930
+	 * Set views array for the Custom Template List Table
931
+	 */
932
+	public function _set_list_table_views_custom_mtps()
933
+	{
934
+		$this->_set_list_table_views_global_mtps();
935
+		$this->_views['in_use']['bulk_action'] = array(
936
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
+		);
938
+	}
939 939
 
940 940
 
941
-    /**
942
-     * set views array for message queue list table
943
-     *
944
-     * @throws InvalidDataTypeException
945
-     * @throws InvalidInterfaceException
946
-     * @throws InvalidArgumentException
947
-     * @throws EE_Error
948
-     * @throws ReflectionException
949
-     */
950
-    public function _set_list_table_views_default()
951
-    {
952
-        EE_Registry::instance()->load_helper('Template');
953
-        
954
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
-            'ee_send_message',
956
-            'message_list_table_bulk_actions'
957
-        )
958
-            ? array(
959
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
-                'send_now'              => esc_html__('Send Now', 'event_espresso')
963
-            )
964
-            : array();
965
-        
966
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
-            'ee_delete_messages',
968
-            'message_list_table_bulk_actions'
969
-        )
970
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
-            : array();
972
-        
973
-        
974
-        $this->_views = array(
975
-            'all' => array(
976
-                'slug'        => 'all',
977
-                'label'       => esc_html__('All', 'event_espresso'),
978
-                'count'       => 0,
979
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
-            )
981
-        );
982
-        
983
-        
984
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
985
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
-                continue;
987
-            }
988
-            $status_bulk_actions = $common_bulk_actions;
989
-            //unset bulk actions not applying to status
990
-            if (! empty($status_bulk_actions)) {
991
-                switch ($status) {
992
-                    case EEM_Message::status_idle:
993
-                    case EEM_Message::status_resend:
994
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
-                        break;
941
+	/**
942
+	 * set views array for message queue list table
943
+	 *
944
+	 * @throws InvalidDataTypeException
945
+	 * @throws InvalidInterfaceException
946
+	 * @throws InvalidArgumentException
947
+	 * @throws EE_Error
948
+	 * @throws ReflectionException
949
+	 */
950
+	public function _set_list_table_views_default()
951
+	{
952
+		EE_Registry::instance()->load_helper('Template');
953
+        
954
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
+			'ee_send_message',
956
+			'message_list_table_bulk_actions'
957
+		)
958
+			? array(
959
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
+				'send_now'              => esc_html__('Send Now', 'event_espresso')
963
+			)
964
+			: array();
965
+        
966
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
+			'ee_delete_messages',
968
+			'message_list_table_bulk_actions'
969
+		)
970
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
+			: array();
972
+        
973
+        
974
+		$this->_views = array(
975
+			'all' => array(
976
+				'slug'        => 'all',
977
+				'label'       => esc_html__('All', 'event_espresso'),
978
+				'count'       => 0,
979
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
+			)
981
+		);
982
+        
983
+        
984
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
985
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
+				continue;
987
+			}
988
+			$status_bulk_actions = $common_bulk_actions;
989
+			//unset bulk actions not applying to status
990
+			if (! empty($status_bulk_actions)) {
991
+				switch ($status) {
992
+					case EEM_Message::status_idle:
993
+					case EEM_Message::status_resend:
994
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
+						break;
996 996
                     
997
-                    case EEM_Message::status_failed:
998
-                    case EEM_Message::status_debug_only:
999
-                    case EEM_Message::status_messenger_executing:
1000
-                        $status_bulk_actions = array();
1001
-                        break;
997
+					case EEM_Message::status_failed:
998
+					case EEM_Message::status_debug_only:
999
+					case EEM_Message::status_messenger_executing:
1000
+						$status_bulk_actions = array();
1001
+						break;
1002 1002
                     
1003
-                    case EEM_Message::status_incomplete:
1004
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
-                        break;
1003
+					case EEM_Message::status_incomplete:
1004
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
+						break;
1006 1006
                     
1007
-                    case EEM_Message::status_retry:
1008
-                    case EEM_Message::status_sent:
1009
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
-                        break;
1011
-                }
1012
-            }
1007
+					case EEM_Message::status_retry:
1008
+					case EEM_Message::status_sent:
1009
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
+						break;
1011
+				}
1012
+			}
1013 1013
 
1014
-            //skip adding messenger executing status to views because it will be included with the Failed view.
1015
-            if ( $status === EEM_Message::status_messenger_executing ) {
1016
-                continue;
1017
-            }
1014
+			//skip adding messenger executing status to views because it will be included with the Failed view.
1015
+			if ( $status === EEM_Message::status_messenger_executing ) {
1016
+				continue;
1017
+			}
1018 1018
             
1019
-            $this->_views[strtolower($status)] = array(
1020
-                'slug'        => strtolower($status),
1021
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
-                'count'       => 0,
1023
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
-            );
1025
-        }
1026
-    }
1019
+			$this->_views[strtolower($status)] = array(
1020
+				'slug'        => strtolower($status),
1021
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
+				'count'       => 0,
1023
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
+			);
1025
+		}
1026
+	}
1027 1027
     
1028 1028
     
1029
-    protected function _ee_default_messages_overview_list_table()
1030
-    {
1031
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
-        $this->display_admin_list_table_page_with_no_sidebar();
1033
-    }
1029
+	protected function _ee_default_messages_overview_list_table()
1030
+	{
1031
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
+		$this->display_admin_list_table_page_with_no_sidebar();
1033
+	}
1034 1034
     
1035 1035
     
1036
-    protected function _message_queue_list_table()
1037
-    {
1038
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
-        $this->_template_args['per_column']        = 6;
1040
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
-        $this->_template_args['before_list_table'] = '<h3>'
1042
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1043
-                                                     . '</h3>';
1044
-        $this->display_admin_list_table_page_with_no_sidebar();
1045
-    }
1036
+	protected function _message_queue_list_table()
1037
+	{
1038
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
+		$this->_template_args['per_column']        = 6;
1040
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
+		$this->_template_args['before_list_table'] = '<h3>'
1042
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1043
+													 . '</h3>';
1044
+		$this->display_admin_list_table_page_with_no_sidebar();
1045
+	}
1046 1046
     
1047 1047
     
1048
-    protected function _message_legend_items()
1049
-    {
1050
-        
1051
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
-        $action_items       = array();
1053
-        
1054
-        foreach ($action_css_classes as $action_item => $action_details) {
1055
-            if ($action_item === 'see_notifications_for') {
1056
-                continue;
1057
-            }
1058
-            $action_items[$action_item] = array(
1059
-                'class' => $action_details['css_class'],
1060
-                'desc'  => $action_details['label']
1061
-            );
1062
-        }
1063
-        
1064
-        /** @type array $status_items status legend setup */
1065
-        $status_items = array(
1066
-            'sent_status'       => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
-            ),
1070
-            'idle_status'       => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
-            ),
1074
-            'failed_status'     => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
-            ),
1078
-            'messenger_executing_status' => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
-            ),
1082
-            'resend_status'     => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
-            ),
1086
-            'incomplete_status' => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
-            ),
1090
-            'retry_status'      => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
-            )
1094
-        );
1095
-        if (EEM_Message::debug()) {
1096
-            $status_items['debug_only_status'] = array(
1097
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
-            );
1100
-        }
1101
-        
1102
-        return array_merge($action_items, $status_items);
1103
-    }
1048
+	protected function _message_legend_items()
1049
+	{
1050
+        
1051
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
+		$action_items       = array();
1053
+        
1054
+		foreach ($action_css_classes as $action_item => $action_details) {
1055
+			if ($action_item === 'see_notifications_for') {
1056
+				continue;
1057
+			}
1058
+			$action_items[$action_item] = array(
1059
+				'class' => $action_details['css_class'],
1060
+				'desc'  => $action_details['label']
1061
+			);
1062
+		}
1063
+        
1064
+		/** @type array $status_items status legend setup */
1065
+		$status_items = array(
1066
+			'sent_status'       => array(
1067
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
+			),
1070
+			'idle_status'       => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
+			),
1074
+			'failed_status'     => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
+			),
1078
+			'messenger_executing_status' => array(
1079
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
+			),
1082
+			'resend_status'     => array(
1083
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
+			),
1086
+			'incomplete_status' => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
+			),
1090
+			'retry_status'      => array(
1091
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
+			)
1094
+		);
1095
+		if (EEM_Message::debug()) {
1096
+			$status_items['debug_only_status'] = array(
1097
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
+			);
1100
+		}
1101
+        
1102
+		return array_merge($action_items, $status_items);
1103
+	}
1104 1104
     
1105 1105
     
1106
-    protected function _custom_mtps_preview()
1107
-    {
1108
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
-        $this->_template_args['preview_text'] = '<strong>'
1112
-            . esc_html__(
1113
-                '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.',
1114
-                'event_espresso'
1115
-            )
1116
-            . '</strong>';
1106
+	protected function _custom_mtps_preview()
1107
+	{
1108
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
+			. ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
+		$this->_template_args['preview_text'] = '<strong>'
1112
+			. esc_html__(
1113
+				'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.',
1114
+				'event_espresso'
1115
+			)
1116
+			. '</strong>';
1117 1117
 
1118
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1119
-    }
1118
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1119
+	}
1120 1120
 
1121 1121
 
1122
-    /**
1123
-     * get_message_templates
1124
-     * This gets all the message templates for listing on the overview list.
1125
-     *
1126
-     * @access public
1127
-     * @param int    $perpage the amount of templates groups to show per page
1128
-     * @param string $type    the current _view we're getting templates for
1129
-     * @param bool   $count   return count?
1130
-     * @param bool   $all     disregard any paging info (get all data);
1131
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
-     * @return array
1133
-     * @throws EE_Error
1134
-     * @throws InvalidArgumentException
1135
-     * @throws InvalidDataTypeException
1136
-     * @throws InvalidInterfaceException
1137
-     */
1138
-    public function get_message_templates(
1139
-        $perpage = 10,
1140
-        $type = 'in_use',
1141
-        $count = false,
1142
-        $all = false,
1143
-        $global = true)
1144
-    {
1145
-        
1146
-        $MTP = EEM_Message_Template_Group::instance();
1147
-        
1148
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
-        $orderby                    = $this->_req_data['orderby'];
1150
-        
1151
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
-            ? $this->_req_data['order']
1153
-            : 'ASC';
1154
-        
1155
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
-            ? $this->_req_data['paged']
1157
-            : 1;
1158
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
-            ? $this->_req_data['perpage']
1160
-            : $perpage;
1161
-        
1162
-        $offset = ($current_page - 1) * $per_page;
1163
-        $limit  = $all ? null : array($offset, $per_page);
1164
-        
1165
-        
1166
-        //options will match what is in the _views array property
1167
-        switch ($type) {
1168
-            case 'in_use':
1169
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
-                break;
1171
-            default:
1172
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
-        }
1174
-        
1175
-        return $templates;
1176
-    }
1122
+	/**
1123
+	 * get_message_templates
1124
+	 * This gets all the message templates for listing on the overview list.
1125
+	 *
1126
+	 * @access public
1127
+	 * @param int    $perpage the amount of templates groups to show per page
1128
+	 * @param string $type    the current _view we're getting templates for
1129
+	 * @param bool   $count   return count?
1130
+	 * @param bool   $all     disregard any paging info (get all data);
1131
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
+	 * @return array
1133
+	 * @throws EE_Error
1134
+	 * @throws InvalidArgumentException
1135
+	 * @throws InvalidDataTypeException
1136
+	 * @throws InvalidInterfaceException
1137
+	 */
1138
+	public function get_message_templates(
1139
+		$perpage = 10,
1140
+		$type = 'in_use',
1141
+		$count = false,
1142
+		$all = false,
1143
+		$global = true)
1144
+	{
1145
+        
1146
+		$MTP = EEM_Message_Template_Group::instance();
1147
+        
1148
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
+		$orderby                    = $this->_req_data['orderby'];
1150
+        
1151
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
+			? $this->_req_data['order']
1153
+			: 'ASC';
1154
+        
1155
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
+			? $this->_req_data['paged']
1157
+			: 1;
1158
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
+			? $this->_req_data['perpage']
1160
+			: $perpage;
1161
+        
1162
+		$offset = ($current_page - 1) * $per_page;
1163
+		$limit  = $all ? null : array($offset, $per_page);
1164
+        
1165
+        
1166
+		//options will match what is in the _views array property
1167
+		switch ($type) {
1168
+			case 'in_use':
1169
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
+				break;
1171
+			default:
1172
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
+		}
1174
+        
1175
+		return $templates;
1176
+	}
1177 1177
     
1178 1178
     
1179
-    /**
1180
-     * filters etc might need a list of installed message_types
1181
-     * @return array an array of message type objects
1182
-     */
1183
-    public function get_installed_message_types()
1184
-    {
1185
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
-        $installed               = array();
1187
-        
1188
-        foreach ($installed_message_types as $message_type) {
1189
-            $installed[$message_type->name] = $message_type;
1190
-        }
1191
-        
1192
-        return $installed;
1193
-    }
1179
+	/**
1180
+	 * filters etc might need a list of installed message_types
1181
+	 * @return array an array of message type objects
1182
+	 */
1183
+	public function get_installed_message_types()
1184
+	{
1185
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
+		$installed               = array();
1187
+        
1188
+		foreach ($installed_message_types as $message_type) {
1189
+			$installed[$message_type->name] = $message_type;
1190
+		}
1191
+        
1192
+		return $installed;
1193
+	}
1194 1194
     
1195 1195
     
1196
-    /**
1197
-     * _add_message_template
1198
-     *
1199
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1200
-     *
1201
-     * @param string $message_type
1202
-     * @param string $messenger
1203
-     * @param string $GRP_ID
1204
-     *
1205
-     * @throws EE_error
1206
-     */
1207
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
-    {
1209
-        //set values override any request data
1210
-        $message_type = ! empty($message_type) ? $message_type : '';
1211
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
-            ? $this->_req_data['message_type']
1213
-            : $message_type;
1214
-        
1215
-        $messenger = ! empty($messenger) ? $messenger : '';
1216
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
-            ? $this->_req_data['messenger']
1218
-            : $messenger;
1219
-        
1220
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
-        
1223
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
-        if (empty($message_type) || empty($messenger)) {
1225
-            throw new EE_Error(
1226
-                esc_html__(
1227
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
-                    'event_espresso'
1229
-                )
1230
-            );
1231
-        }
1232
-        
1233
-        //we need the GRP_ID for the template being used as the base for the new template
1234
-        if (empty($GRP_ID)) {
1235
-            throw new EE_Error(
1236
-                esc_html__(
1237
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
-                    'event_espresso'
1239
-                )
1240
-            );
1241
-        }
1242
-        
1243
-        //let's just make sure the template gets generated!
1244
-        
1245
-        //we need to reassign some variables for what the insert is expecting
1246
-        $this->_req_data['MTP_messenger']    = $messenger;
1247
-        $this->_req_data['MTP_message_type'] = $message_type;
1248
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1249
-        $this->_insert_or_update_message_template(true);
1250
-    }
1196
+	/**
1197
+	 * _add_message_template
1198
+	 *
1199
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1200
+	 *
1201
+	 * @param string $message_type
1202
+	 * @param string $messenger
1203
+	 * @param string $GRP_ID
1204
+	 *
1205
+	 * @throws EE_error
1206
+	 */
1207
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
+	{
1209
+		//set values override any request data
1210
+		$message_type = ! empty($message_type) ? $message_type : '';
1211
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
+			? $this->_req_data['message_type']
1213
+			: $message_type;
1214
+        
1215
+		$messenger = ! empty($messenger) ? $messenger : '';
1216
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
+			? $this->_req_data['messenger']
1218
+			: $messenger;
1219
+        
1220
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
+        
1223
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
+		if (empty($message_type) || empty($messenger)) {
1225
+			throw new EE_Error(
1226
+				esc_html__(
1227
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
+					'event_espresso'
1229
+				)
1230
+			);
1231
+		}
1232
+        
1233
+		//we need the GRP_ID for the template being used as the base for the new template
1234
+		if (empty($GRP_ID)) {
1235
+			throw new EE_Error(
1236
+				esc_html__(
1237
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
+					'event_espresso'
1239
+				)
1240
+			);
1241
+		}
1242
+        
1243
+		//let's just make sure the template gets generated!
1244
+        
1245
+		//we need to reassign some variables for what the insert is expecting
1246
+		$this->_req_data['MTP_messenger']    = $messenger;
1247
+		$this->_req_data['MTP_message_type'] = $message_type;
1248
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1249
+		$this->_insert_or_update_message_template(true);
1250
+	}
1251 1251
 
1252 1252
 
1253
-    /**
1254
-     * public wrapper for the _add_message_template method
1255
-     *
1256
-     * @param string $message_type     message type slug
1257
-     * @param string $messenger        messenger slug
1258
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
-     *                                 off of.
1260
-     * @throws EE_error
1261
-     */
1262
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1263
-    {
1264
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
-    }
1253
+	/**
1254
+	 * public wrapper for the _add_message_template method
1255
+	 *
1256
+	 * @param string $message_type     message type slug
1257
+	 * @param string $messenger        messenger slug
1258
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
+	 *                                 off of.
1260
+	 * @throws EE_error
1261
+	 */
1262
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1263
+	{
1264
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
+	}
1266 1266
 
1267 1267
 
1268
-    /**
1269
-     * _edit_message_template
1270
-     *
1271
-     * @access protected
1272
-     * @return void
1273
-     * @throws InvalidIdentifierException
1274
-     * @throws DomainException
1275
-     * @throws EE_Error
1276
-     * @throws InvalidArgumentException
1277
-     * @throws ReflectionException
1278
-     * @throws InvalidDataTypeException
1279
-     * @throws InvalidInterfaceException
1280
-     */
1281
-    protected function _edit_message_template()
1282
-    {
1283
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
-        $template_fields = '';
1285
-        $sidebar_fields  = '';
1286
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
-        // valid html in the templates.
1288
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
-        
1290
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
-            ? absint($this->_req_data['id'])
1292
-            : false;
1293
-        
1294
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1295
-        $message_template_group = $this->_message_template_group;
1296
-        $c_label                = $message_template_group->context_label();
1297
-        $c_config               = $message_template_group->contexts_config();
1298
-        
1299
-        reset($c_config);
1300
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
-            ? strtolower($this->_req_data['context'])
1302
-            : key($c_config);
1303
-        
1304
-        
1305
-        if (empty($GRP_ID)) {
1306
-            $action = 'insert_message_template';
1307
-            $edit_message_template_form_url = add_query_arg(
1308
-                array('action' => $action, 'noheader' => true),
1309
-                EE_MSG_ADMIN_URL
1310
-            );
1311
-        } else {
1312
-            $action = 'update_message_template';
1313
-            $edit_message_template_form_url = add_query_arg(
1314
-                array('action' => $action, 'noheader' => true),
1315
-                EE_MSG_ADMIN_URL
1316
-            );
1317
-        }
1318
-        
1319
-        //set active messenger for this view
1320
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
-            $message_template_group->messenger()
1322
-        );
1323
-        $this->_active_message_type_name = $message_template_group->message_type();
1324
-        
1325
-        
1326
-        //Do we have any validation errors?
1327
-        $validators = $this->_get_transient();
1328
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
-        
1330
-        
1331
-        //we need to assemble the title from Various details
1332
-        $context_label = sprintf(
1333
-            esc_html__('(%s %s)', 'event_espresso'),
1334
-            $c_config[$context]['label'],
1335
-            ucwords($c_label['label'])
1336
-        );
1337
-        
1338
-        $title = sprintf(
1339
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1340
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1341
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1342
-            $context_label
1343
-        );
1344
-        
1345
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1346
-        $this->_template_args['message_template'] = $message_template_group;
1347
-        $this->_template_args['is_extra_fields']  = false;
1348
-        
1349
-        
1350
-        //let's get EEH_MSG_Template so we can get template form fields
1351
-        $template_field_structure = EEH_MSG_Template::get_fields(
1352
-            $message_template_group->messenger(),
1353
-            $message_template_group->message_type()
1354
-        );
1355
-        
1356
-        if ( ! $template_field_structure) {
1357
-            $template_field_structure = false;
1358
-            $template_fields          = esc_html__(
1359
-                'There was an error in assembling the fields for this display (you should see an error message)',
1360
-                'event_espresso'
1361
-            );
1362
-        }
1363
-        
1364
-        
1365
-        $message_templates = $message_template_group->context_templates();
1366
-        
1367
-        
1368
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
-        // will get handled in the "extra" array.
1370
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
-                unset($template_field_structure[$context][$reference_field]);
1373
-            }
1374
-        }
1375
-        
1376
-        //let's loop through the template_field_structure and actually assemble the input fields!
1377
-        if ( ! empty($template_field_structure)) {
1378
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
-                // the extra array and reset them.
1381
-                if ($template_field === 'extra') {
1382
-                    $this->_template_args['is_extra_fields'] = true;
1383
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
-                        $message_template = $message_templates[$context][$reference_field];
1385
-                        $content          = $message_template instanceof EE_Message_Template
1386
-                            ? $message_template->get('MTP_content')
1387
-                            : '';
1388
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1389
-                            //let's verify if we need this extra field via the shortcodes parameter.
1390
-                            $continue = false;
1391
-                            if (isset($extra_array['shortcodes_required'])) {
1392
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
-                                        $continue = true;
1395
-                                    }
1396
-                                }
1397
-                                if ($continue) {
1398
-                                    continue;
1399
-                                }
1400
-                            }
1268
+	/**
1269
+	 * _edit_message_template
1270
+	 *
1271
+	 * @access protected
1272
+	 * @return void
1273
+	 * @throws InvalidIdentifierException
1274
+	 * @throws DomainException
1275
+	 * @throws EE_Error
1276
+	 * @throws InvalidArgumentException
1277
+	 * @throws ReflectionException
1278
+	 * @throws InvalidDataTypeException
1279
+	 * @throws InvalidInterfaceException
1280
+	 */
1281
+	protected function _edit_message_template()
1282
+	{
1283
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
+		$template_fields = '';
1285
+		$sidebar_fields  = '';
1286
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
+		// valid html in the templates.
1288
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
+        
1290
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
+			? absint($this->_req_data['id'])
1292
+			: false;
1293
+        
1294
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1295
+		$message_template_group = $this->_message_template_group;
1296
+		$c_label                = $message_template_group->context_label();
1297
+		$c_config               = $message_template_group->contexts_config();
1298
+        
1299
+		reset($c_config);
1300
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
+			? strtolower($this->_req_data['context'])
1302
+			: key($c_config);
1303
+        
1304
+        
1305
+		if (empty($GRP_ID)) {
1306
+			$action = 'insert_message_template';
1307
+			$edit_message_template_form_url = add_query_arg(
1308
+				array('action' => $action, 'noheader' => true),
1309
+				EE_MSG_ADMIN_URL
1310
+			);
1311
+		} else {
1312
+			$action = 'update_message_template';
1313
+			$edit_message_template_form_url = add_query_arg(
1314
+				array('action' => $action, 'noheader' => true),
1315
+				EE_MSG_ADMIN_URL
1316
+			);
1317
+		}
1318
+        
1319
+		//set active messenger for this view
1320
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
+			$message_template_group->messenger()
1322
+		);
1323
+		$this->_active_message_type_name = $message_template_group->message_type();
1324
+        
1325
+        
1326
+		//Do we have any validation errors?
1327
+		$validators = $this->_get_transient();
1328
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
+        
1330
+        
1331
+		//we need to assemble the title from Various details
1332
+		$context_label = sprintf(
1333
+			esc_html__('(%s %s)', 'event_espresso'),
1334
+			$c_config[$context]['label'],
1335
+			ucwords($c_label['label'])
1336
+		);
1337
+        
1338
+		$title = sprintf(
1339
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1340
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1341
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1342
+			$context_label
1343
+		);
1344
+        
1345
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1346
+		$this->_template_args['message_template'] = $message_template_group;
1347
+		$this->_template_args['is_extra_fields']  = false;
1348
+        
1349
+        
1350
+		//let's get EEH_MSG_Template so we can get template form fields
1351
+		$template_field_structure = EEH_MSG_Template::get_fields(
1352
+			$message_template_group->messenger(),
1353
+			$message_template_group->message_type()
1354
+		);
1355
+        
1356
+		if ( ! $template_field_structure) {
1357
+			$template_field_structure = false;
1358
+			$template_fields          = esc_html__(
1359
+				'There was an error in assembling the fields for this display (you should see an error message)',
1360
+				'event_espresso'
1361
+			);
1362
+		}
1363
+        
1364
+        
1365
+		$message_templates = $message_template_group->context_templates();
1366
+        
1367
+        
1368
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
+		// will get handled in the "extra" array.
1370
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
+				unset($template_field_structure[$context][$reference_field]);
1373
+			}
1374
+		}
1375
+        
1376
+		//let's loop through the template_field_structure and actually assemble the input fields!
1377
+		if ( ! empty($template_field_structure)) {
1378
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
+				// the extra array and reset them.
1381
+				if ($template_field === 'extra') {
1382
+					$this->_template_args['is_extra_fields'] = true;
1383
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
+						$message_template = $message_templates[$context][$reference_field];
1385
+						$content          = $message_template instanceof EE_Message_Template
1386
+							? $message_template->get('MTP_content')
1387
+							: '';
1388
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1389
+							//let's verify if we need this extra field via the shortcodes parameter.
1390
+							$continue = false;
1391
+							if (isset($extra_array['shortcodes_required'])) {
1392
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
+										$continue = true;
1395
+									}
1396
+								}
1397
+								if ($continue) {
1398
+									continue;
1399
+								}
1400
+							}
1401 1401
                             
1402
-                            $field_id                                = $reference_field
1403
-                                                                       . '-'
1404
-                                                                       . $extra_field
1405
-                                                                       . '-content';
1406
-                            $template_form_fields[$field_id]         = $extra_array;
1407
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
-                                                                       . $reference_field
1409
-                                                                       . '][content]['
1410
-                                                                       . $extra_field . ']';
1411
-                            $css_class                               = isset($extra_array['css_class'])
1412
-                                ? $extra_array['css_class']
1413
-                                : '';
1402
+							$field_id                                = $reference_field
1403
+																	   . '-'
1404
+																	   . $extra_field
1405
+																	   . '-content';
1406
+							$template_form_fields[$field_id]         = $extra_array;
1407
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
+																	   . $reference_field
1409
+																	   . '][content]['
1410
+																	   . $extra_field . ']';
1411
+							$css_class                               = isset($extra_array['css_class'])
1412
+								? $extra_array['css_class']
1413
+								: '';
1414 1414
                             
1415
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
-                                && in_array($extra_field, $v_fields, true)
1417
-                                &&
1418
-                                (
1419
-                                    is_array($validators[$extra_field])
1420
-                                    && isset($validators[$extra_field]['msg'])
1421
-                                )
1422
-                                ? 'validate-error ' . $css_class
1423
-                                : $css_class;
1415
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
+								&& in_array($extra_field, $v_fields, true)
1417
+								&&
1418
+								(
1419
+									is_array($validators[$extra_field])
1420
+									&& isset($validators[$extra_field]['msg'])
1421
+								)
1422
+								? 'validate-error ' . $css_class
1423
+								: $css_class;
1424 1424
                             
1425
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
-                                                                        && isset($content[$extra_field])
1427
-                                ? $content[$extra_field]
1428
-                                : '';
1425
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
+																		&& isset($content[$extra_field])
1427
+								? $content[$extra_field]
1428
+								: '';
1429 1429
                             
1430
-                            //do we have a validation error?  if we do then let's use that value instead
1431
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
-                                ? $validators[$extra_field]['value']
1433
-                                : $template_form_fields[$field_id]['value'];
1430
+							//do we have a validation error?  if we do then let's use that value instead
1431
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
+								? $validators[$extra_field]['value']
1433
+								: $template_form_fields[$field_id]['value'];
1434 1434
                             
1435 1435
                             
1436
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1436
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1437 1437
                             
1438
-                            //shortcode selector
1439
-                            $field_name_to_use                                 = $extra_field === 'main'
1440
-                                ? 'content'
1441
-                                : $extra_field;
1442
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
-                                $field_name_to_use,
1444
-                                $field_id
1445
-                            );
1438
+							//shortcode selector
1439
+							$field_name_to_use                                 = $extra_field === 'main'
1440
+								? 'content'
1441
+								: $extra_field;
1442
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
+								$field_name_to_use,
1444
+								$field_id
1445
+							);
1446 1446
                             
1447
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
-                                //we want to decode the entities
1449
-                                $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value'];
1447
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
+								//we want to decode the entities
1449
+								$template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value'];
1450 1450
                                 
1451
-                            }/**/
1452
-                        }
1453
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1454
-                        $templatefield_templatename_id = $reference_field . '-name';
1451
+							}/**/
1452
+						}
1453
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1454
+						$templatefield_templatename_id = $reference_field . '-name';
1455 1455
                         
1456
-                        $template_form_fields[$templatefield_MTP_id] = array(
1457
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1458
-                            'label'      => null,
1459
-                            'input'      => 'hidden',
1460
-                            'type'       => 'int',
1461
-                            'required'   => false,
1462
-                            'validation' => false,
1463
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1464
-                            'css_class'  => '',
1465
-                            'format'     => '%d',
1466
-                            'db-col'     => 'MTP_ID'
1467
-                        );
1456
+						$template_form_fields[$templatefield_MTP_id] = array(
1457
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1458
+							'label'      => null,
1459
+							'input'      => 'hidden',
1460
+							'type'       => 'int',
1461
+							'required'   => false,
1462
+							'validation' => false,
1463
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1464
+							'css_class'  => '',
1465
+							'format'     => '%d',
1466
+							'db-col'     => 'MTP_ID'
1467
+						);
1468 1468
                         
1469
-                        $template_form_fields[$templatefield_templatename_id] = array(
1470
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1471
-                            'label'      => null,
1472
-                            'input'      => 'hidden',
1473
-                            'type'       => 'string',
1474
-                            'required'   => false,
1475
-                            'validation' => true,
1476
-                            'value'      => $reference_field,
1477
-                            'css_class'  => '',
1478
-                            'format'     => '%s',
1479
-                            'db-col'     => 'MTP_template_field'
1480
-                        );
1481
-                    }
1482
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1483
-                } else {
1484
-                    $field_id                                 = $template_field . '-content';
1485
-                    $template_form_fields[$field_id]          = $field_setup_array;
1486
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1487
-                    $message_template                         = isset($message_templates[$context][$template_field])
1488
-                        ? $message_templates[$context][$template_field]
1489
-                        : null;
1490
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1491
-                                                                && is_array($message_templates[$context])
1492
-                                                                && $message_template instanceof EE_Message_Template
1493
-                        ? $message_template->get('MTP_content')
1494
-                        : '';
1469
+						$template_form_fields[$templatefield_templatename_id] = array(
1470
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1471
+							'label'      => null,
1472
+							'input'      => 'hidden',
1473
+							'type'       => 'string',
1474
+							'required'   => false,
1475
+							'validation' => true,
1476
+							'value'      => $reference_field,
1477
+							'css_class'  => '',
1478
+							'format'     => '%s',
1479
+							'db-col'     => 'MTP_template_field'
1480
+						);
1481
+					}
1482
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1483
+				} else {
1484
+					$field_id                                 = $template_field . '-content';
1485
+					$template_form_fields[$field_id]          = $field_setup_array;
1486
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1487
+					$message_template                         = isset($message_templates[$context][$template_field])
1488
+						? $message_templates[$context][$template_field]
1489
+						: null;
1490
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1491
+																&& is_array($message_templates[$context])
1492
+																&& $message_template instanceof EE_Message_Template
1493
+						? $message_template->get('MTP_content')
1494
+						: '';
1495 1495
                     
1496
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1497
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1498
-                        ? $validators[$template_field]['value']
1499
-                        : $template_form_fields[$field_id]['value'];
1496
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1497
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1498
+						? $validators[$template_field]['value']
1499
+						: $template_form_fields[$field_id]['value'];
1500 1500
                     
1501 1501
                     
1502
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1503
-                    $css_class                                    = isset($field_setup_array['css_class'])
1504
-                        ? $field_setup_array['css_class']
1505
-                        : '';
1506
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1507
-                                                                    && in_array($template_field, $v_fields, true)
1508
-                                                                    && isset($validators[$template_field]['msg'])
1509
-                        ? 'validate-error ' . $css_class
1510
-                        : $css_class;
1502
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1503
+					$css_class                                    = isset($field_setup_array['css_class'])
1504
+						? $field_setup_array['css_class']
1505
+						: '';
1506
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1507
+																	&& in_array($template_field, $v_fields, true)
1508
+																	&& isset($validators[$template_field]['msg'])
1509
+						? 'validate-error ' . $css_class
1510
+						: $css_class;
1511 1511
                     
1512
-                    //shortcode selector
1513
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1514
-                        $template_field, $field_id
1515
-                    );
1516
-                }
1512
+					//shortcode selector
1513
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1514
+						$template_field, $field_id
1515
+					);
1516
+				}
1517 1517
                 
1518
-                //k took care of content field(s) now let's take care of others.
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
-                //foreach template field there are actually two form fields created
1524
-                $template_form_fields[$templatefield_MTP_id] = array(
1525
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1526
-                    'label'      => null,
1527
-                    'input'      => 'hidden',
1528
-                    'type'       => 'int',
1529
-                    'required'   => false,
1530
-                    'validation' => true,
1531
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1532
-                    'css_class'  => '',
1533
-                    'format'     => '%d',
1534
-                    'db-col'     => 'MTP_ID'
1535
-                );
1523
+				//foreach template field there are actually two form fields created
1524
+				$template_form_fields[$templatefield_MTP_id] = array(
1525
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1526
+					'label'      => null,
1527
+					'input'      => 'hidden',
1528
+					'type'       => 'int',
1529
+					'required'   => false,
1530
+					'validation' => true,
1531
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1532
+					'css_class'  => '',
1533
+					'format'     => '%d',
1534
+					'db-col'     => 'MTP_ID'
1535
+				);
1536 1536
                 
1537
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1538
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1539
-                    'label'      => null,
1540
-                    'input'      => 'hidden',
1541
-                    'type'       => 'string',
1542
-                    'required'   => false,
1543
-                    'validation' => true,
1544
-                    'value'      => $template_field,
1545
-                    'css_class'  => '',
1546
-                    'format'     => '%s',
1547
-                    'db-col'     => 'MTP_template_field'
1548
-                );
1537
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1538
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1539
+					'label'      => null,
1540
+					'input'      => 'hidden',
1541
+					'type'       => 'string',
1542
+					'required'   => false,
1543
+					'validation' => true,
1544
+					'value'      => $template_field,
1545
+					'css_class'  => '',
1546
+					'format'     => '%s',
1547
+					'db-col'     => 'MTP_template_field'
1548
+				);
1549 1549
                 
1550
-            }
1550
+			}
1551 1551
             
1552
-            //add other fields
1553
-            $template_form_fields['ee-msg-current-context'] = array(
1554
-                'name'       => 'MTP_context',
1555
-                'label'      => null,
1556
-                'input'      => 'hidden',
1557
-                'type'       => 'string',
1558
-                'required'   => false,
1559
-                'validation' => true,
1560
-                'value'      => $context,
1561
-                'css_class'  => '',
1562
-                'format'     => '%s',
1563
-                'db-col'     => 'MTP_context'
1564
-            );
1552
+			//add other fields
1553
+			$template_form_fields['ee-msg-current-context'] = array(
1554
+				'name'       => 'MTP_context',
1555
+				'label'      => null,
1556
+				'input'      => 'hidden',
1557
+				'type'       => 'string',
1558
+				'required'   => false,
1559
+				'validation' => true,
1560
+				'value'      => $context,
1561
+				'css_class'  => '',
1562
+				'format'     => '%s',
1563
+				'db-col'     => 'MTP_context'
1564
+			);
1565 1565
             
1566
-            $template_form_fields['ee-msg-grp-id'] = array(
1567
-                'name'       => 'GRP_ID',
1568
-                'label'      => null,
1569
-                'input'      => 'hidden',
1570
-                'type'       => 'int',
1571
-                'required'   => false,
1572
-                'validation' => true,
1573
-                'value'      => $GRP_ID,
1574
-                'css_class'  => '',
1575
-                'format'     => '%d',
1576
-                'db-col'     => 'GRP_ID'
1577
-            );
1566
+			$template_form_fields['ee-msg-grp-id'] = array(
1567
+				'name'       => 'GRP_ID',
1568
+				'label'      => null,
1569
+				'input'      => 'hidden',
1570
+				'type'       => 'int',
1571
+				'required'   => false,
1572
+				'validation' => true,
1573
+				'value'      => $GRP_ID,
1574
+				'css_class'  => '',
1575
+				'format'     => '%d',
1576
+				'db-col'     => 'GRP_ID'
1577
+			);
1578 1578
             
1579
-            $template_form_fields['ee-msg-messenger'] = array(
1580
-                'name'       => 'MTP_messenger',
1581
-                'label'      => null,
1582
-                'input'      => 'hidden',
1583
-                'type'       => 'string',
1584
-                'required'   => false,
1585
-                'validation' => true,
1586
-                'value'      => $message_template_group->messenger(),
1587
-                'css_class'  => '',
1588
-                'format'     => '%s',
1589
-                'db-col'     => 'MTP_messenger'
1590
-            );
1579
+			$template_form_fields['ee-msg-messenger'] = array(
1580
+				'name'       => 'MTP_messenger',
1581
+				'label'      => null,
1582
+				'input'      => 'hidden',
1583
+				'type'       => 'string',
1584
+				'required'   => false,
1585
+				'validation' => true,
1586
+				'value'      => $message_template_group->messenger(),
1587
+				'css_class'  => '',
1588
+				'format'     => '%s',
1589
+				'db-col'     => 'MTP_messenger'
1590
+			);
1591 1591
             
1592
-            $template_form_fields['ee-msg-message-type'] = array(
1593
-                'name'       => 'MTP_message_type',
1594
-                'label'      => null,
1595
-                'input'      => 'hidden',
1596
-                'type'       => 'string',
1597
-                'required'   => false,
1598
-                'validation' => true,
1599
-                'value'      => $message_template_group->message_type(),
1600
-                'css_class'  => '',
1601
-                'format'     => '%s',
1602
-                'db-col'     => 'MTP_message_type'
1603
-            );
1592
+			$template_form_fields['ee-msg-message-type'] = array(
1593
+				'name'       => 'MTP_message_type',
1594
+				'label'      => null,
1595
+				'input'      => 'hidden',
1596
+				'type'       => 'string',
1597
+				'required'   => false,
1598
+				'validation' => true,
1599
+				'value'      => $message_template_group->message_type(),
1600
+				'css_class'  => '',
1601
+				'format'     => '%s',
1602
+				'db-col'     => 'MTP_message_type'
1603
+			);
1604 1604
             
1605
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1606
-                'name'       => 'MTP_is_global',
1607
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1608
-                'input'      => 'hidden',
1609
-                'type'       => 'int',
1610
-                'required'   => false,
1611
-                'validation' => true,
1612
-                'value'      => $message_template_group->get('MTP_is_global'),
1613
-                'css_class'  => '',
1614
-                'format'     => '%d',
1615
-                'db-col'     => 'MTP_is_global'
1616
-            );
1605
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1606
+				'name'       => 'MTP_is_global',
1607
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1608
+				'input'      => 'hidden',
1609
+				'type'       => 'int',
1610
+				'required'   => false,
1611
+				'validation' => true,
1612
+				'value'      => $message_template_group->get('MTP_is_global'),
1613
+				'css_class'  => '',
1614
+				'format'     => '%d',
1615
+				'db-col'     => 'MTP_is_global'
1616
+			);
1617 1617
             
1618
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1619
-                'name'       => 'MTP_is_override',
1620
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1621
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1622
-                'type'       => 'int',
1623
-                'required'   => false,
1624
-                'validation' => true,
1625
-                'value'      => $message_template_group->get('MTP_is_override'),
1626
-                'css_class'  => '',
1627
-                'format'     => '%d',
1628
-                'db-col'     => 'MTP_is_override'
1629
-            );
1618
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1619
+				'name'       => 'MTP_is_override',
1620
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1621
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1622
+				'type'       => 'int',
1623
+				'required'   => false,
1624
+				'validation' => true,
1625
+				'value'      => $message_template_group->get('MTP_is_override'),
1626
+				'css_class'  => '',
1627
+				'format'     => '%d',
1628
+				'db-col'     => 'MTP_is_override'
1629
+			);
1630 1630
             
1631
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1632
-                'name'       => 'MTP_is_active',
1633
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1634
-                'input'      => 'hidden',
1635
-                'type'       => 'int',
1636
-                'required'   => false,
1637
-                'validation' => true,
1638
-                'value'      => $message_template_group->is_active(),
1639
-                'css_class'  => '',
1640
-                'format'     => '%d',
1641
-                'db-col'     => 'MTP_is_active'
1642
-            );
1631
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1632
+				'name'       => 'MTP_is_active',
1633
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1634
+				'input'      => 'hidden',
1635
+				'type'       => 'int',
1636
+				'required'   => false,
1637
+				'validation' => true,
1638
+				'value'      => $message_template_group->is_active(),
1639
+				'css_class'  => '',
1640
+				'format'     => '%d',
1641
+				'db-col'     => 'MTP_is_active'
1642
+			);
1643 1643
             
1644
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1645
-                'name'       => 'MTP_deleted',
1646
-                'label'      => null,
1647
-                'input'      => 'hidden',
1648
-                'type'       => 'int',
1649
-                'required'   => false,
1650
-                'validation' => true,
1651
-                'value'      => $message_template_group->get('MTP_deleted'),
1652
-                'css_class'  => '',
1653
-                'format'     => '%d',
1654
-                'db-col'     => 'MTP_deleted'
1655
-            );
1656
-            $sidebar_form_fields['ee-msg-author']  = array(
1657
-                'name'       => 'MTP_user_id',
1658
-                'label'      => esc_html__('Author', 'event_espresso'),
1659
-                'input'      => 'hidden',
1660
-                'type'       => 'int',
1661
-                'required'   => false,
1662
-                'validation' => false,
1663
-                'value'      => $message_template_group->user(),
1664
-                'format'     => '%d',
1665
-                'db-col'     => 'MTP_user_id'
1666
-            );
1644
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1645
+				'name'       => 'MTP_deleted',
1646
+				'label'      => null,
1647
+				'input'      => 'hidden',
1648
+				'type'       => 'int',
1649
+				'required'   => false,
1650
+				'validation' => true,
1651
+				'value'      => $message_template_group->get('MTP_deleted'),
1652
+				'css_class'  => '',
1653
+				'format'     => '%d',
1654
+				'db-col'     => 'MTP_deleted'
1655
+			);
1656
+			$sidebar_form_fields['ee-msg-author']  = array(
1657
+				'name'       => 'MTP_user_id',
1658
+				'label'      => esc_html__('Author', 'event_espresso'),
1659
+				'input'      => 'hidden',
1660
+				'type'       => 'int',
1661
+				'required'   => false,
1662
+				'validation' => false,
1663
+				'value'      => $message_template_group->user(),
1664
+				'format'     => '%d',
1665
+				'db-col'     => 'MTP_user_id'
1666
+			);
1667 1667
             
1668
-            $sidebar_form_fields['ee-msg-route'] = array(
1669
-                'name'  => 'action',
1670
-                'input' => 'hidden',
1671
-                'type'  => 'string',
1672
-                'value' => $action
1673
-            );
1668
+			$sidebar_form_fields['ee-msg-route'] = array(
1669
+				'name'  => 'action',
1670
+				'input' => 'hidden',
1671
+				'type'  => 'string',
1672
+				'value' => $action
1673
+			);
1674 1674
             
1675
-            $sidebar_form_fields['ee-msg-id']        = array(
1676
-                'name'  => 'id',
1677
-                'input' => 'hidden',
1678
-                'type'  => 'int',
1679
-                'value' => $GRP_ID
1680
-            );
1681
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1682
-                'name'  => $action . '_nonce',
1683
-                'input' => 'hidden',
1684
-                'type'  => 'string',
1685
-                'value' => wp_create_nonce($action . '_nonce')
1686
-            );
1675
+			$sidebar_form_fields['ee-msg-id']        = array(
1676
+				'name'  => 'id',
1677
+				'input' => 'hidden',
1678
+				'type'  => 'int',
1679
+				'value' => $GRP_ID
1680
+			);
1681
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1682
+				'name'  => $action . '_nonce',
1683
+				'input' => 'hidden',
1684
+				'type'  => 'string',
1685
+				'value' => wp_create_nonce($action . '_nonce')
1686
+			);
1687 1687
             
1688
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1689
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1690
-                    'name'  => 'template_switch',
1691
-                    'input' => 'hidden',
1692
-                    'type'  => 'int',
1693
-                    'value' => 1
1694
-                );
1695
-            }
1688
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1689
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1690
+					'name'  => 'template_switch',
1691
+					'input' => 'hidden',
1692
+					'type'  => 'int',
1693
+					'value' => 1
1694
+				);
1695
+			}
1696 1696
             
1697 1697
             
1698
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1699
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1698
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1699
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1700 1700
             
1701 1701
             
1702
-        } //end if ( !empty($template_field_structure) )
1703
-        
1704
-        //set extra content for publish box
1705
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1706
-        $this->_set_publish_post_box_vars(
1707
-            'id',
1708
-            $GRP_ID,
1709
-            false,
1710
-            add_query_arg(
1711
-                array('action' => 'global_mtps'),
1712
-                $this->_admin_base_url
1713
-            )
1714
-        );
1715
-        
1716
-        //add preview button
1717
-        $preview_url    = parent::add_query_args_and_nonce(
1718
-            array(
1719
-                'message_type' => $message_template_group->message_type(),
1720
-                'messenger'    => $message_template_group->messenger(),
1721
-                'context'      => $context,
1722
-                'GRP_ID'       => $GRP_ID,
1723
-                'action'       => 'preview_message'
1724
-            ),
1725
-            $this->_admin_base_url
1726
-        );
1727
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1728
-                          . esc_html__('Preview', 'event_espresso')
1729
-                          . '</a>';
1730
-        
1731
-        
1732
-        //setup context switcher
1733
-        $context_switcher_args = array(
1734
-            'page'    => 'espresso_messages',
1735
-            'action'  => 'edit_message_template',
1736
-            'id'      => $GRP_ID,
1737
-            'context' => $context,
1738
-            'extra'   => $preview_button
1739
-        );
1740
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1741
-        
1742
-        
1743
-        //main box
1744
-        $this->_template_args['template_fields']                         = $template_fields;
1745
-        $this->_template_args['sidebar_box_id']                          = 'details';
1746
-        $this->_template_args['action']                                  = $action;
1747
-        $this->_template_args['context']                                 = $context;
1748
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1749
-        $this->_template_args['learn_more_about_message_templates_link'] =
1750
-            $this->_learn_more_about_message_templates_link();
1751
-        
1752
-        
1753
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1754
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1755
-            $message_template_group,
1756
-            $context,
1757
-            $context_label
1758
-        );
1759
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1760
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1761
-        
1762
-        $this->_template_path = $this->_template_args['GRP_ID']
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';
1765
-        
1766
-        //send along EE_Message_Template_Group object for further template use.
1767
-        $this->_template_args['MTP'] = $message_template_group;
1768
-        
1769
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1770
-            $this->_template_path,
1771
-            $this->_template_args,
1772
-            true
1773
-        );
1774
-        
1775
-        
1776
-        //finally, let's set the admin_page title
1777
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1778
-        
1779
-        
1780
-        //we need to take care of setting the shortcodes property for use elsewhere.
1781
-        $this->_set_shortcodes();
1782
-        
1783
-        
1784
-        //final template wrapper
1785
-        $this->display_admin_page_with_sidebar();
1786
-    }
1702
+		} //end if ( !empty($template_field_structure) )
1703
+        
1704
+		//set extra content for publish box
1705
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1706
+		$this->_set_publish_post_box_vars(
1707
+			'id',
1708
+			$GRP_ID,
1709
+			false,
1710
+			add_query_arg(
1711
+				array('action' => 'global_mtps'),
1712
+				$this->_admin_base_url
1713
+			)
1714
+		);
1715
+        
1716
+		//add preview button
1717
+		$preview_url    = parent::add_query_args_and_nonce(
1718
+			array(
1719
+				'message_type' => $message_template_group->message_type(),
1720
+				'messenger'    => $message_template_group->messenger(),
1721
+				'context'      => $context,
1722
+				'GRP_ID'       => $GRP_ID,
1723
+				'action'       => 'preview_message'
1724
+			),
1725
+			$this->_admin_base_url
1726
+		);
1727
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1728
+						  . esc_html__('Preview', 'event_espresso')
1729
+						  . '</a>';
1730
+        
1731
+        
1732
+		//setup context switcher
1733
+		$context_switcher_args = array(
1734
+			'page'    => 'espresso_messages',
1735
+			'action'  => 'edit_message_template',
1736
+			'id'      => $GRP_ID,
1737
+			'context' => $context,
1738
+			'extra'   => $preview_button
1739
+		);
1740
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1741
+        
1742
+        
1743
+		//main box
1744
+		$this->_template_args['template_fields']                         = $template_fields;
1745
+		$this->_template_args['sidebar_box_id']                          = 'details';
1746
+		$this->_template_args['action']                                  = $action;
1747
+		$this->_template_args['context']                                 = $context;
1748
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1749
+		$this->_template_args['learn_more_about_message_templates_link'] =
1750
+			$this->_learn_more_about_message_templates_link();
1751
+        
1752
+        
1753
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1754
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1755
+			$message_template_group,
1756
+			$context,
1757
+			$context_label
1758
+		);
1759
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1760
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1761
+        
1762
+		$this->_template_path = $this->_template_args['GRP_ID']
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';
1765
+        
1766
+		//send along EE_Message_Template_Group object for further template use.
1767
+		$this->_template_args['MTP'] = $message_template_group;
1768
+        
1769
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1770
+			$this->_template_path,
1771
+			$this->_template_args,
1772
+			true
1773
+		);
1774
+        
1775
+        
1776
+		//finally, let's set the admin_page title
1777
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1778
+        
1779
+        
1780
+		//we need to take care of setting the shortcodes property for use elsewhere.
1781
+		$this->_set_shortcodes();
1782
+        
1783
+        
1784
+		//final template wrapper
1785
+		$this->display_admin_page_with_sidebar();
1786
+	}
1787 1787
     
1788 1788
     
1789
-    public function filter_tinymce_init($mceInit, $editor_id)
1790
-    {
1791
-        return $mceInit;
1792
-    }
1789
+	public function filter_tinymce_init($mceInit, $editor_id)
1790
+	{
1791
+		return $mceInit;
1792
+	}
1793 1793
     
1794 1794
     
1795
-    public function add_context_switcher()
1796
-    {
1797
-        return $this->_context_switcher;
1798
-    }
1795
+	public function add_context_switcher()
1796
+	{
1797
+		return $this->_context_switcher;
1798
+	}
1799 1799
 
1800 1800
 
1801
-    /**
1802
-     * Adds the activation/deactivation toggle for the message template context.
1803
-     *
1804
-     * @param EE_Message_Template_Group $message_template_group
1805
-     * @param string                    $context
1806
-     * @param string                    $context_label
1807
-     * @return string
1808
-     * @throws DomainException
1809
-     * @throws EE_Error
1810
-     * @throws InvalidIdentifierException
1811
-     */
1812
-    protected function add_active_context_element(
1813
-        EE_Message_Template_Group $message_template_group,
1814
-        $context,
1815
-        $context_label
1816
-    ) {
1817
-        $template_args = array(
1818
-            'context' => $context,
1819
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1820
-            'is_active' => $message_template_group->is_context_active($context),
1821
-            'on_off_action' => $message_template_group->is_context_active($context)
1822
-                ? 'context-off'
1823
-                : 'context-on',
1824
-            'context_label' => str_replace(array('(', ')'), '', $context_label),
1825
-            'message_template_group_id' => $message_template_group->ID()
1826
-        );
1827
-        return EEH_Template::display_template(
1828
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1829
-          $template_args,
1830
-          true
1831
-        );
1832
-    }
1801
+	/**
1802
+	 * Adds the activation/deactivation toggle for the message template context.
1803
+	 *
1804
+	 * @param EE_Message_Template_Group $message_template_group
1805
+	 * @param string                    $context
1806
+	 * @param string                    $context_label
1807
+	 * @return string
1808
+	 * @throws DomainException
1809
+	 * @throws EE_Error
1810
+	 * @throws InvalidIdentifierException
1811
+	 */
1812
+	protected function add_active_context_element(
1813
+		EE_Message_Template_Group $message_template_group,
1814
+		$context,
1815
+		$context_label
1816
+	) {
1817
+		$template_args = array(
1818
+			'context' => $context,
1819
+			'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1820
+			'is_active' => $message_template_group->is_context_active($context),
1821
+			'on_off_action' => $message_template_group->is_context_active($context)
1822
+				? 'context-off'
1823
+				: 'context-on',
1824
+			'context_label' => str_replace(array('(', ')'), '', $context_label),
1825
+			'message_template_group_id' => $message_template_group->ID()
1826
+		);
1827
+		return EEH_Template::display_template(
1828
+		  EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1829
+		  $template_args,
1830
+		  true
1831
+		);
1832
+	}
1833 1833
 
1834 1834
 
1835
-    /**
1836
-     * Ajax callback for `toggle_context_template` ajax action.
1837
-     * Handles toggling the message context on or off.
1838
-     * @throws EE_Error
1839
-     * @throws InvalidArgumentException
1840
-     * @throws InvalidDataTypeException
1841
-     * @throws InvalidIdentifierException
1842
-     * @throws InvalidInterfaceException
1843
-     */
1844
-    public function toggle_context_template()
1845
-    {
1846
-        $success = true;
1847
-        //check for required data
1848
-        if (!isset(
1849
-            $this->_req_data['message_template_group_id'],
1850
-            $this->_req_data['context'],
1851
-            $this->_req_data['status']
1852
-        )) {
1853
-            EE_Error::add_error(
1854
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1855
-                __FILE__,
1856
-                __FUNCTION__,
1857
-                __LINE__
1858
-            );
1859
-            $success = false;
1860
-        }
1835
+	/**
1836
+	 * Ajax callback for `toggle_context_template` ajax action.
1837
+	 * Handles toggling the message context on or off.
1838
+	 * @throws EE_Error
1839
+	 * @throws InvalidArgumentException
1840
+	 * @throws InvalidDataTypeException
1841
+	 * @throws InvalidIdentifierException
1842
+	 * @throws InvalidInterfaceException
1843
+	 */
1844
+	public function toggle_context_template()
1845
+	{
1846
+		$success = true;
1847
+		//check for required data
1848
+		if (!isset(
1849
+			$this->_req_data['message_template_group_id'],
1850
+			$this->_req_data['context'],
1851
+			$this->_req_data['status']
1852
+		)) {
1853
+			EE_Error::add_error(
1854
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1855
+				__FILE__,
1856
+				__FUNCTION__,
1857
+				__LINE__
1858
+			);
1859
+			$success = false;
1860
+		}
1861 1861
 
1862
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1863
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1864
-            : '';
1865
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1866
-        $this->_verify_nonce($nonce, $nonce_ref);
1867
-        $status = $this->_req_data['status'];
1868
-        if ($status !== 'off' && $status !=='on') {
1869
-            EE_Error::add_error(
1870
-                sprintf(
1871
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1872
-                    $this->_req_data['status']
1873
-                ),
1874
-                __FILE__,
1875
-                __FUNCTION__,
1876
-                __LINE__
1877
-            );
1878
-            $success = false;
1879
-        }
1880
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1881
-            $this->_req_data['message_template_group_id']
1882
-        );
1883
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1884
-            EE_Error::add_error(
1885
-                sprintf(
1886
-                    esc_html__(
1887
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1888
-                        'event_espresso'
1889
-                    ),
1890
-                    $this->_req_data['message_template_group_id'],
1891
-                    'EE_Message_Template_Group'
1892
-                ),
1893
-                __FILE__,
1894
-                __FUNCTION__,
1895
-                __LINE__
1896
-            );
1897
-            $success = false;
1898
-        }
1899
-        if ($success) {
1900
-            $success = $status === 'off'
1901
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1902
-                : $message_template_group->activate_context($this->_req_data['context']);
1903
-        }
1904
-        $this->_template_args['success'] = $success;
1905
-        $this->_return_json();
1906
-    }
1862
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1863
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1864
+			: '';
1865
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1866
+		$this->_verify_nonce($nonce, $nonce_ref);
1867
+		$status = $this->_req_data['status'];
1868
+		if ($status !== 'off' && $status !=='on') {
1869
+			EE_Error::add_error(
1870
+				sprintf(
1871
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1872
+					$this->_req_data['status']
1873
+				),
1874
+				__FILE__,
1875
+				__FUNCTION__,
1876
+				__LINE__
1877
+			);
1878
+			$success = false;
1879
+		}
1880
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1881
+			$this->_req_data['message_template_group_id']
1882
+		);
1883
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1884
+			EE_Error::add_error(
1885
+				sprintf(
1886
+					esc_html__(
1887
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1888
+						'event_espresso'
1889
+					),
1890
+					$this->_req_data['message_template_group_id'],
1891
+					'EE_Message_Template_Group'
1892
+				),
1893
+				__FILE__,
1894
+				__FUNCTION__,
1895
+				__LINE__
1896
+			);
1897
+			$success = false;
1898
+		}
1899
+		if ($success) {
1900
+			$success = $status === 'off'
1901
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1902
+				: $message_template_group->activate_context($this->_req_data['context']);
1903
+		}
1904
+		$this->_template_args['success'] = $success;
1905
+		$this->_return_json();
1906
+	}
1907 1907
 
1908 1908
 
1909 1909
     
1910
-    public function _add_form_element_before()
1911
-    {
1912
-        return '<form method="post" action="'
1913
-               . $this->_template_args["edit_message_template_form_url"]
1914
-               . '" id="ee-msg-edit-frm">';
1915
-    }
1910
+	public function _add_form_element_before()
1911
+	{
1912
+		return '<form method="post" action="'
1913
+			   . $this->_template_args["edit_message_template_form_url"]
1914
+			   . '" id="ee-msg-edit-frm">';
1915
+	}
1916 1916
     
1917
-    public function _add_form_element_after()
1918
-    {
1919
-        return '</form>';
1920
-    }
1917
+	public function _add_form_element_after()
1918
+	{
1919
+		return '</form>';
1920
+	}
1921 1921
 
1922 1922
 
1923
-    /**
1924
-     * This executes switching the template pack for a message template.
1925
-     *
1926
-     * @since 4.5.0
1927
-     * @throws EE_Error
1928
-     * @throws InvalidDataTypeException
1929
-     * @throws InvalidInterfaceException
1930
-     * @throws InvalidArgumentException
1931
-     * @throws ReflectionException
1932
-     */
1933
-    public function switch_template_pack()
1934
-    {
1935
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1936
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1937
-        
1938
-        //verify we have needed values.
1939
-        if (empty($GRP_ID) || empty($template_pack)) {
1940
-            $this->_template_args['error'] = true;
1941
-            EE_Error::add_error(
1942
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1943
-                __FILE__,
1944
-                __FUNCTION__,
1945
-                __LINE__
1946
-            );
1947
-        } else {
1948
-            //get template, set the new template_pack and then reset to default
1949
-            /** @type EE_Message_Template_Group $message_template_group */
1950
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1923
+	/**
1924
+	 * This executes switching the template pack for a message template.
1925
+	 *
1926
+	 * @since 4.5.0
1927
+	 * @throws EE_Error
1928
+	 * @throws InvalidDataTypeException
1929
+	 * @throws InvalidInterfaceException
1930
+	 * @throws InvalidArgumentException
1931
+	 * @throws ReflectionException
1932
+	 */
1933
+	public function switch_template_pack()
1934
+	{
1935
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1936
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1937
+        
1938
+		//verify we have needed values.
1939
+		if (empty($GRP_ID) || empty($template_pack)) {
1940
+			$this->_template_args['error'] = true;
1941
+			EE_Error::add_error(
1942
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1943
+				__FILE__,
1944
+				__FUNCTION__,
1945
+				__LINE__
1946
+			);
1947
+		} else {
1948
+			//get template, set the new template_pack and then reset to default
1949
+			/** @type EE_Message_Template_Group $message_template_group */
1950
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1951 1951
             
1952
-            $message_template_group->set_template_pack_name($template_pack);
1953
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1954
-            $this->_req_data['mt']   = $message_template_group->message_type();
1952
+			$message_template_group->set_template_pack_name($template_pack);
1953
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1954
+			$this->_req_data['mt']   = $message_template_group->message_type();
1955 1955
             
1956
-            $query_args = $this->_reset_to_default_template();
1956
+			$query_args = $this->_reset_to_default_template();
1957 1957
             
1958
-            if (empty($query_args['id'])) {
1959
-                EE_Error::add_error(
1960
-                    esc_html__(
1961
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1962
-                        'event_espresso'
1963
-                    ),
1964
-                    __FILE__,
1965
-                    __FUNCTION__,
1966
-                    __LINE__
1967
-                );
1968
-                $this->_template_args['error'] = true;
1969
-            } else {
1970
-                $template_label       = $message_template_group->get_template_pack()->label;
1971
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1972
-                EE_Error::add_success(
1973
-                    sprintf(
1974
-                        esc_html__(
1975
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1976
-                            'event_espresso'
1977
-                        ),
1978
-                        $template_label,
1979
-                        $template_pack_labels->template_pack
1980
-                    )
1981
-                );
1982
-                //generate the redirect url for js.
1983
-                $url                                          = self::add_query_args_and_nonce($query_args,
1984
-                    $this->_admin_base_url);
1985
-                $this->_template_args['data']['redirect_url'] = $url;
1986
-                $this->_template_args['success']              = true;
1987
-            }
1958
+			if (empty($query_args['id'])) {
1959
+				EE_Error::add_error(
1960
+					esc_html__(
1961
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1962
+						'event_espresso'
1963
+					),
1964
+					__FILE__,
1965
+					__FUNCTION__,
1966
+					__LINE__
1967
+				);
1968
+				$this->_template_args['error'] = true;
1969
+			} else {
1970
+				$template_label       = $message_template_group->get_template_pack()->label;
1971
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1972
+				EE_Error::add_success(
1973
+					sprintf(
1974
+						esc_html__(
1975
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1976
+							'event_espresso'
1977
+						),
1978
+						$template_label,
1979
+						$template_pack_labels->template_pack
1980
+					)
1981
+				);
1982
+				//generate the redirect url for js.
1983
+				$url                                          = self::add_query_args_and_nonce($query_args,
1984
+					$this->_admin_base_url);
1985
+				$this->_template_args['data']['redirect_url'] = $url;
1986
+				$this->_template_args['success']              = true;
1987
+			}
1988 1988
             
1989
-            $this->_return_json();
1989
+			$this->_return_json();
1990 1990
             
1991
-        }
1992
-    }
1991
+		}
1992
+	}
1993 1993
 
1994 1994
 
1995
-    /**
1996
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1997
-     * they want.
1998
-     *
1999
-     * @access protected
2000
-     * @return array|null
2001
-     * @throws EE_Error
2002
-     * @throws InvalidArgumentException
2003
-     * @throws InvalidDataTypeException
2004
-     * @throws InvalidInterfaceException
2005
-     */
2006
-    protected function _reset_to_default_template()
2007
-    {
2008
-        
2009
-        $templates = array();
2010
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2011
-        //we need to make sure we've got the info we need.
2012
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2013
-            EE_Error::add_error(
2014
-                esc_html__(
2015
-                    '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.',
2016
-                    'event_espresso'
2017
-                ),
2018
-                __FILE__, __FUNCTION__, __LINE__
2019
-            );
2020
-        }
2021
-        
2022
-        // all templates will be reset to whatever the defaults are
2023
-        // for the global template matching the messenger and message type.
2024
-        $success = ! empty($GRP_ID) ? true : false;
2025
-        
2026
-        if ($success) {
1995
+	/**
1996
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1997
+	 * they want.
1998
+	 *
1999
+	 * @access protected
2000
+	 * @return array|null
2001
+	 * @throws EE_Error
2002
+	 * @throws InvalidArgumentException
2003
+	 * @throws InvalidDataTypeException
2004
+	 * @throws InvalidInterfaceException
2005
+	 */
2006
+	protected function _reset_to_default_template()
2007
+	{
2008
+        
2009
+		$templates = array();
2010
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2011
+		//we need to make sure we've got the info we need.
2012
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2013
+			EE_Error::add_error(
2014
+				esc_html__(
2015
+					'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.',
2016
+					'event_espresso'
2017
+				),
2018
+				__FILE__, __FUNCTION__, __LINE__
2019
+			);
2020
+		}
2021
+        
2022
+		// all templates will be reset to whatever the defaults are
2023
+		// for the global template matching the messenger and message type.
2024
+		$success = ! empty($GRP_ID) ? true : false;
2025
+        
2026
+		if ($success) {
2027 2027
             
2028
-            //let's first determine if the incoming template is a global template,
2029
-            // if it isn't then we need to get the global template matching messenger and message type.
2030
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2028
+			//let's first determine if the incoming template is a global template,
2029
+			// if it isn't then we need to get the global template matching messenger and message type.
2030
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2031 2031
             
2032 2032
             
2033
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2034
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2033
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2034
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2035 2035
             
2036
-            if ($success) {
2037
-                // if successfully deleted, lets generate the new ones.
2038
-                // Note. We set GLOBAL to true, because resets on ANY template
2039
-                // will use the related global template defaults for regeneration.
2040
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2041
-                // HOWEVER, we DO keep the template pack and template variation set
2042
-                // for the current custom template when resetting.
2043
-                $templates = $this->_generate_new_templates(
2044
-                    $this->_req_data['msgr'],
2045
-                    $this->_req_data['mt'],
2046
-                    $GRP_ID,
2047
-                    true
2048
-                );
2049
-            }
2036
+			if ($success) {
2037
+				// if successfully deleted, lets generate the new ones.
2038
+				// Note. We set GLOBAL to true, because resets on ANY template
2039
+				// will use the related global template defaults for regeneration.
2040
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2041
+				// HOWEVER, we DO keep the template pack and template variation set
2042
+				// for the current custom template when resetting.
2043
+				$templates = $this->_generate_new_templates(
2044
+					$this->_req_data['msgr'],
2045
+					$this->_req_data['mt'],
2046
+					$GRP_ID,
2047
+					true
2048
+				);
2049
+			}
2050 2050
             
2051
-        }
2052
-        
2053
-        //any error messages?
2054
-        if ( ! $success) {
2055
-            EE_Error::add_error(
2056
-                esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2057
-                    'event_espresso'),
2058
-                __FILE__, __FUNCTION__, __LINE__
2059
-            );
2060
-        }
2061
-        
2062
-        //all good, let's add a success message!
2063
-        if ($success && ! empty($templates)) {
2064
-            //the info for the template we generated is the first element in the returned array
2065
-            // $templates = $templates[0];
2066
-            EE_Error::overwrite_success();
2067
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2068
-        }
2069
-        
2070
-        
2071
-        $query_args = array(
2072
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2073
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2074
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2075
-        );
2076
-        
2077
-        //if called via ajax then we return query args otherwise redirect
2078
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2079
-            return $query_args;
2080
-        } else {
2081
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2051
+		}
2052
+        
2053
+		//any error messages?
2054
+		if ( ! $success) {
2055
+			EE_Error::add_error(
2056
+				esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2057
+					'event_espresso'),
2058
+				__FILE__, __FUNCTION__, __LINE__
2059
+			);
2060
+		}
2061
+        
2062
+		//all good, let's add a success message!
2063
+		if ($success && ! empty($templates)) {
2064
+			//the info for the template we generated is the first element in the returned array
2065
+			// $templates = $templates[0];
2066
+			EE_Error::overwrite_success();
2067
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2068
+		}
2069
+        
2070
+        
2071
+		$query_args = array(
2072
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2073
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2074
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2075
+		);
2076
+        
2077
+		//if called via ajax then we return query args otherwise redirect
2078
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2079
+			return $query_args;
2080
+		} else {
2081
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2082 2082
 
2083
-            return null;
2084
-        }
2085
-    }
2083
+			return null;
2084
+		}
2085
+	}
2086 2086
 
2087 2087
 
2088
-    /**
2089
-     * Retrieve and set the message preview for display.
2090
-     *
2091
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2092
-     * @return string
2093
-     * @throws ReflectionException
2094
-     * @throws EE_Error
2095
-     * @throws InvalidArgumentException
2096
-     * @throws InvalidDataTypeException
2097
-     * @throws InvalidInterfaceException
2098
-     */
2099
-    public function _preview_message($send = false)
2100
-    {
2101
-        //first make sure we've got the necessary parameters
2102
-        if (
2103
-        ! isset(
2104
-            $this->_req_data['message_type'],
2105
-            $this->_req_data['messenger'],
2106
-            $this->_req_data['messenger'],
2107
-            $this->_req_data['GRP_ID']
2108
-        )
2109
-        ) {
2110
-            EE_Error::add_error(
2111
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2112
-                __FILE__, __FUNCTION__, __LINE__
2113
-            );
2114
-        }
2115
-        
2116
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2117
-        
2118
-        
2119
-        //get the preview!
2120
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2121
-            $this->_req_data['messenger'], $send);
2122
-        
2123
-        if ($send) {
2124
-            return $preview;
2125
-        }
2126
-        
2127
-        //let's add a button to go back to the edit view
2128
-        $query_args             = array(
2129
-            'id'      => $this->_req_data['GRP_ID'],
2130
-            'context' => $this->_req_data['context'],
2131
-            'action'  => 'edit_message_template'
2132
-        );
2133
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2134
-        $preview_button         = '<a href="'
2135
-                                  . $go_back_url
2136
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2137
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2138
-                                  . '</a>';
2139
-        $message_types          = $this->get_installed_message_types();
2140
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger(
2141
-                $this->_req_data['messenger']
2142
-        );
2143
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2144
-            ? ucwords($active_messenger->label['singular'])
2145
-            : esc_html__('Unknown Messenger', 'event_espresso');
2146
-        //let's provide a helpful title for context
2147
-        $preview_title = sprintf(
2148
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2149
-            $active_messenger_label,
2150
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2151
-        );
2152
-        //setup display of preview.
2153
-        $this->_admin_page_title                    = $preview_title;
2154
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2155
-        $this->_template_args['data']['force_json'] = true;
2156
-        
2157
-        return '';
2158
-    }
2088
+	/**
2089
+	 * Retrieve and set the message preview for display.
2090
+	 *
2091
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2092
+	 * @return string
2093
+	 * @throws ReflectionException
2094
+	 * @throws EE_Error
2095
+	 * @throws InvalidArgumentException
2096
+	 * @throws InvalidDataTypeException
2097
+	 * @throws InvalidInterfaceException
2098
+	 */
2099
+	public function _preview_message($send = false)
2100
+	{
2101
+		//first make sure we've got the necessary parameters
2102
+		if (
2103
+		! isset(
2104
+			$this->_req_data['message_type'],
2105
+			$this->_req_data['messenger'],
2106
+			$this->_req_data['messenger'],
2107
+			$this->_req_data['GRP_ID']
2108
+		)
2109
+		) {
2110
+			EE_Error::add_error(
2111
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2112
+				__FILE__, __FUNCTION__, __LINE__
2113
+			);
2114
+		}
2115
+        
2116
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2117
+        
2118
+        
2119
+		//get the preview!
2120
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2121
+			$this->_req_data['messenger'], $send);
2122
+        
2123
+		if ($send) {
2124
+			return $preview;
2125
+		}
2126
+        
2127
+		//let's add a button to go back to the edit view
2128
+		$query_args             = array(
2129
+			'id'      => $this->_req_data['GRP_ID'],
2130
+			'context' => $this->_req_data['context'],
2131
+			'action'  => 'edit_message_template'
2132
+		);
2133
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2134
+		$preview_button         = '<a href="'
2135
+								  . $go_back_url
2136
+								  . '" class="button-secondary messages-preview-go-back-button">'
2137
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2138
+								  . '</a>';
2139
+		$message_types          = $this->get_installed_message_types();
2140
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger(
2141
+				$this->_req_data['messenger']
2142
+		);
2143
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2144
+			? ucwords($active_messenger->label['singular'])
2145
+			: esc_html__('Unknown Messenger', 'event_espresso');
2146
+		//let's provide a helpful title for context
2147
+		$preview_title = sprintf(
2148
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2149
+			$active_messenger_label,
2150
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2151
+		);
2152
+		//setup display of preview.
2153
+		$this->_admin_page_title                    = $preview_title;
2154
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2155
+		$this->_template_args['data']['force_json'] = true;
2156
+        
2157
+		return '';
2158
+	}
2159 2159
     
2160 2160
     
2161
-    /**
2162
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2163
-     * gets called automatically.
2164
-     *
2165
-     * @since 4.5.0
2166
-     *
2167
-     * @return string
2168
-     */
2169
-    protected function _display_preview_message()
2170
-    {
2171
-        $this->display_admin_page_with_no_sidebar();
2172
-    }
2161
+	/**
2162
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2163
+	 * gets called automatically.
2164
+	 *
2165
+	 * @since 4.5.0
2166
+	 *
2167
+	 * @return string
2168
+	 */
2169
+	protected function _display_preview_message()
2170
+	{
2171
+		$this->display_admin_page_with_no_sidebar();
2172
+	}
2173 2173
     
2174 2174
     
2175
-    /**
2176
-     * registers metaboxes that should show up on the "edit_message_template" page
2177
-     *
2178
-     * @access protected
2179
-     * @return void
2180
-     */
2181
-    protected function _register_edit_meta_boxes()
2182
-    {
2183
-        add_meta_box(
2184
-            'mtp_valid_shortcodes',
2185
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2186
-            array($this, 'shortcode_meta_box'),
2187
-            $this->_current_screen->id,
2188
-            'side',
2189
-            'default');
2190
-        add_meta_box(
2191
-            'mtp_extra_actions',
2192
-            esc_html__('Extra Actions', 'event_espresso'),
2193
-            array($this, 'extra_actions_meta_box'),
2194
-            $this->_current_screen->id,
2195
-            'side',
2196
-            'high'
2197
-        );
2198
-        add_meta_box(
2199
-            'mtp_templates',
2200
-            esc_html__('Template Styles', 'event_espresso'),
2201
-            array($this, 'template_pack_meta_box'),
2202
-            $this->_current_screen->id,
2203
-            'side',
2204
-            'high'
2205
-        );
2206
-    }
2175
+	/**
2176
+	 * registers metaboxes that should show up on the "edit_message_template" page
2177
+	 *
2178
+	 * @access protected
2179
+	 * @return void
2180
+	 */
2181
+	protected function _register_edit_meta_boxes()
2182
+	{
2183
+		add_meta_box(
2184
+			'mtp_valid_shortcodes',
2185
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2186
+			array($this, 'shortcode_meta_box'),
2187
+			$this->_current_screen->id,
2188
+			'side',
2189
+			'default');
2190
+		add_meta_box(
2191
+			'mtp_extra_actions',
2192
+			esc_html__('Extra Actions', 'event_espresso'),
2193
+			array($this, 'extra_actions_meta_box'),
2194
+			$this->_current_screen->id,
2195
+			'side',
2196
+			'high'
2197
+		);
2198
+		add_meta_box(
2199
+			'mtp_templates',
2200
+			esc_html__('Template Styles', 'event_espresso'),
2201
+			array($this, 'template_pack_meta_box'),
2202
+			$this->_current_screen->id,
2203
+			'side',
2204
+			'high'
2205
+		);
2206
+	}
2207 2207
 
2208 2208
 
2209
-    /**
2210
-     * metabox content for all template pack and variation selection.
2211
-     *
2212
-     * @since 4.5.0
2213
-     * @return string
2214
-     * @throws DomainException
2215
-     * @throws EE_Error
2216
-     * @throws InvalidArgumentException
2217
-     * @throws ReflectionException
2218
-     * @throws InvalidDataTypeException
2219
-     * @throws InvalidInterfaceException
2220
-     */
2221
-    public function template_pack_meta_box()
2222
-    {
2223
-        $this->_set_message_template_group();
2224
-        
2225
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2226
-        
2227
-        $tp_select_values = array();
2228
-        
2229
-        foreach ($tp_collection as $tp) {
2230
-            //only include template packs that support this messenger and message type!
2231
-            $supports = $tp->get_supports();
2232
-            if (
2233
-                ! isset($supports[$this->_message_template_group->messenger()])
2234
-                || ! in_array(
2235
-                    $this->_message_template_group->message_type(),
2236
-                    $supports[$this->_message_template_group->messenger()],
2237
-                    true
2238
-                )
2239
-            ) {
2240
-                //not supported
2241
-                continue;
2242
-            }
2209
+	/**
2210
+	 * metabox content for all template pack and variation selection.
2211
+	 *
2212
+	 * @since 4.5.0
2213
+	 * @return string
2214
+	 * @throws DomainException
2215
+	 * @throws EE_Error
2216
+	 * @throws InvalidArgumentException
2217
+	 * @throws ReflectionException
2218
+	 * @throws InvalidDataTypeException
2219
+	 * @throws InvalidInterfaceException
2220
+	 */
2221
+	public function template_pack_meta_box()
2222
+	{
2223
+		$this->_set_message_template_group();
2224
+        
2225
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2226
+        
2227
+		$tp_select_values = array();
2228
+        
2229
+		foreach ($tp_collection as $tp) {
2230
+			//only include template packs that support this messenger and message type!
2231
+			$supports = $tp->get_supports();
2232
+			if (
2233
+				! isset($supports[$this->_message_template_group->messenger()])
2234
+				|| ! in_array(
2235
+					$this->_message_template_group->message_type(),
2236
+					$supports[$this->_message_template_group->messenger()],
2237
+					true
2238
+				)
2239
+			) {
2240
+				//not supported
2241
+				continue;
2242
+			}
2243 2243
             
2244
-            $tp_select_values[] = array(
2245
-                'text' => $tp->label,
2246
-                'id'   => $tp->dbref
2247
-            );
2248
-        }
2249
-        
2250
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2251
-        // the default template pack.  This still allows for the odd template pack to override.
2252
-        if (empty($tp_select_values)) {
2253
-            $tp_select_values[] = array(
2254
-                'text' => esc_html__('Default', 'event_espresso'),
2255
-                'id'   => 'default'
2256
-            );
2257
-        }
2258
-        
2259
-        //setup variation select values for the currently selected template.
2260
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2261
-            $this->_message_template_group->messenger(),
2262
-            $this->_message_template_group->message_type()
2263
-        );
2264
-        $variations_select_values = array();
2265
-        foreach ($variations as $variation => $label) {
2266
-            $variations_select_values[] = array(
2267
-                'text' => $label,
2268
-                'id'   => $variation
2269
-            );
2270
-        }
2271
-        
2272
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2273
-        
2274
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2275
-            'MTP_template_pack',
2276
-            $tp_select_values,
2277
-            $this->_message_template_group->get_template_pack_name()
2278
-        );
2279
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2280
-            'MTP_template_variation',
2281
-            $variations_select_values,
2282
-            $this->_message_template_group->get_template_pack_variation()
2283
-        );
2284
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2285
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2286
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2287
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2288
-        
2289
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2290
-        
2291
-        EEH_Template::display_template($template, $template_args);
2292
-    }
2244
+			$tp_select_values[] = array(
2245
+				'text' => $tp->label,
2246
+				'id'   => $tp->dbref
2247
+			);
2248
+		}
2249
+        
2250
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2251
+		// the default template pack.  This still allows for the odd template pack to override.
2252
+		if (empty($tp_select_values)) {
2253
+			$tp_select_values[] = array(
2254
+				'text' => esc_html__('Default', 'event_espresso'),
2255
+				'id'   => 'default'
2256
+			);
2257
+		}
2258
+        
2259
+		//setup variation select values for the currently selected template.
2260
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2261
+			$this->_message_template_group->messenger(),
2262
+			$this->_message_template_group->message_type()
2263
+		);
2264
+		$variations_select_values = array();
2265
+		foreach ($variations as $variation => $label) {
2266
+			$variations_select_values[] = array(
2267
+				'text' => $label,
2268
+				'id'   => $variation
2269
+			);
2270
+		}
2271
+        
2272
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2273
+        
2274
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2275
+			'MTP_template_pack',
2276
+			$tp_select_values,
2277
+			$this->_message_template_group->get_template_pack_name()
2278
+		);
2279
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2280
+			'MTP_template_variation',
2281
+			$variations_select_values,
2282
+			$this->_message_template_group->get_template_pack_variation()
2283
+		);
2284
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2285
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2286
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2287
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2288
+        
2289
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2290
+        
2291
+		EEH_Template::display_template($template, $template_args);
2292
+	}
2293 2293
     
2294 2294
     
2295
-    /**
2296
-     * This meta box holds any extra actions related to Message Templates
2297
-     * For now, this includes Resetting templates to defaults and sending a test email.
2298
-     *
2299
-     * @access  public
2300
-     * @return void
2301
-     * @throws EE_Error
2302
-     */
2303
-    public function extra_actions_meta_box()
2304
-    {
2305
-        $template_form_fields = array();
2306
-        
2307
-        $extra_args = array(
2308
-            'msgr'   => $this->_message_template_group->messenger(),
2309
-            'mt'     => $this->_message_template_group->message_type(),
2310
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2311
-        );
2312
-        //first we need to see if there are any fields
2313
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2314
-        
2315
-        if ( ! empty($fields)) {
2316
-            //yup there be fields
2317
-            foreach ($fields as $field => $config) {
2318
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2319
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2320
-                $default  = isset($config['default']) ? $config['default'] : '';
2321
-                $default  = isset($config['value']) ? $config['value'] : $default;
2295
+	/**
2296
+	 * This meta box holds any extra actions related to Message Templates
2297
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2298
+	 *
2299
+	 * @access  public
2300
+	 * @return void
2301
+	 * @throws EE_Error
2302
+	 */
2303
+	public function extra_actions_meta_box()
2304
+	{
2305
+		$template_form_fields = array();
2306
+        
2307
+		$extra_args = array(
2308
+			'msgr'   => $this->_message_template_group->messenger(),
2309
+			'mt'     => $this->_message_template_group->message_type(),
2310
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2311
+		);
2312
+		//first we need to see if there are any fields
2313
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2314
+        
2315
+		if ( ! empty($fields)) {
2316
+			//yup there be fields
2317
+			foreach ($fields as $field => $config) {
2318
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2319
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2320
+				$default  = isset($config['default']) ? $config['default'] : '';
2321
+				$default  = isset($config['value']) ? $config['value'] : $default;
2322 2322
                 
2323
-                // if type is hidden and the value is empty
2324
-                // something may have gone wrong so let's correct with the defaults
2325
-                $fix              = $config['input'] === 'hidden'
2326
-                                    && isset($existing[$field])
2327
-                                    && empty($existing[$field])
2328
-                    ? $default
2329
-                    : '';
2330
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2331
-                    ? $existing[$field]
2332
-                    : $fix;
2323
+				// if type is hidden and the value is empty
2324
+				// something may have gone wrong so let's correct with the defaults
2325
+				$fix              = $config['input'] === 'hidden'
2326
+									&& isset($existing[$field])
2327
+									&& empty($existing[$field])
2328
+					? $default
2329
+					: '';
2330
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2331
+					? $existing[$field]
2332
+					: $fix;
2333 2333
                 
2334
-                $template_form_fields[$field_id] = array(
2335
-                    'name'       => 'test_settings_fld[' . $field . ']',
2336
-                    'label'      => $config['label'],
2337
-                    'input'      => $config['input'],
2338
-                    'type'       => $config['type'],
2339
-                    'required'   => $config['required'],
2340
-                    'validation' => $config['validation'],
2341
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2342
-                    'css_class'  => $config['css_class'],
2343
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2344
-                    'default'    => $default,
2345
-                    'format'     => $config['format']
2346
-                );
2347
-            }
2348
-        }
2349
-        
2350
-        $test_settings_fields = ! empty($template_form_fields)
2351
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2352
-            : '';
2353
-        
2354
-        $test_settings_html = '';
2355
-        //print out $test_settings_fields
2356
-        if ( ! empty($test_settings_fields)) {
2357
-            echo $test_settings_fields;
2358
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2359
-            $test_settings_html .= 'name="test_button" value="';
2360
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2361
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2362
-        }
2363
-        
2364
-        //and button
2365
-        $test_settings_html .= '<p>'
2366
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2367
-                               . '</p>';
2368
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2369
-        $test_settings_html .= $this->get_action_link_or_button(
2370
-            'reset_to_default',
2371
-            'reset',
2372
-            $extra_args,
2373
-            'button-primary reset-default-button'
2374
-        );
2375
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2376
-        echo $test_settings_html;
2377
-    }
2334
+				$template_form_fields[$field_id] = array(
2335
+					'name'       => 'test_settings_fld[' . $field . ']',
2336
+					'label'      => $config['label'],
2337
+					'input'      => $config['input'],
2338
+					'type'       => $config['type'],
2339
+					'required'   => $config['required'],
2340
+					'validation' => $config['validation'],
2341
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2342
+					'css_class'  => $config['css_class'],
2343
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2344
+					'default'    => $default,
2345
+					'format'     => $config['format']
2346
+				);
2347
+			}
2348
+		}
2349
+        
2350
+		$test_settings_fields = ! empty($template_form_fields)
2351
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2352
+			: '';
2353
+        
2354
+		$test_settings_html = '';
2355
+		//print out $test_settings_fields
2356
+		if ( ! empty($test_settings_fields)) {
2357
+			echo $test_settings_fields;
2358
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2359
+			$test_settings_html .= 'name="test_button" value="';
2360
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2361
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2362
+		}
2363
+        
2364
+		//and button
2365
+		$test_settings_html .= '<p>'
2366
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2367
+							   . '</p>';
2368
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2369
+		$test_settings_html .= $this->get_action_link_or_button(
2370
+			'reset_to_default',
2371
+			'reset',
2372
+			$extra_args,
2373
+			'button-primary reset-default-button'
2374
+		);
2375
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2376
+		echo $test_settings_html;
2377
+	}
2378 2378
 
2379 2379
 
2380
-    /**
2381
-     * This returns the shortcode selector skeleton for a given context and field.
2382
-     *
2383
-     * @since 4.9.rc.000
2384
-     * @param string $field           The name of the field retrieving shortcodes for.
2385
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2386
-     * @return string
2387
-     * @throws DomainException
2388
-     * @throws EE_Error
2389
-     * @throws InvalidArgumentException
2390
-     * @throws ReflectionException
2391
-     * @throws InvalidDataTypeException
2392
-     * @throws InvalidInterfaceException
2393
-     */
2394
-    protected function _get_shortcode_selector($field, $linked_input_id)
2395
-    {
2396
-        $template_args = array(
2397
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2398
-            'fieldname'       => $field,
2399
-            'linked_input_id' => $linked_input_id
2400
-        );
2401
-        
2402
-        return EEH_Template::display_template(
2403
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2404
-            $template_args,
2405
-            true
2406
-        );
2407
-    }
2380
+	/**
2381
+	 * This returns the shortcode selector skeleton for a given context and field.
2382
+	 *
2383
+	 * @since 4.9.rc.000
2384
+	 * @param string $field           The name of the field retrieving shortcodes for.
2385
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2386
+	 * @return string
2387
+	 * @throws DomainException
2388
+	 * @throws EE_Error
2389
+	 * @throws InvalidArgumentException
2390
+	 * @throws ReflectionException
2391
+	 * @throws InvalidDataTypeException
2392
+	 * @throws InvalidInterfaceException
2393
+	 */
2394
+	protected function _get_shortcode_selector($field, $linked_input_id)
2395
+	{
2396
+		$template_args = array(
2397
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2398
+			'fieldname'       => $field,
2399
+			'linked_input_id' => $linked_input_id
2400
+		);
2401
+        
2402
+		return EEH_Template::display_template(
2403
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2404
+			$template_args,
2405
+			true
2406
+		);
2407
+	}
2408 2408
 
2409 2409
 
2410
-    /**
2411
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2412
-     * page)
2413
-     *
2414
-     * @access public
2415
-     * @return void
2416
-     * @throws EE_Error
2417
-     * @throws InvalidArgumentException
2418
-     * @throws ReflectionException
2419
-     * @throws InvalidDataTypeException
2420
-     * @throws InvalidInterfaceException
2421
-     */
2422
-    public function shortcode_meta_box()
2423
-    {
2424
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2425
-        //$messenger = $this->_message_template_group->messenger_obj();
2426
-        //now let's set the content depending on the status of the shortcodes array
2427
-        if (empty($shortcodes)) {
2428
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2429
-            echo $content;
2430
-        } else {
2431
-            //$alt = 0;
2432
-            ?>
2410
+	/**
2411
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2412
+	 * page)
2413
+	 *
2414
+	 * @access public
2415
+	 * @return void
2416
+	 * @throws EE_Error
2417
+	 * @throws InvalidArgumentException
2418
+	 * @throws ReflectionException
2419
+	 * @throws InvalidDataTypeException
2420
+	 * @throws InvalidInterfaceException
2421
+	 */
2422
+	public function shortcode_meta_box()
2423
+	{
2424
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2425
+		//$messenger = $this->_message_template_group->messenger_obj();
2426
+		//now let's set the content depending on the status of the shortcodes array
2427
+		if (empty($shortcodes)) {
2428
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2429
+			echo $content;
2430
+		} else {
2431
+			//$alt = 0;
2432
+			?>
2433 2433
             <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2434 2434
             <p class="small-text"><?php printf(
2435
-                    esc_html__(
2436
-                        'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2437
-                        'event_espresso'
2438
-                    ),
2439
-                    '<span class="dashicons dashicons-menu"></span>'
2440
-                ); ?></p>
2435
+					esc_html__(
2436
+						'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2437
+						'event_espresso'
2438
+					),
2439
+					'<span class="dashicons dashicons-menu"></span>'
2440
+				); ?></p>
2441 2441
             <?php
2442
-        }
2442
+		}
2443 2443
         
2444 2444
         
2445
-    }
2445
+	}
2446 2446
 
2447 2447
 
2448
-    /**
2449
-     * used to set the $_shortcodes property for when its needed elsewhere.
2450
-     *
2451
-     * @access protected
2452
-     * @return void
2453
-     * @throws EE_Error
2454
-     * @throws InvalidArgumentException
2455
-     * @throws ReflectionException
2456
-     * @throws InvalidDataTypeException
2457
-     * @throws InvalidInterfaceException
2458
-     */
2459
-    protected function _set_shortcodes()
2460
-    {
2461
-        
2462
-        //no need to run this if the property is already set
2463
-        if ( ! empty($this->_shortcodes)) {
2464
-            return;
2465
-        }
2466
-        
2467
-        $this->_shortcodes = $this->_get_shortcodes();
2468
-    }
2448
+	/**
2449
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2450
+	 *
2451
+	 * @access protected
2452
+	 * @return void
2453
+	 * @throws EE_Error
2454
+	 * @throws InvalidArgumentException
2455
+	 * @throws ReflectionException
2456
+	 * @throws InvalidDataTypeException
2457
+	 * @throws InvalidInterfaceException
2458
+	 */
2459
+	protected function _set_shortcodes()
2460
+	{
2461
+        
2462
+		//no need to run this if the property is already set
2463
+		if ( ! empty($this->_shortcodes)) {
2464
+			return;
2465
+		}
2466
+        
2467
+		$this->_shortcodes = $this->_get_shortcodes();
2468
+	}
2469 2469
 
2470 2470
 
2471
-    /**
2472
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2473
-     * property)
2474
-     *
2475
-     * @access  protected
2476
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2477
-     *                         for. Defaults to all (for the given context)
2478
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2479
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2480
-     *                         true just an array of shortcode/label pairs.
2481
-     * @throws EE_Error
2482
-     * @throws InvalidArgumentException
2483
-     * @throws ReflectionException
2484
-     * @throws InvalidDataTypeException
2485
-     * @throws InvalidInterfaceException
2486
-     */
2487
-    protected function _get_shortcodes($fields = array(), $merged = true)
2488
-    {
2489
-        $this->_set_message_template_group();
2490
-        
2491
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2492
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2493
-            ? absint($this->_req_data['id'])
2494
-            : false;
2495
-        $context = isset($this->_req_data['context'])
2496
-            ? $this->_req_data['context']
2497
-            : key($this->_message_template_group->contexts_config());
2498
-        
2499
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2500
-    }
2471
+	/**
2472
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2473
+	 * property)
2474
+	 *
2475
+	 * @access  protected
2476
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2477
+	 *                         for. Defaults to all (for the given context)
2478
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2479
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2480
+	 *                         true just an array of shortcode/label pairs.
2481
+	 * @throws EE_Error
2482
+	 * @throws InvalidArgumentException
2483
+	 * @throws ReflectionException
2484
+	 * @throws InvalidDataTypeException
2485
+	 * @throws InvalidInterfaceException
2486
+	 */
2487
+	protected function _get_shortcodes($fields = array(), $merged = true)
2488
+	{
2489
+		$this->_set_message_template_group();
2490
+        
2491
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2492
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2493
+			? absint($this->_req_data['id'])
2494
+			: false;
2495
+		$context = isset($this->_req_data['context'])
2496
+			? $this->_req_data['context']
2497
+			: key($this->_message_template_group->contexts_config());
2498
+        
2499
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2500
+	}
2501 2501
 
2502 2502
 
2503
-    /**
2504
-     * This sets the _message_template property (containing the called message_template object)
2505
-     *
2506
-     * @access protected
2507
-     * @return void
2508
-     * @throws EE_Error
2509
-     * @throws InvalidArgumentException
2510
-     * @throws ReflectionException
2511
-     * @throws InvalidDataTypeException
2512
-     * @throws InvalidInterfaceException
2513
-     */
2514
-    protected function _set_message_template_group()
2515
-    {
2516
-        
2517
-        if ( ! empty($this->_message_template_group)) {
2518
-            return;
2519
-        } //get out if this is already set.
2520
-        
2521
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2522
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2523
-        
2524
-        //let's get the message templates
2525
-        $MTP = EEM_Message_Template_Group::instance();
2526
-        
2527
-        if (empty($GRP_ID)) {
2528
-            $this->_message_template_group = $MTP->create_default_object();
2529
-        } else {
2530
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2531
-        }
2532
-        
2533
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2534
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2535
-        
2536
-    }
2503
+	/**
2504
+	 * This sets the _message_template property (containing the called message_template object)
2505
+	 *
2506
+	 * @access protected
2507
+	 * @return void
2508
+	 * @throws EE_Error
2509
+	 * @throws InvalidArgumentException
2510
+	 * @throws ReflectionException
2511
+	 * @throws InvalidDataTypeException
2512
+	 * @throws InvalidInterfaceException
2513
+	 */
2514
+	protected function _set_message_template_group()
2515
+	{
2516
+        
2517
+		if ( ! empty($this->_message_template_group)) {
2518
+			return;
2519
+		} //get out if this is already set.
2520
+        
2521
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2522
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2523
+        
2524
+		//let's get the message templates
2525
+		$MTP = EEM_Message_Template_Group::instance();
2526
+        
2527
+		if (empty($GRP_ID)) {
2528
+			$this->_message_template_group = $MTP->create_default_object();
2529
+		} else {
2530
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2531
+		}
2532
+        
2533
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2534
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2535
+        
2536
+	}
2537 2537
 
2538 2538
 
2539
-    /**
2540
-     * sets up a context switcher for edit forms
2541
-     *
2542
-     * @access  protected
2543
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2544
-     * @param array                      $args                  various things the context switcher needs.
2545
-     * @throws EE_Error
2546
-     */
2547
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2548
-    {
2549
-        $context_details = $template_group_object->contexts_config();
2550
-        $context_label   = $template_group_object->context_label();
2551
-        ob_start();
2552
-        ?>
2539
+	/**
2540
+	 * sets up a context switcher for edit forms
2541
+	 *
2542
+	 * @access  protected
2543
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2544
+	 * @param array                      $args                  various things the context switcher needs.
2545
+	 * @throws EE_Error
2546
+	 */
2547
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2548
+	{
2549
+		$context_details = $template_group_object->contexts_config();
2550
+		$context_label   = $template_group_object->context_label();
2551
+		ob_start();
2552
+		?>
2553 2553
         <div class="ee-msg-switcher-container">
2554 2554
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2555 2555
                 <?php
2556
-                foreach ($args as $name => $value) {
2557
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2558
-                        continue;
2559
-                    }
2560
-                    ?>
2556
+				foreach ($args as $name => $value) {
2557
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2558
+						continue;
2559
+					}
2560
+					?>
2561 2561
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2562 2562
                     <?php
2563
-                }
2564
-                //setup nonce_url
2565
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2566
-                ?>
2563
+				}
2564
+				//setup nonce_url
2565
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2566
+				?>
2567 2567
                 <select name="context">
2568 2568
                     <?php
2569
-                    $context_templates = $template_group_object->context_templates();
2570
-                    if (is_array($context_templates)) :
2571
-                        foreach ($context_templates as $context => $template_fields) :
2572
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2573
-                            ?>
2569
+					$context_templates = $template_group_object->context_templates();
2570
+					if (is_array($context_templates)) :
2571
+						foreach ($context_templates as $context => $template_fields) :
2572
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2573
+							?>
2574 2574
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2575 2575
                                 <?php echo $context_details[$context]['label']; ?>
2576 2576
                             </option>
@@ -2583,1853 +2583,1853 @@  discard block
 block discarded – undo
2583 2583
             <?php echo $args['extra']; ?>
2584 2584
         </div> <!-- end .ee-msg-switcher-container -->
2585 2585
         <?php
2586
-        $output = ob_get_contents();
2587
-        ob_clean();
2588
-        $this->_context_switcher = $output;
2589
-    }
2586
+		$output = ob_get_contents();
2587
+		ob_clean();
2588
+		$this->_context_switcher = $output;
2589
+	}
2590 2590
     
2591 2591
     
2592
-    /**
2593
-     * utility for sanitizing new values coming in.
2594
-     * Note: this is only used when updating a context.
2595
-     *
2596
-     * @access protected
2597
-     *
2598
-     * @param int $index This helps us know which template field to select from the request array.
2599
-     *
2600
-     * @return array
2601
-     */
2602
-    protected function _set_message_template_column_values($index)
2603
-    {
2604
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2605
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2606
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2607
-            }
2608
-        }
2609
-        
2610
-        
2611
-        $set_column_values = array(
2612
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2613
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2614
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2615
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2616
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2617
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2618
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2619
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2620
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2621
-                ? absint($this->_req_data['MTP_is_global'])
2622
-                : 0,
2623
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2624
-                ? absint($this->_req_data['MTP_is_override'])
2625
-                : 0,
2626
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2627
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2628
-        );
2629
-        
2630
-        
2631
-        return $set_column_values;
2632
-    }
2592
+	/**
2593
+	 * utility for sanitizing new values coming in.
2594
+	 * Note: this is only used when updating a context.
2595
+	 *
2596
+	 * @access protected
2597
+	 *
2598
+	 * @param int $index This helps us know which template field to select from the request array.
2599
+	 *
2600
+	 * @return array
2601
+	 */
2602
+	protected function _set_message_template_column_values($index)
2603
+	{
2604
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2605
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2606
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2607
+			}
2608
+		}
2609
+        
2610
+        
2611
+		$set_column_values = array(
2612
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2613
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2614
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2615
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2616
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2617
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2618
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2619
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2620
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2621
+				? absint($this->_req_data['MTP_is_global'])
2622
+				: 0,
2623
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2624
+				? absint($this->_req_data['MTP_is_override'])
2625
+				: 0,
2626
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2627
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2628
+		);
2629
+        
2630
+        
2631
+		return $set_column_values;
2632
+	}
2633 2633
     
2634 2634
     
2635
-    protected function _insert_or_update_message_template($new = false)
2636
-    {
2637
-        
2638
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2639
-        $success  = 0;
2640
-        $override = false;
2641
-        
2642
-        //setup notices description
2643
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2644
-        
2645
-        //need the message type and messenger objects to be able to use the labels for the notices
2646
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2647
-        $messenger_label  = $messenger_object instanceof EE_messenger
2648
-            ? ucwords($messenger_object->label['singular'])
2649
-            : '';
2650
-        
2651
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2652
-            ? $this->_req_data['MTP_message_type']
2653
-            : '';
2654
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2655
-        
2656
-        $message_type_label = $message_type_object instanceof EE_message_type
2657
-            ? ucwords($message_type_object->label['singular'])
2658
-            : '';
2659
-        
2660
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2661
-            ? $this->_req_data['MTP_context']
2662
-            : '';
2663
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2664
-        
2665
-        $item_desc = $messenger_label && $message_type_label
2666
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2667
-            : '';
2668
-        $item_desc .= 'Message Template';
2669
-        $query_args  = array();
2670
-        $edit_array  = array();
2671
-        $action_desc = '';
2672
-        
2673
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2674
-        // user to edit.
2675
-        if ($new) {
2676
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2677
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2678
-                if (empty($edit_array)) {
2679
-                    $success = 0;
2680
-                } else {
2681
-                    $success    = 1;
2682
-                    $edit_array = $edit_array[0];
2683
-                    $query_args = array(
2684
-                        'id'      => $edit_array['GRP_ID'],
2685
-                        'context' => $edit_array['MTP_context'],
2686
-                        'action'  => 'edit_message_template'
2687
-                    );
2688
-                }
2689
-            }
2690
-            $action_desc = 'created';
2691
-        } else {
2692
-            $MTPG = EEM_Message_Template_Group::instance();
2693
-            $MTP  = EEM_Message_Template::instance();
2635
+	protected function _insert_or_update_message_template($new = false)
2636
+	{
2637
+        
2638
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2639
+		$success  = 0;
2640
+		$override = false;
2641
+        
2642
+		//setup notices description
2643
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2644
+        
2645
+		//need the message type and messenger objects to be able to use the labels for the notices
2646
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2647
+		$messenger_label  = $messenger_object instanceof EE_messenger
2648
+			? ucwords($messenger_object->label['singular'])
2649
+			: '';
2650
+        
2651
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2652
+			? $this->_req_data['MTP_message_type']
2653
+			: '';
2654
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2655
+        
2656
+		$message_type_label = $message_type_object instanceof EE_message_type
2657
+			? ucwords($message_type_object->label['singular'])
2658
+			: '';
2659
+        
2660
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2661
+			? $this->_req_data['MTP_context']
2662
+			: '';
2663
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2664
+        
2665
+		$item_desc = $messenger_label && $message_type_label
2666
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2667
+			: '';
2668
+		$item_desc .= 'Message Template';
2669
+		$query_args  = array();
2670
+		$edit_array  = array();
2671
+		$action_desc = '';
2672
+        
2673
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2674
+		// user to edit.
2675
+		if ($new) {
2676
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2677
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2678
+				if (empty($edit_array)) {
2679
+					$success = 0;
2680
+				} else {
2681
+					$success    = 1;
2682
+					$edit_array = $edit_array[0];
2683
+					$query_args = array(
2684
+						'id'      => $edit_array['GRP_ID'],
2685
+						'context' => $edit_array['MTP_context'],
2686
+						'action'  => 'edit_message_template'
2687
+					);
2688
+				}
2689
+			}
2690
+			$action_desc = 'created';
2691
+		} else {
2692
+			$MTPG = EEM_Message_Template_Group::instance();
2693
+			$MTP  = EEM_Message_Template::instance();
2694 2694
             
2695 2695
             
2696
-            //run update for each template field in displayed context
2697
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2698
-                EE_Error::add_error(
2699
-                    esc_html__(
2700
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2701
-                        'event_espresso'
2702
-                    ),
2703
-                    __FILE__,
2704
-                    __FUNCTION__,
2705
-                    __LINE__
2706
-                );
2707
-                $success = 0;
2696
+			//run update for each template field in displayed context
2697
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2698
+				EE_Error::add_error(
2699
+					esc_html__(
2700
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2701
+						'event_espresso'
2702
+					),
2703
+					__FILE__,
2704
+					__FUNCTION__,
2705
+					__LINE__
2706
+				);
2707
+				$success = 0;
2708 2708
                 
2709
-            } else {
2710
-                //first validate all fields!
2711
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2712
-                    $message_type_slug);
2709
+			} else {
2710
+				//first validate all fields!
2711
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2712
+					$message_type_slug);
2713 2713
                 
2714
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2715
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2716
-                //  WE need to make sure there is no actual error messages in validates.
2717
-                if (is_array($validates) && ! empty($validates)) {
2718
-                    //add the transient so when the form loads we know which fields to highlight
2719
-                    $this->_add_transient('edit_message_template', $validates);
2714
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2715
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2716
+				//  WE need to make sure there is no actual error messages in validates.
2717
+				if (is_array($validates) && ! empty($validates)) {
2718
+					//add the transient so when the form loads we know which fields to highlight
2719
+					$this->_add_transient('edit_message_template', $validates);
2720 2720
                     
2721
-                    $success = 0;
2721
+					$success = 0;
2722 2722
                     
2723
-                    //setup notices
2724
-                    foreach ($validates as $field => $error) {
2725
-                        if (isset($error['msg'])) {
2726
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2727
-                        }
2728
-                    }
2723
+					//setup notices
2724
+					foreach ($validates as $field => $error) {
2725
+						if (isset($error['msg'])) {
2726
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2727
+						}
2728
+					}
2729 2729
                     
2730
-                } else {
2731
-                    $set_column_values = array();
2732
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2733
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2730
+				} else {
2731
+					$set_column_values = array();
2732
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2733
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2734 2734
                         
2735
-                        $where_cols_n_values = array(
2736
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2737
-                        );
2738
-                        //if they aren't allowed to use all JS, restrict them to just posty-y tags
2739
-                        if (! current_user_can('unfiltered_html')){
2740
-                            if (is_array($set_column_values['MTP_content'])){
2741
-                                 foreach($set_column_values['MTP_content'] as $key => $value) {
2742
-                                     $set_column_values['MTP_content'][$key] = wp_kses(
2743
-                                         $value,
2744
-                                         wp_kses_allowed_html('post')
2745
-                                     );
2746
-                                 }
2747
-                            } else {
2748
-                                $set_column_values['MTP_content'] = wp_kses(
2749
-                                    $set_column_values['MTP_content'],
2750
-                                    wp_kses_allowed_html('post')
2751
-                                );
2752
-                            }
2753
-                        }
2754
-                        $message_template_fields = array(
2755
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2756
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2757
-                            'MTP_context'        => $set_column_values['MTP_context'],
2758
-                            'MTP_content'        => $set_column_values['MTP_content']
2759
-                        );
2760
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2761
-                            if ($updated === false) {
2762
-                                EE_Error::add_error(
2763
-                                    sprintf(
2764
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2765
-                                        $template_field
2766
-                                    ),
2767
-                                    __FILE__,
2768
-                                    __FUNCTION__,
2769
-                                    __LINE__
2770
-                                );
2771
-                            } else {
2772
-                                $success = 1;
2773
-                            }
2774
-                        } else {
2775
-                            //only do this logic if we don't have a MTP_ID for this field
2776
-                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2777
-                                //this has already been through the template field validator and sanitized, so it will be
2778
-                                //safe to insert this field.  Why insert?  This typically happens when we introduce a new
2779
-                                //message template field in a messenger/message type and existing users don't have the
2780
-                                //default setup for it.
2781
-                                //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2782
-                                $updated = $MTP->insert($message_template_fields);
2783
-                                if (! $updated || is_wp_error($updated)) {
2784
-                                    EE_Error::add_error(
2785
-                                        sprintf(
2786
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2787
-                                            $template_field
2788
-                                        ),
2789
-                                        __FILE__,
2790
-                                        __FUNCTION__,
2791
-                                        __LINE__
2792
-                                    );
2793
-                                    $success = 0;
2794
-                                } else {
2795
-                                    $success = 1;
2796
-                                }
2797
-                            }
2798
-                        }
2799
-                        $action_desc = 'updated';
2800
-                    }
2735
+						$where_cols_n_values = array(
2736
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2737
+						);
2738
+						//if they aren't allowed to use all JS, restrict them to just posty-y tags
2739
+						if (! current_user_can('unfiltered_html')){
2740
+							if (is_array($set_column_values['MTP_content'])){
2741
+								 foreach($set_column_values['MTP_content'] as $key => $value) {
2742
+									 $set_column_values['MTP_content'][$key] = wp_kses(
2743
+										 $value,
2744
+										 wp_kses_allowed_html('post')
2745
+									 );
2746
+								 }
2747
+							} else {
2748
+								$set_column_values['MTP_content'] = wp_kses(
2749
+									$set_column_values['MTP_content'],
2750
+									wp_kses_allowed_html('post')
2751
+								);
2752
+							}
2753
+						}
2754
+						$message_template_fields = array(
2755
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2756
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2757
+							'MTP_context'        => $set_column_values['MTP_context'],
2758
+							'MTP_content'        => $set_column_values['MTP_content']
2759
+						);
2760
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2761
+							if ($updated === false) {
2762
+								EE_Error::add_error(
2763
+									sprintf(
2764
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2765
+										$template_field
2766
+									),
2767
+									__FILE__,
2768
+									__FUNCTION__,
2769
+									__LINE__
2770
+								);
2771
+							} else {
2772
+								$success = 1;
2773
+							}
2774
+						} else {
2775
+							//only do this logic if we don't have a MTP_ID for this field
2776
+							if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2777
+								//this has already been through the template field validator and sanitized, so it will be
2778
+								//safe to insert this field.  Why insert?  This typically happens when we introduce a new
2779
+								//message template field in a messenger/message type and existing users don't have the
2780
+								//default setup for it.
2781
+								//@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2782
+								$updated = $MTP->insert($message_template_fields);
2783
+								if (! $updated || is_wp_error($updated)) {
2784
+									EE_Error::add_error(
2785
+										sprintf(
2786
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2787
+											$template_field
2788
+										),
2789
+										__FILE__,
2790
+										__FUNCTION__,
2791
+										__LINE__
2792
+									);
2793
+									$success = 0;
2794
+								} else {
2795
+									$success = 1;
2796
+								}
2797
+							}
2798
+						}
2799
+						$action_desc = 'updated';
2800
+					}
2801 2801
                     
2802
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2803
-                    $mtpg_fields = array(
2804
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2805
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2806
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2807
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2808
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2809
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2810
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2811
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2812
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2813
-                            : '',
2814
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2815
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2816
-                            : ''
2817
-                    );
2802
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2803
+					$mtpg_fields = array(
2804
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2805
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2806
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2807
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2808
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2809
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2810
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2811
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2812
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2813
+							: '',
2814
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2815
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2816
+							: ''
2817
+					);
2818 2818
                     
2819
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2820
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2819
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2820
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2821 2821
                     
2822
-                    if ($updated === false) {
2823
-                        EE_Error::add_error(
2824
-                            sprintf(
2825
-                                esc_html__(
2826
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2827
-                                    'event_espresso'
2828
-                                ),
2829
-                                $set_column_values['GRP_ID']
2830
-                            ),
2831
-                            __FILE__,
2832
-                            __FUNCTION__,
2833
-                            __LINE__
2834
-                        );
2835
-                    } else {
2836
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2837
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2838
-                            ? $this->_req_data['MTP_template_pack']
2839
-                            : 'default';
2822
+					if ($updated === false) {
2823
+						EE_Error::add_error(
2824
+							sprintf(
2825
+								esc_html__(
2826
+									'The Message Template Group (%d) was NOT updated for some reason',
2827
+									'event_espresso'
2828
+								),
2829
+								$set_column_values['GRP_ID']
2830
+							),
2831
+							__FILE__,
2832
+							__FUNCTION__,
2833
+							__LINE__
2834
+						);
2835
+					} else {
2836
+						//k now we need to ensure the template_pack and template_variation fields are set.
2837
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2838
+							? $this->_req_data['MTP_template_pack']
2839
+							: 'default';
2840 2840
                         
2841
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2842
-                            ? $this->_req_data['MTP_template_variation']
2843
-                            : 'default';
2841
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2842
+							? $this->_req_data['MTP_template_variation']
2843
+							: 'default';
2844 2844
                         
2845
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2846
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2847
-                            $mtpg_obj->set_template_pack_name($template_pack);
2848
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2849
-                        }
2850
-                        $success = 1;
2851
-                    }
2852
-                }
2853
-            }
2845
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2846
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2847
+							$mtpg_obj->set_template_pack_name($template_pack);
2848
+							$mtpg_obj->set_template_pack_variation($template_variation);
2849
+						}
2850
+						$success = 1;
2851
+					}
2852
+				}
2853
+			}
2854 2854
             
2855
-        }
2856
-        
2857
-        //we return things differently if doing ajax
2858
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2859
-            $this->_template_args['success'] = $success;
2860
-            $this->_template_args['error']   = ! $success ? true : false;
2861
-            $this->_template_args['content'] = '';
2862
-            $this->_template_args['data']    = array(
2863
-                'grpID'        => $edit_array['GRP_ID'],
2864
-                'templateName' => $edit_array['template_name']
2865
-            );
2866
-            if ($success) {
2867
-                EE_Error::overwrite_success();
2868
-                EE_Error::add_success(
2869
-                    esc_html__(
2870
-                        '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.',
2871
-                        'event_espresso'
2872
-                    )
2873
-                );
2874
-            }
2855
+		}
2856
+        
2857
+		//we return things differently if doing ajax
2858
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2859
+			$this->_template_args['success'] = $success;
2860
+			$this->_template_args['error']   = ! $success ? true : false;
2861
+			$this->_template_args['content'] = '';
2862
+			$this->_template_args['data']    = array(
2863
+				'grpID'        => $edit_array['GRP_ID'],
2864
+				'templateName' => $edit_array['template_name']
2865
+			);
2866
+			if ($success) {
2867
+				EE_Error::overwrite_success();
2868
+				EE_Error::add_success(
2869
+					esc_html__(
2870
+						'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.',
2871
+						'event_espresso'
2872
+					)
2873
+				);
2874
+			}
2875 2875
             
2876
-            $this->_return_json();
2877
-        }
2878
-        
2879
-        
2880
-        //was a test send triggered?
2881
-        if (isset($this->_req_data['test_button'])) {
2882
-            EE_Error::overwrite_success();
2883
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2884
-            $override = true;
2885
-        }
2886
-        
2887
-        if (empty($query_args)) {
2888
-            $query_args = array(
2889
-                'id'      => $this->_req_data['GRP_ID'],
2890
-                'context' => $context_slug,
2891
-                'action'  => 'edit_message_template'
2892
-            );
2893
-        }
2894
-        
2895
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2896
-    }
2876
+			$this->_return_json();
2877
+		}
2878
+        
2879
+        
2880
+		//was a test send triggered?
2881
+		if (isset($this->_req_data['test_button'])) {
2882
+			EE_Error::overwrite_success();
2883
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2884
+			$override = true;
2885
+		}
2886
+        
2887
+		if (empty($query_args)) {
2888
+			$query_args = array(
2889
+				'id'      => $this->_req_data['GRP_ID'],
2890
+				'context' => $context_slug,
2891
+				'action'  => 'edit_message_template'
2892
+			);
2893
+		}
2894
+        
2895
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2896
+	}
2897 2897
 
2898 2898
 
2899
-    /**
2900
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2901
-     *
2902
-     * @param  string $context      what context being tested
2903
-     * @param  string $messenger    messenger being tested
2904
-     * @param  string $message_type message type being tested
2905
-     * @throws EE_Error
2906
-     * @throws InvalidArgumentException
2907
-     * @throws InvalidDataTypeException
2908
-     * @throws InvalidInterfaceException
2909
-     */
2910
-    protected function _do_test_send($context, $messenger, $message_type)
2911
-    {
2912
-        //set things up for preview
2913
-        $this->_req_data['messenger']    = $messenger;
2914
-        $this->_req_data['message_type'] = $message_type;
2915
-        $this->_req_data['context']      = $context;
2916
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2917
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2918
-        
2919
-        //let's save any existing fields that might be required by the messenger
2920
-        if (
2921
-            isset($this->_req_data['test_settings_fld'])
2922
-            && $active_messenger instanceof EE_messenger
2923
-            && apply_filters(
2924
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2925
-                true,
2926
-                $this->_req_data['test_settings_fld'],
2927
-                $active_messenger
2928
-            )
2929
-        ) {
2930
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2931
-        }
2932
-        
2933
-        $success = $this->_preview_message(true);
2934
-        
2935
-        if ($success) {
2936
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2937
-        } else {
2938
-            EE_Error::add_error(
2939
-                esc_html__('The test message was not sent', 'event_espresso'),
2940
-                __FILE__,
2941
-                __FUNCTION__,
2942
-                __LINE__
2943
-            );
2944
-        }
2945
-    }
2899
+	/**
2900
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2901
+	 *
2902
+	 * @param  string $context      what context being tested
2903
+	 * @param  string $messenger    messenger being tested
2904
+	 * @param  string $message_type message type being tested
2905
+	 * @throws EE_Error
2906
+	 * @throws InvalidArgumentException
2907
+	 * @throws InvalidDataTypeException
2908
+	 * @throws InvalidInterfaceException
2909
+	 */
2910
+	protected function _do_test_send($context, $messenger, $message_type)
2911
+	{
2912
+		//set things up for preview
2913
+		$this->_req_data['messenger']    = $messenger;
2914
+		$this->_req_data['message_type'] = $message_type;
2915
+		$this->_req_data['context']      = $context;
2916
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2917
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2918
+        
2919
+		//let's save any existing fields that might be required by the messenger
2920
+		if (
2921
+			isset($this->_req_data['test_settings_fld'])
2922
+			&& $active_messenger instanceof EE_messenger
2923
+			&& apply_filters(
2924
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2925
+				true,
2926
+				$this->_req_data['test_settings_fld'],
2927
+				$active_messenger
2928
+			)
2929
+		) {
2930
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2931
+		}
2932
+        
2933
+		$success = $this->_preview_message(true);
2934
+        
2935
+		if ($success) {
2936
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2937
+		} else {
2938
+			EE_Error::add_error(
2939
+				esc_html__('The test message was not sent', 'event_espresso'),
2940
+				__FILE__,
2941
+				__FUNCTION__,
2942
+				__LINE__
2943
+			);
2944
+		}
2945
+	}
2946 2946
     
2947 2947
     
2948
-    /**
2949
-     * _generate_new_templates
2950
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2951
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2952
-     * for the event.
2953
-     *
2954
-     *
2955
-     * @param  string $messenger     the messenger we are generating templates for
2956
-     * @param array   $message_types array of message types that the templates are generated for.
2957
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2958
-     *                               indicate the message_template_group being used as the base.
2959
-     *
2960
-     * @param bool    $global
2961
-     *
2962
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2963
-     *                               encountering problems.
2964
-     * @throws EE_Error
2965
-     */
2966
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2967
-    {
2968
-        
2969
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2970
-        // just don't generate any templates.
2971
-        if (empty($message_types)) {
2972
-            return true;
2973
-        }
2974
-        
2975
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2976
-    }
2948
+	/**
2949
+	 * _generate_new_templates
2950
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2951
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2952
+	 * for the event.
2953
+	 *
2954
+	 *
2955
+	 * @param  string $messenger     the messenger we are generating templates for
2956
+	 * @param array   $message_types array of message types that the templates are generated for.
2957
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2958
+	 *                               indicate the message_template_group being used as the base.
2959
+	 *
2960
+	 * @param bool    $global
2961
+	 *
2962
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2963
+	 *                               encountering problems.
2964
+	 * @throws EE_Error
2965
+	 */
2966
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2967
+	{
2968
+        
2969
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2970
+		// just don't generate any templates.
2971
+		if (empty($message_types)) {
2972
+			return true;
2973
+		}
2974
+        
2975
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2976
+	}
2977 2977
 
2978 2978
 
2979
-    /**
2980
-     * [_trash_or_restore_message_template]
2981
-     *
2982
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2983
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2984
-     *                        an individual context (FALSE).
2985
-     * @return void
2986
-     * @throws EE_Error
2987
-     * @throws InvalidArgumentException
2988
-     * @throws InvalidDataTypeException
2989
-     * @throws InvalidInterfaceException
2990
-     */
2991
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2992
-    {
2993
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2994
-        $MTP = EEM_Message_Template_Group::instance();
2995
-        
2996
-        $success = 1;
2997
-        
2998
-        //incoming GRP_IDs
2999
-        if ($all) {
3000
-            //Checkboxes
3001
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3002
-                //if array has more than one element then success message should be plural.
3003
-                //todo: what about nonce?
3004
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2979
+	/**
2980
+	 * [_trash_or_restore_message_template]
2981
+	 *
2982
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2983
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2984
+	 *                        an individual context (FALSE).
2985
+	 * @return void
2986
+	 * @throws EE_Error
2987
+	 * @throws InvalidArgumentException
2988
+	 * @throws InvalidDataTypeException
2989
+	 * @throws InvalidInterfaceException
2990
+	 */
2991
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2992
+	{
2993
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2994
+		$MTP = EEM_Message_Template_Group::instance();
2995
+        
2996
+		$success = 1;
2997
+        
2998
+		//incoming GRP_IDs
2999
+		if ($all) {
3000
+			//Checkboxes
3001
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3002
+				//if array has more than one element then success message should be plural.
3003
+				//todo: what about nonce?
3004
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3005 3005
                 
3006
-                //cycle through checkboxes
3007
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3008
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3009
-                    if ( ! $trashed_or_restored) {
3010
-                        $success = 0;
3011
-                    }
3012
-                }
3013
-            } else {
3014
-                //grab single GRP_ID and handle
3015
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3016
-                if ( ! empty($GRP_ID)) {
3017
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3018
-                    if ( ! $trashed_or_restored) {
3019
-                        $success = 0;
3020
-                    }
3021
-                } else {
3022
-                    $success = 0;
3023
-                }
3024
-            }
3006
+				//cycle through checkboxes
3007
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3008
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3009
+					if ( ! $trashed_or_restored) {
3010
+						$success = 0;
3011
+					}
3012
+				}
3013
+			} else {
3014
+				//grab single GRP_ID and handle
3015
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3016
+				if ( ! empty($GRP_ID)) {
3017
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3018
+					if ( ! $trashed_or_restored) {
3019
+						$success = 0;
3020
+					}
3021
+				} else {
3022
+					$success = 0;
3023
+				}
3024
+			}
3025 3025
             
3026
-        }
3026
+		}
3027 3027
         
3028
-        $action_desc = $trash
3029
-            ? esc_html__('moved to the trash', 'event_espresso')
3030
-            : esc_html__('restored', 'event_espresso');
3028
+		$action_desc = $trash
3029
+			? esc_html__('moved to the trash', 'event_espresso')
3030
+			: esc_html__('restored', 'event_espresso');
3031 3031
         
3032
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3032
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3033 3033
         
3034
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3035
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3034
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3035
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3036 3036
         
3037
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3038
-            'event_espresso') : $item_desc;
3037
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3038
+			'event_espresso') : $item_desc;
3039 3039
         
3040
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3040
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3041 3041
         
3042
-    }
3042
+	}
3043 3043
 
3044 3044
 
3045
-    /**
3046
-     * [_delete_message_template]
3047
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3048
-     *
3049
-     * @return void
3050
-     * @throws EE_Error
3051
-     * @throws InvalidArgumentException
3052
-     * @throws InvalidDataTypeException
3053
-     * @throws InvalidInterfaceException
3054
-     */
3055
-    protected function _delete_message_template()
3056
-    {
3057
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3058
-        
3059
-        //checkboxes
3060
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3061
-            //if array has more than one element then success message should be plural
3062
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3045
+	/**
3046
+	 * [_delete_message_template]
3047
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3048
+	 *
3049
+	 * @return void
3050
+	 * @throws EE_Error
3051
+	 * @throws InvalidArgumentException
3052
+	 * @throws InvalidDataTypeException
3053
+	 * @throws InvalidInterfaceException
3054
+	 */
3055
+	protected function _delete_message_template()
3056
+	{
3057
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3058
+        
3059
+		//checkboxes
3060
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3061
+			//if array has more than one element then success message should be plural
3062
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3063 3063
             
3064
-            //cycle through bulk action checkboxes
3065
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3066
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3067
-            }
3068
-        } else {
3069
-            //grab single grp_id and delete
3070
-            $GRP_ID  = absint($this->_req_data['id']);
3071
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3072
-        }
3073
-        
3074
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3075
-        
3076
-    }
3064
+			//cycle through bulk action checkboxes
3065
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3066
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3067
+			}
3068
+		} else {
3069
+			//grab single grp_id and delete
3070
+			$GRP_ID  = absint($this->_req_data['id']);
3071
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3072
+		}
3073
+        
3074
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3075
+        
3076
+	}
3077 3077
 
3078 3078
 
3079
-    /**
3080
-     * helper for permanently deleting a mtP group and all related message_templates
3081
-     *
3082
-     * @param  int  $GRP_ID        The group being deleted
3083
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3084
-     * @return bool boolean to indicate the success of the deletes or not.
3085
-     * @throws EE_Error
3086
-     * @throws InvalidArgumentException
3087
-     * @throws InvalidDataTypeException
3088
-     * @throws InvalidInterfaceException
3089
-     */
3090
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3091
-    {
3092
-        $success = 1;
3093
-        $MTPG    = EEM_Message_Template_Group::instance();
3094
-        //first let's GET this group
3095
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3096
-        //then delete permanently all the related Message Templates
3097
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3098
-        
3099
-        if ($deleted === 0) {
3100
-            $success = 0;
3101
-        }
3102
-        
3103
-        //now delete permanently this particular group
3104
-        
3105
-        if ($include_group && ! $MTG->delete_permanently()) {
3106
-            $success = 0;
3107
-        }
3108
-        
3109
-        return $success;
3110
-    }
3079
+	/**
3080
+	 * helper for permanently deleting a mtP group and all related message_templates
3081
+	 *
3082
+	 * @param  int  $GRP_ID        The group being deleted
3083
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3084
+	 * @return bool boolean to indicate the success of the deletes or not.
3085
+	 * @throws EE_Error
3086
+	 * @throws InvalidArgumentException
3087
+	 * @throws InvalidDataTypeException
3088
+	 * @throws InvalidInterfaceException
3089
+	 */
3090
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3091
+	{
3092
+		$success = 1;
3093
+		$MTPG    = EEM_Message_Template_Group::instance();
3094
+		//first let's GET this group
3095
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3096
+		//then delete permanently all the related Message Templates
3097
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3098
+        
3099
+		if ($deleted === 0) {
3100
+			$success = 0;
3101
+		}
3102
+        
3103
+		//now delete permanently this particular group
3104
+        
3105
+		if ($include_group && ! $MTG->delete_permanently()) {
3106
+			$success = 0;
3107
+		}
3108
+        
3109
+		return $success;
3110
+	}
3111 3111
     
3112 3112
     
3113
-    /**
3114
-     *    _learn_more_about_message_templates_link
3115
-     * @access protected
3116
-     * @return string
3117
-     */
3118
-    protected function _learn_more_about_message_templates_link()
3119
-    {
3120
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3121
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3122
-               . '</a>';
3123
-    }
3113
+	/**
3114
+	 *    _learn_more_about_message_templates_link
3115
+	 * @access protected
3116
+	 * @return string
3117
+	 */
3118
+	protected function _learn_more_about_message_templates_link()
3119
+	{
3120
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3121
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3122
+			   . '</a>';
3123
+	}
3124 3124
 
3125 3125
 
3126
-    /**
3127
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3128
-     * ajax and other routes.
3129
-     *
3130
-     * @return void
3131
-     * @throws DomainException
3132
-     */
3133
-    protected function _settings()
3134
-    {
3135
-        
3136
-        
3137
-        $this->_set_m_mt_settings();
3138
-        
3139
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3140
-            ? $this->_req_data['selected_messenger']
3141
-            : 'email';
3142
-        
3143
-        //let's setup the messenger tabs
3144
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3145
-            $this->_m_mt_settings['messenger_tabs'],
3146
-            'messenger_links',
3147
-            '|',
3148
-            $selected_messenger
3149
-        );
3150
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3151
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3152
-        
3153
-        $this->display_admin_page_with_sidebar();
3154
-        
3155
-    }
3126
+	/**
3127
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3128
+	 * ajax and other routes.
3129
+	 *
3130
+	 * @return void
3131
+	 * @throws DomainException
3132
+	 */
3133
+	protected function _settings()
3134
+	{
3135
+        
3136
+        
3137
+		$this->_set_m_mt_settings();
3138
+        
3139
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3140
+			? $this->_req_data['selected_messenger']
3141
+			: 'email';
3142
+        
3143
+		//let's setup the messenger tabs
3144
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3145
+			$this->_m_mt_settings['messenger_tabs'],
3146
+			'messenger_links',
3147
+			'|',
3148
+			$selected_messenger
3149
+		);
3150
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3151
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3152
+        
3153
+		$this->display_admin_page_with_sidebar();
3154
+        
3155
+	}
3156 3156
 
3157 3157
 
3158
-    /**
3159
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3160
-     *
3161
-     * @access protected
3162
-     * @return void
3163
-     * @throws DomainException
3164
-     */
3165
-    protected function _set_m_mt_settings()
3166
-    {
3167
-        //first if this is already set then lets get out no need to regenerate data.
3168
-        if ( ! empty($this->_m_mt_settings)) {
3169
-            return;
3170
-        }
3171
-        
3172
-        //get all installed messengers and message_types
3173
-        /** @type EE_messenger[] $messengers */
3174
-        $messengers = $this->_message_resource_manager->installed_messengers();
3175
-        /** @type EE_message_type[] $message_types */
3176
-        $message_types = $this->_message_resource_manager->installed_message_types();
3177
-        
3178
-        
3179
-        //assemble the array for the _tab_text_links helper
3180
-        
3181
-        foreach ($messengers as $messenger) {
3182
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3183
-                'label' => ucwords($messenger->label['singular']),
3184
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3185
-                    ? 'messenger-active'
3186
-                    : '',
3187
-                'href'  => $messenger->name,
3188
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3189
-                'slug'  => $messenger->name,
3190
-                'obj'   => $messenger
3191
-            );
3158
+	/**
3159
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3160
+	 *
3161
+	 * @access protected
3162
+	 * @return void
3163
+	 * @throws DomainException
3164
+	 */
3165
+	protected function _set_m_mt_settings()
3166
+	{
3167
+		//first if this is already set then lets get out no need to regenerate data.
3168
+		if ( ! empty($this->_m_mt_settings)) {
3169
+			return;
3170
+		}
3171
+        
3172
+		//get all installed messengers and message_types
3173
+		/** @type EE_messenger[] $messengers */
3174
+		$messengers = $this->_message_resource_manager->installed_messengers();
3175
+		/** @type EE_message_type[] $message_types */
3176
+		$message_types = $this->_message_resource_manager->installed_message_types();
3177
+        
3178
+        
3179
+		//assemble the array for the _tab_text_links helper
3180
+        
3181
+		foreach ($messengers as $messenger) {
3182
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3183
+				'label' => ucwords($messenger->label['singular']),
3184
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3185
+					? 'messenger-active'
3186
+					: '',
3187
+				'href'  => $messenger->name,
3188
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3189
+				'slug'  => $messenger->name,
3190
+				'obj'   => $messenger
3191
+			);
3192 3192
             
3193 3193
             
3194
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3194
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3195 3195
             
3196
-            foreach ($message_types as $message_type) {
3197
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3198
-                // it shouldn't show in either the inactive OR active metabox.
3199
-                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3200
-                    continue;
3201
-                }
3196
+			foreach ($message_types as $message_type) {
3197
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3198
+				// it shouldn't show in either the inactive OR active metabox.
3199
+				if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3200
+					continue;
3201
+				}
3202 3202
                 
3203
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3204
-                    $messenger->name,
3205
-                    $message_type->name
3206
-                )
3207
-                    ? 'active'
3208
-                    : 'inactive';
3203
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3204
+					$messenger->name,
3205
+					$message_type->name
3206
+				)
3207
+					? 'active'
3208
+					: 'inactive';
3209 3209
                 
3210
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3211
-                    'label'    => ucwords($message_type->label['singular']),
3212
-                    'class'    => 'message-type-' . $a_or_i,
3213
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3214
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3215
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3216
-                    'title'    => $a_or_i === 'active'
3217
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3218
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3219
-                    'content'  => $a_or_i === 'active'
3220
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3221
-                        : $this->_message_type_settings_content($message_type, $messenger),
3222
-                    'slug'     => $message_type->name,
3223
-                    'active'   => $a_or_i === 'active',
3224
-                    'obj'      => $message_type
3225
-                );
3226
-            }
3227
-        }
3228
-    }
3210
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3211
+					'label'    => ucwords($message_type->label['singular']),
3212
+					'class'    => 'message-type-' . $a_or_i,
3213
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3214
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3215
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3216
+					'title'    => $a_or_i === 'active'
3217
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3218
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3219
+					'content'  => $a_or_i === 'active'
3220
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3221
+						: $this->_message_type_settings_content($message_type, $messenger),
3222
+					'slug'     => $message_type->name,
3223
+					'active'   => $a_or_i === 'active',
3224
+					'obj'      => $message_type
3225
+				);
3226
+			}
3227
+		}
3228
+	}
3229 3229
 
3230 3230
 
3231
-    /**
3232
-     * This just prepares the content for the message type settings
3233
-     *
3234
-     * @param  EE_message_type  $message_type The message type object
3235
-     * @param  EE_messenger  $messenger    The messenger object
3236
-     * @param  boolean $active       Whether the message type is active or not
3237
-     * @return string html output for the content
3238
-     * @throws DomainException
3239
-     */
3240
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3241
-    {
3242
-        //get message type fields
3243
-        $fields                                         = $message_type->get_admin_settings_fields();
3244
-        $settings_template_args['template_form_fields'] = '';
3245
-        
3246
-        if ( ! empty($fields) && $active) {
3231
+	/**
3232
+	 * This just prepares the content for the message type settings
3233
+	 *
3234
+	 * @param  EE_message_type  $message_type The message type object
3235
+	 * @param  EE_messenger  $messenger    The messenger object
3236
+	 * @param  boolean $active       Whether the message type is active or not
3237
+	 * @return string html output for the content
3238
+	 * @throws DomainException
3239
+	 */
3240
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3241
+	{
3242
+		//get message type fields
3243
+		$fields                                         = $message_type->get_admin_settings_fields();
3244
+		$settings_template_args['template_form_fields'] = '';
3245
+        
3246
+		if ( ! empty($fields) && $active) {
3247 3247
             
3248
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3248
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3249 3249
             
3250
-            foreach ($fields as $fldname => $fldprops) {
3251
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3252
-                $template_form_field[$field_id] = array(
3253
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3254
-                    'label'      => $fldprops['label'],
3255
-                    'input'      => $fldprops['field_type'],
3256
-                    'type'       => $fldprops['value_type'],
3257
-                    'required'   => $fldprops['required'],
3258
-                    'validation' => $fldprops['validation'],
3259
-                    'value'      => isset($existing_settings[$fldname])
3260
-                        ? $existing_settings[$fldname]
3261
-                        : $fldprops['default'],
3262
-                    'options'    => isset($fldprops['options'])
3263
-                        ? $fldprops['options']
3264
-                        : array(),
3265
-                    'default'    => isset($existing_settings[$fldname])
3266
-                        ? $existing_settings[$fldname]
3267
-                        : $fldprops['default'],
3268
-                    'css_class'  => 'no-drag',
3269
-                    'format'     => $fldprops['format']
3270
-                );
3271
-            }
3250
+			foreach ($fields as $fldname => $fldprops) {
3251
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3252
+				$template_form_field[$field_id] = array(
3253
+					'name'       => 'message_type_settings[' . $fldname . ']',
3254
+					'label'      => $fldprops['label'],
3255
+					'input'      => $fldprops['field_type'],
3256
+					'type'       => $fldprops['value_type'],
3257
+					'required'   => $fldprops['required'],
3258
+					'validation' => $fldprops['validation'],
3259
+					'value'      => isset($existing_settings[$fldname])
3260
+						? $existing_settings[$fldname]
3261
+						: $fldprops['default'],
3262
+					'options'    => isset($fldprops['options'])
3263
+						? $fldprops['options']
3264
+						: array(),
3265
+					'default'    => isset($existing_settings[$fldname])
3266
+						? $existing_settings[$fldname]
3267
+						: $fldprops['default'],
3268
+					'css_class'  => 'no-drag',
3269
+					'format'     => $fldprops['format']
3270
+				);
3271
+			}
3272 3272
             
3273 3273
             
3274
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3275
-                ? $this->_generate_admin_form_fields(
3276
-                    $template_form_field,
3277
-                    'string',
3278
-                    'ee_mt_activate_form'
3279
-                )
3280
-                : '';
3281
-        }
3282
-        
3283
-        $settings_template_args['description'] = $message_type->description;
3284
-        //we also need some hidden fields
3285
-        $settings_template_args['hidden_fields'] = array(
3286
-            'message_type_settings[messenger]'    => array(
3287
-                'type'  => 'hidden',
3288
-                'value' => $messenger->name
3289
-            ),
3290
-            'message_type_settings[message_type]' => array(
3291
-                'type'  => 'hidden',
3292
-                'value' => $message_type->name
3293
-            ),
3294
-            'type'                                => array(
3295
-                'type'  => 'hidden',
3296
-                'value' => 'message_type'
3297
-            )
3298
-        );
3299
-        
3300
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3301
-            $settings_template_args['hidden_fields'],
3302
-            'array'
3303
-        );
3304
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3305
-            ? ' hidden'
3306
-            : '';
3307
-        
3308
-        
3309
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3310
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
3311
-        
3312
-        return $content;
3313
-    }
3274
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3275
+				? $this->_generate_admin_form_fields(
3276
+					$template_form_field,
3277
+					'string',
3278
+					'ee_mt_activate_form'
3279
+				)
3280
+				: '';
3281
+		}
3282
+        
3283
+		$settings_template_args['description'] = $message_type->description;
3284
+		//we also need some hidden fields
3285
+		$settings_template_args['hidden_fields'] = array(
3286
+			'message_type_settings[messenger]'    => array(
3287
+				'type'  => 'hidden',
3288
+				'value' => $messenger->name
3289
+			),
3290
+			'message_type_settings[message_type]' => array(
3291
+				'type'  => 'hidden',
3292
+				'value' => $message_type->name
3293
+			),
3294
+			'type'                                => array(
3295
+				'type'  => 'hidden',
3296
+				'value' => 'message_type'
3297
+			)
3298
+		);
3299
+        
3300
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3301
+			$settings_template_args['hidden_fields'],
3302
+			'array'
3303
+		);
3304
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3305
+			? ' hidden'
3306
+			: '';
3307
+        
3308
+        
3309
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3310
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
3311
+        
3312
+		return $content;
3313
+	}
3314 3314
 
3315 3315
 
3316
-    /**
3317
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3318
-     *
3319
-     * @access protected
3320
-     * @return void
3321
-     * @throws DomainException
3322
-     */
3323
-    protected function _messages_settings_metaboxes()
3324
-    {
3325
-        $this->_set_m_mt_settings();
3326
-        $m_boxes         = $mt_boxes = array();
3327
-        $m_template_args = $mt_template_args = array();
3328
-        
3329
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3330
-            ? $this->_req_data['selected_messenger']
3331
-            : 'email';
3332
-        
3333
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3334
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3335
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3336
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3337
-                //messenger meta boxes
3338
-                $active                                 = $selected_messenger === $messenger;
3339
-                $active_mt_tabs                         = isset(
3340
-                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3341
-                )
3342
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3343
-                    : '';
3344
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3345
-                    esc_html__('%s Settings', 'event_espresso'),
3346
-                    $tab_array['label']
3347
-                );
3348
-                $m_template_args[$messenger . '_a_box'] = array(
3349
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3350
-                    'inactive_message_types' => isset(
3351
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3352
-                    )
3353
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3354
-                        : '',
3355
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3356
-                    'hidden'                 => $active ? '' : ' hidden',
3357
-                    'hide_on_message'        => $hide_on_message,
3358
-                    'messenger'              => $messenger,
3359
-                    'active'                 => $active
3360
-                );
3361
-                // message type meta boxes
3362
-                // (which is really just the inactive container for each messenger
3363
-                // showing inactive message types for that messenger)
3364
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3365
-                $mt_template_args[$messenger . '_i_box'] = array(
3366
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3367
-                    'inactive_message_types' => isset(
3368
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3369
-                    )
3370
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3371
-                        : '',
3372
-                    'hidden'                 => $active ? '' : ' hidden',
3373
-                    'hide_on_message'        => $hide_on_message,
3374
-                    'hide_off_message'       => $hide_off_message,
3375
-                    'messenger'              => $messenger,
3376
-                    'active'                 => $active
3377
-                );
3378
-            }
3379
-        }
3380
-        
3381
-        
3382
-        //register messenger metaboxes
3383
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3384
-        foreach ($m_boxes as $box => $label) {
3385
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3386
-            $msgr          = str_replace('_a_box', '', $box);
3387
-            add_meta_box(
3388
-                'espresso_' . $msgr . '_settings',
3389
-                $label,
3390
-                function ($post, $metabox) {
3391
-                    echo EEH_Template::display_template(
3392
-                            $metabox["args"]["template_path"],
3393
-                            $metabox["args"]["template_args"],
3394
-                            true
3395
-                    );
3396
-                },
3397
-                $this->_current_screen->id,
3398
-                'normal',
3399
-                'high',
3400
-                $callback_args
3401
-            );
3402
-        }
3403
-        
3404
-        //register message type metaboxes
3405
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3406
-        foreach ($mt_boxes as $box => $label) {
3407
-            $callback_args = array(
3408
-                'template_path' => $mt_template_path,
3409
-                'template_args' => $mt_template_args[$box]
3410
-            );
3411
-            $mt            = str_replace('_i_box', '', $box);
3412
-            add_meta_box(
3413
-                'espresso_' . $mt . '_inactive_mts',
3414
-                $label,
3415
-                function ($post, $metabox) {
3416
-                    echo EEH_Template::display_template(
3417
-                            $metabox["args"]["template_path"],
3418
-                            $metabox["args"]["template_args"],
3419
-                            true
3420
-                    );
3421
-                },
3422
-                $this->_current_screen->id,
3423
-                'side',
3424
-                'high',
3425
-                $callback_args
3426
-            );
3427
-        }
3428
-        
3429
-        //register metabox for global messages settings but only when on the main site.  On single site installs this
3430
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3431
-        if (is_main_site()) {
3432
-            add_meta_box(
3433
-                'espresso_global_message_settings',
3434
-                esc_html__('Global Message Settings', 'event_espresso'),
3435
-                array($this, 'global_messages_settings_metabox_content'),
3436
-                $this->_current_screen->id,
3437
-                'normal',
3438
-                'low',
3439
-                array()
3440
-            );
3441
-        }
3442
-        
3443
-    }
3316
+	/**
3317
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3318
+	 *
3319
+	 * @access protected
3320
+	 * @return void
3321
+	 * @throws DomainException
3322
+	 */
3323
+	protected function _messages_settings_metaboxes()
3324
+	{
3325
+		$this->_set_m_mt_settings();
3326
+		$m_boxes         = $mt_boxes = array();
3327
+		$m_template_args = $mt_template_args = array();
3328
+        
3329
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3330
+			? $this->_req_data['selected_messenger']
3331
+			: 'email';
3332
+        
3333
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3334
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3335
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3336
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3337
+				//messenger meta boxes
3338
+				$active                                 = $selected_messenger === $messenger;
3339
+				$active_mt_tabs                         = isset(
3340
+					$this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3341
+				)
3342
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3343
+					: '';
3344
+				$m_boxes[$messenger . '_a_box']         = sprintf(
3345
+					esc_html__('%s Settings', 'event_espresso'),
3346
+					$tab_array['label']
3347
+				);
3348
+				$m_template_args[$messenger . '_a_box'] = array(
3349
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3350
+					'inactive_message_types' => isset(
3351
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3352
+					)
3353
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3354
+						: '',
3355
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3356
+					'hidden'                 => $active ? '' : ' hidden',
3357
+					'hide_on_message'        => $hide_on_message,
3358
+					'messenger'              => $messenger,
3359
+					'active'                 => $active
3360
+				);
3361
+				// message type meta boxes
3362
+				// (which is really just the inactive container for each messenger
3363
+				// showing inactive message types for that messenger)
3364
+				$mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3365
+				$mt_template_args[$messenger . '_i_box'] = array(
3366
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3367
+					'inactive_message_types' => isset(
3368
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3369
+					)
3370
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3371
+						: '',
3372
+					'hidden'                 => $active ? '' : ' hidden',
3373
+					'hide_on_message'        => $hide_on_message,
3374
+					'hide_off_message'       => $hide_off_message,
3375
+					'messenger'              => $messenger,
3376
+					'active'                 => $active
3377
+				);
3378
+			}
3379
+		}
3380
+        
3381
+        
3382
+		//register messenger metaboxes
3383
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3384
+		foreach ($m_boxes as $box => $label) {
3385
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3386
+			$msgr          = str_replace('_a_box', '', $box);
3387
+			add_meta_box(
3388
+				'espresso_' . $msgr . '_settings',
3389
+				$label,
3390
+				function ($post, $metabox) {
3391
+					echo EEH_Template::display_template(
3392
+							$metabox["args"]["template_path"],
3393
+							$metabox["args"]["template_args"],
3394
+							true
3395
+					);
3396
+				},
3397
+				$this->_current_screen->id,
3398
+				'normal',
3399
+				'high',
3400
+				$callback_args
3401
+			);
3402
+		}
3403
+        
3404
+		//register message type metaboxes
3405
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3406
+		foreach ($mt_boxes as $box => $label) {
3407
+			$callback_args = array(
3408
+				'template_path' => $mt_template_path,
3409
+				'template_args' => $mt_template_args[$box]
3410
+			);
3411
+			$mt            = str_replace('_i_box', '', $box);
3412
+			add_meta_box(
3413
+				'espresso_' . $mt . '_inactive_mts',
3414
+				$label,
3415
+				function ($post, $metabox) {
3416
+					echo EEH_Template::display_template(
3417
+							$metabox["args"]["template_path"],
3418
+							$metabox["args"]["template_args"],
3419
+							true
3420
+					);
3421
+				},
3422
+				$this->_current_screen->id,
3423
+				'side',
3424
+				'high',
3425
+				$callback_args
3426
+			);
3427
+		}
3428
+        
3429
+		//register metabox for global messages settings but only when on the main site.  On single site installs this
3430
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3431
+		if (is_main_site()) {
3432
+			add_meta_box(
3433
+				'espresso_global_message_settings',
3434
+				esc_html__('Global Message Settings', 'event_espresso'),
3435
+				array($this, 'global_messages_settings_metabox_content'),
3436
+				$this->_current_screen->id,
3437
+				'normal',
3438
+				'low',
3439
+				array()
3440
+			);
3441
+		}
3442
+        
3443
+	}
3444 3444
 
3445 3445
 
3446
-    /**
3447
-     *  This generates the content for the global messages settings metabox.
3448
-     *
3449
-     * @return string
3450
-     * @throws EE_Error
3451
-     * @throws InvalidArgumentException
3452
-     * @throws ReflectionException
3453
-     * @throws InvalidDataTypeException
3454
-     * @throws InvalidInterfaceException
3455
-     */
3456
-    public function global_messages_settings_metabox_content()
3457
-    {
3458
-        $form = $this->_generate_global_settings_form();
3459
-        echo $form->form_open(
3460
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3461
-                'POST'
3462
-            )
3463
-             . $form->get_html()
3464
-             . $form->form_close();
3465
-    }
3446
+	/**
3447
+	 *  This generates the content for the global messages settings metabox.
3448
+	 *
3449
+	 * @return string
3450
+	 * @throws EE_Error
3451
+	 * @throws InvalidArgumentException
3452
+	 * @throws ReflectionException
3453
+	 * @throws InvalidDataTypeException
3454
+	 * @throws InvalidInterfaceException
3455
+	 */
3456
+	public function global_messages_settings_metabox_content()
3457
+	{
3458
+		$form = $this->_generate_global_settings_form();
3459
+		echo $form->form_open(
3460
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3461
+				'POST'
3462
+			)
3463
+			 . $form->get_html()
3464
+			 . $form->form_close();
3465
+	}
3466 3466
 
3467 3467
 
3468
-    /**
3469
-     * This generates and returns the form object for the global messages settings.
3470
-     *
3471
-     * @return EE_Form_Section_Proper
3472
-     * @throws EE_Error
3473
-     * @throws InvalidArgumentException
3474
-     * @throws ReflectionException
3475
-     * @throws InvalidDataTypeException
3476
-     * @throws InvalidInterfaceException
3477
-     */
3478
-    protected function _generate_global_settings_form()
3479
-    {
3480
-        EE_Registry::instance()->load_helper('HTML');
3481
-        /** @var EE_Network_Core_Config $network_config */
3482
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3483
-        
3484
-        return new EE_Form_Section_Proper(
3485
-            array(
3486
-                'name'            => 'global_messages_settings',
3487
-                'html_id'         => 'global_messages_settings',
3488
-                'html_class'      => 'form-table',
3489
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3490
-                'subsections'     => apply_filters(
3491
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3492
-                    array(
3493
-                        'do_messages_on_same_request' => new EE_Select_Input(
3494
-                            array(
3495
-                                true  => esc_html__("On the same request", "event_espresso"),
3496
-                                false => esc_html__("On a separate request", "event_espresso")
3497
-                            ),
3498
-                            array(
3499
-                                'default'         => $network_config->do_messages_on_same_request,
3500
-                                'html_label_text' => esc_html__(
3501
-                                    'Generate and send all messages:',
3502
-                                    'event_espresso'
3503
-                                ),
3504
-                                'html_help_text'  => esc_html__(
3505
-                                    '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.',
3506
-                                    'event_espresso'
3507
-                                ),
3508
-                            )
3509
-                        ),
3510
-                        'delete_threshold' => new EE_Select_Input(
3511
-                            array(
3512
-                                0 => esc_html__('Forever', 'event_espresso'),
3513
-                                3 => esc_html__('3 Months', 'event_espresso'),
3514
-                                6 => esc_html__('6 Months', 'event_espresso'),
3515
-                                9 => esc_html__('9 Months', 'event_espresso'),
3516
-                                12 => esc_html__('12 Months', 'event_espresso'),
3517
-                                24 => esc_html__('24 Months', 'event_espresso'),
3518
-                                36 => esc_html__('36 Months', 'event_espresso')
3519
-                            ),
3520
-                            array(
3521
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3522
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3523
-                                'html_help_text' => esc_html__(
3524
-                                    'You can control how long a record of processed messages is kept via this option.',
3525
-                                    'event_espresso'
3526
-                                ),
3527
-                            )
3528
-                        ),
3529
-                        'update_settings'             => new EE_Submit_Input(
3530
-                            array(
3531
-                                'default'         => esc_html__('Update', 'event_espresso'),
3532
-                                'html_label_text' => '&nbsp'
3533
-                            )
3534
-                        )
3535
-                    )
3536
-                )
3537
-            )
3538
-        );
3539
-    }
3468
+	/**
3469
+	 * This generates and returns the form object for the global messages settings.
3470
+	 *
3471
+	 * @return EE_Form_Section_Proper
3472
+	 * @throws EE_Error
3473
+	 * @throws InvalidArgumentException
3474
+	 * @throws ReflectionException
3475
+	 * @throws InvalidDataTypeException
3476
+	 * @throws InvalidInterfaceException
3477
+	 */
3478
+	protected function _generate_global_settings_form()
3479
+	{
3480
+		EE_Registry::instance()->load_helper('HTML');
3481
+		/** @var EE_Network_Core_Config $network_config */
3482
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3483
+        
3484
+		return new EE_Form_Section_Proper(
3485
+			array(
3486
+				'name'            => 'global_messages_settings',
3487
+				'html_id'         => 'global_messages_settings',
3488
+				'html_class'      => 'form-table',
3489
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3490
+				'subsections'     => apply_filters(
3491
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3492
+					array(
3493
+						'do_messages_on_same_request' => new EE_Select_Input(
3494
+							array(
3495
+								true  => esc_html__("On the same request", "event_espresso"),
3496
+								false => esc_html__("On a separate request", "event_espresso")
3497
+							),
3498
+							array(
3499
+								'default'         => $network_config->do_messages_on_same_request,
3500
+								'html_label_text' => esc_html__(
3501
+									'Generate and send all messages:',
3502
+									'event_espresso'
3503
+								),
3504
+								'html_help_text'  => esc_html__(
3505
+									'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.',
3506
+									'event_espresso'
3507
+								),
3508
+							)
3509
+						),
3510
+						'delete_threshold' => new EE_Select_Input(
3511
+							array(
3512
+								0 => esc_html__('Forever', 'event_espresso'),
3513
+								3 => esc_html__('3 Months', 'event_espresso'),
3514
+								6 => esc_html__('6 Months', 'event_espresso'),
3515
+								9 => esc_html__('9 Months', 'event_espresso'),
3516
+								12 => esc_html__('12 Months', 'event_espresso'),
3517
+								24 => esc_html__('24 Months', 'event_espresso'),
3518
+								36 => esc_html__('36 Months', 'event_espresso')
3519
+							),
3520
+							array(
3521
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3522
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3523
+								'html_help_text' => esc_html__(
3524
+									'You can control how long a record of processed messages is kept via this option.',
3525
+									'event_espresso'
3526
+								),
3527
+							)
3528
+						),
3529
+						'update_settings'             => new EE_Submit_Input(
3530
+							array(
3531
+								'default'         => esc_html__('Update', 'event_espresso'),
3532
+								'html_label_text' => '&nbsp'
3533
+							)
3534
+						)
3535
+					)
3536
+				)
3537
+			)
3538
+		);
3539
+	}
3540 3540
 
3541 3541
 
3542
-    /**
3543
-     * This handles updating the global settings set on the admin page.
3544
-     *
3545
-     * @throws EE_Error
3546
-     * @throws InvalidDataTypeException
3547
-     * @throws InvalidInterfaceException
3548
-     * @throws InvalidArgumentException
3549
-     * @throws ReflectionException
3550
-     */
3551
-    protected function _update_global_settings()
3552
-    {
3553
-        /** @var EE_Network_Core_Config $network_config */
3554
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3555
-        $messages_config = EE_Registry::instance()->CFG->messages;
3556
-        $form           = $this->_generate_global_settings_form();
3557
-        if ($form->was_submitted()) {
3558
-            $form->receive_form_submission();
3559
-            if ($form->is_valid()) {
3560
-                $valid_data = $form->valid_data();
3561
-                foreach ($valid_data as $property => $value) {
3562
-                    $setter = 'set_' . $property;
3563
-                    if (method_exists($network_config, $setter)) {
3564
-                        $network_config->{$setter}($value);
3565
-                    } else if (
3566
-                        property_exists($network_config, $property)
3567
-                        && $network_config->{$property} !== $value
3568
-                    ) {
3569
-                        $network_config->{$property} = $value;
3570
-                    } else if (
3571
-                        property_exists($messages_config, $property)
3572
-                        && $messages_config->{$property} !== $value
3573
-                    ) {
3574
-                        $messages_config->{$property} = $value;
3575
-                    }
3576
-                }
3577
-                //only update if the form submission was valid!
3578
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3579
-                EE_Registry::instance()->CFG->update_espresso_config();
3580
-                EE_Error::overwrite_success();
3581
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3582
-            }
3583
-        }
3584
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3585
-    }
3542
+	/**
3543
+	 * This handles updating the global settings set on the admin page.
3544
+	 *
3545
+	 * @throws EE_Error
3546
+	 * @throws InvalidDataTypeException
3547
+	 * @throws InvalidInterfaceException
3548
+	 * @throws InvalidArgumentException
3549
+	 * @throws ReflectionException
3550
+	 */
3551
+	protected function _update_global_settings()
3552
+	{
3553
+		/** @var EE_Network_Core_Config $network_config */
3554
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3555
+		$messages_config = EE_Registry::instance()->CFG->messages;
3556
+		$form           = $this->_generate_global_settings_form();
3557
+		if ($form->was_submitted()) {
3558
+			$form->receive_form_submission();
3559
+			if ($form->is_valid()) {
3560
+				$valid_data = $form->valid_data();
3561
+				foreach ($valid_data as $property => $value) {
3562
+					$setter = 'set_' . $property;
3563
+					if (method_exists($network_config, $setter)) {
3564
+						$network_config->{$setter}($value);
3565
+					} else if (
3566
+						property_exists($network_config, $property)
3567
+						&& $network_config->{$property} !== $value
3568
+					) {
3569
+						$network_config->{$property} = $value;
3570
+					} else if (
3571
+						property_exists($messages_config, $property)
3572
+						&& $messages_config->{$property} !== $value
3573
+					) {
3574
+						$messages_config->{$property} = $value;
3575
+					}
3576
+				}
3577
+				//only update if the form submission was valid!
3578
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3579
+				EE_Registry::instance()->CFG->update_espresso_config();
3580
+				EE_Error::overwrite_success();
3581
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3582
+			}
3583
+		}
3584
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3585
+	}
3586 3586
 
3587 3587
 
3588
-    /**
3589
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3590
-     *
3591
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3592
-     * @return string html formatted tabs
3593
-     * @throws DomainException
3594
-     */
3595
-    protected function _get_mt_tabs($tab_array)
3596
-    {
3597
-        $tab_array = (array)$tab_array;
3598
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3599
-        $tabs      = '';
3600
-        
3601
-        foreach ($tab_array as $tab) {
3602
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3603
-        }
3604
-        
3605
-        return $tabs;
3606
-    }
3588
+	/**
3589
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3590
+	 *
3591
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3592
+	 * @return string html formatted tabs
3593
+	 * @throws DomainException
3594
+	 */
3595
+	protected function _get_mt_tabs($tab_array)
3596
+	{
3597
+		$tab_array = (array)$tab_array;
3598
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3599
+		$tabs      = '';
3600
+        
3601
+		foreach ($tab_array as $tab) {
3602
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3603
+		}
3604
+        
3605
+		return $tabs;
3606
+	}
3607 3607
 
3608 3608
 
3609
-    /**
3610
-     * This prepares the content of the messenger meta box admin settings
3611
-     *
3612
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3613
-     * @return string html formatted content
3614
-     * @throws DomainException
3615
-     */
3616
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3617
-    {
3609
+	/**
3610
+	 * This prepares the content of the messenger meta box admin settings
3611
+	 *
3612
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3613
+	 * @return string html formatted content
3614
+	 * @throws DomainException
3615
+	 */
3616
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3617
+	{
3618 3618
         
3619
-        $fields                                         = $messenger->get_admin_settings_fields();
3620
-        $settings_template_args['template_form_fields'] = '';
3619
+		$fields                                         = $messenger->get_admin_settings_fields();
3620
+		$settings_template_args['template_form_fields'] = '';
3621 3621
         
3622
-        //is $messenger active?
3623
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3622
+		//is $messenger active?
3623
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3624 3624
         
3625 3625
         
3626
-        if ( ! empty($fields)) {
3626
+		if ( ! empty($fields)) {
3627 3627
             
3628
-            $existing_settings = $messenger->get_existing_admin_settings();
3628
+			$existing_settings = $messenger->get_existing_admin_settings();
3629 3629
             
3630
-            foreach ($fields as $fldname => $fldprops) {
3631
-                $field_id                       = $messenger->name . '-' . $fldname;
3632
-                $template_form_field[$field_id] = array(
3633
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3634
-                    'label'      => $fldprops['label'],
3635
-                    'input'      => $fldprops['field_type'],
3636
-                    'type'       => $fldprops['value_type'],
3637
-                    'required'   => $fldprops['required'],
3638
-                    'validation' => $fldprops['validation'],
3639
-                    'value'      => isset($existing_settings[$field_id])
3640
-                        ? $existing_settings[$field_id]
3641
-                        : $fldprops['default'],
3642
-                    'css_class'  => '',
3643
-                    'format'     => $fldprops['format']
3644
-                );
3645
-            }
3630
+			foreach ($fields as $fldname => $fldprops) {
3631
+				$field_id                       = $messenger->name . '-' . $fldname;
3632
+				$template_form_field[$field_id] = array(
3633
+					'name'       => 'messenger_settings[' . $field_id . ']',
3634
+					'label'      => $fldprops['label'],
3635
+					'input'      => $fldprops['field_type'],
3636
+					'type'       => $fldprops['value_type'],
3637
+					'required'   => $fldprops['required'],
3638
+					'validation' => $fldprops['validation'],
3639
+					'value'      => isset($existing_settings[$field_id])
3640
+						? $existing_settings[$field_id]
3641
+						: $fldprops['default'],
3642
+					'css_class'  => '',
3643
+					'format'     => $fldprops['format']
3644
+				);
3645
+			}
3646 3646
             
3647 3647
             
3648
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3649
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3650
-                : '';
3651
-        }
3652
-        
3653
-        //we also need some hidden fields
3654
-        $settings_template_args['hidden_fields'] = array(
3655
-            'messenger_settings[messenger]' => array(
3656
-                'type'  => 'hidden',
3657
-                'value' => $messenger->name
3658
-            ),
3659
-            'type'                          => array(
3660
-                'type'  => 'hidden',
3661
-                'value' => 'messenger'
3662
-            )
3663
-        );
3664
-        
3665
-        //make sure any active message types that are existing are included in the hidden fields
3666
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3667
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3668
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3669
-                    'type'  => 'hidden',
3670
-                    'value' => $mt
3671
-                );
3672
-            }
3673
-        }
3674
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3675
-            $settings_template_args['hidden_fields'],
3676
-            'array'
3677
-        );
3678
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3679
-        
3680
-        $settings_template_args['messenger']           = $messenger->name;
3681
-        $settings_template_args['description']         = $messenger->description;
3682
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3683
-        
3684
-        
3685
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3686
-            $messenger->name
3687
-        )
3688
-            ? $settings_template_args['show_hide_edit_form']
3689
-            : ' hidden';
3690
-        
3691
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3692
-            ? ' hidden'
3693
-            : $settings_template_args['show_hide_edit_form'];
3694
-        
3695
-        
3696
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3697
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3698
-        $settings_template_args['on_off_status'] = $active ? true : false;
3699
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3700
-        $content                                 = EEH_Template::display_template(
3701
-            $template,
3702
-            $settings_template_args,
3703
-            true
3704
-        );
3705
-        
3706
-        return $content;
3707
-    }
3648
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3649
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3650
+				: '';
3651
+		}
3652
+        
3653
+		//we also need some hidden fields
3654
+		$settings_template_args['hidden_fields'] = array(
3655
+			'messenger_settings[messenger]' => array(
3656
+				'type'  => 'hidden',
3657
+				'value' => $messenger->name
3658
+			),
3659
+			'type'                          => array(
3660
+				'type'  => 'hidden',
3661
+				'value' => 'messenger'
3662
+			)
3663
+		);
3664
+        
3665
+		//make sure any active message types that are existing are included in the hidden fields
3666
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3667
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3668
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3669
+					'type'  => 'hidden',
3670
+					'value' => $mt
3671
+				);
3672
+			}
3673
+		}
3674
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3675
+			$settings_template_args['hidden_fields'],
3676
+			'array'
3677
+		);
3678
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3679
+        
3680
+		$settings_template_args['messenger']           = $messenger->name;
3681
+		$settings_template_args['description']         = $messenger->description;
3682
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3683
+        
3684
+        
3685
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3686
+			$messenger->name
3687
+		)
3688
+			? $settings_template_args['show_hide_edit_form']
3689
+			: ' hidden';
3690
+        
3691
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3692
+			? ' hidden'
3693
+			: $settings_template_args['show_hide_edit_form'];
3694
+        
3695
+        
3696
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3697
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3698
+		$settings_template_args['on_off_status'] = $active ? true : false;
3699
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3700
+		$content                                 = EEH_Template::display_template(
3701
+			$template,
3702
+			$settings_template_args,
3703
+			true
3704
+		);
3705
+        
3706
+		return $content;
3707
+	}
3708 3708
 
3709 3709
 
3710
-    /**
3711
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3712
-     *
3713
-     * @throws DomainException
3714
-     * @throws EE_Error
3715
-     * @throws InvalidDataTypeException
3716
-     * @throws InvalidInterfaceException
3717
-     * @throws InvalidArgumentException
3718
-     * @throws ReflectionException
3719
-     */
3720
-    public function activate_messenger_toggle()
3721
-    {
3722
-        $success = true;
3723
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3724
-        //let's check that we have required data
3725
-        if ( ! isset($this->_req_data['messenger'])) {
3726
-            EE_Error::add_error(
3727
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3728
-                __FILE__,
3729
-                __FUNCTION__,
3730
-                __LINE__
3731
-            );
3732
-            $success = false;
3733
-        }
3734
-        
3735
-        //do a nonce check here since we're not arriving via a normal route
3736
-        $nonce     = isset($this->_req_data['activate_nonce'])
3737
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3738
-            : '';
3739
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3740
-        
3741
-        $this->_verify_nonce($nonce, $nonce_ref);
3742
-        
3743
-        
3744
-        if ( ! isset($this->_req_data['status'])) {
3745
-            EE_Error::add_error(
3746
-                esc_html__(
3747
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3748
-                    'event_espresso'
3749
-                ),
3750
-                __FILE__,
3751
-                __FUNCTION__,
3752
-                __LINE__
3753
-            );
3754
-            $success = false;
3755
-        }
3756
-        
3757
-        //do check to verify we have a valid status.
3758
-        $status = $this->_req_data['status'];
3759
-        
3760
-        if ($status !== 'off' && $status !== 'on') {
3761
-            EE_Error::add_error(
3762
-                sprintf(
3763
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3764
-                    $this->_req_data['status']
3765
-                ),
3766
-                __FILE__,
3767
-                __FUNCTION__,
3768
-                __LINE__
3769
-            );
3770
-            $success = false;
3771
-        }
3772
-        
3773
-        if ($success) {
3774
-            //made it here?  Stop dawdling then!!
3775
-            $success = $status === 'off'
3776
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3777
-                : $this->_activate_messenger($this->_req_data['messenger']);
3778
-        }
3779
-        
3780
-        $this->_template_args['success'] = $success;
3781
-        
3782
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3783
-        $this->_return_json();
3784
-        
3785
-    }
3710
+	/**
3711
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3712
+	 *
3713
+	 * @throws DomainException
3714
+	 * @throws EE_Error
3715
+	 * @throws InvalidDataTypeException
3716
+	 * @throws InvalidInterfaceException
3717
+	 * @throws InvalidArgumentException
3718
+	 * @throws ReflectionException
3719
+	 */
3720
+	public function activate_messenger_toggle()
3721
+	{
3722
+		$success = true;
3723
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3724
+		//let's check that we have required data
3725
+		if ( ! isset($this->_req_data['messenger'])) {
3726
+			EE_Error::add_error(
3727
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3728
+				__FILE__,
3729
+				__FUNCTION__,
3730
+				__LINE__
3731
+			);
3732
+			$success = false;
3733
+		}
3734
+        
3735
+		//do a nonce check here since we're not arriving via a normal route
3736
+		$nonce     = isset($this->_req_data['activate_nonce'])
3737
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3738
+			: '';
3739
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3740
+        
3741
+		$this->_verify_nonce($nonce, $nonce_ref);
3742
+        
3743
+        
3744
+		if ( ! isset($this->_req_data['status'])) {
3745
+			EE_Error::add_error(
3746
+				esc_html__(
3747
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3748
+					'event_espresso'
3749
+				),
3750
+				__FILE__,
3751
+				__FUNCTION__,
3752
+				__LINE__
3753
+			);
3754
+			$success = false;
3755
+		}
3756
+        
3757
+		//do check to verify we have a valid status.
3758
+		$status = $this->_req_data['status'];
3759
+        
3760
+		if ($status !== 'off' && $status !== 'on') {
3761
+			EE_Error::add_error(
3762
+				sprintf(
3763
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3764
+					$this->_req_data['status']
3765
+				),
3766
+				__FILE__,
3767
+				__FUNCTION__,
3768
+				__LINE__
3769
+			);
3770
+			$success = false;
3771
+		}
3772
+        
3773
+		if ($success) {
3774
+			//made it here?  Stop dawdling then!!
3775
+			$success = $status === 'off'
3776
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3777
+				: $this->_activate_messenger($this->_req_data['messenger']);
3778
+		}
3779
+        
3780
+		$this->_template_args['success'] = $success;
3781
+        
3782
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3783
+		$this->_return_json();
3784
+        
3785
+	}
3786 3786
 
3787 3787
 
3788
-    /**
3789
-     * used by ajax from the messages settings page to activate|deactivate a message type
3790
-     *
3791
-     * @throws DomainException
3792
-     * @throws EE_Error
3793
-     * @throws ReflectionException
3794
-     * @throws InvalidDataTypeException
3795
-     * @throws InvalidInterfaceException
3796
-     * @throws InvalidArgumentException
3797
-     */
3798
-    public function activate_mt_toggle()
3799
-    {
3800
-        $success = true;
3801
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3802
-        
3803
-        //let's make sure we have the necessary data
3804
-        if ( ! isset($this->_req_data['message_type'])) {
3805
-            EE_Error::add_error(
3806
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3807
-                __FILE__,
3808
-                __FUNCTION__,
3809
-                __LINE__
3810
-            );
3811
-            $success = false;
3812
-        }
3813
-        
3814
-        if ( ! isset($this->_req_data['messenger'])) {
3815
-            EE_Error::add_error(
3816
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3817
-                __FILE__,
3818
-                __FUNCTION__,
3819
-                __LINE__
3820
-            );
3821
-            $success = false;
3822
-        }
3823
-        
3824
-        if ( ! isset($this->_req_data['status'])) {
3825
-            EE_Error::add_error(
3826
-                esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3827
-                    'event_espresso'),
3828
-                __FILE__,
3829
-                __FUNCTION__,
3830
-                __LINE__
3831
-            );
3832
-            $success = false;
3833
-        }
3834
-        
3835
-        
3836
-        //do check to verify we have a valid status.
3837
-        $status = $this->_req_data['status'];
3838
-        
3839
-        if ($status !== 'activate' && $status !== 'deactivate') {
3840
-            EE_Error::add_error(
3841
-                sprintf(
3842
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3843
-                    $this->_req_data['status']
3844
-                ),
3845
-                __FILE__,
3846
-                __FUNCTION__,
3847
-                __LINE__
3848
-            );
3849
-            $success = false;
3850
-        }
3851
-        
3852
-        
3853
-        //do a nonce check here since we're not arriving via a normal route
3854
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3855
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3856
-        
3857
-        $this->_verify_nonce($nonce, $nonce_ref);
3858
-        
3859
-        if ($success) {
3860
-            //made it here? um, what are you waiting for then?
3861
-            $success = $status === 'deactivate'
3862
-                ? $this->_deactivate_message_type_for_messenger(
3863
-                    $this->_req_data['messenger'],
3864
-                    $this->_req_data['message_type']
3865
-                )
3866
-                : $this->_activate_message_type_for_messenger(
3867
-                    $this->_req_data['messenger'],
3868
-                    $this->_req_data['message_type']
3869
-                );
3870
-        }
3871
-        
3872
-        $this->_template_args['success'] = $success;
3873
-        $this->_return_json();
3874
-    }
3788
+	/**
3789
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3790
+	 *
3791
+	 * @throws DomainException
3792
+	 * @throws EE_Error
3793
+	 * @throws ReflectionException
3794
+	 * @throws InvalidDataTypeException
3795
+	 * @throws InvalidInterfaceException
3796
+	 * @throws InvalidArgumentException
3797
+	 */
3798
+	public function activate_mt_toggle()
3799
+	{
3800
+		$success = true;
3801
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3802
+        
3803
+		//let's make sure we have the necessary data
3804
+		if ( ! isset($this->_req_data['message_type'])) {
3805
+			EE_Error::add_error(
3806
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3807
+				__FILE__,
3808
+				__FUNCTION__,
3809
+				__LINE__
3810
+			);
3811
+			$success = false;
3812
+		}
3813
+        
3814
+		if ( ! isset($this->_req_data['messenger'])) {
3815
+			EE_Error::add_error(
3816
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3817
+				__FILE__,
3818
+				__FUNCTION__,
3819
+				__LINE__
3820
+			);
3821
+			$success = false;
3822
+		}
3823
+        
3824
+		if ( ! isset($this->_req_data['status'])) {
3825
+			EE_Error::add_error(
3826
+				esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3827
+					'event_espresso'),
3828
+				__FILE__,
3829
+				__FUNCTION__,
3830
+				__LINE__
3831
+			);
3832
+			$success = false;
3833
+		}
3834
+        
3835
+        
3836
+		//do check to verify we have a valid status.
3837
+		$status = $this->_req_data['status'];
3838
+        
3839
+		if ($status !== 'activate' && $status !== 'deactivate') {
3840
+			EE_Error::add_error(
3841
+				sprintf(
3842
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3843
+					$this->_req_data['status']
3844
+				),
3845
+				__FILE__,
3846
+				__FUNCTION__,
3847
+				__LINE__
3848
+			);
3849
+			$success = false;
3850
+		}
3851
+        
3852
+        
3853
+		//do a nonce check here since we're not arriving via a normal route
3854
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3855
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3856
+        
3857
+		$this->_verify_nonce($nonce, $nonce_ref);
3858
+        
3859
+		if ($success) {
3860
+			//made it here? um, what are you waiting for then?
3861
+			$success = $status === 'deactivate'
3862
+				? $this->_deactivate_message_type_for_messenger(
3863
+					$this->_req_data['messenger'],
3864
+					$this->_req_data['message_type']
3865
+				)
3866
+				: $this->_activate_message_type_for_messenger(
3867
+					$this->_req_data['messenger'],
3868
+					$this->_req_data['message_type']
3869
+				);
3870
+		}
3871
+        
3872
+		$this->_template_args['success'] = $success;
3873
+		$this->_return_json();
3874
+	}
3875 3875
 
3876 3876
 
3877
-    /**
3878
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3879
-     *
3880
-     * @param string $messenger_name The name of the messenger being activated
3881
-     * @return bool
3882
-     * @throws DomainException
3883
-     * @throws EE_Error
3884
-     * @throws InvalidArgumentException
3885
-     * @throws ReflectionException
3886
-     * @throws InvalidDataTypeException
3887
-     * @throws InvalidInterfaceException
3888
-     */
3889
-    protected function _activate_messenger($messenger_name)
3890
-    {
3891
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3892
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3893
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3894
-            ? $active_messenger->get_default_message_types()
3895
-            : array();
3896
-        
3897
-        //ensure is active
3898
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3899
-        
3900
-        //set response_data for reload
3901
-        foreach ($message_types_to_activate as $message_type_name) {
3902
-            /** @var EE_message_type $message_type */
3903
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3904
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3905
-                    $messenger_name,
3906
-                    $message_type_name
3907
-                )
3908
-                && $message_type instanceof EE_message_type
3909
-            ) {
3910
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3911
-                if ($message_type->get_admin_settings_fields()) {
3912
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3913
-                }
3914
-            }
3915
-        }
3916
-        
3917
-        //add success message for activating messenger
3918
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3919
-        
3920
-    }
3877
+	/**
3878
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3879
+	 *
3880
+	 * @param string $messenger_name The name of the messenger being activated
3881
+	 * @return bool
3882
+	 * @throws DomainException
3883
+	 * @throws EE_Error
3884
+	 * @throws InvalidArgumentException
3885
+	 * @throws ReflectionException
3886
+	 * @throws InvalidDataTypeException
3887
+	 * @throws InvalidInterfaceException
3888
+	 */
3889
+	protected function _activate_messenger($messenger_name)
3890
+	{
3891
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3892
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3893
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3894
+			? $active_messenger->get_default_message_types()
3895
+			: array();
3896
+        
3897
+		//ensure is active
3898
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3899
+        
3900
+		//set response_data for reload
3901
+		foreach ($message_types_to_activate as $message_type_name) {
3902
+			/** @var EE_message_type $message_type */
3903
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3904
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3905
+					$messenger_name,
3906
+					$message_type_name
3907
+				)
3908
+				&& $message_type instanceof EE_message_type
3909
+			) {
3910
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3911
+				if ($message_type->get_admin_settings_fields()) {
3912
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3913
+				}
3914
+			}
3915
+		}
3916
+        
3917
+		//add success message for activating messenger
3918
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3919
+        
3920
+	}
3921 3921
 
3922 3922
 
3923
-    /**
3924
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3925
-     *
3926
-     * @param string $messenger_name The name of the messenger being activated
3927
-     * @return bool
3928
-     * @throws DomainException
3929
-     * @throws EE_Error
3930
-     * @throws InvalidArgumentException
3931
-     * @throws ReflectionException
3932
-     * @throws InvalidDataTypeException
3933
-     * @throws InvalidInterfaceException
3934
-     */
3935
-    protected function _deactivate_messenger($messenger_name)
3936
-    {
3937
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3938
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3939
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3940
-        
3941
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3942
-    }
3923
+	/**
3924
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3925
+	 *
3926
+	 * @param string $messenger_name The name of the messenger being activated
3927
+	 * @return bool
3928
+	 * @throws DomainException
3929
+	 * @throws EE_Error
3930
+	 * @throws InvalidArgumentException
3931
+	 * @throws ReflectionException
3932
+	 * @throws InvalidDataTypeException
3933
+	 * @throws InvalidInterfaceException
3934
+	 */
3935
+	protected function _deactivate_messenger($messenger_name)
3936
+	{
3937
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3938
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3939
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3940
+        
3941
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3942
+	}
3943 3943
 
3944 3944
 
3945
-    /**
3946
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3947
-     *
3948
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3949
-     * @param string $message_type_name The name of the message type being activated for the messenger
3950
-     * @return bool
3951
-     * @throws DomainException
3952
-     * @throws EE_Error
3953
-     * @throws InvalidArgumentException
3954
-     * @throws ReflectionException
3955
-     * @throws InvalidDataTypeException
3956
-     * @throws InvalidInterfaceException
3957
-     */
3958
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3959
-    {
3960
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3961
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3962
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3963
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3964
-        
3965
-        //ensure is active
3966
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3967
-        
3968
-        //set response for load
3969
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3970
-            $message_type_name)
3971
-        ) {
3972
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3973
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3974
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3975
-            }
3976
-        }
3977
-        
3978
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3979
-            $message_type_to_activate);
3980
-    }
3945
+	/**
3946
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3947
+	 *
3948
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3949
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3950
+	 * @return bool
3951
+	 * @throws DomainException
3952
+	 * @throws EE_Error
3953
+	 * @throws InvalidArgumentException
3954
+	 * @throws ReflectionException
3955
+	 * @throws InvalidDataTypeException
3956
+	 * @throws InvalidInterfaceException
3957
+	 */
3958
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3959
+	{
3960
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3961
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3962
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3963
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3964
+        
3965
+		//ensure is active
3966
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3967
+        
3968
+		//set response for load
3969
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3970
+			$message_type_name)
3971
+		) {
3972
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3973
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3974
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3975
+			}
3976
+		}
3977
+        
3978
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3979
+			$message_type_to_activate);
3980
+	}
3981 3981
 
3982 3982
 
3983
-    /**
3984
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3985
-     *
3986
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3987
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3988
-     * @return bool
3989
-     * @throws DomainException
3990
-     * @throws EE_Error
3991
-     * @throws InvalidArgumentException
3992
-     * @throws ReflectionException
3993
-     * @throws InvalidDataTypeException
3994
-     * @throws InvalidInterfaceException
3995
-     */
3996
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3997
-    {
3998
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3999
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4000
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4001
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4002
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4003
-        
4004
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
4005
-            $message_type_to_deactivate);
4006
-    }
3983
+	/**
3984
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3985
+	 *
3986
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3987
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3988
+	 * @return bool
3989
+	 * @throws DomainException
3990
+	 * @throws EE_Error
3991
+	 * @throws InvalidArgumentException
3992
+	 * @throws ReflectionException
3993
+	 * @throws InvalidDataTypeException
3994
+	 * @throws InvalidInterfaceException
3995
+	 */
3996
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3997
+	{
3998
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3999
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4000
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4001
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4002
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4003
+        
4004
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
4005
+			$message_type_to_deactivate);
4006
+	}
4007 4007
     
4008 4008
     
4009
-    /**
4010
-     * This just initializes the defaults for activating messenger and message type responses.
4011
-     */
4012
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4013
-    {
4014
-        $this->_template_args['data']['active_mts'] = array();
4015
-        $this->_template_args['data']['mt_reload']  = array();
4016
-    }
4009
+	/**
4010
+	 * This just initializes the defaults for activating messenger and message type responses.
4011
+	 */
4012
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4013
+	{
4014
+		$this->_template_args['data']['active_mts'] = array();
4015
+		$this->_template_args['data']['mt_reload']  = array();
4016
+	}
4017 4017
 
4018 4018
 
4019
-    /**
4020
-     * Setup appropriate response for activating a messenger and/or message types
4021
-     *
4022
-     * @param EE_messenger         $messenger
4023
-     * @param EE_message_type|null $message_type
4024
-     * @return bool
4025
-     * @throws DomainException
4026
-     * @throws EE_Error
4027
-     * @throws InvalidArgumentException
4028
-     * @throws ReflectionException
4029
-     * @throws InvalidDataTypeException
4030
-     * @throws InvalidInterfaceException
4031
-     */
4032
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4033
-        $messenger,
4034
-        EE_Message_Type $message_type = null
4035
-    ) {
4036
-        //if $messenger isn't a valid messenger object then get out.
4037
-        if ( ! $messenger instanceof EE_Messenger) {
4038
-            EE_Error::add_error(
4039
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4040
-                __FILE__,
4041
-                __FUNCTION__,
4042
-                __LINE__
4043
-            );
4019
+	/**
4020
+	 * Setup appropriate response for activating a messenger and/or message types
4021
+	 *
4022
+	 * @param EE_messenger         $messenger
4023
+	 * @param EE_message_type|null $message_type
4024
+	 * @return bool
4025
+	 * @throws DomainException
4026
+	 * @throws EE_Error
4027
+	 * @throws InvalidArgumentException
4028
+	 * @throws ReflectionException
4029
+	 * @throws InvalidDataTypeException
4030
+	 * @throws InvalidInterfaceException
4031
+	 */
4032
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4033
+		$messenger,
4034
+		EE_Message_Type $message_type = null
4035
+	) {
4036
+		//if $messenger isn't a valid messenger object then get out.
4037
+		if ( ! $messenger instanceof EE_Messenger) {
4038
+			EE_Error::add_error(
4039
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4040
+				__FILE__,
4041
+				__FUNCTION__,
4042
+				__LINE__
4043
+			);
4044 4044
             
4045
-            return false;
4046
-        }
4047
-        //activated
4048
-        if ($this->_template_args['data']['active_mts']) {
4049
-            EE_Error::overwrite_success();
4050
-            //activated a message type with the messenger
4051
-            if ($message_type instanceof EE_message_type) {
4052
-                EE_Error::add_success(
4053
-                    sprintf(
4054
-                        esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4055
-                        ucwords($message_type->label['singular']),
4056
-                        ucwords($messenger->label['singular'])
4057
-                    )
4058
-                );
4045
+			return false;
4046
+		}
4047
+		//activated
4048
+		if ($this->_template_args['data']['active_mts']) {
4049
+			EE_Error::overwrite_success();
4050
+			//activated a message type with the messenger
4051
+			if ($message_type instanceof EE_message_type) {
4052
+				EE_Error::add_success(
4053
+					sprintf(
4054
+						esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4055
+						ucwords($message_type->label['singular']),
4056
+						ucwords($messenger->label['singular'])
4057
+					)
4058
+				);
4059 4059
                 
4060
-                //if message type was invoice then let's make sure we activate the invoice payment method.
4061
-                if ($message_type->name === 'invoice') {
4062
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4063
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4064
-                    if ($pm instanceof EE_Payment_Method) {
4065
-                        EE_Error::add_attention(
4066
-                            esc_html__(
4067
-                                '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.',
4068
-                                'event_espresso'
4069
-                            )
4070
-                        );
4071
-                    }
4072
-                }
4073
-                //just toggles the entire messenger
4074
-            } else {
4075
-                EE_Error::add_success(
4076
-                    sprintf(
4077
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4078
-                        ucwords($messenger->label['singular'])
4079
-                    )
4080
-                );
4081
-            }
4060
+				//if message type was invoice then let's make sure we activate the invoice payment method.
4061
+				if ($message_type->name === 'invoice') {
4062
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4063
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4064
+					if ($pm instanceof EE_Payment_Method) {
4065
+						EE_Error::add_attention(
4066
+							esc_html__(
4067
+								'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.',
4068
+								'event_espresso'
4069
+							)
4070
+						);
4071
+					}
4072
+				}
4073
+				//just toggles the entire messenger
4074
+			} else {
4075
+				EE_Error::add_success(
4076
+					sprintf(
4077
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4078
+						ucwords($messenger->label['singular'])
4079
+					)
4080
+				);
4081
+			}
4082 4082
             
4083
-            return true;
4083
+			return true;
4084 4084
             
4085
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4086
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4087
-            //in which case we just give a success message for the messenger being successfully activated.
4088
-        } else {
4089
-            if ( ! $messenger->get_default_message_types()) {
4090
-                //messenger doesn't have any default message types so still a success.
4091
-                EE_Error::add_success(
4092
-                    sprintf(
4093
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4094
-                        ucwords($messenger->label['singular'])
4095
-                    )
4096
-                );
4085
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4086
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4087
+			//in which case we just give a success message for the messenger being successfully activated.
4088
+		} else {
4089
+			if ( ! $messenger->get_default_message_types()) {
4090
+				//messenger doesn't have any default message types so still a success.
4091
+				EE_Error::add_success(
4092
+					sprintf(
4093
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4094
+						ucwords($messenger->label['singular'])
4095
+					)
4096
+				);
4097 4097
                 
4098
-                return true;
4099
-            } else {
4100
-                EE_Error::add_error(
4101
-                    $message_type instanceof EE_message_type
4102
-                        ? sprintf(
4103
-                        esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4104
-                        ucwords($message_type->label['singular']),
4105
-                        ucwords($messenger->label['singular'])
4106
-                    )
4107
-                        : sprintf(
4108
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4109
-                        ucwords($messenger->label['singular'])
4110
-                    ),
4111
-                    __FILE__,
4112
-                    __FUNCTION__,
4113
-                    __LINE__
4114
-                );
4098
+				return true;
4099
+			} else {
4100
+				EE_Error::add_error(
4101
+					$message_type instanceof EE_message_type
4102
+						? sprintf(
4103
+						esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4104
+						ucwords($message_type->label['singular']),
4105
+						ucwords($messenger->label['singular'])
4106
+					)
4107
+						: sprintf(
4108
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4109
+						ucwords($messenger->label['singular'])
4110
+					),
4111
+					__FILE__,
4112
+					__FUNCTION__,
4113
+					__LINE__
4114
+				);
4115 4115
                 
4116
-                return false;
4117
-            }
4118
-        }
4119
-    }
4116
+				return false;
4117
+			}
4118
+		}
4119
+	}
4120 4120
 
4121 4121
 
4122
-    /**
4123
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4124
-     *
4125
-     * @param EE_messenger         $messenger
4126
-     * @param EE_message_type|null $message_type
4127
-     * @return bool
4128
-     * @throws DomainException
4129
-     * @throws EE_Error
4130
-     * @throws InvalidArgumentException
4131
-     * @throws ReflectionException
4132
-     * @throws InvalidDataTypeException
4133
-     * @throws InvalidInterfaceException
4134
-     */
4135
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4136
-        $messenger,
4137
-        EE_message_type $message_type = null
4138
-    ) {
4139
-        EE_Error::overwrite_success();
4140
-        
4141
-        //if $messenger isn't a valid messenger object then get out.
4142
-        if ( ! $messenger instanceof EE_Messenger) {
4143
-            EE_Error::add_error(
4144
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4145
-                __FILE__,
4146
-                __FUNCTION__,
4147
-                __LINE__
4148
-            );
4122
+	/**
4123
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4124
+	 *
4125
+	 * @param EE_messenger         $messenger
4126
+	 * @param EE_message_type|null $message_type
4127
+	 * @return bool
4128
+	 * @throws DomainException
4129
+	 * @throws EE_Error
4130
+	 * @throws InvalidArgumentException
4131
+	 * @throws ReflectionException
4132
+	 * @throws InvalidDataTypeException
4133
+	 * @throws InvalidInterfaceException
4134
+	 */
4135
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4136
+		$messenger,
4137
+		EE_message_type $message_type = null
4138
+	) {
4139
+		EE_Error::overwrite_success();
4140
+        
4141
+		//if $messenger isn't a valid messenger object then get out.
4142
+		if ( ! $messenger instanceof EE_Messenger) {
4143
+			EE_Error::add_error(
4144
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4145
+				__FILE__,
4146
+				__FUNCTION__,
4147
+				__LINE__
4148
+			);
4149 4149
             
4150
-            return false;
4151
-        }
4152
-        
4153
-        if ($message_type instanceof EE_message_type) {
4154
-            $message_type_name = $message_type->name;
4155
-            EE_Error::add_success(
4156
-                sprintf(
4157
-                    esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4158
-                    ucwords($message_type->label['singular']),
4159
-                    ucwords($messenger->label['singular'])
4160
-                )
4161
-            );
4162
-        } else {
4163
-            $message_type_name = '';
4164
-            EE_Error::add_success(
4165
-                sprintf(
4166
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4167
-                    ucwords($messenger->label['singular'])
4168
-                )
4169
-            );
4170
-        }
4171
-        
4172
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4173
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4174
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4175
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4176
-            if ($count_updated > 0) {
4177
-                $msg = $message_type_name === 'invoice'
4178
-                    ? esc_html__(
4179
-                        '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.',
4180
-                        'event_espresso'
4181
-                    )
4182
-                    : esc_html__(
4183
-                        '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.',
4184
-                        'event_espresso'
4185
-                    );
4186
-                EE_Error::add_attention($msg);
4187
-            }
4188
-        }
4189
-        
4190
-        return true;
4191
-    }
4150
+			return false;
4151
+		}
4152
+        
4153
+		if ($message_type instanceof EE_message_type) {
4154
+			$message_type_name = $message_type->name;
4155
+			EE_Error::add_success(
4156
+				sprintf(
4157
+					esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4158
+					ucwords($message_type->label['singular']),
4159
+					ucwords($messenger->label['singular'])
4160
+				)
4161
+			);
4162
+		} else {
4163
+			$message_type_name = '';
4164
+			EE_Error::add_success(
4165
+				sprintf(
4166
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4167
+					ucwords($messenger->label['singular'])
4168
+				)
4169
+			);
4170
+		}
4171
+        
4172
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4173
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4174
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4175
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4176
+			if ($count_updated > 0) {
4177
+				$msg = $message_type_name === 'invoice'
4178
+					? esc_html__(
4179
+						'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.',
4180
+						'event_espresso'
4181
+					)
4182
+					: esc_html__(
4183
+						'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.',
4184
+						'event_espresso'
4185
+					);
4186
+				EE_Error::add_attention($msg);
4187
+			}
4188
+		}
4189
+        
4190
+		return true;
4191
+	}
4192 4192
 
4193 4193
 
4194
-    /**
4195
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4196
-     *
4197
-     * @throws DomainException
4198
-     */
4199
-    public function update_mt_form()
4200
-    {
4201
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4202
-            EE_Error::add_error(
4203
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4204
-                __FILE__,
4205
-                __FUNCTION__,
4206
-                __LINE__
4207
-            );
4208
-            $this->_return_json();
4209
-        }
4210
-        
4211
-        $message_types = $this->get_installed_message_types();
4212
-        
4213
-        $message_type = $message_types[$this->_req_data['message_type']];
4214
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4215
-        
4216
-        $content                         = $this->_message_type_settings_content(
4217
-            $message_type,
4218
-            $messenger,
4219
-            true
4220
-        );
4221
-        $this->_template_args['success'] = true;
4222
-        $this->_template_args['content'] = $content;
4223
-        $this->_return_json();
4224
-    }
4194
+	/**
4195
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4196
+	 *
4197
+	 * @throws DomainException
4198
+	 */
4199
+	public function update_mt_form()
4200
+	{
4201
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4202
+			EE_Error::add_error(
4203
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4204
+				__FILE__,
4205
+				__FUNCTION__,
4206
+				__LINE__
4207
+			);
4208
+			$this->_return_json();
4209
+		}
4210
+        
4211
+		$message_types = $this->get_installed_message_types();
4212
+        
4213
+		$message_type = $message_types[$this->_req_data['message_type']];
4214
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4215
+        
4216
+		$content                         = $this->_message_type_settings_content(
4217
+			$message_type,
4218
+			$messenger,
4219
+			true
4220
+		);
4221
+		$this->_template_args['success'] = true;
4222
+		$this->_template_args['content'] = $content;
4223
+		$this->_return_json();
4224
+	}
4225 4225
     
4226 4226
     
4227
-    /**
4228
-     * this handles saving the settings for a messenger or message type
4229
-     *
4230
-     */
4231
-    public function save_settings()
4232
-    {
4233
-        if ( ! isset($this->_req_data['type'])) {
4234
-            EE_Error::add_error(
4235
-                esc_html__(
4236
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4237
-                    'event_espresso'
4238
-                ),
4239
-                __FILE__,
4240
-                __FUNCTION__,
4241
-                __LINE__
4242
-            );
4243
-            $this->_template_args['error'] = true;
4244
-            $this->_return_json();
4245
-        }
4246
-        
4247
-        
4248
-        if ($this->_req_data['type'] === 'messenger') {
4249
-            //this should be an array.
4250
-            $settings  = $this->_req_data['messenger_settings'];
4251
-            $messenger = $settings['messenger'];
4252
-            //let's setup the settings data
4253
-            foreach ($settings as $key => $value) {
4254
-                switch ($key) {
4255
-                    case 'messenger' :
4256
-                        unset($settings['messenger']);
4257
-                        break;
4258
-                    case 'message_types' :
4259
-                        unset($settings['message_types']);
4260
-                        break;
4261
-                    default :
4262
-                        $settings[$key] = $value;
4263
-                        break;
4264
-                }
4265
-            }
4266
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4267
-        } elseif ($this->_req_data['type'] === 'message_type') {
4268
-            $settings     = $this->_req_data['message_type_settings'];
4269
-            $messenger    = $settings['messenger'];
4270
-            $message_type = $settings['message_type'];
4227
+	/**
4228
+	 * this handles saving the settings for a messenger or message type
4229
+	 *
4230
+	 */
4231
+	public function save_settings()
4232
+	{
4233
+		if ( ! isset($this->_req_data['type'])) {
4234
+			EE_Error::add_error(
4235
+				esc_html__(
4236
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4237
+					'event_espresso'
4238
+				),
4239
+				__FILE__,
4240
+				__FUNCTION__,
4241
+				__LINE__
4242
+			);
4243
+			$this->_template_args['error'] = true;
4244
+			$this->_return_json();
4245
+		}
4246
+        
4247
+        
4248
+		if ($this->_req_data['type'] === 'messenger') {
4249
+			//this should be an array.
4250
+			$settings  = $this->_req_data['messenger_settings'];
4251
+			$messenger = $settings['messenger'];
4252
+			//let's setup the settings data
4253
+			foreach ($settings as $key => $value) {
4254
+				switch ($key) {
4255
+					case 'messenger' :
4256
+						unset($settings['messenger']);
4257
+						break;
4258
+					case 'message_types' :
4259
+						unset($settings['message_types']);
4260
+						break;
4261
+					default :
4262
+						$settings[$key] = $value;
4263
+						break;
4264
+				}
4265
+			}
4266
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4267
+		} elseif ($this->_req_data['type'] === 'message_type') {
4268
+			$settings     = $this->_req_data['message_type_settings'];
4269
+			$messenger    = $settings['messenger'];
4270
+			$message_type = $settings['message_type'];
4271 4271
             
4272
-            foreach ($settings as $key => $value) {
4273
-                switch ($key) {
4274
-                    case 'messenger' :
4275
-                        unset($settings['messenger']);
4276
-                        break;
4277
-                    case 'message_type' :
4278
-                        unset($settings['message_type']);
4279
-                        break;
4280
-                    default :
4281
-                        $settings[$key] = $value;
4282
-                        break;
4283
-                }
4284
-            }
4272
+			foreach ($settings as $key => $value) {
4273
+				switch ($key) {
4274
+					case 'messenger' :
4275
+						unset($settings['messenger']);
4276
+						break;
4277
+					case 'message_type' :
4278
+						unset($settings['message_type']);
4279
+						break;
4280
+					default :
4281
+						$settings[$key] = $value;
4282
+						break;
4283
+				}
4284
+			}
4285 4285
             
4286
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4287
-        }
4288
-        
4289
-        //okay we should have the data all setup.  Now we just update!
4290
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4291
-        
4292
-        if ($success) {
4293
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4294
-        } else {
4295
-            EE_Error::add_error(
4296
-                esc_html__(
4297
-                    'Settings did not get updated',
4298
-                    'event_espresso'
4299
-                ),
4300
-                __FILE__,
4301
-                __FUNCTION__,
4302
-                __LINE__
4303
-            );
4304
-        }
4305
-        
4306
-        $this->_template_args['success'] = $success;
4307
-        $this->_return_json();
4308
-    }
4286
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4287
+		}
4288
+        
4289
+		//okay we should have the data all setup.  Now we just update!
4290
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4291
+        
4292
+		if ($success) {
4293
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4294
+		} else {
4295
+			EE_Error::add_error(
4296
+				esc_html__(
4297
+					'Settings did not get updated',
4298
+					'event_espresso'
4299
+				),
4300
+				__FILE__,
4301
+				__FUNCTION__,
4302
+				__LINE__
4303
+			);
4304
+		}
4305
+        
4306
+		$this->_template_args['success'] = $success;
4307
+		$this->_return_json();
4308
+	}
4309 4309
     
4310 4310
     
4311 4311
     
4312 4312
     
4313
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4313
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4314 4314
 
4315 4315
 
4316
-    /**
4317
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4318
-     * However, this does not send immediately, it just queues for sending.
4319
-     *
4320
-     * @since 4.9.0
4321
-     * @throws EE_Error
4322
-     * @throws InvalidDataTypeException
4323
-     * @throws InvalidInterfaceException
4324
-     * @throws InvalidArgumentException
4325
-     * @throws ReflectionException
4326
-     */
4327
-    protected function _generate_now()
4328
-    {
4329
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4330
-        $this->_redirect_after_action(false, '', '', array(), true);
4331
-    }
4316
+	/**
4317
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4318
+	 * However, this does not send immediately, it just queues for sending.
4319
+	 *
4320
+	 * @since 4.9.0
4321
+	 * @throws EE_Error
4322
+	 * @throws InvalidDataTypeException
4323
+	 * @throws InvalidInterfaceException
4324
+	 * @throws InvalidArgumentException
4325
+	 * @throws ReflectionException
4326
+	 */
4327
+	protected function _generate_now()
4328
+	{
4329
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4330
+		$this->_redirect_after_action(false, '', '', array(), true);
4331
+	}
4332 4332
 
4333 4333
 
4334
-    /**
4335
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4336
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4337
-     *
4338
-     * @since 4.9.0
4339
-     * @throws EE_Error
4340
-     * @throws InvalidDataTypeException
4341
-     * @throws InvalidInterfaceException
4342
-     * @throws InvalidArgumentException
4343
-     * @throws ReflectionException
4344
-     */
4345
-    protected function _generate_and_send_now()
4346
-    {
4347
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4348
-        $this->_redirect_after_action(false, '', '', array(), true);
4349
-    }
4334
+	/**
4335
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4336
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4337
+	 *
4338
+	 * @since 4.9.0
4339
+	 * @throws EE_Error
4340
+	 * @throws InvalidDataTypeException
4341
+	 * @throws InvalidInterfaceException
4342
+	 * @throws InvalidArgumentException
4343
+	 * @throws ReflectionException
4344
+	 */
4345
+	protected function _generate_and_send_now()
4346
+	{
4347
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4348
+		$this->_redirect_after_action(false, '', '', array(), true);
4349
+	}
4350 4350
 
4351 4351
 
4352
-    /**
4353
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4354
-     *
4355
-     * @since 4.9.0
4356
-     * @throws EE_Error
4357
-     * @throws InvalidDataTypeException
4358
-     * @throws InvalidInterfaceException
4359
-     * @throws InvalidArgumentException
4360
-     * @throws ReflectionException
4361
-     */
4362
-    protected function _queue_for_resending()
4363
-    {
4364
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4365
-        $this->_redirect_after_action(false, '', '', array(), true);
4366
-    }
4352
+	/**
4353
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4354
+	 *
4355
+	 * @since 4.9.0
4356
+	 * @throws EE_Error
4357
+	 * @throws InvalidDataTypeException
4358
+	 * @throws InvalidInterfaceException
4359
+	 * @throws InvalidArgumentException
4360
+	 * @throws ReflectionException
4361
+	 */
4362
+	protected function _queue_for_resending()
4363
+	{
4364
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4365
+		$this->_redirect_after_action(false, '', '', array(), true);
4366
+	}
4367 4367
 
4368 4368
 
4369
-    /**
4370
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4371
-     *
4372
-     * @since 4.9.0
4373
-     * @throws EE_Error
4374
-     * @throws InvalidDataTypeException
4375
-     * @throws InvalidInterfaceException
4376
-     * @throws InvalidArgumentException
4377
-     * @throws ReflectionException
4378
-     */
4379
-    protected function _send_now()
4380
-    {
4381
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4382
-        $this->_redirect_after_action(false, '', '', array(), true);
4383
-    }
4369
+	/**
4370
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4371
+	 *
4372
+	 * @since 4.9.0
4373
+	 * @throws EE_Error
4374
+	 * @throws InvalidDataTypeException
4375
+	 * @throws InvalidInterfaceException
4376
+	 * @throws InvalidArgumentException
4377
+	 * @throws ReflectionException
4378
+	 */
4379
+	protected function _send_now()
4380
+	{
4381
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4382
+		$this->_redirect_after_action(false, '', '', array(), true);
4383
+	}
4384 4384
 
4385 4385
 
4386
-    /**
4387
-     * Deletes EE_messages for IDs in the request.
4388
-     *
4389
-     * @since 4.9.0
4390
-     * @throws EE_Error
4391
-     * @throws InvalidDataTypeException
4392
-     * @throws InvalidInterfaceException
4393
-     * @throws InvalidArgumentException
4394
-     */
4395
-    protected function _delete_ee_messages()
4396
-    {
4397
-        $msg_ids       = $this->_get_msg_ids_from_request();
4398
-        $deleted_count = 0;
4399
-        foreach ($msg_ids as $msg_id) {
4400
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4401
-                $deleted_count++;
4402
-            }
4403
-        }
4404
-        if ($deleted_count) {
4405
-            $this->_redirect_after_action(
4406
-                true,
4407
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
4408
-                esc_html__('deleted', 'event_espresso')
4409
-            );
4410
-        } else {
4411
-            EE_Error::add_error(
4412
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4413
-                __FILE__, __FUNCTION__, __LINE__
4414
-            );
4415
-            $this->_redirect_after_action(false, '', '', array(), true);
4416
-        }
4417
-    }
4386
+	/**
4387
+	 * Deletes EE_messages for IDs in the request.
4388
+	 *
4389
+	 * @since 4.9.0
4390
+	 * @throws EE_Error
4391
+	 * @throws InvalidDataTypeException
4392
+	 * @throws InvalidInterfaceException
4393
+	 * @throws InvalidArgumentException
4394
+	 */
4395
+	protected function _delete_ee_messages()
4396
+	{
4397
+		$msg_ids       = $this->_get_msg_ids_from_request();
4398
+		$deleted_count = 0;
4399
+		foreach ($msg_ids as $msg_id) {
4400
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4401
+				$deleted_count++;
4402
+			}
4403
+		}
4404
+		if ($deleted_count) {
4405
+			$this->_redirect_after_action(
4406
+				true,
4407
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
4408
+				esc_html__('deleted', 'event_espresso')
4409
+			);
4410
+		} else {
4411
+			EE_Error::add_error(
4412
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4413
+				__FILE__, __FUNCTION__, __LINE__
4414
+			);
4415
+			$this->_redirect_after_action(false, '', '', array(), true);
4416
+		}
4417
+	}
4418 4418
     
4419 4419
     
4420
-    /**
4421
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4422
-     * @since 4.9.0
4423
-     * @return array
4424
-     */
4425
-    protected function _get_msg_ids_from_request()
4426
-    {
4427
-        if ( ! isset($this->_req_data['MSG_ID'])) {
4428
-            return array();
4429
-        }
4430
-        
4431
-        return is_array($this->_req_data['MSG_ID'])
4432
-            ? array_keys($this->_req_data['MSG_ID'])
4433
-            : array($this->_req_data['MSG_ID']);
4434
-    }
4420
+	/**
4421
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4422
+	 * @since 4.9.0
4423
+	 * @return array
4424
+	 */
4425
+	protected function _get_msg_ids_from_request()
4426
+	{
4427
+		if ( ! isset($this->_req_data['MSG_ID'])) {
4428
+			return array();
4429
+		}
4430
+        
4431
+		return is_array($this->_req_data['MSG_ID'])
4432
+			? array_keys($this->_req_data['MSG_ID'])
4433
+			: array($this->_req_data['MSG_ID']);
4434
+	}
4435 4435
 }
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
         $this->_admin_base_url  = EE_MSG_ADMIN_URL;
95 95
         $this->_admin_base_path = EE_MSG_ADMIN;
96 96
         
97
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
97
+        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array();
98 98
         
99 99
         $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100 100
         $this->_load_message_resource_manager();
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254 254
             $messenger_options
255 255
         );
256
-        $input             = new EE_Select_Input(
256
+        $input = new EE_Select_Input(
257 257
             $messenger_options,
258 258
             array(
259 259
                 'html_name'  => 'ee_messenger_filter_by',
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
             array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292 292
             $message_type_options
293 293
         );
294
-        $input                = new EE_Select_Input(
294
+        $input = new EE_Select_Input(
295 295
             $message_type_options,
296 296
             array(
297 297
                 'html_name'  => 'ee_message_type_filter_by',
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
             array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330 330
             $context_options
331 331
         );
332
-        $input           = new EE_Select_Input(
332
+        $input = new EE_Select_Input(
333 333
             $context_options,
334 334
             array(
335 335
                 'html_name'  => 'ee_context_filter_by',
@@ -711,53 +711,53 @@  discard block
 block discarded – undo
711 711
     
712 712
     public function messages_help_tab()
713 713
     {
714
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
714
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
715 715
     }
716 716
     
717 717
     
718 718
     public function messengers_help_tab()
719 719
     {
720
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
720
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
721 721
     }
722 722
     
723 723
     
724 724
     public function message_types_help_tab()
725 725
     {
726
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
726
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
727 727
     }
728 728
     
729 729
     
730 730
     public function messages_overview_help_tab()
731 731
     {
732
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
732
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
733 733
     }
734 734
     
735 735
     
736 736
     public function message_templates_help_tab()
737 737
     {
738
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
738
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
739 739
     }
740 740
     
741 741
     
742 742
     public function edit_message_template_help_tab()
743 743
     {
744
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
744
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
745 745
                         . esc_attr__('Editor Title', 'event_espresso')
746 746
                         . '" />';
747
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
747
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
748 748
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
749 749
                         . '" />';
750
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
750
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
751 751
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
752 752
                         . '" />';
753
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
753
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
754 754
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
755 755
                         . '" />';
756
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
756
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
757 757
                         . esc_attr__('Publish Metabox', 'event_espresso')
758 758
                         . '" />';
759 759
         EEH_Template::display_template(
760
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
760
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
761 761
             $args
762 762
         );
763 763
     }
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
         $this->_set_shortcodes();
769 769
         $args['shortcodes'] = $this->_shortcodes;
770 770
         EEH_Template::display_template(
771
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
771
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
772 772
             $args
773 773
         );
774 774
     }
@@ -776,16 +776,16 @@  discard block
 block discarded – undo
776 776
     
777 777
     public function preview_message_help_tab()
778 778
     {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
779
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
780 780
     }
781 781
     
782 782
     
783 783
     public function settings_help_tab()
784 784
     {
785
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
785
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
786
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
787
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
788
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
789 789
         $args['img3'] = '<div class="switch">'
790 790
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791 791
                         . ' type="checkbox" checked="checked">'
@@ -796,18 +796,18 @@  discard block
 block discarded – undo
796 796
                         . ' type="checkbox">'
797 797
                         . '<label for="ee-on-off-toggle-on"></label>'
798 798
                         . '</div>';
799
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
799
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
800 800
     }
801 801
     
802 802
     
803 803
     public function load_scripts_styles()
804 804
     {
805
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
805
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806 806
         wp_enqueue_style('espresso_ee_msg');
807 807
         
808
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
808
+        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js',
809 809
             array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
810
+        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
811 811
             array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812 812
     }
813 813
     
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
         
840 840
         $this->_set_shortcodes();
841 841
         
842
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
842
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
843 843
             esc_html__(
844 844
                 '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.',
845 845
                 'event_espresso'
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
         
859 859
         wp_register_script(
860 860
             'ee_msgs_edit_js',
861
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
861
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
862 862
             array('jquery'),
863 863
             EVENT_ESPRESSO_VERSION
864 864
         );
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
     {
902 902
         wp_register_style(
903 903
             'ee-message-settings',
904
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
904
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
905 905
             array(),
906 906
             EVENT_ESPRESSO_VERSION
907 907
         );
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
             }
988 988
             $status_bulk_actions = $common_bulk_actions;
989 989
             //unset bulk actions not applying to status
990
-            if (! empty($status_bulk_actions)) {
990
+            if ( ! empty($status_bulk_actions)) {
991 991
                 switch ($status) {
992 992
                     case EEM_Message::status_idle:
993 993
                     case EEM_Message::status_resend:
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
             }
1013 1013
 
1014 1014
             //skip adding messenger executing status to views because it will be included with the Failed view.
1015
-            if ( $status === EEM_Message::status_messenger_executing ) {
1015
+            if ($status === EEM_Message::status_messenger_executing) {
1016 1016
                 continue;
1017 1017
             }
1018 1018
             
@@ -1064,37 +1064,37 @@  discard block
 block discarded – undo
1064 1064
         /** @type array $status_items status legend setup */
1065 1065
         $status_items = array(
1066 1066
             'sent_status'       => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1067
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1068 1068
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069 1069
             ),
1070 1070
             'idle_status'       => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1071
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1072 1072
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073 1073
             ),
1074 1074
             'failed_status'     => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1075
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1076 1076
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077 1077
             ),
1078 1078
             'messenger_executing_status' => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1079
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1080 1080
                 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081 1081
             ),
1082 1082
             'resend_status'     => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1083
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1084 1084
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085 1085
             ),
1086 1086
             'incomplete_status' => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1087
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1088 1088
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089 1089
             ),
1090 1090
             'retry_status'      => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1091
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1092 1092
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093 1093
             )
1094 1094
         );
1095 1095
         if (EEM_Message::debug()) {
1096 1096
             $status_items['debug_only_status'] = array(
1097
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1097
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1098 1098
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099 1099
             );
1100 1100
         }
@@ -1106,8 +1106,8 @@  discard block
 block discarded – undo
1106 1106
     protected function _custom_mtps_preview()
1107 1107
     {
1108 1108
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1109
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1110
+            . ' alt="'.esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso').'" />';
1111 1111
         $this->_template_args['preview_text'] = '<strong>'
1112 1112
             . esc_html__(
1113 1113
                 '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.',
@@ -1389,7 +1389,7 @@  discard block
 block discarded – undo
1389 1389
                             //let's verify if we need this extra field via the shortcodes parameter.
1390 1390
                             $continue = false;
1391 1391
                             if (isset($extra_array['shortcodes_required'])) {
1392
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1392
+                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1393 1393
                                     if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394 1394
                                         $continue = true;
1395 1395
                                     }
@@ -1399,7 +1399,7 @@  discard block
 block discarded – undo
1399 1399
                                 }
1400 1400
                             }
1401 1401
                             
1402
-                            $field_id                                = $reference_field
1402
+                            $field_id = $reference_field
1403 1403
                                                                        . '-'
1404 1404
                                                                        . $extra_field
1405 1405
                                                                        . '-content';
@@ -1407,8 +1407,8 @@  discard block
 block discarded – undo
1407 1407
                             $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408 1408
                                                                        . $reference_field
1409 1409
                                                                        . '][content]['
1410
-                                                                       . $extra_field . ']';
1411
-                            $css_class                               = isset($extra_array['css_class'])
1410
+                                                                       . $extra_field.']';
1411
+                            $css_class = isset($extra_array['css_class'])
1412 1412
                                 ? $extra_array['css_class']
1413 1413
                                 : '';
1414 1414
                             
@@ -1419,7 +1419,7 @@  discard block
 block discarded – undo
1419 1419
                                     is_array($validators[$extra_field])
1420 1420
                                     && isset($validators[$extra_field]['msg'])
1421 1421
                                 )
1422
-                                ? 'validate-error ' . $css_class
1422
+                                ? 'validate-error '.$css_class
1423 1423
                                 : $css_class;
1424 1424
                             
1425 1425
                             $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__(
@@ -2125,7 +2125,7 @@  discard block
 block discarded – undo
2125 2125
         }
2126 2126
         
2127 2127
         //let's add a button to go back to the edit view
2128
-        $query_args             = array(
2128
+        $query_args = array(
2129 2129
             'id'      => $this->_req_data['GRP_ID'],
2130 2130
             'context' => $this->_req_data['context'],
2131 2131
             'action'  => 'edit_message_template'
@@ -2151,7 +2151,7 @@  discard block
 block discarded – undo
2151 2151
         );
2152 2152
         //setup display of preview.
2153 2153
         $this->_admin_page_title                    = $preview_title;
2154
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2154
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2155 2155
         $this->_template_args['data']['force_json'] = true;
2156 2156
         
2157 2157
         return '';
@@ -2257,7 +2257,7 @@  discard block
 block discarded – undo
2257 2257
         }
2258 2258
         
2259 2259
         //setup variation select values for the currently selected template.
2260
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2260
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2261 2261
             $this->_message_template_group->messenger(),
2262 2262
             $this->_message_template_group->message_type()
2263 2263
         );
@@ -2271,12 +2271,12 @@  discard block
 block discarded – undo
2271 2271
         
2272 2272
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2273 2273
         
2274
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2274
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2275 2275
             'MTP_template_pack',
2276 2276
             $tp_select_values,
2277 2277
             $this->_message_template_group->get_template_pack_name()
2278 2278
         );
2279
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2279
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2280 2280
             'MTP_template_variation',
2281 2281
             $variations_select_values,
2282 2282
             $this->_message_template_group->get_template_pack_variation()
@@ -2286,7 +2286,7 @@  discard block
 block discarded – undo
2286 2286
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2287 2287
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2288 2288
         
2289
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2289
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2290 2290
         
2291 2291
         EEH_Template::display_template($template, $template_args);
2292 2292
     }
@@ -2315,14 +2315,14 @@  discard block
 block discarded – undo
2315 2315
         if ( ! empty($fields)) {
2316 2316
             //yup there be fields
2317 2317
             foreach ($fields as $field => $config) {
2318
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2318
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2319 2319
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2320 2320
                 $default  = isset($config['default']) ? $config['default'] : '';
2321 2321
                 $default  = isset($config['value']) ? $config['value'] : $default;
2322 2322
                 
2323 2323
                 // if type is hidden and the value is empty
2324 2324
                 // something may have gone wrong so let's correct with the defaults
2325
-                $fix              = $config['input'] === 'hidden'
2325
+                $fix = $config['input'] === 'hidden'
2326 2326
                                     && isset($existing[$field])
2327 2327
                                     && empty($existing[$field])
2328 2328
                     ? $default
@@ -2332,7 +2332,7 @@  discard block
 block discarded – undo
2332 2332
                     : $fix;
2333 2333
                 
2334 2334
                 $template_form_fields[$field_id] = array(
2335
-                    'name'       => 'test_settings_fld[' . $field . ']',
2335
+                    'name'       => 'test_settings_fld['.$field.']',
2336 2336
                     'label'      => $config['label'],
2337 2337
                     'input'      => $config['input'],
2338 2338
                     'type'       => $config['type'],
@@ -2400,7 +2400,7 @@  discard block
 block discarded – undo
2400 2400
         );
2401 2401
         
2402 2402
         return EEH_Template::display_template(
2403
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2403
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2404 2404
             $template_args,
2405 2405
             true
2406 2406
         );
@@ -2425,7 +2425,7 @@  discard block
 block discarded – undo
2425 2425
         //$messenger = $this->_message_template_group->messenger_obj();
2426 2426
         //now let's set the content depending on the status of the shortcodes array
2427 2427
         if (empty($shortcodes)) {
2428
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2428
+            $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2429 2429
             echo $content;
2430 2430
         } else {
2431 2431
             //$alt = 0;
@@ -2562,7 +2562,7 @@  discard block
 block discarded – undo
2562 2562
                     <?php
2563 2563
                 }
2564 2564
                 //setup nonce_url
2565
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2565
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2566 2566
                 ?>
2567 2567
                 <select name="context">
2568 2568
                     <?php
@@ -2663,7 +2663,7 @@  discard block
 block discarded – undo
2663 2663
         $context      = ucwords(str_replace('_', ' ', $context_slug));
2664 2664
         
2665 2665
         $item_desc = $messenger_label && $message_type_label
2666
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2666
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2667 2667
             : '';
2668 2668
         $item_desc .= 'Message Template';
2669 2669
         $query_args  = array();
@@ -2736,9 +2736,9 @@  discard block
 block discarded – undo
2736 2736
                             'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2737 2737
                         );
2738 2738
                         //if they aren't allowed to use all JS, restrict them to just posty-y tags
2739
-                        if (! current_user_can('unfiltered_html')){
2740
-                            if (is_array($set_column_values['MTP_content'])){
2741
-                                 foreach($set_column_values['MTP_content'] as $key => $value) {
2739
+                        if ( ! current_user_can('unfiltered_html')) {
2740
+                            if (is_array($set_column_values['MTP_content'])) {
2741
+                                 foreach ($set_column_values['MTP_content'] as $key => $value) {
2742 2742
                                      $set_column_values['MTP_content'][$key] = wp_kses(
2743 2743
                                          $value,
2744 2744
                                          wp_kses_allowed_html('post')
@@ -2780,7 +2780,7 @@  discard block
 block discarded – undo
2780 2780
                                 //default setup for it.
2781 2781
                                 //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2782 2782
                                 $updated = $MTP->insert($message_template_fields);
2783
-                                if (! $updated || is_wp_error($updated)) {
2783
+                                if ( ! $updated || is_wp_error($updated)) {
2784 2784
                                     EE_Error::add_error(
2785 2785
                                         sprintf(
2786 2786
                                             esc_html__('%s field could not be updated.', 'event_espresso'),
@@ -3141,7 +3141,7 @@  discard block
 block discarded – undo
3141 3141
             : 'email';
3142 3142
         
3143 3143
         //let's setup the messenger tabs
3144
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3144
+        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3145 3145
             $this->_m_mt_settings['messenger_tabs'],
3146 3146
             'messenger_links',
3147 3147
             '|',
@@ -3209,10 +3209,10 @@  discard block
 block discarded – undo
3209 3209
                 
3210 3210
                 $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3211 3211
                     'label'    => ucwords($message_type->label['singular']),
3212
-                    'class'    => 'message-type-' . $a_or_i,
3213
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3214
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3215
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3212
+                    'class'    => 'message-type-'.$a_or_i,
3213
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3214
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3215
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3216 3216
                     'title'    => $a_or_i === 'active'
3217 3217
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3218 3218
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3248,9 +3248,9 @@  discard block
 block discarded – undo
3248 3248
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3249 3249
             
3250 3250
             foreach ($fields as $fldname => $fldprops) {
3251
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3251
+                $field_id                       = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3252 3252
                 $template_form_field[$field_id] = array(
3253
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3253
+                    'name'       => 'message_type_settings['.$fldname.']',
3254 3254
                     'label'      => $fldprops['label'],
3255 3255
                     'input'      => $fldprops['field_type'],
3256 3256
                     'type'       => $fldprops['value_type'],
@@ -3301,12 +3301,12 @@  discard block
 block discarded – undo
3301 3301
             $settings_template_args['hidden_fields'],
3302 3302
             'array'
3303 3303
         );
3304
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3304
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3305 3305
             ? ' hidden'
3306 3306
             : '';
3307 3307
         
3308 3308
         
3309
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3309
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3310 3310
         $content  = EEH_Template::display_template($template, $settings_template_args, true);
3311 3311
         
3312 3312
         return $content;
@@ -3341,11 +3341,11 @@  discard block
 block discarded – undo
3341 3341
                 )
3342 3342
                     ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3343 3343
                     : '';
3344
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3344
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3345 3345
                     esc_html__('%s Settings', 'event_espresso'),
3346 3346
                     $tab_array['label']
3347 3347
                 );
3348
-                $m_template_args[$messenger . '_a_box'] = array(
3348
+                $m_template_args[$messenger.'_a_box'] = array(
3349 3349
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3350 3350
                     'inactive_message_types' => isset(
3351 3351
                         $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
@@ -3361,8 +3361,8 @@  discard block
 block discarded – undo
3361 3361
                 // message type meta boxes
3362 3362
                 // (which is really just the inactive container for each messenger
3363 3363
                 // showing inactive message types for that messenger)
3364
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3365
-                $mt_template_args[$messenger . '_i_box'] = array(
3364
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3365
+                $mt_template_args[$messenger.'_i_box'] = array(
3366 3366
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3367 3367
                     'inactive_message_types' => isset(
3368 3368
                         $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
@@ -3380,14 +3380,14 @@  discard block
 block discarded – undo
3380 3380
         
3381 3381
         
3382 3382
         //register messenger metaboxes
3383
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3383
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3384 3384
         foreach ($m_boxes as $box => $label) {
3385 3385
             $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3386 3386
             $msgr          = str_replace('_a_box', '', $box);
3387 3387
             add_meta_box(
3388
-                'espresso_' . $msgr . '_settings',
3388
+                'espresso_'.$msgr.'_settings',
3389 3389
                 $label,
3390
-                function ($post, $metabox) {
3390
+                function($post, $metabox) {
3391 3391
                     echo EEH_Template::display_template(
3392 3392
                             $metabox["args"]["template_path"],
3393 3393
                             $metabox["args"]["template_args"],
@@ -3402,17 +3402,17 @@  discard block
 block discarded – undo
3402 3402
         }
3403 3403
         
3404 3404
         //register message type metaboxes
3405
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3405
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3406 3406
         foreach ($mt_boxes as $box => $label) {
3407 3407
             $callback_args = array(
3408 3408
                 'template_path' => $mt_template_path,
3409 3409
                 'template_args' => $mt_template_args[$box]
3410 3410
             );
3411
-            $mt            = str_replace('_i_box', '', $box);
3411
+            $mt = str_replace('_i_box', '', $box);
3412 3412
             add_meta_box(
3413
-                'espresso_' . $mt . '_inactive_mts',
3413
+                'espresso_'.$mt.'_inactive_mts',
3414 3414
                 $label,
3415
-                function ($post, $metabox) {
3415
+                function($post, $metabox) {
3416 3416
                     echo EEH_Template::display_template(
3417 3417
                             $metabox["args"]["template_path"],
3418 3418
                             $metabox["args"]["template_args"],
@@ -3559,7 +3559,7 @@  discard block
 block discarded – undo
3559 3559
             if ($form->is_valid()) {
3560 3560
                 $valid_data = $form->valid_data();
3561 3561
                 foreach ($valid_data as $property => $value) {
3562
-                    $setter = 'set_' . $property;
3562
+                    $setter = 'set_'.$property;
3563 3563
                     if (method_exists($network_config, $setter)) {
3564 3564
                         $network_config->{$setter}($value);
3565 3565
                     } else if (
@@ -3594,8 +3594,8 @@  discard block
 block discarded – undo
3594 3594
      */
3595 3595
     protected function _get_mt_tabs($tab_array)
3596 3596
     {
3597
-        $tab_array = (array)$tab_array;
3598
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3597
+        $tab_array = (array) $tab_array;
3598
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3599 3599
         $tabs      = '';
3600 3600
         
3601 3601
         foreach ($tab_array as $tab) {
@@ -3628,9 +3628,9 @@  discard block
 block discarded – undo
3628 3628
             $existing_settings = $messenger->get_existing_admin_settings();
3629 3629
             
3630 3630
             foreach ($fields as $fldname => $fldprops) {
3631
-                $field_id                       = $messenger->name . '-' . $fldname;
3631
+                $field_id                       = $messenger->name.'-'.$fldname;
3632 3632
                 $template_form_field[$field_id] = array(
3633
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3633
+                    'name'       => 'messenger_settings['.$field_id.']',
3634 3634
                     'label'      => $fldprops['label'],
3635 3635
                     'input'      => $fldprops['field_type'],
3636 3636
                     'type'       => $fldprops['value_type'],
@@ -3665,7 +3665,7 @@  discard block
 block discarded – undo
3665 3665
         //make sure any active message types that are existing are included in the hidden fields
3666 3666
         if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3667 3667
             foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3668
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3668
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(
3669 3669
                     'type'  => 'hidden',
3670 3670
                     'value' => $mt
3671 3671
                 );
@@ -3694,9 +3694,9 @@  discard block
 block discarded – undo
3694 3694
         
3695 3695
         
3696 3696
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3697
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3697
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3698 3698
         $settings_template_args['on_off_status'] = $active ? true : false;
3699
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3699
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3700 3700
         $content                                 = EEH_Template::display_template(
3701 3701
             $template,
3702 3702
             $settings_template_args,
@@ -3736,7 +3736,7 @@  discard block
 block discarded – undo
3736 3736
         $nonce     = isset($this->_req_data['activate_nonce'])
3737 3737
             ? sanitize_text_field($this->_req_data['activate_nonce'])
3738 3738
             : '';
3739
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3739
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3740 3740
         
3741 3741
         $this->_verify_nonce($nonce, $nonce_ref);
3742 3742
         
@@ -3852,7 +3852,7 @@  discard block
 block discarded – undo
3852 3852
         
3853 3853
         //do a nonce check here since we're not arriving via a normal route
3854 3854
         $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3855
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3855
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
3856 3856
         
3857 3857
         $this->_verify_nonce($nonce, $nonce_ref);
3858 3858
         
@@ -4213,7 +4213,7 @@  discard block
 block discarded – undo
4213 4213
         $message_type = $message_types[$this->_req_data['message_type']];
4214 4214
         $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4215 4215
         
4216
-        $content                         = $this->_message_type_settings_content(
4216
+        $content = $this->_message_type_settings_content(
4217 4217
             $message_type,
4218 4218
             $messenger,
4219 4219
             true
Please login to merge, or discard this patch.
core/db_models/fields/EE_Text_Field_Base.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -7,49 +7,49 @@
 block discarded – undo
7 7
 abstract class EE_Text_Field_Base extends EE_Model_Field_Base
8 8
 {
9 9
 
10
-    /**
11
-     * Gets the value in the format expected when being set.
12
-     * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead.
13
-     * @param mixed $value_of_field_on_model_object
14
-     * @return mixed|string
15
-     */
16
-    public function prepare_for_get($value_of_field_on_model_object)
17
-    {
18
-        return $value_of_field_on_model_object;
19
-    }
10
+	/**
11
+	 * Gets the value in the format expected when being set.
12
+	 * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead.
13
+	 * @param mixed $value_of_field_on_model_object
14
+	 * @return mixed|string
15
+	 */
16
+	public function prepare_for_get($value_of_field_on_model_object)
17
+	{
18
+		return $value_of_field_on_model_object;
19
+	}
20 20
 
21
-    /**
22
-     * Accepts schema of 'form_input' which formats the string for echoing in form input's value.
23
-     *
24
-     * @param string $value_on_field_to_be_outputted
25
-     * @param string $schema
26
-     * @return string
27
-     */
28
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
29
-    {
30
-        if ($schema === 'form_input') {
31
-            $value_on_field_to_be_outputted = (string)htmlentities(
32
-                $value_on_field_to_be_outputted,
33
-                ENT_QUOTES,
34
-                'UTF-8'
35
-            );
36
-        }
37
-        return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
38
-    }
21
+	/**
22
+	 * Accepts schema of 'form_input' which formats the string for echoing in form input's value.
23
+	 *
24
+	 * @param string $value_on_field_to_be_outputted
25
+	 * @param string $schema
26
+	 * @return string
27
+	 */
28
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
29
+	{
30
+		if ($schema === 'form_input') {
31
+			$value_on_field_to_be_outputted = (string)htmlentities(
32
+				$value_on_field_to_be_outputted,
33
+				ENT_QUOTES,
34
+				'UTF-8'
35
+			);
36
+		}
37
+		return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
38
+	}
39 39
 
40
-    /**
41
-     * Data received from the user should be exactly as they hope to save it in the DB, with the exception that
42
-     * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP
43
-     * in magic-quotes fashion. We used to call html_entity_decode on the value here,
44
-     * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary
45
-     * because web browsers always decode HTML entities in element attributes, like a form element's value attribute.
46
-     * So if we do it again here, we'll be removing HTML entities the user intended to have.)
47
-     *
48
-     * @param string $value_inputted_for_field_on_model_object
49
-     * @return string
50
-     */
51
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
52
-    {
53
-        return stripslashes(parent::prepare_for_set($value_inputted_for_field_on_model_object));
54
-    }
40
+	/**
41
+	 * Data received from the user should be exactly as they hope to save it in the DB, with the exception that
42
+	 * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP
43
+	 * in magic-quotes fashion. We used to call html_entity_decode on the value here,
44
+	 * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary
45
+	 * because web browsers always decode HTML entities in element attributes, like a form element's value attribute.
46
+	 * So if we do it again here, we'll be removing HTML entities the user intended to have.)
47
+	 *
48
+	 * @param string $value_inputted_for_field_on_model_object
49
+	 * @return string
50
+	 */
51
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
52
+	{
53
+		return stripslashes(parent::prepare_for_set($value_inputted_for_field_on_model_object));
54
+	}
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Html_messenger.class.php 1 patch
Indentation   +548 added lines, -548 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (!defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -16,552 +16,552 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * The following are the properties that this messenger requires for displaying the html
21
-     */
22
-    /**
23
-     * This is the html body generated by the template via the message type.
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_content;
28
-
29
-
30
-    /**
31
-     * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
32
-     * equivalent to the "subject" of the page.
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_subject;
37
-
38
-
39
-    /**
40
-     * EE_Html_messenger constructor.
41
-     */
42
-    public function __construct()
43
-    {
44
-        //set properties
45
-        $this->name = 'html';
46
-        $this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
47
-        $this->label = array(
48
-            'singular' => __('html', 'event_espresso'),
49
-            'plural' => __('html', 'event_espresso'),
50
-        );
51
-        $this->activate_on_install = true;
52
-        // add the "powered by EE" credit link to the HTML receipt and invoice
53
-        add_filter(
54
-            'FHEE__EE_Html_messenger___send_message__main_body',
55
-            array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
56
-            10,
57
-            3
58
-        );
59
-        parent::__construct();
60
-    }
61
-
62
-
63
-    /**
64
-     * HTML Messenger desires execution immediately.
65
-     *
66
-     * @see    parent::send_now() for documentation.
67
-     * @since  4.9.0
68
-     * @return bool
69
-     */
70
-    public function send_now()
71
-    {
72
-        return true;
73
-    }
74
-
75
-
76
-    /**
77
-     * HTML Messenger allows an empty to field.
78
-     *
79
-     * @see    parent::allow_empty_to_field() for documentation
80
-     * @since  4.9.0
81
-     * @return bool
82
-     */
83
-    public function allow_empty_to_field()
84
-    {
85
-        return true;
86
-    }
87
-
88
-
89
-    /**
90
-     * @see abstract declaration in EE_messenger for details.
91
-     */
92
-    protected function _set_admin_pages()
93
-    {
94
-        $this->admin_registered_pages = array('events_edit' => true);
95
-    }
96
-
97
-
98
-    /**
99
-     * @see abstract declaration in EE_messenger for details.
100
-     */
101
-    protected function _set_valid_shortcodes()
102
-    {
103
-        $this->_valid_shortcodes = array();
104
-    }
105
-
106
-
107
-    /**
108
-     * @see abstract declaration in EE_messenger for details.
109
-     */
110
-    protected function _set_validator_config()
111
-    {
112
-        $this->_validator_config = array(
113
-            'subject' => array(
114
-                'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
115
-            ),
116
-            'content' => array(
117
-                'shortcodes' => array(
118
-                    'organization',
119
-                    'primary_registration_list',
120
-                    'primary_registration_details',
121
-                    'email',
122
-                    'transaction',
123
-                    'event_list',
124
-                    'payment_list',
125
-                    'venue',
126
-                    'line_item_list',
127
-                    'messenger',
128
-                    'ticket_list',
129
-                ),
130
-            ),
131
-            'event_list' => array(
132
-                'shortcodes' => array(
133
-                    'event',
134
-                    'ticket_list',
135
-                    'venue',
136
-                    'primary_registration_details',
137
-                    'primary_registration_list',
138
-                    'event_author',
139
-                ),
140
-                'required' => array('[EVENT_LIST]'),
141
-            ),
142
-            'ticket_list' => array(
143
-                'shortcodes' => array(
144
-                    'attendee_list',
145
-                    'ticket',
146
-                    'datetime_list',
147
-                    'primary_registration_details',
148
-                    'line_item_list',
149
-                    'venue',
150
-                ),
151
-                'required' => array('[TICKET_LIST]'),
152
-            ),
153
-            'ticket_line_item_no_pms' => array(
154
-                'shortcodes' => array('line_item', 'ticket'),
155
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
-            ),
157
-            'ticket_line_item_pms' => array(
158
-                'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
159
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
160
-            ),
161
-            'price_modifier_line_item_list' => array(
162
-                'shortcodes' => array('line_item'),
163
-                'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
164
-            ),
165
-            'datetime_list' => array(
166
-                'shortcodes' => array('datetime'),
167
-                'required' => array('[DATETIME_LIST]'),
168
-            ),
169
-            'attendee_list' => array(
170
-                'shortcodes' => array('attendee'),
171
-                'required' => array('[ATTENDEE_LIST]'),
172
-            ),
173
-            'tax_line_item_list' => array(
174
-                'shortcodes' => array('line_item'),
175
-                'required' => array('[TAX_LINE_ITEM_LIST]'),
176
-            ),
177
-            'additional_line_item_list' => array(
178
-                'shortcodes' => array('line_item'),
179
-                'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
180
-            ),
181
-            'payment_list' => array(
182
-                'shortcodes' => array('payment'),
183
-                'required' => array('[PAYMENT_LIST_*]'),
184
-            ),
185
-        );
186
-    }
187
-
188
-
189
-    /**
190
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
191
-     * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
192
-     * (i.e. swap out css files or something else).
193
-     *
194
-     * @since 4.5.0
195
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
196
-     * @return void
197
-     */
198
-    public function do_secondary_messenger_hooks($sending_messenger_name)
199
-    {
200
-        if ($sending_messenger_name = 'pdf') {
201
-            add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
202
-        }
203
-    }
204
-
205
-
206
-    /**
207
-     * @param                            $variation_path
208
-     * @param \EE_Messages_Template_Pack $template_pack
209
-     * @param                            $messenger_name
210
-     * @param                            $message_type_name
211
-     * @param                            $url
212
-     * @param                            $type
213
-     * @param                            $variation
214
-     * @param                            $skip_filters
215
-     * @return string
216
-     */
217
-    public function add_html_css(
218
-        $variation_path,
219
-        EE_Messages_Template_Pack $template_pack,
220
-        $messenger_name,
221
-        $message_type_name,
222
-        $url,
223
-        $type,
224
-        $variation,
225
-        $skip_filters
226
-    )
227
-    {
228
-        $variation = $template_pack->get_variation(
229
-            $this->name,
230
-            $message_type_name,
231
-            $type,
232
-            $variation,
233
-            $url,
234
-            '.css',
235
-            $skip_filters
236
-        );
237
-        return $variation;
238
-    }
239
-
240
-
241
-    /**
242
-     * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
243
-     * messenger can add their own js.
244
-     *
245
-     * @return void.
246
-     */
247
-    public function enqueue_scripts_styles()
248
-    {
249
-        parent::enqueue_scripts_styles();
250
-        do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
251
-    }
252
-
253
-
254
-    /**
255
-     * _set_template_fields
256
-     * This sets up the fields that a messenger requires for the message to go out.
257
-     *
258
-     * @access  protected
259
-     * @return void
260
-     */
261
-    protected function _set_template_fields()
262
-    {
263
-        // any extra template fields that are NOT used by the messenger
264
-        // but will get used by a messenger field for shortcode replacement
265
-        // get added to the 'extra' key in an associated array
266
-        // indexed by the messenger field they relate to.
267
-        // This is important for the Messages_admin to know what fields to display to the user.
268
-        // Also, notice that the "values" are equal to the field type
269
-        // that messages admin will use to know what kind of field to display.
270
-        // The values ALSO have one index labeled "shortcode".
271
-        // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
272
-        // is required in order for this extra field to be displayed.
273
-        //  If the required shortcode isn't part of the shortcodes array
274
-        // then the field is not needed and will not be displayed/parsed.
275
-        $this->_template_fields = array(
276
-            'subject' => array(
277
-                'input' => 'text',
278
-                'label' => __('Page Title', 'event_espresso'),
279
-                'type' => 'string',
280
-                'required' => true,
281
-                'validation' => true,
282
-                'css_class' => 'large-text',
283
-                'format' => '%s',
284
-            ),
285
-            'content' => '',
286
-            //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
287
-            'extra' => array(
288
-                'content' => array(
289
-                    'main' => array(
290
-                        'input' => 'wp_editor',
291
-                        'label' => __('Main Content', 'event_espresso'),
292
-                        'type' => 'string',
293
-                        'required' => true,
294
-                        'validation' => true,
295
-                        'format' => '%s',
296
-                        'rows' => '15',
297
-                    ),
298
-                    'event_list' => array(
299
-                        'input' => 'wp_editor',
300
-                        'label' => '[EVENT_LIST]',
301
-                        'type' => 'string',
302
-                        'required' => true,
303
-                        'validation' => true,
304
-                        'format' => '%s',
305
-                        'rows' => '15',
306
-                        'shortcodes_required' => array('[EVENT_LIST]'),
307
-                    ),
308
-                    'ticket_list' => array(
309
-                        'input' => 'textarea',
310
-                        'label' => '[TICKET_LIST]',
311
-                        'type' => 'string',
312
-                        'required' => true,
313
-                        'validation' => true,
314
-                        'format' => '%s',
315
-                        'css_class' => 'large-text',
316
-                        'rows' => '10',
317
-                        'shortcodes_required' => array('[TICKET_LIST]'),
318
-                    ),
319
-                    'ticket_line_item_no_pms' => array(
320
-                        'input' => 'textarea',
321
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
322
-                                'Ticket Line Item List with no Price Modifiers',
323
-                                'event_espresso'
324
-                            ),
325
-                        'type' => 'string',
326
-                        'required' => false,
327
-                        'validation' => true,
328
-                        'format' => '%s',
329
-                        'css_class' => 'large-text',
330
-                        'rows' => '5',
331
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
332
-                    ),
333
-                    'ticket_line_item_pms' => array(
334
-                        'input' => 'textarea',
335
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
336
-                                'Ticket Line Item List with Price Modifiers',
337
-                                'event_espresso'
338
-                            ),
339
-                        'type' => 'string',
340
-                        'required' => false,
341
-                        'validation' => true,
342
-                        'format' => '%s',
343
-                        'css_class' => 'large-text',
344
-                        'rows' => '5',
345
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
346
-                    ),
347
-                    'price_modifier_line_item_list' => array(
348
-                        'input' => 'textarea',
349
-                        'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
350
-                        'type' => 'string',
351
-                        'required' => false,
352
-                        'validation' => true,
353
-                        'format' => '%s',
354
-                        'css_class' => 'large-text',
355
-                        'rows' => '5',
356
-                        'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
357
-                    ),
358
-                    'datetime_list' => array(
359
-                        'input' => 'textarea',
360
-                        'label' => '[DATETIME_LIST]',
361
-                        'type' => 'string',
362
-                        'required' => true,
363
-                        'validation' => true,
364
-                        'format' => '%s',
365
-                        'css_class' => 'large-text',
366
-                        'rows' => '5',
367
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
368
-                    ),
369
-                    'attendee_list' => array(
370
-                        'input' => 'textarea',
371
-                        'label' => '[ATTENDEE_LIST]',
372
-                        'type' => 'string',
373
-                        'required' => true,
374
-                        'validation' => true,
375
-                        'format' => '%s',
376
-                        'css_class' => 'large-text',
377
-                        'rows' => '5',
378
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
379
-                    ),
380
-                    'tax_line_item_list' => array(
381
-                        'input' => 'textarea',
382
-                        'label' => '[TAX_LINE_ITEM_LIST]',
383
-                        'type' => 'string',
384
-                        'required' => false,
385
-                        'validation' => true,
386
-                        'format' => '%s',
387
-                        'css_class' => 'large-text',
388
-                        'rows' => '5',
389
-                        'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
390
-                    ),
391
-                    'additional_line_item_list' => array(
392
-                        'input' => 'textarea',
393
-                        'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
394
-                        'type' => 'string',
395
-                        'required' => false,
396
-                        'validation' => true,
397
-                        'format' => '%s',
398
-                        'css_class' => 'large-text',
399
-                        'rows' => '5',
400
-                        'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
401
-                    ),
402
-                    'payment_list' => array(
403
-                        'input' => 'textarea',
404
-                        'label' => '[PAYMENT_LIST]',
405
-                        'type' => 'string',
406
-                        'required' => true,
407
-                        'validation' => true,
408
-                        'format' => '%s',
409
-                        'css_class' => 'large-text',
410
-                        'rows' => '5',
411
-                        'shortcodes_required' => array('[PAYMENT_LIST_*]'),
412
-                    ),
413
-                ),
414
-            ),
415
-        );
416
-    }
417
-
418
-
419
-    /**
420
-     * @see   definition of this method in parent
421
-     * @since 4.5.0
422
-     */
423
-    protected function _set_default_message_types()
424
-    {
425
-        $this->_default_message_types = array('receipt', 'invoice');
426
-    }
427
-
428
-
429
-    /**
430
-     * @see   definition of this method in parent
431
-     * @since 4.5.0
432
-     */
433
-    protected function _set_valid_message_types()
434
-    {
435
-        $this->_valid_message_types = array('receipt', 'invoice');
436
-    }
437
-
438
-
439
-    /**
440
-     * Displays the message in the browser.
441
-     *
442
-     * @since 4.5.0
443
-     * @return string.
444
-     */
445
-    protected function _send_message()
446
-    {
447
-        $this->_template_args = array(
448
-            'page_title' => $this->_subject,
449
-            'base_css' => $this->get_variation(
450
-                $this->_tmp_pack,
451
-                $this->_incoming_message_type->name,
452
-                true,
453
-                'base',
454
-                $this->_variation
455
-            ),
456
-            'print_css' => $this->get_variation(
457
-                $this->_tmp_pack,
458
-                $this->_incoming_message_type->name,
459
-                true,
460
-                'print',
461
-                $this->_variation
462
-            ),
463
-            'main_css' => $this->get_variation(
464
-                $this->_tmp_pack,
465
-                $this->_incoming_message_type->name,
466
-                true,
467
-                'main',
468
-                $this->_variation
469
-            ),
470
-            'main_body' => wpautop(
471
-                apply_filters(
472
-                    'FHEE__EE_Html_messenger___send_message__main_body',
473
-                    $this->_content,
474
-                    $this->_content,
475
-                    $this->_incoming_message_type
476
-                )
477
-            )
478
-        );
479
-        $this->_deregister_wp_hooks();
480
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
481
-        echo $this->_get_main_template();
482
-        exit();
483
-    }
484
-
485
-
486
-    /**
487
-     * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
488
-     * interfere with our templates.  If users want to add any custom styles or scripts they must use the
489
-     * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
490
-     *
491
-     * @since 4.5.0
492
-     * @return void
493
-     */
494
-    protected function _deregister_wp_hooks()
495
-    {
496
-        remove_all_actions('wp_head');
497
-        remove_all_actions('wp_footer');
498
-        remove_all_actions('wp_print_footer_scripts');
499
-        remove_all_actions('wp_enqueue_scripts');
500
-        global $wp_scripts, $wp_styles;
501
-        $wp_scripts = $wp_styles = array();
502
-        //just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
503
-        add_action('wp_footer', 'wp_print_footer_scripts');
504
-        add_action('wp_print_footer_scripts', '_wp_footer_scripts');
505
-        add_action('wp_head', 'wp_enqueue_scripts');
506
-    }
507
-
508
-
509
-    /**
510
-     * Overwrite parent _get_main_template for display_html purposes.
511
-     *
512
-     * @since  4.5.0
513
-     * @param bool $preview
514
-     * @return string
515
-     */
516
-    protected function _get_main_template($preview = false)
517
-    {
518
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
519
-        //include message type as a template arg
520
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
521
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
522
-    }
523
-
524
-
525
-    /**
526
-     * @return string
527
-     */
528
-    protected function _preview()
529
-    {
530
-        return $this->_send_message();
531
-    }
532
-
533
-
534
-    protected function _set_admin_settings_fields()
535
-    {
536
-    }
537
-
538
-
539
-    /**
540
-     * add the "powered by EE" credit link to the HTML receipt and invoice
541
-     *
542
-     * @param string $content
543
-     * @param string $content_again
544
-     * @param \EE_message_type $incoming_message_type
545
-     * @return string
546
-     */
547
-    public function add_powered_by_credit_link_to_receipt_and_invoice(
548
-        $content = '',
549
-        $content_again = '',
550
-        EE_message_type $incoming_message_type
551
-    )
552
-    {
553
-        if (
554
-            ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
555
-            && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
556
-        ) {
557
-            $content .= \EEH_Template::powered_by_event_espresso(
558
-                    'aln-cntr',
559
-                    '',
560
-                    array('utm_content' => 'messages_system')
561
-                )
562
-                . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
563
-        }
564
-        return $content;
565
-    }
19
+	/**
20
+	 * The following are the properties that this messenger requires for displaying the html
21
+	 */
22
+	/**
23
+	 * This is the html body generated by the template via the message type.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_content;
28
+
29
+
30
+	/**
31
+	 * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
32
+	 * equivalent to the "subject" of the page.
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_subject;
37
+
38
+
39
+	/**
40
+	 * EE_Html_messenger constructor.
41
+	 */
42
+	public function __construct()
43
+	{
44
+		//set properties
45
+		$this->name = 'html';
46
+		$this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
47
+		$this->label = array(
48
+			'singular' => __('html', 'event_espresso'),
49
+			'plural' => __('html', 'event_espresso'),
50
+		);
51
+		$this->activate_on_install = true;
52
+		// add the "powered by EE" credit link to the HTML receipt and invoice
53
+		add_filter(
54
+			'FHEE__EE_Html_messenger___send_message__main_body',
55
+			array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
56
+			10,
57
+			3
58
+		);
59
+		parent::__construct();
60
+	}
61
+
62
+
63
+	/**
64
+	 * HTML Messenger desires execution immediately.
65
+	 *
66
+	 * @see    parent::send_now() for documentation.
67
+	 * @since  4.9.0
68
+	 * @return bool
69
+	 */
70
+	public function send_now()
71
+	{
72
+		return true;
73
+	}
74
+
75
+
76
+	/**
77
+	 * HTML Messenger allows an empty to field.
78
+	 *
79
+	 * @see    parent::allow_empty_to_field() for documentation
80
+	 * @since  4.9.0
81
+	 * @return bool
82
+	 */
83
+	public function allow_empty_to_field()
84
+	{
85
+		return true;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @see abstract declaration in EE_messenger for details.
91
+	 */
92
+	protected function _set_admin_pages()
93
+	{
94
+		$this->admin_registered_pages = array('events_edit' => true);
95
+	}
96
+
97
+
98
+	/**
99
+	 * @see abstract declaration in EE_messenger for details.
100
+	 */
101
+	protected function _set_valid_shortcodes()
102
+	{
103
+		$this->_valid_shortcodes = array();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @see abstract declaration in EE_messenger for details.
109
+	 */
110
+	protected function _set_validator_config()
111
+	{
112
+		$this->_validator_config = array(
113
+			'subject' => array(
114
+				'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
115
+			),
116
+			'content' => array(
117
+				'shortcodes' => array(
118
+					'organization',
119
+					'primary_registration_list',
120
+					'primary_registration_details',
121
+					'email',
122
+					'transaction',
123
+					'event_list',
124
+					'payment_list',
125
+					'venue',
126
+					'line_item_list',
127
+					'messenger',
128
+					'ticket_list',
129
+				),
130
+			),
131
+			'event_list' => array(
132
+				'shortcodes' => array(
133
+					'event',
134
+					'ticket_list',
135
+					'venue',
136
+					'primary_registration_details',
137
+					'primary_registration_list',
138
+					'event_author',
139
+				),
140
+				'required' => array('[EVENT_LIST]'),
141
+			),
142
+			'ticket_list' => array(
143
+				'shortcodes' => array(
144
+					'attendee_list',
145
+					'ticket',
146
+					'datetime_list',
147
+					'primary_registration_details',
148
+					'line_item_list',
149
+					'venue',
150
+				),
151
+				'required' => array('[TICKET_LIST]'),
152
+			),
153
+			'ticket_line_item_no_pms' => array(
154
+				'shortcodes' => array('line_item', 'ticket'),
155
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
+			),
157
+			'ticket_line_item_pms' => array(
158
+				'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
159
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
160
+			),
161
+			'price_modifier_line_item_list' => array(
162
+				'shortcodes' => array('line_item'),
163
+				'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
164
+			),
165
+			'datetime_list' => array(
166
+				'shortcodes' => array('datetime'),
167
+				'required' => array('[DATETIME_LIST]'),
168
+			),
169
+			'attendee_list' => array(
170
+				'shortcodes' => array('attendee'),
171
+				'required' => array('[ATTENDEE_LIST]'),
172
+			),
173
+			'tax_line_item_list' => array(
174
+				'shortcodes' => array('line_item'),
175
+				'required' => array('[TAX_LINE_ITEM_LIST]'),
176
+			),
177
+			'additional_line_item_list' => array(
178
+				'shortcodes' => array('line_item'),
179
+				'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
180
+			),
181
+			'payment_list' => array(
182
+				'shortcodes' => array('payment'),
183
+				'required' => array('[PAYMENT_LIST_*]'),
184
+			),
185
+		);
186
+	}
187
+
188
+
189
+	/**
190
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
191
+	 * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
192
+	 * (i.e. swap out css files or something else).
193
+	 *
194
+	 * @since 4.5.0
195
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
196
+	 * @return void
197
+	 */
198
+	public function do_secondary_messenger_hooks($sending_messenger_name)
199
+	{
200
+		if ($sending_messenger_name = 'pdf') {
201
+			add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
202
+		}
203
+	}
204
+
205
+
206
+	/**
207
+	 * @param                            $variation_path
208
+	 * @param \EE_Messages_Template_Pack $template_pack
209
+	 * @param                            $messenger_name
210
+	 * @param                            $message_type_name
211
+	 * @param                            $url
212
+	 * @param                            $type
213
+	 * @param                            $variation
214
+	 * @param                            $skip_filters
215
+	 * @return string
216
+	 */
217
+	public function add_html_css(
218
+		$variation_path,
219
+		EE_Messages_Template_Pack $template_pack,
220
+		$messenger_name,
221
+		$message_type_name,
222
+		$url,
223
+		$type,
224
+		$variation,
225
+		$skip_filters
226
+	)
227
+	{
228
+		$variation = $template_pack->get_variation(
229
+			$this->name,
230
+			$message_type_name,
231
+			$type,
232
+			$variation,
233
+			$url,
234
+			'.css',
235
+			$skip_filters
236
+		);
237
+		return $variation;
238
+	}
239
+
240
+
241
+	/**
242
+	 * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
243
+	 * messenger can add their own js.
244
+	 *
245
+	 * @return void.
246
+	 */
247
+	public function enqueue_scripts_styles()
248
+	{
249
+		parent::enqueue_scripts_styles();
250
+		do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
251
+	}
252
+
253
+
254
+	/**
255
+	 * _set_template_fields
256
+	 * This sets up the fields that a messenger requires for the message to go out.
257
+	 *
258
+	 * @access  protected
259
+	 * @return void
260
+	 */
261
+	protected function _set_template_fields()
262
+	{
263
+		// any extra template fields that are NOT used by the messenger
264
+		// but will get used by a messenger field for shortcode replacement
265
+		// get added to the 'extra' key in an associated array
266
+		// indexed by the messenger field they relate to.
267
+		// This is important for the Messages_admin to know what fields to display to the user.
268
+		// Also, notice that the "values" are equal to the field type
269
+		// that messages admin will use to know what kind of field to display.
270
+		// The values ALSO have one index labeled "shortcode".
271
+		// The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
272
+		// is required in order for this extra field to be displayed.
273
+		//  If the required shortcode isn't part of the shortcodes array
274
+		// then the field is not needed and will not be displayed/parsed.
275
+		$this->_template_fields = array(
276
+			'subject' => array(
277
+				'input' => 'text',
278
+				'label' => __('Page Title', 'event_espresso'),
279
+				'type' => 'string',
280
+				'required' => true,
281
+				'validation' => true,
282
+				'css_class' => 'large-text',
283
+				'format' => '%s',
284
+			),
285
+			'content' => '',
286
+			//left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
287
+			'extra' => array(
288
+				'content' => array(
289
+					'main' => array(
290
+						'input' => 'wp_editor',
291
+						'label' => __('Main Content', 'event_espresso'),
292
+						'type' => 'string',
293
+						'required' => true,
294
+						'validation' => true,
295
+						'format' => '%s',
296
+						'rows' => '15',
297
+					),
298
+					'event_list' => array(
299
+						'input' => 'wp_editor',
300
+						'label' => '[EVENT_LIST]',
301
+						'type' => 'string',
302
+						'required' => true,
303
+						'validation' => true,
304
+						'format' => '%s',
305
+						'rows' => '15',
306
+						'shortcodes_required' => array('[EVENT_LIST]'),
307
+					),
308
+					'ticket_list' => array(
309
+						'input' => 'textarea',
310
+						'label' => '[TICKET_LIST]',
311
+						'type' => 'string',
312
+						'required' => true,
313
+						'validation' => true,
314
+						'format' => '%s',
315
+						'css_class' => 'large-text',
316
+						'rows' => '10',
317
+						'shortcodes_required' => array('[TICKET_LIST]'),
318
+					),
319
+					'ticket_line_item_no_pms' => array(
320
+						'input' => 'textarea',
321
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
322
+								'Ticket Line Item List with no Price Modifiers',
323
+								'event_espresso'
324
+							),
325
+						'type' => 'string',
326
+						'required' => false,
327
+						'validation' => true,
328
+						'format' => '%s',
329
+						'css_class' => 'large-text',
330
+						'rows' => '5',
331
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
332
+					),
333
+					'ticket_line_item_pms' => array(
334
+						'input' => 'textarea',
335
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
336
+								'Ticket Line Item List with Price Modifiers',
337
+								'event_espresso'
338
+							),
339
+						'type' => 'string',
340
+						'required' => false,
341
+						'validation' => true,
342
+						'format' => '%s',
343
+						'css_class' => 'large-text',
344
+						'rows' => '5',
345
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
346
+					),
347
+					'price_modifier_line_item_list' => array(
348
+						'input' => 'textarea',
349
+						'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
350
+						'type' => 'string',
351
+						'required' => false,
352
+						'validation' => true,
353
+						'format' => '%s',
354
+						'css_class' => 'large-text',
355
+						'rows' => '5',
356
+						'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
357
+					),
358
+					'datetime_list' => array(
359
+						'input' => 'textarea',
360
+						'label' => '[DATETIME_LIST]',
361
+						'type' => 'string',
362
+						'required' => true,
363
+						'validation' => true,
364
+						'format' => '%s',
365
+						'css_class' => 'large-text',
366
+						'rows' => '5',
367
+						'shortcodes_required' => array('[DATETIME_LIST]'),
368
+					),
369
+					'attendee_list' => array(
370
+						'input' => 'textarea',
371
+						'label' => '[ATTENDEE_LIST]',
372
+						'type' => 'string',
373
+						'required' => true,
374
+						'validation' => true,
375
+						'format' => '%s',
376
+						'css_class' => 'large-text',
377
+						'rows' => '5',
378
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
379
+					),
380
+					'tax_line_item_list' => array(
381
+						'input' => 'textarea',
382
+						'label' => '[TAX_LINE_ITEM_LIST]',
383
+						'type' => 'string',
384
+						'required' => false,
385
+						'validation' => true,
386
+						'format' => '%s',
387
+						'css_class' => 'large-text',
388
+						'rows' => '5',
389
+						'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
390
+					),
391
+					'additional_line_item_list' => array(
392
+						'input' => 'textarea',
393
+						'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
394
+						'type' => 'string',
395
+						'required' => false,
396
+						'validation' => true,
397
+						'format' => '%s',
398
+						'css_class' => 'large-text',
399
+						'rows' => '5',
400
+						'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
401
+					),
402
+					'payment_list' => array(
403
+						'input' => 'textarea',
404
+						'label' => '[PAYMENT_LIST]',
405
+						'type' => 'string',
406
+						'required' => true,
407
+						'validation' => true,
408
+						'format' => '%s',
409
+						'css_class' => 'large-text',
410
+						'rows' => '5',
411
+						'shortcodes_required' => array('[PAYMENT_LIST_*]'),
412
+					),
413
+				),
414
+			),
415
+		);
416
+	}
417
+
418
+
419
+	/**
420
+	 * @see   definition of this method in parent
421
+	 * @since 4.5.0
422
+	 */
423
+	protected function _set_default_message_types()
424
+	{
425
+		$this->_default_message_types = array('receipt', 'invoice');
426
+	}
427
+
428
+
429
+	/**
430
+	 * @see   definition of this method in parent
431
+	 * @since 4.5.0
432
+	 */
433
+	protected function _set_valid_message_types()
434
+	{
435
+		$this->_valid_message_types = array('receipt', 'invoice');
436
+	}
437
+
438
+
439
+	/**
440
+	 * Displays the message in the browser.
441
+	 *
442
+	 * @since 4.5.0
443
+	 * @return string.
444
+	 */
445
+	protected function _send_message()
446
+	{
447
+		$this->_template_args = array(
448
+			'page_title' => $this->_subject,
449
+			'base_css' => $this->get_variation(
450
+				$this->_tmp_pack,
451
+				$this->_incoming_message_type->name,
452
+				true,
453
+				'base',
454
+				$this->_variation
455
+			),
456
+			'print_css' => $this->get_variation(
457
+				$this->_tmp_pack,
458
+				$this->_incoming_message_type->name,
459
+				true,
460
+				'print',
461
+				$this->_variation
462
+			),
463
+			'main_css' => $this->get_variation(
464
+				$this->_tmp_pack,
465
+				$this->_incoming_message_type->name,
466
+				true,
467
+				'main',
468
+				$this->_variation
469
+			),
470
+			'main_body' => wpautop(
471
+				apply_filters(
472
+					'FHEE__EE_Html_messenger___send_message__main_body',
473
+					$this->_content,
474
+					$this->_content,
475
+					$this->_incoming_message_type
476
+				)
477
+			)
478
+		);
479
+		$this->_deregister_wp_hooks();
480
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
481
+		echo $this->_get_main_template();
482
+		exit();
483
+	}
484
+
485
+
486
+	/**
487
+	 * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
488
+	 * interfere with our templates.  If users want to add any custom styles or scripts they must use the
489
+	 * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
490
+	 *
491
+	 * @since 4.5.0
492
+	 * @return void
493
+	 */
494
+	protected function _deregister_wp_hooks()
495
+	{
496
+		remove_all_actions('wp_head');
497
+		remove_all_actions('wp_footer');
498
+		remove_all_actions('wp_print_footer_scripts');
499
+		remove_all_actions('wp_enqueue_scripts');
500
+		global $wp_scripts, $wp_styles;
501
+		$wp_scripts = $wp_styles = array();
502
+		//just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
503
+		add_action('wp_footer', 'wp_print_footer_scripts');
504
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
505
+		add_action('wp_head', 'wp_enqueue_scripts');
506
+	}
507
+
508
+
509
+	/**
510
+	 * Overwrite parent _get_main_template for display_html purposes.
511
+	 *
512
+	 * @since  4.5.0
513
+	 * @param bool $preview
514
+	 * @return string
515
+	 */
516
+	protected function _get_main_template($preview = false)
517
+	{
518
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
519
+		//include message type as a template arg
520
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
521
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
522
+	}
523
+
524
+
525
+	/**
526
+	 * @return string
527
+	 */
528
+	protected function _preview()
529
+	{
530
+		return $this->_send_message();
531
+	}
532
+
533
+
534
+	protected function _set_admin_settings_fields()
535
+	{
536
+	}
537
+
538
+
539
+	/**
540
+	 * add the "powered by EE" credit link to the HTML receipt and invoice
541
+	 *
542
+	 * @param string $content
543
+	 * @param string $content_again
544
+	 * @param \EE_message_type $incoming_message_type
545
+	 * @return string
546
+	 */
547
+	public function add_powered_by_credit_link_to_receipt_and_invoice(
548
+		$content = '',
549
+		$content_again = '',
550
+		EE_message_type $incoming_message_type
551
+	)
552
+	{
553
+		if (
554
+			($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
555
+			&& apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
556
+		) {
557
+			$content .= \EEH_Template::powered_by_event_espresso(
558
+					'aln-cntr',
559
+					'',
560
+					array('utm_content' => 'messages_system')
561
+				)
562
+				. EEH_HTML::div(EEH_HTML::p('&nbsp;'));
563
+		}
564
+		return $content;
565
+	}
566 566
 
567 567
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 2 patches
Indentation   +637 added lines, -637 removed lines patch added patch discarded remove patch
@@ -8,641 +8,641 @@
 block discarded – undo
8 8
 class EE_Email_messenger extends EE_messenger
9 9
 {
10 10
 
11
-    /**
12
-     * To field for email
13
-     * @var string
14
-     */
15
-    protected $_to = '';
16
-
17
-
18
-    /**
19
-     * CC field for email.
20
-     * @var string
21
-     */
22
-    protected $_cc = '';
23
-
24
-    /**
25
-     * From field for email
26
-     * @var string
27
-     */
28
-    protected $_from = '';
29
-
30
-
31
-    /**
32
-     * Subject field for email
33
-     * @var string
34
-     */
35
-    protected $_subject = '';
36
-
37
-
38
-    /**
39
-     * Content field for email
40
-     * @var string
41
-     */
42
-    protected $_content = '';
43
-
44
-
45
-    /**
46
-     * constructor
47
-     *
48
-     * @access public
49
-     */
50
-    public function __construct()
51
-    {
52
-        //set name and description properties
53
-        $this->name                = 'email';
54
-        $this->description         = sprintf(
55
-            esc_html__(
56
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
57
-                'event_espresso'
58
-            ),
59
-            '<code>wp_mail</code>'
60
-        );
61
-        $this->label               = array(
62
-            'singular' => esc_html__('email', 'event_espresso'),
63
-            'plural'   => esc_html__('emails', 'event_espresso'),
64
-        );
65
-        $this->activate_on_install = true;
66
-
67
-        //we're using defaults so let's call parent constructor that will take care of setting up all the other
68
-        // properties
69
-        parent::__construct();
70
-    }
71
-
72
-
73
-    /**
74
-     * see abstract declaration in parent class for details.
75
-     */
76
-    protected function _set_admin_pages()
77
-    {
78
-        $this->admin_registered_pages = array(
79
-            'events_edit' => true,
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * see abstract declaration in parent class for details
86
-     */
87
-    protected function _set_valid_shortcodes()
88
-    {
89
-        //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
90
-        // message type.
91
-        $this->_valid_shortcodes = array(
92
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
94
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
95
-        );
96
-    }
97
-
98
-
99
-    /**
100
-     * see abstract declaration in parent class for details
101
-     *
102
-     * @access protected
103
-     * @return void
104
-     */
105
-    protected function _set_validator_config()
106
-    {
107
-        $valid_shortcodes = $this->get_valid_shortcodes();
108
-
109
-        $this->_validator_config = array(
110
-            'to'            => array(
111
-                'shortcodes' => $valid_shortcodes['to'],
112
-                'type'       => 'email',
113
-            ),
114
-            'cc' => array(
115
-                'shortcodes' => $valid_shortcodes['to'],
116
-                'type' => 'email',
117
-            ),
118
-            'from'          => array(
119
-                'shortcodes' => $valid_shortcodes['from'],
120
-                'type'       => 'email',
121
-            ),
122
-            'subject'       => array(
123
-                'shortcodes' => array(
124
-                    'organization',
125
-                    'primary_registration_details',
126
-                    'event_author',
127
-                    'primary_registration_details',
128
-                    'recipient_details',
129
-                ),
130
-            ),
131
-            'content'       => array(
132
-                'shortcodes' => array(
133
-                    'event_list',
134
-                    'attendee_list',
135
-                    'ticket_list',
136
-                    'organization',
137
-                    'primary_registration_details',
138
-                    'primary_registration_list',
139
-                    'event_author',
140
-                    'recipient_details',
141
-                    'recipient_list',
142
-                    'transaction',
143
-                    'messenger',
144
-                ),
145
-            ),
146
-            'attendee_list' => array(
147
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
148
-                'required'   => array('[ATTENDEE_LIST]'),
149
-            ),
150
-            'event_list'    => array(
151
-                'shortcodes' => array(
152
-                    'event',
153
-                    'attendee_list',
154
-                    'ticket_list',
155
-                    'venue',
156
-                    'datetime_list',
157
-                    'attendee',
158
-                    'primary_registration_details',
159
-                    'primary_registration_list',
160
-                    'event_author',
161
-                    'recipient_details',
162
-                    'recipient_list',
163
-                ),
164
-                'required'   => array('[EVENT_LIST]'),
165
-            ),
166
-            'ticket_list'   => array(
167
-                'shortcodes' => array(
168
-                    'event_list',
169
-                    'attendee_list',
170
-                    'ticket',
171
-                    'datetime_list',
172
-                    'primary_registration_details',
173
-                    'recipient_details',
174
-                ),
175
-                'required'   => array('[TICKET_LIST]'),
176
-            ),
177
-            'datetime_list' => array(
178
-                'shortcodes' => array('datetime'),
179
-                'required'   => array('[DATETIME_LIST]'),
180
-            ),
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * @see   parent EE_messenger class for docs
187
-     * @since 4.5.0
188
-     */
189
-    public function do_secondary_messenger_hooks($sending_messenger_name)
190
-    {
191
-        if ($sending_messenger_name = 'html') {
192
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
193
-        }
194
-    }
195
-
196
-
197
-    public function add_email_css(
198
-        $variation_path,
199
-        $messenger,
200
-        $message_type,
201
-        $type,
202
-        $variation,
203
-        $file_extension,
204
-        $url,
205
-        EE_Messages_Template_Pack $template_pack
206
-    ) {
207
-        //prevent recursion on this callback.
208
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
209
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
210
-
211
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
212
-        return $variation;
213
-    }
214
-
215
-
216
-    /**
217
-     * See parent for details
218
-     *
219
-     * @access protected
220
-     * @return void
221
-     */
222
-    protected function _set_test_settings_fields()
223
-    {
224
-        $this->_test_settings_fields = array(
225
-            'to'      => array(
226
-                'input'      => 'text',
227
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
228
-                'type'       => 'email',
229
-                'required'   => true,
230
-                'validation' => true,
231
-                'css_class'  => 'large-text',
232
-                'format'     => '%s',
233
-                'default'    => get_bloginfo('admin_email'),
234
-            ),
235
-            'subject' => array(
236
-                'input'      => 'hidden',
237
-                'label'      => '',
238
-                'type'       => 'string',
239
-                'required'   => false,
240
-                'validation' => false,
241
-                'format'     => '%s',
242
-                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
243
-                'default'    => '',
244
-                'css_class'  => '',
245
-            ),
246
-        );
247
-    }
248
-
249
-
250
-    /**
251
-     * _set_template_fields
252
-     * This sets up the fields that a messenger requires for the message to go out.
253
-     *
254
-     * @access  protected
255
-     * @return void
256
-     */
257
-    protected function _set_template_fields()
258
-    {
259
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
260
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
261
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
262
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
263
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
264
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
265
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
266
-        // will not be displayed/parsed.
267
-        $this->_template_fields = array(
268
-            'to'      => array(
269
-                'input'      => 'text',
270
-                'label'      => esc_html_x(
271
-                    'To',
272
-                    'Label for the "To" field for email addresses',
273
-                    'event_espresso'
274
-                ),
275
-                'type'       => 'string',
276
-                'required'   => true,
277
-                'validation' => true,
278
-                'css_class'  => 'large-text',
279
-                'format'     => '%s',
280
-            ),
281
-            'cc'      => array(
282
-                'input'      => 'text',
283
-                'label'      => esc_html_x(
284
-                    'CC',
285
-                    'Label for the "Carbon Copy" field used for additional email addresses',
286
-                    'event_espresso'
287
-                ),
288
-                'type'       => 'string',
289
-                'required'   => false,
290
-                'validation' => true,
291
-                'css_class'  => 'large-text',
292
-                'format'     => '%s',
293
-            ),
294
-            'from'    => array(
295
-                'input'      => 'text',
296
-                'label'      => esc_html_x(
297
-                    'From',
298
-                    'Label for the "From" field for email addresses.',
299
-                    'event_espresso'
300
-                ),
301
-                'type'       => 'string',
302
-                'required'   => true,
303
-                'validation' => true,
304
-                'css_class'  => 'large-text',
305
-                'format'     => '%s',
306
-            ),
307
-            'subject' => array(
308
-                'input'      => 'text',
309
-                'label'      => esc_html_x(
310
-                    'Subject',
311
-                    'Label for the "Subject" field (short description of contents) for emails.',
312
-                    'event_espresso'
313
-                ),
314
-                'type'       => 'string',
315
-                'required'   => true,
316
-                'validation' => true,
317
-                'css_class'  => 'large-text',
318
-                'format'     => '%s',
319
-            ),
320
-            'content' => '',
321
-            //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
322
-            'extra'   => array(
323
-                'content' => array(
324
-                    'main'          => array(
325
-                        'input'      => 'wp_editor',
326
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
327
-                        'type'       => 'string',
328
-                        'required'   => true,
329
-                        'validation' => true,
330
-                        'format'     => '%s',
331
-                        'rows'       => '15',
332
-                    ),
333
-                    'event_list'    => array(
334
-                        'input'               => 'wp_editor',
335
-                        'label'               => '[EVENT_LIST]',
336
-                        'type'                => 'string',
337
-                        'required'            => true,
338
-                        'validation'          => true,
339
-                        'format'              => '%s',
340
-                        'rows'                => '15',
341
-                        'shortcodes_required' => array('[EVENT_LIST]'),
342
-                    ),
343
-                    'attendee_list' => array(
344
-                        'input'               => 'textarea',
345
-                        'label'               => '[ATTENDEE_LIST]',
346
-                        'type'                => 'string',
347
-                        'required'            => true,
348
-                        'validation'          => true,
349
-                        'format'              => '%s',
350
-                        'css_class'           => 'large-text',
351
-                        'rows'                => '5',
352
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
353
-                    ),
354
-                    'ticket_list'   => array(
355
-                        'input'               => 'textarea',
356
-                        'label'               => '[TICKET_LIST]',
357
-                        'type'                => 'string',
358
-                        'required'            => true,
359
-                        'validation'          => true,
360
-                        'format'              => '%s',
361
-                        'css_class'           => 'large-text',
362
-                        'rows'                => '10',
363
-                        'shortcodes_required' => array('[TICKET_LIST]'),
364
-                    ),
365
-                    'datetime_list' => array(
366
-                        'input'               => 'textarea',
367
-                        'label'               => '[DATETIME_LIST]',
368
-                        'type'                => 'string',
369
-                        'required'            => true,
370
-                        'validation'          => true,
371
-                        'format'              => '%s',
372
-                        'css_class'           => 'large-text',
373
-                        'rows'                => '10',
374
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
375
-                    ),
376
-                ),
377
-            ),
378
-        );
379
-    }
380
-
381
-
382
-    /**
383
-     * See definition of this class in parent
384
-     */
385
-    protected function _set_default_message_types()
386
-    {
387
-        $this->_default_message_types = array(
388
-            'payment',
389
-            'payment_refund',
390
-            'registration',
391
-            'not_approved_registration',
392
-            'pending_approval',
393
-        );
394
-    }
395
-
396
-
397
-    /**
398
-     * @see   definition of this class in parent
399
-     * @since 4.5.0
400
-     */
401
-    protected function _set_valid_message_types()
402
-    {
403
-        $this->_valid_message_types = array(
404
-            'payment',
405
-            'registration',
406
-            'not_approved_registration',
407
-            'declined_registration',
408
-            'cancelled_registration',
409
-            'pending_approval',
410
-            'registration_summary',
411
-            'payment_reminder',
412
-            'payment_declined',
413
-            'payment_refund',
414
-        );
415
-    }
416
-
417
-
418
-    /**
419
-     * setting up admin_settings_fields for messenger.
420
-     */
421
-    protected function _set_admin_settings_fields()
422
-    {
423
-    }
424
-
425
-    /**
426
-     * We just deliver the messages don't kill us!!
427
-     *
428
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
429
-     *              present.
430
-     * @throws EE_Error
431
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
432
-     */
433
-    protected function _send_message()
434
-    {
435
-        $success = wp_mail(
436
-            $this->_to,
437
-            $this->_subject,
438
-            $this->_body(),
439
-            $this->_headers()
440
-        );
441
-        if (! $success) {
442
-            EE_Error::add_error(
443
-                sprintf(
444
-                    esc_html__(
445
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
-                        'event_espresso'
447
-                    ),
448
-                    $this->_to,
449
-                    $this->_from,
450
-                    '<br />'
451
-                ),
452
-                __FILE__,
453
-                __FUNCTION__,
454
-                __LINE__
455
-            );
456
-        }
457
-        return $success;
458
-    }
459
-
460
-
461
-    /**
462
-     * see parent for definition
463
-     *
464
-     * @return string html body of the message content and the related css.
465
-     * @throws EE_Error
466
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
-     */
468
-    protected function _preview()
469
-    {
470
-        return $this->_body(true);
471
-    }
472
-
473
-
474
-    /**
475
-     * Setup headers for email
476
-     *
477
-     * @access protected
478
-     * @return string formatted header for email
479
-     */
480
-    protected function _headers()
481
-    {
482
-        $this->_ensure_has_from_email_address();
483
-        $from    = $this->_from;
484
-        $headers = array(
485
-            'From:' . $from,
486
-            'Reply-To:' . $from,
487
-            'Content-Type:text/html; charset=utf-8',
488
-        );
489
-
490
-        if (! empty($this->_cc)) {
491
-            $headers[] = 'cc: ' . $this->_cc;
492
-        }
493
-
494
-        //but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
495
-        // header.
496
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
497
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
498
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
499
-    }
500
-
501
-
502
-    /**
503
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
504
-     * address for the from address to avoid problems with sending emails.
505
-     */
506
-    protected function _ensure_has_from_email_address()
507
-    {
508
-        if (empty($this->_from)) {
509
-            $this->_from = get_bloginfo('admin_email');
510
-        }
511
-    }
512
-
513
-
514
-    /**
515
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
516
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
517
-     * be empty
518
-     *
519
-     * @since 4.3.1
520
-     * @return array
521
-     */
522
-    private function _parse_from()
523
-    {
524
-        if (strpos($this->_from, '<') !== false) {
525
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
526
-            $from_name = str_replace('"', '', $from_name);
527
-            $from_name = trim($from_name);
528
-
529
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
530
-            $from_email = str_replace('>', '', $from_email);
531
-            $from_email = trim($from_email);
532
-        } elseif (trim($this->_from) !== '') {
533
-            $from_name  = '';
534
-            $from_email = trim($this->_from);
535
-        } else {
536
-            $from_name = $from_email = '';
537
-        }
538
-        return array($from_name, $from_email);
539
-    }
540
-
541
-
542
-    /**
543
-     * Callback for the wp_mail_from filter.
544
-     *
545
-     * @since 4.3.1
546
-     * @param string $from_email What the original from_email is.
547
-     * @return string
548
-     */
549
-    public function set_from_address($from_email)
550
-    {
551
-        $parsed_from = $this->_parse_from();
552
-        //includes fallback if the parsing failed.
553
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
554
-            ? $parsed_from[1]
555
-            : get_bloginfo('admin_email');
556
-        return $from_email;
557
-    }
558
-
559
-
560
-    /**
561
-     * Callback fro the wp_mail_from_name filter.
562
-     *
563
-     * @since 4.3.1
564
-     * @param string $from_name The original from_name.
565
-     * @return string
566
-     */
567
-    public function set_from_name($from_name)
568
-    {
569
-        $parsed_from = $this->_parse_from();
570
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
571
-            $from_name = $parsed_from[0];
572
-        }
573
-
574
-        //if from name is "WordPress" let's sub in the site name instead (more friendly!)
575
-        $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;
576
-
577
-        return $from_name;
578
-    }
579
-
580
-
581
-    /**
582
-     * setup body for email
583
-     *
584
-     * @param bool $preview will determine whether this is preview template or not.
585
-     * @return string formatted body for email.
586
-     * @throws EE_Error
587
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
588
-     */
589
-    protected function _body($preview = false)
590
-    {
591
-        //setup template args!
592
-        $this->_template_args = array(
593
-            'subject'   => $this->_subject,
594
-            'from'      => $this->_from,
595
-            'main_body' => wpautop($this->_content),
596
-        );
597
-        $body                 = $this->_get_main_template($preview);
598
-
599
-        /**
600
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
601
-         *
602
-         * @type    bool $preview Indicates whether a preview is being generated or not.
603
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
604
-         */
605
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
606
-            //require CssToInlineStyles library and its dependencies via composer autoloader
607
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
608
-
609
-            //now if this isn't a preview, let's setup the body so it has inline styles
610
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
611
-                $style = file_get_contents(
612
-                    $this->get_variation(
613
-                        $this->_tmp_pack,
614
-                        $this->_incoming_message_type->name,
615
-                        false,
616
-                        'main',
617
-                        $this->_variation
618
-                    ),
619
-                    true
620
-                );
621
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
622
-                //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
623
-                $body  = ltrim($CSS->convert(true), ">\n");
624
-                //see https://events.codebasehq.com/projects/event-espresso/tickets/8609
625
-                $body  = ltrim($body, "<?");
626
-            }
627
-
628
-        }
629
-        return $body;
630
-    }
631
-
632
-
633
-    /**
634
-     * This just returns any existing test settings that might be saved in the database
635
-     *
636
-     * @access public
637
-     * @return array
638
-     */
639
-    public function get_existing_test_settings()
640
-    {
641
-        $settings = parent::get_existing_test_settings();
642
-        //override subject if present because we always want it to be fresh.
643
-        if (is_array($settings) && ! empty($settings['subject'])) {
644
-            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
645
-        }
646
-        return $settings;
647
-    }
11
+	/**
12
+	 * To field for email
13
+	 * @var string
14
+	 */
15
+	protected $_to = '';
16
+
17
+
18
+	/**
19
+	 * CC field for email.
20
+	 * @var string
21
+	 */
22
+	protected $_cc = '';
23
+
24
+	/**
25
+	 * From field for email
26
+	 * @var string
27
+	 */
28
+	protected $_from = '';
29
+
30
+
31
+	/**
32
+	 * Subject field for email
33
+	 * @var string
34
+	 */
35
+	protected $_subject = '';
36
+
37
+
38
+	/**
39
+	 * Content field for email
40
+	 * @var string
41
+	 */
42
+	protected $_content = '';
43
+
44
+
45
+	/**
46
+	 * constructor
47
+	 *
48
+	 * @access public
49
+	 */
50
+	public function __construct()
51
+	{
52
+		//set name and description properties
53
+		$this->name                = 'email';
54
+		$this->description         = sprintf(
55
+			esc_html__(
56
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
57
+				'event_espresso'
58
+			),
59
+			'<code>wp_mail</code>'
60
+		);
61
+		$this->label               = array(
62
+			'singular' => esc_html__('email', 'event_espresso'),
63
+			'plural'   => esc_html__('emails', 'event_espresso'),
64
+		);
65
+		$this->activate_on_install = true;
66
+
67
+		//we're using defaults so let's call parent constructor that will take care of setting up all the other
68
+		// properties
69
+		parent::__construct();
70
+	}
71
+
72
+
73
+	/**
74
+	 * see abstract declaration in parent class for details.
75
+	 */
76
+	protected function _set_admin_pages()
77
+	{
78
+		$this->admin_registered_pages = array(
79
+			'events_edit' => true,
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * see abstract declaration in parent class for details
86
+	 */
87
+	protected function _set_valid_shortcodes()
88
+	{
89
+		//remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
90
+		// message type.
91
+		$this->_valid_shortcodes = array(
92
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
94
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
95
+		);
96
+	}
97
+
98
+
99
+	/**
100
+	 * see abstract declaration in parent class for details
101
+	 *
102
+	 * @access protected
103
+	 * @return void
104
+	 */
105
+	protected function _set_validator_config()
106
+	{
107
+		$valid_shortcodes = $this->get_valid_shortcodes();
108
+
109
+		$this->_validator_config = array(
110
+			'to'            => array(
111
+				'shortcodes' => $valid_shortcodes['to'],
112
+				'type'       => 'email',
113
+			),
114
+			'cc' => array(
115
+				'shortcodes' => $valid_shortcodes['to'],
116
+				'type' => 'email',
117
+			),
118
+			'from'          => array(
119
+				'shortcodes' => $valid_shortcodes['from'],
120
+				'type'       => 'email',
121
+			),
122
+			'subject'       => array(
123
+				'shortcodes' => array(
124
+					'organization',
125
+					'primary_registration_details',
126
+					'event_author',
127
+					'primary_registration_details',
128
+					'recipient_details',
129
+				),
130
+			),
131
+			'content'       => array(
132
+				'shortcodes' => array(
133
+					'event_list',
134
+					'attendee_list',
135
+					'ticket_list',
136
+					'organization',
137
+					'primary_registration_details',
138
+					'primary_registration_list',
139
+					'event_author',
140
+					'recipient_details',
141
+					'recipient_list',
142
+					'transaction',
143
+					'messenger',
144
+				),
145
+			),
146
+			'attendee_list' => array(
147
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
148
+				'required'   => array('[ATTENDEE_LIST]'),
149
+			),
150
+			'event_list'    => array(
151
+				'shortcodes' => array(
152
+					'event',
153
+					'attendee_list',
154
+					'ticket_list',
155
+					'venue',
156
+					'datetime_list',
157
+					'attendee',
158
+					'primary_registration_details',
159
+					'primary_registration_list',
160
+					'event_author',
161
+					'recipient_details',
162
+					'recipient_list',
163
+				),
164
+				'required'   => array('[EVENT_LIST]'),
165
+			),
166
+			'ticket_list'   => array(
167
+				'shortcodes' => array(
168
+					'event_list',
169
+					'attendee_list',
170
+					'ticket',
171
+					'datetime_list',
172
+					'primary_registration_details',
173
+					'recipient_details',
174
+				),
175
+				'required'   => array('[TICKET_LIST]'),
176
+			),
177
+			'datetime_list' => array(
178
+				'shortcodes' => array('datetime'),
179
+				'required'   => array('[DATETIME_LIST]'),
180
+			),
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * @see   parent EE_messenger class for docs
187
+	 * @since 4.5.0
188
+	 */
189
+	public function do_secondary_messenger_hooks($sending_messenger_name)
190
+	{
191
+		if ($sending_messenger_name = 'html') {
192
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
193
+		}
194
+	}
195
+
196
+
197
+	public function add_email_css(
198
+		$variation_path,
199
+		$messenger,
200
+		$message_type,
201
+		$type,
202
+		$variation,
203
+		$file_extension,
204
+		$url,
205
+		EE_Messages_Template_Pack $template_pack
206
+	) {
207
+		//prevent recursion on this callback.
208
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
209
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
210
+
211
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
212
+		return $variation;
213
+	}
214
+
215
+
216
+	/**
217
+	 * See parent for details
218
+	 *
219
+	 * @access protected
220
+	 * @return void
221
+	 */
222
+	protected function _set_test_settings_fields()
223
+	{
224
+		$this->_test_settings_fields = array(
225
+			'to'      => array(
226
+				'input'      => 'text',
227
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
228
+				'type'       => 'email',
229
+				'required'   => true,
230
+				'validation' => true,
231
+				'css_class'  => 'large-text',
232
+				'format'     => '%s',
233
+				'default'    => get_bloginfo('admin_email'),
234
+			),
235
+			'subject' => array(
236
+				'input'      => 'hidden',
237
+				'label'      => '',
238
+				'type'       => 'string',
239
+				'required'   => false,
240
+				'validation' => false,
241
+				'format'     => '%s',
242
+				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
243
+				'default'    => '',
244
+				'css_class'  => '',
245
+			),
246
+		);
247
+	}
248
+
249
+
250
+	/**
251
+	 * _set_template_fields
252
+	 * This sets up the fields that a messenger requires for the message to go out.
253
+	 *
254
+	 * @access  protected
255
+	 * @return void
256
+	 */
257
+	protected function _set_template_fields()
258
+	{
259
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
260
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
261
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
262
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
263
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
264
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
265
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
266
+		// will not be displayed/parsed.
267
+		$this->_template_fields = array(
268
+			'to'      => array(
269
+				'input'      => 'text',
270
+				'label'      => esc_html_x(
271
+					'To',
272
+					'Label for the "To" field for email addresses',
273
+					'event_espresso'
274
+				),
275
+				'type'       => 'string',
276
+				'required'   => true,
277
+				'validation' => true,
278
+				'css_class'  => 'large-text',
279
+				'format'     => '%s',
280
+			),
281
+			'cc'      => array(
282
+				'input'      => 'text',
283
+				'label'      => esc_html_x(
284
+					'CC',
285
+					'Label for the "Carbon Copy" field used for additional email addresses',
286
+					'event_espresso'
287
+				),
288
+				'type'       => 'string',
289
+				'required'   => false,
290
+				'validation' => true,
291
+				'css_class'  => 'large-text',
292
+				'format'     => '%s',
293
+			),
294
+			'from'    => array(
295
+				'input'      => 'text',
296
+				'label'      => esc_html_x(
297
+					'From',
298
+					'Label for the "From" field for email addresses.',
299
+					'event_espresso'
300
+				),
301
+				'type'       => 'string',
302
+				'required'   => true,
303
+				'validation' => true,
304
+				'css_class'  => 'large-text',
305
+				'format'     => '%s',
306
+			),
307
+			'subject' => array(
308
+				'input'      => 'text',
309
+				'label'      => esc_html_x(
310
+					'Subject',
311
+					'Label for the "Subject" field (short description of contents) for emails.',
312
+					'event_espresso'
313
+				),
314
+				'type'       => 'string',
315
+				'required'   => true,
316
+				'validation' => true,
317
+				'css_class'  => 'large-text',
318
+				'format'     => '%s',
319
+			),
320
+			'content' => '',
321
+			//left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
322
+			'extra'   => array(
323
+				'content' => array(
324
+					'main'          => array(
325
+						'input'      => 'wp_editor',
326
+						'label'      => esc_html__('Main Content', 'event_espresso'),
327
+						'type'       => 'string',
328
+						'required'   => true,
329
+						'validation' => true,
330
+						'format'     => '%s',
331
+						'rows'       => '15',
332
+					),
333
+					'event_list'    => array(
334
+						'input'               => 'wp_editor',
335
+						'label'               => '[EVENT_LIST]',
336
+						'type'                => 'string',
337
+						'required'            => true,
338
+						'validation'          => true,
339
+						'format'              => '%s',
340
+						'rows'                => '15',
341
+						'shortcodes_required' => array('[EVENT_LIST]'),
342
+					),
343
+					'attendee_list' => array(
344
+						'input'               => 'textarea',
345
+						'label'               => '[ATTENDEE_LIST]',
346
+						'type'                => 'string',
347
+						'required'            => true,
348
+						'validation'          => true,
349
+						'format'              => '%s',
350
+						'css_class'           => 'large-text',
351
+						'rows'                => '5',
352
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
353
+					),
354
+					'ticket_list'   => array(
355
+						'input'               => 'textarea',
356
+						'label'               => '[TICKET_LIST]',
357
+						'type'                => 'string',
358
+						'required'            => true,
359
+						'validation'          => true,
360
+						'format'              => '%s',
361
+						'css_class'           => 'large-text',
362
+						'rows'                => '10',
363
+						'shortcodes_required' => array('[TICKET_LIST]'),
364
+					),
365
+					'datetime_list' => array(
366
+						'input'               => 'textarea',
367
+						'label'               => '[DATETIME_LIST]',
368
+						'type'                => 'string',
369
+						'required'            => true,
370
+						'validation'          => true,
371
+						'format'              => '%s',
372
+						'css_class'           => 'large-text',
373
+						'rows'                => '10',
374
+						'shortcodes_required' => array('[DATETIME_LIST]'),
375
+					),
376
+				),
377
+			),
378
+		);
379
+	}
380
+
381
+
382
+	/**
383
+	 * See definition of this class in parent
384
+	 */
385
+	protected function _set_default_message_types()
386
+	{
387
+		$this->_default_message_types = array(
388
+			'payment',
389
+			'payment_refund',
390
+			'registration',
391
+			'not_approved_registration',
392
+			'pending_approval',
393
+		);
394
+	}
395
+
396
+
397
+	/**
398
+	 * @see   definition of this class in parent
399
+	 * @since 4.5.0
400
+	 */
401
+	protected function _set_valid_message_types()
402
+	{
403
+		$this->_valid_message_types = array(
404
+			'payment',
405
+			'registration',
406
+			'not_approved_registration',
407
+			'declined_registration',
408
+			'cancelled_registration',
409
+			'pending_approval',
410
+			'registration_summary',
411
+			'payment_reminder',
412
+			'payment_declined',
413
+			'payment_refund',
414
+		);
415
+	}
416
+
417
+
418
+	/**
419
+	 * setting up admin_settings_fields for messenger.
420
+	 */
421
+	protected function _set_admin_settings_fields()
422
+	{
423
+	}
424
+
425
+	/**
426
+	 * We just deliver the messages don't kill us!!
427
+	 *
428
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
429
+	 *              present.
430
+	 * @throws EE_Error
431
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
432
+	 */
433
+	protected function _send_message()
434
+	{
435
+		$success = wp_mail(
436
+			$this->_to,
437
+			$this->_subject,
438
+			$this->_body(),
439
+			$this->_headers()
440
+		);
441
+		if (! $success) {
442
+			EE_Error::add_error(
443
+				sprintf(
444
+					esc_html__(
445
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
+						'event_espresso'
447
+					),
448
+					$this->_to,
449
+					$this->_from,
450
+					'<br />'
451
+				),
452
+				__FILE__,
453
+				__FUNCTION__,
454
+				__LINE__
455
+			);
456
+		}
457
+		return $success;
458
+	}
459
+
460
+
461
+	/**
462
+	 * see parent for definition
463
+	 *
464
+	 * @return string html body of the message content and the related css.
465
+	 * @throws EE_Error
466
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
+	 */
468
+	protected function _preview()
469
+	{
470
+		return $this->_body(true);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Setup headers for email
476
+	 *
477
+	 * @access protected
478
+	 * @return string formatted header for email
479
+	 */
480
+	protected function _headers()
481
+	{
482
+		$this->_ensure_has_from_email_address();
483
+		$from    = $this->_from;
484
+		$headers = array(
485
+			'From:' . $from,
486
+			'Reply-To:' . $from,
487
+			'Content-Type:text/html; charset=utf-8',
488
+		);
489
+
490
+		if (! empty($this->_cc)) {
491
+			$headers[] = 'cc: ' . $this->_cc;
492
+		}
493
+
494
+		//but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
495
+		// header.
496
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
497
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
498
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
499
+	}
500
+
501
+
502
+	/**
503
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
504
+	 * address for the from address to avoid problems with sending emails.
505
+	 */
506
+	protected function _ensure_has_from_email_address()
507
+	{
508
+		if (empty($this->_from)) {
509
+			$this->_from = get_bloginfo('admin_email');
510
+		}
511
+	}
512
+
513
+
514
+	/**
515
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
516
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
517
+	 * be empty
518
+	 *
519
+	 * @since 4.3.1
520
+	 * @return array
521
+	 */
522
+	private function _parse_from()
523
+	{
524
+		if (strpos($this->_from, '<') !== false) {
525
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
526
+			$from_name = str_replace('"', '', $from_name);
527
+			$from_name = trim($from_name);
528
+
529
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
530
+			$from_email = str_replace('>', '', $from_email);
531
+			$from_email = trim($from_email);
532
+		} elseif (trim($this->_from) !== '') {
533
+			$from_name  = '';
534
+			$from_email = trim($this->_from);
535
+		} else {
536
+			$from_name = $from_email = '';
537
+		}
538
+		return array($from_name, $from_email);
539
+	}
540
+
541
+
542
+	/**
543
+	 * Callback for the wp_mail_from filter.
544
+	 *
545
+	 * @since 4.3.1
546
+	 * @param string $from_email What the original from_email is.
547
+	 * @return string
548
+	 */
549
+	public function set_from_address($from_email)
550
+	{
551
+		$parsed_from = $this->_parse_from();
552
+		//includes fallback if the parsing failed.
553
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
554
+			? $parsed_from[1]
555
+			: get_bloginfo('admin_email');
556
+		return $from_email;
557
+	}
558
+
559
+
560
+	/**
561
+	 * Callback fro the wp_mail_from_name filter.
562
+	 *
563
+	 * @since 4.3.1
564
+	 * @param string $from_name The original from_name.
565
+	 * @return string
566
+	 */
567
+	public function set_from_name($from_name)
568
+	{
569
+		$parsed_from = $this->_parse_from();
570
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
571
+			$from_name = $parsed_from[0];
572
+		}
573
+
574
+		//if from name is "WordPress" let's sub in the site name instead (more friendly!)
575
+		$from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;
576
+
577
+		return $from_name;
578
+	}
579
+
580
+
581
+	/**
582
+	 * setup body for email
583
+	 *
584
+	 * @param bool $preview will determine whether this is preview template or not.
585
+	 * @return string formatted body for email.
586
+	 * @throws EE_Error
587
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
588
+	 */
589
+	protected function _body($preview = false)
590
+	{
591
+		//setup template args!
592
+		$this->_template_args = array(
593
+			'subject'   => $this->_subject,
594
+			'from'      => $this->_from,
595
+			'main_body' => wpautop($this->_content),
596
+		);
597
+		$body                 = $this->_get_main_template($preview);
598
+
599
+		/**
600
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
601
+		 *
602
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
603
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
604
+		 */
605
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
606
+			//require CssToInlineStyles library and its dependencies via composer autoloader
607
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
608
+
609
+			//now if this isn't a preview, let's setup the body so it has inline styles
610
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
611
+				$style = file_get_contents(
612
+					$this->get_variation(
613
+						$this->_tmp_pack,
614
+						$this->_incoming_message_type->name,
615
+						false,
616
+						'main',
617
+						$this->_variation
618
+					),
619
+					true
620
+				);
621
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
622
+				//for some reason the library has a bracket and new line at the beginning.  This takes care of that.
623
+				$body  = ltrim($CSS->convert(true), ">\n");
624
+				//see https://events.codebasehq.com/projects/event-espresso/tickets/8609
625
+				$body  = ltrim($body, "<?");
626
+			}
627
+
628
+		}
629
+		return $body;
630
+	}
631
+
632
+
633
+	/**
634
+	 * This just returns any existing test settings that might be saved in the database
635
+	 *
636
+	 * @access public
637
+	 * @return array
638
+	 */
639
+	public function get_existing_test_settings()
640
+	{
641
+		$settings = parent::get_existing_test_settings();
642
+		//override subject if present because we always want it to be fresh.
643
+		if (is_array($settings) && ! empty($settings['subject'])) {
644
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
645
+		}
646
+		return $settings;
647
+	}
648 648
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             ),
59 59
             '<code>wp_mail</code>'
60 60
         );
61
-        $this->label               = array(
61
+        $this->label = array(
62 62
             'singular' => esc_html__('email', 'event_espresso'),
63 63
             'plural'   => esc_html__('emails', 'event_espresso'),
64 64
         );
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
             $this->_body(),
439 439
             $this->_headers()
440 440
         );
441
-        if (! $success) {
441
+        if ( ! $success) {
442 442
             EE_Error::add_error(
443 443
                 sprintf(
444 444
                     esc_html__(
@@ -482,13 +482,13 @@  discard block
 block discarded – undo
482 482
         $this->_ensure_has_from_email_address();
483 483
         $from    = $this->_from;
484 484
         $headers = array(
485
-            'From:' . $from,
486
-            'Reply-To:' . $from,
485
+            'From:'.$from,
486
+            'Reply-To:'.$from,
487 487
             'Content-Type:text/html; charset=utf-8',
488 488
         );
489 489
 
490
-        if (! empty($this->_cc)) {
491
-            $headers[] = 'cc: ' . $this->_cc;
490
+        if ( ! empty($this->_cc)) {
491
+            $headers[] = 'cc: '.$this->_cc;
492 492
         }
493 493
 
494 494
         //but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
             'from'      => $this->_from,
595 595
             'main_body' => wpautop($this->_content),
596 596
         );
597
-        $body                 = $this->_get_main_template($preview);
597
+        $body = $this->_get_main_template($preview);
598 598
 
599 599
         /**
600 600
          * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
@@ -604,10 +604,10 @@  discard block
 block discarded – undo
604 604
          */
605 605
         if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
606 606
             //require CssToInlineStyles library and its dependencies via composer autoloader
607
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
607
+            require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php';
608 608
 
609 609
             //now if this isn't a preview, let's setup the body so it has inline styles
610
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
610
+            if ( ! $preview || ($preview && defined('DOING_AJAX'))) {
611 611
                 $style = file_get_contents(
612 612
                     $this->get_variation(
613 613
                         $this->_tmp_pack,
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Pdf_messenger.class.php 2 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @subpackage messages
8 8
  */
9 9
 if (!defined('EVENT_ESPRESSO_VERSION'))
10
-    exit('NO direct script access allowed');
10
+	exit('NO direct script access allowed');
11 11
 
12 12
 /**
13 13
  *
@@ -24,343 +24,343 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * The following are the properties that this messenger requires for generating pdf
29
-     */
30
-
31
-    /**
32
-     * This is the pdf body generated by the template via the message type.
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_content;
37
-
38
-
39
-    /**
40
-     * This is for the page title that gets displayed.  This will end up being the filename for the generated pdf.
41
-     *
42
-     * @var string
43
-     */
44
-    protected $_subject;
45
-
46
-
47
-    /**
48
-     * @return EE_Pdf_messenger
49
-     */
50
-    public function __construct()
51
-    {
52
-        //set properties
53
-        $this->name = 'pdf';
54
-        $this->description = __('This messenger is used for generating a pdf version of the message.', 'event_espresso');
55
-        $this->label = array(
56
-            'singular' => __('PDF', 'event_espresso'),
57
-            'plural' => __('PDFs', 'event_espresso')
58
-        );
59
-        $this->activate_on_install = TRUE;
60
-
61
-        parent::__construct();
62
-    }
63
-
64
-
65
-    /**
66
-     * PDF Messenger desires execution immediately.
67
-     * @see  parent::send_now() for documentation.
68
-     * @since  4.9.0
69
-     * @return bool
70
-     */
71
-    public function send_now()
72
-    {
73
-        return true;
74
-    }
75
-
76
-
77
-    /**
78
-     * HTML Messenger allows an empty to field.
79
-     * @see parent::allow_empty_to_field() for documentation
80
-     * @since  4.9.0
81
-     * @return bool
82
-     */
83
-    public function allow_empty_to_field()
84
-    {
85
-        return true;
86
-    }
87
-
88
-
89
-    /**
90
-     * @see abstract declaration in EE_messenger for details.
91
-     */
92
-    protected function _set_admin_pages()
93
-    {
94
-        $this->admin_registered_pages = array('events_edit' => false);
95
-    }
96
-
97
-
98
-    /**
99
-     * @see abstract declaration in EE_messenger for details.
100
-     */
101
-    protected function _set_valid_shortcodes()
102
-    {
103
-        $this->_valid_shortcodes = array();
104
-    }
105
-
106
-
107
-    /**
108
-     * @see abstract declaration in EE_messenger for details.
109
-     */
110
-    protected function _set_validator_config()
111
-    {
112
-        $this->_validator_config = array(
113
-            'subject' => array(
114
-                'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
115
-            ),
116
-            'content' => array(
117
-                'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
118
-            ),
119
-            'attendee_list' => array(
120
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
121
-                'required' => array('[ATTENDEE_LIST]')
122
-            ),
123
-            'event_list' => array(
124
-                'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'),
125
-                'required' => array('[EVENT_LIST]')
126
-            ),
127
-            'ticket_list' => array(
128
-                'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'),
129
-                'required' => array('[TICKET_LIST]')
130
-            ),
131
-            'datetime_list' => array(
132
-                'shortcodes' => array('datetime'),
133
-                'required' => array('[DATETIME_LIST]')
134
-            ),
135
-        );
136
-    }
137
-
138
-
139
-    /**
140
-     * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this messenger can add their own js.
141
-     *
142
-     * @return void.
143
-     */
144
-    public function enqueue_scripts_styles()
145
-    {
146
-        parent::enqueue_scripts_styles();
147
-        do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
148
-    }
149
-
150
-
151
-    /**
152
-     * _set_template_fields
153
-     * This sets up the fields that a messenger requires for the message to go out.
154
-     *
155
-     * @access  protected
156
-     * @return void
157
-     */
158
-    protected function _set_template_fields()
159
-    {
160
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to.  This is important for the Messages_admin to know what fields to display to the user.  Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed.
161
-        $this->_template_fields = array(
162
-            'subject' => array(
163
-                'input' => 'text',
164
-                'label' => __('Page Title', 'event_espresso'),
165
-                'type' => 'string',
166
-                'required' => TRUE,
167
-                'validation' => TRUE,
168
-                'css_class' => 'large-text',
169
-                'format' => '%s'
170
-            ),
171
-            'content' => '', //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
172
-            'extra' => array(
173
-                'content' => array(
174
-                    'main' => array(
175
-                        'input' => 'wp_editor',
176
-                        'label' => __('Main Content', 'event_espresso'),
177
-                        'type' => 'string',
178
-                        'required' => TRUE,
179
-                        'validation' => TRUE,
180
-                        'format' => '%s',
181
-                        'rows' => '15'
182
-                    ),
183
-                    'event_list' => array(
184
-                        'input' => 'wp_editor',
185
-                        'label' => '[EVENT_LIST]',
186
-                        'type' => 'string',
187
-                        'required' => TRUE,
188
-                        'validation' => TRUE,
189
-                        'format' => '%s',
190
-                        'rows' => '15',
191
-                        'shortcodes_required' => array('[EVENT_LIST]')
192
-                    ),
193
-                    'attendee_list' => array(
194
-                        'input' => 'textarea',
195
-                        'label' => '[ATTENDEE_LIST]',
196
-                        'type' => 'string',
197
-                        'required' => TRUE,
198
-                        'validation' => TRUE,
199
-                        'format' => '%s',
200
-                        'css_class' => 'large-text',
201
-                        'rows' => '5',
202
-                        'shortcodes_required' => array('[ATTENDEE_LIST]')
203
-                    ),
204
-                    'ticket_list' => array(
205
-                        'input' => 'textarea',
206
-                        'label' => '[TICKET_LIST]',
207
-                        'type' => 'string',
208
-                        'required' => TRUE,
209
-                        'validation' => TRUE,
210
-                        'format' => '%s',
211
-                        'css_class' => 'large-text',
212
-                        'rows' => '10',
213
-                        'shortcodes_required' => array('[TICKET_LIST]')
214
-                    ),
215
-                    'datetime_list' => array(
216
-                        'input' => 'textarea',
217
-                        'label' => '[DATETIME_LIST]',
218
-                        'type' => 'string',
219
-                        'required' => TRUE,
220
-                        'validation' => TRUE,
221
-                        'format' => '%s',
222
-                        'css_class' => 'large-text',
223
-                        'rows' => '10',
224
-                        'shortcodes_required' => array('[DATETIME_LIST]')
225
-                    )
226
-                )
227
-            )
228
-        );
229
-    }
230
-
231
-
232
-    /**
233
-     * @see definition of this method in parent
234
-     *
235
-     * @since 4.5.0
236
-     *
237
-     */
238
-    protected function _set_default_message_types()
239
-    {
240
-        //note currently PDF is only a secondary messenger so it never has any associated message types.
241
-        $this->_default_message_types = array();
242
-    }
243
-
244
-
245
-    /**
246
-     * @see definition of this method in parent
247
-     *
248
-     * @since 4.5.0
249
-     */
250
-    protected function _set_valid_message_types()
251
-    {
252
-        $this->_valid_message_types = array();
253
-    }
254
-
255
-
256
-    /**
257
-     * Generates html version of the message content and then sends it to the pdf generator.
258
-     *
259
-     *
260
-     * @since 4.5.0
261
-     *
262
-     * @return string.
263
-     */
264
-    protected function _send_message()
265
-    {
266
-        $this->_template_args = array(
267
-            'page_title' => $this->_subject,
268
-            'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation),
269
-            'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation),
270
-            'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation),
271
-            'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',
272
-            'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content)
273
-        );
274
-        $this->_deregister_wp_hooks();
275
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
276
-        $content = $this->_get_main_template();
27
+	/**
28
+	 * The following are the properties that this messenger requires for generating pdf
29
+	 */
30
+
31
+	/**
32
+	 * This is the pdf body generated by the template via the message type.
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_content;
37
+
38
+
39
+	/**
40
+	 * This is for the page title that gets displayed.  This will end up being the filename for the generated pdf.
41
+	 *
42
+	 * @var string
43
+	 */
44
+	protected $_subject;
45
+
46
+
47
+	/**
48
+	 * @return EE_Pdf_messenger
49
+	 */
50
+	public function __construct()
51
+	{
52
+		//set properties
53
+		$this->name = 'pdf';
54
+		$this->description = __('This messenger is used for generating a pdf version of the message.', 'event_espresso');
55
+		$this->label = array(
56
+			'singular' => __('PDF', 'event_espresso'),
57
+			'plural' => __('PDFs', 'event_espresso')
58
+		);
59
+		$this->activate_on_install = TRUE;
60
+
61
+		parent::__construct();
62
+	}
63
+
64
+
65
+	/**
66
+	 * PDF Messenger desires execution immediately.
67
+	 * @see  parent::send_now() for documentation.
68
+	 * @since  4.9.0
69
+	 * @return bool
70
+	 */
71
+	public function send_now()
72
+	{
73
+		return true;
74
+	}
75
+
76
+
77
+	/**
78
+	 * HTML Messenger allows an empty to field.
79
+	 * @see parent::allow_empty_to_field() for documentation
80
+	 * @since  4.9.0
81
+	 * @return bool
82
+	 */
83
+	public function allow_empty_to_field()
84
+	{
85
+		return true;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @see abstract declaration in EE_messenger for details.
91
+	 */
92
+	protected function _set_admin_pages()
93
+	{
94
+		$this->admin_registered_pages = array('events_edit' => false);
95
+	}
96
+
97
+
98
+	/**
99
+	 * @see abstract declaration in EE_messenger for details.
100
+	 */
101
+	protected function _set_valid_shortcodes()
102
+	{
103
+		$this->_valid_shortcodes = array();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @see abstract declaration in EE_messenger for details.
109
+	 */
110
+	protected function _set_validator_config()
111
+	{
112
+		$this->_validator_config = array(
113
+			'subject' => array(
114
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
115
+			),
116
+			'content' => array(
117
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
118
+			),
119
+			'attendee_list' => array(
120
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
121
+				'required' => array('[ATTENDEE_LIST]')
122
+			),
123
+			'event_list' => array(
124
+				'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'),
125
+				'required' => array('[EVENT_LIST]')
126
+			),
127
+			'ticket_list' => array(
128
+				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'),
129
+				'required' => array('[TICKET_LIST]')
130
+			),
131
+			'datetime_list' => array(
132
+				'shortcodes' => array('datetime'),
133
+				'required' => array('[DATETIME_LIST]')
134
+			),
135
+		);
136
+	}
137
+
138
+
139
+	/**
140
+	 * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this messenger can add their own js.
141
+	 *
142
+	 * @return void.
143
+	 */
144
+	public function enqueue_scripts_styles()
145
+	{
146
+		parent::enqueue_scripts_styles();
147
+		do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
148
+	}
149
+
150
+
151
+	/**
152
+	 * _set_template_fields
153
+	 * This sets up the fields that a messenger requires for the message to go out.
154
+	 *
155
+	 * @access  protected
156
+	 * @return void
157
+	 */
158
+	protected function _set_template_fields()
159
+	{
160
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to.  This is important for the Messages_admin to know what fields to display to the user.  Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed.
161
+		$this->_template_fields = array(
162
+			'subject' => array(
163
+				'input' => 'text',
164
+				'label' => __('Page Title', 'event_espresso'),
165
+				'type' => 'string',
166
+				'required' => TRUE,
167
+				'validation' => TRUE,
168
+				'css_class' => 'large-text',
169
+				'format' => '%s'
170
+			),
171
+			'content' => '', //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
172
+			'extra' => array(
173
+				'content' => array(
174
+					'main' => array(
175
+						'input' => 'wp_editor',
176
+						'label' => __('Main Content', 'event_espresso'),
177
+						'type' => 'string',
178
+						'required' => TRUE,
179
+						'validation' => TRUE,
180
+						'format' => '%s',
181
+						'rows' => '15'
182
+					),
183
+					'event_list' => array(
184
+						'input' => 'wp_editor',
185
+						'label' => '[EVENT_LIST]',
186
+						'type' => 'string',
187
+						'required' => TRUE,
188
+						'validation' => TRUE,
189
+						'format' => '%s',
190
+						'rows' => '15',
191
+						'shortcodes_required' => array('[EVENT_LIST]')
192
+					),
193
+					'attendee_list' => array(
194
+						'input' => 'textarea',
195
+						'label' => '[ATTENDEE_LIST]',
196
+						'type' => 'string',
197
+						'required' => TRUE,
198
+						'validation' => TRUE,
199
+						'format' => '%s',
200
+						'css_class' => 'large-text',
201
+						'rows' => '5',
202
+						'shortcodes_required' => array('[ATTENDEE_LIST]')
203
+					),
204
+					'ticket_list' => array(
205
+						'input' => 'textarea',
206
+						'label' => '[TICKET_LIST]',
207
+						'type' => 'string',
208
+						'required' => TRUE,
209
+						'validation' => TRUE,
210
+						'format' => '%s',
211
+						'css_class' => 'large-text',
212
+						'rows' => '10',
213
+						'shortcodes_required' => array('[TICKET_LIST]')
214
+					),
215
+					'datetime_list' => array(
216
+						'input' => 'textarea',
217
+						'label' => '[DATETIME_LIST]',
218
+						'type' => 'string',
219
+						'required' => TRUE,
220
+						'validation' => TRUE,
221
+						'format' => '%s',
222
+						'css_class' => 'large-text',
223
+						'rows' => '10',
224
+						'shortcodes_required' => array('[DATETIME_LIST]')
225
+					)
226
+				)
227
+			)
228
+		);
229
+	}
230
+
231
+
232
+	/**
233
+	 * @see definition of this method in parent
234
+	 *
235
+	 * @since 4.5.0
236
+	 *
237
+	 */
238
+	protected function _set_default_message_types()
239
+	{
240
+		//note currently PDF is only a secondary messenger so it never has any associated message types.
241
+		$this->_default_message_types = array();
242
+	}
243
+
244
+
245
+	/**
246
+	 * @see definition of this method in parent
247
+	 *
248
+	 * @since 4.5.0
249
+	 */
250
+	protected function _set_valid_message_types()
251
+	{
252
+		$this->_valid_message_types = array();
253
+	}
254
+
255
+
256
+	/**
257
+	 * Generates html version of the message content and then sends it to the pdf generator.
258
+	 *
259
+	 *
260
+	 * @since 4.5.0
261
+	 *
262
+	 * @return string.
263
+	 */
264
+	protected function _send_message()
265
+	{
266
+		$this->_template_args = array(
267
+			'page_title' => $this->_subject,
268
+			'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation),
269
+			'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation),
270
+			'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation),
271
+			'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',
272
+			'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content)
273
+		);
274
+		$this->_deregister_wp_hooks();
275
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
276
+		$content = $this->_get_main_template();
277 277
 //		die( $content );
278
-        $this->_do_pdf($content);
279
-        exit(0);
280
-    }
281
-
282
-
283
-    /**
284
-     * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates.  If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook.
285
-     *
286
-     * @since 4.5.0
287
-     *
288
-     * @return void
289
-     */
290
-    protected function _deregister_wp_hooks()
291
-    {
292
-        remove_all_actions('wp_head');
293
-        remove_all_actions('wp_footer');
294
-        remove_all_actions('wp_print_footer_scripts');
295
-        remove_all_actions('wp_enqueue_scripts');
296
-        global $wp_scripts, $wp_styles;
297
-        $wp_scripts = $wp_styles = array();
298
-
299
-        //just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
300
-        add_action('wp_head', 'wp_enqueue_scripts');
301
-        add_action('wp_footer', 'wp_print_footer_scripts');
302
-        add_action('wp_print_footer_scripts', '_wp_footer_scripts');
303
-    }
304
-
305
-
306
-    /**
307
-     * Overwrite parent _get_main_template for pdf purposes.
308
-     *
309
-     * @since  4.5.0
310
-     *
311
-     * @param bool $preview
312
-     * @return string
313
-     */
314
-    protected function _get_main_template($preview = FALSE)
315
-    {
316
-        $wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main');
317
-        //add message type to template_args
318
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
319
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE);
320
-    }
321
-
322
-
323
-    /**
324
-     * This takes care of loading the dompdf library and generating the actual pdf
325
-     *
326
-     * @param string $content This is the generated html content being converted into a pdf.
327
-     *
328
-     * @return void
329
-     */
330
-    protected function _do_pdf($content = '')
331
-    {
332
-        $invoice_name = $this->_subject;
333
-
334
-        //only load dompdf if nobody else has yet...
335
-        if (!defined('DOMPDF_DIR')) {
336
-            define('DOMPDF_ENABLE_REMOTE', TRUE);
337
-            define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
338
-            define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
339
-            require_once(EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php');
340
-        }
341
-        $dompdf = new DOMPDF();
342
-        if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) {
343
-            $dompdf->set_paper(DOMPDF_DEFAULT_PAPER_SIZE);
344
-        }
345
-        //Remove all spaces between HTML tags
346
-        $content = preg_replace('/>\s+</', '><', $content);
347
-        $dompdf->load_html($content);
348
-        $dompdf->render();
349
-        //forcing the browser to open a download dialog.
350
-        $dompdf->stream($invoice_name . ".pdf", array('Attachment' => TRUE));
351
-    }
352
-
353
-
354
-    /**
355
-     * @return string
356
-     */
357
-    protected function _preview()
358
-    {
359
-        return $this->_send_message();
360
-    }
361
-
362
-
363
-    protected function _set_admin_settings_fields()
364
-    {
365
-    }
278
+		$this->_do_pdf($content);
279
+		exit(0);
280
+	}
281
+
282
+
283
+	/**
284
+	 * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates.  If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook.
285
+	 *
286
+	 * @since 4.5.0
287
+	 *
288
+	 * @return void
289
+	 */
290
+	protected function _deregister_wp_hooks()
291
+	{
292
+		remove_all_actions('wp_head');
293
+		remove_all_actions('wp_footer');
294
+		remove_all_actions('wp_print_footer_scripts');
295
+		remove_all_actions('wp_enqueue_scripts');
296
+		global $wp_scripts, $wp_styles;
297
+		$wp_scripts = $wp_styles = array();
298
+
299
+		//just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
300
+		add_action('wp_head', 'wp_enqueue_scripts');
301
+		add_action('wp_footer', 'wp_print_footer_scripts');
302
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
303
+	}
304
+
305
+
306
+	/**
307
+	 * Overwrite parent _get_main_template for pdf purposes.
308
+	 *
309
+	 * @since  4.5.0
310
+	 *
311
+	 * @param bool $preview
312
+	 * @return string
313
+	 */
314
+	protected function _get_main_template($preview = FALSE)
315
+	{
316
+		$wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main');
317
+		//add message type to template_args
318
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
319
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE);
320
+	}
321
+
322
+
323
+	/**
324
+	 * This takes care of loading the dompdf library and generating the actual pdf
325
+	 *
326
+	 * @param string $content This is the generated html content being converted into a pdf.
327
+	 *
328
+	 * @return void
329
+	 */
330
+	protected function _do_pdf($content = '')
331
+	{
332
+		$invoice_name = $this->_subject;
333
+
334
+		//only load dompdf if nobody else has yet...
335
+		if (!defined('DOMPDF_DIR')) {
336
+			define('DOMPDF_ENABLE_REMOTE', TRUE);
337
+			define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
338
+			define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
339
+			require_once(EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php');
340
+		}
341
+		$dompdf = new DOMPDF();
342
+		if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) {
343
+			$dompdf->set_paper(DOMPDF_DEFAULT_PAPER_SIZE);
344
+		}
345
+		//Remove all spaces between HTML tags
346
+		$content = preg_replace('/>\s+</', '><', $content);
347
+		$dompdf->load_html($content);
348
+		$dompdf->render();
349
+		//forcing the browser to open a download dialog.
350
+		$dompdf->stream($invoice_name . ".pdf", array('Attachment' => TRUE));
351
+	}
352
+
353
+
354
+	/**
355
+	 * @return string
356
+	 */
357
+	protected function _preview()
358
+	{
359
+		return $this->_send_message();
360
+	}
361
+
362
+
363
+	protected function _set_admin_settings_fields()
364
+	{
365
+	}
366 366
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION'))
9
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
10 10
     exit('NO direct script access allowed');
11 11
 
12 12
 /**
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
             'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation),
269 269
             'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation),
270 270
             'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation),
271
-            'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',
271
+            'extra_css' => EE_LIBRARIES_URL.'messages/defaults/default/variations/pdf_base_default.css',
272 272
             'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content)
273 273
         );
274 274
         $this->_deregister_wp_hooks();
@@ -332,11 +332,11 @@  discard block
 block discarded – undo
332 332
         $invoice_name = $this->_subject;
333 333
 
334 334
         //only load dompdf if nobody else has yet...
335
-        if (!defined('DOMPDF_DIR')) {
335
+        if ( ! defined('DOMPDF_DIR')) {
336 336
             define('DOMPDF_ENABLE_REMOTE', TRUE);
337 337
             define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
338 338
             define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
339
-            require_once(EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php');
339
+            require_once(EE_THIRD_PARTY.'dompdf/dompdf_config.inc.php');
340 340
         }
341 341
         $dompdf = new DOMPDF();
342 342
         if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) {
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
         $dompdf->load_html($content);
348 348
         $dompdf->render();
349 349
         //forcing the browser to open a download dialog.
350
-        $dompdf->stream($invoice_name . ".pdf", array('Attachment' => TRUE));
350
+        $dompdf->stream($invoice_name.".pdf", array('Attachment' => TRUE));
351 351
     }
352 352
 
353 353
 
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Generator.lib.php 1 patch
Indentation   +969 added lines, -969 removed lines patch added patch discarded remove patch
@@ -13,973 +13,973 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @type EE_Messages_Data_Handler_Collection
18
-     */
19
-    protected $_data_handler_collection;
20
-
21
-    /**
22
-     * @type  EE_Message_Template_Group_Collection
23
-     */
24
-    protected $_template_collection;
25
-
26
-    /**
27
-     * This will hold the data handler for the current EE_Message being generated.
28
-     *
29
-     * @type EE_Messages_incoming_data
30
-     */
31
-    protected $_current_data_handler;
32
-
33
-    /**
34
-     * This holds the EE_Messages_Queue that contains the messages to generate.
35
-     *
36
-     * @type EE_Messages_Queue
37
-     */
38
-    protected $_generation_queue;
39
-
40
-    /**
41
-     * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
-     *
43
-     * @type EE_Messages_Queue
44
-     */
45
-    protected $_ready_queue;
46
-
47
-    /**
48
-     * This is a container for any error messages that get created through the generation
49
-     * process.
50
-     *
51
-     * @type array
52
-     */
53
-    protected $_error_msg = array();
54
-
55
-    /**
56
-     * Flag used to set when the current EE_Message in the generation queue has been verified.
57
-     *
58
-     * @type bool
59
-     */
60
-    protected $_verified = false;
61
-
62
-    /**
63
-     * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
-     *
65
-     * @type EE_messenger
66
-     */
67
-    protected $_current_messenger;
68
-
69
-    /**
70
-     * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
-     *
72
-     * @type EE_message_type
73
-     */
74
-    protected $_current_message_type;
75
-
76
-    /**
77
-     * @type EEH_Parse_Shortcodes
78
-     */
79
-    protected $_shortcode_parser;
80
-
81
-
82
-    /**
83
-     * @param EE_Messages_Queue                     $generation_queue
84
-     * @param \EE_Messages_Queue                    $ready_queue
85
-     * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
-     * @param \EE_Message_Template_Group_Collection $template_collection
87
-     * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
-     */
89
-    public function __construct(
90
-        EE_Messages_Queue $generation_queue,
91
-        EE_Messages_Queue $ready_queue,
92
-        EE_Messages_Data_Handler_Collection $data_handler_collection,
93
-        EE_Message_Template_Group_Collection $template_collection,
94
-        EEH_Parse_Shortcodes $shortcode_parser
95
-    ) {
96
-        $this->_generation_queue        = $generation_queue;
97
-        $this->_ready_queue             = $ready_queue;
98
-        $this->_data_handler_collection = $data_handler_collection;
99
-        $this->_template_collection     = $template_collection;
100
-        $this->_shortcode_parser        = $shortcode_parser;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return EE_Messages_Queue
106
-     */
107
-    public function generation_queue()
108
-    {
109
-        return $this->_generation_queue;
110
-    }
111
-
112
-
113
-    /**
114
-     *  This iterates through the provided queue and generates the EE_Message objects.
115
-     *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
-     *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
-     *  for the caller to decide what to do with it.
118
-     *
119
-     * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
-     * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public function generate($save = true)
125
-    {
126
-        //iterate through the messages in the queue, generate, and add to new queue.
127
-        $this->_generation_queue->get_message_repository()->rewind();
128
-        while ($this->_generation_queue->get_message_repository()->valid()) {
129
-            //reset "current" properties
130
-            $this->_reset_current_properties();
131
-
132
-            /** @type EE_Message $msg */
133
-            $msg = $this->_generation_queue->get_message_repository()->current();
134
-
135
-            /**
136
-             * need to get the next object and capture it for setting manually after deletes.  The reason is that when
137
-             * an object is removed from the repo then valid for the next object will fail.
138
-             */
139
-            $this->_generation_queue->get_message_repository()->next();
140
-            $next_msg = $this->_generation_queue->get_message_repository()->current();
141
-            //restore pointer to current item
142
-            $this->_generation_queue->get_message_repository()->set_current($msg);
143
-
144
-            //skip and delete if the current $msg is NOT incomplete (queued for generation)
145
-            if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
146
-                //we keep this item in the db just remove from the repo.
147
-                $this->_generation_queue->get_message_repository()->remove($msg);
148
-                //next item
149
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
150
-                continue;
151
-            }
152
-
153
-            if ($this->_verify()) {
154
-                //let's get generating!
155
-                $this->_generate();
156
-            }
157
-
158
-            //don't persist debug_only messages if the messages system is not in debug mode.
159
-            if ($msg->STS_ID() === EEM_Message::status_debug_only
160
-                && ! EEM_Message::debug()
161
-            ) {
162
-                do_action(
163
-                    'AHEE__EE_Messages_Generator__generate__before_debug_delete',
164
-                    $msg,
165
-                    $this->_error_msg,
166
-                    $this->_current_messenger,
167
-                    $this->_current_message_type,
168
-                    $this->_current_data_handler
169
-                );
170
-                $this->_generation_queue->get_message_repository()->delete();
171
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
172
-                continue;
173
-            }
174
-
175
-            //if there are error messages then let's set the status and the error message.
176
-            if ($this->_error_msg) {
177
-                //if the status is already debug only, then let's leave it at that.
178
-                if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
179
-                    $msg->set_STS_ID(EEM_Message::status_failed);
180
-                }
181
-                do_action(
182
-                    'AHEE__EE_Messages_Generator__generate__processing_failed_message',
183
-                    $msg,
184
-                    $this->_error_msg,
185
-                    $this->_current_messenger,
186
-                    $this->_current_message_type,
187
-                    $this->_current_data_handler
188
-                );
189
-                $msg->set_error_message(
190
-                    esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
191
-                    . "\n"
192
-                    . implode("\n", $this->_error_msg)
193
-                );
194
-                $msg->set_modified(time());
195
-            } else {
196
-                do_action(
197
-                    'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
198
-                    $msg,
199
-                    $this->_error_msg,
200
-                    $this->_current_messenger,
201
-                    $this->_current_message_type,
202
-                    $this->_current_data_handler
203
-                );
204
-                //remove from db
205
-                $this->_generation_queue->get_message_repository()->delete();
206
-            }
207
-            //next item
208
-            $this->_generation_queue->get_message_repository()->set_current($next_msg);
209
-        }
210
-
211
-        //generation queue is ALWAYS saved to record any errors in the generation process.
212
-        $this->_generation_queue->save();
213
-
214
-        /**
215
-         * save _ready_queue if flag set.
216
-         * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
217
-         * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
218
-         * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
219
-         * irrelevant.
220
-         */
221
-        if ($save) {
222
-            $this->_ready_queue->save();
223
-        }
224
-
225
-        //final reset of properties
226
-        $this->_reset_current_properties();
227
-
228
-        return $this->_ready_queue;
229
-    }
230
-
231
-
232
-    /**
233
-     * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
234
-     * in the generation queue.
235
-     */
236
-    protected function _reset_current_properties()
237
-    {
238
-        $this->_verified = false;
239
-        //make sure any _data value in the current message type is reset
240
-        if ($this->_current_message_type instanceof EE_message_type) {
241
-            $this->_current_message_type->reset_data();
242
-        }
243
-        $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
244
-    }
245
-
246
-
247
-    /**
248
-     * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
249
-     * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
250
-     * _generating_queue.
251
-     *
252
-     * @return bool Whether the message was successfully generated or not.
253
-     * @throws EE_Error
254
-     * @throws InvalidArgumentException
255
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
-     */
258
-    protected function _generate()
259
-    {
260
-        //double check verification has run and that everything is ready to work with (saves us having to validate
261
-        // everything again).
262
-        if (! $this->_verified) {
263
-            return false; //get out because we don't have a valid setup to work with.
264
-        }
265
-
266
-
267
-        try {
268
-            $addressees = $this->_current_message_type->get_addressees(
269
-                $this->_current_data_handler,
270
-                $this->_generation_queue->get_message_repository()->current()->context()
271
-            );
272
-        } catch (EE_Error $e) {
273
-            $this->_error_msg[] = $e->getMessage();
274
-            return false;
275
-        }
276
-
277
-
278
-        //if no addressees then get out because there is nothing to generation (possible bad data).
279
-        if (! $this->_valid_addressees($addressees)) {
280
-            do_action(
281
-                'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282
-                $this->_generation_queue->get_message_repository()->current(),
283
-                $addressees,
284
-                $this->_current_messenger,
285
-                $this->_current_message_type,
286
-                $this->_current_data_handler
287
-            );
288
-            $this->_generation_queue->get_message_repository()->current()->set_STS_ID(
289
-                EEM_Message::status_debug_only
290
-            );
291
-            $this->_error_msg[] = esc_html__(
292
-                'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
293
-                'event_espresso'
294
-            );
295
-            return false;
296
-        }
297
-
298
-        $message_template_group = $this->_get_message_template_group();
299
-
300
-        //in the unlikely event there is no EE_Message_Template_Group available, get out!
301
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
302
-            $this->_error_msg[] = esc_html__(
303
-                'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304
-                'event_espresso'
305
-            );
306
-            return false;
307
-        }
308
-
309
-        //get formatted templates for using to parse and setup EE_Message objects.
310
-        $templates = $this->_get_templates($message_template_group);
311
-
312
-
313
-        //setup new EE_Message objects (and add to _ready_queue)
314
-        return $this->_assemble_messages($addressees, $templates, $message_template_group);
315
-    }
316
-
317
-
318
-    /**
319
-     * Retrieves the message template group being used for generating messages.
320
-     * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
321
-     *
322
-     * @return EE_Message_Template_Group|null
323
-     * @throws EE_Error
324
-     * @throws InvalidArgumentException
325
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
326
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
327
-     */
328
-    protected function _get_message_template_group()
329
-    {
330
-        //first see if there is a specific message template group requested (current message in the queue has a specific
331
-        //GRP_ID
332
-        $message_template_group = $this->_specific_message_template_group_from_queue();
333
-        if ($message_template_group instanceof EE_Message_Template_Group) {
334
-            return $message_template_group;
335
-        }
336
-
337
-        //get event_ids from the datahandler so we can check to see if there's already a message template group for them
338
-        //in the collection.
339
-        $event_ids              = $this->_get_event_ids_from_current_data_handler();
340
-        $message_template_group = $this->_template_collection->get_by_key(
341
-            $this->_template_collection->getKey(
342
-                $this->_current_messenger->name,
343
-                $this->_current_message_type->name,
344
-                $event_ids
345
-            )
346
-        );
347
-
348
-        //if we have a message template group then no need to hit the database, just return it.
349
-        if ($message_template_group instanceof EE_Message_Template_Group) {
350
-            return $message_template_group;
351
-        }
352
-
353
-        //okay made it here, so let's get the global group first for this messenger and message type to ensure
354
-        //there is no override set.
355
-        $global_message_template_group =
356
-            $this->_get_global_message_template_group_for_current_messenger_and_message_type();
357
-
358
-        if ($global_message_template_group instanceof EE_Message_Template_Group
359
-            && $global_message_template_group->get('MTP_is_override')
360
-        ) {
361
-            return $global_message_template_group;
362
-        }
363
-
364
-        //if we're still here, that means there was no message template group for the events in the collection and
365
-        //the global message template group for the messenger and message type is not set for override.  So next step is
366
-        //to see if there is a common shared custom message template group for this set of events.
367
-        $message_template_group = $this->_get_shared_message_template_for_events($event_ids);
368
-        if ($message_template_group instanceof EE_Message_Template_Group) {
369
-            return $message_template_group;
370
-        }
371
-
372
-        //STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
373
-        //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
374
-        //and return it.
375
-        if ($global_message_template_group instanceof EE_Message_Template_Group) {
376
-            $this->_template_collection->add(
377
-                $global_message_template_group,
378
-                $event_ids
379
-            );
380
-            return $global_message_template_group;
381
-        }
382
-
383
-        //if we land here that means there's NO active message template group for this set.
384
-        //TODO this will be a good target for some optimization down the road.  Whenever there is no active message
385
-        //template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
386
-        //this should likely bit hit rarely enough that it's not a significant issue.
387
-        return null;
388
-    }
389
-
390
-
391
-    /**
392
-     * This checks the current message in the queue and determines if there is a specific Message Template Group
393
-     * requested for that message.
394
-     *
395
-     * @return EE_Message_Template_Group|null
396
-     * @throws EE_Error
397
-     * @throws InvalidArgumentException
398
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
399
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
400
-     */
401
-    protected function _specific_message_template_group_from_queue()
402
-    {
403
-        //is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
404
-        //so let's use that.
405
-        $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
406
-
407
-        if ($GRP_ID) {
408
-            //attempt to retrieve from repo first
409
-            $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410
-            if ($message_template_group instanceof EE_Message_Template_Group) {
411
-                return $message_template_group;  //got it!
412
-            }
413
-
414
-            //nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
415
-            //is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
416
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
417
-            if ($message_template_group instanceof EE_Message_Template_Group) {
418
-                $this->_template_collection->add($message_template_group);
419
-                return $message_template_group;
420
-            }
421
-        }
422
-        return null;
423
-    }
424
-
425
-
426
-    /**
427
-     * Returns whether the event ids passed in all share the same message template group for the current message type
428
-     * and messenger.
429
-     *
430
-     * @param array $event_ids
431
-     * @return bool true means they DO share the same message template group, false means they don't.
432
-     * @throws EE_Error
433
-     * @throws InvalidArgumentException
434
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
-     */
437
-    protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
438
-    {
439
-        foreach ($this->_current_data_handler->events as $event) {
440
-            $event_ids[$event['ID']] = $event['ID'];
441
-        }
442
-        $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
443
-            array(
444
-                array(
445
-                    'Event.EVT_ID'           => array('IN', $event_ids),
446
-                    'MTP_messenger'    => $this->_current_messenger->name,
447
-                    'MTP_message_type' => $this->_current_message_type->name,
448
-                ),
449
-            ),
450
-            'GRP_ID',
451
-            true
452
-        );
453
-        return $count_of_message_template_groups === 1;
454
-    }
455
-
456
-
457
-    /**
458
-     * This will get the shared message template group for events that are in the current data handler but ONLY if
459
-     * there's a single shared message template group among all the events.  Otherwise it returns null.
460
-     *
461
-     * @param array $event_ids
462
-     * @return EE_Message_Template_Group|null
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
466
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
467
-     */
468
-    protected function _get_shared_message_template_for_events(array $event_ids)
469
-    {
470
-        $message_template_group = null;
471
-        if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
472
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one(
473
-                array(
474
-                    array(
475
-                        'Event.EVT_ID'           => array('IN', $event_ids),
476
-                        'MTP_messenger'    => $this->_current_messenger->name,
477
-                        'MTP_message_type' => $this->_current_message_type->name,
478
-                        'MTP_is_active'    => true,
479
-                    ),
480
-                    'group_by' => 'GRP_ID',
481
-                )
482
-            );
483
-            //store this in the collection if its valid
484
-            if ($message_template_group instanceof EE_Message_Template_Group) {
485
-                $this->_template_collection->add(
486
-                    $message_template_group,
487
-                    $event_ids
488
-                );
489
-            }
490
-        }
491
-        return $message_template_group;
492
-    }
493
-
494
-
495
-    /**
496
-     * Retrieves the global message template group for the current messenger and message type.
497
-     *
498
-     * @return EE_Message_Template_Group|null
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
502
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
503
-     */
504
-    protected function _get_global_message_template_group_for_current_messenger_and_message_type()
505
-    {
506
-        //first check the collection (we use an array with 0 in it to represent global groups).
507
-        $global_message_template_group = $this->_template_collection->get_by_key(
508
-            $this->_template_collection->getKey(
509
-                $this->_current_messenger->name,
510
-                $this->_current_message_type->name,
511
-                array(0)
512
-            )
513
-        );
514
-
515
-        //if we don't have a group lets hit the db.
516
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
517
-            $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518
-                array(
519
-                    array(
520
-                        'MTP_messenger'    => $this->_current_messenger->name,
521
-                        'MTP_message_type' => $this->_current_message_type->name,
522
-                        'MTP_is_active'    => true,
523
-                        'MTP_is_global'    => true,
524
-                    ),
525
-                )
526
-            );
527
-            //if we have a group, add it to the collection.
528
-            if ($global_message_template_group instanceof EE_Message_Template_Group) {
529
-                $this->_template_collection->add(
530
-                    $global_message_template_group,
531
-                    array(0)
532
-                );
533
-            }
534
-        }
535
-        return $global_message_template_group;
536
-    }
537
-
538
-
539
-    /**
540
-     * Returns an array of event ids for all the events within the current data handler.
541
-     *
542
-     * @return array
543
-     */
544
-    protected function _get_event_ids_from_current_data_handler()
545
-    {
546
-        $event_ids = array();
547
-        foreach ($this->_current_data_handler->events as $event) {
548
-            $event_ids[$event['ID']] = $event['ID'];
549
-        }
550
-        return $event_ids;
551
-    }
552
-
553
-
554
-    /**
555
-     *  Retrieves formatted array of template information for each context specific to the given
556
-     *  EE_Message_Template_Group
557
-     *
558
-     * @param EE_Message_Template_Group $message_template_group
559
-     * @return array The returned array is in this structure:
560
-     *                          array(
561
-     *                          'field_name' => array(
562
-     *                          'context' => 'content'
563
-     *                          )
564
-     *                          )
565
-     * @throws EE_Error
566
-     */
567
-    protected function _get_templates(EE_Message_Template_Group $message_template_group)
568
-    {
569
-        $templates         = array();
570
-        $context_templates = $message_template_group->context_templates();
571
-        foreach ($context_templates as $context => $template_fields) {
572
-            foreach ($template_fields as $template_field => $template_obj) {
573
-                if (! $template_obj instanceof EE_Message_Template) {
574
-                    continue;
575
-                }
576
-                $templates[$template_field][$context] = $template_obj->get('MTP_content');
577
-            }
578
-        }
579
-        return $templates;
580
-    }
581
-
582
-
583
-    /**
584
-     * Assembles new fully generated EE_Message objects and adds to _ready_queue
585
-     *
586
-     * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
587
-     *                                               context.
588
-     * @param array                     $templates   formatted array of templates used for parsing data.
589
-     * @param EE_Message_Template_Group $message_template_group
590
-     * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
591
-     *                                               method will attempt to generate ALL EE_Message objects and add to
592
-     *                                               the _ready_queue.  Successfully generated messages get added to the
593
-     *                                               queue with EEM_Message::status_idle, unsuccessfully generated
594
-     *                                               messages will get added to the queue as EEM_Message::status_failed.
595
-     *                                               Very rarely should "false" be returned from this method.
596
-     * @throws EE_Error
597
-     */
598
-    protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
599
-    {
600
-
601
-        //if templates are empty then get out because we can't generate anything.
602
-        if (! $templates) {
603
-            $this->_error_msg[] = esc_html__(
604
-                'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605
-                'event_espresso'
606
-            );
607
-            return false;
608
-        }
609
-
610
-        //We use this as the counter for generated messages because don't forget we may be executing this inside of a
611
-        //generation_queue.  So _ready_queue may have generated EE_Message objects already.
612
-        $generated_count = 0;
613
-        foreach ($addressees as $context => $recipients) {
614
-            foreach ($recipients as $recipient) {
615
-                $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
616
-                if ($message instanceof EE_Message) {
617
-                    $this->_ready_queue->add(
618
-                        $message,
619
-                        array(),
620
-                        $this->_generation_queue->get_message_repository()->is_preview(),
621
-                        $this->_generation_queue->get_message_repository()->is_test_send()
622
-                    );
623
-                    $generated_count++;
624
-                }
625
-
626
-                //if the current MSG being generated is for a test send then we'll only use ONE message in the
627
-                // generation.
628
-                if ($this->_generation_queue->get_message_repository()->is_test_send()) {
629
-                    break 2;
630
-                }
631
-            }
632
-        }
633
-
634
-        //if there are no generated messages then something else fatal went wrong.
635
-        return $generated_count > 0;
636
-    }
637
-
638
-
639
-    /**
640
-     * @param string                    $context   The context for the generated message.
641
-     * @param EE_Messages_Addressee     $recipient
642
-     * @param array                     $templates formatted array of templates used for parsing data.
643
-     * @param EE_Message_Template_Group $message_template_group
644
-     * @return bool|EE_Message
645
-     * @throws EE_Error
646
-     */
647
-    protected function _setup_message_object(
648
-        $context,
649
-        EE_Messages_Addressee $recipient,
650
-        $templates,
651
-        EE_Message_Template_Group $message_template_group
652
-    ) {
653
-        //stuff we already know
654
-        $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
655
-        $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
656
-            ? $this->_current_data_handler->txn->ID()
657
-            : $transaction_id;
658
-        $message_fields = array(
659
-            'GRP_ID'           => $message_template_group->ID(),
660
-            'TXN_ID'           => $transaction_id,
661
-            'MSG_messenger'    => $this->_current_messenger->name,
662
-            'MSG_message_type' => $this->_current_message_type->name,
663
-            'MSG_context'      => $context,
664
-        );
665
-
666
-        //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
667
-        // the info from the att_obj found in the EE_Messages_Addressee object.
668
-        if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
669
-            $message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
670
-                ? $recipient->att_obj->ID()
671
-                : 0;
672
-            $message_fields['MSG_recipient_type'] = 'Attendee';
673
-        } else {
674
-            $message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
675
-            $message_fields['MSG_recipient_type'] = $recipient->recipient_type;
676
-        }
677
-        $message = EE_Message_Factory::create($message_fields);
678
-
679
-        //grab valid shortcodes for shortcode parser
680
-        $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
681
-        $m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
682
-
683
-        //if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
684
-        if ((
685
-                (
686
-                    empty($templates['to'][$context])
687
-                    && ! $this->_current_messenger->allow_empty_to_field()
688
-                )
689
-                || ! $message_template_group->is_context_active($context)
690
-            )
691
-            && ! $this->_generation_queue->get_message_repository()->is_preview()
692
-        ) {
693
-            //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
694
-            //field.
695
-            return false;
696
-        }
697
-        $error_msg = array();
698
-        foreach ($templates as $field => $field_context) {
699
-            $error_msg = array();
700
-            //let's setup the valid shortcodes for the incoming context.
701
-            $valid_shortcodes = $mt_shortcodes[$context];
702
-            //merge in valid shortcodes for the field.
703
-            $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704
-            if (isset($templates[$field][$context])) {
705
-                //prefix field.
706
-                $column_name = 'MSG_' . $field;
707
-                try {
708
-                    $content = $this->_shortcode_parser->parse_message_template(
709
-                        $templates[$field][$context],
710
-                        $recipient,
711
-                        $shortcodes,
712
-                        $this->_current_message_type,
713
-                        $this->_current_messenger,
714
-                        $message
715
-                    );
716
-                    //the model field removes slashes when setting (usually necessary when the input is from the
717
-                    //request) but this value is from another model and has no slashes. So add them so it matchces
718
-                    //what the field expected (otherwise slashes will have been stripped from this an extra time)
719
-                    $message->set_field_or_extra_meta($column_name, addslashes($content));
720
-                } catch (EE_Error $e) {
721
-                    $error_msg[] = sprintf(
722
-                        esc_html__(
723
-                            'There was a problem generating the content for the field %s: %s',
724
-                            'event_espresso'
725
-                        ),
726
-                        $field,
727
-                        $e->getMessage()
728
-                    );
729
-                    $message->set_STS_ID(EEM_Message::status_failed);
730
-                }
731
-            }
732
-        }
733
-
734
-        if ($message->STS_ID() === EEM_Message::status_failed) {
735
-            $error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
736
-                         . "\n"
737
-                         . implode("\n", $error_msg);
738
-            $message->set_error_message($error_msg);
739
-        } else {
740
-            $message->set_STS_ID(EEM_Message::status_idle);
741
-        }
742
-        return $message;
743
-    }
744
-
745
-
746
-    /**
747
-     * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
748
-     * error message if either is missing.
749
-     *
750
-     * @return bool true means there were no errors, false means there were errors.
751
-     * @throws EE_Error
752
-     * @throws ReflectionException
753
-     */
754
-    protected function _verify()
755
-    {
756
-        //reset error message to an empty array.
757
-        $this->_error_msg = array();
758
-        $valid            = true;
759
-        $valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
760
-        $valid            = $valid ? $this->_validate_and_setup_data() : $valid;
761
-
762
-        //set the verified flag so we know everything has been validated.
763
-        $this->_verified = $valid;
764
-
765
-        return $valid;
766
-    }
767
-
768
-
769
-    /**
770
-     * This accepts an array and validates that it is an array indexed by context with each value being an array of
771
-     * EE_Messages_Addressee objects.
772
-     *
773
-     * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
774
-     * @return bool
775
-     */
776
-    protected function _valid_addressees($addressees)
777
-    {
778
-        if (! $addressees || ! is_array($addressees)) {
779
-            return false;
780
-        }
781
-
782
-        foreach ($addressees as $addressee_array) {
783
-            foreach ($addressee_array as $addressee) {
784
-                if (! $addressee instanceof EE_Messages_Addressee) {
785
-                    return false;
786
-                }
787
-            }
788
-        }
789
-        return true;
790
-    }
791
-
792
-
793
-    /**
794
-     * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
795
-     * queue. This process sets error messages if something is wrong.
796
-     *
797
-     * @return bool   true is if there are no errors.  false is if there is.
798
-     */
799
-    protected function _validate_messenger_and_message_type()
800
-    {
801
-
802
-        //first are there any existing error messages?  If so then return.
803
-        if ($this->_error_msg) {
804
-            return false;
805
-        }
806
-        /** @type EE_Message $message */
807
-        $message = $this->_generation_queue->get_message_repository()->current();
808
-        try {
809
-            $this->_current_messenger = $message->valid_messenger(true)
810
-                ? $message->messenger_object()
811
-                : null;
812
-        } catch (Exception $e) {
813
-            $this->_error_msg[] = $e->getMessage();
814
-        }
815
-        try {
816
-            $this->_current_message_type = $message->valid_message_type(true)
817
-                ? $message->message_type_object()
818
-                : null;
819
-        } catch (Exception $e) {
820
-            $this->_error_msg[] = $e->getMessage();
821
-        }
822
-
823
-        /**
824
-         * Check if there is any generation data, but only if this is not for a preview.
825
-         */
826
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
827
-            && (
828
-                ! $this->_generation_queue->get_message_repository()->is_preview()
829
-                && $this->_generation_queue->get_message_repository()->get_data_handler()
830
-                   !== 'EE_Messages_Preview_incoming_data'
831
-            )
832
-        ) {
833
-            $this->_error_msg[] = esc_html__(
834
-                'There is no generation data for this message. Unable to generate.',
835
-                'event_espresso'
836
-            );
837
-        }
838
-
839
-        return empty($this->_error_msg);
840
-    }
841
-
842
-
843
-    /**
844
-     * This method retrieves the expected data handler for the message type and validates the generation data for that
845
-     * data handler.
846
-     *
847
-     * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
848
-     * @throws EE_Error
849
-     * @throws ReflectionException
850
-     */
851
-    protected function _validate_and_setup_data()
852
-    {
853
-
854
-        //First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
855
-        //be used anyways.
856
-        if ($this->_error_msg) {
857
-            return false;
858
-        }
859
-
860
-        $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
861
-
862
-        /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
863
-        $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
864
-            ? $this->_generation_queue->get_message_repository()->get_data_handler()
865
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
866
-
867
-        //If this EE_Message is for a preview, then let's switch out to the preview data handler.
868
-        if ($this->_generation_queue->get_message_repository()->is_preview()) {
869
-            $data_handler_class_name = 'EE_Messages_Preview_incoming_data';
870
-        }
871
-
872
-        //First get the class name for the data handler (and also verifies it exists.
873
-        if (! class_exists($data_handler_class_name)) {
874
-            $this->_error_msg[] = sprintf(
875
-                esc_html__(
876
-                    'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
877
-                    'event_espresso'
878
-                ),
879
-                'EE_Messages_incoming_data',
880
-                $data_handler_class_name
881
-            );
882
-            return false;
883
-        }
884
-
885
-        //convert generation_data for data_handler_instantiation.
886
-        $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
887
-
888
-        //note, this may set error messages as well.
889
-        $this->_set_data_handler($generation_data, $data_handler_class_name);
890
-
891
-        return empty($this->_error_msg);
892
-    }
893
-
894
-
895
-    /**
896
-     * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
897
-     * adds it to the _data repository.
898
-     *
899
-     * @param mixed  $generating_data           This is data expected by the instantiated data handler.
900
-     * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
901
-     *                                          instantiated.
902
-     * @return void .
903
-     * @throws EE_Error
904
-     * @throws ReflectionException
905
-     */
906
-    protected function _set_data_handler($generating_data, $data_handler_class_name)
907
-    {
908
-        //valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
909
-        //is already a ready data handler in the repository.
910
-        $this->_current_data_handler = $this->_data_handler_collection->get_by_key(
911
-            $this->_data_handler_collection->get_key(
912
-                $data_handler_class_name,
913
-                $generating_data
914
-            )
915
-        );
916
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
917
-            //no saved data_handler in the repo so let's set one up and add it to the repo.
918
-            try {
919
-                $this->_current_data_handler = new $data_handler_class_name($generating_data);
920
-                $this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
921
-            } catch (EE_Error $e) {
922
-                $this->_error_msg[] = $e->get_error();
923
-            }
924
-        }
925
-    }
926
-
927
-
928
-    /**
929
-     * The queued EE_Message for generation does not save the data used for generation as objects
930
-     * because serialization of those objects could be problematic if the data is saved to the db.
931
-     * So this method calls the static method on the associated data_handler for the given message_type
932
-     * and that preps the data for later instantiation when generating.
933
-     *
934
-     * @param EE_Message_To_Generate $message_to_generate
935
-     * @param bool                   $preview Indicate whether this is being used for a preview or not.
936
-     * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
937
-     */
938
-    protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
939
-    {
940
-        /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
941
-        $data_handler = $message_to_generate->get_data_handler_class_name($preview);
942
-        if (! $message_to_generate->valid()) {
943
-            return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
944
-        }
945
-        return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
946
-    }
947
-
948
-
949
-    /**
950
-     * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
951
-     *
952
-     * @param EE_Message_To_Generate $message_to_generate
953
-     * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
954
-     * @throws InvalidArgumentException
955
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
956
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
957
-     */
958
-    public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
959
-    {
960
-        //prep data
961
-        $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
962
-
963
-        $message = $message_to_generate->get_EE_Message();
964
-
965
-        //is there a GRP_ID in the request?
966
-        if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
967
-            $message->set_GRP_ID($GRP_ID);
968
-        }
969
-
970
-        if ($data === false) {
971
-            $message->set_STS_ID(EEM_Message::status_failed);
972
-            $message->set_error_message(
973
-                esc_html__(
974
-                    'Unable to prepare data for persistence to the database.',
975
-                    'event_espresso'
976
-                )
977
-            );
978
-        } else {
979
-            //make sure that the data handler is cached on the message as well
980
-            $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
981
-        }
982
-
983
-        $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
984
-    }
16
+	/**
17
+	 * @type EE_Messages_Data_Handler_Collection
18
+	 */
19
+	protected $_data_handler_collection;
20
+
21
+	/**
22
+	 * @type  EE_Message_Template_Group_Collection
23
+	 */
24
+	protected $_template_collection;
25
+
26
+	/**
27
+	 * This will hold the data handler for the current EE_Message being generated.
28
+	 *
29
+	 * @type EE_Messages_incoming_data
30
+	 */
31
+	protected $_current_data_handler;
32
+
33
+	/**
34
+	 * This holds the EE_Messages_Queue that contains the messages to generate.
35
+	 *
36
+	 * @type EE_Messages_Queue
37
+	 */
38
+	protected $_generation_queue;
39
+
40
+	/**
41
+	 * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
+	 *
43
+	 * @type EE_Messages_Queue
44
+	 */
45
+	protected $_ready_queue;
46
+
47
+	/**
48
+	 * This is a container for any error messages that get created through the generation
49
+	 * process.
50
+	 *
51
+	 * @type array
52
+	 */
53
+	protected $_error_msg = array();
54
+
55
+	/**
56
+	 * Flag used to set when the current EE_Message in the generation queue has been verified.
57
+	 *
58
+	 * @type bool
59
+	 */
60
+	protected $_verified = false;
61
+
62
+	/**
63
+	 * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
+	 *
65
+	 * @type EE_messenger
66
+	 */
67
+	protected $_current_messenger;
68
+
69
+	/**
70
+	 * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
+	 *
72
+	 * @type EE_message_type
73
+	 */
74
+	protected $_current_message_type;
75
+
76
+	/**
77
+	 * @type EEH_Parse_Shortcodes
78
+	 */
79
+	protected $_shortcode_parser;
80
+
81
+
82
+	/**
83
+	 * @param EE_Messages_Queue                     $generation_queue
84
+	 * @param \EE_Messages_Queue                    $ready_queue
85
+	 * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
+	 * @param \EE_Message_Template_Group_Collection $template_collection
87
+	 * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
+	 */
89
+	public function __construct(
90
+		EE_Messages_Queue $generation_queue,
91
+		EE_Messages_Queue $ready_queue,
92
+		EE_Messages_Data_Handler_Collection $data_handler_collection,
93
+		EE_Message_Template_Group_Collection $template_collection,
94
+		EEH_Parse_Shortcodes $shortcode_parser
95
+	) {
96
+		$this->_generation_queue        = $generation_queue;
97
+		$this->_ready_queue             = $ready_queue;
98
+		$this->_data_handler_collection = $data_handler_collection;
99
+		$this->_template_collection     = $template_collection;
100
+		$this->_shortcode_parser        = $shortcode_parser;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return EE_Messages_Queue
106
+	 */
107
+	public function generation_queue()
108
+	{
109
+		return $this->_generation_queue;
110
+	}
111
+
112
+
113
+	/**
114
+	 *  This iterates through the provided queue and generates the EE_Message objects.
115
+	 *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
+	 *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
+	 *  for the caller to decide what to do with it.
118
+	 *
119
+	 * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
+	 * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public function generate($save = true)
125
+	{
126
+		//iterate through the messages in the queue, generate, and add to new queue.
127
+		$this->_generation_queue->get_message_repository()->rewind();
128
+		while ($this->_generation_queue->get_message_repository()->valid()) {
129
+			//reset "current" properties
130
+			$this->_reset_current_properties();
131
+
132
+			/** @type EE_Message $msg */
133
+			$msg = $this->_generation_queue->get_message_repository()->current();
134
+
135
+			/**
136
+			 * need to get the next object and capture it for setting manually after deletes.  The reason is that when
137
+			 * an object is removed from the repo then valid for the next object will fail.
138
+			 */
139
+			$this->_generation_queue->get_message_repository()->next();
140
+			$next_msg = $this->_generation_queue->get_message_repository()->current();
141
+			//restore pointer to current item
142
+			$this->_generation_queue->get_message_repository()->set_current($msg);
143
+
144
+			//skip and delete if the current $msg is NOT incomplete (queued for generation)
145
+			if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
146
+				//we keep this item in the db just remove from the repo.
147
+				$this->_generation_queue->get_message_repository()->remove($msg);
148
+				//next item
149
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
150
+				continue;
151
+			}
152
+
153
+			if ($this->_verify()) {
154
+				//let's get generating!
155
+				$this->_generate();
156
+			}
157
+
158
+			//don't persist debug_only messages if the messages system is not in debug mode.
159
+			if ($msg->STS_ID() === EEM_Message::status_debug_only
160
+				&& ! EEM_Message::debug()
161
+			) {
162
+				do_action(
163
+					'AHEE__EE_Messages_Generator__generate__before_debug_delete',
164
+					$msg,
165
+					$this->_error_msg,
166
+					$this->_current_messenger,
167
+					$this->_current_message_type,
168
+					$this->_current_data_handler
169
+				);
170
+				$this->_generation_queue->get_message_repository()->delete();
171
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
172
+				continue;
173
+			}
174
+
175
+			//if there are error messages then let's set the status and the error message.
176
+			if ($this->_error_msg) {
177
+				//if the status is already debug only, then let's leave it at that.
178
+				if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
179
+					$msg->set_STS_ID(EEM_Message::status_failed);
180
+				}
181
+				do_action(
182
+					'AHEE__EE_Messages_Generator__generate__processing_failed_message',
183
+					$msg,
184
+					$this->_error_msg,
185
+					$this->_current_messenger,
186
+					$this->_current_message_type,
187
+					$this->_current_data_handler
188
+				);
189
+				$msg->set_error_message(
190
+					esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
191
+					. "\n"
192
+					. implode("\n", $this->_error_msg)
193
+				);
194
+				$msg->set_modified(time());
195
+			} else {
196
+				do_action(
197
+					'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
198
+					$msg,
199
+					$this->_error_msg,
200
+					$this->_current_messenger,
201
+					$this->_current_message_type,
202
+					$this->_current_data_handler
203
+				);
204
+				//remove from db
205
+				$this->_generation_queue->get_message_repository()->delete();
206
+			}
207
+			//next item
208
+			$this->_generation_queue->get_message_repository()->set_current($next_msg);
209
+		}
210
+
211
+		//generation queue is ALWAYS saved to record any errors in the generation process.
212
+		$this->_generation_queue->save();
213
+
214
+		/**
215
+		 * save _ready_queue if flag set.
216
+		 * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
217
+		 * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
218
+		 * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
219
+		 * irrelevant.
220
+		 */
221
+		if ($save) {
222
+			$this->_ready_queue->save();
223
+		}
224
+
225
+		//final reset of properties
226
+		$this->_reset_current_properties();
227
+
228
+		return $this->_ready_queue;
229
+	}
230
+
231
+
232
+	/**
233
+	 * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
234
+	 * in the generation queue.
235
+	 */
236
+	protected function _reset_current_properties()
237
+	{
238
+		$this->_verified = false;
239
+		//make sure any _data value in the current message type is reset
240
+		if ($this->_current_message_type instanceof EE_message_type) {
241
+			$this->_current_message_type->reset_data();
242
+		}
243
+		$this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
244
+	}
245
+
246
+
247
+	/**
248
+	 * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
249
+	 * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
250
+	 * _generating_queue.
251
+	 *
252
+	 * @return bool Whether the message was successfully generated or not.
253
+	 * @throws EE_Error
254
+	 * @throws InvalidArgumentException
255
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
+	 */
258
+	protected function _generate()
259
+	{
260
+		//double check verification has run and that everything is ready to work with (saves us having to validate
261
+		// everything again).
262
+		if (! $this->_verified) {
263
+			return false; //get out because we don't have a valid setup to work with.
264
+		}
265
+
266
+
267
+		try {
268
+			$addressees = $this->_current_message_type->get_addressees(
269
+				$this->_current_data_handler,
270
+				$this->_generation_queue->get_message_repository()->current()->context()
271
+			);
272
+		} catch (EE_Error $e) {
273
+			$this->_error_msg[] = $e->getMessage();
274
+			return false;
275
+		}
276
+
277
+
278
+		//if no addressees then get out because there is nothing to generation (possible bad data).
279
+		if (! $this->_valid_addressees($addressees)) {
280
+			do_action(
281
+				'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282
+				$this->_generation_queue->get_message_repository()->current(),
283
+				$addressees,
284
+				$this->_current_messenger,
285
+				$this->_current_message_type,
286
+				$this->_current_data_handler
287
+			);
288
+			$this->_generation_queue->get_message_repository()->current()->set_STS_ID(
289
+				EEM_Message::status_debug_only
290
+			);
291
+			$this->_error_msg[] = esc_html__(
292
+				'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
293
+				'event_espresso'
294
+			);
295
+			return false;
296
+		}
297
+
298
+		$message_template_group = $this->_get_message_template_group();
299
+
300
+		//in the unlikely event there is no EE_Message_Template_Group available, get out!
301
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
302
+			$this->_error_msg[] = esc_html__(
303
+				'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304
+				'event_espresso'
305
+			);
306
+			return false;
307
+		}
308
+
309
+		//get formatted templates for using to parse and setup EE_Message objects.
310
+		$templates = $this->_get_templates($message_template_group);
311
+
312
+
313
+		//setup new EE_Message objects (and add to _ready_queue)
314
+		return $this->_assemble_messages($addressees, $templates, $message_template_group);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Retrieves the message template group being used for generating messages.
320
+	 * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
321
+	 *
322
+	 * @return EE_Message_Template_Group|null
323
+	 * @throws EE_Error
324
+	 * @throws InvalidArgumentException
325
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
326
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
327
+	 */
328
+	protected function _get_message_template_group()
329
+	{
330
+		//first see if there is a specific message template group requested (current message in the queue has a specific
331
+		//GRP_ID
332
+		$message_template_group = $this->_specific_message_template_group_from_queue();
333
+		if ($message_template_group instanceof EE_Message_Template_Group) {
334
+			return $message_template_group;
335
+		}
336
+
337
+		//get event_ids from the datahandler so we can check to see if there's already a message template group for them
338
+		//in the collection.
339
+		$event_ids              = $this->_get_event_ids_from_current_data_handler();
340
+		$message_template_group = $this->_template_collection->get_by_key(
341
+			$this->_template_collection->getKey(
342
+				$this->_current_messenger->name,
343
+				$this->_current_message_type->name,
344
+				$event_ids
345
+			)
346
+		);
347
+
348
+		//if we have a message template group then no need to hit the database, just return it.
349
+		if ($message_template_group instanceof EE_Message_Template_Group) {
350
+			return $message_template_group;
351
+		}
352
+
353
+		//okay made it here, so let's get the global group first for this messenger and message type to ensure
354
+		//there is no override set.
355
+		$global_message_template_group =
356
+			$this->_get_global_message_template_group_for_current_messenger_and_message_type();
357
+
358
+		if ($global_message_template_group instanceof EE_Message_Template_Group
359
+			&& $global_message_template_group->get('MTP_is_override')
360
+		) {
361
+			return $global_message_template_group;
362
+		}
363
+
364
+		//if we're still here, that means there was no message template group for the events in the collection and
365
+		//the global message template group for the messenger and message type is not set for override.  So next step is
366
+		//to see if there is a common shared custom message template group for this set of events.
367
+		$message_template_group = $this->_get_shared_message_template_for_events($event_ids);
368
+		if ($message_template_group instanceof EE_Message_Template_Group) {
369
+			return $message_template_group;
370
+		}
371
+
372
+		//STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
373
+		//So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
374
+		//and return it.
375
+		if ($global_message_template_group instanceof EE_Message_Template_Group) {
376
+			$this->_template_collection->add(
377
+				$global_message_template_group,
378
+				$event_ids
379
+			);
380
+			return $global_message_template_group;
381
+		}
382
+
383
+		//if we land here that means there's NO active message template group for this set.
384
+		//TODO this will be a good target for some optimization down the road.  Whenever there is no active message
385
+		//template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
386
+		//this should likely bit hit rarely enough that it's not a significant issue.
387
+		return null;
388
+	}
389
+
390
+
391
+	/**
392
+	 * This checks the current message in the queue and determines if there is a specific Message Template Group
393
+	 * requested for that message.
394
+	 *
395
+	 * @return EE_Message_Template_Group|null
396
+	 * @throws EE_Error
397
+	 * @throws InvalidArgumentException
398
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
399
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
400
+	 */
401
+	protected function _specific_message_template_group_from_queue()
402
+	{
403
+		//is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
404
+		//so let's use that.
405
+		$GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
406
+
407
+		if ($GRP_ID) {
408
+			//attempt to retrieve from repo first
409
+			$message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410
+			if ($message_template_group instanceof EE_Message_Template_Group) {
411
+				return $message_template_group;  //got it!
412
+			}
413
+
414
+			//nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
415
+			//is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
416
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
417
+			if ($message_template_group instanceof EE_Message_Template_Group) {
418
+				$this->_template_collection->add($message_template_group);
419
+				return $message_template_group;
420
+			}
421
+		}
422
+		return null;
423
+	}
424
+
425
+
426
+	/**
427
+	 * Returns whether the event ids passed in all share the same message template group for the current message type
428
+	 * and messenger.
429
+	 *
430
+	 * @param array $event_ids
431
+	 * @return bool true means they DO share the same message template group, false means they don't.
432
+	 * @throws EE_Error
433
+	 * @throws InvalidArgumentException
434
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
+	 */
437
+	protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
438
+	{
439
+		foreach ($this->_current_data_handler->events as $event) {
440
+			$event_ids[$event['ID']] = $event['ID'];
441
+		}
442
+		$count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
443
+			array(
444
+				array(
445
+					'Event.EVT_ID'           => array('IN', $event_ids),
446
+					'MTP_messenger'    => $this->_current_messenger->name,
447
+					'MTP_message_type' => $this->_current_message_type->name,
448
+				),
449
+			),
450
+			'GRP_ID',
451
+			true
452
+		);
453
+		return $count_of_message_template_groups === 1;
454
+	}
455
+
456
+
457
+	/**
458
+	 * This will get the shared message template group for events that are in the current data handler but ONLY if
459
+	 * there's a single shared message template group among all the events.  Otherwise it returns null.
460
+	 *
461
+	 * @param array $event_ids
462
+	 * @return EE_Message_Template_Group|null
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
466
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
467
+	 */
468
+	protected function _get_shared_message_template_for_events(array $event_ids)
469
+	{
470
+		$message_template_group = null;
471
+		if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
472
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one(
473
+				array(
474
+					array(
475
+						'Event.EVT_ID'           => array('IN', $event_ids),
476
+						'MTP_messenger'    => $this->_current_messenger->name,
477
+						'MTP_message_type' => $this->_current_message_type->name,
478
+						'MTP_is_active'    => true,
479
+					),
480
+					'group_by' => 'GRP_ID',
481
+				)
482
+			);
483
+			//store this in the collection if its valid
484
+			if ($message_template_group instanceof EE_Message_Template_Group) {
485
+				$this->_template_collection->add(
486
+					$message_template_group,
487
+					$event_ids
488
+				);
489
+			}
490
+		}
491
+		return $message_template_group;
492
+	}
493
+
494
+
495
+	/**
496
+	 * Retrieves the global message template group for the current messenger and message type.
497
+	 *
498
+	 * @return EE_Message_Template_Group|null
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
502
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
503
+	 */
504
+	protected function _get_global_message_template_group_for_current_messenger_and_message_type()
505
+	{
506
+		//first check the collection (we use an array with 0 in it to represent global groups).
507
+		$global_message_template_group = $this->_template_collection->get_by_key(
508
+			$this->_template_collection->getKey(
509
+				$this->_current_messenger->name,
510
+				$this->_current_message_type->name,
511
+				array(0)
512
+			)
513
+		);
514
+
515
+		//if we don't have a group lets hit the db.
516
+		if (! $global_message_template_group instanceof EE_Message_Template_Group) {
517
+			$global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518
+				array(
519
+					array(
520
+						'MTP_messenger'    => $this->_current_messenger->name,
521
+						'MTP_message_type' => $this->_current_message_type->name,
522
+						'MTP_is_active'    => true,
523
+						'MTP_is_global'    => true,
524
+					),
525
+				)
526
+			);
527
+			//if we have a group, add it to the collection.
528
+			if ($global_message_template_group instanceof EE_Message_Template_Group) {
529
+				$this->_template_collection->add(
530
+					$global_message_template_group,
531
+					array(0)
532
+				);
533
+			}
534
+		}
535
+		return $global_message_template_group;
536
+	}
537
+
538
+
539
+	/**
540
+	 * Returns an array of event ids for all the events within the current data handler.
541
+	 *
542
+	 * @return array
543
+	 */
544
+	protected function _get_event_ids_from_current_data_handler()
545
+	{
546
+		$event_ids = array();
547
+		foreach ($this->_current_data_handler->events as $event) {
548
+			$event_ids[$event['ID']] = $event['ID'];
549
+		}
550
+		return $event_ids;
551
+	}
552
+
553
+
554
+	/**
555
+	 *  Retrieves formatted array of template information for each context specific to the given
556
+	 *  EE_Message_Template_Group
557
+	 *
558
+	 * @param EE_Message_Template_Group $message_template_group
559
+	 * @return array The returned array is in this structure:
560
+	 *                          array(
561
+	 *                          'field_name' => array(
562
+	 *                          'context' => 'content'
563
+	 *                          )
564
+	 *                          )
565
+	 * @throws EE_Error
566
+	 */
567
+	protected function _get_templates(EE_Message_Template_Group $message_template_group)
568
+	{
569
+		$templates         = array();
570
+		$context_templates = $message_template_group->context_templates();
571
+		foreach ($context_templates as $context => $template_fields) {
572
+			foreach ($template_fields as $template_field => $template_obj) {
573
+				if (! $template_obj instanceof EE_Message_Template) {
574
+					continue;
575
+				}
576
+				$templates[$template_field][$context] = $template_obj->get('MTP_content');
577
+			}
578
+		}
579
+		return $templates;
580
+	}
581
+
582
+
583
+	/**
584
+	 * Assembles new fully generated EE_Message objects and adds to _ready_queue
585
+	 *
586
+	 * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
587
+	 *                                               context.
588
+	 * @param array                     $templates   formatted array of templates used for parsing data.
589
+	 * @param EE_Message_Template_Group $message_template_group
590
+	 * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
591
+	 *                                               method will attempt to generate ALL EE_Message objects and add to
592
+	 *                                               the _ready_queue.  Successfully generated messages get added to the
593
+	 *                                               queue with EEM_Message::status_idle, unsuccessfully generated
594
+	 *                                               messages will get added to the queue as EEM_Message::status_failed.
595
+	 *                                               Very rarely should "false" be returned from this method.
596
+	 * @throws EE_Error
597
+	 */
598
+	protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
599
+	{
600
+
601
+		//if templates are empty then get out because we can't generate anything.
602
+		if (! $templates) {
603
+			$this->_error_msg[] = esc_html__(
604
+				'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605
+				'event_espresso'
606
+			);
607
+			return false;
608
+		}
609
+
610
+		//We use this as the counter for generated messages because don't forget we may be executing this inside of a
611
+		//generation_queue.  So _ready_queue may have generated EE_Message objects already.
612
+		$generated_count = 0;
613
+		foreach ($addressees as $context => $recipients) {
614
+			foreach ($recipients as $recipient) {
615
+				$message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
616
+				if ($message instanceof EE_Message) {
617
+					$this->_ready_queue->add(
618
+						$message,
619
+						array(),
620
+						$this->_generation_queue->get_message_repository()->is_preview(),
621
+						$this->_generation_queue->get_message_repository()->is_test_send()
622
+					);
623
+					$generated_count++;
624
+				}
625
+
626
+				//if the current MSG being generated is for a test send then we'll only use ONE message in the
627
+				// generation.
628
+				if ($this->_generation_queue->get_message_repository()->is_test_send()) {
629
+					break 2;
630
+				}
631
+			}
632
+		}
633
+
634
+		//if there are no generated messages then something else fatal went wrong.
635
+		return $generated_count > 0;
636
+	}
637
+
638
+
639
+	/**
640
+	 * @param string                    $context   The context for the generated message.
641
+	 * @param EE_Messages_Addressee     $recipient
642
+	 * @param array                     $templates formatted array of templates used for parsing data.
643
+	 * @param EE_Message_Template_Group $message_template_group
644
+	 * @return bool|EE_Message
645
+	 * @throws EE_Error
646
+	 */
647
+	protected function _setup_message_object(
648
+		$context,
649
+		EE_Messages_Addressee $recipient,
650
+		$templates,
651
+		EE_Message_Template_Group $message_template_group
652
+	) {
653
+		//stuff we already know
654
+		$transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
655
+		$transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
656
+			? $this->_current_data_handler->txn->ID()
657
+			: $transaction_id;
658
+		$message_fields = array(
659
+			'GRP_ID'           => $message_template_group->ID(),
660
+			'TXN_ID'           => $transaction_id,
661
+			'MSG_messenger'    => $this->_current_messenger->name,
662
+			'MSG_message_type' => $this->_current_message_type->name,
663
+			'MSG_context'      => $context,
664
+		);
665
+
666
+		//recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
667
+		// the info from the att_obj found in the EE_Messages_Addressee object.
668
+		if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
669
+			$message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
670
+				? $recipient->att_obj->ID()
671
+				: 0;
672
+			$message_fields['MSG_recipient_type'] = 'Attendee';
673
+		} else {
674
+			$message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
675
+			$message_fields['MSG_recipient_type'] = $recipient->recipient_type;
676
+		}
677
+		$message = EE_Message_Factory::create($message_fields);
678
+
679
+		//grab valid shortcodes for shortcode parser
680
+		$mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
681
+		$m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
682
+
683
+		//if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
684
+		if ((
685
+				(
686
+					empty($templates['to'][$context])
687
+					&& ! $this->_current_messenger->allow_empty_to_field()
688
+				)
689
+				|| ! $message_template_group->is_context_active($context)
690
+			)
691
+			&& ! $this->_generation_queue->get_message_repository()->is_preview()
692
+		) {
693
+			//we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
694
+			//field.
695
+			return false;
696
+		}
697
+		$error_msg = array();
698
+		foreach ($templates as $field => $field_context) {
699
+			$error_msg = array();
700
+			//let's setup the valid shortcodes for the incoming context.
701
+			$valid_shortcodes = $mt_shortcodes[$context];
702
+			//merge in valid shortcodes for the field.
703
+			$shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704
+			if (isset($templates[$field][$context])) {
705
+				//prefix field.
706
+				$column_name = 'MSG_' . $field;
707
+				try {
708
+					$content = $this->_shortcode_parser->parse_message_template(
709
+						$templates[$field][$context],
710
+						$recipient,
711
+						$shortcodes,
712
+						$this->_current_message_type,
713
+						$this->_current_messenger,
714
+						$message
715
+					);
716
+					//the model field removes slashes when setting (usually necessary when the input is from the
717
+					//request) but this value is from another model and has no slashes. So add them so it matchces
718
+					//what the field expected (otherwise slashes will have been stripped from this an extra time)
719
+					$message->set_field_or_extra_meta($column_name, addslashes($content));
720
+				} catch (EE_Error $e) {
721
+					$error_msg[] = sprintf(
722
+						esc_html__(
723
+							'There was a problem generating the content for the field %s: %s',
724
+							'event_espresso'
725
+						),
726
+						$field,
727
+						$e->getMessage()
728
+					);
729
+					$message->set_STS_ID(EEM_Message::status_failed);
730
+				}
731
+			}
732
+		}
733
+
734
+		if ($message->STS_ID() === EEM_Message::status_failed) {
735
+			$error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
736
+						 . "\n"
737
+						 . implode("\n", $error_msg);
738
+			$message->set_error_message($error_msg);
739
+		} else {
740
+			$message->set_STS_ID(EEM_Message::status_idle);
741
+		}
742
+		return $message;
743
+	}
744
+
745
+
746
+	/**
747
+	 * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
748
+	 * error message if either is missing.
749
+	 *
750
+	 * @return bool true means there were no errors, false means there were errors.
751
+	 * @throws EE_Error
752
+	 * @throws ReflectionException
753
+	 */
754
+	protected function _verify()
755
+	{
756
+		//reset error message to an empty array.
757
+		$this->_error_msg = array();
758
+		$valid            = true;
759
+		$valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
760
+		$valid            = $valid ? $this->_validate_and_setup_data() : $valid;
761
+
762
+		//set the verified flag so we know everything has been validated.
763
+		$this->_verified = $valid;
764
+
765
+		return $valid;
766
+	}
767
+
768
+
769
+	/**
770
+	 * This accepts an array and validates that it is an array indexed by context with each value being an array of
771
+	 * EE_Messages_Addressee objects.
772
+	 *
773
+	 * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
774
+	 * @return bool
775
+	 */
776
+	protected function _valid_addressees($addressees)
777
+	{
778
+		if (! $addressees || ! is_array($addressees)) {
779
+			return false;
780
+		}
781
+
782
+		foreach ($addressees as $addressee_array) {
783
+			foreach ($addressee_array as $addressee) {
784
+				if (! $addressee instanceof EE_Messages_Addressee) {
785
+					return false;
786
+				}
787
+			}
788
+		}
789
+		return true;
790
+	}
791
+
792
+
793
+	/**
794
+	 * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
795
+	 * queue. This process sets error messages if something is wrong.
796
+	 *
797
+	 * @return bool   true is if there are no errors.  false is if there is.
798
+	 */
799
+	protected function _validate_messenger_and_message_type()
800
+	{
801
+
802
+		//first are there any existing error messages?  If so then return.
803
+		if ($this->_error_msg) {
804
+			return false;
805
+		}
806
+		/** @type EE_Message $message */
807
+		$message = $this->_generation_queue->get_message_repository()->current();
808
+		try {
809
+			$this->_current_messenger = $message->valid_messenger(true)
810
+				? $message->messenger_object()
811
+				: null;
812
+		} catch (Exception $e) {
813
+			$this->_error_msg[] = $e->getMessage();
814
+		}
815
+		try {
816
+			$this->_current_message_type = $message->valid_message_type(true)
817
+				? $message->message_type_object()
818
+				: null;
819
+		} catch (Exception $e) {
820
+			$this->_error_msg[] = $e->getMessage();
821
+		}
822
+
823
+		/**
824
+		 * Check if there is any generation data, but only if this is not for a preview.
825
+		 */
826
+		if (! $this->_generation_queue->get_message_repository()->get_generation_data()
827
+			&& (
828
+				! $this->_generation_queue->get_message_repository()->is_preview()
829
+				&& $this->_generation_queue->get_message_repository()->get_data_handler()
830
+				   !== 'EE_Messages_Preview_incoming_data'
831
+			)
832
+		) {
833
+			$this->_error_msg[] = esc_html__(
834
+				'There is no generation data for this message. Unable to generate.',
835
+				'event_espresso'
836
+			);
837
+		}
838
+
839
+		return empty($this->_error_msg);
840
+	}
841
+
842
+
843
+	/**
844
+	 * This method retrieves the expected data handler for the message type and validates the generation data for that
845
+	 * data handler.
846
+	 *
847
+	 * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
848
+	 * @throws EE_Error
849
+	 * @throws ReflectionException
850
+	 */
851
+	protected function _validate_and_setup_data()
852
+	{
853
+
854
+		//First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
855
+		//be used anyways.
856
+		if ($this->_error_msg) {
857
+			return false;
858
+		}
859
+
860
+		$generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
861
+
862
+		/** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
863
+		$data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
864
+			? $this->_generation_queue->get_message_repository()->get_data_handler()
865
+			: 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
866
+
867
+		//If this EE_Message is for a preview, then let's switch out to the preview data handler.
868
+		if ($this->_generation_queue->get_message_repository()->is_preview()) {
869
+			$data_handler_class_name = 'EE_Messages_Preview_incoming_data';
870
+		}
871
+
872
+		//First get the class name for the data handler (and also verifies it exists.
873
+		if (! class_exists($data_handler_class_name)) {
874
+			$this->_error_msg[] = sprintf(
875
+				esc_html__(
876
+					'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
877
+					'event_espresso'
878
+				),
879
+				'EE_Messages_incoming_data',
880
+				$data_handler_class_name
881
+			);
882
+			return false;
883
+		}
884
+
885
+		//convert generation_data for data_handler_instantiation.
886
+		$generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
887
+
888
+		//note, this may set error messages as well.
889
+		$this->_set_data_handler($generation_data, $data_handler_class_name);
890
+
891
+		return empty($this->_error_msg);
892
+	}
893
+
894
+
895
+	/**
896
+	 * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
897
+	 * adds it to the _data repository.
898
+	 *
899
+	 * @param mixed  $generating_data           This is data expected by the instantiated data handler.
900
+	 * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
901
+	 *                                          instantiated.
902
+	 * @return void .
903
+	 * @throws EE_Error
904
+	 * @throws ReflectionException
905
+	 */
906
+	protected function _set_data_handler($generating_data, $data_handler_class_name)
907
+	{
908
+		//valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
909
+		//is already a ready data handler in the repository.
910
+		$this->_current_data_handler = $this->_data_handler_collection->get_by_key(
911
+			$this->_data_handler_collection->get_key(
912
+				$data_handler_class_name,
913
+				$generating_data
914
+			)
915
+		);
916
+		if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
917
+			//no saved data_handler in the repo so let's set one up and add it to the repo.
918
+			try {
919
+				$this->_current_data_handler = new $data_handler_class_name($generating_data);
920
+				$this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
921
+			} catch (EE_Error $e) {
922
+				$this->_error_msg[] = $e->get_error();
923
+			}
924
+		}
925
+	}
926
+
927
+
928
+	/**
929
+	 * The queued EE_Message for generation does not save the data used for generation as objects
930
+	 * because serialization of those objects could be problematic if the data is saved to the db.
931
+	 * So this method calls the static method on the associated data_handler for the given message_type
932
+	 * and that preps the data for later instantiation when generating.
933
+	 *
934
+	 * @param EE_Message_To_Generate $message_to_generate
935
+	 * @param bool                   $preview Indicate whether this is being used for a preview or not.
936
+	 * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
937
+	 */
938
+	protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
939
+	{
940
+		/** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
941
+		$data_handler = $message_to_generate->get_data_handler_class_name($preview);
942
+		if (! $message_to_generate->valid()) {
943
+			return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
944
+		}
945
+		return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
946
+	}
947
+
948
+
949
+	/**
950
+	 * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
951
+	 *
952
+	 * @param EE_Message_To_Generate $message_to_generate
953
+	 * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
954
+	 * @throws InvalidArgumentException
955
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
956
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
957
+	 */
958
+	public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
959
+	{
960
+		//prep data
961
+		$data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
962
+
963
+		$message = $message_to_generate->get_EE_Message();
964
+
965
+		//is there a GRP_ID in the request?
966
+		if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
967
+			$message->set_GRP_ID($GRP_ID);
968
+		}
969
+
970
+		if ($data === false) {
971
+			$message->set_STS_ID(EEM_Message::status_failed);
972
+			$message->set_error_message(
973
+				esc_html__(
974
+					'Unable to prepare data for persistence to the database.',
975
+					'event_espresso'
976
+				)
977
+			);
978
+		} else {
979
+			//make sure that the data handler is cached on the message as well
980
+			$data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
981
+		}
982
+
983
+		$this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
984
+	}
985 985
 }
Please login to merge, or discard this patch.