Completed
Branch BUG-10209-session-encoding (55265b)
by
unknown
63:54 queued 51:59
created
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +3605 added lines, -3605 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,2203 +17,2203 @@  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_message',
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
-                    'messages_overview_other_help_tab'                          => array(
531
-                        'title'    => __('Messages Other', 'event_espresso'),
532
-                        'filename' => 'messages_overview_other',
533
-                    ),
534
-                ),
535
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
536
-                'require_nonce' => false
537
-            ),
538
-            'custom_mtps'              => array(
539
-                'nav'           => array(
540
-                    'label' => __('Custom Message Templates', 'event_espresso'),
541
-                    'order' => 30
542
-                ),
543
-                'help_tabs'     => array(),
544
-                'help_tour'     => array(),
545
-                'require_nonce' => false
546
-            ),
547
-            'add_new_message_template' => array(
548
-                'nav'           => array(
549
-                    'label'      => __('Add New Message Templates', 'event_espresso'),
550
-                    'order'      => 5,
551
-                    'persistent' => false
552
-                ),
553
-                'require_nonce' => false
554
-            ),
555
-            'edit_message_template'    => array(
556
-                'labels'        => array(
557
-                    'buttons'    => array(
558
-                        'reset' => __('Reset Templates'),
559
-                    ),
560
-                    'publishbox' => __('Update Actions', 'event_espresso')
561
-                ),
562
-                'nav'           => array(
563
-                    'label'      => __('Edit Message Templates', 'event_espresso'),
564
-                    'order'      => 5,
565
-                    'persistent' => false,
566
-                    'url'        => ''
567
-                ),
568
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
569
-                'has_metaboxes' => true,
570
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
571
-                'help_tabs'     => array(
572
-                    'edit_message_template'       => array(
573
-                        'title'    => __('Message Template Editor', 'event_espresso'),
574
-                        'callback' => 'edit_message_template_help_tab'
575
-                    ),
576
-                    'message_templates_help_tab'  => array(
577
-                        'title'    => __('Message Templates', 'event_espresso'),
578
-                        'filename' => 'messages_templates'
579
-                    ),
580
-                    'message_template_shortcodes' => array(
581
-                        'title'    => __('Message Shortcodes', 'event_espresso'),
582
-                        'callback' => 'message_template_shortcodes_help_tab'
583
-                    ),
584
-                    'message_preview_help_tab'    => array(
585
-                        'title'    => __('Message Preview', 'event_espresso'),
586
-                        'filename' => 'messages_preview'
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_message',
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
+					'messages_overview_other_help_tab'                          => array(
531
+						'title'    => __('Messages Other', 'event_espresso'),
532
+						'filename' => 'messages_overview_other',
533
+					),
534
+				),
535
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
536
+				'require_nonce' => false
537
+			),
538
+			'custom_mtps'              => array(
539
+				'nav'           => array(
540
+					'label' => __('Custom Message Templates', 'event_espresso'),
541
+					'order' => 30
542
+				),
543
+				'help_tabs'     => array(),
544
+				'help_tour'     => array(),
545
+				'require_nonce' => false
546
+			),
547
+			'add_new_message_template' => array(
548
+				'nav'           => array(
549
+					'label'      => __('Add New Message Templates', 'event_espresso'),
550
+					'order'      => 5,
551
+					'persistent' => false
552
+				),
553
+				'require_nonce' => false
554
+			),
555
+			'edit_message_template'    => array(
556
+				'labels'        => array(
557
+					'buttons'    => array(
558
+						'reset' => __('Reset Templates'),
559
+					),
560
+					'publishbox' => __('Update Actions', 'event_espresso')
561
+				),
562
+				'nav'           => array(
563
+					'label'      => __('Edit Message Templates', 'event_espresso'),
564
+					'order'      => 5,
565
+					'persistent' => false,
566
+					'url'        => ''
567
+				),
568
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
569
+				'has_metaboxes' => true,
570
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
571
+				'help_tabs'     => array(
572
+					'edit_message_template'       => array(
573
+						'title'    => __('Message Template Editor', 'event_espresso'),
574
+						'callback' => 'edit_message_template_help_tab'
575
+					),
576
+					'message_templates_help_tab'  => array(
577
+						'title'    => __('Message Templates', 'event_espresso'),
578
+						'filename' => 'messages_templates'
579
+					),
580
+					'message_template_shortcodes' => array(
581
+						'title'    => __('Message Shortcodes', 'event_espresso'),
582
+						'callback' => 'message_template_shortcodes_help_tab'
583
+					),
584
+					'message_preview_help_tab'    => array(
585
+						'title'    => __('Message Preview', 'event_espresso'),
586
+						'filename' => 'messages_preview'
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
-    }
783
-    
784
-    
785
-    public function load_scripts_styles_edit_message_template()
786
-    {
787
-        
788
-        $this->_set_shortcodes();
781
+		return $mce_css;
782
+	}
783
+    
784
+    
785
+	public function load_scripts_styles_edit_message_template()
786
+	{
787
+        
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');
798
-        
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
-            EVENT_ESPRESSO_VERSION);
801
-        
802
-        wp_enqueue_script('ee_admin_js');
803
-        wp_enqueue_script('ee_msgs_edit_js');
804
-        
805
-        //add in special css for tiny_mce
806
-        add_filter('mce_css', array($this, 'wp_editor_css'));
807
-    }
808
-    
809
-    
810
-    public function load_scripts_styles_display_preview_message()
811
-    {
812
-        
813
-        $this->_set_message_template_group();
814
-        
815
-        if (isset($this->_req_data['messenger'])) {
816
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
-        }
818
-        
819
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820
-        
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
-    }
826
-    
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');
834
-        
835
-        wp_enqueue_script('ee-messages-settings');
836
-    }
837
-    
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
-                'bulk_action' => array(
850
-                    'trash_message_template' => __('Move to Trash', 'event_espresso')
851
-                )
852
-            )
853
-        );
854
-    }
855
-    
856
-    
857
-    /**
858
-     * set views array for message queue list table
859
-     */
860
-    public function _set_list_table_views_default()
861
-    {
862
-        EE_Registry::instance()->load_helper('Template');
863
-        
864
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
865
-            'message_list_table_bulk_actions')
866
-            ? array(
867
-                'generate_now'          => __('Generate Now', 'event_espresso'),
868
-                'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
869
-                'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
870
-                'send_now'              => __('Send Now', 'event_espresso')
871
-            )
872
-            : array();
873
-        
874
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
875
-            'message_list_table_bulk_actions')
876
-            ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
877
-            : array();
878
-        
879
-        
880
-        $this->_views = array(
881
-            'all' => array(
882
-                'slug'        => 'all',
883
-                'label'       => __('All', 'event_espresso'),
884
-                'count'       => 0,
885
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
886
-            )
887
-        );
888
-        
889
-        
890
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
891
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
892
-                continue;
893
-            }
894
-            $status_bulk_actions = $common_bulk_actions;
895
-            //unset bulk actions not applying to status
896
-            if ( ! empty($status_bulk_actions)) {
897
-                switch ($status) {
898
-                    case EEM_Message::status_idle :
899
-                    case EEM_Message::status_resend :
900
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
901
-                        break;
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
+        
799
+		wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
+			EVENT_ESPRESSO_VERSION);
801
+        
802
+		wp_enqueue_script('ee_admin_js');
803
+		wp_enqueue_script('ee_msgs_edit_js');
804
+        
805
+		//add in special css for tiny_mce
806
+		add_filter('mce_css', array($this, 'wp_editor_css'));
807
+	}
808
+    
809
+    
810
+	public function load_scripts_styles_display_preview_message()
811
+	{
812
+        
813
+		$this->_set_message_template_group();
814
+        
815
+		if (isset($this->_req_data['messenger'])) {
816
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
+		}
818
+        
819
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820
+        
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
+	}
826
+    
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');
834
+        
835
+		wp_enqueue_script('ee-messages-settings');
836
+	}
837
+    
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
+				'bulk_action' => array(
850
+					'trash_message_template' => __('Move to Trash', 'event_espresso')
851
+				)
852
+			)
853
+		);
854
+	}
855
+    
856
+    
857
+	/**
858
+	 * set views array for message queue list table
859
+	 */
860
+	public function _set_list_table_views_default()
861
+	{
862
+		EE_Registry::instance()->load_helper('Template');
863
+        
864
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
865
+			'message_list_table_bulk_actions')
866
+			? array(
867
+				'generate_now'          => __('Generate Now', 'event_espresso'),
868
+				'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
869
+				'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
870
+				'send_now'              => __('Send Now', 'event_espresso')
871
+			)
872
+			: array();
873
+        
874
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
875
+			'message_list_table_bulk_actions')
876
+			? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
877
+			: array();
878
+        
879
+        
880
+		$this->_views = array(
881
+			'all' => array(
882
+				'slug'        => 'all',
883
+				'label'       => __('All', 'event_espresso'),
884
+				'count'       => 0,
885
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
886
+			)
887
+		);
888
+        
889
+        
890
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
891
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
892
+				continue;
893
+			}
894
+			$status_bulk_actions = $common_bulk_actions;
895
+			//unset bulk actions not applying to status
896
+			if ( ! empty($status_bulk_actions)) {
897
+				switch ($status) {
898
+					case EEM_Message::status_idle :
899
+					case EEM_Message::status_resend :
900
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
901
+						break;
902 902
                     
903
-                    case EEM_Message::status_failed :
904
-                    case EEM_Message::status_debug_only :
905
-                        $status_bulk_actions = array();
906
-                        break;
903
+					case EEM_Message::status_failed :
904
+					case EEM_Message::status_debug_only :
905
+						$status_bulk_actions = array();
906
+						break;
907 907
                     
908
-                    case EEM_Message::status_incomplete :
909
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
910
-                        break;
908
+					case EEM_Message::status_incomplete :
909
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
910
+						break;
911 911
                     
912
-                    case EEM_Message::status_retry :
913
-                    case EEM_Message::status_sent :
914
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
915
-                        break;
916
-                }
917
-            }
912
+					case EEM_Message::status_retry :
913
+					case EEM_Message::status_sent :
914
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
915
+						break;
916
+				}
917
+			}
918 918
             
919
-            $this->_views[strtolower($status)] = array(
920
-                'slug'        => strtolower($status),
921
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
922
-                'count'       => 0,
923
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
924
-            );
925
-        }
926
-    }
927
-    
928
-    
929
-    protected function _ee_default_messages_overview_list_table()
930
-    {
931
-        $this->_admin_page_title = __('Default Message Templates', 'event_espresso');
932
-        $this->display_admin_list_table_page_with_no_sidebar();
933
-    }
934
-    
935
-    
936
-    protected function _message_queue_list_table()
937
-    {
938
-        $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
939
-        $this->_template_args['per_column']        = 6;
940
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
941
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
942
-        $this->display_admin_list_table_page_with_no_sidebar();
943
-    }
944
-    
945
-    
946
-    protected function _message_legend_items()
947
-    {
948
-        
949
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
950
-        $action_items       = array();
951
-        
952
-        foreach ($action_css_classes as $action_item => $action_details) {
953
-            if ($action_item === 'see_notifications_for') {
954
-                continue;
955
-            }
956
-            $action_items[$action_item] = array(
957
-                'class' => $action_details['css_class'],
958
-                'desc'  => $action_details['label']
959
-            );
960
-        }
961
-        
962
-        /** @type array $status_items status legend setup */
963
-        $status_items = array(
964
-            'sent_status'       => array(
965
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
966
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
967
-            ),
968
-            'idle_status'       => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
970
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
971
-            ),
972
-            'failed_status'     => array(
973
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
974
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
975
-            ),
976
-            'resend_status'     => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
978
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
979
-            ),
980
-            'incomplete_status' => array(
981
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
982
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
983
-            ),
984
-            'retry_status'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
986
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
987
-            )
988
-        );
989
-        if (EEM_Message::debug()) {
990
-            $status_items['debug_only_status'] = array(
991
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
992
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
993
-            );
994
-        }
995
-        
996
-        return array_merge($action_items, $status_items);
997
-    }
998
-    
999
-    
1000
-    protected function _custom_mtps_preview()
1001
-    {
1002
-        $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1003
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1004
-                'event_espresso') . '" />';
1005
-        $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the caffeinated version of Event Espresso.  With the Custom Message Templates feature, you are able to create custom templates and set them per event.',
1006
-                'event_espresso') . '</strong>';
1007
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1008
-    }
1009
-    
1010
-    
1011
-    /**
1012
-     * get_message_templates
1013
-     * This gets all the message templates for listing on the overview list.
1014
-     *
1015
-     * @access public
1016
-     *
1017
-     * @param int    $perpage the amount of templates groups to show per page
1018
-     * @param string $type    the current _view we're getting templates for
1019
-     * @param bool   $count   return count?
1020
-     * @param bool   $all     disregard any paging info (get all data);
1021
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1022
-     *
1023
-     * @return array
1024
-     */
1025
-    public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1026
-    {
1027
-        
1028
-        $MTP = EEM_Message_Template_Group::instance();
1029
-        
1030
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1031
-        $orderby                    = $this->_req_data['orderby'];
1032
-        
1033
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1034
-        
1035
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1036
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1037
-        
1038
-        $offset = ($current_page - 1) * $per_page;
1039
-        $limit  = $all ? null : array($offset, $per_page);
1040
-        
1041
-        
1042
-        //options will match what is in the _views array property
1043
-        switch ($type) {
919
+			$this->_views[strtolower($status)] = array(
920
+				'slug'        => strtolower($status),
921
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
922
+				'count'       => 0,
923
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
924
+			);
925
+		}
926
+	}
927
+    
928
+    
929
+	protected function _ee_default_messages_overview_list_table()
930
+	{
931
+		$this->_admin_page_title = __('Default Message Templates', 'event_espresso');
932
+		$this->display_admin_list_table_page_with_no_sidebar();
933
+	}
934
+    
935
+    
936
+	protected function _message_queue_list_table()
937
+	{
938
+		$this->_search_btn_label                   = __('Message Activity', 'event_espresso');
939
+		$this->_template_args['per_column']        = 6;
940
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
941
+		$this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
942
+		$this->display_admin_list_table_page_with_no_sidebar();
943
+	}
944
+    
945
+    
946
+	protected function _message_legend_items()
947
+	{
948
+        
949
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
950
+		$action_items       = array();
951
+        
952
+		foreach ($action_css_classes as $action_item => $action_details) {
953
+			if ($action_item === 'see_notifications_for') {
954
+				continue;
955
+			}
956
+			$action_items[$action_item] = array(
957
+				'class' => $action_details['css_class'],
958
+				'desc'  => $action_details['label']
959
+			);
960
+		}
961
+        
962
+		/** @type array $status_items status legend setup */
963
+		$status_items = array(
964
+			'sent_status'       => array(
965
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
966
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
967
+			),
968
+			'idle_status'       => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
970
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
971
+			),
972
+			'failed_status'     => array(
973
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
974
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
975
+			),
976
+			'resend_status'     => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
978
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
979
+			),
980
+			'incomplete_status' => array(
981
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
982
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
983
+			),
984
+			'retry_status'      => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
986
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
987
+			)
988
+		);
989
+		if (EEM_Message::debug()) {
990
+			$status_items['debug_only_status'] = array(
991
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
992
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
993
+			);
994
+		}
995
+        
996
+		return array_merge($action_items, $status_items);
997
+	}
998
+    
999
+    
1000
+	protected function _custom_mtps_preview()
1001
+	{
1002
+		$this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1003
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1004
+				'event_espresso') . '" />';
1005
+		$this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the caffeinated version of Event Espresso.  With the Custom Message Templates feature, you are able to create custom templates and set them per event.',
1006
+				'event_espresso') . '</strong>';
1007
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1008
+	}
1009
+    
1010
+    
1011
+	/**
1012
+	 * get_message_templates
1013
+	 * This gets all the message templates for listing on the overview list.
1014
+	 *
1015
+	 * @access public
1016
+	 *
1017
+	 * @param int    $perpage the amount of templates groups to show per page
1018
+	 * @param string $type    the current _view we're getting templates for
1019
+	 * @param bool   $count   return count?
1020
+	 * @param bool   $all     disregard any paging info (get all data);
1021
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1022
+	 *
1023
+	 * @return array
1024
+	 */
1025
+	public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1026
+	{
1027
+        
1028
+		$MTP = EEM_Message_Template_Group::instance();
1029
+        
1030
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1031
+		$orderby                    = $this->_req_data['orderby'];
1032
+        
1033
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1034
+        
1035
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1036
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1037
+        
1038
+		$offset = ($current_page - 1) * $per_page;
1039
+		$limit  = $all ? null : array($offset, $per_page);
1040
+        
1041
+        
1042
+		//options will match what is in the _views array property
1043
+		switch ($type) {
1044 1044
             
1045
-            case 'in_use':
1046
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1047
-                break;
1045
+			case 'in_use':
1046
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1047
+				break;
1048 1048
             
1049
-            default:
1050
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1049
+			default:
1050
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1051 1051
             
1052
-        }
1053
-        
1054
-        return $templates;
1055
-    }
1056
-    
1057
-    
1058
-    /**
1059
-     * filters etc might need a list of installed message_types
1060
-     * @return array an array of message type objects
1061
-     */
1062
-    public function get_installed_message_types()
1063
-    {
1064
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1065
-        $installed               = array();
1066
-        
1067
-        foreach ($installed_message_types as $message_type) {
1068
-            $installed[$message_type->name] = $message_type;
1069
-        }
1070
-        
1071
-        return $installed;
1072
-    }
1073
-    
1074
-    
1075
-    /**
1076
-     * _add_message_template
1077
-     *
1078
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1079
-     *
1080
-     * @param string $message_type
1081
-     * @param string $messenger
1082
-     * @param string $GRP_ID
1083
-     *
1084
-     * @throws EE_error
1085
-     */
1086
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1087
-    {
1088
-        //set values override any request data
1089
-        $message_type = ! empty($message_type) ? $message_type : '';
1090
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1091
-        
1092
-        $messenger = ! empty($messenger) ? $messenger : '';
1093
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1094
-        
1095
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1096
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1097
-        
1098
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1099
-        if (empty($message_type) || empty($messenger)) {
1100
-            throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1101
-                'event_espresso'));
1102
-        }
1103
-        
1104
-        //we need the GRP_ID for the template being used as the base for the new template
1105
-        if (empty($GRP_ID)) {
1106
-            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',
1107
-                'event_espresso'));
1108
-        }
1109
-        
1110
-        //let's just make sure the template gets generated!
1111
-        
1112
-        //we need to reassign some variables for what the insert is expecting
1113
-        $this->_req_data['MTP_messenger']    = $messenger;
1114
-        $this->_req_data['MTP_message_type'] = $message_type;
1115
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1116
-        $this->_insert_or_update_message_template(true);
1117
-    }
1118
-    
1119
-    
1120
-    /**
1121
-     * public wrapper for the _add_message_template method
1122
-     *
1123
-     * @param string $message_type     message type slug
1124
-     * @param string $messenger        messenger slug
1125
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1126
-     *                                 off of.
1127
-     */
1128
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1129
-    {
1130
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1131
-    }
1132
-    
1133
-    
1134
-    /**
1135
-     * _edit_message_template
1136
-     *
1137
-     * @access protected
1138
-     * @return void
1139
-     */
1140
-    protected function _edit_message_template()
1141
-    {
1142
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1143
-        $template_fields = '';
1144
-        $sidebar_fields  = '';
1145
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1146
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1147
-        
1148
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1149
-            ? absint($this->_req_data['id'])
1150
-            : false;
1151
-        
1152
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1153
-        $message_template_group = $this->_message_template_group;
1154
-        $c_label                = $message_template_group->context_label();
1155
-        $c_config               = $message_template_group->contexts_config();
1156
-        
1157
-        reset($c_config);
1158
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1159
-            ? strtolower($this->_req_data['context'])
1160
-            : key($c_config);
1161
-        
1162
-        
1163
-        if (empty($GRP_ID)) {
1164
-            $action = 'insert_message_template';
1165
-            //$button_both = false;
1166
-            //$button_text = array( __( 'Save','event_espresso') );
1167
-            //$button_actions = array('something_different');
1168
-            //$referrer = false;
1169
-            $edit_message_template_form_url = add_query_arg(
1170
-                array('action' => $action, 'noheader' => true),
1171
-                EE_MSG_ADMIN_URL
1172
-            );
1173
-        } else {
1174
-            $action = 'update_message_template';
1175
-            //$button_both = true;
1176
-            //$button_text = array();
1177
-            //$button_actions = array();
1178
-            //$referrer = $this->_admin_base_url;
1179
-            $edit_message_template_form_url = add_query_arg(
1180
-                array('action' => $action, 'noheader' => true),
1181
-                EE_MSG_ADMIN_URL
1182
-            );
1183
-        }
1184
-        
1185
-        //set active messenger for this view
1186
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1187
-            $message_template_group->messenger()
1188
-        );
1189
-        $this->_active_message_type_name = $message_template_group->message_type();
1190
-        
1191
-        
1192
-        //Do we have any validation errors?
1193
-        $validators = $this->_get_transient();
1194
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1195
-        
1196
-        
1197
-        //we need to assemble the title from Various details
1198
-        $context_label = sprintf(
1199
-            __('(%s %s)', 'event_espresso'),
1200
-            $c_config[$context]['label'],
1201
-            ucwords($c_label['label'])
1202
-        );
1203
-        
1204
-        $title = sprintf(
1205
-            __(' %s %s Template %s', 'event_espresso'),
1206
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1207
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1208
-            $context_label
1209
-        );
1210
-        
1211
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1212
-        $this->_template_args['message_template'] = $message_template_group;
1213
-        $this->_template_args['is_extra_fields']  = false;
1214
-        
1215
-        
1216
-        //let's get EEH_MSG_Template so we can get template form fields
1217
-        $template_field_structure = EEH_MSG_Template::get_fields(
1218
-            $message_template_group->messenger(),
1219
-            $message_template_group->message_type()
1220
-        );
1221
-        
1222
-        if ( ! $template_field_structure) {
1223
-            $template_field_structure = false;
1224
-            $template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1225
-                'event_espresso');
1226
-        }
1227
-        
1228
-        
1229
-        $message_templates = $message_template_group->context_templates();
1230
-        
1231
-        
1232
-        //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.
1233
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1234
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1235
-                unset($template_field_structure[$context][$reference_field]);
1236
-            }
1237
-        }
1238
-        
1239
-        //let's loop through the template_field_structure and actually assemble the input fields!
1240
-        if ( ! empty($template_field_structure)) {
1241
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1242
-                //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.
1243
-                if ($template_field == 'extra') {
1244
-                    $this->_template_args['is_extra_fields'] = true;
1245
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1246
-                        $message_template = $message_templates[$context][$reference_field];
1247
-                        $content          = $message_template instanceof EE_Message_Template
1248
-                            ? $message_template->get('MTP_content')
1249
-                            : '';
1250
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1251
-                            //let's verify if we need this extra field via the shortcodes parameter.
1252
-                            $continue = false;
1253
-                            if (isset($extra_array['shortcodes_required'])) {
1254
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1255
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1256
-                                        $continue = true;
1257
-                                    }
1258
-                                }
1259
-                                if ($continue) {
1260
-                                    continue;
1261
-                                }
1262
-                            }
1052
+		}
1053
+        
1054
+		return $templates;
1055
+	}
1056
+    
1057
+    
1058
+	/**
1059
+	 * filters etc might need a list of installed message_types
1060
+	 * @return array an array of message type objects
1061
+	 */
1062
+	public function get_installed_message_types()
1063
+	{
1064
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1065
+		$installed               = array();
1066
+        
1067
+		foreach ($installed_message_types as $message_type) {
1068
+			$installed[$message_type->name] = $message_type;
1069
+		}
1070
+        
1071
+		return $installed;
1072
+	}
1073
+    
1074
+    
1075
+	/**
1076
+	 * _add_message_template
1077
+	 *
1078
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1079
+	 *
1080
+	 * @param string $message_type
1081
+	 * @param string $messenger
1082
+	 * @param string $GRP_ID
1083
+	 *
1084
+	 * @throws EE_error
1085
+	 */
1086
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1087
+	{
1088
+		//set values override any request data
1089
+		$message_type = ! empty($message_type) ? $message_type : '';
1090
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1091
+        
1092
+		$messenger = ! empty($messenger) ? $messenger : '';
1093
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1094
+        
1095
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1096
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1097
+        
1098
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1099
+		if (empty($message_type) || empty($messenger)) {
1100
+			throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1101
+				'event_espresso'));
1102
+		}
1103
+        
1104
+		//we need the GRP_ID for the template being used as the base for the new template
1105
+		if (empty($GRP_ID)) {
1106
+			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',
1107
+				'event_espresso'));
1108
+		}
1109
+        
1110
+		//let's just make sure the template gets generated!
1111
+        
1112
+		//we need to reassign some variables for what the insert is expecting
1113
+		$this->_req_data['MTP_messenger']    = $messenger;
1114
+		$this->_req_data['MTP_message_type'] = $message_type;
1115
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1116
+		$this->_insert_or_update_message_template(true);
1117
+	}
1118
+    
1119
+    
1120
+	/**
1121
+	 * public wrapper for the _add_message_template method
1122
+	 *
1123
+	 * @param string $message_type     message type slug
1124
+	 * @param string $messenger        messenger slug
1125
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1126
+	 *                                 off of.
1127
+	 */
1128
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1129
+	{
1130
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1131
+	}
1132
+    
1133
+    
1134
+	/**
1135
+	 * _edit_message_template
1136
+	 *
1137
+	 * @access protected
1138
+	 * @return void
1139
+	 */
1140
+	protected function _edit_message_template()
1141
+	{
1142
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1143
+		$template_fields = '';
1144
+		$sidebar_fields  = '';
1145
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1146
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1147
+        
1148
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1149
+			? absint($this->_req_data['id'])
1150
+			: false;
1151
+        
1152
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1153
+		$message_template_group = $this->_message_template_group;
1154
+		$c_label                = $message_template_group->context_label();
1155
+		$c_config               = $message_template_group->contexts_config();
1156
+        
1157
+		reset($c_config);
1158
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1159
+			? strtolower($this->_req_data['context'])
1160
+			: key($c_config);
1161
+        
1162
+        
1163
+		if (empty($GRP_ID)) {
1164
+			$action = 'insert_message_template';
1165
+			//$button_both = false;
1166
+			//$button_text = array( __( 'Save','event_espresso') );
1167
+			//$button_actions = array('something_different');
1168
+			//$referrer = false;
1169
+			$edit_message_template_form_url = add_query_arg(
1170
+				array('action' => $action, 'noheader' => true),
1171
+				EE_MSG_ADMIN_URL
1172
+			);
1173
+		} else {
1174
+			$action = 'update_message_template';
1175
+			//$button_both = true;
1176
+			//$button_text = array();
1177
+			//$button_actions = array();
1178
+			//$referrer = $this->_admin_base_url;
1179
+			$edit_message_template_form_url = add_query_arg(
1180
+				array('action' => $action, 'noheader' => true),
1181
+				EE_MSG_ADMIN_URL
1182
+			);
1183
+		}
1184
+        
1185
+		//set active messenger for this view
1186
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1187
+			$message_template_group->messenger()
1188
+		);
1189
+		$this->_active_message_type_name = $message_template_group->message_type();
1190
+        
1191
+        
1192
+		//Do we have any validation errors?
1193
+		$validators = $this->_get_transient();
1194
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1195
+        
1196
+        
1197
+		//we need to assemble the title from Various details
1198
+		$context_label = sprintf(
1199
+			__('(%s %s)', 'event_espresso'),
1200
+			$c_config[$context]['label'],
1201
+			ucwords($c_label['label'])
1202
+		);
1203
+        
1204
+		$title = sprintf(
1205
+			__(' %s %s Template %s', 'event_espresso'),
1206
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1207
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1208
+			$context_label
1209
+		);
1210
+        
1211
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1212
+		$this->_template_args['message_template'] = $message_template_group;
1213
+		$this->_template_args['is_extra_fields']  = false;
1214
+        
1215
+        
1216
+		//let's get EEH_MSG_Template so we can get template form fields
1217
+		$template_field_structure = EEH_MSG_Template::get_fields(
1218
+			$message_template_group->messenger(),
1219
+			$message_template_group->message_type()
1220
+		);
1221
+        
1222
+		if ( ! $template_field_structure) {
1223
+			$template_field_structure = false;
1224
+			$template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1225
+				'event_espresso');
1226
+		}
1227
+        
1228
+        
1229
+		$message_templates = $message_template_group->context_templates();
1230
+        
1231
+        
1232
+		//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.
1233
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1234
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1235
+				unset($template_field_structure[$context][$reference_field]);
1236
+			}
1237
+		}
1238
+        
1239
+		//let's loop through the template_field_structure and actually assemble the input fields!
1240
+		if ( ! empty($template_field_structure)) {
1241
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1242
+				//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.
1243
+				if ($template_field == 'extra') {
1244
+					$this->_template_args['is_extra_fields'] = true;
1245
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1246
+						$message_template = $message_templates[$context][$reference_field];
1247
+						$content          = $message_template instanceof EE_Message_Template
1248
+							? $message_template->get('MTP_content')
1249
+							: '';
1250
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1251
+							//let's verify if we need this extra field via the shortcodes parameter.
1252
+							$continue = false;
1253
+							if (isset($extra_array['shortcodes_required'])) {
1254
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1255
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1256
+										$continue = true;
1257
+									}
1258
+								}
1259
+								if ($continue) {
1260
+									continue;
1261
+								}
1262
+							}
1263 1263
                             
1264
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1265
-                            $template_form_fields[$field_id]         = $extra_array;
1266
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1267
-                            $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1264
+							$field_id                                = $reference_field . '-' . $extra_field . '-content';
1265
+							$template_form_fields[$field_id]         = $extra_array;
1266
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1267
+							$css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1268 1268
                             
1269
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1270
-                                                                            && in_array($extra_field, $v_fields)
1271
-                                                                            &&
1272
-                                                                            (
1273
-                                                                                is_array($validators[$extra_field])
1274
-                                                                                && isset($validators[$extra_field]['msg'])
1275
-                                                                            )
1276
-                                ? 'validate-error ' . $css_class
1277
-                                : $css_class;
1269
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1270
+																			&& in_array($extra_field, $v_fields)
1271
+																			&&
1272
+																			(
1273
+																				is_array($validators[$extra_field])
1274
+																				&& isset($validators[$extra_field]['msg'])
1275
+																			)
1276
+								? 'validate-error ' . $css_class
1277
+								: $css_class;
1278 1278
                             
1279
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1280
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1281
-                                : '';
1279
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1280
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1281
+								: '';
1282 1282
                             
1283
-                            //do we have a validation error?  if we do then let's use that value instead
1284
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1283
+							//do we have a validation error?  if we do then let's use that value instead
1284
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1285 1285
                             
1286 1286
                             
1287
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1287
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1288 1288
                             
1289
-                            //shortcode selector
1290
-                            $field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1291
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1292
-                                $field_name_to_use,
1293
-                                $field_id
1294
-                            );
1289
+							//shortcode selector
1290
+							$field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1291
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1292
+								$field_name_to_use,
1293
+								$field_id
1294
+							);
1295 1295
                             
1296
-                            if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1297
-                                //we want to decode the entities
1298
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1299
-                                    html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1300
-                                );
1296
+							if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1297
+								//we want to decode the entities
1298
+								$template_form_fields[$field_id]['value'] = stripslashes(
1299
+									html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1300
+								);
1301 1301
                                 
1302
-                            }/**/
1303
-                        }
1304
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1305
-                        $templatefield_templatename_id = $reference_field . '-name';
1302
+							}/**/
1303
+						}
1304
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1305
+						$templatefield_templatename_id = $reference_field . '-name';
1306 1306
                         
1307
-                        $template_form_fields[$templatefield_MTP_id] = array(
1308
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1309
-                            'label'      => null,
1310
-                            'input'      => 'hidden',
1311
-                            'type'       => 'int',
1312
-                            'required'   => false,
1313
-                            'validation' => false,
1314
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1315
-                            'css_class'  => '',
1316
-                            'format'     => '%d',
1317
-                            'db-col'     => 'MTP_ID'
1318
-                        );
1307
+						$template_form_fields[$templatefield_MTP_id] = array(
1308
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1309
+							'label'      => null,
1310
+							'input'      => 'hidden',
1311
+							'type'       => 'int',
1312
+							'required'   => false,
1313
+							'validation' => false,
1314
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1315
+							'css_class'  => '',
1316
+							'format'     => '%d',
1317
+							'db-col'     => 'MTP_ID'
1318
+						);
1319 1319
                         
1320
-                        $template_form_fields[$templatefield_templatename_id] = array(
1321
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1322
-                            'label'      => null,
1323
-                            'input'      => 'hidden',
1324
-                            'type'       => 'string',
1325
-                            'required'   => false,
1326
-                            'validation' => true,
1327
-                            'value'      => $reference_field,
1328
-                            'css_class'  => '',
1329
-                            'format'     => '%s',
1330
-                            'db-col'     => 'MTP_template_field'
1331
-                        );
1332
-                    }
1333
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1334
-                } else {
1335
-                    $field_id                                 = $template_field . '-content';
1336
-                    $template_form_fields[$field_id]          = $field_setup_array;
1337
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1338
-                    $message_template                         = isset($message_templates[$context][$template_field])
1339
-                        ? $message_templates[$context][$template_field]
1340
-                        : null;
1341
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1342
-                                                                && is_array($message_templates[$context])
1343
-                                                                && $message_template instanceof EE_Message_Template
1344
-                        ? $message_template->get('MTP_content')
1345
-                        : '';
1320
+						$template_form_fields[$templatefield_templatename_id] = array(
1321
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1322
+							'label'      => null,
1323
+							'input'      => 'hidden',
1324
+							'type'       => 'string',
1325
+							'required'   => false,
1326
+							'validation' => true,
1327
+							'value'      => $reference_field,
1328
+							'css_class'  => '',
1329
+							'format'     => '%s',
1330
+							'db-col'     => 'MTP_template_field'
1331
+						);
1332
+					}
1333
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1334
+				} else {
1335
+					$field_id                                 = $template_field . '-content';
1336
+					$template_form_fields[$field_id]          = $field_setup_array;
1337
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1338
+					$message_template                         = isset($message_templates[$context][$template_field])
1339
+						? $message_templates[$context][$template_field]
1340
+						: null;
1341
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1342
+																&& is_array($message_templates[$context])
1343
+																&& $message_template instanceof EE_Message_Template
1344
+						? $message_template->get('MTP_content')
1345
+						: '';
1346 1346
                     
1347
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1348
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1349
-                        ? $validators[$template_field]['value']
1350
-                        : $template_form_fields[$field_id]['value'];
1347
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1348
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1349
+						? $validators[$template_field]['value']
1350
+						: $template_form_fields[$field_id]['value'];
1351 1351
                     
1352 1352
                     
1353
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1354
-                    $css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1355
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1356
-                                                                    && in_array($template_field, $v_fields)
1357
-                                                                    && isset($validators[$template_field]['msg'])
1358
-                        ? 'validate-error ' . $css_class
1359
-                        : $css_class;
1353
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1354
+					$css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1355
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1356
+																	&& in_array($template_field, $v_fields)
1357
+																	&& isset($validators[$template_field]['msg'])
1358
+						? 'validate-error ' . $css_class
1359
+						: $css_class;
1360 1360
                     
1361
-                    //shortcode selector
1362
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1363
-                        $template_field, $field_id
1364
-                    );
1365
-                }
1361
+					//shortcode selector
1362
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1363
+						$template_field, $field_id
1364
+					);
1365
+				}
1366 1366
                 
1367
-                //k took care of content field(s) now let's take care of others.
1367
+				//k took care of content field(s) now let's take care of others.
1368 1368
                 
1369
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1370
-                $templatefield_field_templatename_id = $template_field . '-name';
1369
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1370
+				$templatefield_field_templatename_id = $template_field . '-name';
1371 1371
                 
1372
-                //foreach template field there are actually two form fields created
1373
-                $template_form_fields[$templatefield_MTP_id] = array(
1374
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1375
-                    'label'      => null,
1376
-                    'input'      => 'hidden',
1377
-                    'type'       => 'int',
1378
-                    'required'   => false,
1379
-                    'validation' => true,
1380
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1381
-                    'css_class'  => '',
1382
-                    'format'     => '%d',
1383
-                    'db-col'     => 'MTP_ID'
1384
-                );
1372
+				//foreach template field there are actually two form fields created
1373
+				$template_form_fields[$templatefield_MTP_id] = array(
1374
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1375
+					'label'      => null,
1376
+					'input'      => 'hidden',
1377
+					'type'       => 'int',
1378
+					'required'   => false,
1379
+					'validation' => true,
1380
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1381
+					'css_class'  => '',
1382
+					'format'     => '%d',
1383
+					'db-col'     => 'MTP_ID'
1384
+				);
1385 1385
                 
1386
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1387
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1388
-                    'label'      => null,
1389
-                    'input'      => 'hidden',
1390
-                    'type'       => 'string',
1391
-                    'required'   => false,
1392
-                    'validation' => true,
1393
-                    'value'      => $template_field,
1394
-                    'css_class'  => '',
1395
-                    'format'     => '%s',
1396
-                    'db-col'     => 'MTP_template_field'
1397
-                );
1386
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1387
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1388
+					'label'      => null,
1389
+					'input'      => 'hidden',
1390
+					'type'       => 'string',
1391
+					'required'   => false,
1392
+					'validation' => true,
1393
+					'value'      => $template_field,
1394
+					'css_class'  => '',
1395
+					'format'     => '%s',
1396
+					'db-col'     => 'MTP_template_field'
1397
+				);
1398 1398
                 
1399
-            }
1399
+			}
1400 1400
             
1401
-            //add other fields
1402
-            $template_form_fields['ee-msg-current-context'] = array(
1403
-                'name'       => 'MTP_context',
1404
-                'label'      => null,
1405
-                'input'      => 'hidden',
1406
-                'type'       => 'string',
1407
-                'required'   => false,
1408
-                'validation' => true,
1409
-                'value'      => $context,
1410
-                'css_class'  => '',
1411
-                'format'     => '%s',
1412
-                'db-col'     => 'MTP_context'
1413
-            );
1401
+			//add other fields
1402
+			$template_form_fields['ee-msg-current-context'] = array(
1403
+				'name'       => 'MTP_context',
1404
+				'label'      => null,
1405
+				'input'      => 'hidden',
1406
+				'type'       => 'string',
1407
+				'required'   => false,
1408
+				'validation' => true,
1409
+				'value'      => $context,
1410
+				'css_class'  => '',
1411
+				'format'     => '%s',
1412
+				'db-col'     => 'MTP_context'
1413
+			);
1414 1414
             
1415
-            $template_form_fields['ee-msg-grp-id'] = array(
1416
-                'name'       => 'GRP_ID',
1417
-                'label'      => null,
1418
-                'input'      => 'hidden',
1419
-                'type'       => 'int',
1420
-                'required'   => false,
1421
-                'validation' => true,
1422
-                'value'      => $GRP_ID,
1423
-                'css_class'  => '',
1424
-                'format'     => '%d',
1425
-                'db-col'     => 'GRP_ID'
1426
-            );
1415
+			$template_form_fields['ee-msg-grp-id'] = array(
1416
+				'name'       => 'GRP_ID',
1417
+				'label'      => null,
1418
+				'input'      => 'hidden',
1419
+				'type'       => 'int',
1420
+				'required'   => false,
1421
+				'validation' => true,
1422
+				'value'      => $GRP_ID,
1423
+				'css_class'  => '',
1424
+				'format'     => '%d',
1425
+				'db-col'     => 'GRP_ID'
1426
+			);
1427 1427
             
1428
-            $template_form_fields['ee-msg-messenger'] = array(
1429
-                'name'       => 'MTP_messenger',
1430
-                'label'      => null,
1431
-                'input'      => 'hidden',
1432
-                'type'       => 'string',
1433
-                'required'   => false,
1434
-                'validation' => true,
1435
-                'value'      => $message_template_group->messenger(),
1436
-                'css_class'  => '',
1437
-                'format'     => '%s',
1438
-                'db-col'     => 'MTP_messenger'
1439
-            );
1428
+			$template_form_fields['ee-msg-messenger'] = array(
1429
+				'name'       => 'MTP_messenger',
1430
+				'label'      => null,
1431
+				'input'      => 'hidden',
1432
+				'type'       => 'string',
1433
+				'required'   => false,
1434
+				'validation' => true,
1435
+				'value'      => $message_template_group->messenger(),
1436
+				'css_class'  => '',
1437
+				'format'     => '%s',
1438
+				'db-col'     => 'MTP_messenger'
1439
+			);
1440 1440
             
1441
-            $template_form_fields['ee-msg-message-type'] = array(
1442
-                'name'       => 'MTP_message_type',
1443
-                'label'      => null,
1444
-                'input'      => 'hidden',
1445
-                'type'       => 'string',
1446
-                'required'   => false,
1447
-                'validation' => true,
1448
-                'value'      => $message_template_group->message_type(),
1449
-                'css_class'  => '',
1450
-                'format'     => '%s',
1451
-                'db-col'     => 'MTP_message_type'
1452
-            );
1441
+			$template_form_fields['ee-msg-message-type'] = array(
1442
+				'name'       => 'MTP_message_type',
1443
+				'label'      => null,
1444
+				'input'      => 'hidden',
1445
+				'type'       => 'string',
1446
+				'required'   => false,
1447
+				'validation' => true,
1448
+				'value'      => $message_template_group->message_type(),
1449
+				'css_class'  => '',
1450
+				'format'     => '%s',
1451
+				'db-col'     => 'MTP_message_type'
1452
+			);
1453 1453
             
1454
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1455
-                'name'       => 'MTP_is_global',
1456
-                'label'      => __('Global Template', 'event_espresso'),
1457
-                'input'      => 'hidden',
1458
-                'type'       => 'int',
1459
-                'required'   => false,
1460
-                'validation' => true,
1461
-                'value'      => $message_template_group->get('MTP_is_global'),
1462
-                'css_class'  => '',
1463
-                'format'     => '%d',
1464
-                'db-col'     => 'MTP_is_global'
1465
-            );
1454
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1455
+				'name'       => 'MTP_is_global',
1456
+				'label'      => __('Global Template', 'event_espresso'),
1457
+				'input'      => 'hidden',
1458
+				'type'       => 'int',
1459
+				'required'   => false,
1460
+				'validation' => true,
1461
+				'value'      => $message_template_group->get('MTP_is_global'),
1462
+				'css_class'  => '',
1463
+				'format'     => '%d',
1464
+				'db-col'     => 'MTP_is_global'
1465
+			);
1466 1466
             
1467
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1468
-                'name'       => 'MTP_is_override',
1469
-                'label'      => __('Override all custom', 'event_espresso'),
1470
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1471
-                'type'       => 'int',
1472
-                'required'   => false,
1473
-                'validation' => true,
1474
-                'value'      => $message_template_group->get('MTP_is_override'),
1475
-                'css_class'  => '',
1476
-                'format'     => '%d',
1477
-                'db-col'     => 'MTP_is_override'
1478
-            );
1467
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1468
+				'name'       => 'MTP_is_override',
1469
+				'label'      => __('Override all custom', 'event_espresso'),
1470
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1471
+				'type'       => 'int',
1472
+				'required'   => false,
1473
+				'validation' => true,
1474
+				'value'      => $message_template_group->get('MTP_is_override'),
1475
+				'css_class'  => '',
1476
+				'format'     => '%d',
1477
+				'db-col'     => 'MTP_is_override'
1478
+			);
1479 1479
             
1480
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1481
-                'name'       => 'MTP_is_active',
1482
-                'label'      => __('Active Template', 'event_espresso'),
1483
-                'input'      => 'hidden',
1484
-                'type'       => 'int',
1485
-                'required'   => false,
1486
-                'validation' => true,
1487
-                'value'      => $message_template_group->is_active(),
1488
-                'css_class'  => '',
1489
-                'format'     => '%d',
1490
-                'db-col'     => 'MTP_is_active'
1491
-            );
1480
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1481
+				'name'       => 'MTP_is_active',
1482
+				'label'      => __('Active Template', 'event_espresso'),
1483
+				'input'      => 'hidden',
1484
+				'type'       => 'int',
1485
+				'required'   => false,
1486
+				'validation' => true,
1487
+				'value'      => $message_template_group->is_active(),
1488
+				'css_class'  => '',
1489
+				'format'     => '%d',
1490
+				'db-col'     => 'MTP_is_active'
1491
+			);
1492 1492
             
1493
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1494
-                'name'       => 'MTP_deleted',
1495
-                'label'      => null,
1496
-                'input'      => 'hidden',
1497
-                'type'       => 'int',
1498
-                'required'   => false,
1499
-                'validation' => true,
1500
-                'value'      => $message_template_group->get('MTP_deleted'),
1501
-                'css_class'  => '',
1502
-                'format'     => '%d',
1503
-                'db-col'     => 'MTP_deleted'
1504
-            );
1505
-            $sidebar_form_fields['ee-msg-author']  = array(
1506
-                'name'       => 'MTP_user_id',
1507
-                'label'      => __('Author', 'event_espresso'),
1508
-                'input'      => 'hidden',
1509
-                'type'       => 'int',
1510
-                'required'   => false,
1511
-                'validation' => false,
1512
-                'value'      => $message_template_group->user(),
1513
-                'format'     => '%d',
1514
-                'db-col'     => 'MTP_user_id'
1515
-            );
1493
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1494
+				'name'       => 'MTP_deleted',
1495
+				'label'      => null,
1496
+				'input'      => 'hidden',
1497
+				'type'       => 'int',
1498
+				'required'   => false,
1499
+				'validation' => true,
1500
+				'value'      => $message_template_group->get('MTP_deleted'),
1501
+				'css_class'  => '',
1502
+				'format'     => '%d',
1503
+				'db-col'     => 'MTP_deleted'
1504
+			);
1505
+			$sidebar_form_fields['ee-msg-author']  = array(
1506
+				'name'       => 'MTP_user_id',
1507
+				'label'      => __('Author', 'event_espresso'),
1508
+				'input'      => 'hidden',
1509
+				'type'       => 'int',
1510
+				'required'   => false,
1511
+				'validation' => false,
1512
+				'value'      => $message_template_group->user(),
1513
+				'format'     => '%d',
1514
+				'db-col'     => 'MTP_user_id'
1515
+			);
1516 1516
             
1517
-            $sidebar_form_fields['ee-msg-route'] = array(
1518
-                'name'  => 'action',
1519
-                'input' => 'hidden',
1520
-                'type'  => 'string',
1521
-                'value' => $action
1522
-            );
1517
+			$sidebar_form_fields['ee-msg-route'] = array(
1518
+				'name'  => 'action',
1519
+				'input' => 'hidden',
1520
+				'type'  => 'string',
1521
+				'value' => $action
1522
+			);
1523 1523
             
1524
-            $sidebar_form_fields['ee-msg-id']        = array(
1525
-                'name'  => 'id',
1526
-                'input' => 'hidden',
1527
-                'type'  => 'int',
1528
-                'value' => $GRP_ID
1529
-            );
1530
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1531
-                'name'  => $action . '_nonce',
1532
-                'input' => 'hidden',
1533
-                'type'  => 'string',
1534
-                'value' => wp_create_nonce($action . '_nonce')
1535
-            );
1524
+			$sidebar_form_fields['ee-msg-id']        = array(
1525
+				'name'  => 'id',
1526
+				'input' => 'hidden',
1527
+				'type'  => 'int',
1528
+				'value' => $GRP_ID
1529
+			);
1530
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1531
+				'name'  => $action . '_nonce',
1532
+				'input' => 'hidden',
1533
+				'type'  => 'string',
1534
+				'value' => wp_create_nonce($action . '_nonce')
1535
+			);
1536 1536
             
1537
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1538
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1539
-                    'name'  => 'template_switch',
1540
-                    'input' => 'hidden',
1541
-                    'type'  => 'int',
1542
-                    'value' => 1
1543
-                );
1544
-            }
1537
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1538
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1539
+					'name'  => 'template_switch',
1540
+					'input' => 'hidden',
1541
+					'type'  => 'int',
1542
+					'value' => 1
1543
+				);
1544
+			}
1545 1545
             
1546 1546
             
1547
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1548
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1547
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1548
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1549 1549
             
1550 1550
             
1551
-        } //end if ( !empty($template_field_structure) )
1551
+		} //end if ( !empty($template_field_structure) )
1552 1552
         
1553
-        //set extra content for publish box
1554
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1555
-        $this->_set_publish_post_box_vars(
1556
-            'id',
1557
-            $GRP_ID,
1558
-            false,
1559
-            add_query_arg(
1560
-                array('action' => 'global_mtps'),
1561
-                $this->_admin_base_url
1562
-            )
1563
-        );
1564
-        
1565
-        //add preview button
1566
-        $preview_url    = parent::add_query_args_and_nonce(
1567
-            array(
1568
-                'message_type' => $message_template_group->message_type(),
1569
-                'messenger'    => $message_template_group->messenger(),
1570
-                'context'      => $context,
1571
-                'GRP_ID'       => $GRP_ID,
1572
-                'action'       => 'preview_message'
1573
-            ),
1574
-            $this->_admin_base_url
1575
-        );
1576
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1577
-                'event_espresso') . '</a>';
1578
-        
1579
-        
1580
-        //setup context switcher
1581
-        $context_switcher_args = array(
1582
-            'page'    => 'espresso_messages',
1583
-            'action'  => 'edit_message_template',
1584
-            'id'      => $GRP_ID,
1585
-            'context' => $context,
1586
-            'extra'   => $preview_button
1587
-        );
1588
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1589
-        
1590
-        
1591
-        //main box
1592
-        $this->_template_args['template_fields']                         = $template_fields;
1593
-        $this->_template_args['sidebar_box_id']                          = 'details';
1594
-        $this->_template_args['action']                                  = $action;
1595
-        $this->_template_args['context']                                 = $context;
1596
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1597
-        $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1598
-        
1599
-        
1600
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1601
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1602
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1603
-        
1604
-        $this->_template_path = $this->_template_args['GRP_ID']
1605
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1606
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1607
-        
1608
-        //send along EE_Message_Template_Group object for further template use.
1609
-        $this->_template_args['MTP'] = $message_template_group;
1610
-        
1611
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1612
-            $this->_template_args, true);
1613
-        
1614
-        
1615
-        //finally, let's set the admin_page title
1616
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1617
-        
1618
-        
1619
-        //we need to take care of setting the shortcodes property for use elsewhere.
1620
-        $this->_set_shortcodes();
1621
-        
1622
-        
1623
-        //final template wrapper
1624
-        $this->display_admin_page_with_sidebar();
1625
-    }
1626
-    
1627
-    
1628
-    public function filter_tinymce_init($mceInit, $editor_id)
1629
-    {
1630
-        return $mceInit;
1631
-    }
1632
-    
1633
-    
1634
-    public function add_context_switcher()
1635
-    {
1636
-        return $this->_context_switcher;
1637
-    }
1638
-    
1639
-    public function _add_form_element_before()
1640
-    {
1641
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1642
-    }
1643
-    
1644
-    public function _add_form_element_after()
1645
-    {
1646
-        return '</form>';
1647
-    }
1648
-    
1649
-    
1650
-    /**
1651
-     * This executes switching the template pack for a message template.
1652
-     *
1653
-     * @since 4.5.0
1654
-     *
1655
-     */
1656
-    public function switch_template_pack()
1657
-    {
1658
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1659
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1660
-        
1661
-        //verify we have needed values.
1662
-        if (empty($GRP_ID) || empty($template_pack)) {
1663
-            $this->_template_args['error'] = true;
1664
-            EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1665
-                __FILE__, __FUNCTION__, __LINE__);
1666
-        } else {
1667
-            //get template, set the new template_pack and then reset to default
1668
-            /** @type EE_Message_Template_Group $message_template_group */
1669
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1553
+		//set extra content for publish box
1554
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1555
+		$this->_set_publish_post_box_vars(
1556
+			'id',
1557
+			$GRP_ID,
1558
+			false,
1559
+			add_query_arg(
1560
+				array('action' => 'global_mtps'),
1561
+				$this->_admin_base_url
1562
+			)
1563
+		);
1564
+        
1565
+		//add preview button
1566
+		$preview_url    = parent::add_query_args_and_nonce(
1567
+			array(
1568
+				'message_type' => $message_template_group->message_type(),
1569
+				'messenger'    => $message_template_group->messenger(),
1570
+				'context'      => $context,
1571
+				'GRP_ID'       => $GRP_ID,
1572
+				'action'       => 'preview_message'
1573
+			),
1574
+			$this->_admin_base_url
1575
+		);
1576
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1577
+				'event_espresso') . '</a>';
1578
+        
1579
+        
1580
+		//setup context switcher
1581
+		$context_switcher_args = array(
1582
+			'page'    => 'espresso_messages',
1583
+			'action'  => 'edit_message_template',
1584
+			'id'      => $GRP_ID,
1585
+			'context' => $context,
1586
+			'extra'   => $preview_button
1587
+		);
1588
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1589
+        
1590
+        
1591
+		//main box
1592
+		$this->_template_args['template_fields']                         = $template_fields;
1593
+		$this->_template_args['sidebar_box_id']                          = 'details';
1594
+		$this->_template_args['action']                                  = $action;
1595
+		$this->_template_args['context']                                 = $context;
1596
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1597
+		$this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1598
+        
1599
+        
1600
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1601
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1602
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1603
+        
1604
+		$this->_template_path = $this->_template_args['GRP_ID']
1605
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1606
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1607
+        
1608
+		//send along EE_Message_Template_Group object for further template use.
1609
+		$this->_template_args['MTP'] = $message_template_group;
1610
+        
1611
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1612
+			$this->_template_args, true);
1613
+        
1614
+        
1615
+		//finally, let's set the admin_page title
1616
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1617
+        
1618
+        
1619
+		//we need to take care of setting the shortcodes property for use elsewhere.
1620
+		$this->_set_shortcodes();
1621
+        
1622
+        
1623
+		//final template wrapper
1624
+		$this->display_admin_page_with_sidebar();
1625
+	}
1626
+    
1627
+    
1628
+	public function filter_tinymce_init($mceInit, $editor_id)
1629
+	{
1630
+		return $mceInit;
1631
+	}
1632
+    
1633
+    
1634
+	public function add_context_switcher()
1635
+	{
1636
+		return $this->_context_switcher;
1637
+	}
1638
+    
1639
+	public function _add_form_element_before()
1640
+	{
1641
+		return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1642
+	}
1643
+    
1644
+	public function _add_form_element_after()
1645
+	{
1646
+		return '</form>';
1647
+	}
1648
+    
1649
+    
1650
+	/**
1651
+	 * This executes switching the template pack for a message template.
1652
+	 *
1653
+	 * @since 4.5.0
1654
+	 *
1655
+	 */
1656
+	public function switch_template_pack()
1657
+	{
1658
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1659
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1660
+        
1661
+		//verify we have needed values.
1662
+		if (empty($GRP_ID) || empty($template_pack)) {
1663
+			$this->_template_args['error'] = true;
1664
+			EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1665
+				__FILE__, __FUNCTION__, __LINE__);
1666
+		} else {
1667
+			//get template, set the new template_pack and then reset to default
1668
+			/** @type EE_Message_Template_Group $message_template_group */
1669
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1670 1670
             
1671
-            $message_template_group->set_template_pack_name($template_pack);
1672
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1673
-            $this->_req_data['mt']   = $message_template_group->message_type();
1671
+			$message_template_group->set_template_pack_name($template_pack);
1672
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1673
+			$this->_req_data['mt']   = $message_template_group->message_type();
1674 1674
             
1675
-            $query_args = $this->_reset_to_default_template();
1675
+			$query_args = $this->_reset_to_default_template();
1676 1676
             
1677
-            if (empty($query_args['id'])) {
1678
-                EE_Error::add_error(
1679
-                    __(
1680
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1681
-                        'event_espresso'
1682
-                    ),
1683
-                    __FILE__, __FUNCTION__, __LINE__
1684
-                );
1685
-                $this->_template_args['error'] = true;
1686
-            } else {
1687
-                $template_label       = $message_template_group->get_template_pack()->label;
1688
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1689
-                EE_Error::add_success(
1690
-                    sprintf(
1691
-                        __(
1692
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1693
-                            'event_espresso'
1694
-                        ),
1695
-                        $template_label,
1696
-                        $template_pack_labels->template_pack
1697
-                    )
1698
-                );
1699
-                //generate the redirect url for js.
1700
-                $url                                          = self::add_query_args_and_nonce($query_args,
1701
-                    $this->_admin_base_url);
1702
-                $this->_template_args['data']['redirect_url'] = $url;
1703
-                $this->_template_args['success']              = true;
1704
-            }
1677
+			if (empty($query_args['id'])) {
1678
+				EE_Error::add_error(
1679
+					__(
1680
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1681
+						'event_espresso'
1682
+					),
1683
+					__FILE__, __FUNCTION__, __LINE__
1684
+				);
1685
+				$this->_template_args['error'] = true;
1686
+			} else {
1687
+				$template_label       = $message_template_group->get_template_pack()->label;
1688
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1689
+				EE_Error::add_success(
1690
+					sprintf(
1691
+						__(
1692
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1693
+							'event_espresso'
1694
+						),
1695
+						$template_label,
1696
+						$template_pack_labels->template_pack
1697
+					)
1698
+				);
1699
+				//generate the redirect url for js.
1700
+				$url                                          = self::add_query_args_and_nonce($query_args,
1701
+					$this->_admin_base_url);
1702
+				$this->_template_args['data']['redirect_url'] = $url;
1703
+				$this->_template_args['success']              = true;
1704
+			}
1705 1705
             
1706
-            $this->_return_json();
1706
+			$this->_return_json();
1707 1707
             
1708
-        }
1709
-    }
1710
-    
1711
-    
1712
-    /**
1713
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1714
-     * they want.
1715
-     *
1716
-     * @access protected
1717
-     * @return array|null
1718
-     */
1719
-    protected function _reset_to_default_template()
1720
-    {
1721
-        
1722
-        $templates = array();
1723
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1724
-        //we need to make sure we've got the info we need.
1725
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1726
-            EE_Error::add_error(
1727
-                __(
1728
-                    '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.',
1729
-                    'event_espresso'
1730
-                ),
1731
-                __FILE__, __FUNCTION__, __LINE__
1732
-            );
1733
-        }
1734
-        
1735
-        // all templates will be reset to whatever the defaults are
1736
-        // for the global template matching the messenger and message type.
1737
-        $success = ! empty($GRP_ID) ? true : false;
1738
-        
1739
-        if ($success) {
1708
+		}
1709
+	}
1710
+    
1711
+    
1712
+	/**
1713
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1714
+	 * they want.
1715
+	 *
1716
+	 * @access protected
1717
+	 * @return array|null
1718
+	 */
1719
+	protected function _reset_to_default_template()
1720
+	{
1721
+        
1722
+		$templates = array();
1723
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1724
+		//we need to make sure we've got the info we need.
1725
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1726
+			EE_Error::add_error(
1727
+				__(
1728
+					'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.',
1729
+					'event_espresso'
1730
+				),
1731
+				__FILE__, __FUNCTION__, __LINE__
1732
+			);
1733
+		}
1734
+        
1735
+		// all templates will be reset to whatever the defaults are
1736
+		// for the global template matching the messenger and message type.
1737
+		$success = ! empty($GRP_ID) ? true : false;
1738
+        
1739
+		if ($success) {
1740 1740
             
1741
-            //let's first determine if the incoming template is a global template,
1742
-            // if it isn't then we need to get the global template matching messenger and message type.
1743
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1741
+			//let's first determine if the incoming template is a global template,
1742
+			// if it isn't then we need to get the global template matching messenger and message type.
1743
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1744 1744
             
1745 1745
             
1746
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1747
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
1746
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1747
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
1748 1748
             
1749
-            if ($success) {
1750
-                // if successfully deleted, lets generate the new ones.
1751
-                // Note. We set GLOBAL to true, because resets on ANY template
1752
-                // will use the related global template defaults for regeneration.
1753
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1754
-                // HOWEVER, we DO keep the template pack and template variation set
1755
-                // for the current custom template when resetting.
1756
-                $templates = $this->_generate_new_templates(
1757
-                    $this->_req_data['msgr'],
1758
-                    $this->_req_data['mt'],
1759
-                    $GRP_ID,
1760
-                    true
1761
-                );
1762
-            }
1749
+			if ($success) {
1750
+				// if successfully deleted, lets generate the new ones.
1751
+				// Note. We set GLOBAL to true, because resets on ANY template
1752
+				// will use the related global template defaults for regeneration.
1753
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1754
+				// HOWEVER, we DO keep the template pack and template variation set
1755
+				// for the current custom template when resetting.
1756
+				$templates = $this->_generate_new_templates(
1757
+					$this->_req_data['msgr'],
1758
+					$this->_req_data['mt'],
1759
+					$GRP_ID,
1760
+					true
1761
+				);
1762
+			}
1763 1763
             
1764
-        }
1765
-        
1766
-        //any error messages?
1767
-        if ( ! $success) {
1768
-            EE_Error::add_error(
1769
-                __('Something went wrong with deleting existing templates. Unable to reset to default',
1770
-                    'event_espresso'),
1771
-                __FILE__, __FUNCTION__, __LINE__
1772
-            );
1773
-        }
1774
-        
1775
-        //all good, let's add a success message!
1776
-        if ($success && ! empty($templates)) {
1777
-            $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1778
-            EE_Error::overwrite_success();
1779
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1780
-        }
1781
-        
1782
-        
1783
-        $query_args = array(
1784
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1785
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1786
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1787
-        );
1788
-        
1789
-        //if called via ajax then we return query args otherwise redirect
1790
-        if (defined('DOING_AJAX') && DOING_AJAX) {
1791
-            return $query_args;
1792
-        } else {
1793
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1764
+		}
1765
+        
1766
+		//any error messages?
1767
+		if ( ! $success) {
1768
+			EE_Error::add_error(
1769
+				__('Something went wrong with deleting existing templates. Unable to reset to default',
1770
+					'event_espresso'),
1771
+				__FILE__, __FUNCTION__, __LINE__
1772
+			);
1773
+		}
1774
+        
1775
+		//all good, let's add a success message!
1776
+		if ($success && ! empty($templates)) {
1777
+			$templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1778
+			EE_Error::overwrite_success();
1779
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1780
+		}
1781
+        
1782
+        
1783
+		$query_args = array(
1784
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1785
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1786
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1787
+		);
1788
+        
1789
+		//if called via ajax then we return query args otherwise redirect
1790
+		if (defined('DOING_AJAX') && DOING_AJAX) {
1791
+			return $query_args;
1792
+		} else {
1793
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1794 1794
             
1795
-            return null;
1796
-        }
1797
-    }
1798
-    
1799
-    
1800
-    /**
1801
-     * Retrieve and set the message preview for display.
1802
-     *
1803
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1804
-     *
1805
-     * @return string
1806
-     */
1807
-    public function _preview_message($send = false)
1808
-    {
1809
-        //first make sure we've got the necessary parameters
1810
-        if (
1811
-        ! isset(
1812
-            $this->_req_data['message_type'],
1813
-            $this->_req_data['messenger'],
1814
-            $this->_req_data['messenger'],
1815
-            $this->_req_data['GRP_ID']
1816
-        )
1817
-        ) {
1818
-            EE_Error::add_error(
1819
-                __('Missing necessary parameters for displaying preview', 'event_espresso'),
1820
-                __FILE__, __FUNCTION__, __LINE__
1821
-            );
1822
-        }
1823
-        
1824
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1825
-        
1826
-        
1827
-        //get the preview!
1828
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1829
-            $this->_req_data['messenger'], $send);
1830
-        
1831
-        if ($send) {
1832
-            return $preview;
1833
-        }
1834
-        
1835
-        //let's add a button to go back to the edit view
1836
-        $query_args             = array(
1837
-            'id'      => $this->_req_data['GRP_ID'],
1838
-            'context' => $this->_req_data['context'],
1839
-            'action'  => 'edit_message_template'
1840
-        );
1841
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1842
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1843
-                'event_espresso') . '</a>';
1844
-        $message_types          = $this->get_installed_message_types();
1845
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1846
-        $active_messenger_label = $active_messenger instanceof EE_messenger
1847
-            ? ucwords($active_messenger->label['singular'])
1848
-            : esc_html__('Unknown Messenger', 'event_espresso');
1849
-        //let's provide a helpful title for context
1850
-        $preview_title = sprintf(
1851
-            __('Viewing Preview for %s %s Message Template', 'event_espresso'),
1852
-            $active_messenger_label,
1853
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1854
-        );
1855
-        //setup display of preview.
1856
-        $this->_admin_page_title                    = $preview_title;
1857
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1858
-        $this->_template_args['data']['force_json'] = true;
1859
-        
1860
-        return '';
1861
-    }
1862
-    
1863
-    
1864
-    /**
1865
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1866
-     * gets called automatically.
1867
-     *
1868
-     * @since 4.5.0
1869
-     *
1870
-     * @return string
1871
-     */
1872
-    protected function _display_preview_message()
1873
-    {
1874
-        $this->display_admin_page_with_no_sidebar();
1875
-    }
1876
-    
1877
-    
1878
-    /**
1879
-     * registers metaboxes that should show up on the "edit_message_template" page
1880
-     *
1881
-     * @access protected
1882
-     * @return void
1883
-     */
1884
-    protected function _register_edit_meta_boxes()
1885
-    {
1886
-        add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1887
-            array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1888
-        add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1889
-            $this->_current_screen->id, 'side', 'high');
1890
-        add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1891
-            $this->_current_screen->id, 'side', 'high');
1892
-    }
1893
-    
1894
-    
1895
-    /**
1896
-     * metabox content for all template pack and variation selection.
1897
-     *
1898
-     * @since 4.5.0
1899
-     *
1900
-     * @return string
1901
-     */
1902
-    public function template_pack_meta_box()
1903
-    {
1904
-        $this->_set_message_template_group();
1905
-        
1906
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
1907
-        
1908
-        $tp_select_values = array();
1909
-        
1910
-        foreach ($tp_collection as $tp) {
1911
-            //only include template packs that support this messenger and message type!
1912
-            $supports = $tp->get_supports();
1913
-            if (
1914
-                ! isset($supports[$this->_message_template_group->messenger()])
1915
-                || ! in_array(
1916
-                    $this->_message_template_group->message_type(),
1917
-                    $supports[$this->_message_template_group->messenger()]
1918
-                )
1919
-            ) {
1920
-                //not supported
1921
-                continue;
1922
-            }
1795
+			return null;
1796
+		}
1797
+	}
1798
+    
1799
+    
1800
+	/**
1801
+	 * Retrieve and set the message preview for display.
1802
+	 *
1803
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1804
+	 *
1805
+	 * @return string
1806
+	 */
1807
+	public function _preview_message($send = false)
1808
+	{
1809
+		//first make sure we've got the necessary parameters
1810
+		if (
1811
+		! isset(
1812
+			$this->_req_data['message_type'],
1813
+			$this->_req_data['messenger'],
1814
+			$this->_req_data['messenger'],
1815
+			$this->_req_data['GRP_ID']
1816
+		)
1817
+		) {
1818
+			EE_Error::add_error(
1819
+				__('Missing necessary parameters for displaying preview', 'event_espresso'),
1820
+				__FILE__, __FUNCTION__, __LINE__
1821
+			);
1822
+		}
1823
+        
1824
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1825
+        
1826
+        
1827
+		//get the preview!
1828
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1829
+			$this->_req_data['messenger'], $send);
1830
+        
1831
+		if ($send) {
1832
+			return $preview;
1833
+		}
1834
+        
1835
+		//let's add a button to go back to the edit view
1836
+		$query_args             = array(
1837
+			'id'      => $this->_req_data['GRP_ID'],
1838
+			'context' => $this->_req_data['context'],
1839
+			'action'  => 'edit_message_template'
1840
+		);
1841
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1842
+		$preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1843
+				'event_espresso') . '</a>';
1844
+		$message_types          = $this->get_installed_message_types();
1845
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1846
+		$active_messenger_label = $active_messenger instanceof EE_messenger
1847
+			? ucwords($active_messenger->label['singular'])
1848
+			: esc_html__('Unknown Messenger', 'event_espresso');
1849
+		//let's provide a helpful title for context
1850
+		$preview_title = sprintf(
1851
+			__('Viewing Preview for %s %s Message Template', 'event_espresso'),
1852
+			$active_messenger_label,
1853
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1854
+		);
1855
+		//setup display of preview.
1856
+		$this->_admin_page_title                    = $preview_title;
1857
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1858
+		$this->_template_args['data']['force_json'] = true;
1859
+        
1860
+		return '';
1861
+	}
1862
+    
1863
+    
1864
+	/**
1865
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1866
+	 * gets called automatically.
1867
+	 *
1868
+	 * @since 4.5.0
1869
+	 *
1870
+	 * @return string
1871
+	 */
1872
+	protected function _display_preview_message()
1873
+	{
1874
+		$this->display_admin_page_with_no_sidebar();
1875
+	}
1876
+    
1877
+    
1878
+	/**
1879
+	 * registers metaboxes that should show up on the "edit_message_template" page
1880
+	 *
1881
+	 * @access protected
1882
+	 * @return void
1883
+	 */
1884
+	protected function _register_edit_meta_boxes()
1885
+	{
1886
+		add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1887
+			array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1888
+		add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1889
+			$this->_current_screen->id, 'side', 'high');
1890
+		add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1891
+			$this->_current_screen->id, 'side', 'high');
1892
+	}
1893
+    
1894
+    
1895
+	/**
1896
+	 * metabox content for all template pack and variation selection.
1897
+	 *
1898
+	 * @since 4.5.0
1899
+	 *
1900
+	 * @return string
1901
+	 */
1902
+	public function template_pack_meta_box()
1903
+	{
1904
+		$this->_set_message_template_group();
1905
+        
1906
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
1907
+        
1908
+		$tp_select_values = array();
1909
+        
1910
+		foreach ($tp_collection as $tp) {
1911
+			//only include template packs that support this messenger and message type!
1912
+			$supports = $tp->get_supports();
1913
+			if (
1914
+				! isset($supports[$this->_message_template_group->messenger()])
1915
+				|| ! in_array(
1916
+					$this->_message_template_group->message_type(),
1917
+					$supports[$this->_message_template_group->messenger()]
1918
+				)
1919
+			) {
1920
+				//not supported
1921
+				continue;
1922
+			}
1923 1923
             
1924
-            $tp_select_values[] = array(
1925
-                'text' => $tp->label,
1926
-                'id'   => $tp->dbref
1927
-            );
1928
-        }
1929
-        
1930
-        //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.
1931
-        if (empty($tp_select_values)) {
1932
-            $tp_select_values[] = array(
1933
-                'text' => __('Default', 'event_espresso'),
1934
-                'id'   => 'default'
1935
-            );
1936
-        }
1937
-        
1938
-        //setup variation select values for the currently selected template.
1939
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1940
-            $this->_message_template_group->messenger(),
1941
-            $this->_message_template_group->message_type()
1942
-        );
1943
-        $variations_select_values = array();
1944
-        foreach ($variations as $variation => $label) {
1945
-            $variations_select_values[] = array(
1946
-                'text' => $label,
1947
-                'id'   => $variation
1948
-            );
1949
-        }
1950
-        
1951
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1952
-        
1953
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1954
-            'MTP_template_pack',
1955
-            $tp_select_values,
1956
-            $this->_message_template_group->get_template_pack_name()
1957
-        );
1958
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1959
-            'MTP_template_variation',
1960
-            $variations_select_values,
1961
-            $this->_message_template_group->get_template_pack_variation()
1962
-        );
1963
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
1964
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
1965
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1966
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1967
-        
1968
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1969
-        
1970
-        EEH_Template::display_template($template, $template_args);
1971
-    }
1972
-    
1973
-    
1974
-    /**
1975
-     * This meta box holds any extra actions related to Message Templates
1976
-     * For now, this includes Resetting templates to defaults and sending a test email.
1977
-     *
1978
-     * @access  public
1979
-     * @return void
1980
-     * @throws \EE_Error
1981
-     */
1982
-    public function extra_actions_meta_box()
1983
-    {
1984
-        $template_form_fields = array();
1985
-        
1986
-        $extra_args = array(
1987
-            'msgr'   => $this->_message_template_group->messenger(),
1988
-            'mt'     => $this->_message_template_group->message_type(),
1989
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
1990
-        );
1991
-        //first we need to see if there are any fields
1992
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
1993
-        
1994
-        if ( ! empty($fields)) {
1995
-            //yup there be fields
1996
-            foreach ($fields as $field => $config) {
1997
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
1998
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
1999
-                $default  = isset($config['default']) ? $config['default'] : '';
2000
-                $default  = isset($config['value']) ? $config['value'] : $default;
1924
+			$tp_select_values[] = array(
1925
+				'text' => $tp->label,
1926
+				'id'   => $tp->dbref
1927
+			);
1928
+		}
1929
+        
1930
+		//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.
1931
+		if (empty($tp_select_values)) {
1932
+			$tp_select_values[] = array(
1933
+				'text' => __('Default', 'event_espresso'),
1934
+				'id'   => 'default'
1935
+			);
1936
+		}
1937
+        
1938
+		//setup variation select values for the currently selected template.
1939
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
1940
+			$this->_message_template_group->messenger(),
1941
+			$this->_message_template_group->message_type()
1942
+		);
1943
+		$variations_select_values = array();
1944
+		foreach ($variations as $variation => $label) {
1945
+			$variations_select_values[] = array(
1946
+				'text' => $label,
1947
+				'id'   => $variation
1948
+			);
1949
+		}
1950
+        
1951
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1952
+        
1953
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1954
+			'MTP_template_pack',
1955
+			$tp_select_values,
1956
+			$this->_message_template_group->get_template_pack_name()
1957
+		);
1958
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
1959
+			'MTP_template_variation',
1960
+			$variations_select_values,
1961
+			$this->_message_template_group->get_template_pack_variation()
1962
+		);
1963
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
1964
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
1965
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1966
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1967
+        
1968
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1969
+        
1970
+		EEH_Template::display_template($template, $template_args);
1971
+	}
1972
+    
1973
+    
1974
+	/**
1975
+	 * This meta box holds any extra actions related to Message Templates
1976
+	 * For now, this includes Resetting templates to defaults and sending a test email.
1977
+	 *
1978
+	 * @access  public
1979
+	 * @return void
1980
+	 * @throws \EE_Error
1981
+	 */
1982
+	public function extra_actions_meta_box()
1983
+	{
1984
+		$template_form_fields = array();
1985
+        
1986
+		$extra_args = array(
1987
+			'msgr'   => $this->_message_template_group->messenger(),
1988
+			'mt'     => $this->_message_template_group->message_type(),
1989
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
1990
+		);
1991
+		//first we need to see if there are any fields
1992
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
1993
+        
1994
+		if ( ! empty($fields)) {
1995
+			//yup there be fields
1996
+			foreach ($fields as $field => $config) {
1997
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
1998
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
1999
+				$default  = isset($config['default']) ? $config['default'] : '';
2000
+				$default  = isset($config['value']) ? $config['value'] : $default;
2001 2001
                 
2002
-                // if type is hidden and the value is empty
2003
-                // something may have gone wrong so let's correct with the defaults
2004
-                $fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2005
-                    ? $default
2006
-                    : '';
2007
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2008
-                    ? $existing[$field]
2009
-                    : $fix;
2002
+				// if type is hidden and the value is empty
2003
+				// something may have gone wrong so let's correct with the defaults
2004
+				$fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2005
+					? $default
2006
+					: '';
2007
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2008
+					? $existing[$field]
2009
+					: $fix;
2010 2010
                 
2011
-                $template_form_fields[$field_id] = array(
2012
-                    'name'       => 'test_settings_fld[' . $field . ']',
2013
-                    'label'      => $config['label'],
2014
-                    'input'      => $config['input'],
2015
-                    'type'       => $config['type'],
2016
-                    'required'   => $config['required'],
2017
-                    'validation' => $config['validation'],
2018
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2019
-                    'css_class'  => $config['css_class'],
2020
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2021
-                    'default'    => $default,
2022
-                    'format'     => $config['format']
2023
-                );
2024
-            }
2025
-        }
2026
-        
2027
-        $test_settings_fields = ! empty($template_form_fields)
2028
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2029
-            : '';
2030
-        
2031
-        $test_settings_html = '';
2032
-        //print out $test_settings_fields
2033
-        if ( ! empty($test_settings_fields)) {
2034
-            echo $test_settings_fields;
2035
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2036
-            $test_settings_html .= 'name="test_button" value="';
2037
-            $test_settings_html .= __('Test Send', 'event_espresso');
2038
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2039
-        }
2040
-        
2041
-        //and button
2042
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2043
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2044
-        $test_settings_html .= $this->get_action_link_or_button(
2045
-            'reset_to_default',
2046
-            'reset',
2047
-            $extra_args,
2048
-            'button-primary reset-default-button'
2049
-        );
2050
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2051
-        echo $test_settings_html;
2052
-    }
2053
-    
2054
-    
2055
-    /**
2056
-     * This returns the shortcode selector skeleton for a given context and field.
2057
-     *
2058
-     * @since 4.9.rc.000
2059
-     *
2060
-     * @param string $field           The name of the field retrieving shortcodes for.
2061
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2062
-     *
2063
-     * @return string
2064
-     */
2065
-    protected function _get_shortcode_selector($field, $linked_input_id)
2066
-    {
2067
-        $template_args = array(
2068
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2069
-            'fieldname'       => $field,
2070
-            'linked_input_id' => $linked_input_id
2071
-        );
2072
-        
2073
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2074
-            $template_args, true);
2075
-    }
2076
-    
2077
-    
2078
-    /**
2079
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2080
-     * page)
2081
-     *
2082
-     * @access public
2083
-     * @return void
2084
-     */
2085
-    public function shortcode_meta_box()
2086
-    {
2087
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2088
-        //$messenger = $this->_message_template_group->messenger_obj();
2089
-        //now let's set the content depending on the status of the shortcodes array
2090
-        if (empty($shortcodes)) {
2091
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2092
-            echo $content;
2093
-        } else {
2094
-            //$alt = 0;
2095
-            ?>
2011
+				$template_form_fields[$field_id] = array(
2012
+					'name'       => 'test_settings_fld[' . $field . ']',
2013
+					'label'      => $config['label'],
2014
+					'input'      => $config['input'],
2015
+					'type'       => $config['type'],
2016
+					'required'   => $config['required'],
2017
+					'validation' => $config['validation'],
2018
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2019
+					'css_class'  => $config['css_class'],
2020
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2021
+					'default'    => $default,
2022
+					'format'     => $config['format']
2023
+				);
2024
+			}
2025
+		}
2026
+        
2027
+		$test_settings_fields = ! empty($template_form_fields)
2028
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2029
+			: '';
2030
+        
2031
+		$test_settings_html = '';
2032
+		//print out $test_settings_fields
2033
+		if ( ! empty($test_settings_fields)) {
2034
+			echo $test_settings_fields;
2035
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2036
+			$test_settings_html .= 'name="test_button" value="';
2037
+			$test_settings_html .= __('Test Send', 'event_espresso');
2038
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2039
+		}
2040
+        
2041
+		//and button
2042
+		$test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2043
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2044
+		$test_settings_html .= $this->get_action_link_or_button(
2045
+			'reset_to_default',
2046
+			'reset',
2047
+			$extra_args,
2048
+			'button-primary reset-default-button'
2049
+		);
2050
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2051
+		echo $test_settings_html;
2052
+	}
2053
+    
2054
+    
2055
+	/**
2056
+	 * This returns the shortcode selector skeleton for a given context and field.
2057
+	 *
2058
+	 * @since 4.9.rc.000
2059
+	 *
2060
+	 * @param string $field           The name of the field retrieving shortcodes for.
2061
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2062
+	 *
2063
+	 * @return string
2064
+	 */
2065
+	protected function _get_shortcode_selector($field, $linked_input_id)
2066
+	{
2067
+		$template_args = array(
2068
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2069
+			'fieldname'       => $field,
2070
+			'linked_input_id' => $linked_input_id
2071
+		);
2072
+        
2073
+		return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2074
+			$template_args, true);
2075
+	}
2076
+    
2077
+    
2078
+	/**
2079
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2080
+	 * page)
2081
+	 *
2082
+	 * @access public
2083
+	 * @return void
2084
+	 */
2085
+	public function shortcode_meta_box()
2086
+	{
2087
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2088
+		//$messenger = $this->_message_template_group->messenger_obj();
2089
+		//now let's set the content depending on the status of the shortcodes array
2090
+		if (empty($shortcodes)) {
2091
+			$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2092
+			echo $content;
2093
+		} else {
2094
+			//$alt = 0;
2095
+			?>
2096 2096
             <div
2097 2097
                 style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2098 2098
             <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2099
-                    'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2099
+					'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2100 2100
             <?php
2101
-        }
2102
-        
2103
-        
2104
-    }
2105
-    
2106
-    
2107
-    /**
2108
-     * used to set the $_shortcodes property for when its needed elsewhere.
2109
-     *
2110
-     * @access protected
2111
-     * @return void
2112
-     */
2113
-    protected function _set_shortcodes()
2114
-    {
2115
-        
2116
-        //no need to run this if the property is already set
2117
-        if ( ! empty($this->_shortcodes)) {
2118
-            return;
2119
-        }
2120
-        
2121
-        $this->_shortcodes = $this->_get_shortcodes();
2122
-    }
2123
-    
2124
-    
2125
-    /**
2126
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2127
-     * property)
2128
-     *
2129
-     * @access  protected
2130
-     *
2131
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2132
-     *                         for. Defaults to all (for the given context)
2133
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2134
-     *
2135
-     * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2136
-     *                        true just an array of shortcode/label pairs.
2137
-     */
2138
-    protected function _get_shortcodes($fields = array(), $merged = true)
2139
-    {
2140
-        $this->_set_message_template_group();
2141
-        
2142
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2143
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2144
-        $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2145
-        
2146
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2147
-    }
2148
-    
2149
-    
2150
-    /**
2151
-     * This sets the _message_template property (containing the called message_template object)
2152
-     *
2153
-     * @access protected
2154
-     * @return  void
2155
-     */
2156
-    protected function _set_message_template_group()
2157
-    {
2158
-        
2159
-        if ( ! empty($this->_message_template_group)) {
2160
-            return;
2161
-        } //get out if this is already set.
2162
-        
2163
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2164
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2165
-        
2166
-        //let's get the message templates
2167
-        $MTP = EEM_Message_Template_Group::instance();
2168
-        
2169
-        if (empty($GRP_ID)) {
2170
-            $this->_message_template_group = $MTP->create_default_object();
2171
-        } else {
2172
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2173
-        }
2174
-        
2175
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2176
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2177
-        
2178
-    }
2179
-    
2180
-    
2181
-    /**
2182
-     * sets up a context switcher for edit forms
2183
-     *
2184
-     * @access  protected
2185
-     *
2186
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2187
-     * @param array                      $args                  various things the context switcher needs.
2188
-     *
2189
-     */
2190
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2191
-    {
2192
-        $context_details = $template_group_object->contexts_config();
2193
-        $context_label   = $template_group_object->context_label();
2194
-        ob_start();
2195
-        ?>
2101
+		}
2102
+        
2103
+        
2104
+	}
2105
+    
2106
+    
2107
+	/**
2108
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2109
+	 *
2110
+	 * @access protected
2111
+	 * @return void
2112
+	 */
2113
+	protected function _set_shortcodes()
2114
+	{
2115
+        
2116
+		//no need to run this if the property is already set
2117
+		if ( ! empty($this->_shortcodes)) {
2118
+			return;
2119
+		}
2120
+        
2121
+		$this->_shortcodes = $this->_get_shortcodes();
2122
+	}
2123
+    
2124
+    
2125
+	/**
2126
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2127
+	 * property)
2128
+	 *
2129
+	 * @access  protected
2130
+	 *
2131
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2132
+	 *                         for. Defaults to all (for the given context)
2133
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2134
+	 *
2135
+	 * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2136
+	 *                        true just an array of shortcode/label pairs.
2137
+	 */
2138
+	protected function _get_shortcodes($fields = array(), $merged = true)
2139
+	{
2140
+		$this->_set_message_template_group();
2141
+        
2142
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2143
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2144
+		$context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2145
+        
2146
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2147
+	}
2148
+    
2149
+    
2150
+	/**
2151
+	 * This sets the _message_template property (containing the called message_template object)
2152
+	 *
2153
+	 * @access protected
2154
+	 * @return  void
2155
+	 */
2156
+	protected function _set_message_template_group()
2157
+	{
2158
+        
2159
+		if ( ! empty($this->_message_template_group)) {
2160
+			return;
2161
+		} //get out if this is already set.
2162
+        
2163
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2164
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2165
+        
2166
+		//let's get the message templates
2167
+		$MTP = EEM_Message_Template_Group::instance();
2168
+        
2169
+		if (empty($GRP_ID)) {
2170
+			$this->_message_template_group = $MTP->create_default_object();
2171
+		} else {
2172
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2173
+		}
2174
+        
2175
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2176
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2177
+        
2178
+	}
2179
+    
2180
+    
2181
+	/**
2182
+	 * sets up a context switcher for edit forms
2183
+	 *
2184
+	 * @access  protected
2185
+	 *
2186
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2187
+	 * @param array                      $args                  various things the context switcher needs.
2188
+	 *
2189
+	 */
2190
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2191
+	{
2192
+		$context_details = $template_group_object->contexts_config();
2193
+		$context_label   = $template_group_object->context_label();
2194
+		ob_start();
2195
+		?>
2196 2196
         <div class="ee-msg-switcher-container">
2197 2197
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2198 2198
                 <?php
2199
-                foreach ($args as $name => $value) {
2200
-                    if ($name == 'context' || empty($value) || $name == 'extra') {
2201
-                        continue;
2202
-                    }
2203
-                    ?>
2199
+				foreach ($args as $name => $value) {
2200
+					if ($name == 'context' || empty($value) || $name == 'extra') {
2201
+						continue;
2202
+					}
2203
+					?>
2204 2204
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2205 2205
                     <?php
2206
-                }
2207
-                //setup nonce_url
2208
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2209
-                ?>
2206
+				}
2207
+				//setup nonce_url
2208
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2209
+				?>
2210 2210
                 <select name="context">
2211 2211
                     <?php
2212
-                    $context_templates = $template_group_object->context_templates();
2213
-                    if (is_array($context_templates)) :
2214
-                        foreach ($context_templates as $context => $template_fields) :
2215
-                            $checked = ($context == $args['context']) ? 'selected="selected"' : '';
2216
-                            ?>
2212
+					$context_templates = $template_group_object->context_templates();
2213
+					if (is_array($context_templates)) :
2214
+						foreach ($context_templates as $context => $template_fields) :
2215
+							$checked = ($context == $args['context']) ? 'selected="selected"' : '';
2216
+							?>
2217 2217
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2218 2218
                                 <?php echo $context_details[$context]['label']; ?>
2219 2219
                             </option>
@@ -2226,1554 +2226,1554 @@  discard block
 block discarded – undo
2226 2226
             <?php echo $args['extra']; ?>
2227 2227
         </div> <!-- end .ee-msg-switcher-container -->
2228 2228
         <?php
2229
-        $output = ob_get_contents();
2230
-        ob_clean();
2231
-        $this->_context_switcher = $output;
2232
-    }
2233
-    
2234
-    
2235
-    /**
2236
-     * utility for sanitizing new values coming in.
2237
-     * Note: this is only used when updating a context.
2238
-     *
2239
-     * @access protected
2240
-     *
2241
-     * @param int $index This helps us know which template field to select from the request array.
2242
-     *
2243
-     * @return array
2244
-     */
2245
-    protected function _set_message_template_column_values($index)
2246
-    {
2247
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2248
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2249
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2250
-            }
2251
-        } /*else {
2229
+		$output = ob_get_contents();
2230
+		ob_clean();
2231
+		$this->_context_switcher = $output;
2232
+	}
2233
+    
2234
+    
2235
+	/**
2236
+	 * utility for sanitizing new values coming in.
2237
+	 * Note: this is only used when updating a context.
2238
+	 *
2239
+	 * @access protected
2240
+	 *
2241
+	 * @param int $index This helps us know which template field to select from the request array.
2242
+	 *
2243
+	 * @return array
2244
+	 */
2245
+	protected function _set_message_template_column_values($index)
2246
+	{
2247
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2248
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2249
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2250
+			}
2251
+		} /*else {
2252 2252
 			$this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content'];
2253 2253
 		}*/
2254 2254
         
2255 2255
         
2256
-        $set_column_values = array(
2257
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2258
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2259
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2260
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2261
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2262
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2263
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2264
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2265
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2266
-                ? absint($this->_req_data['MTP_is_global'])
2267
-                : 0,
2268
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2269
-                ? absint($this->_req_data['MTP_is_override'])
2270
-                : 0,
2271
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2272
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2273
-        );
2274
-        
2275
-        
2276
-        return $set_column_values;
2277
-    }
2278
-    
2279
-    
2280
-    protected function _insert_or_update_message_template($new = false)
2281
-    {
2282
-        
2283
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2284
-        $success  = 0;
2285
-        $override = false;
2286
-        
2287
-        //setup notices description
2288
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2289
-        
2290
-        //need the message type and messenger objects to be able to use the labels for the notices
2291
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2292
-        $messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2293
-        
2294
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2295
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2296
-        
2297
-        $message_type_label = $message_type_object instanceof EE_message_type
2298
-            ? ucwords($message_type_object->label['singular'])
2299
-            : '';
2300
-        
2301
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2302
-            ? $this->_req_data['MTP_context']
2303
-            : '';
2304
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2305
-        
2306
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2307
-        $item_desc .= 'Message Template';
2308
-        $query_args  = array();
2309
-        $edit_array  = array();
2310
-        $action_desc = '';
2311
-        
2312
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2313
-        if ($new) {
2314
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2315
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2316
-                if (empty($edit_array)) {
2317
-                    $success = 0;
2318
-                } else {
2319
-                    $success    = 1;
2320
-                    $edit_array = $edit_array[0];
2321
-                    $query_args = array(
2322
-                        'id'      => $edit_array['GRP_ID'],
2323
-                        'context' => $edit_array['MTP_context'],
2324
-                        'action'  => 'edit_message_template'
2325
-                    );
2326
-                }
2327
-            }
2328
-            $action_desc = 'created';
2329
-        } else {
2330
-            $MTPG = EEM_Message_Template_Group::instance();
2331
-            $MTP  = EEM_Message_Template::instance();
2256
+		$set_column_values = array(
2257
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2258
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2259
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2260
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2261
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2262
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2263
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2264
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2265
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2266
+				? absint($this->_req_data['MTP_is_global'])
2267
+				: 0,
2268
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2269
+				? absint($this->_req_data['MTP_is_override'])
2270
+				: 0,
2271
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2272
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2273
+		);
2274
+        
2275
+        
2276
+		return $set_column_values;
2277
+	}
2278
+    
2279
+    
2280
+	protected function _insert_or_update_message_template($new = false)
2281
+	{
2282
+        
2283
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2284
+		$success  = 0;
2285
+		$override = false;
2286
+        
2287
+		//setup notices description
2288
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2289
+        
2290
+		//need the message type and messenger objects to be able to use the labels for the notices
2291
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2292
+		$messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2293
+        
2294
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2295
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2296
+        
2297
+		$message_type_label = $message_type_object instanceof EE_message_type
2298
+			? ucwords($message_type_object->label['singular'])
2299
+			: '';
2300
+        
2301
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2302
+			? $this->_req_data['MTP_context']
2303
+			: '';
2304
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2305
+        
2306
+		$item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2307
+		$item_desc .= 'Message Template';
2308
+		$query_args  = array();
2309
+		$edit_array  = array();
2310
+		$action_desc = '';
2311
+        
2312
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2313
+		if ($new) {
2314
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2315
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2316
+				if (empty($edit_array)) {
2317
+					$success = 0;
2318
+				} else {
2319
+					$success    = 1;
2320
+					$edit_array = $edit_array[0];
2321
+					$query_args = array(
2322
+						'id'      => $edit_array['GRP_ID'],
2323
+						'context' => $edit_array['MTP_context'],
2324
+						'action'  => 'edit_message_template'
2325
+					);
2326
+				}
2327
+			}
2328
+			$action_desc = 'created';
2329
+		} else {
2330
+			$MTPG = EEM_Message_Template_Group::instance();
2331
+			$MTP  = EEM_Message_Template::instance();
2332 2332
             
2333 2333
             
2334
-            //run update for each template field in displayed context
2335
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2336
-                EE_Error::add_error(
2337
-                    __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2338
-                        'event_espresso'),
2339
-                    __FILE__, __FUNCTION__, __LINE__
2340
-                );
2341
-                $success = 0;
2334
+			//run update for each template field in displayed context
2335
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2336
+				EE_Error::add_error(
2337
+					__('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2338
+						'event_espresso'),
2339
+					__FILE__, __FUNCTION__, __LINE__
2340
+				);
2341
+				$success = 0;
2342 2342
                 
2343
-            } else {
2344
-                //first validate all fields!
2345
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2346
-                    $message_type_slug);
2343
+			} else {
2344
+				//first validate all fields!
2345
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2346
+					$message_type_slug);
2347 2347
                 
2348
-                //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.
2349
-                if (is_array($validates) && ! empty($validates)) {
2350
-                    //add the transient so when the form loads we know which fields to highlight
2351
-                    $this->_add_transient('edit_message_template', $validates);
2348
+				//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.
2349
+				if (is_array($validates) && ! empty($validates)) {
2350
+					//add the transient so when the form loads we know which fields to highlight
2351
+					$this->_add_transient('edit_message_template', $validates);
2352 2352
                     
2353
-                    $success = 0;
2353
+					$success = 0;
2354 2354
                     
2355
-                    //setup notices
2356
-                    foreach ($validates as $field => $error) {
2357
-                        if (isset($error['msg'])) {
2358
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2359
-                        }
2360
-                    }
2355
+					//setup notices
2356
+					foreach ($validates as $field => $error) {
2357
+						if (isset($error['msg'])) {
2358
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2359
+						}
2360
+					}
2361 2361
                     
2362
-                } else {
2363
-                    $set_column_values = array();
2364
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2365
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2362
+				} else {
2363
+					$set_column_values = array();
2364
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2365
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2366 2366
                         
2367
-                        $where_cols_n_values = array(
2368
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2369
-                        );
2367
+						$where_cols_n_values = array(
2368
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2369
+						);
2370 2370
                         
2371
-                        $message_template_fields = array(
2372
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2373
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2374
-                            'MTP_context'        => $set_column_values['MTP_context'],
2375
-                            'MTP_content'        => $set_column_values['MTP_content']
2376
-                        );
2377
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2378
-                            if ($updated === false) {
2379
-                                EE_Error::add_error(
2380
-                                    sprintf(
2381
-                                        __('%s field was NOT updated for some reason', 'event_espresso'),
2382
-                                        $template_field
2383
-                                    ),
2384
-                                    __FILE__, __FUNCTION__, __LINE__
2385
-                                );
2386
-                            } else {
2387
-                                $success = 1;
2388
-                            }
2389
-                        }
2390
-                        $action_desc = 'updated';
2391
-                    }
2371
+						$message_template_fields = array(
2372
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2373
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2374
+							'MTP_context'        => $set_column_values['MTP_context'],
2375
+							'MTP_content'        => $set_column_values['MTP_content']
2376
+						);
2377
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2378
+							if ($updated === false) {
2379
+								EE_Error::add_error(
2380
+									sprintf(
2381
+										__('%s field was NOT updated for some reason', 'event_espresso'),
2382
+										$template_field
2383
+									),
2384
+									__FILE__, __FUNCTION__, __LINE__
2385
+								);
2386
+							} else {
2387
+								$success = 1;
2388
+							}
2389
+						}
2390
+						$action_desc = 'updated';
2391
+					}
2392 2392
                     
2393
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2394
-                    $mtpg_fields = array(
2395
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2396
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2397
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2398
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2399
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2400
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2401
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2402
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2403
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2404
-                            : '',
2405
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2406
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2407
-                            : ''
2408
-                    );
2393
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2394
+					$mtpg_fields = array(
2395
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2396
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2397
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2398
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2399
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2400
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2401
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2402
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2403
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2404
+							: '',
2405
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2406
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2407
+							: ''
2408
+					);
2409 2409
                     
2410
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2411
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2410
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2411
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2412 2412
                     
2413
-                    if ($updated === false) {
2414
-                        EE_Error::add_error(
2415
-                            sprintf(
2416
-                                __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2417
-                                $set_column_values['GRP_ID']
2418
-                            ),
2419
-                            __FILE__, __FUNCTION__, __LINE__
2420
-                        );
2421
-                    } else {
2422
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2423
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2424
-                            ? $this->_req_data['MTP_template_pack']
2425
-                            : 'default';
2413
+					if ($updated === false) {
2414
+						EE_Error::add_error(
2415
+							sprintf(
2416
+								__('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2417
+								$set_column_values['GRP_ID']
2418
+							),
2419
+							__FILE__, __FUNCTION__, __LINE__
2420
+						);
2421
+					} else {
2422
+						//k now we need to ensure the template_pack and template_variation fields are set.
2423
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2424
+							? $this->_req_data['MTP_template_pack']
2425
+							: 'default';
2426 2426
                         
2427
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2428
-                            ? $this->_req_data['MTP_template_variation']
2429
-                            : 'default';
2427
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2428
+							? $this->_req_data['MTP_template_variation']
2429
+							: 'default';
2430 2430
                         
2431
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2432
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2433
-                            $mtpg_obj->set_template_pack_name($template_pack);
2434
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2435
-                        }
2436
-                        $success = 1;
2437
-                    }
2438
-                }
2439
-            }
2431
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2432
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2433
+							$mtpg_obj->set_template_pack_name($template_pack);
2434
+							$mtpg_obj->set_template_pack_variation($template_variation);
2435
+						}
2436
+						$success = 1;
2437
+					}
2438
+				}
2439
+			}
2440 2440
             
2441
-        }
2442
-        
2443
-        //we return things differently if doing ajax
2444
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2445
-            $this->_template_args['success'] = $success;
2446
-            $this->_template_args['error']   = ! $success ? true : false;
2447
-            $this->_template_args['content'] = '';
2448
-            $this->_template_args['data']    = array(
2449
-                'grpID'        => $edit_array['GRP_ID'],
2450
-                'templateName' => $edit_array['template_name']
2451
-            );
2452
-            if ($success) {
2453
-                EE_Error::overwrite_success();
2454
-                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.',
2455
-                    'event_espresso'));
2456
-            }
2441
+		}
2442
+        
2443
+		//we return things differently if doing ajax
2444
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2445
+			$this->_template_args['success'] = $success;
2446
+			$this->_template_args['error']   = ! $success ? true : false;
2447
+			$this->_template_args['content'] = '';
2448
+			$this->_template_args['data']    = array(
2449
+				'grpID'        => $edit_array['GRP_ID'],
2450
+				'templateName' => $edit_array['template_name']
2451
+			);
2452
+			if ($success) {
2453
+				EE_Error::overwrite_success();
2454
+				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.',
2455
+					'event_espresso'));
2456
+			}
2457 2457
             
2458
-            $this->_return_json();
2459
-        }
2460
-        
2461
-        
2462
-        //was a test send triggered?
2463
-        if (isset($this->_req_data['test_button'])) {
2464
-            EE_Error::overwrite_success();
2465
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2466
-            $override = true;
2467
-        }
2468
-        
2469
-        if (empty($query_args)) {
2470
-            $query_args = array(
2471
-                'id'      => $this->_req_data['GRP_ID'],
2472
-                'context' => $context_slug,
2473
-                'action'  => 'edit_message_template'
2474
-            );
2475
-        }
2476
-        
2477
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2478
-    }
2479
-    
2480
-    
2481
-    /**
2482
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2483
-     *
2484
-     * @param  string $context      what context being tested
2485
-     * @param  string $messenger    messenger being tested
2486
-     * @param  string $message_type message type being tested
2487
-     *
2488
-     */
2489
-    protected function _do_test_send($context, $messenger, $message_type)
2490
-    {
2491
-        //set things up for preview
2492
-        $this->_req_data['messenger']    = $messenger;
2493
-        $this->_req_data['message_type'] = $message_type;
2494
-        $this->_req_data['context']      = $context;
2495
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2496
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2497
-        
2498
-        //let's save any existing fields that might be required by the messenger
2499
-        if (
2500
-            isset($this->_req_data['test_settings_fld'])
2501
-            && $active_messenger instanceof EE_messenger
2502
-        ) {
2503
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2504
-        }
2505
-        
2506
-        $success = $this->_preview_message(true);
2507
-        
2508
-        if ($success) {
2509
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2510
-        } else {
2511
-            EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2512
-                __LINE__);
2513
-        }
2514
-    }
2515
-    
2516
-    
2517
-    /**
2518
-     * _generate_new_templates
2519
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2520
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2521
-     * for the event.
2522
-     *
2523
-     *
2524
-     * @param  string $messenger     the messenger we are generating templates for
2525
-     * @param array   $message_types array of message types that the templates are generated for.
2526
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2527
-     *                               indicate the message_template_group being used as the base.
2528
-     *
2529
-     * @param bool    $global
2530
-     *
2531
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2532
-     *                               encountering problems.
2533
-     * @throws \EE_Error
2534
-     */
2535
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2536
-    {
2537
-        
2538
-        //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.
2539
-        if (empty($message_types)) {
2540
-            return true;
2541
-        }
2542
-        
2543
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2544
-    }
2545
-    
2546
-    
2547
-    /**
2548
-     * [_trash_or_restore_message_template]
2549
-     *
2550
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2551
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2552
-     *                        an individual context (FALSE).
2553
-     *
2554
-     * @return void
2555
-     */
2556
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2557
-    {
2558
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2559
-        $MTP = EEM_Message_Template_Group::instance();
2560
-        
2561
-        $success = 1;
2562
-        
2563
-        //incoming GRP_IDs
2564
-        if ($all) {
2565
-            //Checkboxes
2566
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2567
-                //if array has more than one element then success message should be plural.
2568
-                //todo: what about nonce?
2569
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2458
+			$this->_return_json();
2459
+		}
2460
+        
2461
+        
2462
+		//was a test send triggered?
2463
+		if (isset($this->_req_data['test_button'])) {
2464
+			EE_Error::overwrite_success();
2465
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2466
+			$override = true;
2467
+		}
2468
+        
2469
+		if (empty($query_args)) {
2470
+			$query_args = array(
2471
+				'id'      => $this->_req_data['GRP_ID'],
2472
+				'context' => $context_slug,
2473
+				'action'  => 'edit_message_template'
2474
+			);
2475
+		}
2476
+        
2477
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2478
+	}
2479
+    
2480
+    
2481
+	/**
2482
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2483
+	 *
2484
+	 * @param  string $context      what context being tested
2485
+	 * @param  string $messenger    messenger being tested
2486
+	 * @param  string $message_type message type being tested
2487
+	 *
2488
+	 */
2489
+	protected function _do_test_send($context, $messenger, $message_type)
2490
+	{
2491
+		//set things up for preview
2492
+		$this->_req_data['messenger']    = $messenger;
2493
+		$this->_req_data['message_type'] = $message_type;
2494
+		$this->_req_data['context']      = $context;
2495
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2496
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2497
+        
2498
+		//let's save any existing fields that might be required by the messenger
2499
+		if (
2500
+			isset($this->_req_data['test_settings_fld'])
2501
+			&& $active_messenger instanceof EE_messenger
2502
+		) {
2503
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2504
+		}
2505
+        
2506
+		$success = $this->_preview_message(true);
2507
+        
2508
+		if ($success) {
2509
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2510
+		} else {
2511
+			EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2512
+				__LINE__);
2513
+		}
2514
+	}
2515
+    
2516
+    
2517
+	/**
2518
+	 * _generate_new_templates
2519
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2520
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2521
+	 * for the event.
2522
+	 *
2523
+	 *
2524
+	 * @param  string $messenger     the messenger we are generating templates for
2525
+	 * @param array   $message_types array of message types that the templates are generated for.
2526
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2527
+	 *                               indicate the message_template_group being used as the base.
2528
+	 *
2529
+	 * @param bool    $global
2530
+	 *
2531
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2532
+	 *                               encountering problems.
2533
+	 * @throws \EE_Error
2534
+	 */
2535
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2536
+	{
2537
+        
2538
+		//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.
2539
+		if (empty($message_types)) {
2540
+			return true;
2541
+		}
2542
+        
2543
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2544
+	}
2545
+    
2546
+    
2547
+	/**
2548
+	 * [_trash_or_restore_message_template]
2549
+	 *
2550
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2551
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2552
+	 *                        an individual context (FALSE).
2553
+	 *
2554
+	 * @return void
2555
+	 */
2556
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2557
+	{
2558
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2559
+		$MTP = EEM_Message_Template_Group::instance();
2560
+        
2561
+		$success = 1;
2562
+        
2563
+		//incoming GRP_IDs
2564
+		if ($all) {
2565
+			//Checkboxes
2566
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2567
+				//if array has more than one element then success message should be plural.
2568
+				//todo: what about nonce?
2569
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2570 2570
                 
2571
-                //cycle through checkboxes
2572
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2573
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2574
-                    if ( ! $trashed_or_restored) {
2575
-                        $success = 0;
2576
-                    }
2577
-                }
2578
-            } else {
2579
-                //grab single GRP_ID and handle
2580
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2581
-                if ( ! empty($GRP_ID)) {
2582
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2583
-                    if ( ! $trashed_or_restored) {
2584
-                        $success = 0;
2585
-                    }
2586
-                } else {
2587
-                    $success = 0;
2588
-                }
2589
-            }
2571
+				//cycle through checkboxes
2572
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2573
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2574
+					if ( ! $trashed_or_restored) {
2575
+						$success = 0;
2576
+					}
2577
+				}
2578
+			} else {
2579
+				//grab single GRP_ID and handle
2580
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2581
+				if ( ! empty($GRP_ID)) {
2582
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2583
+					if ( ! $trashed_or_restored) {
2584
+						$success = 0;
2585
+					}
2586
+				} else {
2587
+					$success = 0;
2588
+				}
2589
+			}
2590 2590
             
2591
-        }
2591
+		}
2592 2592
         
2593
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2593
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2594 2594
         
2595
-        $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2595
+		$action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2596 2596
         
2597
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2598
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2597
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2598
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2599 2599
         
2600
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2601
-            'event_espresso') : $item_desc;
2600
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2601
+			'event_espresso') : $item_desc;
2602 2602
         
2603
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
2603
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
2604 2604
         
2605
-    }
2605
+	}
2606 2606
     
2607 2607
     
2608
-    /**
2609
-     * [_delete_message_template]
2610
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2611
-     * @return void
2612
-     */
2613
-    protected function _delete_message_template()
2614
-    {
2615
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2608
+	/**
2609
+	 * [_delete_message_template]
2610
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2611
+	 * @return void
2612
+	 */
2613
+	protected function _delete_message_template()
2614
+	{
2615
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2616 2616
         
2617
-        //checkboxes
2618
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2619
-            //if array has more than one element then success message should be plural
2620
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2617
+		//checkboxes
2618
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2619
+			//if array has more than one element then success message should be plural
2620
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2621 2621
             
2622
-            //cycle through bulk action checkboxes
2623
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2624
-                $success = $this->_delete_mtp_permanently($GRP_ID);
2625
-            }
2626
-        } else {
2627
-            //grab single grp_id and delete
2628
-            $GRP_ID  = absint($this->_req_data['id']);
2629
-            $success = $this->_delete_mtp_permanently($GRP_ID);
2630
-        }
2631
-        
2632
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2633
-        
2634
-    }
2635
-    
2636
-    
2637
-    /**
2638
-     * helper for permanently deleting a mtP group and all related message_templates
2639
-     *
2640
-     * @param  int  $GRP_ID        The group being deleted
2641
-     * @param  bool $include_group whether to delete the Message Template Group as well.
2642
-     *
2643
-     * @return bool        boolean to indicate the success of the deletes or not.
2644
-     */
2645
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2646
-    {
2647
-        $success = 1;
2648
-        $MTPG    = EEM_Message_Template_Group::instance();
2649
-        //first let's GET this group
2650
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
2651
-        //then delete permanently all the related Message Templates
2652
-        $deleted = $MTG->delete_related_permanently('Message_Template');
2653
-        
2654
-        if ($deleted === 0) {
2655
-            $success = 0;
2656
-        }
2657
-        
2658
-        //now delete permanently this particular group
2659
-        
2660
-        if ($include_group && ! $MTG->delete_permanently()) {
2661
-            $success = 0;
2662
-        }
2663
-        
2664
-        return $success;
2665
-    }
2666
-    
2667
-    
2668
-    /**
2669
-     *    _learn_more_about_message_templates_link
2670
-     * @access protected
2671
-     * @return string
2672
-     */
2673
-    protected function _learn_more_about_message_templates_link()
2674
-    {
2675
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2676
-            'event_espresso') . '</a>';
2677
-    }
2678
-    
2679
-    
2680
-    /**
2681
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2682
-     * ajax and other routes.
2683
-     * @return void
2684
-     */
2685
-    protected function _settings()
2686
-    {
2687
-        
2688
-        
2689
-        $this->_set_m_mt_settings();
2690
-        
2691
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2692
-        
2693
-        //let's setup the messenger tabs
2694
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2695
-            'messenger_links', '|', $selected_messenger);
2696
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2697
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2698
-        
2699
-        $this->display_admin_page_with_sidebar();
2700
-        
2701
-    }
2702
-    
2703
-    
2704
-    /**
2705
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2706
-     *
2707
-     * @access protected
2708
-     * @return void
2709
-     */
2710
-    protected function _set_m_mt_settings()
2711
-    {
2712
-        //first if this is already set then lets get out no need to regenerate data.
2713
-        if ( ! empty($this->_m_mt_settings)) {
2714
-            return;
2715
-        }
2716
-        
2717
-        //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2718
-        
2719
-        //get all installed messengers and message_types
2720
-        /** @type EE_messenger[] $messengers */
2721
-        $messengers = $this->_message_resource_manager->installed_messengers();
2722
-        /** @type EE_message_type[] $message_types */
2723
-        $message_types = $this->_message_resource_manager->installed_message_types();
2724
-        
2725
-        
2726
-        //assemble the array for the _tab_text_links helper
2727
-        
2728
-        foreach ($messengers as $messenger) {
2729
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2730
-                'label' => ucwords($messenger->label['singular']),
2731
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2732
-                'href'  => $messenger->name,
2733
-                'title' => __('Modify this Messenger', 'event_espresso'),
2734
-                'slug'  => $messenger->name,
2735
-                'obj'   => $messenger
2736
-            );
2622
+			//cycle through bulk action checkboxes
2623
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2624
+				$success = $this->_delete_mtp_permanently($GRP_ID);
2625
+			}
2626
+		} else {
2627
+			//grab single grp_id and delete
2628
+			$GRP_ID  = absint($this->_req_data['id']);
2629
+			$success = $this->_delete_mtp_permanently($GRP_ID);
2630
+		}
2631
+        
2632
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2633
+        
2634
+	}
2635
+    
2636
+    
2637
+	/**
2638
+	 * helper for permanently deleting a mtP group and all related message_templates
2639
+	 *
2640
+	 * @param  int  $GRP_ID        The group being deleted
2641
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
2642
+	 *
2643
+	 * @return bool        boolean to indicate the success of the deletes or not.
2644
+	 */
2645
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2646
+	{
2647
+		$success = 1;
2648
+		$MTPG    = EEM_Message_Template_Group::instance();
2649
+		//first let's GET this group
2650
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
2651
+		//then delete permanently all the related Message Templates
2652
+		$deleted = $MTG->delete_related_permanently('Message_Template');
2653
+        
2654
+		if ($deleted === 0) {
2655
+			$success = 0;
2656
+		}
2657
+        
2658
+		//now delete permanently this particular group
2659
+        
2660
+		if ($include_group && ! $MTG->delete_permanently()) {
2661
+			$success = 0;
2662
+		}
2663
+        
2664
+		return $success;
2665
+	}
2666
+    
2667
+    
2668
+	/**
2669
+	 *    _learn_more_about_message_templates_link
2670
+	 * @access protected
2671
+	 * @return string
2672
+	 */
2673
+	protected function _learn_more_about_message_templates_link()
2674
+	{
2675
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2676
+			'event_espresso') . '</a>';
2677
+	}
2678
+    
2679
+    
2680
+	/**
2681
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2682
+	 * ajax and other routes.
2683
+	 * @return void
2684
+	 */
2685
+	protected function _settings()
2686
+	{
2687
+        
2688
+        
2689
+		$this->_set_m_mt_settings();
2690
+        
2691
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2692
+        
2693
+		//let's setup the messenger tabs
2694
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2695
+			'messenger_links', '|', $selected_messenger);
2696
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2697
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2698
+        
2699
+		$this->display_admin_page_with_sidebar();
2700
+        
2701
+	}
2702
+    
2703
+    
2704
+	/**
2705
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2706
+	 *
2707
+	 * @access protected
2708
+	 * @return void
2709
+	 */
2710
+	protected function _set_m_mt_settings()
2711
+	{
2712
+		//first if this is already set then lets get out no need to regenerate data.
2713
+		if ( ! empty($this->_m_mt_settings)) {
2714
+			return;
2715
+		}
2716
+        
2717
+		//$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2718
+        
2719
+		//get all installed messengers and message_types
2720
+		/** @type EE_messenger[] $messengers */
2721
+		$messengers = $this->_message_resource_manager->installed_messengers();
2722
+		/** @type EE_message_type[] $message_types */
2723
+		$message_types = $this->_message_resource_manager->installed_message_types();
2724
+        
2725
+        
2726
+		//assemble the array for the _tab_text_links helper
2727
+        
2728
+		foreach ($messengers as $messenger) {
2729
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2730
+				'label' => ucwords($messenger->label['singular']),
2731
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2732
+				'href'  => $messenger->name,
2733
+				'title' => __('Modify this Messenger', 'event_espresso'),
2734
+				'slug'  => $messenger->name,
2735
+				'obj'   => $messenger
2736
+			);
2737 2737
             
2738 2738
             
2739
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2739
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2740 2740
             
2741
-            foreach ($message_types as $message_type) {
2742
-                //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.
2743
-                if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2744
-                    continue;
2745
-                }
2741
+			foreach ($message_types as $message_type) {
2742
+				//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.
2743
+				if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2744
+					continue;
2745
+				}
2746 2746
                 
2747
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2748
-                    $message_type->name) ? 'active' : 'inactive';
2747
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2748
+					$message_type->name) ? 'active' : 'inactive';
2749 2749
                 
2750
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2751
-                    'label'    => ucwords($message_type->label['singular']),
2752
-                    'class'    => 'message-type-' . $a_or_i,
2753
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2754
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2755
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2756
-                    'title'    => $a_or_i == 'active'
2757
-                        ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2758
-                        : __('Drag this message type to the messenger to activate', 'event_espresso'),
2759
-                    'content'  => $a_or_i == 'active'
2760
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2761
-                        : $this->_message_type_settings_content($message_type, $messenger),
2762
-                    'slug'     => $message_type->name,
2763
-                    'active'   => $a_or_i == 'active' ? true : false,
2764
-                    'obj'      => $message_type
2765
-                );
2766
-            }
2767
-        }
2768
-    }
2769
-    
2770
-    
2771
-    /**
2772
-     * This just prepares the content for the message type settings
2773
-     *
2774
-     * @param  object  $message_type The message type object
2775
-     * @param  object  $messenger    The messenger object
2776
-     * @param  boolean $active       Whether the message type is active or not
2777
-     *
2778
-     * @return string                html output for the content
2779
-     */
2780
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2781
-    {
2782
-        //get message type fields
2783
-        $fields                                         = $message_type->get_admin_settings_fields();
2784
-        $settings_template_args['template_form_fields'] = '';
2785
-        
2786
-        if ( ! empty($fields) && $active) {
2750
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2751
+					'label'    => ucwords($message_type->label['singular']),
2752
+					'class'    => 'message-type-' . $a_or_i,
2753
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2754
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2755
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2756
+					'title'    => $a_or_i == 'active'
2757
+						? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2758
+						: __('Drag this message type to the messenger to activate', 'event_espresso'),
2759
+					'content'  => $a_or_i == 'active'
2760
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2761
+						: $this->_message_type_settings_content($message_type, $messenger),
2762
+					'slug'     => $message_type->name,
2763
+					'active'   => $a_or_i == 'active' ? true : false,
2764
+					'obj'      => $message_type
2765
+				);
2766
+			}
2767
+		}
2768
+	}
2769
+    
2770
+    
2771
+	/**
2772
+	 * This just prepares the content for the message type settings
2773
+	 *
2774
+	 * @param  object  $message_type The message type object
2775
+	 * @param  object  $messenger    The messenger object
2776
+	 * @param  boolean $active       Whether the message type is active or not
2777
+	 *
2778
+	 * @return string                html output for the content
2779
+	 */
2780
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2781
+	{
2782
+		//get message type fields
2783
+		$fields                                         = $message_type->get_admin_settings_fields();
2784
+		$settings_template_args['template_form_fields'] = '';
2785
+        
2786
+		if ( ! empty($fields) && $active) {
2787 2787
             
2788
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2788
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2789 2789
             
2790
-            foreach ($fields as $fldname => $fldprops) {
2791
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2792
-                $template_form_field[$field_id] = array(
2793
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2794
-                    'label'      => $fldprops['label'],
2795
-                    'input'      => $fldprops['field_type'],
2796
-                    'type'       => $fldprops['value_type'],
2797
-                    'required'   => $fldprops['required'],
2798
-                    'validation' => $fldprops['validation'],
2799
-                    'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2800
-                    'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2801
-                    'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2802
-                    'css_class'  => 'no-drag',
2803
-                    'format'     => $fldprops['format']
2804
-                );
2805
-            }
2790
+			foreach ($fields as $fldname => $fldprops) {
2791
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2792
+				$template_form_field[$field_id] = array(
2793
+					'name'       => 'message_type_settings[' . $fldname . ']',
2794
+					'label'      => $fldprops['label'],
2795
+					'input'      => $fldprops['field_type'],
2796
+					'type'       => $fldprops['value_type'],
2797
+					'required'   => $fldprops['required'],
2798
+					'validation' => $fldprops['validation'],
2799
+					'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2800
+					'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2801
+					'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2802
+					'css_class'  => 'no-drag',
2803
+					'format'     => $fldprops['format']
2804
+				);
2805
+			}
2806 2806
             
2807 2807
             
2808
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2809
-                'string', 'ee_mt_activate_form') : '';
2810
-        }
2811
-        
2812
-        $settings_template_args['description'] = $message_type->description;
2813
-        //we also need some hidden fields
2814
-        $settings_template_args['hidden_fields'] = array(
2815
-            'message_type_settings[messenger]'    => array(
2816
-                'type'  => 'hidden',
2817
-                'value' => $messenger->name
2818
-            ),
2819
-            'message_type_settings[message_type]' => array(
2820
-                'type'  => 'hidden',
2821
-                'value' => $message_type->name
2822
-            ),
2823
-            'type'                                => array(
2824
-                'type'  => 'hidden',
2825
-                'value' => 'message_type'
2826
-            )
2827
-        );
2828
-        
2829
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2830
-            'array');
2831
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2832
-        
2833
-        
2834
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2835
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
2836
-        
2837
-        return $content;
2838
-    }
2839
-    
2840
-    
2841
-    /**
2842
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
2843
-     *
2844
-     * @access protected
2845
-     * @return void
2846
-     */
2847
-    protected function _messages_settings_metaboxes()
2848
-    {
2849
-        $this->_set_m_mt_settings();
2850
-        $m_boxes         = $mt_boxes = array();
2851
-        $m_template_args = $mt_template_args = array();
2852
-        
2853
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2854
-        
2855
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
2856
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2857
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2858
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2859
-                //messenger meta boxes
2860
-                $active                                 = $selected_messenger == $messenger ? true : false;
2861
-                $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2862
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2863
-                    : '';
2864
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2865
-                    __('%s Settings', 'event_espresso'),
2866
-                    $tab_array['label']
2867
-                );
2868
-                $m_template_args[$messenger . '_a_box'] = array(
2869
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2870
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2871
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2872
-                        : '',
2873
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2874
-                    'hidden'                 => $active ? '' : ' hidden',
2875
-                    'hide_on_message'        => $hide_on_message,
2876
-                    'messenger'              => $messenger,
2877
-                    'active'                 => $active
2878
-                );
2879
-                // message type meta boxes
2880
-                // (which is really just the inactive container for each messenger
2881
-                // showing inactive message types for that messenger)
2882
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2883
-                $mt_template_args[$messenger . '_i_box'] = array(
2884
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2885
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2886
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2887
-                        : '',
2888
-                    'hidden'                 => $active ? '' : ' hidden',
2889
-                    'hide_on_message'        => $hide_on_message,
2890
-                    'hide_off_message'       => $hide_off_message,
2891
-                    'messenger'              => $messenger,
2892
-                    'active'                 => $active
2893
-                );
2894
-            }
2895
-        }
2896
-        
2897
-        
2898
-        //register messenger metaboxes
2899
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2900
-        foreach ($m_boxes as $box => $label) {
2901
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2902
-            $msgr          = str_replace('_a_box', '', $box);
2903
-            add_meta_box(
2904
-                'espresso_' . $msgr . '_settings',
2905
-                $label,
2906
-                function ($post, $metabox) {
2907
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2908
-                        $metabox["args"]["template_args"], true);
2909
-                },
2910
-                $this->_current_screen->id,
2911
-                'normal',
2912
-                'high',
2913
-                $callback_args
2914
-            );
2915
-        }
2916
-        
2917
-        //register message type metaboxes
2918
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2919
-        foreach ($mt_boxes as $box => $label) {
2920
-            $callback_args = array(
2921
-                'template_path' => $mt_template_path,
2922
-                'template_args' => $mt_template_args[$box]
2923
-            );
2924
-            $mt            = str_replace('_i_box', '', $box);
2925
-            add_meta_box(
2926
-                'espresso_' . $mt . '_inactive_mts',
2927
-                $label,
2928
-                function ($post, $metabox) {
2929
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2930
-                        $metabox["args"]["template_args"], true);
2931
-                },
2932
-                $this->_current_screen->id,
2933
-                'side',
2934
-                'high',
2935
-                $callback_args
2936
-            );
2937
-        }
2938
-        
2939
-        //register metabox for global messages settings but only when on the main site.  On single site installs this will
2940
-        //always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2941
-        if (is_main_site()) {
2942
-            add_meta_box(
2943
-                'espresso_global_message_settings',
2944
-                __('Global Message Settings', 'event_espresso'),
2945
-                array($this, 'global_messages_settings_metabox_content'),
2946
-                $this->_current_screen->id,
2947
-                'normal',
2948
-                'low',
2949
-                array()
2950
-            );
2951
-        }
2952
-        
2953
-    }
2954
-    
2955
-    
2956
-    /**
2957
-     *  This generates the content for the global messages settings metabox.
2958
-     * @return string
2959
-     */
2960
-    public function global_messages_settings_metabox_content()
2961
-    {
2962
-        $form = $this->_generate_global_settings_form();
2963
-        echo $form->form_open(
2964
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2965
-                'POST'
2966
-            )
2967
-             . $form->get_html()
2968
-             . $form->form_close();
2969
-    }
2970
-    
2971
-    
2972
-    /**
2973
-     * This generates and returns the form object for the global messages settings.
2974
-     * @return EE_Form_Section_Proper
2975
-     */
2976
-    protected function _generate_global_settings_form()
2977
-    {
2978
-        EE_Registry::instance()->load_helper('HTML');
2979
-        /** @var EE_Network_Core_Config $network_config */
2980
-        $network_config = EE_Registry::instance()->NET_CFG->core;
2981
-        
2982
-        return new EE_Form_Section_Proper(
2983
-            array(
2984
-                'name'            => 'global_messages_settings',
2985
-                'html_id'         => 'global_messages_settings',
2986
-                'html_class'      => 'form-table',
2987
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2988
-                'subsections'     => apply_filters(
2989
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
2990
-                    array(
2991
-                        'do_messages_on_same_request' => new EE_Select_Input(
2992
-                            array(
2993
-                                true  => __("On the same request", "event_espresso"),
2994
-                                false => __("On a separate request", "event_espresso")
2995
-                            ),
2996
-                            array(
2997
-                                'default'         => $network_config->do_messages_on_same_request,
2998
-                                'html_label_text' => __('Generate and send all messages:', 'event_espresso'),
2999
-                                'html_help_text'  => __('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.',
3000
-                                    'event_espresso'),
3001
-                            )
3002
-                        ),
3003
-                        'update_settings'             => new EE_Submit_Input(
3004
-                            array(
3005
-                                'default'         => __('Update', 'event_espresso'),
3006
-                                'html_label_text' => '&nbsp'
3007
-                            )
3008
-                        )
3009
-                    )
3010
-                )
3011
-            )
3012
-        );
3013
-    }
3014
-    
3015
-    
3016
-    /**
3017
-     * This handles updating the global settings set on the admin page.
3018
-     * @throws \EE_Error
3019
-     */
3020
-    protected function _update_global_settings()
3021
-    {
3022
-        /** @var EE_Network_Core_Config $network_config */
3023
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3024
-        $form           = $this->_generate_global_settings_form();
3025
-        if ($form->was_submitted()) {
3026
-            $form->receive_form_submission();
3027
-            if ($form->is_valid()) {
3028
-                $valid_data = $form->valid_data();
3029
-                foreach ($valid_data as $property => $value) {
3030
-                    $setter = 'set_' . $property;
3031
-                    if (method_exists($network_config, $setter)) {
3032
-                        $network_config->{$setter}($value);
3033
-                    } else if (
3034
-                        property_exists($network_config, $property)
3035
-                        && $network_config->{$property} !== $value
3036
-                    ) {
3037
-                        $network_config->{$property} = $value;
3038
-                    }
3039
-                }
3040
-                //only update if the form submission was valid!
3041
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3042
-                EE_Error::overwrite_success();
3043
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3044
-            }
3045
-        }
3046
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3047
-    }
3048
-    
3049
-    
3050
-    /**
3051
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3052
-     *
3053
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3054
-     *
3055
-     * @return string            html formatted tabs
3056
-     */
3057
-    protected function _get_mt_tabs($tab_array)
3058
-    {
3059
-        $tab_array = (array)$tab_array;
3060
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3061
-        $tabs      = '';
3062
-        
3063
-        foreach ($tab_array as $tab) {
3064
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3065
-        }
3066
-        
3067
-        return $tabs;
3068
-    }
3069
-    
3070
-    
3071
-    /**
3072
-     * This prepares the content of the messenger meta box admin settings
3073
-     *
3074
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3075
-     *
3076
-     * @return string            html formatted content
3077
-     */
3078
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3079
-    {
3080
-        
3081
-        $fields                                         = $messenger->get_admin_settings_fields();
3082
-        $settings_template_args['template_form_fields'] = '';
3083
-        
3084
-        //is $messenger active?
3085
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3086
-        
3087
-        
3088
-        if ( ! empty($fields)) {
2808
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2809
+				'string', 'ee_mt_activate_form') : '';
2810
+		}
2811
+        
2812
+		$settings_template_args['description'] = $message_type->description;
2813
+		//we also need some hidden fields
2814
+		$settings_template_args['hidden_fields'] = array(
2815
+			'message_type_settings[messenger]'    => array(
2816
+				'type'  => 'hidden',
2817
+				'value' => $messenger->name
2818
+			),
2819
+			'message_type_settings[message_type]' => array(
2820
+				'type'  => 'hidden',
2821
+				'value' => $message_type->name
2822
+			),
2823
+			'type'                                => array(
2824
+				'type'  => 'hidden',
2825
+				'value' => 'message_type'
2826
+			)
2827
+		);
2828
+        
2829
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2830
+			'array');
2831
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2832
+        
2833
+        
2834
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2835
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
2836
+        
2837
+		return $content;
2838
+	}
2839
+    
2840
+    
2841
+	/**
2842
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
2843
+	 *
2844
+	 * @access protected
2845
+	 * @return void
2846
+	 */
2847
+	protected function _messages_settings_metaboxes()
2848
+	{
2849
+		$this->_set_m_mt_settings();
2850
+		$m_boxes         = $mt_boxes = array();
2851
+		$m_template_args = $mt_template_args = array();
2852
+        
2853
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2854
+        
2855
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
2856
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2857
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2858
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2859
+				//messenger meta boxes
2860
+				$active                                 = $selected_messenger == $messenger ? true : false;
2861
+				$active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2862
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2863
+					: '';
2864
+				$m_boxes[$messenger . '_a_box']         = sprintf(
2865
+					__('%s Settings', 'event_espresso'),
2866
+					$tab_array['label']
2867
+				);
2868
+				$m_template_args[$messenger . '_a_box'] = array(
2869
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2870
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2871
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2872
+						: '',
2873
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2874
+					'hidden'                 => $active ? '' : ' hidden',
2875
+					'hide_on_message'        => $hide_on_message,
2876
+					'messenger'              => $messenger,
2877
+					'active'                 => $active
2878
+				);
2879
+				// message type meta boxes
2880
+				// (which is really just the inactive container for each messenger
2881
+				// showing inactive message types for that messenger)
2882
+				$mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2883
+				$mt_template_args[$messenger . '_i_box'] = array(
2884
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2885
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2886
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2887
+						: '',
2888
+					'hidden'                 => $active ? '' : ' hidden',
2889
+					'hide_on_message'        => $hide_on_message,
2890
+					'hide_off_message'       => $hide_off_message,
2891
+					'messenger'              => $messenger,
2892
+					'active'                 => $active
2893
+				);
2894
+			}
2895
+		}
2896
+        
2897
+        
2898
+		//register messenger metaboxes
2899
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2900
+		foreach ($m_boxes as $box => $label) {
2901
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2902
+			$msgr          = str_replace('_a_box', '', $box);
2903
+			add_meta_box(
2904
+				'espresso_' . $msgr . '_settings',
2905
+				$label,
2906
+				function ($post, $metabox) {
2907
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2908
+						$metabox["args"]["template_args"], true);
2909
+				},
2910
+				$this->_current_screen->id,
2911
+				'normal',
2912
+				'high',
2913
+				$callback_args
2914
+			);
2915
+		}
2916
+        
2917
+		//register message type metaboxes
2918
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2919
+		foreach ($mt_boxes as $box => $label) {
2920
+			$callback_args = array(
2921
+				'template_path' => $mt_template_path,
2922
+				'template_args' => $mt_template_args[$box]
2923
+			);
2924
+			$mt            = str_replace('_i_box', '', $box);
2925
+			add_meta_box(
2926
+				'espresso_' . $mt . '_inactive_mts',
2927
+				$label,
2928
+				function ($post, $metabox) {
2929
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2930
+						$metabox["args"]["template_args"], true);
2931
+				},
2932
+				$this->_current_screen->id,
2933
+				'side',
2934
+				'high',
2935
+				$callback_args
2936
+			);
2937
+		}
2938
+        
2939
+		//register metabox for global messages settings but only when on the main site.  On single site installs this will
2940
+		//always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2941
+		if (is_main_site()) {
2942
+			add_meta_box(
2943
+				'espresso_global_message_settings',
2944
+				__('Global Message Settings', 'event_espresso'),
2945
+				array($this, 'global_messages_settings_metabox_content'),
2946
+				$this->_current_screen->id,
2947
+				'normal',
2948
+				'low',
2949
+				array()
2950
+			);
2951
+		}
2952
+        
2953
+	}
2954
+    
2955
+    
2956
+	/**
2957
+	 *  This generates the content for the global messages settings metabox.
2958
+	 * @return string
2959
+	 */
2960
+	public function global_messages_settings_metabox_content()
2961
+	{
2962
+		$form = $this->_generate_global_settings_form();
2963
+		echo $form->form_open(
2964
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2965
+				'POST'
2966
+			)
2967
+			 . $form->get_html()
2968
+			 . $form->form_close();
2969
+	}
2970
+    
2971
+    
2972
+	/**
2973
+	 * This generates and returns the form object for the global messages settings.
2974
+	 * @return EE_Form_Section_Proper
2975
+	 */
2976
+	protected function _generate_global_settings_form()
2977
+	{
2978
+		EE_Registry::instance()->load_helper('HTML');
2979
+		/** @var EE_Network_Core_Config $network_config */
2980
+		$network_config = EE_Registry::instance()->NET_CFG->core;
2981
+        
2982
+		return new EE_Form_Section_Proper(
2983
+			array(
2984
+				'name'            => 'global_messages_settings',
2985
+				'html_id'         => 'global_messages_settings',
2986
+				'html_class'      => 'form-table',
2987
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2988
+				'subsections'     => apply_filters(
2989
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
2990
+					array(
2991
+						'do_messages_on_same_request' => new EE_Select_Input(
2992
+							array(
2993
+								true  => __("On the same request", "event_espresso"),
2994
+								false => __("On a separate request", "event_espresso")
2995
+							),
2996
+							array(
2997
+								'default'         => $network_config->do_messages_on_same_request,
2998
+								'html_label_text' => __('Generate and send all messages:', 'event_espresso'),
2999
+								'html_help_text'  => __('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.',
3000
+									'event_espresso'),
3001
+							)
3002
+						),
3003
+						'update_settings'             => new EE_Submit_Input(
3004
+							array(
3005
+								'default'         => __('Update', 'event_espresso'),
3006
+								'html_label_text' => '&nbsp'
3007
+							)
3008
+						)
3009
+					)
3010
+				)
3011
+			)
3012
+		);
3013
+	}
3014
+    
3015
+    
3016
+	/**
3017
+	 * This handles updating the global settings set on the admin page.
3018
+	 * @throws \EE_Error
3019
+	 */
3020
+	protected function _update_global_settings()
3021
+	{
3022
+		/** @var EE_Network_Core_Config $network_config */
3023
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3024
+		$form           = $this->_generate_global_settings_form();
3025
+		if ($form->was_submitted()) {
3026
+			$form->receive_form_submission();
3027
+			if ($form->is_valid()) {
3028
+				$valid_data = $form->valid_data();
3029
+				foreach ($valid_data as $property => $value) {
3030
+					$setter = 'set_' . $property;
3031
+					if (method_exists($network_config, $setter)) {
3032
+						$network_config->{$setter}($value);
3033
+					} else if (
3034
+						property_exists($network_config, $property)
3035
+						&& $network_config->{$property} !== $value
3036
+					) {
3037
+						$network_config->{$property} = $value;
3038
+					}
3039
+				}
3040
+				//only update if the form submission was valid!
3041
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3042
+				EE_Error::overwrite_success();
3043
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3044
+			}
3045
+		}
3046
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3047
+	}
3048
+    
3049
+    
3050
+	/**
3051
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3052
+	 *
3053
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3054
+	 *
3055
+	 * @return string            html formatted tabs
3056
+	 */
3057
+	protected function _get_mt_tabs($tab_array)
3058
+	{
3059
+		$tab_array = (array)$tab_array;
3060
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3061
+		$tabs      = '';
3062
+        
3063
+		foreach ($tab_array as $tab) {
3064
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3065
+		}
3066
+        
3067
+		return $tabs;
3068
+	}
3069
+    
3070
+    
3071
+	/**
3072
+	 * This prepares the content of the messenger meta box admin settings
3073
+	 *
3074
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3075
+	 *
3076
+	 * @return string            html formatted content
3077
+	 */
3078
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3079
+	{
3080
+        
3081
+		$fields                                         = $messenger->get_admin_settings_fields();
3082
+		$settings_template_args['template_form_fields'] = '';
3083
+        
3084
+		//is $messenger active?
3085
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3086
+        
3087
+        
3088
+		if ( ! empty($fields)) {
3089 3089
             
3090
-            $existing_settings = $messenger->get_existing_admin_settings();
3090
+			$existing_settings = $messenger->get_existing_admin_settings();
3091 3091
             
3092
-            foreach ($fields as $fldname => $fldprops) {
3093
-                $field_id                       = $messenger->name . '-' . $fldname;
3094
-                $template_form_field[$field_id] = array(
3095
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3096
-                    'label'      => $fldprops['label'],
3097
-                    'input'      => $fldprops['field_type'],
3098
-                    'type'       => $fldprops['value_type'],
3099
-                    'required'   => $fldprops['required'],
3100
-                    'validation' => $fldprops['validation'],
3101
-                    'value'      => isset($existing_settings[$field_id])
3102
-                        ? $existing_settings[$field_id]
3103
-                        : $fldprops['default'],
3104
-                    'css_class'  => '',
3105
-                    'format'     => $fldprops['format']
3106
-                );
3107
-            }
3092
+			foreach ($fields as $fldname => $fldprops) {
3093
+				$field_id                       = $messenger->name . '-' . $fldname;
3094
+				$template_form_field[$field_id] = array(
3095
+					'name'       => 'messenger_settings[' . $field_id . ']',
3096
+					'label'      => $fldprops['label'],
3097
+					'input'      => $fldprops['field_type'],
3098
+					'type'       => $fldprops['value_type'],
3099
+					'required'   => $fldprops['required'],
3100
+					'validation' => $fldprops['validation'],
3101
+					'value'      => isset($existing_settings[$field_id])
3102
+						? $existing_settings[$field_id]
3103
+						: $fldprops['default'],
3104
+					'css_class'  => '',
3105
+					'format'     => $fldprops['format']
3106
+				);
3107
+			}
3108 3108
             
3109 3109
             
3110
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3111
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3112
-                : '';
3113
-        }
3114
-        
3115
-        //we also need some hidden fields
3116
-        $settings_template_args['hidden_fields'] = array(
3117
-            'messenger_settings[messenger]' => array(
3118
-                'type'  => 'hidden',
3119
-                'value' => $messenger->name
3120
-            ),
3121
-            'type'                          => array(
3122
-                'type'  => 'hidden',
3123
-                'value' => 'messenger'
3124
-            )
3125
-        );
3126
-        
3127
-        //make sure any active message types that are existing are included in the hidden fields
3128
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3129
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3130
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3131
-                    'type'  => 'hidden',
3132
-                    'value' => $mt
3133
-                );
3134
-            }
3135
-        }
3136
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3137
-            $settings_template_args['hidden_fields'],
3138
-            'array'
3139
-        );
3140
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3141
-        
3142
-        $settings_template_args['messenger']           = $messenger->name;
3143
-        $settings_template_args['description']         = $messenger->description;
3144
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3145
-        
3146
-        
3147
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3148
-            ? $settings_template_args['show_hide_edit_form']
3149
-            : ' hidden';
3150
-        
3151
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3152
-            ? ' hidden'
3153
-            : $settings_template_args['show_hide_edit_form'];
3154
-        
3155
-        
3156
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3157
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3158
-        $settings_template_args['on_off_status'] = $active ? true : false;
3159
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3160
-        $content                                 = EEH_Template::display_template($template, $settings_template_args,
3161
-            true);
3162
-        
3163
-        return $content;
3164
-    }
3165
-    
3166
-    
3167
-    /**
3168
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3169
-     */
3170
-    public function activate_messenger_toggle()
3171
-    {
3172
-        $success = true;
3173
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3174
-        //let's check that we have required data
3175
-        if ( ! isset($this->_req_data['messenger'])) {
3176
-            EE_Error::add_error(
3177
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3178
-                __FILE__,
3179
-                __FUNCTION__,
3180
-                __LINE__
3181
-            );
3182
-            $success = false;
3183
-        }
3184
-        
3185
-        //do a nonce check here since we're not arriving via a normal route
3186
-        $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3187
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3188
-        
3189
-        $this->_verify_nonce($nonce, $nonce_ref);
3190
-        
3191
-        
3192
-        if ( ! isset($this->_req_data['status'])) {
3193
-            EE_Error::add_error(
3194
-                __(
3195
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3196
-                    'event_espresso'
3197
-                ),
3198
-                __FILE__,
3199
-                __FUNCTION__,
3200
-                __LINE__
3201
-            );
3202
-            $success = false;
3203
-        }
3204
-        
3205
-        //do check to verify we have a valid status.
3206
-        $status = $this->_req_data['status'];
3207
-        
3208
-        if ($status != 'off' && $status != 'on') {
3209
-            EE_Error::add_error(
3210
-                sprintf(
3211
-                    __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3212
-                    $this->_req_data['status']
3213
-                ),
3214
-                __FILE__,
3215
-                __FUNCTION__,
3216
-                __LINE__
3217
-            );
3218
-            $success = false;
3219
-        }
3220
-        
3221
-        if ($success) {
3222
-            //made it here?  Stop dawdling then!!
3223
-            $success = $status == 'off'
3224
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3225
-                : $this->_activate_messenger($this->_req_data['messenger']);
3226
-        }
3227
-        
3228
-        $this->_template_args['success'] = $success;
3229
-        
3230
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3231
-        $this->_return_json();
3232
-        
3233
-    }
3234
-    
3235
-    
3236
-    /**
3237
-     * used by ajax from the messages settings page to activate|deactivate a message type
3238
-     *
3239
-     */
3240
-    public function activate_mt_toggle()
3241
-    {
3242
-        $success = true;
3243
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3244
-        
3245
-        //let's make sure we have the necessary data
3246
-        if ( ! isset($this->_req_data['message_type'])) {
3247
-            EE_Error::add_error(
3248
-                __('Message Type name needed to toggle activation. None given', 'event_espresso'),
3249
-                __FILE__, __FUNCTION__, __LINE__
3250
-            );
3251
-            $success = false;
3252
-        }
3253
-        
3254
-        if ( ! isset($this->_req_data['messenger'])) {
3255
-            EE_Error::add_error(
3256
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3257
-                __FILE__, __FUNCTION__, __LINE__
3258
-            );
3259
-            $success = false;
3260
-        }
3261
-        
3262
-        if ( ! isset($this->_req_data['status'])) {
3263
-            EE_Error::add_error(
3264
-                __('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3265
-                    'event_espresso'),
3266
-                __FILE__, __FUNCTION__, __LINE__
3267
-            );
3268
-            $success = false;
3269
-        }
3270
-        
3271
-        
3272
-        //do check to verify we have a valid status.
3273
-        $status = $this->_req_data['status'];
3274
-        
3275
-        if ($status != 'activate' && $status != 'deactivate') {
3276
-            EE_Error::add_error(
3277
-                sprintf(
3278
-                    __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3279
-                    $this->_req_data['status']
3280
-                ),
3281
-                __FILE__, __FUNCTION__, __LINE__
3282
-            );
3283
-            $success = false;
3284
-        }
3285
-        
3286
-        
3287
-        //do a nonce check here since we're not arriving via a normal route
3288
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3289
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3290
-        
3291
-        $this->_verify_nonce($nonce, $nonce_ref);
3292
-        
3293
-        if ($success) {
3294
-            //made it here? um, what are you waiting for then?
3295
-            $success = $status == 'deactivate'
3296
-                ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3297
-                    $this->_req_data['message_type'])
3298
-                : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3299
-                    $this->_req_data['message_type']);
3300
-        }
3301
-        
3302
-        $this->_template_args['success'] = $success;
3303
-        $this->_return_json();
3304
-    }
3305
-    
3306
-    
3307
-    /**
3308
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3309
-     *
3310
-     * @param string $messenger_name The name of the messenger being activated
3311
-     *
3312
-     * @return bool
3313
-     */
3314
-    protected function _activate_messenger($messenger_name)
3315
-    {
3316
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3317
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3318
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3319
-        
3320
-        //ensure is active
3321
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3322
-        
3323
-        //set response_data for reload
3324
-        foreach ($message_types_to_activate as $message_type_name) {
3325
-            /** @var EE_message_type $message_type */
3326
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3327
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3328
-                    $message_type_name)
3329
-                && $message_type instanceof EE_message_type
3330
-            ) {
3331
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3332
-                if ($message_type->get_admin_settings_fields()) {
3333
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3334
-                }
3335
-            }
3336
-        }
3337
-        
3338
-        //add success message for activating messenger
3339
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3340
-        
3341
-    }
3342
-    
3343
-    
3344
-    /**
3345
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3346
-     *
3347
-     * @param string $messenger_name The name of the messenger being activated
3348
-     *
3349
-     * @return bool
3350
-     */
3351
-    protected function _deactivate_messenger($messenger_name)
3352
-    {
3353
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3354
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3355
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3356
-        
3357
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3358
-    }
3359
-    
3360
-    
3361
-    /**
3362
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3363
-     *
3364
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3365
-     * @param string $message_type_name The name of the message type being activated for the messenger
3366
-     *
3367
-     * @return bool
3368
-     */
3369
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3370
-    {
3371
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3372
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3373
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3374
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3375
-        
3376
-        //ensure is active
3377
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3378
-        
3379
-        //set response for load
3380
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3381
-            $message_type_name)
3382
-        ) {
3383
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3384
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3385
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3386
-            }
3387
-        }
3388
-        
3389
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3390
-            $message_type_to_activate);
3391
-    }
3392
-    
3393
-    
3394
-    /**
3395
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3396
-     *
3397
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3398
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3399
-     *
3400
-     * @return bool
3401
-     */
3402
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3403
-    {
3404
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3405
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3406
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3407
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3408
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3409
-        
3410
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3411
-            $message_type_to_deactivate);
3412
-    }
3413
-    
3414
-    
3415
-    /**
3416
-     * This just initializes the defaults for activating messenger and message type responses.
3417
-     */
3418
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3419
-    {
3420
-        $this->_template_args['data']['active_mts'] = array();
3421
-        $this->_template_args['data']['mt_reload']  = array();
3422
-    }
3423
-    
3424
-    
3425
-    /**
3426
-     * Setup appropriate response for activating a messenger and/or message types
3427
-     *
3428
-     * @param EE_messenger         $messenger
3429
-     * @param EE_message_type|null $message_type
3430
-     *
3431
-     * @return bool
3432
-     * @throws EE_Error
3433
-     */
3434
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3435
-        $messenger,
3436
-        EE_Message_Type $message_type = null
3437
-    ) {
3438
-        //if $messenger isn't a valid messenger object then get out.
3439
-        if ( ! $messenger instanceof EE_Messenger) {
3440
-            EE_Error::add_error(
3441
-                __('The messenger being activated is not a valid messenger', 'event_espresso'),
3442
-                __FILE__,
3443
-                __FUNCTION__,
3444
-                __LINE__
3445
-            );
3110
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3111
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3112
+				: '';
3113
+		}
3114
+        
3115
+		//we also need some hidden fields
3116
+		$settings_template_args['hidden_fields'] = array(
3117
+			'messenger_settings[messenger]' => array(
3118
+				'type'  => 'hidden',
3119
+				'value' => $messenger->name
3120
+			),
3121
+			'type'                          => array(
3122
+				'type'  => 'hidden',
3123
+				'value' => 'messenger'
3124
+			)
3125
+		);
3126
+        
3127
+		//make sure any active message types that are existing are included in the hidden fields
3128
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3129
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3130
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3131
+					'type'  => 'hidden',
3132
+					'value' => $mt
3133
+				);
3134
+			}
3135
+		}
3136
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3137
+			$settings_template_args['hidden_fields'],
3138
+			'array'
3139
+		);
3140
+		$active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3141
+        
3142
+		$settings_template_args['messenger']           = $messenger->name;
3143
+		$settings_template_args['description']         = $messenger->description;
3144
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3145
+        
3146
+        
3147
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3148
+			? $settings_template_args['show_hide_edit_form']
3149
+			: ' hidden';
3150
+        
3151
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3152
+			? ' hidden'
3153
+			: $settings_template_args['show_hide_edit_form'];
3154
+        
3155
+        
3156
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3157
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3158
+		$settings_template_args['on_off_status'] = $active ? true : false;
3159
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3160
+		$content                                 = EEH_Template::display_template($template, $settings_template_args,
3161
+			true);
3162
+        
3163
+		return $content;
3164
+	}
3165
+    
3166
+    
3167
+	/**
3168
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3169
+	 */
3170
+	public function activate_messenger_toggle()
3171
+	{
3172
+		$success = true;
3173
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3174
+		//let's check that we have required data
3175
+		if ( ! isset($this->_req_data['messenger'])) {
3176
+			EE_Error::add_error(
3177
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3178
+				__FILE__,
3179
+				__FUNCTION__,
3180
+				__LINE__
3181
+			);
3182
+			$success = false;
3183
+		}
3184
+        
3185
+		//do a nonce check here since we're not arriving via a normal route
3186
+		$nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3187
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3188
+        
3189
+		$this->_verify_nonce($nonce, $nonce_ref);
3190
+        
3191
+        
3192
+		if ( ! isset($this->_req_data['status'])) {
3193
+			EE_Error::add_error(
3194
+				__(
3195
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3196
+					'event_espresso'
3197
+				),
3198
+				__FILE__,
3199
+				__FUNCTION__,
3200
+				__LINE__
3201
+			);
3202
+			$success = false;
3203
+		}
3204
+        
3205
+		//do check to verify we have a valid status.
3206
+		$status = $this->_req_data['status'];
3207
+        
3208
+		if ($status != 'off' && $status != 'on') {
3209
+			EE_Error::add_error(
3210
+				sprintf(
3211
+					__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3212
+					$this->_req_data['status']
3213
+				),
3214
+				__FILE__,
3215
+				__FUNCTION__,
3216
+				__LINE__
3217
+			);
3218
+			$success = false;
3219
+		}
3220
+        
3221
+		if ($success) {
3222
+			//made it here?  Stop dawdling then!!
3223
+			$success = $status == 'off'
3224
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3225
+				: $this->_activate_messenger($this->_req_data['messenger']);
3226
+		}
3227
+        
3228
+		$this->_template_args['success'] = $success;
3229
+        
3230
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3231
+		$this->_return_json();
3232
+        
3233
+	}
3234
+    
3235
+    
3236
+	/**
3237
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3238
+	 *
3239
+	 */
3240
+	public function activate_mt_toggle()
3241
+	{
3242
+		$success = true;
3243
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3244
+        
3245
+		//let's make sure we have the necessary data
3246
+		if ( ! isset($this->_req_data['message_type'])) {
3247
+			EE_Error::add_error(
3248
+				__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3249
+				__FILE__, __FUNCTION__, __LINE__
3250
+			);
3251
+			$success = false;
3252
+		}
3253
+        
3254
+		if ( ! isset($this->_req_data['messenger'])) {
3255
+			EE_Error::add_error(
3256
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3257
+				__FILE__, __FUNCTION__, __LINE__
3258
+			);
3259
+			$success = false;
3260
+		}
3261
+        
3262
+		if ( ! isset($this->_req_data['status'])) {
3263
+			EE_Error::add_error(
3264
+				__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3265
+					'event_espresso'),
3266
+				__FILE__, __FUNCTION__, __LINE__
3267
+			);
3268
+			$success = false;
3269
+		}
3270
+        
3271
+        
3272
+		//do check to verify we have a valid status.
3273
+		$status = $this->_req_data['status'];
3274
+        
3275
+		if ($status != 'activate' && $status != 'deactivate') {
3276
+			EE_Error::add_error(
3277
+				sprintf(
3278
+					__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3279
+					$this->_req_data['status']
3280
+				),
3281
+				__FILE__, __FUNCTION__, __LINE__
3282
+			);
3283
+			$success = false;
3284
+		}
3285
+        
3286
+        
3287
+		//do a nonce check here since we're not arriving via a normal route
3288
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3289
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3290
+        
3291
+		$this->_verify_nonce($nonce, $nonce_ref);
3292
+        
3293
+		if ($success) {
3294
+			//made it here? um, what are you waiting for then?
3295
+			$success = $status == 'deactivate'
3296
+				? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3297
+					$this->_req_data['message_type'])
3298
+				: $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3299
+					$this->_req_data['message_type']);
3300
+		}
3301
+        
3302
+		$this->_template_args['success'] = $success;
3303
+		$this->_return_json();
3304
+	}
3305
+    
3306
+    
3307
+	/**
3308
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3309
+	 *
3310
+	 * @param string $messenger_name The name of the messenger being activated
3311
+	 *
3312
+	 * @return bool
3313
+	 */
3314
+	protected function _activate_messenger($messenger_name)
3315
+	{
3316
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3317
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3318
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3319
+        
3320
+		//ensure is active
3321
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3322
+        
3323
+		//set response_data for reload
3324
+		foreach ($message_types_to_activate as $message_type_name) {
3325
+			/** @var EE_message_type $message_type */
3326
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3327
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3328
+					$message_type_name)
3329
+				&& $message_type instanceof EE_message_type
3330
+			) {
3331
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3332
+				if ($message_type->get_admin_settings_fields()) {
3333
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3334
+				}
3335
+			}
3336
+		}
3337
+        
3338
+		//add success message for activating messenger
3339
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3340
+        
3341
+	}
3342
+    
3343
+    
3344
+	/**
3345
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3346
+	 *
3347
+	 * @param string $messenger_name The name of the messenger being activated
3348
+	 *
3349
+	 * @return bool
3350
+	 */
3351
+	protected function _deactivate_messenger($messenger_name)
3352
+	{
3353
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3354
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3355
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3356
+        
3357
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3358
+	}
3359
+    
3360
+    
3361
+	/**
3362
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3363
+	 *
3364
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3365
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3366
+	 *
3367
+	 * @return bool
3368
+	 */
3369
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3370
+	{
3371
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3372
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3373
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3374
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3375
+        
3376
+		//ensure is active
3377
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3378
+        
3379
+		//set response for load
3380
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3381
+			$message_type_name)
3382
+		) {
3383
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3384
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3385
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3386
+			}
3387
+		}
3388
+        
3389
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3390
+			$message_type_to_activate);
3391
+	}
3392
+    
3393
+    
3394
+	/**
3395
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3396
+	 *
3397
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3398
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3399
+	 *
3400
+	 * @return bool
3401
+	 */
3402
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3403
+	{
3404
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3405
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3406
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3407
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3408
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3409
+        
3410
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3411
+			$message_type_to_deactivate);
3412
+	}
3413
+    
3414
+    
3415
+	/**
3416
+	 * This just initializes the defaults for activating messenger and message type responses.
3417
+	 */
3418
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3419
+	{
3420
+		$this->_template_args['data']['active_mts'] = array();
3421
+		$this->_template_args['data']['mt_reload']  = array();
3422
+	}
3423
+    
3424
+    
3425
+	/**
3426
+	 * Setup appropriate response for activating a messenger and/or message types
3427
+	 *
3428
+	 * @param EE_messenger         $messenger
3429
+	 * @param EE_message_type|null $message_type
3430
+	 *
3431
+	 * @return bool
3432
+	 * @throws EE_Error
3433
+	 */
3434
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3435
+		$messenger,
3436
+		EE_Message_Type $message_type = null
3437
+	) {
3438
+		//if $messenger isn't a valid messenger object then get out.
3439
+		if ( ! $messenger instanceof EE_Messenger) {
3440
+			EE_Error::add_error(
3441
+				__('The messenger being activated is not a valid messenger', 'event_espresso'),
3442
+				__FILE__,
3443
+				__FUNCTION__,
3444
+				__LINE__
3445
+			);
3446 3446
             
3447
-            return false;
3448
-        }
3449
-        //activated
3450
-        if ($this->_template_args['data']['active_mts']) {
3451
-            EE_Error::overwrite_success();
3452
-            //activated a message type with the messenger
3453
-            if ($message_type instanceof EE_message_type) {
3454
-                EE_Error::add_success(
3455
-                    sprintf(
3456
-                        __('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3457
-                        ucwords($message_type->label['singular']),
3458
-                        ucwords($messenger->label['singular'])
3459
-                    )
3460
-                );
3447
+			return false;
3448
+		}
3449
+		//activated
3450
+		if ($this->_template_args['data']['active_mts']) {
3451
+			EE_Error::overwrite_success();
3452
+			//activated a message type with the messenger
3453
+			if ($message_type instanceof EE_message_type) {
3454
+				EE_Error::add_success(
3455
+					sprintf(
3456
+						__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3457
+						ucwords($message_type->label['singular']),
3458
+						ucwords($messenger->label['singular'])
3459
+					)
3460
+				);
3461 3461
                 
3462
-                //if message type was invoice then let's make sure we activate the invoice payment method.
3463
-                if ($message_type->name == 'invoice') {
3464
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3465
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3466
-                    if ($pm instanceof EE_Payment_Method) {
3467
-                        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.',
3468
-                            'event_espresso'));
3469
-                    }
3470
-                }
3471
-                //just toggles the entire messenger
3472
-            } else {
3473
-                EE_Error::add_success(
3474
-                    sprintf(
3475
-                        __('%s messenger has been successfully activated', 'event_espresso'),
3476
-                        ucwords($messenger->label['singular'])
3477
-                    )
3478
-                );
3479
-            }
3462
+				//if message type was invoice then let's make sure we activate the invoice payment method.
3463
+				if ($message_type->name == 'invoice') {
3464
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3465
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3466
+					if ($pm instanceof EE_Payment_Method) {
3467
+						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.',
3468
+							'event_espresso'));
3469
+					}
3470
+				}
3471
+				//just toggles the entire messenger
3472
+			} else {
3473
+				EE_Error::add_success(
3474
+					sprintf(
3475
+						__('%s messenger has been successfully activated', 'event_espresso'),
3476
+						ucwords($messenger->label['singular'])
3477
+					)
3478
+				);
3479
+			}
3480 3480
             
3481
-            return true;
3481
+			return true;
3482 3482
             
3483
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3484
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3485
-            //in which case we just give a success message for the messenger being successfully activated.
3486
-        } else {
3487
-            if ( ! $messenger->get_default_message_types()) {
3488
-                //messenger doesn't have any default message types so still a success.
3489
-                EE_Error::add_success(
3490
-                    sprintf(
3491
-                        __('%s messenger was successfully activated.', 'event_espresso'),
3492
-                        ucwords($messenger->label['singular'])
3493
-                    )
3494
-                );
3483
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3484
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3485
+			//in which case we just give a success message for the messenger being successfully activated.
3486
+		} else {
3487
+			if ( ! $messenger->get_default_message_types()) {
3488
+				//messenger doesn't have any default message types so still a success.
3489
+				EE_Error::add_success(
3490
+					sprintf(
3491
+						__('%s messenger was successfully activated.', 'event_espresso'),
3492
+						ucwords($messenger->label['singular'])
3493
+					)
3494
+				);
3495 3495
                 
3496
-                return true;
3497
-            } else {
3498
-                EE_Error::add_error(
3499
-                    $message_type instanceof EE_message_type
3500
-                        ? sprintf(
3501
-                        __('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3502
-                        ucwords($message_type->label['singular']),
3503
-                        ucwords($messenger->label['singular'])
3504
-                    )
3505
-                        : sprintf(
3506
-                        __('%s messenger was not successfully activated', 'event_espresso'),
3507
-                        ucwords($messenger->label['singular'])
3508
-                    ),
3509
-                    __FILE__,
3510
-                    __FUNCTION__,
3511
-                    __LINE__
3512
-                );
3496
+				return true;
3497
+			} else {
3498
+				EE_Error::add_error(
3499
+					$message_type instanceof EE_message_type
3500
+						? sprintf(
3501
+						__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3502
+						ucwords($message_type->label['singular']),
3503
+						ucwords($messenger->label['singular'])
3504
+					)
3505
+						: sprintf(
3506
+						__('%s messenger was not successfully activated', 'event_espresso'),
3507
+						ucwords($messenger->label['singular'])
3508
+					),
3509
+					__FILE__,
3510
+					__FUNCTION__,
3511
+					__LINE__
3512
+				);
3513 3513
                 
3514
-                return false;
3515
-            }
3516
-        }
3517
-    }
3518
-    
3519
-    
3520
-    /**
3521
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3522
-     *
3523
-     * @param EE_messenger         $messenger
3524
-     * @param EE_message_type|null $message_type
3525
-     *
3526
-     * @return bool
3527
-     */
3528
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3529
-        $messenger,
3530
-        EE_message_type $message_type = null
3531
-    ) {
3532
-        EE_Error::overwrite_success();
3533
-        
3534
-        //if $messenger isn't a valid messenger object then get out.
3535
-        if ( ! $messenger instanceof EE_Messenger) {
3536
-            EE_Error::add_error(
3537
-                __('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3538
-                __FILE__,
3539
-                __FUNCTION__,
3540
-                __LINE__
3541
-            );
3514
+				return false;
3515
+			}
3516
+		}
3517
+	}
3518
+    
3519
+    
3520
+	/**
3521
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3522
+	 *
3523
+	 * @param EE_messenger         $messenger
3524
+	 * @param EE_message_type|null $message_type
3525
+	 *
3526
+	 * @return bool
3527
+	 */
3528
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3529
+		$messenger,
3530
+		EE_message_type $message_type = null
3531
+	) {
3532
+		EE_Error::overwrite_success();
3533
+        
3534
+		//if $messenger isn't a valid messenger object then get out.
3535
+		if ( ! $messenger instanceof EE_Messenger) {
3536
+			EE_Error::add_error(
3537
+				__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3538
+				__FILE__,
3539
+				__FUNCTION__,
3540
+				__LINE__
3541
+			);
3542 3542
             
3543
-            return false;
3544
-        }
3545
-        
3546
-        if ($message_type instanceof EE_message_type) {
3547
-            $message_type_name = $message_type->name;
3548
-            EE_Error::add_success(
3549
-                sprintf(
3550
-                    __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3551
-                    ucwords($message_type->label['singular']),
3552
-                    ucwords($messenger->label['singular'])
3553
-                )
3554
-            );
3555
-        } else {
3556
-            $message_type_name = '';
3557
-            EE_Error::add_success(
3558
-                sprintf(
3559
-                    __('%s messenger has been successfully deactivated.', 'event_espresso'),
3560
-                    ucwords($messenger->label['singular'])
3561
-                )
3562
-            );
3563
-        }
3564
-        
3565
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3566
-        if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3567
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3568
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3569
-            if ($count_updated > 0) {
3570
-                $msg = $message_type_name == 'invoice'
3571
-                    ? __('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.',
3572
-                        'event_espresso')
3573
-                    : __('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.',
3574
-                        'event_espresso');
3575
-                EE_Error::add_attention($msg);
3576
-            }
3577
-        }
3578
-        
3579
-        return true;
3580
-    }
3581
-    
3582
-    
3583
-    /**
3584
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3585
-     */
3586
-    public function update_mt_form()
3587
-    {
3588
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3589
-            EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3590
-                __LINE__);
3591
-            $this->_return_json();
3592
-        }
3593
-        
3594
-        $message_types = $this->get_installed_message_types();
3595
-        
3596
-        $message_type = $message_types[$this->_req_data['message_type']];
3597
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3598
-        
3599
-        $content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3600
-        $this->_template_args['success'] = true;
3601
-        $this->_template_args['content'] = $content;
3602
-        $this->_return_json();
3603
-    }
3604
-    
3605
-    
3606
-    /**
3607
-     * this handles saving the settings for a messenger or message type
3608
-     *
3609
-     */
3610
-    public function save_settings()
3611
-    {
3612
-        if ( ! isset($this->_req_data['type'])) {
3613
-            EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3614
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3615
-            $this->_template_args['error'] = true;
3616
-            $this->_return_json();
3617
-        }
3618
-        
3619
-        
3620
-        if ($this->_req_data['type'] == 'messenger') {
3621
-            $settings  = $this->_req_data['messenger_settings']; //this should be an array.
3622
-            $messenger = $settings['messenger'];
3623
-            //let's setup the settings data
3624
-            foreach ($settings as $key => $value) {
3625
-                switch ($key) {
3626
-                    case 'messenger' :
3627
-                        unset($settings['messenger']);
3628
-                        break;
3629
-                    case 'message_types' :
3630
-                        unset($settings['message_types']);
3631
-                        break;
3632
-                    default :
3633
-                        $settings[$key] = $value;
3634
-                        break;
3635
-                }
3636
-            }
3637
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3638
-        } else if ($this->_req_data['type'] == 'message_type') {
3639
-            $settings     = $this->_req_data['message_type_settings'];
3640
-            $messenger    = $settings['messenger'];
3641
-            $message_type = $settings['message_type'];
3543
+			return false;
3544
+		}
3545
+        
3546
+		if ($message_type instanceof EE_message_type) {
3547
+			$message_type_name = $message_type->name;
3548
+			EE_Error::add_success(
3549
+				sprintf(
3550
+					__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3551
+					ucwords($message_type->label['singular']),
3552
+					ucwords($messenger->label['singular'])
3553
+				)
3554
+			);
3555
+		} else {
3556
+			$message_type_name = '';
3557
+			EE_Error::add_success(
3558
+				sprintf(
3559
+					__('%s messenger has been successfully deactivated.', 'event_espresso'),
3560
+					ucwords($messenger->label['singular'])
3561
+				)
3562
+			);
3563
+		}
3564
+        
3565
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3566
+		if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3567
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3568
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3569
+			if ($count_updated > 0) {
3570
+				$msg = $message_type_name == 'invoice'
3571
+					? __('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.',
3572
+						'event_espresso')
3573
+					: __('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.',
3574
+						'event_espresso');
3575
+				EE_Error::add_attention($msg);
3576
+			}
3577
+		}
3578
+        
3579
+		return true;
3580
+	}
3581
+    
3582
+    
3583
+	/**
3584
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3585
+	 */
3586
+	public function update_mt_form()
3587
+	{
3588
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3589
+			EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3590
+				__LINE__);
3591
+			$this->_return_json();
3592
+		}
3593
+        
3594
+		$message_types = $this->get_installed_message_types();
3595
+        
3596
+		$message_type = $message_types[$this->_req_data['message_type']];
3597
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3598
+        
3599
+		$content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3600
+		$this->_template_args['success'] = true;
3601
+		$this->_template_args['content'] = $content;
3602
+		$this->_return_json();
3603
+	}
3604
+    
3605
+    
3606
+	/**
3607
+	 * this handles saving the settings for a messenger or message type
3608
+	 *
3609
+	 */
3610
+	public function save_settings()
3611
+	{
3612
+		if ( ! isset($this->_req_data['type'])) {
3613
+			EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3614
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3615
+			$this->_template_args['error'] = true;
3616
+			$this->_return_json();
3617
+		}
3618
+        
3619
+        
3620
+		if ($this->_req_data['type'] == 'messenger') {
3621
+			$settings  = $this->_req_data['messenger_settings']; //this should be an array.
3622
+			$messenger = $settings['messenger'];
3623
+			//let's setup the settings data
3624
+			foreach ($settings as $key => $value) {
3625
+				switch ($key) {
3626
+					case 'messenger' :
3627
+						unset($settings['messenger']);
3628
+						break;
3629
+					case 'message_types' :
3630
+						unset($settings['message_types']);
3631
+						break;
3632
+					default :
3633
+						$settings[$key] = $value;
3634
+						break;
3635
+				}
3636
+			}
3637
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3638
+		} else if ($this->_req_data['type'] == 'message_type') {
3639
+			$settings     = $this->_req_data['message_type_settings'];
3640
+			$messenger    = $settings['messenger'];
3641
+			$message_type = $settings['message_type'];
3642 3642
             
3643
-            foreach ($settings as $key => $value) {
3644
-                switch ($key) {
3645
-                    case 'messenger' :
3646
-                        unset($settings['messenger']);
3647
-                        break;
3648
-                    case 'message_type' :
3649
-                        unset($settings['message_type']);
3650
-                        break;
3651
-                    default :
3652
-                        $settings[$key] = $value;
3653
-                        break;
3654
-                }
3655
-            }
3643
+			foreach ($settings as $key => $value) {
3644
+				switch ($key) {
3645
+					case 'messenger' :
3646
+						unset($settings['messenger']);
3647
+						break;
3648
+					case 'message_type' :
3649
+						unset($settings['message_type']);
3650
+						break;
3651
+					default :
3652
+						$settings[$key] = $value;
3653
+						break;
3654
+				}
3655
+			}
3656 3656
             
3657
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3658
-        }
3659
-        
3660
-        //okay we should have the data all setup.  Now we just update!
3661
-        $success = $this->_message_resource_manager->update_active_messengers_option();
3662
-        
3663
-        if ($success) {
3664
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
3665
-        } else {
3666
-            EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3667
-        }
3668
-        
3669
-        $this->_template_args['success'] = $success;
3670
-        $this->_return_json();
3671
-    }
3672
-    
3673
-    
3674
-    
3675
-    
3676
-    /**  EE MESSAGE PROCESSING ACTIONS **/
3677
-    
3678
-    
3679
-    /**
3680
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3681
-     * However, this does not send immediately, it just queues for sending.
3682
-     *
3683
-     * @since 4.9.0
3684
-     */
3685
-    protected function _generate_now()
3686
-    {
3687
-        $msg_ids = $this->_get_msg_ids_from_request();
3688
-        EED_Messages::generate_now($msg_ids);
3689
-        $this->_redirect_after_action(false, '', '', array(), true);
3690
-    }
3691
-    
3692
-    
3693
-    /**
3694
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3695
-     * are EEM_Message::status_resend or EEM_Message::status_idle
3696
-     *
3697
-     * @since 4.9.0
3698
-     *
3699
-     */
3700
-    protected function _generate_and_send_now()
3701
-    {
3702
-        $this->_generate_now();
3703
-        $this->_send_now();
3704
-        $this->_redirect_after_action(false, '', '', array(), true);
3705
-    }
3706
-    
3707
-    
3708
-    /**
3709
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3710
-     *
3711
-     * @since 4.9.0
3712
-     */
3713
-    protected function _queue_for_resending()
3714
-    {
3715
-        $msg_ids = $this->_get_msg_ids_from_request();
3716
-        EED_Messages::queue_for_resending($msg_ids);
3717
-        $this->_redirect_after_action(false, '', '', array(), true);
3718
-    }
3719
-    
3720
-    
3721
-    /**
3722
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3723
-     *
3724
-     * @since 4.9.0
3725
-     */
3726
-    protected function _send_now()
3727
-    {
3728
-        $msg_ids = $this->_get_msg_ids_from_request();
3729
-        EED_Messages::send_now($msg_ids);
3730
-        $this->_redirect_after_action(false, '', '', array(), true);
3731
-    }
3732
-    
3733
-    
3734
-    /**
3735
-     * Deletes EE_messages for IDs in the request.
3736
-     *
3737
-     * @since 4.9.0
3738
-     */
3739
-    protected function _delete_ee_messages()
3740
-    {
3741
-        $msg_ids       = $this->_get_msg_ids_from_request();
3742
-        $deleted_count = 0;
3743
-        foreach ($msg_ids as $msg_id) {
3744
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3745
-                $deleted_count++;
3746
-            }
3747
-        }
3748
-        if ($deleted_count) {
3749
-            $this->_redirect_after_action(
3750
-                true,
3751
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
3752
-                __('deleted', 'event_espresso')
3753
-            );
3754
-        } else {
3755
-            EE_Error::add_error(
3756
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3757
-                __FILE__, __FUNCTION__, __LINE__
3758
-            );
3759
-            $this->_redirect_after_action(false, '', '', array(), true);
3760
-        }
3761
-    }
3762
-    
3763
-    
3764
-    /**
3765
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3766
-     * @since 4.9.0
3767
-     * @return array
3768
-     */
3769
-    protected function _get_msg_ids_from_request()
3770
-    {
3771
-        if ( ! isset($this->_req_data['MSG_ID'])) {
3772
-            return array();
3773
-        }
3774
-        
3775
-        return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3776
-    }
3657
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3658
+		}
3659
+        
3660
+		//okay we should have the data all setup.  Now we just update!
3661
+		$success = $this->_message_resource_manager->update_active_messengers_option();
3662
+        
3663
+		if ($success) {
3664
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
3665
+		} else {
3666
+			EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3667
+		}
3668
+        
3669
+		$this->_template_args['success'] = $success;
3670
+		$this->_return_json();
3671
+	}
3672
+    
3673
+    
3674
+    
3675
+    
3676
+	/**  EE MESSAGE PROCESSING ACTIONS **/
3677
+    
3678
+    
3679
+	/**
3680
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3681
+	 * However, this does not send immediately, it just queues for sending.
3682
+	 *
3683
+	 * @since 4.9.0
3684
+	 */
3685
+	protected function _generate_now()
3686
+	{
3687
+		$msg_ids = $this->_get_msg_ids_from_request();
3688
+		EED_Messages::generate_now($msg_ids);
3689
+		$this->_redirect_after_action(false, '', '', array(), true);
3690
+	}
3691
+    
3692
+    
3693
+	/**
3694
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3695
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
3696
+	 *
3697
+	 * @since 4.9.0
3698
+	 *
3699
+	 */
3700
+	protected function _generate_and_send_now()
3701
+	{
3702
+		$this->_generate_now();
3703
+		$this->_send_now();
3704
+		$this->_redirect_after_action(false, '', '', array(), true);
3705
+	}
3706
+    
3707
+    
3708
+	/**
3709
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3710
+	 *
3711
+	 * @since 4.9.0
3712
+	 */
3713
+	protected function _queue_for_resending()
3714
+	{
3715
+		$msg_ids = $this->_get_msg_ids_from_request();
3716
+		EED_Messages::queue_for_resending($msg_ids);
3717
+		$this->_redirect_after_action(false, '', '', array(), true);
3718
+	}
3719
+    
3720
+    
3721
+	/**
3722
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3723
+	 *
3724
+	 * @since 4.9.0
3725
+	 */
3726
+	protected function _send_now()
3727
+	{
3728
+		$msg_ids = $this->_get_msg_ids_from_request();
3729
+		EED_Messages::send_now($msg_ids);
3730
+		$this->_redirect_after_action(false, '', '', array(), true);
3731
+	}
3732
+    
3733
+    
3734
+	/**
3735
+	 * Deletes EE_messages for IDs in the request.
3736
+	 *
3737
+	 * @since 4.9.0
3738
+	 */
3739
+	protected function _delete_ee_messages()
3740
+	{
3741
+		$msg_ids       = $this->_get_msg_ids_from_request();
3742
+		$deleted_count = 0;
3743
+		foreach ($msg_ids as $msg_id) {
3744
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3745
+				$deleted_count++;
3746
+			}
3747
+		}
3748
+		if ($deleted_count) {
3749
+			$this->_redirect_after_action(
3750
+				true,
3751
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
3752
+				__('deleted', 'event_espresso')
3753
+			);
3754
+		} else {
3755
+			EE_Error::add_error(
3756
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3757
+				__FILE__, __FUNCTION__, __LINE__
3758
+			);
3759
+			$this->_redirect_after_action(false, '', '', array(), true);
3760
+		}
3761
+	}
3762
+    
3763
+    
3764
+	/**
3765
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3766
+	 * @since 4.9.0
3767
+	 * @return array
3768
+	 */
3769
+	protected function _get_msg_ids_from_request()
3770
+	{
3771
+		if ( ! isset($this->_req_data['MSG_ID'])) {
3772
+			return array();
3773
+		}
3774
+        
3775
+		return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3776
+	}
3777 3777
     
3778 3778
     
3779 3779
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 1 patch
Indentation   +1420 added lines, -1420 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
 
@@ -16,1429 +16,1429 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
21
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
22
-     */
23
-    const req_type_normal = 0;
24
-
25
-    /**
26
-     * Indicates this is a brand new installation of EE so we should install
27
-     * tables and default data etc
28
-     */
29
-    const req_type_new_activation = 1;
30
-
31
-    /**
32
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
33
-     * and we just exited maintenance mode). We MUST check the database is setup properly
34
-     * and that default data is setup too
35
-     */
36
-    const req_type_reactivation = 2;
37
-
38
-    /**
39
-     * indicates that EE has been upgraded since its previous request.
40
-     * We may have data migration scripts to call and will want to trigger maintenance mode
41
-     */
42
-    const req_type_upgrade = 3;
43
-
44
-    /**
45
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
46
-     */
47
-    const req_type_downgrade = 4;
48
-
49
-    /**
50
-     * @deprecated since version 4.6.0.dev.006
51
-     * Now whenever a new_activation is detected the request type is still just
52
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
53
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
54
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
55
-     * (Specifically, when the migration manager indicates migrations are finished
56
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
57
-     */
58
-    const req_type_activation_but_not_installed = 5;
59
-
60
-    /**
61
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
62
-     */
63
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
64
-
65
-
66
-    /**
67
-     *    instance of the EE_System object
68
-     *
69
-     * @var    $_instance
70
-     * @access    private
71
-     */
72
-    private static $_instance = null;
73
-
74
-    /**
75
-     * @type  EE_Registry $Registry
76
-     * @access    protected
77
-     */
78
-    protected $registry;
79
-
80
-    /**
81
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
82
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
83
-     *
84
-     * @var int
85
-     */
86
-    private $_req_type;
87
-
88
-    /**
89
-     * Whether or not there was a non-micro version change in EE core version during this request
90
-     *
91
-     * @var boolean
92
-     */
93
-    private $_major_version_change = false;
94
-
95
-
96
-
97
-    /**
98
-     * @singleton method used to instantiate class object
99
-     * @access    public
100
-     * @param  \EE_Registry $Registry
101
-     * @return \EE_System
102
-     */
103
-    public static function instance(EE_Registry $Registry = null)
104
-    {
105
-        // check if class object is instantiated
106
-        if ( ! self::$_instance instanceof EE_System) {
107
-            self::$_instance = new self($Registry);
108
-        }
109
-        return self::$_instance;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * resets the instance and returns it
116
-     *
117
-     * @return EE_System
118
-     */
119
-    public static function reset()
120
-    {
121
-        self::$_instance->_req_type = null;
122
-        //make sure none of the old hooks are left hanging around
123
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
124
-        //we need to reset the migration manager in order for it to detect DMSs properly
125
-        EE_Data_Migration_Manager::reset();
126
-        self::instance()->detect_activations_or_upgrades();
127
-        self::instance()->perform_activations_upgrades_and_migrations();
128
-        return self::instance();
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     *    sets hooks for running rest of system
135
-     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
136
-     *    starting EE Addons from any other point may lead to problems
137
-     *
138
-     * @access private
139
-     * @param  \EE_Registry $Registry
140
-     */
141
-    private function __construct(EE_Registry $Registry)
142
-    {
143
-        $this->registry = $Registry;
144
-        do_action('AHEE__EE_System__construct__begin', $this);
145
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
146
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
147
-        // when an ee addon is activated, we want to call the core hook(s) again
148
-        // because the newly-activated addon didn't get a chance to run at all
149
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
150
-        // detect whether install or upgrade
151
-        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
152
-            3);
153
-        // load EE_Config, EE_Textdomain, etc
154
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
155
-        // load EE_Config, EE_Textdomain, etc
156
-        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
157
-            array($this, 'register_shortcodes_modules_and_widgets'), 7);
158
-        // you wanna get going? I wanna get going... let's get going!
159
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
160
-        //other housekeeping
161
-        //exclude EE critical pages from wp_list_pages
162
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
163
-        // ALL EE Addons should use the following hook point to attach their initial setup too
164
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
165
-        do_action('AHEE__EE_System__construct__complete', $this);
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * load_espresso_addons
172
-     * allow addons to load first so that they can set hooks for running DMS's, etc
173
-     * this is hooked into both:
174
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
175
-     *        which runs during the WP 'plugins_loaded' action at priority 5
176
-     *    and the WP 'activate_plugin' hookpoint
177
-     *
178
-     * @access public
179
-     * @return void
180
-     */
181
-    public function load_espresso_addons()
182
-    {
183
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
184
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
185
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
186
-        //load and setup EE_Capabilities
187
-        $this->registry->load_core('Capabilities');
188
-        //caps need to be initialized on every request so that capability maps are set.
189
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
190
-        $this->registry->CAP->init_caps();
191
-        do_action('AHEE__EE_System__load_espresso_addons');
192
-        //if the WP API basic auth plugin isn't already loaded, load it now.
193
-        //We want it for mobile apps. Just include the entire plugin
194
-        //also, don't load the basic auth when a plugin is getting activated, because
195
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
196
-        //and causes a fatal error
197
-        if ( ! function_exists('json_basic_auth_handler')
198
-             && ! function_exists('json_basic_auth_error')
199
-             && ! (
200
-                isset($_GET['action'])
201
-                && in_array($_GET['action'], array('activate', 'activate-selected'))
202
-            )
203
-             && ! (
204
-                isset($_GET['activate'])
205
-                && $_GET['activate'] === 'true'
206
-            )
207
-        ) {
208
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
209
-        }
19
+	/**
20
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
21
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
22
+	 */
23
+	const req_type_normal = 0;
24
+
25
+	/**
26
+	 * Indicates this is a brand new installation of EE so we should install
27
+	 * tables and default data etc
28
+	 */
29
+	const req_type_new_activation = 1;
30
+
31
+	/**
32
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
33
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
34
+	 * and that default data is setup too
35
+	 */
36
+	const req_type_reactivation = 2;
37
+
38
+	/**
39
+	 * indicates that EE has been upgraded since its previous request.
40
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
41
+	 */
42
+	const req_type_upgrade = 3;
43
+
44
+	/**
45
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
46
+	 */
47
+	const req_type_downgrade = 4;
48
+
49
+	/**
50
+	 * @deprecated since version 4.6.0.dev.006
51
+	 * Now whenever a new_activation is detected the request type is still just
52
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
53
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
54
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
55
+	 * (Specifically, when the migration manager indicates migrations are finished
56
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
57
+	 */
58
+	const req_type_activation_but_not_installed = 5;
59
+
60
+	/**
61
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
62
+	 */
63
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
64
+
65
+
66
+	/**
67
+	 *    instance of the EE_System object
68
+	 *
69
+	 * @var    $_instance
70
+	 * @access    private
71
+	 */
72
+	private static $_instance = null;
73
+
74
+	/**
75
+	 * @type  EE_Registry $Registry
76
+	 * @access    protected
77
+	 */
78
+	protected $registry;
79
+
80
+	/**
81
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
82
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
83
+	 *
84
+	 * @var int
85
+	 */
86
+	private $_req_type;
87
+
88
+	/**
89
+	 * Whether or not there was a non-micro version change in EE core version during this request
90
+	 *
91
+	 * @var boolean
92
+	 */
93
+	private $_major_version_change = false;
94
+
95
+
96
+
97
+	/**
98
+	 * @singleton method used to instantiate class object
99
+	 * @access    public
100
+	 * @param  \EE_Registry $Registry
101
+	 * @return \EE_System
102
+	 */
103
+	public static function instance(EE_Registry $Registry = null)
104
+	{
105
+		// check if class object is instantiated
106
+		if ( ! self::$_instance instanceof EE_System) {
107
+			self::$_instance = new self($Registry);
108
+		}
109
+		return self::$_instance;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * resets the instance and returns it
116
+	 *
117
+	 * @return EE_System
118
+	 */
119
+	public static function reset()
120
+	{
121
+		self::$_instance->_req_type = null;
122
+		//make sure none of the old hooks are left hanging around
123
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
124
+		//we need to reset the migration manager in order for it to detect DMSs properly
125
+		EE_Data_Migration_Manager::reset();
126
+		self::instance()->detect_activations_or_upgrades();
127
+		self::instance()->perform_activations_upgrades_and_migrations();
128
+		return self::instance();
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 *    sets hooks for running rest of system
135
+	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
136
+	 *    starting EE Addons from any other point may lead to problems
137
+	 *
138
+	 * @access private
139
+	 * @param  \EE_Registry $Registry
140
+	 */
141
+	private function __construct(EE_Registry $Registry)
142
+	{
143
+		$this->registry = $Registry;
144
+		do_action('AHEE__EE_System__construct__begin', $this);
145
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
146
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
147
+		// when an ee addon is activated, we want to call the core hook(s) again
148
+		// because the newly-activated addon didn't get a chance to run at all
149
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
150
+		// detect whether install or upgrade
151
+		add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
152
+			3);
153
+		// load EE_Config, EE_Textdomain, etc
154
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
155
+		// load EE_Config, EE_Textdomain, etc
156
+		add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
157
+			array($this, 'register_shortcodes_modules_and_widgets'), 7);
158
+		// you wanna get going? I wanna get going... let's get going!
159
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
160
+		//other housekeeping
161
+		//exclude EE critical pages from wp_list_pages
162
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
163
+		// ALL EE Addons should use the following hook point to attach their initial setup too
164
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
165
+		do_action('AHEE__EE_System__construct__complete', $this);
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * load_espresso_addons
172
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
173
+	 * this is hooked into both:
174
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
175
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
176
+	 *    and the WP 'activate_plugin' hookpoint
177
+	 *
178
+	 * @access public
179
+	 * @return void
180
+	 */
181
+	public function load_espresso_addons()
182
+	{
183
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
184
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
185
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
186
+		//load and setup EE_Capabilities
187
+		$this->registry->load_core('Capabilities');
188
+		//caps need to be initialized on every request so that capability maps are set.
189
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
190
+		$this->registry->CAP->init_caps();
191
+		do_action('AHEE__EE_System__load_espresso_addons');
192
+		//if the WP API basic auth plugin isn't already loaded, load it now.
193
+		//We want it for mobile apps. Just include the entire plugin
194
+		//also, don't load the basic auth when a plugin is getting activated, because
195
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
196
+		//and causes a fatal error
197
+		if ( ! function_exists('json_basic_auth_handler')
198
+			 && ! function_exists('json_basic_auth_error')
199
+			 && ! (
200
+				isset($_GET['action'])
201
+				&& in_array($_GET['action'], array('activate', 'activate-selected'))
202
+			)
203
+			 && ! (
204
+				isset($_GET['activate'])
205
+				&& $_GET['activate'] === 'true'
206
+			)
207
+		) {
208
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
209
+		}
210 210
         
211
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * detect_activations_or_upgrades
218
-     * Checks for activation or upgrade of core first;
219
-     * then also checks if any registered addons have been activated or upgraded
220
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
221
-     * which runs during the WP 'plugins_loaded' action at priority 3
222
-     *
223
-     * @access public
224
-     * @return void
225
-     */
226
-    public function detect_activations_or_upgrades()
227
-    {
228
-        //first off: let's make sure to handle core
229
-        $this->detect_if_activation_or_upgrade();
230
-        foreach ($this->registry->addons as $addon) {
231
-            //detect teh request type for that addon
232
-            $addon->detect_activation_or_upgrade();
233
-        }
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * detect_if_activation_or_upgrade
240
-     * Takes care of detecting whether this is a brand new install or code upgrade,
241
-     * and either setting up the DB or setting up maintenance mode etc.
242
-     *
243
-     * @access public
244
-     * @return void
245
-     */
246
-    public function detect_if_activation_or_upgrade()
247
-    {
248
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
249
-        // load M-Mode class
250
-        $this->registry->load_core('Maintenance_Mode');
251
-        // check if db has been updated, or if its a brand-new installation
252
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
253
-        $request_type = $this->detect_req_type($espresso_db_update);
254
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
255
-        switch ($request_type) {
256
-            case EE_System::req_type_new_activation:
257
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
258
-                $this->_handle_core_version_change($espresso_db_update);
259
-                break;
260
-            case EE_System::req_type_reactivation:
261
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
262
-                $this->_handle_core_version_change($espresso_db_update);
263
-                break;
264
-            case EE_System::req_type_upgrade:
265
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
266
-                //migrations may be required now that we've upgraded
267
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
268
-                $this->_handle_core_version_change($espresso_db_update);
211
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * detect_activations_or_upgrades
218
+	 * Checks for activation or upgrade of core first;
219
+	 * then also checks if any registered addons have been activated or upgraded
220
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
221
+	 * which runs during the WP 'plugins_loaded' action at priority 3
222
+	 *
223
+	 * @access public
224
+	 * @return void
225
+	 */
226
+	public function detect_activations_or_upgrades()
227
+	{
228
+		//first off: let's make sure to handle core
229
+		$this->detect_if_activation_or_upgrade();
230
+		foreach ($this->registry->addons as $addon) {
231
+			//detect teh request type for that addon
232
+			$addon->detect_activation_or_upgrade();
233
+		}
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * detect_if_activation_or_upgrade
240
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
241
+	 * and either setting up the DB or setting up maintenance mode etc.
242
+	 *
243
+	 * @access public
244
+	 * @return void
245
+	 */
246
+	public function detect_if_activation_or_upgrade()
247
+	{
248
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
249
+		// load M-Mode class
250
+		$this->registry->load_core('Maintenance_Mode');
251
+		// check if db has been updated, or if its a brand-new installation
252
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
253
+		$request_type = $this->detect_req_type($espresso_db_update);
254
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
255
+		switch ($request_type) {
256
+			case EE_System::req_type_new_activation:
257
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
258
+				$this->_handle_core_version_change($espresso_db_update);
259
+				break;
260
+			case EE_System::req_type_reactivation:
261
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
262
+				$this->_handle_core_version_change($espresso_db_update);
263
+				break;
264
+			case EE_System::req_type_upgrade:
265
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
266
+				//migrations may be required now that we've upgraded
267
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
268
+				$this->_handle_core_version_change($espresso_db_update);
269 269
 //				echo "done upgrade";die;
270
-                break;
271
-            case EE_System::req_type_downgrade:
272
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
273
-                //its possible migrations are no longer required
274
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
275
-                $this->_handle_core_version_change($espresso_db_update);
276
-                break;
277
-            case EE_System::req_type_normal:
278
-            default:
270
+				break;
271
+			case EE_System::req_type_downgrade:
272
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
273
+				//its possible migrations are no longer required
274
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
275
+				$this->_handle_core_version_change($espresso_db_update);
276
+				break;
277
+			case EE_System::req_type_normal:
278
+			default:
279 279
 //				$this->_maybe_redirect_to_ee_about();
280
-                break;
281
-        }
282
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * Updates the list of installed versions and sets hooks for
289
-     * initializing the database later during the request
290
-     *
291
-     * @param array $espresso_db_update
292
-     */
293
-    protected function _handle_core_version_change($espresso_db_update)
294
-    {
295
-        $this->update_list_of_installed_versions($espresso_db_update);
296
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
297
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
298
-            array($this, 'initialize_db_if_no_migrations_required'));
299
-    }
300
-
301
-
302
-
303
-    /**
304
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
305
-     * information about what versions of EE have been installed and activated,
306
-     * NOT necessarily the state of the database
307
-     *
308
-     * @param null $espresso_db_update
309
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
310
-     *           from the options table
311
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
312
-     */
313
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
314
-    {
315
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
316
-        if ( ! $espresso_db_update) {
317
-            $espresso_db_update = get_option('espresso_db_update');
318
-        }
319
-        // check that option is an array
320
-        if ( ! is_array($espresso_db_update)) {
321
-            // if option is FALSE, then it never existed
322
-            if ($espresso_db_update === false) {
323
-                // make $espresso_db_update an array and save option with autoload OFF
324
-                $espresso_db_update = array();
325
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
326
-            } else {
327
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
328
-                $espresso_db_update = array($espresso_db_update => array());
329
-                update_option('espresso_db_update', $espresso_db_update);
330
-            }
331
-        } else {
332
-            $corrected_db_update = array();
333
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
334
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
335
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
336
-                    //the key is an int, and the value IS NOT an array
337
-                    //so it must be numerically-indexed, where values are versions installed...
338
-                    //fix it!
339
-                    $version_string = $should_be_array;
340
-                    $corrected_db_update[$version_string] = array('unknown-date');
341
-                } else {
342
-                    //ok it checks out
343
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
344
-                }
345
-            }
346
-            $espresso_db_update = $corrected_db_update;
347
-            update_option('espresso_db_update', $espresso_db_update);
348
-        }
349
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
350
-        return $espresso_db_update;
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * Does the traditional work of setting up the plugin's database and adding default data.
357
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
358
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
359
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
360
-     * so that it will be done when migrations are finished
361
-     *
362
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
363
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
364
-     *                                       This is a resource-intensive job
365
-     *                                       so we prefer to only do it when necessary
366
-     * @return void
367
-     */
368
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
369
-    {
370
-        $request_type = $this->detect_req_type();
371
-        //only initialize system if we're not in maintenance mode.
372
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
373
-            update_option('ee_flush_rewrite_rules', true);
374
-            if ($verify_schema) {
375
-                EEH_Activation::initialize_db_and_folders();
376
-            }
377
-            EEH_Activation::initialize_db_content();
378
-            EEH_Activation::system_initialization();
379
-            if ($initialize_addons_too) {
380
-                $this->initialize_addons();
381
-            }
382
-        } else {
383
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
384
-        }
385
-        if ($request_type === EE_System::req_type_new_activation
386
-            || $request_type === EE_System::req_type_reactivation
387
-            || (
388
-                $request_type === EE_System::req_type_upgrade
389
-                && $this->is_major_version_change()
390
-            )
391
-        ) {
392
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
393
-        }
394
-    }
395
-
396
-
397
-
398
-    /**
399
-     * Initializes the db for all registered addons
400
-     */
401
-    public function initialize_addons()
402
-    {
403
-        //foreach registered addon, make sure its db is up-to-date too
404
-        foreach ($this->registry->addons as $addon) {
405
-            $addon->initialize_db_if_no_migrations_required();
406
-        }
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
413
-     *
414
-     * @param    array  $version_history
415
-     * @param    string $current_version_to_add version to be added to the version history
416
-     * @return    boolean success as to whether or not this option was changed
417
-     */
418
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
419
-    {
420
-        if ( ! $version_history) {
421
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
422
-        }
423
-        if ($current_version_to_add == null) {
424
-            $current_version_to_add = espresso_version();
425
-        }
426
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
427
-        // re-save
428
-        return update_option('espresso_db_update', $version_history);
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * Detects if the current version indicated in the has existed in the list of
435
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
436
-     *
437
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
438
-     *                                  If not supplied, fetches it from the options table.
439
-     *                                  Also, caches its result so later parts of the code can also know whether
440
-     *                                  there's been an update or not. This way we can add the current version to
441
-     *                                  espresso_db_update, but still know if this is a new install or not
442
-     * @return int one of the constants on EE_System::req_type_
443
-     */
444
-    public function detect_req_type($espresso_db_update = null)
445
-    {
446
-        if ($this->_req_type === null) {
447
-            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
448
-                : $this->fix_espresso_db_upgrade_option();
449
-            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
450
-                'ee_espresso_activation', espresso_version());
451
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
452
-        }
453
-        return $this->_req_type;
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * Returns whether or not there was a non-micro version change (ie, change in either
460
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
461
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
462
-     *
463
-     * @param $activation_history
464
-     * @return bool
465
-     */
466
-    protected function _detect_major_version_change($activation_history)
467
-    {
468
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
469
-        $previous_version_parts = explode('.', $previous_version);
470
-        $current_version_parts = explode('.', espresso_version());
471
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
472
-               && ($previous_version_parts[0] !== $current_version_parts[0]
473
-                   || $previous_version_parts[1] !== $current_version_parts[1]
474
-               );
475
-    }
476
-
477
-
478
-
479
-    /**
480
-     * Returns true if either the major or minor version of EE changed during this request.
481
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
482
-     *
483
-     * @return bool
484
-     */
485
-    public function is_major_version_change()
486
-    {
487
-        return $this->_major_version_change;
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
494
-     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
495
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
496
-     * just activated to (for core that will always be espresso_version())
497
-     *
498
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
499
-     *                                                 ee plugin. for core that's 'espresso_db_update'
500
-     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
501
-     *                                                 indicate that this plugin was just activated
502
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
503
-     *                                                 espresso_version())
504
-     * @return int one of the constants on EE_System::req_type_*
505
-     */
506
-    public static function detect_req_type_given_activation_history(
507
-        $activation_history_for_addon,
508
-        $activation_indicator_option_name,
509
-        $version_to_upgrade_to
510
-    ) {
511
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
512
-        if ($activation_history_for_addon) {
513
-            //it exists, so this isn't a completely new install
514
-            //check if this version already in that list of previously installed versions
515
-            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
516
-                //it a version we haven't seen before
517
-                if ($version_is_higher === 1) {
518
-                    $req_type = EE_System::req_type_upgrade;
519
-                } else {
520
-                    $req_type = EE_System::req_type_downgrade;
521
-                }
522
-                delete_option($activation_indicator_option_name);
523
-            } else {
524
-                // its not an update. maybe a reactivation?
525
-                if (get_option($activation_indicator_option_name, false)) {
526
-                    if ($version_is_higher === -1) {
527
-                        $req_type = EE_System::req_type_downgrade;
528
-                    } elseif ($version_is_higher === 0) {
529
-                        //we've seen this version before, but it's an activation. must be a reactivation
530
-                        $req_type = EE_System::req_type_reactivation;
531
-                    } else {//$version_is_higher === 1
532
-                        $req_type = EE_System::req_type_upgrade;
533
-                    }
534
-                    delete_option($activation_indicator_option_name);
535
-                } else {
536
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
537
-                    if ($version_is_higher === -1) {
538
-                        $req_type = EE_System::req_type_downgrade;
539
-                    } elseif ($version_is_higher === 0) {
540
-                        //we've seen this version before and it's not an activation. its normal request
541
-                        $req_type = EE_System::req_type_normal;
542
-                    } else {//$version_is_higher === 1
543
-                        $req_type = EE_System::req_type_upgrade;
544
-                    }
545
-                }
546
-            }
547
-        } else {
548
-            //brand new install
549
-            $req_type = EE_System::req_type_new_activation;
550
-            delete_option($activation_indicator_option_name);
551
-        }
552
-        return $req_type;
553
-    }
554
-
555
-
556
-
557
-    /**
558
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
559
-     * the $activation_history_for_addon
560
-     *
561
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
562
-     *                                             sometimes containing 'unknown-date'
563
-     * @param string $version_to_upgrade_to        (current version)
564
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
565
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
566
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
567
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
568
-     */
569
-    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
570
-    {
571
-        //find the most recently-activated version
572
-        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
573
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * Gets the most recently active version listed in the activation history,
580
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
581
-     *
582
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
583
-     *                                   sometimes containing 'unknown-date'
584
-     * @return string
585
-     */
586
-    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
587
-    {
588
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
589
-        $most_recently_active_version = '0.0.0.dev.000';
590
-        if (is_array($activation_history)) {
591
-            foreach ($activation_history as $version => $times_activated) {
592
-                //check there is a record of when this version was activated. Otherwise,
593
-                //mark it as unknown
594
-                if ( ! $times_activated) {
595
-                    $times_activated = array('unknown-date');
596
-                }
597
-                if (is_string($times_activated)) {
598
-                    $times_activated = array($times_activated);
599
-                }
600
-                foreach ($times_activated as $an_activation) {
601
-                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
602
-                        $most_recently_active_version = $version;
603
-                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
604
-                            ? '1970-01-01 00:00:00' : $an_activation;
605
-                    }
606
-                }
607
-            }
608
-        }
609
-        return $most_recently_active_version;
610
-    }
611
-
612
-
613
-
614
-    /**
615
-     * This redirects to the about EE page after activation
616
-     *
617
-     * @return void
618
-     */
619
-    public function redirect_to_about_ee()
620
-    {
621
-        $notices = EE_Error::get_notices(false);
622
-        //if current user is an admin and it's not an ajax or rest request
623
-        if (
624
-            ! (defined('DOING_AJAX') && DOING_AJAX)
625
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
626
-            && ! isset($notices['errors'])
627
-            && apply_filters(
628
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
629
-                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
630
-            )
631
-        ) {
632
-            $query_params = array('page' => 'espresso_about');
633
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
634
-                $query_params['new_activation'] = true;
635
-            }
636
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
637
-                $query_params['reactivation'] = true;
638
-            }
639
-            $url = add_query_arg($query_params, admin_url('admin.php'));
640
-            wp_safe_redirect($url);
641
-            exit();
642
-        }
643
-    }
644
-
645
-
646
-
647
-    /**
648
-     * load_core_configuration
649
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
650
-     * which runs during the WP 'plugins_loaded' action at priority 5
651
-     *
652
-     * @return void
653
-     */
654
-    public function load_core_configuration()
655
-    {
656
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
657
-        $this->registry->load_core('EE_Load_Textdomain');
658
-        //load textdomain
659
-        EE_Load_Textdomain::load_textdomain();
660
-        // load and setup EE_Config and EE_Network_Config
661
-        $this->registry->load_core('Config');
662
-        $this->registry->load_core('Network_Config');
663
-        // setup autoloaders
664
-        // enable logging?
665
-        if ($this->registry->CFG->admin->use_full_logging) {
666
-            $this->registry->load_core('Log');
667
-        }
668
-        // check for activation errors
669
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
670
-        if ($activation_errors) {
671
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
672
-            update_option('ee_plugin_activation_errors', false);
673
-        }
674
-        // get model names
675
-        $this->_parse_model_names();
676
-        //load caf stuff a chance to play during the activation process too.
677
-        $this->_maybe_brew_regular();
678
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
679
-    }
680
-
681
-
682
-
683
-    /**
684
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
685
-     *
686
-     * @return void
687
-     */
688
-    private function _parse_model_names()
689
-    {
690
-        //get all the files in the EE_MODELS folder that end in .model.php
691
-        $models = glob(EE_MODELS . '*.model.php');
692
-        $model_names = array();
693
-        $non_abstract_db_models = array();
694
-        foreach ($models as $model) {
695
-            // get model classname
696
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
697
-            $short_name = str_replace('EEM_', '', $classname);
698
-            $reflectionClass = new ReflectionClass($classname);
699
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
700
-                $non_abstract_db_models[$short_name] = $classname;
701
-            }
702
-            $model_names[$short_name] = $classname;
703
-        }
704
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
705
-        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
706
-            $non_abstract_db_models);
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
713
-     * that need to be setup before our EE_System launches.
714
-     *
715
-     * @return void
716
-     */
717
-    private function _maybe_brew_regular()
718
-    {
719
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
720
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
721
-        }
722
-    }
723
-
724
-
725
-
726
-    /**
727
-     * register_shortcodes_modules_and_widgets
728
-     * generate lists of shortcodes and modules, then verify paths and classes
729
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
730
-     * which runs during the WP 'plugins_loaded' action at priority 7
731
-     *
732
-     * @access public
733
-     * @return void
734
-     */
735
-    public function register_shortcodes_modules_and_widgets()
736
-    {
737
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
738
-        // check for addons using old hookpoint
739
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
740
-            $this->_incompatible_addon_error();
741
-        }
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * _incompatible_addon_error
748
-     *
749
-     * @access public
750
-     * @return void
751
-     */
752
-    private function _incompatible_addon_error()
753
-    {
754
-        // get array of classes hooking into here
755
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
756
-        if ( ! empty($class_names)) {
757
-            $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
758
-                'event_espresso');
759
-            $msg .= '<ul>';
760
-            foreach ($class_names as $class_name) {
761
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
762
-                        $class_name) . '</b></li>';
763
-            }
764
-            $msg .= '</ul>';
765
-            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
766
-                'event_espresso');
767
-            // save list of incompatible addons to wp-options for later use
768
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
769
-            if (is_admin()) {
770
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
771
-            }
772
-        }
773
-    }
774
-
775
-
776
-
777
-    /**
778
-     * brew_espresso
779
-     * begins the process of setting hooks for initializing EE in the correct order
780
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
781
-     * which runs during the WP 'plugins_loaded' action at priority 9
782
-     *
783
-     * @return void
784
-     */
785
-    public function brew_espresso()
786
-    {
787
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
788
-        // load some final core systems
789
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
790
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
791
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
792
-        add_action('init', array($this, 'load_controllers'), 7);
793
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
794
-        add_action('init', array($this, 'initialize'), 10);
795
-        add_action('init', array($this, 'initialize_last'), 100);
796
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25);
797
-        add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25);
798
-        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
799
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
800
-            // pew pew pew
801
-            $this->registry->load_core('PUE');
802
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
803
-        }
804
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
805
-    }
806
-
807
-
808
-
809
-    /**
810
-     *    set_hooks_for_core
811
-     *
812
-     * @access public
813
-     * @return    void
814
-     */
815
-    public function set_hooks_for_core()
816
-    {
817
-        $this->_deactivate_incompatible_addons();
818
-        do_action('AHEE__EE_System__set_hooks_for_core');
819
-    }
820
-
821
-
822
-
823
-    /**
824
-     * Using the information gathered in EE_System::_incompatible_addon_error,
825
-     * deactivates any addons considered incompatible with the current version of EE
826
-     */
827
-    private function _deactivate_incompatible_addons()
828
-    {
829
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
830
-        if ( ! empty($incompatible_addons)) {
831
-            $active_plugins = get_option('active_plugins', array());
832
-            foreach ($active_plugins as $active_plugin) {
833
-                foreach ($incompatible_addons as $incompatible_addon) {
834
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
835
-                        unset($_GET['activate']);
836
-                        espresso_deactivate_plugin($active_plugin);
837
-                    }
838
-                }
839
-            }
840
-        }
841
-    }
842
-
843
-
844
-
845
-    /**
846
-     *    perform_activations_upgrades_and_migrations
847
-     *
848
-     * @access public
849
-     * @return    void
850
-     */
851
-    public function perform_activations_upgrades_and_migrations()
852
-    {
853
-        //first check if we had previously attempted to setup EE's directories but failed
854
-        if (EEH_Activation::upload_directories_incomplete()) {
855
-            EEH_Activation::create_upload_directories();
856
-        }
857
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
858
-    }
859
-
860
-
861
-
862
-    /**
863
-     *    load_CPTs_and_session
864
-     *
865
-     * @access public
866
-     * @return    void
867
-     */
868
-    public function load_CPTs_and_session()
869
-    {
870
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
871
-        // register Custom Post Types
872
-        $this->registry->load_core('Register_CPTs');
873
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
874
-    }
875
-
876
-
877
-
878
-    /**
879
-     * load_controllers
880
-     * this is the best place to load any additional controllers that needs access to EE core.
881
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
882
-     * time
883
-     *
884
-     * @access public
885
-     * @return void
886
-     */
887
-    public function load_controllers()
888
-    {
889
-        do_action('AHEE__EE_System__load_controllers__start');
890
-        // let's get it started
891
-        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
892
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
893
-            $this->registry->load_core('Front_Controller', array(), false, true);
894
-        } else if ( ! EE_FRONT_AJAX) {
895
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
896
-            EE_Registry::instance()->load_core('Admin');
897
-        }
898
-        do_action('AHEE__EE_System__load_controllers__complete');
899
-    }
900
-
901
-
902
-
903
-    /**
904
-     * core_loaded_and_ready
905
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
906
-     *
907
-     * @access public
908
-     * @return void
909
-     */
910
-    public function core_loaded_and_ready()
911
-    {
912
-        do_action('AHEE__EE_System__core_loaded_and_ready');
913
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
914
-        $this->registry->load_core('Session');
915
-        //		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
916
-    }
917
-
918
-
919
-
920
-    /**
921
-     * initialize
922
-     * this is the best place to begin initializing client code
923
-     *
924
-     * @access public
925
-     * @return void
926
-     */
927
-    public function initialize()
928
-    {
929
-        do_action('AHEE__EE_System__initialize');
930
-    }
931
-
932
-
933
-
934
-    /**
935
-     * initialize_last
936
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
937
-     * initialize has done so
938
-     *
939
-     * @access public
940
-     * @return void
941
-     */
942
-    public function initialize_last()
943
-    {
944
-        do_action('AHEE__EE_System__initialize_last');
945
-    }
946
-
947
-
948
-
949
-    /**
950
-     * set_hooks_for_shortcodes_modules_and_addons
951
-     * this is the best place for other systems to set callbacks for hooking into other parts of EE
952
-     * this happens at the very beginning of the wp_loaded hookpoint
953
-     *
954
-     * @access public
955
-     * @return void
956
-     */
957
-    public function set_hooks_for_shortcodes_modules_and_addons()
958
-    {
280
+				break;
281
+		}
282
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * Updates the list of installed versions and sets hooks for
289
+	 * initializing the database later during the request
290
+	 *
291
+	 * @param array $espresso_db_update
292
+	 */
293
+	protected function _handle_core_version_change($espresso_db_update)
294
+	{
295
+		$this->update_list_of_installed_versions($espresso_db_update);
296
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
297
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
298
+			array($this, 'initialize_db_if_no_migrations_required'));
299
+	}
300
+
301
+
302
+
303
+	/**
304
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
305
+	 * information about what versions of EE have been installed and activated,
306
+	 * NOT necessarily the state of the database
307
+	 *
308
+	 * @param null $espresso_db_update
309
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
310
+	 *           from the options table
311
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
312
+	 */
313
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
314
+	{
315
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
316
+		if ( ! $espresso_db_update) {
317
+			$espresso_db_update = get_option('espresso_db_update');
318
+		}
319
+		// check that option is an array
320
+		if ( ! is_array($espresso_db_update)) {
321
+			// if option is FALSE, then it never existed
322
+			if ($espresso_db_update === false) {
323
+				// make $espresso_db_update an array and save option with autoload OFF
324
+				$espresso_db_update = array();
325
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
326
+			} else {
327
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
328
+				$espresso_db_update = array($espresso_db_update => array());
329
+				update_option('espresso_db_update', $espresso_db_update);
330
+			}
331
+		} else {
332
+			$corrected_db_update = array();
333
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
334
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
335
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
336
+					//the key is an int, and the value IS NOT an array
337
+					//so it must be numerically-indexed, where values are versions installed...
338
+					//fix it!
339
+					$version_string = $should_be_array;
340
+					$corrected_db_update[$version_string] = array('unknown-date');
341
+				} else {
342
+					//ok it checks out
343
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
344
+				}
345
+			}
346
+			$espresso_db_update = $corrected_db_update;
347
+			update_option('espresso_db_update', $espresso_db_update);
348
+		}
349
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
350
+		return $espresso_db_update;
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * Does the traditional work of setting up the plugin's database and adding default data.
357
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
358
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
359
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
360
+	 * so that it will be done when migrations are finished
361
+	 *
362
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
363
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
364
+	 *                                       This is a resource-intensive job
365
+	 *                                       so we prefer to only do it when necessary
366
+	 * @return void
367
+	 */
368
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
369
+	{
370
+		$request_type = $this->detect_req_type();
371
+		//only initialize system if we're not in maintenance mode.
372
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
373
+			update_option('ee_flush_rewrite_rules', true);
374
+			if ($verify_schema) {
375
+				EEH_Activation::initialize_db_and_folders();
376
+			}
377
+			EEH_Activation::initialize_db_content();
378
+			EEH_Activation::system_initialization();
379
+			if ($initialize_addons_too) {
380
+				$this->initialize_addons();
381
+			}
382
+		} else {
383
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
384
+		}
385
+		if ($request_type === EE_System::req_type_new_activation
386
+			|| $request_type === EE_System::req_type_reactivation
387
+			|| (
388
+				$request_type === EE_System::req_type_upgrade
389
+				&& $this->is_major_version_change()
390
+			)
391
+		) {
392
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
393
+		}
394
+	}
395
+
396
+
397
+
398
+	/**
399
+	 * Initializes the db for all registered addons
400
+	 */
401
+	public function initialize_addons()
402
+	{
403
+		//foreach registered addon, make sure its db is up-to-date too
404
+		foreach ($this->registry->addons as $addon) {
405
+			$addon->initialize_db_if_no_migrations_required();
406
+		}
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
413
+	 *
414
+	 * @param    array  $version_history
415
+	 * @param    string $current_version_to_add version to be added to the version history
416
+	 * @return    boolean success as to whether or not this option was changed
417
+	 */
418
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
419
+	{
420
+		if ( ! $version_history) {
421
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
422
+		}
423
+		if ($current_version_to_add == null) {
424
+			$current_version_to_add = espresso_version();
425
+		}
426
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
427
+		// re-save
428
+		return update_option('espresso_db_update', $version_history);
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * Detects if the current version indicated in the has existed in the list of
435
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
436
+	 *
437
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
438
+	 *                                  If not supplied, fetches it from the options table.
439
+	 *                                  Also, caches its result so later parts of the code can also know whether
440
+	 *                                  there's been an update or not. This way we can add the current version to
441
+	 *                                  espresso_db_update, but still know if this is a new install or not
442
+	 * @return int one of the constants on EE_System::req_type_
443
+	 */
444
+	public function detect_req_type($espresso_db_update = null)
445
+	{
446
+		if ($this->_req_type === null) {
447
+			$espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
448
+				: $this->fix_espresso_db_upgrade_option();
449
+			$this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
450
+				'ee_espresso_activation', espresso_version());
451
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
452
+		}
453
+		return $this->_req_type;
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * Returns whether or not there was a non-micro version change (ie, change in either
460
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
461
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
462
+	 *
463
+	 * @param $activation_history
464
+	 * @return bool
465
+	 */
466
+	protected function _detect_major_version_change($activation_history)
467
+	{
468
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
469
+		$previous_version_parts = explode('.', $previous_version);
470
+		$current_version_parts = explode('.', espresso_version());
471
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
472
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
473
+				   || $previous_version_parts[1] !== $current_version_parts[1]
474
+			   );
475
+	}
476
+
477
+
478
+
479
+	/**
480
+	 * Returns true if either the major or minor version of EE changed during this request.
481
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
482
+	 *
483
+	 * @return bool
484
+	 */
485
+	public function is_major_version_change()
486
+	{
487
+		return $this->_major_version_change;
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
494
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
495
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
496
+	 * just activated to (for core that will always be espresso_version())
497
+	 *
498
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
499
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
500
+	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
501
+	 *                                                 indicate that this plugin was just activated
502
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
503
+	 *                                                 espresso_version())
504
+	 * @return int one of the constants on EE_System::req_type_*
505
+	 */
506
+	public static function detect_req_type_given_activation_history(
507
+		$activation_history_for_addon,
508
+		$activation_indicator_option_name,
509
+		$version_to_upgrade_to
510
+	) {
511
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
512
+		if ($activation_history_for_addon) {
513
+			//it exists, so this isn't a completely new install
514
+			//check if this version already in that list of previously installed versions
515
+			if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
516
+				//it a version we haven't seen before
517
+				if ($version_is_higher === 1) {
518
+					$req_type = EE_System::req_type_upgrade;
519
+				} else {
520
+					$req_type = EE_System::req_type_downgrade;
521
+				}
522
+				delete_option($activation_indicator_option_name);
523
+			} else {
524
+				// its not an update. maybe a reactivation?
525
+				if (get_option($activation_indicator_option_name, false)) {
526
+					if ($version_is_higher === -1) {
527
+						$req_type = EE_System::req_type_downgrade;
528
+					} elseif ($version_is_higher === 0) {
529
+						//we've seen this version before, but it's an activation. must be a reactivation
530
+						$req_type = EE_System::req_type_reactivation;
531
+					} else {//$version_is_higher === 1
532
+						$req_type = EE_System::req_type_upgrade;
533
+					}
534
+					delete_option($activation_indicator_option_name);
535
+				} else {
536
+					//we've seen this version before and the activation indicate doesn't show it was just activated
537
+					if ($version_is_higher === -1) {
538
+						$req_type = EE_System::req_type_downgrade;
539
+					} elseif ($version_is_higher === 0) {
540
+						//we've seen this version before and it's not an activation. its normal request
541
+						$req_type = EE_System::req_type_normal;
542
+					} else {//$version_is_higher === 1
543
+						$req_type = EE_System::req_type_upgrade;
544
+					}
545
+				}
546
+			}
547
+		} else {
548
+			//brand new install
549
+			$req_type = EE_System::req_type_new_activation;
550
+			delete_option($activation_indicator_option_name);
551
+		}
552
+		return $req_type;
553
+	}
554
+
555
+
556
+
557
+	/**
558
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
559
+	 * the $activation_history_for_addon
560
+	 *
561
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
562
+	 *                                             sometimes containing 'unknown-date'
563
+	 * @param string $version_to_upgrade_to        (current version)
564
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
565
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
566
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
567
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
568
+	 */
569
+	protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
570
+	{
571
+		//find the most recently-activated version
572
+		$most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
573
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * Gets the most recently active version listed in the activation history,
580
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
581
+	 *
582
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
583
+	 *                                   sometimes containing 'unknown-date'
584
+	 * @return string
585
+	 */
586
+	protected static function _get_most_recently_active_version_from_activation_history($activation_history)
587
+	{
588
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
589
+		$most_recently_active_version = '0.0.0.dev.000';
590
+		if (is_array($activation_history)) {
591
+			foreach ($activation_history as $version => $times_activated) {
592
+				//check there is a record of when this version was activated. Otherwise,
593
+				//mark it as unknown
594
+				if ( ! $times_activated) {
595
+					$times_activated = array('unknown-date');
596
+				}
597
+				if (is_string($times_activated)) {
598
+					$times_activated = array($times_activated);
599
+				}
600
+				foreach ($times_activated as $an_activation) {
601
+					if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
602
+						$most_recently_active_version = $version;
603
+						$most_recently_active_version_activation = $an_activation == 'unknown-date'
604
+							? '1970-01-01 00:00:00' : $an_activation;
605
+					}
606
+				}
607
+			}
608
+		}
609
+		return $most_recently_active_version;
610
+	}
611
+
612
+
613
+
614
+	/**
615
+	 * This redirects to the about EE page after activation
616
+	 *
617
+	 * @return void
618
+	 */
619
+	public function redirect_to_about_ee()
620
+	{
621
+		$notices = EE_Error::get_notices(false);
622
+		//if current user is an admin and it's not an ajax or rest request
623
+		if (
624
+			! (defined('DOING_AJAX') && DOING_AJAX)
625
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
626
+			&& ! isset($notices['errors'])
627
+			&& apply_filters(
628
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
629
+				$this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
630
+			)
631
+		) {
632
+			$query_params = array('page' => 'espresso_about');
633
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
634
+				$query_params['new_activation'] = true;
635
+			}
636
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
637
+				$query_params['reactivation'] = true;
638
+			}
639
+			$url = add_query_arg($query_params, admin_url('admin.php'));
640
+			wp_safe_redirect($url);
641
+			exit();
642
+		}
643
+	}
644
+
645
+
646
+
647
+	/**
648
+	 * load_core_configuration
649
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
650
+	 * which runs during the WP 'plugins_loaded' action at priority 5
651
+	 *
652
+	 * @return void
653
+	 */
654
+	public function load_core_configuration()
655
+	{
656
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
657
+		$this->registry->load_core('EE_Load_Textdomain');
658
+		//load textdomain
659
+		EE_Load_Textdomain::load_textdomain();
660
+		// load and setup EE_Config and EE_Network_Config
661
+		$this->registry->load_core('Config');
662
+		$this->registry->load_core('Network_Config');
663
+		// setup autoloaders
664
+		// enable logging?
665
+		if ($this->registry->CFG->admin->use_full_logging) {
666
+			$this->registry->load_core('Log');
667
+		}
668
+		// check for activation errors
669
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
670
+		if ($activation_errors) {
671
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
672
+			update_option('ee_plugin_activation_errors', false);
673
+		}
674
+		// get model names
675
+		$this->_parse_model_names();
676
+		//load caf stuff a chance to play during the activation process too.
677
+		$this->_maybe_brew_regular();
678
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
679
+	}
680
+
681
+
682
+
683
+	/**
684
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
685
+	 *
686
+	 * @return void
687
+	 */
688
+	private function _parse_model_names()
689
+	{
690
+		//get all the files in the EE_MODELS folder that end in .model.php
691
+		$models = glob(EE_MODELS . '*.model.php');
692
+		$model_names = array();
693
+		$non_abstract_db_models = array();
694
+		foreach ($models as $model) {
695
+			// get model classname
696
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
697
+			$short_name = str_replace('EEM_', '', $classname);
698
+			$reflectionClass = new ReflectionClass($classname);
699
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
700
+				$non_abstract_db_models[$short_name] = $classname;
701
+			}
702
+			$model_names[$short_name] = $classname;
703
+		}
704
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
705
+		$this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
706
+			$non_abstract_db_models);
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
713
+	 * that need to be setup before our EE_System launches.
714
+	 *
715
+	 * @return void
716
+	 */
717
+	private function _maybe_brew_regular()
718
+	{
719
+		if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
720
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
721
+		}
722
+	}
723
+
724
+
725
+
726
+	/**
727
+	 * register_shortcodes_modules_and_widgets
728
+	 * generate lists of shortcodes and modules, then verify paths and classes
729
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
730
+	 * which runs during the WP 'plugins_loaded' action at priority 7
731
+	 *
732
+	 * @access public
733
+	 * @return void
734
+	 */
735
+	public function register_shortcodes_modules_and_widgets()
736
+	{
737
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
738
+		// check for addons using old hookpoint
739
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
740
+			$this->_incompatible_addon_error();
741
+		}
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * _incompatible_addon_error
748
+	 *
749
+	 * @access public
750
+	 * @return void
751
+	 */
752
+	private function _incompatible_addon_error()
753
+	{
754
+		// get array of classes hooking into here
755
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
756
+		if ( ! empty($class_names)) {
757
+			$msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
758
+				'event_espresso');
759
+			$msg .= '<ul>';
760
+			foreach ($class_names as $class_name) {
761
+				$msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
762
+						$class_name) . '</b></li>';
763
+			}
764
+			$msg .= '</ul>';
765
+			$msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
766
+				'event_espresso');
767
+			// save list of incompatible addons to wp-options for later use
768
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
769
+			if (is_admin()) {
770
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
771
+			}
772
+		}
773
+	}
774
+
775
+
776
+
777
+	/**
778
+	 * brew_espresso
779
+	 * begins the process of setting hooks for initializing EE in the correct order
780
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
781
+	 * which runs during the WP 'plugins_loaded' action at priority 9
782
+	 *
783
+	 * @return void
784
+	 */
785
+	public function brew_espresso()
786
+	{
787
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
788
+		// load some final core systems
789
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
790
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
791
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
792
+		add_action('init', array($this, 'load_controllers'), 7);
793
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
794
+		add_action('init', array($this, 'initialize'), 10);
795
+		add_action('init', array($this, 'initialize_last'), 100);
796
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25);
797
+		add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25);
798
+		add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
799
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
800
+			// pew pew pew
801
+			$this->registry->load_core('PUE');
802
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
803
+		}
804
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
805
+	}
806
+
807
+
808
+
809
+	/**
810
+	 *    set_hooks_for_core
811
+	 *
812
+	 * @access public
813
+	 * @return    void
814
+	 */
815
+	public function set_hooks_for_core()
816
+	{
817
+		$this->_deactivate_incompatible_addons();
818
+		do_action('AHEE__EE_System__set_hooks_for_core');
819
+	}
820
+
821
+
822
+
823
+	/**
824
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
825
+	 * deactivates any addons considered incompatible with the current version of EE
826
+	 */
827
+	private function _deactivate_incompatible_addons()
828
+	{
829
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
830
+		if ( ! empty($incompatible_addons)) {
831
+			$active_plugins = get_option('active_plugins', array());
832
+			foreach ($active_plugins as $active_plugin) {
833
+				foreach ($incompatible_addons as $incompatible_addon) {
834
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
835
+						unset($_GET['activate']);
836
+						espresso_deactivate_plugin($active_plugin);
837
+					}
838
+				}
839
+			}
840
+		}
841
+	}
842
+
843
+
844
+
845
+	/**
846
+	 *    perform_activations_upgrades_and_migrations
847
+	 *
848
+	 * @access public
849
+	 * @return    void
850
+	 */
851
+	public function perform_activations_upgrades_and_migrations()
852
+	{
853
+		//first check if we had previously attempted to setup EE's directories but failed
854
+		if (EEH_Activation::upload_directories_incomplete()) {
855
+			EEH_Activation::create_upload_directories();
856
+		}
857
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
858
+	}
859
+
860
+
861
+
862
+	/**
863
+	 *    load_CPTs_and_session
864
+	 *
865
+	 * @access public
866
+	 * @return    void
867
+	 */
868
+	public function load_CPTs_and_session()
869
+	{
870
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
871
+		// register Custom Post Types
872
+		$this->registry->load_core('Register_CPTs');
873
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
874
+	}
875
+
876
+
877
+
878
+	/**
879
+	 * load_controllers
880
+	 * this is the best place to load any additional controllers that needs access to EE core.
881
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
882
+	 * time
883
+	 *
884
+	 * @access public
885
+	 * @return void
886
+	 */
887
+	public function load_controllers()
888
+	{
889
+		do_action('AHEE__EE_System__load_controllers__start');
890
+		// let's get it started
891
+		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
892
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
893
+			$this->registry->load_core('Front_Controller', array(), false, true);
894
+		} else if ( ! EE_FRONT_AJAX) {
895
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
896
+			EE_Registry::instance()->load_core('Admin');
897
+		}
898
+		do_action('AHEE__EE_System__load_controllers__complete');
899
+	}
900
+
901
+
902
+
903
+	/**
904
+	 * core_loaded_and_ready
905
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
906
+	 *
907
+	 * @access public
908
+	 * @return void
909
+	 */
910
+	public function core_loaded_and_ready()
911
+	{
912
+		do_action('AHEE__EE_System__core_loaded_and_ready');
913
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
914
+		$this->registry->load_core('Session');
915
+		//		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
916
+	}
917
+
918
+
919
+
920
+	/**
921
+	 * initialize
922
+	 * this is the best place to begin initializing client code
923
+	 *
924
+	 * @access public
925
+	 * @return void
926
+	 */
927
+	public function initialize()
928
+	{
929
+		do_action('AHEE__EE_System__initialize');
930
+	}
931
+
932
+
933
+
934
+	/**
935
+	 * initialize_last
936
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
937
+	 * initialize has done so
938
+	 *
939
+	 * @access public
940
+	 * @return void
941
+	 */
942
+	public function initialize_last()
943
+	{
944
+		do_action('AHEE__EE_System__initialize_last');
945
+	}
946
+
947
+
948
+
949
+	/**
950
+	 * set_hooks_for_shortcodes_modules_and_addons
951
+	 * this is the best place for other systems to set callbacks for hooking into other parts of EE
952
+	 * this happens at the very beginning of the wp_loaded hookpoint
953
+	 *
954
+	 * @access public
955
+	 * @return void
956
+	 */
957
+	public function set_hooks_for_shortcodes_modules_and_addons()
958
+	{
959 959
 //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
960
-    }
961
-
962
-
963
-
964
-    /**
965
-     * do_not_cache
966
-     * sets no cache headers and defines no cache constants for WP plugins
967
-     *
968
-     * @access public
969
-     * @return void
970
-     */
971
-    public static function do_not_cache()
972
-    {
973
-        // set no cache constants
974
-        if ( ! defined('DONOTCACHEPAGE')) {
975
-            define('DONOTCACHEPAGE', true);
976
-        }
977
-        if ( ! defined('DONOTCACHCEOBJECT')) {
978
-            define('DONOTCACHCEOBJECT', true);
979
-        }
980
-        if ( ! defined('DONOTCACHEDB')) {
981
-            define('DONOTCACHEDB', true);
982
-        }
983
-        // add no cache headers
984
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
985
-        // plus a little extra for nginx and Google Chrome
986
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
987
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
988
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
989
-    }
990
-
991
-
992
-
993
-    /**
994
-     *    extra_nocache_headers
995
-     *
996
-     * @access    public
997
-     * @param $headers
998
-     * @return    array
999
-     */
1000
-    public static function extra_nocache_headers($headers)
1001
-    {
1002
-        // for NGINX
1003
-        $headers['X-Accel-Expires'] = 0;
1004
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1005
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1006
-        return $headers;
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     *    nocache_headers
1013
-     *
1014
-     * @access    public
1015
-     * @return    void
1016
-     */
1017
-    public static function nocache_headers()
1018
-    {
1019
-        nocache_headers();
1020
-    }
1021
-
1022
-
1023
-
1024
-    /**
1025
-     *    espresso_toolbar_items
1026
-     *
1027
-     * @access public
1028
-     * @param  WP_Admin_Bar $admin_bar
1029
-     * @return void
1030
-     */
1031
-    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1032
-    {
1033
-        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1034
-        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1035
-            || defined('DOING_AJAX')
1036
-            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1037
-        ) {
1038
-            return;
1039
-        }
1040
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1041
-        $menu_class = 'espresso_menu_item_class';
1042
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1043
-        //because they're only defined in each of their respective constructors
1044
-        //and this might be a frontend request, in which case they aren't available
1045
-        $events_admin_url = admin_url("admin.php?page=espresso_events");
1046
-        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1047
-        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1048
-        //Top Level
1049
-        $admin_bar->add_menu(array(
1050
-            'id'    => 'espresso-toolbar',
1051
-            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1052
-                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1053
-                       . '</span>',
1054
-            'href'  => $events_admin_url,
1055
-            'meta'  => array(
1056
-                'title' => __('Event Espresso', 'event_espresso'),
1057
-                'class' => $menu_class . 'first',
1058
-            ),
1059
-        ));
1060
-        //Events
1061
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1062
-            $admin_bar->add_menu(array(
1063
-                'id'     => 'espresso-toolbar-events',
1064
-                'parent' => 'espresso-toolbar',
1065
-                'title'  => __('Events', 'event_espresso'),
1066
-                'href'   => $events_admin_url,
1067
-                'meta'   => array(
1068
-                    'title'  => __('Events', 'event_espresso'),
1069
-                    'target' => '',
1070
-                    'class'  => $menu_class,
1071
-                ),
1072
-            ));
1073
-        }
1074
-        if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1075
-            //Events Add New
1076
-            $admin_bar->add_menu(array(
1077
-                'id'     => 'espresso-toolbar-events-new',
1078
-                'parent' => 'espresso-toolbar-events',
1079
-                'title'  => __('Add New', 'event_espresso'),
1080
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1081
-                'meta'   => array(
1082
-                    'title'  => __('Add New', 'event_espresso'),
1083
-                    'target' => '',
1084
-                    'class'  => $menu_class,
1085
-                ),
1086
-            ));
1087
-        }
1088
-        if (is_single() && (get_post_type() == 'espresso_events')) {
1089
-            //Current post
1090
-            global $post;
1091
-            if ($this->registry->CAP->current_user_can('ee_edit_event',
1092
-                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1093
-            ) {
1094
-                //Events Edit Current Event
1095
-                $admin_bar->add_menu(array(
1096
-                    'id'     => 'espresso-toolbar-events-edit',
1097
-                    'parent' => 'espresso-toolbar-events',
1098
-                    'title'  => __('Edit Event', 'event_espresso'),
1099
-                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1100
-                        $events_admin_url),
1101
-                    'meta'   => array(
1102
-                        'title'  => __('Edit Event', 'event_espresso'),
1103
-                        'target' => '',
1104
-                        'class'  => $menu_class,
1105
-                    ),
1106
-                ));
1107
-            }
1108
-        }
1109
-        //Events View
1110
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1111
-            'ee_admin_bar_menu_espresso-toolbar-events-view')
1112
-        ) {
1113
-            $admin_bar->add_menu(array(
1114
-                'id'     => 'espresso-toolbar-events-view',
1115
-                'parent' => 'espresso-toolbar-events',
1116
-                'title'  => __('View', 'event_espresso'),
1117
-                'href'   => $events_admin_url,
1118
-                'meta'   => array(
1119
-                    'title'  => __('View', 'event_espresso'),
1120
-                    'target' => '',
1121
-                    'class'  => $menu_class,
1122
-                ),
1123
-            ));
1124
-        }
1125
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1126
-            //Events View All
1127
-            $admin_bar->add_menu(array(
1128
-                'id'     => 'espresso-toolbar-events-all',
1129
-                'parent' => 'espresso-toolbar-events-view',
1130
-                'title'  => __('All', 'event_espresso'),
1131
-                'href'   => $events_admin_url,
1132
-                'meta'   => array(
1133
-                    'title'  => __('All', 'event_espresso'),
1134
-                    'target' => '',
1135
-                    'class'  => $menu_class,
1136
-                ),
1137
-            ));
1138
-        }
1139
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1140
-            'ee_admin_bar_menu_espresso-toolbar-events-today')
1141
-        ) {
1142
-            //Events View Today
1143
-            $admin_bar->add_menu(array(
1144
-                'id'     => 'espresso-toolbar-events-today',
1145
-                'parent' => 'espresso-toolbar-events-view',
1146
-                'title'  => __('Today', 'event_espresso'),
1147
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1148
-                    $events_admin_url),
1149
-                'meta'   => array(
1150
-                    'title'  => __('Today', 'event_espresso'),
1151
-                    'target' => '',
1152
-                    'class'  => $menu_class,
1153
-                ),
1154
-            ));
1155
-        }
1156
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1157
-            'ee_admin_bar_menu_espresso-toolbar-events-month')
1158
-        ) {
1159
-            //Events View This Month
1160
-            $admin_bar->add_menu(array(
1161
-                'id'     => 'espresso-toolbar-events-month',
1162
-                'parent' => 'espresso-toolbar-events-view',
1163
-                'title'  => __('This Month', 'event_espresso'),
1164
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1165
-                    $events_admin_url),
1166
-                'meta'   => array(
1167
-                    'title'  => __('This Month', 'event_espresso'),
1168
-                    'target' => '',
1169
-                    'class'  => $menu_class,
1170
-                ),
1171
-            ));
1172
-        }
1173
-        //Registration Overview
1174
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1175
-            'ee_admin_bar_menu_espresso-toolbar-registrations')
1176
-        ) {
1177
-            $admin_bar->add_menu(array(
1178
-                'id'     => 'espresso-toolbar-registrations',
1179
-                'parent' => 'espresso-toolbar',
1180
-                'title'  => __('Registrations', 'event_espresso'),
1181
-                'href'   => $reg_admin_url,
1182
-                'meta'   => array(
1183
-                    'title'  => __('Registrations', 'event_espresso'),
1184
-                    'target' => '',
1185
-                    'class'  => $menu_class,
1186
-                ),
1187
-            ));
1188
-        }
1189
-        //Registration Overview Today
1190
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1191
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1192
-        ) {
1193
-            $admin_bar->add_menu(array(
1194
-                'id'     => 'espresso-toolbar-registrations-today',
1195
-                'parent' => 'espresso-toolbar-registrations',
1196
-                'title'  => __('Today', 'event_espresso'),
1197
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1198
-                    $reg_admin_url),
1199
-                'meta'   => array(
1200
-                    'title'  => __('Today', 'event_espresso'),
1201
-                    'target' => '',
1202
-                    'class'  => $menu_class,
1203
-                ),
1204
-            ));
1205
-        }
1206
-        //Registration Overview Today Completed
1207
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1208
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1209
-        ) {
1210
-            $admin_bar->add_menu(array(
1211
-                'id'     => 'espresso-toolbar-registrations-today-approved',
1212
-                'parent' => 'espresso-toolbar-registrations-today',
1213
-                'title'  => __('Approved', 'event_espresso'),
1214
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1215
-                    'action'      => 'default',
1216
-                    'status'      => 'today',
1217
-                    '_reg_status' => EEM_Registration::status_id_approved,
1218
-                ), $reg_admin_url),
1219
-                'meta'   => array(
1220
-                    'title'  => __('Approved', 'event_espresso'),
1221
-                    'target' => '',
1222
-                    'class'  => $menu_class,
1223
-                ),
1224
-            ));
1225
-        }
1226
-        //Registration Overview Today Pending\
1227
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1228
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1229
-        ) {
1230
-            $admin_bar->add_menu(array(
1231
-                'id'     => 'espresso-toolbar-registrations-today-pending',
1232
-                'parent' => 'espresso-toolbar-registrations-today',
1233
-                'title'  => __('Pending', 'event_espresso'),
1234
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1235
-                    'action'     => 'default',
1236
-                    'status'     => 'today',
1237
-                    'reg_status' => EEM_Registration::status_id_pending_payment,
1238
-                ), $reg_admin_url),
1239
-                'meta'   => array(
1240
-                    'title'  => __('Pending Payment', 'event_espresso'),
1241
-                    'target' => '',
1242
-                    'class'  => $menu_class,
1243
-                ),
1244
-            ));
1245
-        }
1246
-        //Registration Overview Today Incomplete
1247
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1248
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1249
-        ) {
1250
-            $admin_bar->add_menu(array(
1251
-                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1252
-                'parent' => 'espresso-toolbar-registrations-today',
1253
-                'title'  => __('Not Approved', 'event_espresso'),
1254
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1255
-                    'action'      => 'default',
1256
-                    'status'      => 'today',
1257
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1258
-                ), $reg_admin_url),
1259
-                'meta'   => array(
1260
-                    'title'  => __('Not Approved', 'event_espresso'),
1261
-                    'target' => '',
1262
-                    'class'  => $menu_class,
1263
-                ),
1264
-            ));
1265
-        }
1266
-        //Registration Overview Today Incomplete
1267
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1268
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1269
-        ) {
1270
-            $admin_bar->add_menu(array(
1271
-                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1272
-                'parent' => 'espresso-toolbar-registrations-today',
1273
-                'title'  => __('Cancelled', 'event_espresso'),
1274
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1275
-                    'action'      => 'default',
1276
-                    'status'      => 'today',
1277
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1278
-                ), $reg_admin_url),
1279
-                'meta'   => array(
1280
-                    'title'  => __('Cancelled', 'event_espresso'),
1281
-                    'target' => '',
1282
-                    'class'  => $menu_class,
1283
-                ),
1284
-            ));
1285
-        }
1286
-        //Registration Overview This Month
1287
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1288
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1289
-        ) {
1290
-            $admin_bar->add_menu(array(
1291
-                'id'     => 'espresso-toolbar-registrations-month',
1292
-                'parent' => 'espresso-toolbar-registrations',
1293
-                'title'  => __('This Month', 'event_espresso'),
1294
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1295
-                    $reg_admin_url),
1296
-                'meta'   => array(
1297
-                    'title'  => __('This Month', 'event_espresso'),
1298
-                    'target' => '',
1299
-                    'class'  => $menu_class,
1300
-                ),
1301
-            ));
1302
-        }
1303
-        //Registration Overview This Month Approved
1304
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1305
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1306
-        ) {
1307
-            $admin_bar->add_menu(array(
1308
-                'id'     => 'espresso-toolbar-registrations-month-approved',
1309
-                'parent' => 'espresso-toolbar-registrations-month',
1310
-                'title'  => __('Approved', 'event_espresso'),
1311
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1312
-                    'action'      => 'default',
1313
-                    'status'      => 'month',
1314
-                    '_reg_status' => EEM_Registration::status_id_approved,
1315
-                ), $reg_admin_url),
1316
-                'meta'   => array(
1317
-                    'title'  => __('Approved', 'event_espresso'),
1318
-                    'target' => '',
1319
-                    'class'  => $menu_class,
1320
-                ),
1321
-            ));
1322
-        }
1323
-        //Registration Overview This Month Pending
1324
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1325
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1326
-        ) {
1327
-            $admin_bar->add_menu(array(
1328
-                'id'     => 'espresso-toolbar-registrations-month-pending',
1329
-                'parent' => 'espresso-toolbar-registrations-month',
1330
-                'title'  => __('Pending', 'event_espresso'),
1331
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1332
-                    'action'      => 'default',
1333
-                    'status'      => 'month',
1334
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1335
-                ), $reg_admin_url),
1336
-                'meta'   => array(
1337
-                    'title'  => __('Pending', 'event_espresso'),
1338
-                    'target' => '',
1339
-                    'class'  => $menu_class,
1340
-                ),
1341
-            ));
1342
-        }
1343
-        //Registration Overview This Month Not Approved
1344
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1345
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1346
-        ) {
1347
-            $admin_bar->add_menu(array(
1348
-                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1349
-                'parent' => 'espresso-toolbar-registrations-month',
1350
-                'title'  => __('Not Approved', 'event_espresso'),
1351
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1352
-                    'action'      => 'default',
1353
-                    'status'      => 'month',
1354
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1355
-                ), $reg_admin_url),
1356
-                'meta'   => array(
1357
-                    'title'  => __('Not Approved', 'event_espresso'),
1358
-                    'target' => '',
1359
-                    'class'  => $menu_class,
1360
-                ),
1361
-            ));
1362
-        }
1363
-        //Registration Overview This Month Cancelled
1364
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1365
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1366
-        ) {
1367
-            $admin_bar->add_menu(array(
1368
-                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1369
-                'parent' => 'espresso-toolbar-registrations-month',
1370
-                'title'  => __('Cancelled', 'event_espresso'),
1371
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1372
-                    'action'      => 'default',
1373
-                    'status'      => 'month',
1374
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1375
-                ), $reg_admin_url),
1376
-                'meta'   => array(
1377
-                    'title'  => __('Cancelled', 'event_espresso'),
1378
-                    'target' => '',
1379
-                    'class'  => $menu_class,
1380
-                ),
1381
-            ));
1382
-        }
1383
-        //Extensions & Services
1384
-        if ($this->registry->CAP->current_user_can('ee_read_ee',
1385
-            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1386
-        ) {
1387
-            $admin_bar->add_menu(array(
1388
-                'id'     => 'espresso-toolbar-extensions-and-services',
1389
-                'parent' => 'espresso-toolbar',
1390
-                'title'  => __('Extensions & Services', 'event_espresso'),
1391
-                'href'   => $extensions_admin_url,
1392
-                'meta'   => array(
1393
-                    'title'  => __('Extensions & Services', 'event_espresso'),
1394
-                    'target' => '',
1395
-                    'class'  => $menu_class,
1396
-                ),
1397
-            ));
1398
-        }
1399
-    }
1400
-
1401
-
1402
-
1403
-    /**
1404
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1405
-     * never returned with the function.
1406
-     *
1407
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1408
-     * @return array
1409
-     */
1410
-    public function remove_pages_from_wp_list_pages($exclude_array)
1411
-    {
1412
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1413
-    }
1414
-
1415
-
1416
-
1417
-
1418
-
1419
-
1420
-    /***********************************************        WP_ENQUEUE_SCRIPTS HOOK         ***********************************************/
1421
-    /**
1422
-     *    wp_enqueue_scripts
1423
-     *
1424
-     * @access    public
1425
-     * @return    void
1426
-     */
1427
-    public function wp_enqueue_scripts()
1428
-    {
1429
-        // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' );
1430
-        if (apply_filters('FHEE_load_EE_System_scripts', true)) {
1431
-            // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1432
-            if (apply_filters('FHEE_load_jquery_validate', false)) {
1433
-                // register jQuery Validate and additional methods
1434
-                wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
1435
-                    array('jquery'), '1.15.0', true);
1436
-                wp_register_script('jquery-validate-extra-methods',
1437
-                    EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
1438
-                    array('jquery', 'jquery-validate'), '1.15.0', true);
1439
-            }
1440
-        }
1441
-    }
960
+	}
961
+
962
+
963
+
964
+	/**
965
+	 * do_not_cache
966
+	 * sets no cache headers and defines no cache constants for WP plugins
967
+	 *
968
+	 * @access public
969
+	 * @return void
970
+	 */
971
+	public static function do_not_cache()
972
+	{
973
+		// set no cache constants
974
+		if ( ! defined('DONOTCACHEPAGE')) {
975
+			define('DONOTCACHEPAGE', true);
976
+		}
977
+		if ( ! defined('DONOTCACHCEOBJECT')) {
978
+			define('DONOTCACHCEOBJECT', true);
979
+		}
980
+		if ( ! defined('DONOTCACHEDB')) {
981
+			define('DONOTCACHEDB', true);
982
+		}
983
+		// add no cache headers
984
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
985
+		// plus a little extra for nginx and Google Chrome
986
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
987
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
988
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
989
+	}
990
+
991
+
992
+
993
+	/**
994
+	 *    extra_nocache_headers
995
+	 *
996
+	 * @access    public
997
+	 * @param $headers
998
+	 * @return    array
999
+	 */
1000
+	public static function extra_nocache_headers($headers)
1001
+	{
1002
+		// for NGINX
1003
+		$headers['X-Accel-Expires'] = 0;
1004
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1005
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1006
+		return $headers;
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 *    nocache_headers
1013
+	 *
1014
+	 * @access    public
1015
+	 * @return    void
1016
+	 */
1017
+	public static function nocache_headers()
1018
+	{
1019
+		nocache_headers();
1020
+	}
1021
+
1022
+
1023
+
1024
+	/**
1025
+	 *    espresso_toolbar_items
1026
+	 *
1027
+	 * @access public
1028
+	 * @param  WP_Admin_Bar $admin_bar
1029
+	 * @return void
1030
+	 */
1031
+	public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1032
+	{
1033
+		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
1034
+		if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1035
+			|| defined('DOING_AJAX')
1036
+			|| ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1037
+		) {
1038
+			return;
1039
+		}
1040
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1041
+		$menu_class = 'espresso_menu_item_class';
1042
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1043
+		//because they're only defined in each of their respective constructors
1044
+		//and this might be a frontend request, in which case they aren't available
1045
+		$events_admin_url = admin_url("admin.php?page=espresso_events");
1046
+		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1047
+		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1048
+		//Top Level
1049
+		$admin_bar->add_menu(array(
1050
+			'id'    => 'espresso-toolbar',
1051
+			'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1052
+					   . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1053
+					   . '</span>',
1054
+			'href'  => $events_admin_url,
1055
+			'meta'  => array(
1056
+				'title' => __('Event Espresso', 'event_espresso'),
1057
+				'class' => $menu_class . 'first',
1058
+			),
1059
+		));
1060
+		//Events
1061
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1062
+			$admin_bar->add_menu(array(
1063
+				'id'     => 'espresso-toolbar-events',
1064
+				'parent' => 'espresso-toolbar',
1065
+				'title'  => __('Events', 'event_espresso'),
1066
+				'href'   => $events_admin_url,
1067
+				'meta'   => array(
1068
+					'title'  => __('Events', 'event_espresso'),
1069
+					'target' => '',
1070
+					'class'  => $menu_class,
1071
+				),
1072
+			));
1073
+		}
1074
+		if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1075
+			//Events Add New
1076
+			$admin_bar->add_menu(array(
1077
+				'id'     => 'espresso-toolbar-events-new',
1078
+				'parent' => 'espresso-toolbar-events',
1079
+				'title'  => __('Add New', 'event_espresso'),
1080
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1081
+				'meta'   => array(
1082
+					'title'  => __('Add New', 'event_espresso'),
1083
+					'target' => '',
1084
+					'class'  => $menu_class,
1085
+				),
1086
+			));
1087
+		}
1088
+		if (is_single() && (get_post_type() == 'espresso_events')) {
1089
+			//Current post
1090
+			global $post;
1091
+			if ($this->registry->CAP->current_user_can('ee_edit_event',
1092
+				'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1093
+			) {
1094
+				//Events Edit Current Event
1095
+				$admin_bar->add_menu(array(
1096
+					'id'     => 'espresso-toolbar-events-edit',
1097
+					'parent' => 'espresso-toolbar-events',
1098
+					'title'  => __('Edit Event', 'event_espresso'),
1099
+					'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1100
+						$events_admin_url),
1101
+					'meta'   => array(
1102
+						'title'  => __('Edit Event', 'event_espresso'),
1103
+						'target' => '',
1104
+						'class'  => $menu_class,
1105
+					),
1106
+				));
1107
+			}
1108
+		}
1109
+		//Events View
1110
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1111
+			'ee_admin_bar_menu_espresso-toolbar-events-view')
1112
+		) {
1113
+			$admin_bar->add_menu(array(
1114
+				'id'     => 'espresso-toolbar-events-view',
1115
+				'parent' => 'espresso-toolbar-events',
1116
+				'title'  => __('View', 'event_espresso'),
1117
+				'href'   => $events_admin_url,
1118
+				'meta'   => array(
1119
+					'title'  => __('View', 'event_espresso'),
1120
+					'target' => '',
1121
+					'class'  => $menu_class,
1122
+				),
1123
+			));
1124
+		}
1125
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1126
+			//Events View All
1127
+			$admin_bar->add_menu(array(
1128
+				'id'     => 'espresso-toolbar-events-all',
1129
+				'parent' => 'espresso-toolbar-events-view',
1130
+				'title'  => __('All', 'event_espresso'),
1131
+				'href'   => $events_admin_url,
1132
+				'meta'   => array(
1133
+					'title'  => __('All', 'event_espresso'),
1134
+					'target' => '',
1135
+					'class'  => $menu_class,
1136
+				),
1137
+			));
1138
+		}
1139
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1140
+			'ee_admin_bar_menu_espresso-toolbar-events-today')
1141
+		) {
1142
+			//Events View Today
1143
+			$admin_bar->add_menu(array(
1144
+				'id'     => 'espresso-toolbar-events-today',
1145
+				'parent' => 'espresso-toolbar-events-view',
1146
+				'title'  => __('Today', 'event_espresso'),
1147
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1148
+					$events_admin_url),
1149
+				'meta'   => array(
1150
+					'title'  => __('Today', 'event_espresso'),
1151
+					'target' => '',
1152
+					'class'  => $menu_class,
1153
+				),
1154
+			));
1155
+		}
1156
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1157
+			'ee_admin_bar_menu_espresso-toolbar-events-month')
1158
+		) {
1159
+			//Events View This Month
1160
+			$admin_bar->add_menu(array(
1161
+				'id'     => 'espresso-toolbar-events-month',
1162
+				'parent' => 'espresso-toolbar-events-view',
1163
+				'title'  => __('This Month', 'event_espresso'),
1164
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1165
+					$events_admin_url),
1166
+				'meta'   => array(
1167
+					'title'  => __('This Month', 'event_espresso'),
1168
+					'target' => '',
1169
+					'class'  => $menu_class,
1170
+				),
1171
+			));
1172
+		}
1173
+		//Registration Overview
1174
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1175
+			'ee_admin_bar_menu_espresso-toolbar-registrations')
1176
+		) {
1177
+			$admin_bar->add_menu(array(
1178
+				'id'     => 'espresso-toolbar-registrations',
1179
+				'parent' => 'espresso-toolbar',
1180
+				'title'  => __('Registrations', 'event_espresso'),
1181
+				'href'   => $reg_admin_url,
1182
+				'meta'   => array(
1183
+					'title'  => __('Registrations', 'event_espresso'),
1184
+					'target' => '',
1185
+					'class'  => $menu_class,
1186
+				),
1187
+			));
1188
+		}
1189
+		//Registration Overview Today
1190
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1191
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1192
+		) {
1193
+			$admin_bar->add_menu(array(
1194
+				'id'     => 'espresso-toolbar-registrations-today',
1195
+				'parent' => 'espresso-toolbar-registrations',
1196
+				'title'  => __('Today', 'event_espresso'),
1197
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1198
+					$reg_admin_url),
1199
+				'meta'   => array(
1200
+					'title'  => __('Today', 'event_espresso'),
1201
+					'target' => '',
1202
+					'class'  => $menu_class,
1203
+				),
1204
+			));
1205
+		}
1206
+		//Registration Overview Today Completed
1207
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1208
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1209
+		) {
1210
+			$admin_bar->add_menu(array(
1211
+				'id'     => 'espresso-toolbar-registrations-today-approved',
1212
+				'parent' => 'espresso-toolbar-registrations-today',
1213
+				'title'  => __('Approved', 'event_espresso'),
1214
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1215
+					'action'      => 'default',
1216
+					'status'      => 'today',
1217
+					'_reg_status' => EEM_Registration::status_id_approved,
1218
+				), $reg_admin_url),
1219
+				'meta'   => array(
1220
+					'title'  => __('Approved', 'event_espresso'),
1221
+					'target' => '',
1222
+					'class'  => $menu_class,
1223
+				),
1224
+			));
1225
+		}
1226
+		//Registration Overview Today Pending\
1227
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1228
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1229
+		) {
1230
+			$admin_bar->add_menu(array(
1231
+				'id'     => 'espresso-toolbar-registrations-today-pending',
1232
+				'parent' => 'espresso-toolbar-registrations-today',
1233
+				'title'  => __('Pending', 'event_espresso'),
1234
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1235
+					'action'     => 'default',
1236
+					'status'     => 'today',
1237
+					'reg_status' => EEM_Registration::status_id_pending_payment,
1238
+				), $reg_admin_url),
1239
+				'meta'   => array(
1240
+					'title'  => __('Pending Payment', 'event_espresso'),
1241
+					'target' => '',
1242
+					'class'  => $menu_class,
1243
+				),
1244
+			));
1245
+		}
1246
+		//Registration Overview Today Incomplete
1247
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1248
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1249
+		) {
1250
+			$admin_bar->add_menu(array(
1251
+				'id'     => 'espresso-toolbar-registrations-today-not-approved',
1252
+				'parent' => 'espresso-toolbar-registrations-today',
1253
+				'title'  => __('Not Approved', 'event_espresso'),
1254
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1255
+					'action'      => 'default',
1256
+					'status'      => 'today',
1257
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1258
+				), $reg_admin_url),
1259
+				'meta'   => array(
1260
+					'title'  => __('Not Approved', 'event_espresso'),
1261
+					'target' => '',
1262
+					'class'  => $menu_class,
1263
+				),
1264
+			));
1265
+		}
1266
+		//Registration Overview Today Incomplete
1267
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1268
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1269
+		) {
1270
+			$admin_bar->add_menu(array(
1271
+				'id'     => 'espresso-toolbar-registrations-today-cancelled',
1272
+				'parent' => 'espresso-toolbar-registrations-today',
1273
+				'title'  => __('Cancelled', 'event_espresso'),
1274
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1275
+					'action'      => 'default',
1276
+					'status'      => 'today',
1277
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1278
+				), $reg_admin_url),
1279
+				'meta'   => array(
1280
+					'title'  => __('Cancelled', 'event_espresso'),
1281
+					'target' => '',
1282
+					'class'  => $menu_class,
1283
+				),
1284
+			));
1285
+		}
1286
+		//Registration Overview This Month
1287
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1288
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1289
+		) {
1290
+			$admin_bar->add_menu(array(
1291
+				'id'     => 'espresso-toolbar-registrations-month',
1292
+				'parent' => 'espresso-toolbar-registrations',
1293
+				'title'  => __('This Month', 'event_espresso'),
1294
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1295
+					$reg_admin_url),
1296
+				'meta'   => array(
1297
+					'title'  => __('This Month', 'event_espresso'),
1298
+					'target' => '',
1299
+					'class'  => $menu_class,
1300
+				),
1301
+			));
1302
+		}
1303
+		//Registration Overview This Month Approved
1304
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1305
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1306
+		) {
1307
+			$admin_bar->add_menu(array(
1308
+				'id'     => 'espresso-toolbar-registrations-month-approved',
1309
+				'parent' => 'espresso-toolbar-registrations-month',
1310
+				'title'  => __('Approved', 'event_espresso'),
1311
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1312
+					'action'      => 'default',
1313
+					'status'      => 'month',
1314
+					'_reg_status' => EEM_Registration::status_id_approved,
1315
+				), $reg_admin_url),
1316
+				'meta'   => array(
1317
+					'title'  => __('Approved', 'event_espresso'),
1318
+					'target' => '',
1319
+					'class'  => $menu_class,
1320
+				),
1321
+			));
1322
+		}
1323
+		//Registration Overview This Month Pending
1324
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1325
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1326
+		) {
1327
+			$admin_bar->add_menu(array(
1328
+				'id'     => 'espresso-toolbar-registrations-month-pending',
1329
+				'parent' => 'espresso-toolbar-registrations-month',
1330
+				'title'  => __('Pending', 'event_espresso'),
1331
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1332
+					'action'      => 'default',
1333
+					'status'      => 'month',
1334
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1335
+				), $reg_admin_url),
1336
+				'meta'   => array(
1337
+					'title'  => __('Pending', 'event_espresso'),
1338
+					'target' => '',
1339
+					'class'  => $menu_class,
1340
+				),
1341
+			));
1342
+		}
1343
+		//Registration Overview This Month Not Approved
1344
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1345
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1346
+		) {
1347
+			$admin_bar->add_menu(array(
1348
+				'id'     => 'espresso-toolbar-registrations-month-not-approved',
1349
+				'parent' => 'espresso-toolbar-registrations-month',
1350
+				'title'  => __('Not Approved', 'event_espresso'),
1351
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1352
+					'action'      => 'default',
1353
+					'status'      => 'month',
1354
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1355
+				), $reg_admin_url),
1356
+				'meta'   => array(
1357
+					'title'  => __('Not Approved', 'event_espresso'),
1358
+					'target' => '',
1359
+					'class'  => $menu_class,
1360
+				),
1361
+			));
1362
+		}
1363
+		//Registration Overview This Month Cancelled
1364
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1365
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1366
+		) {
1367
+			$admin_bar->add_menu(array(
1368
+				'id'     => 'espresso-toolbar-registrations-month-cancelled',
1369
+				'parent' => 'espresso-toolbar-registrations-month',
1370
+				'title'  => __('Cancelled', 'event_espresso'),
1371
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1372
+					'action'      => 'default',
1373
+					'status'      => 'month',
1374
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1375
+				), $reg_admin_url),
1376
+				'meta'   => array(
1377
+					'title'  => __('Cancelled', 'event_espresso'),
1378
+					'target' => '',
1379
+					'class'  => $menu_class,
1380
+				),
1381
+			));
1382
+		}
1383
+		//Extensions & Services
1384
+		if ($this->registry->CAP->current_user_can('ee_read_ee',
1385
+			'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1386
+		) {
1387
+			$admin_bar->add_menu(array(
1388
+				'id'     => 'espresso-toolbar-extensions-and-services',
1389
+				'parent' => 'espresso-toolbar',
1390
+				'title'  => __('Extensions & Services', 'event_espresso'),
1391
+				'href'   => $extensions_admin_url,
1392
+				'meta'   => array(
1393
+					'title'  => __('Extensions & Services', 'event_espresso'),
1394
+					'target' => '',
1395
+					'class'  => $menu_class,
1396
+				),
1397
+			));
1398
+		}
1399
+	}
1400
+
1401
+
1402
+
1403
+	/**
1404
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1405
+	 * never returned with the function.
1406
+	 *
1407
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1408
+	 * @return array
1409
+	 */
1410
+	public function remove_pages_from_wp_list_pages($exclude_array)
1411
+	{
1412
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1413
+	}
1414
+
1415
+
1416
+
1417
+
1418
+
1419
+
1420
+	/***********************************************        WP_ENQUEUE_SCRIPTS HOOK         ***********************************************/
1421
+	/**
1422
+	 *    wp_enqueue_scripts
1423
+	 *
1424
+	 * @access    public
1425
+	 * @return    void
1426
+	 */
1427
+	public function wp_enqueue_scripts()
1428
+	{
1429
+		// unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' );
1430
+		if (apply_filters('FHEE_load_EE_System_scripts', true)) {
1431
+			// jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1432
+			if (apply_filters('FHEE_load_jquery_validate', false)) {
1433
+				// register jQuery Validate and additional methods
1434
+				wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
1435
+					array('jquery'), '1.15.0', true);
1436
+				wp_register_script('jquery-validate-extra-methods',
1437
+					EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
1438
+					array('jquery', 'jquery-validate'), '1.15.0', true);
1439
+			}
1440
+		}
1441
+	}
1442 1442
 
1443 1443
 
1444 1444
 
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_Checkout.class.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2 2
  /**
3
- *
4
- * Class EE_Checkout
5
- *
6
- * Description
7
- *
8
- * @package 			Event Espresso
9
- * @subpackage    core
10
- * @author				Brent Christensen
11
- * @since 				4.5.0
12
- *
13
- */
3
+  *
4
+  * Class EE_Checkout
5
+  *
6
+  * Description
7
+  *
8
+  * @package 			Event Espresso
9
+  * @subpackage    core
10
+  * @author				Brent Christensen
11
+  * @since 				4.5.0
12
+  *
13
+  */
14 14
 class EE_Checkout {
15 15
 
16 16
 	/**
@@ -804,10 +804,10 @@  discard block
 block discarded – undo
804 804
 	 */
805 805
 	public function visit_allows_processing_of_this_registration( EE_Registration $registration ) {
806 806
 		return ! $this->revisit
807
-		       || $this->primary_revisit
808
-		       || (
809
-			       $this->revisit && $this->reg_url_link === $registration->reg_url_link()
810
-		       )
807
+			   || $this->primary_revisit
808
+			   || (
809
+				   $this->revisit && $this->reg_url_link === $registration->reg_url_link()
810
+			   )
811 811
 			? true
812 812
 			: false;
813 813
 	}
@@ -1199,16 +1199,16 @@  discard block
 block discarded – undo
1199 1199
 	 * @return array
1200 1200
 	 * @throws \EE_Error
1201 1201
 	 */
1202
-    public function __sleep()
1203
-    {
1204
-	    if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) {
1205
-		    $this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1206
-	    }        // remove the reg form and the checkout
1207
-	    if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1208
-		    $this->transaction = $this->transaction->ID();
1209
-	    }        // remove the reg form and the checkout
1210
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) );
1211
-    }
1202
+	public function __sleep()
1203
+	{
1204
+		if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) {
1205
+			$this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1206
+		}        // remove the reg form and the checkout
1207
+		if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1208
+			$this->transaction = $this->transaction->ID();
1209
+		}        // remove the reg form and the checkout
1210
+		return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) );
1211
+	}
1212 1212
 
1213 1213
 
1214 1214
 	/**
Please login to merge, or discard this patch.
Spacing   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
 		$this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url();
248 248
 		$this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url();
249 249
 		$this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url();
250
-		$this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE );
250
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', TRUE);
251 251
 		$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax;
252
-		$this->reg_cache_where_params = array( 'order_by' => array( 'REG_count' => 'ASC' ));
252
+		$this->reg_cache_where_params = array('order_by' => array('REG_count' => 'ASC'));
253 253
 	}
254 254
 
255 255
 
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
 	 * @return boolean
261 261
 	 */
262 262
 	public function any_reg_status_updated() {
263
-		foreach ( $this->reg_status_updated as $reg_status ) {
264
-			if ( $reg_status ) {
263
+		foreach ($this->reg_status_updated as $reg_status) {
264
+			if ($reg_status) {
265 265
 				return true;
266 266
 			}
267 267
 		}
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 	 * @param $REG_ID
275 275
 	 * @return boolean
276 276
 	 */
277
-	public function reg_status_updated( $REG_ID ) {
278
-		return isset( $this->reg_status_updated[ $REG_ID ] ) ? $this->reg_status_updated[ $REG_ID ] : false;
277
+	public function reg_status_updated($REG_ID) {
278
+		return isset($this->reg_status_updated[$REG_ID]) ? $this->reg_status_updated[$REG_ID] : false;
279 279
 	}
280 280
 
281 281
 
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param $REG_ID
285 285
 	 * @param $reg_status
286 286
 	 */
287
-	public function set_reg_status_updated( $REG_ID, $reg_status ) {
288
-		$this->reg_status_updated[ $REG_ID ] = filter_var( $reg_status, FILTER_VALIDATE_BOOLEAN );
287
+	public function set_reg_status_updated($REG_ID, $reg_status) {
288
+		$this->reg_status_updated[$REG_ID] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
289 289
 	}
290 290
 
291 291
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 	 * can ONLY be set by the  Finalize_Registration reg step
307 307
 	 */
308 308
 	public function set_exit_spco() {
309
-		if ( $this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) {
309
+		if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
310 310
 			$this->exit_spco = true;
311 311
 		}
312 312
 	}
@@ -323,12 +323,12 @@  discard block
 block discarded – undo
323 323
 	 */
324 324
 	public function reset_for_current_request() {
325 325
 		$this->process_form_submission = FALSE;
326
-		$this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', true );
326
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
327 327
 		$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax;
328 328
 		$this->continue_reg = true;
329 329
 		$this->redirect = false;
330 330
 		// don't reset the cached redirect form if we're about to be asked to display it !!!
331
-		if ( EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ) !== 'redirect_form' ) {
331
+		if (EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step') !== 'redirect_form') {
332 332
 			$this->redirect_form = '';
333 333
 		}
334 334
 		$this->redirect_url = '';
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @param EE_SPCO_Reg_Step $reg_step_obj
346 346
 	 * @return    void
347 347
 	 */
348
-	public function add_reg_step( EE_SPCO_Reg_Step $reg_step_obj ) {
349
-		$this->reg_steps[ $reg_step_obj->slug()  ] = $reg_step_obj;
348
+	public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) {
349
+		$this->reg_steps[$reg_step_obj->slug()] = $reg_step_obj;
350 350
 	}
351 351
 
352 352
 
@@ -362,22 +362,22 @@  discard block
 block discarded – undo
362 362
 	 * @return    void
363 363
 	 * @throws \EE_Error
364 364
 	 */
365
-	public function skip_reg_step( $reg_step_slug = '' ) {
366
-		$step_to_skip = $this->find_reg_step( $reg_step_slug );
367
-		if ( $step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step() ) {
368
-			$step_to_skip->set_is_current_step( false );
365
+	public function skip_reg_step($reg_step_slug = '') {
366
+		$step_to_skip = $this->find_reg_step($reg_step_slug);
367
+		if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) {
368
+			$step_to_skip->set_is_current_step(false);
369 369
 			$step_to_skip->set_completed();
370 370
 			// advance to the next step
371
-			$this->set_current_step( $this->next_step->slug() );
371
+			$this->set_current_step($this->next_step->slug());
372 372
 			// also reset the step param in the request in case any other code references that directly
373
-			EE_Registry::instance()->REQ->set( 'step', $this->current_step->slug() );
373
+			EE_Registry::instance()->REQ->set('step', $this->current_step->slug());
374 374
 			// since we are skipping a step and setting the current step to be what was previously the next step,
375 375
 			// we need to check that the next step is now correct, and not still set to the current step.
376
-			if ( $this->current_step->slug() === $this->next_step->slug() ) {
376
+			if ($this->current_step->slug() === $this->next_step->slug()) {
377 377
 				// correctly setup the next step
378 378
 				$this->set_next_step();
379 379
 			}
380
-			$this->set_reg_step_initiated( $this->current_step );
380
+			$this->set_reg_step_initiated($this->current_step);
381 381
 		}
382 382
 	}
383 383
 
@@ -391,14 +391,14 @@  discard block
 block discarded – undo
391 391
 	 * @param bool   $reset whether to reset reg steps after removal
392 392
 	 * @throws EE_Error
393 393
 	 */
394
-	public function remove_reg_step( $reg_step_slug = '', $reset = true ) {
395
-		unset( $this->reg_steps[ $reg_step_slug  ] );
396
-		if ( $this->transaction instanceof EE_Transaction ) {
394
+	public function remove_reg_step($reg_step_slug = '', $reset = true) {
395
+		unset($this->reg_steps[$reg_step_slug]);
396
+		if ($this->transaction instanceof EE_Transaction) {
397 397
 			// now remove reg step from TXN and save
398
-			$this->transaction->remove_reg_step( $reg_step_slug );
398
+			$this->transaction->remove_reg_step($reg_step_slug);
399 399
 			$this->transaction->save();
400 400
 		}
401
-		if ( $reset ) {
401
+		if ($reset) {
402 402
 			$this->reset_reg_steps();
403 403
 		}
404 404
 	}
@@ -413,9 +413,9 @@  discard block
 block discarded – undo
413 413
 	 * @param int    $order
414 414
 	 * @return    void
415 415
 	 */
416
-	public function set_reg_step_order( $reg_step_slug = '', $order = 100 ) {
417
-		if ( isset( $this->reg_steps[ $reg_step_slug  ] )) {
418
-			$this->reg_steps[ $reg_step_slug ]->set_order( $order );
416
+	public function set_reg_step_order($reg_step_slug = '', $order = 100) {
417
+		if (isset($this->reg_steps[$reg_step_slug])) {
418
+			$this->reg_steps[$reg_step_slug]->set_order($order);
419 419
 		}
420 420
 	}
421 421
 
@@ -428,25 +428,25 @@  discard block
 block discarded – undo
428 428
 	 * @param string $current_step
429 429
 	 * @return    void
430 430
 	 */
431
-	public function set_current_step( $current_step ) {
431
+	public function set_current_step($current_step) {
432 432
 		// grab what step we're on
433
-		$this->current_step = isset( $this->reg_steps[ $current_step ] ) ? $this->reg_steps[ $current_step ] : reset( $this->reg_steps );
433
+		$this->current_step = isset($this->reg_steps[$current_step]) ? $this->reg_steps[$current_step] : reset($this->reg_steps);
434 434
 		// verify instance
435
-		if ( $this->current_step instanceof EE_SPCO_Reg_Step ) {
435
+		if ($this->current_step instanceof EE_SPCO_Reg_Step) {
436 436
 			// we don't want to repeat completed steps if this is the first time through SPCO
437
-			if ( $this->continue_reg && ! $this->revisit && $this->current_step->completed() ) {
437
+			if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) {
438 438
 				// so advance to the next step
439 439
 				$this->set_next_step();
440
-				if ( $this->next_step instanceof EE_SPCO_Reg_Step ) {
440
+				if ($this->next_step instanceof EE_SPCO_Reg_Step) {
441 441
 					// and attempt to set it as the current step
442
-					$this->set_current_step( $this->next_step->slug() );
442
+					$this->set_current_step($this->next_step->slug());
443 443
 				}
444 444
 				return;
445 445
 			}
446
-			$this->current_step->set_is_current_step( TRUE );
446
+			$this->current_step->set_is_current_step(TRUE);
447 447
 		} else {
448 448
 			EE_Error::add_error(
449
-				__( 'The current step could not be set.', 'event_espresso' ),
449
+				__('The current step could not be set.', 'event_espresso'),
450 450
 				__FILE__, __FUNCTION__, __LINE__
451 451
 			);
452 452
 		}
@@ -463,20 +463,20 @@  discard block
 block discarded – undo
463 463
 	 */
464 464
 	public function set_next_step() {
465 465
 		// set pointer to start of array
466
-		reset( $this->reg_steps );
466
+		reset($this->reg_steps);
467 467
 		// if there is more than one step
468
-		if ( count( $this->reg_steps ) > 1 ) {
468
+		if (count($this->reg_steps) > 1) {
469 469
 			// advance to the current step and set pointer
470
-			while ( key( $this->reg_steps ) !== $this->current_step->slug() && key( $this->reg_steps ) !== '' ) {
471
-				next( $this->reg_steps );
470
+			while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') {
471
+				next($this->reg_steps);
472 472
 			}
473 473
 		}
474 474
 		// advance one more spot ( if it exists )
475
-		$this->next_step = next( $this->reg_steps );
475
+		$this->next_step = next($this->reg_steps);
476 476
 		// verify instance
477
-		$this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step  : NULL;
477
+		$this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL;
478 478
 		// then back to current step to reset
479
-		prev( $this->reg_steps );
479
+		prev($this->reg_steps);
480 480
 	}
481 481
 
482 482
 
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
 	 *  @return 	EE_SPCO_Reg_Step | null
491 491
 	 */
492 492
 	public function get_next_reg_step() {
493
-		$next = next( $this->reg_steps );
494
-		prev( $this->reg_steps );
493
+		$next = next($this->reg_steps);
494
+		prev($this->reg_steps);
495 495
 		return $next instanceof EE_SPCO_Reg_Step ? $next : null;
496 496
 	}
497 497
 
@@ -506,8 +506,8 @@  discard block
 block discarded – undo
506 506
 	 *  @return 	EE_SPCO_Reg_Step | null
507 507
 	 */
508 508
 	public function get_prev_reg_step() {
509
-		$prev = prev( $this->reg_steps );
510
-		next( $this->reg_steps );
509
+		$prev = prev($this->reg_steps);
510
+		next($this->reg_steps);
511 511
 		return $prev instanceof EE_SPCO_Reg_Step ? $prev : null;
512 512
 	}
513 513
 
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
 	 * @return void
521 521
 	 */
522 522
 	public function sort_reg_steps() {
523
-		$reg_step_sorting_callback = apply_filters( 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback' );
524
-		uasort( $this->reg_steps, array( $this, $reg_step_sorting_callback ));
523
+		$reg_step_sorting_callback = apply_filters('FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback');
524
+		uasort($this->reg_steps, array($this, $reg_step_sorting_callback));
525 525
 	}
526 526
 
527 527
 
@@ -534,19 +534,19 @@  discard block
 block discarded – undo
534 534
 	 * @param string $reg_step_slug
535 535
 	 * @return EE_SPCO_Reg_Step|null
536 536
 	 */
537
-	public function find_reg_step( $reg_step_slug = '' ) {
538
-		if ( ! empty( $reg_step_slug ) ) {
537
+	public function find_reg_step($reg_step_slug = '') {
538
+		if ( ! empty($reg_step_slug)) {
539 539
 			// copy reg step array
540 540
 			$reg_steps = $this->reg_steps;
541 541
 			// set pointer to start of array
542
-			reset( $reg_steps );
542
+			reset($reg_steps);
543 543
 			// if there is more than one step
544
-			if ( count( $reg_steps ) > 1 ) {
544
+			if (count($reg_steps) > 1) {
545 545
 				// advance to the current step and set pointer
546
-				while ( key( $reg_steps ) !== $reg_step_slug && key( $reg_steps ) !== '' ) {
547
-					next( $reg_steps );
546
+				while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') {
547
+					next($reg_steps);
548 548
 				}
549
-				return current( $reg_steps );
549
+				return current($reg_steps);
550 550
 			}
551 551
 		}
552 552
 		return null;
@@ -562,17 +562,17 @@  discard block
 block discarded – undo
562 562
 	 * @param EE_SPCO_Reg_Step $reg_step_B
563 563
 	 * @return int
564 564
 	 */
565
-	public function reg_step_sorting_callback( EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B ) {
565
+	public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B) {
566 566
 		// send finalize_registration step to the end of the array
567
-		if ( $reg_step_A->slug() === 'finalize_registration' ) {
567
+		if ($reg_step_A->slug() === 'finalize_registration') {
568 568
 			return 1;
569
-		} else if ( $reg_step_B->slug() === 'finalize_registration' ) {
569
+		} else if ($reg_step_B->slug() === 'finalize_registration') {
570 570
 			return -1;
571 571
 		}
572
-		if ( $reg_step_A->order() === $reg_step_B->order() ) {
572
+		if ($reg_step_A->order() === $reg_step_B->order()) {
573 573
 			return 0;
574 574
 		}
575
-		return ( $reg_step_A->order() > $reg_step_B->order() ) ? 1 : -1;
575
+		return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1;
576 576
 	}
577 577
 
578 578
 
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 	 * @param    EE_SPCO_Reg_Step $reg_step
585 585
 	 * @throws \EE_Error
586 586
 	 */
587
-	public function set_reg_step_initiated( EE_SPCO_Reg_Step $reg_step ) {
587
+	public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step) {
588 588
 		// call set_reg_step_initiated ???
589 589
 		if (
590 590
 			// first time visiting SPCO ?
@@ -597,11 +597,11 @@  discard block
 block discarded – undo
597 597
 			)
598 598
 		) {
599 599
 			// set the start time for this reg step
600
-			if ( ! $this->transaction->set_reg_step_initiated( $reg_step->slug() ) ) {
601
-				if ( WP_DEBUG ) {
600
+			if ( ! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
601
+				if (WP_DEBUG) {
602 602
 					EE_Error::add_error(
603 603
 						sprintf(
604
-							__( 'The "%1$s" registration step was not initialized properly.', 'event_espresso' ),
604
+							__('The "%1$s" registration step was not initialized properly.', 'event_espresso'),
605 605
 							$reg_step->name()
606 606
 						),
607 607
 						__FILE__, __FUNCTION__, __LINE__
@@ -620,10 +620,10 @@  discard block
 block discarded – undo
620 620
 	 * 	@return 	void
621 621
 	 */
622 622
 	public function set_reg_step_JSON_info() {
623
-		EE_Registry::$i18n_js_strings[ 'reg_steps' ] = array();
623
+		EE_Registry::$i18n_js_strings['reg_steps'] = array();
624 624
 		// pass basic reg step data to JS
625
-		foreach ( $this->reg_steps as $reg_step ) {
626
-			EE_Registry::$i18n_js_strings[ 'reg_steps' ][] = $reg_step->slug();
625
+		foreach ($this->reg_steps as $reg_step) {
626
+			EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug();
627 627
 		}
628 628
 		// reset reg step html
629 629
 //		$this->json_response->set_reg_step_html( '' );
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 	 */
640 640
 	public function reset_reg_steps() {
641 641
 		$this->sort_reg_steps();
642
-		$this->set_current_step( EE_Registry::instance()->REQ->get( 'step' ));
642
+		$this->set_current_step(EE_Registry::instance()->REQ->get('step'));
643 643
 		$this->set_next_step();
644 644
 		// the text that appears on the reg step form submit button
645 645
 		$this->current_step->set_submit_button_text();
@@ -656,9 +656,9 @@  discard block
 block discarded – undo
656 656
 	 */
657 657
 	public function get_registration_time_limit() {
658 658
 
659
-		$registration_time_limit = (float)( EE_Registry::instance()	->SSN->expiration() - time() );
659
+		$registration_time_limit = (float) (EE_Registry::instance()	->SSN->expiration() - time());
660 660
 		$time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s';
661
-		$registration_time_limit = date( $time_limit_format, $registration_time_limit );
661
+		$registration_time_limit = date($time_limit_format, $registration_time_limit);
662 662
 		return apply_filters(
663 663
 			'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit',
664 664
 			$registration_time_limit
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
 		//		overpaid TXN
679 679
 		//		free TXN ( total = 0.00 )
680 680
 		// then payment required is TRUE
681
-		return ! ( $this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free() ) ? TRUE : FALSE;
681
+		return ! ($this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free()) ? TRUE : FALSE;
682 682
 	}
683 683
 
684 684
 
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
 	 * @param EE_Transaction $transaction
691 691
 	 * @return EE_Cart
692 692
 	 */
693
-	public function get_cart_for_transaction( $transaction ) {
694
-		$session = EE_Registry::instance()->load_core( 'Session' );
695
-		$cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn( $transaction, $session ) : null;
693
+	public function get_cart_for_transaction($transaction) {
694
+		$session = EE_Registry::instance()->load_core('Session');
695
+		$cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null;
696 696
 		// verify cart
697
-		if ( ! $cart instanceof EE_Cart ) {
698
-			$cart = EE_Registry::instance()->load_core( 'Cart' );
697
+		if ( ! $cart instanceof EE_Cart) {
698
+			$cart = EE_Registry::instance()->load_core('Cart');
699 699
 		}
700 700
 
701 701
 		return $cart;
@@ -711,8 +711,8 @@  discard block
 block discarded – undo
711 711
 	 */
712 712
 	public function initialize_txn_reg_steps_array() {
713 713
 		$txn_reg_steps_array = array();
714
-		foreach ( $this->reg_steps as $reg_step ) {
715
-			$txn_reg_steps_array[ $reg_step->slug() ] = FALSE;
714
+		foreach ($this->reg_steps as $reg_step) {
715
+			$txn_reg_steps_array[$reg_step->slug()] = FALSE;
716 716
 		}
717 717
 		return $txn_reg_steps_array;
718 718
 	}
@@ -728,14 +728,14 @@  discard block
 block discarded – undo
728 728
 	 */
729 729
 	public function update_txn_reg_steps_array() {
730 730
 		$updated = false;
731
-		foreach ( $this->reg_steps as $reg_step ) {
732
-			if ( $reg_step->completed() ) {
733
-				$updated = $this->transaction->set_reg_step_completed( $reg_step->slug() )
731
+		foreach ($this->reg_steps as $reg_step) {
732
+			if ($reg_step->completed()) {
733
+				$updated = $this->transaction->set_reg_step_completed($reg_step->slug())
734 734
 					? true
735 735
 					: $updated;
736 736
 			}
737 737
 		}
738
-		if ( $updated ) {
738
+		if ($updated) {
739 739
 			$this->transaction->save();
740 740
 		}
741 741
 		return $updated;
@@ -751,14 +751,14 @@  discard block
 block discarded – undo
751 751
 	 * @throws \EE_Error
752 752
 	 */
753 753
 	public function stash_transaction_and_checkout() {
754
-		if ( ! $this->revisit ) {
754
+		if ( ! $this->revisit) {
755 755
 			$this->update_txn_reg_steps_array();
756 756
 		}
757 757
 		$this->track_transaction_and_registration_status_updates();
758 758
 		// save all data to the db, but suppress errors
759 759
 		//$this->save_all_data( FALSE );
760 760
 		// cache the checkout in the session
761
-		EE_Registry::instance()->SSN->set_checkout( $this );
761
+		EE_Registry::instance()->SSN->set_checkout($this);
762 762
 	}
763 763
 
764 764
 
@@ -773,15 +773,15 @@  discard block
 block discarded – undo
773 773
 	 */
774 774
 	public function track_transaction_and_registration_status_updates() {
775 775
 		// verify the transaction
776
-		if ( $this->transaction instanceof EE_Transaction ) {
776
+		if ($this->transaction instanceof EE_Transaction) {
777 777
 			// has there been a TXN status change during this checkout?
778 778
 			$this->txn_status_updated = $this->transaction->txn_status_updated();
779 779
 			/** @type EE_Registration_Processor $registration_processor */
780
-			$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
780
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
781 781
 			// grab the saved registrations from the transaction
782
-			foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) {
783
-				if ( $registration_processor->reg_status_updated( $registration->ID() ) ) {
784
-					$this->set_reg_status_updated( $registration->ID(), true );
782
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
783
+				if ($registration_processor->reg_status_updated($registration->ID())) {
784
+					$this->set_reg_status_updated($registration->ID(), true);
785 785
 				}
786 786
 			}
787 787
 		}
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 	 * @return    bool
803 803
 	 * @throws \EE_Error
804 804
 	 */
805
-	public function visit_allows_processing_of_this_registration( EE_Registration $registration ) {
805
+	public function visit_allows_processing_of_this_registration(EE_Registration $registration) {
806 806
 		return ! $this->revisit
807 807
 		       || $this->primary_revisit
808 808
 		       || (
@@ -835,18 +835,18 @@  discard block
 block discarded – undo
835 835
 	 * @return bool
836 836
 	 * @throws \EE_Error
837 837
 	 */
838
-	public function save_all_data( $show_errors = TRUE ) {
838
+	public function save_all_data($show_errors = TRUE) {
839 839
 		// verify the transaction
840
-		if ( $this->transaction instanceof EE_Transaction ) {
840
+		if ($this->transaction instanceof EE_Transaction) {
841 841
 			// save to ensure that TXN has ID
842 842
 			$this->transaction->save();
843 843
 			// grab the saved registrations from the transaction
844
-			foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as  $registration ) {
845
-				$this->_save_registration( $registration, $show_errors );
844
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as  $registration) {
845
+				$this->_save_registration($registration, $show_errors);
846 846
 			}
847 847
 		} else {
848
-			if ( $show_errors ) {
849
-				EE_Error::add_error( __( 'A valid Transaction was not found when attempting to save your registration information.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
848
+			if ($show_errors) {
849
+				EE_Error::add_error(__('A valid Transaction was not found when attempting to save your registration information.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
850 850
 			}
851 851
 			return FALSE;
852 852
 		}
@@ -863,32 +863,32 @@  discard block
 block discarded – undo
863 863
 	 * @return void
864 864
 	 * @throws \EE_Error
865 865
 	 */
866
-	private function _save_registration( $registration, $show_errors = TRUE  ) {
866
+	private function _save_registration($registration, $show_errors = TRUE) {
867 867
 		// verify object
868
-		if ( $registration instanceof EE_Registration ) {
868
+		if ($registration instanceof EE_Registration) {
869 869
 			// should this registration be processed during this visit ?
870
-			if ( $this->visit_allows_processing_of_this_registration( $registration ) ) {
870
+			if ($this->visit_allows_processing_of_this_registration($registration)) {
871 871
 				//set TXN ID
872
-				if ( ! $registration->transaction_ID() ) {
873
-					$registration->set_transaction_id( $this->transaction->ID() );
872
+				if ( ! $registration->transaction_ID()) {
873
+					$registration->set_transaction_id($this->transaction->ID());
874 874
 				}
875 875
 				// verify and save the attendee
876
-				$this->_save_registration_attendee( $registration, $show_errors );
876
+				$this->_save_registration_attendee($registration, $show_errors);
877 877
 				// save answers to reg form questions
878
-				$this->_save_registration_answers( $registration, $show_errors );
878
+				$this->_save_registration_answers($registration, $show_errors);
879 879
 				// save changes
880 880
 				$registration->save();
881 881
 				// update txn cache
882
-				if ( ! $this->transaction->update_cache_after_object_save( 'Registration', $registration )) {
883
-					if ( $show_errors ) {
884
-						EE_Error::add_error( __( 'The newly saved Registration object could not be cached on the Transaction.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
882
+				if ( ! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
883
+					if ($show_errors) {
884
+						EE_Error::add_error(__('The newly saved Registration object could not be cached on the Transaction.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
885 885
 					}
886 886
 				}
887 887
 			}
888 888
 		} else {
889
-			if ( $show_errors ) {
889
+			if ($show_errors) {
890 890
 				EE_Error::add_error(
891
-					__( 'An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso' ),
891
+					__('An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso'),
892 892
 					__FILE__, __FUNCTION__, __LINE__
893 893
 				);
894 894
 			}
@@ -905,25 +905,25 @@  discard block
 block discarded – undo
905 905
 	 * @return void
906 906
 	 * @throws \EE_Error
907 907
 	 */
908
-	private function _save_registration_attendee( $registration, $show_errors = TRUE ) {
909
-		if ( $registration->attendee() instanceof EE_Attendee ) {
908
+	private function _save_registration_attendee($registration, $show_errors = TRUE) {
909
+		if ($registration->attendee() instanceof EE_Attendee) {
910 910
 			// save so that ATT has ID
911 911
 			$registration->attendee()->save();
912
-			if ( ! $registration->update_cache_after_object_save( 'Attendee', $registration->attendee() ) ) {
913
-				if ( $show_errors ) {
912
+			if ( ! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
913
+				if ($show_errors) {
914 914
 					EE_Error::add_error(
915
-						__( 'The newly saved Attendee object could not be cached on the registration.', 'event_espresso' ),
915
+						__('The newly saved Attendee object could not be cached on the registration.', 'event_espresso'),
916 916
 						__FILE__, __FUNCTION__, __LINE__
917 917
 					);
918 918
 				}
919 919
 			}
920 920
 		} else {
921
-			if ( $show_errors ) {
921
+			if ($show_errors) {
922 922
 				EE_Error::add_error(
923 923
 					sprintf(
924 924
 						'%1$s||%1$s $attendee = %2$s',
925
-						__( 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso' ),
926
-						var_export( $registration->attendee(), true )
925
+						__('Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso'),
926
+						var_export($registration->attendee(), true)
927 927
 					),
928 928
 					__FILE__, __FUNCTION__, __LINE__
929 929
 				);
@@ -941,25 +941,25 @@  discard block
 block discarded – undo
941 941
 	 * @return void
942 942
 	 * @throws \EE_Error
943 943
 	 */
944
-	private function _save_registration_answers( $registration, $show_errors = TRUE ) {
944
+	private function _save_registration_answers($registration, $show_errors = TRUE) {
945 945
 		// now save the answers
946
-		foreach ( $registration->answers() as $cache_key => $answer ) {
946
+		foreach ($registration->answers() as $cache_key => $answer) {
947 947
 			// verify object
948
-			if ( $answer instanceof EE_Answer ) {
949
-				$answer->set_registration( $registration->ID() );
948
+			if ($answer instanceof EE_Answer) {
949
+				$answer->set_registration($registration->ID());
950 950
 				$answer->save();
951
-				if ( ! $registration->update_cache_after_object_save( 'Answer', $answer, $cache_key )) {
952
-					if ( $show_errors ) {
951
+				if ( ! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
952
+					if ($show_errors) {
953 953
 						EE_Error::add_error(
954
-							__( 'The newly saved Answer object could not be cached on the registration.', 'event_espresso' ),
954
+							__('The newly saved Answer object could not be cached on the registration.', 'event_espresso'),
955 955
 							__FILE__, __FUNCTION__, __LINE__
956 956
 						);
957 957
 					}
958 958
 				}
959 959
 			} else {
960
-				if ( $show_errors ) {
960
+				if ($show_errors) {
961 961
 					EE_Error::add_error(
962
-						__( 'An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso' ),
962
+						__('An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso'),
963 963
 						__FILE__, __FUNCTION__, __LINE__
964 964
 					);
965 965
 				}
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
 	 * @return bool
979 979
 	 * @throws \EE_Error
980 980
 	 */
981
-	public function refresh_all_entities( $from_db = false ) {
981
+	public function refresh_all_entities($from_db = false) {
982 982
 		$from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response'
983 983
 			? true
984 984
 			: $from_db;
@@ -1002,11 +1002,11 @@  discard block
 block discarded – undo
1002 1002
 	 */
1003 1003
 	protected function refresh_from_db() {
1004 1004
 		// verify the transaction
1005
-		if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1005
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1006 1006
 			// pull fresh TXN data from the db
1007
-			$this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db( $this->transaction->ID() );
1007
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID());
1008 1008
 			// update EE_Checkout's cached primary_attendee object
1009
-			$this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db( $this->transaction );
1009
+			$this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction);
1010 1010
 			// update EE_Checkout's cached payment object
1011 1011
 			$payment = $this->transaction->last_payment();
1012 1012
 			$this->payment = $payment instanceof EE_Payment ? $payment : $this->payment;
@@ -1014,9 +1014,9 @@  discard block
 block discarded – undo
1014 1014
 			$payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null;
1015 1015
 			$this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method : $this->payment_method;
1016 1016
 			//now refresh the cart, based on the TXN
1017
-			$this->cart = $this->get_cart_for_transaction( $this->transaction );
1017
+			$this->cart = $this->get_cart_for_transaction($this->transaction);
1018 1018
 		} else {
1019
-			EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
1019
+			EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1020 1020
 			return FALSE;
1021 1021
 		}
1022 1022
 		return TRUE;
@@ -1031,21 +1031,21 @@  discard block
 block discarded – undo
1031 1031
 	 * @return  EE_Attendee | null
1032 1032
 	 * @throws \EE_Error
1033 1033
 	 */
1034
-	protected function _refresh_primary_attendee_obj_from_db( EE_Transaction $transaction ) {
1034
+	protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction) {
1035 1035
 
1036 1036
 		$primary_attendee_obj = null;
1037 1037
 		// grab the saved registrations from the transaction
1038
-		foreach ( $transaction->registrations( $this->reg_cache_where_params, true ) as $registration ) {
1038
+		foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) {
1039 1039
 			// verify object
1040
-			if ( $registration instanceof EE_Registration ) {
1040
+			if ($registration instanceof EE_Registration) {
1041 1041
 				$attendee = $registration->attendee();
1042 1042
 				// verify object && maybe cache primary_attendee_obj ?
1043
-				if ( $attendee instanceof EE_Attendee&& $registration->is_primary_registrant() ) {
1043
+				if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) {
1044 1044
 					$primary_attendee_obj = $attendee;
1045 1045
 				}
1046 1046
 			} else {
1047 1047
 				EE_Error::add_error(
1048
-						__( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ),
1048
+						__('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'),
1049 1049
 						__FILE__, __FUNCTION__, __LINE__
1050 1050
 				);
1051 1051
 			}
@@ -1066,43 +1066,43 @@  discard block
 block discarded – undo
1066 1066
 	 */
1067 1067
 	protected function refresh_entity_map() {
1068 1068
 		// verify the transaction
1069
-		if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1069
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1070 1070
 			// never cache payment info
1071
-			$this->transaction->clear_cache( 'Payment' );
1071
+			$this->transaction->clear_cache('Payment');
1072 1072
 			// is the Payment Options Reg Step completed ?
1073
-			if ( $this->transaction->reg_step_completed( 'payment_options' ) ) {
1073
+			if ($this->transaction->reg_step_completed('payment_options')) {
1074 1074
 				// then check for payments and update TXN accordingly
1075 1075
 				/** @type EE_Transaction_Payments $transaction_payments */
1076
-				$transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' );
1077
-				$transaction_payments->calculate_total_payments_and_update_status( $this->transaction );
1076
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1077
+				$transaction_payments->calculate_total_payments_and_update_status($this->transaction);
1078 1078
 			}
1079 1079
 			// grab the saved registrations from the transaction
1080 1080
 			foreach (
1081
-				$this->transaction->registrations( $this->reg_cache_where_params ) as $reg_cache_ID => $registration
1081
+				$this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration
1082 1082
 			) {
1083
-				$this->_refresh_registration( $reg_cache_ID, $registration );
1083
+				$this->_refresh_registration($reg_cache_ID, $registration);
1084 1084
 			}
1085 1085
 			// make sure our cached TXN is added to the model entity mapper
1086
-			$this->transaction = $this->transaction->get_model()->refresh_entity_map_with( $this->transaction->ID(), $this->transaction );
1086
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_with($this->transaction->ID(), $this->transaction);
1087 1087
 
1088 1088
 		} else {
1089
-			EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
1089
+			EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1090 1090
 			return FALSE;
1091 1091
 		}
1092 1092
 		// verify and update the cart because inaccurate totals are not so much fun
1093
-		if ( $this->cart instanceof EE_Cart ) {
1093
+		if ($this->cart instanceof EE_Cart) {
1094 1094
 			$grand_total = $this->cart->get_grand_total();
1095
-			if ( $grand_total instanceof EE_Line_Item && $grand_total->ID() ) {
1095
+			if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) {
1096 1096
 				$grand_total->recalculate_total_including_taxes();
1097 1097
 				$grand_total = $grand_total->get_model()->refresh_entity_map_with(
1098 1098
 					$this->cart->get_grand_total()->ID(),
1099 1099
 					$this->cart->get_grand_total()
1100 1100
 				);
1101 1101
 			}
1102
-			if ( $grand_total instanceof EE_Line_Item ) {
1103
-				$this->cart = EE_Cart::instance( $grand_total );
1102
+			if ($grand_total instanceof EE_Line_Item) {
1103
+				$this->cart = EE_Cart::instance($grand_total);
1104 1104
 			} else {
1105
-				EE_Error::add_error( __( 'A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1105
+				EE_Error::add_error(__('A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1106 1106
 				return false;
1107 1107
 			}
1108 1108
 		}
@@ -1119,19 +1119,19 @@  discard block
 block discarded – undo
1119 1119
 	 * @return void
1120 1120
 	 * @throws \EE_Error
1121 1121
 	 */
1122
-	protected function _refresh_registration( $reg_cache_ID, $registration ) {
1122
+	protected function _refresh_registration($reg_cache_ID, $registration) {
1123 1123
 
1124 1124
 		// verify object
1125
-		if ( $registration instanceof EE_Registration ) {
1125
+		if ($registration instanceof EE_Registration) {
1126 1126
 			// update the entity mapper attendee
1127
-			$this->_refresh_registration_attendee( $registration );
1127
+			$this->_refresh_registration_attendee($registration);
1128 1128
 			// update the entity mapper answers for reg form questions
1129
-			$this->_refresh_registration_answers( $registration );
1129
+			$this->_refresh_registration_answers($registration);
1130 1130
 			// make sure the cached registration is added to the model entity mapper
1131
-			$registration->get_model()->refresh_entity_map_with( $reg_cache_ID, $registration );
1131
+			$registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration);
1132 1132
 		} else {
1133 1133
 			EE_Error::add_error(
1134
-				__( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ),
1134
+				__('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'),
1135 1135
 				__FILE__, __FUNCTION__, __LINE__
1136 1136
 			);
1137 1137
 		}
@@ -1146,15 +1146,15 @@  discard block
 block discarded – undo
1146 1146
 	 * @return void
1147 1147
 	 * @throws \EE_Error
1148 1148
 	 */
1149
-	protected function _refresh_registration_attendee( $registration ) {
1149
+	protected function _refresh_registration_attendee($registration) {
1150 1150
 
1151 1151
 		$attendee = $registration->attendee();
1152 1152
 		// verify object
1153
-		if ( $attendee instanceof EE_Attendee && $attendee->ID() ) {
1153
+		if ($attendee instanceof EE_Attendee && $attendee->ID()) {
1154 1154
 			// make sure the cached attendee is added to the model entity mapper
1155
-			$registration->attendee()->get_model()->refresh_entity_map_with( $attendee->ID(), $attendee );
1155
+			$registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee);
1156 1156
 			// maybe cache primary_attendee_obj ?
1157
-			if ( $registration->is_primary_registrant() ) {
1157
+			if ($registration->is_primary_registrant()) {
1158 1158
 				$this->primary_attendee_obj = $attendee;
1159 1159
 			}
1160 1160
 		}
@@ -1169,19 +1169,19 @@  discard block
 block discarded – undo
1169 1169
 	 * @return void
1170 1170
 	 * @throws \EE_Error
1171 1171
 	 */
1172
-	protected function _refresh_registration_answers( $registration ) {
1172
+	protected function _refresh_registration_answers($registration) {
1173 1173
 
1174 1174
 		// now update the answers
1175
-		foreach ( $registration->answers() as $cache_key => $answer ) {
1175
+		foreach ($registration->answers() as $cache_key => $answer) {
1176 1176
 			// verify object
1177
-			if ( $answer instanceof EE_Answer ) {
1178
-				if ( $answer->ID() ) {
1177
+			if ($answer instanceof EE_Answer) {
1178
+				if ($answer->ID()) {
1179 1179
 					// make sure the cached answer is added to the model entity mapper
1180
-					$answer->get_model()->refresh_entity_map_with( $answer->ID(), $answer );
1180
+					$answer->get_model()->refresh_entity_map_with($answer->ID(), $answer);
1181 1181
 				}
1182 1182
 			} else {
1183 1183
 				EE_Error::add_error(
1184
-					__( 'An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso' ),
1184
+					__('An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso'),
1185 1185
 					__FILE__, __FUNCTION__, __LINE__
1186 1186
 				);
1187 1187
 			}
@@ -1201,13 +1201,13 @@  discard block
 block discarded – undo
1201 1201
 	 */
1202 1202
     public function __sleep()
1203 1203
     {
1204
-	    if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) {
1204
+	    if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) {
1205 1205
 		    $this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1206 1206
 	    }        // remove the reg form and the checkout
1207
-	    if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1207
+	    if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1208 1208
 		    $this->transaction = $this->transaction->ID();
1209 1209
 	    }        // remove the reg form and the checkout
1210
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) );
1210
+        return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form'));
1211 1211
     }
1212 1212
 
1213 1213
 
@@ -1217,15 +1217,15 @@  discard block
 block discarded – undo
1217 1217
 	 * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object
1218 1218
 	 */
1219 1219
 	public function __wakeup() {
1220
-		if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint( $this->primary_attendee_obj ) !== 0 ) {
1220
+		if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1221 1221
 			// $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db
1222
-			$this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID( $this->primary_attendee_obj );
1222
+			$this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj);
1223 1223
 		}
1224
-		if ( ! $this->transaction instanceof EE_Transaction && absint( $this->transaction ) !== 0 ) {
1224
+		if ( ! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1225 1225
 			// $this->transaction is actually just an ID, so use it to get the object from the db
1226
-			$this->transaction = EEM_Transaction::instance()->get_one_by_ID( $this->transaction );
1226
+			$this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction);
1227 1227
 		}
1228
-		foreach ( $this->reg_steps as $reg_step ) {
1228
+		foreach ($this->reg_steps as $reg_step) {
1229 1229
 			$reg_step->checkout = $this;
1230 1230
 		}
1231 1231
 	}
@@ -1242,12 +1242,12 @@  discard block
 block discarded – undo
1242 1242
 	 * @param bool   $display_request
1243 1243
 	 * @throws \EE_Error
1244 1244
 	 */
1245
-	public function log( $class = '', $func = '', $line = '', $info = array(), $display_request = false ) {
1245
+	public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false) {
1246 1246
 		$disabled = true;
1247
-		if ( WP_DEBUG && ! $disabled ) {
1248
-			$debug_data = get_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array() );
1247
+		if (WP_DEBUG && ! $disabled) {
1248
+			$debug_data = get_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), array());
1249 1249
 			$default_data = array(
1250
-				$class 		=> $func . '() : ' . $line,
1250
+				$class 		=> $func.'() : '.$line,
1251 1251
 				'request->step' 		=> $this->step,
1252 1252
 				'request->action' 	=> $this->action,
1253 1253
 				'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ?
@@ -1259,24 +1259,24 @@  discard block
 block discarded – undo
1259 1259
 				'reg_url_link' => $this->reg_url_link,
1260 1260
 				'REQ' => $display_request ? $_REQUEST : '',
1261 1261
 			);
1262
-			if ( $this->transaction instanceof EE_Transaction ) {
1263
-				$default_data[ 'TXN_status' ] 		= $this->transaction->status_ID();
1264
-				$default_data[ 'TXN_reg_steps' ] 	= $this->transaction->reg_steps();
1265
-				foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $REG_ID => $registration ) {
1266
-					$default_data[ 'registrations' ][ $REG_ID ] = $registration->status_ID();
1262
+			if ($this->transaction instanceof EE_Transaction) {
1263
+				$default_data['TXN_status'] = $this->transaction->status_ID();
1264
+				$default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
1265
+				foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
1266
+					$default_data['registrations'][$REG_ID] = $registration->status_ID();
1267 1267
 				}
1268
-				if ( $this->transaction->ID() ) {
1269
-					$TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
1268
+				if ($this->transaction->ID()) {
1269
+					$TXN_ID = 'EE_Transaction: '.$this->transaction->ID();
1270 1270
 					// don't serialize objects
1271
-					$info = $this->_strip_objects( $info );
1272
-					if ( ! isset( $debug_data[ $TXN_ID ] ) ) {
1273
-						$debug_data[ $TXN_ID ] = array();
1271
+					$info = $this->_strip_objects($info);
1272
+					if ( ! isset($debug_data[$TXN_ID])) {
1273
+						$debug_data[$TXN_ID] = array();
1274 1274
 					}
1275
-					$debug_data[ $TXN_ID ][ microtime() ] = array_merge(
1275
+					$debug_data[$TXN_ID][microtime()] = array_merge(
1276 1276
 						$default_data,
1277 1277
 						$info
1278 1278
 					);
1279
-					update_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data );
1279
+					update_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), $debug_data);
1280 1280
 				}
1281 1281
 			}
1282 1282
 		}
@@ -1289,23 +1289,23 @@  discard block
 block discarded – undo
1289 1289
 	 * @param array $info
1290 1290
 	 * @return array
1291 1291
 	 */
1292
-	public function _strip_objects( $info = array() ) {
1293
-		foreach ( (array)$info as $key => $value ) {
1294
-			if ( is_array( $value )) {
1295
-				$info[ $key ] = $this->_strip_objects( $value );
1296
-			} else if ( is_object( $value ) ) {
1297
-				$object_class = get_class( $value );
1298
-				$info[ $object_class ] = array();
1299
-				$info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : 0;
1300
-				if ( method_exists( $value, 'status' ) ) {
1301
-					$info[ $object_class ][ 'status' ] = $value->status();
1302
-				} else if ( method_exists( $value, 'status_ID' ) ) {
1303
-					$info[ $object_class ][ 'status' ] = $value->status_ID();
1292
+	public function _strip_objects($info = array()) {
1293
+		foreach ((array) $info as $key => $value) {
1294
+			if (is_array($value)) {
1295
+				$info[$key] = $this->_strip_objects($value);
1296
+			} else if (is_object($value)) {
1297
+				$object_class = get_class($value);
1298
+				$info[$object_class] = array();
1299
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1300
+				if (method_exists($value, 'status')) {
1301
+					$info[$object_class]['status'] = $value->status();
1302
+				} else if (method_exists($value, 'status_ID')) {
1303
+					$info[$object_class]['status'] = $value->status_ID();
1304 1304
 				}
1305
-				unset( $info[ $key ] );
1305
+				unset($info[$key]);
1306 1306
 			}
1307 1307
 		}
1308
-		return (array)$info;
1308
+		return (array) $info;
1309 1309
 	}
1310 1310
 
1311 1311
 
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	 * @throws \EE_Error
203 203
 	 */
204 204
 	public static function set_definitions() {
205
-        define( 'SPCO_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS );
205
+		define( 'SPCO_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS );
206 206
 		define( 'SPCO_CSS_URL', plugin_dir_url( __FILE__ ) . 'css' . DS );
207 207
 		define( 'SPCO_IMG_URL', plugin_dir_url( __FILE__ ) . 'img' . DS );
208 208
 		define( 'SPCO_JS_URL', plugin_dir_url( __FILE__ ) . 'js' . DS );
@@ -322,9 +322,9 @@  discard block
 block discarded – undo
322 322
 
323 323
 
324 324
 	/**
325
-     * process_registration_from_admin
326
-     *
327
-     * @access public
325
+	 * process_registration_from_admin
326
+	 *
327
+	 * @access public
328 328
 	 * @return \EE_Transaction
329 329
 	 * @throws \EE_Error
330 330
 	 */
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 * @throws \EE_Error
360 360
 	 */
361 361
 	public function run( $WP_Query ) {
362
-        if (
362
+		if (
363 363
 			$WP_Query instanceof WP_Query
364 364
 			&& $WP_Query->is_main_query()
365 365
 			&& apply_filters( 'FHEE__EED_Single_Page_Checkout__run', true )
@@ -371,38 +371,38 @@  discard block
 block discarded – undo
371 371
 
372 372
 
373 373
 
374
-    /**
375
-     * determines whether current url matches reg page url
376
-     *
377
-     * @return bool
378
-     */
379
-    protected function _is_reg_checkout() {
380
-        // get current permalink for reg page without any extra query args
381
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
382
-        // get request URI for current request, but without the scheme or host
383
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
384
-        $current_request_uri = html_entity_decode( $current_request_uri );
385
-        // get array of query args from the current request URI
386
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
387
-        // grab page id if it is set
388
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
389
-        // and remove the page id from the query args (we will re-add it later)
390
-        unset($query_args['page_id']);
391
-        // now strip all query args from current request URI
392
-        $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri);
393
-        // and re-add the page id if it was set
394
-        if ($page_id){
395
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
396
-        }
397
-        // remove slashes and ?
398
-        $current_request_uri = trim($current_request_uri, '?/');
399
-	    // is current request URI part of the known full reg page URL ?
400
-        return strpos($reg_page_url, $current_request_uri) !== false;
401
-    }
402
-
403
-
404
-
405
-    /**
374
+	/**
375
+	 * determines whether current url matches reg page url
376
+	 *
377
+	 * @return bool
378
+	 */
379
+	protected function _is_reg_checkout() {
380
+		// get current permalink for reg page without any extra query args
381
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
382
+		// get request URI for current request, but without the scheme or host
383
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
384
+		$current_request_uri = html_entity_decode( $current_request_uri );
385
+		// get array of query args from the current request URI
386
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
387
+		// grab page id if it is set
388
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
389
+		// and remove the page id from the query args (we will re-add it later)
390
+		unset($query_args['page_id']);
391
+		// now strip all query args from current request URI
392
+		$current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri);
393
+		// and re-add the page id if it was set
394
+		if ($page_id){
395
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
396
+		}
397
+		// remove slashes and ?
398
+		$current_request_uri = trim($current_request_uri, '?/');
399
+		// is current request URI part of the known full reg page URL ?
400
+		return strpos($reg_page_url, $current_request_uri) !== false;
401
+	}
402
+
403
+
404
+
405
+	/**
406 406
 	 *    run
407 407
 	 *
408 408
 	 * @access    public
@@ -428,16 +428,16 @@  discard block
 block discarded – undo
428 428
 		if ( EED_Single_Page_Checkout::$_initialized ) {
429 429
 			return;
430 430
 		}
431
-        try {
432
-	        // setup the EE_Checkout object
431
+		try {
432
+			// setup the EE_Checkout object
433 433
 			$this->checkout = $this->_initialize_checkout();
434 434
 			// filter checkout
435 435
 			$this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout );
436 436
 			// get the $_GET
437 437
 			$this->_get_request_vars();
438
-            if ($this->_block_bots()) {
439
-                return;
440
-            }
438
+			if ($this->_block_bots()) {
439
+				return;
440
+			}
441 441
 			// filter continue_reg
442 442
 			$this->checkout->continue_reg = apply_filters( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout );
443 443
 			// load the reg steps array
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
 	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
599 599
 	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
600 600
 	 * then where you coming from man?
601
-     *
602
-     * @return boolean
601
+	 *
602
+	 * @return boolean
603 603
 	 */
604 604
 	private function _block_bots() {
605 605
 		$invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
@@ -854,15 +854,15 @@  discard block
 block discarded – undo
854 854
 
855 855
 
856 856
 
857
-    /**
858
-     * _get_registrations
859
-     *
860
-     * @access private
861
-     * @param EE_Transaction $transaction
862
-     * @return void
863
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
864
-     * @throws \EE_Error
865
-     */
857
+	/**
858
+	 * _get_registrations
859
+	 *
860
+	 * @access private
861
+	 * @param EE_Transaction $transaction
862
+	 * @return void
863
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
864
+	 * @throws \EE_Error
865
+	 */
866 866
 	private function _get_registrations( EE_Transaction $transaction ) {
867 867
 		// first step: grab the registrants  { : o
868 868
 		$registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, true );
@@ -884,12 +884,12 @@  discard block
 block discarded – undo
884 884
 			if ( $registration instanceof EE_Registration ) {
885 885
 				// we display all attendee info for the primary registrant
886 886
 				if ( $this->checkout->reg_url_link === $registration->reg_url_link()
887
-				     && $registration->is_primary_registrant()
887
+					 && $registration->is_primary_registrant()
888 888
 				) {
889 889
 					$this->checkout->primary_revisit = true;
890 890
 					break;
891 891
 				} else if ( $this->checkout->revisit
892
-				            && $this->checkout->reg_url_link !== $registration->reg_url_link()
892
+							&& $this->checkout->reg_url_link !== $registration->reg_url_link()
893 893
 				) {
894 894
 					// but hide info if it doesn't belong to you
895 895
 					$transaction->clear_cache( 'Registration', $registration->ID() );
@@ -901,15 +901,15 @@  discard block
 block discarded – undo
901 901
 
902 902
 
903 903
 
904
-    /**
905
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
906
-     *
907
-     * @access private
908
-     * @param EE_Transaction $transaction
909
-     * @return    array
910
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
911
-     * @throws \EE_Error
912
-     */
904
+	/**
905
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
906
+	 *
907
+	 * @access private
908
+	 * @param EE_Transaction $transaction
909
+	 * @return    array
910
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
911
+	 * @throws \EE_Error
912
+	 */
913 913
 	private function _initialize_registrations( EE_Transaction $transaction ) {
914 914
 		$att_nmbr = 0;
915 915
 		$registrations = array();
@@ -922,23 +922,23 @@  discard block
 block discarded – undo
922 922
 				//do the following for each ticket of this type they selected
923 923
 				for ( $x = 1; $x <= $line_item->quantity(); $x++ ) {
924 924
 					$att_nmbr++;
925
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
926
-                    $CreateRegistrationCommand = EE_Registry::instance()
927
-                        ->create(
928
-                           'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
929
-                           array(
930
-	                           $transaction,
931
-	                           $line_item,
932
-	                           $att_nmbr,
933
-	                           $this->checkout->total_ticket_count
934
-                           )
935
-                        );
936
-                    // override capabilities for frontend registrations
937
-                    if ( ! is_admin()) {
938
-                        $CreateRegistrationCommand->setCapCheck(
939
-	                        new PublicCapabilities( '', 'create_new_registration' )
940
-                        );
941
-                    }
925
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
926
+					$CreateRegistrationCommand = EE_Registry::instance()
927
+						->create(
928
+						   'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
929
+						   array(
930
+							   $transaction,
931
+							   $line_item,
932
+							   $att_nmbr,
933
+							   $this->checkout->total_ticket_count
934
+						   )
935
+						);
936
+					// override capabilities for frontend registrations
937
+					if ( ! is_admin()) {
938
+						$CreateRegistrationCommand->setCapCheck(
939
+							new PublicCapabilities( '', 'create_new_registration' )
940
+						);
941
+					}
942 942
 					$registration = EE_Registry::instance()->BUS->execute( $CreateRegistrationCommand );
943 943
 					if ( ! $registration instanceof EE_Registration ) {
944 944
 						throw new InvalidEntityException( $registration, 'EE_Registration' );
@@ -1433,10 +1433,10 @@  discard block
 block discarded – undo
1433 1433
 				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1434 1434
 			}
1435 1435
 			$this->checkout->redirect_url = apply_filters(
1436
-			    'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1437
-                $this->checkout->redirect_url,
1438
-                $this->checkout
1439
-            );
1436
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1437
+				$this->checkout->redirect_url,
1438
+				$this->checkout
1439
+			);
1440 1440
 		}
1441 1441
 	}
1442 1442
 
Please login to merge, or discard this patch.
Spacing   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\domain\services\capabilities\PublicCapabilities;
2 2
 use EventEspresso\core\exceptions\InvalidEntityException;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	 * @return EED_Single_Page_Checkout
55 55
 	 */
56 56
 	public static function instance() {
57
-		add_filter( 'EED_Single_Page_Checkout__SPCO_active', '__return_true' );
58
-		return parent::get_instance( __CLASS__ );
57
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
58
+		return parent::get_instance(__CLASS__);
59 59
 	}
60 60
 
61 61
 
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 	 */
101 101
 	public static function set_hooks_admin() {
102 102
 		EED_Single_Page_Checkout::set_definitions();
103
-		if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )) {
103
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
104 104
 			// hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called
105
-			add_action( 'pre_get_posts', array( 'EED_Single_Page_Checkout', 'load_reg_steps' ), 1 );
105
+			add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1);
106 106
 			return;
107 107
 		}
108 108
 		// going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 		EED_Single_Page_Checkout::load_request_handler();
111 111
 		EED_Single_Page_Checkout::load_reg_steps();
112 112
 		// set ajax hooks
113
-		add_action( 'wp_ajax_process_reg_step', array( 'EED_Single_Page_Checkout', 'process_reg_step' ));
114
-		add_action( 'wp_ajax_nopriv_process_reg_step', array( 'EED_Single_Page_Checkout', 'process_reg_step' ));
115
-		add_action( 'wp_ajax_display_spco_reg_step', array( 'EED_Single_Page_Checkout', 'display_reg_step' ));
116
-		add_action( 'wp_ajax_nopriv_display_spco_reg_step', array( 'EED_Single_Page_Checkout', 'display_reg_step' ));
117
-		add_action( 'wp_ajax_update_reg_step', array( 'EED_Single_Page_Checkout', 'update_reg_step' ));
118
-		add_action( 'wp_ajax_nopriv_update_reg_step', array( 'EED_Single_Page_Checkout', 'update_reg_step' ));
113
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
114
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
115
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
116
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
117
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
118
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
119 119
 	}
120 120
 
121 121
 
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 	 * @param string $ajax_action
127 127
 	 * @throws \EE_Error
128 128
 	 */
129
-	public static function process_ajax_request( $ajax_action ) {
130
-		EE_Registry::instance()->REQ->set( 'action', $ajax_action );
129
+	public static function process_ajax_request($ajax_action) {
130
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
131 131
 		EED_Single_Page_Checkout::instance()->_initialize();
132 132
 	}
133 133
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 * @throws \EE_Error
140 140
 	 */
141 141
 	public static function display_reg_step() {
142
-		EED_Single_Page_Checkout::process_ajax_request( 'display_spco_reg_step' );
142
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
143 143
 	}
144 144
 
145 145
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @throws \EE_Error
151 151
 	 */
152 152
 	public static function process_reg_step() {
153
-		EED_Single_Page_Checkout::process_ajax_request( 'process_reg_step' );
153
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
154 154
 	}
155 155
 
156 156
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 * @throws \EE_Error
162 162
 	 */
163 163
 	public static function update_reg_step() {
164
-		EED_Single_Page_Checkout::process_ajax_request( 'update_reg_step' );
164
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
165 165
 	}
166 166
 
167 167
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @throws \EE_Error
175 175
 	 */
176 176
 	public static function update_checkout() {
177
-		EED_Single_Page_Checkout::process_ajax_request( 'update_checkout' );
177
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
178 178
 	}
179 179
 
180 180
 
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 */
188 188
 	public static function load_request_handler() {
189 189
 		// load core Request_Handler class
190
-		if ( ! isset( EE_Registry::instance()->REQ )) {
191
-			EE_Registry::instance()->load_core( 'Request_Handler' );
190
+		if ( ! isset(EE_Registry::instance()->REQ)) {
191
+			EE_Registry::instance()->load_core('Request_Handler');
192 192
 		}
193 193
 	}
194 194
 
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 	 * @throws \EE_Error
203 203
 	 */
204 204
 	public static function set_definitions() {
205
-        define( 'SPCO_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS );
206
-		define( 'SPCO_CSS_URL', plugin_dir_url( __FILE__ ) . 'css' . DS );
207
-		define( 'SPCO_IMG_URL', plugin_dir_url( __FILE__ ) . 'img' . DS );
208
-		define( 'SPCO_JS_URL', plugin_dir_url( __FILE__ ) . 'js' . DS );
209
-		define( 'SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS );
210
-		define( 'SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS );
211
-		define( 'SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS );
212
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( SPCO_BASE_PATH, TRUE );
205
+        define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS);
206
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
207
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
208
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
209
+		define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
210
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
211
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
212
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, TRUE);
213 213
 	}
214 214
 
215 215
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	public static function load_reg_steps() {
226 226
 		static $reg_steps_loaded = FALSE;
227
-		if ( $reg_steps_loaded ) {
227
+		if ($reg_steps_loaded) {
228 228
 			return;
229 229
 		}
230 230
 		// filter list of reg_steps
@@ -233,24 +233,24 @@  discard block
 block discarded – undo
233 233
 			EED_Single_Page_Checkout::get_reg_steps()
234 234
 		);
235 235
 		// sort by key (order)
236
-		ksort( $reg_steps_to_load );
236
+		ksort($reg_steps_to_load);
237 237
 		// loop through folders
238
-		foreach ( $reg_steps_to_load as $order => $reg_step ) {
238
+		foreach ($reg_steps_to_load as $order => $reg_step) {
239 239
 			// we need a
240
-			if ( isset( $reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'] )) {
240
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
241 241
 				// copy over to the reg_steps_array
242
-				EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
242
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
243 243
 				// register custom key route for each reg step
244 244
 				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
245
-				EE_Config::register_route( $reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step' );
245
+				EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step');
246 246
 				// add AJAX or other hooks
247
-				if ( isset( $reg_step['has_hooks'] ) && $reg_step['has_hooks'] ) {
247
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
248 248
 					// setup autoloaders if necessary
249
-					if ( ! class_exists( $reg_step['class_name'] )) {
250
-						EEH_Autoloader::register_autoloaders_for_each_file_in_folder( $reg_step['file_path'], TRUE );
249
+					if ( ! class_exists($reg_step['class_name'])) {
250
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], TRUE);
251 251
 					}
252
-					if ( is_callable( $reg_step['class_name'], 'set_hooks' )) {
253
-						call_user_func( array( $reg_step['class_name'], 'set_hooks' ));
252
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
253
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
254 254
 					}
255 255
 				}
256 256
 			}
@@ -269,28 +269,28 @@  discard block
 block discarded – undo
269 269
 	 */
270 270
 	public static function get_reg_steps() {
271 271
 		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
272
-		if ( empty( $reg_steps )) {
272
+		if (empty($reg_steps)) {
273 273
 			$reg_steps = array(
274 274
 				10 => array(
275
-					'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information',
275
+					'file_path' => SPCO_REG_STEPS_PATH.'attendee_information',
276 276
 					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
277 277
 					'slug' => 'attendee_information',
278 278
 					'has_hooks' => FALSE
279 279
 				),
280 280
 				20 => array(
281
-					'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation',
281
+					'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation',
282 282
 					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
283 283
 					'slug' => 'registration_confirmation',
284 284
 					'has_hooks' => FALSE
285 285
 				),
286 286
 				30 => array(
287
-					'file_path' => SPCO_REG_STEPS_PATH . 'payment_options',
287
+					'file_path' => SPCO_REG_STEPS_PATH.'payment_options',
288 288
 					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
289 289
 					'slug' => 'payment_options',
290 290
 					'has_hooks' => TRUE
291 291
 				),
292 292
 				999 => array(
293
-					'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration',
293
+					'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration',
294 294
 					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
295 295
 					'slug' => 'finalize_registration',
296 296
 					'has_hooks' => FALSE
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
 	 */
312 312
 	public static function registration_checkout_for_admin() {
313 313
 		EED_Single_Page_Checkout::load_reg_steps();
314
-		EE_Registry::instance()->REQ->set( 'step', 'attendee_information' );
315
-		EE_Registry::instance()->REQ->set( 'action', 'display_spco_reg_step' );
316
-		EE_Registry::instance()->REQ->set( 'process_form_submission', false );
314
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
315
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
316
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
317 317
 		EED_Single_Page_Checkout::instance()->_initialize();
318 318
 		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
319 319
 		return EE_Registry::instance()->REQ->get_output();
@@ -330,15 +330,15 @@  discard block
 block discarded – undo
330 330
 	 */
331 331
 	public static function process_registration_from_admin() {
332 332
 		EED_Single_Page_Checkout::load_reg_steps();
333
-		EE_Registry::instance()->REQ->set( 'step', 'attendee_information' );
334
-		EE_Registry::instance()->REQ->set( 'action', 'process_reg_step' );
335
-		EE_Registry::instance()->REQ->set( 'process_form_submission', true );
333
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
334
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
335
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
336 336
 		EED_Single_Page_Checkout::instance()->_initialize();
337
-		if ( EED_Single_Page_Checkout::instance()->checkout->current_step->completed() ) {
338
-			$final_reg_step = end( EED_Single_Page_Checkout::instance()->checkout->reg_steps );
339
-			if ( $final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) {
340
-				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated( $final_reg_step );
341
-				if ( $final_reg_step->process_reg_step() ) {
337
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
338
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
339
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
340
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
341
+				if ($final_reg_step->process_reg_step()) {
342 342
 					$final_reg_step->set_completed();
343 343
 					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
344 344
 					return EED_Single_Page_Checkout::instance()->checkout->transaction;
@@ -358,11 +358,11 @@  discard block
 block discarded – undo
358 358
 	 * @return    void
359 359
 	 * @throws \EE_Error
360 360
 	 */
361
-	public function run( $WP_Query ) {
361
+	public function run($WP_Query) {
362 362
         if (
363 363
 			$WP_Query instanceof WP_Query
364 364
 			&& $WP_Query->is_main_query()
365
-			&& apply_filters( 'FHEE__EED_Single_Page_Checkout__run', true )
365
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
366 366
 			&& $this->_is_reg_checkout()
367 367
 		) {
368 368
 			$this->_initialize();
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
         $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
382 382
         // get request URI for current request, but without the scheme or host
383 383
         $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
384
-        $current_request_uri = html_entity_decode( $current_request_uri );
384
+        $current_request_uri = html_entity_decode($current_request_uri);
385 385
         // get array of query args from the current request URI
386 386
         $query_args = \EEH_URL::get_query_string($current_request_uri);
387 387
         // grab page id if it is set
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         // now strip all query args from current request URI
392 392
         $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri);
393 393
         // and re-add the page id if it was set
394
-        if ($page_id){
394
+        if ($page_id) {
395 395
             $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
396 396
         }
397 397
         // remove slashes and ?
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
 	 * @return    void
411 411
 	 * @throws \EE_Error
412 412
 	 */
413
-	public static function init( $WP_Query ) {
414
-		EED_Single_Page_Checkout::instance()->run( $WP_Query );
413
+	public static function init($WP_Query) {
414
+		EED_Single_Page_Checkout::instance()->run($WP_Query);
415 415
 	}
416 416
 
417 417
 
@@ -425,37 +425,37 @@  discard block
 block discarded – undo
425 425
 	 */
426 426
 	private function _initialize() {
427 427
 		// ensure SPCO doesn't run twice
428
-		if ( EED_Single_Page_Checkout::$_initialized ) {
428
+		if (EED_Single_Page_Checkout::$_initialized) {
429 429
 			return;
430 430
 		}
431 431
         try {
432 432
 	        // setup the EE_Checkout object
433 433
 			$this->checkout = $this->_initialize_checkout();
434 434
 			// filter checkout
435
-			$this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout );
435
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
436 436
 			// get the $_GET
437 437
 			$this->_get_request_vars();
438 438
             if ($this->_block_bots()) {
439 439
                 return;
440 440
             }
441 441
 			// filter continue_reg
442
-			$this->checkout->continue_reg = apply_filters( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout );
442
+			$this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout);
443 443
 			// load the reg steps array
444
-			if ( ! $this->_load_and_instantiate_reg_steps() ) {
444
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
445 445
 				EED_Single_Page_Checkout::$_initialized = true;
446 446
 				return;
447 447
 			}
448 448
 			// set the current step
449
-			$this->checkout->set_current_step( $this->checkout->step );
449
+			$this->checkout->set_current_step($this->checkout->step);
450 450
 			// and the next step
451 451
 			$this->checkout->set_next_step();
452 452
 			// was there already a valid transaction in the checkout from the session ?
453
-			if ( ! $this->checkout->transaction instanceof EE_Transaction ) {
453
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
454 454
 				// get transaction from db or session
455 455
 				$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
456 456
 					? $this->_get_transaction_and_cart_for_previous_visit()
457 457
 					: $this->_get_cart_for_current_session_and_setup_new_transaction();
458
-				if ( ! $this->checkout->transaction instanceof EE_Transaction ) {
458
+				if ( ! $this->checkout->transaction instanceof EE_Transaction) {
459 459
 					// add some style and make it dance
460 460
 					$this->checkout->transaction = EE_Transaction::new_instance();
461 461
 					$this->add_styles_and_scripts();
@@ -463,10 +463,10 @@  discard block
 block discarded – undo
463 463
 					return;
464 464
 				}
465 465
 				// and the registrations for the transaction
466
-				$this->_get_registrations( $this->checkout->transaction );
466
+				$this->_get_registrations($this->checkout->transaction);
467 467
 			}
468 468
 			// verify that everything has been setup correctly
469
-			if ( ! $this->_final_verifications() ) {
469
+			if ( ! $this->_final_verifications()) {
470 470
 				EED_Single_Page_Checkout::$_initialized = true;
471 471
 				return;
472 472
 			}
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 			// set no cache headers and constants
492 492
 			EE_System::do_not_cache();
493 493
 			// add anchor
494
-			add_action( 'loop_start', array( $this, 'set_checkout_anchor' ), 1 );
495
-		} catch ( Exception $e ) {
496
-			EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ );
494
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
495
+		} catch (Exception $e) {
496
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
497 497
 		}
498 498
 	}
499 499
 
@@ -511,20 +511,20 @@  discard block
 block discarded – undo
511 511
 		// look in session for existing checkout
512 512
 		$checkout = EE_Registry::instance()->SSN->checkout();
513 513
 		// verify
514
-		if ( ! $checkout instanceof EE_Checkout ) {
514
+		if ( ! $checkout instanceof EE_Checkout) {
515 515
 			// instantiate EE_Checkout object for handling the properties of the current checkout process
516
-			$checkout = EE_Registry::instance()->load_file( SPCO_INC_PATH, 'EE_Checkout', 'class', array(), FALSE  );
516
+			$checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), FALSE);
517 517
 		} else {
518
-			if ( $checkout->current_step->is_final_step() && $checkout->exit_spco() === true )  {
518
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
519 519
 				$this->unlock_transaction();
520
-				wp_safe_redirect( $checkout->redirect_url );
520
+				wp_safe_redirect($checkout->redirect_url);
521 521
 				exit();
522 522
 			}
523 523
 		}
524
-		$checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout );
524
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
525 525
 		// verify again
526
-		if ( ! $checkout instanceof EE_Checkout ) {
527
-			throw new EE_Error( __( 'The EE_Checkout class could not be loaded.', 'event_espresso' ) );
526
+		if ( ! $checkout instanceof EE_Checkout) {
527
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
528 528
 		}
529 529
 		// reset anything that needs a clean slate for each request
530 530
 		$checkout->reset_for_current_request();
@@ -544,26 +544,26 @@  discard block
 block discarded – undo
544 544
 		// load classes
545 545
 		EED_Single_Page_Checkout::load_request_handler();
546 546
 		//make sure this request is marked as belonging to EE
547
-		EE_Registry::instance()->REQ->set_espresso_page( TRUE );
547
+		EE_Registry::instance()->REQ->set_espresso_page(TRUE);
548 548
 		// which step is being requested ?
549
-		$this->checkout->step = EE_Registry::instance()->REQ->get( 'step', $this->_get_first_step() );
549
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
550 550
 		// which step is being edited ?
551
-		$this->checkout->edit_step = EE_Registry::instance()->REQ->get( 'edit_step', '' );
551
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
552 552
 		// and what we're doing on the current step
553
-		$this->checkout->action = EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' );
553
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
554 554
 		// timestamp
555
-		$this->checkout->uts = EE_Registry::instance()->REQ->get( 'uts', 0 );
555
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
556 556
 		// returning to edit ?
557
-		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get( 'e_reg_url_link', '' );
557
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
558 558
 		// or some other kind of revisit ?
559
-		$this->checkout->revisit = EE_Registry::instance()->REQ->get( 'revisit', FALSE );
559
+		$this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', FALSE);
560 560
 		// and whether or not to generate a reg form for this request
561
-		$this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get( 'generate_reg_form', TRUE ); 		// TRUE 	FALSE
561
+		$this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', TRUE); // TRUE 	FALSE
562 562
 		// and whether or not to process a reg form submission for this request
563
-		$this->checkout->process_form_submission = EE_Registry::instance()->REQ->get( 'process_form_submission', FALSE ); 		// TRUE 	FALSE
563
+		$this->checkout->process_form_submission = EE_Registry::instance()->REQ->get('process_form_submission', FALSE); // TRUE 	FALSE
564 564
 		$this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step'
565 565
 			? $this->checkout->process_form_submission
566
-			: FALSE; 		// TRUE 	FALSE
566
+			: FALSE; // TRUE 	FALSE
567 567
 		// $this->_display_request_vars();
568 568
 	}
569 569
 
@@ -576,17 +576,17 @@  discard block
 block discarded – undo
576 576
 	 * @return    void
577 577
 	 */
578 578
 	protected function _display_request_vars() {
579
-		if ( ! WP_DEBUG ) {
579
+		if ( ! WP_DEBUG) {
580 580
 			return;
581 581
 		}
582
-		EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
583
-		EEH_Debug_Tools::printr( $this->checkout->step, '$this->checkout->step', __FILE__, __LINE__ );
584
-		EEH_Debug_Tools::printr( $this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__ );
585
-		EEH_Debug_Tools::printr( $this->checkout->action, '$this->checkout->action', __FILE__, __LINE__ );
586
-		EEH_Debug_Tools::printr( $this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__ );
587
-		EEH_Debug_Tools::printr( $this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__ );
588
-		EEH_Debug_Tools::printr( $this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__ );
589
-		EEH_Debug_Tools::printr( $this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__ );
582
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
583
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
584
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
585
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
586
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
587
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
588
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
589
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
590 590
 	}
591 591
 
592 592
 
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	 */
604 604
 	private function _block_bots() {
605 605
 		$invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
606
-		if ( $invalid_checkout_access->checkoutAccessIsInvalid( $this->checkout ) ) {
606
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
607 607
 			return true;
608 608
 		}
609 609
 		return false;
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
 	 * @return    array
621 621
 	 */
622 622
 	private function _get_first_step() {
623
-		$first_step = reset( EED_Single_Page_Checkout::$_reg_steps_array );
624
-		return isset( $first_step['slug'] ) ? $first_step['slug'] : 'attendee_information';
623
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
624
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
625 625
 	}
626 626
 
627 627
 
@@ -637,27 +637,27 @@  discard block
 block discarded – undo
637 637
 	private function _load_and_instantiate_reg_steps() {
638 638
 		// have reg_steps already been instantiated ?
639 639
 		if (
640
-			empty( $this->checkout->reg_steps ) ||
641
-			apply_filters( 'FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout )
640
+			empty($this->checkout->reg_steps) ||
641
+			apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
642 642
 		) {
643 643
 			// if not, then loop through raw reg steps array
644
-			foreach ( EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step ) {
645
-				if ( ! $this->_load_and_instantiate_reg_step( $reg_step, $order )) {
644
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
645
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
646 646
 					return false;
647 647
 				}
648 648
 			}
649 649
 			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = TRUE;
650 650
 			EE_Registry::instance()->CFG->registration->reg_confirmation_last = TRUE;
651 651
 			// skip the registration_confirmation page ?
652
-			if ( EE_Registry::instance()->CFG->registration->skip_reg_confirmation ) {
652
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
653 653
 				// just remove it from the reg steps array
654
-				$this->checkout->remove_reg_step( 'registration_confirmation', false );
654
+				$this->checkout->remove_reg_step('registration_confirmation', false);
655 655
 			} else if (
656
-				isset( $this->checkout->reg_steps['registration_confirmation'] )
656
+				isset($this->checkout->reg_steps['registration_confirmation'])
657 657
 				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
658 658
 			) {
659 659
 				// set the order to something big like 100
660
-				$this->checkout->set_reg_step_order( 'registration_confirmation', 100 );
660
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
661 661
 			}
662 662
 			// filter the array for good luck
663 663
 			$this->checkout->reg_steps = apply_filters(
@@ -667,13 +667,13 @@  discard block
 block discarded – undo
667 667
 			// finally re-sort based on the reg step class order properties
668 668
 			$this->checkout->sort_reg_steps();
669 669
 		} else {
670
-			foreach ( $this->checkout->reg_steps as $reg_step ) {
670
+			foreach ($this->checkout->reg_steps as $reg_step) {
671 671
 				// set all current step stati to FALSE
672
-				$reg_step->set_is_current_step( FALSE );
672
+				$reg_step->set_is_current_step(FALSE);
673 673
 			}
674 674
 		}
675
-		if ( empty( $this->checkout->reg_steps )) {
676
-			EE_Error::add_error( __( 'No Reg Steps were loaded..', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
675
+		if (empty($this->checkout->reg_steps)) {
676
+			EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
677 677
 			return false;
678 678
 		}
679 679
 			// make reg step details available to JS
@@ -691,10 +691,10 @@  discard block
 block discarded – undo
691 691
 	 * @param int   $order
692 692
 	 * @return bool
693 693
 	 */
694
-	private function _load_and_instantiate_reg_step( $reg_step = array(), $order = 0 ) {
694
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) {
695 695
 
696 696
 		// we need a file_path, class_name, and slug to add a reg step
697
-		if ( isset( $reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'] )) {
697
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
698 698
 			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
699 699
 			if (
700 700
 				$this->checkout->reg_url_link
@@ -712,26 +712,26 @@  discard block
 block discarded – undo
712 712
 				FALSE
713 713
 			);
714 714
 			// did we gets the goods ?
715
-			if ( $reg_step_obj instanceof EE_SPCO_Reg_Step ) {
715
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
716 716
 				// set reg step order based on config
717
-				$reg_step_obj->set_order( $order );
717
+				$reg_step_obj->set_order($order);
718 718
 				// add instantiated reg step object to the master reg steps array
719
-				$this->checkout->add_reg_step( $reg_step_obj );
719
+				$this->checkout->add_reg_step($reg_step_obj);
720 720
 			} else {
721 721
 				EE_Error::add_error(
722
-					__( 'The current step could not be set.', 'event_espresso' ),
722
+					__('The current step could not be set.', 'event_espresso'),
723 723
 					__FILE__, __FUNCTION__, __LINE__
724 724
 				);
725 725
 				return false;
726 726
 			}
727 727
 		} else {
728
-			if ( WP_DEBUG ) {
728
+			if (WP_DEBUG) {
729 729
 				EE_Error::add_error(
730 730
 					sprintf(
731
-						__( 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso' ),
732
-						isset( $reg_step['file_path'] ) ? $reg_step['file_path'] : '',
733
-						isset( $reg_step['class_name'] ) ? $reg_step['class_name'] : '',
734
-						isset( $reg_step['slug'] ) ? $reg_step['slug'] : '',
731
+						__('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'),
732
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
733
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
734
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
735 735
 						'<ul>',
736 736
 						'<li>',
737 737
 						'</li>',
@@ -755,16 +755,16 @@  discard block
 block discarded – undo
755 755
 	 */
756 756
 	private function _get_transaction_and_cart_for_previous_visit() {
757 757
 		/** @var $TXN_model EEM_Transaction */
758
-		$TXN_model = EE_Registry::instance()->load_model( 'Transaction' );
758
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
759 759
 		// because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db
760
-		$transaction = $TXN_model->get_transaction_from_reg_url_link( $this->checkout->reg_url_link );
760
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
761 761
 		// verify transaction
762
-		if ( $transaction instanceof EE_Transaction ) {
762
+		if ($transaction instanceof EE_Transaction) {
763 763
 			// and get the cart that was used for that transaction
764
-			$this->checkout->cart = $this->_get_cart_for_transaction( $transaction );
764
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
765 765
 			return $transaction;
766 766
 		} else {
767
-			EE_Error::add_error( __( 'Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
767
+			EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
768 768
 			return NULL;
769 769
 		}
770 770
 	}
@@ -778,8 +778,8 @@  discard block
 block discarded – undo
778 778
 	 * @param EE_Transaction $transaction
779 779
 	 * @return EE_Cart
780 780
 	 */
781
-	private function _get_cart_for_transaction( $transaction ) {
782
-		return $this->checkout->get_cart_for_transaction( $transaction );
781
+	private function _get_cart_for_transaction($transaction) {
782
+		return $this->checkout->get_cart_for_transaction($transaction);
783 783
 	}
784 784
 
785 785
 
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
 	 * @param EE_Transaction $transaction
792 792
 	 * @return EE_Cart
793 793
 	 */
794
-	public function get_cart_for_transaction( EE_Transaction $transaction ) {
795
-		return $this->checkout->get_cart_for_transaction( $transaction );
794
+	public function get_cart_for_transaction(EE_Transaction $transaction) {
795
+		return $this->checkout->get_cart_for_transaction($transaction);
796 796
 	}
797 797
 
798 798
 
@@ -808,17 +808,17 @@  discard block
 block discarded – undo
808 808
 	private function _get_cart_for_current_session_and_setup_new_transaction() {
809 809
 		//  if there's no transaction, then this is the FIRST visit to SPCO
810 810
 		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
811
-		$this->checkout->cart = $this->_get_cart_for_transaction( NULL );
811
+		$this->checkout->cart = $this->_get_cart_for_transaction(NULL);
812 812
 		// and then create a new transaction
813 813
 		$transaction = $this->_initialize_transaction();
814 814
 		// verify transaction
815
-		if ( $transaction instanceof EE_Transaction ) {
815
+		if ($transaction instanceof EE_Transaction) {
816 816
 			// save it so that we have an ID for other objects to use
817 817
 			$transaction->save();
818 818
 			// and save TXN data to the cart
819
-			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( $transaction->ID() );
819
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
820 820
 		} else {
821
-			EE_Error::add_error( __( 'A Valid Transaction could not be initialized.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
821
+			EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
822 822
 		}
823 823
 		return $transaction;
824 824
 	}
@@ -846,8 +846,8 @@  discard block
 block discarded – undo
846 846
 					'STS_ID'        => EEM_Transaction::failed_status_code,
847 847
 				)
848 848
 			);
849
-		} catch( Exception $e ) {
850
-			EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
849
+		} catch (Exception $e) {
850
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
851 851
 		}
852 852
 		return NULL;
853 853
 	}
@@ -863,38 +863,38 @@  discard block
 block discarded – undo
863 863
      * @throws \EventEspresso\core\exceptions\InvalidEntityException
864 864
      * @throws \EE_Error
865 865
      */
866
-	private function _get_registrations( EE_Transaction $transaction ) {
866
+	private function _get_registrations(EE_Transaction $transaction) {
867 867
 		// first step: grab the registrants  { : o
868
-		$registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, true );
868
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
869 869
 		// verify registrations have been set
870
-		if ( empty( $registrations )) {
870
+		if (empty($registrations)) {
871 871
 			// if no cached registrations, then check the db
872
-			$registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, false );
872
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
873 873
 			// still nothing ? well as long as this isn't a revisit
874
-			if ( empty( $registrations ) && ! $this->checkout->revisit ) {
874
+			if (empty($registrations) && ! $this->checkout->revisit) {
875 875
 				// generate new registrations from scratch
876
-				$registrations = $this->_initialize_registrations( $transaction );
876
+				$registrations = $this->_initialize_registrations($transaction);
877 877
 			}
878 878
 		}
879 879
 		// sort by their original registration order
880
-		usort( $registrations, array( 'EED_Single_Page_Checkout', 'sort_registrations_by_REG_count' ));
880
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
881 881
 		// then loop thru the array
882
-		foreach ( $registrations as $registration ) {
882
+		foreach ($registrations as $registration) {
883 883
 			// verify each registration
884
-			if ( $registration instanceof EE_Registration ) {
884
+			if ($registration instanceof EE_Registration) {
885 885
 				// we display all attendee info for the primary registrant
886
-				if ( $this->checkout->reg_url_link === $registration->reg_url_link()
886
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
887 887
 				     && $registration->is_primary_registrant()
888 888
 				) {
889 889
 					$this->checkout->primary_revisit = true;
890 890
 					break;
891
-				} else if ( $this->checkout->revisit
891
+				} else if ($this->checkout->revisit
892 892
 				            && $this->checkout->reg_url_link !== $registration->reg_url_link()
893 893
 				) {
894 894
 					// but hide info if it doesn't belong to you
895
-					$transaction->clear_cache( 'Registration', $registration->ID() );
895
+					$transaction->clear_cache('Registration', $registration->ID());
896 896
 				}
897
-				$this->checkout->set_reg_status_updated( $registration->ID(), false );
897
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
898 898
 			}
899 899
 		}
900 900
 	}
@@ -910,17 +910,17 @@  discard block
 block discarded – undo
910 910
      * @throws \EventEspresso\core\exceptions\InvalidEntityException
911 911
      * @throws \EE_Error
912 912
      */
913
-	private function _initialize_registrations( EE_Transaction $transaction ) {
913
+	private function _initialize_registrations(EE_Transaction $transaction) {
914 914
 		$att_nmbr = 0;
915 915
 		$registrations = array();
916
-		if ( $transaction instanceof EE_Transaction ) {
916
+		if ($transaction instanceof EE_Transaction) {
917 917
 			/** @type EE_Registration_Processor $registration_processor */
918
-			$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
918
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
919 919
 			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
920 920
 			// now let's add the cart items to the $transaction
921
-			foreach ( $this->checkout->cart->get_tickets() as $line_item ) {
921
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
922 922
 				//do the following for each ticket of this type they selected
923
-				for ( $x = 1; $x <= $line_item->quantity(); $x++ ) {
923
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
924 924
 					$att_nmbr++;
925 925
                     /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
926 926
                     $CreateRegistrationCommand = EE_Registry::instance()
@@ -936,17 +936,17 @@  discard block
 block discarded – undo
936 936
                     // override capabilities for frontend registrations
937 937
                     if ( ! is_admin()) {
938 938
                         $CreateRegistrationCommand->setCapCheck(
939
-	                        new PublicCapabilities( '', 'create_new_registration' )
939
+	                        new PublicCapabilities('', 'create_new_registration')
940 940
                         );
941 941
                     }
942
-					$registration = EE_Registry::instance()->BUS->execute( $CreateRegistrationCommand );
943
-					if ( ! $registration instanceof EE_Registration ) {
944
-						throw new InvalidEntityException( $registration, 'EE_Registration' );
942
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
943
+					if ( ! $registration instanceof EE_Registration) {
944
+						throw new InvalidEntityException($registration, 'EE_Registration');
945 945
 					}
946
-					$registrations[ $registration->ID() ] = $registration;
946
+					$registrations[$registration->ID()] = $registration;
947 947
 				}
948 948
 			}
949
-			$registration_processor->fix_reg_final_price_rounding_issue( $transaction );
949
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
950 950
 		}
951 951
 		return $registrations;
952 952
 	}
@@ -961,12 +961,12 @@  discard block
 block discarded – undo
961 961
 	 * @param EE_Registration $reg_B
962 962
 	 * @return int
963 963
 	 */
964
-	public static function sort_registrations_by_REG_count( EE_Registration $reg_A, EE_Registration $reg_B ) {
964
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) {
965 965
 		// this shouldn't ever happen within the same TXN, but oh well
966
-		if ( $reg_A->count() === $reg_B->count() ) {
966
+		if ($reg_A->count() === $reg_B->count()) {
967 967
 			return 0;
968 968
 		}
969
-		return ( $reg_A->count() > $reg_B->count() ) ? 1 : -1;
969
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
970 970
 	}
971 971
 
972 972
 
@@ -981,21 +981,21 @@  discard block
 block discarded – undo
981 981
 	 */
982 982
 	private function _final_verifications() {
983 983
 		// filter checkout
984
-		$this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout );
984
+		$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout);
985 985
 		//verify that current step is still set correctly
986
-		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step ) {
987
-			EE_Error::add_error( __( 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
986
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
987
+			EE_Error::add_error(__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
988 988
 			return false;
989 989
 		}
990 990
 		// if returning to SPCO, then verify that primary registrant is set
991
-		if ( ! empty( $this->checkout->reg_url_link )) {
991
+		if ( ! empty($this->checkout->reg_url_link)) {
992 992
 			$valid_registrant = $this->checkout->transaction->primary_registration();
993
-			if ( ! $valid_registrant instanceof EE_Registration ) {
994
-				EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
993
+			if ( ! $valid_registrant instanceof EE_Registration) {
994
+				EE_Error::add_error(__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
995 995
 				return false;
996 996
 			}
997 997
 			$valid_registrant = null;
998
-			foreach ( $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ) as $registration ) {
998
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
999 999
 				if (
1000 1000
 					$registration instanceof EE_Registration
1001 1001
 					&& $registration->reg_url_link() === $this->checkout->reg_url_link
@@ -1003,9 +1003,9 @@  discard block
 block discarded – undo
1003 1003
 					$valid_registrant = $registration;
1004 1004
 				}
1005 1005
 			}
1006
-			if ( ! $valid_registrant instanceof EE_Registration ) {
1006
+			if ( ! $valid_registrant instanceof EE_Registration) {
1007 1007
 				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1008
-				if ( EED_Single_Page_Checkout::$_checkout_verified ) {
1008
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1009 1009
 					// clear the session, mark the checkout as unverified, and try again
1010 1010
 					EE_Registry::instance()->SSN->clear_session();
1011 1011
 					EED_Single_Page_Checkout::$_initialized = false;
@@ -1014,13 +1014,13 @@  discard block
 block discarded – undo
1014 1014
 					EE_Error::reset_notices();
1015 1015
 					return false;
1016 1016
 				}
1017
-				EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1017
+				EE_Error::add_error(__('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1018 1018
 				return false;
1019 1019
 			}
1020 1020
 		}
1021 1021
 		// now that things have been kinda sufficiently verified,
1022 1022
 		// let's add the checkout to the session so that's available other systems
1023
-		EE_Registry::instance()->SSN->set_checkout( $this->checkout );
1023
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1024 1024
 		return true;
1025 1025
 	}
1026 1026
 
@@ -1035,15 +1035,15 @@  discard block
 block discarded – undo
1035 1035
 	 * @param bool $reinitializing
1036 1036
 	 * @throws \EE_Error
1037 1037
 	 */
1038
-	private function _initialize_reg_steps( $reinitializing = false ) {
1039
-		$this->checkout->set_reg_step_initiated( $this->checkout->current_step );
1038
+	private function _initialize_reg_steps($reinitializing = false) {
1039
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1040 1040
 		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1041
-		foreach ( $this->checkout->reg_steps as $reg_step ) {
1042
-			if ( ! $reg_step->initialize_reg_step() ) {
1041
+		foreach ($this->checkout->reg_steps as $reg_step) {
1042
+			if ( ! $reg_step->initialize_reg_step()) {
1043 1043
 				// if not initialized then maybe this step is being removed...
1044
-				if ( ! $reinitializing && $reg_step->is_current_step() ) {
1044
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1045 1045
 					// if it was the current step, then we need to start over here
1046
-					$this->_initialize_reg_steps( true );
1046
+					$this->_initialize_reg_steps(true);
1047 1047
 					return;
1048 1048
 				}
1049 1049
 				continue;
@@ -1052,13 +1052,13 @@  discard block
 block discarded – undo
1052 1052
 			$reg_step->enqueue_styles_and_scripts();
1053 1053
 			// i18n
1054 1054
 			$reg_step->translate_js_strings();
1055
-			if ( $reg_step->is_current_step() ) {
1055
+			if ($reg_step->is_current_step()) {
1056 1056
 				// the text that appears on the reg step form submit button
1057 1057
 				$reg_step->set_submit_button_text();
1058 1058
 			}
1059 1059
 		}
1060 1060
 		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1061
-		do_action( "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step );
1061
+		do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step);
1062 1062
 	}
1063 1063
 
1064 1064
 
@@ -1071,43 +1071,43 @@  discard block
 block discarded – undo
1071 1071
 	 */
1072 1072
 	private function _check_form_submission() {
1073 1073
 		//does this request require the reg form to be generated ?
1074
-		if ( $this->checkout->generate_reg_form ) {
1074
+		if ($this->checkout->generate_reg_form) {
1075 1075
 			// ever heard that song by Blue Rodeo ?
1076 1076
 			try {
1077 1077
 				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1078 1078
 				// if not displaying a form, then check for form submission
1079
-				if ( $this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted() ) {
1079
+				if ($this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted()) {
1080 1080
 					// clear out any old data in case this step is being run again
1081
-					$this->checkout->current_step->set_valid_data( array() );
1081
+					$this->checkout->current_step->set_valid_data(array());
1082 1082
 					// capture submitted form data
1083 1083
 					$this->checkout->current_step->reg_form->receive_form_submission(
1084
-						apply_filters( 'FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout )
1084
+						apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout)
1085 1085
 					);
1086 1086
 					// validate submitted form data
1087
-					if ( ! $this->checkout->continue_reg && ! $this->checkout->current_step->reg_form->is_valid() ) {
1087
+					if ( ! $this->checkout->continue_reg && ! $this->checkout->current_step->reg_form->is_valid()) {
1088 1088
 						// thou shall not pass !!!
1089 1089
 						$this->checkout->continue_reg = FALSE;
1090 1090
 						// any form validation errors?
1091
-						if ( $this->checkout->current_step->reg_form->submission_error_message() !== '' ) {
1091
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1092 1092
 							$submission_error_messages = array();
1093 1093
 							// bad, bad, bad registrant
1094
-							foreach( $this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error ){
1095
-								if ( $validation_error instanceof EE_Validation_Error ) {
1094
+							foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) {
1095
+								if ($validation_error instanceof EE_Validation_Error) {
1096 1096
 									$submission_error_messages[] = sprintf(
1097
-										__( '%s : %s', 'event_espresso' ),
1097
+										__('%s : %s', 'event_espresso'),
1098 1098
 										$validation_error->get_form_section()->html_label_text(),
1099 1099
 										$validation_error->getMessage()
1100 1100
 									);
1101 1101
 								}
1102 1102
 							}
1103
-							EE_Error::add_error( implode( '<br />', $submission_error_messages ), __FILE__, __FUNCTION__, __LINE__ );
1103
+							EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1104 1104
 						}
1105 1105
 						// well not really... what will happen is we'll just get redirected back to redo the current step
1106 1106
 						$this->go_to_next_step();
1107 1107
 						return;
1108 1108
 					}
1109 1109
 				}
1110
-			} catch( EE_Error $e ) {
1110
+			} catch (EE_Error $e) {
1111 1111
 				$e->get_error();
1112 1112
 			}
1113 1113
 		}
@@ -1124,22 +1124,22 @@  discard block
 block discarded – undo
1124 1124
 	 */
1125 1125
 	private function _process_form_action() {
1126 1126
 		// what cha wanna do?
1127
-		switch( $this->checkout->action ) {
1127
+		switch ($this->checkout->action) {
1128 1128
 			// AJAX next step reg form
1129 1129
 			case 'display_spco_reg_step' :
1130 1130
 				$this->checkout->redirect = FALSE;
1131
-				if ( EE_Registry::instance()->REQ->ajax ) {
1132
-					$this->checkout->json_response->set_reg_step_html( $this->checkout->current_step->display_reg_form() );
1131
+				if (EE_Registry::instance()->REQ->ajax) {
1132
+					$this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form());
1133 1133
 				}
1134 1134
 				break;
1135 1135
 
1136 1136
 			default :
1137 1137
 				// meh... do one of those other steps first
1138
-				if ( ! empty( $this->checkout->action ) && is_callable( array( $this->checkout->current_step, $this->checkout->action ))) {
1138
+				if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) {
1139 1139
 					// dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1140
-					do_action( "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step );
1140
+					do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1141 1141
 					// call action on current step
1142
-					if ( call_user_func( array( $this->checkout->current_step, $this->checkout->action )) ) {
1142
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1143 1143
 						// good registrant, you get to proceed
1144 1144
 						if (
1145 1145
 							$this->checkout->current_step->success_message() !== ''
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 						) {
1151 1151
 								EE_Error::add_success(
1152 1152
 									$this->checkout->current_step->success_message()
1153
-									. '<br />' . $this->checkout->next_step->_instructions()
1153
+									. '<br />'.$this->checkout->next_step->_instructions()
1154 1154
 								);
1155 1155
 
1156 1156
 						}
@@ -1158,12 +1158,12 @@  discard block
 block discarded – undo
1158 1158
 						$this->_setup_redirect();
1159 1159
 					}
1160 1160
 					// dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1161
-					do_action( "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step );
1161
+					do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1162 1162
 
1163 1163
 				} else {
1164 1164
 					EE_Error::add_error(
1165 1165
 						sprintf(
1166
-							__( 'The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso' ),
1166
+							__('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'),
1167 1167
 							$this->checkout->action,
1168 1168
 							$this->checkout->current_step->name()
1169 1169
 						),
@@ -1189,10 +1189,10 @@  discard block
 block discarded – undo
1189 1189
 	public function add_styles_and_scripts() {
1190 1190
 		// i18n
1191 1191
 		$this->translate_js_strings();
1192
-		if ( $this->checkout->admin_request ) {
1193
-			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10 );
1192
+		if ($this->checkout->admin_request) {
1193
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1194 1194
 		} else {
1195
-			add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles_and_scripts' ), 10 );
1195
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1196 1196
 		}
1197 1197
 	}
1198 1198
 
@@ -1208,42 +1208,42 @@  discard block
 block discarded – undo
1208 1208
 		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1209 1209
 		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1210 1210
 		EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1211
-		EE_Registry::$i18n_js_strings['invalid_json_response'] = __( 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso' );
1212
-		EE_Registry::$i18n_js_strings['validation_error'] = __( 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso' );
1213
-		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso' );
1211
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1212
+		EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso');
1213
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso');
1214 1214
 		EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso');
1215 1215
 		EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso');
1216
-		EE_Registry::$i18n_js_strings['process_registration'] = sprintf( __( 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso' ), '<br/>', '<br/>' );
1217
-		EE_Registry::$i18n_js_strings['language'] = get_bloginfo( 'language' );
1216
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(__('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), '<br/>', '<br/>');
1217
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1218 1218
 		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1219 1219
 		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1220 1220
 		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1221
-		EE_Registry::$i18n_js_strings['timer_years'] = __( 'years', 'event_espresso' );
1222
-		EE_Registry::$i18n_js_strings['timer_months'] = __( 'months', 'event_espresso' );
1223
-		EE_Registry::$i18n_js_strings['timer_weeks'] = __( 'weeks', 'event_espresso' );
1224
-		EE_Registry::$i18n_js_strings['timer_days'] = __( 'days', 'event_espresso' );
1225
-		EE_Registry::$i18n_js_strings['timer_hours'] = __( 'hours', 'event_espresso' );
1226
-		EE_Registry::$i18n_js_strings['timer_minutes'] = __( 'minutes', 'event_espresso' );
1227
-		EE_Registry::$i18n_js_strings['timer_seconds'] = __( 'seconds', 'event_espresso' );
1228
-		EE_Registry::$i18n_js_strings['timer_year'] = __( 'year', 'event_espresso' );
1229
-		EE_Registry::$i18n_js_strings['timer_month'] = __( 'month', 'event_espresso' );
1230
-		EE_Registry::$i18n_js_strings['timer_week'] = __( 'week', 'event_espresso' );
1231
-		EE_Registry::$i18n_js_strings['timer_day'] = __( 'day', 'event_espresso' );
1232
-		EE_Registry::$i18n_js_strings['timer_hour'] = __( 'hour', 'event_espresso' );
1233
-		EE_Registry::$i18n_js_strings['timer_minute'] = __( 'minute', 'event_espresso' );
1234
-		EE_Registry::$i18n_js_strings['timer_second'] = __( 'second', 'event_espresso' );
1221
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1222
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1223
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1224
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1225
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1226
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1227
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1228
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1229
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1230
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1231
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1232
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1233
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1234
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1235 1235
 		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1236
-			__( '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', 'event_espresso' ),
1236
+			__('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', 'event_espresso'),
1237 1237
 			'<h4 class="important-notice">',
1238 1238
 			'</h4>',
1239 1239
 			'<br />',
1240 1240
 			'<p>',
1241
-			'<a href="'. get_post_type_archive_link( 'espresso_events' ) . '" title="',
1241
+			'<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1242 1242
 			'">',
1243 1243
 			'</a>',
1244 1244
 			'</p>'
1245 1245
 		);
1246
-		EE_Registry::$i18n_js_strings[ 'ajax_submit' ] = apply_filters( 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true );
1246
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true);
1247 1247
 	}
1248 1248
 
1249 1249
 
@@ -1257,27 +1257,27 @@  discard block
 block discarded – undo
1257 1257
 	 */
1258 1258
 	public function enqueue_styles_and_scripts() {
1259 1259
 		// load css
1260
-		wp_register_style( 'single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION );
1261
-		wp_enqueue_style( 'single_page_checkout' );
1260
+		wp_register_style('single_page_checkout', SPCO_CSS_URL.'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1261
+		wp_enqueue_style('single_page_checkout');
1262 1262
 		// load JS
1263
-		wp_register_script( 'jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array( 'jquery' ), '1.0.1', TRUE );
1264
-		wp_register_script( 'jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array( 'jquery_plugin' ), '2.0.2', TRUE );
1265
-		wp_register_script( 'single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array( 'espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown' ), EVENT_ESPRESSO_VERSION, TRUE );
1263
+		wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL.'jquery	.plugin.min.js', array('jquery'), '1.0.1', TRUE);
1264
+		wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL.'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', TRUE);
1265
+		wp_register_script('single_page_checkout', SPCO_JS_URL.'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, TRUE);
1266 1266
 		$this->checkout->registration_form->enqueue_js();
1267 1267
 		$this->checkout->current_step->reg_form->enqueue_js();
1268
-		wp_enqueue_script( 'single_page_checkout' );
1268
+		wp_enqueue_script('single_page_checkout');
1269 1269
 
1270 1270
 		/**
1271 1271
 		 * global action hook for enqueueing styles and scripts with
1272 1272
 		 * spco calls.
1273 1273
 		 */
1274
-		do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this );
1274
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1275 1275
 
1276 1276
 		/**
1277 1277
 		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1278 1278
 		 * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1279 1279
 		 */
1280
-		do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this );
1280
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), $this);
1281 1281
 
1282 1282
 	}
1283 1283
 
@@ -1292,19 +1292,19 @@  discard block
 block discarded – undo
1292 1292
 	 */
1293 1293
 	private function _display_spco_reg_form() {
1294 1294
 		// if registering via the admin, just display the reg form for the current step
1295
-		if ( $this->checkout->admin_request ) {
1296
-			EE_Registry::instance()->REQ->add_output( $this->checkout->current_step->display_reg_form() );
1295
+		if ($this->checkout->admin_request) {
1296
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1297 1297
 		} else {
1298 1298
 			// add powered by EE msg
1299
-			add_action( 'AHEE__SPCO__reg_form_footer', array( 'EED_Single_Page_Checkout', 'display_registration_footer' ));
1299
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1300 1300
 
1301
-			$empty_cart = count( $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ) ) < 1 ? true : false;
1301
+			$empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 ? true : false;
1302 1302
 			$cookies_not_set_msg = '';
1303
-			if ( $empty_cart && ! isset( $_COOKIE[ 'ee_cookie_test' ] ) ) {
1303
+			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1304 1304
 				$cookies_not_set_msg = apply_filters(
1305 1305
 					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1306 1306
 					sprintf(
1307
-						__( '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', 'event_espresso' ),
1307
+						__('%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', 'event_espresso'),
1308 1308
 						'<div class="ee-attention">',
1309 1309
 						'</div>',
1310 1310
 						'<h6 class="important-notice">',
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
 					'layout_strategy' =>
1325 1325
 						new EE_Template_Layout(
1326 1326
 							array(
1327
-								'layout_template_file' 			=> SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1327
+								'layout_template_file' 			=> SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1328 1328
 								'template_args' => array(
1329 1329
 									'empty_cart' 		=> $empty_cart,
1330 1330
 									'revisit' 				=> $this->checkout->revisit,
@@ -1333,8 +1333,8 @@  discard block
 block discarded – undo
1333 1333
 									'empty_msg' 		=> apply_filters(
1334 1334
 										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1335 1335
 										sprintf(
1336
-											__( 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso' ),
1337
-											'<a href="' . get_post_type_archive_link( 'espresso_events' ) . '" title="',
1336
+											__('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso'),
1337
+											'<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1338 1338
 											'">',
1339 1339
 											'</a>'
1340 1340
 										)
@@ -1342,14 +1342,14 @@  discard block
 block discarded – undo
1342 1342
 									'cookies_not_set_msg' 		=> $cookies_not_set_msg,
1343 1343
 									'registration_time_limit' 	=> $this->checkout->get_registration_time_limit(),
1344 1344
 									'session_expiration' 			=>
1345
-										date( 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) )
1345
+										date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1346 1346
 							)
1347 1347
 						)
1348 1348
 					)
1349 1349
 				)
1350 1350
 			);
1351 1351
 			// load template and add to output sent that gets filtered into the_content()
1352
-			EE_Registry::instance()->REQ->add_output( $this->checkout->registration_form->get_html() );
1352
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1353 1353
 		}
1354 1354
 	}
1355 1355
 
@@ -1363,8 +1363,8 @@  discard block
 block discarded – undo
1363 1363
 	 * @internal  param string $label
1364 1364
 	 * @return void
1365 1365
 	 */
1366
-	public function add_extra_finalize_registration_inputs( $next_step ) {
1367
-		if ( $next_step === 'finalize_registration' ) {
1366
+	public function add_extra_finalize_registration_inputs($next_step) {
1367
+		if ($next_step === 'finalize_registration') {
1368 1368
 			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1369 1369
 		}
1370 1370
 	}
@@ -1386,8 +1386,8 @@  discard block
 block discarded – undo
1386 1386
 		) {
1387 1387
 			add_filter(
1388 1388
 				'FHEE__EEH_Template__powered_by_event_espresso__url',
1389
-				function( $url) {
1390
-					return apply_filters( 'FHEE__EE_Front_Controller__registration_footer__url', $url );
1389
+				function($url) {
1390
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1391 1391
 				}
1392 1392
 			);
1393 1393
 			echo apply_filters(
@@ -1395,7 +1395,7 @@  discard block
 block discarded – undo
1395 1395
 				\EEH_Template::powered_by_event_espresso(
1396 1396
 					'',
1397 1397
 					'espresso-registration-footer-dv',
1398
-					array( 'utm_content' => 'registration_checkout' )
1398
+					array('utm_content' => 'registration_checkout')
1399 1399
 				)
1400 1400
 			);
1401 1401
 		}
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
 	 * @throws \EE_Error
1413 1413
 	 */
1414 1414
 	public function unlock_transaction() {
1415
-		if ( $this->checkout->transaction instanceof EE_Transaction ) {
1415
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1416 1416
 			$this->checkout->transaction->unlock();
1417 1417
 		}
1418 1418
 	}
@@ -1427,9 +1427,9 @@  discard block
 block discarded – undo
1427 1427
 	 * @return void
1428 1428
 	 */
1429 1429
 	private function _setup_redirect() {
1430
-		if ( $this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step ) {
1430
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1431 1431
 			$this->checkout->redirect = TRUE;
1432
-			if ( empty( $this->checkout->redirect_url )) {
1432
+			if (empty($this->checkout->redirect_url)) {
1433 1433
 				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1434 1434
 			}
1435 1435
 			$this->checkout->redirect_url = apply_filters(
@@ -1450,9 +1450,9 @@  discard block
 block discarded – undo
1450 1450
 	 * @throws \EE_Error
1451 1451
 	 */
1452 1452
 	public function go_to_next_step() {
1453
-		if ( EE_Registry::instance()->REQ->ajax ) {
1453
+		if (EE_Registry::instance()->REQ->ajax) {
1454 1454
 			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1455
-			$this->checkout->json_response->set_unexpected_errors( ob_get_clean() );
1455
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1456 1456
 		}
1457 1457
 		$this->unlock_transaction();
1458 1458
 		// just return for these conditions
@@ -1481,7 +1481,7 @@  discard block
 block discarded – undo
1481 1481
 	 */
1482 1482
 	protected function _handle_json_response() {
1483 1483
 		// if this is an ajax request
1484
-		if ( EE_Registry::instance()->REQ->ajax ) {
1484
+		if (EE_Registry::instance()->REQ->ajax) {
1485 1485
 			// DEBUG LOG
1486 1486
 			//$this->checkout->log(
1487 1487
 			//	__CLASS__, __FUNCTION__, __LINE__,
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
 			$this->checkout->json_response->set_registration_time_limit(
1495 1495
 				$this->checkout->get_registration_time_limit()
1496 1496
 			);
1497
-			$this->checkout->json_response->set_payment_amount( $this->checkout->amount_owing );
1497
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1498 1498
 			// just send the ajax (
1499 1499
 			$json_response = apply_filters(
1500 1500
 				'FHEE__EE_Single_Page_Checkout__JSON_response',
@@ -1515,9 +1515,9 @@  discard block
 block discarded – undo
1515 1515
 	 */
1516 1516
 	protected function _handle_html_redirects() {
1517 1517
 		// going somewhere ?
1518
-		if ( $this->checkout->redirect && ! empty( $this->checkout->redirect_url ) ) {
1518
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1519 1519
 			// store notices in a transient
1520
-			EE_Error::get_notices( false, true, true );
1520
+			EE_Error::get_notices(false, true, true);
1521 1521
 			// DEBUG LOG
1522 1522
 			//$this->checkout->log(
1523 1523
 			//	__CLASS__, __FUNCTION__, __LINE__,
@@ -1527,7 +1527,7 @@  discard block
 block discarded – undo
1527 1527
 			//		'headers_list'    => headers_list(),
1528 1528
 			//	)
1529 1529
 			//);
1530
-			wp_safe_redirect( $this->checkout->redirect_url );
1530
+			wp_safe_redirect($this->checkout->redirect_url);
1531 1531
 			exit();
1532 1532
 		}
1533 1533
 	}
Please login to merge, or discard this patch.
espresso.php 1 patch
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'ABSPATH' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('ABSPATH')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  * @link             {@link http://www.eventespresso.com}
40 40
  * @since            4.0
41 41
  */
42
-if ( function_exists( 'espresso_version' ) ) {
42
+if (function_exists('espresso_version')) {
43 43
 
44 44
 	/**
45 45
 	 *    espresso_duplicate_plugin_error
@@ -56,15 +56,15 @@  discard block
 block discarded – undo
56 56
 			</p>
57 57
 		</div>
58 58
 		<?php
59
-		espresso_deactivate_plugin( plugin_basename( __FILE__ ) );
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60 60
 	}
61
-	add_action( 'admin_notices', 'espresso_duplicate_plugin_error', 1 );
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 
63 63
 } else {
64 64
 
65
-	define( 'EE_MIN_PHP_VER_REQUIRED', '5.3.0' );
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.0');
66 66
 
67
-	if ( ! version_compare( PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=' ) ) {
67
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
68 68
 
69 69
 		/**
70 70
 		 * espresso_minimum_php_version_error
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 				</p>
91 91
 			</div>
92 92
 			<?php
93
-			espresso_deactivate_plugin( plugin_basename( __FILE__ ) );
93
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
94 94
 		}
95
-		add_action( 'admin_notices', 'espresso_minimum_php_version_error', 1 );
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96 96
 
97 97
 	} else {
98 98
 
@@ -103,99 +103,99 @@  discard block
 block discarded – undo
103 103
 		 * @return string
104 104
 		 */
105 105
 		function espresso_version() {
106
-			return apply_filters( 'FHEE__espresso__espresso_version', '4.9.22.rc.002' );
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.002');
107 107
 		}
108 108
 
109 109
 		// define versions
110
-		define( 'EVENT_ESPRESSO_VERSION', espresso_version() );
111
-		define( 'EE_MIN_WP_VER_REQUIRED', '4.1' );
112
-		define( 'EE_MIN_WP_VER_RECOMMENDED', '4.4.2' );
113
-		define( 'EE_MIN_PHP_VER_RECOMMENDED', '5.4.44' );
114
-		define( 'EVENT_ESPRESSO_MAIN_FILE', __FILE__ );
110
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
111
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
112
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
113
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
114
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
115 115
 
116 116
 		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
117
-		if ( ! defined( 'DS' ) ) {
118
-			define( 'DS', '/' );
117
+		if ( ! defined('DS')) {
118
+			define('DS', '/');
119 119
 		}
120
-		if ( ! defined( 'PS' ) ) {
121
-			define( 'PS', PATH_SEPARATOR );
120
+		if ( ! defined('PS')) {
121
+			define('PS', PATH_SEPARATOR);
122 122
 		}
123
-		if ( ! defined( 'SP' ) ) {
124
-			define( 'SP', ' ' );
123
+		if ( ! defined('SP')) {
124
+			define('SP', ' ');
125 125
 		}
126
-		if ( ! defined( 'EENL' ) ) {
127
-			define( 'EENL', "\n" );
126
+		if ( ! defined('EENL')) {
127
+			define('EENL', "\n");
128 128
 		}
129
-		define( 'EE_SUPPORT_EMAIL', '[email protected]' );
129
+		define('EE_SUPPORT_EMAIL', '[email protected]');
130 130
 		// define the plugin directory and URL
131
-		define( 'EE_PLUGIN_BASENAME', plugin_basename( EVENT_ESPRESSO_MAIN_FILE ) );
132
-		define( 'EE_PLUGIN_DIR_PATH', plugin_dir_path( EVENT_ESPRESSO_MAIN_FILE ) );
133
-		define( 'EE_PLUGIN_DIR_URL', plugin_dir_url( EVENT_ESPRESSO_MAIN_FILE ) );
131
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
132
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
133
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
134 134
 		// main root folder paths
135
-		define( 'EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS );
136
-		define( 'EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS );
137
-		define( 'EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS );
138
-		define( 'EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS );
139
-		define( 'EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS );
140
-		define( 'EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS );
141
-		define( 'EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS );
142
-		define( 'EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS );
135
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS);
136
+		define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS);
137
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS);
138
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS);
139
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS);
140
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS);
141
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS);
142
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS);
143 143
 		// core system paths
144
-		define( 'EE_ADMIN', EE_CORE . 'admin' . DS );
145
-		define( 'EE_CPTS', EE_CORE . 'CPTs' . DS );
146
-		define( 'EE_CLASSES', EE_CORE . 'db_classes' . DS );
147
-		define( 'EE_INTERFACES', EE_CORE . 'interfaces' . DS );
148
-		define( 'EE_BUSINESS', EE_CORE . 'business' . DS );
149
-		define( 'EE_MODELS', EE_CORE . 'db_models' . DS );
150
-		define( 'EE_HELPERS', EE_CORE . 'helpers' . DS );
151
-		define( 'EE_LIBRARIES', EE_CORE . 'libraries' . DS );
152
-		define( 'EE_TEMPLATES', EE_CORE . 'templates' . DS );
153
-		define( 'EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS );
154
-		define( 'EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS );
155
-		define( 'EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS );
144
+		define('EE_ADMIN', EE_CORE.'admin'.DS);
145
+		define('EE_CPTS', EE_CORE.'CPTs'.DS);
146
+		define('EE_CLASSES', EE_CORE.'db_classes'.DS);
147
+		define('EE_INTERFACES', EE_CORE.'interfaces'.DS);
148
+		define('EE_BUSINESS', EE_CORE.'business'.DS);
149
+		define('EE_MODELS', EE_CORE.'db_models'.DS);
150
+		define('EE_HELPERS', EE_CORE.'helpers'.DS);
151
+		define('EE_LIBRARIES', EE_CORE.'libraries'.DS);
152
+		define('EE_TEMPLATES', EE_CORE.'templates'.DS);
153
+		define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS);
154
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS);
155
+		define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS);
156 156
 		// gateways
157
-		define( 'EE_GATEWAYS', EE_MODULES . 'gateways' . DS );
158
-		define( 'EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS );
157
+		define('EE_GATEWAYS', EE_MODULES.'gateways'.DS);
158
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS);
159 159
 		// asset URL paths
160
-		define( 'EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS );
161
-		define( 'EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS );
162
-		define( 'EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS );
163
-		define( 'EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS );
164
-		define( 'EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/' );
165
-		define( 'EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/' );
160
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS);
161
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS);
162
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS);
163
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS);
164
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/');
165
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/');
166 166
 		// define upload paths
167 167
 		$uploads = wp_upload_dir();
168 168
 		// define the uploads directory and URL
169
-		define( 'EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS );
170
-		define( 'EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS );
169
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS);
170
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS);
171 171
 		// define the templates directory and URL
172
-		define( 'EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS );
173
-		define( 'EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS );
172
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS);
173
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS);
174 174
 		// define the gateway directory and URL
175
-		define( 'EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS );
176
-		define( 'EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS );
175
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS);
176
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS);
177 177
 		// languages folder/path
178
-		define( 'EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS );
179
-		define( 'EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS );
178
+		define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS);
179
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS);
180 180
 		//check for dompdf fonts in uploads
181
-		if ( file_exists( EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS ) ) {
182
-			define( 'DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS );
181
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) {
182
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS);
183 183
 		}
184 184
 		//ajax constants
185 185
 		define(
186 186
 			'EE_FRONT_AJAX',
187
-			isset( $_REQUEST['ee_front_ajax'] ) || isset( $_REQUEST['data']['ee_front_ajax'] ) ? true : false
187
+			isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
188 188
 		);
189 189
 		define(
190 190
 			'EE_ADMIN_AJAX',
191
-			isset( $_REQUEST['ee_admin_ajax'] ) || isset( $_REQUEST['data']['ee_admin_ajax'] ) ? true : false
191
+			isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
192 192
 		);
193 193
 		//just a handy constant occasionally needed for finding values representing infinity in the DB
194 194
 		//you're better to use this than its straight value (currently -1) in case you ever
195 195
 		//want to change its default value! or find when -1 means infinity
196
-		define( 'EE_INF_IN_DB', -1 );
197
-		define( 'EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX );
198
-		define( 'EE_DEBUG', false );
196
+		define('EE_INF_IN_DB', -1);
197
+		define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
198
+		define('EE_DEBUG', false);
199 199
 
200 200
 
201 201
 		/**
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
 		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
204 204
 		 */
205 205
 		function espresso_plugin_activation() {
206
-			update_option( 'ee_espresso_activation', true );
206
+			update_option('ee_espresso_activation', true);
207 207
 		}
208
-		register_activation_hook( EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation' );
208
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
209 209
 
210 210
 
211 211
 
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
 		 */
216 216
 		function espresso_load_error_handling() {
217 217
 			// load debugging tools
218
-			if ( WP_DEBUG === true && is_readable( EE_HELPERS . 'EEH_Debug_Tools.helper.php' ) ) {
219
-				require_once( EE_HELPERS . 'EEH_Debug_Tools.helper.php' );
218
+			if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) {
219
+				require_once(EE_HELPERS.'EEH_Debug_Tools.helper.php');
220 220
 				EEH_Debug_Tools::instance();
221 221
 			}
222 222
 			// load error handling
223
-			if ( is_readable( EE_CORE . 'EE_Error.core.php' ) ) {
224
-				require_once( EE_CORE . 'EE_Error.core.php' );
223
+			if (is_readable(EE_CORE.'EE_Error.core.php')) {
224
+				require_once(EE_CORE.'EE_Error.core.php');
225 225
 			} else {
226
-				wp_die( esc_html__( 'The EE_Error core class could not be loaded.', 'event_espresso' ) );
226
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
227 227
 			}
228 228
 		}
229 229
 
@@ -237,16 +237,16 @@  discard block
 block discarded – undo
237 237
 		 * @param    string $full_path_to_file
238 238
 		 * @throws    EE_Error
239 239
 		 */
240
-		function espresso_load_required( $classname, $full_path_to_file ) {
240
+		function espresso_load_required($classname, $full_path_to_file) {
241 241
 			static $error_handling_loaded = false;
242
-			if ( ! $error_handling_loaded ) {
242
+			if ( ! $error_handling_loaded) {
243 243
 				espresso_load_error_handling();
244 244
 				$error_handling_loaded = true;
245 245
 			}
246
-			if ( is_readable( $full_path_to_file ) ) {
247
-				require_once( $full_path_to_file );
246
+			if (is_readable($full_path_to_file)) {
247
+				require_once($full_path_to_file);
248 248
 			} else {
249
-				throw new EE_Error (
249
+				throw new EE_Error(
250 250
 					sprintf(
251 251
 						esc_html__(
252 252
 							'The %s class file could not be located or is not readable due to file permissions.',
@@ -258,15 +258,15 @@  discard block
 block discarded – undo
258 258
 			}
259 259
 		}
260 260
 
261
-		espresso_load_required( 'EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' );
262
-		espresso_load_required( 'EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' );
263
-		espresso_load_required( 'EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php' );
261
+		espresso_load_required('EEH_Base', EE_CORE.'helpers'.DS.'EEH_Base.helper.php');
262
+		espresso_load_required('EEH_File', EE_CORE.'helpers'.DS.'EEH_File.helper.php');
263
+		espresso_load_required('EE_Bootstrap', EE_CORE.'EE_Bootstrap.core.php');
264 264
 		new EE_Bootstrap();
265 265
 
266 266
 	}
267 267
 }
268 268
 
269
-if ( ! function_exists( 'espresso_deactivate_plugin' ) ) {
269
+if ( ! function_exists('espresso_deactivate_plugin')) {
270 270
 
271 271
 	/**
272 272
 	 *    deactivate_plugin
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
 	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
277 277
 	 * @return    void
278 278
 	 */
279
-	function espresso_deactivate_plugin( $plugin_basename = '' ) {
280
-		if ( ! function_exists( 'deactivate_plugins' ) ) {
281
-			require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
279
+	function espresso_deactivate_plugin($plugin_basename = '') {
280
+		if ( ! function_exists('deactivate_plugins')) {
281
+			require_once(ABSPATH.'wp-admin/includes/plugin.php');
282 282
 		}
283
-		unset( $_GET['activate'], $_REQUEST['activate'] );
284
-		deactivate_plugins( $plugin_basename );
283
+		unset($_GET['activate'], $_REQUEST['activate']);
284
+		deactivate_plugins($plugin_basename);
285 285
 	}
286 286
 
287 287
 }
Please login to merge, or discard this patch.
core/EE_Cart.core.php 1 patch
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4
-do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
4
+do_action('AHEE_log', __FILE__, __FUNCTION__, '');
5 5
 
6 6
 
7 7
 
@@ -61,24 +61,24 @@  discard block
 block discarded – undo
61 61
 	 * @return \EE_Cart
62 62
 	 * @throws \EE_Error
63 63
 	 */
64
-	public static function instance( EE_Line_Item $grand_total = null, EE_Session $session = null ) {
65
-		if ( ! empty( $grand_total ) ) {
66
-			self::$_instance = new self( $grand_total, $session );
64
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) {
65
+		if ( ! empty($grand_total)) {
66
+			self::$_instance = new self($grand_total, $session);
67 67
 		}
68 68
 		// or maybe retrieve an existing one ?
69
-		if ( ! self::$_instance instanceof EE_Cart ) {
69
+		if ( ! self::$_instance instanceof EE_Cart) {
70 70
 			// try getting the cart out of the session
71 71
 			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
72
-			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self( $grand_total, $session );
73
-			unset( $saved_cart );
72
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
73
+			unset($saved_cart);
74 74
 		}
75 75
 		// verify that cart is ok and grand total line item exists
76
-		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item ) {
77
-			self::$_instance = new self( $grand_total, $session );
76
+		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
77
+			self::$_instance = new self($grand_total, $session);
78 78
 		}
79 79
 		self::$_instance->get_grand_total();
80 80
 		// once everything is all said and done, save the cart to the EE_Session
81
-		add_action( 'shutdown', array( self::$_instance, 'save_cart' ), 90 );
81
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
82 82
 		return self::$_instance;
83 83
 	}
84 84
 
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
 	 * @param EE_Line_Item $grand_total
93 93
 	 * @param EE_Session   $session
94 94
 	 */
95
-	private function __construct( EE_Line_Item $grand_total = null, EE_Session $session = null ) {
96
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
97
-		$this->set_session( $session );
98
-		if ( $grand_total instanceof EE_Line_Item ) {
99
-			$this->set_grand_total_line_item( $grand_total );
95
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) {
96
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
97
+		$this->set_session($session);
98
+		if ($grand_total instanceof EE_Line_Item) {
99
+			$this->set_grand_total_line_item($grand_total);
100 100
 		}
101 101
 	}
102 102
 
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 	 * @return EE_Cart
111 111
 	 * @throws \EE_Error
112 112
 	 */
113
-	public static function reset( EE_Line_Item $grand_total = null, EE_Session $session = null ) {
114
-		remove_action( 'shutdown', array( self::$_instance, 'save_cart' ), 90 );
115
-		if ( $session instanceof EE_Session ) {
113
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) {
114
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
115
+		if ($session instanceof EE_Session) {
116 116
 			$session->reset_cart();
117 117
 		}
118 118
 		self::$_instance = null;
119
-		return self::instance( $grand_total, $session );
119
+		return self::instance($grand_total, $session);
120 120
 	}
121 121
 
122 122
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 * @return \EE_Session
126 126
 	 */
127 127
 	public function session() {
128
-		if ( ! $this->_session instanceof EE_Session ) {
128
+		if ( ! $this->_session instanceof EE_Session) {
129 129
 			$this->set_session();
130 130
 		}
131 131
 		return $this->_session;
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 	/**
137 137
 	 * @param EE_Session $session
138 138
 	 */
139
-	public function set_session( EE_Session $session = null ) {
140
-		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core( 'Session' );
139
+	public function set_session(EE_Session $session = null) {
140
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
141 141
 	}
142 142
 
143 143
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @param EE_Line_Item $line_item
150 150
 	 */
151
-	public function set_grand_total_line_item( EE_Line_Item $line_item ) {
151
+	public function set_grand_total_line_item(EE_Line_Item $line_item) {
152 152
 		$this->_grand_total = $line_item;
153 153
 	}
154 154
 
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
 	 * @return \EE_Cart
164 164
 	 * @throws \EE_Error
165 165
 	 */
166
-	public static function get_cart_from_txn( EE_Transaction $transaction, EE_Session $session = null ) {
166
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) {
167 167
 		$grand_total = $transaction->total_line_item();
168 168
 		$grand_total->get_items();
169 169
 		$grand_total->tax_descendants();
170
-		return EE_Cart::instance( $grand_total, $session );
170
+		return EE_Cart::instance($grand_total, $session);
171 171
 	}
172 172
 
173 173
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 * @return \EE_Line_Item[]
193 193
 	 */
194 194
 	public function get_tickets() {
195
-		return EEH_Line_Item::get_ticket_line_items( $this->_grand_total );
195
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
196 196
 	}
197 197
 
198 198
 
@@ -206,12 +206,12 @@  discard block
 block discarded – undo
206 206
 	 */
207 207
 	public function all_ticket_quantity_count() {
208 208
 		$tickets = $this->get_tickets();
209
-		if ( empty( $tickets ) ) {
209
+		if (empty($tickets)) {
210 210
 			return 0;
211 211
 		}
212 212
 		$count = 0;
213
-		foreach ( $tickets as $ticket ) {
214
-			$count += $ticket->get( 'LIN_quantity' );
213
+		foreach ($tickets as $ticket) {
214
+			$count += $ticket->get('LIN_quantity');
215 215
 		}
216 216
 		return $count;
217 217
 	}
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @throws \EE_Error
226 226
 	 */
227 227
 	public function get_taxes() {
228
-		return EEH_Line_Item::get_taxes_subtotal( $this->_grand_total )->children();
228
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
229 229
 	}
230 230
 
231 231
 
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	 * @return TRUE on success, FALSE on fail
251 251
 	 * @throws \EE_Error
252 252
 	 */
253
-	public function add_ticket_to_cart( EE_Ticket $ticket, $qty = 1 ) {
254
-		EEH_Line_Item::add_ticket_purchase( $this->get_grand_total(), $ticket, $qty );
253
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) {
254
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
255 255
 		return $this->save_cart() ? true : false;
256 256
 	}
257 257
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @throws \EE_Error
279 279
 	 */
280 280
 	public function get_applied_taxes() {
281
-		return EEH_Line_Item::ensure_taxes_applied( $this->_grand_total );
281
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
282 282
 	}
283 283
 
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @throws \EE_Error
292 292
 	 */
293 293
 	public function get_cart_grand_total() {
294
-		EEH_Line_Item::ensure_taxes_applied( $this->_grand_total );
294
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
295 295
 		return $this->get_grand_total()->total();
296 296
 	}
297 297
 
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
 	 */
307 307
 	public function recalculate_all_cart_totals() {
308 308
 		$pre_tax_total = $this->get_cart_total_before_tax();
309
-		$taxes_total = EEH_Line_Item::ensure_taxes_applied( $this->_grand_total );
310
-		$this->_grand_total->set_total( $pre_tax_total + $taxes_total );
309
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
310
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
311 311
 		$this->_grand_total->save_this_and_descendants_to_txn();
312 312
 		return $this->get_grand_total()->total();
313 313
 	}
@@ -322,9 +322,9 @@  discard block
 block discarded – undo
322 322
 	 * @return int on success, FALSE on fail
323 323
 	 * @throws \EE_Error
324 324
 	 */
325
-	public function delete_items( $line_item_codes = false ) {
326
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
327
-		return EEH_Line_Item::delete_items( $this->get_grand_total(), $line_item_codes );
325
+	public function delete_items($line_item_codes = false) {
326
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
327
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
328 328
 	}
329 329
 
330 330
 
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 	 * @throws \EE_Error
337 337
 	 */
338 338
 	public function empty_cart() {
339
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
339
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
340 340
 		$this->_grand_total = $this->_create_grand_total();
341
-		return $this->save_cart( true );
341
+		return $this->save_cart(true);
342 342
 	}
343 343
 
344 344
 
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
 	 * @throws \EE_Error
351 351
 	 */
352 352
 	public function delete_cart() {
353
-		$deleted = EEH_Line_Item::delete_all_child_items( $this->_grand_total );
354
-		if ( $deleted ) {
353
+		$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
354
+		if ($deleted) {
355 355
 			$deleted += $this->_grand_total->delete();
356 356
 			$this->_grand_total = null;
357 357
 		}
@@ -367,18 +367,18 @@  discard block
 block discarded – undo
367 367
 	 * @return TRUE on success, FALSE on fail
368 368
 	 * @throws \EE_Error
369 369
 	 */
370
-	public function save_cart( $apply_taxes = true ) {
371
-		if ( $apply_taxes && $this->_grand_total instanceof EE_Line_Item ) {
372
-			EEH_Line_Item::ensure_taxes_applied( $this->_grand_total );
370
+	public function save_cart($apply_taxes = true) {
371
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
372
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
373 373
 			//make sure we don't cache the transaction because it can get stale
374
-			if ( $this->_grand_total->get_one_from_cache( 'Transaction' ) instanceof EE_Transaction
375
-			     && $this->_grand_total->get_one_from_cache( 'Transaction' )->ID()
374
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
375
+			     && $this->_grand_total->get_one_from_cache('Transaction')->ID()
376 376
 			) {
377
-				$this->_grand_total->clear_cache( 'Transaction', null, true );
377
+				$this->_grand_total->clear_cache('Transaction', null, true);
378 378
 			}
379 379
 		}
380
-		if ( $this->session() instanceof EE_Session ) {
381
-			return $this->session()->set_cart( $this );
380
+		if ($this->session() instanceof EE_Session) {
381
+			return $this->session()->set_cart($this);
382 382
 		} else {
383 383
 			return false;
384 384
 		}
@@ -387,9 +387,9 @@  discard block
 block discarded – undo
387 387
 
388 388
 
389 389
 	public function __wakeup() {
390
-		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0 ) {
390
+		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
391 391
 			// $this->_grand_total is actually just an ID, so use it to get the object from the db
392
-			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID( $this->_grand_total);
392
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
393 393
 		}
394 394
 	}
395 395
 
@@ -399,10 +399,10 @@  discard block
 block discarded – undo
399 399
 	 * @return array
400 400
 	 */
401 401
 	public function __sleep() {
402
-		if ( $this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID() ) {
402
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
403 403
 			$this->_grand_total = $this->_grand_total->ID();
404 404
 		}
405
-		return array( '_grand_total' );
405
+		return array('_grand_total');
406 406
 	}
407 407
 
408 408
 
Please login to merge, or discard this patch.
core/db_classes/EE_Base_Class.class.php 1 patch
Spacing   +485 added lines, -485 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
2
-do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
2
+do_action('AHEE_log', __FILE__, ' FILE LOADED', '');
3 3
 /**
4 4
  *
5 5
  * Event Espresso
@@ -110,58 +110,58 @@  discard block
 block discarded – undo
110 110
 	 *                                                 		 format.
111 111
 	 * @throws EE_Error
112 112
 	 */
113
-	protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array() ){
113
+	protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array()) {
114 114
 
115
-		$className=get_class($this);
115
+		$className = get_class($this);
116 116
 
117
-		do_action("AHEE__{$className}__construct",$this,$fieldValues);
118
-		$model=$this->get_model();
119
-		$model_fields = $model->field_settings( FALSE );
117
+		do_action("AHEE__{$className}__construct", $this, $fieldValues);
118
+		$model = $this->get_model();
119
+		$model_fields = $model->field_settings(FALSE);
120 120
 		// ensure $fieldValues is an array
121
-		$fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues );
121
+		$fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
122 122
 		// EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
123 123
 		// verify client code has not passed any invalid field names
124
-		foreach($fieldValues as $field_name=> $field_value){
125
-			if( ! isset( $model_fields[ $field_name] ) ){
126
-				throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields))));
124
+		foreach ($fieldValues as $field_name=> $field_value) {
125
+			if ( ! isset($model_fields[$field_name])) {
126
+				throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
127 127
 			}
128 128
 		}
129 129
 		// EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
130
-		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone );
130
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
131 131
 
132
-		if ( ! empty( $date_formats ) && is_array( $date_formats ) ) {
133
-			list( $this->_dt_frmt, $this->_tm_frmt ) = $date_formats;
132
+		if ( ! empty($date_formats) && is_array($date_formats)) {
133
+			list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
134 134
 		} else {
135 135
 			//set default formats for date and time
136
-			$this->_dt_frmt = (string) get_option( 'date_format', 'Y-m-d' );
137
-			$this->_tm_frmt = (string) get_option( 'time_format', 'g:i a' );
136
+			$this->_dt_frmt = (string) get_option('date_format', 'Y-m-d');
137
+			$this->_tm_frmt = (string) get_option('time_format', 'g:i a');
138 138
 		}
139 139
 
140 140
 		//if db model is instantiating
141
-		if ( $bydb ){
141
+		if ($bydb) {
142 142
 			//client code has indicated these field values are from the database
143
-			foreach( $model_fields as $fieldName => $field ){
144
-				$this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null );
143
+			foreach ($model_fields as $fieldName => $field) {
144
+				$this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
145 145
 			}
146 146
 		} else {
147 147
 			//we're constructing a brand
148 148
 			//new instance of the model object. Generally, this means we'll need to do more field validation
149
-			foreach( $model_fields as $fieldName => $field ){
150
-				$this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true );
149
+			foreach ($model_fields as $fieldName => $field) {
150
+				$this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
151 151
 			}
152 152
 		}
153 153
 
154 154
 		//remember what values were passed to this constructor
155 155
 		$this->_props_n_values_provided_in_constructor = $fieldValues;
156 156
 		//remember in entity mapper
157
-		if( ! $bydb  && $model->has_primary_key_field() && $this->ID() ){
157
+		if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
158 158
 			$model->add_to_entity_map($this);
159 159
 		}
160 160
 		//setup all the relations
161
-		foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){
162
-			if($relation_obj instanceof EE_Belongs_To_Relation){
161
+		foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) {
162
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
163 163
 				$this->_model_relations[$relation_name] = NULL;
164
-			}else{
164
+			} else {
165 165
 				$this->_model_relations[$relation_name] = array();
166 166
 			}
167 167
 		}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		 * Action done at the end of each model object construction
170 170
 		 * @param EE_Base_Class $this the model object just created
171 171
 		 */
172
-		do_action( 'AHEE__EE_Base_Class__construct__finished', $this );
172
+		do_action('AHEE__EE_Base_Class__construct__finished', $this);
173 173
 	}
174 174
 
175 175
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @param boolean $allow_persist
190 190
 	 * @return boolean
191 191
 	 */
192
-	public function set_allow_persist( $allow_persist ) {
192
+	public function set_allow_persist($allow_persist) {
193 193
 		return $this->_allow_persist = $allow_persist;
194 194
 	}
195 195
 
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 	 * @return mixed|null
204 204
 	 * @throws \EE_Error
205 205
 	 */
206
-	public function get_original( $field_name ){
207
-		if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) &&
208
-				$field_settings = $this->get_model()->field_settings_for( $field_name )){
209
-			return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] );
210
-		}else{
206
+	public function get_original($field_name) {
207
+		if (isset($this->_props_n_values_provided_in_constructor[$field_name]) &&
208
+				$field_settings = $this->get_model()->field_settings_for($field_name)) {
209
+			return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
210
+		} else {
211 211
 			return NULL;
212 212
 		}
213 213
 	}
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @param EE_Base_Class $obj
218 218
 	 * @return string
219 219
 	 */
220
-	public function get_class($obj){
220
+	public function get_class($obj) {
221 221
 		return get_class($obj);
222 222
 	}
223 223
 
@@ -232,19 +232,19 @@  discard block
 block discarded – undo
232 232
 	 * @param bool      $use_default
233 233
 	 * @throws \EE_Error
234 234
 	 */
235
-	public function set( $field_name, $field_value, $use_default = FALSE ){
236
-		$field_obj = $this->get_model()->field_settings_for( $field_name );
237
-		if ( $field_obj instanceof EE_Model_Field_Base ) {
235
+	public function set($field_name, $field_value, $use_default = FALSE) {
236
+		$field_obj = $this->get_model()->field_settings_for($field_name);
237
+		if ($field_obj instanceof EE_Model_Field_Base) {
238 238
 //			if ( method_exists( $field_obj, 'set_timezone' )) {
239
-			if ( $field_obj instanceof EE_Datetime_Field ) {
240
-				$field_obj->set_timezone( $this->_timezone );
241
-				$field_obj->set_date_format( $this->_dt_frmt );
242
-				$field_obj->set_time_format( $this->_tm_frmt );
239
+			if ($field_obj instanceof EE_Datetime_Field) {
240
+				$field_obj->set_timezone($this->_timezone);
241
+				$field_obj->set_date_format($this->_dt_frmt);
242
+				$field_obj->set_time_format($this->_tm_frmt);
243 243
 			}
244 244
 
245 245
 			$holder_of_value = $field_obj->prepare_for_set($field_value);
246 246
 			//should the value be null?
247
-			if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){
247
+			if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) {
248 248
 				$this->_fields[$field_name] = $field_obj->get_default_value();
249 249
 
250 250
 				/**
@@ -256,26 +256,26 @@  discard block
 block discarded – undo
256 256
 				 */
257 257
 				if (
258 258
 					$field_obj instanceof EE_Datetime_Field
259
-					&& $this->_fields[ $field_name ] !== null
259
+					&& $this->_fields[$field_name] !== null
260 260
 					&& ! $this->_fields[$field_name] instanceof DateTime
261 261
 				) {
262
-					empty( $this->_fields[$field_name] )
263
-						? $this->set( $field_name, time() )
264
-						: $this->set( $field_name, $this->_fields[$field_name] );
262
+					empty($this->_fields[$field_name])
263
+						? $this->set($field_name, time())
264
+						: $this->set($field_name, $this->_fields[$field_name]);
265 265
 				}
266 266
 
267
-			}else{
267
+			} else {
268 268
 				$this->_fields[$field_name] = $holder_of_value;
269 269
 			}
270 270
 
271 271
 			//if we're not in the constructor...
272 272
 			//now check if what we set was a primary key
273
-			if(
273
+			if (
274 274
 				//note: props_n_values_provided_in_constructor is only set at the END of the constructor
275 275
 				$this->_props_n_values_provided_in_constructor
276 276
 				&& $field_value
277
-				&& $field_name === self::_get_primary_key_name( get_class( $this ) )
278
-			){
277
+				&& $field_name === self::_get_primary_key_name(get_class($this))
278
+			) {
279 279
 				//if so, we want all this object's fields to be filled either with
280 280
 				//what we've explicitly set on this model
281 281
 				//or what we have in the db
@@ -283,20 +283,20 @@  discard block
 block discarded – undo
283 283
 				$fields_on_model = self::_get_model(get_class($this))->field_settings();
284 284
 
285 285
 				$obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
286
-				foreach($fields_on_model as $field_obj){
287
-					if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
288
-						&& $field_obj->get_name() !== $field_name ){
286
+				foreach ($fields_on_model as $field_obj) {
287
+					if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
288
+						&& $field_obj->get_name() !== $field_name) {
289 289
 
290
-						$this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name()));
290
+						$this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
291 291
 					}
292 292
 				}
293 293
 				//oh this model object has an ID? well make sure its in the entity mapper
294 294
 				$this->get_model()->add_to_entity_map($this);
295 295
 			}
296 296
 			//let's unset any cache for this field_name from the $_cached_properties property.
297
-			$this->_clear_cached_property( $field_name );
298
-		}else{
299
-			throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name  ) );
297
+			$this->_clear_cached_property($field_name);
298
+		} else {
299
+			throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name));
300 300
 		}
301 301
 
302 302
 	}
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
 	 * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
314 314
 	 * @throws \EE_Error
315 315
 	 */
316
-	public function set_field_or_extra_meta( $field_name, $field_value ) {
317
-		if ( $this->get_model()->has_field( $field_name ) ) {
318
-			$this->set( $field_name, $field_value );
316
+	public function set_field_or_extra_meta($field_name, $field_value) {
317
+		if ($this->get_model()->has_field($field_name)) {
318
+			$this->set($field_name, $field_value);
319 319
 			return true;
320 320
 		} else {
321 321
 			//ensure this object is saved first so that extra meta can be properly related.
322 322
 			$this->save();
323
-			return $this->update_extra_meta( $field_name, $field_value );
323
+			return $this->update_extra_meta($field_name, $field_value);
324 324
 		}
325 325
 	}
326 326
 
@@ -341,12 +341,12 @@  discard block
 block discarded – undo
341 341
 	 * @return mixed|null  value for the field if found.  null if not found.
342 342
 	 * @throws \EE_Error
343 343
 	 */
344
-	public function get_field_or_extra_meta( $field_name ) {
345
-		if ( $this->get_model()->has_field( $field_name ) ) {
346
-			$column_value = $this->get( $field_name );
344
+	public function get_field_or_extra_meta($field_name) {
345
+		if ($this->get_model()->has_field($field_name)) {
346
+			$column_value = $this->get($field_name);
347 347
 		} else {
348 348
 			//This isn't a column in the main table, let's see if it is in the extra meta.
349
-			$column_value = $this->get_extra_meta( $field_name, true, null );
349
+			$column_value = $this->get_extra_meta($field_name, true, null);
350 350
 		}
351 351
 		return $column_value;
352 352
 	}
@@ -362,18 +362,18 @@  discard block
 block discarded – undo
362 362
 	 * @return void
363 363
 	 * @throws \EE_Error
364 364
 	 */
365
-	public function set_timezone( $timezone = '' ) {
366
-		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone );
365
+	public function set_timezone($timezone = '') {
366
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
367 367
 		//make sure we clear all cached properties because they won't be relevant now
368 368
 		$this->_clear_cached_properties();
369 369
 
370 370
 		//make sure we update field settings and the date for all EE_Datetime_Fields
371
-		$model_fields = $this->get_model()->field_settings( false );
372
-		foreach ( $model_fields as $field_name => $field_obj ) {
373
-			if ( $field_obj instanceof EE_Datetime_Field ) {
374
-				$field_obj->set_timezone( $this->_timezone );
375
-				if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) {
376
-					$this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) );
371
+		$model_fields = $this->get_model()->field_settings(false);
372
+		foreach ($model_fields as $field_name => $field_obj) {
373
+			if ($field_obj instanceof EE_Datetime_Field) {
374
+				$field_obj->set_timezone($this->_timezone);
375
+				if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
376
+					$this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
377 377
 				}
378 378
 			}
379 379
 		}
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	 *
403 403
 	 * @param string $format   should be a format recognizable by PHP date() functions.
404 404
 	 */
405
-	public function set_date_format( $format ) {
405
+	public function set_date_format($format) {
406 406
 		$this->_dt_frmt = $format;
407 407
 		//clear cached_properties because they won't be relevant now.
408 408
 		$this->_clear_cached_properties();
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 	 * @since 4.6
419 419
 	 * @param string $format should be a format recognizable by PHP date() functions.
420 420
 	 */
421
-	public function set_time_format( $format ) {
421
+	public function set_time_format($format) {
422 422
 		$this->_tm_frmt = $format;
423 423
 		//clear cached_properties because they won't be relevant now.
424 424
 		$this->_clear_cached_properties();
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 	 *
436 436
 	 * @return mixed string|array
437 437
 	 */
438
-	public function get_format( $full = true ) {
439
-		return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt );
438
+	public function get_format($full = true) {
439
+		return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
440 440
 	}
441 441
 
442 442
 
@@ -454,17 +454,17 @@  discard block
 block discarded – undo
454 454
 	 * @throws EE_Error
455 455
 	 * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array)
456 456
 	 */
457
-	public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){
457
+	public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) {
458 458
 		// its entirely possible that there IS no related object yet in which case there is nothing to cache.
459
-		if ( ! $object_to_cache instanceof EE_Base_Class ) {
459
+		if ( ! $object_to_cache instanceof EE_Base_Class) {
460 460
 			return FALSE;
461 461
 		}
462 462
 		// also get "how" the object is related, or throw an error
463
-		if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) {
464
-			throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this )));
463
+		if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
464
+			throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this)));
465 465
 		}
466 466
 		// how many things are related ?
467
-		if( $relationship_to_model instanceof EE_Belongs_To_Relation ){
467
+		if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
468 468
 			// if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
469 469
 			// so for these model objects just set it to be cached
470 470
 			$this->_model_relations[$relationName] = $object_to_cache;
@@ -472,26 +472,26 @@  discard block
 block discarded – undo
472 472
 		} else {
473 473
 			// otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
474 474
 			// eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
475
-			if( ! is_array( $this->_model_relations[$relationName] )) {
475
+			if ( ! is_array($this->_model_relations[$relationName])) {
476 476
 				// if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
477
-				$this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array();
477
+				$this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array();
478 478
 			}
479 479
 			// first check for a cache_id which is normally empty
480
-			if ( ! empty( $cache_id )) {
480
+			if ( ! empty($cache_id)) {
481 481
 				// if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
482
-				$this->_model_relations[$relationName][ $cache_id ] = $object_to_cache;
482
+				$this->_model_relations[$relationName][$cache_id] = $object_to_cache;
483 483
 				$return = $cache_id;
484
-			} elseif ( $object_to_cache->ID() ) {
484
+			} elseif ($object_to_cache->ID()) {
485 485
 				// OR the cached object originally came from the db, so let's just use it's PK for an ID
486
-				$this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache;
486
+				$this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
487 487
 				$return = $object_to_cache->ID();
488 488
 			} else {
489 489
 				// OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
490 490
 				$this->_model_relations[$relationName][] = $object_to_cache;
491 491
 				  // move the internal pointer to the end of the array
492
-				end( $this->_model_relations[$relationName] );
492
+				end($this->_model_relations[$relationName]);
493 493
 				// and grab the key so that we can return it
494
-				$return = key( $this->_model_relations[$relationName] );
494
+				$return = key($this->_model_relations[$relationName]);
495 495
 			}
496 496
 
497 497
 		}
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
 	 * @return void
511 511
 	 * @throws \EE_Error
512 512
 	 */
513
-	protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) {
513
+	protected function _set_cached_property($fieldname, $value, $cache_type = NULL) {
514 514
 		//first make sure this property exists
515 515
 		$this->get_model()->field_settings_for($fieldname);
516 516
 
517
-		$cache_type = empty( $cache_type ) ? 'standard' : $cache_type;
517
+		$cache_type = empty($cache_type) ? 'standard' : $cache_type;
518 518
 		$this->_cached_properties[$fieldname][$cache_type] = $value;
519 519
 	}
520 520
 
@@ -535,36 +535,36 @@  discard block
 block discarded – undo
535 535
 	 * @return mixed                   whatever the value for the property is we're retrieving
536 536
 	 * @throws \EE_Error
537 537
 	 */
538
-	protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) {
538
+	protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) {
539 539
 		//verify the field exists
540 540
 		$this->get_model()->field_settings_for($fieldname);
541 541
 
542 542
 		$cache_type = $pretty ? 'pretty' : 'standard';
543
-		$cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : '';
543
+		$cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : '';
544 544
 
545
-		if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) {
545
+		if (isset($this->_cached_properties[$fieldname][$cache_type])) {
546 546
 			return $this->_cached_properties[$fieldname][$cache_type];
547 547
 		}
548 548
 
549 549
 		$field_obj = $this->get_model()->field_settings_for($fieldname);
550
-		if ( $field_obj instanceof EE_Model_Field_Base ) {
550
+		if ($field_obj instanceof EE_Model_Field_Base) {
551 551
 			/**
552 552
 			 * maybe this is EE_Datetime_Field.  If so we need to make sure timezone and
553 553
 			 * formats are correct.
554 554
 			 */
555
-			if ( $field_obj instanceof EE_Datetime_Field ) {
556
-				$field_obj->set_timezone( $this->_timezone );
557
-				$field_obj->set_date_format( $this->_dt_frmt, $pretty );
558
-				$field_obj->set_time_format( $this->_tm_frmt, $pretty );
555
+			if ($field_obj instanceof EE_Datetime_Field) {
556
+				$field_obj->set_timezone($this->_timezone);
557
+				$field_obj->set_date_format($this->_dt_frmt, $pretty);
558
+				$field_obj->set_time_format($this->_tm_frmt, $pretty);
559 559
 			}
560 560
 
561
-			if( ! isset($this->_fields[$fieldname])){
561
+			if ( ! isset($this->_fields[$fieldname])) {
562 562
 				$this->_fields[$fieldname] = NULL;
563 563
 			}
564 564
 			$value = $pretty
565 565
 				? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
566
-				: $field_obj->prepare_for_get($this->_fields[$fieldname] );
567
-			$this->_set_cached_property( $fieldname, $value, $cache_type );
566
+				: $field_obj->prepare_for_get($this->_fields[$fieldname]);
567
+			$this->_set_cached_property($fieldname, $value, $cache_type);
568 568
 			return $value;
569 569
 		}
570 570
 		return null;
@@ -590,9 +590,9 @@  discard block
 block discarded – undo
590 590
 	 * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
591 591
 	 * @return void
592 592
 	 */
593
-	protected function _clear_cached_property( $property_name ) {
594
-		if ( isset( $this->_cached_properties[ $property_name ] ) ) {
595
-			unset( $this->_cached_properties[ $property_name ] );
593
+	protected function _clear_cached_property($property_name) {
594
+		if (isset($this->_cached_properties[$property_name])) {
595
+			unset($this->_cached_properties[$property_name]);
596 596
 		}
597 597
 	}
598 598
 
@@ -606,12 +606,12 @@  discard block
 block discarded – undo
606 606
 	 * @return EE_Base_Class
607 607
 	 * @throws \EE_Error
608 608
 	 */
609
-	protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){
609
+	protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) {
610 610
 		$other_model_instance = self::_get_model_instance_with_name(
611
-			self::_get_model_classname( $model_name ),
611
+			self::_get_model_classname($model_name),
612 612
 			$this->_timezone
613 613
 		);
614
-		return $other_model_instance->ensure_is_obj( $object_or_id );
614
+		return $other_model_instance->ensure_is_obj($object_or_id);
615 615
 	}
616 616
 
617 617
 
@@ -628,32 +628,32 @@  discard block
 block discarded – undo
628 628
 	 * @throws EE_Error
629 629
 	 * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all
630 630
 	 */
631
-	public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){
631
+	public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) {
632 632
 		$relationship_to_model = $this->get_model()->related_settings_for($relationName);
633 633
 		$index_in_cache = '';
634
-		if( ! $relationship_to_model){
634
+		if ( ! $relationship_to_model) {
635 635
 			throw new EE_Error(
636 636
 				sprintf(
637
-					__( "There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso' ),
637
+					__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
638 638
 					$relationName,
639
-					get_class( $this )
639
+					get_class($this)
640 640
 				)
641 641
 			);
642 642
 		}
643
-		if($clear_all){
643
+		if ($clear_all) {
644 644
 			$obj_removed = true;
645 645
 			$this->_model_relations[$relationName]  = null;
646
-		}elseif($relationship_to_model instanceof EE_Belongs_To_Relation){
646
+		}elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
647 647
 			$obj_removed = $this->_model_relations[$relationName];
648 648
 			$this->_model_relations[$relationName]  = null;
649
-		}else{
650
-			if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){
649
+		} else {
650
+			if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) {
651 651
 				$index_in_cache = $object_to_remove_or_index_into_array->ID();
652
-				if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){
652
+				if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) {
653 653
 					$index_found_at = NULL;
654 654
 					//find this object in the array even though it has a different key
655
-					foreach($this->_model_relations[$relationName] as $index=>$obj){
656
-						if(
655
+					foreach ($this->_model_relations[$relationName] as $index=>$obj) {
656
+						if (
657 657
 							$obj instanceof EE_Base_Class
658 658
 							&& (
659 659
 								$obj == $object_to_remove_or_index_into_array
@@ -664,34 +664,34 @@  discard block
 block discarded – undo
664 664
 							break;
665 665
 						}
666 666
 					}
667
-					if($index_found_at){
667
+					if ($index_found_at) {
668 668
 						$index_in_cache = $index_found_at;
669
-					}else{
669
+					} else {
670 670
 						//it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
671 671
 						//if it wasn't in it to begin with. So we're done
672 672
 						return $object_to_remove_or_index_into_array;
673 673
 					}
674 674
 				}
675
-			}elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){
675
+			}elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
676 676
 				//so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
677
-				foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){
678
-					if($potentially_obj_we_want == $object_to_remove_or_index_into_array){
677
+				foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
678
+					if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
679 679
 						$index_in_cache = $index;
680 680
 					}
681 681
 				}
682
-			}else{
682
+			} else {
683 683
 				$index_in_cache = $object_to_remove_or_index_into_array;
684 684
 			}
685 685
 			//supposedly we've found it. But it could just be that the client code
686 686
 			//provided a bad index/object
687 687
 			if (
688 688
 				isset(
689
-					$this->_model_relations[ $relationName ],
690
-					$this->_model_relations[ $relationName ][ $index_in_cache ]
689
+					$this->_model_relations[$relationName],
690
+					$this->_model_relations[$relationName][$index_in_cache]
691 691
 				)
692 692
 			) {
693
-				$obj_removed = $this->_model_relations[ $relationName ][ $index_in_cache ];
694
-				unset( $this->_model_relations[ $relationName ][ $index_in_cache ] );
693
+				$obj_removed = $this->_model_relations[$relationName][$index_in_cache];
694
+				unset($this->_model_relations[$relationName][$index_in_cache]);
695 695
 			} else {
696 696
 				//that thing was never cached anyways.
697 697
 				$obj_removed = null;
@@ -712,24 +712,24 @@  discard block
 block discarded – undo
712 712
 	 * @return boolean TRUE on success, FALSE on fail
713 713
 	 * @throws \EE_Error
714 714
 	 */
715
-	public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') {
715
+	public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') {
716 716
 		// verify that incoming object is of the correct type
717
-		$obj_class = 'EE_' . $relationName;
718
-		if ( $newly_saved_object instanceof $obj_class ) {
717
+		$obj_class = 'EE_'.$relationName;
718
+		if ($newly_saved_object instanceof $obj_class) {
719 719
 			/* @type EE_Base_Class $newly_saved_object*/
720 720
 			// now get the type of relation
721
-			$relationship_to_model = $this->get_model()->related_settings_for( $relationName );
721
+			$relationship_to_model = $this->get_model()->related_settings_for($relationName);
722 722
 			// if this is a 1:1 relationship
723
-			if( $relationship_to_model instanceof EE_Belongs_To_Relation ) {
723
+			if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
724 724
 				// then just replace the cached object with the newly saved object
725 725
 				$this->_model_relations[$relationName] = $newly_saved_object;
726 726
 				return TRUE;
727 727
 			// or if it's some kind of sordid feral polyamorous relationship...
728
-			} elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) {
728
+			} elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) {
729 729
 				// then remove the current cached item
730
-				unset( $this->_model_relations[$relationName][ $current_cache_id ] );
730
+				unset($this->_model_relations[$relationName][$current_cache_id]);
731 731
 				// and cache the newly saved object using it's new ID
732
-				$this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object;
732
+				$this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
733 733
 				return TRUE;
734 734
 			}
735 735
 		}
@@ -745,11 +745,11 @@  discard block
 block discarded – undo
745 745
 	 * @param string $relationName
746 746
 	 * @return EE_Base_Class
747 747
 	 */
748
-	public function get_one_from_cache($relationName){
749
-		$cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null;
750
-		if(is_array($cached_array_or_object)){
748
+	public function get_one_from_cache($relationName) {
749
+		$cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null;
750
+		if (is_array($cached_array_or_object)) {
751 751
 			return array_shift($cached_array_or_object);
752
-		}else{
752
+		} else {
753 753
 			return $cached_array_or_object;
754 754
 		}
755 755
 	}
@@ -764,23 +764,23 @@  discard block
 block discarded – undo
764 764
 	 * @throws \EE_Error
765 765
 	 * @return EE_Base_Class[] NOT necessarily indexed by primary keys
766 766
 	 */
767
-	public function get_all_from_cache($relationName){
768
-		$objects = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array();
767
+	public function get_all_from_cache($relationName) {
768
+		$objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
769 769
 		// if the result is not an array, but exists, make it an array
770
-		$objects = is_array( $objects ) ? $objects : array( $objects );
770
+		$objects = is_array($objects) ? $objects : array($objects);
771 771
 		//bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
772 772
 		//basically, if this model object was stored in the session, and these cached model objects
773 773
 		//already have IDs, let's make sure they're in their model's entity mapper
774 774
 		//otherwise we will have duplicates next time we call
775 775
 		// EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
776
-		$model = EE_Registry::instance()->load_model( $relationName );
777
-		foreach( $objects as $model_object ){
778
-			if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){
776
+		$model = EE_Registry::instance()->load_model($relationName);
777
+		foreach ($objects as $model_object) {
778
+			if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
779 779
 				//ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
780
-				if( $model_object->ID() ){
781
-					$model->add_to_entity_map( $model_object );
780
+				if ($model_object->ID()) {
781
+					$model->add_to_entity_map($model_object);
782 782
 				}
783
-			}else{
783
+			} else {
784 784
 				throw new EE_Error(
785 785
 					sprintf(
786 786
 						__(
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 							'event_espresso'
789 789
 						),
790 790
 						$relationName,
791
-						gettype( $model_object )
791
+						gettype($model_object)
792 792
 					)
793 793
 				);
794 794
 			}
@@ -810,15 +810,15 @@  discard block
 block discarded – undo
810 810
 	 * @return array|EE_Base_Class[]
811 811
 	 * @throws \EE_Error
812 812
 	 */
813
-	public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
814
-		$field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field()
813
+	public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
814
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
815 815
 			? $this->get_model()->get_primary_key_field()->get_name()
816 816
 			: $field_to_order_by;
817
-		$current_value = ! empty( $field ) ? $this->get( $field ) : null;
818
-		if ( empty( $field ) || empty( $current_value ) ) {
817
+		$current_value = ! empty($field) ? $this->get($field) : null;
818
+		if (empty($field) || empty($current_value)) {
819 819
 			return array();
820 820
 		}
821
-		return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select );
821
+		return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
822 822
 	}
823 823
 
824 824
 
@@ -835,15 +835,15 @@  discard block
 block discarded – undo
835 835
 	 * @return array|EE_Base_Class[]
836 836
 	 * @throws \EE_Error
837 837
 	 */
838
-	public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
839
-		$field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field()
838
+	public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
839
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
840 840
 			? $this->get_model()->get_primary_key_field()->get_name()
841 841
 			: $field_to_order_by;
842
-		$current_value = ! empty( $field ) ? $this->get( $field ) : null;
843
-		if ( empty( $field ) || empty( $current_value ) ) {
842
+		$current_value = ! empty($field) ? $this->get($field) : null;
843
+		if (empty($field) || empty($current_value)) {
844 844
 			return array();
845 845
 		}
846
-		return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select );
846
+		return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
847 847
 	}
848 848
 
849 849
 
@@ -859,15 +859,15 @@  discard block
 block discarded – undo
859 859
 	 * @return array|EE_Base_Class
860 860
 	 * @throws \EE_Error
861 861
 	 */
862
-	public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
863
-		$field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field()
862
+	public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
863
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
864 864
 			? $this->get_model()->get_primary_key_field()->get_name()
865 865
 			: $field_to_order_by;
866
-		$current_value = ! empty( $field ) ? $this->get( $field ) : null;
867
-		if ( empty( $field ) || empty( $current_value ) ) {
866
+		$current_value = ! empty($field) ? $this->get($field) : null;
867
+		if (empty($field) || empty($current_value)) {
868 868
 			return array();
869 869
 		}
870
-		return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select );
870
+		return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
871 871
 	}
872 872
 
873 873
 
@@ -883,15 +883,15 @@  discard block
 block discarded – undo
883 883
 	 * @return array|EE_Base_Class
884 884
 	 * @throws \EE_Error
885 885
 	 */
886
-	public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
887
-		$field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field()
886
+	public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
887
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
888 888
 			? $this->get_model()->get_primary_key_field()->get_name()
889 889
 			: $field_to_order_by;
890
-		$current_value = ! empty( $field ) ? $this->get( $field ) : null;
891
-		if ( empty( $field ) || empty( $current_value ) ) {
890
+		$current_value = ! empty($field) ? $this->get($field) : null;
891
+		if (empty($field) || empty($current_value)) {
892 892
 			return array();
893 893
 		}
894
-		return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select );
894
+		return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
895 895
 	}
896 896
 
897 897
 
@@ -904,25 +904,25 @@  discard block
 block discarded – undo
904 904
 	 * @param mixed  $field_value_from_db
905 905
 	 * @throws \EE_Error
906 906
 	 */
907
-	public function set_from_db($field_name,$field_value_from_db){
907
+	public function set_from_db($field_name, $field_value_from_db) {
908 908
 		$field_obj = $this->get_model()->field_settings_for($field_name);
909
-		if ( $field_obj instanceof EE_Model_Field_Base ) {
909
+		if ($field_obj instanceof EE_Model_Field_Base) {
910 910
 			//you would think the DB has no NULLs for non-null label fields right? wrong!
911 911
 			//eg, a CPT model object could have an entry in the posts table, but no
912 912
 			//entry in the meta table. Meaning that all its columns in the meta table
913 913
 			//are null! yikes! so when we find one like that, use defaults for its meta columns
914
-			if($field_value_from_db === NULL ){
915
-				if( $field_obj->is_nullable()){
914
+			if ($field_value_from_db === NULL) {
915
+				if ($field_obj->is_nullable()) {
916 916
 					//if the field allows nulls, then let it be null
917 917
 					$field_value = NULL;
918
-				}else{
918
+				} else {
919 919
 					$field_value = $field_obj->get_default_value();
920 920
 				}
921
-			}else{
922
-				$field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db );
921
+			} else {
922
+				$field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
923 923
 			}
924 924
 			$this->_fields[$field_name] = $field_value;
925
-			$this->_clear_cached_property( $field_name );
925
+			$this->_clear_cached_property($field_name);
926 926
 		}
927 927
 	}
928 928
 
@@ -938,8 +938,8 @@  discard block
 block discarded – undo
938 938
 	 * @return mixed
939 939
 	 * @throws \EE_Error
940 940
 	 */
941
-	public function get($field_name, $extra_cache_ref = NULL ){
942
-		return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref );
941
+	public function get($field_name, $extra_cache_ref = NULL) {
942
+		return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref);
943 943
 	}
944 944
 
945 945
 
@@ -972,10 +972,10 @@  discard block
 block discarded – undo
972 972
 	 *                                         just null is returned (because that indicates that likely
973 973
 	 *                                         this field is nullable).
974 974
 	 */
975
-	public function get_DateTime_object( $field_name ) {
976
-		$field_settings = $this->get_model()->field_settings_for( $field_name );
975
+	public function get_DateTime_object($field_name) {
976
+		$field_settings = $this->get_model()->field_settings_for($field_name);
977 977
 
978
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
978
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
979 979
 			EE_Error::add_error(
980 980
 				sprintf(
981 981
 					__(
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
 	 * @return void
1008 1008
 	 * @throws \EE_Error
1009 1009
 	 */
1010
-	public function e($field_name, $extra_cache_ref = NULL){
1010
+	public function e($field_name, $extra_cache_ref = NULL) {
1011 1011
 		echo $this->get_pretty($field_name, $extra_cache_ref);
1012 1012
 	}
1013 1013
 
@@ -1021,8 +1021,8 @@  discard block
 block discarded – undo
1021 1021
 	 * @return void
1022 1022
 	 * @throws \EE_Error
1023 1023
 	 */
1024
-	public function f($field_name){
1025
-		$this->e($field_name,'form_input');
1024
+	public function f($field_name) {
1025
+		$this->e($field_name, 'form_input');
1026 1026
 	}
1027 1027
 
1028 1028
 
@@ -1035,8 +1035,8 @@  discard block
 block discarded – undo
1035 1035
 	 * @return mixed
1036 1036
 	 * @throws \EE_Error
1037 1037
 	 */
1038
-	public function get_pretty($field_name, $extra_cache_ref = NULL){
1039
-		return  $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref );
1038
+	public function get_pretty($field_name, $extra_cache_ref = NULL) {
1039
+		return  $this->_get_cached_property($field_name, TRUE, $extra_cache_ref);
1040 1040
 	}
1041 1041
 
1042 1042
 
@@ -1058,36 +1058,36 @@  discard block
 block discarded – undo
1058 1058
 	 *                               if field is not a valid dtt field, or void if echoing
1059 1059
 	 * @throws \EE_Error
1060 1060
 	 */
1061
-	protected function _get_datetime( $field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false ) {
1061
+	protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) {
1062 1062
 
1063
-		$in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt :  $dt_frmt;
1063
+		$in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt;
1064 1064
 		$in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt;
1065 1065
 
1066 1066
 		//validate field for datetime and returns field settings if valid.
1067
-		$field = $this->_get_dtt_field_settings( $field_name );
1067
+		$field = $this->_get_dtt_field_settings($field_name);
1068 1068
 
1069 1069
 		//clear cached property if either formats are not null.
1070
-		if( $dt_frmt !== null || $tm_frmt !== null ) {
1071
-			$this->_clear_cached_property( $field_name );
1070
+		if ($dt_frmt !== null || $tm_frmt !== null) {
1071
+			$this->_clear_cached_property($field_name);
1072 1072
 			//reset format properties because they are used in get()
1073 1073
 			$this->_dt_frmt = $in_dt_frmt;
1074 1074
 			$this->_tm_frmt = $in_tm_frmt;
1075 1075
 		}
1076
-		if ( $echo ) {
1077
-			$field->set_pretty_date_format( $in_dt_frmt );
1076
+		if ($echo) {
1077
+			$field->set_pretty_date_format($in_dt_frmt);
1078 1078
 		} else {
1079
-			$field->set_date_format( $in_dt_frmt );
1079
+			$field->set_date_format($in_dt_frmt);
1080 1080
 		}
1081
-		if ( $echo ) {
1082
-			$field->set_pretty_time_format( $in_tm_frmt );
1081
+		if ($echo) {
1082
+			$field->set_pretty_time_format($in_tm_frmt);
1083 1083
 		} else {
1084
-			$field->set_time_format( $in_tm_frmt );
1084
+			$field->set_time_format($in_tm_frmt);
1085 1085
 		}
1086 1086
 		//set timezone in field object
1087
-		$field->set_timezone( $this->_timezone );
1087
+		$field->set_timezone($this->_timezone);
1088 1088
 
1089 1089
 		//set the output returned
1090
-		switch ( $date_or_time ) {
1090
+		switch ($date_or_time) {
1091 1091
 
1092 1092
 			case 'D' :
1093 1093
 				$field->set_date_time_output('date');
@@ -1102,11 +1102,11 @@  discard block
 block discarded – undo
1102 1102
 		}
1103 1103
 
1104 1104
 
1105
-		if ( $echo ) {
1106
-			$this->e( $field_name, $date_or_time );
1105
+		if ($echo) {
1106
+			$this->e($field_name, $date_or_time);
1107 1107
 			return '';
1108 1108
 		 }
1109
-		return $this->get( $field_name, $date_or_time );
1109
+		return $this->get($field_name, $date_or_time);
1110 1110
 	}
1111 1111
 
1112 1112
 
@@ -1119,8 +1119,8 @@  discard block
 block discarded – undo
1119 1119
 	 * @return string            datetime value formatted
1120 1120
 	 * @throws \EE_Error
1121 1121
 	 */
1122
-	public function get_date( $field_name, $format = NULL ) {
1123
-		return $this->_get_datetime( $field_name, $format, NULL, 'D' );
1122
+	public function get_date($field_name, $format = NULL) {
1123
+		return $this->_get_datetime($field_name, $format, NULL, 'D');
1124 1124
 	}
1125 1125
 
1126 1126
 
@@ -1130,8 +1130,8 @@  discard block
 block discarded – undo
1130 1130
 	 * @param null $format
1131 1131
 	 * @throws \EE_Error
1132 1132
 	 */
1133
-	public function e_date( $field_name, $format = NULL ) {
1134
-		$this->_get_datetime( $field_name, $format, NULL, 'D', TRUE );
1133
+	public function e_date($field_name, $format = NULL) {
1134
+		$this->_get_datetime($field_name, $format, NULL, 'D', TRUE);
1135 1135
 	}
1136 1136
 
1137 1137
 
@@ -1144,8 +1144,8 @@  discard block
 block discarded – undo
1144 1144
 	 * @return string             datetime value formatted
1145 1145
 	 * @throws \EE_Error
1146 1146
 	 */
1147
-	public function get_time( $field_name, $format = NULL ) {
1148
-		return $this->_get_datetime( $field_name, NULL, $format, 'T' );
1147
+	public function get_time($field_name, $format = NULL) {
1148
+		return $this->_get_datetime($field_name, NULL, $format, 'T');
1149 1149
 	}
1150 1150
 
1151 1151
 
@@ -1155,8 +1155,8 @@  discard block
 block discarded – undo
1155 1155
 	 * @param null $format
1156 1156
 	 * @throws \EE_Error
1157 1157
 	 */
1158
-	public function e_time( $field_name, $format = NULL ) {
1159
-		$this->_get_datetime( $field_name, NULL, $format, 'T', TRUE );
1158
+	public function e_time($field_name, $format = NULL) {
1159
+		$this->_get_datetime($field_name, NULL, $format, 'T', TRUE);
1160 1160
 	}
1161 1161
 
1162 1162
 
@@ -1170,8 +1170,8 @@  discard block
 block discarded – undo
1170 1170
 	 * @return string             datetime value formatted
1171 1171
 	 * @throws \EE_Error
1172 1172
 	 */
1173
-	public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) {
1174
-		return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt );
1173
+	public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) {
1174
+		return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1175 1175
 	}
1176 1176
 
1177 1177
 
@@ -1182,8 +1182,8 @@  discard block
 block discarded – undo
1182 1182
 	 * @param null $tm_frmt
1183 1183
 	 * @throws \EE_Error
1184 1184
 	 */
1185
-	public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) {
1186
-		$this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE);
1185
+	public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) {
1186
+		$this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE);
1187 1187
 	}
1188 1188
 
1189 1189
 
@@ -1197,11 +1197,11 @@  discard block
 block discarded – undo
1197 1197
 	 * @throws \EE_Error
1198 1198
 	 *                           field name.
1199 1199
 	 */
1200
-	public function get_i18n_datetime( $field_name, $format = NULL ) {
1201
-		$format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1200
+	public function get_i18n_datetime($field_name, $format = NULL) {
1201
+		$format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format;
1202 1202
 		return date_i18n(
1203 1203
 			$format,
1204
-			EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone )
1204
+			EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1205 1205
 		);
1206 1206
 	}
1207 1207
 
@@ -1214,14 +1214,14 @@  discard block
 block discarded – undo
1214 1214
 	 * @throws EE_Error
1215 1215
 	 * @return EE_Datetime_Field
1216 1216
 	 */
1217
-	protected function _get_dtt_field_settings( $field_name ) {
1217
+	protected function _get_dtt_field_settings($field_name) {
1218 1218
 		$field = $this->get_model()->field_settings_for($field_name);
1219 1219
 
1220 1220
 		//check if field is dtt
1221
-		if ( $field instanceof EE_Datetime_Field ) {
1221
+		if ($field instanceof EE_Datetime_Field) {
1222 1222
 			return $field;
1223 1223
 		} else {
1224
-			throw new EE_Error( sprintf( __('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) );
1224
+			throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1225 1225
 		}
1226 1226
 	}
1227 1227
 
@@ -1242,8 +1242,8 @@  discard block
 block discarded – undo
1242 1242
 	 * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1243 1243
 	 * @throws \EE_Error
1244 1244
 	 */
1245
-	protected function _set_time_for( $time, $fieldname ) {
1246
-		$this->_set_date_time( 'T', $time, $fieldname );
1245
+	protected function _set_time_for($time, $fieldname) {
1246
+		$this->_set_date_time('T', $time, $fieldname);
1247 1247
 	}
1248 1248
 
1249 1249
 
@@ -1256,8 +1256,8 @@  discard block
 block discarded – undo
1256 1256
 	 * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1257 1257
 	 * @throws \EE_Error
1258 1258
 	 */
1259
-	protected function _set_date_for( $date, $fieldname ) {
1260
-		$this->_set_date_time( 'D', $date, $fieldname );
1259
+	protected function _set_date_for($date, $fieldname) {
1260
+		$this->_set_date_time('D', $date, $fieldname);
1261 1261
 	}
1262 1262
 
1263 1263
 
@@ -1271,26 +1271,26 @@  discard block
 block discarded – undo
1271 1271
 	 * @param string          $fieldname      the name of the field the date OR time is being set on (must match a EE_Datetime_Field property)
1272 1272
 	 * @throws \EE_Error
1273 1273
 	 */
1274
-	protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) {
1275
-		$field = $this->_get_dtt_field_settings( $fieldname );
1276
-		$field->set_timezone( $this->_timezone );
1277
-		$field->set_date_format( $this->_dt_frmt );
1278
-		$field->set_time_format( $this->_tm_frmt );
1279
-		switch ( $what ) {
1274
+	protected function _set_date_time($what = 'T', $datetime_value, $fieldname) {
1275
+		$field = $this->_get_dtt_field_settings($fieldname);
1276
+		$field->set_timezone($this->_timezone);
1277
+		$field->set_date_format($this->_dt_frmt);
1278
+		$field->set_time_format($this->_tm_frmt);
1279
+		switch ($what) {
1280 1280
 			case 'T' :
1281
-				$this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_time(
1281
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1282 1282
 					$datetime_value,
1283
-					$this->_fields[ $fieldname ]
1283
+					$this->_fields[$fieldname]
1284 1284
 				);
1285 1285
 				break;
1286 1286
 			case 'D' :
1287
-				$this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_date(
1287
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1288 1288
 					$datetime_value,
1289
-					$this->_fields[ $fieldname ]
1289
+					$this->_fields[$fieldname]
1290 1290
 				);
1291 1291
 				break;
1292 1292
 			case 'B' :
1293
-				$this->_fields[ $fieldname ] = $field->prepare_for_set( $datetime_value );
1293
+				$this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1294 1294
 				break;
1295 1295
 		}
1296 1296
 		$this->_clear_cached_property($fieldname);
@@ -1312,17 +1312,17 @@  discard block
 block discarded – undo
1312 1312
 	 * @throws EE_Error
1313 1313
 	 * @return string timestamp
1314 1314
 	 */
1315
-	public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) {
1315
+	public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') {
1316 1316
 		$timezone = EEH_DTT_Helper::get_timezone();
1317
-		if ( $timezone === $this->_timezone ) {
1317
+		if ($timezone === $this->_timezone) {
1318 1318
 			return '';
1319 1319
 		}
1320 1320
 		$original_timezone = $this->_timezone;
1321
-		$this->set_timezone( $timezone );
1321
+		$this->set_timezone($timezone);
1322 1322
 
1323 1323
 		$fn = (array) $field_name;
1324
-		$args = array_merge( $fn, (array) $args );
1325
-		if ( ! method_exists( $this, $callback ) ) {
1324
+		$args = array_merge($fn, (array) $args);
1325
+		if ( ! method_exists($this, $callback)) {
1326 1326
 			throw new EE_Error(
1327 1327
 				sprintf(
1328 1328
 					__(
@@ -1334,9 +1334,9 @@  discard block
 block discarded – undo
1334 1334
 			);
1335 1335
 		}
1336 1336
 		$args = (array) $args;
1337
-		$return =  $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append;
1337
+		$return = $prepend.call_user_func_array(array($this, $callback), $args).$append;
1338 1338
 
1339
-		$this->set_timezone( $original_timezone );
1339
+		$this->set_timezone($original_timezone);
1340 1340
 		return $return;
1341 1341
 	}
1342 1342
 
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
 	 * @return boolean | int
1351 1351
 	 * @throws \EE_Error
1352 1352
 	 */
1353
-	public function delete(){
1353
+	public function delete() {
1354 1354
 		/**
1355 1355
 		 * Called just before the `EE_Base_Class::_delete` method call.
1356 1356
 		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
 		 *
1360 1360
 		 * @param EE_Base_Class $model_object about to be 'deleted'
1361 1361
 		 */
1362
-		do_action( 'AHEE__EE_Base_Class__delete__before', $this );
1362
+		do_action('AHEE__EE_Base_Class__delete__before', $this);
1363 1363
 		$result = $this->_delete();
1364 1364
 		/**
1365 1365
 		 * Called just after the `EE_Base_Class::_delete` method call.
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
 		 * @param EE_Base_Class $model_object that was just 'deleted'
1370 1370
 		 * @param boolean $result
1371 1371
 		 */
1372
-		do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result );
1372
+		do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1373 1373
 		return $result;
1374 1374
 	}
1375 1375
 
@@ -1395,22 +1395,22 @@  discard block
 block discarded – undo
1395 1395
 	 * @return bool | int
1396 1396
 	 * @throws \EE_Error
1397 1397
 	 */
1398
-	public function delete_permanently(){
1398
+	public function delete_permanently() {
1399 1399
 		/**
1400 1400
 		 * Called just before HARD deleting a model object
1401 1401
 		 *
1402 1402
 		 * @param EE_Base_Class $model_object about to be 'deleted'
1403 1403
 		 */
1404
-		do_action( 'AHEE__EE_Base_Class__delete_permanently__before', $this );
1405
-		$model=$this->get_model();
1406
-		$result=$model->delete_permanently_by_ID($this->ID());
1404
+		do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1405
+		$model = $this->get_model();
1406
+		$result = $model->delete_permanently_by_ID($this->ID());
1407 1407
 		$this->refresh_cache_of_related_objects();
1408 1408
 		/**
1409 1409
 		 * Called just after HARD deleting a model object
1410 1410
 		 * @param EE_Base_Class $model_object that was just 'deleted'
1411 1411
 		 * @param boolean $result
1412 1412
 		 */
1413
-		do_action( 'AHEE__EE_Base_Class__delete_permanently__end', $this, $result );
1413
+		do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1414 1414
 		return $result;
1415 1415
 	}
1416 1416
 
@@ -1423,18 +1423,18 @@  discard block
 block discarded – undo
1423 1423
 	 * @throws \EE_Error
1424 1424
 	 */
1425 1425
         public function refresh_cache_of_related_objects() {
1426
-            foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) {
1427
-                if( ! empty( $this->_model_relations[ $relation_name ] ) ) {
1428
-                    $related_objects = $this->_model_relations[ $relation_name ];
1429
-                    if( $relation_obj instanceof EE_Belongs_To_Relation ) {
1426
+            foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1427
+                if ( ! empty($this->_model_relations[$relation_name])) {
1428
+                    $related_objects = $this->_model_relations[$relation_name];
1429
+                    if ($relation_obj instanceof EE_Belongs_To_Relation) {
1430 1430
                         //this relation only stores a single model object, not an array
1431 1431
                         //but let's make it consistent
1432
-                        $related_objects = array( $related_objects );
1432
+                        $related_objects = array($related_objects);
1433 1433
                     }
1434
-                    foreach( $related_objects as $related_object ) {
1434
+                    foreach ($related_objects as $related_object) {
1435 1435
                         //only refresh their cache if they're in memory
1436
-                        if( $related_object instanceof EE_Base_Class ) {
1437
-							$related_object->clear_cache( $this->get_model()->get_this_model_name(), $this );
1436
+                        if ($related_object instanceof EE_Base_Class) {
1437
+							$related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1438 1438
                         }
1439 1439
                     }
1440 1440
                 }
@@ -1454,17 +1454,17 @@  discard block
 block discarded – undo
1454 1454
 	 * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1455 1455
 	 * isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1456 1456
 	 */
1457
-	public function save($set_cols_n_values=array()) {
1457
+	public function save($set_cols_n_values = array()) {
1458 1458
 		/**
1459 1459
 		 * Filters the fields we're about to save on the model object
1460 1460
 		 *
1461 1461
 		 * @param array $set_cols_n_values
1462 1462
 		 * @param EE_Base_Class $model_object
1463 1463
 		 */
1464
-		$set_cols_n_values = (array)apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this  );
1464
+		$set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this);
1465 1465
 		//set attributes as provided in $set_cols_n_values
1466
-		foreach($set_cols_n_values as $column=>$value){
1467
-			$this->set($column,$value);
1466
+		foreach ($set_cols_n_values as $column=>$value) {
1467
+			$this->set($column, $value);
1468 1468
 		}
1469 1469
 		/**
1470 1470
 		 * Saving a model object.
@@ -1472,8 +1472,8 @@  discard block
 block discarded – undo
1472 1472
 		 * Before we perform a save, this action is fired.
1473 1473
 		 * @param EE_Base_Class $model_object the model object about to be saved.
1474 1474
 		 */
1475
-		do_action( 'AHEE__EE_Base_Class__save__begin', $this );
1476
-		if( ! $this->allow_persist() ) {
1475
+		do_action('AHEE__EE_Base_Class__save__begin', $this);
1476
+		if ( ! $this->allow_persist()) {
1477 1477
 			return 0;
1478 1478
 		}
1479 1479
 		//now get current attribute values
@@ -1483,61 +1483,61 @@  discard block
 block discarded – undo
1483 1483
 		$old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object();
1484 1484
 		$this->get_model()->assume_values_already_prepared_by_model_object(true);
1485 1485
 		//does this model have an autoincrement PK?
1486
-		if($this->get_model()->has_primary_key_field()){
1487
-			if($this->get_model()->get_primary_key_field()->is_auto_increment()){
1486
+		if ($this->get_model()->has_primary_key_field()) {
1487
+			if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1488 1488
 				//ok check if it's set, if so: update; if not, insert
1489
-				if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){
1490
-					$results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() );
1489
+				if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1490
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1491 1491
 				} else {
1492
-					unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]);
1493
-					$results = $this->get_model()->insert( $save_cols_n_values );
1494
-					if($results){
1492
+					unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1493
+					$results = $this->get_model()->insert($save_cols_n_values);
1494
+					if ($results) {
1495 1495
 						//if successful, set the primary key
1496 1496
 						//but don't use the normal SET method, because it will check if
1497 1497
 						//an item with the same ID exists in the mapper & db, then
1498 1498
 						//will find it in the db (because we just added it) and THAT object
1499 1499
 						//will get added to the mapper before we can add this one!
1500 1500
 						//but if we just avoid using the SET method, all that headache can be avoided
1501
-						$pk_field_name =self::_get_primary_key_name( get_class($this));
1501
+						$pk_field_name = self::_get_primary_key_name(get_class($this));
1502 1502
 						$this->_fields[$pk_field_name] = $results;
1503 1503
 						$this->_clear_cached_property($pk_field_name);
1504
-						$this->get_model()->add_to_entity_map( $this );
1504
+						$this->get_model()->add_to_entity_map($this);
1505 1505
 						$this->_update_cached_related_model_objs_fks();
1506 1506
 					}
1507 1507
 				}
1508
-			}else{//PK is NOT auto-increment
1508
+			} else {//PK is NOT auto-increment
1509 1509
 				//so check if one like it already exists in the db
1510
-				if( $this->get_model()->exists_by_ID( $this->ID() ) ){
1511
-					if( WP_DEBUG && ! $this->in_entity_map() ){
1510
+				if ($this->get_model()->exists_by_ID($this->ID())) {
1511
+					if (WP_DEBUG && ! $this->in_entity_map()) {
1512 1512
 						throw new EE_Error(
1513 1513
 							sprintf(
1514
-								__( 'Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso' ),
1514
+								__('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso'),
1515 1515
 								get_class($this),
1516
-								get_class( $this->get_model() ) . '::instance()->add_to_entity_map()',
1517
-								get_class( $this->get_model() ) . '::instance()->get_one_by_ID()',
1516
+								get_class($this->get_model()).'::instance()->add_to_entity_map()',
1517
+								get_class($this->get_model()).'::instance()->get_one_by_ID()',
1518 1518
 								'<br />'
1519 1519
 							)
1520 1520
 						);
1521 1521
 					}
1522 1522
 					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1523
-				}else{
1523
+				} else {
1524 1524
 					$results = $this->get_model()->insert($save_cols_n_values);
1525 1525
 					$this->_update_cached_related_model_objs_fks();
1526 1526
 				}
1527 1527
 			}
1528
-		}else{//there is NO primary key
1528
+		} else {//there is NO primary key
1529 1529
 			$already_in_db = false;
1530
-			foreach($this->get_model()->unique_indexes() as $index){
1530
+			foreach ($this->get_model()->unique_indexes() as $index) {
1531 1531
 				$uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1532
-				if($this->get_model()->exists(array($uniqueness_where_params))){
1532
+				if ($this->get_model()->exists(array($uniqueness_where_params))) {
1533 1533
 					$already_in_db = true;
1534 1534
 				}
1535 1535
 			}
1536
-			if( $already_in_db ){
1537
-				$combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() );
1538
-				$results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values );
1539
-			}else{
1540
-				$results = $this->get_model()->insert( $save_cols_n_values );
1536
+			if ($already_in_db) {
1537
+				$combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields());
1538
+				$results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1539
+			} else {
1540
+				$results = $this->get_model()->insert($save_cols_n_values);
1541 1541
 			}
1542 1542
 		}
1543 1543
 		//restore the old assumption about values being prepared by the model object
@@ -1550,7 +1550,7 @@  discard block
 block discarded – undo
1550 1550
 		 * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted
1551 1551
 		 * the new ID (or 0 if an error occurred and it wasn't updated)
1552 1552
 		 */
1553
-		do_action( 'AHEE__EE_Base_Class__save__end', $this, $results );
1553
+		do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1554 1554
 		return $results;
1555 1555
 	}
1556 1556
 
@@ -1565,15 +1565,15 @@  discard block
 block discarded – undo
1565 1565
 	 * @return void
1566 1566
 	 * @throws \EE_Error
1567 1567
 	 */
1568
-	protected function _update_cached_related_model_objs_fks(){
1569
-		foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){
1570
-			if( $relation_obj instanceof EE_Has_Many_Relation ){
1571
-				foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) {
1568
+	protected function _update_cached_related_model_objs_fks() {
1569
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1570
+			if ($relation_obj instanceof EE_Has_Many_Relation) {
1571
+				foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1572 1572
 					$fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1573 1573
 						$this->get_model()->get_this_model_name()
1574 1574
 					);
1575
-					$related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() );
1576
-					if( $related_model_obj_in_cache->ID() ){
1575
+					$related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1576
+					if ($related_model_obj_in_cache->ID()) {
1577 1577
 						$related_model_obj_in_cache->save();
1578 1578
 					}
1579 1579
 				}
@@ -1594,21 +1594,21 @@  discard block
 block discarded – undo
1594 1594
 	 * @return int ID of new model object on save; 0 on failure+
1595 1595
 	 * @throws \EE_Error
1596 1596
 	 */
1597
-	public function save_new_cached_related_model_objs(){
1597
+	public function save_new_cached_related_model_objs() {
1598 1598
 		//make sure this has been saved
1599
-		if( ! $this->ID()){
1599
+		if ( ! $this->ID()) {
1600 1600
 			$id = $this->save();
1601
-		}else{
1601
+		} else {
1602 1602
 			$id = $this->ID();
1603 1603
 		}
1604 1604
 		//now save all the NEW cached model objects  (ie they don't exist in the DB)
1605
-		foreach($this->get_model()->relation_settings() as $relationName => $relationObj){
1605
+		foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1606 1606
 
1607 1607
 
1608
-			if($this->_model_relations[$relationName]){
1608
+			if ($this->_model_relations[$relationName]) {
1609 1609
 				//is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1610 1610
 				//or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1611
-				if($relationObj instanceof EE_Belongs_To_Relation){
1611
+				if ($relationObj instanceof EE_Belongs_To_Relation) {
1612 1612
 					//add a relation to that relation type (which saves the appropriate thing in the process)
1613 1613
 					//but ONLY if it DOES NOT exist in the DB
1614 1614
 					/* @var $related_model_obj EE_Base_Class */
@@ -1617,8 +1617,8 @@  discard block
 block discarded – undo
1617 1617
 						$this->_add_relation_to($related_model_obj, $relationName);
1618 1618
 						$related_model_obj->save_new_cached_related_model_objs();
1619 1619
 //					}
1620
-				}else{
1621
-					foreach($this->_model_relations[$relationName] as $related_model_obj){
1620
+				} else {
1621
+					foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1622 1622
 						//add a relation to that relation type (which saves the appropriate thing in the process)
1623 1623
 						//but ONLY if it DOES NOT exist in the DB
1624 1624
 //						if( ! $related_model_obj->ID()){
@@ -1639,8 +1639,8 @@  discard block
 block discarded – undo
1639 1639
 	 * @return \EEM_Base | \EEM_CPT_Base
1640 1640
 	 */
1641 1641
 	public function get_model() {
1642
-		$modelName = self::_get_model_classname( get_class($this) );
1643
-		return self::_get_model_instance_with_name($modelName, $this->_timezone );
1642
+		$modelName = self::_get_model_classname(get_class($this));
1643
+		return self::_get_model_instance_with_name($modelName, $this->_timezone);
1644 1644
 	}
1645 1645
 
1646 1646
 
@@ -1651,10 +1651,10 @@  discard block
 block discarded – undo
1651 1651
 	 * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1652 1652
 	 * @throws \EE_Error
1653 1653
 	 */
1654
-	protected static function _get_object_from_entity_mapper($props_n_values, $classname){
1654
+	protected static function _get_object_from_entity_mapper($props_n_values, $classname) {
1655 1655
 		//TODO: will not work for Term_Relationships because they have no PK!
1656
-		$primary_id_ref = self::_get_primary_key_name( $classname );
1657
-		if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) {
1656
+		$primary_id_ref = self::_get_primary_key_name($classname);
1657
+		if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1658 1658
 			$id = $props_n_values[$primary_id_ref];
1659 1659
 			return self::_get_model($classname)->get_from_entity_map($id);
1660 1660
 		}
@@ -1675,37 +1675,37 @@  discard block
 block discarded – undo
1675 1675
 	 * @return mixed (EE_Base_Class|bool)
1676 1676
 	 * @throws \EE_Error
1677 1677
 	 */
1678
-	protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL, $date_formats = array() ) {
1678
+	protected static function _check_for_object($props_n_values, $classname, $timezone = NULL, $date_formats = array()) {
1679 1679
 		$existing = null;
1680
-		if ( self::_get_model( $classname )->has_primary_key_field() ) {
1681
-			$primary_id_ref = self::_get_primary_key_name( $classname );
1682
-			if ( array_key_exists( $primary_id_ref, $props_n_values )
1683
-			     && ! empty( $props_n_values[ $primary_id_ref ] )
1680
+		if (self::_get_model($classname)->has_primary_key_field()) {
1681
+			$primary_id_ref = self::_get_primary_key_name($classname);
1682
+			if (array_key_exists($primary_id_ref, $props_n_values)
1683
+			     && ! empty($props_n_values[$primary_id_ref])
1684 1684
 			) {
1685
-				$existing = self::_get_model( $classname, $timezone )->get_one_by_ID(
1686
-					$props_n_values[ $primary_id_ref ]
1685
+				$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1686
+					$props_n_values[$primary_id_ref]
1687 1687
 				);
1688 1688
 			}
1689
-		} elseif ( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ) {
1689
+		} elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1690 1690
 			//no primary key on this model, but there's still a matching item in the DB
1691
-			$existing = self::_get_model( $classname, $timezone )->get_one_by_ID(
1692
-				self::_get_model( $classname, $timezone )->get_index_primary_key_string( $props_n_values )
1691
+			$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1692
+				self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1693 1693
 			);
1694 1694
 		}
1695
-		if ( $existing ) {
1695
+		if ($existing) {
1696 1696
 
1697 1697
 			//set date formats if present before setting values
1698
-			if ( ! empty( $date_formats ) && is_array( $date_formats ) ) {
1699
-				$existing->set_date_format( $date_formats[0] );
1700
-				$existing->set_time_format( $date_formats[1] );
1698
+			if ( ! empty($date_formats) && is_array($date_formats)) {
1699
+				$existing->set_date_format($date_formats[0]);
1700
+				$existing->set_time_format($date_formats[1]);
1701 1701
 			} else {
1702 1702
 				//set default formats for date and time
1703
-				$existing->set_date_format( get_option( 'date_format' ) );
1704
-				$existing->set_time_format( get_option( 'time_format' ) );
1703
+				$existing->set_date_format(get_option('date_format'));
1704
+				$existing->set_time_format(get_option('time_format'));
1705 1705
 			}
1706 1706
 
1707
-			foreach ( $props_n_values as $property => $field_value ) {
1708
-				$existing->set( $property, $field_value );
1707
+			foreach ($props_n_values as $property => $field_value) {
1708
+				$existing->set($property, $field_value);
1709 1709
 			}
1710 1710
 			return $existing;
1711 1711
 		} else {
@@ -1723,9 +1723,9 @@  discard block
 block discarded – undo
1723 1723
 	 * @throws EE_Error
1724 1724
 	 * @return EEM_Base
1725 1725
 	 */
1726
-	protected static function  _get_model( $classname, $timezone = NULL ){
1726
+	protected static function  _get_model($classname, $timezone = NULL) {
1727 1727
 		//find model for this class
1728
-		if( ! $classname ){
1728
+		if ( ! $classname) {
1729 1729
 			throw new EE_Error(
1730 1730
 				sprintf(
1731 1731
 					__(
@@ -1736,8 +1736,8 @@  discard block
 block discarded – undo
1736 1736
 				)
1737 1737
 			);
1738 1738
 		}
1739
-		$modelName=self::_get_model_classname($classname);
1740
-		return self::_get_model_instance_with_name($modelName, $timezone );
1739
+		$modelName = self::_get_model_classname($classname);
1740
+		return self::_get_model_instance_with_name($modelName, $timezone);
1741 1741
 	}
1742 1742
 
1743 1743
 
@@ -1748,10 +1748,10 @@  discard block
 block discarded – undo
1748 1748
 	 * @param null   $timezone
1749 1749
 	 * @return EEM_Base
1750 1750
 	 */
1751
-	protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){
1752
-		$model_classname = str_replace( 'EEM_', '', $model_classname );
1753
-		$model = EE_Registry::instance()->load_model( $model_classname );
1754
-		$model->set_timezone( $timezone );
1751
+	protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) {
1752
+		$model_classname = str_replace('EEM_', '', $model_classname);
1753
+		$model = EE_Registry::instance()->load_model($model_classname);
1754
+		$model->set_timezone($timezone);
1755 1755
 		return $model;
1756 1756
 	}
1757 1757
 
@@ -1763,10 +1763,10 @@  discard block
 block discarded – undo
1763 1763
 	 * @param null $model_name
1764 1764
 	 * @return string like EEM_Attendee
1765 1765
 	 */
1766
-	private static function _get_model_classname( $model_name = null){
1767
-		if(strpos($model_name,"EE_")===0){
1768
-			$model_classname=str_replace("EE_","EEM_",$model_name);
1769
-		}else{
1766
+	private static function _get_model_classname($model_name = null) {
1767
+		if (strpos($model_name, "EE_") === 0) {
1768
+			$model_classname = str_replace("EE_", "EEM_", $model_name);
1769
+		} else {
1770 1770
 			$model_classname = "EEM_".$model_name;
1771 1771
 		}
1772 1772
 		return $model_classname;
@@ -1780,16 +1780,16 @@  discard block
 block discarded – undo
1780 1780
 	 * @throws EE_Error
1781 1781
 	 * @return string
1782 1782
 	 */
1783
-	protected static function _get_primary_key_name( $classname = NULL ){
1784
-		if( ! $classname){
1783
+	protected static function _get_primary_key_name($classname = NULL) {
1784
+		if ( ! $classname) {
1785 1785
 			throw new EE_Error(
1786 1786
 				sprintf(
1787
-					__( "What were you thinking calling _get_primary_key_name(%s)", "event_espresso" ),
1787
+					__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1788 1788
 					$classname
1789 1789
 				)
1790 1790
 			);
1791 1791
 		}
1792
-		return self::_get_model( $classname )->get_primary_key_field()->get_name();
1792
+		return self::_get_model($classname)->get_primary_key_field()->get_name();
1793 1793
 	}
1794 1794
 
1795 1795
 
@@ -1803,12 +1803,12 @@  discard block
 block discarded – undo
1803 1803
 	 * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1804 1804
 	 * @throws \EE_Error
1805 1805
 	 */
1806
-	public function ID(){
1806
+	public function ID() {
1807 1807
 		//now that we know the name of the variable, use a variable variable to get its value and return its
1808
-		if( $this->get_model()->has_primary_key_field() ) {
1809
-			return $this->_fields[ self::_get_primary_key_name( get_class($this) ) ];
1810
-		}else{
1811
-			return $this->get_model()->get_index_primary_key_string( $this->_fields );
1808
+		if ($this->get_model()->has_primary_key_field()) {
1809
+			return $this->_fields[self::_get_primary_key_name(get_class($this))];
1810
+		} else {
1811
+			return $this->get_model()->get_index_primary_key_string($this->_fields);
1812 1812
 		}
1813 1813
 	}
1814 1814
 
@@ -1826,38 +1826,38 @@  discard block
 block discarded – undo
1826 1826
 	 * @throws EE_Error
1827 1827
 	 * @return EE_Base_Class the object the relation was added to
1828 1828
 	 */
1829
-	public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){
1829
+	public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) {
1830 1830
 		//if this thing exists in the DB, save the relation to the DB
1831
-		if( $this->ID() ){
1832
-			$otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values );
1831
+		if ($this->ID()) {
1832
+			$otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values);
1833 1833
 			//clear cache so future get_many_related and get_first_related() return new results.
1834
-			$this->clear_cache( $relationName, $otherObject, TRUE );
1835
-                        if( $otherObject instanceof EE_Base_Class ) {
1836
-                            $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this );
1834
+			$this->clear_cache($relationName, $otherObject, TRUE);
1835
+                        if ($otherObject instanceof EE_Base_Class) {
1836
+                            $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1837 1837
                         }
1838 1838
 		} else {
1839 1839
 			//this thing doesn't exist in the DB,  so just cache it
1840
-			if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){
1841
-				throw new EE_Error( sprintf(
1842
-					__( 'Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso' ),
1840
+			if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1841
+				throw new EE_Error(sprintf(
1842
+					__('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'),
1843 1843
 					$otherObjectModelObjectOrID,
1844
-					get_class( $this )
1844
+					get_class($this)
1845 1845
 				));
1846 1846
 			} else {
1847 1847
 				$otherObject = $otherObjectModelObjectOrID;
1848 1848
 			}
1849
-			$this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id );
1849
+			$this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1850 1850
 		}
1851
-                if( $otherObject instanceof EE_Base_Class ) {
1851
+                if ($otherObject instanceof EE_Base_Class) {
1852 1852
                     //fix the reciprocal relation too
1853
-                    if( $otherObject->ID() ) {
1853
+                    if ($otherObject->ID()) {
1854 1854
                             //its saved so assumed relations exist in the DB, so we can just
1855 1855
                             //clear the cache so future queries use the updated info in the DB
1856
-                            $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true );
1856
+                            $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1857 1857
                     } else {
1858 1858
 
1859 1859
                             //it's not saved, so it caches relations like this
1860
-                            $otherObject->cache( $this->get_model()->get_this_model_name(), $this );
1860
+                            $otherObject->cache($this->get_model()->get_this_model_name(), $this);
1861 1861
                     }
1862 1862
                 }
1863 1863
 		return $otherObject;
@@ -1881,17 +1881,17 @@  discard block
 block discarded – undo
1881 1881
 	 * @return EE_Base_Class the relation was removed from
1882 1882
 	 * @throws \EE_Error
1883 1883
 	 */
1884
-	public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){
1885
-		if ( $this->ID() ) {
1884
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) {
1885
+		if ($this->ID()) {
1886 1886
 			//if this exists in the DB, save the relation change to the DB too
1887
-			$otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query );
1888
-			$this->clear_cache( $relationName, $otherObject );
1887
+			$otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query);
1888
+			$this->clear_cache($relationName, $otherObject);
1889 1889
 		} else {
1890 1890
 			//this doesn't exist in the DB, just remove it from the cache
1891
-			$otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID );
1891
+			$otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
1892 1892
 		}
1893
-                if( $otherObject instanceof EE_Base_Class ) {
1894
-                    $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this );
1893
+                if ($otherObject instanceof EE_Base_Class) {
1894
+                    $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1895 1895
                 }
1896 1896
 		return $otherObject;
1897 1897
 	}
@@ -1906,18 +1906,18 @@  discard block
 block discarded – undo
1906 1906
 	 * @return EE_Base_Class
1907 1907
 	 * @throws \EE_Error
1908 1908
 	 */
1909
-	public function _remove_relations($relationName,$where_query_params = array()){
1910
-		if ( $this->ID() ) {
1909
+	public function _remove_relations($relationName, $where_query_params = array()) {
1910
+		if ($this->ID()) {
1911 1911
 			//if this exists in the DB, save the relation change to the DB too
1912
-			$otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params );
1913
-			$this->clear_cache( $relationName, null, true );
1912
+			$otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
1913
+			$this->clear_cache($relationName, null, true);
1914 1914
 		} else {
1915 1915
 			//this doesn't exist in the DB, just remove it from the cache
1916
-			$otherObjects = $this->clear_cache( $relationName, null, true );
1916
+			$otherObjects = $this->clear_cache($relationName, null, true);
1917 1917
 		}
1918
-                if( is_array( $otherObjects ) ) {
1919
-                    foreach ( $otherObjects as $otherObject ) {
1920
-                            $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this );
1918
+                if (is_array($otherObjects)) {
1919
+                    foreach ($otherObjects as $otherObject) {
1920
+                            $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1921 1921
                     }
1922 1922
                 }
1923 1923
 		return $otherObjects;
@@ -1937,27 +1937,27 @@  discard block
 block discarded – undo
1937 1937
 	 * @throws \EE_Error
1938 1938
 	 *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs
1939 1939
 	 */
1940
-	public function get_many_related($relationName,$query_params = array()){
1941
-		if($this->ID()){
1940
+	public function get_many_related($relationName, $query_params = array()) {
1941
+		if ($this->ID()) {
1942 1942
 			//this exists in the DB, so get the related things from either the cache or the DB
1943 1943
 			//if there are query parameters, forget about caching the related model objects.
1944
-			if( $query_params ){
1944
+			if ($query_params) {
1945 1945
 				$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1946
-			}else{
1946
+			} else {
1947 1947
 				//did we already cache the result of this query?
1948 1948
 				$cached_results = $this->get_all_from_cache($relationName);
1949
-				if ( ! $cached_results ){
1949
+				if ( ! $cached_results) {
1950 1950
 					$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1951 1951
 					//if no query parameters were passed, then we got all the related model objects
1952 1952
 					//for that relation. We can cache them then.
1953
-					foreach($related_model_objects as $related_model_object){
1953
+					foreach ($related_model_objects as $related_model_object) {
1954 1954
 						$this->cache($relationName, $related_model_object);
1955 1955
 					}
1956
-				}else{
1956
+				} else {
1957 1957
 					$related_model_objects = $cached_results;
1958 1958
 				}
1959 1959
 			}
1960
-		}else{
1960
+		} else {
1961 1961
 			//this doesn't exist in the DB, so just get the related things from the cache
1962 1962
 			$related_model_objects = $this->get_all_from_cache($relationName);
1963 1963
 		}
@@ -1975,8 +1975,8 @@  discard block
 block discarded – undo
1975 1975
 	 * @param bool   	$distinct       if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
1976 1976
 	 * @return int
1977 1977
 	 */
1978
-	public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1979
-		return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct);
1978
+	public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1979
+		return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
1980 1980
 	}
1981 1981
 
1982 1982
 
@@ -1990,7 +1990,7 @@  discard block
 block discarded – undo
1990 1990
 	 * 						By default, uses primary key (which doesn't make much sense, so you should probably change it)
1991 1991
 	 * @return int
1992 1992
 	 */
1993
-	public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){
1993
+	public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) {
1994 1994
 		return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
1995 1995
 	}
1996 1996
 
@@ -2004,33 +2004,33 @@  discard block
 block discarded – undo
2004 2004
 	 * @return EE_Base_Class (not an array, a single object)
2005 2005
 	 * @throws \EE_Error
2006 2006
 	 */
2007
-	public function get_first_related($relationName,$query_params = array()){
2008
-		if($this->ID()){//this exists in the DB, get from the cache OR the DB
2007
+	public function get_first_related($relationName, $query_params = array()) {
2008
+		if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2009 2009
 
2010 2010
 			//if they've provided some query parameters, don't bother trying to cache the result
2011 2011
 			//also make sure we're not caching the result of get_first_related
2012 2012
 			//on a relation which should have an array of objects (because the cache might have an array of objects)
2013
-			if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){
2014
-				$related_model_object =  $this->get_model()->get_first_related($this, $relationName, $query_params);
2015
-			}else{
2013
+			if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2014
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2015
+			} else {
2016 2016
 				//first, check if we've already cached the result of this query
2017 2017
 				$cached_result = $this->get_one_from_cache($relationName);
2018
-				if ( ! $cached_result ){
2018
+				if ( ! $cached_result) {
2019 2019
 
2020 2020
 					$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2021
-					$this->cache($relationName,$related_model_object);
2022
-				}else{
2021
+					$this->cache($relationName, $related_model_object);
2022
+				} else {
2023 2023
 					$related_model_object = $cached_result;
2024 2024
 				}
2025 2025
 			}
2026
-		}else{
2026
+		} else {
2027 2027
 			$related_model_object = null;
2028 2028
 			//this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2029
-			if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){
2030
-				$related_model_object =  $this->get_model()->get_first_related($this, $relationName, $query_params);
2029
+			if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2030
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2031 2031
 			}
2032 2032
 			//this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2033
-			if( ! $related_model_object){
2033
+			if ( ! $related_model_object) {
2034 2034
 				$related_model_object = $this->get_one_from_cache($relationName);
2035 2035
 			}
2036 2036
 
@@ -2052,12 +2052,12 @@  discard block
 block discarded – undo
2052 2052
 	 * @return int how many deleted
2053 2053
 	 * @throws \EE_Error
2054 2054
 	 */
2055
-	public function delete_related($relationName,$query_params = array()){
2056
-		if($this->ID()){
2057
-			$count =  $this->get_model()->delete_related($this, $relationName, $query_params);
2058
-		}else{
2055
+	public function delete_related($relationName, $query_params = array()) {
2056
+		if ($this->ID()) {
2057
+			$count = $this->get_model()->delete_related($this, $relationName, $query_params);
2058
+		} else {
2059 2059
 			$count = count($this->get_all_from_cache($relationName));
2060
-			$this->clear_cache($relationName,NULL,TRUE);
2060
+			$this->clear_cache($relationName, NULL, TRUE);
2061 2061
 		}
2062 2062
 		return $count;
2063 2063
 	}
@@ -2076,13 +2076,13 @@  discard block
 block discarded – undo
2076 2076
 	 * @return int how many deleted (including those soft deleted)
2077 2077
 	 * @throws \EE_Error
2078 2078
 	 */
2079
-	public function delete_related_permanently($relationName,$query_params = array()){
2080
-		if($this->ID()){
2081
-			$count =  $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2082
-		}else{
2079
+	public function delete_related_permanently($relationName, $query_params = array()) {
2080
+		if ($this->ID()) {
2081
+			$count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2082
+		} else {
2083 2083
 			$count = count($this->get_all_from_cache($relationName));
2084 2084
 		}
2085
-		$this->clear_cache($relationName,NULL,TRUE);
2085
+		$this->clear_cache($relationName, NULL, TRUE);
2086 2086
 		return $count;
2087 2087
 	}
2088 2088
 
@@ -2098,7 +2098,7 @@  discard block
 block discarded – undo
2098 2098
 	 * @param  string $field_name property to check
2099 2099
 	 * @return bool            				  TRUE if existing,FALSE if not.
2100 2100
 	 */
2101
-	public function is_set( $field_name ) {
2101
+	public function is_set($field_name) {
2102 2102
 		return isset($this->_fields[$field_name]);
2103 2103
 	}
2104 2104
 
@@ -2110,11 +2110,11 @@  discard block
 block discarded – undo
2110 2110
 	 * @throws EE_Error
2111 2111
 	 * @return bool                              TRUE if existing, throw EE_Error if not.
2112 2112
 	 */
2113
-	protected function _property_exists( $properties ) {
2113
+	protected function _property_exists($properties) {
2114 2114
 
2115
-		foreach ( (array) $properties as $property_name ) {
2115
+		foreach ((array) $properties as $property_name) {
2116 2116
 			//first make sure this property exists
2117
-			if ( ! $this->_fields[ $property_name ] ) {
2117
+			if ( ! $this->_fields[$property_name]) {
2118 2118
 				throw new EE_Error(
2119 2119
 					sprintf(
2120 2120
 						__(
@@ -2142,7 +2142,7 @@  discard block
 block discarded – undo
2142 2142
 		$fields = $this->get_model()->field_settings(FALSE);
2143 2143
 		$properties = array();
2144 2144
 		//remove prepended underscore
2145
-		foreach ( $fields as $field_name => $settings ) {
2145
+		foreach ($fields as $field_name => $settings) {
2146 2146
 			$properties[$field_name] = $this->get($field_name);
2147 2147
 		}
2148 2148
 		return $properties;
@@ -2172,10 +2172,10 @@  discard block
 block discarded – undo
2172 2172
 	 * @throws EE_Error
2173 2173
 	 * @return mixed whatever the plugin which calls add_filter decides
2174 2174
 	 */
2175
-	public function __call($methodName,$args){
2176
-		$className=get_class($this);
2177
-		$tagName="FHEE__{$className}__{$methodName}";
2178
-		if ( ! has_filter( $tagName ) ) {
2175
+	public function __call($methodName, $args) {
2176
+		$className = get_class($this);
2177
+		$tagName = "FHEE__{$className}__{$methodName}";
2178
+		if ( ! has_filter($tagName)) {
2179 2179
 			throw new EE_Error(
2180 2180
 				sprintf(
2181 2181
 					__(
@@ -2188,7 +2188,7 @@  discard block
 block discarded – undo
2188 2188
 				)
2189 2189
 			);
2190 2190
 		}
2191
-		return apply_filters($tagName,null,$this,$args);
2191
+		return apply_filters($tagName, null, $this, $args);
2192 2192
 	}
2193 2193
 
2194 2194
 
@@ -2204,7 +2204,7 @@  discard block
 block discarded – undo
2204 2204
 	 * @throws \EE_Error
2205 2205
 	 * NOTE: if the values haven't changed, returns 0
2206 2206
 	 */
2207
-	public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){
2207
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) {
2208 2208
 		$query_params = array(
2209 2209
 			array(
2210 2210
 				'EXM_key'  => $meta_key,
@@ -2212,17 +2212,17 @@  discard block
 block discarded – undo
2212 2212
 				'EXM_type' => $this->get_model()->get_this_model_name()
2213 2213
 			)
2214 2214
 		);
2215
-		if ( $previous_value !== null ) {
2215
+		if ($previous_value !== null) {
2216 2216
 			$query_params[0]['EXM_value'] = $meta_value;
2217 2217
 		}
2218
-		$existing_rows_like_that = EEM_Extra_Meta::instance()->get_all( $query_params );
2219
-		if ( ! $existing_rows_like_that ) {
2220
-			return $this->add_extra_meta( $meta_key, $meta_value );
2218
+		$existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2219
+		if ( ! $existing_rows_like_that) {
2220
+			return $this->add_extra_meta($meta_key, $meta_value);
2221 2221
 		} else {
2222
-			foreach ( $existing_rows_like_that as $existing_row ) {
2223
-				$existing_row->save( array( 'EXM_value' => $meta_value ) );
2222
+			foreach ($existing_rows_like_that as $existing_row) {
2223
+				$existing_row->save(array('EXM_value' => $meta_value));
2224 2224
 			}
2225
-			return count( $existing_rows_like_that );
2225
+			return count($existing_rows_like_that);
2226 2226
 		}
2227 2227
 	}
2228 2228
 
@@ -2239,8 +2239,8 @@  discard block
 block discarded – undo
2239 2239
 	 * @return boolean
2240 2240
 	 * @throws \EE_Error
2241 2241
 	 */
2242
-	public function add_extra_meta($meta_key,$meta_value,$unique = false){
2243
-		if ( $unique ) {
2242
+	public function add_extra_meta($meta_key, $meta_value, $unique = false) {
2243
+		if ($unique) {
2244 2244
 			$existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2245 2245
 				array(
2246 2246
 					array(
@@ -2250,7 +2250,7 @@  discard block
 block discarded – undo
2250 2250
 					)
2251 2251
 				)
2252 2252
 			);
2253
-			if ( $existing_extra_meta ) {
2253
+			if ($existing_extra_meta) {
2254 2254
 				return false;
2255 2255
 			}
2256 2256
 		}
@@ -2277,7 +2277,7 @@  discard block
 block discarded – undo
2277 2277
 	 * @return int number of extra meta rows deleted
2278 2278
 	 * @throws \EE_Error
2279 2279
 	 */
2280
-	public function delete_extra_meta($meta_key,$meta_value = NULL){
2280
+	public function delete_extra_meta($meta_key, $meta_value = NULL) {
2281 2281
 		$query_params = array(
2282 2282
 			array(
2283 2283
 				'EXM_key'  => $meta_key,
@@ -2285,10 +2285,10 @@  discard block
 block discarded – undo
2285 2285
 				'EXM_type' => $this->get_model()->get_this_model_name()
2286 2286
 			)
2287 2287
 		);
2288
-		if ( $meta_value !== null ) {
2288
+		if ($meta_value !== null) {
2289 2289
 			$query_params[0]['EXM_value'] = $meta_value;
2290 2290
 		}
2291
-		return EEM_Extra_Meta::instance()->delete( $query_params );
2291
+		return EEM_Extra_Meta::instance()->delete($query_params);
2292 2292
 	}
2293 2293
 
2294 2294
 
@@ -2304,25 +2304,25 @@  discard block
 block discarded – undo
2304 2304
 	 * @return mixed single value if $single; array if ! $single
2305 2305
 	 * @throws \EE_Error
2306 2306
 	 */
2307
-	public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){
2308
-		if($single){
2309
-			$result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key)));
2310
-			if ( $result instanceof EE_Extra_Meta ){
2307
+	public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) {
2308
+		if ($single) {
2309
+			$result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key)));
2310
+			if ($result instanceof EE_Extra_Meta) {
2311 2311
 				return $result->value();
2312
-			}else{
2312
+			} else {
2313 2313
 				return $default;
2314 2314
 			}
2315
-		}else{
2316
-			$results =  $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key)));
2317
-			if($results){
2315
+		} else {
2316
+			$results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key)));
2317
+			if ($results) {
2318 2318
 				$values = array();
2319
-				foreach($results as $result){
2320
-					if ( $result instanceof EE_Extra_Meta ){
2319
+				foreach ($results as $result) {
2320
+					if ($result instanceof EE_Extra_Meta) {
2321 2321
 						$values[$result->ID()] = $result->value();
2322 2322
 					}
2323 2323
 				}
2324 2324
 				return $values;
2325
-			}else{
2325
+			} else {
2326 2326
 				return $default;
2327 2327
 			}
2328 2328
 		}
@@ -2344,20 +2344,20 @@  discard block
 block discarded – undo
2344 2344
 	 * @return array
2345 2345
 	 * @throws \EE_Error
2346 2346
 	 */
2347
-	public function all_extra_meta_array($one_of_each_key = true){
2347
+	public function all_extra_meta_array($one_of_each_key = true) {
2348 2348
 		$return_array = array();
2349
-		if($one_of_each_key){
2349
+		if ($one_of_each_key) {
2350 2350
 			$extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key'));
2351
-			foreach($extra_meta_objs as $extra_meta_obj){
2352
-				if ( $extra_meta_obj instanceof EE_Extra_Meta ) {
2351
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2352
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2353 2353
 					$return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2354 2354
 				}
2355 2355
 			}
2356
-		}else{
2356
+		} else {
2357 2357
 			$extra_meta_objs = $this->get_many_related('Extra_Meta');
2358
-			foreach($extra_meta_objs as $extra_meta_obj){
2359
-				if ( $extra_meta_obj instanceof EE_Extra_Meta ) {
2360
-					if( ! isset($return_array[$extra_meta_obj->key()])){
2358
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2359
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2360
+					if ( ! isset($return_array[$extra_meta_obj->key()])) {
2361 2361
 						$return_array[$extra_meta_obj->key()] = array();
2362 2362
 					}
2363 2363
 					$return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
@@ -2375,19 +2375,19 @@  discard block
 block discarded – undo
2375 2375
 	 * @return string
2376 2376
 	 * @throws \EE_Error
2377 2377
 	 */
2378
-	public function name(){
2378
+	public function name() {
2379 2379
 		//find a field that's not a text field
2380 2380
 		$field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2381
-		if($field_we_can_use){
2381
+		if ($field_we_can_use) {
2382 2382
 			return $this->get($field_we_can_use->get_name());
2383
-		}else{
2383
+		} else {
2384 2384
 			$first_few_properties = $this->model_field_array();
2385
-			$first_few_properties = array_slice($first_few_properties,0,3);
2385
+			$first_few_properties = array_slice($first_few_properties, 0, 3);
2386 2386
 			$name_parts = array();
2387
-			foreach( $first_few_properties as $name=> $value ){
2387
+			foreach ($first_few_properties as $name=> $value) {
2388 2388
 				$name_parts[] = "$name:$value";
2389 2389
 			}
2390
-			return implode(",",$name_parts);
2390
+			return implode(",", $name_parts);
2391 2391
 		}
2392 2392
 	}
2393 2393
 
@@ -2400,11 +2400,11 @@  discard block
 block discarded – undo
2400 2400
 	 * @return boolean
2401 2401
 	 * @throws \EE_Error
2402 2402
 	 */
2403
-	public function in_entity_map(){
2404
-		if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) {
2403
+	public function in_entity_map() {
2404
+		if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2405 2405
 			//well, if we looked, did we find it in the entity map?
2406 2406
 			return TRUE;
2407
-		}else{
2407
+		} else {
2408 2408
 			return FALSE;
2409 2409
 		}
2410 2410
 	}
@@ -2415,21 +2415,21 @@  discard block
 block discarded – undo
2415 2415
 	 * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2416 2416
 	 * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2417 2417
 	 */
2418
-	public function refresh_from_db(){
2419
-		if( $this->ID() && $this->in_entity_map() ){
2420
-			$this->get_model()->refresh_entity_map_from_db( $this->ID() );
2421
-		}else{
2418
+	public function refresh_from_db() {
2419
+		if ($this->ID() && $this->in_entity_map()) {
2420
+			$this->get_model()->refresh_entity_map_from_db($this->ID());
2421
+		} else {
2422 2422
 			//if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2423 2423
 			//if it has an ID but it's not in the map, and you're asking me to refresh it
2424 2424
 			//that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2425 2425
 			//absolutely nothing in it for this ID
2426
-			if( WP_DEBUG ) {
2426
+			if (WP_DEBUG) {
2427 2427
 				throw new EE_Error(
2428 2428
 					sprintf(
2429
-						__( 'Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso' ),
2429
+						__('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso'),
2430 2430
 						$this->ID(),
2431
-						get_class( $this->get_model() ) . '::instance()->add_to_entity_map()',
2432
-						get_class( $this->get_model() ) . '::instance()->refresh_entity_map()'
2431
+						get_class($this->get_model()).'::instance()->add_to_entity_map()',
2432
+						get_class($this->get_model()).'::instance()->refresh_entity_map()'
2433 2433
 					)
2434 2434
 				);
2435 2435
 			}
@@ -2443,11 +2443,11 @@  discard block
 block discarded – undo
2443 2443
 	 * (probably a bad assumption they have made, oh well)
2444 2444
 	 * @return string
2445 2445
 	 */
2446
-	public function __toString(){
2446
+	public function __toString() {
2447 2447
 		try {
2448
-			return sprintf( '%s (%s)', $this->name(), $this->ID() );
2449
-		} catch ( Exception $e ) {
2450
-			EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ );
2448
+			return sprintf('%s (%s)', $this->name(), $this->ID());
2449
+		} catch (Exception $e) {
2450
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2451 2451
 			return '';
2452 2452
 		}
2453 2453
 	}
@@ -2483,19 +2483,19 @@  discard block
 block discarded – undo
2483 2483
 	 * @throws \EE_Error
2484 2484
 	 */
2485 2485
 	public function __sleep() {
2486
-		foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) {
2487
-			if( $relation_obj instanceof EE_Belongs_To_Relation ) {
2488
-				$classname = 'EE_' . $this->get_model()->get_this_model_name();
2489
-				if(
2490
-					$this->get_one_from_cache( $relation_name ) instanceof $classname
2491
-					&& $this->get_one_from_cache( $relation_name )->ID()
2486
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2487
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
2488
+				$classname = 'EE_'.$this->get_model()->get_this_model_name();
2489
+				if (
2490
+					$this->get_one_from_cache($relation_name) instanceof $classname
2491
+					&& $this->get_one_from_cache($relation_name)->ID()
2492 2492
 				) {
2493
-					$this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() );
2493
+					$this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2494 2494
 				}
2495 2495
 			}
2496 2496
 		}
2497 2497
 		$this->_props_n_values_provided_in_constructor = array();
2498
-		return array_keys( get_object_vars( $this ) );
2498
+		return array_keys(get_object_vars($this));
2499 2499
 	}
2500 2500
 
2501 2501
 
Please login to merge, or discard this patch.
core/domain/entities/DbSafeDateTime.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\domain\entities;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -34,23 +34,23 @@  discard block
 block discarded – undo
34 34
 
35 35
 
36 36
 	public function __toString() {
37
-		return $this->format( DbSafeDateTime::db_safe_timestamp_format );
37
+		return $this->format(DbSafeDateTime::db_safe_timestamp_format);
38 38
 	}
39 39
 
40 40
 
41 41
 
42 42
 	public function __sleep() {
43
-		$this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format );
44
-		return array( '_datetime_string' );
43
+		$this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format);
44
+		return array('_datetime_string');
45 45
 	}
46 46
 
47 47
 
48 48
 
49 49
 	public function __wakeup() {
50
-		$date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string );
50
+		$date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
51 51
 		$this->__construct(
52
-			$date->format( \EE_Datetime_Field::mysql_timestamp_format),
53
-			new \DateTimeZone( $date->format( 'e' ) )
52
+			$date->format(\EE_Datetime_Field::mysql_timestamp_format),
53
+			new \DateTimeZone($date->format('e'))
54 54
 		);
55 55
 	}
56 56
 
Please login to merge, or discard this patch.
core/EE_Session.core.php 2 patches
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -163,18 +163,18 @@  discard block
 block discarded – undo
163 163
 				$this->{$var_name} = $session_setting;
164 164
 			}
165 165
 		}
166
-         // are we using encryption?
167
-         $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data();
168
-         // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
169
-        // encrypt data via: $this->encryption->encrypt();
170
-        $this->encryption = $encryption;
166
+		 // are we using encryption?
167
+		 $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data();
168
+		 // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
169
+		// encrypt data via: $this->encryption->encrypt();
170
+		$this->encryption = $encryption;
171 171
 		// filter hook allows outside functions/classes/plugins to change default empty cart
172 172
 		$extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() );
173 173
 		array_merge( $this->_default_session_vars, $extra_default_session_vars );
174 174
 		// apply default session vars
175 175
 		$this->_set_defaults();
176
-         add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
177
-         // check request for 'clear_session' param
176
+		 add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
177
+		 // check request for 'clear_session' param
178 178
 		add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' ));
179 179
 		// once everything is all said and done,
180 180
 		add_action( 'shutdown', array( $this, 'update' ), 100 );
@@ -184,18 +184,18 @@  discard block
 block discarded – undo
184 184
 
185 185
 
186 186
 
187
-     /**
188
-      * @return void
189
-      * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
190
-      * @throws \EE_Error
191
-      */
187
+	 /**
188
+	  * @return void
189
+	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
190
+	  * @throws \EE_Error
191
+	  */
192 192
 	 public function open_session() {
193
-         // check for existing session and retrieve it from db
194
-         if ( ! $this->_espresso_session()) {
195
-             // or just start a new one
196
-             $this->_create_espresso_session();
197
-         }
198
-     }
193
+		 // check for existing session and retrieve it from db
194
+		 if ( ! $this->_espresso_session()) {
195
+			 // or just start a new one
196
+			 $this->_create_espresso_session();
197
+		 }
198
+	 }
199 199
 
200 200
 
201 201
 	 /**
@@ -408,16 +408,16 @@  discard block
 block discarded – undo
408 408
 		// set the "user agent"
409 409
 		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE;
410 410
 		// now let's retrieve what's in the db
411
-        $session_data = $this->_retrieve_session_data();
412
-        if (! empty($session_data)) {
413
-            // get the current time in UTC
411
+		$session_data = $this->_retrieve_session_data();
412
+		if (! empty($session_data)) {
413
+			// get the current time in UTC
414 414
 			$this->_time = isset( $this->_time ) ? $this->_time : time();
415 415
 			// and reset the session expiration
416 416
 			$this->_expiration = isset( $session_data['expiration'] )
417 417
 				? $session_data['expiration']
418 418
 				: $this->_time + $this->_lifespan;
419 419
 		} else {
420
-            // set initial site access time and the session expiration
420
+			// set initial site access time and the session expiration
421 421
 			$this->_set_init_access_and_expiration();
422 422
 			// set referer
423 423
 			$this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] )
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 			// no previous session = go back and create one (on top of the data above)
427 427
 			return FALSE;
428 428
 		}
429
-        // now the user agent
429
+		// now the user agent
430 430
 		if ( $session_data['user_agent'] !== $this->_user_agent ) {
431 431
 			return FALSE;
432 432
 		}
@@ -444,95 +444,95 @@  discard block
 block discarded – undo
444 444
 
445 445
 
446 446
 
447
-     /**
448
-      * _get_session_data
449
-      * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases
450
-      *
451
-      * @return array
452
-      * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
453
-      */
454
-     protected function _retrieve_session_data()
455
-     {
456
-         $ssn_key = EE_Session::session_id_prefix . $this->_sid;
457
-         try {
458
-             // we're using WP's Transient API to store session data using the PHP session ID as the option name
459
-             $session_data = get_transient($ssn_key);
460
-	         if ($session_data === false) {
461
-		         return array();
462
-             }
463
-             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
464
-                 $hash_check = get_transient(EE_Session::hash_check_prefix . $this->_sid);
465
-                 if ($hash_check && $hash_check !== md5($session_data)) {
466
-	                 EE_Error::add_error(
467
-                         sprintf(
468
-                             __('The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', 'event_espresso'),
469
-                             EE_Session::session_id_prefix . $this->_sid
470
-                         ),
471
-                         __FILE__, __FUNCTION__, __LINE__
472
-                     );
473
-                 }
474
-             }
475
-         } catch (Exception $e) {
476
-             // let's just eat that error for now and attempt to correct any corrupted data
477
-             global $wpdb;
478
-             $row = $wpdb->get_row(
479
-                 $wpdb->prepare(
480
-                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
481
-                     '_transient_' . $ssn_key
482
-                 )
483
-             );
484
-             $session_data = is_object($row) ? $row->option_value : null;
485
-             if ($session_data) {
486
-                 $session_data = preg_replace_callback(
487
-                     '!s:(d+):"(.*?)";!',
488
-                     function ($match) {
489
-                         return $match[1] === strlen($match[2])
490
-                             ? $match[0]
491
-                             : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
492
-                     },
493
-                     $session_data
494
-                 );
495
-             }
496
-	         $session_data = maybe_unserialize($session_data);
497
-         }
498
-	     // in case the data is encoded... try to decode it
499
-         $session_data = $this->encryption instanceof EE_Encryption
500
-             ? $this->encryption->base64_string_decode($session_data)
501
-             : $session_data;
502
-
503
-         if ( ! is_array($session_data)) {
504
-             try {
505
-	             $session_data = maybe_unserialize($session_data);
506
-             } catch (Exception $e) {
507
-                 $msg = esc_html__(
508
-                     'An error occurred while attempting to unserialize the session data.',
509
-                     'event_espresso'
510
-                 );
511
-                 $msg .= WP_DEBUG
512
-                     ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
513
-                     : '';
514
-                 throw new InvalidSessionDataException($msg, 0, $e);
515
-             }
516
-         }
517
-         // just a check to make sure the session array is indeed an array
518
-         if ( ! is_array($session_data)) {
519
-             // no?!?! then something is wrong
520
-             $msg = esc_html__(
521
-                 'The session data is missing, invalid, or corrupted.',
522
-                 'event_espresso'
523
-             );
524
-             $msg .= WP_DEBUG
525
-                 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
526
-                 : '';
527
-	         throw new InvalidSessionDataException($msg);
528
-         }
529
-	     if ( isset( $this->_session_data['transaction'] ) && absint( $this->_session_data['transaction'] ) !== 0 ) {
530
-		     $this->_session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
531
-			     $this->_session_data['transaction']
532
-	         );
533
-	     }
534
-	     return $session_data;
535
-     }
447
+	 /**
448
+	  * _get_session_data
449
+	  * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases
450
+	  *
451
+	  * @return array
452
+	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
453
+	  */
454
+	 protected function _retrieve_session_data()
455
+	 {
456
+		 $ssn_key = EE_Session::session_id_prefix . $this->_sid;
457
+		 try {
458
+			 // we're using WP's Transient API to store session data using the PHP session ID as the option name
459
+			 $session_data = get_transient($ssn_key);
460
+			 if ($session_data === false) {
461
+				 return array();
462
+			 }
463
+			 if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
464
+				 $hash_check = get_transient(EE_Session::hash_check_prefix . $this->_sid);
465
+				 if ($hash_check && $hash_check !== md5($session_data)) {
466
+					 EE_Error::add_error(
467
+						 sprintf(
468
+							 __('The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', 'event_espresso'),
469
+							 EE_Session::session_id_prefix . $this->_sid
470
+						 ),
471
+						 __FILE__, __FUNCTION__, __LINE__
472
+					 );
473
+				 }
474
+			 }
475
+		 } catch (Exception $e) {
476
+			 // let's just eat that error for now and attempt to correct any corrupted data
477
+			 global $wpdb;
478
+			 $row = $wpdb->get_row(
479
+				 $wpdb->prepare(
480
+					 "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
481
+					 '_transient_' . $ssn_key
482
+				 )
483
+			 );
484
+			 $session_data = is_object($row) ? $row->option_value : null;
485
+			 if ($session_data) {
486
+				 $session_data = preg_replace_callback(
487
+					 '!s:(d+):"(.*?)";!',
488
+					 function ($match) {
489
+						 return $match[1] === strlen($match[2])
490
+							 ? $match[0]
491
+							 : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
492
+					 },
493
+					 $session_data
494
+				 );
495
+			 }
496
+			 $session_data = maybe_unserialize($session_data);
497
+		 }
498
+		 // in case the data is encoded... try to decode it
499
+		 $session_data = $this->encryption instanceof EE_Encryption
500
+			 ? $this->encryption->base64_string_decode($session_data)
501
+			 : $session_data;
502
+
503
+		 if ( ! is_array($session_data)) {
504
+			 try {
505
+				 $session_data = maybe_unserialize($session_data);
506
+			 } catch (Exception $e) {
507
+				 $msg = esc_html__(
508
+					 'An error occurred while attempting to unserialize the session data.',
509
+					 'event_espresso'
510
+				 );
511
+				 $msg .= WP_DEBUG
512
+					 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
513
+					 : '';
514
+				 throw new InvalidSessionDataException($msg, 0, $e);
515
+			 }
516
+		 }
517
+		 // just a check to make sure the session array is indeed an array
518
+		 if ( ! is_array($session_data)) {
519
+			 // no?!?! then something is wrong
520
+			 $msg = esc_html__(
521
+				 'The session data is missing, invalid, or corrupted.',
522
+				 'event_espresso'
523
+			 );
524
+			 $msg .= WP_DEBUG
525
+				 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
526
+				 : '';
527
+			 throw new InvalidSessionDataException($msg);
528
+		 }
529
+		 if ( isset( $this->_session_data['transaction'] ) && absint( $this->_session_data['transaction'] ) !== 0 ) {
530
+			 $this->_session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
531
+				 $this->_session_data['transaction']
532
+			 );
533
+		 }
534
+		 return $session_data;
535
+	 }
536 536
 
537 537
 
538 538
 
Please login to merge, or discard this patch.
Spacing   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\InvalidSessionDataException;
2 2
 
3
-if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
4 4
 /**
5 5
  *
6 6
  * EE_Session class
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	  * array for defining default session vars
92 92
 	  * @var array
93 93
 	  */
94
-	 private $_default_session_vars = array (
94
+	 private $_default_session_vars = array(
95 95
 		'id' => NULL,
96 96
 		'user_id' => NULL,
97 97
 		'ip_address' => NULL,
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 	  * @throws InvalidSessionDataException
112 112
 	  * @throws \EE_Error
113 113
 	  */
114
-	public static function instance( EE_Encryption $encryption = null ) {
114
+	public static function instance(EE_Encryption $encryption = null) {
115 115
 		// check if class object is instantiated
116 116
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
117 117
 		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
118
-		if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) {
119
-			self::$_instance = new self( $encryption );
118
+		if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
119
+			self::$_instance = new self($encryption);
120 120
 		}
121 121
 		return self::$_instance;
122 122
 	}
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 	  * @throws \EE_Error
133 133
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
134 134
 	  */
135
-	 protected function __construct( EE_Encryption $encryption = null ) {
135
+	 protected function __construct(EE_Encryption $encryption = null) {
136 136
 
137 137
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
138
-		if ( ! apply_filters( 'FHEE_load_EE_Session', TRUE ) ) {
138
+		if ( ! apply_filters('FHEE_load_EE_Session', TRUE)) {
139 139
 			return;
140 140
 		}
141
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
142
-		if ( ! defined( 'ESPRESSO_SESSION' ) ) {
143
-			define( 'ESPRESSO_SESSION', true );
141
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
142
+		if ( ! defined('ESPRESSO_SESSION')) {
143
+			define('ESPRESSO_SESSION', true);
144 144
 		}
145 145
 		// default session lifespan in seconds
146 146
 		$this->_lifespan = apply_filters(
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 		 * 		}
155 155
 		 */
156 156
 		// retrieve session options from db
157
-		$session_settings = (array) get_option( 'ee_session_settings', array() );
158
-		if ( ! empty( $session_settings )) {
157
+		$session_settings = (array) get_option('ee_session_settings', array());
158
+		if ( ! empty($session_settings)) {
159 159
 			// cycle though existing session options
160
-			foreach ( $session_settings as $var_name => $session_setting ) {
160
+			foreach ($session_settings as $var_name => $session_setting) {
161 161
 				// set values for class properties
162
-				$var_name = '_' . $var_name;
162
+				$var_name = '_'.$var_name;
163 163
 				$this->{$var_name} = $session_setting;
164 164
 			}
165 165
 		}
@@ -169,17 +169,17 @@  discard block
 block discarded – undo
169 169
         // encrypt data via: $this->encryption->encrypt();
170 170
         $this->encryption = $encryption;
171 171
 		// filter hook allows outside functions/classes/plugins to change default empty cart
172
-		$extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() );
173
-		array_merge( $this->_default_session_vars, $extra_default_session_vars );
172
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
173
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
174 174
 		// apply default session vars
175 175
 		$this->_set_defaults();
176 176
          add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
177 177
          // check request for 'clear_session' param
178
-		add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' ));
178
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
179 179
 		// once everything is all said and done,
180
-		add_action( 'shutdown', array( $this, 'update' ), 100 );
181
-		add_action( 'shutdown', array( $this, 'garbage_collection' ), 999 );
182
-		add_filter( 'wp_redirect', array( $this, 'update_on_redirect' ), 100, 1 );
180
+		add_action('shutdown', array($this, 'update'), 100);
181
+		add_action('shutdown', array($this, 'garbage_collection'), 999);
182
+		add_filter('wp_redirect', array($this, 'update_on_redirect'), 100, 1);
183 183
 	}
184 184
 
185 185
 
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	private function _set_defaults() {
226 226
 		// set some defaults
227
-		foreach ( $this->_default_session_vars as $key => $default_var ) {
228
-			if ( is_array( $default_var )) {
229
-				$this->_session_data[ $key ] = array();
227
+		foreach ($this->_default_session_vars as $key => $default_var) {
228
+			if (is_array($default_var)) {
229
+				$this->_session_data[$key] = array();
230 230
 			} else {
231
-				$this->_session_data[ $key ] = '';
231
+				$this->_session_data[$key] = '';
232 232
 			}
233 233
 		}
234 234
 	}
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	  * @param \EE_Cart $cart
251 251
 	  * @return bool
252 252
 	  */
253
-	 public function set_cart( EE_Cart $cart ) {
253
+	 public function set_cart(EE_Cart $cart) {
254 254
 		 $this->_session_data['cart'] = $cart;
255 255
 		 return TRUE;
256 256
 	 }
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	  * @return \EE_Cart
271 271
 	  */
272 272
 	 public function cart() {
273
-		 return isset( $this->_session_data['cart'] ) ? $this->_session_data['cart'] : NULL;
273
+		 return isset($this->_session_data['cart']) ? $this->_session_data['cart'] : NULL;
274 274
 	 }
275 275
 
276 276
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	  * @param \EE_Checkout $checkout
280 280
 	  * @return bool
281 281
 	  */
282
-	 public function set_checkout( EE_Checkout $checkout ) {
282
+	 public function set_checkout(EE_Checkout $checkout) {
283 283
 		 $this->_session_data['checkout'] = $checkout;
284 284
 		 return TRUE;
285 285
 	 }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	  * @return \EE_Checkout
300 300
 	  */
301 301
 	 public function checkout() {
302
-		 return isset( $this->_session_data['checkout'] ) ? $this->_session_data['checkout'] : NULL;
302
+		 return isset($this->_session_data['checkout']) ? $this->_session_data['checkout'] : NULL;
303 303
 	 }
304 304
 
305 305
 
@@ -309,9 +309,9 @@  discard block
 block discarded – undo
309 309
 	  * @return bool
310 310
 	  * @throws \EE_Error
311 311
 	  */
312
-	 public function set_transaction( EE_Transaction $transaction ) {
312
+	 public function set_transaction(EE_Transaction $transaction) {
313 313
 		 // first remove the session from the transaction before we save the transaction in the session
314
-		 $transaction->set_txn_session_data( NULL );
314
+		 $transaction->set_txn_session_data(NULL);
315 315
 		 $this->_session_data['transaction'] = $transaction;
316 316
 		 return TRUE;
317 317
 	 }
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	  * @return \EE_Transaction
332 332
 	  */
333 333
 	 public function transaction() {
334
-		 return isset( $this->_session_data['transaction'] ) ? $this->_session_data['transaction'] : NULL;
334
+		 return isset($this->_session_data['transaction']) ? $this->_session_data['transaction'] : NULL;
335 335
 	 }
336 336
 
337 337
 
@@ -343,15 +343,15 @@  discard block
 block discarded – undo
343 343
 	  * @param bool $reset_cache
344 344
 	  * @return    array
345 345
 	  */
346
-	public function get_session_data( $key = NULL, $reset_cache = FALSE ) {
347
-		if ( $reset_cache ) {
346
+	public function get_session_data($key = NULL, $reset_cache = FALSE) {
347
+		if ($reset_cache) {
348 348
 			$this->reset_cart();
349 349
 			$this->reset_checkout();
350 350
 			$this->reset_transaction();
351 351
 		}
352
-		 if ( ! empty( $key ))  {
353
-			return  isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL;
354
-		}  else  {
352
+		 if ( ! empty($key)) {
353
+			return  isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL;
354
+		} else {
355 355
 			return $this->_session_data;
356 356
 		}
357 357
 	}
@@ -364,20 +364,20 @@  discard block
 block discarded – undo
364 364
 	  * @param 	array $data
365 365
 	  * @return 	TRUE on success, FALSE on fail
366 366
 	  */
367
-	public function set_session_data( $data ) {
367
+	public function set_session_data($data) {
368 368
 
369 369
 		// nothing ??? bad data ??? go home!
370
-		if ( empty( $data ) || ! is_array( $data )) {
371
-			EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
370
+		if (empty($data) || ! is_array($data)) {
371
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
372 372
 			return FALSE;
373 373
 		}
374 374
 
375
-		foreach ( $data as $key =>$value ) {
376
-			if ( isset( $this->_default_session_vars[ $key ] )) {
377
-				EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ );
375
+		foreach ($data as $key =>$value) {
376
+			if (isset($this->_default_session_vars[$key])) {
377
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
378 378
 				return FALSE;
379 379
 			} else {
380
-				$this->_session_data[ $key ] = $value;
380
+				$this->_session_data[$key] = $value;
381 381
 			}
382 382
 		}
383 383
 
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
 	  * @throws \EE_Error
396 396
 	  */
397 397
 	private function _espresso_session() {
398
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
398
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
399 399
 		// check that session has started
400
-		if ( session_id() === '' ) {
400
+		if (session_id() === '') {
401 401
 			//starts a new session if one doesn't already exist, or re-initiates an existing one
402 402
 			session_start();
403 403
 		}
@@ -406,38 +406,38 @@  discard block
 block discarded – undo
406 406
 		// and the visitors IP
407 407
 		$this->_ip_address = $this->_visitor_ip();
408 408
 		// set the "user agent"
409
-		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE;
409
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE;
410 410
 		// now let's retrieve what's in the db
411 411
         $session_data = $this->_retrieve_session_data();
412
-        if (! empty($session_data)) {
412
+        if ( ! empty($session_data)) {
413 413
             // get the current time in UTC
414
-			$this->_time = isset( $this->_time ) ? $this->_time : time();
414
+			$this->_time = isset($this->_time) ? $this->_time : time();
415 415
 			// and reset the session expiration
416
-			$this->_expiration = isset( $session_data['expiration'] )
416
+			$this->_expiration = isset($session_data['expiration'])
417 417
 				? $session_data['expiration']
418 418
 				: $this->_time + $this->_lifespan;
419 419
 		} else {
420 420
             // set initial site access time and the session expiration
421 421
 			$this->_set_init_access_and_expiration();
422 422
 			// set referer
423
-			$this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] )
424
-				? esc_attr( $_SERVER['HTTP_REFERER'] )
423
+			$this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
424
+				? esc_attr($_SERVER['HTTP_REFERER'])
425 425
 				: '';
426 426
 			// no previous session = go back and create one (on top of the data above)
427 427
 			return FALSE;
428 428
 		}
429 429
         // now the user agent
430
-		if ( $session_data['user_agent'] !== $this->_user_agent ) {
430
+		if ($session_data['user_agent'] !== $this->_user_agent) {
431 431
 			return FALSE;
432 432
 		}
433 433
 		// wait a minute... how old are you?
434
-		if ( $this->_time > $this->_expiration ) {
434
+		if ($this->_time > $this->_expiration) {
435 435
 			// yer too old fer me!
436 436
 			// wipe out everything that isn't a default session datum
437
-			$this->clear_session( __CLASS__, __FUNCTION__ );
437
+			$this->clear_session(__CLASS__, __FUNCTION__);
438 438
 		}
439 439
 		// make event espresso session data available to plugin
440
-		$this->_session_data = array_merge( $this->_session_data, $session_data );
440
+		$this->_session_data = array_merge($this->_session_data, $session_data);
441 441
 		return TRUE;
442 442
 
443 443
 	}
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
       */
454 454
      protected function _retrieve_session_data()
455 455
      {
456
-         $ssn_key = EE_Session::session_id_prefix . $this->_sid;
456
+         $ssn_key = EE_Session::session_id_prefix.$this->_sid;
457 457
          try {
458 458
              // we're using WP's Transient API to store session data using the PHP session ID as the option name
459 459
              $session_data = get_transient($ssn_key);
@@ -461,12 +461,12 @@  discard block
 block discarded – undo
461 461
 		         return array();
462 462
              }
463 463
              if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
464
-                 $hash_check = get_transient(EE_Session::hash_check_prefix . $this->_sid);
464
+                 $hash_check = get_transient(EE_Session::hash_check_prefix.$this->_sid);
465 465
                  if ($hash_check && $hash_check !== md5($session_data)) {
466 466
 	                 EE_Error::add_error(
467 467
                          sprintf(
468 468
                              __('The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', 'event_espresso'),
469
-                             EE_Session::session_id_prefix . $this->_sid
469
+                             EE_Session::session_id_prefix.$this->_sid
470 470
                          ),
471 471
                          __FILE__, __FUNCTION__, __LINE__
472 472
                      );
@@ -478,17 +478,17 @@  discard block
 block discarded – undo
478 478
              $row = $wpdb->get_row(
479 479
                  $wpdb->prepare(
480 480
                      "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
481
-                     '_transient_' . $ssn_key
481
+                     '_transient_'.$ssn_key
482 482
                  )
483 483
              );
484 484
              $session_data = is_object($row) ? $row->option_value : null;
485 485
              if ($session_data) {
486 486
                  $session_data = preg_replace_callback(
487 487
                      '!s:(d+):"(.*?)";!',
488
-                     function ($match) {
488
+                     function($match) {
489 489
                          return $match[1] === strlen($match[2])
490 490
                              ? $match[0]
491
-                             : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
491
+                             : 's:'.strlen($match[2]).':"'.$match[2].'";';
492 492
                      },
493 493
                      $session_data
494 494
                  );
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
                      'event_espresso'
510 510
                  );
511 511
                  $msg .= WP_DEBUG
512
-                     ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
512
+                     ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
513 513
                      : '';
514 514
                  throw new InvalidSessionDataException($msg, 0, $e);
515 515
              }
@@ -522,11 +522,11 @@  discard block
 block discarded – undo
522 522
                  'event_espresso'
523 523
              );
524 524
              $msg .= WP_DEBUG
525
-                 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
525
+                 ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
526 526
                  : '';
527 527
 	         throw new InvalidSessionDataException($msg);
528 528
          }
529
-	     if ( isset( $this->_session_data['transaction'] ) && absint( $this->_session_data['transaction'] ) !== 0 ) {
529
+	     if (isset($this->_session_data['transaction']) && absint($this->_session_data['transaction']) !== 0) {
530 530
 		     $this->_session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
531 531
 			     $this->_session_data['transaction']
532 532
 	         );
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
 	  */
548 548
 	protected function _generate_session_id() {
549 549
 		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
550
-		if ( isset( $_REQUEST[ 'EESID' ] ) ) {
551
-			$session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] );
550
+		if (isset($_REQUEST['EESID'])) {
551
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
552 552
 		} else {
553
-			$session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() );
553
+			$session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
554 554
 		}
555
-		return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id );
555
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
556 556
 	}
557 557
 
558 558
 
@@ -564,20 +564,20 @@  discard block
 block discarded – undo
564 564
 	  */
565 565
 	protected function _get_sid_salt() {
566 566
 		// was session id salt already saved to db ?
567
-		if ( empty( $this->_sid_salt ) ) {
567
+		if (empty($this->_sid_salt)) {
568 568
 			// no?  then maybe use WP defined constant
569
-			if ( defined( 'AUTH_SALT' ) ) {
569
+			if (defined('AUTH_SALT')) {
570 570
 				$this->_sid_salt = AUTH_SALT;
571 571
 			}
572 572
 			// if salt doesn't exist or is too short
573
-			if ( empty( $this->_sid_salt ) || strlen( $this->_sid_salt ) < 32 ) {
573
+			if (empty($this->_sid_salt) || strlen($this->_sid_salt) < 32) {
574 574
 				// create a new one
575
-				$this->_sid_salt = wp_generate_password( 64 );
575
+				$this->_sid_salt = wp_generate_password(64);
576 576
 			}
577 577
 			// and save it as a permanent session setting
578
-			$session_settings = get_option( 'ee_session_settings' );
579
-			$session_settings[ 'sid_salt' ] = $this->_sid_salt;
580
-			update_option( 'ee_session_settings', $session_settings );
578
+			$session_settings = get_option('ee_session_settings');
579
+			$session_settings['sid_salt'] = $this->_sid_salt;
580
+			update_option('ee_session_settings', $session_settings);
581 581
 		}
582 582
 		return $this->_sid_salt;
583 583
 	}
@@ -605,19 +605,19 @@  discard block
 block discarded – undo
605 605
 	  * @param bool $new_session
606 606
 	  * @return TRUE on success, FALSE on fail
607 607
 	  */
608
-	public function update( $new_session = FALSE ) {
609
-		$this->_session_data = isset( $this->_session_data )
610
-			&& is_array( $this->_session_data )
611
-			&& isset( $this->_session_data['id'])
608
+	public function update($new_session = FALSE) {
609
+		$this->_session_data = isset($this->_session_data)
610
+			&& is_array($this->_session_data)
611
+			&& isset($this->_session_data['id'])
612 612
 			? $this->_session_data
613 613
 			: array();
614
-		if ( empty( $this->_session_data )) {
614
+		if (empty($this->_session_data)) {
615 615
 			$this->_set_defaults();
616 616
 		}
617 617
 		$session_data = array();
618
-		foreach ( $this->_session_data as $key => $value ) {
618
+		foreach ($this->_session_data as $key => $value) {
619 619
 
620
-			switch( $key ) {
620
+			switch ($key) {
621 621
 
622 622
 				case 'id' :
623 623
 					// session ID
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 				break;
636 636
 
637 637
 				case 'init_access' :
638
-					$session_data['init_access'] = absint( $value );
638
+					$session_data['init_access'] = absint($value);
639 639
 				break;
640 640
 
641 641
 				case 'last_access' :
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 
646 646
 				case 'expiration' :
647 647
 					// when the session expires
648
-					$session_data['expiration'] = ! empty( $this->_expiration )
648
+					$session_data['expiration'] = ! empty($this->_expiration)
649 649
 						? $this->_expiration
650 650
 						: $session_data['init_access'] + $this->_lifespan;
651 651
 				break;
@@ -657,11 +657,11 @@  discard block
 block discarded – undo
657 657
 
658 658
 				case 'pages_visited' :
659 659
 					$page_visit = $this->_get_page_visit();
660
-					if ( $page_visit ) {
660
+					if ($page_visit) {
661 661
 						// set pages visited where the first will be the http referrer
662
-						$this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit;
662
+						$this->_session_data['pages_visited'][$this->_time] = $page_visit;
663 663
 						// we'll only save the last 10 page visits.
664
-						$session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 );
664
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
665 665
 					}
666 666
 				break;
667 667
 
@@ -675,9 +675,9 @@  discard block
 block discarded – undo
675 675
 
676 676
 		$this->_session_data = $session_data;
677 677
 		// creating a new session does not require saving to the db just yet
678
-		if ( ! $new_session ) {
678
+		if ( ! $new_session) {
679 679
 			// ready? let's save
680
-			if ( $this->_save_session_to_db() ) {
680
+			if ($this->_save_session_to_db()) {
681 681
 				return TRUE;
682 682
 			} else {
683 683
 				return FALSE;
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 	  * @param string $location
700 700
 	  * @return mixed
701 701
 	  */
702
-	 public function update_on_redirect( $location ) {
702
+	 public function update_on_redirect($location) {
703 703
 		 $this->update();
704 704
 		 return $location;
705 705
 	}
@@ -711,9 +711,9 @@  discard block
 block discarded – undo
711 711
 	 * 	@return bool
712 712
 	 */
713 713
 	private function _create_espresso_session( ) {
714
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' );
714
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
715 715
 		// use the update function for now with $new_session arg set to TRUE
716
-		return  $this->update( TRUE ) ? TRUE : FALSE;
716
+		return  $this->update(TRUE) ? TRUE : FALSE;
717 717
 	}
718 718
 
719 719
 
@@ -739,15 +739,15 @@  discard block
 block discarded – undo
739 739
 				// OR an admin request that is NOT AJAX
740 740
 				|| (
741 741
 					is_admin()
742
-					&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
742
+					&& ! (defined('DOING_AJAX') && DOING_AJAX)
743 743
 				)
744 744
 			)
745 745
 		) {
746 746
 			return false;
747 747
 		}
748 748
 		$transaction = $this->_session_data['transaction'];
749
-		if ( $transaction instanceof EE_Transaction ) {
750
-			if ( ! $transaction->ID() ) {
749
+		if ($transaction instanceof EE_Transaction) {
750
+			if ( ! $transaction->ID()) {
751 751
 				$transaction->save();
752 752
 			}
753 753
 			$this->_session_data['transaction'] = $transaction->ID();
@@ -755,13 +755,13 @@  discard block
 block discarded – undo
755 755
 		// then serialize all of our session data
756 756
 		$session_data = serialize($this->_session_data);
757 757
 		// do we need to also encode it to avoid corrupted data when saved to the db?
758
-		$session_data = $this->_use_encryption ? $this->encryption->base64_string_encode( $session_data ) : $session_data;
758
+		$session_data = $this->_use_encryption ? $this->encryption->base64_string_encode($session_data) : $session_data;
759 759
 		// maybe save hash check
760
-		if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) {
761
-			set_transient( EE_Session::hash_check_prefix . $this->_sid, md5( $session_data ), $this->_lifespan );
760
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
761
+			set_transient(EE_Session::hash_check_prefix.$this->_sid, md5($session_data), $this->_lifespan);
762 762
 		}
763 763
 		// we're using the Transient API for storing session data, cuz it's so damn simple -> set_transient(  transient ID, data, expiry )
764
-		return set_transient( EE_Session::session_id_prefix . $this->_sid, $session_data, $this->_lifespan );
764
+		return set_transient(EE_Session::session_id_prefix.$this->_sid, $session_data, $this->_lifespan);
765 765
 	}
766 766
 
767 767
 
@@ -787,10 +787,10 @@  discard block
 block discarded – undo
787 787
 			'HTTP_FORWARDED',
788 788
 			'REMOTE_ADDR'
789 789
 		);
790
-		foreach ( $server_keys as $key ){
791
-			if ( isset( $_SERVER[ $key ] )) {
792
-				foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) {
793
-					if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) {
790
+		foreach ($server_keys as $key) {
791
+			if (isset($_SERVER[$key])) {
792
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
793
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) {
794 794
 						$visitor_ip = $ip;
795 795
 					}
796 796
 				}
@@ -809,32 +809,32 @@  discard block
 block discarded – undo
809 809
 	 *			@return string
810 810
 	 */
811 811
 	public function _get_page_visit() {
812
-		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
812
+		$page_visit = home_url('/').'wp-admin/admin-ajax.php';
813 813
 		// check for request url
814
-		if ( isset( $_SERVER['REQUEST_URI'] )) {
814
+		if (isset($_SERVER['REQUEST_URI'])) {
815 815
 			$http_host = '';
816 816
 			$page_id = '?';
817 817
 			$e_reg = '';
818
-			$request_uri = esc_url( $_SERVER['REQUEST_URI'] );
819
-			$ru_bits = explode( '?', $request_uri );
818
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
819
+			$ru_bits = explode('?', $request_uri);
820 820
 			$request_uri = $ru_bits[0];
821 821
 			// check for and grab host as well
822
-			if ( isset( $_SERVER['HTTP_HOST'] )) {
823
-				$http_host = esc_url( $_SERVER['HTTP_HOST'] );
822
+			if (isset($_SERVER['HTTP_HOST'])) {
823
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
824 824
 			}
825 825
 			// check for page_id in SERVER REQUEST
826
-			if ( isset( $_REQUEST['page_id'] )) {
826
+			if (isset($_REQUEST['page_id'])) {
827 827
 				// rebuild $e_reg without any of the extra parameters
828
-				$page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&amp;';
828
+				$page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
829 829
 			}
830 830
 			// check for $e_reg in SERVER REQUEST
831
-			if ( isset( $_REQUEST['ee'] )) {
831
+			if (isset($_REQUEST['ee'])) {
832 832
 				// rebuild $e_reg without any of the extra parameters
833
-				$e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] );
833
+				$e_reg = 'ee='.esc_attr($_REQUEST['ee']);
834 834
 			}
835
-			$page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' );
835
+			$page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
836 836
 		}
837
-		return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : '';
837
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
838 838
 
839 839
 	}
840 840
 
@@ -863,14 +863,14 @@  discard block
 block discarded – undo
863 863
 	  * @param string $function
864 864
 	  * @return void
865 865
 	  */
866
-	public function clear_session( $class = '', $function = '' ) {
866
+	public function clear_session($class = '', $function = '') {
867 867
 		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
868
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' .  $function . '()' );
868
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
869 869
 		$this->reset_cart();
870 870
 		$this->reset_checkout();
871 871
 		$this->reset_transaction();
872 872
 		// wipe out everything that isn't a default session datum
873
-		$this->reset_data( array_keys( $this->_session_data ));
873
+		$this->reset_data(array_keys($this->_session_data));
874 874
 		// reset initial site access time and the session expiration
875 875
 		$this->_set_init_access_and_expiration();
876 876
 		$this->_save_session_to_db();
@@ -885,42 +885,42 @@  discard block
 block discarded – undo
885 885
 	  * @param bool  $show_all_notices
886 886
 	  * @return TRUE on success, FALSE on fail
887 887
 	  */
888
-	public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) {
888
+	public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) {
889 889
 		// if $data_to_reset is not in an array, then put it in one
890
-		if ( ! is_array( $data_to_reset ) ) {
891
-			$data_to_reset = array ( $data_to_reset );
890
+		if ( ! is_array($data_to_reset)) {
891
+			$data_to_reset = array($data_to_reset);
892 892
 		}
893 893
 		// nothing ??? go home!
894
-		if ( empty( $data_to_reset )) {
895
-			EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
894
+		if (empty($data_to_reset)) {
895
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
896 896
 			return FALSE;
897 897
 		}
898 898
 		$return_value = TRUE;
899 899
 		// since $data_to_reset is an array, cycle through the values
900
-		foreach ( $data_to_reset as $reset ) {
900
+		foreach ($data_to_reset as $reset) {
901 901
 
902 902
 			// first check to make sure it is a valid session var
903
-			if ( isset( $this->_session_data[ $reset ] )) {
903
+			if (isset($this->_session_data[$reset])) {
904 904
 				// then check to make sure it is not a default var
905
-				if ( ! array_key_exists( $reset, $this->_default_session_vars )) {
905
+				if ( ! array_key_exists($reset, $this->_default_session_vars)) {
906 906
 					// remove session var
907
-					unset( $this->_session_data[ $reset ] );
908
-					if ( $show_all_notices ) {
909
-						EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
907
+					unset($this->_session_data[$reset]);
908
+					if ($show_all_notices) {
909
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
910 910
 					}
911
-					$return_value = !isset($return_value) ? TRUE : $return_value;
911
+					$return_value = ! isset($return_value) ? TRUE : $return_value;
912 912
 
913 913
 				} else {
914 914
 					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
915
-					if ( $show_all_notices ) {
916
-						EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
915
+					if ($show_all_notices) {
916
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
917 917
 					}
918 918
 					$return_value = FALSE;
919 919
 				}
920 920
 
921
-			} else if ( $show_all_notices ) {
921
+			} else if ($show_all_notices) {
922 922
 				// oops! that session var does not exist!
923
-				EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
923
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
924 924
 				$return_value = FALSE;
925 925
 			}
926 926
 
@@ -940,8 +940,8 @@  discard block
 block discarded – undo
940 940
 	 *   @access public
941 941
 	 */
942 942
 	public function wp_loaded() {
943
-		if ( isset(  EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) {
944
-			$this->clear_session( __CLASS__, __FUNCTION__ );
943
+		if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) {
944
+			$this->clear_session(__CLASS__, __FUNCTION__);
945 945
 		}
946 946
 	}
947 947
 
@@ -966,24 +966,24 @@  discard block
 block discarded – undo
966 966
 	  */
967 967
 	 public function garbage_collection() {
968 968
 		 // only perform during regular requests
969
-		 if ( ! defined( 'DOING_AJAX') || ! DOING_AJAX ) {
969
+		 if ( ! defined('DOING_AJAX') || ! DOING_AJAX) {
970 970
 			 /** @type WPDB $wpdb */
971 971
 			 global $wpdb;
972 972
 			 // since transient expiration timestamps are set in the future, we can compare against NOW
973 973
 			 $expiration = time();
974
-			 $too_far_in_the_the_future = $expiration + ( $this->_lifespan * 2 );
974
+			 $too_far_in_the_the_future = $expiration + ($this->_lifespan * 2);
975 975
 			 // filter the query limit. Set to 0 to turn off garbage collection
976
-			 $expired_session_transient_delete_query_limit = absint( apply_filters( 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', 50 ));
976
+			 $expired_session_transient_delete_query_limit = absint(apply_filters('FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', 50));
977 977
 			 // non-zero LIMIT means take out the trash
978
-			 if ( $expired_session_transient_delete_query_limit ) {
978
+			 if ($expired_session_transient_delete_query_limit) {
979 979
 				 //array of transient keys that require garbage collection
980 980
 				 $session_keys = array(
981 981
 					 EE_Session::session_id_prefix,
982 982
 					 EE_Session::hash_check_prefix,
983 983
 				 );
984
-				 foreach ( $session_keys as $session_key ) {
985
-					 $session_key = str_replace( '_', '\_', $session_key );
986
-					 $session_key = '\_transient\_timeout\_' . $session_key . '%';
984
+				 foreach ($session_keys as $session_key) {
985
+					 $session_key = str_replace('_', '\_', $session_key);
986
+					 $session_key = '\_transient\_timeout\_'.$session_key.'%';
987 987
 					 $SQL = "
988 988
 					SELECT option_name
989 989
 					FROM {$wpdb->options}
@@ -993,25 +993,25 @@  discard block
 block discarded – undo
993 993
 					OR option_value > {$too_far_in_the_the_future} )
994 994
 					LIMIT {$expired_session_transient_delete_query_limit}
995 995
 				";
996
-					 $expired_sessions = $wpdb->get_col( $SQL );
996
+					 $expired_sessions = $wpdb->get_col($SQL);
997 997
 					 // valid results?
998
-					 if ( ! $expired_sessions instanceof WP_Error && ! empty( $expired_sessions ) ) {
998
+					 if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
999 999
 						 // format array of results into something usable within the actual DELETE query's IN clause
1000 1000
 						 $expired = array();
1001
-						 foreach ( $expired_sessions as $expired_session ) {
1002
-							 $expired[ ] = "'" . $expired_session . "'";
1003
-							 $expired[ ] = "'" . str_replace( 'timeout_', '', $expired_session ) . "'";
1001
+						 foreach ($expired_sessions as $expired_session) {
1002
+							 $expired[] = "'".$expired_session."'";
1003
+							 $expired[] = "'".str_replace('timeout_', '', $expired_session)."'";
1004 1004
 						 }
1005
-						 $expired = implode( ', ', $expired );
1005
+						 $expired = implode(', ', $expired);
1006 1006
 						 $SQL = "
1007 1007
 						DELETE FROM {$wpdb->options}
1008 1008
 						WHERE option_name
1009 1009
 						IN ( $expired );
1010 1010
 					 ";
1011
-						 $results = $wpdb->query( $SQL );
1011
+						 $results = $wpdb->query($SQL);
1012 1012
 						 // if something went wrong, then notify the admin
1013
-						 if ( $results instanceof WP_Error && is_admin() ) {
1014
-							 EE_Error::add_error( $results->get_error_message(), __FILE__, __FUNCTION__, __LINE__ );
1013
+						 if ($results instanceof WP_Error && is_admin()) {
1014
+							 EE_Error::add_error($results->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
1015 1015
 						 }
1016 1016
 					 }
1017 1017
 				 }
@@ -1032,34 +1032,34 @@  discard block
 block discarded – undo
1032 1032
 	  * @param $data1
1033 1033
 	  * @return string
1034 1034
 	  */
1035
-	 private function find_serialize_error( $data1 ) {
1035
+	 private function find_serialize_error($data1) {
1036 1036
 		$error = "<pre>";
1037 1037
 		 $data2 = preg_replace_callback(
1038 1038
 			 '!s:(\d+):"(.*?)";!',
1039
-			 function ( $match ) {
1040
-				 return ( $match[1] === strlen( $match[2] ) )
1039
+			 function($match) {
1040
+				 return ($match[1] === strlen($match[2]))
1041 1041
 					 ? $match[0]
1042 1042
 					 : 's:'
1043
-					   . strlen( $match[2] )
1043
+					   . strlen($match[2])
1044 1044
 					   . ':"'
1045 1045
 					   . $match[2]
1046 1046
 					   . '";';
1047 1047
 			 },
1048 1048
 			 $data1
1049 1049
 		 );
1050
-		$max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 );
1051
-		$error .= $data1 . PHP_EOL;
1052
-		$error .= $data2 . PHP_EOL;
1053
-		for ( $i = 0; $i < $max; $i++ ) {
1054
-			if ( @$data1[ $i ] !== @$data2[ $i ] ) {
1055
-				$error .= "Difference " . @$data1[ $i ] . " != " . @$data2[ $i ] . PHP_EOL;
1056
-				$error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . " != " . ord( @$data2[ $i ] ) . PHP_EOL;
1057
-				$error .= "\t-> Line Number = $i" . PHP_EOL;
1058
-				$start = ( $i - 20 );
1059
-				$start = ( $start < 0 ) ? 0 : $start;
1050
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1051
+		$error .= $data1.PHP_EOL;
1052
+		$error .= $data2.PHP_EOL;
1053
+		for ($i = 0; $i < $max; $i++) {
1054
+			if (@$data1[$i] !== @$data2[$i]) {
1055
+				$error .= "Difference ".@$data1[$i]." != ".@$data2[$i].PHP_EOL;
1056
+				$error .= "\t-> ORD number ".ord(@$data1[$i])." != ".ord(@$data2[$i]).PHP_EOL;
1057
+				$error .= "\t-> Line Number = $i".PHP_EOL;
1058
+				$start = ($i - 20);
1059
+				$start = ($start < 0) ? 0 : $start;
1060 1060
 				$length = 40;
1061 1061
 				$point = $max - $i;
1062
-				if ( $point < 20 ) {
1062
+				if ($point < 20) {
1063 1063
 					$rlength = 1;
1064 1064
 					$rpoint = -$point;
1065 1065
 				} else {
@@ -1068,16 +1068,16 @@  discard block
 block discarded – undo
1068 1068
 				}
1069 1069
 				$error .= "\t-> Section Data1  = ";
1070 1070
 				$error .= substr_replace(
1071
-					substr( $data1, $start, $length ),
1072
-					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1071
+					substr($data1, $start, $length),
1072
+					"<b style=\"color:green\">{$data1[$i]}</b>",
1073 1073
 					$rpoint,
1074 1074
 					$rlength
1075 1075
 				);
1076 1076
 				$error .= PHP_EOL;
1077 1077
 				$error .= "\t-> Section Data2  = ";
1078 1078
 				$error .= substr_replace(
1079
-					substr( $data2, $start, $length ),
1080
-					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1079
+					substr($data2, $start, $length),
1080
+					"<b style=\"color:red\">{$data2[$i]}</b>",
1081 1081
 					$rpoint,
1082 1082
 					$rlength
1083 1083
 				);
Please login to merge, or discard this patch.