Completed
Branch FET-10766-extract-activation-d... (2c1e01)
by
unknown
84:57 queued 73:57
created
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +3632 added lines, -3632 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('NO direct script access allowed');
2
+	exit('NO direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -17,2222 +17,2222 @@  discard block
 block discarded – undo
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19 19
     
20
-    /**
21
-     * @type EE_Message_Resource_Manager $_message_resource_manager
22
-     */
23
-    protected $_message_resource_manager;
24
-    
25
-    /**
26
-     * @type string $_active_message_type_name
27
-     */
28
-    protected $_active_message_type_name = '';
29
-    
30
-    /**
31
-     * @type EE_messenger $_active_messenger
32
-     */
33
-    protected $_active_messenger;
34
-    protected $_activate_state;
35
-    protected $_activate_meta_box_type;
36
-    protected $_current_message_meta_box;
37
-    protected $_current_message_meta_box_object;
38
-    protected $_context_switcher;
39
-    protected $_shortcodes = array();
40
-    protected $_active_messengers = array();
41
-    protected $_active_message_types = array();
42
-    
43
-    /**
44
-     * @var EE_Message_Template_Group $_message_template_group
45
-     */
46
-    protected $_message_template_group;
47
-    protected $_m_mt_settings = array();
48
-    
49
-    
50
-    /**
51
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
-     * IF there is no group then it gets automatically set to the Default template pack.
53
-     *
54
-     * @since 4.5.0
55
-     *
56
-     * @var EE_Messages_Template_Pack
57
-     */
58
-    protected $_template_pack;
59
-    
60
-    
61
-    /**
62
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
-     * group is.  If there is no group then it automatically gets set to default.
64
-     *
65
-     * @since 4.5.0
66
-     *
67
-     * @var string
68
-     */
69
-    protected $_variation;
70
-    
71
-    
72
-    /**
73
-     * @param bool $routing
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        //make sure messages autoloader is running
78
-        EED_Messages::set_autoloaders();
79
-        parent::__construct($routing);
80
-    }
81
-    
82
-    
83
-    protected function _init_page_props()
84
-    {
85
-        $this->page_slug        = EE_MSG_PG_SLUG;
86
-        $this->page_label       = __('Messages Settings', 'event_espresso');
87
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
-        $this->_admin_base_path = EE_MSG_ADMIN;
89
-        
90
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
-        
92
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
-        $this->_load_message_resource_manager();
94
-    }
95
-    
96
-    
97
-    /**
98
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
-     *
100
-     *
101
-     * @throws EE_Error
102
-     */
103
-    protected function _load_message_resource_manager()
104
-    {
105
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
-    }
107
-    
108
-    
109
-    /**
110
-     * @deprecated 4.9.9.rc.014
111
-     * @return array
112
-     */
113
-    public function get_messengers_for_list_table()
114
-    {
115
-        EE_Error::doing_it_wrong(
116
-            __METHOD__,
117
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
20
+	/**
21
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
22
+	 */
23
+	protected $_message_resource_manager;
24
+    
25
+	/**
26
+	 * @type string $_active_message_type_name
27
+	 */
28
+	protected $_active_message_type_name = '';
29
+    
30
+	/**
31
+	 * @type EE_messenger $_active_messenger
32
+	 */
33
+	protected $_active_messenger;
34
+	protected $_activate_state;
35
+	protected $_activate_meta_box_type;
36
+	protected $_current_message_meta_box;
37
+	protected $_current_message_meta_box_object;
38
+	protected $_context_switcher;
39
+	protected $_shortcodes = array();
40
+	protected $_active_messengers = array();
41
+	protected $_active_message_types = array();
42
+    
43
+	/**
44
+	 * @var EE_Message_Template_Group $_message_template_group
45
+	 */
46
+	protected $_message_template_group;
47
+	protected $_m_mt_settings = array();
48
+    
49
+    
50
+	/**
51
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
+	 * IF there is no group then it gets automatically set to the Default template pack.
53
+	 *
54
+	 * @since 4.5.0
55
+	 *
56
+	 * @var EE_Messages_Template_Pack
57
+	 */
58
+	protected $_template_pack;
59
+    
60
+    
61
+	/**
62
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
+	 * group is.  If there is no group then it automatically gets set to default.
64
+	 *
65
+	 * @since 4.5.0
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_variation;
70
+    
71
+    
72
+	/**
73
+	 * @param bool $routing
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		//make sure messages autoloader is running
78
+		EED_Messages::set_autoloaders();
79
+		parent::__construct($routing);
80
+	}
81
+    
82
+    
83
+	protected function _init_page_props()
84
+	{
85
+		$this->page_slug        = EE_MSG_PG_SLUG;
86
+		$this->page_label       = __('Messages Settings', 'event_espresso');
87
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
+		$this->_admin_base_path = EE_MSG_ADMIN;
89
+        
90
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
+        
92
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
+		$this->_load_message_resource_manager();
94
+	}
95
+    
96
+    
97
+	/**
98
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
+	 *
100
+	 *
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function _load_message_resource_manager()
104
+	{
105
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
+	}
107
+    
108
+    
109
+	/**
110
+	 * @deprecated 4.9.9.rc.014
111
+	 * @return array
112
+	 */
113
+	public function get_messengers_for_list_table()
114
+	{
115
+		EE_Error::doing_it_wrong(
116
+			__METHOD__,
117
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
118 118
 			values for use in creating a messenger filter dropdown which is now generated differently via
119 119
 			 Messages_Admin_Page::get_messengers_select_input', 'event_espresso'),
120
-            '4.9.9.rc.014'
121
-        );
122
-        
123
-        $m_values          = array();
124
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
-        //setup messengers for selects
126
-        $i = 1;
127
-        foreach ($active_messengers as $active_messenger) {
128
-            if ($active_messenger instanceof EE_Message) {
129
-                $m_values[$i]['id']   = $active_messenger->messenger();
130
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
-                $i++;
132
-            }
133
-        }
134
-        
135
-        return $m_values;
136
-    }
137
-    
138
-    
139
-    /**
140
-     * @deprecated 4.9.9.rc.014
141
-     * @return array
142
-     */
143
-    public function get_message_types_for_list_table()
144
-    {
145
-        EE_Error::doing_it_wrong(
146
-            __METHOD__,
147
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
120
+			'4.9.9.rc.014'
121
+		);
122
+        
123
+		$m_values          = array();
124
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
+		//setup messengers for selects
126
+		$i = 1;
127
+		foreach ($active_messengers as $active_messenger) {
128
+			if ($active_messenger instanceof EE_Message) {
129
+				$m_values[$i]['id']   = $active_messenger->messenger();
130
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
+				$i++;
132
+			}
133
+		}
134
+        
135
+		return $m_values;
136
+	}
137
+    
138
+    
139
+	/**
140
+	 * @deprecated 4.9.9.rc.014
141
+	 * @return array
142
+	 */
143
+	public function get_message_types_for_list_table()
144
+	{
145
+		EE_Error::doing_it_wrong(
146
+			__METHOD__,
147
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
148 148
 			values for use in creating a message type filter dropdown which is now generated differently via
149 149
 			 Messages_Admin_Page::get_message_types_select_input', 'event_espresso'),
150
-            '4.9.9.rc.014'
151
-        );
152
-        
153
-        $mt_values       = array();
154
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
-        $i               = 1;
156
-        foreach ($active_messages as $active_message) {
157
-            if ($active_message instanceof EE_Message) {
158
-                $mt_values[$i]['id']   = $active_message->message_type();
159
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
-                $i++;
161
-            }
162
-        }
163
-        
164
-        return $mt_values;
165
-    }
166
-    
167
-    
168
-    /**
169
-     * @deprecated 4.9.9.rc.014
170
-     * @return array
171
-     */
172
-    public function get_contexts_for_message_types_for_list_table()
173
-    {
174
-        EE_Error::doing_it_wrong(
175
-            __METHOD__,
176
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
150
+			'4.9.9.rc.014'
151
+		);
152
+        
153
+		$mt_values       = array();
154
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
+		$i               = 1;
156
+		foreach ($active_messages as $active_message) {
157
+			if ($active_message instanceof EE_Message) {
158
+				$mt_values[$i]['id']   = $active_message->message_type();
159
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
+				$i++;
161
+			}
162
+		}
163
+        
164
+		return $mt_values;
165
+	}
166
+    
167
+    
168
+	/**
169
+	 * @deprecated 4.9.9.rc.014
170
+	 * @return array
171
+	 */
172
+	public function get_contexts_for_message_types_for_list_table()
173
+	{
174
+		EE_Error::doing_it_wrong(
175
+			__METHOD__,
176
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
177 177
 			values for use in creating a message type context filter dropdown which is now generated differently via
178 178
 			 Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'),
179
-            '4.9.9.rc.014'
180
-        );
181
-        
182
-        $contexts                = array();
183
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
-        foreach ($active_message_contexts as $active_message) {
185
-            if ($active_message instanceof EE_Message) {
186
-                $message_type = $active_message->message_type_object();
187
-                if ($message_type instanceof EE_message_type) {
188
-                    $message_type_contexts = $message_type->get_contexts();
189
-                    foreach ($message_type_contexts as $context => $context_details) {
190
-                        $contexts[$context] = $context_details['label'];
191
-                    }
192
-                }
193
-            }
194
-        }
195
-        
196
-        return $contexts;
197
-    }
198
-    
199
-    
200
-    /**
201
-     * Generate select input with provided messenger options array.
202
-     *
203
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
-     *                                 labels.
205
-     *
206
-     * @return string
207
-     */
208
-    public function get_messengers_select_input($messenger_options)
209
-    {
210
-        //if empty or just one value then just return an empty string
211
-        if (empty($messenger_options)
212
-            || ! is_array($messenger_options)
213
-            || count($messenger_options) === 1
214
-        ) {
215
-            return '';
216
-        }
217
-        //merge in default
218
-        $messenger_options = array_merge(
219
-            array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
-            $messenger_options
221
-        );
222
-        $input             = new EE_Select_Input(
223
-            $messenger_options,
224
-            array(
225
-                'html_name'  => 'ee_messenger_filter_by',
226
-                'html_id'    => 'ee_messenger_filter_by',
227
-                'html_class' => 'wide',
228
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
-                    : 'none_selected'
231
-            )
232
-        );
233
-        
234
-        return $input->get_html_for_input();
235
-    }
236
-    
237
-    
238
-    /**
239
-     * Generate select input with provided message type options array.
240
-     *
241
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
-     *                                    message type labels
243
-     *
244
-     * @return string
245
-     */
246
-    public function get_message_types_select_input($message_type_options)
247
-    {
248
-        //if empty or count of options is 1 then just return an empty string
249
-        if (empty($message_type_options)
250
-            || ! is_array($message_type_options)
251
-            || count($message_type_options) === 1
252
-        ) {
253
-            return '';
254
-        }
255
-        //merge in default
256
-        $message_type_options = array_merge(
257
-            array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
-            $message_type_options
259
-        );
260
-        $input                = new EE_Select_Input(
261
-            $message_type_options,
262
-            array(
263
-                'html_name'  => 'ee_message_type_filter_by',
264
-                'html_id'    => 'ee_message_type_filter_by',
265
-                'html_class' => 'wide',
266
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
-                    : 'none_selected',
269
-            )
270
-        );
271
-        
272
-        return $input->get_html_for_input();
273
-    }
274
-    
275
-    
276
-    /**
277
-     * Generate select input with provide message type contexts array.
278
-     *
279
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
-     *                               context label.
281
-     *
282
-     * @return string
283
-     */
284
-    public function get_contexts_for_message_types_select_input($context_options)
285
-    {
286
-        //if empty or count of options is one then just return empty string
287
-        if (empty($context_options)
288
-            || ! is_array($context_options)
289
-            || count($context_options) === 1
290
-        ) {
291
-            return '';
292
-        }
293
-        //merge in default
294
-        $context_options = array_merge(
295
-            array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
-            $context_options
297
-        );
298
-        $input           = new EE_Select_Input(
299
-            $context_options,
300
-            array(
301
-                'html_name'  => 'ee_context_filter_by',
302
-                'html_id'    => 'ee_context_filter_by',
303
-                'html_class' => 'wide',
304
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
305
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
306
-                    : 'none_selected',
307
-            )
308
-        );
309
-        
310
-        return $input->get_html_for_input();
311
-    }
312
-    
313
-    
314
-    protected function _ajax_hooks()
315
-    {
316
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
-    }
322
-    
323
-    
324
-    protected function _define_page_props()
325
-    {
326
-        $this->_admin_page_title = $this->page_label;
327
-        $this->_labels           = array(
328
-            'buttons'    => array(
329
-                'add'    => __('Add New Message Template', 'event_espresso'),
330
-                'edit'   => __('Edit Message Template', 'event_espresso'),
331
-                'delete' => __('Delete Message Template', 'event_espresso')
332
-            ),
333
-            'publishbox' => __('Update Actions', 'event_espresso')
334
-        );
335
-    }
336
-    
337
-    
338
-    /**
339
-     *        an array for storing key => value pairs of request actions and their corresponding methods
340
-     * @access protected
341
-     * @return void
342
-     */
343
-    protected function _set_page_routes()
344
-    {
345
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
-            ? $this->_req_data['GRP_ID']
347
-            : 0;
348
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
-            ? $this->_req_data['id']
350
-            : $grp_id;
351
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
-            ? $this->_req_data['MSG_ID']
353
-            : 0;
354
-        
355
-        $this->_page_routes = array(
356
-            'default'                          => array(
357
-                'func'       => '_message_queue_list_table',
358
-                'capability' => 'ee_read_global_messages'
359
-            ),
360
-            'global_mtps'                      => array(
361
-                'func'       => '_ee_default_messages_overview_list_table',
362
-                'capability' => 'ee_read_global_messages'
363
-            ),
364
-            'custom_mtps'                      => array(
365
-                'func'       => '_custom_mtps_preview',
366
-                'capability' => 'ee_read_messages'
367
-            ),
368
-            'add_new_message_template'         => array(
369
-                'func'       => '_add_message_template',
370
-                'capability' => 'ee_edit_messages',
371
-                'noheader'   => true
372
-            ),
373
-            'edit_message_template'            => array(
374
-                'func'       => '_edit_message_template',
375
-                'capability' => 'ee_edit_message',
376
-                'obj_id'     => $grp_id
377
-            ),
378
-            'preview_message'                  => array(
379
-                'func'               => '_preview_message',
380
-                'capability'         => 'ee_read_message',
381
-                'obj_id'             => $grp_id,
382
-                'noheader'           => true,
383
-                'headers_sent_route' => 'display_preview_message'
384
-            ),
385
-            'display_preview_message'          => array(
386
-                'func'       => '_display_preview_message',
387
-                'capability' => 'ee_read_message',
388
-                'obj_id'     => $grp_id
389
-            ),
390
-            'insert_message_template'          => array(
391
-                'func'       => '_insert_or_update_message_template',
392
-                'capability' => 'ee_edit_messages',
393
-                'args'       => array('new_template' => true),
394
-                'noheader'   => true
395
-            ),
396
-            'update_message_template'          => array(
397
-                'func'       => '_insert_or_update_message_template',
398
-                'capability' => 'ee_edit_message',
399
-                'obj_id'     => $grp_id,
400
-                'args'       => array('new_template' => false),
401
-                'noheader'   => true
402
-            ),
403
-            'trash_message_template'           => array(
404
-                'func'       => '_trash_or_restore_message_template',
405
-                'capability' => 'ee_delete_message',
406
-                'obj_id'     => $grp_id,
407
-                'args'       => array('trash' => true, 'all' => true),
408
-                'noheader'   => true
409
-            ),
410
-            'trash_message_template_context'   => array(
411
-                'func'       => '_trash_or_restore_message_template',
412
-                'capability' => 'ee_delete_message',
413
-                'obj_id'     => $grp_id,
414
-                'args'       => array('trash' => true),
415
-                'noheader'   => true
416
-            ),
417
-            'restore_message_template'         => array(
418
-                'func'       => '_trash_or_restore_message_template',
419
-                'capability' => 'ee_delete_message',
420
-                'obj_id'     => $grp_id,
421
-                'args'       => array('trash' => false, 'all' => true),
422
-                'noheader'   => true
423
-            ),
424
-            'restore_message_template_context' => array(
425
-                'func'       => '_trash_or_restore_message_template',
426
-                'capability' => 'ee_delete_message',
427
-                'obj_id'     => $grp_id,
428
-                'args'       => array('trash' => false),
429
-                'noheader'   => true
430
-            ),
431
-            'delete_message_template'          => array(
432
-                'func'       => '_delete_message_template',
433
-                'capability' => 'ee_delete_message',
434
-                'obj_id'     => $grp_id,
435
-                'noheader'   => true
436
-            ),
437
-            'reset_to_default'                 => array(
438
-                'func'       => '_reset_to_default_template',
439
-                'capability' => 'ee_edit_message',
440
-                'obj_id'     => $grp_id,
441
-                'noheader'   => true
442
-            ),
443
-            'settings'                         => array(
444
-                'func'       => '_settings',
445
-                'capability' => 'manage_options'
446
-            ),
447
-            'update_global_settings'           => array(
448
-                'func'       => '_update_global_settings',
449
-                'capability' => 'manage_options',
450
-                'noheader'   => true
451
-            ),
452
-            'generate_now'                     => array(
453
-                'func'       => '_generate_now',
454
-                'capability' => 'ee_send_message',
455
-                'noheader'   => true
456
-            ),
457
-            'generate_and_send_now'            => array(
458
-                'func'       => '_generate_and_send_now',
459
-                'capability' => 'ee_send_message',
460
-                'noheader'   => true
461
-            ),
462
-            'queue_for_resending'              => array(
463
-                'func'       => '_queue_for_resending',
464
-                'capability' => 'ee_send_message',
465
-                'noheader'   => true
466
-            ),
467
-            'send_now'                         => array(
468
-                'func'       => '_send_now',
469
-                'capability' => 'ee_send_message',
470
-                'noheader'   => true
471
-            ),
472
-            'delete_ee_message'                => array(
473
-                'func'       => '_delete_ee_messages',
474
-                'capability' => 'ee_delete_messages',
475
-                'noheader'   => true
476
-            ),
477
-            'delete_ee_messages'               => array(
478
-                'func'       => '_delete_ee_messages',
479
-                'capability' => 'ee_delete_messages',
480
-                'noheader'   => true,
481
-                'obj_id'     => $msg_id
482
-            )
483
-        );
484
-    }
485
-    
486
-    
487
-    protected function _set_page_config()
488
-    {
489
-        $this->_page_config = array(
490
-            'default'                  => array(
491
-                'nav'           => array(
492
-                    'label' => __('Message Activity', 'event_espresso'),
493
-                    'order' => 10
494
-                ),
495
-                'list_table'    => 'EE_Message_List_Table',
496
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
-                'require_nonce' => false
498
-            ),
499
-            'global_mtps'              => array(
500
-                'nav'           => array(
501
-                    'label' => __('Default Message Templates', 'event_espresso'),
502
-                    'order' => 20
503
-                ),
504
-                'list_table'    => 'Messages_Template_List_Table',
505
-                'help_tabs'     => array(
506
-                    'messages_overview_help_tab'                                => array(
507
-                        'title'    => __('Messages Overview', 'event_espresso'),
508
-                        'filename' => 'messages_overview'
509
-                    ),
510
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
511
-                        'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'messages_overview_table_column_headings'
513
-                    ),
514
-                    'messages_overview_messages_filters_help_tab'               => array(
515
-                        'title'    => __('Message Filters', 'event_espresso'),
516
-                        'filename' => 'messages_overview_filters'
517
-                    ),
518
-                    'messages_overview_messages_views_help_tab'                 => array(
519
-                        'title'    => __('Message Views', 'event_espresso'),
520
-                        'filename' => 'messages_overview_views'
521
-                    ),
522
-                    'message_overview_message_types_help_tab'                   => array(
523
-                        'title'    => __('Message Types', 'event_espresso'),
524
-                        'filename' => 'messages_overview_types'
525
-                    ),
526
-                    'messages_overview_messengers_help_tab'                     => array(
527
-                        'title'    => __('Messengers', 'event_espresso'),
528
-                        'filename' => 'messages_overview_messengers',
529
-                    ),
530
-                ),
531
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
532
-                'require_nonce' => false
533
-            ),
534
-            'custom_mtps'              => array(
535
-                'nav'           => array(
536
-                    'label' => __('Custom Message Templates', 'event_espresso'),
537
-                    'order' => 30
538
-                ),
539
-                'help_tabs'     => array(),
540
-                'help_tour'     => array(),
541
-                'require_nonce' => false
542
-            ),
543
-            'add_new_message_template' => array(
544
-                'nav'           => array(
545
-                    'label'      => __('Add New Message Templates', 'event_espresso'),
546
-                    'order'      => 5,
547
-                    'persistent' => false
548
-                ),
549
-                'require_nonce' => false
550
-            ),
551
-            'edit_message_template'    => array(
552
-                'labels'        => array(
553
-                    'buttons'    => array(
554
-                        'reset' => __('Reset Templates'),
555
-                    ),
556
-                    'publishbox' => __('Update Actions', 'event_espresso')
557
-                ),
558
-                'nav'           => array(
559
-                    'label'      => __('Edit Message Templates', 'event_espresso'),
560
-                    'order'      => 5,
561
-                    'persistent' => false,
562
-                    'url'        => ''
563
-                ),
564
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
565
-                'has_metaboxes' => true,
566
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
567
-                'help_tabs'     => array(
568
-                    'edit_message_template'       => array(
569
-                        'title'    => __('Message Template Editor', 'event_espresso'),
570
-                        'callback' => 'edit_message_template_help_tab'
571
-                    ),
572
-                    'message_templates_help_tab'  => array(
573
-                        'title'    => __('Message Templates', 'event_espresso'),
574
-                        'filename' => 'messages_templates'
575
-                    ),
576
-                    'message_template_shortcodes' => array(
577
-                        'title'    => __('Message Shortcodes', 'event_espresso'),
578
-                        'callback' => 'message_template_shortcodes_help_tab'
579
-                    ),
580
-                    'message_preview_help_tab'    => array(
581
-                        'title'    => __('Message Preview', 'event_espresso'),
582
-                        'filename' => 'messages_preview'
583
-                    ),
584
-                    'messages_overview_other_help_tab'                          => array(
585
-                        'title'    => __('Messages Other', 'event_espresso'),
586
-                        'filename' => 'messages_overview_other',
587
-                    ),
588
-                ),
589
-                'require_nonce' => false
590
-            ),
591
-            'display_preview_message'  => array(
592
-                'nav'           => array(
593
-                    'label'      => __('Message Preview', 'event_espresso'),
594
-                    'order'      => 5,
595
-                    'url'        => '',
596
-                    'persistent' => false
597
-                ),
598
-                'help_tabs'     => array(
599
-                    'preview_message' => array(
600
-                        'title'    => __('About Previews', 'event_espresso'),
601
-                        'callback' => 'preview_message_help_tab'
602
-                    )
603
-                ),
604
-                'require_nonce' => false
605
-            ),
606
-            'settings'                 => array(
607
-                'nav'           => array(
608
-                    'label' => __('Settings', 'event_espresso'),
609
-                    'order' => 40
610
-                ),
611
-                'metaboxes'     => array('_messages_settings_metaboxes'),
612
-                'help_tabs'     => array(
613
-                    'messages_settings_help_tab'               => array(
614
-                        'title'    => __('Messages Settings', 'event_espresso'),
615
-                        'filename' => 'messages_settings'
616
-                    ),
617
-                    'messages_settings_message_types_help_tab' => array(
618
-                        'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
-                        'filename' => 'messages_settings_message_types'
620
-                    ),
621
-                    'messages_settings_messengers_help_tab'    => array(
622
-                        'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
-                        'filename' => 'messages_settings_messengers'
624
-                    ),
625
-                ),
626
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
627
-                'require_nonce' => false
628
-            )
629
-        );
630
-    }
631
-    
632
-    
633
-    protected function _add_screen_options()
634
-    {
635
-        //todo
636
-    }
637
-    
638
-    
639
-    protected function _add_screen_options_global_mtps()
640
-    {
641
-        /**
642
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
644
-         */
645
-        $page_title              = $this->_admin_page_title;
646
-        $this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
-        $this->_per_page_screen_option();
648
-        $this->_admin_page_title = $page_title;
649
-    }
650
-    
651
-    
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_admin_page_title = __('Message Activity', 'event_espresso');
655
-        $this->_per_page_screen_option();
656
-    }
657
-    
658
-    
659
-    //none of the below group are currently used for Messages
660
-    protected function _add_feature_pointers()
661
-    {
662
-    }
663
-    
664
-    public function admin_init()
665
-    {
666
-    }
667
-    
668
-    public function admin_notices()
669
-    {
670
-    }
671
-    
672
-    public function admin_footer_scripts()
673
-    {
674
-    }
675
-    
676
-    
677
-    public function messages_help_tab()
678
-    {
679
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
-    }
681
-    
682
-    
683
-    public function messengers_help_tab()
684
-    {
685
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
-    }
687
-    
688
-    
689
-    public function message_types_help_tab()
690
-    {
691
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
-    }
693
-    
694
-    
695
-    public function messages_overview_help_tab()
696
-    {
697
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
-    }
699
-    
700
-    
701
-    public function message_templates_help_tab()
702
-    {
703
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
-    }
705
-    
706
-    
707
-    public function edit_message_template_help_tab()
708
-    {
709
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
-                'event_espresso') . '" />';
711
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
-                'event_espresso') . '" />';
713
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
-                'event_espresso') . '" />';
715
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
-                'event_espresso') . '" />';
717
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
-                'event_espresso') . '" />';
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
-            $args);
721
-    }
722
-    
723
-    
724
-    public function message_template_shortcodes_help_tab()
725
-    {
726
-        $this->_set_shortcodes();
727
-        $args['shortcodes'] = $this->_shortcodes;
728
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
-            $args);
730
-    }
179
+			'4.9.9.rc.014'
180
+		);
181
+        
182
+		$contexts                = array();
183
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
+		foreach ($active_message_contexts as $active_message) {
185
+			if ($active_message instanceof EE_Message) {
186
+				$message_type = $active_message->message_type_object();
187
+				if ($message_type instanceof EE_message_type) {
188
+					$message_type_contexts = $message_type->get_contexts();
189
+					foreach ($message_type_contexts as $context => $context_details) {
190
+						$contexts[$context] = $context_details['label'];
191
+					}
192
+				}
193
+			}
194
+		}
195
+        
196
+		return $contexts;
197
+	}
198
+    
199
+    
200
+	/**
201
+	 * Generate select input with provided messenger options array.
202
+	 *
203
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
+	 *                                 labels.
205
+	 *
206
+	 * @return string
207
+	 */
208
+	public function get_messengers_select_input($messenger_options)
209
+	{
210
+		//if empty or just one value then just return an empty string
211
+		if (empty($messenger_options)
212
+			|| ! is_array($messenger_options)
213
+			|| count($messenger_options) === 1
214
+		) {
215
+			return '';
216
+		}
217
+		//merge in default
218
+		$messenger_options = array_merge(
219
+			array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
+			$messenger_options
221
+		);
222
+		$input             = new EE_Select_Input(
223
+			$messenger_options,
224
+			array(
225
+				'html_name'  => 'ee_messenger_filter_by',
226
+				'html_id'    => 'ee_messenger_filter_by',
227
+				'html_class' => 'wide',
228
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
+					: 'none_selected'
231
+			)
232
+		);
233
+        
234
+		return $input->get_html_for_input();
235
+	}
236
+    
237
+    
238
+	/**
239
+	 * Generate select input with provided message type options array.
240
+	 *
241
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
+	 *                                    message type labels
243
+	 *
244
+	 * @return string
245
+	 */
246
+	public function get_message_types_select_input($message_type_options)
247
+	{
248
+		//if empty or count of options is 1 then just return an empty string
249
+		if (empty($message_type_options)
250
+			|| ! is_array($message_type_options)
251
+			|| count($message_type_options) === 1
252
+		) {
253
+			return '';
254
+		}
255
+		//merge in default
256
+		$message_type_options = array_merge(
257
+			array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
+			$message_type_options
259
+		);
260
+		$input                = new EE_Select_Input(
261
+			$message_type_options,
262
+			array(
263
+				'html_name'  => 'ee_message_type_filter_by',
264
+				'html_id'    => 'ee_message_type_filter_by',
265
+				'html_class' => 'wide',
266
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
+					: 'none_selected',
269
+			)
270
+		);
271
+        
272
+		return $input->get_html_for_input();
273
+	}
274
+    
275
+    
276
+	/**
277
+	 * Generate select input with provide message type contexts array.
278
+	 *
279
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
+	 *                               context label.
281
+	 *
282
+	 * @return string
283
+	 */
284
+	public function get_contexts_for_message_types_select_input($context_options)
285
+	{
286
+		//if empty or count of options is one then just return empty string
287
+		if (empty($context_options)
288
+			|| ! is_array($context_options)
289
+			|| count($context_options) === 1
290
+		) {
291
+			return '';
292
+		}
293
+		//merge in default
294
+		$context_options = array_merge(
295
+			array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
+			$context_options
297
+		);
298
+		$input           = new EE_Select_Input(
299
+			$context_options,
300
+			array(
301
+				'html_name'  => 'ee_context_filter_by',
302
+				'html_id'    => 'ee_context_filter_by',
303
+				'html_class' => 'wide',
304
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
305
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
306
+					: 'none_selected',
307
+			)
308
+		);
309
+        
310
+		return $input->get_html_for_input();
311
+	}
312
+    
313
+    
314
+	protected function _ajax_hooks()
315
+	{
316
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
+	}
322
+    
323
+    
324
+	protected function _define_page_props()
325
+	{
326
+		$this->_admin_page_title = $this->page_label;
327
+		$this->_labels           = array(
328
+			'buttons'    => array(
329
+				'add'    => __('Add New Message Template', 'event_espresso'),
330
+				'edit'   => __('Edit Message Template', 'event_espresso'),
331
+				'delete' => __('Delete Message Template', 'event_espresso')
332
+			),
333
+			'publishbox' => __('Update Actions', 'event_espresso')
334
+		);
335
+	}
336
+    
337
+    
338
+	/**
339
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
340
+	 * @access protected
341
+	 * @return void
342
+	 */
343
+	protected function _set_page_routes()
344
+	{
345
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
+			? $this->_req_data['GRP_ID']
347
+			: 0;
348
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
+			? $this->_req_data['id']
350
+			: $grp_id;
351
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
+			? $this->_req_data['MSG_ID']
353
+			: 0;
354
+        
355
+		$this->_page_routes = array(
356
+			'default'                          => array(
357
+				'func'       => '_message_queue_list_table',
358
+				'capability' => 'ee_read_global_messages'
359
+			),
360
+			'global_mtps'                      => array(
361
+				'func'       => '_ee_default_messages_overview_list_table',
362
+				'capability' => 'ee_read_global_messages'
363
+			),
364
+			'custom_mtps'                      => array(
365
+				'func'       => '_custom_mtps_preview',
366
+				'capability' => 'ee_read_messages'
367
+			),
368
+			'add_new_message_template'         => array(
369
+				'func'       => '_add_message_template',
370
+				'capability' => 'ee_edit_messages',
371
+				'noheader'   => true
372
+			),
373
+			'edit_message_template'            => array(
374
+				'func'       => '_edit_message_template',
375
+				'capability' => 'ee_edit_message',
376
+				'obj_id'     => $grp_id
377
+			),
378
+			'preview_message'                  => array(
379
+				'func'               => '_preview_message',
380
+				'capability'         => 'ee_read_message',
381
+				'obj_id'             => $grp_id,
382
+				'noheader'           => true,
383
+				'headers_sent_route' => 'display_preview_message'
384
+			),
385
+			'display_preview_message'          => array(
386
+				'func'       => '_display_preview_message',
387
+				'capability' => 'ee_read_message',
388
+				'obj_id'     => $grp_id
389
+			),
390
+			'insert_message_template'          => array(
391
+				'func'       => '_insert_or_update_message_template',
392
+				'capability' => 'ee_edit_messages',
393
+				'args'       => array('new_template' => true),
394
+				'noheader'   => true
395
+			),
396
+			'update_message_template'          => array(
397
+				'func'       => '_insert_or_update_message_template',
398
+				'capability' => 'ee_edit_message',
399
+				'obj_id'     => $grp_id,
400
+				'args'       => array('new_template' => false),
401
+				'noheader'   => true
402
+			),
403
+			'trash_message_template'           => array(
404
+				'func'       => '_trash_or_restore_message_template',
405
+				'capability' => 'ee_delete_message',
406
+				'obj_id'     => $grp_id,
407
+				'args'       => array('trash' => true, 'all' => true),
408
+				'noheader'   => true
409
+			),
410
+			'trash_message_template_context'   => array(
411
+				'func'       => '_trash_or_restore_message_template',
412
+				'capability' => 'ee_delete_message',
413
+				'obj_id'     => $grp_id,
414
+				'args'       => array('trash' => true),
415
+				'noheader'   => true
416
+			),
417
+			'restore_message_template'         => array(
418
+				'func'       => '_trash_or_restore_message_template',
419
+				'capability' => 'ee_delete_message',
420
+				'obj_id'     => $grp_id,
421
+				'args'       => array('trash' => false, 'all' => true),
422
+				'noheader'   => true
423
+			),
424
+			'restore_message_template_context' => array(
425
+				'func'       => '_trash_or_restore_message_template',
426
+				'capability' => 'ee_delete_message',
427
+				'obj_id'     => $grp_id,
428
+				'args'       => array('trash' => false),
429
+				'noheader'   => true
430
+			),
431
+			'delete_message_template'          => array(
432
+				'func'       => '_delete_message_template',
433
+				'capability' => 'ee_delete_message',
434
+				'obj_id'     => $grp_id,
435
+				'noheader'   => true
436
+			),
437
+			'reset_to_default'                 => array(
438
+				'func'       => '_reset_to_default_template',
439
+				'capability' => 'ee_edit_message',
440
+				'obj_id'     => $grp_id,
441
+				'noheader'   => true
442
+			),
443
+			'settings'                         => array(
444
+				'func'       => '_settings',
445
+				'capability' => 'manage_options'
446
+			),
447
+			'update_global_settings'           => array(
448
+				'func'       => '_update_global_settings',
449
+				'capability' => 'manage_options',
450
+				'noheader'   => true
451
+			),
452
+			'generate_now'                     => array(
453
+				'func'       => '_generate_now',
454
+				'capability' => 'ee_send_message',
455
+				'noheader'   => true
456
+			),
457
+			'generate_and_send_now'            => array(
458
+				'func'       => '_generate_and_send_now',
459
+				'capability' => 'ee_send_message',
460
+				'noheader'   => true
461
+			),
462
+			'queue_for_resending'              => array(
463
+				'func'       => '_queue_for_resending',
464
+				'capability' => 'ee_send_message',
465
+				'noheader'   => true
466
+			),
467
+			'send_now'                         => array(
468
+				'func'       => '_send_now',
469
+				'capability' => 'ee_send_message',
470
+				'noheader'   => true
471
+			),
472
+			'delete_ee_message'                => array(
473
+				'func'       => '_delete_ee_messages',
474
+				'capability' => 'ee_delete_messages',
475
+				'noheader'   => true
476
+			),
477
+			'delete_ee_messages'               => array(
478
+				'func'       => '_delete_ee_messages',
479
+				'capability' => 'ee_delete_messages',
480
+				'noheader'   => true,
481
+				'obj_id'     => $msg_id
482
+			)
483
+		);
484
+	}
485
+    
486
+    
487
+	protected function _set_page_config()
488
+	{
489
+		$this->_page_config = array(
490
+			'default'                  => array(
491
+				'nav'           => array(
492
+					'label' => __('Message Activity', 'event_espresso'),
493
+					'order' => 10
494
+				),
495
+				'list_table'    => 'EE_Message_List_Table',
496
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
+				'require_nonce' => false
498
+			),
499
+			'global_mtps'              => array(
500
+				'nav'           => array(
501
+					'label' => __('Default Message Templates', 'event_espresso'),
502
+					'order' => 20
503
+				),
504
+				'list_table'    => 'Messages_Template_List_Table',
505
+				'help_tabs'     => array(
506
+					'messages_overview_help_tab'                                => array(
507
+						'title'    => __('Messages Overview', 'event_espresso'),
508
+						'filename' => 'messages_overview'
509
+					),
510
+					'messages_overview_messages_table_column_headings_help_tab' => array(
511
+						'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
+						'filename' => 'messages_overview_table_column_headings'
513
+					),
514
+					'messages_overview_messages_filters_help_tab'               => array(
515
+						'title'    => __('Message Filters', 'event_espresso'),
516
+						'filename' => 'messages_overview_filters'
517
+					),
518
+					'messages_overview_messages_views_help_tab'                 => array(
519
+						'title'    => __('Message Views', 'event_espresso'),
520
+						'filename' => 'messages_overview_views'
521
+					),
522
+					'message_overview_message_types_help_tab'                   => array(
523
+						'title'    => __('Message Types', 'event_espresso'),
524
+						'filename' => 'messages_overview_types'
525
+					),
526
+					'messages_overview_messengers_help_tab'                     => array(
527
+						'title'    => __('Messengers', 'event_espresso'),
528
+						'filename' => 'messages_overview_messengers',
529
+					),
530
+				),
531
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
532
+				'require_nonce' => false
533
+			),
534
+			'custom_mtps'              => array(
535
+				'nav'           => array(
536
+					'label' => __('Custom Message Templates', 'event_espresso'),
537
+					'order' => 30
538
+				),
539
+				'help_tabs'     => array(),
540
+				'help_tour'     => array(),
541
+				'require_nonce' => false
542
+			),
543
+			'add_new_message_template' => array(
544
+				'nav'           => array(
545
+					'label'      => __('Add New Message Templates', 'event_espresso'),
546
+					'order'      => 5,
547
+					'persistent' => false
548
+				),
549
+				'require_nonce' => false
550
+			),
551
+			'edit_message_template'    => array(
552
+				'labels'        => array(
553
+					'buttons'    => array(
554
+						'reset' => __('Reset Templates'),
555
+					),
556
+					'publishbox' => __('Update Actions', 'event_espresso')
557
+				),
558
+				'nav'           => array(
559
+					'label'      => __('Edit Message Templates', 'event_espresso'),
560
+					'order'      => 5,
561
+					'persistent' => false,
562
+					'url'        => ''
563
+				),
564
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
565
+				'has_metaboxes' => true,
566
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
567
+				'help_tabs'     => array(
568
+					'edit_message_template'       => array(
569
+						'title'    => __('Message Template Editor', 'event_espresso'),
570
+						'callback' => 'edit_message_template_help_tab'
571
+					),
572
+					'message_templates_help_tab'  => array(
573
+						'title'    => __('Message Templates', 'event_espresso'),
574
+						'filename' => 'messages_templates'
575
+					),
576
+					'message_template_shortcodes' => array(
577
+						'title'    => __('Message Shortcodes', 'event_espresso'),
578
+						'callback' => 'message_template_shortcodes_help_tab'
579
+					),
580
+					'message_preview_help_tab'    => array(
581
+						'title'    => __('Message Preview', 'event_espresso'),
582
+						'filename' => 'messages_preview'
583
+					),
584
+					'messages_overview_other_help_tab'                          => array(
585
+						'title'    => __('Messages Other', 'event_espresso'),
586
+						'filename' => 'messages_overview_other',
587
+					),
588
+				),
589
+				'require_nonce' => false
590
+			),
591
+			'display_preview_message'  => array(
592
+				'nav'           => array(
593
+					'label'      => __('Message Preview', 'event_espresso'),
594
+					'order'      => 5,
595
+					'url'        => '',
596
+					'persistent' => false
597
+				),
598
+				'help_tabs'     => array(
599
+					'preview_message' => array(
600
+						'title'    => __('About Previews', 'event_espresso'),
601
+						'callback' => 'preview_message_help_tab'
602
+					)
603
+				),
604
+				'require_nonce' => false
605
+			),
606
+			'settings'                 => array(
607
+				'nav'           => array(
608
+					'label' => __('Settings', 'event_espresso'),
609
+					'order' => 40
610
+				),
611
+				'metaboxes'     => array('_messages_settings_metaboxes'),
612
+				'help_tabs'     => array(
613
+					'messages_settings_help_tab'               => array(
614
+						'title'    => __('Messages Settings', 'event_espresso'),
615
+						'filename' => 'messages_settings'
616
+					),
617
+					'messages_settings_message_types_help_tab' => array(
618
+						'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
+						'filename' => 'messages_settings_message_types'
620
+					),
621
+					'messages_settings_messengers_help_tab'    => array(
622
+						'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
+						'filename' => 'messages_settings_messengers'
624
+					),
625
+				),
626
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
627
+				'require_nonce' => false
628
+			)
629
+		);
630
+	}
631
+    
632
+    
633
+	protected function _add_screen_options()
634
+	{
635
+		//todo
636
+	}
637
+    
638
+    
639
+	protected function _add_screen_options_global_mtps()
640
+	{
641
+		/**
642
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
644
+		 */
645
+		$page_title              = $this->_admin_page_title;
646
+		$this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
+		$this->_per_page_screen_option();
648
+		$this->_admin_page_title = $page_title;
649
+	}
650
+    
651
+    
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_admin_page_title = __('Message Activity', 'event_espresso');
655
+		$this->_per_page_screen_option();
656
+	}
657
+    
658
+    
659
+	//none of the below group are currently used for Messages
660
+	protected function _add_feature_pointers()
661
+	{
662
+	}
663
+    
664
+	public function admin_init()
665
+	{
666
+	}
667
+    
668
+	public function admin_notices()
669
+	{
670
+	}
671
+    
672
+	public function admin_footer_scripts()
673
+	{
674
+	}
675
+    
676
+    
677
+	public function messages_help_tab()
678
+	{
679
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
+	}
681
+    
682
+    
683
+	public function messengers_help_tab()
684
+	{
685
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
+	}
687
+    
688
+    
689
+	public function message_types_help_tab()
690
+	{
691
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
+	}
693
+    
694
+    
695
+	public function messages_overview_help_tab()
696
+	{
697
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
+	}
699
+    
700
+    
701
+	public function message_templates_help_tab()
702
+	{
703
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
+	}
705
+    
706
+    
707
+	public function edit_message_template_help_tab()
708
+	{
709
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
+				'event_espresso') . '" />';
711
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
+				'event_espresso') . '" />';
713
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
+				'event_espresso') . '" />';
715
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
+				'event_espresso') . '" />';
717
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
+				'event_espresso') . '" />';
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
+			$args);
721
+	}
722
+    
723
+    
724
+	public function message_template_shortcodes_help_tab()
725
+	{
726
+		$this->_set_shortcodes();
727
+		$args['shortcodes'] = $this->_shortcodes;
728
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
+			$args);
730
+	}
731 731
     
732 732
     
733
-    public function preview_message_help_tab()
734
-    {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
-    }
733
+	public function preview_message_help_tab()
734
+	{
735
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
+	}
737 737
     
738
-    
739
-    public function settings_help_tab()
740
-    {
741
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
-                'event_espresso') . '" />';
743
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
-                'event_espresso') . '" />';
745
-        $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
-        $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
-    }
738
+    
739
+	public function settings_help_tab()
740
+	{
741
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
+				'event_espresso') . '" />';
743
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
+				'event_espresso') . '" />';
745
+		$args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
+		$args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
+	}
749 749
     
750 750
     
751
-    public function load_scripts_styles()
752
-    {
753
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
-        wp_enqueue_style('espresso_ee_msg');
751
+	public function load_scripts_styles()
752
+	{
753
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
+		wp_enqueue_style('espresso_ee_msg');
755 755
         
756
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
-    }
756
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
+	}
761 761
     
762 762
     
763
-    public function load_scripts_styles_default()
764
-    {
765
-        wp_enqueue_script('ee-msg-list-table-js');
766
-    }
763
+	public function load_scripts_styles_default()
764
+	{
765
+		wp_enqueue_script('ee-msg-list-table-js');
766
+	}
767 767
     
768 768
     
769
-    public function wp_editor_css($mce_css)
770
-    {
771
-        //if we're on the edit_message_template route
772
-        if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
-            $message_type_name = $this->_active_message_type_name;
769
+	public function wp_editor_css($mce_css)
770
+	{
771
+		//if we're on the edit_message_template route
772
+		if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
+			$message_type_name = $this->_active_message_type_name;
774 774
             
775
-            //we're going to REPLACE the existing mce css
776
-            //we need to get the css file location from the active messenger
777
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
-                'wpeditor', $this->_variation);
779
-        }
775
+			//we're going to REPLACE the existing mce css
776
+			//we need to get the css file location from the active messenger
777
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
+				'wpeditor', $this->_variation);
779
+		}
780 780
         
781
-        return $mce_css;
782
-    }
781
+		return $mce_css;
782
+	}
783 783
     
784 784
     
785
-    public function load_scripts_styles_edit_message_template()
786
-    {
785
+	public function load_scripts_styles_edit_message_template()
786
+	{
787 787
         
788
-        $this->_set_shortcodes();
788
+		$this->_set_shortcodes();
789 789
         
790
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
-            __('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.',
792
-                'event_espresso'),
793
-            $this->_message_template_group->messenger_obj()->label['singular'],
794
-            $this->_message_template_group->message_type_obj()->label['singular']
795
-        );
796
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
-            'event_espresso');
790
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
+			__('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.',
792
+				'event_espresso'),
793
+			$this->_message_template_group->messenger_obj()->label['singular'],
794
+			$this->_message_template_group->message_type_obj()->label['singular']
795
+		);
796
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
+			'event_espresso');
798 798
         
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
-            EVENT_ESPRESSO_VERSION);
799
+		wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
+			EVENT_ESPRESSO_VERSION);
801 801
         
802
-        wp_enqueue_script('ee_admin_js');
803
-        wp_enqueue_script('ee_msgs_edit_js');
802
+		wp_enqueue_script('ee_admin_js');
803
+		wp_enqueue_script('ee_msgs_edit_js');
804 804
         
805
-        //add in special css for tiny_mce
806
-        add_filter('mce_css', array($this, 'wp_editor_css'));
807
-    }
805
+		//add in special css for tiny_mce
806
+		add_filter('mce_css', array($this, 'wp_editor_css'));
807
+	}
808 808
     
809 809
     
810
-    public function load_scripts_styles_display_preview_message()
811
-    {
810
+	public function load_scripts_styles_display_preview_message()
811
+	{
812 812
         
813
-        $this->_set_message_template_group();
813
+		$this->_set_message_template_group();
814 814
         
815
-        if (isset($this->_req_data['messenger'])) {
816
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
-        }
815
+		if (isset($this->_req_data['messenger'])) {
816
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
+		}
818 818
         
819
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
819
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820 820
         
821 821
         
822
-        wp_enqueue_style('espresso_preview_css',
823
-            $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
-                $this->_variation));
825
-    }
822
+		wp_enqueue_style('espresso_preview_css',
823
+			$this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
+				$this->_variation));
825
+	}
826 826
     
827 827
     
828
-    public function load_scripts_styles_settings()
829
-    {
830
-        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
-            EVENT_ESPRESSO_VERSION);
832
-        wp_enqueue_style('ee-text-links');
833
-        wp_enqueue_style('ee-message-settings');
828
+	public function load_scripts_styles_settings()
829
+	{
830
+		wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
+			EVENT_ESPRESSO_VERSION);
832
+		wp_enqueue_style('ee-text-links');
833
+		wp_enqueue_style('ee-message-settings');
834 834
         
835
-        wp_enqueue_script('ee-messages-settings');
836
-    }
835
+		wp_enqueue_script('ee-messages-settings');
836
+	}
837 837
     
838 838
     
839
-    /**
840
-     * set views array for List Table
841
-     */
842
-    public function _set_list_table_views_global_mtps()
843
-    {
844
-        $this->_views = array(
845
-            'in_use' => array(
846
-                'slug'        => 'in_use',
847
-                'label'       => __('In Use', 'event_espresso'),
848
-                'count'       => 0,
849
-            )
850
-        );
851
-    }
839
+	/**
840
+	 * set views array for List Table
841
+	 */
842
+	public function _set_list_table_views_global_mtps()
843
+	{
844
+		$this->_views = array(
845
+			'in_use' => array(
846
+				'slug'        => 'in_use',
847
+				'label'       => __('In Use', 'event_espresso'),
848
+				'count'       => 0,
849
+			)
850
+		);
851
+	}
852 852
 
853 853
 
854
-    /**
855
-     * Set views array for the Custom Template List Table
856
-     */
857
-    public function _set_list_table_views_custom_mtps()
858
-    {
859
-        $this->_set_list_table_views_global_mtps();
860
-        $this->_views['in_use']['bulk_action'] = array(
861
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
862
-        );
863
-    }
864
-    
865
-    
866
-    /**
867
-     * set views array for message queue list table
868
-     */
869
-    public function _set_list_table_views_default()
870
-    {
871
-        EE_Registry::instance()->load_helper('Template');
872
-        
873
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
874
-            'message_list_table_bulk_actions')
875
-            ? array(
876
-                'generate_now'          => __('Generate Now', 'event_espresso'),
877
-                'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
878
-                'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
879
-                'send_now'              => __('Send Now', 'event_espresso')
880
-            )
881
-            : array();
882
-        
883
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
884
-            'message_list_table_bulk_actions')
885
-            ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
886
-            : array();
887
-        
888
-        
889
-        $this->_views = array(
890
-            'all' => array(
891
-                'slug'        => 'all',
892
-                'label'       => __('All', 'event_espresso'),
893
-                'count'       => 0,
894
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
895
-            )
896
-        );
897
-        
898
-        
899
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
900
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
901
-                continue;
902
-            }
903
-            $status_bulk_actions = $common_bulk_actions;
904
-            //unset bulk actions not applying to status
905
-            if (! empty($status_bulk_actions)) {
906
-                switch ($status) {
907
-                    case EEM_Message::status_idle:
908
-                    case EEM_Message::status_resend:
909
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
910
-                        break;
854
+	/**
855
+	 * Set views array for the Custom Template List Table
856
+	 */
857
+	public function _set_list_table_views_custom_mtps()
858
+	{
859
+		$this->_set_list_table_views_global_mtps();
860
+		$this->_views['in_use']['bulk_action'] = array(
861
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
862
+		);
863
+	}
864
+    
865
+    
866
+	/**
867
+	 * set views array for message queue list table
868
+	 */
869
+	public function _set_list_table_views_default()
870
+	{
871
+		EE_Registry::instance()->load_helper('Template');
872
+        
873
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
874
+			'message_list_table_bulk_actions')
875
+			? array(
876
+				'generate_now'          => __('Generate Now', 'event_espresso'),
877
+				'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
878
+				'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
879
+				'send_now'              => __('Send Now', 'event_espresso')
880
+			)
881
+			: array();
882
+        
883
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
884
+			'message_list_table_bulk_actions')
885
+			? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
886
+			: array();
887
+        
888
+        
889
+		$this->_views = array(
890
+			'all' => array(
891
+				'slug'        => 'all',
892
+				'label'       => __('All', 'event_espresso'),
893
+				'count'       => 0,
894
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
895
+			)
896
+		);
897
+        
898
+        
899
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
900
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
901
+				continue;
902
+			}
903
+			$status_bulk_actions = $common_bulk_actions;
904
+			//unset bulk actions not applying to status
905
+			if (! empty($status_bulk_actions)) {
906
+				switch ($status) {
907
+					case EEM_Message::status_idle:
908
+					case EEM_Message::status_resend:
909
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
910
+						break;
911 911
                     
912
-                    case EEM_Message::status_failed:
913
-                    case EEM_Message::status_debug_only:
914
-                    case EEM_Message::status_messenger_executing:
915
-                        $status_bulk_actions = array();
916
-                        break;
912
+					case EEM_Message::status_failed:
913
+					case EEM_Message::status_debug_only:
914
+					case EEM_Message::status_messenger_executing:
915
+						$status_bulk_actions = array();
916
+						break;
917 917
                     
918
-                    case EEM_Message::status_incomplete:
919
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
920
-                        break;
918
+					case EEM_Message::status_incomplete:
919
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
920
+						break;
921 921
                     
922
-                    case EEM_Message::status_retry:
923
-                    case EEM_Message::status_sent:
924
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
925
-                        break;
926
-                }
927
-            }
922
+					case EEM_Message::status_retry:
923
+					case EEM_Message::status_sent:
924
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
925
+						break;
926
+				}
927
+			}
928 928
 
929
-            //skip adding messenger executing status to views because it will be included with the Failed view.
930
-            if ( $status === EEM_Message::status_messenger_executing ) {
931
-                continue;
932
-            }
929
+			//skip adding messenger executing status to views because it will be included with the Failed view.
930
+			if ( $status === EEM_Message::status_messenger_executing ) {
931
+				continue;
932
+			}
933 933
             
934
-            $this->_views[strtolower($status)] = array(
935
-                'slug'        => strtolower($status),
936
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
937
-                'count'       => 0,
938
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
939
-            );
940
-        }
941
-    }
942
-    
943
-    
944
-    protected function _ee_default_messages_overview_list_table()
945
-    {
946
-        $this->_admin_page_title = __('Default Message Templates', 'event_espresso');
947
-        $this->display_admin_list_table_page_with_no_sidebar();
948
-    }
949
-    
950
-    
951
-    protected function _message_queue_list_table()
952
-    {
953
-        $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
954
-        $this->_template_args['per_column']        = 6;
955
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
956
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
957
-        $this->display_admin_list_table_page_with_no_sidebar();
958
-    }
959
-    
960
-    
961
-    protected function _message_legend_items()
962
-    {
963
-        
964
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
965
-        $action_items       = array();
966
-        
967
-        foreach ($action_css_classes as $action_item => $action_details) {
968
-            if ($action_item === 'see_notifications_for') {
969
-                continue;
970
-            }
971
-            $action_items[$action_item] = array(
972
-                'class' => $action_details['css_class'],
973
-                'desc'  => $action_details['label']
974
-            );
975
-        }
976
-        
977
-        /** @type array $status_items status legend setup */
978
-        $status_items = array(
979
-            'sent_status'       => array(
980
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
981
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
982
-            ),
983
-            'idle_status'       => array(
984
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
985
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
986
-            ),
987
-            'failed_status'     => array(
988
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
989
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
990
-            ),
991
-            'messenger_executing_status' => array(
992
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
993
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
994
-            ),
995
-            'resend_status'     => array(
996
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
997
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
998
-            ),
999
-            'incomplete_status' => array(
1000
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1001
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1002
-            ),
1003
-            'retry_status'      => array(
1004
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1005
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1006
-            )
1007
-        );
1008
-        if (EEM_Message::debug()) {
1009
-            $status_items['debug_only_status'] = array(
1010
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1011
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1012
-            );
1013
-        }
1014
-        
1015
-        return array_merge($action_items, $status_items);
1016
-    }
1017
-    
1018
-    
1019
-    protected function _custom_mtps_preview()
1020
-    {
1021
-        $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1022
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1023
-                'event_espresso') . '" />';
1024
-        $this->_template_args['preview_text'] = '<strong>' . __('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.',
1025
-                'event_espresso') . '</strong>';
1026
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1027
-    }
1028
-    
1029
-    
1030
-    /**
1031
-     * get_message_templates
1032
-     * This gets all the message templates for listing on the overview list.
1033
-     *
1034
-     * @access public
1035
-     *
1036
-     * @param int    $perpage the amount of templates groups to show per page
1037
-     * @param string $type    the current _view we're getting templates for
1038
-     * @param bool   $count   return count?
1039
-     * @param bool   $all     disregard any paging info (get all data);
1040
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1041
-     *
1042
-     * @return array
1043
-     */
1044
-    public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1045
-    {
1046
-        
1047
-        $MTP = EEM_Message_Template_Group::instance();
1048
-        
1049
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1050
-        $orderby                    = $this->_req_data['orderby'];
1051
-        
1052
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1053
-        
1054
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1055
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1056
-        
1057
-        $offset = ($current_page - 1) * $per_page;
1058
-        $limit  = $all ? null : array($offset, $per_page);
1059
-        
1060
-        
1061
-        //options will match what is in the _views array property
1062
-        switch ($type) {
934
+			$this->_views[strtolower($status)] = array(
935
+				'slug'        => strtolower($status),
936
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
937
+				'count'       => 0,
938
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
939
+			);
940
+		}
941
+	}
942
+    
943
+    
944
+	protected function _ee_default_messages_overview_list_table()
945
+	{
946
+		$this->_admin_page_title = __('Default Message Templates', 'event_espresso');
947
+		$this->display_admin_list_table_page_with_no_sidebar();
948
+	}
949
+    
950
+    
951
+	protected function _message_queue_list_table()
952
+	{
953
+		$this->_search_btn_label                   = __('Message Activity', 'event_espresso');
954
+		$this->_template_args['per_column']        = 6;
955
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
956
+		$this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
957
+		$this->display_admin_list_table_page_with_no_sidebar();
958
+	}
959
+    
960
+    
961
+	protected function _message_legend_items()
962
+	{
963
+        
964
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
965
+		$action_items       = array();
966
+        
967
+		foreach ($action_css_classes as $action_item => $action_details) {
968
+			if ($action_item === 'see_notifications_for') {
969
+				continue;
970
+			}
971
+			$action_items[$action_item] = array(
972
+				'class' => $action_details['css_class'],
973
+				'desc'  => $action_details['label']
974
+			);
975
+		}
976
+        
977
+		/** @type array $status_items status legend setup */
978
+		$status_items = array(
979
+			'sent_status'       => array(
980
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
981
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
982
+			),
983
+			'idle_status'       => array(
984
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
985
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
986
+			),
987
+			'failed_status'     => array(
988
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
989
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
990
+			),
991
+			'messenger_executing_status' => array(
992
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
993
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
994
+			),
995
+			'resend_status'     => array(
996
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
997
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
998
+			),
999
+			'incomplete_status' => array(
1000
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1001
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1002
+			),
1003
+			'retry_status'      => array(
1004
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1005
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1006
+			)
1007
+		);
1008
+		if (EEM_Message::debug()) {
1009
+			$status_items['debug_only_status'] = array(
1010
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1011
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1012
+			);
1013
+		}
1014
+        
1015
+		return array_merge($action_items, $status_items);
1016
+	}
1017
+    
1018
+    
1019
+	protected function _custom_mtps_preview()
1020
+	{
1021
+		$this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1022
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1023
+				'event_espresso') . '" />';
1024
+		$this->_template_args['preview_text'] = '<strong>' . __('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.',
1025
+				'event_espresso') . '</strong>';
1026
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1027
+	}
1028
+    
1029
+    
1030
+	/**
1031
+	 * get_message_templates
1032
+	 * This gets all the message templates for listing on the overview list.
1033
+	 *
1034
+	 * @access public
1035
+	 *
1036
+	 * @param int    $perpage the amount of templates groups to show per page
1037
+	 * @param string $type    the current _view we're getting templates for
1038
+	 * @param bool   $count   return count?
1039
+	 * @param bool   $all     disregard any paging info (get all data);
1040
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1041
+	 *
1042
+	 * @return array
1043
+	 */
1044
+	public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1045
+	{
1046
+        
1047
+		$MTP = EEM_Message_Template_Group::instance();
1048
+        
1049
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1050
+		$orderby                    = $this->_req_data['orderby'];
1051
+        
1052
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1053
+        
1054
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1055
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1056
+        
1057
+		$offset = ($current_page - 1) * $per_page;
1058
+		$limit  = $all ? null : array($offset, $per_page);
1059
+        
1060
+        
1061
+		//options will match what is in the _views array property
1062
+		switch ($type) {
1063 1063
             
1064
-            case 'in_use':
1065
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1066
-                break;
1064
+			case 'in_use':
1065
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1066
+				break;
1067 1067
             
1068
-            default:
1069
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1068
+			default:
1069
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1070 1070
             
1071
-        }
1072
-        
1073
-        return $templates;
1074
-    }
1075
-    
1076
-    
1077
-    /**
1078
-     * filters etc might need a list of installed message_types
1079
-     * @return array an array of message type objects
1080
-     */
1081
-    public function get_installed_message_types()
1082
-    {
1083
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1084
-        $installed               = array();
1085
-        
1086
-        foreach ($installed_message_types as $message_type) {
1087
-            $installed[$message_type->name] = $message_type;
1088
-        }
1089
-        
1090
-        return $installed;
1091
-    }
1092
-    
1093
-    
1094
-    /**
1095
-     * _add_message_template
1096
-     *
1097
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1098
-     *
1099
-     * @param string $message_type
1100
-     * @param string $messenger
1101
-     * @param string $GRP_ID
1102
-     *
1103
-     * @throws EE_error
1104
-     */
1105
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1106
-    {
1107
-        //set values override any request data
1108
-        $message_type = ! empty($message_type) ? $message_type : '';
1109
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1110
-        
1111
-        $messenger = ! empty($messenger) ? $messenger : '';
1112
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1113
-        
1114
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1115
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1116
-        
1117
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1118
-        if (empty($message_type) || empty($messenger)) {
1119
-            throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1120
-                'event_espresso'));
1121
-        }
1122
-        
1123
-        //we need the GRP_ID for the template being used as the base for the new template
1124
-        if (empty($GRP_ID)) {
1125
-            throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1126
-                'event_espresso'));
1127
-        }
1128
-        
1129
-        //let's just make sure the template gets generated!
1130
-        
1131
-        //we need to reassign some variables for what the insert is expecting
1132
-        $this->_req_data['MTP_messenger']    = $messenger;
1133
-        $this->_req_data['MTP_message_type'] = $message_type;
1134
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1135
-        $this->_insert_or_update_message_template(true);
1136
-    }
1137
-    
1138
-    
1139
-    /**
1140
-     * public wrapper for the _add_message_template method
1141
-     *
1142
-     * @param string $message_type     message type slug
1143
-     * @param string $messenger        messenger slug
1144
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1145
-     *                                 off of.
1146
-     */
1147
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1148
-    {
1149
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1150
-    }
1151
-    
1152
-    
1153
-    /**
1154
-     * _edit_message_template
1155
-     *
1156
-     * @access protected
1157
-     * @return void
1158
-     */
1159
-    protected function _edit_message_template()
1160
-    {
1161
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1162
-        $template_fields = '';
1163
-        $sidebar_fields  = '';
1164
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1165
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1166
-        
1167
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1168
-            ? absint($this->_req_data['id'])
1169
-            : false;
1170
-        
1171
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1172
-        $message_template_group = $this->_message_template_group;
1173
-        $c_label                = $message_template_group->context_label();
1174
-        $c_config               = $message_template_group->contexts_config();
1175
-        
1176
-        reset($c_config);
1177
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1178
-            ? strtolower($this->_req_data['context'])
1179
-            : key($c_config);
1180
-        
1181
-        
1182
-        if (empty($GRP_ID)) {
1183
-            $action = 'insert_message_template';
1184
-            //$button_both = false;
1185
-            //$button_text = array( __( 'Save','event_espresso') );
1186
-            //$button_actions = array('something_different');
1187
-            //$referrer = false;
1188
-            $edit_message_template_form_url = add_query_arg(
1189
-                array('action' => $action, 'noheader' => true),
1190
-                EE_MSG_ADMIN_URL
1191
-            );
1192
-        } else {
1193
-            $action = 'update_message_template';
1194
-            //$button_both = true;
1195
-            //$button_text = array();
1196
-            //$button_actions = array();
1197
-            //$referrer = $this->_admin_base_url;
1198
-            $edit_message_template_form_url = add_query_arg(
1199
-                array('action' => $action, 'noheader' => true),
1200
-                EE_MSG_ADMIN_URL
1201
-            );
1202
-        }
1203
-        
1204
-        //set active messenger for this view
1205
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1206
-            $message_template_group->messenger()
1207
-        );
1208
-        $this->_active_message_type_name = $message_template_group->message_type();
1209
-        
1210
-        
1211
-        //Do we have any validation errors?
1212
-        $validators = $this->_get_transient();
1213
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1214
-        
1215
-        
1216
-        //we need to assemble the title from Various details
1217
-        $context_label = sprintf(
1218
-            __('(%s %s)', 'event_espresso'),
1219
-            $c_config[$context]['label'],
1220
-            ucwords($c_label['label'])
1221
-        );
1222
-        
1223
-        $title = sprintf(
1224
-            __(' %s %s Template %s', 'event_espresso'),
1225
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1226
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1227
-            $context_label
1228
-        );
1229
-        
1230
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1231
-        $this->_template_args['message_template'] = $message_template_group;
1232
-        $this->_template_args['is_extra_fields']  = false;
1233
-        
1234
-        
1235
-        //let's get EEH_MSG_Template so we can get template form fields
1236
-        $template_field_structure = EEH_MSG_Template::get_fields(
1237
-            $message_template_group->messenger(),
1238
-            $message_template_group->message_type()
1239
-        );
1240
-        
1241
-        if ( ! $template_field_structure) {
1242
-            $template_field_structure = false;
1243
-            $template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1244
-                'event_espresso');
1245
-        }
1246
-        
1247
-        
1248
-        $message_templates = $message_template_group->context_templates();
1249
-        
1250
-        
1251
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1252
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1253
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1254
-                unset($template_field_structure[$context][$reference_field]);
1255
-            }
1256
-        }
1257
-        
1258
-        //let's loop through the template_field_structure and actually assemble the input fields!
1259
-        if ( ! empty($template_field_structure)) {
1260
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1261
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1262
-                if ($template_field == 'extra') {
1263
-                    $this->_template_args['is_extra_fields'] = true;
1264
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1265
-                        $message_template = $message_templates[$context][$reference_field];
1266
-                        $content          = $message_template instanceof EE_Message_Template
1267
-                            ? $message_template->get('MTP_content')
1268
-                            : '';
1269
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1270
-                            //let's verify if we need this extra field via the shortcodes parameter.
1271
-                            $continue = false;
1272
-                            if (isset($extra_array['shortcodes_required'])) {
1273
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1274
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1275
-                                        $continue = true;
1276
-                                    }
1277
-                                }
1278
-                                if ($continue) {
1279
-                                    continue;
1280
-                                }
1281
-                            }
1071
+		}
1072
+        
1073
+		return $templates;
1074
+	}
1075
+    
1076
+    
1077
+	/**
1078
+	 * filters etc might need a list of installed message_types
1079
+	 * @return array an array of message type objects
1080
+	 */
1081
+	public function get_installed_message_types()
1082
+	{
1083
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1084
+		$installed               = array();
1085
+        
1086
+		foreach ($installed_message_types as $message_type) {
1087
+			$installed[$message_type->name] = $message_type;
1088
+		}
1089
+        
1090
+		return $installed;
1091
+	}
1092
+    
1093
+    
1094
+	/**
1095
+	 * _add_message_template
1096
+	 *
1097
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1098
+	 *
1099
+	 * @param string $message_type
1100
+	 * @param string $messenger
1101
+	 * @param string $GRP_ID
1102
+	 *
1103
+	 * @throws EE_error
1104
+	 */
1105
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1106
+	{
1107
+		//set values override any request data
1108
+		$message_type = ! empty($message_type) ? $message_type : '';
1109
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1110
+        
1111
+		$messenger = ! empty($messenger) ? $messenger : '';
1112
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1113
+        
1114
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1115
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1116
+        
1117
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1118
+		if (empty($message_type) || empty($messenger)) {
1119
+			throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1120
+				'event_espresso'));
1121
+		}
1122
+        
1123
+		//we need the GRP_ID for the template being used as the base for the new template
1124
+		if (empty($GRP_ID)) {
1125
+			throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1126
+				'event_espresso'));
1127
+		}
1128
+        
1129
+		//let's just make sure the template gets generated!
1130
+        
1131
+		//we need to reassign some variables for what the insert is expecting
1132
+		$this->_req_data['MTP_messenger']    = $messenger;
1133
+		$this->_req_data['MTP_message_type'] = $message_type;
1134
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1135
+		$this->_insert_or_update_message_template(true);
1136
+	}
1137
+    
1138
+    
1139
+	/**
1140
+	 * public wrapper for the _add_message_template method
1141
+	 *
1142
+	 * @param string $message_type     message type slug
1143
+	 * @param string $messenger        messenger slug
1144
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1145
+	 *                                 off of.
1146
+	 */
1147
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1148
+	{
1149
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1150
+	}
1151
+    
1152
+    
1153
+	/**
1154
+	 * _edit_message_template
1155
+	 *
1156
+	 * @access protected
1157
+	 * @return void
1158
+	 */
1159
+	protected function _edit_message_template()
1160
+	{
1161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1162
+		$template_fields = '';
1163
+		$sidebar_fields  = '';
1164
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1165
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1166
+        
1167
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1168
+			? absint($this->_req_data['id'])
1169
+			: false;
1170
+        
1171
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1172
+		$message_template_group = $this->_message_template_group;
1173
+		$c_label                = $message_template_group->context_label();
1174
+		$c_config               = $message_template_group->contexts_config();
1175
+        
1176
+		reset($c_config);
1177
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1178
+			? strtolower($this->_req_data['context'])
1179
+			: key($c_config);
1180
+        
1181
+        
1182
+		if (empty($GRP_ID)) {
1183
+			$action = 'insert_message_template';
1184
+			//$button_both = false;
1185
+			//$button_text = array( __( 'Save','event_espresso') );
1186
+			//$button_actions = array('something_different');
1187
+			//$referrer = false;
1188
+			$edit_message_template_form_url = add_query_arg(
1189
+				array('action' => $action, 'noheader' => true),
1190
+				EE_MSG_ADMIN_URL
1191
+			);
1192
+		} else {
1193
+			$action = 'update_message_template';
1194
+			//$button_both = true;
1195
+			//$button_text = array();
1196
+			//$button_actions = array();
1197
+			//$referrer = $this->_admin_base_url;
1198
+			$edit_message_template_form_url = add_query_arg(
1199
+				array('action' => $action, 'noheader' => true),
1200
+				EE_MSG_ADMIN_URL
1201
+			);
1202
+		}
1203
+        
1204
+		//set active messenger for this view
1205
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1206
+			$message_template_group->messenger()
1207
+		);
1208
+		$this->_active_message_type_name = $message_template_group->message_type();
1209
+        
1210
+        
1211
+		//Do we have any validation errors?
1212
+		$validators = $this->_get_transient();
1213
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1214
+        
1215
+        
1216
+		//we need to assemble the title from Various details
1217
+		$context_label = sprintf(
1218
+			__('(%s %s)', 'event_espresso'),
1219
+			$c_config[$context]['label'],
1220
+			ucwords($c_label['label'])
1221
+		);
1222
+        
1223
+		$title = sprintf(
1224
+			__(' %s %s Template %s', 'event_espresso'),
1225
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1226
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1227
+			$context_label
1228
+		);
1229
+        
1230
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1231
+		$this->_template_args['message_template'] = $message_template_group;
1232
+		$this->_template_args['is_extra_fields']  = false;
1233
+        
1234
+        
1235
+		//let's get EEH_MSG_Template so we can get template form fields
1236
+		$template_field_structure = EEH_MSG_Template::get_fields(
1237
+			$message_template_group->messenger(),
1238
+			$message_template_group->message_type()
1239
+		);
1240
+        
1241
+		if ( ! $template_field_structure) {
1242
+			$template_field_structure = false;
1243
+			$template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1244
+				'event_espresso');
1245
+		}
1246
+        
1247
+        
1248
+		$message_templates = $message_template_group->context_templates();
1249
+        
1250
+        
1251
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1252
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1253
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1254
+				unset($template_field_structure[$context][$reference_field]);
1255
+			}
1256
+		}
1257
+        
1258
+		//let's loop through the template_field_structure and actually assemble the input fields!
1259
+		if ( ! empty($template_field_structure)) {
1260
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1261
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1262
+				if ($template_field == 'extra') {
1263
+					$this->_template_args['is_extra_fields'] = true;
1264
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1265
+						$message_template = $message_templates[$context][$reference_field];
1266
+						$content          = $message_template instanceof EE_Message_Template
1267
+							? $message_template->get('MTP_content')
1268
+							: '';
1269
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1270
+							//let's verify if we need this extra field via the shortcodes parameter.
1271
+							$continue = false;
1272
+							if (isset($extra_array['shortcodes_required'])) {
1273
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1274
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1275
+										$continue = true;
1276
+									}
1277
+								}
1278
+								if ($continue) {
1279
+									continue;
1280
+								}
1281
+							}
1282 1282
                             
1283
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1284
-                            $template_form_fields[$field_id]         = $extra_array;
1285
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1286
-                            $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1283
+							$field_id                                = $reference_field . '-' . $extra_field . '-content';
1284
+							$template_form_fields[$field_id]         = $extra_array;
1285
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1286
+							$css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1287 1287
                             
1288
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1289
-                                                                            && in_array($extra_field, $v_fields)
1290
-                                                                            &&
1291
-                                                                            (
1292
-                                                                                is_array($validators[$extra_field])
1293
-                                                                                && isset($validators[$extra_field]['msg'])
1294
-                                                                            )
1295
-                                ? 'validate-error ' . $css_class
1296
-                                : $css_class;
1288
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1289
+																			&& in_array($extra_field, $v_fields)
1290
+																			&&
1291
+																			(
1292
+																				is_array($validators[$extra_field])
1293
+																				&& isset($validators[$extra_field]['msg'])
1294
+																			)
1295
+								? 'validate-error ' . $css_class
1296
+								: $css_class;
1297 1297
                             
1298
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1299
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1300
-                                : '';
1298
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1299
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1300
+								: '';
1301 1301
                             
1302
-                            //do we have a validation error?  if we do then let's use that value instead
1303
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1302
+							//do we have a validation error?  if we do then let's use that value instead
1303
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1304 1304
                             
1305 1305
                             
1306
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1306
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1307 1307
                             
1308
-                            //shortcode selector
1309
-                            $field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1310
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1311
-                                $field_name_to_use,
1312
-                                $field_id
1313
-                            );
1308
+							//shortcode selector
1309
+							$field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1310
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1311
+								$field_name_to_use,
1312
+								$field_id
1313
+							);
1314 1314
                             
1315
-                            if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1316
-                                //we want to decode the entities
1317
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1318
-                                    html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1319
-                                );
1315
+							if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1316
+								//we want to decode the entities
1317
+								$template_form_fields[$field_id]['value'] = stripslashes(
1318
+									html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1319
+								);
1320 1320
                                 
1321
-                            }/**/
1322
-                        }
1323
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1324
-                        $templatefield_templatename_id = $reference_field . '-name';
1321
+							}/**/
1322
+						}
1323
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1324
+						$templatefield_templatename_id = $reference_field . '-name';
1325 1325
                         
1326
-                        $template_form_fields[$templatefield_MTP_id] = array(
1327
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1328
-                            'label'      => null,
1329
-                            'input'      => 'hidden',
1330
-                            'type'       => 'int',
1331
-                            'required'   => false,
1332
-                            'validation' => false,
1333
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1334
-                            'css_class'  => '',
1335
-                            'format'     => '%d',
1336
-                            'db-col'     => 'MTP_ID'
1337
-                        );
1326
+						$template_form_fields[$templatefield_MTP_id] = array(
1327
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1328
+							'label'      => null,
1329
+							'input'      => 'hidden',
1330
+							'type'       => 'int',
1331
+							'required'   => false,
1332
+							'validation' => false,
1333
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1334
+							'css_class'  => '',
1335
+							'format'     => '%d',
1336
+							'db-col'     => 'MTP_ID'
1337
+						);
1338 1338
                         
1339
-                        $template_form_fields[$templatefield_templatename_id] = array(
1340
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1341
-                            'label'      => null,
1342
-                            'input'      => 'hidden',
1343
-                            'type'       => 'string',
1344
-                            'required'   => false,
1345
-                            'validation' => true,
1346
-                            'value'      => $reference_field,
1347
-                            'css_class'  => '',
1348
-                            'format'     => '%s',
1349
-                            'db-col'     => 'MTP_template_field'
1350
-                        );
1351
-                    }
1352
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1353
-                } else {
1354
-                    $field_id                                 = $template_field . '-content';
1355
-                    $template_form_fields[$field_id]          = $field_setup_array;
1356
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1357
-                    $message_template                         = isset($message_templates[$context][$template_field])
1358
-                        ? $message_templates[$context][$template_field]
1359
-                        : null;
1360
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1361
-                                                                && is_array($message_templates[$context])
1362
-                                                                && $message_template instanceof EE_Message_Template
1363
-                        ? $message_template->get('MTP_content')
1364
-                        : '';
1339
+						$template_form_fields[$templatefield_templatename_id] = array(
1340
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1341
+							'label'      => null,
1342
+							'input'      => 'hidden',
1343
+							'type'       => 'string',
1344
+							'required'   => false,
1345
+							'validation' => true,
1346
+							'value'      => $reference_field,
1347
+							'css_class'  => '',
1348
+							'format'     => '%s',
1349
+							'db-col'     => 'MTP_template_field'
1350
+						);
1351
+					}
1352
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1353
+				} else {
1354
+					$field_id                                 = $template_field . '-content';
1355
+					$template_form_fields[$field_id]          = $field_setup_array;
1356
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1357
+					$message_template                         = isset($message_templates[$context][$template_field])
1358
+						? $message_templates[$context][$template_field]
1359
+						: null;
1360
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1361
+																&& is_array($message_templates[$context])
1362
+																&& $message_template instanceof EE_Message_Template
1363
+						? $message_template->get('MTP_content')
1364
+						: '';
1365 1365
                     
1366
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1367
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1368
-                        ? $validators[$template_field]['value']
1369
-                        : $template_form_fields[$field_id]['value'];
1366
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1367
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1368
+						? $validators[$template_field]['value']
1369
+						: $template_form_fields[$field_id]['value'];
1370 1370
                     
1371 1371
                     
1372
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1373
-                    $css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1374
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1375
-                                                                    && in_array($template_field, $v_fields)
1376
-                                                                    && isset($validators[$template_field]['msg'])
1377
-                        ? 'validate-error ' . $css_class
1378
-                        : $css_class;
1372
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1373
+					$css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1374
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1375
+																	&& in_array($template_field, $v_fields)
1376
+																	&& isset($validators[$template_field]['msg'])
1377
+						? 'validate-error ' . $css_class
1378
+						: $css_class;
1379 1379
                     
1380
-                    //shortcode selector
1381
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1382
-                        $template_field, $field_id
1383
-                    );
1384
-                }
1380
+					//shortcode selector
1381
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1382
+						$template_field, $field_id
1383
+					);
1384
+				}
1385 1385
                 
1386
-                //k took care of content field(s) now let's take care of others.
1386
+				//k took care of content field(s) now let's take care of others.
1387 1387
                 
1388
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1389
-                $templatefield_field_templatename_id = $template_field . '-name';
1388
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1389
+				$templatefield_field_templatename_id = $template_field . '-name';
1390 1390
                 
1391
-                //foreach template field there are actually two form fields created
1392
-                $template_form_fields[$templatefield_MTP_id] = array(
1393
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1394
-                    'label'      => null,
1395
-                    'input'      => 'hidden',
1396
-                    'type'       => 'int',
1397
-                    'required'   => false,
1398
-                    'validation' => true,
1399
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1400
-                    'css_class'  => '',
1401
-                    'format'     => '%d',
1402
-                    'db-col'     => 'MTP_ID'
1403
-                );
1391
+				//foreach template field there are actually two form fields created
1392
+				$template_form_fields[$templatefield_MTP_id] = array(
1393
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1394
+					'label'      => null,
1395
+					'input'      => 'hidden',
1396
+					'type'       => 'int',
1397
+					'required'   => false,
1398
+					'validation' => true,
1399
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1400
+					'css_class'  => '',
1401
+					'format'     => '%d',
1402
+					'db-col'     => 'MTP_ID'
1403
+				);
1404 1404
                 
1405
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1406
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1407
-                    'label'      => null,
1408
-                    'input'      => 'hidden',
1409
-                    'type'       => 'string',
1410
-                    'required'   => false,
1411
-                    'validation' => true,
1412
-                    'value'      => $template_field,
1413
-                    'css_class'  => '',
1414
-                    'format'     => '%s',
1415
-                    'db-col'     => 'MTP_template_field'
1416
-                );
1405
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1406
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1407
+					'label'      => null,
1408
+					'input'      => 'hidden',
1409
+					'type'       => 'string',
1410
+					'required'   => false,
1411
+					'validation' => true,
1412
+					'value'      => $template_field,
1413
+					'css_class'  => '',
1414
+					'format'     => '%s',
1415
+					'db-col'     => 'MTP_template_field'
1416
+				);
1417 1417
                 
1418
-            }
1418
+			}
1419 1419
             
1420
-            //add other fields
1421
-            $template_form_fields['ee-msg-current-context'] = array(
1422
-                'name'       => 'MTP_context',
1423
-                'label'      => null,
1424
-                'input'      => 'hidden',
1425
-                'type'       => 'string',
1426
-                'required'   => false,
1427
-                'validation' => true,
1428
-                'value'      => $context,
1429
-                'css_class'  => '',
1430
-                'format'     => '%s',
1431
-                'db-col'     => 'MTP_context'
1432
-            );
1420
+			//add other fields
1421
+			$template_form_fields['ee-msg-current-context'] = array(
1422
+				'name'       => 'MTP_context',
1423
+				'label'      => null,
1424
+				'input'      => 'hidden',
1425
+				'type'       => 'string',
1426
+				'required'   => false,
1427
+				'validation' => true,
1428
+				'value'      => $context,
1429
+				'css_class'  => '',
1430
+				'format'     => '%s',
1431
+				'db-col'     => 'MTP_context'
1432
+			);
1433 1433
             
1434
-            $template_form_fields['ee-msg-grp-id'] = array(
1435
-                'name'       => 'GRP_ID',
1436
-                'label'      => null,
1437
-                'input'      => 'hidden',
1438
-                'type'       => 'int',
1439
-                'required'   => false,
1440
-                'validation' => true,
1441
-                'value'      => $GRP_ID,
1442
-                'css_class'  => '',
1443
-                'format'     => '%d',
1444
-                'db-col'     => 'GRP_ID'
1445
-            );
1434
+			$template_form_fields['ee-msg-grp-id'] = array(
1435
+				'name'       => 'GRP_ID',
1436
+				'label'      => null,
1437
+				'input'      => 'hidden',
1438
+				'type'       => 'int',
1439
+				'required'   => false,
1440
+				'validation' => true,
1441
+				'value'      => $GRP_ID,
1442
+				'css_class'  => '',
1443
+				'format'     => '%d',
1444
+				'db-col'     => 'GRP_ID'
1445
+			);
1446 1446
             
1447
-            $template_form_fields['ee-msg-messenger'] = array(
1448
-                'name'       => 'MTP_messenger',
1449
-                'label'      => null,
1450
-                'input'      => 'hidden',
1451
-                'type'       => 'string',
1452
-                'required'   => false,
1453
-                'validation' => true,
1454
-                'value'      => $message_template_group->messenger(),
1455
-                'css_class'  => '',
1456
-                'format'     => '%s',
1457
-                'db-col'     => 'MTP_messenger'
1458
-            );
1447
+			$template_form_fields['ee-msg-messenger'] = array(
1448
+				'name'       => 'MTP_messenger',
1449
+				'label'      => null,
1450
+				'input'      => 'hidden',
1451
+				'type'       => 'string',
1452
+				'required'   => false,
1453
+				'validation' => true,
1454
+				'value'      => $message_template_group->messenger(),
1455
+				'css_class'  => '',
1456
+				'format'     => '%s',
1457
+				'db-col'     => 'MTP_messenger'
1458
+			);
1459 1459
             
1460
-            $template_form_fields['ee-msg-message-type'] = array(
1461
-                'name'       => 'MTP_message_type',
1462
-                'label'      => null,
1463
-                'input'      => 'hidden',
1464
-                'type'       => 'string',
1465
-                'required'   => false,
1466
-                'validation' => true,
1467
-                'value'      => $message_template_group->message_type(),
1468
-                'css_class'  => '',
1469
-                'format'     => '%s',
1470
-                'db-col'     => 'MTP_message_type'
1471
-            );
1460
+			$template_form_fields['ee-msg-message-type'] = array(
1461
+				'name'       => 'MTP_message_type',
1462
+				'label'      => null,
1463
+				'input'      => 'hidden',
1464
+				'type'       => 'string',
1465
+				'required'   => false,
1466
+				'validation' => true,
1467
+				'value'      => $message_template_group->message_type(),
1468
+				'css_class'  => '',
1469
+				'format'     => '%s',
1470
+				'db-col'     => 'MTP_message_type'
1471
+			);
1472 1472
             
1473
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1474
-                'name'       => 'MTP_is_global',
1475
-                'label'      => __('Global Template', 'event_espresso'),
1476
-                'input'      => 'hidden',
1477
-                'type'       => 'int',
1478
-                'required'   => false,
1479
-                'validation' => true,
1480
-                'value'      => $message_template_group->get('MTP_is_global'),
1481
-                'css_class'  => '',
1482
-                'format'     => '%d',
1483
-                'db-col'     => 'MTP_is_global'
1484
-            );
1473
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1474
+				'name'       => 'MTP_is_global',
1475
+				'label'      => __('Global Template', 'event_espresso'),
1476
+				'input'      => 'hidden',
1477
+				'type'       => 'int',
1478
+				'required'   => false,
1479
+				'validation' => true,
1480
+				'value'      => $message_template_group->get('MTP_is_global'),
1481
+				'css_class'  => '',
1482
+				'format'     => '%d',
1483
+				'db-col'     => 'MTP_is_global'
1484
+			);
1485 1485
             
1486
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1487
-                'name'       => 'MTP_is_override',
1488
-                'label'      => __('Override all custom', 'event_espresso'),
1489
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1490
-                'type'       => 'int',
1491
-                'required'   => false,
1492
-                'validation' => true,
1493
-                'value'      => $message_template_group->get('MTP_is_override'),
1494
-                'css_class'  => '',
1495
-                'format'     => '%d',
1496
-                'db-col'     => 'MTP_is_override'
1497
-            );
1486
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1487
+				'name'       => 'MTP_is_override',
1488
+				'label'      => __('Override all custom', 'event_espresso'),
1489
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1490
+				'type'       => 'int',
1491
+				'required'   => false,
1492
+				'validation' => true,
1493
+				'value'      => $message_template_group->get('MTP_is_override'),
1494
+				'css_class'  => '',
1495
+				'format'     => '%d',
1496
+				'db-col'     => 'MTP_is_override'
1497
+			);
1498 1498
             
1499
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1500
-                'name'       => 'MTP_is_active',
1501
-                'label'      => __('Active Template', 'event_espresso'),
1502
-                'input'      => 'hidden',
1503
-                'type'       => 'int',
1504
-                'required'   => false,
1505
-                'validation' => true,
1506
-                'value'      => $message_template_group->is_active(),
1507
-                'css_class'  => '',
1508
-                'format'     => '%d',
1509
-                'db-col'     => 'MTP_is_active'
1510
-            );
1499
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1500
+				'name'       => 'MTP_is_active',
1501
+				'label'      => __('Active Template', 'event_espresso'),
1502
+				'input'      => 'hidden',
1503
+				'type'       => 'int',
1504
+				'required'   => false,
1505
+				'validation' => true,
1506
+				'value'      => $message_template_group->is_active(),
1507
+				'css_class'  => '',
1508
+				'format'     => '%d',
1509
+				'db-col'     => 'MTP_is_active'
1510
+			);
1511 1511
             
1512
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1513
-                'name'       => 'MTP_deleted',
1514
-                'label'      => null,
1515
-                'input'      => 'hidden',
1516
-                'type'       => 'int',
1517
-                'required'   => false,
1518
-                'validation' => true,
1519
-                'value'      => $message_template_group->get('MTP_deleted'),
1520
-                'css_class'  => '',
1521
-                'format'     => '%d',
1522
-                'db-col'     => 'MTP_deleted'
1523
-            );
1524
-            $sidebar_form_fields['ee-msg-author']  = array(
1525
-                'name'       => 'MTP_user_id',
1526
-                'label'      => __('Author', 'event_espresso'),
1527
-                'input'      => 'hidden',
1528
-                'type'       => 'int',
1529
-                'required'   => false,
1530
-                'validation' => false,
1531
-                'value'      => $message_template_group->user(),
1532
-                'format'     => '%d',
1533
-                'db-col'     => 'MTP_user_id'
1534
-            );
1512
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1513
+				'name'       => 'MTP_deleted',
1514
+				'label'      => null,
1515
+				'input'      => 'hidden',
1516
+				'type'       => 'int',
1517
+				'required'   => false,
1518
+				'validation' => true,
1519
+				'value'      => $message_template_group->get('MTP_deleted'),
1520
+				'css_class'  => '',
1521
+				'format'     => '%d',
1522
+				'db-col'     => 'MTP_deleted'
1523
+			);
1524
+			$sidebar_form_fields['ee-msg-author']  = array(
1525
+				'name'       => 'MTP_user_id',
1526
+				'label'      => __('Author', 'event_espresso'),
1527
+				'input'      => 'hidden',
1528
+				'type'       => 'int',
1529
+				'required'   => false,
1530
+				'validation' => false,
1531
+				'value'      => $message_template_group->user(),
1532
+				'format'     => '%d',
1533
+				'db-col'     => 'MTP_user_id'
1534
+			);
1535 1535
             
1536
-            $sidebar_form_fields['ee-msg-route'] = array(
1537
-                'name'  => 'action',
1538
-                'input' => 'hidden',
1539
-                'type'  => 'string',
1540
-                'value' => $action
1541
-            );
1536
+			$sidebar_form_fields['ee-msg-route'] = array(
1537
+				'name'  => 'action',
1538
+				'input' => 'hidden',
1539
+				'type'  => 'string',
1540
+				'value' => $action
1541
+			);
1542 1542
             
1543
-            $sidebar_form_fields['ee-msg-id']        = array(
1544
-                'name'  => 'id',
1545
-                'input' => 'hidden',
1546
-                'type'  => 'int',
1547
-                'value' => $GRP_ID
1548
-            );
1549
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1550
-                'name'  => $action . '_nonce',
1551
-                'input' => 'hidden',
1552
-                'type'  => 'string',
1553
-                'value' => wp_create_nonce($action . '_nonce')
1554
-            );
1543
+			$sidebar_form_fields['ee-msg-id']        = array(
1544
+				'name'  => 'id',
1545
+				'input' => 'hidden',
1546
+				'type'  => 'int',
1547
+				'value' => $GRP_ID
1548
+			);
1549
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1550
+				'name'  => $action . '_nonce',
1551
+				'input' => 'hidden',
1552
+				'type'  => 'string',
1553
+				'value' => wp_create_nonce($action . '_nonce')
1554
+			);
1555 1555
             
1556
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1557
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1558
-                    'name'  => 'template_switch',
1559
-                    'input' => 'hidden',
1560
-                    'type'  => 'int',
1561
-                    'value' => 1
1562
-                );
1563
-            }
1556
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1557
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1558
+					'name'  => 'template_switch',
1559
+					'input' => 'hidden',
1560
+					'type'  => 'int',
1561
+					'value' => 1
1562
+				);
1563
+			}
1564 1564
             
1565 1565
             
1566
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1567
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1566
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1567
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1568 1568
             
1569 1569
             
1570
-        } //end if ( !empty($template_field_structure) )
1570
+		} //end if ( !empty($template_field_structure) )
1571 1571
         
1572
-        //set extra content for publish box
1573
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1574
-        $this->_set_publish_post_box_vars(
1575
-            'id',
1576
-            $GRP_ID,
1577
-            false,
1578
-            add_query_arg(
1579
-                array('action' => 'global_mtps'),
1580
-                $this->_admin_base_url
1581
-            )
1582
-        );
1583
-        
1584
-        //add preview button
1585
-        $preview_url    = parent::add_query_args_and_nonce(
1586
-            array(
1587
-                'message_type' => $message_template_group->message_type(),
1588
-                'messenger'    => $message_template_group->messenger(),
1589
-                'context'      => $context,
1590
-                'GRP_ID'       => $GRP_ID,
1591
-                'action'       => 'preview_message'
1592
-            ),
1593
-            $this->_admin_base_url
1594
-        );
1595
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1596
-                'event_espresso') . '</a>';
1597
-        
1598
-        
1599
-        //setup context switcher
1600
-        $context_switcher_args = array(
1601
-            'page'    => 'espresso_messages',
1602
-            'action'  => 'edit_message_template',
1603
-            'id'      => $GRP_ID,
1604
-            'context' => $context,
1605
-            'extra'   => $preview_button
1606
-        );
1607
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1608
-        
1609
-        
1610
-        //main box
1611
-        $this->_template_args['template_fields']                         = $template_fields;
1612
-        $this->_template_args['sidebar_box_id']                          = 'details';
1613
-        $this->_template_args['action']                                  = $action;
1614
-        $this->_template_args['context']                                 = $context;
1615
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1616
-        $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1617
-        
1618
-        
1619
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1620
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1621
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1622
-        
1623
-        $this->_template_path = $this->_template_args['GRP_ID']
1624
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1625
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1626
-        
1627
-        //send along EE_Message_Template_Group object for further template use.
1628
-        $this->_template_args['MTP'] = $message_template_group;
1629
-        
1630
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1631
-            $this->_template_args, true);
1632
-        
1633
-        
1634
-        //finally, let's set the admin_page title
1635
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1636
-        
1637
-        
1638
-        //we need to take care of setting the shortcodes property for use elsewhere.
1639
-        $this->_set_shortcodes();
1640
-        
1641
-        
1642
-        //final template wrapper
1643
-        $this->display_admin_page_with_sidebar();
1644
-    }
1645
-    
1646
-    
1647
-    public function filter_tinymce_init($mceInit, $editor_id)
1648
-    {
1649
-        return $mceInit;
1650
-    }
1651
-    
1652
-    
1653
-    public function add_context_switcher()
1654
-    {
1655
-        return $this->_context_switcher;
1656
-    }
1657
-    
1658
-    public function _add_form_element_before()
1659
-    {
1660
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1661
-    }
1662
-    
1663
-    public function _add_form_element_after()
1664
-    {
1665
-        return '</form>';
1666
-    }
1667
-    
1668
-    
1669
-    /**
1670
-     * This executes switching the template pack for a message template.
1671
-     *
1672
-     * @since 4.5.0
1673
-     *
1674
-     */
1675
-    public function switch_template_pack()
1676
-    {
1677
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1678
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1679
-        
1680
-        //verify we have needed values.
1681
-        if (empty($GRP_ID) || empty($template_pack)) {
1682
-            $this->_template_args['error'] = true;
1683
-            EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1684
-                __FILE__, __FUNCTION__, __LINE__);
1685
-        } else {
1686
-            //get template, set the new template_pack and then reset to default
1687
-            /** @type EE_Message_Template_Group $message_template_group */
1688
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1572
+		//set extra content for publish box
1573
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1574
+		$this->_set_publish_post_box_vars(
1575
+			'id',
1576
+			$GRP_ID,
1577
+			false,
1578
+			add_query_arg(
1579
+				array('action' => 'global_mtps'),
1580
+				$this->_admin_base_url
1581
+			)
1582
+		);
1583
+        
1584
+		//add preview button
1585
+		$preview_url    = parent::add_query_args_and_nonce(
1586
+			array(
1587
+				'message_type' => $message_template_group->message_type(),
1588
+				'messenger'    => $message_template_group->messenger(),
1589
+				'context'      => $context,
1590
+				'GRP_ID'       => $GRP_ID,
1591
+				'action'       => 'preview_message'
1592
+			),
1593
+			$this->_admin_base_url
1594
+		);
1595
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1596
+				'event_espresso') . '</a>';
1597
+        
1598
+        
1599
+		//setup context switcher
1600
+		$context_switcher_args = array(
1601
+			'page'    => 'espresso_messages',
1602
+			'action'  => 'edit_message_template',
1603
+			'id'      => $GRP_ID,
1604
+			'context' => $context,
1605
+			'extra'   => $preview_button
1606
+		);
1607
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1608
+        
1609
+        
1610
+		//main box
1611
+		$this->_template_args['template_fields']                         = $template_fields;
1612
+		$this->_template_args['sidebar_box_id']                          = 'details';
1613
+		$this->_template_args['action']                                  = $action;
1614
+		$this->_template_args['context']                                 = $context;
1615
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1616
+		$this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1617
+        
1618
+        
1619
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1620
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1621
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1622
+        
1623
+		$this->_template_path = $this->_template_args['GRP_ID']
1624
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1625
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1626
+        
1627
+		//send along EE_Message_Template_Group object for further template use.
1628
+		$this->_template_args['MTP'] = $message_template_group;
1629
+        
1630
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1631
+			$this->_template_args, true);
1632
+        
1633
+        
1634
+		//finally, let's set the admin_page title
1635
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1636
+        
1637
+        
1638
+		//we need to take care of setting the shortcodes property for use elsewhere.
1639
+		$this->_set_shortcodes();
1640
+        
1641
+        
1642
+		//final template wrapper
1643
+		$this->display_admin_page_with_sidebar();
1644
+	}
1645
+    
1646
+    
1647
+	public function filter_tinymce_init($mceInit, $editor_id)
1648
+	{
1649
+		return $mceInit;
1650
+	}
1651
+    
1652
+    
1653
+	public function add_context_switcher()
1654
+	{
1655
+		return $this->_context_switcher;
1656
+	}
1657
+    
1658
+	public function _add_form_element_before()
1659
+	{
1660
+		return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1661
+	}
1662
+    
1663
+	public function _add_form_element_after()
1664
+	{
1665
+		return '</form>';
1666
+	}
1667
+    
1668
+    
1669
+	/**
1670
+	 * This executes switching the template pack for a message template.
1671
+	 *
1672
+	 * @since 4.5.0
1673
+	 *
1674
+	 */
1675
+	public function switch_template_pack()
1676
+	{
1677
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1678
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1679
+        
1680
+		//verify we have needed values.
1681
+		if (empty($GRP_ID) || empty($template_pack)) {
1682
+			$this->_template_args['error'] = true;
1683
+			EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1684
+				__FILE__, __FUNCTION__, __LINE__);
1685
+		} else {
1686
+			//get template, set the new template_pack and then reset to default
1687
+			/** @type EE_Message_Template_Group $message_template_group */
1688
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1689 1689
             
1690
-            $message_template_group->set_template_pack_name($template_pack);
1691
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1692
-            $this->_req_data['mt']   = $message_template_group->message_type();
1690
+			$message_template_group->set_template_pack_name($template_pack);
1691
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1692
+			$this->_req_data['mt']   = $message_template_group->message_type();
1693 1693
             
1694
-            $query_args = $this->_reset_to_default_template();
1694
+			$query_args = $this->_reset_to_default_template();
1695 1695
             
1696
-            if (empty($query_args['id'])) {
1697
-                EE_Error::add_error(
1698
-                    __(
1699
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1700
-                        'event_espresso'
1701
-                    ),
1702
-                    __FILE__, __FUNCTION__, __LINE__
1703
-                );
1704
-                $this->_template_args['error'] = true;
1705
-            } else {
1706
-                $template_label       = $message_template_group->get_template_pack()->label;
1707
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1708
-                EE_Error::add_success(
1709
-                    sprintf(
1710
-                        __(
1711
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1712
-                            'event_espresso'
1713
-                        ),
1714
-                        $template_label,
1715
-                        $template_pack_labels->template_pack
1716
-                    )
1717
-                );
1718
-                //generate the redirect url for js.
1719
-                $url                                          = self::add_query_args_and_nonce($query_args,
1720
-                    $this->_admin_base_url);
1721
-                $this->_template_args['data']['redirect_url'] = $url;
1722
-                $this->_template_args['success']              = true;
1723
-            }
1696
+			if (empty($query_args['id'])) {
1697
+				EE_Error::add_error(
1698
+					__(
1699
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1700
+						'event_espresso'
1701
+					),
1702
+					__FILE__, __FUNCTION__, __LINE__
1703
+				);
1704
+				$this->_template_args['error'] = true;
1705
+			} else {
1706
+				$template_label       = $message_template_group->get_template_pack()->label;
1707
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1708
+				EE_Error::add_success(
1709
+					sprintf(
1710
+						__(
1711
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1712
+							'event_espresso'
1713
+						),
1714
+						$template_label,
1715
+						$template_pack_labels->template_pack
1716
+					)
1717
+				);
1718
+				//generate the redirect url for js.
1719
+				$url                                          = self::add_query_args_and_nonce($query_args,
1720
+					$this->_admin_base_url);
1721
+				$this->_template_args['data']['redirect_url'] = $url;
1722
+				$this->_template_args['success']              = true;
1723
+			}
1724 1724
             
1725
-            $this->_return_json();
1725
+			$this->_return_json();
1726 1726
             
1727
-        }
1728
-    }
1729
-    
1730
-    
1731
-    /**
1732
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1733
-     * they want.
1734
-     *
1735
-     * @access protected
1736
-     * @return array|null
1737
-     */
1738
-    protected function _reset_to_default_template()
1739
-    {
1740
-        
1741
-        $templates = array();
1742
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1743
-        //we need to make sure we've got the info we need.
1744
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1745
-            EE_Error::add_error(
1746
-                __(
1747
-                    '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.',
1748
-                    'event_espresso'
1749
-                ),
1750
-                __FILE__, __FUNCTION__, __LINE__
1751
-            );
1752
-        }
1753
-        
1754
-        // all templates will be reset to whatever the defaults are
1755
-        // for the global template matching the messenger and message type.
1756
-        $success = ! empty($GRP_ID) ? true : false;
1757
-        
1758
-        if ($success) {
1727
+		}
1728
+	}
1729
+    
1730
+    
1731
+	/**
1732
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1733
+	 * they want.
1734
+	 *
1735
+	 * @access protected
1736
+	 * @return array|null
1737
+	 */
1738
+	protected function _reset_to_default_template()
1739
+	{
1740
+        
1741
+		$templates = array();
1742
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1743
+		//we need to make sure we've got the info we need.
1744
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1745
+			EE_Error::add_error(
1746
+				__(
1747
+					'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.',
1748
+					'event_espresso'
1749
+				),
1750
+				__FILE__, __FUNCTION__, __LINE__
1751
+			);
1752
+		}
1753
+        
1754
+		// all templates will be reset to whatever the defaults are
1755
+		// for the global template matching the messenger and message type.
1756
+		$success = ! empty($GRP_ID) ? true : false;
1757
+        
1758
+		if ($success) {
1759 1759
             
1760
-            //let's first determine if the incoming template is a global template,
1761
-            // if it isn't then we need to get the global template matching messenger and message type.
1762
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1760
+			//let's first determine if the incoming template is a global template,
1761
+			// if it isn't then we need to get the global template matching messenger and message type.
1762
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1763 1763
             
1764 1764
             
1765
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1766
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
1765
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1766
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
1767 1767
             
1768
-            if ($success) {
1769
-                // if successfully deleted, lets generate the new ones.
1770
-                // Note. We set GLOBAL to true, because resets on ANY template
1771
-                // will use the related global template defaults for regeneration.
1772
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1773
-                // HOWEVER, we DO keep the template pack and template variation set
1774
-                // for the current custom template when resetting.
1775
-                $templates = $this->_generate_new_templates(
1776
-                    $this->_req_data['msgr'],
1777
-                    $this->_req_data['mt'],
1778
-                    $GRP_ID,
1779
-                    true
1780
-                );
1781
-            }
1768
+			if ($success) {
1769
+				// if successfully deleted, lets generate the new ones.
1770
+				// Note. We set GLOBAL to true, because resets on ANY template
1771
+				// will use the related global template defaults for regeneration.
1772
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1773
+				// HOWEVER, we DO keep the template pack and template variation set
1774
+				// for the current custom template when resetting.
1775
+				$templates = $this->_generate_new_templates(
1776
+					$this->_req_data['msgr'],
1777
+					$this->_req_data['mt'],
1778
+					$GRP_ID,
1779
+					true
1780
+				);
1781
+			}
1782 1782
             
1783
-        }
1784
-        
1785
-        //any error messages?
1786
-        if ( ! $success) {
1787
-            EE_Error::add_error(
1788
-                __('Something went wrong with deleting existing templates. Unable to reset to default',
1789
-                    'event_espresso'),
1790
-                __FILE__, __FUNCTION__, __LINE__
1791
-            );
1792
-        }
1793
-        
1794
-        //all good, let's add a success message!
1795
-        if ($success && ! empty($templates)) {
1796
-            $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1797
-            EE_Error::overwrite_success();
1798
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1799
-        }
1800
-        
1801
-        
1802
-        $query_args = array(
1803
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1804
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1805
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1806
-        );
1807
-        
1808
-        //if called via ajax then we return query args otherwise redirect
1809
-        if (defined('DOING_AJAX') && DOING_AJAX) {
1810
-            return $query_args;
1811
-        } else {
1812
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1783
+		}
1784
+        
1785
+		//any error messages?
1786
+		if ( ! $success) {
1787
+			EE_Error::add_error(
1788
+				__('Something went wrong with deleting existing templates. Unable to reset to default',
1789
+					'event_espresso'),
1790
+				__FILE__, __FUNCTION__, __LINE__
1791
+			);
1792
+		}
1793
+        
1794
+		//all good, let's add a success message!
1795
+		if ($success && ! empty($templates)) {
1796
+			$templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1797
+			EE_Error::overwrite_success();
1798
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1799
+		}
1800
+        
1801
+        
1802
+		$query_args = array(
1803
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1804
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1805
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1806
+		);
1807
+        
1808
+		//if called via ajax then we return query args otherwise redirect
1809
+		if (defined('DOING_AJAX') && DOING_AJAX) {
1810
+			return $query_args;
1811
+		} else {
1812
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1813 1813
             
1814
-            return null;
1815
-        }
1816
-    }
1817
-    
1818
-    
1819
-    /**
1820
-     * Retrieve and set the message preview for display.
1821
-     *
1822
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1823
-     *
1824
-     * @return string
1825
-     */
1826
-    public function _preview_message($send = false)
1827
-    {
1828
-        //first make sure we've got the necessary parameters
1829
-        if (
1830
-        ! isset(
1831
-            $this->_req_data['message_type'],
1832
-            $this->_req_data['messenger'],
1833
-            $this->_req_data['messenger'],
1834
-            $this->_req_data['GRP_ID']
1835
-        )
1836
-        ) {
1837
-            EE_Error::add_error(
1838
-                __('Missing necessary parameters for displaying preview', 'event_espresso'),
1839
-                __FILE__, __FUNCTION__, __LINE__
1840
-            );
1841
-        }
1842
-        
1843
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1844
-        
1845
-        
1846
-        //get the preview!
1847
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1848
-            $this->_req_data['messenger'], $send);
1849
-        
1850
-        if ($send) {
1851
-            return $preview;
1852
-        }
1853
-        
1854
-        //let's add a button to go back to the edit view
1855
-        $query_args             = array(
1856
-            'id'      => $this->_req_data['GRP_ID'],
1857
-            'context' => $this->_req_data['context'],
1858
-            'action'  => 'edit_message_template'
1859
-        );
1860
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1861
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1862
-                'event_espresso') . '</a>';
1863
-        $message_types          = $this->get_installed_message_types();
1864
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1865
-        $active_messenger_label = $active_messenger instanceof EE_messenger
1866
-            ? ucwords($active_messenger->label['singular'])
1867
-            : esc_html__('Unknown Messenger', 'event_espresso');
1868
-        //let's provide a helpful title for context
1869
-        $preview_title = sprintf(
1870
-            __('Viewing Preview for %s %s Message Template', 'event_espresso'),
1871
-            $active_messenger_label,
1872
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1873
-        );
1874
-        //setup display of preview.
1875
-        $this->_admin_page_title                    = $preview_title;
1876
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1877
-        $this->_template_args['data']['force_json'] = true;
1878
-        
1879
-        return '';
1880
-    }
1881
-    
1882
-    
1883
-    /**
1884
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1885
-     * gets called automatically.
1886
-     *
1887
-     * @since 4.5.0
1888
-     *
1889
-     * @return string
1890
-     */
1891
-    protected function _display_preview_message()
1892
-    {
1893
-        $this->display_admin_page_with_no_sidebar();
1894
-    }
1895
-    
1896
-    
1897
-    /**
1898
-     * registers metaboxes that should show up on the "edit_message_template" page
1899
-     *
1900
-     * @access protected
1901
-     * @return void
1902
-     */
1903
-    protected function _register_edit_meta_boxes()
1904
-    {
1905
-        add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1906
-            array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1907
-        add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1908
-            $this->_current_screen->id, 'side', 'high');
1909
-        add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1910
-            $this->_current_screen->id, 'side', 'high');
1911
-    }
1912
-    
1913
-    
1914
-    /**
1915
-     * metabox content for all template pack and variation selection.
1916
-     *
1917
-     * @since 4.5.0
1918
-     *
1919
-     * @return string
1920
-     */
1921
-    public function template_pack_meta_box()
1922
-    {
1923
-        $this->_set_message_template_group();
1924
-        
1925
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
1926
-        
1927
-        $tp_select_values = array();
1928
-        
1929
-        foreach ($tp_collection as $tp) {
1930
-            //only include template packs that support this messenger and message type!
1931
-            $supports = $tp->get_supports();
1932
-            if (
1933
-                ! isset($supports[$this->_message_template_group->messenger()])
1934
-                || ! in_array(
1935
-                    $this->_message_template_group->message_type(),
1936
-                    $supports[$this->_message_template_group->messenger()]
1937
-                )
1938
-            ) {
1939
-                //not supported
1940
-                continue;
1941
-            }
1814
+			return null;
1815
+		}
1816
+	}
1817
+    
1818
+    
1819
+	/**
1820
+	 * Retrieve and set the message preview for display.
1821
+	 *
1822
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1823
+	 *
1824
+	 * @return string
1825
+	 */
1826
+	public function _preview_message($send = false)
1827
+	{
1828
+		//first make sure we've got the necessary parameters
1829
+		if (
1830
+		! isset(
1831
+			$this->_req_data['message_type'],
1832
+			$this->_req_data['messenger'],
1833
+			$this->_req_data['messenger'],
1834
+			$this->_req_data['GRP_ID']
1835
+		)
1836
+		) {
1837
+			EE_Error::add_error(
1838
+				__('Missing necessary parameters for displaying preview', 'event_espresso'),
1839
+				__FILE__, __FUNCTION__, __LINE__
1840
+			);
1841
+		}
1842
+        
1843
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1844
+        
1845
+        
1846
+		//get the preview!
1847
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1848
+			$this->_req_data['messenger'], $send);
1849
+        
1850
+		if ($send) {
1851
+			return $preview;
1852
+		}
1853
+        
1854
+		//let's add a button to go back to the edit view
1855
+		$query_args             = array(
1856
+			'id'      => $this->_req_data['GRP_ID'],
1857
+			'context' => $this->_req_data['context'],
1858
+			'action'  => 'edit_message_template'
1859
+		);
1860
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1861
+		$preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1862
+				'event_espresso') . '</a>';
1863
+		$message_types          = $this->get_installed_message_types();
1864
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1865
+		$active_messenger_label = $active_messenger instanceof EE_messenger
1866
+			? ucwords($active_messenger->label['singular'])
1867
+			: esc_html__('Unknown Messenger', 'event_espresso');
1868
+		//let's provide a helpful title for context
1869
+		$preview_title = sprintf(
1870
+			__('Viewing Preview for %s %s Message Template', 'event_espresso'),
1871
+			$active_messenger_label,
1872
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1873
+		);
1874
+		//setup display of preview.
1875
+		$this->_admin_page_title                    = $preview_title;
1876
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1877
+		$this->_template_args['data']['force_json'] = true;
1878
+        
1879
+		return '';
1880
+	}
1881
+    
1882
+    
1883
+	/**
1884
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1885
+	 * gets called automatically.
1886
+	 *
1887
+	 * @since 4.5.0
1888
+	 *
1889
+	 * @return string
1890
+	 */
1891
+	protected function _display_preview_message()
1892
+	{
1893
+		$this->display_admin_page_with_no_sidebar();
1894
+	}
1895
+    
1896
+    
1897
+	/**
1898
+	 * registers metaboxes that should show up on the "edit_message_template" page
1899
+	 *
1900
+	 * @access protected
1901
+	 * @return void
1902
+	 */
1903
+	protected function _register_edit_meta_boxes()
1904
+	{
1905
+		add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1906
+			array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1907
+		add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1908
+			$this->_current_screen->id, 'side', 'high');
1909
+		add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1910
+			$this->_current_screen->id, 'side', 'high');
1911
+	}
1912
+    
1913
+    
1914
+	/**
1915
+	 * metabox content for all template pack and variation selection.
1916
+	 *
1917
+	 * @since 4.5.0
1918
+	 *
1919
+	 * @return string
1920
+	 */
1921
+	public function template_pack_meta_box()
1922
+	{
1923
+		$this->_set_message_template_group();
1924
+        
1925
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
1926
+        
1927
+		$tp_select_values = array();
1928
+        
1929
+		foreach ($tp_collection as $tp) {
1930
+			//only include template packs that support this messenger and message type!
1931
+			$supports = $tp->get_supports();
1932
+			if (
1933
+				! isset($supports[$this->_message_template_group->messenger()])
1934
+				|| ! in_array(
1935
+					$this->_message_template_group->message_type(),
1936
+					$supports[$this->_message_template_group->messenger()]
1937
+				)
1938
+			) {
1939
+				//not supported
1940
+				continue;
1941
+			}
1942 1942
             
1943
-            $tp_select_values[] = array(
1944
-                'text' => $tp->label,
1945
-                'id'   => $tp->dbref
1946
-            );
1947
-        }
1948
-        
1949
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1950
-        if (empty($tp_select_values)) {
1951
-            $tp_select_values[] = array(
1952
-                'text' => __('Default', 'event_espresso'),
1953
-                'id'   => 'default'
1954
-            );
1955
-        }
1956
-        
1957
-        //setup variation select values for the currently selected template.
1958
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1959
-            $this->_message_template_group->messenger(),
1960
-            $this->_message_template_group->message_type()
1961
-        );
1962
-        $variations_select_values = array();
1963
-        foreach ($variations as $variation => $label) {
1964
-            $variations_select_values[] = array(
1965
-                'text' => $label,
1966
-                'id'   => $variation
1967
-            );
1968
-        }
1969
-        
1970
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1971
-        
1972
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1973
-            'MTP_template_pack',
1974
-            $tp_select_values,
1975
-            $this->_message_template_group->get_template_pack_name()
1976
-        );
1977
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1978
-            'MTP_template_variation',
1979
-            $variations_select_values,
1980
-            $this->_message_template_group->get_template_pack_variation()
1981
-        );
1982
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
1983
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
1984
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1985
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1986
-        
1987
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1988
-        
1989
-        EEH_Template::display_template($template, $template_args);
1990
-    }
1991
-    
1992
-    
1993
-    /**
1994
-     * This meta box holds any extra actions related to Message Templates
1995
-     * For now, this includes Resetting templates to defaults and sending a test email.
1996
-     *
1997
-     * @access  public
1998
-     * @return void
1999
-     * @throws \EE_Error
2000
-     */
2001
-    public function extra_actions_meta_box()
2002
-    {
2003
-        $template_form_fields = array();
2004
-        
2005
-        $extra_args = array(
2006
-            'msgr'   => $this->_message_template_group->messenger(),
2007
-            'mt'     => $this->_message_template_group->message_type(),
2008
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2009
-        );
2010
-        //first we need to see if there are any fields
2011
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2012
-        
2013
-        if ( ! empty($fields)) {
2014
-            //yup there be fields
2015
-            foreach ($fields as $field => $config) {
2016
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2017
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2018
-                $default  = isset($config['default']) ? $config['default'] : '';
2019
-                $default  = isset($config['value']) ? $config['value'] : $default;
1943
+			$tp_select_values[] = array(
1944
+				'text' => $tp->label,
1945
+				'id'   => $tp->dbref
1946
+			);
1947
+		}
1948
+        
1949
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1950
+		if (empty($tp_select_values)) {
1951
+			$tp_select_values[] = array(
1952
+				'text' => __('Default', 'event_espresso'),
1953
+				'id'   => 'default'
1954
+			);
1955
+		}
1956
+        
1957
+		//setup variation select values for the currently selected template.
1958
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
1959
+			$this->_message_template_group->messenger(),
1960
+			$this->_message_template_group->message_type()
1961
+		);
1962
+		$variations_select_values = array();
1963
+		foreach ($variations as $variation => $label) {
1964
+			$variations_select_values[] = array(
1965
+				'text' => $label,
1966
+				'id'   => $variation
1967
+			);
1968
+		}
1969
+        
1970
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1971
+        
1972
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1973
+			'MTP_template_pack',
1974
+			$tp_select_values,
1975
+			$this->_message_template_group->get_template_pack_name()
1976
+		);
1977
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
1978
+			'MTP_template_variation',
1979
+			$variations_select_values,
1980
+			$this->_message_template_group->get_template_pack_variation()
1981
+		);
1982
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
1983
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
1984
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1985
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1986
+        
1987
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1988
+        
1989
+		EEH_Template::display_template($template, $template_args);
1990
+	}
1991
+    
1992
+    
1993
+	/**
1994
+	 * This meta box holds any extra actions related to Message Templates
1995
+	 * For now, this includes Resetting templates to defaults and sending a test email.
1996
+	 *
1997
+	 * @access  public
1998
+	 * @return void
1999
+	 * @throws \EE_Error
2000
+	 */
2001
+	public function extra_actions_meta_box()
2002
+	{
2003
+		$template_form_fields = array();
2004
+        
2005
+		$extra_args = array(
2006
+			'msgr'   => $this->_message_template_group->messenger(),
2007
+			'mt'     => $this->_message_template_group->message_type(),
2008
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2009
+		);
2010
+		//first we need to see if there are any fields
2011
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2012
+        
2013
+		if ( ! empty($fields)) {
2014
+			//yup there be fields
2015
+			foreach ($fields as $field => $config) {
2016
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2017
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2018
+				$default  = isset($config['default']) ? $config['default'] : '';
2019
+				$default  = isset($config['value']) ? $config['value'] : $default;
2020 2020
                 
2021
-                // if type is hidden and the value is empty
2022
-                // something may have gone wrong so let's correct with the defaults
2023
-                $fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2024
-                    ? $default
2025
-                    : '';
2026
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2027
-                    ? $existing[$field]
2028
-                    : $fix;
2021
+				// if type is hidden and the value is empty
2022
+				// something may have gone wrong so let's correct with the defaults
2023
+				$fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2024
+					? $default
2025
+					: '';
2026
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2027
+					? $existing[$field]
2028
+					: $fix;
2029 2029
                 
2030
-                $template_form_fields[$field_id] = array(
2031
-                    'name'       => 'test_settings_fld[' . $field . ']',
2032
-                    'label'      => $config['label'],
2033
-                    'input'      => $config['input'],
2034
-                    'type'       => $config['type'],
2035
-                    'required'   => $config['required'],
2036
-                    'validation' => $config['validation'],
2037
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2038
-                    'css_class'  => $config['css_class'],
2039
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2040
-                    'default'    => $default,
2041
-                    'format'     => $config['format']
2042
-                );
2043
-            }
2044
-        }
2045
-        
2046
-        $test_settings_fields = ! empty($template_form_fields)
2047
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2048
-            : '';
2049
-        
2050
-        $test_settings_html = '';
2051
-        //print out $test_settings_fields
2052
-        if ( ! empty($test_settings_fields)) {
2053
-            echo $test_settings_fields;
2054
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2055
-            $test_settings_html .= 'name="test_button" value="';
2056
-            $test_settings_html .= __('Test Send', 'event_espresso');
2057
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2058
-        }
2059
-        
2060
-        //and button
2061
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2062
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2063
-        $test_settings_html .= $this->get_action_link_or_button(
2064
-            'reset_to_default',
2065
-            'reset',
2066
-            $extra_args,
2067
-            'button-primary reset-default-button'
2068
-        );
2069
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2070
-        echo $test_settings_html;
2071
-    }
2072
-    
2073
-    
2074
-    /**
2075
-     * This returns the shortcode selector skeleton for a given context and field.
2076
-     *
2077
-     * @since 4.9.rc.000
2078
-     *
2079
-     * @param string $field           The name of the field retrieving shortcodes for.
2080
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2081
-     *
2082
-     * @return string
2083
-     */
2084
-    protected function _get_shortcode_selector($field, $linked_input_id)
2085
-    {
2086
-        $template_args = array(
2087
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2088
-            'fieldname'       => $field,
2089
-            'linked_input_id' => $linked_input_id
2090
-        );
2091
-        
2092
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2093
-            $template_args, true);
2094
-    }
2095
-    
2096
-    
2097
-    /**
2098
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2099
-     * page)
2100
-     *
2101
-     * @access public
2102
-     * @return void
2103
-     */
2104
-    public function shortcode_meta_box()
2105
-    {
2106
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2107
-        //$messenger = $this->_message_template_group->messenger_obj();
2108
-        //now let's set the content depending on the status of the shortcodes array
2109
-        if (empty($shortcodes)) {
2110
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2111
-            echo $content;
2112
-        } else {
2113
-            //$alt = 0;
2114
-            ?>
2030
+				$template_form_fields[$field_id] = array(
2031
+					'name'       => 'test_settings_fld[' . $field . ']',
2032
+					'label'      => $config['label'],
2033
+					'input'      => $config['input'],
2034
+					'type'       => $config['type'],
2035
+					'required'   => $config['required'],
2036
+					'validation' => $config['validation'],
2037
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2038
+					'css_class'  => $config['css_class'],
2039
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2040
+					'default'    => $default,
2041
+					'format'     => $config['format']
2042
+				);
2043
+			}
2044
+		}
2045
+        
2046
+		$test_settings_fields = ! empty($template_form_fields)
2047
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2048
+			: '';
2049
+        
2050
+		$test_settings_html = '';
2051
+		//print out $test_settings_fields
2052
+		if ( ! empty($test_settings_fields)) {
2053
+			echo $test_settings_fields;
2054
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2055
+			$test_settings_html .= 'name="test_button" value="';
2056
+			$test_settings_html .= __('Test Send', 'event_espresso');
2057
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2058
+		}
2059
+        
2060
+		//and button
2061
+		$test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2062
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2063
+		$test_settings_html .= $this->get_action_link_or_button(
2064
+			'reset_to_default',
2065
+			'reset',
2066
+			$extra_args,
2067
+			'button-primary reset-default-button'
2068
+		);
2069
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2070
+		echo $test_settings_html;
2071
+	}
2072
+    
2073
+    
2074
+	/**
2075
+	 * This returns the shortcode selector skeleton for a given context and field.
2076
+	 *
2077
+	 * @since 4.9.rc.000
2078
+	 *
2079
+	 * @param string $field           The name of the field retrieving shortcodes for.
2080
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2081
+	 *
2082
+	 * @return string
2083
+	 */
2084
+	protected function _get_shortcode_selector($field, $linked_input_id)
2085
+	{
2086
+		$template_args = array(
2087
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2088
+			'fieldname'       => $field,
2089
+			'linked_input_id' => $linked_input_id
2090
+		);
2091
+        
2092
+		return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2093
+			$template_args, true);
2094
+	}
2095
+    
2096
+    
2097
+	/**
2098
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2099
+	 * page)
2100
+	 *
2101
+	 * @access public
2102
+	 * @return void
2103
+	 */
2104
+	public function shortcode_meta_box()
2105
+	{
2106
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2107
+		//$messenger = $this->_message_template_group->messenger_obj();
2108
+		//now let's set the content depending on the status of the shortcodes array
2109
+		if (empty($shortcodes)) {
2110
+			$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2111
+			echo $content;
2112
+		} else {
2113
+			//$alt = 0;
2114
+			?>
2115 2115
             <div
2116 2116
                 style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2117 2117
             <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2118
-                    'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2118
+					'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2119 2119
             <?php
2120
-        }
2121
-        
2122
-        
2123
-    }
2124
-    
2125
-    
2126
-    /**
2127
-     * used to set the $_shortcodes property for when its needed elsewhere.
2128
-     *
2129
-     * @access protected
2130
-     * @return void
2131
-     */
2132
-    protected function _set_shortcodes()
2133
-    {
2134
-        
2135
-        //no need to run this if the property is already set
2136
-        if ( ! empty($this->_shortcodes)) {
2137
-            return;
2138
-        }
2139
-        
2140
-        $this->_shortcodes = $this->_get_shortcodes();
2141
-    }
2142
-    
2143
-    
2144
-    /**
2145
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2146
-     * property)
2147
-     *
2148
-     * @access  protected
2149
-     *
2150
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2151
-     *                         for. Defaults to all (for the given context)
2152
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2153
-     *
2154
-     * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2155
-     *                        true just an array of shortcode/label pairs.
2156
-     */
2157
-    protected function _get_shortcodes($fields = array(), $merged = true)
2158
-    {
2159
-        $this->_set_message_template_group();
2160
-        
2161
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2162
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2163
-        $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2164
-        
2165
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2166
-    }
2167
-    
2168
-    
2169
-    /**
2170
-     * This sets the _message_template property (containing the called message_template object)
2171
-     *
2172
-     * @access protected
2173
-     * @return  void
2174
-     */
2175
-    protected function _set_message_template_group()
2176
-    {
2177
-        
2178
-        if ( ! empty($this->_message_template_group)) {
2179
-            return;
2180
-        } //get out if this is already set.
2181
-        
2182
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2183
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2184
-        
2185
-        //let's get the message templates
2186
-        $MTP = EEM_Message_Template_Group::instance();
2187
-        
2188
-        if (empty($GRP_ID)) {
2189
-            $this->_message_template_group = $MTP->create_default_object();
2190
-        } else {
2191
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2192
-        }
2193
-        
2194
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2195
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2196
-        
2197
-    }
2198
-    
2199
-    
2200
-    /**
2201
-     * sets up a context switcher for edit forms
2202
-     *
2203
-     * @access  protected
2204
-     *
2205
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2206
-     * @param array                      $args                  various things the context switcher needs.
2207
-     *
2208
-     */
2209
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2210
-    {
2211
-        $context_details = $template_group_object->contexts_config();
2212
-        $context_label   = $template_group_object->context_label();
2213
-        ob_start();
2214
-        ?>
2120
+		}
2121
+        
2122
+        
2123
+	}
2124
+    
2125
+    
2126
+	/**
2127
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2128
+	 *
2129
+	 * @access protected
2130
+	 * @return void
2131
+	 */
2132
+	protected function _set_shortcodes()
2133
+	{
2134
+        
2135
+		//no need to run this if the property is already set
2136
+		if ( ! empty($this->_shortcodes)) {
2137
+			return;
2138
+		}
2139
+        
2140
+		$this->_shortcodes = $this->_get_shortcodes();
2141
+	}
2142
+    
2143
+    
2144
+	/**
2145
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2146
+	 * property)
2147
+	 *
2148
+	 * @access  protected
2149
+	 *
2150
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2151
+	 *                         for. Defaults to all (for the given context)
2152
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2153
+	 *
2154
+	 * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2155
+	 *                        true just an array of shortcode/label pairs.
2156
+	 */
2157
+	protected function _get_shortcodes($fields = array(), $merged = true)
2158
+	{
2159
+		$this->_set_message_template_group();
2160
+        
2161
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2162
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2163
+		$context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2164
+        
2165
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2166
+	}
2167
+    
2168
+    
2169
+	/**
2170
+	 * This sets the _message_template property (containing the called message_template object)
2171
+	 *
2172
+	 * @access protected
2173
+	 * @return  void
2174
+	 */
2175
+	protected function _set_message_template_group()
2176
+	{
2177
+        
2178
+		if ( ! empty($this->_message_template_group)) {
2179
+			return;
2180
+		} //get out if this is already set.
2181
+        
2182
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2183
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2184
+        
2185
+		//let's get the message templates
2186
+		$MTP = EEM_Message_Template_Group::instance();
2187
+        
2188
+		if (empty($GRP_ID)) {
2189
+			$this->_message_template_group = $MTP->create_default_object();
2190
+		} else {
2191
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2192
+		}
2193
+        
2194
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2195
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2196
+        
2197
+	}
2198
+    
2199
+    
2200
+	/**
2201
+	 * sets up a context switcher for edit forms
2202
+	 *
2203
+	 * @access  protected
2204
+	 *
2205
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2206
+	 * @param array                      $args                  various things the context switcher needs.
2207
+	 *
2208
+	 */
2209
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2210
+	{
2211
+		$context_details = $template_group_object->contexts_config();
2212
+		$context_label   = $template_group_object->context_label();
2213
+		ob_start();
2214
+		?>
2215 2215
         <div class="ee-msg-switcher-container">
2216 2216
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2217 2217
                 <?php
2218
-                foreach ($args as $name => $value) {
2219
-                    if ($name == 'context' || empty($value) || $name == 'extra') {
2220
-                        continue;
2221
-                    }
2222
-                    ?>
2218
+				foreach ($args as $name => $value) {
2219
+					if ($name == 'context' || empty($value) || $name == 'extra') {
2220
+						continue;
2221
+					}
2222
+					?>
2223 2223
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2224 2224
                     <?php
2225
-                }
2226
-                //setup nonce_url
2227
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2228
-                ?>
2225
+				}
2226
+				//setup nonce_url
2227
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2228
+				?>
2229 2229
                 <select name="context">
2230 2230
                     <?php
2231
-                    $context_templates = $template_group_object->context_templates();
2232
-                    if (is_array($context_templates)) :
2233
-                        foreach ($context_templates as $context => $template_fields) :
2234
-                            $checked = ($context == $args['context']) ? 'selected="selected"' : '';
2235
-                            ?>
2231
+					$context_templates = $template_group_object->context_templates();
2232
+					if (is_array($context_templates)) :
2233
+						foreach ($context_templates as $context => $template_fields) :
2234
+							$checked = ($context == $args['context']) ? 'selected="selected"' : '';
2235
+							?>
2236 2236
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2237 2237
                                 <?php echo $context_details[$context]['label']; ?>
2238 2238
                             </option>
@@ -2245,1584 +2245,1584 @@  discard block
 block discarded – undo
2245 2245
             <?php echo $args['extra']; ?>
2246 2246
         </div> <!-- end .ee-msg-switcher-container -->
2247 2247
         <?php
2248
-        $output = ob_get_contents();
2249
-        ob_clean();
2250
-        $this->_context_switcher = $output;
2251
-    }
2252
-    
2253
-    
2254
-    /**
2255
-     * utility for sanitizing new values coming in.
2256
-     * Note: this is only used when updating a context.
2257
-     *
2258
-     * @access protected
2259
-     *
2260
-     * @param int $index This helps us know which template field to select from the request array.
2261
-     *
2262
-     * @return array
2263
-     */
2264
-    protected function _set_message_template_column_values($index)
2265
-    {
2266
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2267
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2268
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2269
-            }
2270
-        } /*else {
2248
+		$output = ob_get_contents();
2249
+		ob_clean();
2250
+		$this->_context_switcher = $output;
2251
+	}
2252
+    
2253
+    
2254
+	/**
2255
+	 * utility for sanitizing new values coming in.
2256
+	 * Note: this is only used when updating a context.
2257
+	 *
2258
+	 * @access protected
2259
+	 *
2260
+	 * @param int $index This helps us know which template field to select from the request array.
2261
+	 *
2262
+	 * @return array
2263
+	 */
2264
+	protected function _set_message_template_column_values($index)
2265
+	{
2266
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2267
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2268
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2269
+			}
2270
+		} /*else {
2271 2271
 			$this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content'];
2272 2272
 		}*/
2273 2273
         
2274 2274
         
2275
-        $set_column_values = array(
2276
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2277
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2278
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2279
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2280
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2281
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2282
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2283
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2284
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2285
-                ? absint($this->_req_data['MTP_is_global'])
2286
-                : 0,
2287
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2288
-                ? absint($this->_req_data['MTP_is_override'])
2289
-                : 0,
2290
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2291
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2292
-        );
2293
-        
2294
-        
2295
-        return $set_column_values;
2296
-    }
2297
-    
2298
-    
2299
-    protected function _insert_or_update_message_template($new = false)
2300
-    {
2301
-        
2302
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2303
-        $success  = 0;
2304
-        $override = false;
2305
-        
2306
-        //setup notices description
2307
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2308
-        
2309
-        //need the message type and messenger objects to be able to use the labels for the notices
2310
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2311
-        $messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2312
-        
2313
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2314
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2315
-        
2316
-        $message_type_label = $message_type_object instanceof EE_message_type
2317
-            ? ucwords($message_type_object->label['singular'])
2318
-            : '';
2319
-        
2320
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2321
-            ? $this->_req_data['MTP_context']
2322
-            : '';
2323
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2324
-        
2325
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2326
-        $item_desc .= 'Message Template';
2327
-        $query_args  = array();
2328
-        $edit_array  = array();
2329
-        $action_desc = '';
2330
-        
2331
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2332
-        if ($new) {
2333
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2334
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2335
-                if (empty($edit_array)) {
2336
-                    $success = 0;
2337
-                } else {
2338
-                    $success    = 1;
2339
-                    $edit_array = $edit_array[0];
2340
-                    $query_args = array(
2341
-                        'id'      => $edit_array['GRP_ID'],
2342
-                        'context' => $edit_array['MTP_context'],
2343
-                        'action'  => 'edit_message_template'
2344
-                    );
2345
-                }
2346
-            }
2347
-            $action_desc = 'created';
2348
-        } else {
2349
-            $MTPG = EEM_Message_Template_Group::instance();
2350
-            $MTP  = EEM_Message_Template::instance();
2275
+		$set_column_values = array(
2276
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2277
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2278
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2279
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2280
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2281
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2282
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2283
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2284
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2285
+				? absint($this->_req_data['MTP_is_global'])
2286
+				: 0,
2287
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2288
+				? absint($this->_req_data['MTP_is_override'])
2289
+				: 0,
2290
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2291
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2292
+		);
2293
+        
2294
+        
2295
+		return $set_column_values;
2296
+	}
2297
+    
2298
+    
2299
+	protected function _insert_or_update_message_template($new = false)
2300
+	{
2301
+        
2302
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2303
+		$success  = 0;
2304
+		$override = false;
2305
+        
2306
+		//setup notices description
2307
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2308
+        
2309
+		//need the message type and messenger objects to be able to use the labels for the notices
2310
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2311
+		$messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2312
+        
2313
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2314
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2315
+        
2316
+		$message_type_label = $message_type_object instanceof EE_message_type
2317
+			? ucwords($message_type_object->label['singular'])
2318
+			: '';
2319
+        
2320
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2321
+			? $this->_req_data['MTP_context']
2322
+			: '';
2323
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2324
+        
2325
+		$item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2326
+		$item_desc .= 'Message Template';
2327
+		$query_args  = array();
2328
+		$edit_array  = array();
2329
+		$action_desc = '';
2330
+        
2331
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2332
+		if ($new) {
2333
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2334
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2335
+				if (empty($edit_array)) {
2336
+					$success = 0;
2337
+				} else {
2338
+					$success    = 1;
2339
+					$edit_array = $edit_array[0];
2340
+					$query_args = array(
2341
+						'id'      => $edit_array['GRP_ID'],
2342
+						'context' => $edit_array['MTP_context'],
2343
+						'action'  => 'edit_message_template'
2344
+					);
2345
+				}
2346
+			}
2347
+			$action_desc = 'created';
2348
+		} else {
2349
+			$MTPG = EEM_Message_Template_Group::instance();
2350
+			$MTP  = EEM_Message_Template::instance();
2351 2351
             
2352 2352
             
2353
-            //run update for each template field in displayed context
2354
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2355
-                EE_Error::add_error(
2356
-                    __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2357
-                        'event_espresso'),
2358
-                    __FILE__, __FUNCTION__, __LINE__
2359
-                );
2360
-                $success = 0;
2353
+			//run update for each template field in displayed context
2354
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2355
+				EE_Error::add_error(
2356
+					__('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2357
+						'event_espresso'),
2358
+					__FILE__, __FUNCTION__, __LINE__
2359
+				);
2360
+				$success = 0;
2361 2361
                 
2362
-            } else {
2363
-                //first validate all fields!
2364
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2365
-                    $message_type_slug);
2362
+			} else {
2363
+				//first validate all fields!
2364
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2365
+					$message_type_slug);
2366 2366
                 
2367
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2368
-                if (is_array($validates) && ! empty($validates)) {
2369
-                    //add the transient so when the form loads we know which fields to highlight
2370
-                    $this->_add_transient('edit_message_template', $validates);
2367
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2368
+				if (is_array($validates) && ! empty($validates)) {
2369
+					//add the transient so when the form loads we know which fields to highlight
2370
+					$this->_add_transient('edit_message_template', $validates);
2371 2371
                     
2372
-                    $success = 0;
2372
+					$success = 0;
2373 2373
                     
2374
-                    //setup notices
2375
-                    foreach ($validates as $field => $error) {
2376
-                        if (isset($error['msg'])) {
2377
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2378
-                        }
2379
-                    }
2374
+					//setup notices
2375
+					foreach ($validates as $field => $error) {
2376
+						if (isset($error['msg'])) {
2377
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2378
+						}
2379
+					}
2380 2380
                     
2381
-                } else {
2382
-                    $set_column_values = array();
2383
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2384
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2381
+				} else {
2382
+					$set_column_values = array();
2383
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2384
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2385 2385
                         
2386
-                        $where_cols_n_values = array(
2387
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2388
-                        );
2386
+						$where_cols_n_values = array(
2387
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2388
+						);
2389 2389
                         
2390
-                        $message_template_fields = array(
2391
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2392
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2393
-                            'MTP_context'        => $set_column_values['MTP_context'],
2394
-                            'MTP_content'        => $set_column_values['MTP_content']
2395
-                        );
2396
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2397
-                            if ($updated === false) {
2398
-                                EE_Error::add_error(
2399
-                                    sprintf(
2400
-                                        __('%s field was NOT updated for some reason', 'event_espresso'),
2401
-                                        $template_field
2402
-                                    ),
2403
-                                    __FILE__, __FUNCTION__, __LINE__
2404
-                                );
2405
-                            } else {
2406
-                                $success = 1;
2407
-                            }
2408
-                        }
2409
-                        $action_desc = 'updated';
2410
-                    }
2390
+						$message_template_fields = array(
2391
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2392
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2393
+							'MTP_context'        => $set_column_values['MTP_context'],
2394
+							'MTP_content'        => $set_column_values['MTP_content']
2395
+						);
2396
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2397
+							if ($updated === false) {
2398
+								EE_Error::add_error(
2399
+									sprintf(
2400
+										__('%s field was NOT updated for some reason', 'event_espresso'),
2401
+										$template_field
2402
+									),
2403
+									__FILE__, __FUNCTION__, __LINE__
2404
+								);
2405
+							} else {
2406
+								$success = 1;
2407
+							}
2408
+						}
2409
+						$action_desc = 'updated';
2410
+					}
2411 2411
                     
2412
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2413
-                    $mtpg_fields = array(
2414
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2415
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2416
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2417
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2418
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2419
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2420
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2421
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2422
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2423
-                            : '',
2424
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2425
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2426
-                            : ''
2427
-                    );
2412
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2413
+					$mtpg_fields = array(
2414
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2415
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2416
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2417
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2418
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2419
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2420
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2421
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2422
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2423
+							: '',
2424
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2425
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2426
+							: ''
2427
+					);
2428 2428
                     
2429
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2430
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2429
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2430
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2431 2431
                     
2432
-                    if ($updated === false) {
2433
-                        EE_Error::add_error(
2434
-                            sprintf(
2435
-                                __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2436
-                                $set_column_values['GRP_ID']
2437
-                            ),
2438
-                            __FILE__, __FUNCTION__, __LINE__
2439
-                        );
2440
-                    } else {
2441
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2442
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2443
-                            ? $this->_req_data['MTP_template_pack']
2444
-                            : 'default';
2432
+					if ($updated === false) {
2433
+						EE_Error::add_error(
2434
+							sprintf(
2435
+								__('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2436
+								$set_column_values['GRP_ID']
2437
+							),
2438
+							__FILE__, __FUNCTION__, __LINE__
2439
+						);
2440
+					} else {
2441
+						//k now we need to ensure the template_pack and template_variation fields are set.
2442
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2443
+							? $this->_req_data['MTP_template_pack']
2444
+							: 'default';
2445 2445
                         
2446
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2447
-                            ? $this->_req_data['MTP_template_variation']
2448
-                            : 'default';
2446
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2447
+							? $this->_req_data['MTP_template_variation']
2448
+							: 'default';
2449 2449
                         
2450
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2451
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2452
-                            $mtpg_obj->set_template_pack_name($template_pack);
2453
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2454
-                        }
2455
-                        $success = 1;
2456
-                    }
2457
-                }
2458
-            }
2450
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2451
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2452
+							$mtpg_obj->set_template_pack_name($template_pack);
2453
+							$mtpg_obj->set_template_pack_variation($template_variation);
2454
+						}
2455
+						$success = 1;
2456
+					}
2457
+				}
2458
+			}
2459 2459
             
2460
-        }
2461
-        
2462
-        //we return things differently if doing ajax
2463
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2464
-            $this->_template_args['success'] = $success;
2465
-            $this->_template_args['error']   = ! $success ? true : false;
2466
-            $this->_template_args['content'] = '';
2467
-            $this->_template_args['data']    = array(
2468
-                'grpID'        => $edit_array['GRP_ID'],
2469
-                'templateName' => $edit_array['template_name']
2470
-            );
2471
-            if ($success) {
2472
-                EE_Error::overwrite_success();
2473
-                EE_Error::add_success(__('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.',
2474
-                    'event_espresso'));
2475
-            }
2460
+		}
2461
+        
2462
+		//we return things differently if doing ajax
2463
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2464
+			$this->_template_args['success'] = $success;
2465
+			$this->_template_args['error']   = ! $success ? true : false;
2466
+			$this->_template_args['content'] = '';
2467
+			$this->_template_args['data']    = array(
2468
+				'grpID'        => $edit_array['GRP_ID'],
2469
+				'templateName' => $edit_array['template_name']
2470
+			);
2471
+			if ($success) {
2472
+				EE_Error::overwrite_success();
2473
+				EE_Error::add_success(__('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.',
2474
+					'event_espresso'));
2475
+			}
2476 2476
             
2477
-            $this->_return_json();
2478
-        }
2479
-        
2480
-        
2481
-        //was a test send triggered?
2482
-        if (isset($this->_req_data['test_button'])) {
2483
-            EE_Error::overwrite_success();
2484
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2485
-            $override = true;
2486
-        }
2487
-        
2488
-        if (empty($query_args)) {
2489
-            $query_args = array(
2490
-                'id'      => $this->_req_data['GRP_ID'],
2491
-                'context' => $context_slug,
2492
-                'action'  => 'edit_message_template'
2493
-            );
2494
-        }
2495
-        
2496
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2497
-    }
2498
-    
2499
-    
2500
-    /**
2501
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2502
-     *
2503
-     * @param  string $context      what context being tested
2504
-     * @param  string $messenger    messenger being tested
2505
-     * @param  string $message_type message type being tested
2506
-     *
2507
-     */
2508
-    protected function _do_test_send($context, $messenger, $message_type)
2509
-    {
2510
-        //set things up for preview
2511
-        $this->_req_data['messenger']    = $messenger;
2512
-        $this->_req_data['message_type'] = $message_type;
2513
-        $this->_req_data['context']      = $context;
2514
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2515
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2516
-        
2517
-        //let's save any existing fields that might be required by the messenger
2518
-        if (
2519
-            isset($this->_req_data['test_settings_fld'])
2520
-            && $active_messenger instanceof EE_messenger
2521
-            && apply_filters(
2522
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2523
-                true,
2524
-                $this->_req_data['test_settings_fld'],
2525
-                $active_messenger
2526
-            )
2527
-        ) {
2528
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2529
-        }
2530
-        
2531
-        $success = $this->_preview_message(true);
2532
-        
2533
-        if ($success) {
2534
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2535
-        } else {
2536
-            EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2537
-                __LINE__);
2538
-        }
2539
-    }
2540
-    
2541
-    
2542
-    /**
2543
-     * _generate_new_templates
2544
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2545
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2546
-     * for the event.
2547
-     *
2548
-     *
2549
-     * @param  string $messenger     the messenger we are generating templates for
2550
-     * @param array   $message_types array of message types that the templates are generated for.
2551
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2552
-     *                               indicate the message_template_group being used as the base.
2553
-     *
2554
-     * @param bool    $global
2555
-     *
2556
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2557
-     *                               encountering problems.
2558
-     * @throws \EE_Error
2559
-     */
2560
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2561
-    {
2562
-        
2563
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2564
-        if (empty($message_types)) {
2565
-            return true;
2566
-        }
2567
-        
2568
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2569
-    }
2570
-    
2571
-    
2572
-    /**
2573
-     * [_trash_or_restore_message_template]
2574
-     *
2575
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2576
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2577
-     *                        an individual context (FALSE).
2578
-     *
2579
-     * @return void
2580
-     */
2581
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2582
-    {
2583
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2584
-        $MTP = EEM_Message_Template_Group::instance();
2585
-        
2586
-        $success = 1;
2587
-        
2588
-        //incoming GRP_IDs
2589
-        if ($all) {
2590
-            //Checkboxes
2591
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2592
-                //if array has more than one element then success message should be plural.
2593
-                //todo: what about nonce?
2594
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2477
+			$this->_return_json();
2478
+		}
2479
+        
2480
+        
2481
+		//was a test send triggered?
2482
+		if (isset($this->_req_data['test_button'])) {
2483
+			EE_Error::overwrite_success();
2484
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2485
+			$override = true;
2486
+		}
2487
+        
2488
+		if (empty($query_args)) {
2489
+			$query_args = array(
2490
+				'id'      => $this->_req_data['GRP_ID'],
2491
+				'context' => $context_slug,
2492
+				'action'  => 'edit_message_template'
2493
+			);
2494
+		}
2495
+        
2496
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2497
+	}
2498
+    
2499
+    
2500
+	/**
2501
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2502
+	 *
2503
+	 * @param  string $context      what context being tested
2504
+	 * @param  string $messenger    messenger being tested
2505
+	 * @param  string $message_type message type being tested
2506
+	 *
2507
+	 */
2508
+	protected function _do_test_send($context, $messenger, $message_type)
2509
+	{
2510
+		//set things up for preview
2511
+		$this->_req_data['messenger']    = $messenger;
2512
+		$this->_req_data['message_type'] = $message_type;
2513
+		$this->_req_data['context']      = $context;
2514
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2515
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2516
+        
2517
+		//let's save any existing fields that might be required by the messenger
2518
+		if (
2519
+			isset($this->_req_data['test_settings_fld'])
2520
+			&& $active_messenger instanceof EE_messenger
2521
+			&& apply_filters(
2522
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2523
+				true,
2524
+				$this->_req_data['test_settings_fld'],
2525
+				$active_messenger
2526
+			)
2527
+		) {
2528
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2529
+		}
2530
+        
2531
+		$success = $this->_preview_message(true);
2532
+        
2533
+		if ($success) {
2534
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2535
+		} else {
2536
+			EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2537
+				__LINE__);
2538
+		}
2539
+	}
2540
+    
2541
+    
2542
+	/**
2543
+	 * _generate_new_templates
2544
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2545
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2546
+	 * for the event.
2547
+	 *
2548
+	 *
2549
+	 * @param  string $messenger     the messenger we are generating templates for
2550
+	 * @param array   $message_types array of message types that the templates are generated for.
2551
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2552
+	 *                               indicate the message_template_group being used as the base.
2553
+	 *
2554
+	 * @param bool    $global
2555
+	 *
2556
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2557
+	 *                               encountering problems.
2558
+	 * @throws \EE_Error
2559
+	 */
2560
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2561
+	{
2562
+        
2563
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2564
+		if (empty($message_types)) {
2565
+			return true;
2566
+		}
2567
+        
2568
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2569
+	}
2570
+    
2571
+    
2572
+	/**
2573
+	 * [_trash_or_restore_message_template]
2574
+	 *
2575
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2576
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2577
+	 *                        an individual context (FALSE).
2578
+	 *
2579
+	 * @return void
2580
+	 */
2581
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2582
+	{
2583
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2584
+		$MTP = EEM_Message_Template_Group::instance();
2585
+        
2586
+		$success = 1;
2587
+        
2588
+		//incoming GRP_IDs
2589
+		if ($all) {
2590
+			//Checkboxes
2591
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2592
+				//if array has more than one element then success message should be plural.
2593
+				//todo: what about nonce?
2594
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2595 2595
                 
2596
-                //cycle through checkboxes
2597
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2598
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
-                    if ( ! $trashed_or_restored) {
2600
-                        $success = 0;
2601
-                    }
2602
-                }
2603
-            } else {
2604
-                //grab single GRP_ID and handle
2605
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2606
-                if ( ! empty($GRP_ID)) {
2607
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2608
-                    if ( ! $trashed_or_restored) {
2609
-                        $success = 0;
2610
-                    }
2611
-                } else {
2612
-                    $success = 0;
2613
-                }
2614
-            }
2596
+				//cycle through checkboxes
2597
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2598
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
+					if ( ! $trashed_or_restored) {
2600
+						$success = 0;
2601
+					}
2602
+				}
2603
+			} else {
2604
+				//grab single GRP_ID and handle
2605
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2606
+				if ( ! empty($GRP_ID)) {
2607
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2608
+					if ( ! $trashed_or_restored) {
2609
+						$success = 0;
2610
+					}
2611
+				} else {
2612
+					$success = 0;
2613
+				}
2614
+			}
2615 2615
             
2616
-        }
2616
+		}
2617 2617
         
2618
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2618
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2619 2619
         
2620
-        $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2620
+		$action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2621 2621
         
2622
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2623
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2622
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2623
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2624 2624
         
2625
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2626
-            'event_espresso') : $item_desc;
2625
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2626
+			'event_espresso') : $item_desc;
2627 2627
         
2628
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
2628
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
2629 2629
         
2630
-    }
2630
+	}
2631 2631
     
2632 2632
     
2633
-    /**
2634
-     * [_delete_message_template]
2635
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2636
-     * @return void
2637
-     */
2638
-    protected function _delete_message_template()
2639
-    {
2640
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2633
+	/**
2634
+	 * [_delete_message_template]
2635
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2636
+	 * @return void
2637
+	 */
2638
+	protected function _delete_message_template()
2639
+	{
2640
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2641 2641
         
2642
-        //checkboxes
2643
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2644
-            //if array has more than one element then success message should be plural
2645
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2642
+		//checkboxes
2643
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2644
+			//if array has more than one element then success message should be plural
2645
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2646 2646
             
2647
-            //cycle through bulk action checkboxes
2648
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2649
-                $success = $this->_delete_mtp_permanently($GRP_ID);
2650
-            }
2651
-        } else {
2652
-            //grab single grp_id and delete
2653
-            $GRP_ID  = absint($this->_req_data['id']);
2654
-            $success = $this->_delete_mtp_permanently($GRP_ID);
2655
-        }
2656
-        
2657
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2658
-        
2659
-    }
2660
-    
2661
-    
2662
-    /**
2663
-     * helper for permanently deleting a mtP group and all related message_templates
2664
-     *
2665
-     * @param  int  $GRP_ID        The group being deleted
2666
-     * @param  bool $include_group whether to delete the Message Template Group as well.
2667
-     *
2668
-     * @return bool        boolean to indicate the success of the deletes or not.
2669
-     */
2670
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2671
-    {
2672
-        $success = 1;
2673
-        $MTPG    = EEM_Message_Template_Group::instance();
2674
-        //first let's GET this group
2675
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
2676
-        //then delete permanently all the related Message Templates
2677
-        $deleted = $MTG->delete_related_permanently('Message_Template');
2678
-        
2679
-        if ($deleted === 0) {
2680
-            $success = 0;
2681
-        }
2682
-        
2683
-        //now delete permanently this particular group
2684
-        
2685
-        if ($include_group && ! $MTG->delete_permanently()) {
2686
-            $success = 0;
2687
-        }
2688
-        
2689
-        return $success;
2690
-    }
2691
-    
2692
-    
2693
-    /**
2694
-     *    _learn_more_about_message_templates_link
2695
-     * @access protected
2696
-     * @return string
2697
-     */
2698
-    protected function _learn_more_about_message_templates_link()
2699
-    {
2700
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2701
-            'event_espresso') . '</a>';
2702
-    }
2703
-    
2704
-    
2705
-    /**
2706
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2707
-     * ajax and other routes.
2708
-     * @return void
2709
-     */
2710
-    protected function _settings()
2711
-    {
2712
-        
2713
-        
2714
-        $this->_set_m_mt_settings();
2715
-        
2716
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2717
-        
2718
-        //let's setup the messenger tabs
2719
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2720
-            'messenger_links', '|', $selected_messenger);
2721
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2722
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2723
-        
2724
-        $this->display_admin_page_with_sidebar();
2725
-        
2726
-    }
2727
-    
2728
-    
2729
-    /**
2730
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2731
-     *
2732
-     * @access protected
2733
-     * @return void
2734
-     */
2735
-    protected function _set_m_mt_settings()
2736
-    {
2737
-        //first if this is already set then lets get out no need to regenerate data.
2738
-        if ( ! empty($this->_m_mt_settings)) {
2739
-            return;
2740
-        }
2741
-        
2742
-        //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2743
-        
2744
-        //get all installed messengers and message_types
2745
-        /** @type EE_messenger[] $messengers */
2746
-        $messengers = $this->_message_resource_manager->installed_messengers();
2747
-        /** @type EE_message_type[] $message_types */
2748
-        $message_types = $this->_message_resource_manager->installed_message_types();
2749
-        
2750
-        
2751
-        //assemble the array for the _tab_text_links helper
2752
-        
2753
-        foreach ($messengers as $messenger) {
2754
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2755
-                'label' => ucwords($messenger->label['singular']),
2756
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2757
-                'href'  => $messenger->name,
2758
-                'title' => __('Modify this Messenger', 'event_espresso'),
2759
-                'slug'  => $messenger->name,
2760
-                'obj'   => $messenger
2761
-            );
2647
+			//cycle through bulk action checkboxes
2648
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2649
+				$success = $this->_delete_mtp_permanently($GRP_ID);
2650
+			}
2651
+		} else {
2652
+			//grab single grp_id and delete
2653
+			$GRP_ID  = absint($this->_req_data['id']);
2654
+			$success = $this->_delete_mtp_permanently($GRP_ID);
2655
+		}
2656
+        
2657
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2658
+        
2659
+	}
2660
+    
2661
+    
2662
+	/**
2663
+	 * helper for permanently deleting a mtP group and all related message_templates
2664
+	 *
2665
+	 * @param  int  $GRP_ID        The group being deleted
2666
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
2667
+	 *
2668
+	 * @return bool        boolean to indicate the success of the deletes or not.
2669
+	 */
2670
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2671
+	{
2672
+		$success = 1;
2673
+		$MTPG    = EEM_Message_Template_Group::instance();
2674
+		//first let's GET this group
2675
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
2676
+		//then delete permanently all the related Message Templates
2677
+		$deleted = $MTG->delete_related_permanently('Message_Template');
2678
+        
2679
+		if ($deleted === 0) {
2680
+			$success = 0;
2681
+		}
2682
+        
2683
+		//now delete permanently this particular group
2684
+        
2685
+		if ($include_group && ! $MTG->delete_permanently()) {
2686
+			$success = 0;
2687
+		}
2688
+        
2689
+		return $success;
2690
+	}
2691
+    
2692
+    
2693
+	/**
2694
+	 *    _learn_more_about_message_templates_link
2695
+	 * @access protected
2696
+	 * @return string
2697
+	 */
2698
+	protected function _learn_more_about_message_templates_link()
2699
+	{
2700
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2701
+			'event_espresso') . '</a>';
2702
+	}
2703
+    
2704
+    
2705
+	/**
2706
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2707
+	 * ajax and other routes.
2708
+	 * @return void
2709
+	 */
2710
+	protected function _settings()
2711
+	{
2712
+        
2713
+        
2714
+		$this->_set_m_mt_settings();
2715
+        
2716
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2717
+        
2718
+		//let's setup the messenger tabs
2719
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2720
+			'messenger_links', '|', $selected_messenger);
2721
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2722
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2723
+        
2724
+		$this->display_admin_page_with_sidebar();
2725
+        
2726
+	}
2727
+    
2728
+    
2729
+	/**
2730
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2731
+	 *
2732
+	 * @access protected
2733
+	 * @return void
2734
+	 */
2735
+	protected function _set_m_mt_settings()
2736
+	{
2737
+		//first if this is already set then lets get out no need to regenerate data.
2738
+		if ( ! empty($this->_m_mt_settings)) {
2739
+			return;
2740
+		}
2741
+        
2742
+		//$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2743
+        
2744
+		//get all installed messengers and message_types
2745
+		/** @type EE_messenger[] $messengers */
2746
+		$messengers = $this->_message_resource_manager->installed_messengers();
2747
+		/** @type EE_message_type[] $message_types */
2748
+		$message_types = $this->_message_resource_manager->installed_message_types();
2749
+        
2750
+        
2751
+		//assemble the array for the _tab_text_links helper
2752
+        
2753
+		foreach ($messengers as $messenger) {
2754
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2755
+				'label' => ucwords($messenger->label['singular']),
2756
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2757
+				'href'  => $messenger->name,
2758
+				'title' => __('Modify this Messenger', 'event_espresso'),
2759
+				'slug'  => $messenger->name,
2760
+				'obj'   => $messenger
2761
+			);
2762 2762
             
2763 2763
             
2764
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2764
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2765 2765
             
2766
-            foreach ($message_types as $message_type) {
2767
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2768
-                if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2769
-                    continue;
2770
-                }
2766
+			foreach ($message_types as $message_type) {
2767
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2768
+				if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2769
+					continue;
2770
+				}
2771 2771
                 
2772
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2773
-                    $message_type->name) ? 'active' : 'inactive';
2772
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2773
+					$message_type->name) ? 'active' : 'inactive';
2774 2774
                 
2775
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2776
-                    'label'    => ucwords($message_type->label['singular']),
2777
-                    'class'    => 'message-type-' . $a_or_i,
2778
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2779
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2780
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2781
-                    'title'    => $a_or_i == 'active'
2782
-                        ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2783
-                        : __('Drag this message type to the messenger to activate', 'event_espresso'),
2784
-                    'content'  => $a_or_i == 'active'
2785
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2786
-                        : $this->_message_type_settings_content($message_type, $messenger),
2787
-                    'slug'     => $message_type->name,
2788
-                    'active'   => $a_or_i == 'active' ? true : false,
2789
-                    'obj'      => $message_type
2790
-                );
2791
-            }
2792
-        }
2793
-    }
2794
-    
2795
-    
2796
-    /**
2797
-     * This just prepares the content for the message type settings
2798
-     *
2799
-     * @param  object  $message_type The message type object
2800
-     * @param  object  $messenger    The messenger object
2801
-     * @param  boolean $active       Whether the message type is active or not
2802
-     *
2803
-     * @return string                html output for the content
2804
-     */
2805
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2806
-    {
2807
-        //get message type fields
2808
-        $fields                                         = $message_type->get_admin_settings_fields();
2809
-        $settings_template_args['template_form_fields'] = '';
2810
-        
2811
-        if ( ! empty($fields) && $active) {
2775
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2776
+					'label'    => ucwords($message_type->label['singular']),
2777
+					'class'    => 'message-type-' . $a_or_i,
2778
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2779
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2780
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2781
+					'title'    => $a_or_i == 'active'
2782
+						? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2783
+						: __('Drag this message type to the messenger to activate', 'event_espresso'),
2784
+					'content'  => $a_or_i == 'active'
2785
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2786
+						: $this->_message_type_settings_content($message_type, $messenger),
2787
+					'slug'     => $message_type->name,
2788
+					'active'   => $a_or_i == 'active' ? true : false,
2789
+					'obj'      => $message_type
2790
+				);
2791
+			}
2792
+		}
2793
+	}
2794
+    
2795
+    
2796
+	/**
2797
+	 * This just prepares the content for the message type settings
2798
+	 *
2799
+	 * @param  object  $message_type The message type object
2800
+	 * @param  object  $messenger    The messenger object
2801
+	 * @param  boolean $active       Whether the message type is active or not
2802
+	 *
2803
+	 * @return string                html output for the content
2804
+	 */
2805
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2806
+	{
2807
+		//get message type fields
2808
+		$fields                                         = $message_type->get_admin_settings_fields();
2809
+		$settings_template_args['template_form_fields'] = '';
2810
+        
2811
+		if ( ! empty($fields) && $active) {
2812 2812
             
2813
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2813
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2814 2814
             
2815
-            foreach ($fields as $fldname => $fldprops) {
2816
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2817
-                $template_form_field[$field_id] = array(
2818
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2819
-                    'label'      => $fldprops['label'],
2820
-                    'input'      => $fldprops['field_type'],
2821
-                    'type'       => $fldprops['value_type'],
2822
-                    'required'   => $fldprops['required'],
2823
-                    'validation' => $fldprops['validation'],
2824
-                    'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2825
-                    'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2826
-                    'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2827
-                    'css_class'  => 'no-drag',
2828
-                    'format'     => $fldprops['format']
2829
-                );
2830
-            }
2815
+			foreach ($fields as $fldname => $fldprops) {
2816
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2817
+				$template_form_field[$field_id] = array(
2818
+					'name'       => 'message_type_settings[' . $fldname . ']',
2819
+					'label'      => $fldprops['label'],
2820
+					'input'      => $fldprops['field_type'],
2821
+					'type'       => $fldprops['value_type'],
2822
+					'required'   => $fldprops['required'],
2823
+					'validation' => $fldprops['validation'],
2824
+					'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2825
+					'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2826
+					'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2827
+					'css_class'  => 'no-drag',
2828
+					'format'     => $fldprops['format']
2829
+				);
2830
+			}
2831 2831
             
2832 2832
             
2833
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2834
-                'string', 'ee_mt_activate_form') : '';
2835
-        }
2836
-        
2837
-        $settings_template_args['description'] = $message_type->description;
2838
-        //we also need some hidden fields
2839
-        $settings_template_args['hidden_fields'] = array(
2840
-            'message_type_settings[messenger]'    => array(
2841
-                'type'  => 'hidden',
2842
-                'value' => $messenger->name
2843
-            ),
2844
-            'message_type_settings[message_type]' => array(
2845
-                'type'  => 'hidden',
2846
-                'value' => $message_type->name
2847
-            ),
2848
-            'type'                                => array(
2849
-                'type'  => 'hidden',
2850
-                'value' => 'message_type'
2851
-            )
2852
-        );
2853
-        
2854
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2855
-            'array');
2856
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2857
-        
2858
-        
2859
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2860
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
2861
-        
2862
-        return $content;
2863
-    }
2864
-    
2865
-    
2866
-    /**
2867
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
2868
-     *
2869
-     * @access protected
2870
-     * @return void
2871
-     */
2872
-    protected function _messages_settings_metaboxes()
2873
-    {
2874
-        $this->_set_m_mt_settings();
2875
-        $m_boxes         = $mt_boxes = array();
2876
-        $m_template_args = $mt_template_args = array();
2877
-        
2878
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2879
-        
2880
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
2881
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2882
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2883
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2884
-                //messenger meta boxes
2885
-                $active                                 = $selected_messenger == $messenger ? true : false;
2886
-                $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2887
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2888
-                    : '';
2889
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2890
-                    __('%s Settings', 'event_espresso'),
2891
-                    $tab_array['label']
2892
-                );
2893
-                $m_template_args[$messenger . '_a_box'] = array(
2894
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2895
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2896
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2897
-                        : '',
2898
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2899
-                    'hidden'                 => $active ? '' : ' hidden',
2900
-                    'hide_on_message'        => $hide_on_message,
2901
-                    'messenger'              => $messenger,
2902
-                    'active'                 => $active
2903
-                );
2904
-                // message type meta boxes
2905
-                // (which is really just the inactive container for each messenger
2906
-                // showing inactive message types for that messenger)
2907
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2908
-                $mt_template_args[$messenger . '_i_box'] = array(
2909
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2910
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2911
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2912
-                        : '',
2913
-                    'hidden'                 => $active ? '' : ' hidden',
2914
-                    'hide_on_message'        => $hide_on_message,
2915
-                    'hide_off_message'       => $hide_off_message,
2916
-                    'messenger'              => $messenger,
2917
-                    'active'                 => $active
2918
-                );
2919
-            }
2920
-        }
2921
-        
2922
-        
2923
-        //register messenger metaboxes
2924
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2925
-        foreach ($m_boxes as $box => $label) {
2926
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2927
-            $msgr          = str_replace('_a_box', '', $box);
2928
-            add_meta_box(
2929
-                'espresso_' . $msgr . '_settings',
2930
-                $label,
2931
-                function ($post, $metabox) {
2932
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2933
-                        $metabox["args"]["template_args"], true);
2934
-                },
2935
-                $this->_current_screen->id,
2936
-                'normal',
2937
-                'high',
2938
-                $callback_args
2939
-            );
2940
-        }
2941
-        
2942
-        //register message type metaboxes
2943
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2944
-        foreach ($mt_boxes as $box => $label) {
2945
-            $callback_args = array(
2946
-                'template_path' => $mt_template_path,
2947
-                'template_args' => $mt_template_args[$box]
2948
-            );
2949
-            $mt            = str_replace('_i_box', '', $box);
2950
-            add_meta_box(
2951
-                'espresso_' . $mt . '_inactive_mts',
2952
-                $label,
2953
-                function ($post, $metabox) {
2954
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2955
-                        $metabox["args"]["template_args"], true);
2956
-                },
2957
-                $this->_current_screen->id,
2958
-                'side',
2959
-                'high',
2960
-                $callback_args
2961
-            );
2962
-        }
2963
-        
2964
-        //register metabox for global messages settings but only when on the main site.  On single site installs this will
2965
-        //always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2966
-        if (is_main_site()) {
2967
-            add_meta_box(
2968
-                'espresso_global_message_settings',
2969
-                __('Global Message Settings', 'event_espresso'),
2970
-                array($this, 'global_messages_settings_metabox_content'),
2971
-                $this->_current_screen->id,
2972
-                'normal',
2973
-                'low',
2974
-                array()
2975
-            );
2976
-        }
2977
-        
2978
-    }
2979
-    
2980
-    
2981
-    /**
2982
-     *  This generates the content for the global messages settings metabox.
2983
-     * @return string
2984
-     */
2985
-    public function global_messages_settings_metabox_content()
2986
-    {
2987
-        $form = $this->_generate_global_settings_form();
2988
-        echo $form->form_open(
2989
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2990
-                'POST'
2991
-            )
2992
-             . $form->get_html()
2993
-             . $form->form_close();
2994
-    }
2995
-    
2996
-    
2997
-    /**
2998
-     * This generates and returns the form object for the global messages settings.
2999
-     * @return EE_Form_Section_Proper
3000
-     */
3001
-    protected function _generate_global_settings_form()
3002
-    {
3003
-        EE_Registry::instance()->load_helper('HTML');
3004
-        /** @var EE_Network_Core_Config $network_config */
3005
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3006
-        
3007
-        return new EE_Form_Section_Proper(
3008
-            array(
3009
-                'name'            => 'global_messages_settings',
3010
-                'html_id'         => 'global_messages_settings',
3011
-                'html_class'      => 'form-table',
3012
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3013
-                'subsections'     => apply_filters(
3014
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3015
-                    array(
3016
-                        'do_messages_on_same_request' => new EE_Select_Input(
3017
-                            array(
3018
-                                true  => esc_html__("On the same request", "event_espresso"),
3019
-                                false => esc_html__("On a separate request", "event_espresso")
3020
-                            ),
3021
-                            array(
3022
-                                'default'         => $network_config->do_messages_on_same_request,
3023
-                                'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3024
-                                'html_help_text'  => esc_html__('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.',
3025
-                                    'event_espresso'),
3026
-                            )
3027
-                        ),
3028
-                        'delete_threshold' => new EE_Select_Input(
3029
-                            array(
3030
-                                0 => esc_html__('Forever', 'event_espresso'),
3031
-                                3 => esc_html__('3 Months', 'event_espresso'),
3032
-                                6 => esc_html__('6 Months', 'event_espresso'),
3033
-                                9 => esc_html__('9 Months', 'event_espresso'),
3034
-                                12 => esc_html__('12 Months', 'event_espresso'),
3035
-                                24 => esc_html__('24 Months', 'event_espresso'),
3036
-                                36 => esc_html__('36 Months', 'event_espresso')
3037
-                            ),
3038
-                            array(
3039
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3040
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3041
-                                'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
2833
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2834
+				'string', 'ee_mt_activate_form') : '';
2835
+		}
2836
+        
2837
+		$settings_template_args['description'] = $message_type->description;
2838
+		//we also need some hidden fields
2839
+		$settings_template_args['hidden_fields'] = array(
2840
+			'message_type_settings[messenger]'    => array(
2841
+				'type'  => 'hidden',
2842
+				'value' => $messenger->name
2843
+			),
2844
+			'message_type_settings[message_type]' => array(
2845
+				'type'  => 'hidden',
2846
+				'value' => $message_type->name
2847
+			),
2848
+			'type'                                => array(
2849
+				'type'  => 'hidden',
2850
+				'value' => 'message_type'
2851
+			)
2852
+		);
2853
+        
2854
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2855
+			'array');
2856
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2857
+        
2858
+        
2859
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2860
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
2861
+        
2862
+		return $content;
2863
+	}
2864
+    
2865
+    
2866
+	/**
2867
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
2868
+	 *
2869
+	 * @access protected
2870
+	 * @return void
2871
+	 */
2872
+	protected function _messages_settings_metaboxes()
2873
+	{
2874
+		$this->_set_m_mt_settings();
2875
+		$m_boxes         = $mt_boxes = array();
2876
+		$m_template_args = $mt_template_args = array();
2877
+        
2878
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2879
+        
2880
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
2881
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2882
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2883
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2884
+				//messenger meta boxes
2885
+				$active                                 = $selected_messenger == $messenger ? true : false;
2886
+				$active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2887
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2888
+					: '';
2889
+				$m_boxes[$messenger . '_a_box']         = sprintf(
2890
+					__('%s Settings', 'event_espresso'),
2891
+					$tab_array['label']
2892
+				);
2893
+				$m_template_args[$messenger . '_a_box'] = array(
2894
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2895
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2896
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2897
+						: '',
2898
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2899
+					'hidden'                 => $active ? '' : ' hidden',
2900
+					'hide_on_message'        => $hide_on_message,
2901
+					'messenger'              => $messenger,
2902
+					'active'                 => $active
2903
+				);
2904
+				// message type meta boxes
2905
+				// (which is really just the inactive container for each messenger
2906
+				// showing inactive message types for that messenger)
2907
+				$mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2908
+				$mt_template_args[$messenger . '_i_box'] = array(
2909
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2910
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2911
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2912
+						: '',
2913
+					'hidden'                 => $active ? '' : ' hidden',
2914
+					'hide_on_message'        => $hide_on_message,
2915
+					'hide_off_message'       => $hide_off_message,
2916
+					'messenger'              => $messenger,
2917
+					'active'                 => $active
2918
+				);
2919
+			}
2920
+		}
2921
+        
2922
+        
2923
+		//register messenger metaboxes
2924
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2925
+		foreach ($m_boxes as $box => $label) {
2926
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2927
+			$msgr          = str_replace('_a_box', '', $box);
2928
+			add_meta_box(
2929
+				'espresso_' . $msgr . '_settings',
2930
+				$label,
2931
+				function ($post, $metabox) {
2932
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2933
+						$metabox["args"]["template_args"], true);
2934
+				},
2935
+				$this->_current_screen->id,
2936
+				'normal',
2937
+				'high',
2938
+				$callback_args
2939
+			);
2940
+		}
2941
+        
2942
+		//register message type metaboxes
2943
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2944
+		foreach ($mt_boxes as $box => $label) {
2945
+			$callback_args = array(
2946
+				'template_path' => $mt_template_path,
2947
+				'template_args' => $mt_template_args[$box]
2948
+			);
2949
+			$mt            = str_replace('_i_box', '', $box);
2950
+			add_meta_box(
2951
+				'espresso_' . $mt . '_inactive_mts',
2952
+				$label,
2953
+				function ($post, $metabox) {
2954
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2955
+						$metabox["args"]["template_args"], true);
2956
+				},
2957
+				$this->_current_screen->id,
2958
+				'side',
2959
+				'high',
2960
+				$callback_args
2961
+			);
2962
+		}
2963
+        
2964
+		//register metabox for global messages settings but only when on the main site.  On single site installs this will
2965
+		//always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2966
+		if (is_main_site()) {
2967
+			add_meta_box(
2968
+				'espresso_global_message_settings',
2969
+				__('Global Message Settings', 'event_espresso'),
2970
+				array($this, 'global_messages_settings_metabox_content'),
2971
+				$this->_current_screen->id,
2972
+				'normal',
2973
+				'low',
2974
+				array()
2975
+			);
2976
+		}
2977
+        
2978
+	}
2979
+    
2980
+    
2981
+	/**
2982
+	 *  This generates the content for the global messages settings metabox.
2983
+	 * @return string
2984
+	 */
2985
+	public function global_messages_settings_metabox_content()
2986
+	{
2987
+		$form = $this->_generate_global_settings_form();
2988
+		echo $form->form_open(
2989
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2990
+				'POST'
2991
+			)
2992
+			 . $form->get_html()
2993
+			 . $form->form_close();
2994
+	}
2995
+    
2996
+    
2997
+	/**
2998
+	 * This generates and returns the form object for the global messages settings.
2999
+	 * @return EE_Form_Section_Proper
3000
+	 */
3001
+	protected function _generate_global_settings_form()
3002
+	{
3003
+		EE_Registry::instance()->load_helper('HTML');
3004
+		/** @var EE_Network_Core_Config $network_config */
3005
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3006
+        
3007
+		return new EE_Form_Section_Proper(
3008
+			array(
3009
+				'name'            => 'global_messages_settings',
3010
+				'html_id'         => 'global_messages_settings',
3011
+				'html_class'      => 'form-table',
3012
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3013
+				'subsections'     => apply_filters(
3014
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3015
+					array(
3016
+						'do_messages_on_same_request' => new EE_Select_Input(
3017
+							array(
3018
+								true  => esc_html__("On the same request", "event_espresso"),
3019
+								false => esc_html__("On a separate request", "event_espresso")
3020
+							),
3021
+							array(
3022
+								'default'         => $network_config->do_messages_on_same_request,
3023
+								'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3024
+								'html_help_text'  => esc_html__('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.',
3025
+									'event_espresso'),
3026
+							)
3027
+						),
3028
+						'delete_threshold' => new EE_Select_Input(
3029
+							array(
3030
+								0 => esc_html__('Forever', 'event_espresso'),
3031
+								3 => esc_html__('3 Months', 'event_espresso'),
3032
+								6 => esc_html__('6 Months', 'event_espresso'),
3033
+								9 => esc_html__('9 Months', 'event_espresso'),
3034
+								12 => esc_html__('12 Months', 'event_espresso'),
3035
+								24 => esc_html__('24 Months', 'event_espresso'),
3036
+								36 => esc_html__('36 Months', 'event_espresso')
3037
+							),
3038
+							array(
3039
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3040
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3041
+								'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
3042 3042
                                                     via this option.', 'event_espresso'),
3043
-                            )
3044
-                        ),
3045
-                        'update_settings'             => new EE_Submit_Input(
3046
-                            array(
3047
-                                'default'         => esc_html__('Update', 'event_espresso'),
3048
-                                'html_label_text' => '&nbsp'
3049
-                            )
3050
-                        )
3051
-                    )
3052
-                )
3053
-            )
3054
-        );
3055
-    }
3056
-    
3057
-    
3058
-    /**
3059
-     * This handles updating the global settings set on the admin page.
3060
-     * @throws \EE_Error
3061
-     */
3062
-    protected function _update_global_settings()
3063
-    {
3064
-        /** @var EE_Network_Core_Config $network_config */
3065
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3066
-        $messages_config = EE_Registry::instance()->CFG->messages;
3067
-        $form           = $this->_generate_global_settings_form();
3068
-        if ($form->was_submitted()) {
3069
-            $form->receive_form_submission();
3070
-            if ($form->is_valid()) {
3071
-                $valid_data = $form->valid_data();
3072
-                foreach ($valid_data as $property => $value) {
3073
-                    $setter = 'set_' . $property;
3074
-                    if (method_exists($network_config, $setter)) {
3075
-                        $network_config->{$setter}($value);
3076
-                    } else if (
3077
-                        property_exists($network_config, $property)
3078
-                        && $network_config->{$property} !== $value
3079
-                    ) {
3080
-                        $network_config->{$property} = $value;
3081
-                    } else if (
3082
-                        property_exists($messages_config, $property)
3083
-                        && $messages_config->{$property} !== $value
3084
-                    ) {
3085
-                        $messages_config->{$property} = $value;
3086
-                    }
3087
-                }
3088
-                //only update if the form submission was valid!
3089
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3090
-                EE_Registry::instance()->CFG->update_espresso_config();
3091
-                EE_Error::overwrite_success();
3092
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3093
-            }
3094
-        }
3095
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3096
-    }
3097
-    
3098
-    
3099
-    /**
3100
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3101
-     *
3102
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3103
-     *
3104
-     * @return string            html formatted tabs
3105
-     */
3106
-    protected function _get_mt_tabs($tab_array)
3107
-    {
3108
-        $tab_array = (array)$tab_array;
3109
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3110
-        $tabs      = '';
3111
-        
3112
-        foreach ($tab_array as $tab) {
3113
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3114
-        }
3115
-        
3116
-        return $tabs;
3117
-    }
3118
-    
3119
-    
3120
-    /**
3121
-     * This prepares the content of the messenger meta box admin settings
3122
-     *
3123
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3124
-     *
3125
-     * @return string            html formatted content
3126
-     */
3127
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3128
-    {
3129
-        
3130
-        $fields                                         = $messenger->get_admin_settings_fields();
3131
-        $settings_template_args['template_form_fields'] = '';
3132
-        
3133
-        //is $messenger active?
3134
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3135
-        
3136
-        
3137
-        if ( ! empty($fields)) {
3043
+							)
3044
+						),
3045
+						'update_settings'             => new EE_Submit_Input(
3046
+							array(
3047
+								'default'         => esc_html__('Update', 'event_espresso'),
3048
+								'html_label_text' => '&nbsp'
3049
+							)
3050
+						)
3051
+					)
3052
+				)
3053
+			)
3054
+		);
3055
+	}
3056
+    
3057
+    
3058
+	/**
3059
+	 * This handles updating the global settings set on the admin page.
3060
+	 * @throws \EE_Error
3061
+	 */
3062
+	protected function _update_global_settings()
3063
+	{
3064
+		/** @var EE_Network_Core_Config $network_config */
3065
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3066
+		$messages_config = EE_Registry::instance()->CFG->messages;
3067
+		$form           = $this->_generate_global_settings_form();
3068
+		if ($form->was_submitted()) {
3069
+			$form->receive_form_submission();
3070
+			if ($form->is_valid()) {
3071
+				$valid_data = $form->valid_data();
3072
+				foreach ($valid_data as $property => $value) {
3073
+					$setter = 'set_' . $property;
3074
+					if (method_exists($network_config, $setter)) {
3075
+						$network_config->{$setter}($value);
3076
+					} else if (
3077
+						property_exists($network_config, $property)
3078
+						&& $network_config->{$property} !== $value
3079
+					) {
3080
+						$network_config->{$property} = $value;
3081
+					} else if (
3082
+						property_exists($messages_config, $property)
3083
+						&& $messages_config->{$property} !== $value
3084
+					) {
3085
+						$messages_config->{$property} = $value;
3086
+					}
3087
+				}
3088
+				//only update if the form submission was valid!
3089
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3090
+				EE_Registry::instance()->CFG->update_espresso_config();
3091
+				EE_Error::overwrite_success();
3092
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3093
+			}
3094
+		}
3095
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3096
+	}
3097
+    
3098
+    
3099
+	/**
3100
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3101
+	 *
3102
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3103
+	 *
3104
+	 * @return string            html formatted tabs
3105
+	 */
3106
+	protected function _get_mt_tabs($tab_array)
3107
+	{
3108
+		$tab_array = (array)$tab_array;
3109
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3110
+		$tabs      = '';
3111
+        
3112
+		foreach ($tab_array as $tab) {
3113
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3114
+		}
3115
+        
3116
+		return $tabs;
3117
+	}
3118
+    
3119
+    
3120
+	/**
3121
+	 * This prepares the content of the messenger meta box admin settings
3122
+	 *
3123
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3124
+	 *
3125
+	 * @return string            html formatted content
3126
+	 */
3127
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3128
+	{
3129
+        
3130
+		$fields                                         = $messenger->get_admin_settings_fields();
3131
+		$settings_template_args['template_form_fields'] = '';
3132
+        
3133
+		//is $messenger active?
3134
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3135
+        
3136
+        
3137
+		if ( ! empty($fields)) {
3138 3138
             
3139
-            $existing_settings = $messenger->get_existing_admin_settings();
3139
+			$existing_settings = $messenger->get_existing_admin_settings();
3140 3140
             
3141
-            foreach ($fields as $fldname => $fldprops) {
3142
-                $field_id                       = $messenger->name . '-' . $fldname;
3143
-                $template_form_field[$field_id] = array(
3144
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3145
-                    'label'      => $fldprops['label'],
3146
-                    'input'      => $fldprops['field_type'],
3147
-                    'type'       => $fldprops['value_type'],
3148
-                    'required'   => $fldprops['required'],
3149
-                    'validation' => $fldprops['validation'],
3150
-                    'value'      => isset($existing_settings[$field_id])
3151
-                        ? $existing_settings[$field_id]
3152
-                        : $fldprops['default'],
3153
-                    'css_class'  => '',
3154
-                    'format'     => $fldprops['format']
3155
-                );
3156
-            }
3141
+			foreach ($fields as $fldname => $fldprops) {
3142
+				$field_id                       = $messenger->name . '-' . $fldname;
3143
+				$template_form_field[$field_id] = array(
3144
+					'name'       => 'messenger_settings[' . $field_id . ']',
3145
+					'label'      => $fldprops['label'],
3146
+					'input'      => $fldprops['field_type'],
3147
+					'type'       => $fldprops['value_type'],
3148
+					'required'   => $fldprops['required'],
3149
+					'validation' => $fldprops['validation'],
3150
+					'value'      => isset($existing_settings[$field_id])
3151
+						? $existing_settings[$field_id]
3152
+						: $fldprops['default'],
3153
+					'css_class'  => '',
3154
+					'format'     => $fldprops['format']
3155
+				);
3156
+			}
3157 3157
             
3158 3158
             
3159
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3160
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3161
-                : '';
3162
-        }
3163
-        
3164
-        //we also need some hidden fields
3165
-        $settings_template_args['hidden_fields'] = array(
3166
-            'messenger_settings[messenger]' => array(
3167
-                'type'  => 'hidden',
3168
-                'value' => $messenger->name
3169
-            ),
3170
-            'type'                          => array(
3171
-                'type'  => 'hidden',
3172
-                'value' => 'messenger'
3173
-            )
3174
-        );
3175
-        
3176
-        //make sure any active message types that are existing are included in the hidden fields
3177
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3178
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3179
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3180
-                    'type'  => 'hidden',
3181
-                    'value' => $mt
3182
-                );
3183
-            }
3184
-        }
3185
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3186
-            $settings_template_args['hidden_fields'],
3187
-            'array'
3188
-        );
3189
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3190
-        
3191
-        $settings_template_args['messenger']           = $messenger->name;
3192
-        $settings_template_args['description']         = $messenger->description;
3193
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3194
-        
3195
-        
3196
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3197
-            ? $settings_template_args['show_hide_edit_form']
3198
-            : ' hidden';
3199
-        
3200
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3201
-            ? ' hidden'
3202
-            : $settings_template_args['show_hide_edit_form'];
3203
-        
3204
-        
3205
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3206
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3207
-        $settings_template_args['on_off_status'] = $active ? true : false;
3208
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3209
-        $content                                 = EEH_Template::display_template($template, $settings_template_args,
3210
-            true);
3211
-        
3212
-        return $content;
3213
-    }
3214
-    
3215
-    
3216
-    /**
3217
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3218
-     */
3219
-    public function activate_messenger_toggle()
3220
-    {
3221
-        $success = true;
3222
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3223
-        //let's check that we have required data
3224
-        if ( ! isset($this->_req_data['messenger'])) {
3225
-            EE_Error::add_error(
3226
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3227
-                __FILE__,
3228
-                __FUNCTION__,
3229
-                __LINE__
3230
-            );
3231
-            $success = false;
3232
-        }
3233
-        
3234
-        //do a nonce check here since we're not arriving via a normal route
3235
-        $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3236
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3237
-        
3238
-        $this->_verify_nonce($nonce, $nonce_ref);
3239
-        
3240
-        
3241
-        if ( ! isset($this->_req_data['status'])) {
3242
-            EE_Error::add_error(
3243
-                __(
3244
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3245
-                    'event_espresso'
3246
-                ),
3247
-                __FILE__,
3248
-                __FUNCTION__,
3249
-                __LINE__
3250
-            );
3251
-            $success = false;
3252
-        }
3253
-        
3254
-        //do check to verify we have a valid status.
3255
-        $status = $this->_req_data['status'];
3256
-        
3257
-        if ($status != 'off' && $status != 'on') {
3258
-            EE_Error::add_error(
3259
-                sprintf(
3260
-                    __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3261
-                    $this->_req_data['status']
3262
-                ),
3263
-                __FILE__,
3264
-                __FUNCTION__,
3265
-                __LINE__
3266
-            );
3267
-            $success = false;
3268
-        }
3269
-        
3270
-        if ($success) {
3271
-            //made it here?  Stop dawdling then!!
3272
-            $success = $status == 'off'
3273
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3274
-                : $this->_activate_messenger($this->_req_data['messenger']);
3275
-        }
3276
-        
3277
-        $this->_template_args['success'] = $success;
3278
-        
3279
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3280
-        $this->_return_json();
3281
-        
3282
-    }
3283
-    
3284
-    
3285
-    /**
3286
-     * used by ajax from the messages settings page to activate|deactivate a message type
3287
-     *
3288
-     */
3289
-    public function activate_mt_toggle()
3290
-    {
3291
-        $success = true;
3292
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3293
-        
3294
-        //let's make sure we have the necessary data
3295
-        if ( ! isset($this->_req_data['message_type'])) {
3296
-            EE_Error::add_error(
3297
-                __('Message Type name needed to toggle activation. None given', 'event_espresso'),
3298
-                __FILE__, __FUNCTION__, __LINE__
3299
-            );
3300
-            $success = false;
3301
-        }
3302
-        
3303
-        if ( ! isset($this->_req_data['messenger'])) {
3304
-            EE_Error::add_error(
3305
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3306
-                __FILE__, __FUNCTION__, __LINE__
3307
-            );
3308
-            $success = false;
3309
-        }
3310
-        
3311
-        if ( ! isset($this->_req_data['status'])) {
3312
-            EE_Error::add_error(
3313
-                __('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3314
-                    'event_espresso'),
3315
-                __FILE__, __FUNCTION__, __LINE__
3316
-            );
3317
-            $success = false;
3318
-        }
3319
-        
3320
-        
3321
-        //do check to verify we have a valid status.
3322
-        $status = $this->_req_data['status'];
3323
-        
3324
-        if ($status != 'activate' && $status != 'deactivate') {
3325
-            EE_Error::add_error(
3326
-                sprintf(
3327
-                    __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3328
-                    $this->_req_data['status']
3329
-                ),
3330
-                __FILE__, __FUNCTION__, __LINE__
3331
-            );
3332
-            $success = false;
3333
-        }
3334
-        
3335
-        
3336
-        //do a nonce check here since we're not arriving via a normal route
3337
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3338
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3339
-        
3340
-        $this->_verify_nonce($nonce, $nonce_ref);
3341
-        
3342
-        if ($success) {
3343
-            //made it here? um, what are you waiting for then?
3344
-            $success = $status == 'deactivate'
3345
-                ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3346
-                    $this->_req_data['message_type'])
3347
-                : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3348
-                    $this->_req_data['message_type']);
3349
-        }
3350
-        
3351
-        $this->_template_args['success'] = $success;
3352
-        $this->_return_json();
3353
-    }
3354
-    
3355
-    
3356
-    /**
3357
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3358
-     *
3359
-     * @param string $messenger_name The name of the messenger being activated
3360
-     *
3361
-     * @return bool
3362
-     */
3363
-    protected function _activate_messenger($messenger_name)
3364
-    {
3365
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3366
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3367
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3368
-        
3369
-        //ensure is active
3370
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3371
-        
3372
-        //set response_data for reload
3373
-        foreach ($message_types_to_activate as $message_type_name) {
3374
-            /** @var EE_message_type $message_type */
3375
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3376
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3377
-                    $message_type_name)
3378
-                && $message_type instanceof EE_message_type
3379
-            ) {
3380
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3381
-                if ($message_type->get_admin_settings_fields()) {
3382
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3383
-                }
3384
-            }
3385
-        }
3386
-        
3387
-        //add success message for activating messenger
3388
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3389
-        
3390
-    }
3391
-    
3392
-    
3393
-    /**
3394
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3395
-     *
3396
-     * @param string $messenger_name The name of the messenger being activated
3397
-     *
3398
-     * @return bool
3399
-     */
3400
-    protected function _deactivate_messenger($messenger_name)
3401
-    {
3402
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3403
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3404
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3405
-        
3406
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3407
-    }
3408
-    
3409
-    
3410
-    /**
3411
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3412
-     *
3413
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3414
-     * @param string $message_type_name The name of the message type being activated for the messenger
3415
-     *
3416
-     * @return bool
3417
-     */
3418
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3419
-    {
3420
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
-        
3425
-        //ensure is active
3426
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3427
-        
3428
-        //set response for load
3429
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3430
-            $message_type_name)
3431
-        ) {
3432
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3433
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3434
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3435
-            }
3436
-        }
3437
-        
3438
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3439
-            $message_type_to_activate);
3440
-    }
3441
-    
3442
-    
3443
-    /**
3444
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3445
-     *
3446
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3447
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3448
-     *
3449
-     * @return bool
3450
-     */
3451
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3452
-    {
3453
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3454
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3455
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3456
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3457
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3458
-        
3459
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3460
-            $message_type_to_deactivate);
3461
-    }
3462
-    
3463
-    
3464
-    /**
3465
-     * This just initializes the defaults for activating messenger and message type responses.
3466
-     */
3467
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3468
-    {
3469
-        $this->_template_args['data']['active_mts'] = array();
3470
-        $this->_template_args['data']['mt_reload']  = array();
3471
-    }
3472
-    
3473
-    
3474
-    /**
3475
-     * Setup appropriate response for activating a messenger and/or message types
3476
-     *
3477
-     * @param EE_messenger         $messenger
3478
-     * @param EE_message_type|null $message_type
3479
-     *
3480
-     * @return bool
3481
-     * @throws EE_Error
3482
-     */
3483
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3484
-        $messenger,
3485
-        EE_Message_Type $message_type = null
3486
-    ) {
3487
-        //if $messenger isn't a valid messenger object then get out.
3488
-        if ( ! $messenger instanceof EE_Messenger) {
3489
-            EE_Error::add_error(
3490
-                __('The messenger being activated is not a valid messenger', 'event_espresso'),
3491
-                __FILE__,
3492
-                __FUNCTION__,
3493
-                __LINE__
3494
-            );
3159
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3160
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3161
+				: '';
3162
+		}
3163
+        
3164
+		//we also need some hidden fields
3165
+		$settings_template_args['hidden_fields'] = array(
3166
+			'messenger_settings[messenger]' => array(
3167
+				'type'  => 'hidden',
3168
+				'value' => $messenger->name
3169
+			),
3170
+			'type'                          => array(
3171
+				'type'  => 'hidden',
3172
+				'value' => 'messenger'
3173
+			)
3174
+		);
3175
+        
3176
+		//make sure any active message types that are existing are included in the hidden fields
3177
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3178
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3179
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3180
+					'type'  => 'hidden',
3181
+					'value' => $mt
3182
+				);
3183
+			}
3184
+		}
3185
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3186
+			$settings_template_args['hidden_fields'],
3187
+			'array'
3188
+		);
3189
+		$active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3190
+        
3191
+		$settings_template_args['messenger']           = $messenger->name;
3192
+		$settings_template_args['description']         = $messenger->description;
3193
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3194
+        
3195
+        
3196
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3197
+			? $settings_template_args['show_hide_edit_form']
3198
+			: ' hidden';
3199
+        
3200
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3201
+			? ' hidden'
3202
+			: $settings_template_args['show_hide_edit_form'];
3203
+        
3204
+        
3205
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3206
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3207
+		$settings_template_args['on_off_status'] = $active ? true : false;
3208
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3209
+		$content                                 = EEH_Template::display_template($template, $settings_template_args,
3210
+			true);
3211
+        
3212
+		return $content;
3213
+	}
3214
+    
3215
+    
3216
+	/**
3217
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3218
+	 */
3219
+	public function activate_messenger_toggle()
3220
+	{
3221
+		$success = true;
3222
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3223
+		//let's check that we have required data
3224
+		if ( ! isset($this->_req_data['messenger'])) {
3225
+			EE_Error::add_error(
3226
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3227
+				__FILE__,
3228
+				__FUNCTION__,
3229
+				__LINE__
3230
+			);
3231
+			$success = false;
3232
+		}
3233
+        
3234
+		//do a nonce check here since we're not arriving via a normal route
3235
+		$nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3236
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3237
+        
3238
+		$this->_verify_nonce($nonce, $nonce_ref);
3239
+        
3240
+        
3241
+		if ( ! isset($this->_req_data['status'])) {
3242
+			EE_Error::add_error(
3243
+				__(
3244
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3245
+					'event_espresso'
3246
+				),
3247
+				__FILE__,
3248
+				__FUNCTION__,
3249
+				__LINE__
3250
+			);
3251
+			$success = false;
3252
+		}
3253
+        
3254
+		//do check to verify we have a valid status.
3255
+		$status = $this->_req_data['status'];
3256
+        
3257
+		if ($status != 'off' && $status != 'on') {
3258
+			EE_Error::add_error(
3259
+				sprintf(
3260
+					__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3261
+					$this->_req_data['status']
3262
+				),
3263
+				__FILE__,
3264
+				__FUNCTION__,
3265
+				__LINE__
3266
+			);
3267
+			$success = false;
3268
+		}
3269
+        
3270
+		if ($success) {
3271
+			//made it here?  Stop dawdling then!!
3272
+			$success = $status == 'off'
3273
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3274
+				: $this->_activate_messenger($this->_req_data['messenger']);
3275
+		}
3276
+        
3277
+		$this->_template_args['success'] = $success;
3278
+        
3279
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3280
+		$this->_return_json();
3281
+        
3282
+	}
3283
+    
3284
+    
3285
+	/**
3286
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3287
+	 *
3288
+	 */
3289
+	public function activate_mt_toggle()
3290
+	{
3291
+		$success = true;
3292
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3293
+        
3294
+		//let's make sure we have the necessary data
3295
+		if ( ! isset($this->_req_data['message_type'])) {
3296
+			EE_Error::add_error(
3297
+				__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3298
+				__FILE__, __FUNCTION__, __LINE__
3299
+			);
3300
+			$success = false;
3301
+		}
3302
+        
3303
+		if ( ! isset($this->_req_data['messenger'])) {
3304
+			EE_Error::add_error(
3305
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3306
+				__FILE__, __FUNCTION__, __LINE__
3307
+			);
3308
+			$success = false;
3309
+		}
3310
+        
3311
+		if ( ! isset($this->_req_data['status'])) {
3312
+			EE_Error::add_error(
3313
+				__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3314
+					'event_espresso'),
3315
+				__FILE__, __FUNCTION__, __LINE__
3316
+			);
3317
+			$success = false;
3318
+		}
3319
+        
3320
+        
3321
+		//do check to verify we have a valid status.
3322
+		$status = $this->_req_data['status'];
3323
+        
3324
+		if ($status != 'activate' && $status != 'deactivate') {
3325
+			EE_Error::add_error(
3326
+				sprintf(
3327
+					__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3328
+					$this->_req_data['status']
3329
+				),
3330
+				__FILE__, __FUNCTION__, __LINE__
3331
+			);
3332
+			$success = false;
3333
+		}
3334
+        
3335
+        
3336
+		//do a nonce check here since we're not arriving via a normal route
3337
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3338
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3339
+        
3340
+		$this->_verify_nonce($nonce, $nonce_ref);
3341
+        
3342
+		if ($success) {
3343
+			//made it here? um, what are you waiting for then?
3344
+			$success = $status == 'deactivate'
3345
+				? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3346
+					$this->_req_data['message_type'])
3347
+				: $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3348
+					$this->_req_data['message_type']);
3349
+		}
3350
+        
3351
+		$this->_template_args['success'] = $success;
3352
+		$this->_return_json();
3353
+	}
3354
+    
3355
+    
3356
+	/**
3357
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3358
+	 *
3359
+	 * @param string $messenger_name The name of the messenger being activated
3360
+	 *
3361
+	 * @return bool
3362
+	 */
3363
+	protected function _activate_messenger($messenger_name)
3364
+	{
3365
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3366
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3367
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3368
+        
3369
+		//ensure is active
3370
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3371
+        
3372
+		//set response_data for reload
3373
+		foreach ($message_types_to_activate as $message_type_name) {
3374
+			/** @var EE_message_type $message_type */
3375
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3376
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3377
+					$message_type_name)
3378
+				&& $message_type instanceof EE_message_type
3379
+			) {
3380
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3381
+				if ($message_type->get_admin_settings_fields()) {
3382
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3383
+				}
3384
+			}
3385
+		}
3386
+        
3387
+		//add success message for activating messenger
3388
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3389
+        
3390
+	}
3391
+    
3392
+    
3393
+	/**
3394
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3395
+	 *
3396
+	 * @param string $messenger_name The name of the messenger being activated
3397
+	 *
3398
+	 * @return bool
3399
+	 */
3400
+	protected function _deactivate_messenger($messenger_name)
3401
+	{
3402
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3403
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3404
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3405
+        
3406
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3407
+	}
3408
+    
3409
+    
3410
+	/**
3411
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3412
+	 *
3413
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3414
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3415
+	 *
3416
+	 * @return bool
3417
+	 */
3418
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3419
+	{
3420
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
+        
3425
+		//ensure is active
3426
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3427
+        
3428
+		//set response for load
3429
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3430
+			$message_type_name)
3431
+		) {
3432
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3433
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3434
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3435
+			}
3436
+		}
3437
+        
3438
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3439
+			$message_type_to_activate);
3440
+	}
3441
+    
3442
+    
3443
+	/**
3444
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3445
+	 *
3446
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3447
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3448
+	 *
3449
+	 * @return bool
3450
+	 */
3451
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3452
+	{
3453
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3454
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3455
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3456
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3457
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3458
+        
3459
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3460
+			$message_type_to_deactivate);
3461
+	}
3462
+    
3463
+    
3464
+	/**
3465
+	 * This just initializes the defaults for activating messenger and message type responses.
3466
+	 */
3467
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3468
+	{
3469
+		$this->_template_args['data']['active_mts'] = array();
3470
+		$this->_template_args['data']['mt_reload']  = array();
3471
+	}
3472
+    
3473
+    
3474
+	/**
3475
+	 * Setup appropriate response for activating a messenger and/or message types
3476
+	 *
3477
+	 * @param EE_messenger         $messenger
3478
+	 * @param EE_message_type|null $message_type
3479
+	 *
3480
+	 * @return bool
3481
+	 * @throws EE_Error
3482
+	 */
3483
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3484
+		$messenger,
3485
+		EE_Message_Type $message_type = null
3486
+	) {
3487
+		//if $messenger isn't a valid messenger object then get out.
3488
+		if ( ! $messenger instanceof EE_Messenger) {
3489
+			EE_Error::add_error(
3490
+				__('The messenger being activated is not a valid messenger', 'event_espresso'),
3491
+				__FILE__,
3492
+				__FUNCTION__,
3493
+				__LINE__
3494
+			);
3495 3495
             
3496
-            return false;
3497
-        }
3498
-        //activated
3499
-        if ($this->_template_args['data']['active_mts']) {
3500
-            EE_Error::overwrite_success();
3501
-            //activated a message type with the messenger
3502
-            if ($message_type instanceof EE_message_type) {
3503
-                EE_Error::add_success(
3504
-                    sprintf(
3505
-                        __('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3506
-                        ucwords($message_type->label['singular']),
3507
-                        ucwords($messenger->label['singular'])
3508
-                    )
3509
-                );
3496
+			return false;
3497
+		}
3498
+		//activated
3499
+		if ($this->_template_args['data']['active_mts']) {
3500
+			EE_Error::overwrite_success();
3501
+			//activated a message type with the messenger
3502
+			if ($message_type instanceof EE_message_type) {
3503
+				EE_Error::add_success(
3504
+					sprintf(
3505
+						__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3506
+						ucwords($message_type->label['singular']),
3507
+						ucwords($messenger->label['singular'])
3508
+					)
3509
+				);
3510 3510
                 
3511
-                //if message type was invoice then let's make sure we activate the invoice payment method.
3512
-                if ($message_type->name == 'invoice') {
3513
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3514
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3515
-                    if ($pm instanceof EE_Payment_Method) {
3516
-                        EE_Error::add_attention(__('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.',
3517
-                            'event_espresso'));
3518
-                    }
3519
-                }
3520
-                //just toggles the entire messenger
3521
-            } else {
3522
-                EE_Error::add_success(
3523
-                    sprintf(
3524
-                        __('%s messenger has been successfully activated', 'event_espresso'),
3525
-                        ucwords($messenger->label['singular'])
3526
-                    )
3527
-                );
3528
-            }
3511
+				//if message type was invoice then let's make sure we activate the invoice payment method.
3512
+				if ($message_type->name == 'invoice') {
3513
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3514
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3515
+					if ($pm instanceof EE_Payment_Method) {
3516
+						EE_Error::add_attention(__('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.',
3517
+							'event_espresso'));
3518
+					}
3519
+				}
3520
+				//just toggles the entire messenger
3521
+			} else {
3522
+				EE_Error::add_success(
3523
+					sprintf(
3524
+						__('%s messenger has been successfully activated', 'event_espresso'),
3525
+						ucwords($messenger->label['singular'])
3526
+					)
3527
+				);
3528
+			}
3529 3529
             
3530
-            return true;
3530
+			return true;
3531 3531
             
3532
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3533
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3534
-            //in which case we just give a success message for the messenger being successfully activated.
3535
-        } else {
3536
-            if ( ! $messenger->get_default_message_types()) {
3537
-                //messenger doesn't have any default message types so still a success.
3538
-                EE_Error::add_success(
3539
-                    sprintf(
3540
-                        __('%s messenger was successfully activated.', 'event_espresso'),
3541
-                        ucwords($messenger->label['singular'])
3542
-                    )
3543
-                );
3532
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3533
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3534
+			//in which case we just give a success message for the messenger being successfully activated.
3535
+		} else {
3536
+			if ( ! $messenger->get_default_message_types()) {
3537
+				//messenger doesn't have any default message types so still a success.
3538
+				EE_Error::add_success(
3539
+					sprintf(
3540
+						__('%s messenger was successfully activated.', 'event_espresso'),
3541
+						ucwords($messenger->label['singular'])
3542
+					)
3543
+				);
3544 3544
                 
3545
-                return true;
3546
-            } else {
3547
-                EE_Error::add_error(
3548
-                    $message_type instanceof EE_message_type
3549
-                        ? sprintf(
3550
-                        __('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3551
-                        ucwords($message_type->label['singular']),
3552
-                        ucwords($messenger->label['singular'])
3553
-                    )
3554
-                        : sprintf(
3555
-                        __('%s messenger was not successfully activated', 'event_espresso'),
3556
-                        ucwords($messenger->label['singular'])
3557
-                    ),
3558
-                    __FILE__,
3559
-                    __FUNCTION__,
3560
-                    __LINE__
3561
-                );
3545
+				return true;
3546
+			} else {
3547
+				EE_Error::add_error(
3548
+					$message_type instanceof EE_message_type
3549
+						? sprintf(
3550
+						__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3551
+						ucwords($message_type->label['singular']),
3552
+						ucwords($messenger->label['singular'])
3553
+					)
3554
+						: sprintf(
3555
+						__('%s messenger was not successfully activated', 'event_espresso'),
3556
+						ucwords($messenger->label['singular'])
3557
+					),
3558
+					__FILE__,
3559
+					__FUNCTION__,
3560
+					__LINE__
3561
+				);
3562 3562
                 
3563
-                return false;
3564
-            }
3565
-        }
3566
-    }
3567
-    
3568
-    
3569
-    /**
3570
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3571
-     *
3572
-     * @param EE_messenger         $messenger
3573
-     * @param EE_message_type|null $message_type
3574
-     *
3575
-     * @return bool
3576
-     */
3577
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3578
-        $messenger,
3579
-        EE_message_type $message_type = null
3580
-    ) {
3581
-        EE_Error::overwrite_success();
3582
-        
3583
-        //if $messenger isn't a valid messenger object then get out.
3584
-        if ( ! $messenger instanceof EE_Messenger) {
3585
-            EE_Error::add_error(
3586
-                __('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3587
-                __FILE__,
3588
-                __FUNCTION__,
3589
-                __LINE__
3590
-            );
3563
+				return false;
3564
+			}
3565
+		}
3566
+	}
3567
+    
3568
+    
3569
+	/**
3570
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3571
+	 *
3572
+	 * @param EE_messenger         $messenger
3573
+	 * @param EE_message_type|null $message_type
3574
+	 *
3575
+	 * @return bool
3576
+	 */
3577
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3578
+		$messenger,
3579
+		EE_message_type $message_type = null
3580
+	) {
3581
+		EE_Error::overwrite_success();
3582
+        
3583
+		//if $messenger isn't a valid messenger object then get out.
3584
+		if ( ! $messenger instanceof EE_Messenger) {
3585
+			EE_Error::add_error(
3586
+				__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3587
+				__FILE__,
3588
+				__FUNCTION__,
3589
+				__LINE__
3590
+			);
3591 3591
             
3592
-            return false;
3593
-        }
3594
-        
3595
-        if ($message_type instanceof EE_message_type) {
3596
-            $message_type_name = $message_type->name;
3597
-            EE_Error::add_success(
3598
-                sprintf(
3599
-                    __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3600
-                    ucwords($message_type->label['singular']),
3601
-                    ucwords($messenger->label['singular'])
3602
-                )
3603
-            );
3604
-        } else {
3605
-            $message_type_name = '';
3606
-            EE_Error::add_success(
3607
-                sprintf(
3608
-                    __('%s messenger has been successfully deactivated.', 'event_espresso'),
3609
-                    ucwords($messenger->label['singular'])
3610
-                )
3611
-            );
3612
-        }
3613
-        
3614
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3615
-        if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3616
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3617
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3618
-            if ($count_updated > 0) {
3619
-                $msg = $message_type_name == 'invoice'
3620
-                    ? __('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.',
3621
-                        'event_espresso')
3622
-                    : __('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.',
3623
-                        'event_espresso');
3624
-                EE_Error::add_attention($msg);
3625
-            }
3626
-        }
3627
-        
3628
-        return true;
3629
-    }
3630
-    
3631
-    
3632
-    /**
3633
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3634
-     */
3635
-    public function update_mt_form()
3636
-    {
3637
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3638
-            EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3639
-                __LINE__);
3640
-            $this->_return_json();
3641
-        }
3642
-        
3643
-        $message_types = $this->get_installed_message_types();
3644
-        
3645
-        $message_type = $message_types[$this->_req_data['message_type']];
3646
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3647
-        
3648
-        $content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3649
-        $this->_template_args['success'] = true;
3650
-        $this->_template_args['content'] = $content;
3651
-        $this->_return_json();
3652
-    }
3653
-    
3654
-    
3655
-    /**
3656
-     * this handles saving the settings for a messenger or message type
3657
-     *
3658
-     */
3659
-    public function save_settings()
3660
-    {
3661
-        if ( ! isset($this->_req_data['type'])) {
3662
-            EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3663
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3664
-            $this->_template_args['error'] = true;
3665
-            $this->_return_json();
3666
-        }
3667
-        
3668
-        
3669
-        if ($this->_req_data['type'] == 'messenger') {
3670
-            $settings  = $this->_req_data['messenger_settings']; //this should be an array.
3671
-            $messenger = $settings['messenger'];
3672
-            //let's setup the settings data
3673
-            foreach ($settings as $key => $value) {
3674
-                switch ($key) {
3675
-                    case 'messenger' :
3676
-                        unset($settings['messenger']);
3677
-                        break;
3678
-                    case 'message_types' :
3679
-                        unset($settings['message_types']);
3680
-                        break;
3681
-                    default :
3682
-                        $settings[$key] = $value;
3683
-                        break;
3684
-                }
3685
-            }
3686
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3687
-        } else if ($this->_req_data['type'] == 'message_type') {
3688
-            $settings     = $this->_req_data['message_type_settings'];
3689
-            $messenger    = $settings['messenger'];
3690
-            $message_type = $settings['message_type'];
3592
+			return false;
3593
+		}
3594
+        
3595
+		if ($message_type instanceof EE_message_type) {
3596
+			$message_type_name = $message_type->name;
3597
+			EE_Error::add_success(
3598
+				sprintf(
3599
+					__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3600
+					ucwords($message_type->label['singular']),
3601
+					ucwords($messenger->label['singular'])
3602
+				)
3603
+			);
3604
+		} else {
3605
+			$message_type_name = '';
3606
+			EE_Error::add_success(
3607
+				sprintf(
3608
+					__('%s messenger has been successfully deactivated.', 'event_espresso'),
3609
+					ucwords($messenger->label['singular'])
3610
+				)
3611
+			);
3612
+		}
3613
+        
3614
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3615
+		if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3616
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3617
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3618
+			if ($count_updated > 0) {
3619
+				$msg = $message_type_name == 'invoice'
3620
+					? __('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.',
3621
+						'event_espresso')
3622
+					: __('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.',
3623
+						'event_espresso');
3624
+				EE_Error::add_attention($msg);
3625
+			}
3626
+		}
3627
+        
3628
+		return true;
3629
+	}
3630
+    
3631
+    
3632
+	/**
3633
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3634
+	 */
3635
+	public function update_mt_form()
3636
+	{
3637
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3638
+			EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3639
+				__LINE__);
3640
+			$this->_return_json();
3641
+		}
3642
+        
3643
+		$message_types = $this->get_installed_message_types();
3644
+        
3645
+		$message_type = $message_types[$this->_req_data['message_type']];
3646
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3647
+        
3648
+		$content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3649
+		$this->_template_args['success'] = true;
3650
+		$this->_template_args['content'] = $content;
3651
+		$this->_return_json();
3652
+	}
3653
+    
3654
+    
3655
+	/**
3656
+	 * this handles saving the settings for a messenger or message type
3657
+	 *
3658
+	 */
3659
+	public function save_settings()
3660
+	{
3661
+		if ( ! isset($this->_req_data['type'])) {
3662
+			EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3663
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3664
+			$this->_template_args['error'] = true;
3665
+			$this->_return_json();
3666
+		}
3667
+        
3668
+        
3669
+		if ($this->_req_data['type'] == 'messenger') {
3670
+			$settings  = $this->_req_data['messenger_settings']; //this should be an array.
3671
+			$messenger = $settings['messenger'];
3672
+			//let's setup the settings data
3673
+			foreach ($settings as $key => $value) {
3674
+				switch ($key) {
3675
+					case 'messenger' :
3676
+						unset($settings['messenger']);
3677
+						break;
3678
+					case 'message_types' :
3679
+						unset($settings['message_types']);
3680
+						break;
3681
+					default :
3682
+						$settings[$key] = $value;
3683
+						break;
3684
+				}
3685
+			}
3686
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3687
+		} else if ($this->_req_data['type'] == 'message_type') {
3688
+			$settings     = $this->_req_data['message_type_settings'];
3689
+			$messenger    = $settings['messenger'];
3690
+			$message_type = $settings['message_type'];
3691 3691
             
3692
-            foreach ($settings as $key => $value) {
3693
-                switch ($key) {
3694
-                    case 'messenger' :
3695
-                        unset($settings['messenger']);
3696
-                        break;
3697
-                    case 'message_type' :
3698
-                        unset($settings['message_type']);
3699
-                        break;
3700
-                    default :
3701
-                        $settings[$key] = $value;
3702
-                        break;
3703
-                }
3704
-            }
3692
+			foreach ($settings as $key => $value) {
3693
+				switch ($key) {
3694
+					case 'messenger' :
3695
+						unset($settings['messenger']);
3696
+						break;
3697
+					case 'message_type' :
3698
+						unset($settings['message_type']);
3699
+						break;
3700
+					default :
3701
+						$settings[$key] = $value;
3702
+						break;
3703
+				}
3704
+			}
3705 3705
             
3706
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3707
-        }
3708
-        
3709
-        //okay we should have the data all setup.  Now we just update!
3710
-        $success = $this->_message_resource_manager->update_active_messengers_option();
3711
-        
3712
-        if ($success) {
3713
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
3714
-        } else {
3715
-            EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3716
-        }
3717
-        
3718
-        $this->_template_args['success'] = $success;
3719
-        $this->_return_json();
3720
-    }
3721
-    
3722
-    
3723
-    
3724
-    
3725
-    /**  EE MESSAGE PROCESSING ACTIONS **/
3726
-    
3727
-    
3728
-    /**
3729
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3730
-     * However, this does not send immediately, it just queues for sending.
3731
-     *
3732
-     * @since 4.9.0
3733
-     */
3734
-    protected function _generate_now()
3735
-    {
3736
-        $msg_ids = $this->_get_msg_ids_from_request();
3737
-        EED_Messages::generate_now($msg_ids);
3738
-        $this->_redirect_after_action(false, '', '', array(), true);
3739
-    }
3740
-    
3741
-    
3742
-    /**
3743
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3744
-     * are EEM_Message::status_resend or EEM_Message::status_idle
3745
-     *
3746
-     * @since 4.9.0
3747
-     *
3748
-     */
3749
-    protected function _generate_and_send_now()
3750
-    {
3751
-        $this->_generate_now();
3752
-        $this->_send_now();
3753
-        $this->_redirect_after_action(false, '', '', array(), true);
3754
-    }
3755
-    
3756
-    
3757
-    /**
3758
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3759
-     *
3760
-     * @since 4.9.0
3761
-     */
3762
-    protected function _queue_for_resending()
3763
-    {
3764
-        $msg_ids = $this->_get_msg_ids_from_request();
3765
-        EED_Messages::queue_for_resending($msg_ids);
3766
-        $this->_redirect_after_action(false, '', '', array(), true);
3767
-    }
3768
-    
3769
-    
3770
-    /**
3771
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3772
-     *
3773
-     * @since 4.9.0
3774
-     */
3775
-    protected function _send_now()
3776
-    {
3777
-        $msg_ids = $this->_get_msg_ids_from_request();
3778
-        EED_Messages::send_now($msg_ids);
3779
-        $this->_redirect_after_action(false, '', '', array(), true);
3780
-    }
3781
-    
3782
-    
3783
-    /**
3784
-     * Deletes EE_messages for IDs in the request.
3785
-     *
3786
-     * @since 4.9.0
3787
-     */
3788
-    protected function _delete_ee_messages()
3789
-    {
3790
-        $msg_ids       = $this->_get_msg_ids_from_request();
3791
-        $deleted_count = 0;
3792
-        foreach ($msg_ids as $msg_id) {
3793
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3794
-                $deleted_count++;
3795
-            }
3796
-        }
3797
-        if ($deleted_count) {
3798
-            $this->_redirect_after_action(
3799
-                true,
3800
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
3801
-                __('deleted', 'event_espresso')
3802
-            );
3803
-        } else {
3804
-            EE_Error::add_error(
3805
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3806
-                __FILE__, __FUNCTION__, __LINE__
3807
-            );
3808
-            $this->_redirect_after_action(false, '', '', array(), true);
3809
-        }
3810
-    }
3811
-    
3812
-    
3813
-    /**
3814
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3815
-     * @since 4.9.0
3816
-     * @return array
3817
-     */
3818
-    protected function _get_msg_ids_from_request()
3819
-    {
3820
-        if ( ! isset($this->_req_data['MSG_ID'])) {
3821
-            return array();
3822
-        }
3823
-        
3824
-        return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3825
-    }
3706
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3707
+		}
3708
+        
3709
+		//okay we should have the data all setup.  Now we just update!
3710
+		$success = $this->_message_resource_manager->update_active_messengers_option();
3711
+        
3712
+		if ($success) {
3713
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
3714
+		} else {
3715
+			EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3716
+		}
3717
+        
3718
+		$this->_template_args['success'] = $success;
3719
+		$this->_return_json();
3720
+	}
3721
+    
3722
+    
3723
+    
3724
+    
3725
+	/**  EE MESSAGE PROCESSING ACTIONS **/
3726
+    
3727
+    
3728
+	/**
3729
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3730
+	 * However, this does not send immediately, it just queues for sending.
3731
+	 *
3732
+	 * @since 4.9.0
3733
+	 */
3734
+	protected function _generate_now()
3735
+	{
3736
+		$msg_ids = $this->_get_msg_ids_from_request();
3737
+		EED_Messages::generate_now($msg_ids);
3738
+		$this->_redirect_after_action(false, '', '', array(), true);
3739
+	}
3740
+    
3741
+    
3742
+	/**
3743
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3744
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
3745
+	 *
3746
+	 * @since 4.9.0
3747
+	 *
3748
+	 */
3749
+	protected function _generate_and_send_now()
3750
+	{
3751
+		$this->_generate_now();
3752
+		$this->_send_now();
3753
+		$this->_redirect_after_action(false, '', '', array(), true);
3754
+	}
3755
+    
3756
+    
3757
+	/**
3758
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3759
+	 *
3760
+	 * @since 4.9.0
3761
+	 */
3762
+	protected function _queue_for_resending()
3763
+	{
3764
+		$msg_ids = $this->_get_msg_ids_from_request();
3765
+		EED_Messages::queue_for_resending($msg_ids);
3766
+		$this->_redirect_after_action(false, '', '', array(), true);
3767
+	}
3768
+    
3769
+    
3770
+	/**
3771
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3772
+	 *
3773
+	 * @since 4.9.0
3774
+	 */
3775
+	protected function _send_now()
3776
+	{
3777
+		$msg_ids = $this->_get_msg_ids_from_request();
3778
+		EED_Messages::send_now($msg_ids);
3779
+		$this->_redirect_after_action(false, '', '', array(), true);
3780
+	}
3781
+    
3782
+    
3783
+	/**
3784
+	 * Deletes EE_messages for IDs in the request.
3785
+	 *
3786
+	 * @since 4.9.0
3787
+	 */
3788
+	protected function _delete_ee_messages()
3789
+	{
3790
+		$msg_ids       = $this->_get_msg_ids_from_request();
3791
+		$deleted_count = 0;
3792
+		foreach ($msg_ids as $msg_id) {
3793
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3794
+				$deleted_count++;
3795
+			}
3796
+		}
3797
+		if ($deleted_count) {
3798
+			$this->_redirect_after_action(
3799
+				true,
3800
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
3801
+				__('deleted', 'event_espresso')
3802
+			);
3803
+		} else {
3804
+			EE_Error::add_error(
3805
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3806
+				__FILE__, __FUNCTION__, __LINE__
3807
+			);
3808
+			$this->_redirect_after_action(false, '', '', array(), true);
3809
+		}
3810
+	}
3811
+    
3812
+    
3813
+	/**
3814
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3815
+	 * @since 4.9.0
3816
+	 * @return array
3817
+	 */
3818
+	protected function _get_msg_ids_from_request()
3819
+	{
3820
+		if ( ! isset($this->_req_data['MSG_ID'])) {
3821
+			return array();
3822
+		}
3823
+        
3824
+		return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3825
+	}
3826 3826
     
3827 3827
     
3828 3828
 }
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         $this->_admin_base_url  = EE_MSG_ADMIN_URL;
88 88
         $this->_admin_base_path = EE_MSG_ADMIN;
89 89
         
90
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
90
+        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array();
91 91
         
92 92
         $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93 93
         $this->_load_message_resource_manager();
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
             array('none_selected' => __('Show All Messengers', 'event_espresso')),
220 220
             $messenger_options
221 221
         );
222
-        $input             = new EE_Select_Input(
222
+        $input = new EE_Select_Input(
223 223
             $messenger_options,
224 224
             array(
225 225
                 'html_name'  => 'ee_messenger_filter_by',
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
             array('none_selected' => __('Show All Message Types', 'event_espresso')),
258 258
             $message_type_options
259 259
         );
260
-        $input                = new EE_Select_Input(
260
+        $input = new EE_Select_Input(
261 261
             $message_type_options,
262 262
             array(
263 263
                 'html_name'  => 'ee_message_type_filter_by',
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             array('none_selected' => __('Show all Contexts', 'event_espresso')),
296 296
             $context_options
297 297
         );
298
-        $input           = new EE_Select_Input(
298
+        $input = new EE_Select_Input(
299 299
             $context_options,
300 300
             array(
301 301
                 'html_name'  => 'ee_context_filter_by',
@@ -676,47 +676,47 @@  discard block
 block discarded – undo
676 676
     
677 677
     public function messages_help_tab()
678 678
     {
679
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
679
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
680 680
     }
681 681
     
682 682
     
683 683
     public function messengers_help_tab()
684 684
     {
685
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
685
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
686 686
     }
687 687
     
688 688
     
689 689
     public function message_types_help_tab()
690 690
     {
691
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
691
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
692 692
     }
693 693
     
694 694
     
695 695
     public function messages_overview_help_tab()
696 696
     {
697
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
697
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
698 698
     }
699 699
     
700 700
     
701 701
     public function message_templates_help_tab()
702 702
     {
703
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
703
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
704 704
     }
705 705
     
706 706
     
707 707
     public function edit_message_template_help_tab()
708 708
     {
709
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
-                'event_espresso') . '" />';
711
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
-                'event_espresso') . '" />';
713
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
-                'event_espresso') . '" />';
715
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
-                'event_espresso') . '" />';
717
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
-                'event_espresso') . '" />';
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
709
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title',
710
+                'event_espresso').'" />';
711
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview',
712
+                'event_espresso').'" />';
713
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields',
714
+                'event_espresso').'" />';
715
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox',
716
+                'event_espresso').'" />';
717
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox',
718
+                'event_espresso').'" />';
719
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
720 720
             $args);
721 721
     }
722 722
     
@@ -725,37 +725,37 @@  discard block
 block discarded – undo
725 725
     {
726 726
         $this->_set_shortcodes();
727 727
         $args['shortcodes'] = $this->_shortcodes;
728
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
728
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
729 729
             $args);
730 730
     }
731 731
     
732 732
     
733 733
     public function preview_message_help_tab()
734 734
     {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
735
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
736 736
     }
737 737
     
738 738
     
739 739
     public function settings_help_tab()
740 740
     {
741
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
-                'event_espresso') . '" />';
743
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
-                'event_espresso') . '" />';
741
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab',
742
+                'event_espresso').'" />';
743
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab',
744
+                'event_espresso').'" />';
745 745
         $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746 746
         $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
747
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
748 748
     }
749 749
     
750 750
     
751 751
     public function load_scripts_styles()
752 752
     {
753
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
753
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754 754
         wp_enqueue_style('espresso_ee_msg');
755 755
         
756
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
756
+        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js',
757 757
             array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
758
+        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
759 759
             array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760 760
     }
761 761
     
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
         
788 788
         $this->_set_shortcodes();
789 789
         
790
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
790
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
791 791
             __('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.',
792 792
                 'event_espresso'),
793 793
             $this->_message_template_group->messenger_obj()->label['singular'],
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
         EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797 797
             'event_espresso');
798 798
         
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
799
+        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'),
800 800
             EVENT_ESPRESSO_VERSION);
801 801
         
802 802
         wp_enqueue_script('ee_admin_js');
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
     
828 828
     public function load_scripts_styles_settings()
829 829
     {
830
-        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
830
+        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(),
831 831
             EVENT_ESPRESSO_VERSION);
832 832
         wp_enqueue_style('ee-text-links');
833 833
         wp_enqueue_style('ee-message-settings');
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
             }
894 894
             $status_bulk_actions = $common_bulk_actions;
895 895
             //unset bulk actions not applying to status
896
-            if (! empty($status_bulk_actions)) {
896
+            if ( ! empty($status_bulk_actions)) {
897 897
                 switch ($status) {
898 898
                     case EEM_Message::status_idle:
899 899
                     case EEM_Message::status_resend:
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
             }
919 919
 
920 920
             //skip adding messenger executing status to views because it will be included with the Failed view.
921
-            if ( $status === EEM_Message::status_messenger_executing ) {
921
+            if ($status === EEM_Message::status_messenger_executing) {
922 922
                 continue;
923 923
             }
924 924
             
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
         $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
945 945
         $this->_template_args['per_column']        = 6;
946 946
         $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
947
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
947
+        $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>';
948 948
         $this->display_admin_list_table_page_with_no_sidebar();
949 949
     }
950 950
     
@@ -968,37 +968,37 @@  discard block
 block discarded – undo
968 968
         /** @type array $status_items status legend setup */
969 969
         $status_items = array(
970 970
             'sent_status'       => array(
971
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
971
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
972 972
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
973 973
             ),
974 974
             'idle_status'       => array(
975
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
975
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
976 976
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
977 977
             ),
978 978
             'failed_status'     => array(
979
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
979
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
980 980
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
981 981
             ),
982 982
             'messenger_executing_status' => array(
983
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
983
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
984 984
                 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
985 985
             ),
986 986
             'resend_status'     => array(
987
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
987
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
988 988
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
989 989
             ),
990 990
             'incomplete_status' => array(
991
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
991
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
992 992
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
993 993
             ),
994 994
             'retry_status'      => array(
995
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
995
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
996 996
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
997 997
             )
998 998
         );
999 999
         if (EEM_Message::debug()) {
1000 1000
             $status_items['debug_only_status'] = array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1001
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1002 1002
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1003 1003
             );
1004 1004
         }
@@ -1010,10 +1010,10 @@  discard block
 block discarded – undo
1010 1010
     protected function _custom_mtps_preview()
1011 1011
     {
1012 1012
         $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1013
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1014
-                'event_espresso') . '" />';
1015
-        $this->_template_args['preview_text'] = '<strong>' . __('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.',
1016
-                'event_espresso') . '</strong>';
1013
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot',
1014
+                'event_espresso').'" />';
1015
+        $this->_template_args['preview_text'] = '<strong>'.__('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.',
1016
+                'event_espresso').'</strong>';
1017 1017
         $this->display_admin_caf_preview_page('custom_message_types', false);
1018 1018
     }
1019 1019
     
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
                             //let's verify if we need this extra field via the shortcodes parameter.
1262 1262
                             $continue = false;
1263 1263
                             if (isset($extra_array['shortcodes_required'])) {
1264
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1264
+                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1265 1265
                                     if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1266 1266
                                         $continue = true;
1267 1267
                                     }
@@ -1271,9 +1271,9 @@  discard block
 block discarded – undo
1271 1271
                                 }
1272 1272
                             }
1273 1273
                             
1274
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1274
+                            $field_id                                = $reference_field.'-'.$extra_field.'-content';
1275 1275
                             $template_form_fields[$field_id]         = $extra_array;
1276
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1276
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']';
1277 1277
                             $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1278 1278
                             
1279 1279
                             $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
                                                                                 is_array($validators[$extra_field])
1284 1284
                                                                                 && isset($validators[$extra_field]['msg'])
1285 1285
                                                                             )
1286
-                                ? 'validate-error ' . $css_class
1286
+                                ? 'validate-error '.$css_class
1287 1287
                                 : $css_class;
1288 1288
                             
1289 1289
                             $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
@@ -1311,11 +1311,11 @@  discard block
 block discarded – undo
1311 1311
                                 
1312 1312
                             }/**/
1313 1313
                         }
1314
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1315
-                        $templatefield_templatename_id = $reference_field . '-name';
1314
+                        $templatefield_MTP_id          = $reference_field.'-MTP_ID';
1315
+                        $templatefield_templatename_id = $reference_field.'-name';
1316 1316
                         
1317 1317
                         $template_form_fields[$templatefield_MTP_id] = array(
1318
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1318
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1319 1319
                             'label'      => null,
1320 1320
                             'input'      => 'hidden',
1321 1321
                             'type'       => 'int',
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
                         );
1329 1329
                         
1330 1330
                         $template_form_fields[$templatefield_templatename_id] = array(
1331
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1331
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1332 1332
                             'label'      => null,
1333 1333
                             'input'      => 'hidden',
1334 1334
                             'type'       => 'string',
@@ -1342,9 +1342,9 @@  discard block
 block discarded – undo
1342 1342
                     }
1343 1343
                     continue; //skip the next stuff, we got the necessary fields here for this dataset.
1344 1344
                 } else {
1345
-                    $field_id                                 = $template_field . '-content';
1345
+                    $field_id                                 = $template_field.'-content';
1346 1346
                     $template_form_fields[$field_id]          = $field_setup_array;
1347
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1347
+                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields['.$template_field.'][content]';
1348 1348
                     $message_template                         = isset($message_templates[$context][$template_field])
1349 1349
                         ? $message_templates[$context][$template_field]
1350 1350
                         : null;
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
                     $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1366 1366
                                                                     && in_array($template_field, $v_fields)
1367 1367
                                                                     && isset($validators[$template_field]['msg'])
1368
-                        ? 'validate-error ' . $css_class
1368
+                        ? 'validate-error '.$css_class
1369 1369
                         : $css_class;
1370 1370
                     
1371 1371
                     //shortcode selector
@@ -1376,12 +1376,12 @@  discard block
 block discarded – undo
1376 1376
                 
1377 1377
                 //k took care of content field(s) now let's take care of others.
1378 1378
                 
1379
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1380
-                $templatefield_field_templatename_id = $template_field . '-name';
1379
+                $templatefield_MTP_id                = $template_field.'-MTP_ID';
1380
+                $templatefield_field_templatename_id = $template_field.'-name';
1381 1381
                 
1382 1382
                 //foreach template field there are actually two form fields created
1383 1383
                 $template_form_fields[$templatefield_MTP_id] = array(
1384
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1384
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1385 1385
                     'label'      => null,
1386 1386
                     'input'      => 'hidden',
1387 1387
                     'type'       => 'int',
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
                 );
1395 1395
                 
1396 1396
                 $template_form_fields[$templatefield_field_templatename_id] = array(
1397
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1397
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1398 1398
                     'label'      => null,
1399 1399
                     'input'      => 'hidden',
1400 1400
                     'type'       => 'string',
@@ -1512,7 +1512,7 @@  discard block
 block discarded – undo
1512 1512
                 'format'     => '%d',
1513 1513
                 'db-col'     => 'MTP_deleted'
1514 1514
             );
1515
-            $sidebar_form_fields['ee-msg-author']  = array(
1515
+            $sidebar_form_fields['ee-msg-author'] = array(
1516 1516
                 'name'       => 'MTP_user_id',
1517 1517
                 'label'      => __('Author', 'event_espresso'),
1518 1518
                 'input'      => 'hidden',
@@ -1531,17 +1531,17 @@  discard block
 block discarded – undo
1531 1531
                 'value' => $action
1532 1532
             );
1533 1533
             
1534
-            $sidebar_form_fields['ee-msg-id']        = array(
1534
+            $sidebar_form_fields['ee-msg-id'] = array(
1535 1535
                 'name'  => 'id',
1536 1536
                 'input' => 'hidden',
1537 1537
                 'type'  => 'int',
1538 1538
                 'value' => $GRP_ID
1539 1539
             );
1540 1540
             $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1541
-                'name'  => $action . '_nonce',
1541
+                'name'  => $action.'_nonce',
1542 1542
                 'input' => 'hidden',
1543 1543
                 'type'  => 'string',
1544
-                'value' => wp_create_nonce($action . '_nonce')
1544
+                'value' => wp_create_nonce($action.'_nonce')
1545 1545
             );
1546 1546
             
1547 1547
             if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
@@ -1573,7 +1573,7 @@  discard block
 block discarded – undo
1573 1573
         );
1574 1574
         
1575 1575
         //add preview button
1576
-        $preview_url    = parent::add_query_args_and_nonce(
1576
+        $preview_url = parent::add_query_args_and_nonce(
1577 1577
             array(
1578 1578
                 'message_type' => $message_template_group->message_type(),
1579 1579
                 'messenger'    => $message_template_group->messenger(),
@@ -1583,8 +1583,8 @@  discard block
 block discarded – undo
1583 1583
             ),
1584 1584
             $this->_admin_base_url
1585 1585
         );
1586
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1587
-                'event_espresso') . '</a>';
1586
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview',
1587
+                'event_espresso').'</a>';
1588 1588
         
1589 1589
         
1590 1590
         //setup context switcher
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
         
1614 1614
         $this->_template_path = $this->_template_args['GRP_ID']
1615 1615
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1616
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1616
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1617 1617
         
1618 1618
         //send along EE_Message_Template_Group object for further template use.
1619 1619
         $this->_template_args['MTP'] = $message_template_group;
@@ -1648,7 +1648,7 @@  discard block
 block discarded – undo
1648 1648
     
1649 1649
     public function _add_form_element_before()
1650 1650
     {
1651
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1651
+        return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">';
1652 1652
     }
1653 1653
     
1654 1654
     public function _add_form_element_after()
@@ -1843,14 +1843,14 @@  discard block
 block discarded – undo
1843 1843
         }
1844 1844
         
1845 1845
         //let's add a button to go back to the edit view
1846
-        $query_args             = array(
1846
+        $query_args = array(
1847 1847
             'id'      => $this->_req_data['GRP_ID'],
1848 1848
             'context' => $this->_req_data['context'],
1849 1849
             'action'  => 'edit_message_template'
1850 1850
         );
1851 1851
         $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1852
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1853
-                'event_espresso') . '</a>';
1852
+        $preview_button         = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit',
1853
+                'event_espresso').'</a>';
1854 1854
         $message_types          = $this->get_installed_message_types();
1855 1855
         $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1856 1856
         $active_messenger_label = $active_messenger instanceof EE_messenger
@@ -1864,7 +1864,7 @@  discard block
 block discarded – undo
1864 1864
         );
1865 1865
         //setup display of preview.
1866 1866
         $this->_admin_page_title                    = $preview_title;
1867
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1867
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview);
1868 1868
         $this->_template_args['data']['force_json'] = true;
1869 1869
         
1870 1870
         return '';
@@ -1946,7 +1946,7 @@  discard block
 block discarded – undo
1946 1946
         }
1947 1947
         
1948 1948
         //setup variation select values for the currently selected template.
1949
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1949
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
1950 1950
             $this->_message_template_group->messenger(),
1951 1951
             $this->_message_template_group->message_type()
1952 1952
         );
@@ -1960,12 +1960,12 @@  discard block
 block discarded – undo
1960 1960
         
1961 1961
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1962 1962
         
1963
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1963
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
1964 1964
             'MTP_template_pack',
1965 1965
             $tp_select_values,
1966 1966
             $this->_message_template_group->get_template_pack_name()
1967 1967
         );
1968
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1968
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
1969 1969
             'MTP_template_variation',
1970 1970
             $variations_select_values,
1971 1971
             $this->_message_template_group->get_template_pack_variation()
@@ -1975,7 +1975,7 @@  discard block
 block discarded – undo
1975 1975
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1976 1976
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1977 1977
         
1978
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1978
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
1979 1979
         
1980 1980
         EEH_Template::display_template($template, $template_args);
1981 1981
     }
@@ -2004,7 +2004,7 @@  discard block
 block discarded – undo
2004 2004
         if ( ! empty($fields)) {
2005 2005
             //yup there be fields
2006 2006
             foreach ($fields as $field => $config) {
2007
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2007
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2008 2008
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2009 2009
                 $default  = isset($config['default']) ? $config['default'] : '';
2010 2010
                 $default  = isset($config['value']) ? $config['value'] : $default;
@@ -2019,7 +2019,7 @@  discard block
 block discarded – undo
2019 2019
                     : $fix;
2020 2020
                 
2021 2021
                 $template_form_fields[$field_id] = array(
2022
-                    'name'       => 'test_settings_fld[' . $field . ']',
2022
+                    'name'       => 'test_settings_fld['.$field.']',
2023 2023
                     'label'      => $config['label'],
2024 2024
                     'input'      => $config['input'],
2025 2025
                     'type'       => $config['type'],
@@ -2049,7 +2049,7 @@  discard block
 block discarded – undo
2049 2049
         }
2050 2050
         
2051 2051
         //and button
2052
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2052
+        $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>';
2053 2053
         $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2054 2054
         $test_settings_html .= $this->get_action_link_or_button(
2055 2055
             'reset_to_default',
@@ -2080,7 +2080,7 @@  discard block
 block discarded – undo
2080 2080
             'linked_input_id' => $linked_input_id
2081 2081
         );
2082 2082
         
2083
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2083
+        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2084 2084
             $template_args, true);
2085 2085
     }
2086 2086
     
@@ -2098,7 +2098,7 @@  discard block
 block discarded – undo
2098 2098
         //$messenger = $this->_message_template_group->messenger_obj();
2099 2099
         //now let's set the content depending on the status of the shortcodes array
2100 2100
         if (empty($shortcodes)) {
2101
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2101
+            $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>';
2102 2102
             echo $content;
2103 2103
         } else {
2104 2104
             //$alt = 0;
@@ -2215,7 +2215,7 @@  discard block
 block discarded – undo
2215 2215
                     <?php
2216 2216
                 }
2217 2217
                 //setup nonce_url
2218
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2218
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2219 2219
                 ?>
2220 2220
                 <select name="context">
2221 2221
                     <?php
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
             : '';
2314 2314
         $context      = ucwords(str_replace('_', ' ', $context_slug));
2315 2315
         
2316
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2316
+        $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : '';
2317 2317
         $item_desc .= 'Message Template';
2318 2318
         $query_args  = array();
2319 2319
         $edit_array  = array();
@@ -2688,8 +2688,8 @@  discard block
 block discarded – undo
2688 2688
      */
2689 2689
     protected function _learn_more_about_message_templates_link()
2690 2690
     {
2691
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2692
-            'event_espresso') . '</a>';
2691
+        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works',
2692
+            'event_espresso').'</a>';
2693 2693
     }
2694 2694
     
2695 2695
     
@@ -2765,10 +2765,10 @@  discard block
 block discarded – undo
2765 2765
                 
2766 2766
                 $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2767 2767
                     'label'    => ucwords($message_type->label['singular']),
2768
-                    'class'    => 'message-type-' . $a_or_i,
2769
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2770
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2771
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2768
+                    'class'    => 'message-type-'.$a_or_i,
2769
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
2770
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
2771
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
2772 2772
                     'title'    => $a_or_i == 'active'
2773 2773
                         ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2774 2774
                         : __('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -2804,9 +2804,9 @@  discard block
 block discarded – undo
2804 2804
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2805 2805
             
2806 2806
             foreach ($fields as $fldname => $fldprops) {
2807
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2807
+                $field_id                       = $messenger->name.'-'.$message_type->name.'-'.$fldname;
2808 2808
                 $template_form_field[$field_id] = array(
2809
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2809
+                    'name'       => 'message_type_settings['.$fldname.']',
2810 2810
                     'label'      => $fldprops['label'],
2811 2811
                     'input'      => $fldprops['field_type'],
2812 2812
                     'type'       => $fldprops['value_type'],
@@ -2847,7 +2847,7 @@  discard block
 block discarded – undo
2847 2847
         $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2848 2848
         
2849 2849
         
2850
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2850
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
2851 2851
         $content  = EEH_Template::display_template($template, $settings_template_args, true);
2852 2852
         
2853 2853
         return $content;
@@ -2877,11 +2877,11 @@  discard block
 block discarded – undo
2877 2877
                 $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2878 2878
                     ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2879 2879
                     : '';
2880
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2880
+                $m_boxes[$messenger.'_a_box']         = sprintf(
2881 2881
                     __('%s Settings', 'event_espresso'),
2882 2882
                     $tab_array['label']
2883 2883
                 );
2884
-                $m_template_args[$messenger . '_a_box'] = array(
2884
+                $m_template_args[$messenger.'_a_box'] = array(
2885 2885
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2886 2886
                     'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2887 2887
                         ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
@@ -2895,8 +2895,8 @@  discard block
 block discarded – undo
2895 2895
                 // message type meta boxes
2896 2896
                 // (which is really just the inactive container for each messenger
2897 2897
                 // showing inactive message types for that messenger)
2898
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2899
-                $mt_template_args[$messenger . '_i_box'] = array(
2898
+                $mt_boxes[$messenger.'_i_box']         = __('Inactive Message Types', 'event_espresso');
2899
+                $mt_template_args[$messenger.'_i_box'] = array(
2900 2900
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2901 2901
                     'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2902 2902
                         ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
@@ -2912,14 +2912,14 @@  discard block
 block discarded – undo
2912 2912
         
2913 2913
         
2914 2914
         //register messenger metaboxes
2915
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2915
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
2916 2916
         foreach ($m_boxes as $box => $label) {
2917 2917
             $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2918 2918
             $msgr          = str_replace('_a_box', '', $box);
2919 2919
             add_meta_box(
2920
-                'espresso_' . $msgr . '_settings',
2920
+                'espresso_'.$msgr.'_settings',
2921 2921
                 $label,
2922
-                function ($post, $metabox) {
2922
+                function($post, $metabox) {
2923 2923
                     echo EEH_Template::display_template($metabox["args"]["template_path"],
2924 2924
                         $metabox["args"]["template_args"], true);
2925 2925
                 },
@@ -2931,17 +2931,17 @@  discard block
 block discarded – undo
2931 2931
         }
2932 2932
         
2933 2933
         //register message type metaboxes
2934
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2934
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
2935 2935
         foreach ($mt_boxes as $box => $label) {
2936 2936
             $callback_args = array(
2937 2937
                 'template_path' => $mt_template_path,
2938 2938
                 'template_args' => $mt_template_args[$box]
2939 2939
             );
2940
-            $mt            = str_replace('_i_box', '', $box);
2940
+            $mt = str_replace('_i_box', '', $box);
2941 2941
             add_meta_box(
2942
-                'espresso_' . $mt . '_inactive_mts',
2942
+                'espresso_'.$mt.'_inactive_mts',
2943 2943
                 $label,
2944
-                function ($post, $metabox) {
2944
+                function($post, $metabox) {
2945 2945
                     echo EEH_Template::display_template($metabox["args"]["template_path"],
2946 2946
                         $metabox["args"]["template_args"], true);
2947 2947
                 },
@@ -3043,7 +3043,7 @@  discard block
 block discarded – undo
3043 3043
             if ($form->is_valid()) {
3044 3044
                 $valid_data = $form->valid_data();
3045 3045
                 foreach ($valid_data as $property => $value) {
3046
-                    $setter = 'set_' . $property;
3046
+                    $setter = 'set_'.$property;
3047 3047
                     if (method_exists($network_config, $setter)) {
3048 3048
                         $network_config->{$setter}($value);
3049 3049
                     } else if (
@@ -3072,8 +3072,8 @@  discard block
 block discarded – undo
3072 3072
      */
3073 3073
     protected function _get_mt_tabs($tab_array)
3074 3074
     {
3075
-        $tab_array = (array)$tab_array;
3076
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3075
+        $tab_array = (array) $tab_array;
3076
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3077 3077
         $tabs      = '';
3078 3078
         
3079 3079
         foreach ($tab_array as $tab) {
@@ -3106,9 +3106,9 @@  discard block
 block discarded – undo
3106 3106
             $existing_settings = $messenger->get_existing_admin_settings();
3107 3107
             
3108 3108
             foreach ($fields as $fldname => $fldprops) {
3109
-                $field_id                       = $messenger->name . '-' . $fldname;
3109
+                $field_id                       = $messenger->name.'-'.$fldname;
3110 3110
                 $template_form_field[$field_id] = array(
3111
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3111
+                    'name'       => 'messenger_settings['.$field_id.']',
3112 3112
                     'label'      => $fldprops['label'],
3113 3113
                     'input'      => $fldprops['field_type'],
3114 3114
                     'type'       => $fldprops['value_type'],
@@ -3143,7 +3143,7 @@  discard block
 block discarded – undo
3143 3143
         //make sure any active message types that are existing are included in the hidden fields
3144 3144
         if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3145 3145
             foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3146
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3146
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(
3147 3147
                     'type'  => 'hidden',
3148 3148
                     'value' => $mt
3149 3149
                 );
@@ -3153,7 +3153,7 @@  discard block
 block discarded – undo
3153 3153
             $settings_template_args['hidden_fields'],
3154 3154
             'array'
3155 3155
         );
3156
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3156
+        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3157 3157
         
3158 3158
         $settings_template_args['messenger']           = $messenger->name;
3159 3159
         $settings_template_args['description']         = $messenger->description;
@@ -3170,9 +3170,9 @@  discard block
 block discarded – undo
3170 3170
         
3171 3171
         
3172 3172
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3173
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3173
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3174 3174
         $settings_template_args['on_off_status'] = $active ? true : false;
3175
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3175
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3176 3176
         $content                                 = EEH_Template::display_template($template, $settings_template_args,
3177 3177
             true);
3178 3178
         
@@ -3200,7 +3200,7 @@  discard block
 block discarded – undo
3200 3200
         
3201 3201
         //do a nonce check here since we're not arriving via a normal route
3202 3202
         $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3203
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3203
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3204 3204
         
3205 3205
         $this->_verify_nonce($nonce, $nonce_ref);
3206 3206
         
@@ -3302,7 +3302,7 @@  discard block
 block discarded – undo
3302 3302
         
3303 3303
         //do a nonce check here since we're not arriving via a normal route
3304 3304
         $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3305
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3305
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
3306 3306
         
3307 3307
         $this->_verify_nonce($nonce, $nonce_ref);
3308 3308
         
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Shortcode.lib.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -27,89 +27,89 @@  discard block
 block discarded – undo
27 27
 class EE_Register_Shortcode implements EEI_Plugin_API
28 28
 {
29 29
 
30
-    /**
31
-     * Holds values for registered shortcodes
32
-     *
33
-     * @var array
34
-     */
35
-    protected static $_settings = array();
30
+	/**
31
+	 * Holds values for registered shortcodes
32
+	 *
33
+	 * @var array
34
+	 */
35
+	protected static $_settings = array();
36 36
 
37 37
 
38
-    /**
39
-     *    Method for registering new EE_Shortcodes
40
-     *
41
-     * @since    4.3.0
42
-     * @param string $shortcode_id a unique identifier for this set of modules Required.
43
-     * @param  array $setup_args   an array of arguments provided for registering shortcodes Required.
44
-     * @type array shortcode_paths        an array of full server paths to folders containing any EES_Shortcodes, or to
45
-     *       the EES_Shortcode files themselves
46
-     * @throws EE_Error
47
-     * @return void
48
-     */
49
-    public static function register($shortcode_id = null, $setup_args = array())
50
-    {
38
+	/**
39
+	 *    Method for registering new EE_Shortcodes
40
+	 *
41
+	 * @since    4.3.0
42
+	 * @param string $shortcode_id a unique identifier for this set of modules Required.
43
+	 * @param  array $setup_args   an array of arguments provided for registering shortcodes Required.
44
+	 * @type array shortcode_paths        an array of full server paths to folders containing any EES_Shortcodes, or to
45
+	 *       the EES_Shortcode files themselves
46
+	 * @throws EE_Error
47
+	 * @return void
48
+	 */
49
+	public static function register($shortcode_id = null, $setup_args = array())
50
+	{
51 51
 
52
-        //required fields MUST be present, so let's make sure they are.
53
-        if (empty($shortcode_id) || ! is_array($setup_args) || empty($setup_args['shortcode_paths'])) {
54
-            throw new EE_Error(__('In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
55
-                'event_espresso'));
56
-        }
52
+		//required fields MUST be present, so let's make sure they are.
53
+		if (empty($shortcode_id) || ! is_array($setup_args) || empty($setup_args['shortcode_paths'])) {
54
+			throw new EE_Error(__('In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
55
+				'event_espresso'));
56
+		}
57 57
 
58
-        //make sure we don't register twice
59
-        if (isset(self::$_settings[$shortcode_id])) {
60
-            return;
61
-        }
58
+		//make sure we don't register twice
59
+		if (isset(self::$_settings[$shortcode_id])) {
60
+			return;
61
+		}
62 62
 
63
-        //make sure this was called in the right place!
64
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')) {
65
-            EE_Error::doing_it_wrong(
66
-                __METHOD__,
67
-                __('An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
68
-                    'event_espresso'),
69
-                '4.3.0'
70
-            );
71
-        }
72
-        //setup $_settings array from incoming values.
73
-        self::$_settings[$shortcode_id] = array(
74
-            // array of full server paths to any EES_Shortcodes used by the shortcode
75
-            'shortcode_paths' => isset($setup_args['shortcode_paths']) ? (array)$setup_args['shortcode_paths'] : array(),
76
-        );
77
-        // add to list of shortcodes to be registered
78
-        add_filter('FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
79
-            array('EE_Register_Shortcode', 'add_shortcodes'));
80
-    }
63
+		//make sure this was called in the right place!
64
+		if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')) {
65
+			EE_Error::doing_it_wrong(
66
+				__METHOD__,
67
+				__('An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
68
+					'event_espresso'),
69
+				'4.3.0'
70
+			);
71
+		}
72
+		//setup $_settings array from incoming values.
73
+		self::$_settings[$shortcode_id] = array(
74
+			// array of full server paths to any EES_Shortcodes used by the shortcode
75
+			'shortcode_paths' => isset($setup_args['shortcode_paths']) ? (array)$setup_args['shortcode_paths'] : array(),
76
+		);
77
+		// add to list of shortcodes to be registered
78
+		add_filter('FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
79
+			array('EE_Register_Shortcode', 'add_shortcodes'));
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * Filters the list of shortcodes to add ours.
85
-     * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
86
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...)
87
-     *
88
-     * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
89
-     * @return array
90
-     */
91
-    public static function add_shortcodes($shortcodes_to_register)
92
-    {
93
-        foreach (self::$_settings as $settings) {
94
-            $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
95
-        }
96
-        return $shortcodes_to_register;
97
-    }
83
+	/**
84
+	 * Filters the list of shortcodes to add ours.
85
+	 * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
86
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...)
87
+	 *
88
+	 * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
89
+	 * @return array
90
+	 */
91
+	public static function add_shortcodes($shortcodes_to_register)
92
+	{
93
+		foreach (self::$_settings as $settings) {
94
+			$shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
95
+		}
96
+		return $shortcodes_to_register;
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * This deregisters a shortcode that was previously registered with a specific $shortcode_id.
102
-     *
103
-     * @since    4.3.0
104
-     * @param string $shortcode_id the name for the shortcode that was previously registered
105
-     * @return void
106
-     */
107
-    public static function deregister($shortcode_id = null)
108
-    {
109
-        if (isset(self::$_settings[$shortcode_id])) {
110
-            unset(self::$_settings[$shortcode_id]);
111
-        }
112
-    }
100
+	/**
101
+	 * This deregisters a shortcode that was previously registered with a specific $shortcode_id.
102
+	 *
103
+	 * @since    4.3.0
104
+	 * @param string $shortcode_id the name for the shortcode that was previously registered
105
+	 * @return void
106
+	 */
107
+	public static function deregister($shortcode_id = null)
108
+	{
109
+		if (isset(self::$_settings[$shortcode_id])) {
110
+			unset(self::$_settings[$shortcode_id]);
111
+		}
112
+	}
113 113
 
114 114
 }
115 115
 // End of file EE_Register_Shortcode.lib.php
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         }
62 62
 
63 63
         //make sure this was called in the right place!
64
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')) {
64
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')) {
65 65
             EE_Error::doing_it_wrong(
66 66
                 __METHOD__,
67 67
                 __('An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         //setup $_settings array from incoming values.
73 73
         self::$_settings[$shortcode_id] = array(
74 74
             // array of full server paths to any EES_Shortcodes used by the shortcode
75
-            'shortcode_paths' => isset($setup_args['shortcode_paths']) ? (array)$setup_args['shortcode_paths'] : array(),
75
+            'shortcode_paths' => isset($setup_args['shortcode_paths']) ? (array) $setup_args['shortcode_paths'] : array(),
76 76
         );
77 77
         // add to list of shortcodes to be registered
78 78
         add_filter('FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
Please login to merge, or discard this patch.
core/EE_Request_Handler.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 
277 277
     /**
278
-     * @param $string
278
+     * @param string $string
279 279
      * @return void
280 280
      */
281 281
     public function add_output($string)
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
 
329 329
     /**
330
-     * @return    mixed
330
+     * @return    boolean
331 331
      */
332 332
     public function is_espresso_page()
333 333
     {
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
     /**
390 390
      * remove param
391 391
      *
392
-     * @param $key
392
+     * @param string $key
393 393
      * @return    void
394 394
      */
395 395
     public function un_set($key)
Please login to merge, or discard this patch.
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -13,389 +13,389 @@
 block discarded – undo
13 13
 final class EE_Request_Handler implements InterminableInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @var EE_Request $request
18
-     */
19
-    private $request;
20
-
21
-    /**
22
-     * @var array $_notice
23
-     */
24
-    private $_notice = array();
25
-
26
-    /**
27
-     * rendered output to be returned to WP
28
-     *
29
-     * @var string $_output
30
-     */
31
-    private $_output = '';
32
-
33
-    /**
34
-     * whether current request is via AJAX
35
-     *
36
-     * @var boolean $ajax
37
-     */
38
-    public $ajax = false;
39
-
40
-    /**
41
-     * whether current request is via AJAX from the frontend of the site
42
-     *
43
-     * @var boolean $front_ajax
44
-     */
45
-    public $front_ajax = false;
46
-
47
-
48
-
49
-    /**
50
-     * @param  EE_Request $request
51
-     */
52
-    public function __construct(EE_Request $request)
53
-    {
54
-        $this->request = $request;
55
-        $this->ajax = $this->request->ajax;
56
-        $this->front_ajax = $this->request->front_ajax;
57
-        do_action('AHEE__EE_Request_Handler__construct__complete');
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @param WP $wp
64
-     * @return void
65
-     * @throws EE_Error
66
-     * @throws ReflectionException
67
-     */
68
-    public function parse_request($wp = null)
69
-    {
70
-        //if somebody forgot to provide us with WP, that's ok because its global
71
-        if (! $wp instanceof WP) {
72
-            global $wp;
73
-        }
74
-        $this->set_request_vars($wp);
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @param WP $wp
81
-     * @return void
82
-     * @throws EE_Error
83
-     * @throws ReflectionException
84
-     */
85
-    public function set_request_vars($wp = null)
86
-    {
87
-        if (! is_admin()) {
88
-            // set request post_id
89
-            $this->request->set('post_id', $this->get_post_id_from_request($wp));
90
-            // set request post name
91
-            $this->request->set('post_name', $this->get_post_name_from_request($wp));
92
-            // set request post_type
93
-            $this->request->set('post_type', $this->get_post_type_from_request($wp));
94
-            // true or false ? is this page being used by EE ?
95
-            $this->set_espresso_page();
96
-        }
97
-    }
98
-
99
-
100
-
101
-    /**
102
-     * @param WP $wp
103
-     * @return int
104
-     */
105
-    public function get_post_id_from_request($wp = null)
106
-    {
107
-        if (! $wp instanceof WP) {
108
-            global $wp;
109
-        }
110
-        $post_id = null;
111
-        if (isset($wp->query_vars['p'])) {
112
-            $post_id = $wp->query_vars['p'];
113
-        }
114
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
115
-            $post_id = $wp->query_vars['page_id'];
116
-        }
117
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118
-            $post_id = basename($wp->request);
119
-        }
120
-        return $post_id;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @param WP $wp
127
-     * @return string
128
-     */
129
-    public function get_post_name_from_request($wp = null)
130
-    {
131
-        if (! $wp instanceof WP) {
132
-            global $wp;
133
-        }
134
-        $post_name = null;
135
-        if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136
-            $post_name = $wp->query_vars['name'];
137
-        }
138
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139
-            $post_name = $wp->query_vars['pagename'];
140
-        }
141
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
142
-            $possible_post_name = basename($wp->request);
143
-            if (! is_numeric($possible_post_name)) {
144
-                /** @type WPDB $wpdb */
145
-                global $wpdb;
146
-                $SQL =
147
-                    "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
148
-                $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
149
-                if ($possible_post_name) {
150
-                    $post_name = $possible_post_name;
151
-                }
152
-            }
153
-        }
154
-        if (! $post_name && $this->get('post_id')) {
155
-            /** @type WPDB $wpdb */
156
-            global $wpdb;
157
-            $SQL =
158
-                "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
159
-            $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
160
-            if ($possible_post_name) {
161
-                $post_name = $possible_post_name;
162
-            }
163
-        }
164
-        return $post_name;
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * @param WP $wp
171
-     * @return mixed
172
-     */
173
-    public function get_post_type_from_request($wp = null)
174
-    {
175
-        if (! $wp instanceof WP) {
176
-            global $wp;
177
-        }
178
-        return isset($wp->query_vars['post_type'])
179
-            ? $wp->query_vars['post_type']
180
-            : null;
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * Just a helper method for getting the url for the displayed page.
187
-     *
188
-     * @param  WP $wp
189
-     * @return string
190
-     */
191
-    public function get_current_page_permalink($wp = null)
192
-    {
193
-        $post_id = $this->get_post_id_from_request($wp);
194
-        if ($post_id) {
195
-            $current_page_permalink = get_permalink($post_id);
196
-        } else {
197
-            if (! $wp instanceof WP) {
198
-                global $wp;
199
-            }
200
-            if ($wp->request) {
201
-                $current_page_permalink = site_url($wp->request);
202
-            } else {
203
-                $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
204
-            }
205
-        }
206
-        return $current_page_permalink;
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * @return bool
213
-     * @throws EE_Error
214
-     * @throws ReflectionException
215
-     */
216
-    public function test_for_espresso_page()
217
-    {
218
-        global $wp;
219
-        /** @type EE_CPT_Strategy $EE_CPT_Strategy */
220
-        $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
221
-        $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
222
-        if (is_array($espresso_CPT_taxonomies)) {
223
-            foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
224
-                if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
225
-                    return true;
226
-                }
227
-            }
228
-        }
229
-        // load espresso CPT endpoints
230
-        $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231
-        $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
-        $post_types = (array)$this->get('post_type');
233
-        foreach ($post_types as $post_type) {
234
-            // was a post name passed ?
235
-            if (isset($post_type_CPT_endpoints[$post_type])) {
236
-                // kk we know this is an espresso page, but is it a specific post ?
237
-                if (! $this->get('post_name')) {
238
-                    // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239
-                    $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240
-                        ? $post_type_CPT_endpoints[$this->get('post_type')]
241
-                        : '';
242
-                    // if the post type matches on of our then set the endpoint
243
-                    if ($post_name) {
244
-                        $this->set('post_name', $post_name);
245
-                    }
246
-                }
247
-                return true;
248
-            }
249
-        }
250
-        return false;
251
-    }
252
-    /**
253
-     * @param $key
254
-     * @param $value
255
-     * @return    void
256
-     */
257
-    public function set_notice($key, $value)
258
-    {
259
-        $this->_notice[$key] = $value;
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     * @param $key
266
-     * @return    mixed
267
-     */
268
-    public function get_notice($key)
269
-    {
270
-        return isset($this->_notice[$key])
271
-            ? $this->_notice[$key]
272
-            : null;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * @param $string
279
-     * @return void
280
-     */
281
-    public function add_output($string)
282
-    {
283
-        $this->_output .= $string;
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * @return string
290
-     */
291
-    public function get_output()
292
-    {
293
-        return $this->_output;
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @param $item
300
-     * @param $key
301
-     */
302
-    public function sanitize_text_field_for_array_walk(&$item, &$key)
303
-    {
304
-        $item = strpos($item, 'email') !== false
305
-            ? sanitize_email($item)
306
-            : sanitize_text_field($item);
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * @param null|bool $value
313
-     * @return void
314
-     * @throws EE_Error
315
-     * @throws ReflectionException
316
-     */
317
-    public function set_espresso_page($value = null)
318
-    {
319
-        $this->request->set(
320
-            'is_espresso_page',
321
-            ! empty($value)
322
-                ? $value
323
-                : $this->test_for_espresso_page()
324
-        );
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * @return    mixed
331
-     */
332
-    public function is_espresso_page()
333
-    {
334
-        return $this->request->is_set('is_espresso_page');
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * returns contents of $_REQUEST
341
-     *
342
-     * @return array
343
-     */
344
-    public function params()
345
-    {
346
-        return $this->request->params();
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * @param      $key
353
-     * @param      $value
354
-     * @param bool $override_ee
355
-     * @return    void
356
-     */
357
-    public function set($key, $value, $override_ee = false)
358
-    {
359
-        $this->request->set($key, $value, $override_ee);
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * @param      $key
366
-     * @param null $default
367
-     * @return    mixed
368
-     */
369
-    public function get($key, $default = null)
370
-    {
371
-        return $this->request->get($key, $default);
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * check if param exists
378
-     *
379
-     * @param $key
380
-     * @return    boolean
381
-     */
382
-    public function is_set($key)
383
-    {
384
-        return $this->request->is_set($key);
385
-    }
386
-
387
-
388
-
389
-    /**
390
-     * remove param
391
-     *
392
-     * @param $key
393
-     * @return    void
394
-     */
395
-    public function un_set($key)
396
-    {
397
-        $this->request->un_set($key);
398
-    }
16
+	/**
17
+	 * @var EE_Request $request
18
+	 */
19
+	private $request;
20
+
21
+	/**
22
+	 * @var array $_notice
23
+	 */
24
+	private $_notice = array();
25
+
26
+	/**
27
+	 * rendered output to be returned to WP
28
+	 *
29
+	 * @var string $_output
30
+	 */
31
+	private $_output = '';
32
+
33
+	/**
34
+	 * whether current request is via AJAX
35
+	 *
36
+	 * @var boolean $ajax
37
+	 */
38
+	public $ajax = false;
39
+
40
+	/**
41
+	 * whether current request is via AJAX from the frontend of the site
42
+	 *
43
+	 * @var boolean $front_ajax
44
+	 */
45
+	public $front_ajax = false;
46
+
47
+
48
+
49
+	/**
50
+	 * @param  EE_Request $request
51
+	 */
52
+	public function __construct(EE_Request $request)
53
+	{
54
+		$this->request = $request;
55
+		$this->ajax = $this->request->ajax;
56
+		$this->front_ajax = $this->request->front_ajax;
57
+		do_action('AHEE__EE_Request_Handler__construct__complete');
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @param WP $wp
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 * @throws ReflectionException
67
+	 */
68
+	public function parse_request($wp = null)
69
+	{
70
+		//if somebody forgot to provide us with WP, that's ok because its global
71
+		if (! $wp instanceof WP) {
72
+			global $wp;
73
+		}
74
+		$this->set_request_vars($wp);
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @param WP $wp
81
+	 * @return void
82
+	 * @throws EE_Error
83
+	 * @throws ReflectionException
84
+	 */
85
+	public function set_request_vars($wp = null)
86
+	{
87
+		if (! is_admin()) {
88
+			// set request post_id
89
+			$this->request->set('post_id', $this->get_post_id_from_request($wp));
90
+			// set request post name
91
+			$this->request->set('post_name', $this->get_post_name_from_request($wp));
92
+			// set request post_type
93
+			$this->request->set('post_type', $this->get_post_type_from_request($wp));
94
+			// true or false ? is this page being used by EE ?
95
+			$this->set_espresso_page();
96
+		}
97
+	}
98
+
99
+
100
+
101
+	/**
102
+	 * @param WP $wp
103
+	 * @return int
104
+	 */
105
+	public function get_post_id_from_request($wp = null)
106
+	{
107
+		if (! $wp instanceof WP) {
108
+			global $wp;
109
+		}
110
+		$post_id = null;
111
+		if (isset($wp->query_vars['p'])) {
112
+			$post_id = $wp->query_vars['p'];
113
+		}
114
+		if (! $post_id && isset($wp->query_vars['page_id'])) {
115
+			$post_id = $wp->query_vars['page_id'];
116
+		}
117
+		if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118
+			$post_id = basename($wp->request);
119
+		}
120
+		return $post_id;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @param WP $wp
127
+	 * @return string
128
+	 */
129
+	public function get_post_name_from_request($wp = null)
130
+	{
131
+		if (! $wp instanceof WP) {
132
+			global $wp;
133
+		}
134
+		$post_name = null;
135
+		if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136
+			$post_name = $wp->query_vars['name'];
137
+		}
138
+		if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139
+			$post_name = $wp->query_vars['pagename'];
140
+		}
141
+		if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
142
+			$possible_post_name = basename($wp->request);
143
+			if (! is_numeric($possible_post_name)) {
144
+				/** @type WPDB $wpdb */
145
+				global $wpdb;
146
+				$SQL =
147
+					"SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
148
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
149
+				if ($possible_post_name) {
150
+					$post_name = $possible_post_name;
151
+				}
152
+			}
153
+		}
154
+		if (! $post_name && $this->get('post_id')) {
155
+			/** @type WPDB $wpdb */
156
+			global $wpdb;
157
+			$SQL =
158
+				"SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
159
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
160
+			if ($possible_post_name) {
161
+				$post_name = $possible_post_name;
162
+			}
163
+		}
164
+		return $post_name;
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * @param WP $wp
171
+	 * @return mixed
172
+	 */
173
+	public function get_post_type_from_request($wp = null)
174
+	{
175
+		if (! $wp instanceof WP) {
176
+			global $wp;
177
+		}
178
+		return isset($wp->query_vars['post_type'])
179
+			? $wp->query_vars['post_type']
180
+			: null;
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Just a helper method for getting the url for the displayed page.
187
+	 *
188
+	 * @param  WP $wp
189
+	 * @return string
190
+	 */
191
+	public function get_current_page_permalink($wp = null)
192
+	{
193
+		$post_id = $this->get_post_id_from_request($wp);
194
+		if ($post_id) {
195
+			$current_page_permalink = get_permalink($post_id);
196
+		} else {
197
+			if (! $wp instanceof WP) {
198
+				global $wp;
199
+			}
200
+			if ($wp->request) {
201
+				$current_page_permalink = site_url($wp->request);
202
+			} else {
203
+				$current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
204
+			}
205
+		}
206
+		return $current_page_permalink;
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * @return bool
213
+	 * @throws EE_Error
214
+	 * @throws ReflectionException
215
+	 */
216
+	public function test_for_espresso_page()
217
+	{
218
+		global $wp;
219
+		/** @type EE_CPT_Strategy $EE_CPT_Strategy */
220
+		$EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
221
+		$espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
222
+		if (is_array($espresso_CPT_taxonomies)) {
223
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
224
+				if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
225
+					return true;
226
+				}
227
+			}
228
+		}
229
+		// load espresso CPT endpoints
230
+		$espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
+		$post_types = (array)$this->get('post_type');
233
+		foreach ($post_types as $post_type) {
234
+			// was a post name passed ?
235
+			if (isset($post_type_CPT_endpoints[$post_type])) {
236
+				// kk we know this is an espresso page, but is it a specific post ?
237
+				if (! $this->get('post_name')) {
238
+					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239
+					$post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240
+						? $post_type_CPT_endpoints[$this->get('post_type')]
241
+						: '';
242
+					// if the post type matches on of our then set the endpoint
243
+					if ($post_name) {
244
+						$this->set('post_name', $post_name);
245
+					}
246
+				}
247
+				return true;
248
+			}
249
+		}
250
+		return false;
251
+	}
252
+	/**
253
+	 * @param $key
254
+	 * @param $value
255
+	 * @return    void
256
+	 */
257
+	public function set_notice($key, $value)
258
+	{
259
+		$this->_notice[$key] = $value;
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 * @param $key
266
+	 * @return    mixed
267
+	 */
268
+	public function get_notice($key)
269
+	{
270
+		return isset($this->_notice[$key])
271
+			? $this->_notice[$key]
272
+			: null;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * @param $string
279
+	 * @return void
280
+	 */
281
+	public function add_output($string)
282
+	{
283
+		$this->_output .= $string;
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * @return string
290
+	 */
291
+	public function get_output()
292
+	{
293
+		return $this->_output;
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @param $item
300
+	 * @param $key
301
+	 */
302
+	public function sanitize_text_field_for_array_walk(&$item, &$key)
303
+	{
304
+		$item = strpos($item, 'email') !== false
305
+			? sanitize_email($item)
306
+			: sanitize_text_field($item);
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * @param null|bool $value
313
+	 * @return void
314
+	 * @throws EE_Error
315
+	 * @throws ReflectionException
316
+	 */
317
+	public function set_espresso_page($value = null)
318
+	{
319
+		$this->request->set(
320
+			'is_espresso_page',
321
+			! empty($value)
322
+				? $value
323
+				: $this->test_for_espresso_page()
324
+		);
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * @return    mixed
331
+	 */
332
+	public function is_espresso_page()
333
+	{
334
+		return $this->request->is_set('is_espresso_page');
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * returns contents of $_REQUEST
341
+	 *
342
+	 * @return array
343
+	 */
344
+	public function params()
345
+	{
346
+		return $this->request->params();
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * @param      $key
353
+	 * @param      $value
354
+	 * @param bool $override_ee
355
+	 * @return    void
356
+	 */
357
+	public function set($key, $value, $override_ee = false)
358
+	{
359
+		$this->request->set($key, $value, $override_ee);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * @param      $key
366
+	 * @param null $default
367
+	 * @return    mixed
368
+	 */
369
+	public function get($key, $default = null)
370
+	{
371
+		return $this->request->get($key, $default);
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * check if param exists
378
+	 *
379
+	 * @param $key
380
+	 * @return    boolean
381
+	 */
382
+	public function is_set($key)
383
+	{
384
+		return $this->request->is_set($key);
385
+	}
386
+
387
+
388
+
389
+	/**
390
+	 * remove param
391
+	 *
392
+	 * @param $key
393
+	 * @return    void
394
+	 */
395
+	public function un_set($key)
396
+	{
397
+		$this->request->un_set($key);
398
+	}
399 399
 
400 400
 
401 401
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public function parse_request($wp = null)
69 69
     {
70 70
         //if somebody forgot to provide us with WP, that's ok because its global
71
-        if (! $wp instanceof WP) {
71
+        if ( ! $wp instanceof WP) {
72 72
             global $wp;
73 73
         }
74 74
         $this->set_request_vars($wp);
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function set_request_vars($wp = null)
86 86
     {
87
-        if (! is_admin()) {
87
+        if ( ! is_admin()) {
88 88
             // set request post_id
89 89
             $this->request->set('post_id', $this->get_post_id_from_request($wp));
90 90
             // set request post name
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function get_post_id_from_request($wp = null)
106 106
     {
107
-        if (! $wp instanceof WP) {
107
+        if ( ! $wp instanceof WP) {
108 108
             global $wp;
109 109
         }
110 110
         $post_id = null;
111 111
         if (isset($wp->query_vars['p'])) {
112 112
             $post_id = $wp->query_vars['p'];
113 113
         }
114
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
114
+        if ( ! $post_id && isset($wp->query_vars['page_id'])) {
115 115
             $post_id = $wp->query_vars['page_id'];
116 116
         }
117
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
117
+        if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118 118
             $post_id = basename($wp->request);
119 119
         }
120 120
         return $post_id;
@@ -128,19 +128,19 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function get_post_name_from_request($wp = null)
130 130
     {
131
-        if (! $wp instanceof WP) {
131
+        if ( ! $wp instanceof WP) {
132 132
             global $wp;
133 133
         }
134 134
         $post_name = null;
135 135
         if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136 136
             $post_name = $wp->query_vars['name'];
137 137
         }
138
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
138
+        if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139 139
             $post_name = $wp->query_vars['pagename'];
140 140
         }
141
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
141
+        if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) {
142 142
             $possible_post_name = basename($wp->request);
143
-            if (! is_numeric($possible_post_name)) {
143
+            if ( ! is_numeric($possible_post_name)) {
144 144
                 /** @type WPDB $wpdb */
145 145
                 global $wpdb;
146 146
                 $SQL =
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                 }
152 152
             }
153 153
         }
154
-        if (! $post_name && $this->get('post_id')) {
154
+        if ( ! $post_name && $this->get('post_id')) {
155 155
             /** @type WPDB $wpdb */
156 156
             global $wpdb;
157 157
             $SQL =
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function get_post_type_from_request($wp = null)
174 174
     {
175
-        if (! $wp instanceof WP) {
175
+        if ( ! $wp instanceof WP) {
176 176
             global $wp;
177 177
         }
178 178
         return isset($wp->query_vars['post_type'])
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         if ($post_id) {
195 195
             $current_page_permalink = get_permalink($post_id);
196 196
         } else {
197
-            if (! $wp instanceof WP) {
197
+            if ( ! $wp instanceof WP) {
198 198
                 global $wp;
199 199
             }
200 200
             if ($wp->request) {
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
         // load espresso CPT endpoints
230 230
         $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231 231
         $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
-        $post_types = (array)$this->get('post_type');
232
+        $post_types = (array) $this->get('post_type');
233 233
         foreach ($post_types as $post_type) {
234 234
             // was a post name passed ?
235 235
             if (isset($post_type_CPT_endpoints[$post_type])) {
236 236
                 // kk we know this is an espresso page, but is it a specific post ?
237
-                if (! $this->get('post_name')) {
237
+                if ( ! $this->get('post_name')) {
238 238
                     // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239 239
                     $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240 240
                         ? $post_type_CPT_endpoints[$this->get('post_type')]
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/DatetimeOffsetFix.php 2 patches
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -18,305 +18,305 @@
 block discarded – undo
18 18
 class DatetimeOffsetFix extends JobHandler
19 19
 {
20 20
 
21
-    /**
22
-     * Key for the option used to track which models have been processed when doing the batches.
23
-     */
24
-    const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix';
25
-
26
-
27
-    const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed';
28
-
29
-    /**
30
-     * Key for the option used to track what the current offset is that will be applied when this tool is executed.
31
-     */
32
-    const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply';
33
-
34
-
35
-    /**
36
-     * String labelling the datetime offset fix type for change-log entries.
37
-     */
38
-    const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix';
39
-
40
-
41
-    /**
42
-     * String labelling a datetime offset fix error for change-log entries.
43
-     */
44
-    const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error';
45
-
46
-    /**
47
-     * @var EEM_Base[]
48
-     */
49
-    protected $models_with_datetime_fields = array();
50
-
51
-
52
-    /**
53
-     * Performs any necessary setup for starting the job. This is also a good
54
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
55
-     * when continue_job will be called
56
-     *
57
-     * @param JobParameters $job_parameters
58
-     * @throws BatchRequestException
59
-     * @return JobStepResponse
60
-     */
61
-    public function create_job(JobParameters $job_parameters)
62
-    {
63
-        $models_with_datetime_fields = $this->getModelsWithDatetimeFields();
64
-        //we'll be doing each model as a batch.
65
-        $job_parameters->set_job_size(count($models_with_datetime_fields));
66
-        return new JobStepResponse(
67
-            $job_parameters,
68
-            esc_html__('Starting Datetime Offset Fix', 'event_espresso')
69
-        );
70
-    }
71
-
72
-    /**
73
-     * Performs another step of the job
74
-     *
75
-     * @param JobParameters $job_parameters
76
-     * @param int           $batch_size
77
-     * @return JobStepResponse
78
-     * @throws \EE_Error
79
-     */
80
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
81
-    {
82
-        $models_to_process = $this->getModelsWithDatetimeFields();
83
-        //let's pop off the a model and do the query to apply the offset.
84
-        $model_to_process = array_pop($models_to_process);
85
-        //update our record
86
-        $this->setModelsToProcess($models_to_process);
87
-        $this->processModel($model_to_process);
88
-        $this->updateCountOfModelsProcessed();
89
-        $job_parameters->set_units_processed($this->getCountOfModelsProcessed());
90
-        if (count($models_to_process) > 0) {
91
-            $job_parameters->set_status(JobParameters::status_continue);
92
-        } else {
93
-            $job_parameters->set_status(JobParameters::status_complete);
94
-        }
95
-        return new JobStepResponse(
96
-            $job_parameters,
97
-            sprintf(
98
-                esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'),
99
-                $model_to_process
100
-            )
101
-        );
102
-    }
103
-
104
-    /**
105
-     * Performs any clean-up logic when we know the job is completed
106
-     *
107
-     * @param JobParameters $job_parameters
108
-     * @return JobStepResponse
109
-     * @throws BatchRequestException
110
-     */
111
-    public function cleanup_job(JobParameters $job_parameters)
112
-    {
113
-        //delete important saved options.
114
-        delete_option(self::MODELS_TO_PROCESS_OPTION_KEY);
115
-        delete_option(self::COUNT_OF_MODELS_PROCESSED);
116
-        return new JobStepResponse($job_parameters, esc_html__(
117
-            'Offset has been applied to all affected fields.',
118
-            'event_espresso'
119
-        ));
120
-    }
121
-
122
-
123
-    /**
124
-     * Contains the logic for processing a model and applying the datetime offset to affected fields on that model.
125
-     * @param string $model_class_name
126
-     * @throws \EE_Error
127
-     */
128
-    protected function processModel($model_class_name)
129
-    {
130
-        global $wpdb;
131
-        /** @var EEM_Base $model */
132
-        $model = $model_class_name::instance();
133
-        $original_offset = self::getOffset();
134
-        $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB';
135
-        $offset = abs($original_offset) * 60;
136
-        //since some affected models might have two tables, we have to get our tables and set up a query for each table.
137
-        foreach ($model->get_tables() as $table) {
138
-            $query = 'UPDATE ' . $table->get_table_name();
139
-            $fields_affected = array();
140
-            $inner_query = array();
141
-            foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
142
-                if ($model_field instanceof EE_Datetime_Field) {
143
-                    $inner_query[] = $model_field->get_table_column() . ' = '
144
-                                     . $sql_date_function . '('
145
-                                     . $model_field->get_table_column()
146
-                                     . ", INTERVAL $offset MINUTE)";
147
-                    $fields_affected[] = $model_field;
148
-                }
149
-            }
150
-            if (! $fields_affected) {
151
-                continue;
152
-            }
153
-            //k convert innerquery to string
154
-            $query .= ' SET ' . implode(',', $inner_query);
155
-            //execute query
156
-            $result = $wpdb->query($query);
157
-            //record log
158
-            if ($result !== false) {
159
-                $this->recordChangeLog($model, $original_offset, $table, $fields_affected);
160
-            } else {
161
-                //record error.
162
-                $error_message = $wpdb->last_error;
163
-                //handle the edgecases where last_error might be empty.
164
-                if (! $error_message) {
165
-                    $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso');
166
-                }
167
-                $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message);
168
-            }
169
-        }
170
-    }
171
-
172
-
173
-    /**
174
-     * Records a changelog entry using the given information.
175
-     *
176
-     * @param EEM_Base              $model
177
-     * @param float                 $offset
178
-     * @param EE_Table_Base         $table
179
-     * @param EE_Model_Field_Base[] $model_fields_affected
180
-     * @param string                $error_message   If present then there was an error so let's record that instead.
181
-     * @throws \EE_Error
182
-     */
183
-    private function recordChangeLog(
184
-        EEM_Base $model,
185
-        $offset,
186
-        EE_Table_Base $table,
187
-        $model_fields_affected,
188
-        $error_message = ''
189
-    ) {
190
-        //setup $fields list.
191
-        $fields = array();
192
-        /** @var EE_Datetime_Field $model_field */
193
-        foreach ($model_fields_affected as $model_field) {
194
-            if (! $model_field instanceof EE_Datetime_Field) {
195
-                continue;
196
-            }
197
-            $fields[] = $model_field->get_name();
198
-        }
199
-        //setup the message for the changelog entry.
200
-        $message = $error_message
201
-            ? sprintf(
202
-                esc_html__(
203
-                    'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s',
204
-                    'event_espresso'
205
-                ),
206
-                $table->get_table_name(),
207
-                $model->get_this_model_name(),
208
-                $offset,
209
-                implode(',', $fields),
210
-                $error_message
211
-            )
212
-            : sprintf(
213
-                esc_html__(
214
-                    'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s',
215
-                    'event_espresso'
216
-                ),
217
-                $table->get_table_name(),
218
-                $model->get_this_model_name(),
219
-                $offset,
220
-                implode(',', $fields)
221
-            );
222
-        //write to the log
223
-        $changelog = EE_Change_Log::new_instance(array(
224
-            'LOG_type' => $error_message
225
-                ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE
226
-                : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE,
227
-            'LOG_message' => $message
228
-        ));
229
-        $changelog->save();
230
-    }
231
-
232
-
233
-    /**
234
-     * Returns an array of models that have datetime fields.
235
-     * This array is added to a short lived transient cache to keep having to build this list to a minimum.
236
-     * @return array  an array of model class names.
237
-     */
238
-    private function getModelsWithDatetimeFields()
239
-    {
240
-        $this->getModelsToProcess();
241
-        if (! empty($this->models_with_datetime_fields)) {
242
-            return $this->models_with_datetime_fields;
243
-        }
244
-
245
-        $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models;
246
-        foreach ($all_non_abstract_models as $non_abstract_model) {
247
-            //get model instance
248
-            /** @var EEM_Base $non_abstract_model */
249
-            $non_abstract_model = $non_abstract_model::instance();
250
-            if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) {
251
-                $this->models_with_datetime_fields[] = get_class($non_abstract_model);
252
-            }
253
-        }
254
-        $this->setModelsToProcess($this->models_with_datetime_fields);
255
-        return $this->models_with_datetime_fields;
256
-    }
257
-
258
-
259
-    /**
260
-     * This simply records the models that have been processed with our tracking option.
261
-     * @param array $models_to_set  array of model class names.
262
-     */
263
-    private function setModelsToProcess($models_to_set)
264
-    {
265
-        update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set);
266
-    }
267
-
268
-
269
-    /**
270
-     * Used to keep track of how many models have been processed for the batch
271
-     * @param $count
272
-     */
273
-    private function updateCountOfModelsProcessed($count = 1)
274
-    {
275
-        $count = $this->getCountOfModelsProcessed() + (int) $count;
276
-        update_option(self::COUNT_OF_MODELS_PROCESSED, $count);
277
-    }
278
-
279
-
280
-    /**
281
-     * Retrieve the tracked number of models processed between requests.
282
-     * @return int
283
-     */
284
-    private function getCountOfModelsProcessed()
285
-    {
286
-        return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0);
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns the models that are left to process.
292
-     * @return array  an array of model class names.
293
-     */
294
-    private function getModelsToProcess()
295
-    {
296
-        if (empty($this->models_with_datetime_fields)) {
297
-            $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array());
298
-        }
299
-        return $this->models_with_datetime_fields;
300
-    }
301
-
302
-
303
-    /**
304
-     * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns.
305
-     * @param float $offset
306
-     */
307
-    public static function updateOffset($offset)
308
-    {
309
-        update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset);
310
-    }
311
-
312
-
313
-    /**
314
-     * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns.
315
-     *
316
-     * @return float
317
-     */
318
-    public static function getOffset()
319
-    {
320
-        return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0);
321
-    }
21
+	/**
22
+	 * Key for the option used to track which models have been processed when doing the batches.
23
+	 */
24
+	const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix';
25
+
26
+
27
+	const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed';
28
+
29
+	/**
30
+	 * Key for the option used to track what the current offset is that will be applied when this tool is executed.
31
+	 */
32
+	const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply';
33
+
34
+
35
+	/**
36
+	 * String labelling the datetime offset fix type for change-log entries.
37
+	 */
38
+	const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix';
39
+
40
+
41
+	/**
42
+	 * String labelling a datetime offset fix error for change-log entries.
43
+	 */
44
+	const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error';
45
+
46
+	/**
47
+	 * @var EEM_Base[]
48
+	 */
49
+	protected $models_with_datetime_fields = array();
50
+
51
+
52
+	/**
53
+	 * Performs any necessary setup for starting the job. This is also a good
54
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
55
+	 * when continue_job will be called
56
+	 *
57
+	 * @param JobParameters $job_parameters
58
+	 * @throws BatchRequestException
59
+	 * @return JobStepResponse
60
+	 */
61
+	public function create_job(JobParameters $job_parameters)
62
+	{
63
+		$models_with_datetime_fields = $this->getModelsWithDatetimeFields();
64
+		//we'll be doing each model as a batch.
65
+		$job_parameters->set_job_size(count($models_with_datetime_fields));
66
+		return new JobStepResponse(
67
+			$job_parameters,
68
+			esc_html__('Starting Datetime Offset Fix', 'event_espresso')
69
+		);
70
+	}
71
+
72
+	/**
73
+	 * Performs another step of the job
74
+	 *
75
+	 * @param JobParameters $job_parameters
76
+	 * @param int           $batch_size
77
+	 * @return JobStepResponse
78
+	 * @throws \EE_Error
79
+	 */
80
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
81
+	{
82
+		$models_to_process = $this->getModelsWithDatetimeFields();
83
+		//let's pop off the a model and do the query to apply the offset.
84
+		$model_to_process = array_pop($models_to_process);
85
+		//update our record
86
+		$this->setModelsToProcess($models_to_process);
87
+		$this->processModel($model_to_process);
88
+		$this->updateCountOfModelsProcessed();
89
+		$job_parameters->set_units_processed($this->getCountOfModelsProcessed());
90
+		if (count($models_to_process) > 0) {
91
+			$job_parameters->set_status(JobParameters::status_continue);
92
+		} else {
93
+			$job_parameters->set_status(JobParameters::status_complete);
94
+		}
95
+		return new JobStepResponse(
96
+			$job_parameters,
97
+			sprintf(
98
+				esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'),
99
+				$model_to_process
100
+			)
101
+		);
102
+	}
103
+
104
+	/**
105
+	 * Performs any clean-up logic when we know the job is completed
106
+	 *
107
+	 * @param JobParameters $job_parameters
108
+	 * @return JobStepResponse
109
+	 * @throws BatchRequestException
110
+	 */
111
+	public function cleanup_job(JobParameters $job_parameters)
112
+	{
113
+		//delete important saved options.
114
+		delete_option(self::MODELS_TO_PROCESS_OPTION_KEY);
115
+		delete_option(self::COUNT_OF_MODELS_PROCESSED);
116
+		return new JobStepResponse($job_parameters, esc_html__(
117
+			'Offset has been applied to all affected fields.',
118
+			'event_espresso'
119
+		));
120
+	}
121
+
122
+
123
+	/**
124
+	 * Contains the logic for processing a model and applying the datetime offset to affected fields on that model.
125
+	 * @param string $model_class_name
126
+	 * @throws \EE_Error
127
+	 */
128
+	protected function processModel($model_class_name)
129
+	{
130
+		global $wpdb;
131
+		/** @var EEM_Base $model */
132
+		$model = $model_class_name::instance();
133
+		$original_offset = self::getOffset();
134
+		$sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB';
135
+		$offset = abs($original_offset) * 60;
136
+		//since some affected models might have two tables, we have to get our tables and set up a query for each table.
137
+		foreach ($model->get_tables() as $table) {
138
+			$query = 'UPDATE ' . $table->get_table_name();
139
+			$fields_affected = array();
140
+			$inner_query = array();
141
+			foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
142
+				if ($model_field instanceof EE_Datetime_Field) {
143
+					$inner_query[] = $model_field->get_table_column() . ' = '
144
+									 . $sql_date_function . '('
145
+									 . $model_field->get_table_column()
146
+									 . ", INTERVAL $offset MINUTE)";
147
+					$fields_affected[] = $model_field;
148
+				}
149
+			}
150
+			if (! $fields_affected) {
151
+				continue;
152
+			}
153
+			//k convert innerquery to string
154
+			$query .= ' SET ' . implode(',', $inner_query);
155
+			//execute query
156
+			$result = $wpdb->query($query);
157
+			//record log
158
+			if ($result !== false) {
159
+				$this->recordChangeLog($model, $original_offset, $table, $fields_affected);
160
+			} else {
161
+				//record error.
162
+				$error_message = $wpdb->last_error;
163
+				//handle the edgecases where last_error might be empty.
164
+				if (! $error_message) {
165
+					$error_message = esc_html__('Unknown mysql error occured.', 'event_espresso');
166
+				}
167
+				$this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message);
168
+			}
169
+		}
170
+	}
171
+
172
+
173
+	/**
174
+	 * Records a changelog entry using the given information.
175
+	 *
176
+	 * @param EEM_Base              $model
177
+	 * @param float                 $offset
178
+	 * @param EE_Table_Base         $table
179
+	 * @param EE_Model_Field_Base[] $model_fields_affected
180
+	 * @param string                $error_message   If present then there was an error so let's record that instead.
181
+	 * @throws \EE_Error
182
+	 */
183
+	private function recordChangeLog(
184
+		EEM_Base $model,
185
+		$offset,
186
+		EE_Table_Base $table,
187
+		$model_fields_affected,
188
+		$error_message = ''
189
+	) {
190
+		//setup $fields list.
191
+		$fields = array();
192
+		/** @var EE_Datetime_Field $model_field */
193
+		foreach ($model_fields_affected as $model_field) {
194
+			if (! $model_field instanceof EE_Datetime_Field) {
195
+				continue;
196
+			}
197
+			$fields[] = $model_field->get_name();
198
+		}
199
+		//setup the message for the changelog entry.
200
+		$message = $error_message
201
+			? sprintf(
202
+				esc_html__(
203
+					'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s',
204
+					'event_espresso'
205
+				),
206
+				$table->get_table_name(),
207
+				$model->get_this_model_name(),
208
+				$offset,
209
+				implode(',', $fields),
210
+				$error_message
211
+			)
212
+			: sprintf(
213
+				esc_html__(
214
+					'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s',
215
+					'event_espresso'
216
+				),
217
+				$table->get_table_name(),
218
+				$model->get_this_model_name(),
219
+				$offset,
220
+				implode(',', $fields)
221
+			);
222
+		//write to the log
223
+		$changelog = EE_Change_Log::new_instance(array(
224
+			'LOG_type' => $error_message
225
+				? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE
226
+				: self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE,
227
+			'LOG_message' => $message
228
+		));
229
+		$changelog->save();
230
+	}
231
+
232
+
233
+	/**
234
+	 * Returns an array of models that have datetime fields.
235
+	 * This array is added to a short lived transient cache to keep having to build this list to a minimum.
236
+	 * @return array  an array of model class names.
237
+	 */
238
+	private function getModelsWithDatetimeFields()
239
+	{
240
+		$this->getModelsToProcess();
241
+		if (! empty($this->models_with_datetime_fields)) {
242
+			return $this->models_with_datetime_fields;
243
+		}
244
+
245
+		$all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models;
246
+		foreach ($all_non_abstract_models as $non_abstract_model) {
247
+			//get model instance
248
+			/** @var EEM_Base $non_abstract_model */
249
+			$non_abstract_model = $non_abstract_model::instance();
250
+			if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) {
251
+				$this->models_with_datetime_fields[] = get_class($non_abstract_model);
252
+			}
253
+		}
254
+		$this->setModelsToProcess($this->models_with_datetime_fields);
255
+		return $this->models_with_datetime_fields;
256
+	}
257
+
258
+
259
+	/**
260
+	 * This simply records the models that have been processed with our tracking option.
261
+	 * @param array $models_to_set  array of model class names.
262
+	 */
263
+	private function setModelsToProcess($models_to_set)
264
+	{
265
+		update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set);
266
+	}
267
+
268
+
269
+	/**
270
+	 * Used to keep track of how many models have been processed for the batch
271
+	 * @param $count
272
+	 */
273
+	private function updateCountOfModelsProcessed($count = 1)
274
+	{
275
+		$count = $this->getCountOfModelsProcessed() + (int) $count;
276
+		update_option(self::COUNT_OF_MODELS_PROCESSED, $count);
277
+	}
278
+
279
+
280
+	/**
281
+	 * Retrieve the tracked number of models processed between requests.
282
+	 * @return int
283
+	 */
284
+	private function getCountOfModelsProcessed()
285
+	{
286
+		return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0);
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns the models that are left to process.
292
+	 * @return array  an array of model class names.
293
+	 */
294
+	private function getModelsToProcess()
295
+	{
296
+		if (empty($this->models_with_datetime_fields)) {
297
+			$this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array());
298
+		}
299
+		return $this->models_with_datetime_fields;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns.
305
+	 * @param float $offset
306
+	 */
307
+	public static function updateOffset($offset)
308
+	{
309
+		update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset);
310
+	}
311
+
312
+
313
+	/**
314
+	 * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns.
315
+	 *
316
+	 * @return float
317
+	 */
318
+	public static function getOffset()
319
+	{
320
+		return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0);
321
+	}
322 322
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -135,23 +135,23 @@  discard block
 block discarded – undo
135 135
         $offset = abs($original_offset) * 60;
136 136
         //since some affected models might have two tables, we have to get our tables and set up a query for each table.
137 137
         foreach ($model->get_tables() as $table) {
138
-            $query = 'UPDATE ' . $table->get_table_name();
138
+            $query = 'UPDATE '.$table->get_table_name();
139 139
             $fields_affected = array();
140 140
             $inner_query = array();
141 141
             foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
142 142
                 if ($model_field instanceof EE_Datetime_Field) {
143
-                    $inner_query[] = $model_field->get_table_column() . ' = '
144
-                                     . $sql_date_function . '('
143
+                    $inner_query[] = $model_field->get_table_column().' = '
144
+                                     . $sql_date_function.'('
145 145
                                      . $model_field->get_table_column()
146 146
                                      . ", INTERVAL $offset MINUTE)";
147 147
                     $fields_affected[] = $model_field;
148 148
                 }
149 149
             }
150
-            if (! $fields_affected) {
150
+            if ( ! $fields_affected) {
151 151
                 continue;
152 152
             }
153 153
             //k convert innerquery to string
154
-            $query .= ' SET ' . implode(',', $inner_query);
154
+            $query .= ' SET '.implode(',', $inner_query);
155 155
             //execute query
156 156
             $result = $wpdb->query($query);
157 157
             //record log
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
                 //record error.
162 162
                 $error_message = $wpdb->last_error;
163 163
                 //handle the edgecases where last_error might be empty.
164
-                if (! $error_message) {
164
+                if ( ! $error_message) {
165 165
                     $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso');
166 166
                 }
167 167
                 $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         $fields = array();
192 192
         /** @var EE_Datetime_Field $model_field */
193 193
         foreach ($model_fields_affected as $model_field) {
194
-            if (! $model_field instanceof EE_Datetime_Field) {
194
+            if ( ! $model_field instanceof EE_Datetime_Field) {
195 195
                 continue;
196 196
             }
197 197
             $fields[] = $model_field->get_name();
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     private function getModelsWithDatetimeFields()
239 239
     {
240 240
         $this->getModelsToProcess();
241
-        if (! empty($this->models_with_datetime_fields)) {
241
+        if ( ! empty($this->models_with_datetime_fields)) {
242 242
             return $this->models_with_datetime_fields;
243 243
         }
244 244
 
Please login to merge, or discard this patch.
core/helpers/EEH_URL.helper.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,6 @@
 block discarded – undo
62 62
      * Checking via GET because HEAD requests are blocked on some server configurations.
63 63
      *
64 64
      * @param string  $url
65
-     * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly
66 65
      * @return boolean
67 66
      */
68 67
     public static function remote_file_exists($url, $args = array())
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -14,234 +14,234 @@  discard block
 block discarded – undo
14 14
 class EEH_URL
15 15
 {
16 16
 
17
-    /**
18
-     * _add_query_arg
19
-     * adds nonce to array of arguments then calls WP add_query_arg function
20
-     *
21
-     * @access public
22
-     * @param array  $args
23
-     * @param string $url
24
-     * @param bool   $exclude_nonce If true then the nonce will be excluded from the generated url.
25
-     * @return string
26
-     */
27
-    public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
28
-    {
29
-        if (empty($url)) {
30
-            $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.',
31
-                'event_espresso');
32
-            $dev_msg  = $user_msg . "\n" . sprintf(
33
-                    __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.',
34
-                        'event_espresso'),
35
-                    __CLASS__
36
-                );
37
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
38
-        }
39
-        // check that an action exists and add nonce
40
-        if (! $exclude_nonce) {
41
-            if (isset($args['action']) && ! empty($args['action'])) {
42
-                $args = array_merge($args,
43
-                    array($args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')));
44
-            } else {
45
-                $args = array_merge($args,
46
-                    array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce')));
47
-            }
48
-        }
49
-
50
-        //finally, let's always add a return address (if present) :)
51
-        $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return'])
52
-            ? array_merge($args, array('return' => $_REQUEST['action']))
53
-            : $args;
54
-
55
-        return add_query_arg($args, $url);
56
-
57
-    }
58
-
59
-
60
-    /**
61
-     * Returns whether not the remote file exists.
62
-     * Checking via GET because HEAD requests are blocked on some server configurations.
63
-     *
64
-     * @param string  $url
65
-     * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly
66
-     * @return boolean
67
-     */
68
-    public static function remote_file_exists($url, $args = array())
69
-    {
70
-        $results = wp_remote_request($url, array_merge(array(
71
-            'method'      => 'GET',
72
-            'redirection' => 1,
73
-        ), $args));
74
-        if (! $results instanceof WP_Error &&
75
-            isset($results['response']) &&
76
-            isset($results['response']['code']) &&
77
-            $results['response']['code'] == '200') {
78
-            return true;
79
-        } else {
80
-            return false;
81
-        }
82
-    }
83
-
84
-
85
-    /**
86
-     * refactor_url
87
-     * primarily used for removing the query string from a URL
88
-     *
89
-     * @param string $url
90
-     * @param bool   $remove_query  - TRUE (default) will strip off any URL params, ie: ?this=1&that=2
91
-     * @param bool   $base_url_only - TRUE will only return the scheme and host with no other parameters
92
-     * @return string
93
-     */
94
-    public static function refactor_url($url = '', $remove_query = true, $base_url_only = false)
95
-    {
96
-        // break apart incoming URL
97
-        $url_bits = parse_url($url);
98
-        // HTTP or HTTPS ?
99
-        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
100
-        // domain
101
-        $host = isset($url_bits['host']) ? $url_bits['host'] : '';
102
-        // if only the base URL is requested, then return that now
103
-        if ($base_url_only) {
104
-            return $scheme . $host;
105
-        }
106
-        $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
107
-        $user = isset($url_bits['user']) ? $url_bits['user'] : '';
108
-        $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
109
-        $pass = ($user || $pass) ? $pass . '@' : '';
110
-        $path = isset($url_bits['path']) ? $url_bits['path'] : '';
111
-        // if the query string is not required, then return what we have so far
112
-        if ($remove_query) {
113
-            return $scheme . $user . $pass . $host . $port . $path;
114
-        }
115
-        $query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
116
-        $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
117
-        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
118
-    }
119
-
120
-
121
-    /**
122
-     * get_query_string
123
-     * returns just the query string from a URL, formatted by default into an array of key value pairs
124
-     *
125
-     * @param string $url
126
-     * @param bool   $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will
127
-     *                         simply return the query string
128
-     * @return string|array
129
-     */
130
-    public static function get_query_string($url = '', $as_array = true)
131
-    {
132
-        // decode, then break apart incoming URL
133
-        $url_bits = parse_url(html_entity_decode($url));
134
-        // grab query string from URL
135
-        $query = isset($url_bits['query']) ? $url_bits['query'] : '';
136
-        // if we don't want the query string formatted into an array of key => value pairs, then just return it as is
137
-        if (! $as_array) {
138
-            return $query;
139
-        }
140
-        // if no query string exists then just return an empty array now
141
-        if (empty($query)) {
142
-            return array();
143
-        }
144
-        // empty array to hold results
145
-        $query_params = array();
146
-        // now break apart the query string into separate params
147
-        $query = explode('&', $query);
148
-        // loop thru our query params
149
-        foreach ($query as $query_args) {
150
-            // break apart the key value pairs
151
-            $query_args = explode('=', $query_args);
152
-            // and add to our results array
153
-            $query_params[$query_args[0]] = $query_args[1];
154
-        }
155
-        return $query_params;
156
-    }
157
-
158
-
159
-    /**
160
-     * prevent_prefetching
161
-     *
162
-     * @return void
163
-     */
164
-    public static function prevent_prefetching()
165
-    {
166
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
167
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
168
-    }
169
-
170
-
171
-    /**
172
-     * This generates a unique site-specific string.
173
-     * An example usage for this string would be to save as a unique identifier for a record in the db for usage in
174
-     * urls.
175
-     *
176
-     * @param   string $prefix Use this to prefix the string with something.
177
-     * @return string
178
-     */
179
-    public static function generate_unique_token($prefix = '')
180
-    {
181
-        $token = md5(uniqid() . mt_rand());
182
-        return $prefix ? $prefix . '_' . $token : $token;
183
-    }
184
-
185
-
186
-    /**
187
-     * add_nocache_headers
188
-     *
189
-     * @return void
190
-     */
191
-    public static function add_nocache_headers()
192
-    {
193
-        // add no cache headers
17
+	/**
18
+	 * _add_query_arg
19
+	 * adds nonce to array of arguments then calls WP add_query_arg function
20
+	 *
21
+	 * @access public
22
+	 * @param array  $args
23
+	 * @param string $url
24
+	 * @param bool   $exclude_nonce If true then the nonce will be excluded from the generated url.
25
+	 * @return string
26
+	 */
27
+	public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
28
+	{
29
+		if (empty($url)) {
30
+			$user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.',
31
+				'event_espresso');
32
+			$dev_msg  = $user_msg . "\n" . sprintf(
33
+					__('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.',
34
+						'event_espresso'),
35
+					__CLASS__
36
+				);
37
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
38
+		}
39
+		// check that an action exists and add nonce
40
+		if (! $exclude_nonce) {
41
+			if (isset($args['action']) && ! empty($args['action'])) {
42
+				$args = array_merge($args,
43
+					array($args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')));
44
+			} else {
45
+				$args = array_merge($args,
46
+					array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce')));
47
+			}
48
+		}
49
+
50
+		//finally, let's always add a return address (if present) :)
51
+		$args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return'])
52
+			? array_merge($args, array('return' => $_REQUEST['action']))
53
+			: $args;
54
+
55
+		return add_query_arg($args, $url);
56
+
57
+	}
58
+
59
+
60
+	/**
61
+	 * Returns whether not the remote file exists.
62
+	 * Checking via GET because HEAD requests are blocked on some server configurations.
63
+	 *
64
+	 * @param string  $url
65
+	 * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly
66
+	 * @return boolean
67
+	 */
68
+	public static function remote_file_exists($url, $args = array())
69
+	{
70
+		$results = wp_remote_request($url, array_merge(array(
71
+			'method'      => 'GET',
72
+			'redirection' => 1,
73
+		), $args));
74
+		if (! $results instanceof WP_Error &&
75
+			isset($results['response']) &&
76
+			isset($results['response']['code']) &&
77
+			$results['response']['code'] == '200') {
78
+			return true;
79
+		} else {
80
+			return false;
81
+		}
82
+	}
83
+
84
+
85
+	/**
86
+	 * refactor_url
87
+	 * primarily used for removing the query string from a URL
88
+	 *
89
+	 * @param string $url
90
+	 * @param bool   $remove_query  - TRUE (default) will strip off any URL params, ie: ?this=1&that=2
91
+	 * @param bool   $base_url_only - TRUE will only return the scheme and host with no other parameters
92
+	 * @return string
93
+	 */
94
+	public static function refactor_url($url = '', $remove_query = true, $base_url_only = false)
95
+	{
96
+		// break apart incoming URL
97
+		$url_bits = parse_url($url);
98
+		// HTTP or HTTPS ?
99
+		$scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
100
+		// domain
101
+		$host = isset($url_bits['host']) ? $url_bits['host'] : '';
102
+		// if only the base URL is requested, then return that now
103
+		if ($base_url_only) {
104
+			return $scheme . $host;
105
+		}
106
+		$port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
107
+		$user = isset($url_bits['user']) ? $url_bits['user'] : '';
108
+		$pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
109
+		$pass = ($user || $pass) ? $pass . '@' : '';
110
+		$path = isset($url_bits['path']) ? $url_bits['path'] : '';
111
+		// if the query string is not required, then return what we have so far
112
+		if ($remove_query) {
113
+			return $scheme . $user . $pass . $host . $port . $path;
114
+		}
115
+		$query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
116
+		$fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
117
+		return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
118
+	}
119
+
120
+
121
+	/**
122
+	 * get_query_string
123
+	 * returns just the query string from a URL, formatted by default into an array of key value pairs
124
+	 *
125
+	 * @param string $url
126
+	 * @param bool   $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will
127
+	 *                         simply return the query string
128
+	 * @return string|array
129
+	 */
130
+	public static function get_query_string($url = '', $as_array = true)
131
+	{
132
+		// decode, then break apart incoming URL
133
+		$url_bits = parse_url(html_entity_decode($url));
134
+		// grab query string from URL
135
+		$query = isset($url_bits['query']) ? $url_bits['query'] : '';
136
+		// if we don't want the query string formatted into an array of key => value pairs, then just return it as is
137
+		if (! $as_array) {
138
+			return $query;
139
+		}
140
+		// if no query string exists then just return an empty array now
141
+		if (empty($query)) {
142
+			return array();
143
+		}
144
+		// empty array to hold results
145
+		$query_params = array();
146
+		// now break apart the query string into separate params
147
+		$query = explode('&', $query);
148
+		// loop thru our query params
149
+		foreach ($query as $query_args) {
150
+			// break apart the key value pairs
151
+			$query_args = explode('=', $query_args);
152
+			// and add to our results array
153
+			$query_params[$query_args[0]] = $query_args[1];
154
+		}
155
+		return $query_params;
156
+	}
157
+
158
+
159
+	/**
160
+	 * prevent_prefetching
161
+	 *
162
+	 * @return void
163
+	 */
164
+	public static function prevent_prefetching()
165
+	{
166
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
167
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
168
+	}
169
+
170
+
171
+	/**
172
+	 * This generates a unique site-specific string.
173
+	 * An example usage for this string would be to save as a unique identifier for a record in the db for usage in
174
+	 * urls.
175
+	 *
176
+	 * @param   string $prefix Use this to prefix the string with something.
177
+	 * @return string
178
+	 */
179
+	public static function generate_unique_token($prefix = '')
180
+	{
181
+		$token = md5(uniqid() . mt_rand());
182
+		return $prefix ? $prefix . '_' . $token : $token;
183
+	}
184
+
185
+
186
+	/**
187
+	 * add_nocache_headers
188
+	 *
189
+	 * @return void
190
+	 */
191
+	public static function add_nocache_headers()
192
+	{
193
+		// add no cache headers
194 194
 //		add_action( 'wp_head' , array( 'EED_Single_Page_Checkout', 'nocache_headers' ), 10 );
195
-        // plus a little extra for nginx
195
+		// plus a little extra for nginx
196 196
 //		add_filter( 'nocache_headers' , array( 'EED_Single_Page_Checkout', 'nocache_headers_nginx' ), 10, 1 );
197
-    }
198
-
199
-
200
-    /**
201
-     * filter_input_server_url
202
-     * uses filter_input() to sanitize one of the INPUT_SERVER URL values
203
-     * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers
204
-     *
205
-     * @param string $server_variable
206
-     * @return string
207
-     */
208
-    public static function filter_input_server_url($server_variable = 'REQUEST_URI')
209
-    {
210
-        $URL              = '';
211
-        $server_variables = array(
212
-            'REQUEST_URI' => 1,
213
-            'HTTP_HOST'   => 1,
214
-            'PHP_SELF'    => 1,
215
-        );
216
-        $server_variable  = strtoupper($server_variable);
217
-        // whitelist INPUT_SERVER var
218
-        if (isset($server_variables[$server_variable])) {
219
-            $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
220
-            if (empty($URL)) {
221
-                // fallback sanitization if the above fails
222
-                $URL = wp_sanitize_redirect($_SERVER[$server_variable]);
223
-            }
224
-        }
225
-        return $URL;
226
-    }
227
-
228
-
229
-    /**
230
-     * Gets the current page's full URL
231
-     *
232
-     * @return string
233
-     */
234
-    public static function current_url()
235
-    {
236
-        if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) {
237
-            $url = is_ssl() ? 'https://' : 'http://';
238
-            $url .= \EEH_URL::filter_input_server_url('HTTP_HOST');
239
-            $url .= \EEH_URL::filter_input_server_url('REQUEST_URI');
240
-        } else {
241
-            $url = 'unknown';
242
-        }
243
-        return $url;
244
-    }
197
+	}
198
+
199
+
200
+	/**
201
+	 * filter_input_server_url
202
+	 * uses filter_input() to sanitize one of the INPUT_SERVER URL values
203
+	 * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers
204
+	 *
205
+	 * @param string $server_variable
206
+	 * @return string
207
+	 */
208
+	public static function filter_input_server_url($server_variable = 'REQUEST_URI')
209
+	{
210
+		$URL              = '';
211
+		$server_variables = array(
212
+			'REQUEST_URI' => 1,
213
+			'HTTP_HOST'   => 1,
214
+			'PHP_SELF'    => 1,
215
+		);
216
+		$server_variable  = strtoupper($server_variable);
217
+		// whitelist INPUT_SERVER var
218
+		if (isset($server_variables[$server_variable])) {
219
+			$URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
220
+			if (empty($URL)) {
221
+				// fallback sanitization if the above fails
222
+				$URL = wp_sanitize_redirect($_SERVER[$server_variable]);
223
+			}
224
+		}
225
+		return $URL;
226
+	}
227
+
228
+
229
+	/**
230
+	 * Gets the current page's full URL
231
+	 *
232
+	 * @return string
233
+	 */
234
+	public static function current_url()
235
+	{
236
+		if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) {
237
+			$url = is_ssl() ? 'https://' : 'http://';
238
+			$url .= \EEH_URL::filter_input_server_url('HTTP_HOST');
239
+			$url .= \EEH_URL::filter_input_server_url('REQUEST_URI');
240
+		} else {
241
+			$url = 'unknown';
242
+		}
243
+		return $url;
244
+	}
245 245
 
246 246
 
247 247
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -29,18 +29,18 @@  discard block
 block discarded – undo
29 29
         if (empty($url)) {
30 30
             $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.',
31 31
                 'event_espresso');
32
-            $dev_msg  = $user_msg . "\n" . sprintf(
32
+            $dev_msg  = $user_msg."\n".sprintf(
33 33
                     __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.',
34 34
                         'event_espresso'),
35 35
                     __CLASS__
36 36
                 );
37
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
37
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
38 38
         }
39 39
         // check that an action exists and add nonce
40
-        if (! $exclude_nonce) {
40
+        if ( ! $exclude_nonce) {
41 41
             if (isset($args['action']) && ! empty($args['action'])) {
42 42
                 $args = array_merge($args,
43
-                    array($args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')));
43
+                    array($args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce')));
44 44
             } else {
45 45
                 $args = array_merge($args,
46 46
                     array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce')));
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             'method'      => 'GET',
72 72
             'redirection' => 1,
73 73
         ), $args));
74
-        if (! $results instanceof WP_Error &&
74
+        if ( ! $results instanceof WP_Error &&
75 75
             isset($results['response']) &&
76 76
             isset($results['response']['code']) &&
77 77
             $results['response']['code'] == '200') {
@@ -96,25 +96,25 @@  discard block
 block discarded – undo
96 96
         // break apart incoming URL
97 97
         $url_bits = parse_url($url);
98 98
         // HTTP or HTTPS ?
99
-        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
99
+        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://';
100 100
         // domain
101 101
         $host = isset($url_bits['host']) ? $url_bits['host'] : '';
102 102
         // if only the base URL is requested, then return that now
103 103
         if ($base_url_only) {
104
-            return $scheme . $host;
104
+            return $scheme.$host;
105 105
         }
106
-        $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
106
+        $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : '';
107 107
         $user = isset($url_bits['user']) ? $url_bits['user'] : '';
108
-        $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
109
-        $pass = ($user || $pass) ? $pass . '@' : '';
108
+        $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : '';
109
+        $pass = ($user || $pass) ? $pass.'@' : '';
110 110
         $path = isset($url_bits['path']) ? $url_bits['path'] : '';
111 111
         // if the query string is not required, then return what we have so far
112 112
         if ($remove_query) {
113
-            return $scheme . $user . $pass . $host . $port . $path;
113
+            return $scheme.$user.$pass.$host.$port.$path;
114 114
         }
115
-        $query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
116
-        $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
117
-        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
115
+        $query    = isset($url_bits['query']) ? '?'.$url_bits['query'] : '';
116
+        $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : '';
117
+        return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
118 118
     }
119 119
 
120 120
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         // grab query string from URL
135 135
         $query = isset($url_bits['query']) ? $url_bits['query'] : '';
136 136
         // if we don't want the query string formatted into an array of key => value pairs, then just return it as is
137
-        if (! $as_array) {
137
+        if ( ! $as_array) {
138 138
             return $query;
139 139
         }
140 140
         // if no query string exists then just return an empty array now
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public static function generate_unique_token($prefix = '')
180 180
     {
181
-        $token = md5(uniqid() . mt_rand());
182
-        return $prefix ? $prefix . '_' . $token : $token;
181
+        $token = md5(uniqid().mt_rand());
182
+        return $prefix ? $prefix.'_'.$token : $token;
183 183
     }
184 184
 
185 185
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             'HTTP_HOST'   => 1,
214 214
             'PHP_SELF'    => 1,
215 215
         );
216
-        $server_variable  = strtoupper($server_variable);
216
+        $server_variable = strtoupper($server_variable);
217 217
         // whitelist INPUT_SERVER var
218 218
         if (isset($server_variables[$server_variable])) {
219 219
             $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,245 +40,245 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.030');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.030');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Psr4AutoloaderInit', EE_CORE . 'EE_Psr4AutoloaderInit.core.php');
262
-        new EE_Psr4AutoloaderInit();
263
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
264
-        new EE_Bootstrap();
265
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Psr4AutoloaderInit', EE_CORE . 'EE_Psr4AutoloaderInit.core.php');
262
+		new EE_Psr4AutoloaderInit();
263
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
264
+		new EE_Bootstrap();
265
+	}
266 266
 }
267 267
 if ( ! function_exists('espresso_deactivate_plugin')) {
268
-    /**
269
-     *    deactivate_plugin
270
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
271
-     *
272
-     * @access public
273
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
274
-     * @return    void
275
-     */
276
-    function espresso_deactivate_plugin($plugin_basename = '')
277
-    {
278
-        if ( ! function_exists('deactivate_plugins')) {
279
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
280
-        }
281
-        unset($_GET['activate'], $_REQUEST['activate']);
282
-        deactivate_plugins($plugin_basename);
283
-    }
268
+	/**
269
+	 *    deactivate_plugin
270
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
271
+	 *
272
+	 * @access public
273
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
274
+	 * @return    void
275
+	 */
276
+	function espresso_deactivate_plugin($plugin_basename = '')
277
+	{
278
+		if ( ! function_exists('deactivate_plugins')) {
279
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
280
+		}
281
+		unset($_GET['activate'], $_REQUEST['activate']);
282
+		deactivate_plugins($plugin_basename);
283
+	}
284 284
 }
285 285
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +761 added lines, -761 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -21,766 +21,766 @@  discard block
 block discarded – undo
21 21
 class EE_Dependency_Map
22 22
 {
23 23
 
24
-    /**
25
-     * This means that the requested class dependency is not present in the dependency map
26
-     */
27
-    const not_registered = 0;
28
-
29
-    /**
30
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
31
-     */
32
-    const load_new_object = 1;
33
-
34
-    /**
35
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
36
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
37
-     */
38
-    const load_from_cache = 2;
39
-
40
-    /**
41
-     * When registering a dependency,
42
-     * this indicates to keep any existing dependencies that already exist,
43
-     * and simply discard any new dependencies declared in the incoming data
44
-     */
45
-    const KEEP_EXISTING_DEPENDENCIES = 0;
46
-
47
-    /**
48
-     * When registering a dependency,
49
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
50
-     */
51
-    const OVERWRITE_DEPENDENCIES = 1;
52
-
53
-
54
-
55
-    /**
56
-     * @type EE_Dependency_Map $_instance
57
-     */
58
-    protected static $_instance;
59
-
60
-    /**
61
-     * @type EE_Request $request
62
-     */
63
-    protected $_request;
64
-
65
-    /**
66
-     * @type EE_Response $response
67
-     */
68
-    protected $_response;
69
-
70
-    /**
71
-     * @type LoaderInterface $loader
72
-     */
73
-    protected $loader;
74
-
75
-    /**
76
-     * @type array $_dependency_map
77
-     */
78
-    protected $_dependency_map = array();
79
-
80
-    /**
81
-     * @type array $_class_loaders
82
-     */
83
-    protected $_class_loaders = array();
84
-
85
-    /**
86
-     * @type array $_aliases
87
-     */
88
-    protected $_aliases = array();
89
-
90
-
91
-
92
-    /**
93
-     * EE_Dependency_Map constructor.
94
-     *
95
-     * @param EE_Request  $request
96
-     * @param EE_Response $response
97
-     */
98
-    protected function __construct(EE_Request $request, EE_Response $response)
99
-    {
100
-        $this->_request = $request;
101
-        $this->_response = $response;
102
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
103
-        do_action('EE_Dependency_Map____construct');
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     * @throws InvalidArgumentException
112
-     */
113
-    public function initialize()
114
-    {
115
-        $this->_register_core_dependencies();
116
-        $this->_register_core_class_loaders();
117
-        $this->_register_core_aliases();
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @singleton method used to instantiate class object
124
-     * @access    public
125
-     * @param EE_Request  $request
126
-     * @param EE_Response $response
127
-     * @return EE_Dependency_Map
128
-     */
129
-    public static function instance(EE_Request $request = null, EE_Response $response = null)
130
-    {
131
-        // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
-            self::$_instance = new EE_Dependency_Map($request, $response);
134
-        }
135
-        return self::$_instance;
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * @param LoaderInterface $loader
142
-     */
143
-    public function setLoader(LoaderInterface $loader)
144
-    {
145
-        $this->loader = $loader;
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @param string $class
152
-     * @param array  $dependencies
153
-     * @param int    $overwrite
154
-     * @return bool
155
-     */
156
-    public static function register_dependencies(
157
-        $class,
158
-        array $dependencies,
159
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
160
-    ) {
161
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * Assigns an array of class names and corresponding load sources (new or cached)
168
-     * to the class specified by the first parameter.
169
-     * IMPORTANT !!!
170
-     * The order of elements in the incoming $dependencies array MUST match
171
-     * the order of the constructor parameters for the class in question.
172
-     * This is especially important when overriding any existing dependencies that are registered.
173
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
174
-     *
175
-     * @param string $class
176
-     * @param array  $dependencies
177
-     * @param int    $overwrite
178
-     * @return bool
179
-     */
180
-    public function registerDependencies(
181
-        $class,
182
-        array $dependencies,
183
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184
-    ) {
185
-        $class = trim($class, '\\');
186
-        $registered = false;
187
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
188
-            self::$_instance->_dependency_map[ $class ] = array();
189
-        }
190
-        // we need to make sure that any aliases used when registering a dependency
191
-        // get resolved to the correct class name
192
-        foreach ((array)$dependencies as $dependency => $load_source) {
193
-            $alias = self::$_instance->get_alias($dependency);
194
-            if (
195
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
196
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
197
-            ) {
198
-                unset($dependencies[$dependency]);
199
-                $dependencies[$alias] = $load_source;
200
-                $registered = true;
201
-            }
202
-        }
203
-        // now add our two lists of dependencies together.
204
-        // using Union (+=) favours the arrays in precedence from left to right,
205
-        // so $dependencies is NOT overwritten because it is listed first
206
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
207
-        // Union is way faster than array_merge() but should be used with caution...
208
-        // especially with numerically indexed arrays
209
-        $dependencies += self::$_instance->_dependency_map[ $class ];
210
-        // now we need to ensure that the resulting dependencies
211
-        // array only has the entries that are required for the class
212
-        // so first count how many dependencies were originally registered for the class
213
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
214
-        // if that count is non-zero (meaning dependencies were already registered)
215
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
216
-            // then truncate the  final array to match that count
217
-            ? array_slice($dependencies, 0, $dependency_count)
218
-            // otherwise just take the incoming array because nothing previously existed
219
-            : $dependencies;
220
-        return $registered;
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * @param string $class_name
227
-     * @param string $loader
228
-     * @return bool
229
-     * @throws DomainException
230
-     */
231
-    public static function register_class_loader($class_name, $loader = 'load_core')
232
-    {
233
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234
-            throw new DomainException(
235
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
236
-            );
237
-        }
238
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
239
-        if (
240
-            ! is_callable($loader)
241
-            && (
242
-                strpos($loader, 'load_') !== 0
243
-                || ! method_exists('EE_Registry', $loader)
244
-            )
245
-        ) {
246
-            throw new DomainException(
247
-                sprintf(
248
-                    esc_html__(
249
-                        '"%1$s" is not a valid loader method on EE_Registry.',
250
-                        'event_espresso'
251
-                    ),
252
-                    $loader
253
-                )
254
-            );
255
-        }
256
-        $class_name = self::$_instance->get_alias($class_name);
257
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
258
-            self::$_instance->_class_loaders[$class_name] = $loader;
259
-            return true;
260
-        }
261
-        return false;
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     * @return array
268
-     */
269
-    public function dependency_map()
270
-    {
271
-        return $this->_dependency_map;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * returns TRUE if dependency map contains a listing for the provided class name
278
-     *
279
-     * @param string $class_name
280
-     * @return boolean
281
-     */
282
-    public function has($class_name = '')
283
-    {
284
-        return isset($this->_dependency_map[$class_name]) ? true : false;
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
291
-     *
292
-     * @param string $class_name
293
-     * @param string $dependency
294
-     * @return bool
295
-     */
296
-    public function has_dependency_for_class($class_name = '', $dependency = '')
297
-    {
298
-        $dependency = $this->get_alias($dependency);
299
-        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
300
-            ? true
301
-            : false;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
308
-     *
309
-     * @param string $class_name
310
-     * @param string $dependency
311
-     * @return int
312
-     */
313
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
314
-    {
315
-        $dependency = $this->get_alias($dependency);
316
-        return $this->has_dependency_for_class($class_name, $dependency)
317
-            ? $this->_dependency_map[$class_name][$dependency]
318
-            : EE_Dependency_Map::not_registered;
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * @param string $class_name
325
-     * @return string | Closure
326
-     */
327
-    public function class_loader($class_name)
328
-    {
329
-        $class_name = $this->get_alias($class_name);
330
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * @return array
337
-     */
338
-    public function class_loaders()
339
-    {
340
-        return $this->_class_loaders;
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * adds an alias for a classname
347
-     *
348
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
349
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
350
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
351
-     */
352
-    public function add_alias($class_name, $alias, $for_class = '')
353
-    {
354
-        if ($for_class !== '') {
355
-            if (! isset($this->_aliases[$for_class])) {
356
-                $this->_aliases[$for_class] = array();
357
-            }
358
-            $this->_aliases[$for_class][$class_name] = $alias;
359
-        }
360
-        $this->_aliases[$class_name] = $alias;
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * returns TRUE if the provided class name has an alias
367
-     *
368
-     * @param string $class_name
369
-     * @param string $for_class
370
-     * @return bool
371
-     */
372
-    public function has_alias($class_name = '', $for_class = '')
373
-    {
374
-        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
375
-               || (
376
-                   isset($this->_aliases[$class_name])
377
-                   && ! is_array($this->_aliases[$class_name])
378
-               );
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * returns alias for class name if one exists, otherwise returns the original classname
385
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
386
-     *  for example:
387
-     *      if the following two entries were added to the _aliases array:
388
-     *          array(
389
-     *              'interface_alias'           => 'some\namespace\interface'
390
-     *              'some\namespace\interface'  => 'some\namespace\classname'
391
-     *          )
392
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
393
-     *      to load an instance of 'some\namespace\classname'
394
-     *
395
-     * @param string $class_name
396
-     * @param string $for_class
397
-     * @return string
398
-     */
399
-    public function get_alias($class_name = '', $for_class = '')
400
-    {
401
-        if (! $this->has_alias($class_name, $for_class)) {
402
-            return $class_name;
403
-        }
404
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
405
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
406
-        }
407
-        return $this->get_alias($this->_aliases[$class_name]);
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
414
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
415
-     * This is done by using the following class constants:
416
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
417
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
418
-     */
419
-    protected function _register_core_dependencies()
420
-    {
421
-        $this->_dependency_map = array(
422
-            'EE_Request_Handler'                                                                                          => array(
423
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
424
-            ),
425
-            'EE_System'                                                                                                   => array(
426
-                'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
427
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
428
-                'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
429
-            ),
430
-            'EE_Session'                                                                                                  => array(
431
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
432
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
433
-            ),
434
-            'EE_Cart'                                                                                                     => array(
435
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
436
-            ),
437
-            'EE_Front_Controller'                                                                                         => array(
438
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
439
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
440
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
441
-            ),
442
-            'EE_Messenger_Collection_Loader'                                                                              => array(
443
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
444
-            ),
445
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
446
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
447
-            ),
448
-            'EE_Message_Resource_Manager'                                                                                 => array(
449
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
450
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
451
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
452
-            ),
453
-            'EE_Message_Factory'                                                                                          => array(
454
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
455
-            ),
456
-            'EE_messages'                                                                                                 => array(
457
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
458
-            ),
459
-            'EE_Messages_Generator'                                                                                       => array(
460
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
461
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
462
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
463
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
464
-            ),
465
-            'EE_Messages_Processor'                                                                                       => array(
466
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
467
-            ),
468
-            'EE_Messages_Queue'                                                                                           => array(
469
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
470
-            ),
471
-            'EE_Messages_Template_Defaults'                                                                               => array(
472
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
473
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
474
-            ),
475
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
476
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
478
-            ),
479
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
480
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
481
-            ),
482
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
483
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
484
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
485
-            ),
486
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
487
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
488
-            ),
489
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
490
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
491
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
492
-            ),
493
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
494
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
495
-            ),
496
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
497
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
498
-            ),
499
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
500
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
501
-            ),
502
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
503
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
504
-            ),
505
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
506
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
507
-            ),
508
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
509
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
510
-            ),
511
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
512
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
513
-            ),
514
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
515
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
516
-            ),
517
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
518
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
519
-            ),
520
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
521
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
522
-            ),
523
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
524
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
525
-            ),
526
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
527
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
528
-            ),
529
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
530
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
531
-            ),
532
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
533
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
534
-            ),
535
-            'EE_Data_Migration_Class_Base'                                                                                => array(
536
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
537
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
540
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
541
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
542
-            ),
543
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
544
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
545
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
546
-            ),
547
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
548
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
549
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
552
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
554
-            ),
555
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
556
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
557
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
558
-            ),
559
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
560
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
561
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
564
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
-            ),
567
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
568
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
-            ),
571
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
572
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
576
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
577
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
578
-            ),
579
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
580
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
581
-            ),
582
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
583
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
584
-            ),
585
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
586
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
587
-            ),
588
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
589
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
590
-            ),
591
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
592
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
593
-            ),
594
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
595
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
596
-            ),
597
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
598
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
599
-            ),
600
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
601
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
602
-            ),
603
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'            => array(
604
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
605
-            ),
606
-            'EventEspresso\core\services\activation\ActivationsAndUpgradesManager' => array(
607
-                'EventEspresso\core\services\activation\ActivationHandler'   => EE_Dependency_Map::load_from_cache,
608
-                'EventEspresso\core\services\activation\RequestTypeDetector' => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EventEspresso\core\services\activation\ActivationHandler'             => array(
611
-                'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
612
-            ),
613
-            'EventEspresso\core\services\activation\InitializeCore'                => array(
614
-                null,
615
-                'EE_Capabilities'           => EE_Dependency_Map::load_from_cache,
616
-                'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
617
-                'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
618
-            ),
619
-            'EventEspresso\core\services\activation\InitializeAddon' => array(
620
-                null,
621
-                'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
622
-                'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
623
-                'EE_Registry'               => EE_Dependency_Map::load_from_cache,
624
-            ),
625
-            'EE_Module_Request_Router' => array(
626
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
627
-            ),
628
-        );
629
-    }
630
-
631
-
632
-
633
-    /**
634
-     * Registers how core classes are loaded.
635
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
636
-     *        'EE_Request_Handler' => 'load_core'
637
-     *        'EE_Messages_Queue'  => 'load_lib'
638
-     *        'EEH_Debug_Tools'    => 'load_helper'
639
-     * or, if greater control is required, by providing a custom closure. For example:
640
-     *        'Some_Class' => function () {
641
-     *            return new Some_Class();
642
-     *        },
643
-     * This is required for instantiating dependencies
644
-     * where an interface has been type hinted in a class constructor. For example:
645
-     *        'Required_Interface' => function () {
646
-     *            return new A_Class_That_Implements_Required_Interface();
647
-     *        },
648
-     */
649
-    protected function _register_core_class_loaders()
650
-    {
651
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
652
-        //be used in a closure.
653
-        $request = &$this->_request;
654
-        $response = &$this->_response;
655
-        $loader = &$this->loader;
656
-        $this->_class_loaders = array(
657
-            //load_core
658
-            'EE_Capabilities'                      => 'load_core',
659
-            'EE_Encryption'                        => 'load_core',
660
-            'EE_Front_Controller'                  => 'load_core',
661
-            'EE_Module_Request_Router'             => 'load_core',
662
-            'EE_Registry'                          => 'load_core',
663
-            'EE_Request'                           => function () use (&$request) {
664
-                return $request;
665
-            },
666
-            'EE_Response'                          => function () use (&$response) {
667
-                return $response;
668
-            },
669
-            'EE_Request_Handler'                   => 'load_core',
670
-            'EE_Session'                           => 'load_core',
671
-            'EE_System'                            => 'load_core',
672
-            'EE_Maintenance_Mode'                  => 'load_core',
673
-            'EE_Register_CPTs'                     => 'load_core',
674
-            'EE_Admin'                             => 'load_core',
675
-            'EE_Data_Migration_Manager'            => 'load_core',
676
-            //load_lib
677
-            'EE_Message_Resource_Manager'          => 'load_lib',
678
-            'EE_Message_Type_Collection'           => 'load_lib',
679
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
680
-            'EE_Messenger_Collection'              => 'load_lib',
681
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
682
-            'EE_Messages_Processor'                => 'load_lib',
683
-            'EE_Message_Repository'                => 'load_lib',
684
-            'EE_Messages_Queue'                    => 'load_lib',
685
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
686
-            'EE_Message_Template_Group_Collection' => 'load_lib',
687
-            'EE_Messages_Generator'                => function () {
688
-                return EE_Registry::instance()->load_lib(
689
-                    'Messages_Generator',
690
-                    array(),
691
-                    false,
692
-                    false
693
-                );
694
-            },
695
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
696
-                return EE_Registry::instance()->load_lib(
697
-                    'Messages_Template_Defaults',
698
-                    $arguments,
699
-                    false,
700
-                    false
701
-                );
702
-            },
703
-            //load_model
704
-            'EEM_Attendee'                         => 'load_model',
705
-            'EEM_Message_Template_Group'           => 'load_model',
706
-            'EEM_Message_Template'                 => 'load_model',
707
-            //load_helper
708
-            'EEH_Parse_Shortcodes'                 => function () {
709
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
710
-                    return new EEH_Parse_Shortcodes();
711
-                }
712
-                return null;
713
-            },
714
-            'EE_Template_Config'                   => function () {
715
-                return EE_Config::instance()->template_settings;
716
-            },
717
-            'EE_Currency_Config'                   => function () {
718
-                return EE_Config::instance()->currency;
719
-            },
720
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
721
-                return $loader;
722
-            },
723
-        );
724
-    }
725
-
726
-
727
-
728
-    /**
729
-     * can be used for supplying alternate names for classes,
730
-     * or for connecting interface names to instantiable classes
731
-     */
732
-    protected function _register_core_aliases()
733
-    {
734
-        $this->_aliases = array(
735
-            'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
736
-            'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
737
-            'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
738
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
739
-            'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
740
-            'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
741
-            'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
742
-            'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
743
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
744
-            'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
745
-            'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
746
-            'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
747
-            'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
748
-            'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
749
-            'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
750
-            'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
751
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
752
-            'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
753
-            'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
754
-            'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
755
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
756
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
757
-            'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
758
-            'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
759
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
760
-            'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
761
-            'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
762
-            'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
763
-            'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
764
-            'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
765
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
766
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
767
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
768
-            'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
769
-            'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
770
-        );
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
777
-     * request Primarily used by unit tests.
778
-     */
779
-    public function reset()
780
-    {
781
-        $this->_register_core_class_loaders();
782
-        $this->_register_core_dependencies();
783
-    }
24
+	/**
25
+	 * This means that the requested class dependency is not present in the dependency map
26
+	 */
27
+	const not_registered = 0;
28
+
29
+	/**
30
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
31
+	 */
32
+	const load_new_object = 1;
33
+
34
+	/**
35
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
36
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
37
+	 */
38
+	const load_from_cache = 2;
39
+
40
+	/**
41
+	 * When registering a dependency,
42
+	 * this indicates to keep any existing dependencies that already exist,
43
+	 * and simply discard any new dependencies declared in the incoming data
44
+	 */
45
+	const KEEP_EXISTING_DEPENDENCIES = 0;
46
+
47
+	/**
48
+	 * When registering a dependency,
49
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
50
+	 */
51
+	const OVERWRITE_DEPENDENCIES = 1;
52
+
53
+
54
+
55
+	/**
56
+	 * @type EE_Dependency_Map $_instance
57
+	 */
58
+	protected static $_instance;
59
+
60
+	/**
61
+	 * @type EE_Request $request
62
+	 */
63
+	protected $_request;
64
+
65
+	/**
66
+	 * @type EE_Response $response
67
+	 */
68
+	protected $_response;
69
+
70
+	/**
71
+	 * @type LoaderInterface $loader
72
+	 */
73
+	protected $loader;
74
+
75
+	/**
76
+	 * @type array $_dependency_map
77
+	 */
78
+	protected $_dependency_map = array();
79
+
80
+	/**
81
+	 * @type array $_class_loaders
82
+	 */
83
+	protected $_class_loaders = array();
84
+
85
+	/**
86
+	 * @type array $_aliases
87
+	 */
88
+	protected $_aliases = array();
89
+
90
+
91
+
92
+	/**
93
+	 * EE_Dependency_Map constructor.
94
+	 *
95
+	 * @param EE_Request  $request
96
+	 * @param EE_Response $response
97
+	 */
98
+	protected function __construct(EE_Request $request, EE_Response $response)
99
+	{
100
+		$this->_request = $request;
101
+		$this->_response = $response;
102
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
103
+		do_action('EE_Dependency_Map____construct');
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 * @throws InvalidArgumentException
112
+	 */
113
+	public function initialize()
114
+	{
115
+		$this->_register_core_dependencies();
116
+		$this->_register_core_class_loaders();
117
+		$this->_register_core_aliases();
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @singleton method used to instantiate class object
124
+	 * @access    public
125
+	 * @param EE_Request  $request
126
+	 * @param EE_Response $response
127
+	 * @return EE_Dependency_Map
128
+	 */
129
+	public static function instance(EE_Request $request = null, EE_Response $response = null)
130
+	{
131
+		// check if class object is instantiated, and instantiated properly
132
+		if (! self::$_instance instanceof EE_Dependency_Map) {
133
+			self::$_instance = new EE_Dependency_Map($request, $response);
134
+		}
135
+		return self::$_instance;
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * @param LoaderInterface $loader
142
+	 */
143
+	public function setLoader(LoaderInterface $loader)
144
+	{
145
+		$this->loader = $loader;
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @param string $class
152
+	 * @param array  $dependencies
153
+	 * @param int    $overwrite
154
+	 * @return bool
155
+	 */
156
+	public static function register_dependencies(
157
+		$class,
158
+		array $dependencies,
159
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
160
+	) {
161
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * Assigns an array of class names and corresponding load sources (new or cached)
168
+	 * to the class specified by the first parameter.
169
+	 * IMPORTANT !!!
170
+	 * The order of elements in the incoming $dependencies array MUST match
171
+	 * the order of the constructor parameters for the class in question.
172
+	 * This is especially important when overriding any existing dependencies that are registered.
173
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
174
+	 *
175
+	 * @param string $class
176
+	 * @param array  $dependencies
177
+	 * @param int    $overwrite
178
+	 * @return bool
179
+	 */
180
+	public function registerDependencies(
181
+		$class,
182
+		array $dependencies,
183
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184
+	) {
185
+		$class = trim($class, '\\');
186
+		$registered = false;
187
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
188
+			self::$_instance->_dependency_map[ $class ] = array();
189
+		}
190
+		// we need to make sure that any aliases used when registering a dependency
191
+		// get resolved to the correct class name
192
+		foreach ((array)$dependencies as $dependency => $load_source) {
193
+			$alias = self::$_instance->get_alias($dependency);
194
+			if (
195
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
196
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
197
+			) {
198
+				unset($dependencies[$dependency]);
199
+				$dependencies[$alias] = $load_source;
200
+				$registered = true;
201
+			}
202
+		}
203
+		// now add our two lists of dependencies together.
204
+		// using Union (+=) favours the arrays in precedence from left to right,
205
+		// so $dependencies is NOT overwritten because it is listed first
206
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
207
+		// Union is way faster than array_merge() but should be used with caution...
208
+		// especially with numerically indexed arrays
209
+		$dependencies += self::$_instance->_dependency_map[ $class ];
210
+		// now we need to ensure that the resulting dependencies
211
+		// array only has the entries that are required for the class
212
+		// so first count how many dependencies were originally registered for the class
213
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
214
+		// if that count is non-zero (meaning dependencies were already registered)
215
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
216
+			// then truncate the  final array to match that count
217
+			? array_slice($dependencies, 0, $dependency_count)
218
+			// otherwise just take the incoming array because nothing previously existed
219
+			: $dependencies;
220
+		return $registered;
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * @param string $class_name
227
+	 * @param string $loader
228
+	 * @return bool
229
+	 * @throws DomainException
230
+	 */
231
+	public static function register_class_loader($class_name, $loader = 'load_core')
232
+	{
233
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234
+			throw new DomainException(
235
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
236
+			);
237
+		}
238
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
239
+		if (
240
+			! is_callable($loader)
241
+			&& (
242
+				strpos($loader, 'load_') !== 0
243
+				|| ! method_exists('EE_Registry', $loader)
244
+			)
245
+		) {
246
+			throw new DomainException(
247
+				sprintf(
248
+					esc_html__(
249
+						'"%1$s" is not a valid loader method on EE_Registry.',
250
+						'event_espresso'
251
+					),
252
+					$loader
253
+				)
254
+			);
255
+		}
256
+		$class_name = self::$_instance->get_alias($class_name);
257
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
258
+			self::$_instance->_class_loaders[$class_name] = $loader;
259
+			return true;
260
+		}
261
+		return false;
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 * @return array
268
+	 */
269
+	public function dependency_map()
270
+	{
271
+		return $this->_dependency_map;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * returns TRUE if dependency map contains a listing for the provided class name
278
+	 *
279
+	 * @param string $class_name
280
+	 * @return boolean
281
+	 */
282
+	public function has($class_name = '')
283
+	{
284
+		return isset($this->_dependency_map[$class_name]) ? true : false;
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
291
+	 *
292
+	 * @param string $class_name
293
+	 * @param string $dependency
294
+	 * @return bool
295
+	 */
296
+	public function has_dependency_for_class($class_name = '', $dependency = '')
297
+	{
298
+		$dependency = $this->get_alias($dependency);
299
+		return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
300
+			? true
301
+			: false;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
308
+	 *
309
+	 * @param string $class_name
310
+	 * @param string $dependency
311
+	 * @return int
312
+	 */
313
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
314
+	{
315
+		$dependency = $this->get_alias($dependency);
316
+		return $this->has_dependency_for_class($class_name, $dependency)
317
+			? $this->_dependency_map[$class_name][$dependency]
318
+			: EE_Dependency_Map::not_registered;
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * @param string $class_name
325
+	 * @return string | Closure
326
+	 */
327
+	public function class_loader($class_name)
328
+	{
329
+		$class_name = $this->get_alias($class_name);
330
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * @return array
337
+	 */
338
+	public function class_loaders()
339
+	{
340
+		return $this->_class_loaders;
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * adds an alias for a classname
347
+	 *
348
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
349
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
350
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
351
+	 */
352
+	public function add_alias($class_name, $alias, $for_class = '')
353
+	{
354
+		if ($for_class !== '') {
355
+			if (! isset($this->_aliases[$for_class])) {
356
+				$this->_aliases[$for_class] = array();
357
+			}
358
+			$this->_aliases[$for_class][$class_name] = $alias;
359
+		}
360
+		$this->_aliases[$class_name] = $alias;
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * returns TRUE if the provided class name has an alias
367
+	 *
368
+	 * @param string $class_name
369
+	 * @param string $for_class
370
+	 * @return bool
371
+	 */
372
+	public function has_alias($class_name = '', $for_class = '')
373
+	{
374
+		return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
375
+			   || (
376
+				   isset($this->_aliases[$class_name])
377
+				   && ! is_array($this->_aliases[$class_name])
378
+			   );
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * returns alias for class name if one exists, otherwise returns the original classname
385
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
386
+	 *  for example:
387
+	 *      if the following two entries were added to the _aliases array:
388
+	 *          array(
389
+	 *              'interface_alias'           => 'some\namespace\interface'
390
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
391
+	 *          )
392
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
393
+	 *      to load an instance of 'some\namespace\classname'
394
+	 *
395
+	 * @param string $class_name
396
+	 * @param string $for_class
397
+	 * @return string
398
+	 */
399
+	public function get_alias($class_name = '', $for_class = '')
400
+	{
401
+		if (! $this->has_alias($class_name, $for_class)) {
402
+			return $class_name;
403
+		}
404
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
405
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
406
+		}
407
+		return $this->get_alias($this->_aliases[$class_name]);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
414
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
415
+	 * This is done by using the following class constants:
416
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
417
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
418
+	 */
419
+	protected function _register_core_dependencies()
420
+	{
421
+		$this->_dependency_map = array(
422
+			'EE_Request_Handler'                                                                                          => array(
423
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
424
+			),
425
+			'EE_System'                                                                                                   => array(
426
+				'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
427
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
428
+				'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
429
+			),
430
+			'EE_Session'                                                                                                  => array(
431
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
432
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
433
+			),
434
+			'EE_Cart'                                                                                                     => array(
435
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
436
+			),
437
+			'EE_Front_Controller'                                                                                         => array(
438
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
439
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
440
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
441
+			),
442
+			'EE_Messenger_Collection_Loader'                                                                              => array(
443
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
444
+			),
445
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
446
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
447
+			),
448
+			'EE_Message_Resource_Manager'                                                                                 => array(
449
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
450
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
451
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
452
+			),
453
+			'EE_Message_Factory'                                                                                          => array(
454
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
455
+			),
456
+			'EE_messages'                                                                                                 => array(
457
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
458
+			),
459
+			'EE_Messages_Generator'                                                                                       => array(
460
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
461
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
462
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
463
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
464
+			),
465
+			'EE_Messages_Processor'                                                                                       => array(
466
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
467
+			),
468
+			'EE_Messages_Queue'                                                                                           => array(
469
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
470
+			),
471
+			'EE_Messages_Template_Defaults'                                                                               => array(
472
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
473
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
474
+			),
475
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
476
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
478
+			),
479
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
480
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
481
+			),
482
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
483
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
484
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
485
+			),
486
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
487
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
488
+			),
489
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
490
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
491
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
492
+			),
493
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
494
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
495
+			),
496
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
497
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
498
+			),
499
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
500
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
501
+			),
502
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
503
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
504
+			),
505
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
506
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
507
+			),
508
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
509
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
510
+			),
511
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
512
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
513
+			),
514
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
515
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
516
+			),
517
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
518
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
519
+			),
520
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
521
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
522
+			),
523
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
524
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
525
+			),
526
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
527
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
528
+			),
529
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
530
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
531
+			),
532
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
533
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
534
+			),
535
+			'EE_Data_Migration_Class_Base'                                                                                => array(
536
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
537
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
540
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
541
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
542
+			),
543
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
544
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
545
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
546
+			),
547
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
548
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
549
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
552
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
554
+			),
555
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
556
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
557
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
558
+			),
559
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
560
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
561
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
564
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
+			),
567
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
568
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
+			),
571
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
572
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
576
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
577
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
578
+			),
579
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
580
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
581
+			),
582
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
583
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
584
+			),
585
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
586
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
587
+			),
588
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
589
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
590
+			),
591
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
592
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
593
+			),
594
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
595
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
596
+			),
597
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
598
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
599
+			),
600
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
601
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
602
+			),
603
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'            => array(
604
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
605
+			),
606
+			'EventEspresso\core\services\activation\ActivationsAndUpgradesManager' => array(
607
+				'EventEspresso\core\services\activation\ActivationHandler'   => EE_Dependency_Map::load_from_cache,
608
+				'EventEspresso\core\services\activation\RequestTypeDetector' => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EventEspresso\core\services\activation\ActivationHandler'             => array(
611
+				'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
612
+			),
613
+			'EventEspresso\core\services\activation\InitializeCore'                => array(
614
+				null,
615
+				'EE_Capabilities'           => EE_Dependency_Map::load_from_cache,
616
+				'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
617
+				'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
618
+			),
619
+			'EventEspresso\core\services\activation\InitializeAddon' => array(
620
+				null,
621
+				'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
622
+				'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
623
+				'EE_Registry'               => EE_Dependency_Map::load_from_cache,
624
+			),
625
+			'EE_Module_Request_Router' => array(
626
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
627
+			),
628
+		);
629
+	}
630
+
631
+
632
+
633
+	/**
634
+	 * Registers how core classes are loaded.
635
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
636
+	 *        'EE_Request_Handler' => 'load_core'
637
+	 *        'EE_Messages_Queue'  => 'load_lib'
638
+	 *        'EEH_Debug_Tools'    => 'load_helper'
639
+	 * or, if greater control is required, by providing a custom closure. For example:
640
+	 *        'Some_Class' => function () {
641
+	 *            return new Some_Class();
642
+	 *        },
643
+	 * This is required for instantiating dependencies
644
+	 * where an interface has been type hinted in a class constructor. For example:
645
+	 *        'Required_Interface' => function () {
646
+	 *            return new A_Class_That_Implements_Required_Interface();
647
+	 *        },
648
+	 */
649
+	protected function _register_core_class_loaders()
650
+	{
651
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
652
+		//be used in a closure.
653
+		$request = &$this->_request;
654
+		$response = &$this->_response;
655
+		$loader = &$this->loader;
656
+		$this->_class_loaders = array(
657
+			//load_core
658
+			'EE_Capabilities'                      => 'load_core',
659
+			'EE_Encryption'                        => 'load_core',
660
+			'EE_Front_Controller'                  => 'load_core',
661
+			'EE_Module_Request_Router'             => 'load_core',
662
+			'EE_Registry'                          => 'load_core',
663
+			'EE_Request'                           => function () use (&$request) {
664
+				return $request;
665
+			},
666
+			'EE_Response'                          => function () use (&$response) {
667
+				return $response;
668
+			},
669
+			'EE_Request_Handler'                   => 'load_core',
670
+			'EE_Session'                           => 'load_core',
671
+			'EE_System'                            => 'load_core',
672
+			'EE_Maintenance_Mode'                  => 'load_core',
673
+			'EE_Register_CPTs'                     => 'load_core',
674
+			'EE_Admin'                             => 'load_core',
675
+			'EE_Data_Migration_Manager'            => 'load_core',
676
+			//load_lib
677
+			'EE_Message_Resource_Manager'          => 'load_lib',
678
+			'EE_Message_Type_Collection'           => 'load_lib',
679
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
680
+			'EE_Messenger_Collection'              => 'load_lib',
681
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
682
+			'EE_Messages_Processor'                => 'load_lib',
683
+			'EE_Message_Repository'                => 'load_lib',
684
+			'EE_Messages_Queue'                    => 'load_lib',
685
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
686
+			'EE_Message_Template_Group_Collection' => 'load_lib',
687
+			'EE_Messages_Generator'                => function () {
688
+				return EE_Registry::instance()->load_lib(
689
+					'Messages_Generator',
690
+					array(),
691
+					false,
692
+					false
693
+				);
694
+			},
695
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
696
+				return EE_Registry::instance()->load_lib(
697
+					'Messages_Template_Defaults',
698
+					$arguments,
699
+					false,
700
+					false
701
+				);
702
+			},
703
+			//load_model
704
+			'EEM_Attendee'                         => 'load_model',
705
+			'EEM_Message_Template_Group'           => 'load_model',
706
+			'EEM_Message_Template'                 => 'load_model',
707
+			//load_helper
708
+			'EEH_Parse_Shortcodes'                 => function () {
709
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
710
+					return new EEH_Parse_Shortcodes();
711
+				}
712
+				return null;
713
+			},
714
+			'EE_Template_Config'                   => function () {
715
+				return EE_Config::instance()->template_settings;
716
+			},
717
+			'EE_Currency_Config'                   => function () {
718
+				return EE_Config::instance()->currency;
719
+			},
720
+			'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
721
+				return $loader;
722
+			},
723
+		);
724
+	}
725
+
726
+
727
+
728
+	/**
729
+	 * can be used for supplying alternate names for classes,
730
+	 * or for connecting interface names to instantiable classes
731
+	 */
732
+	protected function _register_core_aliases()
733
+	{
734
+		$this->_aliases = array(
735
+			'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
736
+			'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
737
+			'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
738
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
739
+			'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
740
+			'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
741
+			'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
742
+			'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
743
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
744
+			'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
745
+			'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
746
+			'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
747
+			'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
748
+			'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
749
+			'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
750
+			'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
751
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
752
+			'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
753
+			'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
754
+			'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
755
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
756
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
757
+			'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
758
+			'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
759
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
760
+			'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
761
+			'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
762
+			'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
763
+			'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
764
+			'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
765
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
766
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
767
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
768
+			'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
769
+			'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
770
+		);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
777
+	 * request Primarily used by unit tests.
778
+	 */
779
+	public function reset()
780
+	{
781
+		$this->_register_core_class_loaders();
782
+		$this->_register_core_dependencies();
783
+	}
784 784
 
785 785
 
786 786
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Indentation   +1654 added lines, -1654 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -17,243 +17,243 @@  discard block
 block discarded – undo
17 17
 class EEH_Activation implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * constant used to indicate a cron task is no longer in use
22
-     */
23
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
24
-
25
-    /**
26
-     * option name that will indicate whether or not we still
27
-     * need to create EE's folders in the uploads directory
28
-     * (because if EE was installed without file system access,
29
-     * we need to request credentials before we can create them)
30
-     */
31
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
-
33
-    /**
34
-     * WP_User->ID
35
-     *
36
-     * @var int
37
-     */
38
-    private static $_default_creator_id;
39
-
40
-    /**
41
-     * indicates whether or not we've already verified core's default data during this request,
42
-     * because after migrations are done, any addons activated while in maintenance mode
43
-     * will want to setup their own default data, and they might hook into core's default data
44
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
-     * This prevents doing that for EVERY single addon.
46
-     *
47
-     * @var boolean
48
-     */
49
-    protected static $_initialized_db_content_already_in_this_request = false;
50
-
51
-    /**
52
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
-     */
54
-    private static $table_analysis;
55
-
56
-    /**
57
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
58
-     */
59
-    private static $table_manager;
60
-
61
-
62
-    /**
63
-     * @return \EventEspresso\core\services\database\TableAnalysis
64
-     */
65
-    public static function getTableAnalysis()
66
-    {
67
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
-        }
70
-        return self::$table_analysis;
71
-    }
72
-
73
-
74
-    /**
75
-     * @return \EventEspresso\core\services\database\TableManager
76
-     */
77
-    public static function getTableManager()
78
-    {
79
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
-        }
82
-        return self::$table_manager;
83
-    }
84
-
85
-
86
-    /**
87
-     *    _ensure_table_name_has_prefix
88
-     *
89
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
-     * @access     public
91
-     * @static
92
-     * @param $table_name
93
-     * @return string
94
-     */
95
-    public static function ensure_table_name_has_prefix($table_name)
96
-    {
97
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
-    }
99
-
100
-
101
-    /**
102
-     *    system_initialization
103
-     *    ensures the EE configuration settings are loaded with at least default options set
104
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
-     *
106
-     * @access public
107
-     * @static
108
-     * @return void
109
-     */
110
-    public static function system_initialization()
111
-    {
112
-        EEH_Activation::reset_and_update_config();
113
-        //which is fired BEFORE activation of plugin anyways
114
-        EEH_Activation::verify_default_pages_exist();
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the database schema and creates folders. This should
120
-     * be called on plugin activation and reactivation
121
-     *
122
-     * @return boolean success, whether the database and folders are setup properly
123
-     * @throws \EE_Error
124
-     */
125
-    public static function initialize_db_and_folders()
126
-    {
127
-        $good_filesystem = EEH_Activation::create_upload_directories();
128
-        $good_db         = EEH_Activation::create_database_tables();
129
-        return $good_filesystem && $good_db;
130
-    }
131
-
132
-
133
-    /**
134
-     * assuming we have an up-to-date database schema, this will populate it
135
-     * with default and initial data. This should be called
136
-     * upon activation of a new plugin, reactivation, and at the end
137
-     * of running migration scripts
138
-     *
139
-     * @throws \EE_Error
140
-     */
141
-    public static function initialize_db_content()
142
-    {
143
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
-            return;
146
-        }
147
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
-
149
-        EEH_Activation::initialize_system_questions();
150
-        EEH_Activation::insert_default_status_codes();
151
-        EEH_Activation::generate_default_message_templates();
152
-        EEH_Activation::create_no_ticket_prices_array();
153
-
154
-        EEH_Activation::validate_messages_system();
155
-        EEH_Activation::insert_default_payment_methods();
156
-        //in case we've
157
-        EEH_Activation::remove_cron_tasks();
158
-        EEH_Activation::create_cron_tasks();
159
-        // remove all TXN locks since that is being done via extra meta now
160
-        delete_option('ee_locked_transactions');
161
-        //also, check for CAF default db content
162
-        do_action('AHEE__EEH_Activation__initialize_db_content');
163
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
164
-        //which users really won't care about on initial activation
165
-        EE_Error::overwrite_success();
166
-    }
167
-
168
-
169
-    /**
170
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
171
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
172
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
173
-     * (null)
174
-     *
175
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
176
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
177
-     * @return array
178
-     * @throws \EE_Error
179
-     */
180
-    public static function get_cron_tasks($which_to_include)
181
-    {
182
-        $cron_tasks = apply_filters(
183
-            'FHEE__EEH_Activation__get_cron_tasks',
184
-            array(
185
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
20
+	/**
21
+	 * constant used to indicate a cron task is no longer in use
22
+	 */
23
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
24
+
25
+	/**
26
+	 * option name that will indicate whether or not we still
27
+	 * need to create EE's folders in the uploads directory
28
+	 * (because if EE was installed without file system access,
29
+	 * we need to request credentials before we can create them)
30
+	 */
31
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
+
33
+	/**
34
+	 * WP_User->ID
35
+	 *
36
+	 * @var int
37
+	 */
38
+	private static $_default_creator_id;
39
+
40
+	/**
41
+	 * indicates whether or not we've already verified core's default data during this request,
42
+	 * because after migrations are done, any addons activated while in maintenance mode
43
+	 * will want to setup their own default data, and they might hook into core's default data
44
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
+	 * This prevents doing that for EVERY single addon.
46
+	 *
47
+	 * @var boolean
48
+	 */
49
+	protected static $_initialized_db_content_already_in_this_request = false;
50
+
51
+	/**
52
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
+	 */
54
+	private static $table_analysis;
55
+
56
+	/**
57
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
58
+	 */
59
+	private static $table_manager;
60
+
61
+
62
+	/**
63
+	 * @return \EventEspresso\core\services\database\TableAnalysis
64
+	 */
65
+	public static function getTableAnalysis()
66
+	{
67
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
+		}
70
+		return self::$table_analysis;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return \EventEspresso\core\services\database\TableManager
76
+	 */
77
+	public static function getTableManager()
78
+	{
79
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
+		}
82
+		return self::$table_manager;
83
+	}
84
+
85
+
86
+	/**
87
+	 *    _ensure_table_name_has_prefix
88
+	 *
89
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
+	 * @access     public
91
+	 * @static
92
+	 * @param $table_name
93
+	 * @return string
94
+	 */
95
+	public static function ensure_table_name_has_prefix($table_name)
96
+	{
97
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
+	}
99
+
100
+
101
+	/**
102
+	 *    system_initialization
103
+	 *    ensures the EE configuration settings are loaded with at least default options set
104
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
+	 *
106
+	 * @access public
107
+	 * @static
108
+	 * @return void
109
+	 */
110
+	public static function system_initialization()
111
+	{
112
+		EEH_Activation::reset_and_update_config();
113
+		//which is fired BEFORE activation of plugin anyways
114
+		EEH_Activation::verify_default_pages_exist();
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the database schema and creates folders. This should
120
+	 * be called on plugin activation and reactivation
121
+	 *
122
+	 * @return boolean success, whether the database and folders are setup properly
123
+	 * @throws \EE_Error
124
+	 */
125
+	public static function initialize_db_and_folders()
126
+	{
127
+		$good_filesystem = EEH_Activation::create_upload_directories();
128
+		$good_db         = EEH_Activation::create_database_tables();
129
+		return $good_filesystem && $good_db;
130
+	}
131
+
132
+
133
+	/**
134
+	 * assuming we have an up-to-date database schema, this will populate it
135
+	 * with default and initial data. This should be called
136
+	 * upon activation of a new plugin, reactivation, and at the end
137
+	 * of running migration scripts
138
+	 *
139
+	 * @throws \EE_Error
140
+	 */
141
+	public static function initialize_db_content()
142
+	{
143
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
+			return;
146
+		}
147
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
+
149
+		EEH_Activation::initialize_system_questions();
150
+		EEH_Activation::insert_default_status_codes();
151
+		EEH_Activation::generate_default_message_templates();
152
+		EEH_Activation::create_no_ticket_prices_array();
153
+
154
+		EEH_Activation::validate_messages_system();
155
+		EEH_Activation::insert_default_payment_methods();
156
+		//in case we've
157
+		EEH_Activation::remove_cron_tasks();
158
+		EEH_Activation::create_cron_tasks();
159
+		// remove all TXN locks since that is being done via extra meta now
160
+		delete_option('ee_locked_transactions');
161
+		//also, check for CAF default db content
162
+		do_action('AHEE__EEH_Activation__initialize_db_content');
163
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
164
+		//which users really won't care about on initial activation
165
+		EE_Error::overwrite_success();
166
+	}
167
+
168
+
169
+	/**
170
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
171
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
172
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
173
+	 * (null)
174
+	 *
175
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
176
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
177
+	 * @return array
178
+	 * @throws \EE_Error
179
+	 */
180
+	public static function get_cron_tasks($which_to_include)
181
+	{
182
+		$cron_tasks = apply_filters(
183
+			'FHEE__EEH_Activation__get_cron_tasks',
184
+			array(
185
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
186 186
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
187
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
188
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
189
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
190
-            )
191
-        );
192
-        if ($which_to_include === 'old') {
193
-            $cron_tasks = array_filter(
194
-                $cron_tasks,
195
-                function ($value) {
196
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
197
-                }
198
-            );
199
-        } elseif ($which_to_include === 'current') {
200
-            $cron_tasks = array_filter($cron_tasks);
201
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
202
-            throw new EE_Error(
203
-                sprintf(
204
-                    __(
205
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
206
-                        'event_espresso'
207
-                    ),
208
-                    $which_to_include
209
-                )
210
-            );
211
-        }
212
-        return $cron_tasks;
213
-    }
214
-
215
-
216
-    /**
217
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
218
-     *
219
-     * @throws \EE_Error
220
-     */
221
-    public static function create_cron_tasks()
222
-    {
223
-
224
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
225
-            if (! wp_next_scheduled($hook_name)) {
226
-                /**
227
-                 * This allows client code to define the initial start timestamp for this schedule.
228
-                 */
229
-                if (is_array($frequency)
230
-                    && count($frequency) === 2
231
-                    && isset($frequency[0], $frequency[1])
232
-                ) {
233
-                    $start_timestamp = $frequency[0];
234
-                    $frequency = $frequency[1];
235
-                } else {
236
-                    $start_timestamp = time();
237
-                }
238
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
239
-            }
240
-        }
241
-
242
-    }
243
-
244
-
245
-    /**
246
-     * Remove the currently-existing and now-removed cron tasks.
247
-     *
248
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
249
-     * @throws \EE_Error
250
-     */
251
-    public static function remove_cron_tasks($remove_all = true)
252
-    {
253
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
254
-        $crons                = _get_cron_array();
255
-        $crons                = is_array($crons) ? $crons : array();
256
-        /* reminder of what $crons look like:
187
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
188
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
189
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
190
+			)
191
+		);
192
+		if ($which_to_include === 'old') {
193
+			$cron_tasks = array_filter(
194
+				$cron_tasks,
195
+				function ($value) {
196
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
197
+				}
198
+			);
199
+		} elseif ($which_to_include === 'current') {
200
+			$cron_tasks = array_filter($cron_tasks);
201
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
202
+			throw new EE_Error(
203
+				sprintf(
204
+					__(
205
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
206
+						'event_espresso'
207
+					),
208
+					$which_to_include
209
+				)
210
+			);
211
+		}
212
+		return $cron_tasks;
213
+	}
214
+
215
+
216
+	/**
217
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
218
+	 *
219
+	 * @throws \EE_Error
220
+	 */
221
+	public static function create_cron_tasks()
222
+	{
223
+
224
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
225
+			if (! wp_next_scheduled($hook_name)) {
226
+				/**
227
+				 * This allows client code to define the initial start timestamp for this schedule.
228
+				 */
229
+				if (is_array($frequency)
230
+					&& count($frequency) === 2
231
+					&& isset($frequency[0], $frequency[1])
232
+				) {
233
+					$start_timestamp = $frequency[0];
234
+					$frequency = $frequency[1];
235
+				} else {
236
+					$start_timestamp = time();
237
+				}
238
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
239
+			}
240
+		}
241
+
242
+	}
243
+
244
+
245
+	/**
246
+	 * Remove the currently-existing and now-removed cron tasks.
247
+	 *
248
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
249
+	 * @throws \EE_Error
250
+	 */
251
+	public static function remove_cron_tasks($remove_all = true)
252
+	{
253
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
254
+		$crons                = _get_cron_array();
255
+		$crons                = is_array($crons) ? $crons : array();
256
+		/* reminder of what $crons look like:
257 257
          * Top-level keys are timestamps, and their values are arrays.
258 258
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
259 259
          * and their values are arrays.
@@ -270,912 +270,912 @@  discard block
 block discarded – undo
270 270
          *					...
271 271
          *      ...
272 272
          */
273
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
274
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
275
-            if (is_array($hooks_to_fire_at_time)) {
276
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
277
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
278
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
279
-                    ) {
280
-                        unset($crons[$timestamp][$hook_name]);
281
-                    }
282
-                }
283
-                //also take care of any empty cron timestamps.
284
-                if (empty($hooks_to_fire_at_time)) {
285
-                    unset($crons[$timestamp]);
286
-                }
287
-            }
288
-        }
289
-        _set_cron_array($crons);
290
-    }
291
-
292
-
293
-    /**
294
-     *    CPT_initialization
295
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
296
-     *
297
-     * @access public
298
-     * @static
299
-     * @return void
300
-     */
301
-    public static function CPT_initialization()
302
-    {
303
-        // register Custom Post Types
304
-        EE_Registry::instance()->load_core('Register_CPTs');
305
-        flush_rewrite_rules();
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     *    reset_and_update_config
312
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
313
-     * If there is old calendar config data saved, then it will get converted on activation.
314
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
315
-     *
316
-     * @access public
317
-     * @static
318
-     * @return void
319
-     */
320
-    public static function reset_and_update_config()
321
-    {
322
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
323
-        add_filter(
324
-            'FHEE__EE_Config___load_core_config__config_settings',
325
-            array('EEH_Activation', 'migrate_old_config_data'),
326
-            10,
327
-            3
328
-        );
329
-        //EE_Config::reset();
330
-        if (! EE_Config::logging_enabled()) {
331
-            delete_option(EE_Config::LOG_NAME);
332
-        }
333
-    }
334
-
335
-
336
-    /**
337
-     *    load_calendar_config
338
-     *
339
-     * @access    public
340
-     * @return    void
341
-     */
342
-    public static function load_calendar_config()
343
-    {
344
-        // grab array of all plugin folders and loop thru it
345
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
346
-        if (empty($plugins)) {
347
-            return;
348
-        }
349
-        foreach ($plugins as $plugin_path) {
350
-            // grab plugin folder name from path
351
-            $plugin = basename($plugin_path);
352
-            // drill down to Espresso plugins
353
-            // then to calendar related plugins
354
-            if (
355
-                strpos($plugin, 'espresso') !== false
356
-                || strpos($plugin, 'Espresso') !== false
357
-                || strpos($plugin, 'ee4') !== false
358
-                || strpos($plugin, 'EE4') !== false
359
-                || strpos($plugin, 'calendar') !== false
360
-            ) {
361
-                // this is what we are looking for
362
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
363
-                // does it exist in this folder ?
364
-                if (is_readable($calendar_config)) {
365
-                    // YEAH! let's load it
366
-                    require_once($calendar_config);
367
-                }
368
-            }
369
-        }
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     *    _migrate_old_config_data
376
-     *
377
-     * @access    public
378
-     * @param array|stdClass $settings
379
-     * @param string         $config
380
-     * @param \EE_Config     $EE_Config
381
-     * @return \stdClass
382
-     */
383
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
384
-    {
385
-        $convert_from_array = array('addons');
386
-        // in case old settings were saved as an array
387
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
388
-            // convert existing settings to an object
389
-            $config_array = $settings;
390
-            $settings = new stdClass();
391
-            foreach ($config_array as $key => $value) {
392
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
393
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
394
-                } else {
395
-                    $settings->{$key} = $value;
396
-                }
397
-            }
398
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
399
-        }
400
-        return $settings;
401
-    }
402
-
403
-
404
-    /**
405
-     * deactivate_event_espresso
406
-     *
407
-     * @access public
408
-     * @static
409
-     * @return void
410
-     */
411
-    public static function deactivate_event_espresso()
412
-    {
413
-        // check permissions
414
-        if (current_user_can('activate_plugins')) {
415
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
416
-        }
417
-    }
418
-
419
-
420
-
421
-
422
-
423
-    /**
424
-     * verify_default_pages_exist
425
-     *
426
-     * @access public
427
-     * @static
428
-     * @return void
429
-     */
430
-    public static function verify_default_pages_exist()
431
-    {
432
-        $critical_page_problem = false;
433
-        $critical_pages = array(
434
-            array(
435
-                'id'   => 'reg_page_id',
436
-                'name' => __('Registration Checkout', 'event_espresso'),
437
-                'post' => null,
438
-                'code' => 'ESPRESSO_CHECKOUT',
439
-            ),
440
-            array(
441
-                'id'   => 'txn_page_id',
442
-                'name' => __('Transactions', 'event_espresso'),
443
-                'post' => null,
444
-                'code' => 'ESPRESSO_TXN_PAGE',
445
-            ),
446
-            array(
447
-                'id'   => 'thank_you_page_id',
448
-                'name' => __('Thank You', 'event_espresso'),
449
-                'post' => null,
450
-                'code' => 'ESPRESSO_THANK_YOU',
451
-            ),
452
-            array(
453
-                'id'   => 'cancel_page_id',
454
-                'name' => __('Registration Cancelled', 'event_espresso'),
455
-                'post' => null,
456
-                'code' => 'ESPRESSO_CANCELLED',
457
-            ),
458
-        );
459
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
460
-        foreach ($critical_pages as $critical_page) {
461
-            // is critical page ID set in config ?
462
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
463
-                // attempt to find post by ID
464
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
465
-            }
466
-            // no dice?
467
-            if ($critical_page['post'] === null) {
468
-                // attempt to find post by title
469
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
470
-                // still nothing?
471
-                if ($critical_page['post'] === null) {
472
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
473
-                    // REALLY? Still nothing ??!?!?
474
-                    if ($critical_page['post'] === null) {
475
-                        $msg = __(
476
-                            'The Event Espresso critical page configuration settings could not be updated.',
477
-                            'event_espresso'
478
-                        );
479
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
480
-                        break;
481
-                    }
482
-                }
483
-            }
484
-            // check that Post ID matches critical page ID in config
485
-            if (
486
-                isset($critical_page['post']->ID)
487
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
488
-            ) {
489
-                //update Config with post ID
490
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
491
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
492
-                    $msg = __(
493
-                        'The Event Espresso critical page configuration settings could not be updated.',
494
-                        'event_espresso'
495
-                    );
496
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
497
-                }
498
-            }
499
-            $critical_page_problem =
500
-                ! isset($critical_page['post']->post_status)
501
-                || $critical_page['post']->post_status !== 'publish'
502
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
503
-                    ? true
504
-                    : $critical_page_problem;
505
-        }
506
-        if ($critical_page_problem) {
507
-            $msg = sprintf(
508
-                __(
509
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
510
-                    'event_espresso'
511
-                ),
512
-                '<a href="'
513
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
514
-                . '">'
515
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
516
-                . '</a>'
517
-            );
518
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
519
-        }
520
-        if (EE_Error::has_notices()) {
521
-            EE_Error::get_notices(false, true, true);
522
-        }
523
-    }
524
-
525
-
526
-
527
-    /**
528
-     * Returns the first post which uses the specified shortcode
529
-     *
530
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
531
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
532
-     *                             "[ESPRESSO_THANK_YOU"
533
-     *                             (we don't search for the closing shortcode bracket because they might have added
534
-     *                             parameter to the shortcode
535
-     * @return WP_Post or NULl
536
-     */
537
-    public static function get_page_by_ee_shortcode($ee_shortcode)
538
-    {
539
-        global $wpdb;
540
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
541
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
542
-        if ($post_id) {
543
-            return get_post($post_id);
544
-        } else {
545
-            return null;
546
-        }
547
-    }
548
-
549
-
550
-    /**
551
-     *    This function generates a post for critical espresso pages
552
-     *
553
-     * @access public
554
-     * @static
555
-     * @param array $critical_page
556
-     * @return array
557
-     */
558
-    public static function create_critical_page($critical_page)
559
-    {
560
-
561
-        $post_args = array(
562
-            'post_title'     => $critical_page['name'],
563
-            'post_status'    => 'publish',
564
-            'post_type'      => 'page',
565
-            'comment_status' => 'closed',
566
-            'post_content'   => '[' . $critical_page['code'] . ']',
567
-        );
568
-
569
-        $post_id = wp_insert_post($post_args);
570
-        if (! $post_id) {
571
-            $msg = sprintf(
572
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
573
-                $critical_page['name']
574
-            );
575
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
-            return $critical_page;
577
-        }
578
-        // get newly created post's details
579
-        if (! $critical_page['post'] = get_post($post_id)) {
580
-            $msg = sprintf(
581
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
582
-                $critical_page['name']
583
-            );
584
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
585
-        }
586
-
587
-        return $critical_page;
588
-
589
-    }
590
-
591
-
592
-
593
-
594
-    /**
595
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
596
-     * The role being used to check is filterable.
597
-     *
598
-     * @since  4.6.0
599
-     * @global WPDB $wpdb
600
-     * @return mixed null|int WP_user ID or NULL
601
-     */
602
-    public static function get_default_creator_id()
603
-    {
604
-        global $wpdb;
605
-        if ( ! empty(self::$_default_creator_id)) {
606
-            return self::$_default_creator_id;
607
-        }/**/
608
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
609
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
610
-        $pre_filtered_id = apply_filters(
611
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
612
-            false,
613
-            $role_to_check
614
-        );
615
-        if ($pre_filtered_id !== false) {
616
-            return (int)$pre_filtered_id;
617
-        }
618
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
619
-        $query = $wpdb->prepare(
620
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
621
-            '%' . $role_to_check . '%'
622
-        );
623
-        $user_id = $wpdb->get_var($query);
624
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
625
-        if ($user_id && (int)$user_id) {
626
-            self::$_default_creator_id = (int)$user_id;
627
-            return self::$_default_creator_id;
628
-        } else {
629
-            return null;
630
-        }
631
-    }
632
-
633
-
634
-
635
-    /**
636
-     * used by EE and EE addons during plugin activation to create tables.
637
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
638
-     * but includes extra logic regarding activations.
639
-     *
640
-     * @access public
641
-     * @static
642
-     * @param string  $table_name              without the $wpdb->prefix
643
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
644
-     *                                         table query)
645
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
646
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
647
-     *                                         and new once this function is done (ie, you really do want to CREATE a
648
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
649
-     *                                         you just want to verify the table exists and matches this definition
650
-     *                                         (and if it HAS data in it you want to leave it be)
651
-     * @return void
652
-     * @throws EE_Error if there are database errors
653
-     */
654
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
655
-    {
656
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
657
-            return;
658
-        }
659
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
660
-        if ( ! function_exists('dbDelta')) {
661
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
662
-        }
663
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
664
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
665
-        // do we need to first delete an existing version of this table ?
666
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
667
-            // ok, delete the table... but ONLY if it's empty
668
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
669
-            // table is NOT empty, are you SURE you want to delete this table ???
670
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
671
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
672
-            } else if ( ! $deleted_safely) {
673
-                // so we should be more cautious rather than just dropping tables so easily
674
-                error_log(
675
-                    sprintf(
676
-                        __(
677
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
678
-                            'event_espresso'
679
-                        ),
680
-                        $wp_table_name,
681
-                        '<br/>',
682
-                        'espresso_db_update'
683
-                    )
684
-                );
685
-            }
686
-        }
687
-        $engine = str_replace('ENGINE=', '', $engine);
688
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     *    add_column_if_it_doesn't_exist
695
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
696
-     *
697
-     * @access     public
698
-     * @static
699
-     * @deprecated instead use TableManager::addColumn()
700
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
701
-     * @param string $column_name
702
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
703
-     *                            'VARCHAR(10)'
704
-     * @return bool|int
705
-     */
706
-    public static function add_column_if_it_doesnt_exist(
707
-        $table_name,
708
-        $column_name,
709
-        $column_info = 'INT UNSIGNED NOT NULL'
710
-    ) {
711
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
712
-    }
713
-
714
-
715
-    /**
716
-     * get_fields_on_table
717
-     * Gets all the fields on the database table.
718
-     *
719
-     * @access     public
720
-     * @deprecated instead use TableManager::getTableColumns()
721
-     * @static
722
-     * @param string $table_name , without prefixed $wpdb->prefix
723
-     * @return array of database column names
724
-     */
725
-    public static function get_fields_on_table($table_name = null)
726
-    {
727
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
728
-    }
729
-
730
-
731
-    /**
732
-     * db_table_is_empty
733
-     *
734
-     * @access     public\
735
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
736
-     * @static
737
-     * @param string $table_name
738
-     * @return bool
739
-     */
740
-    public static function db_table_is_empty($table_name)
741
-    {
742
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
743
-    }
744
-
745
-
746
-    /**
747
-     * delete_db_table_if_empty
748
-     *
749
-     * @access public
750
-     * @static
751
-     * @param string $table_name
752
-     * @return bool | int
753
-     */
754
-    public static function delete_db_table_if_empty($table_name)
755
-    {
756
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
757
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
758
-        }
759
-        return false;
760
-    }
761
-
762
-
763
-    /**
764
-     * delete_unused_db_table
765
-     *
766
-     * @access     public
767
-     * @static
768
-     * @deprecated instead use TableManager::dropTable()
769
-     * @param string $table_name
770
-     * @return bool | int
771
-     */
772
-    public static function delete_unused_db_table($table_name)
773
-    {
774
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
775
-    }
776
-
777
-
778
-    /**
779
-     * drop_index
780
-     *
781
-     * @access     public
782
-     * @static
783
-     * @deprecated instead use TableManager::dropIndex()
784
-     * @param string $table_name
785
-     * @param string $index_name
786
-     * @return bool | int
787
-     */
788
-    public static function drop_index($table_name, $index_name)
789
-    {
790
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
791
-    }
792
-
793
-
794
-
795
-    /**
796
-     * create_database_tables
797
-     *
798
-     * @access public
799
-     * @static
800
-     * @throws EE_Error
801
-     * @return boolean success (whether database is setup properly or not)
802
-     */
803
-    public static function create_database_tables()
804
-    {
805
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
806
-        //find the migration script that sets the database to be compatible with the code
807
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
808
-        if ($dms_name) {
809
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
810
-            $current_data_migration_script->set_migrating(false);
811
-            $current_data_migration_script->schema_changes_before_migration();
812
-            $current_data_migration_script->schema_changes_after_migration();
813
-            if ($current_data_migration_script->get_errors()) {
814
-                if (WP_DEBUG) {
815
-                    foreach ($current_data_migration_script->get_errors() as $error) {
816
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
817
-                    }
818
-                } else {
819
-                    EE_Error::add_error(
820
-                        __(
821
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
273
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
274
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
275
+			if (is_array($hooks_to_fire_at_time)) {
276
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
277
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
278
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
279
+					) {
280
+						unset($crons[$timestamp][$hook_name]);
281
+					}
282
+				}
283
+				//also take care of any empty cron timestamps.
284
+				if (empty($hooks_to_fire_at_time)) {
285
+					unset($crons[$timestamp]);
286
+				}
287
+			}
288
+		}
289
+		_set_cron_array($crons);
290
+	}
291
+
292
+
293
+	/**
294
+	 *    CPT_initialization
295
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
296
+	 *
297
+	 * @access public
298
+	 * @static
299
+	 * @return void
300
+	 */
301
+	public static function CPT_initialization()
302
+	{
303
+		// register Custom Post Types
304
+		EE_Registry::instance()->load_core('Register_CPTs');
305
+		flush_rewrite_rules();
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 *    reset_and_update_config
312
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
313
+	 * If there is old calendar config data saved, then it will get converted on activation.
314
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
315
+	 *
316
+	 * @access public
317
+	 * @static
318
+	 * @return void
319
+	 */
320
+	public static function reset_and_update_config()
321
+	{
322
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
323
+		add_filter(
324
+			'FHEE__EE_Config___load_core_config__config_settings',
325
+			array('EEH_Activation', 'migrate_old_config_data'),
326
+			10,
327
+			3
328
+		);
329
+		//EE_Config::reset();
330
+		if (! EE_Config::logging_enabled()) {
331
+			delete_option(EE_Config::LOG_NAME);
332
+		}
333
+	}
334
+
335
+
336
+	/**
337
+	 *    load_calendar_config
338
+	 *
339
+	 * @access    public
340
+	 * @return    void
341
+	 */
342
+	public static function load_calendar_config()
343
+	{
344
+		// grab array of all plugin folders and loop thru it
345
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
346
+		if (empty($plugins)) {
347
+			return;
348
+		}
349
+		foreach ($plugins as $plugin_path) {
350
+			// grab plugin folder name from path
351
+			$plugin = basename($plugin_path);
352
+			// drill down to Espresso plugins
353
+			// then to calendar related plugins
354
+			if (
355
+				strpos($plugin, 'espresso') !== false
356
+				|| strpos($plugin, 'Espresso') !== false
357
+				|| strpos($plugin, 'ee4') !== false
358
+				|| strpos($plugin, 'EE4') !== false
359
+				|| strpos($plugin, 'calendar') !== false
360
+			) {
361
+				// this is what we are looking for
362
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
363
+				// does it exist in this folder ?
364
+				if (is_readable($calendar_config)) {
365
+					// YEAH! let's load it
366
+					require_once($calendar_config);
367
+				}
368
+			}
369
+		}
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 *    _migrate_old_config_data
376
+	 *
377
+	 * @access    public
378
+	 * @param array|stdClass $settings
379
+	 * @param string         $config
380
+	 * @param \EE_Config     $EE_Config
381
+	 * @return \stdClass
382
+	 */
383
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
384
+	{
385
+		$convert_from_array = array('addons');
386
+		// in case old settings were saved as an array
387
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
388
+			// convert existing settings to an object
389
+			$config_array = $settings;
390
+			$settings = new stdClass();
391
+			foreach ($config_array as $key => $value) {
392
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
393
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
394
+				} else {
395
+					$settings->{$key} = $value;
396
+				}
397
+			}
398
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
399
+		}
400
+		return $settings;
401
+	}
402
+
403
+
404
+	/**
405
+	 * deactivate_event_espresso
406
+	 *
407
+	 * @access public
408
+	 * @static
409
+	 * @return void
410
+	 */
411
+	public static function deactivate_event_espresso()
412
+	{
413
+		// check permissions
414
+		if (current_user_can('activate_plugins')) {
415
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
416
+		}
417
+	}
418
+
419
+
420
+
421
+
422
+
423
+	/**
424
+	 * verify_default_pages_exist
425
+	 *
426
+	 * @access public
427
+	 * @static
428
+	 * @return void
429
+	 */
430
+	public static function verify_default_pages_exist()
431
+	{
432
+		$critical_page_problem = false;
433
+		$critical_pages = array(
434
+			array(
435
+				'id'   => 'reg_page_id',
436
+				'name' => __('Registration Checkout', 'event_espresso'),
437
+				'post' => null,
438
+				'code' => 'ESPRESSO_CHECKOUT',
439
+			),
440
+			array(
441
+				'id'   => 'txn_page_id',
442
+				'name' => __('Transactions', 'event_espresso'),
443
+				'post' => null,
444
+				'code' => 'ESPRESSO_TXN_PAGE',
445
+			),
446
+			array(
447
+				'id'   => 'thank_you_page_id',
448
+				'name' => __('Thank You', 'event_espresso'),
449
+				'post' => null,
450
+				'code' => 'ESPRESSO_THANK_YOU',
451
+			),
452
+			array(
453
+				'id'   => 'cancel_page_id',
454
+				'name' => __('Registration Cancelled', 'event_espresso'),
455
+				'post' => null,
456
+				'code' => 'ESPRESSO_CANCELLED',
457
+			),
458
+		);
459
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
460
+		foreach ($critical_pages as $critical_page) {
461
+			// is critical page ID set in config ?
462
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
463
+				// attempt to find post by ID
464
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
465
+			}
466
+			// no dice?
467
+			if ($critical_page['post'] === null) {
468
+				// attempt to find post by title
469
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
470
+				// still nothing?
471
+				if ($critical_page['post'] === null) {
472
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
473
+					// REALLY? Still nothing ??!?!?
474
+					if ($critical_page['post'] === null) {
475
+						$msg = __(
476
+							'The Event Espresso critical page configuration settings could not be updated.',
477
+							'event_espresso'
478
+						);
479
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
480
+						break;
481
+					}
482
+				}
483
+			}
484
+			// check that Post ID matches critical page ID in config
485
+			if (
486
+				isset($critical_page['post']->ID)
487
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
488
+			) {
489
+				//update Config with post ID
490
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
491
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
492
+					$msg = __(
493
+						'The Event Espresso critical page configuration settings could not be updated.',
494
+						'event_espresso'
495
+					);
496
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
497
+				}
498
+			}
499
+			$critical_page_problem =
500
+				! isset($critical_page['post']->post_status)
501
+				|| $critical_page['post']->post_status !== 'publish'
502
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
503
+					? true
504
+					: $critical_page_problem;
505
+		}
506
+		if ($critical_page_problem) {
507
+			$msg = sprintf(
508
+				__(
509
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
510
+					'event_espresso'
511
+				),
512
+				'<a href="'
513
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
514
+				. '">'
515
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
516
+				. '</a>'
517
+			);
518
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
519
+		}
520
+		if (EE_Error::has_notices()) {
521
+			EE_Error::get_notices(false, true, true);
522
+		}
523
+	}
524
+
525
+
526
+
527
+	/**
528
+	 * Returns the first post which uses the specified shortcode
529
+	 *
530
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
531
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
532
+	 *                             "[ESPRESSO_THANK_YOU"
533
+	 *                             (we don't search for the closing shortcode bracket because they might have added
534
+	 *                             parameter to the shortcode
535
+	 * @return WP_Post or NULl
536
+	 */
537
+	public static function get_page_by_ee_shortcode($ee_shortcode)
538
+	{
539
+		global $wpdb;
540
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
541
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
542
+		if ($post_id) {
543
+			return get_post($post_id);
544
+		} else {
545
+			return null;
546
+		}
547
+	}
548
+
549
+
550
+	/**
551
+	 *    This function generates a post for critical espresso pages
552
+	 *
553
+	 * @access public
554
+	 * @static
555
+	 * @param array $critical_page
556
+	 * @return array
557
+	 */
558
+	public static function create_critical_page($critical_page)
559
+	{
560
+
561
+		$post_args = array(
562
+			'post_title'     => $critical_page['name'],
563
+			'post_status'    => 'publish',
564
+			'post_type'      => 'page',
565
+			'comment_status' => 'closed',
566
+			'post_content'   => '[' . $critical_page['code'] . ']',
567
+		);
568
+
569
+		$post_id = wp_insert_post($post_args);
570
+		if (! $post_id) {
571
+			$msg = sprintf(
572
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
573
+				$critical_page['name']
574
+			);
575
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
+			return $critical_page;
577
+		}
578
+		// get newly created post's details
579
+		if (! $critical_page['post'] = get_post($post_id)) {
580
+			$msg = sprintf(
581
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
582
+				$critical_page['name']
583
+			);
584
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
585
+		}
586
+
587
+		return $critical_page;
588
+
589
+	}
590
+
591
+
592
+
593
+
594
+	/**
595
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
596
+	 * The role being used to check is filterable.
597
+	 *
598
+	 * @since  4.6.0
599
+	 * @global WPDB $wpdb
600
+	 * @return mixed null|int WP_user ID or NULL
601
+	 */
602
+	public static function get_default_creator_id()
603
+	{
604
+		global $wpdb;
605
+		if ( ! empty(self::$_default_creator_id)) {
606
+			return self::$_default_creator_id;
607
+		}/**/
608
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
609
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
610
+		$pre_filtered_id = apply_filters(
611
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
612
+			false,
613
+			$role_to_check
614
+		);
615
+		if ($pre_filtered_id !== false) {
616
+			return (int)$pre_filtered_id;
617
+		}
618
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
619
+		$query = $wpdb->prepare(
620
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
621
+			'%' . $role_to_check . '%'
622
+		);
623
+		$user_id = $wpdb->get_var($query);
624
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
625
+		if ($user_id && (int)$user_id) {
626
+			self::$_default_creator_id = (int)$user_id;
627
+			return self::$_default_creator_id;
628
+		} else {
629
+			return null;
630
+		}
631
+	}
632
+
633
+
634
+
635
+	/**
636
+	 * used by EE and EE addons during plugin activation to create tables.
637
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
638
+	 * but includes extra logic regarding activations.
639
+	 *
640
+	 * @access public
641
+	 * @static
642
+	 * @param string  $table_name              without the $wpdb->prefix
643
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
644
+	 *                                         table query)
645
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
646
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
647
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
648
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
649
+	 *                                         you just want to verify the table exists and matches this definition
650
+	 *                                         (and if it HAS data in it you want to leave it be)
651
+	 * @return void
652
+	 * @throws EE_Error if there are database errors
653
+	 */
654
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
655
+	{
656
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
657
+			return;
658
+		}
659
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
660
+		if ( ! function_exists('dbDelta')) {
661
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
662
+		}
663
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
664
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
665
+		// do we need to first delete an existing version of this table ?
666
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
667
+			// ok, delete the table... but ONLY if it's empty
668
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
669
+			// table is NOT empty, are you SURE you want to delete this table ???
670
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
671
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
672
+			} else if ( ! $deleted_safely) {
673
+				// so we should be more cautious rather than just dropping tables so easily
674
+				error_log(
675
+					sprintf(
676
+						__(
677
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
678
+							'event_espresso'
679
+						),
680
+						$wp_table_name,
681
+						'<br/>',
682
+						'espresso_db_update'
683
+					)
684
+				);
685
+			}
686
+		}
687
+		$engine = str_replace('ENGINE=', '', $engine);
688
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 *    add_column_if_it_doesn't_exist
695
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
696
+	 *
697
+	 * @access     public
698
+	 * @static
699
+	 * @deprecated instead use TableManager::addColumn()
700
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
701
+	 * @param string $column_name
702
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
703
+	 *                            'VARCHAR(10)'
704
+	 * @return bool|int
705
+	 */
706
+	public static function add_column_if_it_doesnt_exist(
707
+		$table_name,
708
+		$column_name,
709
+		$column_info = 'INT UNSIGNED NOT NULL'
710
+	) {
711
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
712
+	}
713
+
714
+
715
+	/**
716
+	 * get_fields_on_table
717
+	 * Gets all the fields on the database table.
718
+	 *
719
+	 * @access     public
720
+	 * @deprecated instead use TableManager::getTableColumns()
721
+	 * @static
722
+	 * @param string $table_name , without prefixed $wpdb->prefix
723
+	 * @return array of database column names
724
+	 */
725
+	public static function get_fields_on_table($table_name = null)
726
+	{
727
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
728
+	}
729
+
730
+
731
+	/**
732
+	 * db_table_is_empty
733
+	 *
734
+	 * @access     public\
735
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
736
+	 * @static
737
+	 * @param string $table_name
738
+	 * @return bool
739
+	 */
740
+	public static function db_table_is_empty($table_name)
741
+	{
742
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
743
+	}
744
+
745
+
746
+	/**
747
+	 * delete_db_table_if_empty
748
+	 *
749
+	 * @access public
750
+	 * @static
751
+	 * @param string $table_name
752
+	 * @return bool | int
753
+	 */
754
+	public static function delete_db_table_if_empty($table_name)
755
+	{
756
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
757
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
758
+		}
759
+		return false;
760
+	}
761
+
762
+
763
+	/**
764
+	 * delete_unused_db_table
765
+	 *
766
+	 * @access     public
767
+	 * @static
768
+	 * @deprecated instead use TableManager::dropTable()
769
+	 * @param string $table_name
770
+	 * @return bool | int
771
+	 */
772
+	public static function delete_unused_db_table($table_name)
773
+	{
774
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
775
+	}
776
+
777
+
778
+	/**
779
+	 * drop_index
780
+	 *
781
+	 * @access     public
782
+	 * @static
783
+	 * @deprecated instead use TableManager::dropIndex()
784
+	 * @param string $table_name
785
+	 * @param string $index_name
786
+	 * @return bool | int
787
+	 */
788
+	public static function drop_index($table_name, $index_name)
789
+	{
790
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
791
+	}
792
+
793
+
794
+
795
+	/**
796
+	 * create_database_tables
797
+	 *
798
+	 * @access public
799
+	 * @static
800
+	 * @throws EE_Error
801
+	 * @return boolean success (whether database is setup properly or not)
802
+	 */
803
+	public static function create_database_tables()
804
+	{
805
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
806
+		//find the migration script that sets the database to be compatible with the code
807
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
808
+		if ($dms_name) {
809
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
810
+			$current_data_migration_script->set_migrating(false);
811
+			$current_data_migration_script->schema_changes_before_migration();
812
+			$current_data_migration_script->schema_changes_after_migration();
813
+			if ($current_data_migration_script->get_errors()) {
814
+				if (WP_DEBUG) {
815
+					foreach ($current_data_migration_script->get_errors() as $error) {
816
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
817
+					}
818
+				} else {
819
+					EE_Error::add_error(
820
+						__(
821
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
822 822
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
823
-                            'event_espresso'
824
-                        )
825
-                    );
826
-                }
827
-                return false;
828
-            }
829
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
830
-        } else {
831
-            EE_Error::add_error(
832
-                __(
833
-                    'Could not determine most up-to-date data migration script from which to pull database schema
823
+							'event_espresso'
824
+						)
825
+					);
826
+				}
827
+				return false;
828
+			}
829
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
830
+		} else {
831
+			EE_Error::add_error(
832
+				__(
833
+					'Could not determine most up-to-date data migration script from which to pull database schema
834 834
                      structure. So database is probably not setup properly',
835
-                    'event_espresso'
836
-                ),
837
-                __FILE__,
838
-                __FUNCTION__,
839
-                __LINE__
840
-            );
841
-            return false;
842
-        }
843
-        return true;
844
-    }
845
-
846
-
847
-
848
-    /**
849
-     * initialize_system_questions
850
-     *
851
-     * @access public
852
-     * @static
853
-     * @return void
854
-     */
855
-    public static function initialize_system_questions()
856
-    {
857
-        // QUESTION GROUPS
858
-        global $wpdb;
859
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
860
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
861
-        // what we have
862
-        $question_groups = $wpdb->get_col($SQL);
863
-        // check the response
864
-        $question_groups = is_array($question_groups) ? $question_groups : array();
865
-        // what we should have
866
-        $QSG_systems = array(1, 2);
867
-        // loop thru what we should have and compare to what we have
868
-        foreach ($QSG_systems as $QSG_system) {
869
-            // reset values array
870
-            $QSG_values = array();
871
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
872
-            if (! in_array("$QSG_system", $question_groups)) {
873
-                // add it
874
-                switch ($QSG_system) {
875
-                    case 1:
876
-                        $QSG_values = array(
877
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
878
-                            'QSG_identifier'      => 'personal-information-' . time(),
879
-                            'QSG_desc'            => '',
880
-                            'QSG_order'           => 1,
881
-                            'QSG_show_group_name' => 1,
882
-                            'QSG_show_group_desc' => 1,
883
-                            'QSG_system'          => EEM_Question_Group::system_personal,
884
-                            'QSG_deleted'         => 0,
885
-                        );
886
-                        break;
887
-                    case 2:
888
-                        $QSG_values = array(
889
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
890
-                            'QSG_identifier'      => 'address-information-' . time(),
891
-                            'QSG_desc'            => '',
892
-                            'QSG_order'           => 2,
893
-                            'QSG_show_group_name' => 1,
894
-                            'QSG_show_group_desc' => 1,
895
-                            'QSG_system'          => EEM_Question_Group::system_address,
896
-                            'QSG_deleted'         => 0,
897
-                        );
898
-                        break;
899
-                }
900
-                // make sure we have some values before inserting them
901
-                if (! empty($QSG_values)) {
902
-                    // insert system question
903
-                    $wpdb->insert(
904
-                        $table_name,
905
-                        $QSG_values,
906
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
907
-                    );
908
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
909
-                }
910
-            }
911
-        }
912
-        // QUESTIONS
913
-        global $wpdb;
914
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
915
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
916
-        // what we have
917
-        $questions = $wpdb->get_col($SQL);
918
-        // what we should have
919
-        $QST_systems = array(
920
-            'fname',
921
-            'lname',
922
-            'email',
923
-            'address',
924
-            'address2',
925
-            'city',
926
-            'country',
927
-            'state',
928
-            'zip',
929
-            'phone',
930
-        );
931
-        $order_for_group_1 = 1;
932
-        $order_for_group_2 = 1;
933
-        // loop thru what we should have and compare to what we have
934
-        foreach ($QST_systems as $QST_system) {
935
-            // reset values array
936
-            $QST_values = array();
937
-            // if we don't have what we should have
938
-            if (! in_array($QST_system, $questions)) {
939
-                // add it
940
-                switch ($QST_system) {
941
-                    case 'fname':
942
-                        $QST_values = array(
943
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
944
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
945
-                            'QST_system'        => 'fname',
946
-                            'QST_type'          => 'TEXT',
947
-                            'QST_required'      => 1,
948
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
949
-                            'QST_order'         => 1,
950
-                            'QST_admin_only'    => 0,
951
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
952
-                            'QST_wp_user'       => self::get_default_creator_id(),
953
-                            'QST_deleted'       => 0,
954
-                        );
955
-                        break;
956
-                    case 'lname':
957
-                        $QST_values = array(
958
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
959
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
960
-                            'QST_system'        => 'lname',
961
-                            'QST_type'          => 'TEXT',
962
-                            'QST_required'      => 1,
963
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
964
-                            'QST_order'         => 2,
965
-                            'QST_admin_only'    => 0,
966
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
967
-                            'QST_wp_user'       => self::get_default_creator_id(),
968
-                            'QST_deleted'       => 0,
969
-                        );
970
-                        break;
971
-                    case 'email':
972
-                        $QST_values = array(
973
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
974
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
975
-                            'QST_system'        => 'email',
976
-                            'QST_type'          => 'EMAIL',
977
-                            'QST_required'      => 1,
978
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
979
-                            'QST_order'         => 3,
980
-                            'QST_admin_only'    => 0,
981
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
982
-                            'QST_wp_user'       => self::get_default_creator_id(),
983
-                            'QST_deleted'       => 0,
984
-                        );
985
-                        break;
986
-                    case 'address':
987
-                        $QST_values = array(
988
-                            'QST_display_text'  => __('Address', 'event_espresso'),
989
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
990
-                            'QST_system'        => 'address',
991
-                            'QST_type'          => 'TEXT',
992
-                            'QST_required'      => 0,
993
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
994
-                            'QST_order'         => 4,
995
-                            'QST_admin_only'    => 0,
996
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
997
-                            'QST_wp_user'       => self::get_default_creator_id(),
998
-                            'QST_deleted'       => 0,
999
-                        );
1000
-                        break;
1001
-                    case 'address2':
1002
-                        $QST_values = array(
1003
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1004
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1005
-                            'QST_system'        => 'address2',
1006
-                            'QST_type'          => 'TEXT',
1007
-                            'QST_required'      => 0,
1008
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1009
-                            'QST_order'         => 5,
1010
-                            'QST_admin_only'    => 0,
1011
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1012
-                            'QST_wp_user'       => self::get_default_creator_id(),
1013
-                            'QST_deleted'       => 0,
1014
-                        );
1015
-                        break;
1016
-                    case 'city':
1017
-                        $QST_values = array(
1018
-                            'QST_display_text'  => __('City', 'event_espresso'),
1019
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1020
-                            'QST_system'        => 'city',
1021
-                            'QST_type'          => 'TEXT',
1022
-                            'QST_required'      => 0,
1023
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1024
-                            'QST_order'         => 6,
1025
-                            'QST_admin_only'    => 0,
1026
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1027
-                            'QST_wp_user'       => self::get_default_creator_id(),
1028
-                            'QST_deleted'       => 0,
1029
-                        );
1030
-                        break;
1031
-                    case 'country':
1032
-                        $QST_values = array(
1033
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1034
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1035
-                            'QST_system'        => 'country',
1036
-                            'QST_type'          => 'COUNTRY',
1037
-                            'QST_required'      => 0,
1038
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1039
-                            'QST_order'         => 7,
1040
-                            'QST_admin_only'    => 0,
1041
-                            'QST_wp_user'       => self::get_default_creator_id(),
1042
-                            'QST_deleted'       => 0,
1043
-                        );
1044
-                        break;
1045
-                    case 'state':
1046
-                        $QST_values = array(
1047
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1048
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1049
-                            'QST_system'        => 'state',
1050
-                            'QST_type'          => 'STATE',
1051
-                            'QST_required'      => 0,
1052
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1053
-                            'QST_order'         => 8,
1054
-                            'QST_admin_only'    => 0,
1055
-                            'QST_wp_user'       => self::get_default_creator_id(),
1056
-                            'QST_deleted'       => 0,
1057
-                        );
1058
-                        break;
1059
-                    case 'zip':
1060
-                        $QST_values = array(
1061
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1062
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1063
-                            'QST_system'        => 'zip',
1064
-                            'QST_type'          => 'TEXT',
1065
-                            'QST_required'      => 0,
1066
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1067
-                            'QST_order'         => 9,
1068
-                            'QST_admin_only'    => 0,
1069
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1070
-                            'QST_wp_user'       => self::get_default_creator_id(),
1071
-                            'QST_deleted'       => 0,
1072
-                        );
1073
-                        break;
1074
-                    case 'phone':
1075
-                        $QST_values = array(
1076
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1077
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1078
-                            'QST_system'        => 'phone',
1079
-                            'QST_type'          => 'TEXT',
1080
-                            'QST_required'      => 0,
1081
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1082
-                            'QST_order'         => 10,
1083
-                            'QST_admin_only'    => 0,
1084
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1085
-                            'QST_wp_user'       => self::get_default_creator_id(),
1086
-                            'QST_deleted'       => 0,
1087
-                        );
1088
-                        break;
1089
-                }
1090
-                if (! empty($QST_values)) {
1091
-                    // insert system question
1092
-                    $wpdb->insert(
1093
-                        $table_name,
1094
-                        $QST_values,
1095
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1096
-                    );
1097
-                    $QST_ID = $wpdb->insert_id;
1098
-                    // QUESTION GROUP QUESTIONS
1099
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1100
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1101
-                    } else {
1102
-                        $system_question_we_want = EEM_Question_Group::system_address;
1103
-                    }
1104
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1105
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1106
-                    } else {
1107
-                        $id_col = EEM_Question_Group::instance()
1108
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1109
-                        if (is_array($id_col)) {
1110
-                            $QSG_ID = reset($id_col);
1111
-                        } else {
1112
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1113
-                            EE_Log::instance()->log(
1114
-                                __FILE__,
1115
-                                __FUNCTION__,
1116
-                                sprintf(
1117
-                                    __(
1118
-                                        'Could not associate question %1$s to a question group because no system question
835
+					'event_espresso'
836
+				),
837
+				__FILE__,
838
+				__FUNCTION__,
839
+				__LINE__
840
+			);
841
+			return false;
842
+		}
843
+		return true;
844
+	}
845
+
846
+
847
+
848
+	/**
849
+	 * initialize_system_questions
850
+	 *
851
+	 * @access public
852
+	 * @static
853
+	 * @return void
854
+	 */
855
+	public static function initialize_system_questions()
856
+	{
857
+		// QUESTION GROUPS
858
+		global $wpdb;
859
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
860
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
861
+		// what we have
862
+		$question_groups = $wpdb->get_col($SQL);
863
+		// check the response
864
+		$question_groups = is_array($question_groups) ? $question_groups : array();
865
+		// what we should have
866
+		$QSG_systems = array(1, 2);
867
+		// loop thru what we should have and compare to what we have
868
+		foreach ($QSG_systems as $QSG_system) {
869
+			// reset values array
870
+			$QSG_values = array();
871
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
872
+			if (! in_array("$QSG_system", $question_groups)) {
873
+				// add it
874
+				switch ($QSG_system) {
875
+					case 1:
876
+						$QSG_values = array(
877
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
878
+							'QSG_identifier'      => 'personal-information-' . time(),
879
+							'QSG_desc'            => '',
880
+							'QSG_order'           => 1,
881
+							'QSG_show_group_name' => 1,
882
+							'QSG_show_group_desc' => 1,
883
+							'QSG_system'          => EEM_Question_Group::system_personal,
884
+							'QSG_deleted'         => 0,
885
+						);
886
+						break;
887
+					case 2:
888
+						$QSG_values = array(
889
+							'QSG_name'            => __('Address Information', 'event_espresso'),
890
+							'QSG_identifier'      => 'address-information-' . time(),
891
+							'QSG_desc'            => '',
892
+							'QSG_order'           => 2,
893
+							'QSG_show_group_name' => 1,
894
+							'QSG_show_group_desc' => 1,
895
+							'QSG_system'          => EEM_Question_Group::system_address,
896
+							'QSG_deleted'         => 0,
897
+						);
898
+						break;
899
+				}
900
+				// make sure we have some values before inserting them
901
+				if (! empty($QSG_values)) {
902
+					// insert system question
903
+					$wpdb->insert(
904
+						$table_name,
905
+						$QSG_values,
906
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
907
+					);
908
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
909
+				}
910
+			}
911
+		}
912
+		// QUESTIONS
913
+		global $wpdb;
914
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
915
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
916
+		// what we have
917
+		$questions = $wpdb->get_col($SQL);
918
+		// what we should have
919
+		$QST_systems = array(
920
+			'fname',
921
+			'lname',
922
+			'email',
923
+			'address',
924
+			'address2',
925
+			'city',
926
+			'country',
927
+			'state',
928
+			'zip',
929
+			'phone',
930
+		);
931
+		$order_for_group_1 = 1;
932
+		$order_for_group_2 = 1;
933
+		// loop thru what we should have and compare to what we have
934
+		foreach ($QST_systems as $QST_system) {
935
+			// reset values array
936
+			$QST_values = array();
937
+			// if we don't have what we should have
938
+			if (! in_array($QST_system, $questions)) {
939
+				// add it
940
+				switch ($QST_system) {
941
+					case 'fname':
942
+						$QST_values = array(
943
+							'QST_display_text'  => __('First Name', 'event_espresso'),
944
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
945
+							'QST_system'        => 'fname',
946
+							'QST_type'          => 'TEXT',
947
+							'QST_required'      => 1,
948
+							'QST_required_text' => __('This field is required', 'event_espresso'),
949
+							'QST_order'         => 1,
950
+							'QST_admin_only'    => 0,
951
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
952
+							'QST_wp_user'       => self::get_default_creator_id(),
953
+							'QST_deleted'       => 0,
954
+						);
955
+						break;
956
+					case 'lname':
957
+						$QST_values = array(
958
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
959
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
960
+							'QST_system'        => 'lname',
961
+							'QST_type'          => 'TEXT',
962
+							'QST_required'      => 1,
963
+							'QST_required_text' => __('This field is required', 'event_espresso'),
964
+							'QST_order'         => 2,
965
+							'QST_admin_only'    => 0,
966
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
967
+							'QST_wp_user'       => self::get_default_creator_id(),
968
+							'QST_deleted'       => 0,
969
+						);
970
+						break;
971
+					case 'email':
972
+						$QST_values = array(
973
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
974
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
975
+							'QST_system'        => 'email',
976
+							'QST_type'          => 'EMAIL',
977
+							'QST_required'      => 1,
978
+							'QST_required_text' => __('This field is required', 'event_espresso'),
979
+							'QST_order'         => 3,
980
+							'QST_admin_only'    => 0,
981
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
982
+							'QST_wp_user'       => self::get_default_creator_id(),
983
+							'QST_deleted'       => 0,
984
+						);
985
+						break;
986
+					case 'address':
987
+						$QST_values = array(
988
+							'QST_display_text'  => __('Address', 'event_espresso'),
989
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
990
+							'QST_system'        => 'address',
991
+							'QST_type'          => 'TEXT',
992
+							'QST_required'      => 0,
993
+							'QST_required_text' => __('This field is required', 'event_espresso'),
994
+							'QST_order'         => 4,
995
+							'QST_admin_only'    => 0,
996
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
997
+							'QST_wp_user'       => self::get_default_creator_id(),
998
+							'QST_deleted'       => 0,
999
+						);
1000
+						break;
1001
+					case 'address2':
1002
+						$QST_values = array(
1003
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1004
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1005
+							'QST_system'        => 'address2',
1006
+							'QST_type'          => 'TEXT',
1007
+							'QST_required'      => 0,
1008
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1009
+							'QST_order'         => 5,
1010
+							'QST_admin_only'    => 0,
1011
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1012
+							'QST_wp_user'       => self::get_default_creator_id(),
1013
+							'QST_deleted'       => 0,
1014
+						);
1015
+						break;
1016
+					case 'city':
1017
+						$QST_values = array(
1018
+							'QST_display_text'  => __('City', 'event_espresso'),
1019
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1020
+							'QST_system'        => 'city',
1021
+							'QST_type'          => 'TEXT',
1022
+							'QST_required'      => 0,
1023
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1024
+							'QST_order'         => 6,
1025
+							'QST_admin_only'    => 0,
1026
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1027
+							'QST_wp_user'       => self::get_default_creator_id(),
1028
+							'QST_deleted'       => 0,
1029
+						);
1030
+						break;
1031
+					case 'country':
1032
+						$QST_values = array(
1033
+							'QST_display_text'  => __('Country', 'event_espresso'),
1034
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1035
+							'QST_system'        => 'country',
1036
+							'QST_type'          => 'COUNTRY',
1037
+							'QST_required'      => 0,
1038
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1039
+							'QST_order'         => 7,
1040
+							'QST_admin_only'    => 0,
1041
+							'QST_wp_user'       => self::get_default_creator_id(),
1042
+							'QST_deleted'       => 0,
1043
+						);
1044
+						break;
1045
+					case 'state':
1046
+						$QST_values = array(
1047
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1048
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1049
+							'QST_system'        => 'state',
1050
+							'QST_type'          => 'STATE',
1051
+							'QST_required'      => 0,
1052
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1053
+							'QST_order'         => 8,
1054
+							'QST_admin_only'    => 0,
1055
+							'QST_wp_user'       => self::get_default_creator_id(),
1056
+							'QST_deleted'       => 0,
1057
+						);
1058
+						break;
1059
+					case 'zip':
1060
+						$QST_values = array(
1061
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1062
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1063
+							'QST_system'        => 'zip',
1064
+							'QST_type'          => 'TEXT',
1065
+							'QST_required'      => 0,
1066
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1067
+							'QST_order'         => 9,
1068
+							'QST_admin_only'    => 0,
1069
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1070
+							'QST_wp_user'       => self::get_default_creator_id(),
1071
+							'QST_deleted'       => 0,
1072
+						);
1073
+						break;
1074
+					case 'phone':
1075
+						$QST_values = array(
1076
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1077
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1078
+							'QST_system'        => 'phone',
1079
+							'QST_type'          => 'TEXT',
1080
+							'QST_required'      => 0,
1081
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1082
+							'QST_order'         => 10,
1083
+							'QST_admin_only'    => 0,
1084
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1085
+							'QST_wp_user'       => self::get_default_creator_id(),
1086
+							'QST_deleted'       => 0,
1087
+						);
1088
+						break;
1089
+				}
1090
+				if (! empty($QST_values)) {
1091
+					// insert system question
1092
+					$wpdb->insert(
1093
+						$table_name,
1094
+						$QST_values,
1095
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1096
+					);
1097
+					$QST_ID = $wpdb->insert_id;
1098
+					// QUESTION GROUP QUESTIONS
1099
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1100
+						$system_question_we_want = EEM_Question_Group::system_personal;
1101
+					} else {
1102
+						$system_question_we_want = EEM_Question_Group::system_address;
1103
+					}
1104
+					if (isset($QSG_IDs[$system_question_we_want])) {
1105
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1106
+					} else {
1107
+						$id_col = EEM_Question_Group::instance()
1108
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1109
+						if (is_array($id_col)) {
1110
+							$QSG_ID = reset($id_col);
1111
+						} else {
1112
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1113
+							EE_Log::instance()->log(
1114
+								__FILE__,
1115
+								__FUNCTION__,
1116
+								sprintf(
1117
+									__(
1118
+										'Could not associate question %1$s to a question group because no system question
1119 1119
                                          group existed',
1120
-                                        'event_espresso'
1121
-                                    ),
1122
-                                    $QST_ID),
1123
-                                'error');
1124
-                            continue;
1125
-                        }
1126
-                    }
1127
-                    // add system questions to groups
1128
-                    $wpdb->insert(
1129
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1130
-                        array(
1131
-                            'QSG_ID'    => $QSG_ID,
1132
-                            'QST_ID'    => $QST_ID,
1133
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1134
-                        ),
1135
-                        array('%d', '%d', '%d')
1136
-                    );
1137
-                }
1138
-            }
1139
-        }
1140
-    }
1141
-
1142
-
1143
-    /**
1144
-     * Makes sure the default payment method (Invoice) is active.
1145
-     * This used to be done automatically as part of constructing the old gateways config
1146
-     *
1147
-     * @throws \EE_Error
1148
-     */
1149
-    public static function insert_default_payment_methods()
1150
-    {
1151
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1152
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1153
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1154
-        } else {
1155
-            EEM_Payment_Method::instance()->verify_button_urls();
1156
-        }
1157
-    }
1158
-
1159
-    /**
1160
-     * insert_default_status_codes
1161
-     *
1162
-     * @access public
1163
-     * @static
1164
-     * @return void
1165
-     */
1166
-    public static function insert_default_status_codes()
1167
-    {
1168
-
1169
-        global $wpdb;
1170
-
1171
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1172
-
1173
-            $table_name = EEM_Status::instance()->table();
1174
-
1175
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1176
-            $wpdb->query($SQL);
1177
-
1178
-            $SQL = "INSERT INTO $table_name
1120
+										'event_espresso'
1121
+									),
1122
+									$QST_ID),
1123
+								'error');
1124
+							continue;
1125
+						}
1126
+					}
1127
+					// add system questions to groups
1128
+					$wpdb->insert(
1129
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1130
+						array(
1131
+							'QSG_ID'    => $QSG_ID,
1132
+							'QST_ID'    => $QST_ID,
1133
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1134
+						),
1135
+						array('%d', '%d', '%d')
1136
+					);
1137
+				}
1138
+			}
1139
+		}
1140
+	}
1141
+
1142
+
1143
+	/**
1144
+	 * Makes sure the default payment method (Invoice) is active.
1145
+	 * This used to be done automatically as part of constructing the old gateways config
1146
+	 *
1147
+	 * @throws \EE_Error
1148
+	 */
1149
+	public static function insert_default_payment_methods()
1150
+	{
1151
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1152
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1153
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1154
+		} else {
1155
+			EEM_Payment_Method::instance()->verify_button_urls();
1156
+		}
1157
+	}
1158
+
1159
+	/**
1160
+	 * insert_default_status_codes
1161
+	 *
1162
+	 * @access public
1163
+	 * @static
1164
+	 * @return void
1165
+	 */
1166
+	public static function insert_default_status_codes()
1167
+	{
1168
+
1169
+		global $wpdb;
1170
+
1171
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1172
+
1173
+			$table_name = EEM_Status::instance()->table();
1174
+
1175
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1176
+			$wpdb->query($SQL);
1177
+
1178
+			$SQL = "INSERT INTO $table_name
1179 1179
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1180 1180
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1181 1181
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1215,523 +1215,523 @@  discard block
 block discarded – undo
1215 1215
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1216 1216
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1217 1217
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1218
-            $wpdb->query($SQL);
1219
-
1220
-        }
1221
-
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * create_upload_directories
1227
-     * Creates folders in the uploads directory to facilitate addons and templates
1228
-     *
1229
-     * @access public
1230
-     * @static
1231
-     * @return boolean success of verifying upload directories exist
1232
-     */
1233
-    public static function create_upload_directories()
1234
-    {
1235
-        // Create the required folders
1236
-        $folders = array(
1237
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1238
-            EVENT_ESPRESSO_GATEWAY_DIR,
1239
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1240
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1241
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1242
-        );
1243
-        foreach ($folders as $folder) {
1244
-            try {
1245
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1246
-                @ chmod($folder, 0755);
1247
-            } catch (EE_Error $e) {
1248
-                EE_Error::add_error(
1249
-                    sprintf(
1250
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1251
-                        $folder,
1252
-                        '<br />' . $e->getMessage()
1253
-                    ),
1254
-                    __FILE__, __FUNCTION__, __LINE__
1255
-                );
1256
-                //indicate we'll need to fix this later
1257
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1258
-                return false;
1259
-            }
1260
-        }
1261
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1262
-        //is disabled, there might be activation errors recorded in there
1263
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1264
-        //remember EE's folders are all good
1265
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1266
-        return true;
1267
-    }
1268
-
1269
-    /**
1270
-     * Whether the upload directories need to be fixed or not.
1271
-     * If EE is installed but filesystem access isn't initially available,
1272
-     * we need to get the user's filesystem credentials and THEN create them,
1273
-     * so there might be period of time when EE is installed but its
1274
-     * upload directories aren't available. This indicates such a state
1275
-     *
1276
-     * @return boolean
1277
-     */
1278
-    public static function upload_directories_incomplete()
1279
-    {
1280
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * generate_default_message_templates
1286
-     *
1287
-     * @static
1288
-     * @throws EE_Error
1289
-     * @return bool     true means new templates were created.
1290
-     *                  false means no templates were created.
1291
-     *                  This is NOT an error flag. To check for errors you will want
1292
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1293
-     */
1294
-    public static function generate_default_message_templates()
1295
-    {
1296
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1297
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1298
-        /*
1218
+			$wpdb->query($SQL);
1219
+
1220
+		}
1221
+
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * create_upload_directories
1227
+	 * Creates folders in the uploads directory to facilitate addons and templates
1228
+	 *
1229
+	 * @access public
1230
+	 * @static
1231
+	 * @return boolean success of verifying upload directories exist
1232
+	 */
1233
+	public static function create_upload_directories()
1234
+	{
1235
+		// Create the required folders
1236
+		$folders = array(
1237
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1238
+			EVENT_ESPRESSO_GATEWAY_DIR,
1239
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1240
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1241
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1242
+		);
1243
+		foreach ($folders as $folder) {
1244
+			try {
1245
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1246
+				@ chmod($folder, 0755);
1247
+			} catch (EE_Error $e) {
1248
+				EE_Error::add_error(
1249
+					sprintf(
1250
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1251
+						$folder,
1252
+						'<br />' . $e->getMessage()
1253
+					),
1254
+					__FILE__, __FUNCTION__, __LINE__
1255
+				);
1256
+				//indicate we'll need to fix this later
1257
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1258
+				return false;
1259
+			}
1260
+		}
1261
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1262
+		//is disabled, there might be activation errors recorded in there
1263
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1264
+		//remember EE's folders are all good
1265
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1266
+		return true;
1267
+	}
1268
+
1269
+	/**
1270
+	 * Whether the upload directories need to be fixed or not.
1271
+	 * If EE is installed but filesystem access isn't initially available,
1272
+	 * we need to get the user's filesystem credentials and THEN create them,
1273
+	 * so there might be period of time when EE is installed but its
1274
+	 * upload directories aren't available. This indicates such a state
1275
+	 *
1276
+	 * @return boolean
1277
+	 */
1278
+	public static function upload_directories_incomplete()
1279
+	{
1280
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * generate_default_message_templates
1286
+	 *
1287
+	 * @static
1288
+	 * @throws EE_Error
1289
+	 * @return bool     true means new templates were created.
1290
+	 *                  false means no templates were created.
1291
+	 *                  This is NOT an error flag. To check for errors you will want
1292
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1293
+	 */
1294
+	public static function generate_default_message_templates()
1295
+	{
1296
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1297
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1298
+		/*
1299 1299
          * This first method is taking care of ensuring any default messengers
1300 1300
          * that should be made active and have templates generated are done.
1301 1301
          */
1302
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1303
-            $message_resource_manager
1304
-        );
1305
-        /**
1306
-         * This method is verifying there are no NEW default message types
1307
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1308
-         */
1309
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1310
-            $message_resource_manager
1311
-        );
1312
-        //after all is done, let's persist these changes to the db.
1313
-        $message_resource_manager->update_has_activated_messengers_option();
1314
-        $message_resource_manager->update_active_messengers_option();
1315
-        // will return true if either of these are true.  Otherwise will return false.
1316
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1317
-    }
1318
-
1319
-
1320
-
1321
-    /**
1322
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1323
-     * @return array|bool
1324
-     * @throws \EE_Error
1325
-     */
1326
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1327
-        EE_Message_Resource_Manager $message_resource_manager
1328
-    ) {
1329
-        /** @type EE_messenger[] $active_messengers */
1330
-        $active_messengers = $message_resource_manager->active_messengers();
1331
-        $installed_message_types = $message_resource_manager->installed_message_types();
1332
-        $templates_created = false;
1333
-        foreach ($active_messengers as $active_messenger) {
1334
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1335
-            $default_message_type_names_to_activate = array();
1336
-            // looping through each default message type reported by the messenger
1337
-            // and setup the actual message types to activate.
1338
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1339
-                // if already active or has already been activated before we skip
1340
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1341
-                // we also skip if the message type is not installed.
1342
-                if (
1343
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1344
-                        $default_message_type_name_for_messenger,
1345
-                        $active_messenger->name
1346
-                    )
1347
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1348
-                        $active_messenger->name,
1349
-                        $default_message_type_name_for_messenger
1350
-                    )
1351
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1352
-                ) {
1353
-                    continue;
1354
-                }
1355
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1356
-            }
1357
-            //let's activate!
1358
-            $message_resource_manager->ensure_message_types_are_active(
1359
-                $default_message_type_names_to_activate,
1360
-                $active_messenger->name,
1361
-                false
1362
-            );
1363
-            //activate the templates for these message types
1364
-            if ( ! empty($default_message_type_names_to_activate)) {
1365
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1366
-                    $active_messenger->name,
1367
-                    $default_message_type_names_for_messenger,
1368
-                    '',
1369
-                    true
1370
-                );
1371
-            }
1372
-        }
1373
-        return $templates_created;
1374
-    }
1375
-
1376
-
1377
-
1378
-    /**
1379
-     * This will activate and generate default messengers and default message types for those messengers.
1380
-     *
1381
-     * @param EE_message_Resource_Manager $message_resource_manager
1382
-     * @return array|bool  True means there were default messengers and message type templates generated.
1383
-     *                     False means that there were no templates generated
1384
-     *                     (which could simply mean there are no default message types for a messenger).
1385
-     * @throws EE_Error
1386
-     */
1387
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1388
-        EE_Message_Resource_Manager $message_resource_manager
1389
-    ) {
1390
-        /** @type EE_messenger[] $messengers_to_generate */
1391
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1392
-        $installed_message_types = $message_resource_manager->installed_message_types();
1393
-        $templates_generated = false;
1394
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1395
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1396
-            //verify the default message types match an installed message type.
1397
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1398
-                if (
1399
-                    ! isset($installed_message_types[$name])
1400
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1401
-                        $name,
1402
-                        $messenger_to_generate->name
1403
-                    )
1404
-                ) {
1405
-                    unset($default_message_type_names_for_messenger[$key]);
1406
-                }
1407
-            }
1408
-            // in previous iterations, the active_messengers option in the db
1409
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1410
-            // This comment is left here just in case we discover that we _do_ need to update before
1411
-            // passing off to create templates (after the refactor is done).
1412
-            // @todo remove this comment when determined not necessary.
1413
-            $message_resource_manager->activate_messenger(
1414
-                $messenger_to_generate->name,
1415
-                $default_message_type_names_for_messenger,
1416
-                false
1417
-            );
1418
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1419
-            if ( ! empty($default_message_type_names_for_messenger)) {
1420
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1421
-                    $messenger_to_generate->name,
1422
-                    $default_message_type_names_for_messenger,
1423
-                    '',
1424
-                    true
1425
-                );
1426
-            }
1427
-        }
1428
-        return $templates_generated;
1429
-    }
1430
-
1431
-
1432
-    /**
1433
-     * This returns the default messengers to generate templates for on activation of EE.
1434
-     * It considers:
1435
-     * - whether a messenger is already active in the db.
1436
-     * - whether a messenger has been made active at any time in the past.
1437
-     *
1438
-     * @static
1439
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1440
-     * @return EE_messenger[]
1441
-     */
1442
-    protected static function _get_default_messengers_to_generate_on_activation(
1443
-        EE_Message_Resource_Manager $message_resource_manager
1444
-    ) {
1445
-        // make sure EED_Messages is loaded because it sets the autoloaders
1446
-        require_once EE_MODULES . 'messages' . DS . 'EED_Messages.module.php';
1447
-        $active_messengers    = $message_resource_manager->active_messengers();
1448
-        $installed_messengers = $message_resource_manager->installed_messengers();
1449
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1450
-
1451
-        $messengers_to_generate = array();
1452
-        foreach ($installed_messengers as $installed_messenger) {
1453
-            //if installed messenger is a messenger that should be activated on install
1454
-            //and is not already active
1455
-            //and has never been activated
1456
-            if (
1457
-                ! $installed_messenger->activate_on_install
1458
-                || isset($active_messengers[$installed_messenger->name])
1459
-                || isset($has_activated[$installed_messenger->name])
1460
-            ) {
1461
-                continue;
1462
-            }
1463
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1464
-        }
1465
-        return $messengers_to_generate;
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * This simply validates active message types to ensure they actually match installed
1471
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1472
-     * rows are set inactive.
1473
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1474
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1475
-     * are still handled in here.
1476
-     *
1477
-     * @since 4.3.1
1478
-     * @return void
1479
-     */
1480
-    public static function validate_messages_system()
1481
-    {
1482
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1483
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1484
-        $message_resource_manager->validate_active_message_types_are_installed();
1485
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1486
-    }
1487
-
1488
-
1489
-    /**
1490
-     * create_no_ticket_prices_array
1491
-     *
1492
-     * @access public
1493
-     * @static
1494
-     * @return void
1495
-     */
1496
-    public static function create_no_ticket_prices_array()
1497
-    {
1498
-        // this creates an array for tracking events that have no active ticket prices created
1499
-        // this allows us to warn admins of the situation so that it can be corrected
1500
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1501
-        if (! $espresso_no_ticket_prices) {
1502
-            add_option('ee_no_ticket_prices', array(), '', false);
1503
-        }
1504
-    }
1505
-
1506
-
1507
-    /**
1508
-     * plugin_deactivation
1509
-     *
1510
-     * @access public
1511
-     * @static
1512
-     * @return void
1513
-     */
1514
-    public static function plugin_deactivation()
1515
-    {
1516
-    }
1517
-
1518
-
1519
-    /**
1520
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1521
-     * (like post meta or term relations)
1522
-     *
1523
-     * @global wpdb $wpdb
1524
-     * @throws \EE_Error
1525
-     */
1526
-    public static function delete_all_espresso_cpt_data()
1527
-    {
1528
-        global $wpdb;
1529
-        //get all the CPT post_types
1530
-        $ee_post_types = array();
1531
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1532
-            if (method_exists($model_name, 'instance')) {
1533
-                $model_obj = call_user_func(array($model_name, 'instance'));
1534
-                if ($model_obj instanceof EEM_CPT_Base) {
1535
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1536
-                }
1537
-            }
1538
-        }
1539
-        //get all our CPTs
1540
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1541
-        $cpt_ids = $wpdb->get_col($query);
1542
-        //delete each post meta and term relations too
1543
-        foreach ($cpt_ids as $post_id) {
1544
-            wp_delete_post($post_id, true);
1545
-        }
1546
-    }
1547
-
1548
-    /**
1549
-     * Deletes all EE custom tables
1550
-     *
1551
-     * @return array
1552
-     */
1553
-    public static function drop_espresso_tables()
1554
-    {
1555
-        $tables = array();
1556
-        // load registry
1557
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1558
-            if (method_exists($model_name, 'instance')) {
1559
-                $model_obj = call_user_func(array($model_name, 'instance'));
1560
-                if ($model_obj instanceof EEM_Base) {
1561
-                    foreach ($model_obj->get_tables() as $table) {
1562
-                        if (strpos($table->get_table_name(), 'esp_')
1563
-                            &&
1564
-                            (
1565
-                                is_main_site()//main site? nuke them all
1566
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1567
-                            )
1568
-                        ) {
1569
-                            $tables[$table->get_table_name()] = $table->get_table_name();
1570
-                        }
1571
-                    }
1572
-                }
1573
-            }
1574
-        }
1575
-
1576
-        //there are some tables whose models were removed.
1577
-        //they should be removed when removing all EE core's data
1578
-        $tables_without_models = array(
1579
-            'esp_promotion',
1580
-            'esp_promotion_applied',
1581
-            'esp_promotion_object',
1582
-            'esp_promotion_rule',
1583
-            'esp_rule',
1584
-        );
1585
-        foreach ($tables_without_models as $table) {
1586
-            $tables[$table] = $table;
1587
-        }
1588
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1589
-    }
1590
-
1591
-
1592
-
1593
-    /**
1594
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1595
-     * each table name provided has a wpdb prefix attached, and that it exists.
1596
-     * Returns the list actually deleted
1597
-     *
1598
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1599
-     * @global WPDB $wpdb
1600
-     * @param array $table_names
1601
-     * @return array of table names which we deleted
1602
-     */
1603
-    public static function drop_tables($table_names)
1604
-    {
1605
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1606
-    }
1607
-
1608
-
1609
-
1610
-    /**
1611
-     * plugin_uninstall
1612
-     *
1613
-     * @access public
1614
-     * @static
1615
-     * @param bool $remove_all
1616
-     * @return void
1617
-     */
1618
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1619
-    {
1620
-        global $wpdb;
1621
-        self::drop_espresso_tables();
1622
-        $wp_options_to_delete = array(
1623
-            'ee_no_ticket_prices'                => true,
1624
-            'ee_active_messengers'               => true,
1625
-            'ee_has_activated_messenger'         => true,
1626
-            'ee_flush_rewrite_rules'             => true,
1627
-            'ee_config'                          => false,
1628
-            'ee_data_migration_current_db_state' => true,
1629
-            'ee_data_migration_mapping_'         => false,
1630
-            'ee_data_migration_script_'          => false,
1631
-            'ee_data_migrations'                 => true,
1632
-            'ee_dms_map'                         => false,
1633
-            'ee_notices'                         => true,
1634
-            'lang_file_check_'                   => false,
1635
-            'ee_maintenance_mode'                => true,
1636
-            'ee_ueip_optin'                      => true,
1637
-            'ee_ueip_has_notified'               => true,
1638
-            'ee_plugin_activation_errors'        => true,
1639
-            'ee_id_mapping_from'                 => false,
1640
-            'espresso_persistent_admin_notices'  => true,
1641
-            'ee_encryption_key'                  => true,
1642
-            'pue_force_upgrade_'                 => false,
1643
-            'pue_json_error_'                    => false,
1644
-            'pue_install_key_'                   => false,
1645
-            'pue_verification_error_'            => false,
1646
-            'pu_dismissed_upgrade_'              => false,
1647
-            'external_updates-'                  => false,
1648
-            'ee_extra_data'                      => true,
1649
-            'ee_ssn_'                            => false,
1650
-            'ee_rss_'                            => false,
1651
-            'ee_rte_n_tx_'                       => false,
1652
-            'ee_pers_admin_notices'              => true,
1653
-            'ee_job_parameters_'                 => false,
1654
-            'ee_upload_directories_incomplete'   => true,
1655
-            'ee_verified_db_collations'          => true,
1656
-        );
1657
-        if (is_main_site()) {
1658
-            $wp_options_to_delete['ee_network_config'] = true;
1659
-        }
1660
-        $undeleted_options = array();
1661
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1662
-            if ($no_wildcard) {
1663
-                if ( ! delete_option($option_name)) {
1664
-                    $undeleted_options[] = $option_name;
1665
-                }
1666
-            } else {
1667
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1668
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1669
-                    if ( ! delete_option($option_name_from_wildcard)) {
1670
-                        $undeleted_options[] = $option_name_from_wildcard;
1671
-                    }
1672
-                }
1673
-            }
1674
-        }
1675
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1676
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1677
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1678
-            $db_update_sans_ee4 = array();
1679
-            foreach ($espresso_db_update as $version => $times_activated) {
1680
-                if ((string)$version[0] === '3') {//if its NON EE4
1681
-                    $db_update_sans_ee4[$version] = $times_activated;
1682
-                }
1683
-            }
1684
-            update_option('espresso_db_update', $db_update_sans_ee4);
1685
-        }
1686
-        $errors = '';
1687
-        if ( ! empty($undeleted_options)) {
1688
-            $errors .= sprintf(
1689
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1690
-                '<br/>',
1691
-                implode(',<br/>', $undeleted_options)
1692
-            );
1693
-        }
1694
-        if ( ! empty($errors)) {
1695
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1696
-        }
1697
-    }
1698
-
1699
-    /**
1700
-     * Gets the mysql error code from the last used query by wpdb
1701
-     *
1702
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1703
-     */
1704
-    public static function last_wpdb_error_code()
1705
-    {
1706
-        global $wpdb;
1707
-        if ($wpdb->use_mysqli) {
1708
-            return mysqli_errno($wpdb->dbh);
1709
-        } else {
1710
-            return mysql_errno($wpdb->dbh);
1711
-        }
1712
-    }
1713
-
1714
-    /**
1715
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1716
-     *
1717
-     * @global wpdb  $wpdb
1718
-     * @deprecated instead use TableAnalysis::tableExists()
1719
-     * @param string $table_name with or without $wpdb->prefix
1720
-     * @return boolean
1721
-     */
1722
-    public static function table_exists($table_name)
1723
-    {
1724
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1725
-    }
1726
-
1727
-    /**
1728
-     * Resets the cache on EEH_Activation
1729
-     */
1730
-    public static function reset()
1731
-    {
1732
-        self::$_default_creator_id                             = null;
1733
-        self::$_initialized_db_content_already_in_this_request = false;
1734
-    }
1302
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1303
+			$message_resource_manager
1304
+		);
1305
+		/**
1306
+		 * This method is verifying there are no NEW default message types
1307
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1308
+		 */
1309
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1310
+			$message_resource_manager
1311
+		);
1312
+		//after all is done, let's persist these changes to the db.
1313
+		$message_resource_manager->update_has_activated_messengers_option();
1314
+		$message_resource_manager->update_active_messengers_option();
1315
+		// will return true if either of these are true.  Otherwise will return false.
1316
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1317
+	}
1318
+
1319
+
1320
+
1321
+	/**
1322
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1323
+	 * @return array|bool
1324
+	 * @throws \EE_Error
1325
+	 */
1326
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1327
+		EE_Message_Resource_Manager $message_resource_manager
1328
+	) {
1329
+		/** @type EE_messenger[] $active_messengers */
1330
+		$active_messengers = $message_resource_manager->active_messengers();
1331
+		$installed_message_types = $message_resource_manager->installed_message_types();
1332
+		$templates_created = false;
1333
+		foreach ($active_messengers as $active_messenger) {
1334
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1335
+			$default_message_type_names_to_activate = array();
1336
+			// looping through each default message type reported by the messenger
1337
+			// and setup the actual message types to activate.
1338
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1339
+				// if already active or has already been activated before we skip
1340
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1341
+				// we also skip if the message type is not installed.
1342
+				if (
1343
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1344
+						$default_message_type_name_for_messenger,
1345
+						$active_messenger->name
1346
+					)
1347
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1348
+						$active_messenger->name,
1349
+						$default_message_type_name_for_messenger
1350
+					)
1351
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1352
+				) {
1353
+					continue;
1354
+				}
1355
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1356
+			}
1357
+			//let's activate!
1358
+			$message_resource_manager->ensure_message_types_are_active(
1359
+				$default_message_type_names_to_activate,
1360
+				$active_messenger->name,
1361
+				false
1362
+			);
1363
+			//activate the templates for these message types
1364
+			if ( ! empty($default_message_type_names_to_activate)) {
1365
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1366
+					$active_messenger->name,
1367
+					$default_message_type_names_for_messenger,
1368
+					'',
1369
+					true
1370
+				);
1371
+			}
1372
+		}
1373
+		return $templates_created;
1374
+	}
1375
+
1376
+
1377
+
1378
+	/**
1379
+	 * This will activate and generate default messengers and default message types for those messengers.
1380
+	 *
1381
+	 * @param EE_message_Resource_Manager $message_resource_manager
1382
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1383
+	 *                     False means that there were no templates generated
1384
+	 *                     (which could simply mean there are no default message types for a messenger).
1385
+	 * @throws EE_Error
1386
+	 */
1387
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1388
+		EE_Message_Resource_Manager $message_resource_manager
1389
+	) {
1390
+		/** @type EE_messenger[] $messengers_to_generate */
1391
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1392
+		$installed_message_types = $message_resource_manager->installed_message_types();
1393
+		$templates_generated = false;
1394
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1395
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1396
+			//verify the default message types match an installed message type.
1397
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1398
+				if (
1399
+					! isset($installed_message_types[$name])
1400
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1401
+						$name,
1402
+						$messenger_to_generate->name
1403
+					)
1404
+				) {
1405
+					unset($default_message_type_names_for_messenger[$key]);
1406
+				}
1407
+			}
1408
+			// in previous iterations, the active_messengers option in the db
1409
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1410
+			// This comment is left here just in case we discover that we _do_ need to update before
1411
+			// passing off to create templates (after the refactor is done).
1412
+			// @todo remove this comment when determined not necessary.
1413
+			$message_resource_manager->activate_messenger(
1414
+				$messenger_to_generate->name,
1415
+				$default_message_type_names_for_messenger,
1416
+				false
1417
+			);
1418
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1419
+			if ( ! empty($default_message_type_names_for_messenger)) {
1420
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1421
+					$messenger_to_generate->name,
1422
+					$default_message_type_names_for_messenger,
1423
+					'',
1424
+					true
1425
+				);
1426
+			}
1427
+		}
1428
+		return $templates_generated;
1429
+	}
1430
+
1431
+
1432
+	/**
1433
+	 * This returns the default messengers to generate templates for on activation of EE.
1434
+	 * It considers:
1435
+	 * - whether a messenger is already active in the db.
1436
+	 * - whether a messenger has been made active at any time in the past.
1437
+	 *
1438
+	 * @static
1439
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1440
+	 * @return EE_messenger[]
1441
+	 */
1442
+	protected static function _get_default_messengers_to_generate_on_activation(
1443
+		EE_Message_Resource_Manager $message_resource_manager
1444
+	) {
1445
+		// make sure EED_Messages is loaded because it sets the autoloaders
1446
+		require_once EE_MODULES . 'messages' . DS . 'EED_Messages.module.php';
1447
+		$active_messengers    = $message_resource_manager->active_messengers();
1448
+		$installed_messengers = $message_resource_manager->installed_messengers();
1449
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1450
+
1451
+		$messengers_to_generate = array();
1452
+		foreach ($installed_messengers as $installed_messenger) {
1453
+			//if installed messenger is a messenger that should be activated on install
1454
+			//and is not already active
1455
+			//and has never been activated
1456
+			if (
1457
+				! $installed_messenger->activate_on_install
1458
+				|| isset($active_messengers[$installed_messenger->name])
1459
+				|| isset($has_activated[$installed_messenger->name])
1460
+			) {
1461
+				continue;
1462
+			}
1463
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1464
+		}
1465
+		return $messengers_to_generate;
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * This simply validates active message types to ensure they actually match installed
1471
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1472
+	 * rows are set inactive.
1473
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1474
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1475
+	 * are still handled in here.
1476
+	 *
1477
+	 * @since 4.3.1
1478
+	 * @return void
1479
+	 */
1480
+	public static function validate_messages_system()
1481
+	{
1482
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1483
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1484
+		$message_resource_manager->validate_active_message_types_are_installed();
1485
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1486
+	}
1487
+
1488
+
1489
+	/**
1490
+	 * create_no_ticket_prices_array
1491
+	 *
1492
+	 * @access public
1493
+	 * @static
1494
+	 * @return void
1495
+	 */
1496
+	public static function create_no_ticket_prices_array()
1497
+	{
1498
+		// this creates an array for tracking events that have no active ticket prices created
1499
+		// this allows us to warn admins of the situation so that it can be corrected
1500
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1501
+		if (! $espresso_no_ticket_prices) {
1502
+			add_option('ee_no_ticket_prices', array(), '', false);
1503
+		}
1504
+	}
1505
+
1506
+
1507
+	/**
1508
+	 * plugin_deactivation
1509
+	 *
1510
+	 * @access public
1511
+	 * @static
1512
+	 * @return void
1513
+	 */
1514
+	public static function plugin_deactivation()
1515
+	{
1516
+	}
1517
+
1518
+
1519
+	/**
1520
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1521
+	 * (like post meta or term relations)
1522
+	 *
1523
+	 * @global wpdb $wpdb
1524
+	 * @throws \EE_Error
1525
+	 */
1526
+	public static function delete_all_espresso_cpt_data()
1527
+	{
1528
+		global $wpdb;
1529
+		//get all the CPT post_types
1530
+		$ee_post_types = array();
1531
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1532
+			if (method_exists($model_name, 'instance')) {
1533
+				$model_obj = call_user_func(array($model_name, 'instance'));
1534
+				if ($model_obj instanceof EEM_CPT_Base) {
1535
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1536
+				}
1537
+			}
1538
+		}
1539
+		//get all our CPTs
1540
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1541
+		$cpt_ids = $wpdb->get_col($query);
1542
+		//delete each post meta and term relations too
1543
+		foreach ($cpt_ids as $post_id) {
1544
+			wp_delete_post($post_id, true);
1545
+		}
1546
+	}
1547
+
1548
+	/**
1549
+	 * Deletes all EE custom tables
1550
+	 *
1551
+	 * @return array
1552
+	 */
1553
+	public static function drop_espresso_tables()
1554
+	{
1555
+		$tables = array();
1556
+		// load registry
1557
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1558
+			if (method_exists($model_name, 'instance')) {
1559
+				$model_obj = call_user_func(array($model_name, 'instance'));
1560
+				if ($model_obj instanceof EEM_Base) {
1561
+					foreach ($model_obj->get_tables() as $table) {
1562
+						if (strpos($table->get_table_name(), 'esp_')
1563
+							&&
1564
+							(
1565
+								is_main_site()//main site? nuke them all
1566
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1567
+							)
1568
+						) {
1569
+							$tables[$table->get_table_name()] = $table->get_table_name();
1570
+						}
1571
+					}
1572
+				}
1573
+			}
1574
+		}
1575
+
1576
+		//there are some tables whose models were removed.
1577
+		//they should be removed when removing all EE core's data
1578
+		$tables_without_models = array(
1579
+			'esp_promotion',
1580
+			'esp_promotion_applied',
1581
+			'esp_promotion_object',
1582
+			'esp_promotion_rule',
1583
+			'esp_rule',
1584
+		);
1585
+		foreach ($tables_without_models as $table) {
1586
+			$tables[$table] = $table;
1587
+		}
1588
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1589
+	}
1590
+
1591
+
1592
+
1593
+	/**
1594
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1595
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1596
+	 * Returns the list actually deleted
1597
+	 *
1598
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1599
+	 * @global WPDB $wpdb
1600
+	 * @param array $table_names
1601
+	 * @return array of table names which we deleted
1602
+	 */
1603
+	public static function drop_tables($table_names)
1604
+	{
1605
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1606
+	}
1607
+
1608
+
1609
+
1610
+	/**
1611
+	 * plugin_uninstall
1612
+	 *
1613
+	 * @access public
1614
+	 * @static
1615
+	 * @param bool $remove_all
1616
+	 * @return void
1617
+	 */
1618
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1619
+	{
1620
+		global $wpdb;
1621
+		self::drop_espresso_tables();
1622
+		$wp_options_to_delete = array(
1623
+			'ee_no_ticket_prices'                => true,
1624
+			'ee_active_messengers'               => true,
1625
+			'ee_has_activated_messenger'         => true,
1626
+			'ee_flush_rewrite_rules'             => true,
1627
+			'ee_config'                          => false,
1628
+			'ee_data_migration_current_db_state' => true,
1629
+			'ee_data_migration_mapping_'         => false,
1630
+			'ee_data_migration_script_'          => false,
1631
+			'ee_data_migrations'                 => true,
1632
+			'ee_dms_map'                         => false,
1633
+			'ee_notices'                         => true,
1634
+			'lang_file_check_'                   => false,
1635
+			'ee_maintenance_mode'                => true,
1636
+			'ee_ueip_optin'                      => true,
1637
+			'ee_ueip_has_notified'               => true,
1638
+			'ee_plugin_activation_errors'        => true,
1639
+			'ee_id_mapping_from'                 => false,
1640
+			'espresso_persistent_admin_notices'  => true,
1641
+			'ee_encryption_key'                  => true,
1642
+			'pue_force_upgrade_'                 => false,
1643
+			'pue_json_error_'                    => false,
1644
+			'pue_install_key_'                   => false,
1645
+			'pue_verification_error_'            => false,
1646
+			'pu_dismissed_upgrade_'              => false,
1647
+			'external_updates-'                  => false,
1648
+			'ee_extra_data'                      => true,
1649
+			'ee_ssn_'                            => false,
1650
+			'ee_rss_'                            => false,
1651
+			'ee_rte_n_tx_'                       => false,
1652
+			'ee_pers_admin_notices'              => true,
1653
+			'ee_job_parameters_'                 => false,
1654
+			'ee_upload_directories_incomplete'   => true,
1655
+			'ee_verified_db_collations'          => true,
1656
+		);
1657
+		if (is_main_site()) {
1658
+			$wp_options_to_delete['ee_network_config'] = true;
1659
+		}
1660
+		$undeleted_options = array();
1661
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1662
+			if ($no_wildcard) {
1663
+				if ( ! delete_option($option_name)) {
1664
+					$undeleted_options[] = $option_name;
1665
+				}
1666
+			} else {
1667
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1668
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1669
+					if ( ! delete_option($option_name_from_wildcard)) {
1670
+						$undeleted_options[] = $option_name_from_wildcard;
1671
+					}
1672
+				}
1673
+			}
1674
+		}
1675
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1676
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1677
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1678
+			$db_update_sans_ee4 = array();
1679
+			foreach ($espresso_db_update as $version => $times_activated) {
1680
+				if ((string)$version[0] === '3') {//if its NON EE4
1681
+					$db_update_sans_ee4[$version] = $times_activated;
1682
+				}
1683
+			}
1684
+			update_option('espresso_db_update', $db_update_sans_ee4);
1685
+		}
1686
+		$errors = '';
1687
+		if ( ! empty($undeleted_options)) {
1688
+			$errors .= sprintf(
1689
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1690
+				'<br/>',
1691
+				implode(',<br/>', $undeleted_options)
1692
+			);
1693
+		}
1694
+		if ( ! empty($errors)) {
1695
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1696
+		}
1697
+	}
1698
+
1699
+	/**
1700
+	 * Gets the mysql error code from the last used query by wpdb
1701
+	 *
1702
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1703
+	 */
1704
+	public static function last_wpdb_error_code()
1705
+	{
1706
+		global $wpdb;
1707
+		if ($wpdb->use_mysqli) {
1708
+			return mysqli_errno($wpdb->dbh);
1709
+		} else {
1710
+			return mysql_errno($wpdb->dbh);
1711
+		}
1712
+	}
1713
+
1714
+	/**
1715
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1716
+	 *
1717
+	 * @global wpdb  $wpdb
1718
+	 * @deprecated instead use TableAnalysis::tableExists()
1719
+	 * @param string $table_name with or without $wpdb->prefix
1720
+	 * @return boolean
1721
+	 */
1722
+	public static function table_exists($table_name)
1723
+	{
1724
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1725
+	}
1726
+
1727
+	/**
1728
+	 * Resets the cache on EEH_Activation
1729
+	 */
1730
+	public static function reset()
1731
+	{
1732
+		self::$_default_creator_id                             = null;
1733
+		self::$_initialized_db_content_already_in_this_request = false;
1734
+	}
1735 1735
 }
1736 1736
 // End of file EEH_Activation.helper.php
1737 1737
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 1 patch
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -24,211 +24,211 @@  discard block
 block discarded – undo
24 24
 class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App
25 25
 {
26 26
 
27
-    /**
28
-     * @type LoaderInterface $loader
29
-     */
30
-    protected $loader;
31
-
32
-    /**
33
-     * @var EE_Request $request
34
-     */
35
-    protected $request;
36
-
37
-    /**
38
-     * @var EE_Response $response
39
-     */
40
-    protected $response;
41
-
42
-    /**
43
-     * @var EE_Dependency_Map $dependency_map
44
-     */
45
-    protected $dependency_map;
46
-
47
-    /**
48
-     * @var EE_Registry $registry
49
-     */
50
-    protected $registry;
51
-
52
-
53
-
54
-    /**
55
-     * EE_Load_Espresso_Core constructor
56
-     */
57
-    public function __construct()
58
-    {
59
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * handle
66
-     * sets hooks for running rest of system
67
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
-     * starting EE Addons from any other point may lead to problems
69
-     *
70
-     * @param EE_Request  $request
71
-     * @param EE_Response $response
72
-     * @return EE_Response
73
-     * @throws EE_Error
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     * @throws InvalidArgumentException
77
-     */
78
-    public function handle_request(EE_Request $request, EE_Response $response)
79
-    {
80
-        $this->request = $request;
81
-        $this->response = $response;
82
-        // info about how to load classes required by other classes
83
-        $this->dependency_map = $this->_load_dependency_map();
84
-        // central repository for classes
85
-        $this->registry = $this->_load_registry();
86
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
87
-        $this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
88
-        $this->dependency_map->setLoader($this->loader);
89
-        // build DI container
90
-        // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
91
-        // $OpenCoffeeShop->addRecipes();
92
-        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
93
-        // workarounds for PHP < 5.3
94
-        $this->_load_class_tools();
95
-        // load interfaces
96
-        espresso_load_required('EEI_Payment_Method_Interfaces',
97
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
98
-        // deprecated functions
99
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
100
-        // WP cron jobs
101
-        $this->registry->load_core('Cron_Tasks');
102
-        $this->registry->load_core('EE_Request_Handler');
103
-        $this->registry->load_core('EE_System');
104
-        return $this->response;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @return EE_Request
111
-     */
112
-    public function request()
113
-    {
114
-        return $this->request;
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * @return EE_Response
121
-     */
122
-    public function response()
123
-    {
124
-        return $this->response;
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     * @return EE_Dependency_Map
131
-     * @throws EE_Error
132
-     */
133
-    public function dependency_map()
134
-    {
135
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
136
-            throw new EE_Error(
137
-                sprintf(
138
-                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
139
-                    print_r($this->dependency_map, true)
140
-                )
141
-            );
142
-        }
143
-        return $this->dependency_map;
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @return EE_Registry
150
-     * @throws EE_Error
151
-     */
152
-    public function registry()
153
-    {
154
-        if (! $this->registry instanceof EE_Registry) {
155
-            throw new EE_Error(
156
-                sprintf(
157
-                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
158
-                    print_r($this->registry, true)
159
-                )
160
-            );
161
-        }
162
-        return $this->registry;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @return EE_Dependency_Map
169
-     */
170
-    private function _load_dependency_map()
171
-    {
172
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
173
-            EE_Error::add_error(
174
-                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
175
-                __FILE__, __FUNCTION__, __LINE__
176
-            );
177
-            wp_die(EE_Error::get_notices());
178
-        }
179
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
180
-        return EE_Dependency_Map::instance($this->request, $this->response);
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * @return EE_Registry
187
-     */
188
-    private function _load_registry()
189
-    {
190
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
191
-            EE_Error::add_error(
192
-                __('The EE_Registry core class could not be loaded.', 'event_espresso'),
193
-                __FILE__, __FUNCTION__, __LINE__
194
-            );
195
-            wp_die(EE_Error::get_notices());
196
-        }
197
-        require_once(EE_CORE . 'EE_Registry.core.php');
198
-        return EE_Registry::instance($this->dependency_map);
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * @return void
205
-     */
206
-    private function _load_class_tools()
207
-    {
208
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
209
-            EE_Error::add_error(
210
-                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
211
-                __FILE__, __FUNCTION__, __LINE__
212
-            );
213
-        }
214
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * called after the request stack has been fully processed
221
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
222
-     *
223
-     * @param EE_Request  $request
224
-     * @param EE_Response $response
225
-     */
226
-    public function handle_response(EE_Request $request, EE_Response $response)
227
-    {
228
-        if ($response->plugin_deactivated()) {
229
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
230
-        }
231
-    }
27
+	/**
28
+	 * @type LoaderInterface $loader
29
+	 */
30
+	protected $loader;
31
+
32
+	/**
33
+	 * @var EE_Request $request
34
+	 */
35
+	protected $request;
36
+
37
+	/**
38
+	 * @var EE_Response $response
39
+	 */
40
+	protected $response;
41
+
42
+	/**
43
+	 * @var EE_Dependency_Map $dependency_map
44
+	 */
45
+	protected $dependency_map;
46
+
47
+	/**
48
+	 * @var EE_Registry $registry
49
+	 */
50
+	protected $registry;
51
+
52
+
53
+
54
+	/**
55
+	 * EE_Load_Espresso_Core constructor
56
+	 */
57
+	public function __construct()
58
+	{
59
+		espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * handle
66
+	 * sets hooks for running rest of system
67
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
+	 * starting EE Addons from any other point may lead to problems
69
+	 *
70
+	 * @param EE_Request  $request
71
+	 * @param EE_Response $response
72
+	 * @return EE_Response
73
+	 * @throws EE_Error
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 * @throws InvalidArgumentException
77
+	 */
78
+	public function handle_request(EE_Request $request, EE_Response $response)
79
+	{
80
+		$this->request = $request;
81
+		$this->response = $response;
82
+		// info about how to load classes required by other classes
83
+		$this->dependency_map = $this->_load_dependency_map();
84
+		// central repository for classes
85
+		$this->registry = $this->_load_registry();
86
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
87
+		$this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
88
+		$this->dependency_map->setLoader($this->loader);
89
+		// build DI container
90
+		// $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
91
+		// $OpenCoffeeShop->addRecipes();
92
+		// $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
93
+		// workarounds for PHP < 5.3
94
+		$this->_load_class_tools();
95
+		// load interfaces
96
+		espresso_load_required('EEI_Payment_Method_Interfaces',
97
+			EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
98
+		// deprecated functions
99
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
100
+		// WP cron jobs
101
+		$this->registry->load_core('Cron_Tasks');
102
+		$this->registry->load_core('EE_Request_Handler');
103
+		$this->registry->load_core('EE_System');
104
+		return $this->response;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @return EE_Request
111
+	 */
112
+	public function request()
113
+	{
114
+		return $this->request;
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * @return EE_Response
121
+	 */
122
+	public function response()
123
+	{
124
+		return $this->response;
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 * @return EE_Dependency_Map
131
+	 * @throws EE_Error
132
+	 */
133
+	public function dependency_map()
134
+	{
135
+		if (! $this->dependency_map instanceof EE_Dependency_Map) {
136
+			throw new EE_Error(
137
+				sprintf(
138
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
139
+					print_r($this->dependency_map, true)
140
+				)
141
+			);
142
+		}
143
+		return $this->dependency_map;
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @return EE_Registry
150
+	 * @throws EE_Error
151
+	 */
152
+	public function registry()
153
+	{
154
+		if (! $this->registry instanceof EE_Registry) {
155
+			throw new EE_Error(
156
+				sprintf(
157
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
158
+					print_r($this->registry, true)
159
+				)
160
+			);
161
+		}
162
+		return $this->registry;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @return EE_Dependency_Map
169
+	 */
170
+	private function _load_dependency_map()
171
+	{
172
+		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
173
+			EE_Error::add_error(
174
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
175
+				__FILE__, __FUNCTION__, __LINE__
176
+			);
177
+			wp_die(EE_Error::get_notices());
178
+		}
179
+		require_once(EE_CORE . 'EE_Dependency_Map.core.php');
180
+		return EE_Dependency_Map::instance($this->request, $this->response);
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * @return EE_Registry
187
+	 */
188
+	private function _load_registry()
189
+	{
190
+		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
191
+			EE_Error::add_error(
192
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
193
+				__FILE__, __FUNCTION__, __LINE__
194
+			);
195
+			wp_die(EE_Error::get_notices());
196
+		}
197
+		require_once(EE_CORE . 'EE_Registry.core.php');
198
+		return EE_Registry::instance($this->dependency_map);
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * @return void
205
+	 */
206
+	private function _load_class_tools()
207
+	{
208
+		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
209
+			EE_Error::add_error(
210
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
211
+				__FILE__, __FUNCTION__, __LINE__
212
+			);
213
+		}
214
+		require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * called after the request stack has been fully processed
221
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
222
+	 *
223
+	 * @param EE_Request  $request
224
+	 * @param EE_Response $response
225
+	 */
226
+	public function handle_response(EE_Request $request, EE_Response $response)
227
+	{
228
+		if ($response->plugin_deactivated()) {
229
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
230
+		}
231
+	}
232 232
 
233 233
 
234 234
 
Please login to merge, or discard this patch.