Completed
Branch BUG-10738-inconsistency-in-ses... (a1eed8)
by
unknown
24:27 queued 12:29
created
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +4060 added lines, -4060 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidInterfaceException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('NO direct script access allowed');
8
+	exit('NO direct script access allowed');
9 9
 }
10 10
 
11 11
 /**
@@ -23,2559 +23,2559 @@  discard block
 block discarded – undo
23 23
 class Messages_Admin_Page extends EE_Admin_Page
24 24
 {
25 25
     
26
-    /**
27
-     * @type EE_Message_Resource_Manager $_message_resource_manager
28
-     */
29
-    protected $_message_resource_manager;
26
+	/**
27
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
28
+	 */
29
+	protected $_message_resource_manager;
30 30
     
31
-    /**
32
-     * @type string $_active_message_type_name
33
-     */
34
-    protected $_active_message_type_name = '';
31
+	/**
32
+	 * @type string $_active_message_type_name
33
+	 */
34
+	protected $_active_message_type_name = '';
35 35
     
36
-    /**
37
-     * @type EE_messenger $_active_messenger
38
-     */
39
-    protected $_active_messenger;
40
-    protected $_activate_state;
41
-    protected $_activate_meta_box_type;
42
-    protected $_current_message_meta_box;
43
-    protected $_current_message_meta_box_object;
44
-    protected $_context_switcher;
45
-    protected $_shortcodes = array();
46
-    protected $_active_messengers = array();
47
-    protected $_active_message_types = array();
36
+	/**
37
+	 * @type EE_messenger $_active_messenger
38
+	 */
39
+	protected $_active_messenger;
40
+	protected $_activate_state;
41
+	protected $_activate_meta_box_type;
42
+	protected $_current_message_meta_box;
43
+	protected $_current_message_meta_box_object;
44
+	protected $_context_switcher;
45
+	protected $_shortcodes = array();
46
+	protected $_active_messengers = array();
47
+	protected $_active_message_types = array();
48 48
     
49
-    /**
50
-     * @var EE_Message_Template_Group $_message_template_group
51
-     */
52
-    protected $_message_template_group;
53
-    protected $_m_mt_settings = array();
49
+	/**
50
+	 * @var EE_Message_Template_Group $_message_template_group
51
+	 */
52
+	protected $_message_template_group;
53
+	protected $_m_mt_settings = array();
54 54
     
55 55
     
56
-    /**
57
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
-     * IF there is no group then it gets automatically set to the Default template pack.
59
-     *
60
-     * @since 4.5.0
61
-     *
62
-     * @var EE_Messages_Template_Pack
63
-     */
64
-    protected $_template_pack;
56
+	/**
57
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
+	 * IF there is no group then it gets automatically set to the Default template pack.
59
+	 *
60
+	 * @since 4.5.0
61
+	 *
62
+	 * @var EE_Messages_Template_Pack
63
+	 */
64
+	protected $_template_pack;
65 65
     
66 66
     
67
-    /**
68
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
-     * group is.  If there is no group then it automatically gets set to default.
70
-     *
71
-     * @since 4.5.0
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_variation;
67
+	/**
68
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
+	 * group is.  If there is no group then it automatically gets set to default.
70
+	 *
71
+	 * @since 4.5.0
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_variation;
76 76
 
77 77
 
78
-    /**
79
-     * @param bool $routing
80
-     * @throws EE_Error
81
-     */
82
-    public function __construct($routing = true)
83
-    {
84
-        //make sure messages autoloader is running
85
-        EED_Messages::set_autoloaders();
86
-        parent::__construct($routing);
87
-    }
78
+	/**
79
+	 * @param bool $routing
80
+	 * @throws EE_Error
81
+	 */
82
+	public function __construct($routing = true)
83
+	{
84
+		//make sure messages autoloader is running
85
+		EED_Messages::set_autoloaders();
86
+		parent::__construct($routing);
87
+	}
88 88
     
89 89
     
90
-    protected function _init_page_props()
91
-    {
92
-        $this->page_slug        = EE_MSG_PG_SLUG;
93
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
-        $this->_admin_base_path = EE_MSG_ADMIN;
96
-        
97
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
-        
99
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
-        $this->_load_message_resource_manager();
101
-    }
90
+	protected function _init_page_props()
91
+	{
92
+		$this->page_slug        = EE_MSG_PG_SLUG;
93
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
+		$this->_admin_base_path = EE_MSG_ADMIN;
96
+        
97
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
+        
99
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
+		$this->_load_message_resource_manager();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
-     *
107
-     * @throws EE_Error
108
-     * @throws InvalidDataTypeException
109
-     * @throws InvalidInterfaceException
110
-     * @throws InvalidArgumentException
111
-     * @throws ReflectionException
112
-     */
113
-    protected function _load_message_resource_manager()
114
-    {
115
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
-    }
104
+	/**
105
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
+	 *
107
+	 * @throws EE_Error
108
+	 * @throws InvalidDataTypeException
109
+	 * @throws InvalidInterfaceException
110
+	 * @throws InvalidArgumentException
111
+	 * @throws ReflectionException
112
+	 */
113
+	protected function _load_message_resource_manager()
114
+	{
115
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * @deprecated 4.9.9.rc.014
121
-     * @return array
122
-     * @throws EE_Error
123
-     * @throws InvalidArgumentException
124
-     * @throws InvalidDataTypeException
125
-     * @throws InvalidInterfaceException
126
-     */
127
-    public function get_messengers_for_list_table()
128
-    {
129
-        EE_Error::doing_it_wrong(
130
-            __METHOD__,
131
-            sprintf(
132
-                esc_html__(
133
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
134
-                    'event_espresso'
135
-                ),
136
-                'Messages_Admin_Page::get_messengers_select_input()'
137
-            ),
138
-            '4.9.9.rc.014'
139
-        );
140
-        
141
-        $m_values          = array();
142
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
-        //setup messengers for selects
144
-        $i = 1;
145
-        foreach ($active_messengers as $active_messenger) {
146
-            if ($active_messenger instanceof EE_Message) {
147
-                $m_values[$i]['id']   = $active_messenger->messenger();
148
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
-                $i++;
150
-            }
151
-        }
152
-        
153
-        return $m_values;
154
-    }
119
+	/**
120
+	 * @deprecated 4.9.9.rc.014
121
+	 * @return array
122
+	 * @throws EE_Error
123
+	 * @throws InvalidArgumentException
124
+	 * @throws InvalidDataTypeException
125
+	 * @throws InvalidInterfaceException
126
+	 */
127
+	public function get_messengers_for_list_table()
128
+	{
129
+		EE_Error::doing_it_wrong(
130
+			__METHOD__,
131
+			sprintf(
132
+				esc_html__(
133
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
134
+					'event_espresso'
135
+				),
136
+				'Messages_Admin_Page::get_messengers_select_input()'
137
+			),
138
+			'4.9.9.rc.014'
139
+		);
140
+        
141
+		$m_values          = array();
142
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
+		//setup messengers for selects
144
+		$i = 1;
145
+		foreach ($active_messengers as $active_messenger) {
146
+			if ($active_messenger instanceof EE_Message) {
147
+				$m_values[$i]['id']   = $active_messenger->messenger();
148
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
+				$i++;
150
+			}
151
+		}
152
+        
153
+		return $m_values;
154
+	}
155 155
 
156 156
 
157
-    /**
158
-     * @deprecated 4.9.9.rc.014
159
-     * @return array
160
-     * @throws EE_Error
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     */
165
-    public function get_message_types_for_list_table()
166
-    {
167
-        EE_Error::doing_it_wrong(
168
-            __METHOD__,
169
-            sprintf(
170
-                esc_html__(
171
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
172
-                    'event_espresso'
173
-                ),
174
-                'Messages_Admin_Page::get_message_types_select_input()'
175
-            ),
176
-            '4.9.9.rc.014'
177
-        );
178
-        
179
-        $mt_values       = array();
180
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
-        $i               = 1;
182
-        foreach ($active_messages as $active_message) {
183
-            if ($active_message instanceof EE_Message) {
184
-                $mt_values[$i]['id']   = $active_message->message_type();
185
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
-                $i++;
187
-            }
188
-        }
189
-        
190
-        return $mt_values;
191
-    }
157
+	/**
158
+	 * @deprecated 4.9.9.rc.014
159
+	 * @return array
160
+	 * @throws EE_Error
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 */
165
+	public function get_message_types_for_list_table()
166
+	{
167
+		EE_Error::doing_it_wrong(
168
+			__METHOD__,
169
+			sprintf(
170
+				esc_html__(
171
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
172
+					'event_espresso'
173
+				),
174
+				'Messages_Admin_Page::get_message_types_select_input()'
175
+			),
176
+			'4.9.9.rc.014'
177
+		);
178
+        
179
+		$mt_values       = array();
180
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
+		$i               = 1;
182
+		foreach ($active_messages as $active_message) {
183
+			if ($active_message instanceof EE_Message) {
184
+				$mt_values[$i]['id']   = $active_message->message_type();
185
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
+				$i++;
187
+			}
188
+		}
189
+        
190
+		return $mt_values;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * @deprecated 4.9.9.rc.014
196
-     * @return array
197
-     * @throws EE_Error
198
-     * @throws InvalidArgumentException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     */
202
-    public function get_contexts_for_message_types_for_list_table()
203
-    {
204
-        EE_Error::doing_it_wrong(
205
-            __METHOD__,
206
-            sprintf(
207
-                esc_html__(
208
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
209
-                    'event_espresso'
210
-                ),
211
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
-            ),
213
-            '4.9.9.rc.014'
214
-        );
215
-        
216
-        $contexts                = array();
217
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
-        foreach ($active_message_contexts as $active_message) {
219
-            if ($active_message instanceof EE_Message) {
220
-                $message_type = $active_message->message_type_object();
221
-                if ($message_type instanceof EE_message_type) {
222
-                    $message_type_contexts = $message_type->get_contexts();
223
-                    foreach ($message_type_contexts as $context => $context_details) {
224
-                        $contexts[$context] = $context_details['label'];
225
-                    }
226
-                }
227
-            }
228
-        }
229
-        
230
-        return $contexts;
231
-    }
194
+	/**
195
+	 * @deprecated 4.9.9.rc.014
196
+	 * @return array
197
+	 * @throws EE_Error
198
+	 * @throws InvalidArgumentException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 */
202
+	public function get_contexts_for_message_types_for_list_table()
203
+	{
204
+		EE_Error::doing_it_wrong(
205
+			__METHOD__,
206
+			sprintf(
207
+				esc_html__(
208
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
209
+					'event_espresso'
210
+				),
211
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
+			),
213
+			'4.9.9.rc.014'
214
+		);
215
+        
216
+		$contexts                = array();
217
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
+		foreach ($active_message_contexts as $active_message) {
219
+			if ($active_message instanceof EE_Message) {
220
+				$message_type = $active_message->message_type_object();
221
+				if ($message_type instanceof EE_message_type) {
222
+					$message_type_contexts = $message_type->get_contexts();
223
+					foreach ($message_type_contexts as $context => $context_details) {
224
+						$contexts[$context] = $context_details['label'];
225
+					}
226
+				}
227
+			}
228
+		}
229
+        
230
+		return $contexts;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * Generate select input with provided messenger options array.
236
-     *
237
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
-     *                                 labels.
239
-     * @return string
240
-     * @throws EE_Error
241
-     */
242
-    public function get_messengers_select_input($messenger_options)
243
-    {
244
-        //if empty or just one value then just return an empty string
245
-        if (empty($messenger_options)
246
-            || ! is_array($messenger_options)
247
-            || count($messenger_options) === 1
248
-        ) {
249
-            return '';
250
-        }
251
-        //merge in default
252
-        $messenger_options = array_merge(
253
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
-            $messenger_options
255
-        );
256
-        $input             = new EE_Select_Input(
257
-            $messenger_options,
258
-            array(
259
-                'html_name'  => 'ee_messenger_filter_by',
260
-                'html_id'    => 'ee_messenger_filter_by',
261
-                'html_class' => 'wide',
262
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
-                    : 'none_selected'
265
-            )
266
-        );
267
-        
268
-        return $input->get_html_for_input();
269
-    }
234
+	/**
235
+	 * Generate select input with provided messenger options array.
236
+	 *
237
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
+	 *                                 labels.
239
+	 * @return string
240
+	 * @throws EE_Error
241
+	 */
242
+	public function get_messengers_select_input($messenger_options)
243
+	{
244
+		//if empty or just one value then just return an empty string
245
+		if (empty($messenger_options)
246
+			|| ! is_array($messenger_options)
247
+			|| count($messenger_options) === 1
248
+		) {
249
+			return '';
250
+		}
251
+		//merge in default
252
+		$messenger_options = array_merge(
253
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
+			$messenger_options
255
+		);
256
+		$input             = new EE_Select_Input(
257
+			$messenger_options,
258
+			array(
259
+				'html_name'  => 'ee_messenger_filter_by',
260
+				'html_id'    => 'ee_messenger_filter_by',
261
+				'html_class' => 'wide',
262
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
+					: 'none_selected'
265
+			)
266
+		);
267
+        
268
+		return $input->get_html_for_input();
269
+	}
270 270
 
271 271
 
272
-    /**
273
-     * Generate select input with provided message type options array.
274
-     *
275
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
-     *                                    message type labels
277
-     * @return string
278
-     * @throws EE_Error
279
-     */
280
-    public function get_message_types_select_input($message_type_options)
281
-    {
282
-        //if empty or count of options is 1 then just return an empty string
283
-        if (empty($message_type_options)
284
-            || ! is_array($message_type_options)
285
-            || count($message_type_options) === 1
286
-        ) {
287
-            return '';
288
-        }
289
-        //merge in default
290
-        $message_type_options = array_merge(
291
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
-            $message_type_options
293
-        );
294
-        $input                = new EE_Select_Input(
295
-            $message_type_options,
296
-            array(
297
-                'html_name'  => 'ee_message_type_filter_by',
298
-                'html_id'    => 'ee_message_type_filter_by',
299
-                'html_class' => 'wide',
300
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
-                    : 'none_selected',
303
-            )
304
-        );
305
-        
306
-        return $input->get_html_for_input();
307
-    }
272
+	/**
273
+	 * Generate select input with provided message type options array.
274
+	 *
275
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
+	 *                                    message type labels
277
+	 * @return string
278
+	 * @throws EE_Error
279
+	 */
280
+	public function get_message_types_select_input($message_type_options)
281
+	{
282
+		//if empty or count of options is 1 then just return an empty string
283
+		if (empty($message_type_options)
284
+			|| ! is_array($message_type_options)
285
+			|| count($message_type_options) === 1
286
+		) {
287
+			return '';
288
+		}
289
+		//merge in default
290
+		$message_type_options = array_merge(
291
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
+			$message_type_options
293
+		);
294
+		$input                = new EE_Select_Input(
295
+			$message_type_options,
296
+			array(
297
+				'html_name'  => 'ee_message_type_filter_by',
298
+				'html_id'    => 'ee_message_type_filter_by',
299
+				'html_class' => 'wide',
300
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
+					: 'none_selected',
303
+			)
304
+		);
305
+        
306
+		return $input->get_html_for_input();
307
+	}
308 308
 
309 309
 
310
-    /**
311
-     * Generate select input with provide message type contexts array.
312
-     *
313
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
-     *                               context label.
315
-     * @return string
316
-     * @throws EE_Error
317
-     */
318
-    public function get_contexts_for_message_types_select_input($context_options)
319
-    {
320
-        //if empty or count of options is one then just return empty string
321
-        if (empty($context_options)
322
-            || ! is_array($context_options)
323
-            || count($context_options) === 1
324
-        ) {
325
-            return '';
326
-        }
327
-        //merge in default
328
-        $context_options = array_merge(
329
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
-            $context_options
331
-        );
332
-        $input           = new EE_Select_Input(
333
-            $context_options,
334
-            array(
335
-                'html_name'  => 'ee_context_filter_by',
336
-                'html_id'    => 'ee_context_filter_by',
337
-                'html_class' => 'wide',
338
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
339
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
340
-                    : 'none_selected',
341
-            )
342
-        );
343
-        
344
-        return $input->get_html_for_input();
345
-    }
310
+	/**
311
+	 * Generate select input with provide message type contexts array.
312
+	 *
313
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
+	 *                               context label.
315
+	 * @return string
316
+	 * @throws EE_Error
317
+	 */
318
+	public function get_contexts_for_message_types_select_input($context_options)
319
+	{
320
+		//if empty or count of options is one then just return empty string
321
+		if (empty($context_options)
322
+			|| ! is_array($context_options)
323
+			|| count($context_options) === 1
324
+		) {
325
+			return '';
326
+		}
327
+		//merge in default
328
+		$context_options = array_merge(
329
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
+			$context_options
331
+		);
332
+		$input           = new EE_Select_Input(
333
+			$context_options,
334
+			array(
335
+				'html_name'  => 'ee_context_filter_by',
336
+				'html_id'    => 'ee_context_filter_by',
337
+				'html_class' => 'wide',
338
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
339
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
340
+					: 'none_selected',
341
+			)
342
+		);
343
+        
344
+		return $input->get_html_for_input();
345
+	}
346 346
     
347 347
     
348
-    protected function _ajax_hooks()
349
-    {
350
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
-    }
348
+	protected function _ajax_hooks()
349
+	{
350
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
+	}
357 357
     
358 358
     
359
-    protected function _define_page_props()
360
-    {
361
-        $this->_admin_page_title = $this->page_label;
362
-        $this->_labels           = array(
363
-            'buttons'    => array(
364
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
-                'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
-            ),
368
-            'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
-        );
370
-    }
359
+	protected function _define_page_props()
360
+	{
361
+		$this->_admin_page_title = $this->page_label;
362
+		$this->_labels           = array(
363
+			'buttons'    => array(
364
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
+				'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
+			),
368
+			'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
+		);
370
+	}
371 371
     
372 372
     
373
-    /**
374
-     *        an array for storing key => value pairs of request actions and their corresponding methods
375
-     * @access protected
376
-     * @return void
377
-     */
378
-    protected function _set_page_routes()
379
-    {
380
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
-            ? $this->_req_data['GRP_ID']
382
-            : 0;
383
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
-            ? $this->_req_data['id']
385
-            : $grp_id;
386
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
-            ? $this->_req_data['MSG_ID']
388
-            : 0;
389
-        
390
-        $this->_page_routes = array(
391
-            'default'                          => array(
392
-                'func'       => '_message_queue_list_table',
393
-                'capability' => 'ee_read_global_messages'
394
-            ),
395
-            'global_mtps'                      => array(
396
-                'func'       => '_ee_default_messages_overview_list_table',
397
-                'capability' => 'ee_read_global_messages'
398
-            ),
399
-            'custom_mtps'                      => array(
400
-                'func'       => '_custom_mtps_preview',
401
-                'capability' => 'ee_read_messages'
402
-            ),
403
-            'add_new_message_template'         => array(
404
-                'func'       => '_add_message_template',
405
-                'capability' => 'ee_edit_messages',
406
-                'noheader'   => true
407
-            ),
408
-            'edit_message_template'            => array(
409
-                'func'       => '_edit_message_template',
410
-                'capability' => 'ee_edit_message',
411
-                'obj_id'     => $grp_id
412
-            ),
413
-            'preview_message'                  => array(
414
-                'func'               => '_preview_message',
415
-                'capability'         => 'ee_read_message',
416
-                'obj_id'             => $grp_id,
417
-                'noheader'           => true,
418
-                'headers_sent_route' => 'display_preview_message'
419
-            ),
420
-            'display_preview_message'          => array(
421
-                'func'       => '_display_preview_message',
422
-                'capability' => 'ee_read_message',
423
-                'obj_id'     => $grp_id
424
-            ),
425
-            'insert_message_template'          => array(
426
-                'func'       => '_insert_or_update_message_template',
427
-                'capability' => 'ee_edit_messages',
428
-                'args'       => array('new_template' => true),
429
-                'noheader'   => true
430
-            ),
431
-            'update_message_template'          => array(
432
-                'func'       => '_insert_or_update_message_template',
433
-                'capability' => 'ee_edit_message',
434
-                'obj_id'     => $grp_id,
435
-                'args'       => array('new_template' => false),
436
-                'noheader'   => true
437
-            ),
438
-            'trash_message_template'           => array(
439
-                'func'       => '_trash_or_restore_message_template',
440
-                'capability' => 'ee_delete_message',
441
-                'obj_id'     => $grp_id,
442
-                'args'       => array('trash' => true, 'all' => true),
443
-                'noheader'   => true
444
-            ),
445
-            'trash_message_template_context'   => array(
446
-                'func'       => '_trash_or_restore_message_template',
447
-                'capability' => 'ee_delete_message',
448
-                'obj_id'     => $grp_id,
449
-                'args'       => array('trash' => true),
450
-                'noheader'   => true
451
-            ),
452
-            'restore_message_template'         => array(
453
-                'func'       => '_trash_or_restore_message_template',
454
-                'capability' => 'ee_delete_message',
455
-                'obj_id'     => $grp_id,
456
-                'args'       => array('trash' => false, 'all' => true),
457
-                'noheader'   => true
458
-            ),
459
-            'restore_message_template_context' => array(
460
-                'func'       => '_trash_or_restore_message_template',
461
-                'capability' => 'ee_delete_message',
462
-                'obj_id'     => $grp_id,
463
-                'args'       => array('trash' => false),
464
-                'noheader'   => true
465
-            ),
466
-            'delete_message_template'          => array(
467
-                'func'       => '_delete_message_template',
468
-                'capability' => 'ee_delete_message',
469
-                'obj_id'     => $grp_id,
470
-                'noheader'   => true
471
-            ),
472
-            'reset_to_default'                 => array(
473
-                'func'       => '_reset_to_default_template',
474
-                'capability' => 'ee_edit_message',
475
-                'obj_id'     => $grp_id,
476
-                'noheader'   => true
477
-            ),
478
-            'settings'                         => array(
479
-                'func'       => '_settings',
480
-                'capability' => 'manage_options'
481
-            ),
482
-            'update_global_settings'           => array(
483
-                'func'       => '_update_global_settings',
484
-                'capability' => 'manage_options',
485
-                'noheader'   => true
486
-            ),
487
-            'generate_now'                     => array(
488
-                'func'       => '_generate_now',
489
-                'capability' => 'ee_send_message',
490
-                'noheader'   => true
491
-            ),
492
-            'generate_and_send_now'            => array(
493
-                'func'       => '_generate_and_send_now',
494
-                'capability' => 'ee_send_message',
495
-                'noheader'   => true
496
-            ),
497
-            'queue_for_resending'              => array(
498
-                'func'       => '_queue_for_resending',
499
-                'capability' => 'ee_send_message',
500
-                'noheader'   => true
501
-            ),
502
-            'send_now'                         => array(
503
-                'func'       => '_send_now',
504
-                'capability' => 'ee_send_message',
505
-                'noheader'   => true
506
-            ),
507
-            'delete_ee_message'                => array(
508
-                'func'       => '_delete_ee_messages',
509
-                'capability' => 'ee_delete_messages',
510
-                'noheader'   => true
511
-            ),
512
-            'delete_ee_messages'               => array(
513
-                'func'       => '_delete_ee_messages',
514
-                'capability' => 'ee_delete_messages',
515
-                'noheader'   => true,
516
-                'obj_id'     => $msg_id
517
-            )
518
-        );
519
-    }
373
+	/**
374
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
375
+	 * @access protected
376
+	 * @return void
377
+	 */
378
+	protected function _set_page_routes()
379
+	{
380
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
+			? $this->_req_data['GRP_ID']
382
+			: 0;
383
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
+			? $this->_req_data['id']
385
+			: $grp_id;
386
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
+			? $this->_req_data['MSG_ID']
388
+			: 0;
389
+        
390
+		$this->_page_routes = array(
391
+			'default'                          => array(
392
+				'func'       => '_message_queue_list_table',
393
+				'capability' => 'ee_read_global_messages'
394
+			),
395
+			'global_mtps'                      => array(
396
+				'func'       => '_ee_default_messages_overview_list_table',
397
+				'capability' => 'ee_read_global_messages'
398
+			),
399
+			'custom_mtps'                      => array(
400
+				'func'       => '_custom_mtps_preview',
401
+				'capability' => 'ee_read_messages'
402
+			),
403
+			'add_new_message_template'         => array(
404
+				'func'       => '_add_message_template',
405
+				'capability' => 'ee_edit_messages',
406
+				'noheader'   => true
407
+			),
408
+			'edit_message_template'            => array(
409
+				'func'       => '_edit_message_template',
410
+				'capability' => 'ee_edit_message',
411
+				'obj_id'     => $grp_id
412
+			),
413
+			'preview_message'                  => array(
414
+				'func'               => '_preview_message',
415
+				'capability'         => 'ee_read_message',
416
+				'obj_id'             => $grp_id,
417
+				'noheader'           => true,
418
+				'headers_sent_route' => 'display_preview_message'
419
+			),
420
+			'display_preview_message'          => array(
421
+				'func'       => '_display_preview_message',
422
+				'capability' => 'ee_read_message',
423
+				'obj_id'     => $grp_id
424
+			),
425
+			'insert_message_template'          => array(
426
+				'func'       => '_insert_or_update_message_template',
427
+				'capability' => 'ee_edit_messages',
428
+				'args'       => array('new_template' => true),
429
+				'noheader'   => true
430
+			),
431
+			'update_message_template'          => array(
432
+				'func'       => '_insert_or_update_message_template',
433
+				'capability' => 'ee_edit_message',
434
+				'obj_id'     => $grp_id,
435
+				'args'       => array('new_template' => false),
436
+				'noheader'   => true
437
+			),
438
+			'trash_message_template'           => array(
439
+				'func'       => '_trash_or_restore_message_template',
440
+				'capability' => 'ee_delete_message',
441
+				'obj_id'     => $grp_id,
442
+				'args'       => array('trash' => true, 'all' => true),
443
+				'noheader'   => true
444
+			),
445
+			'trash_message_template_context'   => array(
446
+				'func'       => '_trash_or_restore_message_template',
447
+				'capability' => 'ee_delete_message',
448
+				'obj_id'     => $grp_id,
449
+				'args'       => array('trash' => true),
450
+				'noheader'   => true
451
+			),
452
+			'restore_message_template'         => array(
453
+				'func'       => '_trash_or_restore_message_template',
454
+				'capability' => 'ee_delete_message',
455
+				'obj_id'     => $grp_id,
456
+				'args'       => array('trash' => false, 'all' => true),
457
+				'noheader'   => true
458
+			),
459
+			'restore_message_template_context' => array(
460
+				'func'       => '_trash_or_restore_message_template',
461
+				'capability' => 'ee_delete_message',
462
+				'obj_id'     => $grp_id,
463
+				'args'       => array('trash' => false),
464
+				'noheader'   => true
465
+			),
466
+			'delete_message_template'          => array(
467
+				'func'       => '_delete_message_template',
468
+				'capability' => 'ee_delete_message',
469
+				'obj_id'     => $grp_id,
470
+				'noheader'   => true
471
+			),
472
+			'reset_to_default'                 => array(
473
+				'func'       => '_reset_to_default_template',
474
+				'capability' => 'ee_edit_message',
475
+				'obj_id'     => $grp_id,
476
+				'noheader'   => true
477
+			),
478
+			'settings'                         => array(
479
+				'func'       => '_settings',
480
+				'capability' => 'manage_options'
481
+			),
482
+			'update_global_settings'           => array(
483
+				'func'       => '_update_global_settings',
484
+				'capability' => 'manage_options',
485
+				'noheader'   => true
486
+			),
487
+			'generate_now'                     => array(
488
+				'func'       => '_generate_now',
489
+				'capability' => 'ee_send_message',
490
+				'noheader'   => true
491
+			),
492
+			'generate_and_send_now'            => array(
493
+				'func'       => '_generate_and_send_now',
494
+				'capability' => 'ee_send_message',
495
+				'noheader'   => true
496
+			),
497
+			'queue_for_resending'              => array(
498
+				'func'       => '_queue_for_resending',
499
+				'capability' => 'ee_send_message',
500
+				'noheader'   => true
501
+			),
502
+			'send_now'                         => array(
503
+				'func'       => '_send_now',
504
+				'capability' => 'ee_send_message',
505
+				'noheader'   => true
506
+			),
507
+			'delete_ee_message'                => array(
508
+				'func'       => '_delete_ee_messages',
509
+				'capability' => 'ee_delete_messages',
510
+				'noheader'   => true
511
+			),
512
+			'delete_ee_messages'               => array(
513
+				'func'       => '_delete_ee_messages',
514
+				'capability' => 'ee_delete_messages',
515
+				'noheader'   => true,
516
+				'obj_id'     => $msg_id
517
+			)
518
+		);
519
+	}
520 520
     
521 521
     
522
-    protected function _set_page_config()
523
-    {
524
-        $this->_page_config = array(
525
-            'default'                  => array(
526
-                'nav'           => array(
527
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
528
-                    'order' => 10
529
-                ),
530
-                'list_table'    => 'EE_Message_List_Table',
531
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
-                'require_nonce' => false
533
-            ),
534
-            'global_mtps'              => array(
535
-                'nav'           => array(
536
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
-                    'order' => 20
538
-                ),
539
-                'list_table'    => 'Messages_Template_List_Table',
540
-                'help_tabs'     => array(
541
-                    'messages_overview_help_tab'                                => array(
542
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
-                        'filename' => 'messages_overview'
544
-                    ),
545
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
546
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
-                        'filename' => 'messages_overview_table_column_headings'
548
-                    ),
549
-                    'messages_overview_messages_filters_help_tab'               => array(
550
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
551
-                        'filename' => 'messages_overview_filters'
552
-                    ),
553
-                    'messages_overview_messages_views_help_tab'                 => array(
554
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
555
-                        'filename' => 'messages_overview_views'
556
-                    ),
557
-                    'message_overview_message_types_help_tab'                   => array(
558
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
559
-                        'filename' => 'messages_overview_types'
560
-                    ),
561
-                    'messages_overview_messengers_help_tab'                     => array(
562
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
563
-                        'filename' => 'messages_overview_messengers',
564
-                    ),
565
-                ),
566
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
567
-                'require_nonce' => false
568
-            ),
569
-            'custom_mtps'              => array(
570
-                'nav'           => array(
571
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
-                    'order' => 30
573
-                ),
574
-                'help_tabs'     => array(),
575
-                'help_tour'     => array(),
576
-                'require_nonce' => false
577
-            ),
578
-            'add_new_message_template' => array(
579
-                'nav'           => array(
580
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
-                    'order'      => 5,
582
-                    'persistent' => false
583
-                ),
584
-                'require_nonce' => false
585
-            ),
586
-            'edit_message_template'    => array(
587
-                'labels'        => array(
588
-                    'buttons'    => array(
589
-                        'reset' => esc_html__('Reset Templates'),
590
-                    ),
591
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
-                ),
593
-                'nav'           => array(
594
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
-                    'order'      => 5,
596
-                    'persistent' => false,
597
-                    'url'        => ''
598
-                ),
599
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
-                'has_metaboxes' => true,
601
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
-                'help_tabs'     => array(
603
-                    'edit_message_template'       => array(
604
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
-                        'callback' => 'edit_message_template_help_tab'
606
-                    ),
607
-                    'message_templates_help_tab'  => array(
608
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
609
-                        'filename' => 'messages_templates'
610
-                    ),
611
-                    'message_template_shortcodes' => array(
612
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
-                        'callback' => 'message_template_shortcodes_help_tab'
614
-                    ),
615
-                    'message_preview_help_tab'    => array(
616
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
617
-                        'filename' => 'messages_preview'
618
-                    ),
619
-                    'messages_overview_other_help_tab'                          => array(
620
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
621
-                        'filename' => 'messages_overview_other',
622
-                    ),
623
-                ),
624
-                'require_nonce' => false
625
-            ),
626
-            'display_preview_message'  => array(
627
-                'nav'           => array(
628
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
629
-                    'order'      => 5,
630
-                    'url'        => '',
631
-                    'persistent' => false
632
-                ),
633
-                'help_tabs'     => array(
634
-                    'preview_message' => array(
635
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
636
-                        'callback' => 'preview_message_help_tab'
637
-                    )
638
-                ),
639
-                'require_nonce' => false
640
-            ),
641
-            'settings'                 => array(
642
-                'nav'           => array(
643
-                    'label' => esc_html__('Settings', 'event_espresso'),
644
-                    'order' => 40
645
-                ),
646
-                'metaboxes'     => array('_messages_settings_metaboxes'),
647
-                'help_tabs'     => array(
648
-                    'messages_settings_help_tab'               => array(
649
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
-                        'filename' => 'messages_settings'
651
-                    ),
652
-                    'messages_settings_message_types_help_tab' => array(
653
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
-                        'filename' => 'messages_settings_message_types'
655
-                    ),
656
-                    'messages_settings_messengers_help_tab'    => array(
657
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
-                        'filename' => 'messages_settings_messengers'
659
-                    ),
660
-                ),
661
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
662
-                'require_nonce' => false
663
-            )
664
-        );
665
-    }
522
+	protected function _set_page_config()
523
+	{
524
+		$this->_page_config = array(
525
+			'default'                  => array(
526
+				'nav'           => array(
527
+					'label' => esc_html__('Message Activity', 'event_espresso'),
528
+					'order' => 10
529
+				),
530
+				'list_table'    => 'EE_Message_List_Table',
531
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
+				'require_nonce' => false
533
+			),
534
+			'global_mtps'              => array(
535
+				'nav'           => array(
536
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
+					'order' => 20
538
+				),
539
+				'list_table'    => 'Messages_Template_List_Table',
540
+				'help_tabs'     => array(
541
+					'messages_overview_help_tab'                                => array(
542
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
+						'filename' => 'messages_overview'
544
+					),
545
+					'messages_overview_messages_table_column_headings_help_tab' => array(
546
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
+						'filename' => 'messages_overview_table_column_headings'
548
+					),
549
+					'messages_overview_messages_filters_help_tab'               => array(
550
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
551
+						'filename' => 'messages_overview_filters'
552
+					),
553
+					'messages_overview_messages_views_help_tab'                 => array(
554
+						'title'    => esc_html__('Message Views', 'event_espresso'),
555
+						'filename' => 'messages_overview_views'
556
+					),
557
+					'message_overview_message_types_help_tab'                   => array(
558
+						'title'    => esc_html__('Message Types', 'event_espresso'),
559
+						'filename' => 'messages_overview_types'
560
+					),
561
+					'messages_overview_messengers_help_tab'                     => array(
562
+						'title'    => esc_html__('Messengers', 'event_espresso'),
563
+						'filename' => 'messages_overview_messengers',
564
+					),
565
+				),
566
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
567
+				'require_nonce' => false
568
+			),
569
+			'custom_mtps'              => array(
570
+				'nav'           => array(
571
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
+					'order' => 30
573
+				),
574
+				'help_tabs'     => array(),
575
+				'help_tour'     => array(),
576
+				'require_nonce' => false
577
+			),
578
+			'add_new_message_template' => array(
579
+				'nav'           => array(
580
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
+					'order'      => 5,
582
+					'persistent' => false
583
+				),
584
+				'require_nonce' => false
585
+			),
586
+			'edit_message_template'    => array(
587
+				'labels'        => array(
588
+					'buttons'    => array(
589
+						'reset' => esc_html__('Reset Templates'),
590
+					),
591
+					'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
+				),
593
+				'nav'           => array(
594
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
+					'order'      => 5,
596
+					'persistent' => false,
597
+					'url'        => ''
598
+				),
599
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
+				'has_metaboxes' => true,
601
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
+				'help_tabs'     => array(
603
+					'edit_message_template'       => array(
604
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
+						'callback' => 'edit_message_template_help_tab'
606
+					),
607
+					'message_templates_help_tab'  => array(
608
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
609
+						'filename' => 'messages_templates'
610
+					),
611
+					'message_template_shortcodes' => array(
612
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
+						'callback' => 'message_template_shortcodes_help_tab'
614
+					),
615
+					'message_preview_help_tab'    => array(
616
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
617
+						'filename' => 'messages_preview'
618
+					),
619
+					'messages_overview_other_help_tab'                          => array(
620
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
621
+						'filename' => 'messages_overview_other',
622
+					),
623
+				),
624
+				'require_nonce' => false
625
+			),
626
+			'display_preview_message'  => array(
627
+				'nav'           => array(
628
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
629
+					'order'      => 5,
630
+					'url'        => '',
631
+					'persistent' => false
632
+				),
633
+				'help_tabs'     => array(
634
+					'preview_message' => array(
635
+						'title'    => esc_html__('About Previews', 'event_espresso'),
636
+						'callback' => 'preview_message_help_tab'
637
+					)
638
+				),
639
+				'require_nonce' => false
640
+			),
641
+			'settings'                 => array(
642
+				'nav'           => array(
643
+					'label' => esc_html__('Settings', 'event_espresso'),
644
+					'order' => 40
645
+				),
646
+				'metaboxes'     => array('_messages_settings_metaboxes'),
647
+				'help_tabs'     => array(
648
+					'messages_settings_help_tab'               => array(
649
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
+						'filename' => 'messages_settings'
651
+					),
652
+					'messages_settings_message_types_help_tab' => array(
653
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
+						'filename' => 'messages_settings_message_types'
655
+					),
656
+					'messages_settings_messengers_help_tab'    => array(
657
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
+						'filename' => 'messages_settings_messengers'
659
+					),
660
+				),
661
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
662
+				'require_nonce' => false
663
+			)
664
+		);
665
+	}
666 666
     
667 667
     
668
-    protected function _add_screen_options()
669
-    {
670
-        //todo
671
-    }
668
+	protected function _add_screen_options()
669
+	{
670
+		//todo
671
+	}
672 672
     
673 673
     
674
-    protected function _add_screen_options_global_mtps()
675
-    {
676
-        /**
677
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
679
-         */
680
-        $page_title              = $this->_admin_page_title;
681
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
-        $this->_per_page_screen_option();
683
-        $this->_admin_page_title = $page_title;
684
-    }
674
+	protected function _add_screen_options_global_mtps()
675
+	{
676
+		/**
677
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
679
+		 */
680
+		$page_title              = $this->_admin_page_title;
681
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
+		$this->_per_page_screen_option();
683
+		$this->_admin_page_title = $page_title;
684
+	}
685 685
     
686 686
     
687
-    protected function _add_screen_options_default()
688
-    {
689
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
-        $this->_per_page_screen_option();
691
-    }
687
+	protected function _add_screen_options_default()
688
+	{
689
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
+		$this->_per_page_screen_option();
691
+	}
692 692
     
693 693
     
694
-    //none of the below group are currently used for Messages
695
-    protected function _add_feature_pointers()
696
-    {
697
-    }
694
+	//none of the below group are currently used for Messages
695
+	protected function _add_feature_pointers()
696
+	{
697
+	}
698 698
     
699
-    public function admin_init()
700
-    {
701
-    }
699
+	public function admin_init()
700
+	{
701
+	}
702 702
     
703
-    public function admin_notices()
704
-    {
705
-    }
703
+	public function admin_notices()
704
+	{
705
+	}
706 706
     
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710 710
     
711 711
     
712
-    public function messages_help_tab()
713
-    {
714
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
-    }
712
+	public function messages_help_tab()
713
+	{
714
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
+	}
716 716
     
717 717
     
718
-    public function messengers_help_tab()
719
-    {
720
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
-    }
718
+	public function messengers_help_tab()
719
+	{
720
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
+	}
722 722
     
723 723
     
724
-    public function message_types_help_tab()
725
-    {
726
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
-    }
724
+	public function message_types_help_tab()
725
+	{
726
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
+	}
728 728
     
729 729
     
730
-    public function messages_overview_help_tab()
731
-    {
732
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
-    }
730
+	public function messages_overview_help_tab()
731
+	{
732
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
+	}
734 734
     
735 735
     
736
-    public function message_templates_help_tab()
737
-    {
738
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
-    }
736
+	public function message_templates_help_tab()
737
+	{
738
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
+	}
740 740
     
741 741
     
742
-    public function edit_message_template_help_tab()
743
-    {
744
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
-                        . esc_attr__('Editor Title', 'event_espresso')
746
-                        . '" />';
747
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
749
-                        . '" />';
750
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
752
-                        . '" />';
753
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
755
-                        . '" />';
756
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
-                        . esc_attr__('Publish Metabox', 'event_espresso')
758
-                        . '" />';
759
-        EEH_Template::display_template(
760
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
-            $args
762
-        );
763
-    }
742
+	public function edit_message_template_help_tab()
743
+	{
744
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
+						. esc_attr__('Editor Title', 'event_espresso')
746
+						. '" />';
747
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
749
+						. '" />';
750
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
752
+						. '" />';
753
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
755
+						. '" />';
756
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
+						. esc_attr__('Publish Metabox', 'event_espresso')
758
+						. '" />';
759
+		EEH_Template::display_template(
760
+			EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
+			$args
762
+		);
763
+	}
764 764
     
765 765
     
766
-    public function message_template_shortcodes_help_tab()
767
-    {
768
-        $this->_set_shortcodes();
769
-        $args['shortcodes'] = $this->_shortcodes;
770
-        EEH_Template::display_template(
771
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
-            $args
773
-        );
774
-    }
766
+	public function message_template_shortcodes_help_tab()
767
+	{
768
+		$this->_set_shortcodes();
769
+		$args['shortcodes'] = $this->_shortcodes;
770
+		EEH_Template::display_template(
771
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
+			$args
773
+		);
774
+	}
775 775
     
776 776
     
777
-    public function preview_message_help_tab()
778
-    {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
-    }
777
+	public function preview_message_help_tab()
778
+	{
779
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
+	}
781 781
     
782 782
     
783
-    public function settings_help_tab()
784
-    {
785
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
-        $args['img3'] = '<div class="switch">'
790
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
-                        . ' type="checkbox" checked="checked">'
792
-                        . '<label for="ee-on-off-toggle-on"></label>'
793
-                        . '</div>';
794
-        $args['img4'] = '<div class="switch">'
795
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
-                        . ' type="checkbox">'
797
-                        . '<label for="ee-on-off-toggle-on"></label>'
798
-                        . '</div>';
799
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
-    }
783
+	public function settings_help_tab()
784
+	{
785
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
+		$args['img3'] = '<div class="switch">'
790
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
+						. ' type="checkbox" checked="checked">'
792
+						. '<label for="ee-on-off-toggle-on"></label>'
793
+						. '</div>';
794
+		$args['img4'] = '<div class="switch">'
795
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
+						. ' type="checkbox">'
797
+						. '<label for="ee-on-off-toggle-on"></label>'
798
+						. '</div>';
799
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
+	}
801 801
     
802 802
     
803
-    public function load_scripts_styles()
804
-    {
805
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
-        wp_enqueue_style('espresso_ee_msg');
807
-        
808
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
-    }
803
+	public function load_scripts_styles()
804
+	{
805
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
+		wp_enqueue_style('espresso_ee_msg');
807
+        
808
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
+	}
813 813
     
814 814
     
815
-    public function load_scripts_styles_default()
816
-    {
817
-        wp_enqueue_script('ee-msg-list-table-js');
818
-    }
815
+	public function load_scripts_styles_default()
816
+	{
817
+		wp_enqueue_script('ee-msg-list-table-js');
818
+	}
819 819
     
820 820
     
821
-    public function wp_editor_css($mce_css)
822
-    {
823
-        //if we're on the edit_message_template route
824
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
-            $message_type_name = $this->_active_message_type_name;
821
+	public function wp_editor_css($mce_css)
822
+	{
823
+		//if we're on the edit_message_template route
824
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
+			$message_type_name = $this->_active_message_type_name;
826 826
             
827
-            //we're going to REPLACE the existing mce css
828
-            //we need to get the css file location from the active messenger
829
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
-                'wpeditor', $this->_variation);
831
-        }
832
-        
833
-        return $mce_css;
834
-    }
827
+			//we're going to REPLACE the existing mce css
828
+			//we need to get the css file location from the active messenger
829
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
+				'wpeditor', $this->_variation);
831
+		}
832
+        
833
+		return $mce_css;
834
+	}
835 835
     
836 836
     
837
-    public function load_scripts_styles_edit_message_template()
838
-    {
839
-        
840
-        $this->_set_shortcodes();
841
-        
842
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
-            esc_html__(
844
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
845
-                'event_espresso'
846
-            ),
847
-            $this->_message_template_group->messenger_obj()->label['singular'],
848
-            $this->_message_template_group->message_type_obj()->label['singular']
849
-        );
850
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
852
-            'event_espresso'
853
-        );
854
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
-            'event_espresso'
857
-        );
858
-        
859
-        wp_register_script(
860
-            'ee_msgs_edit_js',
861
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
-            array('jquery'),
863
-            EVENT_ESPRESSO_VERSION
864
-        );
865
-        
866
-        wp_enqueue_script('ee_admin_js');
867
-        wp_enqueue_script('ee_msgs_edit_js');
868
-        
869
-        //add in special css for tiny_mce
870
-        add_filter('mce_css', array($this, 'wp_editor_css'));
871
-    }
837
+	public function load_scripts_styles_edit_message_template()
838
+	{
839
+        
840
+		$this->_set_shortcodes();
841
+        
842
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
+			esc_html__(
844
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
845
+				'event_espresso'
846
+			),
847
+			$this->_message_template_group->messenger_obj()->label['singular'],
848
+			$this->_message_template_group->message_type_obj()->label['singular']
849
+		);
850
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
852
+			'event_espresso'
853
+		);
854
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
+			'event_espresso'
857
+		);
858
+        
859
+		wp_register_script(
860
+			'ee_msgs_edit_js',
861
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
+			array('jquery'),
863
+			EVENT_ESPRESSO_VERSION
864
+		);
865
+        
866
+		wp_enqueue_script('ee_admin_js');
867
+		wp_enqueue_script('ee_msgs_edit_js');
868
+        
869
+		//add in special css for tiny_mce
870
+		add_filter('mce_css', array($this, 'wp_editor_css'));
871
+	}
872 872
     
873 873
     
874
-    public function load_scripts_styles_display_preview_message()
875
-    {
876
-        
877
-        $this->_set_message_template_group();
878
-        
879
-        if (isset($this->_req_data['messenger'])) {
880
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
-                $this->_req_data['messenger']
882
-            );
883
-        }
884
-        
885
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
-        
887
-        
888
-        wp_enqueue_style('espresso_preview_css',
889
-            $this->_active_messenger->get_variation(
890
-                $this->_template_pack,
891
-                $message_type_name,
892
-                true,
893
-                'preview',
894
-                $this->_variation
895
-            )
896
-        );
897
-    }
874
+	public function load_scripts_styles_display_preview_message()
875
+	{
876
+        
877
+		$this->_set_message_template_group();
878
+        
879
+		if (isset($this->_req_data['messenger'])) {
880
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
+				$this->_req_data['messenger']
882
+			);
883
+		}
884
+        
885
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
+        
887
+        
888
+		wp_enqueue_style('espresso_preview_css',
889
+			$this->_active_messenger->get_variation(
890
+				$this->_template_pack,
891
+				$message_type_name,
892
+				true,
893
+				'preview',
894
+				$this->_variation
895
+			)
896
+		);
897
+	}
898 898
     
899 899
     
900
-    public function load_scripts_styles_settings()
901
-    {
902
-        wp_register_style(
903
-            'ee-message-settings',
904
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
-            array(),
906
-            EVENT_ESPRESSO_VERSION
907
-        );
908
-        wp_enqueue_style('ee-text-links');
909
-        wp_enqueue_style('ee-message-settings');
910
-        wp_enqueue_script('ee-messages-settings');
911
-    }
900
+	public function load_scripts_styles_settings()
901
+	{
902
+		wp_register_style(
903
+			'ee-message-settings',
904
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
+			array(),
906
+			EVENT_ESPRESSO_VERSION
907
+		);
908
+		wp_enqueue_style('ee-text-links');
909
+		wp_enqueue_style('ee-message-settings');
910
+		wp_enqueue_script('ee-messages-settings');
911
+	}
912 912
     
913 913
     
914
-    /**
915
-     * set views array for List Table
916
-     */
917
-    public function _set_list_table_views_global_mtps()
918
-    {
919
-        $this->_views = array(
920
-            'in_use' => array(
921
-                'slug'        => 'in_use',
922
-                'label'       => esc_html__('In Use', 'event_espresso'),
923
-                'count'       => 0,
924
-            )
925
-        );
926
-    }
914
+	/**
915
+	 * set views array for List Table
916
+	 */
917
+	public function _set_list_table_views_global_mtps()
918
+	{
919
+		$this->_views = array(
920
+			'in_use' => array(
921
+				'slug'        => 'in_use',
922
+				'label'       => esc_html__('In Use', 'event_espresso'),
923
+				'count'       => 0,
924
+			)
925
+		);
926
+	}
927 927
 
928 928
 
929
-    /**
930
-     * Set views array for the Custom Template List Table
931
-     */
932
-    public function _set_list_table_views_custom_mtps()
933
-    {
934
-        $this->_set_list_table_views_global_mtps();
935
-        $this->_views['in_use']['bulk_action'] = array(
936
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
-        );
938
-    }
929
+	/**
930
+	 * Set views array for the Custom Template List Table
931
+	 */
932
+	public function _set_list_table_views_custom_mtps()
933
+	{
934
+		$this->_set_list_table_views_global_mtps();
935
+		$this->_views['in_use']['bulk_action'] = array(
936
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
+		);
938
+	}
939 939
 
940 940
 
941
-    /**
942
-     * set views array for message queue list table
943
-     *
944
-     * @throws InvalidDataTypeException
945
-     * @throws InvalidInterfaceException
946
-     * @throws InvalidArgumentException
947
-     * @throws EE_Error
948
-     * @throws ReflectionException
949
-     */
950
-    public function _set_list_table_views_default()
951
-    {
952
-        EE_Registry::instance()->load_helper('Template');
953
-        
954
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
-            'ee_send_message',
956
-            'message_list_table_bulk_actions'
957
-        )
958
-            ? array(
959
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
-                'send_now'              => esc_html__('Send Now', 'event_espresso')
963
-            )
964
-            : array();
965
-        
966
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
-            'ee_delete_messages',
968
-            'message_list_table_bulk_actions'
969
-        )
970
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
-            : array();
972
-        
973
-        
974
-        $this->_views = array(
975
-            'all' => array(
976
-                'slug'        => 'all',
977
-                'label'       => esc_html__('All', 'event_espresso'),
978
-                'count'       => 0,
979
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
-            )
981
-        );
982
-        
983
-        
984
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
985
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
-                continue;
987
-            }
988
-            $status_bulk_actions = $common_bulk_actions;
989
-            //unset bulk actions not applying to status
990
-            if (! empty($status_bulk_actions)) {
991
-                switch ($status) {
992
-                    case EEM_Message::status_idle:
993
-                    case EEM_Message::status_resend:
994
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
-                        break;
941
+	/**
942
+	 * set views array for message queue list table
943
+	 *
944
+	 * @throws InvalidDataTypeException
945
+	 * @throws InvalidInterfaceException
946
+	 * @throws InvalidArgumentException
947
+	 * @throws EE_Error
948
+	 * @throws ReflectionException
949
+	 */
950
+	public function _set_list_table_views_default()
951
+	{
952
+		EE_Registry::instance()->load_helper('Template');
953
+        
954
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
+			'ee_send_message',
956
+			'message_list_table_bulk_actions'
957
+		)
958
+			? array(
959
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
+				'send_now'              => esc_html__('Send Now', 'event_espresso')
963
+			)
964
+			: array();
965
+        
966
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
+			'ee_delete_messages',
968
+			'message_list_table_bulk_actions'
969
+		)
970
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
+			: array();
972
+        
973
+        
974
+		$this->_views = array(
975
+			'all' => array(
976
+				'slug'        => 'all',
977
+				'label'       => esc_html__('All', 'event_espresso'),
978
+				'count'       => 0,
979
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
+			)
981
+		);
982
+        
983
+        
984
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
985
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
+				continue;
987
+			}
988
+			$status_bulk_actions = $common_bulk_actions;
989
+			//unset bulk actions not applying to status
990
+			if (! empty($status_bulk_actions)) {
991
+				switch ($status) {
992
+					case EEM_Message::status_idle:
993
+					case EEM_Message::status_resend:
994
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
+						break;
996 996
                     
997
-                    case EEM_Message::status_failed:
998
-                    case EEM_Message::status_debug_only:
999
-                    case EEM_Message::status_messenger_executing:
1000
-                        $status_bulk_actions = array();
1001
-                        break;
997
+					case EEM_Message::status_failed:
998
+					case EEM_Message::status_debug_only:
999
+					case EEM_Message::status_messenger_executing:
1000
+						$status_bulk_actions = array();
1001
+						break;
1002 1002
                     
1003
-                    case EEM_Message::status_incomplete:
1004
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
-                        break;
1003
+					case EEM_Message::status_incomplete:
1004
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
+						break;
1006 1006
                     
1007
-                    case EEM_Message::status_retry:
1008
-                    case EEM_Message::status_sent:
1009
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
-                        break;
1011
-                }
1012
-            }
1007
+					case EEM_Message::status_retry:
1008
+					case EEM_Message::status_sent:
1009
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
+						break;
1011
+				}
1012
+			}
1013 1013
 
1014
-            //skip adding messenger executing status to views because it will be included with the Failed view.
1015
-            if ( $status === EEM_Message::status_messenger_executing ) {
1016
-                continue;
1017
-            }
1014
+			//skip adding messenger executing status to views because it will be included with the Failed view.
1015
+			if ( $status === EEM_Message::status_messenger_executing ) {
1016
+				continue;
1017
+			}
1018 1018
             
1019
-            $this->_views[strtolower($status)] = array(
1020
-                'slug'        => strtolower($status),
1021
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
-                'count'       => 0,
1023
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
-            );
1025
-        }
1026
-    }
1019
+			$this->_views[strtolower($status)] = array(
1020
+				'slug'        => strtolower($status),
1021
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
+				'count'       => 0,
1023
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
+			);
1025
+		}
1026
+	}
1027 1027
     
1028 1028
     
1029
-    protected function _ee_default_messages_overview_list_table()
1030
-    {
1031
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
-        $this->display_admin_list_table_page_with_no_sidebar();
1033
-    }
1029
+	protected function _ee_default_messages_overview_list_table()
1030
+	{
1031
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
+		$this->display_admin_list_table_page_with_no_sidebar();
1033
+	}
1034 1034
     
1035 1035
     
1036
-    protected function _message_queue_list_table()
1037
-    {
1038
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
-        $this->_template_args['per_column']        = 6;
1040
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
-        $this->_template_args['before_list_table'] = '<h3>'
1042
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1043
-                                                     . '</h3>';
1044
-        $this->display_admin_list_table_page_with_no_sidebar();
1045
-    }
1036
+	protected function _message_queue_list_table()
1037
+	{
1038
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
+		$this->_template_args['per_column']        = 6;
1040
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
+		$this->_template_args['before_list_table'] = '<h3>'
1042
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1043
+													 . '</h3>';
1044
+		$this->display_admin_list_table_page_with_no_sidebar();
1045
+	}
1046 1046
     
1047 1047
     
1048
-    protected function _message_legend_items()
1049
-    {
1050
-        
1051
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
-        $action_items       = array();
1053
-        
1054
-        foreach ($action_css_classes as $action_item => $action_details) {
1055
-            if ($action_item === 'see_notifications_for') {
1056
-                continue;
1057
-            }
1058
-            $action_items[$action_item] = array(
1059
-                'class' => $action_details['css_class'],
1060
-                'desc'  => $action_details['label']
1061
-            );
1062
-        }
1063
-        
1064
-        /** @type array $status_items status legend setup */
1065
-        $status_items = array(
1066
-            'sent_status'       => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
-            ),
1070
-            'idle_status'       => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
-            ),
1074
-            'failed_status'     => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
-            ),
1078
-            'messenger_executing_status' => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
-            ),
1082
-            'resend_status'     => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
-            ),
1086
-            'incomplete_status' => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
-            ),
1090
-            'retry_status'      => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
-            )
1094
-        );
1095
-        if (EEM_Message::debug()) {
1096
-            $status_items['debug_only_status'] = array(
1097
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
-            );
1100
-        }
1101
-        
1102
-        return array_merge($action_items, $status_items);
1103
-    }
1048
+	protected function _message_legend_items()
1049
+	{
1050
+        
1051
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
+		$action_items       = array();
1053
+        
1054
+		foreach ($action_css_classes as $action_item => $action_details) {
1055
+			if ($action_item === 'see_notifications_for') {
1056
+				continue;
1057
+			}
1058
+			$action_items[$action_item] = array(
1059
+				'class' => $action_details['css_class'],
1060
+				'desc'  => $action_details['label']
1061
+			);
1062
+		}
1063
+        
1064
+		/** @type array $status_items status legend setup */
1065
+		$status_items = array(
1066
+			'sent_status'       => array(
1067
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
+			),
1070
+			'idle_status'       => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
+			),
1074
+			'failed_status'     => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
+			),
1078
+			'messenger_executing_status' => array(
1079
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
+			),
1082
+			'resend_status'     => array(
1083
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
+			),
1086
+			'incomplete_status' => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
+			),
1090
+			'retry_status'      => array(
1091
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
+			)
1094
+		);
1095
+		if (EEM_Message::debug()) {
1096
+			$status_items['debug_only_status'] = array(
1097
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
+			);
1100
+		}
1101
+        
1102
+		return array_merge($action_items, $status_items);
1103
+	}
1104 1104
     
1105 1105
     
1106
-    protected function _custom_mtps_preview()
1107
-    {
1108
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
-        $this->_template_args['preview_text'] = '<strong>'
1112
-            . esc_html__(
1113
-                'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1114
-                'event_espresso'
1115
-            )
1116
-            . '</strong>';
1106
+	protected function _custom_mtps_preview()
1107
+	{
1108
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
+			. ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
+		$this->_template_args['preview_text'] = '<strong>'
1112
+			. esc_html__(
1113
+				'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1114
+				'event_espresso'
1115
+			)
1116
+			. '</strong>';
1117 1117
 
1118
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1119
-    }
1118
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1119
+	}
1120 1120
 
1121 1121
 
1122
-    /**
1123
-     * get_message_templates
1124
-     * This gets all the message templates for listing on the overview list.
1125
-     *
1126
-     * @access public
1127
-     * @param int    $perpage the amount of templates groups to show per page
1128
-     * @param string $type    the current _view we're getting templates for
1129
-     * @param bool   $count   return count?
1130
-     * @param bool   $all     disregard any paging info (get all data);
1131
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
-     * @return array
1133
-     * @throws EE_Error
1134
-     * @throws InvalidArgumentException
1135
-     * @throws InvalidDataTypeException
1136
-     * @throws InvalidInterfaceException
1137
-     */
1138
-    public function get_message_templates(
1139
-        $perpage = 10,
1140
-        $type = 'in_use',
1141
-        $count = false,
1142
-        $all = false,
1143
-        $global = true)
1144
-    {
1145
-        
1146
-        $MTP = EEM_Message_Template_Group::instance();
1147
-        
1148
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
-        $orderby                    = $this->_req_data['orderby'];
1150
-        
1151
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
-            ? $this->_req_data['order']
1153
-            : 'ASC';
1154
-        
1155
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
-            ? $this->_req_data['paged']
1157
-            : 1;
1158
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
-            ? $this->_req_data['perpage']
1160
-            : $perpage;
1161
-        
1162
-        $offset = ($current_page - 1) * $per_page;
1163
-        $limit  = $all ? null : array($offset, $per_page);
1164
-        
1165
-        
1166
-        //options will match what is in the _views array property
1167
-        switch ($type) {
1168
-            case 'in_use':
1169
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
-                break;
1171
-            default:
1172
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
-        }
1174
-        
1175
-        return $templates;
1176
-    }
1122
+	/**
1123
+	 * get_message_templates
1124
+	 * This gets all the message templates for listing on the overview list.
1125
+	 *
1126
+	 * @access public
1127
+	 * @param int    $perpage the amount of templates groups to show per page
1128
+	 * @param string $type    the current _view we're getting templates for
1129
+	 * @param bool   $count   return count?
1130
+	 * @param bool   $all     disregard any paging info (get all data);
1131
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
+	 * @return array
1133
+	 * @throws EE_Error
1134
+	 * @throws InvalidArgumentException
1135
+	 * @throws InvalidDataTypeException
1136
+	 * @throws InvalidInterfaceException
1137
+	 */
1138
+	public function get_message_templates(
1139
+		$perpage = 10,
1140
+		$type = 'in_use',
1141
+		$count = false,
1142
+		$all = false,
1143
+		$global = true)
1144
+	{
1145
+        
1146
+		$MTP = EEM_Message_Template_Group::instance();
1147
+        
1148
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
+		$orderby                    = $this->_req_data['orderby'];
1150
+        
1151
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
+			? $this->_req_data['order']
1153
+			: 'ASC';
1154
+        
1155
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
+			? $this->_req_data['paged']
1157
+			: 1;
1158
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
+			? $this->_req_data['perpage']
1160
+			: $perpage;
1161
+        
1162
+		$offset = ($current_page - 1) * $per_page;
1163
+		$limit  = $all ? null : array($offset, $per_page);
1164
+        
1165
+        
1166
+		//options will match what is in the _views array property
1167
+		switch ($type) {
1168
+			case 'in_use':
1169
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
+				break;
1171
+			default:
1172
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
+		}
1174
+        
1175
+		return $templates;
1176
+	}
1177 1177
     
1178 1178
     
1179
-    /**
1180
-     * filters etc might need a list of installed message_types
1181
-     * @return array an array of message type objects
1182
-     */
1183
-    public function get_installed_message_types()
1184
-    {
1185
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
-        $installed               = array();
1187
-        
1188
-        foreach ($installed_message_types as $message_type) {
1189
-            $installed[$message_type->name] = $message_type;
1190
-        }
1191
-        
1192
-        return $installed;
1193
-    }
1179
+	/**
1180
+	 * filters etc might need a list of installed message_types
1181
+	 * @return array an array of message type objects
1182
+	 */
1183
+	public function get_installed_message_types()
1184
+	{
1185
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
+		$installed               = array();
1187
+        
1188
+		foreach ($installed_message_types as $message_type) {
1189
+			$installed[$message_type->name] = $message_type;
1190
+		}
1191
+        
1192
+		return $installed;
1193
+	}
1194 1194
     
1195 1195
     
1196
-    /**
1197
-     * _add_message_template
1198
-     *
1199
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1200
-     *
1201
-     * @param string $message_type
1202
-     * @param string $messenger
1203
-     * @param string $GRP_ID
1204
-     *
1205
-     * @throws EE_error
1206
-     */
1207
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
-    {
1209
-        //set values override any request data
1210
-        $message_type = ! empty($message_type) ? $message_type : '';
1211
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
-            ? $this->_req_data['message_type']
1213
-            : $message_type;
1214
-        
1215
-        $messenger = ! empty($messenger) ? $messenger : '';
1216
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
-            ? $this->_req_data['messenger']
1218
-            : $messenger;
1219
-        
1220
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
-        
1223
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
-        if (empty($message_type) || empty($messenger)) {
1225
-            throw new EE_Error(
1226
-                esc_html__(
1227
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
-                    'event_espresso'
1229
-                )
1230
-            );
1231
-        }
1232
-        
1233
-        //we need the GRP_ID for the template being used as the base for the new template
1234
-        if (empty($GRP_ID)) {
1235
-            throw new EE_Error(
1236
-                esc_html__(
1237
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
-                    'event_espresso'
1239
-                )
1240
-            );
1241
-        }
1242
-        
1243
-        //let's just make sure the template gets generated!
1244
-        
1245
-        //we need to reassign some variables for what the insert is expecting
1246
-        $this->_req_data['MTP_messenger']    = $messenger;
1247
-        $this->_req_data['MTP_message_type'] = $message_type;
1248
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1249
-        $this->_insert_or_update_message_template(true);
1250
-    }
1196
+	/**
1197
+	 * _add_message_template
1198
+	 *
1199
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1200
+	 *
1201
+	 * @param string $message_type
1202
+	 * @param string $messenger
1203
+	 * @param string $GRP_ID
1204
+	 *
1205
+	 * @throws EE_error
1206
+	 */
1207
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
+	{
1209
+		//set values override any request data
1210
+		$message_type = ! empty($message_type) ? $message_type : '';
1211
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
+			? $this->_req_data['message_type']
1213
+			: $message_type;
1214
+        
1215
+		$messenger = ! empty($messenger) ? $messenger : '';
1216
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
+			? $this->_req_data['messenger']
1218
+			: $messenger;
1219
+        
1220
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
+        
1223
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
+		if (empty($message_type) || empty($messenger)) {
1225
+			throw new EE_Error(
1226
+				esc_html__(
1227
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
+					'event_espresso'
1229
+				)
1230
+			);
1231
+		}
1232
+        
1233
+		//we need the GRP_ID for the template being used as the base for the new template
1234
+		if (empty($GRP_ID)) {
1235
+			throw new EE_Error(
1236
+				esc_html__(
1237
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
+					'event_espresso'
1239
+				)
1240
+			);
1241
+		}
1242
+        
1243
+		//let's just make sure the template gets generated!
1244
+        
1245
+		//we need to reassign some variables for what the insert is expecting
1246
+		$this->_req_data['MTP_messenger']    = $messenger;
1247
+		$this->_req_data['MTP_message_type'] = $message_type;
1248
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1249
+		$this->_insert_or_update_message_template(true);
1250
+	}
1251 1251
 
1252 1252
 
1253
-    /**
1254
-     * public wrapper for the _add_message_template method
1255
-     *
1256
-     * @param string $message_type     message type slug
1257
-     * @param string $messenger        messenger slug
1258
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
-     *                                 off of.
1260
-     * @throws EE_error
1261
-     */
1262
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1263
-    {
1264
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
-    }
1253
+	/**
1254
+	 * public wrapper for the _add_message_template method
1255
+	 *
1256
+	 * @param string $message_type     message type slug
1257
+	 * @param string $messenger        messenger slug
1258
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
+	 *                                 off of.
1260
+	 * @throws EE_error
1261
+	 */
1262
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1263
+	{
1264
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
+	}
1266 1266
 
1267 1267
 
1268
-    /**
1269
-     * _edit_message_template
1270
-     *
1271
-     * @access protected
1272
-     * @return void
1273
-     * @throws InvalidIdentifierException
1274
-     * @throws DomainException
1275
-     * @throws EE_Error
1276
-     * @throws InvalidArgumentException
1277
-     * @throws ReflectionException
1278
-     * @throws InvalidDataTypeException
1279
-     * @throws InvalidInterfaceException
1280
-     */
1281
-    protected function _edit_message_template()
1282
-    {
1283
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
-        $template_fields = '';
1285
-        $sidebar_fields  = '';
1286
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
-        // valid html in the templates.
1288
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
-        
1290
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
-            ? absint($this->_req_data['id'])
1292
-            : false;
1293
-        
1294
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1295
-        $message_template_group = $this->_message_template_group;
1296
-        $c_label                = $message_template_group->context_label();
1297
-        $c_config               = $message_template_group->contexts_config();
1298
-        
1299
-        reset($c_config);
1300
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
-            ? strtolower($this->_req_data['context'])
1302
-            : key($c_config);
1303
-        
1304
-        
1305
-        if (empty($GRP_ID)) {
1306
-            $action = 'insert_message_template';
1307
-            $edit_message_template_form_url = add_query_arg(
1308
-                array('action' => $action, 'noheader' => true),
1309
-                EE_MSG_ADMIN_URL
1310
-            );
1311
-        } else {
1312
-            $action = 'update_message_template';
1313
-            $edit_message_template_form_url = add_query_arg(
1314
-                array('action' => $action, 'noheader' => true),
1315
-                EE_MSG_ADMIN_URL
1316
-            );
1317
-        }
1318
-        
1319
-        //set active messenger for this view
1320
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
-            $message_template_group->messenger()
1322
-        );
1323
-        $this->_active_message_type_name = $message_template_group->message_type();
1324
-        
1325
-        
1326
-        //Do we have any validation errors?
1327
-        $validators = $this->_get_transient();
1328
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
-        
1330
-        
1331
-        //we need to assemble the title from Various details
1332
-        $context_label = sprintf(
1333
-            esc_html__('(%s %s)', 'event_espresso'),
1334
-            $c_config[$context]['label'],
1335
-            ucwords($c_label['label'])
1336
-        );
1337
-        
1338
-        $title = sprintf(
1339
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1340
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1341
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1342
-            $context_label
1343
-        );
1344
-        
1345
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1346
-        $this->_template_args['message_template'] = $message_template_group;
1347
-        $this->_template_args['is_extra_fields']  = false;
1348
-        
1349
-        
1350
-        //let's get EEH_MSG_Template so we can get template form fields
1351
-        $template_field_structure = EEH_MSG_Template::get_fields(
1352
-            $message_template_group->messenger(),
1353
-            $message_template_group->message_type()
1354
-        );
1355
-        
1356
-        if ( ! $template_field_structure) {
1357
-            $template_field_structure = false;
1358
-            $template_fields          = esc_html__(
1359
-                'There was an error in assembling the fields for this display (you should see an error message)',
1360
-                'event_espresso'
1361
-            );
1362
-        }
1363
-        
1364
-        
1365
-        $message_templates = $message_template_group->context_templates();
1366
-        
1367
-        
1368
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
-        // will get handled in the "extra" array.
1370
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
-                unset($template_field_structure[$context][$reference_field]);
1373
-            }
1374
-        }
1375
-        
1376
-        //let's loop through the template_field_structure and actually assemble the input fields!
1377
-        if ( ! empty($template_field_structure)) {
1378
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
-                // the extra array and reset them.
1381
-                if ($template_field === 'extra') {
1382
-                    $this->_template_args['is_extra_fields'] = true;
1383
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
-                        $message_template = $message_templates[$context][$reference_field];
1385
-                        $content          = $message_template instanceof EE_Message_Template
1386
-                            ? $message_template->get('MTP_content')
1387
-                            : '';
1388
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1389
-                            //let's verify if we need this extra field via the shortcodes parameter.
1390
-                            $continue = false;
1391
-                            if (isset($extra_array['shortcodes_required'])) {
1392
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
-                                        $continue = true;
1395
-                                    }
1396
-                                }
1397
-                                if ($continue) {
1398
-                                    continue;
1399
-                                }
1400
-                            }
1268
+	/**
1269
+	 * _edit_message_template
1270
+	 *
1271
+	 * @access protected
1272
+	 * @return void
1273
+	 * @throws InvalidIdentifierException
1274
+	 * @throws DomainException
1275
+	 * @throws EE_Error
1276
+	 * @throws InvalidArgumentException
1277
+	 * @throws ReflectionException
1278
+	 * @throws InvalidDataTypeException
1279
+	 * @throws InvalidInterfaceException
1280
+	 */
1281
+	protected function _edit_message_template()
1282
+	{
1283
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
+		$template_fields = '';
1285
+		$sidebar_fields  = '';
1286
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
+		// valid html in the templates.
1288
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
+        
1290
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
+			? absint($this->_req_data['id'])
1292
+			: false;
1293
+        
1294
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1295
+		$message_template_group = $this->_message_template_group;
1296
+		$c_label                = $message_template_group->context_label();
1297
+		$c_config               = $message_template_group->contexts_config();
1298
+        
1299
+		reset($c_config);
1300
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
+			? strtolower($this->_req_data['context'])
1302
+			: key($c_config);
1303
+        
1304
+        
1305
+		if (empty($GRP_ID)) {
1306
+			$action = 'insert_message_template';
1307
+			$edit_message_template_form_url = add_query_arg(
1308
+				array('action' => $action, 'noheader' => true),
1309
+				EE_MSG_ADMIN_URL
1310
+			);
1311
+		} else {
1312
+			$action = 'update_message_template';
1313
+			$edit_message_template_form_url = add_query_arg(
1314
+				array('action' => $action, 'noheader' => true),
1315
+				EE_MSG_ADMIN_URL
1316
+			);
1317
+		}
1318
+        
1319
+		//set active messenger for this view
1320
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
+			$message_template_group->messenger()
1322
+		);
1323
+		$this->_active_message_type_name = $message_template_group->message_type();
1324
+        
1325
+        
1326
+		//Do we have any validation errors?
1327
+		$validators = $this->_get_transient();
1328
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
+        
1330
+        
1331
+		//we need to assemble the title from Various details
1332
+		$context_label = sprintf(
1333
+			esc_html__('(%s %s)', 'event_espresso'),
1334
+			$c_config[$context]['label'],
1335
+			ucwords($c_label['label'])
1336
+		);
1337
+        
1338
+		$title = sprintf(
1339
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1340
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1341
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1342
+			$context_label
1343
+		);
1344
+        
1345
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1346
+		$this->_template_args['message_template'] = $message_template_group;
1347
+		$this->_template_args['is_extra_fields']  = false;
1348
+        
1349
+        
1350
+		//let's get EEH_MSG_Template so we can get template form fields
1351
+		$template_field_structure = EEH_MSG_Template::get_fields(
1352
+			$message_template_group->messenger(),
1353
+			$message_template_group->message_type()
1354
+		);
1355
+        
1356
+		if ( ! $template_field_structure) {
1357
+			$template_field_structure = false;
1358
+			$template_fields          = esc_html__(
1359
+				'There was an error in assembling the fields for this display (you should see an error message)',
1360
+				'event_espresso'
1361
+			);
1362
+		}
1363
+        
1364
+        
1365
+		$message_templates = $message_template_group->context_templates();
1366
+        
1367
+        
1368
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
+		// will get handled in the "extra" array.
1370
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
+				unset($template_field_structure[$context][$reference_field]);
1373
+			}
1374
+		}
1375
+        
1376
+		//let's loop through the template_field_structure and actually assemble the input fields!
1377
+		if ( ! empty($template_field_structure)) {
1378
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
+				// the extra array and reset them.
1381
+				if ($template_field === 'extra') {
1382
+					$this->_template_args['is_extra_fields'] = true;
1383
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
+						$message_template = $message_templates[$context][$reference_field];
1385
+						$content          = $message_template instanceof EE_Message_Template
1386
+							? $message_template->get('MTP_content')
1387
+							: '';
1388
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1389
+							//let's verify if we need this extra field via the shortcodes parameter.
1390
+							$continue = false;
1391
+							if (isset($extra_array['shortcodes_required'])) {
1392
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
+										$continue = true;
1395
+									}
1396
+								}
1397
+								if ($continue) {
1398
+									continue;
1399
+								}
1400
+							}
1401 1401
                             
1402
-                            $field_id                                = $reference_field
1403
-                                                                       . '-'
1404
-                                                                       . $extra_field
1405
-                                                                       . '-content';
1406
-                            $template_form_fields[$field_id]         = $extra_array;
1407
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
-                                                                       . $reference_field
1409
-                                                                       . '][content]['
1410
-                                                                       . $extra_field . ']';
1411
-                            $css_class                               = isset($extra_array['css_class'])
1412
-                                ? $extra_array['css_class']
1413
-                                : '';
1402
+							$field_id                                = $reference_field
1403
+																	   . '-'
1404
+																	   . $extra_field
1405
+																	   . '-content';
1406
+							$template_form_fields[$field_id]         = $extra_array;
1407
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
+																	   . $reference_field
1409
+																	   . '][content]['
1410
+																	   . $extra_field . ']';
1411
+							$css_class                               = isset($extra_array['css_class'])
1412
+								? $extra_array['css_class']
1413
+								: '';
1414 1414
                             
1415
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
-                                && in_array($extra_field, $v_fields, true)
1417
-                                &&
1418
-                                (
1419
-                                    is_array($validators[$extra_field])
1420
-                                    && isset($validators[$extra_field]['msg'])
1421
-                                )
1422
-                                ? 'validate-error ' . $css_class
1423
-                                : $css_class;
1415
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
+								&& in_array($extra_field, $v_fields, true)
1417
+								&&
1418
+								(
1419
+									is_array($validators[$extra_field])
1420
+									&& isset($validators[$extra_field]['msg'])
1421
+								)
1422
+								? 'validate-error ' . $css_class
1423
+								: $css_class;
1424 1424
                             
1425
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
-                                                                        && isset($content[$extra_field])
1427
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1428
-                                : '';
1425
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
+																		&& isset($content[$extra_field])
1427
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1428
+								: '';
1429 1429
                             
1430
-                            //do we have a validation error?  if we do then let's use that value instead
1431
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
-                                ? $validators[$extra_field]['value']
1433
-                                : $template_form_fields[$field_id]['value'];
1430
+							//do we have a validation error?  if we do then let's use that value instead
1431
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
+								? $validators[$extra_field]['value']
1433
+								: $template_form_fields[$field_id]['value'];
1434 1434
                             
1435 1435
                             
1436
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1436
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1437 1437
                             
1438
-                            //shortcode selector
1439
-                            $field_name_to_use                                 = $extra_field === 'main'
1440
-                                ? 'content'
1441
-                                : $extra_field;
1442
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
-                                $field_name_to_use,
1444
-                                $field_id
1445
-                            );
1438
+							//shortcode selector
1439
+							$field_name_to_use                                 = $extra_field === 'main'
1440
+								? 'content'
1441
+								: $extra_field;
1442
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
+								$field_name_to_use,
1444
+								$field_id
1445
+							);
1446 1446
                             
1447
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
-                                //we want to decode the entities
1449
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1450
-                                    html_entity_decode(
1451
-                                        $template_form_fields[$field_id]['value'],
1452
-                                        ENT_QUOTES,
1453
-                                        "UTF-8")
1454
-                                );
1447
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
+								//we want to decode the entities
1449
+								$template_form_fields[$field_id]['value'] = stripslashes(
1450
+									html_entity_decode(
1451
+										$template_form_fields[$field_id]['value'],
1452
+										ENT_QUOTES,
1453
+										"UTF-8")
1454
+								);
1455 1455
                                 
1456
-                            }/**/
1457
-                        }
1458
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1459
-                        $templatefield_templatename_id = $reference_field . '-name';
1456
+							}/**/
1457
+						}
1458
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1459
+						$templatefield_templatename_id = $reference_field . '-name';
1460 1460
                         
1461
-                        $template_form_fields[$templatefield_MTP_id] = array(
1462
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1463
-                            'label'      => null,
1464
-                            'input'      => 'hidden',
1465
-                            'type'       => 'int',
1466
-                            'required'   => false,
1467
-                            'validation' => false,
1468
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1469
-                            'css_class'  => '',
1470
-                            'format'     => '%d',
1471
-                            'db-col'     => 'MTP_ID'
1472
-                        );
1461
+						$template_form_fields[$templatefield_MTP_id] = array(
1462
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1463
+							'label'      => null,
1464
+							'input'      => 'hidden',
1465
+							'type'       => 'int',
1466
+							'required'   => false,
1467
+							'validation' => false,
1468
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1469
+							'css_class'  => '',
1470
+							'format'     => '%d',
1471
+							'db-col'     => 'MTP_ID'
1472
+						);
1473 1473
                         
1474
-                        $template_form_fields[$templatefield_templatename_id] = array(
1475
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1476
-                            'label'      => null,
1477
-                            'input'      => 'hidden',
1478
-                            'type'       => 'string',
1479
-                            'required'   => false,
1480
-                            'validation' => true,
1481
-                            'value'      => $reference_field,
1482
-                            'css_class'  => '',
1483
-                            'format'     => '%s',
1484
-                            'db-col'     => 'MTP_template_field'
1485
-                        );
1486
-                    }
1487
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1488
-                } else {
1489
-                    $field_id                                 = $template_field . '-content';
1490
-                    $template_form_fields[$field_id]          = $field_setup_array;
1491
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1492
-                    $message_template                         = isset($message_templates[$context][$template_field])
1493
-                        ? $message_templates[$context][$template_field]
1494
-                        : null;
1495
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
-                                                                && is_array($message_templates[$context])
1497
-                                                                && $message_template instanceof EE_Message_Template
1498
-                        ? $message_template->get('MTP_content')
1499
-                        : '';
1474
+						$template_form_fields[$templatefield_templatename_id] = array(
1475
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1476
+							'label'      => null,
1477
+							'input'      => 'hidden',
1478
+							'type'       => 'string',
1479
+							'required'   => false,
1480
+							'validation' => true,
1481
+							'value'      => $reference_field,
1482
+							'css_class'  => '',
1483
+							'format'     => '%s',
1484
+							'db-col'     => 'MTP_template_field'
1485
+						);
1486
+					}
1487
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1488
+				} else {
1489
+					$field_id                                 = $template_field . '-content';
1490
+					$template_form_fields[$field_id]          = $field_setup_array;
1491
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1492
+					$message_template                         = isset($message_templates[$context][$template_field])
1493
+						? $message_templates[$context][$template_field]
1494
+						: null;
1495
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
+																&& is_array($message_templates[$context])
1497
+																&& $message_template instanceof EE_Message_Template
1498
+						? $message_template->get('MTP_content')
1499
+						: '';
1500 1500
                     
1501
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1502
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1503
-                        ? $validators[$template_field]['value']
1504
-                        : $template_form_fields[$field_id]['value'];
1501
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1502
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1503
+						? $validators[$template_field]['value']
1504
+						: $template_form_fields[$field_id]['value'];
1505 1505
                     
1506 1506
                     
1507
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1508
-                    $css_class                                    = isset($field_setup_array['css_class'])
1509
-                        ? $field_setup_array['css_class']
1510
-                        : '';
1511
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1512
-                                                                    && in_array($template_field, $v_fields, true)
1513
-                                                                    && isset($validators[$template_field]['msg'])
1514
-                        ? 'validate-error ' . $css_class
1515
-                        : $css_class;
1507
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1508
+					$css_class                                    = isset($field_setup_array['css_class'])
1509
+						? $field_setup_array['css_class']
1510
+						: '';
1511
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1512
+																	&& in_array($template_field, $v_fields, true)
1513
+																	&& isset($validators[$template_field]['msg'])
1514
+						? 'validate-error ' . $css_class
1515
+						: $css_class;
1516 1516
                     
1517
-                    //shortcode selector
1518
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1519
-                        $template_field, $field_id
1520
-                    );
1521
-                }
1517
+					//shortcode selector
1518
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1519
+						$template_field, $field_id
1520
+					);
1521
+				}
1522 1522
                 
1523
-                //k took care of content field(s) now let's take care of others.
1523
+				//k took care of content field(s) now let's take care of others.
1524 1524
                 
1525
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1526
-                $templatefield_field_templatename_id = $template_field . '-name';
1525
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1526
+				$templatefield_field_templatename_id = $template_field . '-name';
1527 1527
                 
1528
-                //foreach template field there are actually two form fields created
1529
-                $template_form_fields[$templatefield_MTP_id] = array(
1530
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1531
-                    'label'      => null,
1532
-                    'input'      => 'hidden',
1533
-                    'type'       => 'int',
1534
-                    'required'   => false,
1535
-                    'validation' => true,
1536
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1537
-                    'css_class'  => '',
1538
-                    'format'     => '%d',
1539
-                    'db-col'     => 'MTP_ID'
1540
-                );
1528
+				//foreach template field there are actually two form fields created
1529
+				$template_form_fields[$templatefield_MTP_id] = array(
1530
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1531
+					'label'      => null,
1532
+					'input'      => 'hidden',
1533
+					'type'       => 'int',
1534
+					'required'   => false,
1535
+					'validation' => true,
1536
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1537
+					'css_class'  => '',
1538
+					'format'     => '%d',
1539
+					'db-col'     => 'MTP_ID'
1540
+				);
1541 1541
                 
1542
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1543
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1544
-                    'label'      => null,
1545
-                    'input'      => 'hidden',
1546
-                    'type'       => 'string',
1547
-                    'required'   => false,
1548
-                    'validation' => true,
1549
-                    'value'      => $template_field,
1550
-                    'css_class'  => '',
1551
-                    'format'     => '%s',
1552
-                    'db-col'     => 'MTP_template_field'
1553
-                );
1542
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1543
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1544
+					'label'      => null,
1545
+					'input'      => 'hidden',
1546
+					'type'       => 'string',
1547
+					'required'   => false,
1548
+					'validation' => true,
1549
+					'value'      => $template_field,
1550
+					'css_class'  => '',
1551
+					'format'     => '%s',
1552
+					'db-col'     => 'MTP_template_field'
1553
+				);
1554 1554
                 
1555
-            }
1555
+			}
1556 1556
             
1557
-            //add other fields
1558
-            $template_form_fields['ee-msg-current-context'] = array(
1559
-                'name'       => 'MTP_context',
1560
-                'label'      => null,
1561
-                'input'      => 'hidden',
1562
-                'type'       => 'string',
1563
-                'required'   => false,
1564
-                'validation' => true,
1565
-                'value'      => $context,
1566
-                'css_class'  => '',
1567
-                'format'     => '%s',
1568
-                'db-col'     => 'MTP_context'
1569
-            );
1557
+			//add other fields
1558
+			$template_form_fields['ee-msg-current-context'] = array(
1559
+				'name'       => 'MTP_context',
1560
+				'label'      => null,
1561
+				'input'      => 'hidden',
1562
+				'type'       => 'string',
1563
+				'required'   => false,
1564
+				'validation' => true,
1565
+				'value'      => $context,
1566
+				'css_class'  => '',
1567
+				'format'     => '%s',
1568
+				'db-col'     => 'MTP_context'
1569
+			);
1570 1570
             
1571
-            $template_form_fields['ee-msg-grp-id'] = array(
1572
-                'name'       => 'GRP_ID',
1573
-                'label'      => null,
1574
-                'input'      => 'hidden',
1575
-                'type'       => 'int',
1576
-                'required'   => false,
1577
-                'validation' => true,
1578
-                'value'      => $GRP_ID,
1579
-                'css_class'  => '',
1580
-                'format'     => '%d',
1581
-                'db-col'     => 'GRP_ID'
1582
-            );
1571
+			$template_form_fields['ee-msg-grp-id'] = array(
1572
+				'name'       => 'GRP_ID',
1573
+				'label'      => null,
1574
+				'input'      => 'hidden',
1575
+				'type'       => 'int',
1576
+				'required'   => false,
1577
+				'validation' => true,
1578
+				'value'      => $GRP_ID,
1579
+				'css_class'  => '',
1580
+				'format'     => '%d',
1581
+				'db-col'     => 'GRP_ID'
1582
+			);
1583 1583
             
1584
-            $template_form_fields['ee-msg-messenger'] = array(
1585
-                'name'       => 'MTP_messenger',
1586
-                'label'      => null,
1587
-                'input'      => 'hidden',
1588
-                'type'       => 'string',
1589
-                'required'   => false,
1590
-                'validation' => true,
1591
-                'value'      => $message_template_group->messenger(),
1592
-                'css_class'  => '',
1593
-                'format'     => '%s',
1594
-                'db-col'     => 'MTP_messenger'
1595
-            );
1584
+			$template_form_fields['ee-msg-messenger'] = array(
1585
+				'name'       => 'MTP_messenger',
1586
+				'label'      => null,
1587
+				'input'      => 'hidden',
1588
+				'type'       => 'string',
1589
+				'required'   => false,
1590
+				'validation' => true,
1591
+				'value'      => $message_template_group->messenger(),
1592
+				'css_class'  => '',
1593
+				'format'     => '%s',
1594
+				'db-col'     => 'MTP_messenger'
1595
+			);
1596 1596
             
1597
-            $template_form_fields['ee-msg-message-type'] = array(
1598
-                'name'       => 'MTP_message_type',
1599
-                'label'      => null,
1600
-                'input'      => 'hidden',
1601
-                'type'       => 'string',
1602
-                'required'   => false,
1603
-                'validation' => true,
1604
-                'value'      => $message_template_group->message_type(),
1605
-                'css_class'  => '',
1606
-                'format'     => '%s',
1607
-                'db-col'     => 'MTP_message_type'
1608
-            );
1597
+			$template_form_fields['ee-msg-message-type'] = array(
1598
+				'name'       => 'MTP_message_type',
1599
+				'label'      => null,
1600
+				'input'      => 'hidden',
1601
+				'type'       => 'string',
1602
+				'required'   => false,
1603
+				'validation' => true,
1604
+				'value'      => $message_template_group->message_type(),
1605
+				'css_class'  => '',
1606
+				'format'     => '%s',
1607
+				'db-col'     => 'MTP_message_type'
1608
+			);
1609 1609
             
1610
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1611
-                'name'       => 'MTP_is_global',
1612
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1613
-                'input'      => 'hidden',
1614
-                'type'       => 'int',
1615
-                'required'   => false,
1616
-                'validation' => true,
1617
-                'value'      => $message_template_group->get('MTP_is_global'),
1618
-                'css_class'  => '',
1619
-                'format'     => '%d',
1620
-                'db-col'     => 'MTP_is_global'
1621
-            );
1610
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1611
+				'name'       => 'MTP_is_global',
1612
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1613
+				'input'      => 'hidden',
1614
+				'type'       => 'int',
1615
+				'required'   => false,
1616
+				'validation' => true,
1617
+				'value'      => $message_template_group->get('MTP_is_global'),
1618
+				'css_class'  => '',
1619
+				'format'     => '%d',
1620
+				'db-col'     => 'MTP_is_global'
1621
+			);
1622 1622
             
1623
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1624
-                'name'       => 'MTP_is_override',
1625
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1626
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1627
-                'type'       => 'int',
1628
-                'required'   => false,
1629
-                'validation' => true,
1630
-                'value'      => $message_template_group->get('MTP_is_override'),
1631
-                'css_class'  => '',
1632
-                'format'     => '%d',
1633
-                'db-col'     => 'MTP_is_override'
1634
-            );
1623
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1624
+				'name'       => 'MTP_is_override',
1625
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1626
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1627
+				'type'       => 'int',
1628
+				'required'   => false,
1629
+				'validation' => true,
1630
+				'value'      => $message_template_group->get('MTP_is_override'),
1631
+				'css_class'  => '',
1632
+				'format'     => '%d',
1633
+				'db-col'     => 'MTP_is_override'
1634
+			);
1635 1635
             
1636
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1637
-                'name'       => 'MTP_is_active',
1638
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1639
-                'input'      => 'hidden',
1640
-                'type'       => 'int',
1641
-                'required'   => false,
1642
-                'validation' => true,
1643
-                'value'      => $message_template_group->is_active(),
1644
-                'css_class'  => '',
1645
-                'format'     => '%d',
1646
-                'db-col'     => 'MTP_is_active'
1647
-            );
1636
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1637
+				'name'       => 'MTP_is_active',
1638
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1639
+				'input'      => 'hidden',
1640
+				'type'       => 'int',
1641
+				'required'   => false,
1642
+				'validation' => true,
1643
+				'value'      => $message_template_group->is_active(),
1644
+				'css_class'  => '',
1645
+				'format'     => '%d',
1646
+				'db-col'     => 'MTP_is_active'
1647
+			);
1648 1648
             
1649
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1650
-                'name'       => 'MTP_deleted',
1651
-                'label'      => null,
1652
-                'input'      => 'hidden',
1653
-                'type'       => 'int',
1654
-                'required'   => false,
1655
-                'validation' => true,
1656
-                'value'      => $message_template_group->get('MTP_deleted'),
1657
-                'css_class'  => '',
1658
-                'format'     => '%d',
1659
-                'db-col'     => 'MTP_deleted'
1660
-            );
1661
-            $sidebar_form_fields['ee-msg-author']  = array(
1662
-                'name'       => 'MTP_user_id',
1663
-                'label'      => esc_html__('Author', 'event_espresso'),
1664
-                'input'      => 'hidden',
1665
-                'type'       => 'int',
1666
-                'required'   => false,
1667
-                'validation' => false,
1668
-                'value'      => $message_template_group->user(),
1669
-                'format'     => '%d',
1670
-                'db-col'     => 'MTP_user_id'
1671
-            );
1649
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1650
+				'name'       => 'MTP_deleted',
1651
+				'label'      => null,
1652
+				'input'      => 'hidden',
1653
+				'type'       => 'int',
1654
+				'required'   => false,
1655
+				'validation' => true,
1656
+				'value'      => $message_template_group->get('MTP_deleted'),
1657
+				'css_class'  => '',
1658
+				'format'     => '%d',
1659
+				'db-col'     => 'MTP_deleted'
1660
+			);
1661
+			$sidebar_form_fields['ee-msg-author']  = array(
1662
+				'name'       => 'MTP_user_id',
1663
+				'label'      => esc_html__('Author', 'event_espresso'),
1664
+				'input'      => 'hidden',
1665
+				'type'       => 'int',
1666
+				'required'   => false,
1667
+				'validation' => false,
1668
+				'value'      => $message_template_group->user(),
1669
+				'format'     => '%d',
1670
+				'db-col'     => 'MTP_user_id'
1671
+			);
1672 1672
             
1673
-            $sidebar_form_fields['ee-msg-route'] = array(
1674
-                'name'  => 'action',
1675
-                'input' => 'hidden',
1676
-                'type'  => 'string',
1677
-                'value' => $action
1678
-            );
1673
+			$sidebar_form_fields['ee-msg-route'] = array(
1674
+				'name'  => 'action',
1675
+				'input' => 'hidden',
1676
+				'type'  => 'string',
1677
+				'value' => $action
1678
+			);
1679 1679
             
1680
-            $sidebar_form_fields['ee-msg-id']        = array(
1681
-                'name'  => 'id',
1682
-                'input' => 'hidden',
1683
-                'type'  => 'int',
1684
-                'value' => $GRP_ID
1685
-            );
1686
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1687
-                'name'  => $action . '_nonce',
1688
-                'input' => 'hidden',
1689
-                'type'  => 'string',
1690
-                'value' => wp_create_nonce($action . '_nonce')
1691
-            );
1680
+			$sidebar_form_fields['ee-msg-id']        = array(
1681
+				'name'  => 'id',
1682
+				'input' => 'hidden',
1683
+				'type'  => 'int',
1684
+				'value' => $GRP_ID
1685
+			);
1686
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1687
+				'name'  => $action . '_nonce',
1688
+				'input' => 'hidden',
1689
+				'type'  => 'string',
1690
+				'value' => wp_create_nonce($action . '_nonce')
1691
+			);
1692 1692
             
1693
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1694
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1695
-                    'name'  => 'template_switch',
1696
-                    'input' => 'hidden',
1697
-                    'type'  => 'int',
1698
-                    'value' => 1
1699
-                );
1700
-            }
1693
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1694
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1695
+					'name'  => 'template_switch',
1696
+					'input' => 'hidden',
1697
+					'type'  => 'int',
1698
+					'value' => 1
1699
+				);
1700
+			}
1701 1701
             
1702 1702
             
1703
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1704
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1703
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1704
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1705 1705
             
1706 1706
             
1707
-        } //end if ( !empty($template_field_structure) )
1708
-        
1709
-        //set extra content for publish box
1710
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1711
-        $this->_set_publish_post_box_vars(
1712
-            'id',
1713
-            $GRP_ID,
1714
-            false,
1715
-            add_query_arg(
1716
-                array('action' => 'global_mtps'),
1717
-                $this->_admin_base_url
1718
-            )
1719
-        );
1720
-        
1721
-        //add preview button
1722
-        $preview_url    = parent::add_query_args_and_nonce(
1723
-            array(
1724
-                'message_type' => $message_template_group->message_type(),
1725
-                'messenger'    => $message_template_group->messenger(),
1726
-                'context'      => $context,
1727
-                'GRP_ID'       => $GRP_ID,
1728
-                'action'       => 'preview_message'
1729
-            ),
1730
-            $this->_admin_base_url
1731
-        );
1732
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1733
-                          . esc_html__('Preview', 'event_espresso')
1734
-                          . '</a>';
1735
-        
1736
-        
1737
-        //setup context switcher
1738
-        $context_switcher_args = array(
1739
-            'page'    => 'espresso_messages',
1740
-            'action'  => 'edit_message_template',
1741
-            'id'      => $GRP_ID,
1742
-            'context' => $context,
1743
-            'extra'   => $preview_button
1744
-        );
1745
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1746
-        
1747
-        
1748
-        //main box
1749
-        $this->_template_args['template_fields']                         = $template_fields;
1750
-        $this->_template_args['sidebar_box_id']                          = 'details';
1751
-        $this->_template_args['action']                                  = $action;
1752
-        $this->_template_args['context']                                 = $context;
1753
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1754
-        $this->_template_args['learn_more_about_message_templates_link'] =
1755
-            $this->_learn_more_about_message_templates_link();
1756
-        
1757
-        
1758
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1759
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1760
-            $message_template_group,
1761
-            $context,
1762
-            $context_label
1763
-        );
1764
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1765
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1766
-        
1767
-        $this->_template_path = $this->_template_args['GRP_ID']
1768
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1769
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1770
-        
1771
-        //send along EE_Message_Template_Group object for further template use.
1772
-        $this->_template_args['MTP'] = $message_template_group;
1773
-        
1774
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1775
-            $this->_template_path,
1776
-            $this->_template_args,
1777
-            true
1778
-        );
1779
-        
1780
-        
1781
-        //finally, let's set the admin_page title
1782
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1783
-        
1784
-        
1785
-        //we need to take care of setting the shortcodes property for use elsewhere.
1786
-        $this->_set_shortcodes();
1787
-        
1788
-        
1789
-        //final template wrapper
1790
-        $this->display_admin_page_with_sidebar();
1791
-    }
1707
+		} //end if ( !empty($template_field_structure) )
1708
+        
1709
+		//set extra content for publish box
1710
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1711
+		$this->_set_publish_post_box_vars(
1712
+			'id',
1713
+			$GRP_ID,
1714
+			false,
1715
+			add_query_arg(
1716
+				array('action' => 'global_mtps'),
1717
+				$this->_admin_base_url
1718
+			)
1719
+		);
1720
+        
1721
+		//add preview button
1722
+		$preview_url    = parent::add_query_args_and_nonce(
1723
+			array(
1724
+				'message_type' => $message_template_group->message_type(),
1725
+				'messenger'    => $message_template_group->messenger(),
1726
+				'context'      => $context,
1727
+				'GRP_ID'       => $GRP_ID,
1728
+				'action'       => 'preview_message'
1729
+			),
1730
+			$this->_admin_base_url
1731
+		);
1732
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1733
+						  . esc_html__('Preview', 'event_espresso')
1734
+						  . '</a>';
1735
+        
1736
+        
1737
+		//setup context switcher
1738
+		$context_switcher_args = array(
1739
+			'page'    => 'espresso_messages',
1740
+			'action'  => 'edit_message_template',
1741
+			'id'      => $GRP_ID,
1742
+			'context' => $context,
1743
+			'extra'   => $preview_button
1744
+		);
1745
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1746
+        
1747
+        
1748
+		//main box
1749
+		$this->_template_args['template_fields']                         = $template_fields;
1750
+		$this->_template_args['sidebar_box_id']                          = 'details';
1751
+		$this->_template_args['action']                                  = $action;
1752
+		$this->_template_args['context']                                 = $context;
1753
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1754
+		$this->_template_args['learn_more_about_message_templates_link'] =
1755
+			$this->_learn_more_about_message_templates_link();
1756
+        
1757
+        
1758
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1759
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1760
+			$message_template_group,
1761
+			$context,
1762
+			$context_label
1763
+		);
1764
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1765
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1766
+        
1767
+		$this->_template_path = $this->_template_args['GRP_ID']
1768
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1769
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1770
+        
1771
+		//send along EE_Message_Template_Group object for further template use.
1772
+		$this->_template_args['MTP'] = $message_template_group;
1773
+        
1774
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1775
+			$this->_template_path,
1776
+			$this->_template_args,
1777
+			true
1778
+		);
1779
+        
1780
+        
1781
+		//finally, let's set the admin_page title
1782
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1783
+        
1784
+        
1785
+		//we need to take care of setting the shortcodes property for use elsewhere.
1786
+		$this->_set_shortcodes();
1787
+        
1788
+        
1789
+		//final template wrapper
1790
+		$this->display_admin_page_with_sidebar();
1791
+	}
1792 1792
     
1793 1793
     
1794
-    public function filter_tinymce_init($mceInit, $editor_id)
1795
-    {
1796
-        return $mceInit;
1797
-    }
1794
+	public function filter_tinymce_init($mceInit, $editor_id)
1795
+	{
1796
+		return $mceInit;
1797
+	}
1798 1798
     
1799 1799
     
1800
-    public function add_context_switcher()
1801
-    {
1802
-        return $this->_context_switcher;
1803
-    }
1800
+	public function add_context_switcher()
1801
+	{
1802
+		return $this->_context_switcher;
1803
+	}
1804 1804
 
1805 1805
 
1806
-    /**
1807
-     * Adds the activation/deactivation toggle for the message template context.
1808
-     *
1809
-     * @param EE_Message_Template_Group $message_template_group
1810
-     * @param string                    $context
1811
-     * @param string                    $context_label
1812
-     * @return string
1813
-     * @throws DomainException
1814
-     * @throws EE_Error
1815
-     * @throws InvalidIdentifierException
1816
-     */
1817
-    protected function add_active_context_element(
1818
-        EE_Message_Template_Group $message_template_group,
1819
-        $context,
1820
-        $context_label
1821
-    ) {
1822
-        $template_args = array(
1823
-            'context' => $context,
1824
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1825
-            'is_active' => $message_template_group->is_context_active($context),
1826
-            'on_off_action' => $message_template_group->is_context_active($context)
1827
-                ? 'context-off'
1828
-                : 'context-on',
1829
-            'context_label' => str_replace(array('(', ')'), '', $context_label),
1830
-            'message_template_group_id' => $message_template_group->ID()
1831
-        );
1832
-        return EEH_Template::display_template(
1833
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1834
-          $template_args,
1835
-          true
1836
-        );
1837
-    }
1806
+	/**
1807
+	 * Adds the activation/deactivation toggle for the message template context.
1808
+	 *
1809
+	 * @param EE_Message_Template_Group $message_template_group
1810
+	 * @param string                    $context
1811
+	 * @param string                    $context_label
1812
+	 * @return string
1813
+	 * @throws DomainException
1814
+	 * @throws EE_Error
1815
+	 * @throws InvalidIdentifierException
1816
+	 */
1817
+	protected function add_active_context_element(
1818
+		EE_Message_Template_Group $message_template_group,
1819
+		$context,
1820
+		$context_label
1821
+	) {
1822
+		$template_args = array(
1823
+			'context' => $context,
1824
+			'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1825
+			'is_active' => $message_template_group->is_context_active($context),
1826
+			'on_off_action' => $message_template_group->is_context_active($context)
1827
+				? 'context-off'
1828
+				: 'context-on',
1829
+			'context_label' => str_replace(array('(', ')'), '', $context_label),
1830
+			'message_template_group_id' => $message_template_group->ID()
1831
+		);
1832
+		return EEH_Template::display_template(
1833
+		  EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1834
+		  $template_args,
1835
+		  true
1836
+		);
1837
+	}
1838 1838
 
1839 1839
 
1840
-    /**
1841
-     * Ajax callback for `toggle_context_template` ajax action.
1842
-     * Handles toggling the message context on or off.
1843
-     * @throws EE_Error
1844
-     * @throws InvalidArgumentException
1845
-     * @throws InvalidDataTypeException
1846
-     * @throws InvalidIdentifierException
1847
-     * @throws InvalidInterfaceException
1848
-     */
1849
-    public function toggle_context_template()
1850
-    {
1851
-        $success = true;
1852
-        //check for required data
1853
-        if (!isset(
1854
-            $this->_req_data['message_template_group_id'],
1855
-            $this->_req_data['context'],
1856
-            $this->_req_data['status']
1857
-        )) {
1858
-            EE_Error::add_error(
1859
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1860
-                __FILE__,
1861
-                __FUNCTION__,
1862
-                __LINE__
1863
-            );
1864
-            $success = false;
1865
-        }
1840
+	/**
1841
+	 * Ajax callback for `toggle_context_template` ajax action.
1842
+	 * Handles toggling the message context on or off.
1843
+	 * @throws EE_Error
1844
+	 * @throws InvalidArgumentException
1845
+	 * @throws InvalidDataTypeException
1846
+	 * @throws InvalidIdentifierException
1847
+	 * @throws InvalidInterfaceException
1848
+	 */
1849
+	public function toggle_context_template()
1850
+	{
1851
+		$success = true;
1852
+		//check for required data
1853
+		if (!isset(
1854
+			$this->_req_data['message_template_group_id'],
1855
+			$this->_req_data['context'],
1856
+			$this->_req_data['status']
1857
+		)) {
1858
+			EE_Error::add_error(
1859
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1860
+				__FILE__,
1861
+				__FUNCTION__,
1862
+				__LINE__
1863
+			);
1864
+			$success = false;
1865
+		}
1866 1866
 
1867
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1868
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1869
-            : '';
1870
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1871
-        $this->_verify_nonce($nonce, $nonce_ref);
1872
-        $status = $this->_req_data['status'];
1873
-        if ($status !== 'off' && $status !=='on') {
1874
-            EE_Error::add_error(
1875
-                sprintf(
1876
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1877
-                    $this->_req_data['status']
1878
-                ),
1879
-                __FILE__,
1880
-                __FUNCTION__,
1881
-                __LINE__
1882
-            );
1883
-            $success = false;
1884
-        }
1885
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1886
-            $this->_req_data['message_template_group_id']
1887
-        );
1888
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1889
-            EE_Error::add_error(
1890
-                sprintf(
1891
-                    esc_html__(
1892
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1893
-                        'event_espresso'
1894
-                    ),
1895
-                    $this->_req_data['message_template_group_id'],
1896
-                    'EE_Message_Template_Group'
1897
-                ),
1898
-                __FILE__,
1899
-                __FUNCTION__,
1900
-                __LINE__
1901
-            );
1902
-            $success = false;
1903
-        }
1904
-        if ($success) {
1905
-            $success = $status === 'off'
1906
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1907
-                : $message_template_group->activate_context($this->_req_data['context']);
1908
-        }
1909
-        $this->_template_args['success'] = $success;
1910
-        $this->_return_json();
1911
-    }
1867
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1868
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1869
+			: '';
1870
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1871
+		$this->_verify_nonce($nonce, $nonce_ref);
1872
+		$status = $this->_req_data['status'];
1873
+		if ($status !== 'off' && $status !=='on') {
1874
+			EE_Error::add_error(
1875
+				sprintf(
1876
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1877
+					$this->_req_data['status']
1878
+				),
1879
+				__FILE__,
1880
+				__FUNCTION__,
1881
+				__LINE__
1882
+			);
1883
+			$success = false;
1884
+		}
1885
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1886
+			$this->_req_data['message_template_group_id']
1887
+		);
1888
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1889
+			EE_Error::add_error(
1890
+				sprintf(
1891
+					esc_html__(
1892
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1893
+						'event_espresso'
1894
+					),
1895
+					$this->_req_data['message_template_group_id'],
1896
+					'EE_Message_Template_Group'
1897
+				),
1898
+				__FILE__,
1899
+				__FUNCTION__,
1900
+				__LINE__
1901
+			);
1902
+			$success = false;
1903
+		}
1904
+		if ($success) {
1905
+			$success = $status === 'off'
1906
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1907
+				: $message_template_group->activate_context($this->_req_data['context']);
1908
+		}
1909
+		$this->_template_args['success'] = $success;
1910
+		$this->_return_json();
1911
+	}
1912 1912
 
1913 1913
 
1914 1914
     
1915
-    public function _add_form_element_before()
1916
-    {
1917
-        return '<form method="post" action="'
1918
-               . $this->_template_args["edit_message_template_form_url"]
1919
-               . '" id="ee-msg-edit-frm">';
1920
-    }
1915
+	public function _add_form_element_before()
1916
+	{
1917
+		return '<form method="post" action="'
1918
+			   . $this->_template_args["edit_message_template_form_url"]
1919
+			   . '" id="ee-msg-edit-frm">';
1920
+	}
1921 1921
     
1922
-    public function _add_form_element_after()
1923
-    {
1924
-        return '</form>';
1925
-    }
1922
+	public function _add_form_element_after()
1923
+	{
1924
+		return '</form>';
1925
+	}
1926 1926
 
1927 1927
 
1928
-    /**
1929
-     * This executes switching the template pack for a message template.
1930
-     *
1931
-     * @since 4.5.0
1932
-     * @throws EE_Error
1933
-     * @throws InvalidDataTypeException
1934
-     * @throws InvalidInterfaceException
1935
-     * @throws InvalidArgumentException
1936
-     * @throws ReflectionException
1937
-     */
1938
-    public function switch_template_pack()
1939
-    {
1940
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1941
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1942
-        
1943
-        //verify we have needed values.
1944
-        if (empty($GRP_ID) || empty($template_pack)) {
1945
-            $this->_template_args['error'] = true;
1946
-            EE_Error::add_error(
1947
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1948
-                __FILE__,
1949
-                __FUNCTION__,
1950
-                __LINE__
1951
-            );
1952
-        } else {
1953
-            //get template, set the new template_pack and then reset to default
1954
-            /** @type EE_Message_Template_Group $message_template_group */
1955
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1928
+	/**
1929
+	 * This executes switching the template pack for a message template.
1930
+	 *
1931
+	 * @since 4.5.0
1932
+	 * @throws EE_Error
1933
+	 * @throws InvalidDataTypeException
1934
+	 * @throws InvalidInterfaceException
1935
+	 * @throws InvalidArgumentException
1936
+	 * @throws ReflectionException
1937
+	 */
1938
+	public function switch_template_pack()
1939
+	{
1940
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1941
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1942
+        
1943
+		//verify we have needed values.
1944
+		if (empty($GRP_ID) || empty($template_pack)) {
1945
+			$this->_template_args['error'] = true;
1946
+			EE_Error::add_error(
1947
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1948
+				__FILE__,
1949
+				__FUNCTION__,
1950
+				__LINE__
1951
+			);
1952
+		} else {
1953
+			//get template, set the new template_pack and then reset to default
1954
+			/** @type EE_Message_Template_Group $message_template_group */
1955
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1956 1956
             
1957
-            $message_template_group->set_template_pack_name($template_pack);
1958
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1959
-            $this->_req_data['mt']   = $message_template_group->message_type();
1957
+			$message_template_group->set_template_pack_name($template_pack);
1958
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1959
+			$this->_req_data['mt']   = $message_template_group->message_type();
1960 1960
             
1961
-            $query_args = $this->_reset_to_default_template();
1961
+			$query_args = $this->_reset_to_default_template();
1962 1962
             
1963
-            if (empty($query_args['id'])) {
1964
-                EE_Error::add_error(
1965
-                    esc_html__(
1966
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1967
-                        'event_espresso'
1968
-                    ),
1969
-                    __FILE__,
1970
-                    __FUNCTION__,
1971
-                    __LINE__
1972
-                );
1973
-                $this->_template_args['error'] = true;
1974
-            } else {
1975
-                $template_label       = $message_template_group->get_template_pack()->label;
1976
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1977
-                EE_Error::add_success(
1978
-                    sprintf(
1979
-                        esc_html__(
1980
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1981
-                            'event_espresso'
1982
-                        ),
1983
-                        $template_label,
1984
-                        $template_pack_labels->template_pack
1985
-                    )
1986
-                );
1987
-                //generate the redirect url for js.
1988
-                $url                                          = self::add_query_args_and_nonce($query_args,
1989
-                    $this->_admin_base_url);
1990
-                $this->_template_args['data']['redirect_url'] = $url;
1991
-                $this->_template_args['success']              = true;
1992
-            }
1963
+			if (empty($query_args['id'])) {
1964
+				EE_Error::add_error(
1965
+					esc_html__(
1966
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1967
+						'event_espresso'
1968
+					),
1969
+					__FILE__,
1970
+					__FUNCTION__,
1971
+					__LINE__
1972
+				);
1973
+				$this->_template_args['error'] = true;
1974
+			} else {
1975
+				$template_label       = $message_template_group->get_template_pack()->label;
1976
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1977
+				EE_Error::add_success(
1978
+					sprintf(
1979
+						esc_html__(
1980
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1981
+							'event_espresso'
1982
+						),
1983
+						$template_label,
1984
+						$template_pack_labels->template_pack
1985
+					)
1986
+				);
1987
+				//generate the redirect url for js.
1988
+				$url                                          = self::add_query_args_and_nonce($query_args,
1989
+					$this->_admin_base_url);
1990
+				$this->_template_args['data']['redirect_url'] = $url;
1991
+				$this->_template_args['success']              = true;
1992
+			}
1993 1993
             
1994
-            $this->_return_json();
1994
+			$this->_return_json();
1995 1995
             
1996
-        }
1997
-    }
1996
+		}
1997
+	}
1998 1998
 
1999 1999
 
2000
-    /**
2001
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2002
-     * they want.
2003
-     *
2004
-     * @access protected
2005
-     * @return array|null
2006
-     * @throws EE_Error
2007
-     * @throws InvalidArgumentException
2008
-     * @throws InvalidDataTypeException
2009
-     * @throws InvalidInterfaceException
2010
-     */
2011
-    protected function _reset_to_default_template()
2012
-    {
2013
-        
2014
-        $templates = array();
2015
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2016
-        //we need to make sure we've got the info we need.
2017
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2018
-            EE_Error::add_error(
2019
-                esc_html__(
2020
-                    '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.',
2021
-                    'event_espresso'
2022
-                ),
2023
-                __FILE__, __FUNCTION__, __LINE__
2024
-            );
2025
-        }
2026
-        
2027
-        // all templates will be reset to whatever the defaults are
2028
-        // for the global template matching the messenger and message type.
2029
-        $success = ! empty($GRP_ID) ? true : false;
2030
-        
2031
-        if ($success) {
2000
+	/**
2001
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2002
+	 * they want.
2003
+	 *
2004
+	 * @access protected
2005
+	 * @return array|null
2006
+	 * @throws EE_Error
2007
+	 * @throws InvalidArgumentException
2008
+	 * @throws InvalidDataTypeException
2009
+	 * @throws InvalidInterfaceException
2010
+	 */
2011
+	protected function _reset_to_default_template()
2012
+	{
2013
+        
2014
+		$templates = array();
2015
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2016
+		//we need to make sure we've got the info we need.
2017
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2018
+			EE_Error::add_error(
2019
+				esc_html__(
2020
+					'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.',
2021
+					'event_espresso'
2022
+				),
2023
+				__FILE__, __FUNCTION__, __LINE__
2024
+			);
2025
+		}
2026
+        
2027
+		// all templates will be reset to whatever the defaults are
2028
+		// for the global template matching the messenger and message type.
2029
+		$success = ! empty($GRP_ID) ? true : false;
2030
+        
2031
+		if ($success) {
2032 2032
             
2033
-            //let's first determine if the incoming template is a global template,
2034
-            // if it isn't then we need to get the global template matching messenger and message type.
2035
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2033
+			//let's first determine if the incoming template is a global template,
2034
+			// if it isn't then we need to get the global template matching messenger and message type.
2035
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2036 2036
             
2037 2037
             
2038
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2039
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2038
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2039
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2040 2040
             
2041
-            if ($success) {
2042
-                // if successfully deleted, lets generate the new ones.
2043
-                // Note. We set GLOBAL to true, because resets on ANY template
2044
-                // will use the related global template defaults for regeneration.
2045
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2046
-                // HOWEVER, we DO keep the template pack and template variation set
2047
-                // for the current custom template when resetting.
2048
-                $templates = $this->_generate_new_templates(
2049
-                    $this->_req_data['msgr'],
2050
-                    $this->_req_data['mt'],
2051
-                    $GRP_ID,
2052
-                    true
2053
-                );
2054
-            }
2041
+			if ($success) {
2042
+				// if successfully deleted, lets generate the new ones.
2043
+				// Note. We set GLOBAL to true, because resets on ANY template
2044
+				// will use the related global template defaults for regeneration.
2045
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2046
+				// HOWEVER, we DO keep the template pack and template variation set
2047
+				// for the current custom template when resetting.
2048
+				$templates = $this->_generate_new_templates(
2049
+					$this->_req_data['msgr'],
2050
+					$this->_req_data['mt'],
2051
+					$GRP_ID,
2052
+					true
2053
+				);
2054
+			}
2055 2055
             
2056
-        }
2057
-        
2058
-        //any error messages?
2059
-        if ( ! $success) {
2060
-            EE_Error::add_error(
2061
-                esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2062
-                    'event_espresso'),
2063
-                __FILE__, __FUNCTION__, __LINE__
2064
-            );
2065
-        }
2066
-        
2067
-        //all good, let's add a success message!
2068
-        if ($success && ! empty($templates)) {
2069
-            //the info for the template we generated is the first element in the returned array
2070
-            // $templates = $templates[0];
2071
-            EE_Error::overwrite_success();
2072
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2073
-        }
2074
-        
2075
-        
2076
-        $query_args = array(
2077
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2078
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2079
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2080
-        );
2081
-        
2082
-        //if called via ajax then we return query args otherwise redirect
2083
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2084
-            return $query_args;
2085
-        } else {
2086
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2056
+		}
2057
+        
2058
+		//any error messages?
2059
+		if ( ! $success) {
2060
+			EE_Error::add_error(
2061
+				esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2062
+					'event_espresso'),
2063
+				__FILE__, __FUNCTION__, __LINE__
2064
+			);
2065
+		}
2066
+        
2067
+		//all good, let's add a success message!
2068
+		if ($success && ! empty($templates)) {
2069
+			//the info for the template we generated is the first element in the returned array
2070
+			// $templates = $templates[0];
2071
+			EE_Error::overwrite_success();
2072
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2073
+		}
2074
+        
2075
+        
2076
+		$query_args = array(
2077
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2078
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2079
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2080
+		);
2081
+        
2082
+		//if called via ajax then we return query args otherwise redirect
2083
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2084
+			return $query_args;
2085
+		} else {
2086
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2087 2087
 
2088
-            return null;
2089
-        }
2090
-    }
2088
+			return null;
2089
+		}
2090
+	}
2091 2091
 
2092 2092
 
2093
-    /**
2094
-     * Retrieve and set the message preview for display.
2095
-     *
2096
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2097
-     * @return string
2098
-     * @throws ReflectionException
2099
-     * @throws EE_Error
2100
-     * @throws InvalidArgumentException
2101
-     * @throws InvalidDataTypeException
2102
-     * @throws InvalidInterfaceException
2103
-     */
2104
-    public function _preview_message($send = false)
2105
-    {
2106
-        //first make sure we've got the necessary parameters
2107
-        if (
2108
-        ! isset(
2109
-            $this->_req_data['message_type'],
2110
-            $this->_req_data['messenger'],
2111
-            $this->_req_data['messenger'],
2112
-            $this->_req_data['GRP_ID']
2113
-        )
2114
-        ) {
2115
-            EE_Error::add_error(
2116
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2117
-                __FILE__, __FUNCTION__, __LINE__
2118
-            );
2119
-        }
2120
-        
2121
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2122
-        
2123
-        
2124
-        //get the preview!
2125
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2126
-            $this->_req_data['messenger'], $send);
2127
-        
2128
-        if ($send) {
2129
-            return $preview;
2130
-        }
2131
-        
2132
-        //let's add a button to go back to the edit view
2133
-        $query_args             = array(
2134
-            'id'      => $this->_req_data['GRP_ID'],
2135
-            'context' => $this->_req_data['context'],
2136
-            'action'  => 'edit_message_template'
2137
-        );
2138
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2139
-        $preview_button         = '<a href="'
2140
-                                  . $go_back_url
2141
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2142
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2143
-                                  . '</a>';
2144
-        $message_types          = $this->get_installed_message_types();
2145
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger(
2146
-                $this->_req_data['messenger']
2147
-        );
2148
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2149
-            ? ucwords($active_messenger->label['singular'])
2150
-            : esc_html__('Unknown Messenger', 'event_espresso');
2151
-        //let's provide a helpful title for context
2152
-        $preview_title = sprintf(
2153
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2154
-            $active_messenger_label,
2155
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2156
-        );
2157
-        //setup display of preview.
2158
-        $this->_admin_page_title                    = $preview_title;
2159
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2160
-        $this->_template_args['data']['force_json'] = true;
2161
-        
2162
-        return '';
2163
-    }
2093
+	/**
2094
+	 * Retrieve and set the message preview for display.
2095
+	 *
2096
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2097
+	 * @return string
2098
+	 * @throws ReflectionException
2099
+	 * @throws EE_Error
2100
+	 * @throws InvalidArgumentException
2101
+	 * @throws InvalidDataTypeException
2102
+	 * @throws InvalidInterfaceException
2103
+	 */
2104
+	public function _preview_message($send = false)
2105
+	{
2106
+		//first make sure we've got the necessary parameters
2107
+		if (
2108
+		! isset(
2109
+			$this->_req_data['message_type'],
2110
+			$this->_req_data['messenger'],
2111
+			$this->_req_data['messenger'],
2112
+			$this->_req_data['GRP_ID']
2113
+		)
2114
+		) {
2115
+			EE_Error::add_error(
2116
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2117
+				__FILE__, __FUNCTION__, __LINE__
2118
+			);
2119
+		}
2120
+        
2121
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2122
+        
2123
+        
2124
+		//get the preview!
2125
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2126
+			$this->_req_data['messenger'], $send);
2127
+        
2128
+		if ($send) {
2129
+			return $preview;
2130
+		}
2131
+        
2132
+		//let's add a button to go back to the edit view
2133
+		$query_args             = array(
2134
+			'id'      => $this->_req_data['GRP_ID'],
2135
+			'context' => $this->_req_data['context'],
2136
+			'action'  => 'edit_message_template'
2137
+		);
2138
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2139
+		$preview_button         = '<a href="'
2140
+								  . $go_back_url
2141
+								  . '" class="button-secondary messages-preview-go-back-button">'
2142
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2143
+								  . '</a>';
2144
+		$message_types          = $this->get_installed_message_types();
2145
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger(
2146
+				$this->_req_data['messenger']
2147
+		);
2148
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2149
+			? ucwords($active_messenger->label['singular'])
2150
+			: esc_html__('Unknown Messenger', 'event_espresso');
2151
+		//let's provide a helpful title for context
2152
+		$preview_title = sprintf(
2153
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2154
+			$active_messenger_label,
2155
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2156
+		);
2157
+		//setup display of preview.
2158
+		$this->_admin_page_title                    = $preview_title;
2159
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2160
+		$this->_template_args['data']['force_json'] = true;
2161
+        
2162
+		return '';
2163
+	}
2164 2164
     
2165 2165
     
2166
-    /**
2167
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2168
-     * gets called automatically.
2169
-     *
2170
-     * @since 4.5.0
2171
-     *
2172
-     * @return string
2173
-     */
2174
-    protected function _display_preview_message()
2175
-    {
2176
-        $this->display_admin_page_with_no_sidebar();
2177
-    }
2166
+	/**
2167
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2168
+	 * gets called automatically.
2169
+	 *
2170
+	 * @since 4.5.0
2171
+	 *
2172
+	 * @return string
2173
+	 */
2174
+	protected function _display_preview_message()
2175
+	{
2176
+		$this->display_admin_page_with_no_sidebar();
2177
+	}
2178 2178
     
2179 2179
     
2180
-    /**
2181
-     * registers metaboxes that should show up on the "edit_message_template" page
2182
-     *
2183
-     * @access protected
2184
-     * @return void
2185
-     */
2186
-    protected function _register_edit_meta_boxes()
2187
-    {
2188
-        add_meta_box(
2189
-            'mtp_valid_shortcodes',
2190
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2191
-            array($this, 'shortcode_meta_box'),
2192
-            $this->_current_screen->id,
2193
-            'side',
2194
-            'default');
2195
-        add_meta_box(
2196
-            'mtp_extra_actions',
2197
-            esc_html__('Extra Actions', 'event_espresso'),
2198
-            array($this, 'extra_actions_meta_box'),
2199
-            $this->_current_screen->id,
2200
-            'side',
2201
-            'high'
2202
-        );
2203
-        add_meta_box(
2204
-            'mtp_templates',
2205
-            esc_html__('Template Styles', 'event_espresso'),
2206
-            array($this, 'template_pack_meta_box'),
2207
-            $this->_current_screen->id,
2208
-            'side',
2209
-            'high'
2210
-        );
2211
-    }
2180
+	/**
2181
+	 * registers metaboxes that should show up on the "edit_message_template" page
2182
+	 *
2183
+	 * @access protected
2184
+	 * @return void
2185
+	 */
2186
+	protected function _register_edit_meta_boxes()
2187
+	{
2188
+		add_meta_box(
2189
+			'mtp_valid_shortcodes',
2190
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2191
+			array($this, 'shortcode_meta_box'),
2192
+			$this->_current_screen->id,
2193
+			'side',
2194
+			'default');
2195
+		add_meta_box(
2196
+			'mtp_extra_actions',
2197
+			esc_html__('Extra Actions', 'event_espresso'),
2198
+			array($this, 'extra_actions_meta_box'),
2199
+			$this->_current_screen->id,
2200
+			'side',
2201
+			'high'
2202
+		);
2203
+		add_meta_box(
2204
+			'mtp_templates',
2205
+			esc_html__('Template Styles', 'event_espresso'),
2206
+			array($this, 'template_pack_meta_box'),
2207
+			$this->_current_screen->id,
2208
+			'side',
2209
+			'high'
2210
+		);
2211
+	}
2212 2212
 
2213 2213
 
2214
-    /**
2215
-     * metabox content for all template pack and variation selection.
2216
-     *
2217
-     * @since 4.5.0
2218
-     * @return string
2219
-     * @throws DomainException
2220
-     * @throws EE_Error
2221
-     * @throws InvalidArgumentException
2222
-     * @throws ReflectionException
2223
-     * @throws InvalidDataTypeException
2224
-     * @throws InvalidInterfaceException
2225
-     */
2226
-    public function template_pack_meta_box()
2227
-    {
2228
-        $this->_set_message_template_group();
2229
-        
2230
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2231
-        
2232
-        $tp_select_values = array();
2233
-        
2234
-        foreach ($tp_collection as $tp) {
2235
-            //only include template packs that support this messenger and message type!
2236
-            $supports = $tp->get_supports();
2237
-            if (
2238
-                ! isset($supports[$this->_message_template_group->messenger()])
2239
-                || ! in_array(
2240
-                    $this->_message_template_group->message_type(),
2241
-                    $supports[$this->_message_template_group->messenger()],
2242
-                    true
2243
-                )
2244
-            ) {
2245
-                //not supported
2246
-                continue;
2247
-            }
2214
+	/**
2215
+	 * metabox content for all template pack and variation selection.
2216
+	 *
2217
+	 * @since 4.5.0
2218
+	 * @return string
2219
+	 * @throws DomainException
2220
+	 * @throws EE_Error
2221
+	 * @throws InvalidArgumentException
2222
+	 * @throws ReflectionException
2223
+	 * @throws InvalidDataTypeException
2224
+	 * @throws InvalidInterfaceException
2225
+	 */
2226
+	public function template_pack_meta_box()
2227
+	{
2228
+		$this->_set_message_template_group();
2229
+        
2230
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2231
+        
2232
+		$tp_select_values = array();
2233
+        
2234
+		foreach ($tp_collection as $tp) {
2235
+			//only include template packs that support this messenger and message type!
2236
+			$supports = $tp->get_supports();
2237
+			if (
2238
+				! isset($supports[$this->_message_template_group->messenger()])
2239
+				|| ! in_array(
2240
+					$this->_message_template_group->message_type(),
2241
+					$supports[$this->_message_template_group->messenger()],
2242
+					true
2243
+				)
2244
+			) {
2245
+				//not supported
2246
+				continue;
2247
+			}
2248 2248
             
2249
-            $tp_select_values[] = array(
2250
-                'text' => $tp->label,
2251
-                'id'   => $tp->dbref
2252
-            );
2253
-        }
2254
-        
2255
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2256
-        // the default template pack.  This still allows for the odd template pack to override.
2257
-        if (empty($tp_select_values)) {
2258
-            $tp_select_values[] = array(
2259
-                'text' => esc_html__('Default', 'event_espresso'),
2260
-                'id'   => 'default'
2261
-            );
2262
-        }
2263
-        
2264
-        //setup variation select values for the currently selected template.
2265
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2266
-            $this->_message_template_group->messenger(),
2267
-            $this->_message_template_group->message_type()
2268
-        );
2269
-        $variations_select_values = array();
2270
-        foreach ($variations as $variation => $label) {
2271
-            $variations_select_values[] = array(
2272
-                'text' => $label,
2273
-                'id'   => $variation
2274
-            );
2275
-        }
2276
-        
2277
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2278
-        
2279
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2280
-            'MTP_template_pack',
2281
-            $tp_select_values,
2282
-            $this->_message_template_group->get_template_pack_name()
2283
-        );
2284
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2285
-            'MTP_template_variation',
2286
-            $variations_select_values,
2287
-            $this->_message_template_group->get_template_pack_variation()
2288
-        );
2289
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2290
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2291
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2292
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2293
-        
2294
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2295
-        
2296
-        EEH_Template::display_template($template, $template_args);
2297
-    }
2249
+			$tp_select_values[] = array(
2250
+				'text' => $tp->label,
2251
+				'id'   => $tp->dbref
2252
+			);
2253
+		}
2254
+        
2255
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2256
+		// the default template pack.  This still allows for the odd template pack to override.
2257
+		if (empty($tp_select_values)) {
2258
+			$tp_select_values[] = array(
2259
+				'text' => esc_html__('Default', 'event_espresso'),
2260
+				'id'   => 'default'
2261
+			);
2262
+		}
2263
+        
2264
+		//setup variation select values for the currently selected template.
2265
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2266
+			$this->_message_template_group->messenger(),
2267
+			$this->_message_template_group->message_type()
2268
+		);
2269
+		$variations_select_values = array();
2270
+		foreach ($variations as $variation => $label) {
2271
+			$variations_select_values[] = array(
2272
+				'text' => $label,
2273
+				'id'   => $variation
2274
+			);
2275
+		}
2276
+        
2277
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2278
+        
2279
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2280
+			'MTP_template_pack',
2281
+			$tp_select_values,
2282
+			$this->_message_template_group->get_template_pack_name()
2283
+		);
2284
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2285
+			'MTP_template_variation',
2286
+			$variations_select_values,
2287
+			$this->_message_template_group->get_template_pack_variation()
2288
+		);
2289
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2290
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2291
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2292
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2293
+        
2294
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2295
+        
2296
+		EEH_Template::display_template($template, $template_args);
2297
+	}
2298 2298
     
2299 2299
     
2300
-    /**
2301
-     * This meta box holds any extra actions related to Message Templates
2302
-     * For now, this includes Resetting templates to defaults and sending a test email.
2303
-     *
2304
-     * @access  public
2305
-     * @return void
2306
-     * @throws EE_Error
2307
-     */
2308
-    public function extra_actions_meta_box()
2309
-    {
2310
-        $template_form_fields = array();
2311
-        
2312
-        $extra_args = array(
2313
-            'msgr'   => $this->_message_template_group->messenger(),
2314
-            'mt'     => $this->_message_template_group->message_type(),
2315
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2316
-        );
2317
-        //first we need to see if there are any fields
2318
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2319
-        
2320
-        if ( ! empty($fields)) {
2321
-            //yup there be fields
2322
-            foreach ($fields as $field => $config) {
2323
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2324
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2325
-                $default  = isset($config['default']) ? $config['default'] : '';
2326
-                $default  = isset($config['value']) ? $config['value'] : $default;
2300
+	/**
2301
+	 * This meta box holds any extra actions related to Message Templates
2302
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2303
+	 *
2304
+	 * @access  public
2305
+	 * @return void
2306
+	 * @throws EE_Error
2307
+	 */
2308
+	public function extra_actions_meta_box()
2309
+	{
2310
+		$template_form_fields = array();
2311
+        
2312
+		$extra_args = array(
2313
+			'msgr'   => $this->_message_template_group->messenger(),
2314
+			'mt'     => $this->_message_template_group->message_type(),
2315
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2316
+		);
2317
+		//first we need to see if there are any fields
2318
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2319
+        
2320
+		if ( ! empty($fields)) {
2321
+			//yup there be fields
2322
+			foreach ($fields as $field => $config) {
2323
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2324
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2325
+				$default  = isset($config['default']) ? $config['default'] : '';
2326
+				$default  = isset($config['value']) ? $config['value'] : $default;
2327 2327
                 
2328
-                // if type is hidden and the value is empty
2329
-                // something may have gone wrong so let's correct with the defaults
2330
-                $fix              = $config['input'] === 'hidden'
2331
-                                    && isset($existing[$field])
2332
-                                    && empty($existing[$field])
2333
-                    ? $default
2334
-                    : '';
2335
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2336
-                    ? $existing[$field]
2337
-                    : $fix;
2328
+				// if type is hidden and the value is empty
2329
+				// something may have gone wrong so let's correct with the defaults
2330
+				$fix              = $config['input'] === 'hidden'
2331
+									&& isset($existing[$field])
2332
+									&& empty($existing[$field])
2333
+					? $default
2334
+					: '';
2335
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2336
+					? $existing[$field]
2337
+					: $fix;
2338 2338
                 
2339
-                $template_form_fields[$field_id] = array(
2340
-                    'name'       => 'test_settings_fld[' . $field . ']',
2341
-                    'label'      => $config['label'],
2342
-                    'input'      => $config['input'],
2343
-                    'type'       => $config['type'],
2344
-                    'required'   => $config['required'],
2345
-                    'validation' => $config['validation'],
2346
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2347
-                    'css_class'  => $config['css_class'],
2348
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2349
-                    'default'    => $default,
2350
-                    'format'     => $config['format']
2351
-                );
2352
-            }
2353
-        }
2354
-        
2355
-        $test_settings_fields = ! empty($template_form_fields)
2356
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2357
-            : '';
2358
-        
2359
-        $test_settings_html = '';
2360
-        //print out $test_settings_fields
2361
-        if ( ! empty($test_settings_fields)) {
2362
-            echo $test_settings_fields;
2363
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2364
-            $test_settings_html .= 'name="test_button" value="';
2365
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2366
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2367
-        }
2368
-        
2369
-        //and button
2370
-        $test_settings_html .= '<p>'
2371
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2372
-                               . '</p>';
2373
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2374
-        $test_settings_html .= $this->get_action_link_or_button(
2375
-            'reset_to_default',
2376
-            'reset',
2377
-            $extra_args,
2378
-            'button-primary reset-default-button'
2379
-        );
2380
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2381
-        echo $test_settings_html;
2382
-    }
2339
+				$template_form_fields[$field_id] = array(
2340
+					'name'       => 'test_settings_fld[' . $field . ']',
2341
+					'label'      => $config['label'],
2342
+					'input'      => $config['input'],
2343
+					'type'       => $config['type'],
2344
+					'required'   => $config['required'],
2345
+					'validation' => $config['validation'],
2346
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2347
+					'css_class'  => $config['css_class'],
2348
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2349
+					'default'    => $default,
2350
+					'format'     => $config['format']
2351
+				);
2352
+			}
2353
+		}
2354
+        
2355
+		$test_settings_fields = ! empty($template_form_fields)
2356
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2357
+			: '';
2358
+        
2359
+		$test_settings_html = '';
2360
+		//print out $test_settings_fields
2361
+		if ( ! empty($test_settings_fields)) {
2362
+			echo $test_settings_fields;
2363
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2364
+			$test_settings_html .= 'name="test_button" value="';
2365
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2366
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2367
+		}
2368
+        
2369
+		//and button
2370
+		$test_settings_html .= '<p>'
2371
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2372
+							   . '</p>';
2373
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2374
+		$test_settings_html .= $this->get_action_link_or_button(
2375
+			'reset_to_default',
2376
+			'reset',
2377
+			$extra_args,
2378
+			'button-primary reset-default-button'
2379
+		);
2380
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2381
+		echo $test_settings_html;
2382
+	}
2383 2383
 
2384 2384
 
2385
-    /**
2386
-     * This returns the shortcode selector skeleton for a given context and field.
2387
-     *
2388
-     * @since 4.9.rc.000
2389
-     * @param string $field           The name of the field retrieving shortcodes for.
2390
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2391
-     * @return string
2392
-     * @throws DomainException
2393
-     * @throws EE_Error
2394
-     * @throws InvalidArgumentException
2395
-     * @throws ReflectionException
2396
-     * @throws InvalidDataTypeException
2397
-     * @throws InvalidInterfaceException
2398
-     */
2399
-    protected function _get_shortcode_selector($field, $linked_input_id)
2400
-    {
2401
-        $template_args = array(
2402
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2403
-            'fieldname'       => $field,
2404
-            'linked_input_id' => $linked_input_id
2405
-        );
2406
-        
2407
-        return EEH_Template::display_template(
2408
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2409
-            $template_args,
2410
-            true
2411
-        );
2412
-    }
2385
+	/**
2386
+	 * This returns the shortcode selector skeleton for a given context and field.
2387
+	 *
2388
+	 * @since 4.9.rc.000
2389
+	 * @param string $field           The name of the field retrieving shortcodes for.
2390
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2391
+	 * @return string
2392
+	 * @throws DomainException
2393
+	 * @throws EE_Error
2394
+	 * @throws InvalidArgumentException
2395
+	 * @throws ReflectionException
2396
+	 * @throws InvalidDataTypeException
2397
+	 * @throws InvalidInterfaceException
2398
+	 */
2399
+	protected function _get_shortcode_selector($field, $linked_input_id)
2400
+	{
2401
+		$template_args = array(
2402
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2403
+			'fieldname'       => $field,
2404
+			'linked_input_id' => $linked_input_id
2405
+		);
2406
+        
2407
+		return EEH_Template::display_template(
2408
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2409
+			$template_args,
2410
+			true
2411
+		);
2412
+	}
2413 2413
 
2414 2414
 
2415
-    /**
2416
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2417
-     * page)
2418
-     *
2419
-     * @access public
2420
-     * @return void
2421
-     * @throws EE_Error
2422
-     * @throws InvalidArgumentException
2423
-     * @throws ReflectionException
2424
-     * @throws InvalidDataTypeException
2425
-     * @throws InvalidInterfaceException
2426
-     */
2427
-    public function shortcode_meta_box()
2428
-    {
2429
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2430
-        //$messenger = $this->_message_template_group->messenger_obj();
2431
-        //now let's set the content depending on the status of the shortcodes array
2432
-        if (empty($shortcodes)) {
2433
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2434
-            echo $content;
2435
-        } else {
2436
-            //$alt = 0;
2437
-            ?>
2415
+	/**
2416
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2417
+	 * page)
2418
+	 *
2419
+	 * @access public
2420
+	 * @return void
2421
+	 * @throws EE_Error
2422
+	 * @throws InvalidArgumentException
2423
+	 * @throws ReflectionException
2424
+	 * @throws InvalidDataTypeException
2425
+	 * @throws InvalidInterfaceException
2426
+	 */
2427
+	public function shortcode_meta_box()
2428
+	{
2429
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2430
+		//$messenger = $this->_message_template_group->messenger_obj();
2431
+		//now let's set the content depending on the status of the shortcodes array
2432
+		if (empty($shortcodes)) {
2433
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2434
+			echo $content;
2435
+		} else {
2436
+			//$alt = 0;
2437
+			?>
2438 2438
             <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2439 2439
             <p class="small-text"><?php printf(
2440
-                    esc_html__(
2441
-                        'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2442
-                        'event_espresso'
2443
-                    ),
2444
-                    '<span class="dashicons dashicons-menu"></span>'
2445
-                ); ?></p>
2440
+					esc_html__(
2441
+						'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2442
+						'event_espresso'
2443
+					),
2444
+					'<span class="dashicons dashicons-menu"></span>'
2445
+				); ?></p>
2446 2446
             <?php
2447
-        }
2447
+		}
2448 2448
         
2449 2449
         
2450
-    }
2450
+	}
2451 2451
 
2452 2452
 
2453
-    /**
2454
-     * used to set the $_shortcodes property for when its needed elsewhere.
2455
-     *
2456
-     * @access protected
2457
-     * @return void
2458
-     * @throws EE_Error
2459
-     * @throws InvalidArgumentException
2460
-     * @throws ReflectionException
2461
-     * @throws InvalidDataTypeException
2462
-     * @throws InvalidInterfaceException
2463
-     */
2464
-    protected function _set_shortcodes()
2465
-    {
2466
-        
2467
-        //no need to run this if the property is already set
2468
-        if ( ! empty($this->_shortcodes)) {
2469
-            return;
2470
-        }
2471
-        
2472
-        $this->_shortcodes = $this->_get_shortcodes();
2473
-    }
2453
+	/**
2454
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2455
+	 *
2456
+	 * @access protected
2457
+	 * @return void
2458
+	 * @throws EE_Error
2459
+	 * @throws InvalidArgumentException
2460
+	 * @throws ReflectionException
2461
+	 * @throws InvalidDataTypeException
2462
+	 * @throws InvalidInterfaceException
2463
+	 */
2464
+	protected function _set_shortcodes()
2465
+	{
2466
+        
2467
+		//no need to run this if the property is already set
2468
+		if ( ! empty($this->_shortcodes)) {
2469
+			return;
2470
+		}
2471
+        
2472
+		$this->_shortcodes = $this->_get_shortcodes();
2473
+	}
2474 2474
 
2475 2475
 
2476
-    /**
2477
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2478
-     * property)
2479
-     *
2480
-     * @access  protected
2481
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2482
-     *                         for. Defaults to all (for the given context)
2483
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2484
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2485
-     *                         true just an array of shortcode/label pairs.
2486
-     * @throws EE_Error
2487
-     * @throws InvalidArgumentException
2488
-     * @throws ReflectionException
2489
-     * @throws InvalidDataTypeException
2490
-     * @throws InvalidInterfaceException
2491
-     */
2492
-    protected function _get_shortcodes($fields = array(), $merged = true)
2493
-    {
2494
-        $this->_set_message_template_group();
2495
-        
2496
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2497
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2498
-            ? absint($this->_req_data['id'])
2499
-            : false;
2500
-        $context = isset($this->_req_data['context'])
2501
-            ? $this->_req_data['context']
2502
-            : key($this->_message_template_group->contexts_config());
2503
-        
2504
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2505
-    }
2476
+	/**
2477
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2478
+	 * property)
2479
+	 *
2480
+	 * @access  protected
2481
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2482
+	 *                         for. Defaults to all (for the given context)
2483
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2484
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2485
+	 *                         true just an array of shortcode/label pairs.
2486
+	 * @throws EE_Error
2487
+	 * @throws InvalidArgumentException
2488
+	 * @throws ReflectionException
2489
+	 * @throws InvalidDataTypeException
2490
+	 * @throws InvalidInterfaceException
2491
+	 */
2492
+	protected function _get_shortcodes($fields = array(), $merged = true)
2493
+	{
2494
+		$this->_set_message_template_group();
2495
+        
2496
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2497
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2498
+			? absint($this->_req_data['id'])
2499
+			: false;
2500
+		$context = isset($this->_req_data['context'])
2501
+			? $this->_req_data['context']
2502
+			: key($this->_message_template_group->contexts_config());
2503
+        
2504
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2505
+	}
2506 2506
 
2507 2507
 
2508
-    /**
2509
-     * This sets the _message_template property (containing the called message_template object)
2510
-     *
2511
-     * @access protected
2512
-     * @return void
2513
-     * @throws EE_Error
2514
-     * @throws InvalidArgumentException
2515
-     * @throws ReflectionException
2516
-     * @throws InvalidDataTypeException
2517
-     * @throws InvalidInterfaceException
2518
-     */
2519
-    protected function _set_message_template_group()
2520
-    {
2521
-        
2522
-        if ( ! empty($this->_message_template_group)) {
2523
-            return;
2524
-        } //get out if this is already set.
2525
-        
2526
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2527
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2528
-        
2529
-        //let's get the message templates
2530
-        $MTP = EEM_Message_Template_Group::instance();
2531
-        
2532
-        if (empty($GRP_ID)) {
2533
-            $this->_message_template_group = $MTP->create_default_object();
2534
-        } else {
2535
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2536
-        }
2537
-        
2538
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2539
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2540
-        
2541
-    }
2508
+	/**
2509
+	 * This sets the _message_template property (containing the called message_template object)
2510
+	 *
2511
+	 * @access protected
2512
+	 * @return void
2513
+	 * @throws EE_Error
2514
+	 * @throws InvalidArgumentException
2515
+	 * @throws ReflectionException
2516
+	 * @throws InvalidDataTypeException
2517
+	 * @throws InvalidInterfaceException
2518
+	 */
2519
+	protected function _set_message_template_group()
2520
+	{
2521
+        
2522
+		if ( ! empty($this->_message_template_group)) {
2523
+			return;
2524
+		} //get out if this is already set.
2525
+        
2526
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2527
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2528
+        
2529
+		//let's get the message templates
2530
+		$MTP = EEM_Message_Template_Group::instance();
2531
+        
2532
+		if (empty($GRP_ID)) {
2533
+			$this->_message_template_group = $MTP->create_default_object();
2534
+		} else {
2535
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2536
+		}
2537
+        
2538
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2539
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2540
+        
2541
+	}
2542 2542
 
2543 2543
 
2544
-    /**
2545
-     * sets up a context switcher for edit forms
2546
-     *
2547
-     * @access  protected
2548
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2549
-     * @param array                      $args                  various things the context switcher needs.
2550
-     * @throws EE_Error
2551
-     */
2552
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2553
-    {
2554
-        $context_details = $template_group_object->contexts_config();
2555
-        $context_label   = $template_group_object->context_label();
2556
-        ob_start();
2557
-        ?>
2544
+	/**
2545
+	 * sets up a context switcher for edit forms
2546
+	 *
2547
+	 * @access  protected
2548
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2549
+	 * @param array                      $args                  various things the context switcher needs.
2550
+	 * @throws EE_Error
2551
+	 */
2552
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2553
+	{
2554
+		$context_details = $template_group_object->contexts_config();
2555
+		$context_label   = $template_group_object->context_label();
2556
+		ob_start();
2557
+		?>
2558 2558
         <div class="ee-msg-switcher-container">
2559 2559
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2560 2560
                 <?php
2561
-                foreach ($args as $name => $value) {
2562
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2563
-                        continue;
2564
-                    }
2565
-                    ?>
2561
+				foreach ($args as $name => $value) {
2562
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2563
+						continue;
2564
+					}
2565
+					?>
2566 2566
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2567 2567
                     <?php
2568
-                }
2569
-                //setup nonce_url
2570
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2571
-                ?>
2568
+				}
2569
+				//setup nonce_url
2570
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2571
+				?>
2572 2572
                 <select name="context">
2573 2573
                     <?php
2574
-                    $context_templates = $template_group_object->context_templates();
2575
-                    if (is_array($context_templates)) :
2576
-                        foreach ($context_templates as $context => $template_fields) :
2577
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2578
-                            ?>
2574
+					$context_templates = $template_group_object->context_templates();
2575
+					if (is_array($context_templates)) :
2576
+						foreach ($context_templates as $context => $template_fields) :
2577
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2578
+							?>
2579 2579
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2580 2580
                                 <?php echo $context_details[$context]['label']; ?>
2581 2581
                             </option>
@@ -2588,1838 +2588,1838 @@  discard block
 block discarded – undo
2588 2588
             <?php echo $args['extra']; ?>
2589 2589
         </div> <!-- end .ee-msg-switcher-container -->
2590 2590
         <?php
2591
-        $output = ob_get_contents();
2592
-        ob_clean();
2593
-        $this->_context_switcher = $output;
2594
-    }
2591
+		$output = ob_get_contents();
2592
+		ob_clean();
2593
+		$this->_context_switcher = $output;
2594
+	}
2595 2595
     
2596 2596
     
2597
-    /**
2598
-     * utility for sanitizing new values coming in.
2599
-     * Note: this is only used when updating a context.
2600
-     *
2601
-     * @access protected
2602
-     *
2603
-     * @param int $index This helps us know which template field to select from the request array.
2604
-     *
2605
-     * @return array
2606
-     */
2607
-    protected function _set_message_template_column_values($index)
2608
-    {
2609
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2610
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2611
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2612
-            }
2613
-        }
2614
-        
2615
-        
2616
-        $set_column_values = array(
2617
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2618
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2619
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2620
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2621
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2622
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2623
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2624
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2625
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2626
-                ? absint($this->_req_data['MTP_is_global'])
2627
-                : 0,
2628
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2629
-                ? absint($this->_req_data['MTP_is_override'])
2630
-                : 0,
2631
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2632
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2633
-        );
2634
-        
2635
-        
2636
-        return $set_column_values;
2637
-    }
2597
+	/**
2598
+	 * utility for sanitizing new values coming in.
2599
+	 * Note: this is only used when updating a context.
2600
+	 *
2601
+	 * @access protected
2602
+	 *
2603
+	 * @param int $index This helps us know which template field to select from the request array.
2604
+	 *
2605
+	 * @return array
2606
+	 */
2607
+	protected function _set_message_template_column_values($index)
2608
+	{
2609
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2610
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2611
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2612
+			}
2613
+		}
2614
+        
2615
+        
2616
+		$set_column_values = array(
2617
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2618
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2619
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2620
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2621
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2622
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2623
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2624
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2625
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2626
+				? absint($this->_req_data['MTP_is_global'])
2627
+				: 0,
2628
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2629
+				? absint($this->_req_data['MTP_is_override'])
2630
+				: 0,
2631
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2632
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2633
+		);
2634
+        
2635
+        
2636
+		return $set_column_values;
2637
+	}
2638 2638
     
2639 2639
     
2640
-    protected function _insert_or_update_message_template($new = false)
2641
-    {
2642
-        
2643
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2644
-        $success  = 0;
2645
-        $override = false;
2646
-        
2647
-        //setup notices description
2648
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2649
-        
2650
-        //need the message type and messenger objects to be able to use the labels for the notices
2651
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2652
-        $messenger_label  = $messenger_object instanceof EE_messenger
2653
-            ? ucwords($messenger_object->label['singular'])
2654
-            : '';
2655
-        
2656
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2657
-            ? $this->_req_data['MTP_message_type']
2658
-            : '';
2659
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2660
-        
2661
-        $message_type_label = $message_type_object instanceof EE_message_type
2662
-            ? ucwords($message_type_object->label['singular'])
2663
-            : '';
2664
-        
2665
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2666
-            ? $this->_req_data['MTP_context']
2667
-            : '';
2668
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2669
-        
2670
-        $item_desc = $messenger_label && $message_type_label
2671
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2672
-            : '';
2673
-        $item_desc .= 'Message Template';
2674
-        $query_args  = array();
2675
-        $edit_array  = array();
2676
-        $action_desc = '';
2677
-        
2678
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2679
-        // user to edit.
2680
-        if ($new) {
2681
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2682
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2683
-                if (empty($edit_array)) {
2684
-                    $success = 0;
2685
-                } else {
2686
-                    $success    = 1;
2687
-                    $edit_array = $edit_array[0];
2688
-                    $query_args = array(
2689
-                        'id'      => $edit_array['GRP_ID'],
2690
-                        'context' => $edit_array['MTP_context'],
2691
-                        'action'  => 'edit_message_template'
2692
-                    );
2693
-                }
2694
-            }
2695
-            $action_desc = 'created';
2696
-        } else {
2697
-            $MTPG = EEM_Message_Template_Group::instance();
2698
-            $MTP  = EEM_Message_Template::instance();
2640
+	protected function _insert_or_update_message_template($new = false)
2641
+	{
2642
+        
2643
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2644
+		$success  = 0;
2645
+		$override = false;
2646
+        
2647
+		//setup notices description
2648
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2649
+        
2650
+		//need the message type and messenger objects to be able to use the labels for the notices
2651
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2652
+		$messenger_label  = $messenger_object instanceof EE_messenger
2653
+			? ucwords($messenger_object->label['singular'])
2654
+			: '';
2655
+        
2656
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2657
+			? $this->_req_data['MTP_message_type']
2658
+			: '';
2659
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2660
+        
2661
+		$message_type_label = $message_type_object instanceof EE_message_type
2662
+			? ucwords($message_type_object->label['singular'])
2663
+			: '';
2664
+        
2665
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2666
+			? $this->_req_data['MTP_context']
2667
+			: '';
2668
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2669
+        
2670
+		$item_desc = $messenger_label && $message_type_label
2671
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2672
+			: '';
2673
+		$item_desc .= 'Message Template';
2674
+		$query_args  = array();
2675
+		$edit_array  = array();
2676
+		$action_desc = '';
2677
+        
2678
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2679
+		// user to edit.
2680
+		if ($new) {
2681
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2682
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2683
+				if (empty($edit_array)) {
2684
+					$success = 0;
2685
+				} else {
2686
+					$success    = 1;
2687
+					$edit_array = $edit_array[0];
2688
+					$query_args = array(
2689
+						'id'      => $edit_array['GRP_ID'],
2690
+						'context' => $edit_array['MTP_context'],
2691
+						'action'  => 'edit_message_template'
2692
+					);
2693
+				}
2694
+			}
2695
+			$action_desc = 'created';
2696
+		} else {
2697
+			$MTPG = EEM_Message_Template_Group::instance();
2698
+			$MTP  = EEM_Message_Template::instance();
2699 2699
             
2700 2700
             
2701
-            //run update for each template field in displayed context
2702
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2703
-                EE_Error::add_error(
2704
-                    esc_html__(
2705
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2706
-                        'event_espresso'
2707
-                    ),
2708
-                    __FILE__,
2709
-                    __FUNCTION__,
2710
-                    __LINE__
2711
-                );
2712
-                $success = 0;
2701
+			//run update for each template field in displayed context
2702
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2703
+				EE_Error::add_error(
2704
+					esc_html__(
2705
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2706
+						'event_espresso'
2707
+					),
2708
+					__FILE__,
2709
+					__FUNCTION__,
2710
+					__LINE__
2711
+				);
2712
+				$success = 0;
2713 2713
                 
2714
-            } else {
2715
-                //first validate all fields!
2716
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2717
-                    $message_type_slug);
2714
+			} else {
2715
+				//first validate all fields!
2716
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2717
+					$message_type_slug);
2718 2718
                 
2719
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2720
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2721
-                //  WE need to make sure there is no actual error messages in validates.
2722
-                if (is_array($validates) && ! empty($validates)) {
2723
-                    //add the transient so when the form loads we know which fields to highlight
2724
-                    $this->_add_transient('edit_message_template', $validates);
2719
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2720
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2721
+				//  WE need to make sure there is no actual error messages in validates.
2722
+				if (is_array($validates) && ! empty($validates)) {
2723
+					//add the transient so when the form loads we know which fields to highlight
2724
+					$this->_add_transient('edit_message_template', $validates);
2725 2725
                     
2726
-                    $success = 0;
2726
+					$success = 0;
2727 2727
                     
2728
-                    //setup notices
2729
-                    foreach ($validates as $field => $error) {
2730
-                        if (isset($error['msg'])) {
2731
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2732
-                        }
2733
-                    }
2728
+					//setup notices
2729
+					foreach ($validates as $field => $error) {
2730
+						if (isset($error['msg'])) {
2731
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2732
+						}
2733
+					}
2734 2734
                     
2735
-                } else {
2736
-                    $set_column_values = array();
2737
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2738
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2735
+				} else {
2736
+					$set_column_values = array();
2737
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2738
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2739 2739
                         
2740
-                        $where_cols_n_values = array(
2741
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2742
-                        );
2740
+						$where_cols_n_values = array(
2741
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2742
+						);
2743 2743
                         
2744
-                        $message_template_fields = array(
2745
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2746
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2747
-                            'MTP_context'        => $set_column_values['MTP_context'],
2748
-                            'MTP_content'        => $set_column_values['MTP_content']
2749
-                        );
2750
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2751
-                            if ($updated === false) {
2752
-                                EE_Error::add_error(
2753
-                                    sprintf(
2754
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2755
-                                        $template_field
2756
-                                    ),
2757
-                                    __FILE__,
2758
-                                    __FUNCTION__,
2759
-                                    __LINE__
2760
-                                );
2761
-                            } else {
2762
-                                $success = 1;
2763
-                            }
2764
-                        } else {
2765
-                            //only do this logic if we don't have a MTP_ID for this field
2766
-                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2767
-                                //this has already been through the template field validator and sanitized, so it will be
2768
-                                //safe to insert this field.  Why insert?  This typically happens when we introduce a new
2769
-                                //message template field in a messenger/message type and existing users don't have the
2770
-                                //default setup for it.
2771
-                                //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2772
-                                $updated = $MTP->insert($message_template_fields);
2773
-                                if (! $updated || is_wp_error($updated)) {
2774
-                                    EE_Error::add_error(
2775
-                                        sprintf(
2776
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2777
-                                            $template_field
2778
-                                        ),
2779
-                                        __FILE__,
2780
-                                        __FUNCTION__,
2781
-                                        __LINE__
2782
-                                    );
2783
-                                    $success = 0;
2784
-                                } else {
2785
-                                    $success = 1;
2786
-                                }
2787
-                            }
2788
-                        }
2789
-                        $action_desc = 'updated';
2790
-                    }
2744
+						$message_template_fields = array(
2745
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2746
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2747
+							'MTP_context'        => $set_column_values['MTP_context'],
2748
+							'MTP_content'        => $set_column_values['MTP_content']
2749
+						);
2750
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2751
+							if ($updated === false) {
2752
+								EE_Error::add_error(
2753
+									sprintf(
2754
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2755
+										$template_field
2756
+									),
2757
+									__FILE__,
2758
+									__FUNCTION__,
2759
+									__LINE__
2760
+								);
2761
+							} else {
2762
+								$success = 1;
2763
+							}
2764
+						} else {
2765
+							//only do this logic if we don't have a MTP_ID for this field
2766
+							if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2767
+								//this has already been through the template field validator and sanitized, so it will be
2768
+								//safe to insert this field.  Why insert?  This typically happens when we introduce a new
2769
+								//message template field in a messenger/message type and existing users don't have the
2770
+								//default setup for it.
2771
+								//@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2772
+								$updated = $MTP->insert($message_template_fields);
2773
+								if (! $updated || is_wp_error($updated)) {
2774
+									EE_Error::add_error(
2775
+										sprintf(
2776
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2777
+											$template_field
2778
+										),
2779
+										__FILE__,
2780
+										__FUNCTION__,
2781
+										__LINE__
2782
+									);
2783
+									$success = 0;
2784
+								} else {
2785
+									$success = 1;
2786
+								}
2787
+							}
2788
+						}
2789
+						$action_desc = 'updated';
2790
+					}
2791 2791
                     
2792
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2793
-                    $mtpg_fields = array(
2794
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2795
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2796
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2797
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2798
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2799
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2800
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2801
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2802
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2803
-                            : '',
2804
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2805
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2806
-                            : ''
2807
-                    );
2792
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2793
+					$mtpg_fields = array(
2794
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2795
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2796
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2797
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2798
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2799
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2800
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2801
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2802
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2803
+							: '',
2804
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2805
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2806
+							: ''
2807
+					);
2808 2808
                     
2809
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2810
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2809
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2810
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2811 2811
                     
2812
-                    if ($updated === false) {
2813
-                        EE_Error::add_error(
2814
-                            sprintf(
2815
-                                esc_html__(
2816
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2817
-                                    'event_espresso'
2818
-                                ),
2819
-                                $set_column_values['GRP_ID']
2820
-                            ),
2821
-                            __FILE__,
2822
-                            __FUNCTION__,
2823
-                            __LINE__
2824
-                        );
2825
-                    } else {
2826
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2827
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2828
-                            ? $this->_req_data['MTP_template_pack']
2829
-                            : 'default';
2812
+					if ($updated === false) {
2813
+						EE_Error::add_error(
2814
+							sprintf(
2815
+								esc_html__(
2816
+									'The Message Template Group (%d) was NOT updated for some reason',
2817
+									'event_espresso'
2818
+								),
2819
+								$set_column_values['GRP_ID']
2820
+							),
2821
+							__FILE__,
2822
+							__FUNCTION__,
2823
+							__LINE__
2824
+						);
2825
+					} else {
2826
+						//k now we need to ensure the template_pack and template_variation fields are set.
2827
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2828
+							? $this->_req_data['MTP_template_pack']
2829
+							: 'default';
2830 2830
                         
2831
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2832
-                            ? $this->_req_data['MTP_template_variation']
2833
-                            : 'default';
2831
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2832
+							? $this->_req_data['MTP_template_variation']
2833
+							: 'default';
2834 2834
                         
2835
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2836
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2837
-                            $mtpg_obj->set_template_pack_name($template_pack);
2838
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2839
-                        }
2840
-                        $success = 1;
2841
-                    }
2842
-                }
2843
-            }
2835
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2836
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2837
+							$mtpg_obj->set_template_pack_name($template_pack);
2838
+							$mtpg_obj->set_template_pack_variation($template_variation);
2839
+						}
2840
+						$success = 1;
2841
+					}
2842
+				}
2843
+			}
2844 2844
             
2845
-        }
2846
-        
2847
-        //we return things differently if doing ajax
2848
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2849
-            $this->_template_args['success'] = $success;
2850
-            $this->_template_args['error']   = ! $success ? true : false;
2851
-            $this->_template_args['content'] = '';
2852
-            $this->_template_args['data']    = array(
2853
-                'grpID'        => $edit_array['GRP_ID'],
2854
-                'templateName' => $edit_array['template_name']
2855
-            );
2856
-            if ($success) {
2857
-                EE_Error::overwrite_success();
2858
-                EE_Error::add_success(
2859
-                    esc_html__(
2860
-                        '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.',
2861
-                        'event_espresso'
2862
-                    )
2863
-                );
2864
-            }
2845
+		}
2846
+        
2847
+		//we return things differently if doing ajax
2848
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2849
+			$this->_template_args['success'] = $success;
2850
+			$this->_template_args['error']   = ! $success ? true : false;
2851
+			$this->_template_args['content'] = '';
2852
+			$this->_template_args['data']    = array(
2853
+				'grpID'        => $edit_array['GRP_ID'],
2854
+				'templateName' => $edit_array['template_name']
2855
+			);
2856
+			if ($success) {
2857
+				EE_Error::overwrite_success();
2858
+				EE_Error::add_success(
2859
+					esc_html__(
2860
+						'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.',
2861
+						'event_espresso'
2862
+					)
2863
+				);
2864
+			}
2865 2865
             
2866
-            $this->_return_json();
2867
-        }
2868
-        
2869
-        
2870
-        //was a test send triggered?
2871
-        if (isset($this->_req_data['test_button'])) {
2872
-            EE_Error::overwrite_success();
2873
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2874
-            $override = true;
2875
-        }
2876
-        
2877
-        if (empty($query_args)) {
2878
-            $query_args = array(
2879
-                'id'      => $this->_req_data['GRP_ID'],
2880
-                'context' => $context_slug,
2881
-                'action'  => 'edit_message_template'
2882
-            );
2883
-        }
2884
-        
2885
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2886
-    }
2866
+			$this->_return_json();
2867
+		}
2868
+        
2869
+        
2870
+		//was a test send triggered?
2871
+		if (isset($this->_req_data['test_button'])) {
2872
+			EE_Error::overwrite_success();
2873
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2874
+			$override = true;
2875
+		}
2876
+        
2877
+		if (empty($query_args)) {
2878
+			$query_args = array(
2879
+				'id'      => $this->_req_data['GRP_ID'],
2880
+				'context' => $context_slug,
2881
+				'action'  => 'edit_message_template'
2882
+			);
2883
+		}
2884
+        
2885
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2886
+	}
2887 2887
 
2888 2888
 
2889
-    /**
2890
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2891
-     *
2892
-     * @param  string $context      what context being tested
2893
-     * @param  string $messenger    messenger being tested
2894
-     * @param  string $message_type message type being tested
2895
-     * @throws EE_Error
2896
-     * @throws InvalidArgumentException
2897
-     * @throws InvalidDataTypeException
2898
-     * @throws InvalidInterfaceException
2899
-     */
2900
-    protected function _do_test_send($context, $messenger, $message_type)
2901
-    {
2902
-        //set things up for preview
2903
-        $this->_req_data['messenger']    = $messenger;
2904
-        $this->_req_data['message_type'] = $message_type;
2905
-        $this->_req_data['context']      = $context;
2906
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2907
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2908
-        
2909
-        //let's save any existing fields that might be required by the messenger
2910
-        if (
2911
-            isset($this->_req_data['test_settings_fld'])
2912
-            && $active_messenger instanceof EE_messenger
2913
-            && apply_filters(
2914
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2915
-                true,
2916
-                $this->_req_data['test_settings_fld'],
2917
-                $active_messenger
2918
-            )
2919
-        ) {
2920
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2921
-        }
2922
-        
2923
-        $success = $this->_preview_message(true);
2924
-        
2925
-        if ($success) {
2926
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2927
-        } else {
2928
-            EE_Error::add_error(
2929
-                esc_html__('The test message was not sent', 'event_espresso'),
2930
-                __FILE__,
2931
-                __FUNCTION__,
2932
-                __LINE__
2933
-            );
2934
-        }
2935
-    }
2889
+	/**
2890
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2891
+	 *
2892
+	 * @param  string $context      what context being tested
2893
+	 * @param  string $messenger    messenger being tested
2894
+	 * @param  string $message_type message type being tested
2895
+	 * @throws EE_Error
2896
+	 * @throws InvalidArgumentException
2897
+	 * @throws InvalidDataTypeException
2898
+	 * @throws InvalidInterfaceException
2899
+	 */
2900
+	protected function _do_test_send($context, $messenger, $message_type)
2901
+	{
2902
+		//set things up for preview
2903
+		$this->_req_data['messenger']    = $messenger;
2904
+		$this->_req_data['message_type'] = $message_type;
2905
+		$this->_req_data['context']      = $context;
2906
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2907
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2908
+        
2909
+		//let's save any existing fields that might be required by the messenger
2910
+		if (
2911
+			isset($this->_req_data['test_settings_fld'])
2912
+			&& $active_messenger instanceof EE_messenger
2913
+			&& apply_filters(
2914
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2915
+				true,
2916
+				$this->_req_data['test_settings_fld'],
2917
+				$active_messenger
2918
+			)
2919
+		) {
2920
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2921
+		}
2922
+        
2923
+		$success = $this->_preview_message(true);
2924
+        
2925
+		if ($success) {
2926
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2927
+		} else {
2928
+			EE_Error::add_error(
2929
+				esc_html__('The test message was not sent', 'event_espresso'),
2930
+				__FILE__,
2931
+				__FUNCTION__,
2932
+				__LINE__
2933
+			);
2934
+		}
2935
+	}
2936 2936
     
2937 2937
     
2938
-    /**
2939
-     * _generate_new_templates
2940
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2941
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2942
-     * for the event.
2943
-     *
2944
-     *
2945
-     * @param  string $messenger     the messenger we are generating templates for
2946
-     * @param array   $message_types array of message types that the templates are generated for.
2947
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2948
-     *                               indicate the message_template_group being used as the base.
2949
-     *
2950
-     * @param bool    $global
2951
-     *
2952
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2953
-     *                               encountering problems.
2954
-     * @throws EE_Error
2955
-     */
2956
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2957
-    {
2958
-        
2959
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2960
-        // just don't generate any templates.
2961
-        if (empty($message_types)) {
2962
-            return true;
2963
-        }
2964
-        
2965
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2966
-    }
2938
+	/**
2939
+	 * _generate_new_templates
2940
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2941
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2942
+	 * for the event.
2943
+	 *
2944
+	 *
2945
+	 * @param  string $messenger     the messenger we are generating templates for
2946
+	 * @param array   $message_types array of message types that the templates are generated for.
2947
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2948
+	 *                               indicate the message_template_group being used as the base.
2949
+	 *
2950
+	 * @param bool    $global
2951
+	 *
2952
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2953
+	 *                               encountering problems.
2954
+	 * @throws EE_Error
2955
+	 */
2956
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2957
+	{
2958
+        
2959
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2960
+		// just don't generate any templates.
2961
+		if (empty($message_types)) {
2962
+			return true;
2963
+		}
2964
+        
2965
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2966
+	}
2967 2967
 
2968 2968
 
2969
-    /**
2970
-     * [_trash_or_restore_message_template]
2971
-     *
2972
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2973
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2974
-     *                        an individual context (FALSE).
2975
-     * @return void
2976
-     * @throws EE_Error
2977
-     * @throws InvalidArgumentException
2978
-     * @throws InvalidDataTypeException
2979
-     * @throws InvalidInterfaceException
2980
-     */
2981
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2982
-    {
2983
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2984
-        $MTP = EEM_Message_Template_Group::instance();
2985
-        
2986
-        $success = 1;
2987
-        
2988
-        //incoming GRP_IDs
2989
-        if ($all) {
2990
-            //Checkboxes
2991
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2992
-                //if array has more than one element then success message should be plural.
2993
-                //todo: what about nonce?
2994
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2969
+	/**
2970
+	 * [_trash_or_restore_message_template]
2971
+	 *
2972
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2973
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2974
+	 *                        an individual context (FALSE).
2975
+	 * @return void
2976
+	 * @throws EE_Error
2977
+	 * @throws InvalidArgumentException
2978
+	 * @throws InvalidDataTypeException
2979
+	 * @throws InvalidInterfaceException
2980
+	 */
2981
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2982
+	{
2983
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2984
+		$MTP = EEM_Message_Template_Group::instance();
2985
+        
2986
+		$success = 1;
2987
+        
2988
+		//incoming GRP_IDs
2989
+		if ($all) {
2990
+			//Checkboxes
2991
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2992
+				//if array has more than one element then success message should be plural.
2993
+				//todo: what about nonce?
2994
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2995 2995
                 
2996
-                //cycle through checkboxes
2997
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2998
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2999
-                    if ( ! $trashed_or_restored) {
3000
-                        $success = 0;
3001
-                    }
3002
-                }
3003
-            } else {
3004
-                //grab single GRP_ID and handle
3005
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3006
-                if ( ! empty($GRP_ID)) {
3007
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3008
-                    if ( ! $trashed_or_restored) {
3009
-                        $success = 0;
3010
-                    }
3011
-                } else {
3012
-                    $success = 0;
3013
-                }
3014
-            }
2996
+				//cycle through checkboxes
2997
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2998
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2999
+					if ( ! $trashed_or_restored) {
3000
+						$success = 0;
3001
+					}
3002
+				}
3003
+			} else {
3004
+				//grab single GRP_ID and handle
3005
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3006
+				if ( ! empty($GRP_ID)) {
3007
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3008
+					if ( ! $trashed_or_restored) {
3009
+						$success = 0;
3010
+					}
3011
+				} else {
3012
+					$success = 0;
3013
+				}
3014
+			}
3015 3015
             
3016
-        }
3016
+		}
3017 3017
         
3018
-        $action_desc = $trash
3019
-            ? esc_html__('moved to the trash', 'event_espresso')
3020
-            : esc_html__('restored', 'event_espresso');
3018
+		$action_desc = $trash
3019
+			? esc_html__('moved to the trash', 'event_espresso')
3020
+			: esc_html__('restored', 'event_espresso');
3021 3021
         
3022
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3022
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3023 3023
         
3024
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3025
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3024
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3025
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3026 3026
         
3027
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3028
-            'event_espresso') : $item_desc;
3027
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3028
+			'event_espresso') : $item_desc;
3029 3029
         
3030
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3030
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3031 3031
         
3032
-    }
3032
+	}
3033 3033
 
3034 3034
 
3035
-    /**
3036
-     * [_delete_message_template]
3037
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3038
-     *
3039
-     * @return void
3040
-     * @throws EE_Error
3041
-     * @throws InvalidArgumentException
3042
-     * @throws InvalidDataTypeException
3043
-     * @throws InvalidInterfaceException
3044
-     */
3045
-    protected function _delete_message_template()
3046
-    {
3047
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3048
-        
3049
-        //checkboxes
3050
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3051
-            //if array has more than one element then success message should be plural
3052
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3035
+	/**
3036
+	 * [_delete_message_template]
3037
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3038
+	 *
3039
+	 * @return void
3040
+	 * @throws EE_Error
3041
+	 * @throws InvalidArgumentException
3042
+	 * @throws InvalidDataTypeException
3043
+	 * @throws InvalidInterfaceException
3044
+	 */
3045
+	protected function _delete_message_template()
3046
+	{
3047
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3048
+        
3049
+		//checkboxes
3050
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3051
+			//if array has more than one element then success message should be plural
3052
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3053 3053
             
3054
-            //cycle through bulk action checkboxes
3055
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3056
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3057
-            }
3058
-        } else {
3059
-            //grab single grp_id and delete
3060
-            $GRP_ID  = absint($this->_req_data['id']);
3061
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3062
-        }
3063
-        
3064
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3065
-        
3066
-    }
3054
+			//cycle through bulk action checkboxes
3055
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3056
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3057
+			}
3058
+		} else {
3059
+			//grab single grp_id and delete
3060
+			$GRP_ID  = absint($this->_req_data['id']);
3061
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3062
+		}
3063
+        
3064
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3065
+        
3066
+	}
3067 3067
 
3068 3068
 
3069
-    /**
3070
-     * helper for permanently deleting a mtP group and all related message_templates
3071
-     *
3072
-     * @param  int  $GRP_ID        The group being deleted
3073
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3074
-     * @return bool boolean to indicate the success of the deletes or not.
3075
-     * @throws EE_Error
3076
-     * @throws InvalidArgumentException
3077
-     * @throws InvalidDataTypeException
3078
-     * @throws InvalidInterfaceException
3079
-     */
3080
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3081
-    {
3082
-        $success = 1;
3083
-        $MTPG    = EEM_Message_Template_Group::instance();
3084
-        //first let's GET this group
3085
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3086
-        //then delete permanently all the related Message Templates
3087
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3088
-        
3089
-        if ($deleted === 0) {
3090
-            $success = 0;
3091
-        }
3092
-        
3093
-        //now delete permanently this particular group
3094
-        
3095
-        if ($include_group && ! $MTG->delete_permanently()) {
3096
-            $success = 0;
3097
-        }
3098
-        
3099
-        return $success;
3100
-    }
3069
+	/**
3070
+	 * helper for permanently deleting a mtP group and all related message_templates
3071
+	 *
3072
+	 * @param  int  $GRP_ID        The group being deleted
3073
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3074
+	 * @return bool boolean to indicate the success of the deletes or not.
3075
+	 * @throws EE_Error
3076
+	 * @throws InvalidArgumentException
3077
+	 * @throws InvalidDataTypeException
3078
+	 * @throws InvalidInterfaceException
3079
+	 */
3080
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3081
+	{
3082
+		$success = 1;
3083
+		$MTPG    = EEM_Message_Template_Group::instance();
3084
+		//first let's GET this group
3085
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3086
+		//then delete permanently all the related Message Templates
3087
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3088
+        
3089
+		if ($deleted === 0) {
3090
+			$success = 0;
3091
+		}
3092
+        
3093
+		//now delete permanently this particular group
3094
+        
3095
+		if ($include_group && ! $MTG->delete_permanently()) {
3096
+			$success = 0;
3097
+		}
3098
+        
3099
+		return $success;
3100
+	}
3101 3101
     
3102 3102
     
3103
-    /**
3104
-     *    _learn_more_about_message_templates_link
3105
-     * @access protected
3106
-     * @return string
3107
-     */
3108
-    protected function _learn_more_about_message_templates_link()
3109
-    {
3110
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3111
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3112
-               . '</a>';
3113
-    }
3103
+	/**
3104
+	 *    _learn_more_about_message_templates_link
3105
+	 * @access protected
3106
+	 * @return string
3107
+	 */
3108
+	protected function _learn_more_about_message_templates_link()
3109
+	{
3110
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3111
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3112
+			   . '</a>';
3113
+	}
3114 3114
 
3115 3115
 
3116
-    /**
3117
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3118
-     * ajax and other routes.
3119
-     *
3120
-     * @return void
3121
-     * @throws DomainException
3122
-     */
3123
-    protected function _settings()
3124
-    {
3125
-        
3126
-        
3127
-        $this->_set_m_mt_settings();
3128
-        
3129
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3130
-            ? $this->_req_data['selected_messenger']
3131
-            : 'email';
3132
-        
3133
-        //let's setup the messenger tabs
3134
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3135
-            $this->_m_mt_settings['messenger_tabs'],
3136
-            'messenger_links',
3137
-            '|',
3138
-            $selected_messenger
3139
-        );
3140
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3141
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3142
-        
3143
-        $this->display_admin_page_with_sidebar();
3144
-        
3145
-    }
3116
+	/**
3117
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3118
+	 * ajax and other routes.
3119
+	 *
3120
+	 * @return void
3121
+	 * @throws DomainException
3122
+	 */
3123
+	protected function _settings()
3124
+	{
3125
+        
3126
+        
3127
+		$this->_set_m_mt_settings();
3128
+        
3129
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3130
+			? $this->_req_data['selected_messenger']
3131
+			: 'email';
3132
+        
3133
+		//let's setup the messenger tabs
3134
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3135
+			$this->_m_mt_settings['messenger_tabs'],
3136
+			'messenger_links',
3137
+			'|',
3138
+			$selected_messenger
3139
+		);
3140
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3141
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3142
+        
3143
+		$this->display_admin_page_with_sidebar();
3144
+        
3145
+	}
3146 3146
 
3147 3147
 
3148
-    /**
3149
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3150
-     *
3151
-     * @access protected
3152
-     * @return void
3153
-     * @throws DomainException
3154
-     */
3155
-    protected function _set_m_mt_settings()
3156
-    {
3157
-        //first if this is already set then lets get out no need to regenerate data.
3158
-        if ( ! empty($this->_m_mt_settings)) {
3159
-            return;
3160
-        }
3161
-        
3162
-        //get all installed messengers and message_types
3163
-        /** @type EE_messenger[] $messengers */
3164
-        $messengers = $this->_message_resource_manager->installed_messengers();
3165
-        /** @type EE_message_type[] $message_types */
3166
-        $message_types = $this->_message_resource_manager->installed_message_types();
3167
-        
3168
-        
3169
-        //assemble the array for the _tab_text_links helper
3170
-        
3171
-        foreach ($messengers as $messenger) {
3172
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3173
-                'label' => ucwords($messenger->label['singular']),
3174
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3175
-                    ? 'messenger-active'
3176
-                    : '',
3177
-                'href'  => $messenger->name,
3178
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3179
-                'slug'  => $messenger->name,
3180
-                'obj'   => $messenger
3181
-            );
3148
+	/**
3149
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3150
+	 *
3151
+	 * @access protected
3152
+	 * @return void
3153
+	 * @throws DomainException
3154
+	 */
3155
+	protected function _set_m_mt_settings()
3156
+	{
3157
+		//first if this is already set then lets get out no need to regenerate data.
3158
+		if ( ! empty($this->_m_mt_settings)) {
3159
+			return;
3160
+		}
3161
+        
3162
+		//get all installed messengers and message_types
3163
+		/** @type EE_messenger[] $messengers */
3164
+		$messengers = $this->_message_resource_manager->installed_messengers();
3165
+		/** @type EE_message_type[] $message_types */
3166
+		$message_types = $this->_message_resource_manager->installed_message_types();
3167
+        
3168
+        
3169
+		//assemble the array for the _tab_text_links helper
3170
+        
3171
+		foreach ($messengers as $messenger) {
3172
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3173
+				'label' => ucwords($messenger->label['singular']),
3174
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3175
+					? 'messenger-active'
3176
+					: '',
3177
+				'href'  => $messenger->name,
3178
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3179
+				'slug'  => $messenger->name,
3180
+				'obj'   => $messenger
3181
+			);
3182 3182
             
3183 3183
             
3184
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3184
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3185 3185
             
3186
-            foreach ($message_types as $message_type) {
3187
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3188
-                // it shouldn't show in either the inactive OR active metabox.
3189
-                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3190
-                    continue;
3191
-                }
3186
+			foreach ($message_types as $message_type) {
3187
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3188
+				// it shouldn't show in either the inactive OR active metabox.
3189
+				if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3190
+					continue;
3191
+				}
3192 3192
                 
3193
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3194
-                    $messenger->name,
3195
-                    $message_type->name
3196
-                )
3197
-                    ? 'active'
3198
-                    : 'inactive';
3193
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3194
+					$messenger->name,
3195
+					$message_type->name
3196
+				)
3197
+					? 'active'
3198
+					: 'inactive';
3199 3199
                 
3200
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3201
-                    'label'    => ucwords($message_type->label['singular']),
3202
-                    'class'    => 'message-type-' . $a_or_i,
3203
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3204
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3205
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3206
-                    'title'    => $a_or_i === 'active'
3207
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3208
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3209
-                    'content'  => $a_or_i === 'active'
3210
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3211
-                        : $this->_message_type_settings_content($message_type, $messenger),
3212
-                    'slug'     => $message_type->name,
3213
-                    'active'   => $a_or_i === 'active',
3214
-                    'obj'      => $message_type
3215
-                );
3216
-            }
3217
-        }
3218
-    }
3200
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3201
+					'label'    => ucwords($message_type->label['singular']),
3202
+					'class'    => 'message-type-' . $a_or_i,
3203
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3204
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3205
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3206
+					'title'    => $a_or_i === 'active'
3207
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3208
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3209
+					'content'  => $a_or_i === 'active'
3210
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3211
+						: $this->_message_type_settings_content($message_type, $messenger),
3212
+					'slug'     => $message_type->name,
3213
+					'active'   => $a_or_i === 'active',
3214
+					'obj'      => $message_type
3215
+				);
3216
+			}
3217
+		}
3218
+	}
3219 3219
 
3220 3220
 
3221
-    /**
3222
-     * This just prepares the content for the message type settings
3223
-     *
3224
-     * @param  EE_message_type  $message_type The message type object
3225
-     * @param  EE_messenger  $messenger    The messenger object
3226
-     * @param  boolean $active       Whether the message type is active or not
3227
-     * @return string html output for the content
3228
-     * @throws DomainException
3229
-     */
3230
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3231
-    {
3232
-        //get message type fields
3233
-        $fields                                         = $message_type->get_admin_settings_fields();
3234
-        $settings_template_args['template_form_fields'] = '';
3235
-        
3236
-        if ( ! empty($fields) && $active) {
3221
+	/**
3222
+	 * This just prepares the content for the message type settings
3223
+	 *
3224
+	 * @param  EE_message_type  $message_type The message type object
3225
+	 * @param  EE_messenger  $messenger    The messenger object
3226
+	 * @param  boolean $active       Whether the message type is active or not
3227
+	 * @return string html output for the content
3228
+	 * @throws DomainException
3229
+	 */
3230
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3231
+	{
3232
+		//get message type fields
3233
+		$fields                                         = $message_type->get_admin_settings_fields();
3234
+		$settings_template_args['template_form_fields'] = '';
3235
+        
3236
+		if ( ! empty($fields) && $active) {
3237 3237
             
3238
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3238
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3239 3239
             
3240
-            foreach ($fields as $fldname => $fldprops) {
3241
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3242
-                $template_form_field[$field_id] = array(
3243
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3244
-                    'label'      => $fldprops['label'],
3245
-                    'input'      => $fldprops['field_type'],
3246
-                    'type'       => $fldprops['value_type'],
3247
-                    'required'   => $fldprops['required'],
3248
-                    'validation' => $fldprops['validation'],
3249
-                    'value'      => isset($existing_settings[$fldname])
3250
-                        ? $existing_settings[$fldname]
3251
-                        : $fldprops['default'],
3252
-                    'options'    => isset($fldprops['options'])
3253
-                        ? $fldprops['options']
3254
-                        : array(),
3255
-                    'default'    => isset($existing_settings[$fldname])
3256
-                        ? $existing_settings[$fldname]
3257
-                        : $fldprops['default'],
3258
-                    'css_class'  => 'no-drag',
3259
-                    'format'     => $fldprops['format']
3260
-                );
3261
-            }
3240
+			foreach ($fields as $fldname => $fldprops) {
3241
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3242
+				$template_form_field[$field_id] = array(
3243
+					'name'       => 'message_type_settings[' . $fldname . ']',
3244
+					'label'      => $fldprops['label'],
3245
+					'input'      => $fldprops['field_type'],
3246
+					'type'       => $fldprops['value_type'],
3247
+					'required'   => $fldprops['required'],
3248
+					'validation' => $fldprops['validation'],
3249
+					'value'      => isset($existing_settings[$fldname])
3250
+						? $existing_settings[$fldname]
3251
+						: $fldprops['default'],
3252
+					'options'    => isset($fldprops['options'])
3253
+						? $fldprops['options']
3254
+						: array(),
3255
+					'default'    => isset($existing_settings[$fldname])
3256
+						? $existing_settings[$fldname]
3257
+						: $fldprops['default'],
3258
+					'css_class'  => 'no-drag',
3259
+					'format'     => $fldprops['format']
3260
+				);
3261
+			}
3262 3262
             
3263 3263
             
3264
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3265
-                ? $this->_generate_admin_form_fields(
3266
-                    $template_form_field,
3267
-                    'string',
3268
-                    'ee_mt_activate_form'
3269
-                )
3270
-                : '';
3271
-        }
3272
-        
3273
-        $settings_template_args['description'] = $message_type->description;
3274
-        //we also need some hidden fields
3275
-        $settings_template_args['hidden_fields'] = array(
3276
-            'message_type_settings[messenger]'    => array(
3277
-                'type'  => 'hidden',
3278
-                'value' => $messenger->name
3279
-            ),
3280
-            'message_type_settings[message_type]' => array(
3281
-                'type'  => 'hidden',
3282
-                'value' => $message_type->name
3283
-            ),
3284
-            'type'                                => array(
3285
-                'type'  => 'hidden',
3286
-                'value' => 'message_type'
3287
-            )
3288
-        );
3289
-        
3290
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3291
-            $settings_template_args['hidden_fields'],
3292
-            'array'
3293
-        );
3294
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3295
-            ? ' hidden'
3296
-            : '';
3297
-        
3298
-        
3299
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3300
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
3301
-        
3302
-        return $content;
3303
-    }
3264
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3265
+				? $this->_generate_admin_form_fields(
3266
+					$template_form_field,
3267
+					'string',
3268
+					'ee_mt_activate_form'
3269
+				)
3270
+				: '';
3271
+		}
3272
+        
3273
+		$settings_template_args['description'] = $message_type->description;
3274
+		//we also need some hidden fields
3275
+		$settings_template_args['hidden_fields'] = array(
3276
+			'message_type_settings[messenger]'    => array(
3277
+				'type'  => 'hidden',
3278
+				'value' => $messenger->name
3279
+			),
3280
+			'message_type_settings[message_type]' => array(
3281
+				'type'  => 'hidden',
3282
+				'value' => $message_type->name
3283
+			),
3284
+			'type'                                => array(
3285
+				'type'  => 'hidden',
3286
+				'value' => 'message_type'
3287
+			)
3288
+		);
3289
+        
3290
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3291
+			$settings_template_args['hidden_fields'],
3292
+			'array'
3293
+		);
3294
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3295
+			? ' hidden'
3296
+			: '';
3297
+        
3298
+        
3299
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3300
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
3301
+        
3302
+		return $content;
3303
+	}
3304 3304
 
3305 3305
 
3306
-    /**
3307
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3308
-     *
3309
-     * @access protected
3310
-     * @return void
3311
-     * @throws DomainException
3312
-     */
3313
-    protected function _messages_settings_metaboxes()
3314
-    {
3315
-        $this->_set_m_mt_settings();
3316
-        $m_boxes         = $mt_boxes = array();
3317
-        $m_template_args = $mt_template_args = array();
3318
-        
3319
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3320
-            ? $this->_req_data['selected_messenger']
3321
-            : 'email';
3322
-        
3323
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3324
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3325
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3326
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3327
-                //messenger meta boxes
3328
-                $active                                 = $selected_messenger === $messenger;
3329
-                $active_mt_tabs                         = isset(
3330
-                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
-                )
3332
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3333
-                    : '';
3334
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3335
-                    esc_html__('%s Settings', 'event_espresso'),
3336
-                    $tab_array['label']
3337
-                );
3338
-                $m_template_args[$messenger . '_a_box'] = array(
3339
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3340
-                    'inactive_message_types' => isset(
3341
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3342
-                    )
3343
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3344
-                        : '',
3345
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3346
-                    'hidden'                 => $active ? '' : ' hidden',
3347
-                    'hide_on_message'        => $hide_on_message,
3348
-                    'messenger'              => $messenger,
3349
-                    'active'                 => $active
3350
-                );
3351
-                // message type meta boxes
3352
-                // (which is really just the inactive container for each messenger
3353
-                // showing inactive message types for that messenger)
3354
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3355
-                $mt_template_args[$messenger . '_i_box'] = array(
3356
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3357
-                    'inactive_message_types' => isset(
3358
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3359
-                    )
3360
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3361
-                        : '',
3362
-                    'hidden'                 => $active ? '' : ' hidden',
3363
-                    'hide_on_message'        => $hide_on_message,
3364
-                    'hide_off_message'       => $hide_off_message,
3365
-                    'messenger'              => $messenger,
3366
-                    'active'                 => $active
3367
-                );
3368
-            }
3369
-        }
3370
-        
3371
-        
3372
-        //register messenger metaboxes
3373
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3374
-        foreach ($m_boxes as $box => $label) {
3375
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3376
-            $msgr          = str_replace('_a_box', '', $box);
3377
-            add_meta_box(
3378
-                'espresso_' . $msgr . '_settings',
3379
-                $label,
3380
-                function ($post, $metabox) {
3381
-                    echo EEH_Template::display_template(
3382
-                            $metabox["args"]["template_path"],
3383
-                            $metabox["args"]["template_args"],
3384
-                            true
3385
-                    );
3386
-                },
3387
-                $this->_current_screen->id,
3388
-                'normal',
3389
-                'high',
3390
-                $callback_args
3391
-            );
3392
-        }
3393
-        
3394
-        //register message type metaboxes
3395
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3396
-        foreach ($mt_boxes as $box => $label) {
3397
-            $callback_args = array(
3398
-                'template_path' => $mt_template_path,
3399
-                'template_args' => $mt_template_args[$box]
3400
-            );
3401
-            $mt            = str_replace('_i_box', '', $box);
3402
-            add_meta_box(
3403
-                'espresso_' . $mt . '_inactive_mts',
3404
-                $label,
3405
-                function ($post, $metabox) {
3406
-                    echo EEH_Template::display_template(
3407
-                            $metabox["args"]["template_path"],
3408
-                            $metabox["args"]["template_args"],
3409
-                            true
3410
-                    );
3411
-                },
3412
-                $this->_current_screen->id,
3413
-                'side',
3414
-                'high',
3415
-                $callback_args
3416
-            );
3417
-        }
3418
-        
3419
-        //register metabox for global messages settings but only when on the main site.  On single site installs this
3420
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3421
-        if (is_main_site()) {
3422
-            add_meta_box(
3423
-                'espresso_global_message_settings',
3424
-                esc_html__('Global Message Settings', 'event_espresso'),
3425
-                array($this, 'global_messages_settings_metabox_content'),
3426
-                $this->_current_screen->id,
3427
-                'normal',
3428
-                'low',
3429
-                array()
3430
-            );
3431
-        }
3432
-        
3433
-    }
3306
+	/**
3307
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3308
+	 *
3309
+	 * @access protected
3310
+	 * @return void
3311
+	 * @throws DomainException
3312
+	 */
3313
+	protected function _messages_settings_metaboxes()
3314
+	{
3315
+		$this->_set_m_mt_settings();
3316
+		$m_boxes         = $mt_boxes = array();
3317
+		$m_template_args = $mt_template_args = array();
3318
+        
3319
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3320
+			? $this->_req_data['selected_messenger']
3321
+			: 'email';
3322
+        
3323
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3324
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3325
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3326
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3327
+				//messenger meta boxes
3328
+				$active                                 = $selected_messenger === $messenger;
3329
+				$active_mt_tabs                         = isset(
3330
+					$this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
+				)
3332
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3333
+					: '';
3334
+				$m_boxes[$messenger . '_a_box']         = sprintf(
3335
+					esc_html__('%s Settings', 'event_espresso'),
3336
+					$tab_array['label']
3337
+				);
3338
+				$m_template_args[$messenger . '_a_box'] = array(
3339
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3340
+					'inactive_message_types' => isset(
3341
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3342
+					)
3343
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3344
+						: '',
3345
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3346
+					'hidden'                 => $active ? '' : ' hidden',
3347
+					'hide_on_message'        => $hide_on_message,
3348
+					'messenger'              => $messenger,
3349
+					'active'                 => $active
3350
+				);
3351
+				// message type meta boxes
3352
+				// (which is really just the inactive container for each messenger
3353
+				// showing inactive message types for that messenger)
3354
+				$mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3355
+				$mt_template_args[$messenger . '_i_box'] = array(
3356
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3357
+					'inactive_message_types' => isset(
3358
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3359
+					)
3360
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3361
+						: '',
3362
+					'hidden'                 => $active ? '' : ' hidden',
3363
+					'hide_on_message'        => $hide_on_message,
3364
+					'hide_off_message'       => $hide_off_message,
3365
+					'messenger'              => $messenger,
3366
+					'active'                 => $active
3367
+				);
3368
+			}
3369
+		}
3370
+        
3371
+        
3372
+		//register messenger metaboxes
3373
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3374
+		foreach ($m_boxes as $box => $label) {
3375
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3376
+			$msgr          = str_replace('_a_box', '', $box);
3377
+			add_meta_box(
3378
+				'espresso_' . $msgr . '_settings',
3379
+				$label,
3380
+				function ($post, $metabox) {
3381
+					echo EEH_Template::display_template(
3382
+							$metabox["args"]["template_path"],
3383
+							$metabox["args"]["template_args"],
3384
+							true
3385
+					);
3386
+				},
3387
+				$this->_current_screen->id,
3388
+				'normal',
3389
+				'high',
3390
+				$callback_args
3391
+			);
3392
+		}
3393
+        
3394
+		//register message type metaboxes
3395
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3396
+		foreach ($mt_boxes as $box => $label) {
3397
+			$callback_args = array(
3398
+				'template_path' => $mt_template_path,
3399
+				'template_args' => $mt_template_args[$box]
3400
+			);
3401
+			$mt            = str_replace('_i_box', '', $box);
3402
+			add_meta_box(
3403
+				'espresso_' . $mt . '_inactive_mts',
3404
+				$label,
3405
+				function ($post, $metabox) {
3406
+					echo EEH_Template::display_template(
3407
+							$metabox["args"]["template_path"],
3408
+							$metabox["args"]["template_args"],
3409
+							true
3410
+					);
3411
+				},
3412
+				$this->_current_screen->id,
3413
+				'side',
3414
+				'high',
3415
+				$callback_args
3416
+			);
3417
+		}
3418
+        
3419
+		//register metabox for global messages settings but only when on the main site.  On single site installs this
3420
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3421
+		if (is_main_site()) {
3422
+			add_meta_box(
3423
+				'espresso_global_message_settings',
3424
+				esc_html__('Global Message Settings', 'event_espresso'),
3425
+				array($this, 'global_messages_settings_metabox_content'),
3426
+				$this->_current_screen->id,
3427
+				'normal',
3428
+				'low',
3429
+				array()
3430
+			);
3431
+		}
3432
+        
3433
+	}
3434 3434
 
3435 3435
 
3436
-    /**
3437
-     *  This generates the content for the global messages settings metabox.
3438
-     *
3439
-     * @return string
3440
-     * @throws EE_Error
3441
-     * @throws InvalidArgumentException
3442
-     * @throws ReflectionException
3443
-     * @throws InvalidDataTypeException
3444
-     * @throws InvalidInterfaceException
3445
-     */
3446
-    public function global_messages_settings_metabox_content()
3447
-    {
3448
-        $form = $this->_generate_global_settings_form();
3449
-        echo $form->form_open(
3450
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3451
-                'POST'
3452
-            )
3453
-             . $form->get_html()
3454
-             . $form->form_close();
3455
-    }
3436
+	/**
3437
+	 *  This generates the content for the global messages settings metabox.
3438
+	 *
3439
+	 * @return string
3440
+	 * @throws EE_Error
3441
+	 * @throws InvalidArgumentException
3442
+	 * @throws ReflectionException
3443
+	 * @throws InvalidDataTypeException
3444
+	 * @throws InvalidInterfaceException
3445
+	 */
3446
+	public function global_messages_settings_metabox_content()
3447
+	{
3448
+		$form = $this->_generate_global_settings_form();
3449
+		echo $form->form_open(
3450
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3451
+				'POST'
3452
+			)
3453
+			 . $form->get_html()
3454
+			 . $form->form_close();
3455
+	}
3456 3456
 
3457 3457
 
3458
-    /**
3459
-     * This generates and returns the form object for the global messages settings.
3460
-     *
3461
-     * @return EE_Form_Section_Proper
3462
-     * @throws EE_Error
3463
-     * @throws InvalidArgumentException
3464
-     * @throws ReflectionException
3465
-     * @throws InvalidDataTypeException
3466
-     * @throws InvalidInterfaceException
3467
-     */
3468
-    protected function _generate_global_settings_form()
3469
-    {
3470
-        EE_Registry::instance()->load_helper('HTML');
3471
-        /** @var EE_Network_Core_Config $network_config */
3472
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3473
-        
3474
-        return new EE_Form_Section_Proper(
3475
-            array(
3476
-                'name'            => 'global_messages_settings',
3477
-                'html_id'         => 'global_messages_settings',
3478
-                'html_class'      => 'form-table',
3479
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3480
-                'subsections'     => apply_filters(
3481
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3482
-                    array(
3483
-                        'do_messages_on_same_request' => new EE_Select_Input(
3484
-                            array(
3485
-                                true  => esc_html__("On the same request", "event_espresso"),
3486
-                                false => esc_html__("On a separate request", "event_espresso")
3487
-                            ),
3488
-                            array(
3489
-                                'default'         => $network_config->do_messages_on_same_request,
3490
-                                'html_label_text' => esc_html__(
3491
-                                    'Generate and send all messages:',
3492
-                                    'event_espresso'
3493
-                                ),
3494
-                                'html_help_text'  => esc_html__(
3495
-                                    '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.',
3496
-                                    'event_espresso'
3497
-                                ),
3498
-                            )
3499
-                        ),
3500
-                        'delete_threshold' => new EE_Select_Input(
3501
-                            array(
3502
-                                0 => esc_html__('Forever', 'event_espresso'),
3503
-                                3 => esc_html__('3 Months', 'event_espresso'),
3504
-                                6 => esc_html__('6 Months', 'event_espresso'),
3505
-                                9 => esc_html__('9 Months', 'event_espresso'),
3506
-                                12 => esc_html__('12 Months', 'event_espresso'),
3507
-                                24 => esc_html__('24 Months', 'event_espresso'),
3508
-                                36 => esc_html__('36 Months', 'event_espresso')
3509
-                            ),
3510
-                            array(
3511
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3512
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3513
-                                'html_help_text' => esc_html__(
3514
-                                    'You can control how long a record of processed messages is kept via this option.',
3515
-                                    'event_espresso'
3516
-                                ),
3517
-                            )
3518
-                        ),
3519
-                        'update_settings'             => new EE_Submit_Input(
3520
-                            array(
3521
-                                'default'         => esc_html__('Update', 'event_espresso'),
3522
-                                'html_label_text' => '&nbsp'
3523
-                            )
3524
-                        )
3525
-                    )
3526
-                )
3527
-            )
3528
-        );
3529
-    }
3458
+	/**
3459
+	 * This generates and returns the form object for the global messages settings.
3460
+	 *
3461
+	 * @return EE_Form_Section_Proper
3462
+	 * @throws EE_Error
3463
+	 * @throws InvalidArgumentException
3464
+	 * @throws ReflectionException
3465
+	 * @throws InvalidDataTypeException
3466
+	 * @throws InvalidInterfaceException
3467
+	 */
3468
+	protected function _generate_global_settings_form()
3469
+	{
3470
+		EE_Registry::instance()->load_helper('HTML');
3471
+		/** @var EE_Network_Core_Config $network_config */
3472
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3473
+        
3474
+		return new EE_Form_Section_Proper(
3475
+			array(
3476
+				'name'            => 'global_messages_settings',
3477
+				'html_id'         => 'global_messages_settings',
3478
+				'html_class'      => 'form-table',
3479
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3480
+				'subsections'     => apply_filters(
3481
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3482
+					array(
3483
+						'do_messages_on_same_request' => new EE_Select_Input(
3484
+							array(
3485
+								true  => esc_html__("On the same request", "event_espresso"),
3486
+								false => esc_html__("On a separate request", "event_espresso")
3487
+							),
3488
+							array(
3489
+								'default'         => $network_config->do_messages_on_same_request,
3490
+								'html_label_text' => esc_html__(
3491
+									'Generate and send all messages:',
3492
+									'event_espresso'
3493
+								),
3494
+								'html_help_text'  => esc_html__(
3495
+									'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.',
3496
+									'event_espresso'
3497
+								),
3498
+							)
3499
+						),
3500
+						'delete_threshold' => new EE_Select_Input(
3501
+							array(
3502
+								0 => esc_html__('Forever', 'event_espresso'),
3503
+								3 => esc_html__('3 Months', 'event_espresso'),
3504
+								6 => esc_html__('6 Months', 'event_espresso'),
3505
+								9 => esc_html__('9 Months', 'event_espresso'),
3506
+								12 => esc_html__('12 Months', 'event_espresso'),
3507
+								24 => esc_html__('24 Months', 'event_espresso'),
3508
+								36 => esc_html__('36 Months', 'event_espresso')
3509
+							),
3510
+							array(
3511
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3512
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3513
+								'html_help_text' => esc_html__(
3514
+									'You can control how long a record of processed messages is kept via this option.',
3515
+									'event_espresso'
3516
+								),
3517
+							)
3518
+						),
3519
+						'update_settings'             => new EE_Submit_Input(
3520
+							array(
3521
+								'default'         => esc_html__('Update', 'event_espresso'),
3522
+								'html_label_text' => '&nbsp'
3523
+							)
3524
+						)
3525
+					)
3526
+				)
3527
+			)
3528
+		);
3529
+	}
3530 3530
 
3531 3531
 
3532
-    /**
3533
-     * This handles updating the global settings set on the admin page.
3534
-     *
3535
-     * @throws EE_Error
3536
-     * @throws InvalidDataTypeException
3537
-     * @throws InvalidInterfaceException
3538
-     * @throws InvalidArgumentException
3539
-     * @throws ReflectionException
3540
-     */
3541
-    protected function _update_global_settings()
3542
-    {
3543
-        /** @var EE_Network_Core_Config $network_config */
3544
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3545
-        $messages_config = EE_Registry::instance()->CFG->messages;
3546
-        $form           = $this->_generate_global_settings_form();
3547
-        if ($form->was_submitted()) {
3548
-            $form->receive_form_submission();
3549
-            if ($form->is_valid()) {
3550
-                $valid_data = $form->valid_data();
3551
-                foreach ($valid_data as $property => $value) {
3552
-                    $setter = 'set_' . $property;
3553
-                    if (method_exists($network_config, $setter)) {
3554
-                        $network_config->{$setter}($value);
3555
-                    } else if (
3556
-                        property_exists($network_config, $property)
3557
-                        && $network_config->{$property} !== $value
3558
-                    ) {
3559
-                        $network_config->{$property} = $value;
3560
-                    } else if (
3561
-                        property_exists($messages_config, $property)
3562
-                        && $messages_config->{$property} !== $value
3563
-                    ) {
3564
-                        $messages_config->{$property} = $value;
3565
-                    }
3566
-                }
3567
-                //only update if the form submission was valid!
3568
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3569
-                EE_Registry::instance()->CFG->update_espresso_config();
3570
-                EE_Error::overwrite_success();
3571
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3572
-            }
3573
-        }
3574
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3575
-    }
3532
+	/**
3533
+	 * This handles updating the global settings set on the admin page.
3534
+	 *
3535
+	 * @throws EE_Error
3536
+	 * @throws InvalidDataTypeException
3537
+	 * @throws InvalidInterfaceException
3538
+	 * @throws InvalidArgumentException
3539
+	 * @throws ReflectionException
3540
+	 */
3541
+	protected function _update_global_settings()
3542
+	{
3543
+		/** @var EE_Network_Core_Config $network_config */
3544
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3545
+		$messages_config = EE_Registry::instance()->CFG->messages;
3546
+		$form           = $this->_generate_global_settings_form();
3547
+		if ($form->was_submitted()) {
3548
+			$form->receive_form_submission();
3549
+			if ($form->is_valid()) {
3550
+				$valid_data = $form->valid_data();
3551
+				foreach ($valid_data as $property => $value) {
3552
+					$setter = 'set_' . $property;
3553
+					if (method_exists($network_config, $setter)) {
3554
+						$network_config->{$setter}($value);
3555
+					} else if (
3556
+						property_exists($network_config, $property)
3557
+						&& $network_config->{$property} !== $value
3558
+					) {
3559
+						$network_config->{$property} = $value;
3560
+					} else if (
3561
+						property_exists($messages_config, $property)
3562
+						&& $messages_config->{$property} !== $value
3563
+					) {
3564
+						$messages_config->{$property} = $value;
3565
+					}
3566
+				}
3567
+				//only update if the form submission was valid!
3568
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3569
+				EE_Registry::instance()->CFG->update_espresso_config();
3570
+				EE_Error::overwrite_success();
3571
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3572
+			}
3573
+		}
3574
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3575
+	}
3576 3576
 
3577 3577
 
3578
-    /**
3579
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3580
-     *
3581
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3582
-     * @return string html formatted tabs
3583
-     * @throws DomainException
3584
-     */
3585
-    protected function _get_mt_tabs($tab_array)
3586
-    {
3587
-        $tab_array = (array)$tab_array;
3588
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3589
-        $tabs      = '';
3590
-        
3591
-        foreach ($tab_array as $tab) {
3592
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3593
-        }
3594
-        
3595
-        return $tabs;
3596
-    }
3578
+	/**
3579
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3580
+	 *
3581
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3582
+	 * @return string html formatted tabs
3583
+	 * @throws DomainException
3584
+	 */
3585
+	protected function _get_mt_tabs($tab_array)
3586
+	{
3587
+		$tab_array = (array)$tab_array;
3588
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3589
+		$tabs      = '';
3590
+        
3591
+		foreach ($tab_array as $tab) {
3592
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3593
+		}
3594
+        
3595
+		return $tabs;
3596
+	}
3597 3597
 
3598 3598
 
3599
-    /**
3600
-     * This prepares the content of the messenger meta box admin settings
3601
-     *
3602
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3603
-     * @return string html formatted content
3604
-     * @throws DomainException
3605
-     */
3606
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3607
-    {
3599
+	/**
3600
+	 * This prepares the content of the messenger meta box admin settings
3601
+	 *
3602
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3603
+	 * @return string html formatted content
3604
+	 * @throws DomainException
3605
+	 */
3606
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3607
+	{
3608 3608
         
3609
-        $fields                                         = $messenger->get_admin_settings_fields();
3610
-        $settings_template_args['template_form_fields'] = '';
3609
+		$fields                                         = $messenger->get_admin_settings_fields();
3610
+		$settings_template_args['template_form_fields'] = '';
3611 3611
         
3612
-        //is $messenger active?
3613
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3612
+		//is $messenger active?
3613
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3614 3614
         
3615 3615
         
3616
-        if ( ! empty($fields)) {
3616
+		if ( ! empty($fields)) {
3617 3617
             
3618
-            $existing_settings = $messenger->get_existing_admin_settings();
3618
+			$existing_settings = $messenger->get_existing_admin_settings();
3619 3619
             
3620
-            foreach ($fields as $fldname => $fldprops) {
3621
-                $field_id                       = $messenger->name . '-' . $fldname;
3622
-                $template_form_field[$field_id] = array(
3623
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3624
-                    'label'      => $fldprops['label'],
3625
-                    'input'      => $fldprops['field_type'],
3626
-                    'type'       => $fldprops['value_type'],
3627
-                    'required'   => $fldprops['required'],
3628
-                    'validation' => $fldprops['validation'],
3629
-                    'value'      => isset($existing_settings[$field_id])
3630
-                        ? $existing_settings[$field_id]
3631
-                        : $fldprops['default'],
3632
-                    'css_class'  => '',
3633
-                    'format'     => $fldprops['format']
3634
-                );
3635
-            }
3620
+			foreach ($fields as $fldname => $fldprops) {
3621
+				$field_id                       = $messenger->name . '-' . $fldname;
3622
+				$template_form_field[$field_id] = array(
3623
+					'name'       => 'messenger_settings[' . $field_id . ']',
3624
+					'label'      => $fldprops['label'],
3625
+					'input'      => $fldprops['field_type'],
3626
+					'type'       => $fldprops['value_type'],
3627
+					'required'   => $fldprops['required'],
3628
+					'validation' => $fldprops['validation'],
3629
+					'value'      => isset($existing_settings[$field_id])
3630
+						? $existing_settings[$field_id]
3631
+						: $fldprops['default'],
3632
+					'css_class'  => '',
3633
+					'format'     => $fldprops['format']
3634
+				);
3635
+			}
3636 3636
             
3637 3637
             
3638
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3639
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3640
-                : '';
3641
-        }
3642
-        
3643
-        //we also need some hidden fields
3644
-        $settings_template_args['hidden_fields'] = array(
3645
-            'messenger_settings[messenger]' => array(
3646
-                'type'  => 'hidden',
3647
-                'value' => $messenger->name
3648
-            ),
3649
-            'type'                          => array(
3650
-                'type'  => 'hidden',
3651
-                'value' => 'messenger'
3652
-            )
3653
-        );
3654
-        
3655
-        //make sure any active message types that are existing are included in the hidden fields
3656
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3657
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3658
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3659
-                    'type'  => 'hidden',
3660
-                    'value' => $mt
3661
-                );
3662
-            }
3663
-        }
3664
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3665
-            $settings_template_args['hidden_fields'],
3666
-            'array'
3667
-        );
3668
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3669
-        
3670
-        $settings_template_args['messenger']           = $messenger->name;
3671
-        $settings_template_args['description']         = $messenger->description;
3672
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3673
-        
3674
-        
3675
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3676
-            $messenger->name
3677
-        )
3678
-            ? $settings_template_args['show_hide_edit_form']
3679
-            : ' hidden';
3680
-        
3681
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3682
-            ? ' hidden'
3683
-            : $settings_template_args['show_hide_edit_form'];
3684
-        
3685
-        
3686
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3687
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3688
-        $settings_template_args['on_off_status'] = $active ? true : false;
3689
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3690
-        $content                                 = EEH_Template::display_template(
3691
-            $template,
3692
-            $settings_template_args,
3693
-            true
3694
-        );
3695
-        
3696
-        return $content;
3697
-    }
3638
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3639
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3640
+				: '';
3641
+		}
3642
+        
3643
+		//we also need some hidden fields
3644
+		$settings_template_args['hidden_fields'] = array(
3645
+			'messenger_settings[messenger]' => array(
3646
+				'type'  => 'hidden',
3647
+				'value' => $messenger->name
3648
+			),
3649
+			'type'                          => array(
3650
+				'type'  => 'hidden',
3651
+				'value' => 'messenger'
3652
+			)
3653
+		);
3654
+        
3655
+		//make sure any active message types that are existing are included in the hidden fields
3656
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3657
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3658
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3659
+					'type'  => 'hidden',
3660
+					'value' => $mt
3661
+				);
3662
+			}
3663
+		}
3664
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3665
+			$settings_template_args['hidden_fields'],
3666
+			'array'
3667
+		);
3668
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3669
+        
3670
+		$settings_template_args['messenger']           = $messenger->name;
3671
+		$settings_template_args['description']         = $messenger->description;
3672
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3673
+        
3674
+        
3675
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3676
+			$messenger->name
3677
+		)
3678
+			? $settings_template_args['show_hide_edit_form']
3679
+			: ' hidden';
3680
+        
3681
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3682
+			? ' hidden'
3683
+			: $settings_template_args['show_hide_edit_form'];
3684
+        
3685
+        
3686
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3687
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3688
+		$settings_template_args['on_off_status'] = $active ? true : false;
3689
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3690
+		$content                                 = EEH_Template::display_template(
3691
+			$template,
3692
+			$settings_template_args,
3693
+			true
3694
+		);
3695
+        
3696
+		return $content;
3697
+	}
3698 3698
 
3699 3699
 
3700
-    /**
3701
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3702
-     *
3703
-     * @throws DomainException
3704
-     * @throws EE_Error
3705
-     * @throws InvalidDataTypeException
3706
-     * @throws InvalidInterfaceException
3707
-     * @throws InvalidArgumentException
3708
-     * @throws ReflectionException
3709
-     */
3710
-    public function activate_messenger_toggle()
3711
-    {
3712
-        $success = true;
3713
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3714
-        //let's check that we have required data
3715
-        if ( ! isset($this->_req_data['messenger'])) {
3716
-            EE_Error::add_error(
3717
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3718
-                __FILE__,
3719
-                __FUNCTION__,
3720
-                __LINE__
3721
-            );
3722
-            $success = false;
3723
-        }
3724
-        
3725
-        //do a nonce check here since we're not arriving via a normal route
3726
-        $nonce     = isset($this->_req_data['activate_nonce'])
3727
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3728
-            : '';
3729
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3730
-        
3731
-        $this->_verify_nonce($nonce, $nonce_ref);
3732
-        
3733
-        
3734
-        if ( ! isset($this->_req_data['status'])) {
3735
-            EE_Error::add_error(
3736
-                esc_html__(
3737
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3738
-                    'event_espresso'
3739
-                ),
3740
-                __FILE__,
3741
-                __FUNCTION__,
3742
-                __LINE__
3743
-            );
3744
-            $success = false;
3745
-        }
3746
-        
3747
-        //do check to verify we have a valid status.
3748
-        $status = $this->_req_data['status'];
3749
-        
3750
-        if ($status !== 'off' && $status !== 'on') {
3751
-            EE_Error::add_error(
3752
-                sprintf(
3753
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3754
-                    $this->_req_data['status']
3755
-                ),
3756
-                __FILE__,
3757
-                __FUNCTION__,
3758
-                __LINE__
3759
-            );
3760
-            $success = false;
3761
-        }
3762
-        
3763
-        if ($success) {
3764
-            //made it here?  Stop dawdling then!!
3765
-            $success = $status === 'off'
3766
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3767
-                : $this->_activate_messenger($this->_req_data['messenger']);
3768
-        }
3769
-        
3770
-        $this->_template_args['success'] = $success;
3771
-        
3772
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3773
-        $this->_return_json();
3774
-        
3775
-    }
3700
+	/**
3701
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3702
+	 *
3703
+	 * @throws DomainException
3704
+	 * @throws EE_Error
3705
+	 * @throws InvalidDataTypeException
3706
+	 * @throws InvalidInterfaceException
3707
+	 * @throws InvalidArgumentException
3708
+	 * @throws ReflectionException
3709
+	 */
3710
+	public function activate_messenger_toggle()
3711
+	{
3712
+		$success = true;
3713
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3714
+		//let's check that we have required data
3715
+		if ( ! isset($this->_req_data['messenger'])) {
3716
+			EE_Error::add_error(
3717
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3718
+				__FILE__,
3719
+				__FUNCTION__,
3720
+				__LINE__
3721
+			);
3722
+			$success = false;
3723
+		}
3724
+        
3725
+		//do a nonce check here since we're not arriving via a normal route
3726
+		$nonce     = isset($this->_req_data['activate_nonce'])
3727
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3728
+			: '';
3729
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3730
+        
3731
+		$this->_verify_nonce($nonce, $nonce_ref);
3732
+        
3733
+        
3734
+		if ( ! isset($this->_req_data['status'])) {
3735
+			EE_Error::add_error(
3736
+				esc_html__(
3737
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3738
+					'event_espresso'
3739
+				),
3740
+				__FILE__,
3741
+				__FUNCTION__,
3742
+				__LINE__
3743
+			);
3744
+			$success = false;
3745
+		}
3746
+        
3747
+		//do check to verify we have a valid status.
3748
+		$status = $this->_req_data['status'];
3749
+        
3750
+		if ($status !== 'off' && $status !== 'on') {
3751
+			EE_Error::add_error(
3752
+				sprintf(
3753
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3754
+					$this->_req_data['status']
3755
+				),
3756
+				__FILE__,
3757
+				__FUNCTION__,
3758
+				__LINE__
3759
+			);
3760
+			$success = false;
3761
+		}
3762
+        
3763
+		if ($success) {
3764
+			//made it here?  Stop dawdling then!!
3765
+			$success = $status === 'off'
3766
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3767
+				: $this->_activate_messenger($this->_req_data['messenger']);
3768
+		}
3769
+        
3770
+		$this->_template_args['success'] = $success;
3771
+        
3772
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3773
+		$this->_return_json();
3774
+        
3775
+	}
3776 3776
 
3777 3777
 
3778
-    /**
3779
-     * used by ajax from the messages settings page to activate|deactivate a message type
3780
-     *
3781
-     * @throws DomainException
3782
-     * @throws EE_Error
3783
-     * @throws ReflectionException
3784
-     * @throws InvalidDataTypeException
3785
-     * @throws InvalidInterfaceException
3786
-     * @throws InvalidArgumentException
3787
-     */
3788
-    public function activate_mt_toggle()
3789
-    {
3790
-        $success = true;
3791
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3792
-        
3793
-        //let's make sure we have the necessary data
3794
-        if ( ! isset($this->_req_data['message_type'])) {
3795
-            EE_Error::add_error(
3796
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3797
-                __FILE__,
3798
-                __FUNCTION__,
3799
-                __LINE__
3800
-            );
3801
-            $success = false;
3802
-        }
3803
-        
3804
-        if ( ! isset($this->_req_data['messenger'])) {
3805
-            EE_Error::add_error(
3806
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3807
-                __FILE__,
3808
-                __FUNCTION__,
3809
-                __LINE__
3810
-            );
3811
-            $success = false;
3812
-        }
3813
-        
3814
-        if ( ! isset($this->_req_data['status'])) {
3815
-            EE_Error::add_error(
3816
-                esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3817
-                    'event_espresso'),
3818
-                __FILE__,
3819
-                __FUNCTION__,
3820
-                __LINE__
3821
-            );
3822
-            $success = false;
3823
-        }
3824
-        
3825
-        
3826
-        //do check to verify we have a valid status.
3827
-        $status = $this->_req_data['status'];
3828
-        
3829
-        if ($status !== 'activate' && $status !== 'deactivate') {
3830
-            EE_Error::add_error(
3831
-                sprintf(
3832
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3833
-                    $this->_req_data['status']
3834
-                ),
3835
-                __FILE__,
3836
-                __FUNCTION__,
3837
-                __LINE__
3838
-            );
3839
-            $success = false;
3840
-        }
3841
-        
3842
-        
3843
-        //do a nonce check here since we're not arriving via a normal route
3844
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3845
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3846
-        
3847
-        $this->_verify_nonce($nonce, $nonce_ref);
3848
-        
3849
-        if ($success) {
3850
-            //made it here? um, what are you waiting for then?
3851
-            $success = $status === 'deactivate'
3852
-                ? $this->_deactivate_message_type_for_messenger(
3853
-                    $this->_req_data['messenger'],
3854
-                    $this->_req_data['message_type']
3855
-                )
3856
-                : $this->_activate_message_type_for_messenger(
3857
-                    $this->_req_data['messenger'],
3858
-                    $this->_req_data['message_type']
3859
-                );
3860
-        }
3861
-        
3862
-        $this->_template_args['success'] = $success;
3863
-        $this->_return_json();
3864
-    }
3778
+	/**
3779
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3780
+	 *
3781
+	 * @throws DomainException
3782
+	 * @throws EE_Error
3783
+	 * @throws ReflectionException
3784
+	 * @throws InvalidDataTypeException
3785
+	 * @throws InvalidInterfaceException
3786
+	 * @throws InvalidArgumentException
3787
+	 */
3788
+	public function activate_mt_toggle()
3789
+	{
3790
+		$success = true;
3791
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3792
+        
3793
+		//let's make sure we have the necessary data
3794
+		if ( ! isset($this->_req_data['message_type'])) {
3795
+			EE_Error::add_error(
3796
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3797
+				__FILE__,
3798
+				__FUNCTION__,
3799
+				__LINE__
3800
+			);
3801
+			$success = false;
3802
+		}
3803
+        
3804
+		if ( ! isset($this->_req_data['messenger'])) {
3805
+			EE_Error::add_error(
3806
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3807
+				__FILE__,
3808
+				__FUNCTION__,
3809
+				__LINE__
3810
+			);
3811
+			$success = false;
3812
+		}
3813
+        
3814
+		if ( ! isset($this->_req_data['status'])) {
3815
+			EE_Error::add_error(
3816
+				esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3817
+					'event_espresso'),
3818
+				__FILE__,
3819
+				__FUNCTION__,
3820
+				__LINE__
3821
+			);
3822
+			$success = false;
3823
+		}
3824
+        
3825
+        
3826
+		//do check to verify we have a valid status.
3827
+		$status = $this->_req_data['status'];
3828
+        
3829
+		if ($status !== 'activate' && $status !== 'deactivate') {
3830
+			EE_Error::add_error(
3831
+				sprintf(
3832
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3833
+					$this->_req_data['status']
3834
+				),
3835
+				__FILE__,
3836
+				__FUNCTION__,
3837
+				__LINE__
3838
+			);
3839
+			$success = false;
3840
+		}
3841
+        
3842
+        
3843
+		//do a nonce check here since we're not arriving via a normal route
3844
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3845
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3846
+        
3847
+		$this->_verify_nonce($nonce, $nonce_ref);
3848
+        
3849
+		if ($success) {
3850
+			//made it here? um, what are you waiting for then?
3851
+			$success = $status === 'deactivate'
3852
+				? $this->_deactivate_message_type_for_messenger(
3853
+					$this->_req_data['messenger'],
3854
+					$this->_req_data['message_type']
3855
+				)
3856
+				: $this->_activate_message_type_for_messenger(
3857
+					$this->_req_data['messenger'],
3858
+					$this->_req_data['message_type']
3859
+				);
3860
+		}
3861
+        
3862
+		$this->_template_args['success'] = $success;
3863
+		$this->_return_json();
3864
+	}
3865 3865
 
3866 3866
 
3867
-    /**
3868
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3869
-     *
3870
-     * @param string $messenger_name The name of the messenger being activated
3871
-     * @return bool
3872
-     * @throws DomainException
3873
-     * @throws EE_Error
3874
-     * @throws InvalidArgumentException
3875
-     * @throws ReflectionException
3876
-     * @throws InvalidDataTypeException
3877
-     * @throws InvalidInterfaceException
3878
-     */
3879
-    protected function _activate_messenger($messenger_name)
3880
-    {
3881
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3882
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3883
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3884
-            ? $active_messenger->get_default_message_types()
3885
-            : array();
3886
-        
3887
-        //ensure is active
3888
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3889
-        
3890
-        //set response_data for reload
3891
-        foreach ($message_types_to_activate as $message_type_name) {
3892
-            /** @var EE_message_type $message_type */
3893
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3894
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3895
-                    $messenger_name,
3896
-                    $message_type_name
3897
-                )
3898
-                && $message_type instanceof EE_message_type
3899
-            ) {
3900
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3901
-                if ($message_type->get_admin_settings_fields()) {
3902
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3903
-                }
3904
-            }
3905
-        }
3906
-        
3907
-        //add success message for activating messenger
3908
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3909
-        
3910
-    }
3867
+	/**
3868
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3869
+	 *
3870
+	 * @param string $messenger_name The name of the messenger being activated
3871
+	 * @return bool
3872
+	 * @throws DomainException
3873
+	 * @throws EE_Error
3874
+	 * @throws InvalidArgumentException
3875
+	 * @throws ReflectionException
3876
+	 * @throws InvalidDataTypeException
3877
+	 * @throws InvalidInterfaceException
3878
+	 */
3879
+	protected function _activate_messenger($messenger_name)
3880
+	{
3881
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3882
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3883
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3884
+			? $active_messenger->get_default_message_types()
3885
+			: array();
3886
+        
3887
+		//ensure is active
3888
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3889
+        
3890
+		//set response_data for reload
3891
+		foreach ($message_types_to_activate as $message_type_name) {
3892
+			/** @var EE_message_type $message_type */
3893
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3894
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3895
+					$messenger_name,
3896
+					$message_type_name
3897
+				)
3898
+				&& $message_type instanceof EE_message_type
3899
+			) {
3900
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3901
+				if ($message_type->get_admin_settings_fields()) {
3902
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3903
+				}
3904
+			}
3905
+		}
3906
+        
3907
+		//add success message for activating messenger
3908
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3909
+        
3910
+	}
3911 3911
 
3912 3912
 
3913
-    /**
3914
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3915
-     *
3916
-     * @param string $messenger_name The name of the messenger being activated
3917
-     * @return bool
3918
-     * @throws DomainException
3919
-     * @throws EE_Error
3920
-     * @throws InvalidArgumentException
3921
-     * @throws ReflectionException
3922
-     * @throws InvalidDataTypeException
3923
-     * @throws InvalidInterfaceException
3924
-     */
3925
-    protected function _deactivate_messenger($messenger_name)
3926
-    {
3927
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3928
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3929
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3930
-        
3931
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3932
-    }
3913
+	/**
3914
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3915
+	 *
3916
+	 * @param string $messenger_name The name of the messenger being activated
3917
+	 * @return bool
3918
+	 * @throws DomainException
3919
+	 * @throws EE_Error
3920
+	 * @throws InvalidArgumentException
3921
+	 * @throws ReflectionException
3922
+	 * @throws InvalidDataTypeException
3923
+	 * @throws InvalidInterfaceException
3924
+	 */
3925
+	protected function _deactivate_messenger($messenger_name)
3926
+	{
3927
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3928
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3929
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3930
+        
3931
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3932
+	}
3933 3933
 
3934 3934
 
3935
-    /**
3936
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3937
-     *
3938
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3939
-     * @param string $message_type_name The name of the message type being activated for the messenger
3940
-     * @return bool
3941
-     * @throws DomainException
3942
-     * @throws EE_Error
3943
-     * @throws InvalidArgumentException
3944
-     * @throws ReflectionException
3945
-     * @throws InvalidDataTypeException
3946
-     * @throws InvalidInterfaceException
3947
-     */
3948
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3949
-    {
3950
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3951
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3952
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3953
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3954
-        
3955
-        //ensure is active
3956
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3957
-        
3958
-        //set response for load
3959
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3960
-            $message_type_name)
3961
-        ) {
3962
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3963
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3964
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3965
-            }
3966
-        }
3967
-        
3968
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3969
-            $message_type_to_activate);
3970
-    }
3935
+	/**
3936
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3937
+	 *
3938
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3939
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3940
+	 * @return bool
3941
+	 * @throws DomainException
3942
+	 * @throws EE_Error
3943
+	 * @throws InvalidArgumentException
3944
+	 * @throws ReflectionException
3945
+	 * @throws InvalidDataTypeException
3946
+	 * @throws InvalidInterfaceException
3947
+	 */
3948
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3949
+	{
3950
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3951
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3952
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3953
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3954
+        
3955
+		//ensure is active
3956
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3957
+        
3958
+		//set response for load
3959
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3960
+			$message_type_name)
3961
+		) {
3962
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3963
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3964
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3965
+			}
3966
+		}
3967
+        
3968
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3969
+			$message_type_to_activate);
3970
+	}
3971 3971
 
3972 3972
 
3973
-    /**
3974
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3975
-     *
3976
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3977
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3978
-     * @return bool
3979
-     * @throws DomainException
3980
-     * @throws EE_Error
3981
-     * @throws InvalidArgumentException
3982
-     * @throws ReflectionException
3983
-     * @throws InvalidDataTypeException
3984
-     * @throws InvalidInterfaceException
3985
-     */
3986
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3987
-    {
3988
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3989
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3990
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3991
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3992
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3993
-        
3994
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3995
-            $message_type_to_deactivate);
3996
-    }
3973
+	/**
3974
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3975
+	 *
3976
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3977
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3978
+	 * @return bool
3979
+	 * @throws DomainException
3980
+	 * @throws EE_Error
3981
+	 * @throws InvalidArgumentException
3982
+	 * @throws ReflectionException
3983
+	 * @throws InvalidDataTypeException
3984
+	 * @throws InvalidInterfaceException
3985
+	 */
3986
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3987
+	{
3988
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3989
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3990
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3991
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3992
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3993
+        
3994
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3995
+			$message_type_to_deactivate);
3996
+	}
3997 3997
     
3998 3998
     
3999
-    /**
4000
-     * This just initializes the defaults for activating messenger and message type responses.
4001
-     */
4002
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4003
-    {
4004
-        $this->_template_args['data']['active_mts'] = array();
4005
-        $this->_template_args['data']['mt_reload']  = array();
4006
-    }
3999
+	/**
4000
+	 * This just initializes the defaults for activating messenger and message type responses.
4001
+	 */
4002
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4003
+	{
4004
+		$this->_template_args['data']['active_mts'] = array();
4005
+		$this->_template_args['data']['mt_reload']  = array();
4006
+	}
4007 4007
 
4008 4008
 
4009
-    /**
4010
-     * Setup appropriate response for activating a messenger and/or message types
4011
-     *
4012
-     * @param EE_messenger         $messenger
4013
-     * @param EE_message_type|null $message_type
4014
-     * @return bool
4015
-     * @throws DomainException
4016
-     * @throws EE_Error
4017
-     * @throws InvalidArgumentException
4018
-     * @throws ReflectionException
4019
-     * @throws InvalidDataTypeException
4020
-     * @throws InvalidInterfaceException
4021
-     */
4022
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4023
-        $messenger,
4024
-        EE_Message_Type $message_type = null
4025
-    ) {
4026
-        //if $messenger isn't a valid messenger object then get out.
4027
-        if ( ! $messenger instanceof EE_Messenger) {
4028
-            EE_Error::add_error(
4029
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4009
+	/**
4010
+	 * Setup appropriate response for activating a messenger and/or message types
4011
+	 *
4012
+	 * @param EE_messenger         $messenger
4013
+	 * @param EE_message_type|null $message_type
4014
+	 * @return bool
4015
+	 * @throws DomainException
4016
+	 * @throws EE_Error
4017
+	 * @throws InvalidArgumentException
4018
+	 * @throws ReflectionException
4019
+	 * @throws InvalidDataTypeException
4020
+	 * @throws InvalidInterfaceException
4021
+	 */
4022
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4023
+		$messenger,
4024
+		EE_Message_Type $message_type = null
4025
+	) {
4026
+		//if $messenger isn't a valid messenger object then get out.
4027
+		if ( ! $messenger instanceof EE_Messenger) {
4028
+			EE_Error::add_error(
4029
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034 4034
             
4035
-            return false;
4036
-        }
4037
-        //activated
4038
-        if ($this->_template_args['data']['active_mts']) {
4039
-            EE_Error::overwrite_success();
4040
-            //activated a message type with the messenger
4041
-            if ($message_type instanceof EE_message_type) {
4042
-                EE_Error::add_success(
4043
-                    sprintf(
4044
-                        esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4045
-                        ucwords($message_type->label['singular']),
4046
-                        ucwords($messenger->label['singular'])
4047
-                    )
4048
-                );
4035
+			return false;
4036
+		}
4037
+		//activated
4038
+		if ($this->_template_args['data']['active_mts']) {
4039
+			EE_Error::overwrite_success();
4040
+			//activated a message type with the messenger
4041
+			if ($message_type instanceof EE_message_type) {
4042
+				EE_Error::add_success(
4043
+					sprintf(
4044
+						esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4045
+						ucwords($message_type->label['singular']),
4046
+						ucwords($messenger->label['singular'])
4047
+					)
4048
+				);
4049 4049
                 
4050
-                //if message type was invoice then let's make sure we activate the invoice payment method.
4051
-                if ($message_type->name === 'invoice') {
4052
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4053
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4054
-                    if ($pm instanceof EE_Payment_Method) {
4055
-                        EE_Error::add_attention(
4056
-                            esc_html__(
4057
-                                '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.',
4058
-                                'event_espresso'
4059
-                            )
4060
-                        );
4061
-                    }
4062
-                }
4063
-                //just toggles the entire messenger
4064
-            } else {
4065
-                EE_Error::add_success(
4066
-                    sprintf(
4067
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4068
-                        ucwords($messenger->label['singular'])
4069
-                    )
4070
-                );
4071
-            }
4050
+				//if message type was invoice then let's make sure we activate the invoice payment method.
4051
+				if ($message_type->name === 'invoice') {
4052
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4053
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4054
+					if ($pm instanceof EE_Payment_Method) {
4055
+						EE_Error::add_attention(
4056
+							esc_html__(
4057
+								'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.',
4058
+								'event_espresso'
4059
+							)
4060
+						);
4061
+					}
4062
+				}
4063
+				//just toggles the entire messenger
4064
+			} else {
4065
+				EE_Error::add_success(
4066
+					sprintf(
4067
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4068
+						ucwords($messenger->label['singular'])
4069
+					)
4070
+				);
4071
+			}
4072 4072
             
4073
-            return true;
4073
+			return true;
4074 4074
             
4075
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4076
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4077
-            //in which case we just give a success message for the messenger being successfully activated.
4078
-        } else {
4079
-            if ( ! $messenger->get_default_message_types()) {
4080
-                //messenger doesn't have any default message types so still a success.
4081
-                EE_Error::add_success(
4082
-                    sprintf(
4083
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4084
-                        ucwords($messenger->label['singular'])
4085
-                    )
4086
-                );
4075
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4076
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4077
+			//in which case we just give a success message for the messenger being successfully activated.
4078
+		} else {
4079
+			if ( ! $messenger->get_default_message_types()) {
4080
+				//messenger doesn't have any default message types so still a success.
4081
+				EE_Error::add_success(
4082
+					sprintf(
4083
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4084
+						ucwords($messenger->label['singular'])
4085
+					)
4086
+				);
4087 4087
                 
4088
-                return true;
4089
-            } else {
4090
-                EE_Error::add_error(
4091
-                    $message_type instanceof EE_message_type
4092
-                        ? sprintf(
4093
-                        esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4094
-                        ucwords($message_type->label['singular']),
4095
-                        ucwords($messenger->label['singular'])
4096
-                    )
4097
-                        : sprintf(
4098
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4099
-                        ucwords($messenger->label['singular'])
4100
-                    ),
4101
-                    __FILE__,
4102
-                    __FUNCTION__,
4103
-                    __LINE__
4104
-                );
4088
+				return true;
4089
+			} else {
4090
+				EE_Error::add_error(
4091
+					$message_type instanceof EE_message_type
4092
+						? sprintf(
4093
+						esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4094
+						ucwords($message_type->label['singular']),
4095
+						ucwords($messenger->label['singular'])
4096
+					)
4097
+						: sprintf(
4098
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4099
+						ucwords($messenger->label['singular'])
4100
+					),
4101
+					__FILE__,
4102
+					__FUNCTION__,
4103
+					__LINE__
4104
+				);
4105 4105
                 
4106
-                return false;
4107
-            }
4108
-        }
4109
-    }
4106
+				return false;
4107
+			}
4108
+		}
4109
+	}
4110 4110
 
4111 4111
 
4112
-    /**
4113
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4114
-     *
4115
-     * @param EE_messenger         $messenger
4116
-     * @param EE_message_type|null $message_type
4117
-     * @return bool
4118
-     * @throws DomainException
4119
-     * @throws EE_Error
4120
-     * @throws InvalidArgumentException
4121
-     * @throws ReflectionException
4122
-     * @throws InvalidDataTypeException
4123
-     * @throws InvalidInterfaceException
4124
-     */
4125
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4126
-        $messenger,
4127
-        EE_message_type $message_type = null
4128
-    ) {
4129
-        EE_Error::overwrite_success();
4130
-        
4131
-        //if $messenger isn't a valid messenger object then get out.
4132
-        if ( ! $messenger instanceof EE_Messenger) {
4133
-            EE_Error::add_error(
4134
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4135
-                __FILE__,
4136
-                __FUNCTION__,
4137
-                __LINE__
4138
-            );
4112
+	/**
4113
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4114
+	 *
4115
+	 * @param EE_messenger         $messenger
4116
+	 * @param EE_message_type|null $message_type
4117
+	 * @return bool
4118
+	 * @throws DomainException
4119
+	 * @throws EE_Error
4120
+	 * @throws InvalidArgumentException
4121
+	 * @throws ReflectionException
4122
+	 * @throws InvalidDataTypeException
4123
+	 * @throws InvalidInterfaceException
4124
+	 */
4125
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4126
+		$messenger,
4127
+		EE_message_type $message_type = null
4128
+	) {
4129
+		EE_Error::overwrite_success();
4130
+        
4131
+		//if $messenger isn't a valid messenger object then get out.
4132
+		if ( ! $messenger instanceof EE_Messenger) {
4133
+			EE_Error::add_error(
4134
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4135
+				__FILE__,
4136
+				__FUNCTION__,
4137
+				__LINE__
4138
+			);
4139 4139
             
4140
-            return false;
4141
-        }
4142
-        
4143
-        if ($message_type instanceof EE_message_type) {
4144
-            $message_type_name = $message_type->name;
4145
-            EE_Error::add_success(
4146
-                sprintf(
4147
-                    esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4148
-                    ucwords($message_type->label['singular']),
4149
-                    ucwords($messenger->label['singular'])
4150
-                )
4151
-            );
4152
-        } else {
4153
-            $message_type_name = '';
4154
-            EE_Error::add_success(
4155
-                sprintf(
4156
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4157
-                    ucwords($messenger->label['singular'])
4158
-                )
4159
-            );
4160
-        }
4161
-        
4162
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4163
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4164
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4165
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4166
-            if ($count_updated > 0) {
4167
-                $msg = $message_type_name === 'invoice'
4168
-                    ? esc_html__(
4169
-                        '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.',
4170
-                        'event_espresso'
4171
-                    )
4172
-                    : esc_html__(
4173
-                        '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.',
4174
-                        'event_espresso'
4175
-                    );
4176
-                EE_Error::add_attention($msg);
4177
-            }
4178
-        }
4179
-        
4180
-        return true;
4181
-    }
4140
+			return false;
4141
+		}
4142
+        
4143
+		if ($message_type instanceof EE_message_type) {
4144
+			$message_type_name = $message_type->name;
4145
+			EE_Error::add_success(
4146
+				sprintf(
4147
+					esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4148
+					ucwords($message_type->label['singular']),
4149
+					ucwords($messenger->label['singular'])
4150
+				)
4151
+			);
4152
+		} else {
4153
+			$message_type_name = '';
4154
+			EE_Error::add_success(
4155
+				sprintf(
4156
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4157
+					ucwords($messenger->label['singular'])
4158
+				)
4159
+			);
4160
+		}
4161
+        
4162
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4163
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4164
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4165
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4166
+			if ($count_updated > 0) {
4167
+				$msg = $message_type_name === 'invoice'
4168
+					? esc_html__(
4169
+						'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.',
4170
+						'event_espresso'
4171
+					)
4172
+					: esc_html__(
4173
+						'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.',
4174
+						'event_espresso'
4175
+					);
4176
+				EE_Error::add_attention($msg);
4177
+			}
4178
+		}
4179
+        
4180
+		return true;
4181
+	}
4182 4182
 
4183 4183
 
4184
-    /**
4185
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4186
-     *
4187
-     * @throws DomainException
4188
-     */
4189
-    public function update_mt_form()
4190
-    {
4191
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4192
-            EE_Error::add_error(
4193
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4194
-                __FILE__,
4195
-                __FUNCTION__,
4196
-                __LINE__
4197
-            );
4198
-            $this->_return_json();
4199
-        }
4200
-        
4201
-        $message_types = $this->get_installed_message_types();
4202
-        
4203
-        $message_type = $message_types[$this->_req_data['message_type']];
4204
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4205
-        
4206
-        $content                         = $this->_message_type_settings_content(
4207
-            $message_type,
4208
-            $messenger,
4209
-            true
4210
-        );
4211
-        $this->_template_args['success'] = true;
4212
-        $this->_template_args['content'] = $content;
4213
-        $this->_return_json();
4214
-    }
4184
+	/**
4185
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4186
+	 *
4187
+	 * @throws DomainException
4188
+	 */
4189
+	public function update_mt_form()
4190
+	{
4191
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4192
+			EE_Error::add_error(
4193
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4194
+				__FILE__,
4195
+				__FUNCTION__,
4196
+				__LINE__
4197
+			);
4198
+			$this->_return_json();
4199
+		}
4200
+        
4201
+		$message_types = $this->get_installed_message_types();
4202
+        
4203
+		$message_type = $message_types[$this->_req_data['message_type']];
4204
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4205
+        
4206
+		$content                         = $this->_message_type_settings_content(
4207
+			$message_type,
4208
+			$messenger,
4209
+			true
4210
+		);
4211
+		$this->_template_args['success'] = true;
4212
+		$this->_template_args['content'] = $content;
4213
+		$this->_return_json();
4214
+	}
4215 4215
     
4216 4216
     
4217
-    /**
4218
-     * this handles saving the settings for a messenger or message type
4219
-     *
4220
-     */
4221
-    public function save_settings()
4222
-    {
4223
-        if ( ! isset($this->_req_data['type'])) {
4224
-            EE_Error::add_error(
4225
-                esc_html__(
4226
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4227
-                    'event_espresso'
4228
-                ),
4229
-                __FILE__,
4230
-                __FUNCTION__,
4231
-                __LINE__
4232
-            );
4233
-            $this->_template_args['error'] = true;
4234
-            $this->_return_json();
4235
-        }
4236
-        
4237
-        
4238
-        if ($this->_req_data['type'] === 'messenger') {
4239
-            //this should be an array.
4240
-            $settings  = $this->_req_data['messenger_settings'];
4241
-            $messenger = $settings['messenger'];
4242
-            //let's setup the settings data
4243
-            foreach ($settings as $key => $value) {
4244
-                switch ($key) {
4245
-                    case 'messenger' :
4246
-                        unset($settings['messenger']);
4247
-                        break;
4248
-                    case 'message_types' :
4249
-                        unset($settings['message_types']);
4250
-                        break;
4251
-                    default :
4252
-                        $settings[$key] = $value;
4253
-                        break;
4254
-                }
4255
-            }
4256
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4257
-        } elseif ($this->_req_data['type'] === 'message_type') {
4258
-            $settings     = $this->_req_data['message_type_settings'];
4259
-            $messenger    = $settings['messenger'];
4260
-            $message_type = $settings['message_type'];
4217
+	/**
4218
+	 * this handles saving the settings for a messenger or message type
4219
+	 *
4220
+	 */
4221
+	public function save_settings()
4222
+	{
4223
+		if ( ! isset($this->_req_data['type'])) {
4224
+			EE_Error::add_error(
4225
+				esc_html__(
4226
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4227
+					'event_espresso'
4228
+				),
4229
+				__FILE__,
4230
+				__FUNCTION__,
4231
+				__LINE__
4232
+			);
4233
+			$this->_template_args['error'] = true;
4234
+			$this->_return_json();
4235
+		}
4236
+        
4237
+        
4238
+		if ($this->_req_data['type'] === 'messenger') {
4239
+			//this should be an array.
4240
+			$settings  = $this->_req_data['messenger_settings'];
4241
+			$messenger = $settings['messenger'];
4242
+			//let's setup the settings data
4243
+			foreach ($settings as $key => $value) {
4244
+				switch ($key) {
4245
+					case 'messenger' :
4246
+						unset($settings['messenger']);
4247
+						break;
4248
+					case 'message_types' :
4249
+						unset($settings['message_types']);
4250
+						break;
4251
+					default :
4252
+						$settings[$key] = $value;
4253
+						break;
4254
+				}
4255
+			}
4256
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4257
+		} elseif ($this->_req_data['type'] === 'message_type') {
4258
+			$settings     = $this->_req_data['message_type_settings'];
4259
+			$messenger    = $settings['messenger'];
4260
+			$message_type = $settings['message_type'];
4261 4261
             
4262
-            foreach ($settings as $key => $value) {
4263
-                switch ($key) {
4264
-                    case 'messenger' :
4265
-                        unset($settings['messenger']);
4266
-                        break;
4267
-                    case 'message_type' :
4268
-                        unset($settings['message_type']);
4269
-                        break;
4270
-                    default :
4271
-                        $settings[$key] = $value;
4272
-                        break;
4273
-                }
4274
-            }
4262
+			foreach ($settings as $key => $value) {
4263
+				switch ($key) {
4264
+					case 'messenger' :
4265
+						unset($settings['messenger']);
4266
+						break;
4267
+					case 'message_type' :
4268
+						unset($settings['message_type']);
4269
+						break;
4270
+					default :
4271
+						$settings[$key] = $value;
4272
+						break;
4273
+				}
4274
+			}
4275 4275
             
4276
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4277
-        }
4278
-        
4279
-        //okay we should have the data all setup.  Now we just update!
4280
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4281
-        
4282
-        if ($success) {
4283
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4284
-        } else {
4285
-            EE_Error::add_error(
4286
-                esc_html__(
4287
-                    'Settings did not get updated',
4288
-                    'event_espresso'
4289
-                ),
4290
-                __FILE__,
4291
-                __FUNCTION__,
4292
-                __LINE__
4293
-            );
4294
-        }
4295
-        
4296
-        $this->_template_args['success'] = $success;
4297
-        $this->_return_json();
4298
-    }
4276
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4277
+		}
4278
+        
4279
+		//okay we should have the data all setup.  Now we just update!
4280
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4281
+        
4282
+		if ($success) {
4283
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4284
+		} else {
4285
+			EE_Error::add_error(
4286
+				esc_html__(
4287
+					'Settings did not get updated',
4288
+					'event_espresso'
4289
+				),
4290
+				__FILE__,
4291
+				__FUNCTION__,
4292
+				__LINE__
4293
+			);
4294
+		}
4295
+        
4296
+		$this->_template_args['success'] = $success;
4297
+		$this->_return_json();
4298
+	}
4299 4299
     
4300 4300
     
4301 4301
     
4302 4302
     
4303
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4303
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4304 4304
 
4305 4305
 
4306
-    /**
4307
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4308
-     * However, this does not send immediately, it just queues for sending.
4309
-     *
4310
-     * @since 4.9.0
4311
-     * @throws EE_Error
4312
-     * @throws InvalidDataTypeException
4313
-     * @throws InvalidInterfaceException
4314
-     * @throws InvalidArgumentException
4315
-     * @throws ReflectionException
4316
-     */
4317
-    protected function _generate_now()
4318
-    {
4319
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4320
-        $this->_redirect_after_action(false, '', '', array(), true);
4321
-    }
4306
+	/**
4307
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4308
+	 * However, this does not send immediately, it just queues for sending.
4309
+	 *
4310
+	 * @since 4.9.0
4311
+	 * @throws EE_Error
4312
+	 * @throws InvalidDataTypeException
4313
+	 * @throws InvalidInterfaceException
4314
+	 * @throws InvalidArgumentException
4315
+	 * @throws ReflectionException
4316
+	 */
4317
+	protected function _generate_now()
4318
+	{
4319
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4320
+		$this->_redirect_after_action(false, '', '', array(), true);
4321
+	}
4322 4322
 
4323 4323
 
4324
-    /**
4325
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4326
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4327
-     *
4328
-     * @since 4.9.0
4329
-     * @throws EE_Error
4330
-     * @throws InvalidDataTypeException
4331
-     * @throws InvalidInterfaceException
4332
-     * @throws InvalidArgumentException
4333
-     * @throws ReflectionException
4334
-     */
4335
-    protected function _generate_and_send_now()
4336
-    {
4337
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4338
-        $this->_redirect_after_action(false, '', '', array(), true);
4339
-    }
4324
+	/**
4325
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4326
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4327
+	 *
4328
+	 * @since 4.9.0
4329
+	 * @throws EE_Error
4330
+	 * @throws InvalidDataTypeException
4331
+	 * @throws InvalidInterfaceException
4332
+	 * @throws InvalidArgumentException
4333
+	 * @throws ReflectionException
4334
+	 */
4335
+	protected function _generate_and_send_now()
4336
+	{
4337
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4338
+		$this->_redirect_after_action(false, '', '', array(), true);
4339
+	}
4340 4340
 
4341 4341
 
4342
-    /**
4343
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4344
-     *
4345
-     * @since 4.9.0
4346
-     * @throws EE_Error
4347
-     * @throws InvalidDataTypeException
4348
-     * @throws InvalidInterfaceException
4349
-     * @throws InvalidArgumentException
4350
-     * @throws ReflectionException
4351
-     */
4352
-    protected function _queue_for_resending()
4353
-    {
4354
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4355
-        $this->_redirect_after_action(false, '', '', array(), true);
4356
-    }
4342
+	/**
4343
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4344
+	 *
4345
+	 * @since 4.9.0
4346
+	 * @throws EE_Error
4347
+	 * @throws InvalidDataTypeException
4348
+	 * @throws InvalidInterfaceException
4349
+	 * @throws InvalidArgumentException
4350
+	 * @throws ReflectionException
4351
+	 */
4352
+	protected function _queue_for_resending()
4353
+	{
4354
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4355
+		$this->_redirect_after_action(false, '', '', array(), true);
4356
+	}
4357 4357
 
4358 4358
 
4359
-    /**
4360
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4361
-     *
4362
-     * @since 4.9.0
4363
-     * @throws EE_Error
4364
-     * @throws InvalidDataTypeException
4365
-     * @throws InvalidInterfaceException
4366
-     * @throws InvalidArgumentException
4367
-     * @throws ReflectionException
4368
-     */
4369
-    protected function _send_now()
4370
-    {
4371
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4372
-        $this->_redirect_after_action(false, '', '', array(), true);
4373
-    }
4359
+	/**
4360
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4361
+	 *
4362
+	 * @since 4.9.0
4363
+	 * @throws EE_Error
4364
+	 * @throws InvalidDataTypeException
4365
+	 * @throws InvalidInterfaceException
4366
+	 * @throws InvalidArgumentException
4367
+	 * @throws ReflectionException
4368
+	 */
4369
+	protected function _send_now()
4370
+	{
4371
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4372
+		$this->_redirect_after_action(false, '', '', array(), true);
4373
+	}
4374 4374
 
4375 4375
 
4376
-    /**
4377
-     * Deletes EE_messages for IDs in the request.
4378
-     *
4379
-     * @since 4.9.0
4380
-     * @throws EE_Error
4381
-     * @throws InvalidDataTypeException
4382
-     * @throws InvalidInterfaceException
4383
-     * @throws InvalidArgumentException
4384
-     */
4385
-    protected function _delete_ee_messages()
4386
-    {
4387
-        $msg_ids       = $this->_get_msg_ids_from_request();
4388
-        $deleted_count = 0;
4389
-        foreach ($msg_ids as $msg_id) {
4390
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4391
-                $deleted_count++;
4392
-            }
4393
-        }
4394
-        if ($deleted_count) {
4395
-            $this->_redirect_after_action(
4396
-                true,
4397
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
4398
-                esc_html__('deleted', 'event_espresso')
4399
-            );
4400
-        } else {
4401
-            EE_Error::add_error(
4402
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4403
-                __FILE__, __FUNCTION__, __LINE__
4404
-            );
4405
-            $this->_redirect_after_action(false, '', '', array(), true);
4406
-        }
4407
-    }
4376
+	/**
4377
+	 * Deletes EE_messages for IDs in the request.
4378
+	 *
4379
+	 * @since 4.9.0
4380
+	 * @throws EE_Error
4381
+	 * @throws InvalidDataTypeException
4382
+	 * @throws InvalidInterfaceException
4383
+	 * @throws InvalidArgumentException
4384
+	 */
4385
+	protected function _delete_ee_messages()
4386
+	{
4387
+		$msg_ids       = $this->_get_msg_ids_from_request();
4388
+		$deleted_count = 0;
4389
+		foreach ($msg_ids as $msg_id) {
4390
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4391
+				$deleted_count++;
4392
+			}
4393
+		}
4394
+		if ($deleted_count) {
4395
+			$this->_redirect_after_action(
4396
+				true,
4397
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
4398
+				esc_html__('deleted', 'event_espresso')
4399
+			);
4400
+		} else {
4401
+			EE_Error::add_error(
4402
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4403
+				__FILE__, __FUNCTION__, __LINE__
4404
+			);
4405
+			$this->_redirect_after_action(false, '', '', array(), true);
4406
+		}
4407
+	}
4408 4408
     
4409 4409
     
4410
-    /**
4411
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4412
-     * @since 4.9.0
4413
-     * @return array
4414
-     */
4415
-    protected function _get_msg_ids_from_request()
4416
-    {
4417
-        if ( ! isset($this->_req_data['MSG_ID'])) {
4418
-            return array();
4419
-        }
4420
-        
4421
-        return is_array($this->_req_data['MSG_ID'])
4422
-            ? array_keys($this->_req_data['MSG_ID'])
4423
-            : array($this->_req_data['MSG_ID']);
4424
-    }
4410
+	/**
4411
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4412
+	 * @since 4.9.0
4413
+	 * @return array
4414
+	 */
4415
+	protected function _get_msg_ids_from_request()
4416
+	{
4417
+		if ( ! isset($this->_req_data['MSG_ID'])) {
4418
+			return array();
4419
+		}
4420
+        
4421
+		return is_array($this->_req_data['MSG_ID'])
4422
+			? array_keys($this->_req_data['MSG_ID'])
4423
+			: array($this->_req_data['MSG_ID']);
4424
+	}
4425 4425
 }
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 
54 54
     /**
55 55
      * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
56
-     * @param $callbacks
56
+     * @param callable[] $callbacks
57 57
      * @return array
58 58
      */
59 59
     public function modify_callbacks($callbacks)
Please login to merge, or discard this patch.
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -18,207 +18,207 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @var EE_Event|null
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    protected function _set_hooks_properties()
28
-    {
29
-
30
-        $this->_name      = 'registration_form';
31
-        $this->_metaboxes = array(
32
-            0 => array(
33
-                'page_route' => array('edit', 'create_new'),
34
-                'func'       => 'primary_questions',
35
-                'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
36
-                'priority'   => 'default',
37
-                'context'    => 'side',
38
-            ),
39
-        );
40
-
41
-        //hook into the handler for saving question groups
42
-        add_filter(
43
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
44
-            array($this, 'modify_callbacks'),
45
-            10
46
-        );
47
-
48
-        //hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
49
-        //restricted by page)
50
-        add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2);
51
-    }
52
-
53
-
54
-    /**
55
-     * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
56
-     * @param $callbacks
57
-     * @return array
58
-     */
59
-    public function modify_callbacks($callbacks)
60
-    {
61
-        //now let's add the question group callback
62
-        $callbacks[] = array($this, 'primary_question_group_update');
63
-        return $callbacks;
64
-    }
65
-
66
-
67
-    /**
68
-     * Hooked into revision restores.
69
-     * @param $post_id
70
-     * @param $revision_id
71
-     * @return EE_Base_Class
72
-     * @throws EE_Error
73
-     * @throws InvalidArgumentException
74
-     * @throws ReflectionException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     */
78
-    public function restore_revision($post_id, $revision_id)
79
-    {
80
-        $EVT_MDL  = EE_Registry::instance()->load_model('Event');
81
-        $post_evt = $EVT_MDL->get_one_by_ID($post_id);
82
-        //restore revision for primary questions
83
-        $post_evt->restore_revision(
84
-            $revision_id,
85
-            array('Question_Group'),
86
-            array('Question_Group' => array('Event_Question_Group.EQG_primary' => 1))
87
-        );
88
-        return $post_evt;
89
-    }
90
-
91
-
92
-    /**
93
-     * Content of metabox.
94
-     * @param $post_id
95
-     * @param $post
96
-     * @throws EE_Error
97
-     * @throws InvalidArgumentException
98
-     * @throws InvalidDataTypeException
99
-     * @throws InvalidInterfaceException
100
-     */
101
-    public function primary_questions($post_id, $post)
102
-    {
103
-        $this->_event = $this->_adminpage_obj->get_event_object();
104
-        $event_id     = $this->_event->ID();
105
-        ?>
21
+	/**
22
+	 * @var EE_Event|null
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	protected function _set_hooks_properties()
28
+	{
29
+
30
+		$this->_name      = 'registration_form';
31
+		$this->_metaboxes = array(
32
+			0 => array(
33
+				'page_route' => array('edit', 'create_new'),
34
+				'func'       => 'primary_questions',
35
+				'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
36
+				'priority'   => 'default',
37
+				'context'    => 'side',
38
+			),
39
+		);
40
+
41
+		//hook into the handler for saving question groups
42
+		add_filter(
43
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
44
+			array($this, 'modify_callbacks'),
45
+			10
46
+		);
47
+
48
+		//hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
49
+		//restricted by page)
50
+		add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2);
51
+	}
52
+
53
+
54
+	/**
55
+	 * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
56
+	 * @param $callbacks
57
+	 * @return array
58
+	 */
59
+	public function modify_callbacks($callbacks)
60
+	{
61
+		//now let's add the question group callback
62
+		$callbacks[] = array($this, 'primary_question_group_update');
63
+		return $callbacks;
64
+	}
65
+
66
+
67
+	/**
68
+	 * Hooked into revision restores.
69
+	 * @param $post_id
70
+	 * @param $revision_id
71
+	 * @return EE_Base_Class
72
+	 * @throws EE_Error
73
+	 * @throws InvalidArgumentException
74
+	 * @throws ReflectionException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 */
78
+	public function restore_revision($post_id, $revision_id)
79
+	{
80
+		$EVT_MDL  = EE_Registry::instance()->load_model('Event');
81
+		$post_evt = $EVT_MDL->get_one_by_ID($post_id);
82
+		//restore revision for primary questions
83
+		$post_evt->restore_revision(
84
+			$revision_id,
85
+			array('Question_Group'),
86
+			array('Question_Group' => array('Event_Question_Group.EQG_primary' => 1))
87
+		);
88
+		return $post_evt;
89
+	}
90
+
91
+
92
+	/**
93
+	 * Content of metabox.
94
+	 * @param $post_id
95
+	 * @param $post
96
+	 * @throws EE_Error
97
+	 * @throws InvalidArgumentException
98
+	 * @throws InvalidDataTypeException
99
+	 * @throws InvalidInterfaceException
100
+	 */
101
+	public function primary_questions($post_id, $post)
102
+	{
103
+		$this->_event = $this->_adminpage_obj->get_event_object();
104
+		$event_id     = $this->_event->ID();
105
+		?>
106 106
         <div class="inside">
107 107
             <p><strong>
108 108
                     <?php _e('Question Groups', 'event_espresso'); ?>
109 109
                 </strong><br/>
110 110
                 <?php
111
-                    printf(
112
-                        esc_html__(
113
-                            'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
114
-                            'event_espresso'
115
-                        ),
116
-                        '<a href="admin.php?page=espresso_registration_form" target="_blank">',
117
-                        '</a>'
118
-                    )
119
-                ?>
111
+					printf(
112
+						esc_html__(
113
+							'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
114
+							'event_espresso'
115
+						),
116
+						'<a href="admin.php?page=espresso_registration_form" target="_blank">',
117
+						'</a>'
118
+					)
119
+				?>
120 120
             </p>
121 121
             <?php
122 122
 
123
-            $qsg_where['QSG_deleted'] = false;
124
-            $query_params             = apply_filters(
125
-                'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
126
-                array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
127
-            );
128
-            $QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
129
-            $EQGs                     = ! empty($event_id)
130
-                ? $this->_event->get_many_related(
131
-                    'Question_Group',
132
-                    array(array('Event_Question_Group.EQG_primary' => 1))
133
-                )
134
-                : array();
135
-            $EQGids                   = array_keys($EQGs);
136
-
137
-            if (! empty($QSGs)) {
138
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
139
-                foreach ($QSGs as $QSG) {
140
-                    $checked         = in_array($QSG->ID(), $EQGids, true)
141
-                                       || $QSG->get('QSG_system') === 1
142
-                        ? ' checked="checked"'
143
-                        : '';
144
-                    $visibility      = $QSG->get('QSG_system') === 1
145
-                        ? ' style="visibility:hidden"'
146
-                        : '';
147
-                    $edit_query_args = $this->_adminpage_obj->is_caf() ? array(
148
-                        'action' => 'edit_question_group',
149
-                        'QSG_ID' => $QSG->ID(),
150
-                    ) : array('action' => 'question_groups');
151
-                    $edit_link       = EE_Admin_Page::add_query_args_and_nonce(
152
-                        $edit_query_args,
153
-                        EE_FORMS_ADMIN_URL
154
-                    );
155
-
156
-                    $html .= '
123
+			$qsg_where['QSG_deleted'] = false;
124
+			$query_params             = apply_filters(
125
+				'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
126
+				array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
127
+			);
128
+			$QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
129
+			$EQGs                     = ! empty($event_id)
130
+				? $this->_event->get_many_related(
131
+					'Question_Group',
132
+					array(array('Event_Question_Group.EQG_primary' => 1))
133
+				)
134
+				: array();
135
+			$EQGids                   = array_keys($EQGs);
136
+
137
+			if (! empty($QSGs)) {
138
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
139
+				foreach ($QSGs as $QSG) {
140
+					$checked         = in_array($QSG->ID(), $EQGids, true)
141
+									   || $QSG->get('QSG_system') === 1
142
+						? ' checked="checked"'
143
+						: '';
144
+					$visibility      = $QSG->get('QSG_system') === 1
145
+						? ' style="visibility:hidden"'
146
+						: '';
147
+					$edit_query_args = $this->_adminpage_obj->is_caf() ? array(
148
+						'action' => 'edit_question_group',
149
+						'QSG_ID' => $QSG->ID(),
150
+					) : array('action' => 'question_groups');
151
+					$edit_link       = EE_Admin_Page::add_query_args_and_nonce(
152
+						$edit_query_args,
153
+						EE_FORMS_ADMIN_URL
154
+					);
155
+
156
+					$html .= '
157 157
 					<p id="event-question-group-' . $QSG->ID() . '">
158 158
 						<input value="' . $QSG->ID() . '" type="checkbox"'
159
-                             . $visibility
160
-                             . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' />
159
+							 . $visibility
160
+							 . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' />
161 161
 						<a href="' . $edit_link . '" title="'
162
-                             . sprintf(
163
-                                 esc_attr__('Edit %s Group', 'event_espresso'),
164
-                                 $QSG->get('QSG_name')
165
-                             )
166
-                             . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
162
+							 . sprintf(
163
+								 esc_attr__('Edit %s Group', 'event_espresso'),
164
+								 $QSG->get('QSG_name')
165
+							 )
166
+							 . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
167 167
 					</p>';
168
-                }
169
-                $html .= count($QSGs) > 10 ? '</div>' : '';
170
-
171
-                echo $html;
172
-            } else {
173
-                 esc_html_e(
174
-                     'There seems to be a problem with your questions. Please contact [email protected]',
175
-                     'event_espresso'
176
-                 );
177
-            }
178
-            do_action('AHEE_event_editor_questions_notice');
179
-            ?>
168
+				}
169
+				$html .= count($QSGs) > 10 ? '</div>' : '';
170
+
171
+				echo $html;
172
+			} else {
173
+				 esc_html_e(
174
+					 'There seems to be a problem with your questions. Please contact [email protected]',
175
+					 'event_espresso'
176
+				 );
177
+			}
178
+			do_action('AHEE_event_editor_questions_notice');
179
+			?>
180 180
         </div>
181 181
         <?php
182
-    }
183
-
184
-
185
-    /**
186
-     * @param EE_Event $evtobj
187
-     * @param array    $data
188
-     * @return bool
189
-     * @throws EE_Error
190
-     */
191
-    public function primary_question_group_update($evtobj, $data)
192
-    {
193
-        $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array();
194
-        $added_qgs       = array_keys($question_groups);
195
-        $success         = array();
196
-
197
-        //let's get all current question groups associated with this event.
198
-        $current_qgs = $evtobj->get_many_related(
199
-            'Question_Group',
200
-            array(array('Event_Question_Group.EQG_primary' => 1))
201
-        );
202
-        $current_qgs = array_keys($current_qgs); //we just want the ids
203
-
204
-        //now let's get the groups selected in the editor and update (IF we have data)
205
-        if (! empty($question_groups)) {
206
-            foreach ($question_groups as $id => $val) {
207
-                //add to event
208
-                if ($val) {
209
-                    $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 1));
210
-                }
211
-                $success[] = ! empty($qg) ? 1 : 0;
212
-            }
213
-        }
214
-
215
-        //wait a minute... are there question groups missing in the saved groups that ARE with the current event?
216
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
217
-
218
-        foreach ($removed_qgs as $qgid) {
219
-            $qg        = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 1));
220
-            $success[] = ! empty($qg) ? 1 : 0;
221
-        }
222
-        return in_array(0, $success, true) ? false : true;
223
-    }
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param EE_Event $evtobj
187
+	 * @param array    $data
188
+	 * @return bool
189
+	 * @throws EE_Error
190
+	 */
191
+	public function primary_question_group_update($evtobj, $data)
192
+	{
193
+		$question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array();
194
+		$added_qgs       = array_keys($question_groups);
195
+		$success         = array();
196
+
197
+		//let's get all current question groups associated with this event.
198
+		$current_qgs = $evtobj->get_many_related(
199
+			'Question_Group',
200
+			array(array('Event_Question_Group.EQG_primary' => 1))
201
+		);
202
+		$current_qgs = array_keys($current_qgs); //we just want the ids
203
+
204
+		//now let's get the groups selected in the editor and update (IF we have data)
205
+		if (! empty($question_groups)) {
206
+			foreach ($question_groups as $id => $val) {
207
+				//add to event
208
+				if ($val) {
209
+					$qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 1));
210
+				}
211
+				$success[] = ! empty($qg) ? 1 : 0;
212
+			}
213
+		}
214
+
215
+		//wait a minute... are there question groups missing in the saved groups that ARE with the current event?
216
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
217
+
218
+		foreach ($removed_qgs as $qgid) {
219
+			$qg        = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 1));
220
+			$success[] = ! empty($qg) ? 1 : 0;
221
+		}
222
+		return in_array(0, $success, true) ? false : true;
223
+	}
224 224
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
                     array(array('Event_Question_Group.EQG_primary' => 1))
133 133
                 )
134 134
                 : array();
135
-            $EQGids                   = array_keys($EQGs);
135
+            $EQGids = array_keys($EQGs);
136 136
 
137
-            if (! empty($QSGs)) {
137
+            if ( ! empty($QSGs)) {
138 138
                 $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
139 139
                 foreach ($QSGs as $QSG) {
140
-                    $checked         = in_array($QSG->ID(), $EQGids, true)
140
+                    $checked = in_array($QSG->ID(), $EQGids, true)
141 141
                                        || $QSG->get('QSG_system') === 1
142 142
                         ? ' checked="checked"'
143 143
                         : '';
@@ -148,22 +148,22 @@  discard block
 block discarded – undo
148 148
                         'action' => 'edit_question_group',
149 149
                         'QSG_ID' => $QSG->ID(),
150 150
                     ) : array('action' => 'question_groups');
151
-                    $edit_link       = EE_Admin_Page::add_query_args_and_nonce(
151
+                    $edit_link = EE_Admin_Page::add_query_args_and_nonce(
152 152
                         $edit_query_args,
153 153
                         EE_FORMS_ADMIN_URL
154 154
                     );
155 155
 
156 156
                     $html .= '
157
-					<p id="event-question-group-' . $QSG->ID() . '">
158
-						<input value="' . $QSG->ID() . '" type="checkbox"'
157
+					<p id="event-question-group-' . $QSG->ID().'">
158
+						<input value="' . $QSG->ID().'" type="checkbox"'
159 159
                              . $visibility
160
-                             . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' />
161
-						<a href="' . $edit_link . '" title="'
160
+                             . ' name="question_groups['.$QSG->ID().']"'.$checked.' />
161
+						<a href="' . $edit_link.'" title="'
162 162
                              . sprintf(
163 163
                                  esc_attr__('Edit %s Group', 'event_espresso'),
164 164
                                  $QSG->get('QSG_name')
165 165
                              )
166
-                             . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
166
+                             . '" target="_blank">'.$QSG->get('QSG_name').'</a>
167 167
 					</p>';
168 168
                 }
169 169
                 $html .= count($QSGs) > 10 ? '</div>' : '';
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      */
191 191
     public function primary_question_group_update($evtobj, $data)
192 192
     {
193
-        $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array();
193
+        $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array();
194 194
         $added_qgs       = array_keys($question_groups);
195 195
         $success         = array();
196 196
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
         $current_qgs = array_keys($current_qgs); //we just want the ids
203 203
 
204 204
         //now let's get the groups selected in the editor and update (IF we have data)
205
-        if (! empty($question_groups)) {
205
+        if ( ! empty($question_groups)) {
206 206
             foreach ($question_groups as $id => $val) {
207 207
                 //add to event
208 208
                 if ($val) {
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks_Extend.class.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -17,208 +17,208 @@
 block discarded – undo
17 17
 class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks
18 18
 {
19 19
     
20
-    /**
21
-     * extending the properties set in espresso_events_Registration_From_Hooks
22
-     *
23
-     * @access protected
24
-     * @return void
25
-     */
26
-    protected function _extend_properties()
27
-    {
28
-        $this->_metaboxes      = array_merge(
29
-            $this->_metaboxes,
30
-            array(
31
-                1 => array(
32
-                    'page_route' => array('create_new', 'edit'),
33
-                    'func'       => 'additional_questions',
34
-                    'label'      => esc_html__('Questions for Additional Registrants', 'event_espresso'),
35
-                    'priority'   => 'default',
36
-                    'context'    => 'side',
37
-                ),
38
-            )
39
-        );
40
-        $this->_scripts_styles = array(
41
-            'registers' => array(
42
-                'extended-event-editor' => array(
43
-                    'url'     => EE_CORE_CAF_ADMIN_EXTEND_URL
44
-                                 . 'registration_form/assets/event-editor-question-groups.js',
45
-                    'depends' => array('jquery'),
46
-                ),
47
-            ),
48
-            'enqueues'  => array(
49
-                'extended-event-editor' => array('edit', 'create_new'),
50
-            ),
51
-        );
52
-    }
53
-
54
-
55
-    /**
56
-     * @param Callable[] $callbacks
57
-     * @return array
58
-     */
59
-    public function modify_callbacks($callbacks)
60
-    {
61
-        $callbacks   = parent::modify_callbacks($callbacks);
62
-        $callbacks[] = array($this, 'additional_question_group_update');
63
-        return $callbacks;
64
-    }
65
-
66
-
67
-    /**
68
-     * Call back hooked into revision restores.
69
-     *
70
-     * @param $post_id
71
-     * @param $revision_id
72
-     * @return EE_Base_Class|void
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws ReflectionException
78
-     */
79
-    public function restore_revision($post_id, $revision_id)
80
-    {
81
-        $post_evt = parent::restore_revision($post_id, $revision_id);
82
-
83
-        //restore revision for additional questions
84
-        $post_evt->restore_revision(
85
-            $revision_id,
86
-            array('Question_Group'),
87
-            array('Question_Group' => array('Event_Question_Group.EQG_primary' => 0)
88
-            )
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * @param $post_id
95
-     * @param $post
96
-     * @throws EE_Error
97
-     * @throws InvalidArgumentException
98
-     * @throws InvalidDataTypeException
99
-     * @throws InvalidInterfaceException
100
-     */
101
-    public function additional_questions($post_id, $post)
102
-    {
103
-        $this->_event = $this->_adminpage_obj->get_event_object();
104
-        $event_id     = $this->_event->ID();
105
-        ?>
20
+	/**
21
+	 * extending the properties set in espresso_events_Registration_From_Hooks
22
+	 *
23
+	 * @access protected
24
+	 * @return void
25
+	 */
26
+	protected function _extend_properties()
27
+	{
28
+		$this->_metaboxes      = array_merge(
29
+			$this->_metaboxes,
30
+			array(
31
+				1 => array(
32
+					'page_route' => array('create_new', 'edit'),
33
+					'func'       => 'additional_questions',
34
+					'label'      => esc_html__('Questions for Additional Registrants', 'event_espresso'),
35
+					'priority'   => 'default',
36
+					'context'    => 'side',
37
+				),
38
+			)
39
+		);
40
+		$this->_scripts_styles = array(
41
+			'registers' => array(
42
+				'extended-event-editor' => array(
43
+					'url'     => EE_CORE_CAF_ADMIN_EXTEND_URL
44
+								 . 'registration_form/assets/event-editor-question-groups.js',
45
+					'depends' => array('jquery'),
46
+				),
47
+			),
48
+			'enqueues'  => array(
49
+				'extended-event-editor' => array('edit', 'create_new'),
50
+			),
51
+		);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param Callable[] $callbacks
57
+	 * @return array
58
+	 */
59
+	public function modify_callbacks($callbacks)
60
+	{
61
+		$callbacks   = parent::modify_callbacks($callbacks);
62
+		$callbacks[] = array($this, 'additional_question_group_update');
63
+		return $callbacks;
64
+	}
65
+
66
+
67
+	/**
68
+	 * Call back hooked into revision restores.
69
+	 *
70
+	 * @param $post_id
71
+	 * @param $revision_id
72
+	 * @return EE_Base_Class|void
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws ReflectionException
78
+	 */
79
+	public function restore_revision($post_id, $revision_id)
80
+	{
81
+		$post_evt = parent::restore_revision($post_id, $revision_id);
82
+
83
+		//restore revision for additional questions
84
+		$post_evt->restore_revision(
85
+			$revision_id,
86
+			array('Question_Group'),
87
+			array('Question_Group' => array('Event_Question_Group.EQG_primary' => 0)
88
+			)
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @param $post_id
95
+	 * @param $post
96
+	 * @throws EE_Error
97
+	 * @throws InvalidArgumentException
98
+	 * @throws InvalidDataTypeException
99
+	 * @throws InvalidInterfaceException
100
+	 */
101
+	public function additional_questions($post_id, $post)
102
+	{
103
+		$this->_event = $this->_adminpage_obj->get_event_object();
104
+		$event_id     = $this->_event->ID();
105
+		?>
106 106
         <div class="inside">
107 107
             <p><strong>
108 108
                     <?php _e('Question Groups', 'event_espresso'); ?>
109 109
                 </strong><br/>
110 110
                 <?php
111
-                    printf(
112
-                        esc_html__(
113
-                            'Add a pre-populated %1$sgroup of questions%2$s to your event.',
114
-                            'event_espresso'
115
-                        ),
116
-                        '<a href="admin.php?page=espresso_registration_form" target="_blank">',
117
-                        '</a>'
118
-                    );
119
-                ?>
111
+					printf(
112
+						esc_html__(
113
+							'Add a pre-populated %1$sgroup of questions%2$s to your event.',
114
+							'event_espresso'
115
+						),
116
+						'<a href="admin.php?page=espresso_registration_form" target="_blank">',
117
+						'</a>'
118
+					);
119
+				?>
120 120
             </p>
121 121
             <?php
122 122
 
123
-            $qsg_where['QSG_deleted'] = false;
124
-            $query_params             = apply_filters(
125
-                'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters',
126
-                array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
127
-            );
128
-            $QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
129
-            $EQGs                     = ! empty($event_id)
130
-                ? $this->_event->get_many_related(
131
-                    'Question_Group',
132
-                    array(array('Event_Question_Group.EQG_primary' => 0))
133
-                )
134
-                : array();
135
-            $EQGids                   = array_keys($EQGs);
136
-
137
-            if (! empty($QSGs)) {
138
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
139
-                foreach ($QSGs as $QSG) {
140
-                    $checked   = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : '';
141
-                    $edit_link = EE_Admin_Page::add_query_args_and_nonce(
142
-                        array(
143
-                            'action' => 'edit_question_group',
144
-                            'QSG_ID' => $QSG->ID(),
145
-                        ),
146
-                        EE_FORMS_ADMIN_URL
147
-                    );
148
-
149
-                    $html .= '
123
+			$qsg_where['QSG_deleted'] = false;
124
+			$query_params             = apply_filters(
125
+				'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters',
126
+				array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
127
+			);
128
+			$QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
129
+			$EQGs                     = ! empty($event_id)
130
+				? $this->_event->get_many_related(
131
+					'Question_Group',
132
+					array(array('Event_Question_Group.EQG_primary' => 0))
133
+				)
134
+				: array();
135
+			$EQGids                   = array_keys($EQGs);
136
+
137
+			if (! empty($QSGs)) {
138
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
139
+				foreach ($QSGs as $QSG) {
140
+					$checked   = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : '';
141
+					$edit_link = EE_Admin_Page::add_query_args_and_nonce(
142
+						array(
143
+							'action' => 'edit_question_group',
144
+							'QSG_ID' => $QSG->ID(),
145
+						),
146
+						EE_FORMS_ADMIN_URL
147
+					);
148
+
149
+					$html .= '
150 150
 					<p id="event-question-group-' . $QSG->ID() . '">
151 151
 						<input value="' . $QSG->ID() . '"'
152
-                        . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
152
+						. ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
153 153
 						<a href="' . $edit_link . '" title="'
154
-                             . sprintf(
155
-                                 esc_attr__('Edit %s Group', 'event_espresso'),
156
-                                 $QSG->get('QSG_name')
157
-                             )
158
-                             . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
154
+							 . sprintf(
155
+								 esc_attr__('Edit %s Group', 'event_espresso'),
156
+								 $QSG->get('QSG_name')
157
+							 )
158
+							 . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
159 159
 					</p>';
160
-                    if ($QSG->ID() === 2) {
161
-                        $html .= '
160
+					if ($QSG->ID() === 2) {
161
+						$html .= '
162 162
 					<p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">'
163
-                        . esc_html__(
164
-                            'The Personal Information question group is required whenever the Address Information question group is activated.',
165
-                            'event_espresso'
166
-                        )
167
-                        . '</p>';
168
-                    }
169
-                }
170
-                $html .= count($QSGs) > 10 ? '</div>' : '';
171
-
172
-                echo $html;
173
-
174
-            } else {
175
-                esc_html_e(
176
-                    'There seems to be a problem with your questions. Please contact [email protected]',
177
-                    'event_espresso'
178
-                );
179
-            }
180
-            do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content');
181
-            ?>
163
+						. esc_html__(
164
+							'The Personal Information question group is required whenever the Address Information question group is activated.',
165
+							'event_espresso'
166
+						)
167
+						. '</p>';
168
+					}
169
+				}
170
+				$html .= count($QSGs) > 10 ? '</div>' : '';
171
+
172
+				echo $html;
173
+
174
+			} else {
175
+				esc_html_e(
176
+					'There seems to be a problem with your questions. Please contact [email protected]',
177
+					'event_espresso'
178
+				);
179
+			}
180
+			do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content');
181
+			?>
182 182
         </div>
183 183
         <?php
184
-    }
185
-
186
-
187
-    public function additional_question_group_update($evtobj, $data)
188
-    {
189
-        $question_groups = ! empty($data['add_attendee_question_groups'])
190
-            ? (array) $data['add_attendee_question_groups']
191
-            : array();
192
-        $added_qgs       = array_keys($question_groups);
193
-        $success         = array();
194
-
195
-        //let's get all current question groups associated with this event.
196
-        $current_qgs = $evtobj->get_many_related(
197
-            'Question_Group',
198
-            array(array('Event_Question_Group.EQG_primary' => 0))
199
-        );
200
-        $current_qgs = array_keys($current_qgs); //we just want the ids
201
-
202
-        //now let's get the groups selected in the editor and update (IF we have data)
203
-        if (! empty($question_groups)) {
204
-            foreach ($question_groups as $id => $val) {
205
-                //add to event
206
-                if ($val) {
207
-                    $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 0));
208
-                }
209
-                $success[] = ! empty($qg) ? 1 : 0;
210
-            }
211
-        }
212
-
213
-        //wait a minute... are there question groups missing in the saved groups that ARE with the current event?
214
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
215
-
216
-        foreach ($removed_qgs as $qgid) {
217
-            $qg        = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 0));
218
-            $success[] = ! empty($qg) ? 1 : 0;
219
-        }
220
-
221
-
222
-        return in_array(0, $success, true) ? false : true;
223
-    }
184
+	}
185
+
186
+
187
+	public function additional_question_group_update($evtobj, $data)
188
+	{
189
+		$question_groups = ! empty($data['add_attendee_question_groups'])
190
+			? (array) $data['add_attendee_question_groups']
191
+			: array();
192
+		$added_qgs       = array_keys($question_groups);
193
+		$success         = array();
194
+
195
+		//let's get all current question groups associated with this event.
196
+		$current_qgs = $evtobj->get_many_related(
197
+			'Question_Group',
198
+			array(array('Event_Question_Group.EQG_primary' => 0))
199
+		);
200
+		$current_qgs = array_keys($current_qgs); //we just want the ids
201
+
202
+		//now let's get the groups selected in the editor and update (IF we have data)
203
+		if (! empty($question_groups)) {
204
+			foreach ($question_groups as $id => $val) {
205
+				//add to event
206
+				if ($val) {
207
+					$qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 0));
208
+				}
209
+				$success[] = ! empty($qg) ? 1 : 0;
210
+			}
211
+		}
212
+
213
+		//wait a minute... are there question groups missing in the saved groups that ARE with the current event?
214
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
215
+
216
+		foreach ($removed_qgs as $qgid) {
217
+			$qg        = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 0));
218
+			$success[] = ! empty($qg) ? 1 : 0;
219
+		}
220
+
221
+
222
+		return in_array(0, $success, true) ? false : true;
223
+	}
224 224
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      */
26 26
     protected function _extend_properties()
27 27
     {
28
-        $this->_metaboxes      = array_merge(
28
+        $this->_metaboxes = array_merge(
29 29
             $this->_metaboxes,
30 30
             array(
31 31
                 1 => array(
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
                     array(array('Event_Question_Group.EQG_primary' => 0))
133 133
                 )
134 134
                 : array();
135
-            $EQGids                   = array_keys($EQGs);
135
+            $EQGids = array_keys($EQGs);
136 136
 
137
-            if (! empty($QSGs)) {
137
+            if ( ! empty($QSGs)) {
138 138
                 $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
139 139
                 foreach ($QSGs as $QSG) {
140 140
                     $checked   = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : '';
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
                     );
148 148
 
149 149
                     $html .= '
150
-					<p id="event-question-group-' . $QSG->ID() . '">
151
-						<input value="' . $QSG->ID() . '"'
152
-                        . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
153
-						<a href="' . $edit_link . '" title="'
150
+					<p id="event-question-group-' . $QSG->ID().'">
151
+						<input value="' . $QSG->ID().'"'
152
+                        . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' />
153
+						<a href="' . $edit_link.'" title="'
154 154
                              . sprintf(
155 155
                                  esc_attr__('Edit %s Group', 'event_espresso'),
156 156
                                  $QSG->get('QSG_name')
157 157
                              )
158
-                             . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
158
+                             . '" target="_blank">'.$QSG->get('QSG_name').'</a>
159 159
 					</p>';
160 160
                     if ($QSG->ID() === 2) {
161 161
                         $html .= '
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         $current_qgs = array_keys($current_qgs); //we just want the ids
201 201
 
202 202
         //now let's get the groups selected in the editor and update (IF we have data)
203
-        if (! empty($question_groups)) {
203
+        if ( ! empty($question_groups)) {
204 204
             foreach ($question_groups as $id => $val) {
205 205
                 //add to event
206 206
                 if ($val) {
Please login to merge, or discard this patch.
core/libraries/messages/data_class/EE_Messages_incoming_data.core.php 2 patches
Indentation   +506 added lines, -506 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('NO direct script access allowed');
4
+	exit('NO direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -27,511 +27,511 @@  discard block
 block discarded – undo
27 27
 {
28 28
 
29 29
 
30
-    /**
31
-     * user id for logged in user when data collected
32
-     *
33
-     * @var string $user_id
34
-     */
35
-    public $user_id;
36
-
37
-    /**
38
-     * IP Address of browser used
39
-     *
40
-     * @var string $ip_address
41
-     */
42
-    public $ip_address;
43
-
44
-    /**
45
-     * browser
46
-     *
47
-     * @var string $user_agent
48
-     */
49
-    public $user_agent;
50
-
51
-    /**
52
-     * Unix timestamp
53
-     *
54
-     * @var string $init_access
55
-     */
56
-    public $init_access;
57
-
58
-    /**
59
-     * Unix timestamp
60
-     *
61
-     * @var string $last_access
62
-     */
63
-    public $last_access;
64
-
65
-    /**
66
-     * The registrations details from the cart
67
-     *
68
-     * @var array $reg_info
69
-     */
70
-    public $reg_info;
71
-
72
-    /**
73
-     * Some data handlers can set what reg status all the registrations are filtered by.
74
-     * The status should match a EEM_Registration status constant.
75
-     *
76
-     * @var string $filtered_reg_status
77
-     */
78
-    public $filtered_reg_status;
79
-
80
-    /**
81
-     * will hold an array of events assembled from $reg_info
82
-     *
83
-     * @var EE_Event[] $events
84
-     */
85
-    public $events;
86
-
87
-    /**
88
-     * holds an array of datetimes assembled from the incoming data.
89
-     *
90
-     * @var EE_Datetime[] $datetimes
91
-     */
92
-    public $datetimes;
93
-
94
-    /**
95
-     * holds an array of tickets assembled from the incoming data.
96
-     *
97
-     * @var EE_Ticket[] $tickets
98
-     */
99
-    public $tickets;
100
-
101
-    /**
102
-     * holds an array with a key of parent line item and values are an array of children of that line item.
103
-     *
104
-     * @since 4.5.0
105
-     * @var EE_Line_Item[] $line_items_with_children
106
-     */
107
-    public $line_items_with_children;
108
-
109
-    /**
110
-     * will hold an array of attendees assembled from the $reg_info
111
-     *
112
-     * @var EE_Attendee[] $attendees
113
-     */
114
-    public $attendees;
115
-
116
-    /**
117
-     * will hold an array of cached registration objects and info assembled from reg_info
118
-     *
119
-     * @var array $registrations
120
-     */
121
-    public $registrations;
122
-
123
-    /**
124
-     * will hold an array of answers assembled from the $reg_info
125
-     *
126
-     * @var EE_Answer[] $answers
127
-     */
128
-    public $answers;
129
-
130
-    /**
131
-     * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
132
-     *
133
-     * @var EE_Question[] $questions
134
-     */
135
-    public $questions;
136
-
137
-    /**
138
-     * Will hold billing data assembled from $billing_info (if present)
139
-     *
140
-     * @var mixed (array|null) $billing
141
-     */
142
-    public $billing;
143
-
144
-    /**
145
-     * The total amount of tax for the transaction
146
-     *
147
-     * @var float $taxes
148
-     */
149
-    public $taxes;
150
-
151
-    /**
152
-     * Holds the line items related to taxes
153
-     *
154
-     * @since 4.5.0
155
-     * @var EE_Line_Item[] $tax_line_items
156
-     */
157
-    public $tax_line_items;
158
-
159
-    /**
160
-     * Hold the line items which aren't taxes and don't relate
161
-     * to tickets. So: promotions and miscellaneous charges
162
-     *
163
-     * @since 4.5
164
-     * @var EE_Line_Item[] $additional_line_items
165
-     */
166
-    public $additional_line_items;
167
-
168
-    /**
169
-     * Holds the grand total EE_Line_Item
170
-     *
171
-     * @var EE_Line_Item $grand_total_line_item
172
-     */
173
-    public $grand_total_line_item;
174
-
175
-    /**
176
-     * holds the grand total price object
177
-     *
178
-     * @var object $grand_total_price_object
179
-     */
180
-    public $grand_total_price_object;
181
-
182
-    /**
183
-     * total number of tickets
184
-     *
185
-     * @var int $total_ticket_count
186
-     */
187
-    public $total_ticket_count;
188
-
189
-    /**
190
-     * Will hold the final transaction object (EE_Transaction)
191
-     *
192
-     * @var EE_Transaction $txn
193
-     */
194
-    public $txn;
195
-
196
-    /**
197
-     * Holds the payments related to a transaction
198
-     *
199
-     * @since 4.5.0
200
-     * @var EE_Payment[] $payments
201
-     */
202
-    public $payments;
203
-
204
-    /**
205
-     * Holds the first related payment related for a transaction
206
-     *
207
-     * @since 4.5.0
208
-     * @var EE_Payment $payment
209
-     */
210
-    public $payment;
211
-
212
-    /**
213
-     * Will hold the label for the txn status
214
-     *
215
-     * @var string $txn_status
216
-     */
217
-    public $txn_status;
218
-
219
-    /**
220
-     * Will hold the final registration object (EE_Registration)
221
-     *
222
-     * @var EE_Registration[] $reg_objs
223
-     */
224
-    public $reg_objs;
225
-
226
-    /**
227
-     * Will hold an array of primary attendee data (if present)
228
-     *
229
-     * @var array $primary_attendee_data
230
-     */
231
-    public $primary_attendee_data;
232
-
233
-    /**
234
-     * This is just an internal object used for passing around the incoming data.
235
-     *
236
-     * @var object $_data
237
-     */
238
-    protected $_data;
239
-
240
-    /**
241
-     * This is just an internal object used for passing around the incoming data.
242
-     *
243
-     * @var object $incoming_data
244
-     */
245
-    public $incoming_data;
246
-
247
-    /**
248
-     * hold objects that might be created
249
-     *
250
-     * @type EE_Registration $reg_obj
251
-     */
252
-    public $reg_obj;
253
-
254
-
255
-    /**
256
-     * constructor
257
-     *
258
-     * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
259
-     *                    data object.  But here parent will be generic because we don't know what's coming in.
260
-     */
261
-    public function __construct($data)
262
-    {
263
-        $this->_data = $data;
264
-        $this->_setup_data();
265
-    }
266
-
267
-
268
-    /**
269
-     * Every child class has to setup the data object !
270
-     *
271
-     * @return void
272
-     */
273
-    abstract protected function _setup_data();
274
-
275
-
276
-    /**
277
-     * Returns database safe representation of the data later used to when instantiating this object.
278
-     *
279
-     * @param mixed $data The incoming data to be prepped.
280
-     * @return mixed   The prepped data for db
281
-     */
282
-    static public function convert_data_for_persistent_storage($data)
283
-    {
284
-        return $data;
285
-    }
286
-
287
-
288
-    /**
289
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
290
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
291
-     *
292
-     * @param $data
293
-     * @return mixed
294
-     */
295
-    static public function convert_data_from_persistent_storage($data)
296
-    {
297
-        return $data;
298
-    }
299
-
300
-
301
-    /**
302
-     * only purpose is to return the data
303
-     *
304
-     * @access public
305
-     * @return object the formatted data object!
306
-     */
307
-    public function data()
308
-    {
309
-        return $this->_data;
310
-    }
311
-
312
-
313
-    /**
314
-     * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
315
-     * is that $this->reg_objs be set.
316
-     *
317
-     * @throws \EE_Error
318
-     */
319
-    protected function _assemble_data()
320
-    {
321
-        //verify that reg_objs is set
322
-        if (
323
-            ! is_array($this->reg_objs)
324
-            && ! reset($this->reg_objs) instanceof EE_Registration
325
-        ) {
326
-            throw new EE_Error(
327
-                __(
328
-                    'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
329
-                    'event_espresso'
330
-                )
331
-            );
332
-        }
333
-
334
-        //get all attendee and events associated with the registrations in this transaction
335
-        $events             = $event_setup = $evtcache = $tickets = $datetimes = array();
336
-        $answers            = $questions = $attendees = $line_items = $registrations = array();
337
-        $total_ticket_count = 0;
338
-
339
-        if (! empty($this->reg_objs)) {
340
-            $event_attendee_count = array();
341
-            foreach ($this->reg_objs as $reg) {
342
-
343
-                if (
344
-                $this->_skip_registration_for_processing($reg)
345
-                ) {
346
-                    continue;
347
-                }
348
-
349
-                $evt_id = $reg->event_ID();
350
-                /** @type EE_Ticket $ticket */
351
-                $ticket          = $reg->get_first_related('Ticket');
352
-                $relateddatetime = $ticket->datetimes();
353
-                $total_ticket_count++;
354
-                $tickets[$ticket->ID()]['ticket']                        = $ticket;
355
-                $tickets[$ticket->ID()]['count']                         = is_array($tickets[$ticket->ID()])
356
-                                                                           && isset($tickets[$ticket->ID()]['count'])
357
-                    ? $tickets[$ticket->ID()]['count'] + 1
358
-                    : 1;
359
-                $tickets[$ticket->ID()]['att_objs'][$reg->attendee_ID()] = $reg->attendee();
360
-                $tickets[$ticket->ID()]['dtt_objs']                      = $relateddatetime;
361
-                $tickets[$ticket->ID()]['reg_objs'][$reg->ID()]          = $reg;
362
-                $event                                                   = $reg->event();
363
-                $tickets[$ticket->ID()]['EE_Event']                      = $event;
364
-                $evtcache[$evt_id]                                       = $event;
365
-                $eventsetup[$evt_id]['reg_objs'][$reg->ID()]             = $reg;
366
-                $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()]          = $ticket;
367
-                $eventsetup[$evt_id]['att_objs'][$reg->attendee_ID()]    = $reg->attendee();
368
-                $event_attendee_count[$evt_id]                           = isset($event_attendee_count[$evt_id])
369
-                    ? $event_attendee_count[$evt_id] + 1
370
-                    : 0;
371
-                $attendees[$reg->attendee_ID()]['line_ref'][]            = $evt_id;
372
-                $attendees[$reg->attendee_ID()]['att_obj']               = $reg->attendee();
373
-                $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()]  = $reg;
374
-                //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
375
-                $attendees[$reg->attendee_ID()]['attendee_email']          = $reg->attendee() instanceof EE_Attendee
376
-                    ? $reg->attendee()->email()
377
-                    : '';
378
-                $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket;
379
-                $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id]       = $event;
380
-
381
-                //registrations
382
-                $registrations[$reg->ID()]['tkt_obj'] = $ticket;
383
-                $registrations[$reg->ID()]['evt_obj'] = $event;
384
-                $registrations[$reg->ID()]['reg_obj'] = $reg;
385
-                $registrations[$reg->ID()]['att_obj'] = $reg->attendee();
386
-
387
-                //set up answer objects
388
-                $rel_ans = $reg->get_many_related('Answer');
389
-                foreach ($rel_ans as $ansid => $answer) {
390
-                    if (! isset($questions[$ansid])) {
391
-                        $questions[$ansid] = $answer->get_first_related('Question');
392
-                    }
393
-                    $answers[$ansid]                               = $answer;
394
-                    $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer;
395
-                }
396
-
397
-                foreach ($relateddatetime as $dtt_id => $datetime) {
398
-                    $eventsetup[$evt_id]['dtt_objs'][$dtt_id]       = $datetime;
399
-                    $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime;
400
-
401
-                    if (isset($datetimes[$dtt_id])) {
402
-                        continue; //already have this info in the datetimes array.
403
-                    }
404
-
405
-                    $datetimes[$dtt_id]['tkt_objs'][]           = $ticket;
406
-                    $datetimes[$dtt_id]['datetime']             = $datetime;
407
-                    $datetimes[$dtt_id]['evt_objs'][$evt_id]    = $event;
408
-                    $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg;
409
-                }
410
-            }
411
-
412
-            //let's loop through the unique event=>reg items and setup data on them
413
-
414
-            if (! empty($eventsetup)) {
415
-                foreach ($eventsetup as $evt_id => $items) {
416
-                    if ($this->txn instanceof EE_Transaction) {
417
-                        $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
418
-                            array(
419
-                                array(
420
-                                    'Ticket.Datetime.EVT_ID' => $evt_id,
421
-                                    'TXN_ID'                 => $this->txn->ID(),
422
-                                ),
423
-                                'default_where_conditions' => 'none',
424
-                            )
425
-                        );
426
-                    } else {
427
-                        $ticket_line_items_for_event = array();
428
-                    }
429
-                    $events[$evt_id] = array(
430
-                        'ID'              => $evt_id,
431
-                        'event'           => $evtcache[$evt_id],
432
-                        'name'            => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '',
433
-                        'total_attendees' => $event_attendee_count[$evt_id],
434
-                        'reg_objs'        => $items['reg_objs'],
435
-                        'tkt_objs'        => $items['tkt_objs'],
436
-                        'att_objs'        => $items['att_objs'],
437
-                        'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
438
-                        'line_items'      => $ticket_line_items_for_event,
439
-                    );
440
-
441
-                    //make sure the tickets have the line items setup for them.
442
-                    foreach ($ticket_line_items_for_event as $line_id => $line_item) {
443
-                        if ($line_item instanceof EE_Line_Item) {
444
-                            $tickets[$line_item->ticket()->ID()]['line_item']      = $line_item;
445
-                            $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children();
446
-                            $line_items[$line_item->ID()]['children']              = $line_item->children();
447
-                            $line_items[$line_item->ID()]['EE_Ticket']             = $line_item->ticket();
448
-                        }
449
-                    }
450
-                }
451
-            }
452
-
453
-            $this->grand_total_line_item = $this->txn instanceof EE_Transaction
454
-                ? $this->txn->total_line_item()
455
-                : null;
456
-        }
457
-
458
-        //lets set the attendees and events properties
459
-        $this->attendees                = $attendees;
460
-        $this->events                   = $events;
461
-        $this->tickets                  = $tickets;
462
-        $this->line_items_with_children = $line_items;
463
-        $this->datetimes                = $datetimes;
464
-        $this->questions                = $questions;
465
-        $this->answers                  = $answers;
466
-        $this->total_ticket_count       = $total_ticket_count;
467
-        $this->registrations            = $registrations;
468
-
469
-        if ($this->txn instanceof EE_Transaction) {
470
-            $this->tax_line_items        = $this->txn->tax_items();
471
-            $this->additional_line_items = $this->txn->non_ticket_line_items();
472
-            $this->payments              = $this->txn->payments();
473
-
474
-            //setup primary registration if we have a single transaction object to work with
475
-
476
-            //let's get just the primary_attendee_data!  First we get the primary registration object.
477
-            $primary_reg = $this->txn->primary_registration();
478
-            // verify
479
-            if ($primary_reg instanceof EE_Registration) {
480
-
481
-                // get attendee object
482
-                if ($primary_reg->attendee() instanceof EE_Attendee) {
483
-
484
-                    //now we can setup the primary_attendee_data array
485
-                    $this->primary_attendee_data = array(
486
-                        'registration_id' => $primary_reg->ID(),
487
-                        'att_obj'         => $primary_reg->attendee(),
488
-                        'reg_obj'         => $primary_reg,
489
-                        'primary_att_obj' => $primary_reg->attendee(),
490
-                        'primary_reg_obj' => $primary_reg,
491
-                    );
492
-
493
-                } else {
494
-                    EE_Error::add_error(
495
-                        __(
496
-                            'Incoming data does not have a valid Attendee object for the primary registrant.',
497
-                            'event_espresso'
498
-                        ),
499
-                        __FILE__,
500
-                        __FUNCTION__,
501
-                        __LINE__
502
-                    );
503
-                }
504
-            } else {
505
-                EE_Error::add_error(
506
-                    __(
507
-                        'Incoming data does not have a valid Registration object for the primary registrant.',
508
-                        'event_espresso'
509
-                    ),
510
-                    __FILE__,
511
-                    __FUNCTION__,
512
-                    __LINE__
513
-                );
514
-            }
515
-        }
516
-    }
517
-
518
-    /**
519
-     * This simply considers whether the given registration should be processed or not based on comparison with the
520
-     * filtered_reg_status property.
521
-     *
522
-     * @param EE_Registration $registration
523
-     * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
524
-     *               processing
525
-     */
526
-    protected function _skip_registration_for_processing(EE_Registration $registration)
527
-    {
528
-        if (empty($this->filtered_reg_status)) {
529
-            return false;
530
-        }
531
-
532
-        //if we made it here then we just compare the filtered_reg_status with the registration status and return that
533
-        return $this->filtered_reg_status !== $registration->status_ID();
534
-    }
30
+	/**
31
+	 * user id for logged in user when data collected
32
+	 *
33
+	 * @var string $user_id
34
+	 */
35
+	public $user_id;
36
+
37
+	/**
38
+	 * IP Address of browser used
39
+	 *
40
+	 * @var string $ip_address
41
+	 */
42
+	public $ip_address;
43
+
44
+	/**
45
+	 * browser
46
+	 *
47
+	 * @var string $user_agent
48
+	 */
49
+	public $user_agent;
50
+
51
+	/**
52
+	 * Unix timestamp
53
+	 *
54
+	 * @var string $init_access
55
+	 */
56
+	public $init_access;
57
+
58
+	/**
59
+	 * Unix timestamp
60
+	 *
61
+	 * @var string $last_access
62
+	 */
63
+	public $last_access;
64
+
65
+	/**
66
+	 * The registrations details from the cart
67
+	 *
68
+	 * @var array $reg_info
69
+	 */
70
+	public $reg_info;
71
+
72
+	/**
73
+	 * Some data handlers can set what reg status all the registrations are filtered by.
74
+	 * The status should match a EEM_Registration status constant.
75
+	 *
76
+	 * @var string $filtered_reg_status
77
+	 */
78
+	public $filtered_reg_status;
79
+
80
+	/**
81
+	 * will hold an array of events assembled from $reg_info
82
+	 *
83
+	 * @var EE_Event[] $events
84
+	 */
85
+	public $events;
86
+
87
+	/**
88
+	 * holds an array of datetimes assembled from the incoming data.
89
+	 *
90
+	 * @var EE_Datetime[] $datetimes
91
+	 */
92
+	public $datetimes;
93
+
94
+	/**
95
+	 * holds an array of tickets assembled from the incoming data.
96
+	 *
97
+	 * @var EE_Ticket[] $tickets
98
+	 */
99
+	public $tickets;
100
+
101
+	/**
102
+	 * holds an array with a key of parent line item and values are an array of children of that line item.
103
+	 *
104
+	 * @since 4.5.0
105
+	 * @var EE_Line_Item[] $line_items_with_children
106
+	 */
107
+	public $line_items_with_children;
108
+
109
+	/**
110
+	 * will hold an array of attendees assembled from the $reg_info
111
+	 *
112
+	 * @var EE_Attendee[] $attendees
113
+	 */
114
+	public $attendees;
115
+
116
+	/**
117
+	 * will hold an array of cached registration objects and info assembled from reg_info
118
+	 *
119
+	 * @var array $registrations
120
+	 */
121
+	public $registrations;
122
+
123
+	/**
124
+	 * will hold an array of answers assembled from the $reg_info
125
+	 *
126
+	 * @var EE_Answer[] $answers
127
+	 */
128
+	public $answers;
129
+
130
+	/**
131
+	 * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
132
+	 *
133
+	 * @var EE_Question[] $questions
134
+	 */
135
+	public $questions;
136
+
137
+	/**
138
+	 * Will hold billing data assembled from $billing_info (if present)
139
+	 *
140
+	 * @var mixed (array|null) $billing
141
+	 */
142
+	public $billing;
143
+
144
+	/**
145
+	 * The total amount of tax for the transaction
146
+	 *
147
+	 * @var float $taxes
148
+	 */
149
+	public $taxes;
150
+
151
+	/**
152
+	 * Holds the line items related to taxes
153
+	 *
154
+	 * @since 4.5.0
155
+	 * @var EE_Line_Item[] $tax_line_items
156
+	 */
157
+	public $tax_line_items;
158
+
159
+	/**
160
+	 * Hold the line items which aren't taxes and don't relate
161
+	 * to tickets. So: promotions and miscellaneous charges
162
+	 *
163
+	 * @since 4.5
164
+	 * @var EE_Line_Item[] $additional_line_items
165
+	 */
166
+	public $additional_line_items;
167
+
168
+	/**
169
+	 * Holds the grand total EE_Line_Item
170
+	 *
171
+	 * @var EE_Line_Item $grand_total_line_item
172
+	 */
173
+	public $grand_total_line_item;
174
+
175
+	/**
176
+	 * holds the grand total price object
177
+	 *
178
+	 * @var object $grand_total_price_object
179
+	 */
180
+	public $grand_total_price_object;
181
+
182
+	/**
183
+	 * total number of tickets
184
+	 *
185
+	 * @var int $total_ticket_count
186
+	 */
187
+	public $total_ticket_count;
188
+
189
+	/**
190
+	 * Will hold the final transaction object (EE_Transaction)
191
+	 *
192
+	 * @var EE_Transaction $txn
193
+	 */
194
+	public $txn;
195
+
196
+	/**
197
+	 * Holds the payments related to a transaction
198
+	 *
199
+	 * @since 4.5.0
200
+	 * @var EE_Payment[] $payments
201
+	 */
202
+	public $payments;
203
+
204
+	/**
205
+	 * Holds the first related payment related for a transaction
206
+	 *
207
+	 * @since 4.5.0
208
+	 * @var EE_Payment $payment
209
+	 */
210
+	public $payment;
211
+
212
+	/**
213
+	 * Will hold the label for the txn status
214
+	 *
215
+	 * @var string $txn_status
216
+	 */
217
+	public $txn_status;
218
+
219
+	/**
220
+	 * Will hold the final registration object (EE_Registration)
221
+	 *
222
+	 * @var EE_Registration[] $reg_objs
223
+	 */
224
+	public $reg_objs;
225
+
226
+	/**
227
+	 * Will hold an array of primary attendee data (if present)
228
+	 *
229
+	 * @var array $primary_attendee_data
230
+	 */
231
+	public $primary_attendee_data;
232
+
233
+	/**
234
+	 * This is just an internal object used for passing around the incoming data.
235
+	 *
236
+	 * @var object $_data
237
+	 */
238
+	protected $_data;
239
+
240
+	/**
241
+	 * This is just an internal object used for passing around the incoming data.
242
+	 *
243
+	 * @var object $incoming_data
244
+	 */
245
+	public $incoming_data;
246
+
247
+	/**
248
+	 * hold objects that might be created
249
+	 *
250
+	 * @type EE_Registration $reg_obj
251
+	 */
252
+	public $reg_obj;
253
+
254
+
255
+	/**
256
+	 * constructor
257
+	 *
258
+	 * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
259
+	 *                    data object.  But here parent will be generic because we don't know what's coming in.
260
+	 */
261
+	public function __construct($data)
262
+	{
263
+		$this->_data = $data;
264
+		$this->_setup_data();
265
+	}
266
+
267
+
268
+	/**
269
+	 * Every child class has to setup the data object !
270
+	 *
271
+	 * @return void
272
+	 */
273
+	abstract protected function _setup_data();
274
+
275
+
276
+	/**
277
+	 * Returns database safe representation of the data later used to when instantiating this object.
278
+	 *
279
+	 * @param mixed $data The incoming data to be prepped.
280
+	 * @return mixed   The prepped data for db
281
+	 */
282
+	static public function convert_data_for_persistent_storage($data)
283
+	{
284
+		return $data;
285
+	}
286
+
287
+
288
+	/**
289
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
290
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
291
+	 *
292
+	 * @param $data
293
+	 * @return mixed
294
+	 */
295
+	static public function convert_data_from_persistent_storage($data)
296
+	{
297
+		return $data;
298
+	}
299
+
300
+
301
+	/**
302
+	 * only purpose is to return the data
303
+	 *
304
+	 * @access public
305
+	 * @return object the formatted data object!
306
+	 */
307
+	public function data()
308
+	{
309
+		return $this->_data;
310
+	}
311
+
312
+
313
+	/**
314
+	 * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
315
+	 * is that $this->reg_objs be set.
316
+	 *
317
+	 * @throws \EE_Error
318
+	 */
319
+	protected function _assemble_data()
320
+	{
321
+		//verify that reg_objs is set
322
+		if (
323
+			! is_array($this->reg_objs)
324
+			&& ! reset($this->reg_objs) instanceof EE_Registration
325
+		) {
326
+			throw new EE_Error(
327
+				__(
328
+					'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
329
+					'event_espresso'
330
+				)
331
+			);
332
+		}
333
+
334
+		//get all attendee and events associated with the registrations in this transaction
335
+		$events             = $event_setup = $evtcache = $tickets = $datetimes = array();
336
+		$answers            = $questions = $attendees = $line_items = $registrations = array();
337
+		$total_ticket_count = 0;
338
+
339
+		if (! empty($this->reg_objs)) {
340
+			$event_attendee_count = array();
341
+			foreach ($this->reg_objs as $reg) {
342
+
343
+				if (
344
+				$this->_skip_registration_for_processing($reg)
345
+				) {
346
+					continue;
347
+				}
348
+
349
+				$evt_id = $reg->event_ID();
350
+				/** @type EE_Ticket $ticket */
351
+				$ticket          = $reg->get_first_related('Ticket');
352
+				$relateddatetime = $ticket->datetimes();
353
+				$total_ticket_count++;
354
+				$tickets[$ticket->ID()]['ticket']                        = $ticket;
355
+				$tickets[$ticket->ID()]['count']                         = is_array($tickets[$ticket->ID()])
356
+																		   && isset($tickets[$ticket->ID()]['count'])
357
+					? $tickets[$ticket->ID()]['count'] + 1
358
+					: 1;
359
+				$tickets[$ticket->ID()]['att_objs'][$reg->attendee_ID()] = $reg->attendee();
360
+				$tickets[$ticket->ID()]['dtt_objs']                      = $relateddatetime;
361
+				$tickets[$ticket->ID()]['reg_objs'][$reg->ID()]          = $reg;
362
+				$event                                                   = $reg->event();
363
+				$tickets[$ticket->ID()]['EE_Event']                      = $event;
364
+				$evtcache[$evt_id]                                       = $event;
365
+				$eventsetup[$evt_id]['reg_objs'][$reg->ID()]             = $reg;
366
+				$eventsetup[$evt_id]['tkt_objs'][$ticket->ID()]          = $ticket;
367
+				$eventsetup[$evt_id]['att_objs'][$reg->attendee_ID()]    = $reg->attendee();
368
+				$event_attendee_count[$evt_id]                           = isset($event_attendee_count[$evt_id])
369
+					? $event_attendee_count[$evt_id] + 1
370
+					: 0;
371
+				$attendees[$reg->attendee_ID()]['line_ref'][]            = $evt_id;
372
+				$attendees[$reg->attendee_ID()]['att_obj']               = $reg->attendee();
373
+				$attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()]  = $reg;
374
+				//$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
375
+				$attendees[$reg->attendee_ID()]['attendee_email']          = $reg->attendee() instanceof EE_Attendee
376
+					? $reg->attendee()->email()
377
+					: '';
378
+				$attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket;
379
+				$attendees[$reg->attendee_ID()]['evt_objs'][$evt_id]       = $event;
380
+
381
+				//registrations
382
+				$registrations[$reg->ID()]['tkt_obj'] = $ticket;
383
+				$registrations[$reg->ID()]['evt_obj'] = $event;
384
+				$registrations[$reg->ID()]['reg_obj'] = $reg;
385
+				$registrations[$reg->ID()]['att_obj'] = $reg->attendee();
386
+
387
+				//set up answer objects
388
+				$rel_ans = $reg->get_many_related('Answer');
389
+				foreach ($rel_ans as $ansid => $answer) {
390
+					if (! isset($questions[$ansid])) {
391
+						$questions[$ansid] = $answer->get_first_related('Question');
392
+					}
393
+					$answers[$ansid]                               = $answer;
394
+					$registrations[$reg->ID()]['ans_objs'][$ansid] = $answer;
395
+				}
396
+
397
+				foreach ($relateddatetime as $dtt_id => $datetime) {
398
+					$eventsetup[$evt_id]['dtt_objs'][$dtt_id]       = $datetime;
399
+					$registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime;
400
+
401
+					if (isset($datetimes[$dtt_id])) {
402
+						continue; //already have this info in the datetimes array.
403
+					}
404
+
405
+					$datetimes[$dtt_id]['tkt_objs'][]           = $ticket;
406
+					$datetimes[$dtt_id]['datetime']             = $datetime;
407
+					$datetimes[$dtt_id]['evt_objs'][$evt_id]    = $event;
408
+					$datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg;
409
+				}
410
+			}
411
+
412
+			//let's loop through the unique event=>reg items and setup data on them
413
+
414
+			if (! empty($eventsetup)) {
415
+				foreach ($eventsetup as $evt_id => $items) {
416
+					if ($this->txn instanceof EE_Transaction) {
417
+						$ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
418
+							array(
419
+								array(
420
+									'Ticket.Datetime.EVT_ID' => $evt_id,
421
+									'TXN_ID'                 => $this->txn->ID(),
422
+								),
423
+								'default_where_conditions' => 'none',
424
+							)
425
+						);
426
+					} else {
427
+						$ticket_line_items_for_event = array();
428
+					}
429
+					$events[$evt_id] = array(
430
+						'ID'              => $evt_id,
431
+						'event'           => $evtcache[$evt_id],
432
+						'name'            => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '',
433
+						'total_attendees' => $event_attendee_count[$evt_id],
434
+						'reg_objs'        => $items['reg_objs'],
435
+						'tkt_objs'        => $items['tkt_objs'],
436
+						'att_objs'        => $items['att_objs'],
437
+						'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
438
+						'line_items'      => $ticket_line_items_for_event,
439
+					);
440
+
441
+					//make sure the tickets have the line items setup for them.
442
+					foreach ($ticket_line_items_for_event as $line_id => $line_item) {
443
+						if ($line_item instanceof EE_Line_Item) {
444
+							$tickets[$line_item->ticket()->ID()]['line_item']      = $line_item;
445
+							$tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children();
446
+							$line_items[$line_item->ID()]['children']              = $line_item->children();
447
+							$line_items[$line_item->ID()]['EE_Ticket']             = $line_item->ticket();
448
+						}
449
+					}
450
+				}
451
+			}
452
+
453
+			$this->grand_total_line_item = $this->txn instanceof EE_Transaction
454
+				? $this->txn->total_line_item()
455
+				: null;
456
+		}
457
+
458
+		//lets set the attendees and events properties
459
+		$this->attendees                = $attendees;
460
+		$this->events                   = $events;
461
+		$this->tickets                  = $tickets;
462
+		$this->line_items_with_children = $line_items;
463
+		$this->datetimes                = $datetimes;
464
+		$this->questions                = $questions;
465
+		$this->answers                  = $answers;
466
+		$this->total_ticket_count       = $total_ticket_count;
467
+		$this->registrations            = $registrations;
468
+
469
+		if ($this->txn instanceof EE_Transaction) {
470
+			$this->tax_line_items        = $this->txn->tax_items();
471
+			$this->additional_line_items = $this->txn->non_ticket_line_items();
472
+			$this->payments              = $this->txn->payments();
473
+
474
+			//setup primary registration if we have a single transaction object to work with
475
+
476
+			//let's get just the primary_attendee_data!  First we get the primary registration object.
477
+			$primary_reg = $this->txn->primary_registration();
478
+			// verify
479
+			if ($primary_reg instanceof EE_Registration) {
480
+
481
+				// get attendee object
482
+				if ($primary_reg->attendee() instanceof EE_Attendee) {
483
+
484
+					//now we can setup the primary_attendee_data array
485
+					$this->primary_attendee_data = array(
486
+						'registration_id' => $primary_reg->ID(),
487
+						'att_obj'         => $primary_reg->attendee(),
488
+						'reg_obj'         => $primary_reg,
489
+						'primary_att_obj' => $primary_reg->attendee(),
490
+						'primary_reg_obj' => $primary_reg,
491
+					);
492
+
493
+				} else {
494
+					EE_Error::add_error(
495
+						__(
496
+							'Incoming data does not have a valid Attendee object for the primary registrant.',
497
+							'event_espresso'
498
+						),
499
+						__FILE__,
500
+						__FUNCTION__,
501
+						__LINE__
502
+					);
503
+				}
504
+			} else {
505
+				EE_Error::add_error(
506
+					__(
507
+						'Incoming data does not have a valid Registration object for the primary registrant.',
508
+						'event_espresso'
509
+					),
510
+					__FILE__,
511
+					__FUNCTION__,
512
+					__LINE__
513
+				);
514
+			}
515
+		}
516
+	}
517
+
518
+	/**
519
+	 * This simply considers whether the given registration should be processed or not based on comparison with the
520
+	 * filtered_reg_status property.
521
+	 *
522
+	 * @param EE_Registration $registration
523
+	 * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
524
+	 *               processing
525
+	 */
526
+	protected function _skip_registration_for_processing(EE_Registration $registration)
527
+	{
528
+		if (empty($this->filtered_reg_status)) {
529
+			return false;
530
+		}
531
+
532
+		//if we made it here then we just compare the filtered_reg_status with the registration status and return that
533
+		return $this->filtered_reg_status !== $registration->status_ID();
534
+	}
535 535
 
536 536
 
537 537
 } //end EE_Messages_incoming_data class
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('NO direct script access allowed');
5 5
 }
6 6
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
         $answers            = $questions = $attendees = $line_items = $registrations = array();
337 337
         $total_ticket_count = 0;
338 338
 
339
-        if (! empty($this->reg_objs)) {
339
+        if ( ! empty($this->reg_objs)) {
340 340
             $event_attendee_count = array();
341 341
             foreach ($this->reg_objs as $reg) {
342 342
 
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
                 //set up answer objects
388 388
                 $rel_ans = $reg->get_many_related('Answer');
389 389
                 foreach ($rel_ans as $ansid => $answer) {
390
-                    if (! isset($questions[$ansid])) {
390
+                    if ( ! isset($questions[$ansid])) {
391 391
                         $questions[$ansid] = $answer->get_first_related('Question');
392 392
                     }
393 393
                     $answers[$ansid]                               = $answer;
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 
412 412
             //let's loop through the unique event=>reg items and setup data on them
413 413
 
414
-            if (! empty($eventsetup)) {
414
+            if ( ! empty($eventsetup)) {
415 415
                 foreach ($eventsetup as $evt_id => $items) {
416 416
                     if ($this->txn instanceof EE_Transaction) {
417 417
                         $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Transaction_Shortcodes.lib.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
                    && isset($this->_extra_data['data'])
275 275
                    && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
276 276
             : $payment;
277
-        if (! $transaction instanceof EE_Transaction) {
277
+        if ( ! $transaction instanceof EE_Transaction) {
278 278
             return '';
279 279
         }
280 280
         switch ($shortcode) {
@@ -289,16 +289,16 @@  discard block
 block discarded – undo
289 289
                 break;
290 290
             case '[INVOICE_LINK]':
291 291
                 $invoice_url = $transaction->invoice_url();
292
-                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
292
+                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
293 293
                 return sprintf(
294 294
                     esc_html__('%sClick here for Invoice%s', 'event_espresso'),
295
-                    '<a href="' . $invoice_url . '">',
295
+                    '<a href="'.$invoice_url.'">',
296 296
                     '</a>'
297 297
                 );
298 298
                 break;
299 299
             case '[INVOICE_URL]':
300 300
                 $invoice_url = $transaction->invoice_url();
301
-                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
301
+                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
302 302
                 break;
303 303
             case '[INVOICE_LOGO_URL]':
304 304
                 return $this->_get_invoice_logo();
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
                 break;
321 321
             case '[TOTAL_COST]':
322 322
                 $total = $transaction->total();
323
-                return ! empty($total) ? EEH_Template::format_currency($total): '';
323
+                return ! empty($total) ? EEH_Template::format_currency($total) : '';
324 324
                 break;
325 325
             case '[PAYMENT_STATUS]':
326 326
                 $status = $transaction->pretty_status();
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
                 return $this->_data->total_ticket_count;
367 367
                 break;
368 368
             case '[TRANSACTION_ADMIN_URL]':
369
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
369
+                require_once EE_CORE.'admin/EE_Admin_Page.core.php';
370 370
                 $query_args = array(
371 371
                     'page'   => 'espresso_transactions',
372 372
                     'action' => 'view_transaction',
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
             case '[RECEIPT_URL]':
379 379
                 //get primary_registration
380 380
                 $reg = $this->_data->primary_reg_obj;
381
-                if (! $reg instanceof EE_Registration) {
381
+                if ( ! $reg instanceof EE_Registration) {
382 382
                     return '';
383 383
                 }
384 384
                 return $reg->receipt_url();
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
      */
463 463
     private function _get_payment_gateway($transaction)
464 464
     {
465
-        if ($transaction instanceof EE_Transaction){
465
+        if ($transaction instanceof EE_Transaction) {
466 466
             $pm = $transaction->payment_method();
467 467
         } else {
468 468
             $pm = null;
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
         if (empty($invoice_logo_url)) {
498 498
             return '';
499 499
         }
500
-        if (! $img_tags) {
500
+        if ( ! $img_tags) {
501 501
             return $invoice_logo_url;
502 502
         }
503 503
         //image tags have been requested.
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
         } else {
509 509
             $image_width = $image_size[0];
510 510
         }
511
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
511
+        return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />';
512 512
     }
513 513
 
514 514
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
      */
546 546
     private function _get_invoice_payment_method()
547 547
     {
548
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
548
+        if ( ! $this->_invoice_pm instanceof EE_Payment_Method) {
549 549
             $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
550 550
             $transaction = ! $transaction instanceof EE_Transaction
551 551
                            && is_array($this->_extra_data)
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
         $attrs = $this->_get_shortcode_attrs($shortcode);
614 614
         //prefix?
615 615
         $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
616
-        return $prefix . $payee_tax_number;
616
+        return $prefix.$payee_tax_number;
617 617
     }
618 618
 
619 619
 
@@ -637,16 +637,16 @@  discard block
 block discarded – undo
637 637
         }
638 638
         if (empty($payee_address)) {
639 639
             $organization = EE_Registry::instance()->CFG->organization;
640
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
640
+            $payee_address = $organization->get_pretty('address_1').'<br>';
641 641
             $payee_address .= ! empty($organization->address_2)
642
-                ? $organization->get_pretty('address_2') . '<br>'
642
+                ? $organization->get_pretty('address_2').'<br>'
643 643
                 : '';
644
-            $payee_address .= $organization->get_pretty('city') . '<br>';
644
+            $payee_address .= $organization->get_pretty('city').'<br>';
645 645
             //state
646 646
             $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
647 647
             $payee_address .= $state instanceof EE_State ? $state->name() : '';
648 648
             //Country
649
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
649
+            $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : '';
650 650
             $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
651 651
         }
652 652
         return $payee_address;
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
     {
683 683
         $reg = $this->_data->primary_reg_obj;
684 684
         $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
685
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
685
+        if ( ! $reg instanceof EE_Registration || empty($message_type)) {
686 686
             return '';
687 687
         }
688 688
         $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
             ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
691 691
         $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
692 692
         $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
693
-        if (! $button) {
693
+        if ( ! $button) {
694 694
             return $switch_to_url;
695 695
         }
696
-        if (! empty($switch_to_url)) {
696
+        if ( ! empty($switch_to_url)) {
697 697
             return '
698
-	<form method="post" action="' . $switch_to_url . '" >
699
-		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
698
+	<form method="post" action="' . $switch_to_url.'" >
699
+		<input class="print_button" type="submit" value="' . $switch_to_label.'" />
700 700
 	</form>
701 701
 			';
702 702
         }
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
     private function _get_subtotal($tax = false)
715 715
     {
716 716
         $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
717
-        if (! $grand_total instanceof EE_Line_Item) {
717
+        if ( ! $grand_total instanceof EE_Line_Item) {
718 718
             return 0;
719 719
         }
720 720
         return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
@@ -741,11 +741,11 @@  discard block
 block discarded – undo
741 741
             $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
742 742
             $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
743 743
             $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
744
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
745
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
744
+            $opening_tag = ! empty($container_tag) ? '<'.$container_tag : '';
745
+            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag;
746 746
             $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
747
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
748
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
747
+            $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : '';
748
+            $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag;
749 749
             //we need to re run this string through the parser to catch any shortcodes that are in it.
750 750
             $owing_content = $this->_shortcode_helper->parse_message_template(
751 751
                 $content,
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
         }
780 780
         $attrs = $this->_get_shortcode_attrs($shortcode);
781 781
         $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
782
-        $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
782
+        $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
783 783
         $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
784 784
             : esc_html__('Payment in full due by: ', 'event_espresso');
785 785
         $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
         try {
788 788
             if ($transaction_created instanceof DateTime) {
789 789
                 $date_due = $transaction_created->add(
790
-                    new DateInterval('P' . $days_until_due . 'D')
790
+                    new DateInterval('P'.$days_until_due.'D')
791 791
                 )->format($format);
792 792
             } else {
793 793
                 throw new Exception();
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
                 'event_espresso'
800 800
             );
801 801
         }
802
-        return $prefix_text . $date_due;
802
+        return $prefix_text.$date_due;
803 803
     }
804 804
 
805 805
 }
Please login to merge, or discard this patch.
Indentation   +776 added lines, -776 removed lines patch added patch discarded remove patch
@@ -21,785 +21,785 @@
 block discarded – undo
21 21
 class EE_Transaction_Shortcodes extends EE_Shortcodes
22 22
 {
23 23
 
24
-    /**
25
-     * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
26
-     */
27
-    protected $_invoice_pm;
28
-
29
-
30
-
31
-    protected function _init_props()
32
-    {
33
-        $this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
34
-        $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
35
-        $this->_shortcodes = array(
36
-            '[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
37
-            '[PAYMENT_URL]'                     => esc_html__(
38
-                'This is a link to make a payment for the event',
39
-                'event_espresso'
40
-            ),
41
-            '[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
42
-                'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
43
-                'event_espresso'
44
-            )
45
-               . '<ul>'
46
-               . '<li>'
47
-               . sprintf(
48
-                   esc_html__(
49
-                       '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
50
-                       'event_espresso'
51
-                   ),
52
-                   '<strong>',
53
-                   '</strong>'
54
-               )
55
-               . '</li>'
56
-               . '<li>'
57
-               . sprintf(
58
-                   esc_html__(
59
-                       '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
60
-                       'event_espresso'
61
-                   ),
62
-                   '<strong>',
63
-                   '</strong>'
64
-               )
65
-               . '</li>'
66
-               . '<li>'
67
-               . sprintf(
68
-                   esc_html__(
69
-                       '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
70
-                       'event_espresso'
71
-                   ),
72
-                   '<strong>',
73
-                   '</strong>'
74
-               )
75
-               . '</li>'
76
-               . '</ul>',
77
-            '[PAYMENT_DUE_DATE_*]'              => esc_html__(
78
-                'This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
79
-                'event_espresso'
80
-            )
81
-               . '<ul>'
82
-               . '<li>'
83
-               . sprintf(
84
-                   esc_html__(
85
-                       '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
86
-                       'event_espresso'
87
-                   ),
88
-                   '<strong>',
89
-                   '</strong>'
90
-               )
91
-               . '</li>'
92
-               . '<li>'
93
-               . sprintf(
94
-                   esc_html__(
95
-                       '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
96
-                       'event_espresso'
97
-                   ),
98
-                   '<strong>',
99
-                   '</strong>'
100
-               )
101
-               . '</li>'
102
-               . '<li>'
103
-               . sprintf(
104
-                   esc_html__(
105
-                       '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
106
-                       'event_espresso'
107
-                   ),
108
-                   '<strong>',
109
-                   '</strong>'
110
-               )
111
-               . '</li>',
112
-            '[INVOICE_LINK]'                    => esc_html__(
113
-                'This is a full html link to the invoice',
114
-                'event_espresso'
115
-            ),
116
-            '[INVOICE_URL]'                     => esc_html__(
117
-                'This is just the url for the invoice',
118
-                'event_espresso'
119
-            ),
120
-            '[INVOICE_LOGO_URL]'                => esc_html__(
121
-                'This returns the url for the logo uploaded via the invoice settings page.',
122
-                'event_espresso'
123
-            ),
124
-            '[INVOICE_LOGO]'                    => esc_html__(
125
-                'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
126
-                'event_espresso'
127
-            ),
128
-            '[INVOICE_PAYEE_NAME]'              => esc_html__(
129
-                'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
130
-                'event_espresso'
131
-            ),
132
-            '[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
133
-                'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
134
-                'event_espresso'
135
-            ),
136
-            '[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
137
-                'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
138
-                'event_espresso'
139
-            ),
140
-            '[INVOICE_PAYEE_EMAIL]'             => esc_html__(
141
-                'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
142
-                'event_espresso'
143
-            ),
144
-            '[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
145
-                esc_html__(
146
-                    'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
147
-                    'event_espresso'
148
-                ),
149
-                '<code>',
150
-                '</code>'
151
-            ),
152
-            '[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
153
-            '[TXN_STATUS]'                      => esc_html__(
154
-                'The transaction status for the transaction.',
155
-                'event_espresso'
156
-            ),
157
-            '[TXN_STATUS_ID]'                   => esc_html__(
158
-                'The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
159
-                'event_espresso'
160
-            ),
161
-            '[PAYMENT_STATUS]'                  => esc_html__(
162
-                'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
163
-                'event_espresso'
164
-            ),
165
-            '[PAYMENT_GATEWAY]'                 => esc_html__(
166
-                'The payment gateway used for the transaction',
167
-                'event_espresso'
168
-            ),
169
-            '[AMOUNT_PAID]'                     => esc_html__(
170
-                'The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
171
-                'event_espresso'
172
-            ),
173
-            '[LAST_AMOUNT_PAID]'                => esc_html__(
174
-                'This is the last payment or refund made on the transaction related to the message being generated.',
175
-                'event_espresso'
176
-            ),
177
-            '[TOTAL_AMOUNT_PAID]'               => esc_html__(
178
-                'This parses to the total amount paid over all payments',
179
-                'event_espresso'
180
-            ),
181
-            '[TOTAL_OWING]'                     => esc_html__(
182
-                'The total owing on a transaction with no attributes.',
183
-                'event_espresso'
184
-            ),
185
-            '[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
186
-            '[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
187
-            '[OWING_STATUS_MESSAGE_*]'          => esc_html__(
188
-                'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
189
-                'event_espresso'
190
-            )
191
-               . '<p></ul>'
192
-               . '<li><strong>still_owing</strong>:'
193
-               . esc_html__(
194
-                   'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
195
-                   'event_espresso'
196
-               )
197
-               . sprintf(
198
-                   esc_html__('%sPlease make a payment.%s', 'event_espresso'),
199
-                   '<a href="[PAYMENT_URL]" class="noPrint">',
200
-                   '</a>'
201
-               )
202
-               . '</li>'
203
-               .
204
-               '<li><strong>none_owing</strong>:'
205
-               . esc_html__(
206
-                   'If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
207
-                   'event_espresso'
208
-               )
209
-               . '</li></ul></p>',
210
-            '[TXN_TOTAL_TICKETS]'               => esc_html__(
211
-                'The total number of all tickets purchased in a transaction',
212
-                'event_espresso'
213
-            ),
214
-            '[TKT_QTY_PURCHASED]'               => sprintf(
215
-                esc_html__(
216
-                    'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
217
-                    'event_espresso'
218
-                ),
219
-                '<strong>',
220
-                '</strong>'
221
-            ),
222
-            '[TRANSACTION_ADMIN_URL]'           => esc_html__(
223
-                'The url to the admin page for this transaction',
224
-                'event_espresso'
225
-            ),
226
-            '[RECEIPT_URL]'                     => esc_html__(
227
-                'This parses to the generated url for retrieving the receipt for the transaction',
228
-                'event_espresso'
229
-            ),
230
-            '[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
231
-                'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
232
-                'event_espresso'
233
-            ),
234
-            '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
235
-                esc_html__(
236
-                    'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
237
-                    'event_espresso'
238
-                ),
239
-                '<code>[INVOICE_RECEIPT_SWITCHER_URL]',
240
-                '</code>'
241
-            ),
242
-            '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__(
243
-                'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.',
244
-                'event_espresso'
245
-            ),
246
-        );
247
-    }
248
-
249
-
250
-    /**
251
-     * @param  string $shortcode the shortcode to be parsed.
252
-     * @return string parsed shortcode
253
-     * @throws EE_Error
254
-     * @throws InvalidArgumentException
255
-     * @throws ReflectionException
256
-     * @throws InvalidDataTypeException
257
-     * @throws InvalidInterfaceException
258
-     */
259
-    protected function _parser($shortcode)
260
-    {
261
-        //attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
262
-        // _extra_data for the transaction.
263
-        $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
264
-        $transaction = ! $transaction instanceof EE_Transaction
265
-                       && is_array($this->_extra_data)
266
-                       && isset($this->_extra_data['data'])
267
-                       && $this->_extra_data['data'] instanceof EE_Messages_Addressee
268
-                            ? $this->_extra_data['data']->txn
269
-                            : $transaction;
270
-        //payment
271
-        $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
272
-        $payment = ! $payment instanceof EE_Payment
273
-                   && is_array($this->_extra_data)
274
-                   && isset($this->_extra_data['data'])
275
-                   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
276
-            : $payment;
277
-        if (! $transaction instanceof EE_Transaction) {
278
-            return '';
279
-        }
280
-        switch ($shortcode) {
281
-            case '[TXN_ID]':
282
-                return $transaction->ID();
283
-                break;
284
-            case '[PAYMENT_URL]':
285
-                $payment_url = $transaction->payment_overview_url();
286
-                return empty($payment_url)
287
-                    ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
288
-                    : $payment_url;
289
-                break;
290
-            case '[INVOICE_LINK]':
291
-                $invoice_url = $transaction->invoice_url();
292
-                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
293
-                return sprintf(
294
-                    esc_html__('%sClick here for Invoice%s', 'event_espresso'),
295
-                    '<a href="' . $invoice_url . '">',
296
-                    '</a>'
297
-                );
298
-                break;
299
-            case '[INVOICE_URL]':
300
-                $invoice_url = $transaction->invoice_url();
301
-                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
302
-                break;
303
-            case '[INVOICE_LOGO_URL]':
304
-                return $this->_get_invoice_logo();
305
-                break;
306
-            case '[INVOICE_LOGO]':
307
-                return $this->_get_invoice_logo(true);
308
-                break;
309
-            case '[INVOICE_PAYEE_NAME]':
310
-                return $this->_get_invoice_payee_name();
311
-                break;
312
-            case '[INVOICE_PAYEE_ADDRESS]':
313
-                return $this->_get_invoice_payee_address();
314
-                break;
315
-            case '[INVOICE_PAYMENT_INSTRUCTIONS]':
316
-                return $this->_get_invoice_payment_instructions();
317
-                break;
318
-            case '[INVOICE_PAYEE_EMAIL]':
319
-                return $this->_get_invoice_payee_email();
320
-                break;
321
-            case '[TOTAL_COST]':
322
-                $total = $transaction->total();
323
-                return ! empty($total) ? EEH_Template::format_currency($total): '';
324
-                break;
325
-            case '[PAYMENT_STATUS]':
326
-                $status = $transaction->pretty_status();
327
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
328
-                break; /**/
329
-            // note the [payment_status] shortcode is kind of misleading because payment status might be different
330
-            // from txn status so I'm adding this here for clarity.
331
-            case '[TXN_STATUS]':
332
-                $status = $transaction->pretty_status();
333
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
334
-                break;
335
-            case '[TXN_STATUS_ID]':
336
-                return $transaction->status_ID();
337
-                break;
338
-            case '[PAYMENT_GATEWAY]':
339
-                return $this->_get_payment_gateway($transaction);
340
-                break;
341
-            case '[AMOUNT_PAID]':
342
-                return $payment instanceof EE_Payment
343
-                    ? EEH_Template::format_currency($payment->amount())
344
-                    : EEH_Template::format_currency(0);
345
-                break;
346
-            case '[LAST_AMOUNT_PAID]':
347
-                $last_payment = $transaction->last_payment();
348
-                return $last_payment instanceof EE_Payment
349
-                    ? EEH_Template::format_currency($last_payment->amount())
350
-                    : EEH_Template::format_currency(0);
351
-            case '[TOTAL_AMOUNT_PAID]':
352
-                return EEH_Template::format_currency($transaction->paid());
353
-                break;
354
-            case '[TOTAL_OWING]':
355
-                $total_owing = $transaction->remaining();
356
-                return EEH_Template::format_currency($total_owing);
357
-                break;
358
-            case '[TXN_SUBTOTAL]':
359
-                return EEH_Template::format_currency($this->_get_subtotal());
360
-                break;
361
-            case '[TXN_TAX_SUBTOTAL]':
362
-                return EEH_Template::format_currency($this->_get_subtotal(true));
363
-                break;
364
-            case '[TKT_QTY_PURCHASED]':
365
-            case '[TXN_TOTAL_TICKETS]':
366
-                return $this->_data->total_ticket_count;
367
-                break;
368
-            case '[TRANSACTION_ADMIN_URL]':
369
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
370
-                $query_args = array(
371
-                    'page'   => 'espresso_transactions',
372
-                    'action' => 'view_transaction',
373
-                    'TXN_ID' => $transaction->ID(),
374
-                );
375
-                $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
376
-                return $url;
377
-                break;
378
-            case '[RECEIPT_URL]':
379
-                //get primary_registration
380
-                $reg = $this->_data->primary_reg_obj;
381
-                if (! $reg instanceof EE_Registration) {
382
-                    return '';
383
-                }
384
-                return $reg->receipt_url();
385
-                break;
386
-            case '[INVOICE_RECEIPT_SWITCHER_URL]':
387
-                return $this->_get_invoice_receipt_switcher(false);
388
-                break;
389
-            case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
390
-                return $this->_get_invoice_receipt_switcher();
391
-                break;
392
-            case '[LAST_PAYMENT_TRANSACTION_ID]':
393
-                $id = '';
394
-                $payment = $payment instanceof EE_Payment && $payment->ID() !== 0
395
-                    ? $payment
396
-                    : $transaction->last_payment();
397
-                if ($payment instanceof EE_Payment) {
398
-                    $id = $payment->txn_id_chq_nmbr();
399
-                }
400
-                return $id;
401
-                break;
402
-        }
403
-        if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
404
-            return $this->_get_custom_total_owing($shortcode);
405
-        }
406
-        if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
407
-            return $this->_get_invoice_payee_tax_number($shortcode);
408
-        }
409
-        if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
410
-            return $this->_get_payment_link_if_needed($shortcode);
411
-        }
412
-        if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
413
-            return $this->_get_payment_due_date($shortcode, $transaction);
414
-        }
415
-        return '';
416
-    }
417
-
418
-
419
-    /**
420
-     * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
421
-     *
422
-     * @since 4.5.0
423
-     * @param string $shortcode the incoming shortcode
424
-     * @return string parsed.
425
-     * @throws EE_Error
426
-     */
427
-    private function _get_custom_total_owing($shortcode)
428
-    {
429
-        $valid_shortcodes = array('transaction');
430
-        $attrs = $this->_get_shortcode_attrs($shortcode);
431
-        //ensure default is set.
432
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
433
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
434
-            ? $addressee->txn->remaining() : 0;
435
-        if ($total_owing > 0) {
436
-            $owing_content = ! empty($attrs['still_owing'])
437
-                ? $attrs['still_owing']
438
-                : sprintf(
439
-                    esc_html__('%sPlease make a payment.%s', 'event_espresso'),
440
-                    '<a href="[PAYMENT_URL]" class="noPrint">',
441
-                    '</a>'
442
-                );
443
-            $owing_content = $this->_shortcode_helper->parse_message_template(
444
-                $owing_content,
445
-                $addressee,
446
-                $valid_shortcodes,
447
-                $this->_message_type,
448
-                $this->_messenger,
449
-                $this->_message
450
-            );
451
-        } else {
452
-            $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
453
-        }
454
-        return $owing_content;
455
-    }
456
-
457
-
458
-    /**
459
-     * @param EE_Transaction $transaction
460
-     * @return string
461
-     * @throws EE_Error
462
-     */
463
-    private function _get_payment_gateway($transaction)
464
-    {
465
-        if ($transaction instanceof EE_Transaction){
466
-            $pm = $transaction->payment_method();
467
-        } else {
468
-            $pm = null;
469
-        }
470
-        return $pm instanceof EE_Payment_Method ? $pm->name() : '';
471
-    }
472
-
473
-
474
-    /**
475
-     * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
476
-     * not present then the organization logo is used if its found (set on the organization settings page).
477
-     *
478
-     * @since 4.5.0
479
-     * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
480
-     * @return string url or html
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     */
486
-    private function _get_invoice_logo($img_tags = false)
487
-    {
488
-        $invoice_logo_url = '';
489
-        //try to get the invoice payment method's logo for this transaction image first
490
-        $pm = $this->_get_invoice_payment_method();
491
-        if ($pm instanceof EE_Payment_Method) {
492
-            $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
493
-        }
494
-        if (empty($invoice_logo_url)) {
495
-            $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
496
-        }
497
-        if (empty($invoice_logo_url)) {
498
-            return '';
499
-        }
500
-        if (! $img_tags) {
501
-            return $invoice_logo_url;
502
-        }
503
-        //image tags have been requested.
504
-        $image_size = getimagesize($invoice_logo_url);
505
-        //if image is wider than 300px, set the width to 300
506
-        if ($image_size[0] > 300) {
507
-            $image_width = 300;
508
-        } else {
509
-            $image_width = $image_size[0];
510
-        }
511
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
512
-    }
513
-
514
-
515
-    /**
516
-     * Used to retrieve the appropriate content for the invoice payee name shortcode
517
-     *
518
-     * @since 4.5.0
519
-     * @return string
520
-     * @throws EE_Error
521
-     * @throws InvalidArgumentException
522
-     * @throws InvalidDataTypeException
523
-     * @throws InvalidInterfaceException
524
-     */
525
-    private function _get_invoice_payee_name()
526
-    {
527
-        $payee_name = null;
528
-        $pm = $this->_get_invoice_payment_method();
529
-        if ($pm instanceof EE_Payment_Method) {
530
-            $payee_name = $pm->get_extra_meta('pdf_payee_name', true);
531
-        }
532
-        $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
533
-        return $payee_name;
534
-    }
535
-
536
-
537
-    /**
538
-     * gets the default invoice payment method, but has a filter so it can be overridden
539
-     *
540
-     * @return EE_Payment_Method|null
541
-     * @throws EE_Error
542
-     * @throws InvalidArgumentException
543
-     * @throws InvalidDataTypeException
544
-     * @throws InvalidInterfaceException
545
-     */
546
-    private function _get_invoice_payment_method()
547
-    {
548
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
549
-            $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
550
-            $transaction = ! $transaction instanceof EE_Transaction
551
-                           && is_array($this->_extra_data)
552
-                           && isset($this->_extra_data['data'])
553
-                           && $this->_extra_data['data'] instanceof EE_Messages_Addressee
554
-                ? $this->_extra_data['data']->txn : $transaction;
555
-            //get the invoice payment method, and remember it for the next call too
556
-            $this->_invoice_pm = apply_filters(
557
-                'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
558
-                EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
559
-                $transaction
560
-            );
561
-        }
562
-        return $this->_invoice_pm;
563
-    }
564
-
565
-
566
-    /**
567
-     * Used to retrieve the appropriate content for the invoice payee email shortcode
568
-     *
569
-     * @since 4.5.0
570
-     * @return string
571
-     * @throws EE_Error
572
-     * @throws InvalidArgumentException
573
-     * @throws InvalidDataTypeException
574
-     * @throws InvalidInterfaceException
575
-     */
576
-    private function _get_invoice_payee_email()
577
-    {
578
-        $payee_email = null;
579
-        $pm = $this->_get_invoice_payment_method();
580
-        if ($pm instanceof EE_Payment_Method) {
581
-            $payee_email = $pm->get_extra_meta('pdf_payee_email', true);
582
-        }
583
-        $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
584
-            : $payee_email;
585
-        return $payee_email;
586
-    }
587
-
588
-
589
-    /**
590
-     * Used to retrieve the appropriate content for the invoice payee tax number shortcode
591
-     *
592
-     * @since 4.5.0
593
-     * @param string $shortcode
594
-     * @return string
595
-     * @throws EE_Error
596
-     * @throws InvalidArgumentException
597
-     * @throws InvalidDataTypeException
598
-     * @throws InvalidInterfaceException
599
-     */
600
-    private function _get_invoice_payee_tax_number($shortcode)
601
-    {
602
-        $payee_tax_number = null;
603
-        $pm = $this->_get_invoice_payment_method();
604
-        if ($pm instanceof EE_Payment_Method) {
605
-            $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
606
-        }
607
-        $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
608
-            : $payee_tax_number;
609
-        if (empty($payee_tax_number)) {
610
-            return '';
611
-        }
612
-        //any attributes?
613
-        $attrs = $this->_get_shortcode_attrs($shortcode);
614
-        //prefix?
615
-        $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
616
-        return $prefix . $payee_tax_number;
617
-    }
618
-
619
-
620
-    /**
621
-     * Used to retrieve the appropriate content for the invoice payee address shortcode.
622
-     *
623
-     * @since 4.5.0
624
-     * @return string
625
-     * @throws EE_Error
626
-     * @throws InvalidArgumentException
627
-     * @throws ReflectionException
628
-     * @throws InvalidDataTypeException
629
-     * @throws InvalidInterfaceException
630
-     */
631
-    private function _get_invoice_payee_address()
632
-    {
633
-        $payee_address = null;
634
-        $pm = $this->_get_invoice_payment_method();
635
-        if ($pm instanceof EE_Payment_Method) {
636
-            $payee_address = $pm->get_extra_meta('pdf_payee_address', true);
637
-        }
638
-        if (empty($payee_address)) {
639
-            $organization = EE_Registry::instance()->CFG->organization;
640
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
641
-            $payee_address .= ! empty($organization->address_2)
642
-                ? $organization->get_pretty('address_2') . '<br>'
643
-                : '';
644
-            $payee_address .= $organization->get_pretty('city') . '<br>';
645
-            //state
646
-            $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
647
-            $payee_address .= $state instanceof EE_State ? $state->name() : '';
648
-            //Country
649
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
650
-            $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
651
-        }
652
-        return $payee_address;
653
-    }
654
-
655
-
656
-    /**
657
-     * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
658
-     *
659
-     * @since 4.5.0
660
-     * @return string
661
-     * @throws EE_Error
662
-     * @throws InvalidArgumentException
663
-     * @throws InvalidDataTypeException
664
-     * @throws InvalidInterfaceException
665
-     */
666
-    private function _get_invoice_payment_instructions()
667
-    {
668
-        $instructions = null;
669
-        $pm = $this->_get_invoice_payment_method();
670
-        return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
671
-    }
672
-
673
-
674
-    /**
675
-     * get invoice/receipt switch button or url.
676
-     *
677
-     * @param bool $button true (default) returns the html for a button, false just returns the url.
678
-     * @return string
679
-     * @throws EE_Error
680
-     */
681
-    protected function _get_invoice_receipt_switcher($button = true)
682
-    {
683
-        $reg = $this->_data->primary_reg_obj;
684
-        $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
685
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
686
-            return '';
687
-        }
688
-        $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
689
-        $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
690
-            ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
691
-        $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
692
-        $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
693
-        if (! $button) {
694
-            return $switch_to_url;
695
-        }
696
-        if (! empty($switch_to_url)) {
697
-            return '
24
+	/**
25
+	 * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
26
+	 */
27
+	protected $_invoice_pm;
28
+
29
+
30
+
31
+	protected function _init_props()
32
+	{
33
+		$this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
34
+		$this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
35
+		$this->_shortcodes = array(
36
+			'[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
37
+			'[PAYMENT_URL]'                     => esc_html__(
38
+				'This is a link to make a payment for the event',
39
+				'event_espresso'
40
+			),
41
+			'[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
42
+				'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
43
+				'event_espresso'
44
+			)
45
+			   . '<ul>'
46
+			   . '<li>'
47
+			   . sprintf(
48
+				   esc_html__(
49
+					   '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
50
+					   'event_espresso'
51
+				   ),
52
+				   '<strong>',
53
+				   '</strong>'
54
+			   )
55
+			   . '</li>'
56
+			   . '<li>'
57
+			   . sprintf(
58
+				   esc_html__(
59
+					   '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
60
+					   'event_espresso'
61
+				   ),
62
+				   '<strong>',
63
+				   '</strong>'
64
+			   )
65
+			   . '</li>'
66
+			   . '<li>'
67
+			   . sprintf(
68
+				   esc_html__(
69
+					   '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
70
+					   'event_espresso'
71
+				   ),
72
+				   '<strong>',
73
+				   '</strong>'
74
+			   )
75
+			   . '</li>'
76
+			   . '</ul>',
77
+			'[PAYMENT_DUE_DATE_*]'              => esc_html__(
78
+				'This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
79
+				'event_espresso'
80
+			)
81
+			   . '<ul>'
82
+			   . '<li>'
83
+			   . sprintf(
84
+				   esc_html__(
85
+					   '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
86
+					   'event_espresso'
87
+				   ),
88
+				   '<strong>',
89
+				   '</strong>'
90
+			   )
91
+			   . '</li>'
92
+			   . '<li>'
93
+			   . sprintf(
94
+				   esc_html__(
95
+					   '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
96
+					   'event_espresso'
97
+				   ),
98
+				   '<strong>',
99
+				   '</strong>'
100
+			   )
101
+			   . '</li>'
102
+			   . '<li>'
103
+			   . sprintf(
104
+				   esc_html__(
105
+					   '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
106
+					   'event_espresso'
107
+				   ),
108
+				   '<strong>',
109
+				   '</strong>'
110
+			   )
111
+			   . '</li>',
112
+			'[INVOICE_LINK]'                    => esc_html__(
113
+				'This is a full html link to the invoice',
114
+				'event_espresso'
115
+			),
116
+			'[INVOICE_URL]'                     => esc_html__(
117
+				'This is just the url for the invoice',
118
+				'event_espresso'
119
+			),
120
+			'[INVOICE_LOGO_URL]'                => esc_html__(
121
+				'This returns the url for the logo uploaded via the invoice settings page.',
122
+				'event_espresso'
123
+			),
124
+			'[INVOICE_LOGO]'                    => esc_html__(
125
+				'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
126
+				'event_espresso'
127
+			),
128
+			'[INVOICE_PAYEE_NAME]'              => esc_html__(
129
+				'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
130
+				'event_espresso'
131
+			),
132
+			'[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
133
+				'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
134
+				'event_espresso'
135
+			),
136
+			'[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
137
+				'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
138
+				'event_espresso'
139
+			),
140
+			'[INVOICE_PAYEE_EMAIL]'             => esc_html__(
141
+				'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
142
+				'event_espresso'
143
+			),
144
+			'[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
145
+				esc_html__(
146
+					'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
147
+					'event_espresso'
148
+				),
149
+				'<code>',
150
+				'</code>'
151
+			),
152
+			'[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
153
+			'[TXN_STATUS]'                      => esc_html__(
154
+				'The transaction status for the transaction.',
155
+				'event_espresso'
156
+			),
157
+			'[TXN_STATUS_ID]'                   => esc_html__(
158
+				'The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
159
+				'event_espresso'
160
+			),
161
+			'[PAYMENT_STATUS]'                  => esc_html__(
162
+				'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
163
+				'event_espresso'
164
+			),
165
+			'[PAYMENT_GATEWAY]'                 => esc_html__(
166
+				'The payment gateway used for the transaction',
167
+				'event_espresso'
168
+			),
169
+			'[AMOUNT_PAID]'                     => esc_html__(
170
+				'The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
171
+				'event_espresso'
172
+			),
173
+			'[LAST_AMOUNT_PAID]'                => esc_html__(
174
+				'This is the last payment or refund made on the transaction related to the message being generated.',
175
+				'event_espresso'
176
+			),
177
+			'[TOTAL_AMOUNT_PAID]'               => esc_html__(
178
+				'This parses to the total amount paid over all payments',
179
+				'event_espresso'
180
+			),
181
+			'[TOTAL_OWING]'                     => esc_html__(
182
+				'The total owing on a transaction with no attributes.',
183
+				'event_espresso'
184
+			),
185
+			'[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
186
+			'[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
187
+			'[OWING_STATUS_MESSAGE_*]'          => esc_html__(
188
+				'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
189
+				'event_espresso'
190
+			)
191
+			   . '<p></ul>'
192
+			   . '<li><strong>still_owing</strong>:'
193
+			   . esc_html__(
194
+				   'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
195
+				   'event_espresso'
196
+			   )
197
+			   . sprintf(
198
+				   esc_html__('%sPlease make a payment.%s', 'event_espresso'),
199
+				   '<a href="[PAYMENT_URL]" class="noPrint">',
200
+				   '</a>'
201
+			   )
202
+			   . '</li>'
203
+			   .
204
+			   '<li><strong>none_owing</strong>:'
205
+			   . esc_html__(
206
+				   'If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
207
+				   'event_espresso'
208
+			   )
209
+			   . '</li></ul></p>',
210
+			'[TXN_TOTAL_TICKETS]'               => esc_html__(
211
+				'The total number of all tickets purchased in a transaction',
212
+				'event_espresso'
213
+			),
214
+			'[TKT_QTY_PURCHASED]'               => sprintf(
215
+				esc_html__(
216
+					'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
217
+					'event_espresso'
218
+				),
219
+				'<strong>',
220
+				'</strong>'
221
+			),
222
+			'[TRANSACTION_ADMIN_URL]'           => esc_html__(
223
+				'The url to the admin page for this transaction',
224
+				'event_espresso'
225
+			),
226
+			'[RECEIPT_URL]'                     => esc_html__(
227
+				'This parses to the generated url for retrieving the receipt for the transaction',
228
+				'event_espresso'
229
+			),
230
+			'[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
231
+				'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
232
+				'event_espresso'
233
+			),
234
+			'[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
235
+				esc_html__(
236
+					'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
237
+					'event_espresso'
238
+				),
239
+				'<code>[INVOICE_RECEIPT_SWITCHER_URL]',
240
+				'</code>'
241
+			),
242
+			'[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__(
243
+				'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.',
244
+				'event_espresso'
245
+			),
246
+		);
247
+	}
248
+
249
+
250
+	/**
251
+	 * @param  string $shortcode the shortcode to be parsed.
252
+	 * @return string parsed shortcode
253
+	 * @throws EE_Error
254
+	 * @throws InvalidArgumentException
255
+	 * @throws ReflectionException
256
+	 * @throws InvalidDataTypeException
257
+	 * @throws InvalidInterfaceException
258
+	 */
259
+	protected function _parser($shortcode)
260
+	{
261
+		//attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
262
+		// _extra_data for the transaction.
263
+		$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
264
+		$transaction = ! $transaction instanceof EE_Transaction
265
+					   && is_array($this->_extra_data)
266
+					   && isset($this->_extra_data['data'])
267
+					   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
268
+							? $this->_extra_data['data']->txn
269
+							: $transaction;
270
+		//payment
271
+		$payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
272
+		$payment = ! $payment instanceof EE_Payment
273
+				   && is_array($this->_extra_data)
274
+				   && isset($this->_extra_data['data'])
275
+				   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
276
+			: $payment;
277
+		if (! $transaction instanceof EE_Transaction) {
278
+			return '';
279
+		}
280
+		switch ($shortcode) {
281
+			case '[TXN_ID]':
282
+				return $transaction->ID();
283
+				break;
284
+			case '[PAYMENT_URL]':
285
+				$payment_url = $transaction->payment_overview_url();
286
+				return empty($payment_url)
287
+					? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
288
+					: $payment_url;
289
+				break;
290
+			case '[INVOICE_LINK]':
291
+				$invoice_url = $transaction->invoice_url();
292
+				$invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
293
+				return sprintf(
294
+					esc_html__('%sClick here for Invoice%s', 'event_espresso'),
295
+					'<a href="' . $invoice_url . '">',
296
+					'</a>'
297
+				);
298
+				break;
299
+			case '[INVOICE_URL]':
300
+				$invoice_url = $transaction->invoice_url();
301
+				return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
302
+				break;
303
+			case '[INVOICE_LOGO_URL]':
304
+				return $this->_get_invoice_logo();
305
+				break;
306
+			case '[INVOICE_LOGO]':
307
+				return $this->_get_invoice_logo(true);
308
+				break;
309
+			case '[INVOICE_PAYEE_NAME]':
310
+				return $this->_get_invoice_payee_name();
311
+				break;
312
+			case '[INVOICE_PAYEE_ADDRESS]':
313
+				return $this->_get_invoice_payee_address();
314
+				break;
315
+			case '[INVOICE_PAYMENT_INSTRUCTIONS]':
316
+				return $this->_get_invoice_payment_instructions();
317
+				break;
318
+			case '[INVOICE_PAYEE_EMAIL]':
319
+				return $this->_get_invoice_payee_email();
320
+				break;
321
+			case '[TOTAL_COST]':
322
+				$total = $transaction->total();
323
+				return ! empty($total) ? EEH_Template::format_currency($total): '';
324
+				break;
325
+			case '[PAYMENT_STATUS]':
326
+				$status = $transaction->pretty_status();
327
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
328
+				break; /**/
329
+			// note the [payment_status] shortcode is kind of misleading because payment status might be different
330
+			// from txn status so I'm adding this here for clarity.
331
+			case '[TXN_STATUS]':
332
+				$status = $transaction->pretty_status();
333
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
334
+				break;
335
+			case '[TXN_STATUS_ID]':
336
+				return $transaction->status_ID();
337
+				break;
338
+			case '[PAYMENT_GATEWAY]':
339
+				return $this->_get_payment_gateway($transaction);
340
+				break;
341
+			case '[AMOUNT_PAID]':
342
+				return $payment instanceof EE_Payment
343
+					? EEH_Template::format_currency($payment->amount())
344
+					: EEH_Template::format_currency(0);
345
+				break;
346
+			case '[LAST_AMOUNT_PAID]':
347
+				$last_payment = $transaction->last_payment();
348
+				return $last_payment instanceof EE_Payment
349
+					? EEH_Template::format_currency($last_payment->amount())
350
+					: EEH_Template::format_currency(0);
351
+			case '[TOTAL_AMOUNT_PAID]':
352
+				return EEH_Template::format_currency($transaction->paid());
353
+				break;
354
+			case '[TOTAL_OWING]':
355
+				$total_owing = $transaction->remaining();
356
+				return EEH_Template::format_currency($total_owing);
357
+				break;
358
+			case '[TXN_SUBTOTAL]':
359
+				return EEH_Template::format_currency($this->_get_subtotal());
360
+				break;
361
+			case '[TXN_TAX_SUBTOTAL]':
362
+				return EEH_Template::format_currency($this->_get_subtotal(true));
363
+				break;
364
+			case '[TKT_QTY_PURCHASED]':
365
+			case '[TXN_TOTAL_TICKETS]':
366
+				return $this->_data->total_ticket_count;
367
+				break;
368
+			case '[TRANSACTION_ADMIN_URL]':
369
+				require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
370
+				$query_args = array(
371
+					'page'   => 'espresso_transactions',
372
+					'action' => 'view_transaction',
373
+					'TXN_ID' => $transaction->ID(),
374
+				);
375
+				$url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
376
+				return $url;
377
+				break;
378
+			case '[RECEIPT_URL]':
379
+				//get primary_registration
380
+				$reg = $this->_data->primary_reg_obj;
381
+				if (! $reg instanceof EE_Registration) {
382
+					return '';
383
+				}
384
+				return $reg->receipt_url();
385
+				break;
386
+			case '[INVOICE_RECEIPT_SWITCHER_URL]':
387
+				return $this->_get_invoice_receipt_switcher(false);
388
+				break;
389
+			case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
390
+				return $this->_get_invoice_receipt_switcher();
391
+				break;
392
+			case '[LAST_PAYMENT_TRANSACTION_ID]':
393
+				$id = '';
394
+				$payment = $payment instanceof EE_Payment && $payment->ID() !== 0
395
+					? $payment
396
+					: $transaction->last_payment();
397
+				if ($payment instanceof EE_Payment) {
398
+					$id = $payment->txn_id_chq_nmbr();
399
+				}
400
+				return $id;
401
+				break;
402
+		}
403
+		if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
404
+			return $this->_get_custom_total_owing($shortcode);
405
+		}
406
+		if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
407
+			return $this->_get_invoice_payee_tax_number($shortcode);
408
+		}
409
+		if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
410
+			return $this->_get_payment_link_if_needed($shortcode);
411
+		}
412
+		if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
413
+			return $this->_get_payment_due_date($shortcode, $transaction);
414
+		}
415
+		return '';
416
+	}
417
+
418
+
419
+	/**
420
+	 * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
421
+	 *
422
+	 * @since 4.5.0
423
+	 * @param string $shortcode the incoming shortcode
424
+	 * @return string parsed.
425
+	 * @throws EE_Error
426
+	 */
427
+	private function _get_custom_total_owing($shortcode)
428
+	{
429
+		$valid_shortcodes = array('transaction');
430
+		$attrs = $this->_get_shortcode_attrs($shortcode);
431
+		//ensure default is set.
432
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
433
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
434
+			? $addressee->txn->remaining() : 0;
435
+		if ($total_owing > 0) {
436
+			$owing_content = ! empty($attrs['still_owing'])
437
+				? $attrs['still_owing']
438
+				: sprintf(
439
+					esc_html__('%sPlease make a payment.%s', 'event_espresso'),
440
+					'<a href="[PAYMENT_URL]" class="noPrint">',
441
+					'</a>'
442
+				);
443
+			$owing_content = $this->_shortcode_helper->parse_message_template(
444
+				$owing_content,
445
+				$addressee,
446
+				$valid_shortcodes,
447
+				$this->_message_type,
448
+				$this->_messenger,
449
+				$this->_message
450
+			);
451
+		} else {
452
+			$owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
453
+		}
454
+		return $owing_content;
455
+	}
456
+
457
+
458
+	/**
459
+	 * @param EE_Transaction $transaction
460
+	 * @return string
461
+	 * @throws EE_Error
462
+	 */
463
+	private function _get_payment_gateway($transaction)
464
+	{
465
+		if ($transaction instanceof EE_Transaction){
466
+			$pm = $transaction->payment_method();
467
+		} else {
468
+			$pm = null;
469
+		}
470
+		return $pm instanceof EE_Payment_Method ? $pm->name() : '';
471
+	}
472
+
473
+
474
+	/**
475
+	 * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
476
+	 * not present then the organization logo is used if its found (set on the organization settings page).
477
+	 *
478
+	 * @since 4.5.0
479
+	 * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
480
+	 * @return string url or html
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 */
486
+	private function _get_invoice_logo($img_tags = false)
487
+	{
488
+		$invoice_logo_url = '';
489
+		//try to get the invoice payment method's logo for this transaction image first
490
+		$pm = $this->_get_invoice_payment_method();
491
+		if ($pm instanceof EE_Payment_Method) {
492
+			$invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
493
+		}
494
+		if (empty($invoice_logo_url)) {
495
+			$invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
496
+		}
497
+		if (empty($invoice_logo_url)) {
498
+			return '';
499
+		}
500
+		if (! $img_tags) {
501
+			return $invoice_logo_url;
502
+		}
503
+		//image tags have been requested.
504
+		$image_size = getimagesize($invoice_logo_url);
505
+		//if image is wider than 300px, set the width to 300
506
+		if ($image_size[0] > 300) {
507
+			$image_width = 300;
508
+		} else {
509
+			$image_width = $image_size[0];
510
+		}
511
+		return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
512
+	}
513
+
514
+
515
+	/**
516
+	 * Used to retrieve the appropriate content for the invoice payee name shortcode
517
+	 *
518
+	 * @since 4.5.0
519
+	 * @return string
520
+	 * @throws EE_Error
521
+	 * @throws InvalidArgumentException
522
+	 * @throws InvalidDataTypeException
523
+	 * @throws InvalidInterfaceException
524
+	 */
525
+	private function _get_invoice_payee_name()
526
+	{
527
+		$payee_name = null;
528
+		$pm = $this->_get_invoice_payment_method();
529
+		if ($pm instanceof EE_Payment_Method) {
530
+			$payee_name = $pm->get_extra_meta('pdf_payee_name', true);
531
+		}
532
+		$payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
533
+		return $payee_name;
534
+	}
535
+
536
+
537
+	/**
538
+	 * gets the default invoice payment method, but has a filter so it can be overridden
539
+	 *
540
+	 * @return EE_Payment_Method|null
541
+	 * @throws EE_Error
542
+	 * @throws InvalidArgumentException
543
+	 * @throws InvalidDataTypeException
544
+	 * @throws InvalidInterfaceException
545
+	 */
546
+	private function _get_invoice_payment_method()
547
+	{
548
+		if (! $this->_invoice_pm instanceof EE_Payment_Method) {
549
+			$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
550
+			$transaction = ! $transaction instanceof EE_Transaction
551
+						   && is_array($this->_extra_data)
552
+						   && isset($this->_extra_data['data'])
553
+						   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
554
+				? $this->_extra_data['data']->txn : $transaction;
555
+			//get the invoice payment method, and remember it for the next call too
556
+			$this->_invoice_pm = apply_filters(
557
+				'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
558
+				EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
559
+				$transaction
560
+			);
561
+		}
562
+		return $this->_invoice_pm;
563
+	}
564
+
565
+
566
+	/**
567
+	 * Used to retrieve the appropriate content for the invoice payee email shortcode
568
+	 *
569
+	 * @since 4.5.0
570
+	 * @return string
571
+	 * @throws EE_Error
572
+	 * @throws InvalidArgumentException
573
+	 * @throws InvalidDataTypeException
574
+	 * @throws InvalidInterfaceException
575
+	 */
576
+	private function _get_invoice_payee_email()
577
+	{
578
+		$payee_email = null;
579
+		$pm = $this->_get_invoice_payment_method();
580
+		if ($pm instanceof EE_Payment_Method) {
581
+			$payee_email = $pm->get_extra_meta('pdf_payee_email', true);
582
+		}
583
+		$payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
584
+			: $payee_email;
585
+		return $payee_email;
586
+	}
587
+
588
+
589
+	/**
590
+	 * Used to retrieve the appropriate content for the invoice payee tax number shortcode
591
+	 *
592
+	 * @since 4.5.0
593
+	 * @param string $shortcode
594
+	 * @return string
595
+	 * @throws EE_Error
596
+	 * @throws InvalidArgumentException
597
+	 * @throws InvalidDataTypeException
598
+	 * @throws InvalidInterfaceException
599
+	 */
600
+	private function _get_invoice_payee_tax_number($shortcode)
601
+	{
602
+		$payee_tax_number = null;
603
+		$pm = $this->_get_invoice_payment_method();
604
+		if ($pm instanceof EE_Payment_Method) {
605
+			$payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
606
+		}
607
+		$payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
608
+			: $payee_tax_number;
609
+		if (empty($payee_tax_number)) {
610
+			return '';
611
+		}
612
+		//any attributes?
613
+		$attrs = $this->_get_shortcode_attrs($shortcode);
614
+		//prefix?
615
+		$prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
616
+		return $prefix . $payee_tax_number;
617
+	}
618
+
619
+
620
+	/**
621
+	 * Used to retrieve the appropriate content for the invoice payee address shortcode.
622
+	 *
623
+	 * @since 4.5.0
624
+	 * @return string
625
+	 * @throws EE_Error
626
+	 * @throws InvalidArgumentException
627
+	 * @throws ReflectionException
628
+	 * @throws InvalidDataTypeException
629
+	 * @throws InvalidInterfaceException
630
+	 */
631
+	private function _get_invoice_payee_address()
632
+	{
633
+		$payee_address = null;
634
+		$pm = $this->_get_invoice_payment_method();
635
+		if ($pm instanceof EE_Payment_Method) {
636
+			$payee_address = $pm->get_extra_meta('pdf_payee_address', true);
637
+		}
638
+		if (empty($payee_address)) {
639
+			$organization = EE_Registry::instance()->CFG->organization;
640
+			$payee_address = $organization->get_pretty('address_1') . '<br>';
641
+			$payee_address .= ! empty($organization->address_2)
642
+				? $organization->get_pretty('address_2') . '<br>'
643
+				: '';
644
+			$payee_address .= $organization->get_pretty('city') . '<br>';
645
+			//state
646
+			$state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
647
+			$payee_address .= $state instanceof EE_State ? $state->name() : '';
648
+			//Country
649
+			$payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
650
+			$payee_address .= ! empty($organization->zip) ? $organization->zip : '';
651
+		}
652
+		return $payee_address;
653
+	}
654
+
655
+
656
+	/**
657
+	 * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
658
+	 *
659
+	 * @since 4.5.0
660
+	 * @return string
661
+	 * @throws EE_Error
662
+	 * @throws InvalidArgumentException
663
+	 * @throws InvalidDataTypeException
664
+	 * @throws InvalidInterfaceException
665
+	 */
666
+	private function _get_invoice_payment_instructions()
667
+	{
668
+		$instructions = null;
669
+		$pm = $this->_get_invoice_payment_method();
670
+		return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
671
+	}
672
+
673
+
674
+	/**
675
+	 * get invoice/receipt switch button or url.
676
+	 *
677
+	 * @param bool $button true (default) returns the html for a button, false just returns the url.
678
+	 * @return string
679
+	 * @throws EE_Error
680
+	 */
681
+	protected function _get_invoice_receipt_switcher($button = true)
682
+	{
683
+		$reg = $this->_data->primary_reg_obj;
684
+		$message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
685
+		if (! $reg instanceof EE_Registration || empty($message_type)) {
686
+			return '';
687
+		}
688
+		$switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
689
+		$switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
690
+			? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
691
+		$switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
692
+		$switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
693
+		if (! $button) {
694
+			return $switch_to_url;
695
+		}
696
+		if (! empty($switch_to_url)) {
697
+			return '
698 698
 	<form method="post" action="' . $switch_to_url . '" >
699 699
 		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
700 700
 	</form>
701 701
 			';
702
-        }
703
-        return '';
704
-    }
705
-
706
-
707
-    /**
708
-     * This returns a subtotal.
709
-     *
710
-     * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
711
-     * @return int
712
-     * @throws EE_Error
713
-     */
714
-    private function _get_subtotal($tax = false)
715
-    {
716
-        $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
717
-        if (! $grand_total instanceof EE_Line_Item) {
718
-            return 0;
719
-        }
720
-        return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
721
-    }
722
-
723
-
724
-    /**
725
-     * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
726
-     *
727
-     * @since 4.7.0
728
-     * @param string $shortcode the incoming shortcode
729
-     * @return string parsed.
730
-     * @throws EE_Error
731
-     */
732
-    private function _get_payment_link_if_needed($shortcode)
733
-    {
734
-        $valid_shortcodes = array('transaction');
735
-        $attrs = $this->_get_shortcode_attrs($shortcode);
736
-        //ensure default is set.
737
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
738
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
739
-            ? $addressee->txn->remaining() : 0;
740
-        if ($total_owing > 0) {
741
-            $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
742
-            $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
743
-            $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
744
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
745
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
746
-            $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
747
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
748
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
749
-            //we need to re run this string through the parser to catch any shortcodes that are in it.
750
-            $owing_content = $this->_shortcode_helper->parse_message_template(
751
-                $content,
752
-                $addressee,
753
-                $valid_shortcodes,
754
-                $this->_message_type,
755
-                $this->_messenger,
756
-                $this->_message
757
-            );
758
-        } else {
759
-            return '';
760
-        }
761
-        return $owing_content;
762
-    }
763
-
764
-
765
-    /**
766
-     * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
767
-     *
768
-     * @since 4.8.28.rc.011
769
-     * @param string         $shortcode The shortcode being parsed.
770
-     * @param EE_Transaction $transaction
771
-     * @return string
772
-     * @throws EE_Error
773
-     */
774
-    protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
775
-    {
776
-        //if transaction is paid in full then we can just return an empty string
777
-        if ($transaction->remaining() === 0) {
778
-            return '';
779
-        }
780
-        $attrs = $this->_get_shortcode_attrs($shortcode);
781
-        $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
782
-        $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
783
-        $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
784
-            : esc_html__('Payment in full due by: ', 'event_espresso');
785
-        $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
786
-        //setup date due:
787
-        try {
788
-            if ($transaction_created instanceof DateTime) {
789
-                $date_due = $transaction_created->add(
790
-                    new DateInterval('P' . $days_until_due . 'D')
791
-                )->format($format);
792
-            } else {
793
-                throw new Exception();
794
-            }
795
-        } catch (Exception $e) {
796
-            //format was likely invalid.
797
-            $date_due = esc_html__(
798
-                'Unable to calculate date due, likely the format string is invalid.',
799
-                'event_espresso'
800
-            );
801
-        }
802
-        return $prefix_text . $date_due;
803
-    }
702
+		}
703
+		return '';
704
+	}
705
+
706
+
707
+	/**
708
+	 * This returns a subtotal.
709
+	 *
710
+	 * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
711
+	 * @return int
712
+	 * @throws EE_Error
713
+	 */
714
+	private function _get_subtotal($tax = false)
715
+	{
716
+		$grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
717
+		if (! $grand_total instanceof EE_Line_Item) {
718
+			return 0;
719
+		}
720
+		return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
721
+	}
722
+
723
+
724
+	/**
725
+	 * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
726
+	 *
727
+	 * @since 4.7.0
728
+	 * @param string $shortcode the incoming shortcode
729
+	 * @return string parsed.
730
+	 * @throws EE_Error
731
+	 */
732
+	private function _get_payment_link_if_needed($shortcode)
733
+	{
734
+		$valid_shortcodes = array('transaction');
735
+		$attrs = $this->_get_shortcode_attrs($shortcode);
736
+		//ensure default is set.
737
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
738
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
739
+			? $addressee->txn->remaining() : 0;
740
+		if ($total_owing > 0) {
741
+			$class = isset($attrs['class']) ? $attrs['class'] : 'callout';
742
+			$custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
743
+			$container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
744
+			$opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
745
+			$opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
746
+			$opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
747
+			$closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
748
+			$content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
749
+			//we need to re run this string through the parser to catch any shortcodes that are in it.
750
+			$owing_content = $this->_shortcode_helper->parse_message_template(
751
+				$content,
752
+				$addressee,
753
+				$valid_shortcodes,
754
+				$this->_message_type,
755
+				$this->_messenger,
756
+				$this->_message
757
+			);
758
+		} else {
759
+			return '';
760
+		}
761
+		return $owing_content;
762
+	}
763
+
764
+
765
+	/**
766
+	 * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
767
+	 *
768
+	 * @since 4.8.28.rc.011
769
+	 * @param string         $shortcode The shortcode being parsed.
770
+	 * @param EE_Transaction $transaction
771
+	 * @return string
772
+	 * @throws EE_Error
773
+	 */
774
+	protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
775
+	{
776
+		//if transaction is paid in full then we can just return an empty string
777
+		if ($transaction->remaining() === 0) {
778
+			return '';
779
+		}
780
+		$attrs = $this->_get_shortcode_attrs($shortcode);
781
+		$format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
782
+		$days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
783
+		$prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
784
+			: esc_html__('Payment in full due by: ', 'event_espresso');
785
+		$transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
786
+		//setup date due:
787
+		try {
788
+			if ($transaction_created instanceof DateTime) {
789
+				$date_due = $transaction_created->add(
790
+					new DateInterval('P' . $days_until_due . 'D')
791
+				)->format($format);
792
+			} else {
793
+				throw new Exception();
794
+			}
795
+		} catch (Exception $e) {
796
+			//format was likely invalid.
797
+			$date_due = esc_html__(
798
+				'Unable to calculate date due, likely the format string is invalid.',
799
+				'event_espresso'
800
+			);
801
+		}
802
+		return $prefix_text . $date_due;
803
+	}
804 804
 
805 805
 }
Please login to merge, or discard this patch.
modules/ticket_selector/EED_Ticket_Selector.module.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 
228 228
     /**
229
-     * @return array  or FALSE
229
+     * @return boolean|null  or FALSE
230 230
      * @throws EE_Error
231 231
      */
232 232
     public function process_ticket_selections()
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
 
240 240
     /**
241
-     * @return string
241
+     * @return false|null
242 242
      */
243 243
     public static function cancel_ticket_selections()
244 244
     {
Please login to merge, or discard this patch.
Indentation   +456 added lines, -456 removed lines patch added patch discarded remove patch
@@ -20,462 +20,462 @@
 block discarded – undo
20 20
 class EED_Ticket_Selector extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * @var DisplayTicketSelector $ticket_selector
25
-     */
26
-    private static $ticket_selector;
27
-
28
-    /**
29
-     * @var TicketSelectorIframeEmbedButton $iframe_embed_button
30
-     */
31
-    private static $iframe_embed_button;
32
-
33
-
34
-
35
-    /**
36
-     * @return EED_Module|EED_Ticket_Selector
37
-     */
38
-    public static function instance()
39
-    {
40
-        return parent::get_instance(__CLASS__);
41
-    }
42
-
43
-
44
-
45
-    /**
46
-     * @return void
47
-     */
48
-    protected function set_config()
49
-    {
50
-        $this->set_config_section('template_settings');
51
-        $this->set_config_class('EE_Ticket_Selector_Config');
52
-        $this->set_config_name('EED_Ticket_Selector');
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     *    set_hooks - for hooking into EE Core, other modules, etc
59
-     *
60
-     * @return void
61
-     */
62
-    public static function set_hooks()
63
-    {
64
-        // routing
65
-        EE_Config::register_route(
66
-            'iframe',
67
-            'EED_Ticket_Selector',
68
-            'ticket_selector_iframe',
69
-            'ticket_selector'
70
-        );
71
-        EE_Config::register_route(
72
-            'process_ticket_selections',
73
-            'EED_Ticket_Selector',
74
-            'process_ticket_selections'
75
-        );
76
-        EE_Config::register_route(
77
-            'cancel_ticket_selections',
78
-            'EED_Ticket_Selector',
79
-            'cancel_ticket_selections'
80
-        );
81
-        add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
82
-        add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1);
83
-        add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0);
84
-        add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10);
85
-        EED_Ticket_Selector::loadIframeAssets();
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
92
-     *
93
-     * @return void
94
-     */
95
-    public static function set_hooks_admin()
96
-    {
97
-        // hook into the end of the \EE_Admin_Page::_load_page_dependencies()
98
-        // to load assets for "espresso_events" page on the "edit" route (action)
99
-        add_action(
100
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
101
-            array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'),
102
-            10
103
-        );
104
-        /**
105
-         * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
106
-         * registrations work.
107
-         */
108
-        add_action(
109
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
110
-            array('EED_Ticket_Selector', 'set_definitions'),
111
-            10
112
-        );
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     *    set_definitions
119
-     *
120
-     * @return void
121
-     * @throws InvalidArgumentException
122
-     * @throws InvalidDataTypeException
123
-     * @throws InvalidInterfaceException
124
-     */
125
-    public static function set_definitions()
126
-    {
127
-        // don't do this twice
128
-        if (defined('TICKET_SELECTOR_ASSETS_URL')) {
129
-            return;
130
-        }
131
-        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
132
-        define(
133
-            'TICKET_SELECTOR_TEMPLATES_PATH',
134
-            str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS
135
-        );
136
-        //if config is not set, initialize
137
-        if (
138
-            ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
139
-        ) {
140
-            EED_Ticket_Selector::instance()->set_config();
141
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
142
-        }
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * @return DisplayTicketSelector
149
-     */
150
-    public static function ticketSelector()
151
-    {
152
-        if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
153
-            EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe());
154
-        }
155
-        return EED_Ticket_Selector::$ticket_selector;
156
-    }
157
-
158
-
159
-    /**
160
-     * gets the ball rolling
161
-     *
162
-     * @param WP $WP
163
-     * @return void
164
-     */
165
-    public function run($WP)
166
-    {
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @return TicketSelectorIframeEmbedButton
173
-     */
174
-    public static function getIframeEmbedButton()
175
-    {
176
-        if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
177
-            self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
178
-        }
179
-        return self::$iframe_embed_button;
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * ticket_selector_iframe_embed_button
186
-     *
187
-     * @return void
188
-     * @throws EE_Error
189
-     */
190
-    public static function ticket_selector_iframe_embed_button()
191
-    {
192
-        $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
193
-        $iframe_embed_button->addEventEditorIframeEmbedButton();
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * ticket_selector_iframe
200
-     *
201
-     * @return void
202
-     * @throws DomainException
203
-     * @throws EE_Error
204
-     */
205
-    public function ticket_selector_iframe()
206
-    {
207
-        $ticket_selector_iframe = new TicketSelectorIframe();
208
-        $ticket_selector_iframe->display();
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * creates buttons for selecting number of attendees for an event
215
-     *
216
-     * @param  WP_Post|int $event
217
-     * @param  bool        $view_details
218
-     * @return string
219
-     * @throws EE_Error
220
-     */
221
-    public static function display_ticket_selector($event = null, $view_details = false)
222
-    {
223
-        return EED_Ticket_Selector::ticketSelector()->display($event, $view_details);
224
-    }
225
-
226
-
227
-
228
-    /**
229
-     * @return array  or FALSE
230
-     * @throws EE_Error
231
-     */
232
-    public function process_ticket_selections()
233
-    {
234
-        $form = new ProcessTicketSelector();
235
-        return $form->processTicketSelections();
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * @return string
242
-     */
243
-    public static function cancel_ticket_selections()
244
-    {
245
-        $form = new ProcessTicketSelector();
246
-        return $form->cancelTicketSelections();
247
-    }
248
-
249
-
250
-
251
-    /**
252
-     * @return void
253
-     */
254
-    public static function translate_js_strings()
255
-    {
256
-        EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
257
-            'please select a datetime',
258
-            'event_espresso'
259
-        );
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     * @return void
266
-     */
267
-    public static function load_tckt_slctr_assets()
268
-    {
269
-        if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) {
270
-            // add some style
271
-            wp_register_style(
272
-                'ticket_selector',
273
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
274
-                array(),
275
-                EVENT_ESPRESSO_VERSION
276
-            );
277
-            wp_enqueue_style('ticket_selector');
278
-            // make it dance
279
-            wp_register_script(
280
-                'ticket_selector',
281
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
282
-                array('espresso_core'),
283
-                EVENT_ESPRESSO_VERSION,
284
-                true
285
-            );
286
-            wp_enqueue_script('ticket_selector');
287
-            require_once EE_LIBRARIES
288
-                         . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php';
289
-            \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
290
-        }
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * @return void
297
-     */
298
-    public static function loadIframeAssets()
299
-    {
300
-        // for event lists
301
-        add_filter(
302
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
303
-            array('EED_Ticket_Selector', 'iframeCss')
304
-        );
305
-        add_filter(
306
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
307
-            array('EED_Ticket_Selector', 'iframeJs')
308
-        );
309
-        // for ticket selectors
310
-        add_filter(
311
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
312
-            array('EED_Ticket_Selector', 'iframeCss')
313
-        );
314
-        add_filter(
315
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
316
-            array('EED_Ticket_Selector', 'iframeJs')
317
-        );
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
324
-     *
325
-     * @param array $iframe_css
326
-     * @return array
327
-     */
328
-    public static function iframeCss(array $iframe_css)
329
-    {
330
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
331
-        return $iframe_css;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
338
-     *
339
-     * @param array $iframe_js
340
-     * @return array
341
-     */
342
-    public static function iframeJs(array $iframe_js)
343
-    {
344
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
345
-        return $iframe_js;
346
-    }
347
-
348
-
349
-    /****************************** DEPRECATED ******************************/
350
-
351
-
352
-
353
-    /**
354
-     * @deprecated
355
-     * @return string
356
-     * @throws EE_Error
357
-     */
358
-    public static function display_view_details_btn()
359
-    {
360
-        // todo add doing_it_wrong() notice during next major version
361
-        return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
362
-    }
363
-
364
-
365
-
366
-    /**
367
-     * @deprecated
368
-     * @return string
369
-     * @throws EE_Error
370
-     */
371
-    public static function display_ticket_selector_submit()
372
-    {
373
-        // todo add doing_it_wrong() notice during next major version
374
-        return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
375
-    }
376
-
377
-
378
-
379
-    /**
380
-     * @deprecated
381
-     * @param string $permalink_string
382
-     * @param int    $id
383
-     * @param string $new_title
384
-     * @param string $new_slug
385
-     * @return string
386
-     * @throws InvalidArgumentException
387
-     * @throws InvalidDataTypeException
388
-     * @throws InvalidInterfaceException
389
-     */
390
-    public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
391
-    {
392
-        // todo add doing_it_wrong() notice during next major version
393
-        if (
394
-            EE_Registry::instance()->REQ->get('page') === 'espresso_events'
395
-            && EE_Registry::instance()->REQ->get('action') === 'edit'
396
-        ) {
397
-            $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
398
-            $iframe_embed_button->addEventEditorIframeEmbedButton();
399
-        }
400
-        return '';
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * @deprecated
407
-     * @param int    $ID
408
-     * @param string $external_url
409
-     * @return string
410
-     */
411
-    public static function ticket_selector_form_open($ID = 0, $external_url = '')
412
-    {
413
-        // todo add doing_it_wrong() notice during next major version
414
-        return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * @deprecated
421
-     * @return string
422
-     */
423
-    public static function ticket_selector_form_close()
424
-    {
425
-        // todo add doing_it_wrong() notice during next major version
426
-        return EED_Ticket_Selector::ticketSelector()->formClose();
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @deprecated
433
-     * @return string
434
-     */
435
-    public static function no_tkt_slctr_end_dv()
436
-    {
437
-        // todo add doing_it_wrong() notice during next major version
438
-        return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * @deprecated 4.9.13
445
-     * @return string
446
-     */
447
-    public static function tkt_slctr_end_dv()
448
-    {
449
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
450
-    }
451
-
452
-
453
-
454
-    /**
455
-     * @deprecated
456
-     * @return string
457
-     */
458
-    public static function clear_tkt_slctr()
459
-    {
460
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
461
-    }
462
-
463
-
464
-
465
-    /**
466
-     * @deprecated
467
-     */
468
-    public static function load_tckt_slctr_assets_admin()
469
-    {
470
-        // todo add doing_it_wrong() notice during next major version
471
-        if (
472
-            EE_Registry::instance()->REQ->get('page') === 'espresso_events'
473
-            && EE_Registry::instance()->REQ->get('action') === 'edit'
474
-        ) {
475
-            $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
476
-            $iframe_embed_button->embedButtonAssets();
477
-        }
478
-    }
23
+	/**
24
+	 * @var DisplayTicketSelector $ticket_selector
25
+	 */
26
+	private static $ticket_selector;
27
+
28
+	/**
29
+	 * @var TicketSelectorIframeEmbedButton $iframe_embed_button
30
+	 */
31
+	private static $iframe_embed_button;
32
+
33
+
34
+
35
+	/**
36
+	 * @return EED_Module|EED_Ticket_Selector
37
+	 */
38
+	public static function instance()
39
+	{
40
+		return parent::get_instance(__CLASS__);
41
+	}
42
+
43
+
44
+
45
+	/**
46
+	 * @return void
47
+	 */
48
+	protected function set_config()
49
+	{
50
+		$this->set_config_section('template_settings');
51
+		$this->set_config_class('EE_Ticket_Selector_Config');
52
+		$this->set_config_name('EED_Ticket_Selector');
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 *    set_hooks - for hooking into EE Core, other modules, etc
59
+	 *
60
+	 * @return void
61
+	 */
62
+	public static function set_hooks()
63
+	{
64
+		// routing
65
+		EE_Config::register_route(
66
+			'iframe',
67
+			'EED_Ticket_Selector',
68
+			'ticket_selector_iframe',
69
+			'ticket_selector'
70
+		);
71
+		EE_Config::register_route(
72
+			'process_ticket_selections',
73
+			'EED_Ticket_Selector',
74
+			'process_ticket_selections'
75
+		);
76
+		EE_Config::register_route(
77
+			'cancel_ticket_selections',
78
+			'EED_Ticket_Selector',
79
+			'cancel_ticket_selections'
80
+		);
81
+		add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
82
+		add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1);
83
+		add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0);
84
+		add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10);
85
+		EED_Ticket_Selector::loadIframeAssets();
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
92
+	 *
93
+	 * @return void
94
+	 */
95
+	public static function set_hooks_admin()
96
+	{
97
+		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
98
+		// to load assets for "espresso_events" page on the "edit" route (action)
99
+		add_action(
100
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
101
+			array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'),
102
+			10
103
+		);
104
+		/**
105
+		 * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
106
+		 * registrations work.
107
+		 */
108
+		add_action(
109
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
110
+			array('EED_Ticket_Selector', 'set_definitions'),
111
+			10
112
+		);
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 *    set_definitions
119
+	 *
120
+	 * @return void
121
+	 * @throws InvalidArgumentException
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws InvalidInterfaceException
124
+	 */
125
+	public static function set_definitions()
126
+	{
127
+		// don't do this twice
128
+		if (defined('TICKET_SELECTOR_ASSETS_URL')) {
129
+			return;
130
+		}
131
+		define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
132
+		define(
133
+			'TICKET_SELECTOR_TEMPLATES_PATH',
134
+			str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS
135
+		);
136
+		//if config is not set, initialize
137
+		if (
138
+			! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
139
+		) {
140
+			EED_Ticket_Selector::instance()->set_config();
141
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
142
+		}
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * @return DisplayTicketSelector
149
+	 */
150
+	public static function ticketSelector()
151
+	{
152
+		if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
153
+			EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe());
154
+		}
155
+		return EED_Ticket_Selector::$ticket_selector;
156
+	}
157
+
158
+
159
+	/**
160
+	 * gets the ball rolling
161
+	 *
162
+	 * @param WP $WP
163
+	 * @return void
164
+	 */
165
+	public function run($WP)
166
+	{
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @return TicketSelectorIframeEmbedButton
173
+	 */
174
+	public static function getIframeEmbedButton()
175
+	{
176
+		if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
177
+			self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
178
+		}
179
+		return self::$iframe_embed_button;
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * ticket_selector_iframe_embed_button
186
+	 *
187
+	 * @return void
188
+	 * @throws EE_Error
189
+	 */
190
+	public static function ticket_selector_iframe_embed_button()
191
+	{
192
+		$iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
193
+		$iframe_embed_button->addEventEditorIframeEmbedButton();
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * ticket_selector_iframe
200
+	 *
201
+	 * @return void
202
+	 * @throws DomainException
203
+	 * @throws EE_Error
204
+	 */
205
+	public function ticket_selector_iframe()
206
+	{
207
+		$ticket_selector_iframe = new TicketSelectorIframe();
208
+		$ticket_selector_iframe->display();
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * creates buttons for selecting number of attendees for an event
215
+	 *
216
+	 * @param  WP_Post|int $event
217
+	 * @param  bool        $view_details
218
+	 * @return string
219
+	 * @throws EE_Error
220
+	 */
221
+	public static function display_ticket_selector($event = null, $view_details = false)
222
+	{
223
+		return EED_Ticket_Selector::ticketSelector()->display($event, $view_details);
224
+	}
225
+
226
+
227
+
228
+	/**
229
+	 * @return array  or FALSE
230
+	 * @throws EE_Error
231
+	 */
232
+	public function process_ticket_selections()
233
+	{
234
+		$form = new ProcessTicketSelector();
235
+		return $form->processTicketSelections();
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * @return string
242
+	 */
243
+	public static function cancel_ticket_selections()
244
+	{
245
+		$form = new ProcessTicketSelector();
246
+		return $form->cancelTicketSelections();
247
+	}
248
+
249
+
250
+
251
+	/**
252
+	 * @return void
253
+	 */
254
+	public static function translate_js_strings()
255
+	{
256
+		EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
257
+			'please select a datetime',
258
+			'event_espresso'
259
+		);
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 * @return void
266
+	 */
267
+	public static function load_tckt_slctr_assets()
268
+	{
269
+		if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) {
270
+			// add some style
271
+			wp_register_style(
272
+				'ticket_selector',
273
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
274
+				array(),
275
+				EVENT_ESPRESSO_VERSION
276
+			);
277
+			wp_enqueue_style('ticket_selector');
278
+			// make it dance
279
+			wp_register_script(
280
+				'ticket_selector',
281
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
282
+				array('espresso_core'),
283
+				EVENT_ESPRESSO_VERSION,
284
+				true
285
+			);
286
+			wp_enqueue_script('ticket_selector');
287
+			require_once EE_LIBRARIES
288
+						 . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php';
289
+			\EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
290
+		}
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * @return void
297
+	 */
298
+	public static function loadIframeAssets()
299
+	{
300
+		// for event lists
301
+		add_filter(
302
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
303
+			array('EED_Ticket_Selector', 'iframeCss')
304
+		);
305
+		add_filter(
306
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
307
+			array('EED_Ticket_Selector', 'iframeJs')
308
+		);
309
+		// for ticket selectors
310
+		add_filter(
311
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
312
+			array('EED_Ticket_Selector', 'iframeCss')
313
+		);
314
+		add_filter(
315
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
316
+			array('EED_Ticket_Selector', 'iframeJs')
317
+		);
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
324
+	 *
325
+	 * @param array $iframe_css
326
+	 * @return array
327
+	 */
328
+	public static function iframeCss(array $iframe_css)
329
+	{
330
+		$iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
331
+		return $iframe_css;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
338
+	 *
339
+	 * @param array $iframe_js
340
+	 * @return array
341
+	 */
342
+	public static function iframeJs(array $iframe_js)
343
+	{
344
+		$iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
345
+		return $iframe_js;
346
+	}
347
+
348
+
349
+	/****************************** DEPRECATED ******************************/
350
+
351
+
352
+
353
+	/**
354
+	 * @deprecated
355
+	 * @return string
356
+	 * @throws EE_Error
357
+	 */
358
+	public static function display_view_details_btn()
359
+	{
360
+		// todo add doing_it_wrong() notice during next major version
361
+		return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
362
+	}
363
+
364
+
365
+
366
+	/**
367
+	 * @deprecated
368
+	 * @return string
369
+	 * @throws EE_Error
370
+	 */
371
+	public static function display_ticket_selector_submit()
372
+	{
373
+		// todo add doing_it_wrong() notice during next major version
374
+		return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
375
+	}
376
+
377
+
378
+
379
+	/**
380
+	 * @deprecated
381
+	 * @param string $permalink_string
382
+	 * @param int    $id
383
+	 * @param string $new_title
384
+	 * @param string $new_slug
385
+	 * @return string
386
+	 * @throws InvalidArgumentException
387
+	 * @throws InvalidDataTypeException
388
+	 * @throws InvalidInterfaceException
389
+	 */
390
+	public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
391
+	{
392
+		// todo add doing_it_wrong() notice during next major version
393
+		if (
394
+			EE_Registry::instance()->REQ->get('page') === 'espresso_events'
395
+			&& EE_Registry::instance()->REQ->get('action') === 'edit'
396
+		) {
397
+			$iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
398
+			$iframe_embed_button->addEventEditorIframeEmbedButton();
399
+		}
400
+		return '';
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * @deprecated
407
+	 * @param int    $ID
408
+	 * @param string $external_url
409
+	 * @return string
410
+	 */
411
+	public static function ticket_selector_form_open($ID = 0, $external_url = '')
412
+	{
413
+		// todo add doing_it_wrong() notice during next major version
414
+		return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * @deprecated
421
+	 * @return string
422
+	 */
423
+	public static function ticket_selector_form_close()
424
+	{
425
+		// todo add doing_it_wrong() notice during next major version
426
+		return EED_Ticket_Selector::ticketSelector()->formClose();
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @deprecated
433
+	 * @return string
434
+	 */
435
+	public static function no_tkt_slctr_end_dv()
436
+	{
437
+		// todo add doing_it_wrong() notice during next major version
438
+		return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * @deprecated 4.9.13
445
+	 * @return string
446
+	 */
447
+	public static function tkt_slctr_end_dv()
448
+	{
449
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
450
+	}
451
+
452
+
453
+
454
+	/**
455
+	 * @deprecated
456
+	 * @return string
457
+	 */
458
+	public static function clear_tkt_slctr()
459
+	{
460
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
461
+	}
462
+
463
+
464
+
465
+	/**
466
+	 * @deprecated
467
+	 */
468
+	public static function load_tckt_slctr_assets_admin()
469
+	{
470
+		// todo add doing_it_wrong() notice during next major version
471
+		if (
472
+			EE_Registry::instance()->REQ->get('page') === 'espresso_events'
473
+			&& EE_Registry::instance()->REQ->get('action') === 'edit'
474
+		) {
475
+			$iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
476
+			$iframe_embed_button->embedButtonAssets();
477
+		}
478
+	}
479 479
 
480 480
 
481 481
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
         if (defined('TICKET_SELECTOR_ASSETS_URL')) {
129 129
             return;
130 130
         }
131
-        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
131
+        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
132 132
         define(
133 133
             'TICKET_SELECTOR_TEMPLATES_PATH',
134
-            str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS
134
+            str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS
135 135
         );
136 136
         //if config is not set, initialize
137 137
         if (
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public static function ticketSelector()
151 151
     {
152
-        if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
152
+        if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
153 153
             EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(EED_Events_Archive::is_iframe());
154 154
         }
155 155
         return EED_Ticket_Selector::$ticket_selector;
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      */
174 174
     public static function getIframeEmbedButton()
175 175
     {
176
-        if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
176
+        if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
177 177
             self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
178 178
         }
179 179
         return self::$iframe_embed_button;
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
             // add some style
271 271
             wp_register_style(
272 272
                 'ticket_selector',
273
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
273
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css',
274 274
                 array(),
275 275
                 EVENT_ESPRESSO_VERSION
276 276
             );
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             // make it dance
279 279
             wp_register_script(
280 280
                 'ticket_selector',
281
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
281
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js',
282 282
                 array('espresso_core'),
283 283
                 EVENT_ESPRESSO_VERSION,
284 284
                 true
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      */
328 328
     public static function iframeCss(array $iframe_css)
329 329
     {
330
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
330
+        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css';
331 331
         return $iframe_css;
332 332
     }
333 333
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     public static function iframeJs(array $iframe_js)
343 343
     {
344
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
344
+        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js';
345 345
         return $iframe_js;
346 346
     }
347 347
 
Please login to merge, or discard this patch.
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Indentation   +734 added lines, -734 removed lines patch added patch discarded remove patch
@@ -36,743 +36,743 @@
 block discarded – undo
36 36
 class DisplayTicketSelector
37 37
 {
38 38
 
39
-    /**
40
-     * event that ticket selector is being generated for
41
-     *
42
-     * @access protected
43
-     * @var EE_Event $event
44
-     */
45
-    protected $event;
46
-
47
-    /**
48
-     * Used to flag when the ticket selector is being called from an external iframe.
49
-     *
50
-     * @var bool $iframe
51
-     */
52
-    protected $iframe = false;
53
-
54
-    /**
55
-     * max attendees that can register for event at one time
56
-     *
57
-     * @var int $max_attendees
58
-     */
59
-    private $max_attendees = EE_INF;
60
-
61
-    /**
62
-     * @var string $date_format
63
-     */
64
-    private $date_format;
65
-
66
-    /**
67
-     * @var string $time_format
68
-     */
69
-    private $time_format;
70
-
71
-    /**
72
-     * @var boolean $display_full_ui
73
-     */
74
-    private $display_full_ui;
75
-
76
-
77
-
78
-    /**
79
-     * DisplayTicketSelector constructor.
80
-     *
81
-     * @param bool $iframe
82
-     */
83
-    public function __construct($iframe = false)
84
-    {
85
-        $this->iframe      = $iframe;
86
-        $this->date_format = apply_filters(
87
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
88
-            get_option('date_format')
89
-        );
90
-        $this->time_format = apply_filters(
91
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
92
-            get_option('time_format')
93
-        );
94
-    }
95
-
96
-
97
-    /**
98
-     * @return bool
99
-     */
100
-    public function isIframe()
101
-    {
102
-        return $this->iframe;
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * @param boolean $iframe
109
-     */
110
-    public function setIframe($iframe = true)
111
-    {
112
-        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
113
-    }
114
-
115
-
116
-    /**
117
-     * finds and sets the \EE_Event object for use throughout class
118
-     *
119
-     * @param mixed $event
120
-     * @return bool
121
-     * @throws EE_Error
122
-     * @throws InvalidDataTypeException
123
-     * @throws InvalidInterfaceException
124
-     * @throws InvalidArgumentException
125
-     */
126
-    protected function setEvent($event = null)
127
-    {
128
-        if ($event === null) {
129
-            global $post;
130
-            $event = $post;
131
-        }
132
-        if ($event instanceof EE_Event) {
133
-            $this->event = $event;
134
-        } elseif ($event instanceof WP_Post) {
135
-            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
136
-                $this->event = $event->EE_Event;
137
-            } elseif ($event->post_type === 'espresso_events') {
138
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
139
-                $this->event     = $event->EE_Event;
140
-            }
141
-        } else {
142
-            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
143
-            $dev_msg  = $user_msg . __(
144
-                    'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
145
-                    'event_espresso'
146
-                );
147
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
148
-            return false;
149
-        }
150
-        return true;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * @return int
157
-     */
158
-    public function getMaxAttendees()
159
-    {
160
-        return $this->max_attendees;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @param int $max_attendees
167
-     */
168
-    public function setMaxAttendees($max_attendees)
169
-    {
170
-        $this->max_attendees = absint(
171
-            apply_filters(
172
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
173
-                $max_attendees
174
-            )
175
-        );
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * Returns whether or not the full ticket selector should be shown or not.
182
-     * Currently, it displays on the frontend (including ajax requests) but not the backend
183
-     *
184
-     * @return bool
185
-     */
186
-    private function display_full_ui()
187
-    {
188
-        if ($this->display_full_ui === null) {
189
-            $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
190
-        }
191
-        return $this->display_full_ui;
192
-    }
193
-
194
-
195
-    /**
196
-     * creates buttons for selecting number of attendees for an event
197
-     *
198
-     * @param WP_Post|int $event
199
-     * @param bool        $view_details
200
-     * @return string
201
-     * @throws EE_Error
202
-     * @throws InvalidArgumentException
203
-     * @throws InvalidDataTypeException
204
-     * @throws InvalidInterfaceException
205
-     */
206
-    public function display($event = null, $view_details = false)
207
-    {
208
-        // reset filter for displaying submit button
209
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
210
-        // poke and prod incoming event till it tells us what it is
211
-        if (! $this->setEvent($event)) {
212
-            return false;
213
-        }
214
-        // begin gathering template arguments by getting event status
215
-        $template_args = array('event_status' => $this->event->get_active_status());
216
-        if (
217
-        $this->activeEventAndShowTicketSelector(
218
-            $event,
219
-            $template_args['event_status'],
220
-            $view_details
221
-        )
222
-        ) {
223
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
224
-        }
225
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
226
-        $this->setMaxAttendees($this->event->additional_limit());
227
-        if ($this->getMaxAttendees() < 1) {
228
-            return $this->ticketSalesClosedMessage();
229
-        }
230
-        // is the event expired ?
231
-        $template_args['event_is_expired'] = $this->event->is_expired();
232
-        if ($template_args['event_is_expired']) {
233
-            return $this->expiredEventMessage();
234
-        }
235
-        // get all tickets for this event ordered by the datetime
236
-        $tickets = $this->getTickets();
237
-        if (count($tickets) < 1) {
238
-            return $this->noTicketAvailableMessage();
239
-        }
240
-        // redirecting to another site for registration ??
241
-        $external_url = (string)$this->event->external_url();
242
-        // if redirecting to another site for registration, then we don't load the TS
243
-        $ticket_selector = $external_url
244
-            ? $this->externalEventRegistration()
245
-            : $this->loadTicketSelector($tickets, $template_args);
246
-        // now set up the form (but not for the admin)
247
-        $ticket_selector = $this->display_full_ui()
248
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
249
-            : $ticket_selector;
250
-        // submit button and form close tag
251
-        $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
252
-        return $ticket_selector;
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * displayTicketSelector
259
-     * examines the event properties and determines whether a Ticket Selector should be displayed
260
-     *
261
-     * @param WP_Post|int $event
262
-     * @param string      $_event_active_status
263
-     * @param bool        $view_details
264
-     * @return bool
265
-     * @throws EE_Error
266
-     */
267
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
268
-    {
269
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
270
-        return $this->display_full_ui()
271
-               && (
272
-                   ! $this->event->display_ticket_selector()
273
-                   || $view_details
274
-                   || post_password_required($event_post)
275
-                   || (
276
-                       $_event_active_status !== EE_Datetime::active
277
-                       && $_event_active_status !== EE_Datetime::upcoming
278
-                       && $_event_active_status !== EE_Datetime::sold_out
279
-                       && ! (
280
-                           $_event_active_status === EE_Datetime::inactive
281
-                           && is_user_logged_in()
282
-                       )
283
-                   )
284
-               );
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * noTicketAvailableMessage
291
-     * notice displayed if event is expired
292
-     *
293
-     * @return string
294
-     * @throws EE_Error
295
-     */
296
-    protected function expiredEventMessage()
297
-    {
298
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
299
-                'We\'re sorry, but all tickets sales have ended because the event is expired.',
300
-                'event_espresso'
301
-            ) . '</span></div><!-- .ee-event-expired-notice -->';
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * noTicketAvailableMessage
308
-     * notice displayed if event has no more tickets available
309
-     *
310
-     * @return string
311
-     * @throws EE_Error
312
-     */
313
-    protected function noTicketAvailableMessage()
314
-    {
315
-        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
316
-        if (current_user_can('edit_post', $this->event->ID())) {
317
-            $no_ticket_available_msg .= sprintf(
318
-                esc_html__(
319
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
320
-                    'event_espresso'
321
-                ),
322
-                '<div class="ee-attention" style="text-align: left;"><b>',
323
-                '</b><br />',
324
-                '<span class="edit-link"><a class="post-edit-link" href="'
325
-                . get_edit_post_link($this->event->ID())
326
-                . '">',
327
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
328
-            );
329
-        }
330
-        return '
39
+	/**
40
+	 * event that ticket selector is being generated for
41
+	 *
42
+	 * @access protected
43
+	 * @var EE_Event $event
44
+	 */
45
+	protected $event;
46
+
47
+	/**
48
+	 * Used to flag when the ticket selector is being called from an external iframe.
49
+	 *
50
+	 * @var bool $iframe
51
+	 */
52
+	protected $iframe = false;
53
+
54
+	/**
55
+	 * max attendees that can register for event at one time
56
+	 *
57
+	 * @var int $max_attendees
58
+	 */
59
+	private $max_attendees = EE_INF;
60
+
61
+	/**
62
+	 * @var string $date_format
63
+	 */
64
+	private $date_format;
65
+
66
+	/**
67
+	 * @var string $time_format
68
+	 */
69
+	private $time_format;
70
+
71
+	/**
72
+	 * @var boolean $display_full_ui
73
+	 */
74
+	private $display_full_ui;
75
+
76
+
77
+
78
+	/**
79
+	 * DisplayTicketSelector constructor.
80
+	 *
81
+	 * @param bool $iframe
82
+	 */
83
+	public function __construct($iframe = false)
84
+	{
85
+		$this->iframe      = $iframe;
86
+		$this->date_format = apply_filters(
87
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
88
+			get_option('date_format')
89
+		);
90
+		$this->time_format = apply_filters(
91
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
92
+			get_option('time_format')
93
+		);
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return bool
99
+	 */
100
+	public function isIframe()
101
+	{
102
+		return $this->iframe;
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * @param boolean $iframe
109
+	 */
110
+	public function setIframe($iframe = true)
111
+	{
112
+		$this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
113
+	}
114
+
115
+
116
+	/**
117
+	 * finds and sets the \EE_Event object for use throughout class
118
+	 *
119
+	 * @param mixed $event
120
+	 * @return bool
121
+	 * @throws EE_Error
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws InvalidInterfaceException
124
+	 * @throws InvalidArgumentException
125
+	 */
126
+	protected function setEvent($event = null)
127
+	{
128
+		if ($event === null) {
129
+			global $post;
130
+			$event = $post;
131
+		}
132
+		if ($event instanceof EE_Event) {
133
+			$this->event = $event;
134
+		} elseif ($event instanceof WP_Post) {
135
+			if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
136
+				$this->event = $event->EE_Event;
137
+			} elseif ($event->post_type === 'espresso_events') {
138
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
139
+				$this->event     = $event->EE_Event;
140
+			}
141
+		} else {
142
+			$user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
143
+			$dev_msg  = $user_msg . __(
144
+					'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
145
+					'event_espresso'
146
+				);
147
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
148
+			return false;
149
+		}
150
+		return true;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * @return int
157
+	 */
158
+	public function getMaxAttendees()
159
+	{
160
+		return $this->max_attendees;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @param int $max_attendees
167
+	 */
168
+	public function setMaxAttendees($max_attendees)
169
+	{
170
+		$this->max_attendees = absint(
171
+			apply_filters(
172
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
173
+				$max_attendees
174
+			)
175
+		);
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * Returns whether or not the full ticket selector should be shown or not.
182
+	 * Currently, it displays on the frontend (including ajax requests) but not the backend
183
+	 *
184
+	 * @return bool
185
+	 */
186
+	private function display_full_ui()
187
+	{
188
+		if ($this->display_full_ui === null) {
189
+			$this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
190
+		}
191
+		return $this->display_full_ui;
192
+	}
193
+
194
+
195
+	/**
196
+	 * creates buttons for selecting number of attendees for an event
197
+	 *
198
+	 * @param WP_Post|int $event
199
+	 * @param bool        $view_details
200
+	 * @return string
201
+	 * @throws EE_Error
202
+	 * @throws InvalidArgumentException
203
+	 * @throws InvalidDataTypeException
204
+	 * @throws InvalidInterfaceException
205
+	 */
206
+	public function display($event = null, $view_details = false)
207
+	{
208
+		// reset filter for displaying submit button
209
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
210
+		// poke and prod incoming event till it tells us what it is
211
+		if (! $this->setEvent($event)) {
212
+			return false;
213
+		}
214
+		// begin gathering template arguments by getting event status
215
+		$template_args = array('event_status' => $this->event->get_active_status());
216
+		if (
217
+		$this->activeEventAndShowTicketSelector(
218
+			$event,
219
+			$template_args['event_status'],
220
+			$view_details
221
+		)
222
+		) {
223
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
224
+		}
225
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
226
+		$this->setMaxAttendees($this->event->additional_limit());
227
+		if ($this->getMaxAttendees() < 1) {
228
+			return $this->ticketSalesClosedMessage();
229
+		}
230
+		// is the event expired ?
231
+		$template_args['event_is_expired'] = $this->event->is_expired();
232
+		if ($template_args['event_is_expired']) {
233
+			return $this->expiredEventMessage();
234
+		}
235
+		// get all tickets for this event ordered by the datetime
236
+		$tickets = $this->getTickets();
237
+		if (count($tickets) < 1) {
238
+			return $this->noTicketAvailableMessage();
239
+		}
240
+		// redirecting to another site for registration ??
241
+		$external_url = (string)$this->event->external_url();
242
+		// if redirecting to another site for registration, then we don't load the TS
243
+		$ticket_selector = $external_url
244
+			? $this->externalEventRegistration()
245
+			: $this->loadTicketSelector($tickets, $template_args);
246
+		// now set up the form (but not for the admin)
247
+		$ticket_selector = $this->display_full_ui()
248
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
249
+			: $ticket_selector;
250
+		// submit button and form close tag
251
+		$ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
252
+		return $ticket_selector;
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * displayTicketSelector
259
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
260
+	 *
261
+	 * @param WP_Post|int $event
262
+	 * @param string      $_event_active_status
263
+	 * @param bool        $view_details
264
+	 * @return bool
265
+	 * @throws EE_Error
266
+	 */
267
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
268
+	{
269
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
270
+		return $this->display_full_ui()
271
+			   && (
272
+				   ! $this->event->display_ticket_selector()
273
+				   || $view_details
274
+				   || post_password_required($event_post)
275
+				   || (
276
+					   $_event_active_status !== EE_Datetime::active
277
+					   && $_event_active_status !== EE_Datetime::upcoming
278
+					   && $_event_active_status !== EE_Datetime::sold_out
279
+					   && ! (
280
+						   $_event_active_status === EE_Datetime::inactive
281
+						   && is_user_logged_in()
282
+					   )
283
+				   )
284
+			   );
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * noTicketAvailableMessage
291
+	 * notice displayed if event is expired
292
+	 *
293
+	 * @return string
294
+	 * @throws EE_Error
295
+	 */
296
+	protected function expiredEventMessage()
297
+	{
298
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
299
+				'We\'re sorry, but all tickets sales have ended because the event is expired.',
300
+				'event_espresso'
301
+			) . '</span></div><!-- .ee-event-expired-notice -->';
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * noTicketAvailableMessage
308
+	 * notice displayed if event has no more tickets available
309
+	 *
310
+	 * @return string
311
+	 * @throws EE_Error
312
+	 */
313
+	protected function noTicketAvailableMessage()
314
+	{
315
+		$no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
316
+		if (current_user_can('edit_post', $this->event->ID())) {
317
+			$no_ticket_available_msg .= sprintf(
318
+				esc_html__(
319
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
320
+					'event_espresso'
321
+				),
322
+				'<div class="ee-attention" style="text-align: left;"><b>',
323
+				'</b><br />',
324
+				'<span class="edit-link"><a class="post-edit-link" href="'
325
+				. get_edit_post_link($this->event->ID())
326
+				. '">',
327
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
328
+			);
329
+		}
330
+		return '
331 331
             <div class="ee-event-expired-notice">
332 332
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
333 333
             </div><!-- .ee-event-expired-notice -->';
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * ticketSalesClosed
340
-     * notice displayed if event ticket sales are turned off
341
-     *
342
-     * @return string
343
-     * @throws EE_Error
344
-     */
345
-    protected function ticketSalesClosedMessage()
346
-    {
347
-        $sales_closed_msg = esc_html__(
348
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
349
-            'event_espresso'
350
-        );
351
-        if (current_user_can('edit_post', $this->event->ID())) {
352
-            $sales_closed_msg .= sprintf(
353
-                esc_html__(
354
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
355
-                    'event_espresso'
356
-                ),
357
-                '<div class="ee-attention" style="text-align: left;"><b>',
358
-                '</b><br />',
359
-                '<span class="edit-link"><a class="post-edit-link" href="'
360
-                . get_edit_post_link($this->event->ID())
361
-                . '">',
362
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
363
-            );
364
-        }
365
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * getTickets
372
-     *
373
-     * @return \EE_Base_Class[]|\EE_Ticket[]
374
-     * @throws EE_Error
375
-     * @throws InvalidDataTypeException
376
-     * @throws InvalidInterfaceException
377
-     * @throws InvalidArgumentException
378
-     */
379
-    protected function getTickets()
380
-    {
381
-        $ticket_query_args = array(
382
-            array('Datetime.EVT_ID' => $this->event->ID()),
383
-            'order_by' => array(
384
-                'TKT_order'              => 'ASC',
385
-                'TKT_required'           => 'DESC',
386
-                'TKT_start_date'         => 'ASC',
387
-                'TKT_end_date'           => 'ASC',
388
-                'Datetime.DTT_EVT_start' => 'DESC',
389
-            ),
390
-        );
391
-        if (
392
-        ! (
393
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
394
-            && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
395
-        )
396
-        ) {
397
-            //use the correct applicable time query depending on what version of core is being run.
398
-            $current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
399
-                ? time()
400
-                : current_time('timestamp');
401
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
402
-        }
403
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * loadTicketSelector
410
-     * begins to assemble template arguments
411
-     * and decides whether to load a "simple" ticket selector, or the standard
412
-     *
413
-     * @param \EE_Ticket[] $tickets
414
-     * @param array        $template_args
415
-     * @return string
416
-     * @throws EE_Error
417
-     */
418
-    protected function loadTicketSelector(array $tickets, array $template_args)
419
-    {
420
-        $template_args['event']            = $this->event;
421
-        $template_args['EVT_ID']           = $this->event->ID();
422
-        $template_args['event_is_expired'] = $this->event->is_expired();
423
-        $template_args['max_atndz']        = $this->getMaxAttendees();
424
-        $template_args['date_format']      = $this->date_format;
425
-        $template_args['time_format']      = $this->time_format;
426
-        /**
427
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
428
-         *
429
-         * @since 4.9.13
430
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
431
-         * @param int $EVT_ID The Event ID
432
-         */
433
-        $template_args['anchor_id']    = apply_filters(
434
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
435
-            '#tkt-slctr-tbl-' . $this->event->ID(),
436
-            $this->event->ID()
437
-        );
438
-        $template_args['tickets']      = $tickets;
439
-        $template_args['ticket_count'] = count($tickets);
440
-        $ticket_selector               = $this->simpleTicketSelector($tickets, $template_args);
441
-        return $ticket_selector instanceof TicketSelectorSimple
442
-            ? $ticket_selector
443
-            : new TicketSelectorStandard(
444
-                $this->event,
445
-                $tickets,
446
-                $this->getMaxAttendees(),
447
-                $template_args,
448
-                $this->date_format,
449
-                $this->time_format
450
-            );
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * simpleTicketSelector
457
-     * there's one ticket, and max attendees is set to one,
458
-     * so if the event is free, then this is a "simple" ticket selector
459
-     * a.k.a. "Dude Where's my Ticket Selector?"
460
-     *
461
-     * @param \EE_Ticket[] $tickets
462
-     * @param array        $template_args
463
-     * @return string
464
-     * @throws EE_Error
465
-     */
466
-    protected function simpleTicketSelector($tickets, array $template_args)
467
-    {
468
-        // if there is only ONE ticket with a max qty of ONE
469
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
470
-            return '';
471
-        }
472
-        /** @var \EE_Ticket $ticket */
473
-        $ticket = reset($tickets);
474
-        // if the ticket is free... then not much need for the ticket selector
475
-        if (
476
-        apply_filters(
477
-            'FHEE__ticket_selector_chart_template__hide_ticket_selector',
478
-            $ticket->is_free(),
479
-            $this->event->ID()
480
-        )
481
-        ) {
482
-            return new TicketSelectorSimple(
483
-                $this->event,
484
-                $ticket,
485
-                $this->getMaxAttendees(),
486
-                $template_args
487
-            );
488
-        }
489
-        return '';
490
-    }
491
-
492
-
493
-
494
-    /**
495
-     * externalEventRegistration
496
-     *
497
-     * @return string
498
-     */
499
-    public function externalEventRegistration()
500
-    {
501
-        // if not we still need to trigger the display of the submit button
502
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
503
-        //display notice to admin that registration is external
504
-        return $this->display_full_ui()
505
-            ? esc_html__(
506
-                'Registration is at an external URL for this event.',
507
-                'event_espresso'
508
-            )
509
-            : '';
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * formOpen
516
-     *
517
-     * @param        int    $ID
518
-     * @param        string $external_url
519
-     * @return        string
520
-     */
521
-    public function formOpen($ID = 0, $external_url = '')
522
-    {
523
-        // if redirecting, we don't need any anything else
524
-        if ($external_url) {
525
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
526
-            // open link in new window ?
527
-            $html       .= apply_filters(
528
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
529
-                $this->isIframe(),
530
-                $this
531
-            )
532
-                ? ' target="_blank"'
533
-                : '';
534
-            $html       .= '>';
535
-            $query_args = EEH_URL::get_query_string($external_url);
536
-            foreach ((array)$query_args as $query_arg => $value) {
537
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
538
-            }
539
-            return $html;
540
-        }
541
-        // if there is no submit button, then don't start building a form
542
-        // because the "View Details" button will build its own form
543
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
544
-            return '';
545
-        }
546
-        $checkout_url = EEH_Event_View::event_link_url($ID);
547
-        if (! $checkout_url) {
548
-            EE_Error::add_error(
549
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
550
-                __FILE__,
551
-                __FUNCTION__,
552
-                __LINE__
553
-            );
554
-        }
555
-        // set no cache headers and constants
556
-        EE_System::do_not_cache();
557
-        $extra_params = $this->iframe ? ' target="_blank"' : '';
558
-        $html         = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
559
-        $html         .= '<input type="hidden" name="ee" value="process_ticket_selections">';
560
-        $html         = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
561
-        return $html;
562
-    }
563
-
564
-
565
-
566
-    /**
567
-     * displaySubmitButton
568
-     *
569
-     * @param  string $external_url
570
-     * @return string
571
-     * @throws EE_Error
572
-     */
573
-    public function displaySubmitButton($external_url = '')
574
-    {
575
-        $html = '';
576
-        if ($this->display_full_ui()) {
577
-            // standard TS displayed with submit button, ie: "Register Now"
578
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
579
-                $html .= $this->displayRegisterNowButton();
580
-                $html .= empty($external_url)
581
-                    ? $this->ticketSelectorEndDiv()
582
-                    : $this->clearTicketSelector();
583
-                $html .= '<br/>' . $this->formClose();
584
-            } elseif ($this->getMaxAttendees() === 1) {
585
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
586
-                if ($this->event->is_sold_out()) {
587
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
588
-                    $html .= apply_filters(
589
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
590
-                        sprintf(
591
-                            __(
592
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
593
-                                'event_espresso'
594
-                            ),
595
-                            '<p class="no-ticket-selector-msg clear-float">',
596
-                            $this->event->name(),
597
-                            '</p>',
598
-                            '<br />'
599
-                        ),
600
-                        $this->event
601
-                    );
602
-                    if (
603
-                    apply_filters(
604
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
605
-                        false,
606
-                        $this->event
607
-                    )
608
-                    ) {
609
-                        $html .= $this->displayRegisterNowButton();
610
-                    }
611
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
612
-                    $html .= $this->ticketSelectorEndDiv();
613
-                } elseif (
614
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
615
-                    && ! is_single()
616
-                ) {
617
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
618
-                    // but no tickets are available, so display event's "View Details" button.
619
-                    // it is being viewed via somewhere other than a single post
620
-                    $html .= $this->displayViewDetailsButton(true);
621
-                } else {
622
-                    $html .= $this->ticketSelectorEndDiv();
623
-                }
624
-            } elseif (is_archive()) {
625
-                // event list, no tickets available so display event's "View Details" button
626
-                $html .= $this->ticketSelectorEndDiv();
627
-                $html .= $this->displayViewDetailsButton();
628
-            } else {
629
-                if (
630
-                apply_filters(
631
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
632
-                    false,
633
-                    $this->event
634
-                )
635
-                ) {
636
-                    $html .= $this->displayRegisterNowButton();
637
-                }
638
-                // no submit or view details button, and no additional content
639
-                $html .= $this->ticketSelectorEndDiv();
640
-            }
641
-            if (! $this->iframe && ! is_archive()) {
642
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
643
-            }
644
-        }
645
-        return apply_filters(
646
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
647
-            $html,
648
-            $this->event,
649
-            $this
650
-        );
651
-    }
652
-
653
-
654
-
655
-    /**
656
-     * @return string
657
-     * @throws EE_Error
658
-     */
659
-    public function displayRegisterNowButton()
660
-    {
661
-        $btn_text     = apply_filters(
662
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
663
-            __('Register Now', 'event_espresso'),
664
-            $this->event
665
-        );
666
-        $external_url = $this->event->external_url();
667
-        $html         = EEH_HTML::div(
668
-            '',
669
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
670
-            'ticket-selector-submit-btn-wrap'
671
-        );
672
-        $html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
673
-        $html         .= ' class="ticket-selector-submit-btn ';
674
-        $html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
675
-        $html         .= ' type="submit" value="' . $btn_text . '" />';
676
-        $html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
677
-        $html         .= apply_filters(
678
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
679
-            '',
680
-            $this->event
681
-        );
682
-        return $html;
683
-    }
684
-
685
-
686
-    /**
687
-     * displayViewDetailsButton
688
-     *
689
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
690
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
691
-     *                    either because they are sold out, expired, or not yet on sale.
692
-     *                    In this case, we need to close the form BEFORE adding any closing divs
693
-     * @return string
694
-     * @throws EE_Error
695
-     */
696
-    public function displayViewDetailsButton($DWMTS = false)
697
-    {
698
-        if (! $this->event->get_permalink()) {
699
-            EE_Error::add_error(
700
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
701
-                __FILE__,
702
-                __FUNCTION__,
703
-                __LINE__
704
-            );
705
-        }
706
-        $view_details_btn = '<form method="POST" action="';
707
-        $view_details_btn .= apply_filters(
708
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
709
-            $this->event->get_permalink(),
710
-            $this->event
711
-        );
712
-        $view_details_btn .= '"';
713
-        // open link in new window ?
714
-        $view_details_btn .= apply_filters(
715
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
716
-            $this->isIframe(),
717
-            $this
718
-        )
719
-            ? ' target="_blank"'
720
-            : '';
721
-        $view_details_btn .= '>';
722
-        $btn_text         = apply_filters(
723
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
724
-            esc_html__('View Details', 'event_espresso'),
725
-            $this->event
726
-        );
727
-        $view_details_btn .= '<input id="ticket-selector-submit-'
728
-                             . $this->event->ID()
729
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
730
-                             . $btn_text
731
-                             . '" />';
732
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
733
-        if ($DWMTS) {
734
-            $view_details_btn .= $this->formClose();
735
-            $view_details_btn .= $this->ticketSelectorEndDiv();
736
-            $view_details_btn .= '<br/>';
737
-        } else {
738
-            $view_details_btn .= $this->clearTicketSelector();
739
-            $view_details_btn .= '<br/>';
740
-            $view_details_btn .= $this->formClose();
741
-        }
742
-        return $view_details_btn;
743
-    }
744
-
745
-
746
-
747
-    /**
748
-     * @return string
749
-     */
750
-    public function ticketSelectorEndDiv()
751
-    {
752
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     * @return string
759
-     */
760
-    public function clearTicketSelector()
761
-    {
762
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
763
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
764
-    }
765
-
766
-
767
-
768
-    /**
769
-     * @access        public
770
-     * @return        string
771
-     */
772
-    public function formClose()
773
-    {
774
-        return '</form>';
775
-    }
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * ticketSalesClosed
340
+	 * notice displayed if event ticket sales are turned off
341
+	 *
342
+	 * @return string
343
+	 * @throws EE_Error
344
+	 */
345
+	protected function ticketSalesClosedMessage()
346
+	{
347
+		$sales_closed_msg = esc_html__(
348
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
349
+			'event_espresso'
350
+		);
351
+		if (current_user_can('edit_post', $this->event->ID())) {
352
+			$sales_closed_msg .= sprintf(
353
+				esc_html__(
354
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
355
+					'event_espresso'
356
+				),
357
+				'<div class="ee-attention" style="text-align: left;"><b>',
358
+				'</b><br />',
359
+				'<span class="edit-link"><a class="post-edit-link" href="'
360
+				. get_edit_post_link($this->event->ID())
361
+				. '">',
362
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
363
+			);
364
+		}
365
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * getTickets
372
+	 *
373
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
374
+	 * @throws EE_Error
375
+	 * @throws InvalidDataTypeException
376
+	 * @throws InvalidInterfaceException
377
+	 * @throws InvalidArgumentException
378
+	 */
379
+	protected function getTickets()
380
+	{
381
+		$ticket_query_args = array(
382
+			array('Datetime.EVT_ID' => $this->event->ID()),
383
+			'order_by' => array(
384
+				'TKT_order'              => 'ASC',
385
+				'TKT_required'           => 'DESC',
386
+				'TKT_start_date'         => 'ASC',
387
+				'TKT_end_date'           => 'ASC',
388
+				'Datetime.DTT_EVT_start' => 'DESC',
389
+			),
390
+		);
391
+		if (
392
+		! (
393
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
394
+			&& EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
395
+		)
396
+		) {
397
+			//use the correct applicable time query depending on what version of core is being run.
398
+			$current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
399
+				? time()
400
+				: current_time('timestamp');
401
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
402
+		}
403
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * loadTicketSelector
410
+	 * begins to assemble template arguments
411
+	 * and decides whether to load a "simple" ticket selector, or the standard
412
+	 *
413
+	 * @param \EE_Ticket[] $tickets
414
+	 * @param array        $template_args
415
+	 * @return string
416
+	 * @throws EE_Error
417
+	 */
418
+	protected function loadTicketSelector(array $tickets, array $template_args)
419
+	{
420
+		$template_args['event']            = $this->event;
421
+		$template_args['EVT_ID']           = $this->event->ID();
422
+		$template_args['event_is_expired'] = $this->event->is_expired();
423
+		$template_args['max_atndz']        = $this->getMaxAttendees();
424
+		$template_args['date_format']      = $this->date_format;
425
+		$template_args['time_format']      = $this->time_format;
426
+		/**
427
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
428
+		 *
429
+		 * @since 4.9.13
430
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
431
+		 * @param int $EVT_ID The Event ID
432
+		 */
433
+		$template_args['anchor_id']    = apply_filters(
434
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
435
+			'#tkt-slctr-tbl-' . $this->event->ID(),
436
+			$this->event->ID()
437
+		);
438
+		$template_args['tickets']      = $tickets;
439
+		$template_args['ticket_count'] = count($tickets);
440
+		$ticket_selector               = $this->simpleTicketSelector($tickets, $template_args);
441
+		return $ticket_selector instanceof TicketSelectorSimple
442
+			? $ticket_selector
443
+			: new TicketSelectorStandard(
444
+				$this->event,
445
+				$tickets,
446
+				$this->getMaxAttendees(),
447
+				$template_args,
448
+				$this->date_format,
449
+				$this->time_format
450
+			);
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * simpleTicketSelector
457
+	 * there's one ticket, and max attendees is set to one,
458
+	 * so if the event is free, then this is a "simple" ticket selector
459
+	 * a.k.a. "Dude Where's my Ticket Selector?"
460
+	 *
461
+	 * @param \EE_Ticket[] $tickets
462
+	 * @param array        $template_args
463
+	 * @return string
464
+	 * @throws EE_Error
465
+	 */
466
+	protected function simpleTicketSelector($tickets, array $template_args)
467
+	{
468
+		// if there is only ONE ticket with a max qty of ONE
469
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
470
+			return '';
471
+		}
472
+		/** @var \EE_Ticket $ticket */
473
+		$ticket = reset($tickets);
474
+		// if the ticket is free... then not much need for the ticket selector
475
+		if (
476
+		apply_filters(
477
+			'FHEE__ticket_selector_chart_template__hide_ticket_selector',
478
+			$ticket->is_free(),
479
+			$this->event->ID()
480
+		)
481
+		) {
482
+			return new TicketSelectorSimple(
483
+				$this->event,
484
+				$ticket,
485
+				$this->getMaxAttendees(),
486
+				$template_args
487
+			);
488
+		}
489
+		return '';
490
+	}
491
+
492
+
493
+
494
+	/**
495
+	 * externalEventRegistration
496
+	 *
497
+	 * @return string
498
+	 */
499
+	public function externalEventRegistration()
500
+	{
501
+		// if not we still need to trigger the display of the submit button
502
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
503
+		//display notice to admin that registration is external
504
+		return $this->display_full_ui()
505
+			? esc_html__(
506
+				'Registration is at an external URL for this event.',
507
+				'event_espresso'
508
+			)
509
+			: '';
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * formOpen
516
+	 *
517
+	 * @param        int    $ID
518
+	 * @param        string $external_url
519
+	 * @return        string
520
+	 */
521
+	public function formOpen($ID = 0, $external_url = '')
522
+	{
523
+		// if redirecting, we don't need any anything else
524
+		if ($external_url) {
525
+			$html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
526
+			// open link in new window ?
527
+			$html       .= apply_filters(
528
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
529
+				$this->isIframe(),
530
+				$this
531
+			)
532
+				? ' target="_blank"'
533
+				: '';
534
+			$html       .= '>';
535
+			$query_args = EEH_URL::get_query_string($external_url);
536
+			foreach ((array)$query_args as $query_arg => $value) {
537
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
538
+			}
539
+			return $html;
540
+		}
541
+		// if there is no submit button, then don't start building a form
542
+		// because the "View Details" button will build its own form
543
+		if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
544
+			return '';
545
+		}
546
+		$checkout_url = EEH_Event_View::event_link_url($ID);
547
+		if (! $checkout_url) {
548
+			EE_Error::add_error(
549
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
550
+				__FILE__,
551
+				__FUNCTION__,
552
+				__LINE__
553
+			);
554
+		}
555
+		// set no cache headers and constants
556
+		EE_System::do_not_cache();
557
+		$extra_params = $this->iframe ? ' target="_blank"' : '';
558
+		$html         = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
559
+		$html         .= '<input type="hidden" name="ee" value="process_ticket_selections">';
560
+		$html         = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
561
+		return $html;
562
+	}
563
+
564
+
565
+
566
+	/**
567
+	 * displaySubmitButton
568
+	 *
569
+	 * @param  string $external_url
570
+	 * @return string
571
+	 * @throws EE_Error
572
+	 */
573
+	public function displaySubmitButton($external_url = '')
574
+	{
575
+		$html = '';
576
+		if ($this->display_full_ui()) {
577
+			// standard TS displayed with submit button, ie: "Register Now"
578
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
579
+				$html .= $this->displayRegisterNowButton();
580
+				$html .= empty($external_url)
581
+					? $this->ticketSelectorEndDiv()
582
+					: $this->clearTicketSelector();
583
+				$html .= '<br/>' . $this->formClose();
584
+			} elseif ($this->getMaxAttendees() === 1) {
585
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
586
+				if ($this->event->is_sold_out()) {
587
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
588
+					$html .= apply_filters(
589
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
590
+						sprintf(
591
+							__(
592
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
593
+								'event_espresso'
594
+							),
595
+							'<p class="no-ticket-selector-msg clear-float">',
596
+							$this->event->name(),
597
+							'</p>',
598
+							'<br />'
599
+						),
600
+						$this->event
601
+					);
602
+					if (
603
+					apply_filters(
604
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
605
+						false,
606
+						$this->event
607
+					)
608
+					) {
609
+						$html .= $this->displayRegisterNowButton();
610
+					}
611
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
612
+					$html .= $this->ticketSelectorEndDiv();
613
+				} elseif (
614
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
615
+					&& ! is_single()
616
+				) {
617
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
618
+					// but no tickets are available, so display event's "View Details" button.
619
+					// it is being viewed via somewhere other than a single post
620
+					$html .= $this->displayViewDetailsButton(true);
621
+				} else {
622
+					$html .= $this->ticketSelectorEndDiv();
623
+				}
624
+			} elseif (is_archive()) {
625
+				// event list, no tickets available so display event's "View Details" button
626
+				$html .= $this->ticketSelectorEndDiv();
627
+				$html .= $this->displayViewDetailsButton();
628
+			} else {
629
+				if (
630
+				apply_filters(
631
+					'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
632
+					false,
633
+					$this->event
634
+				)
635
+				) {
636
+					$html .= $this->displayRegisterNowButton();
637
+				}
638
+				// no submit or view details button, and no additional content
639
+				$html .= $this->ticketSelectorEndDiv();
640
+			}
641
+			if (! $this->iframe && ! is_archive()) {
642
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
643
+			}
644
+		}
645
+		return apply_filters(
646
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
647
+			$html,
648
+			$this->event,
649
+			$this
650
+		);
651
+	}
652
+
653
+
654
+
655
+	/**
656
+	 * @return string
657
+	 * @throws EE_Error
658
+	 */
659
+	public function displayRegisterNowButton()
660
+	{
661
+		$btn_text     = apply_filters(
662
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
663
+			__('Register Now', 'event_espresso'),
664
+			$this->event
665
+		);
666
+		$external_url = $this->event->external_url();
667
+		$html         = EEH_HTML::div(
668
+			'',
669
+			'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
670
+			'ticket-selector-submit-btn-wrap'
671
+		);
672
+		$html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
673
+		$html         .= ' class="ticket-selector-submit-btn ';
674
+		$html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
675
+		$html         .= ' type="submit" value="' . $btn_text . '" />';
676
+		$html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
677
+		$html         .= apply_filters(
678
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
679
+			'',
680
+			$this->event
681
+		);
682
+		return $html;
683
+	}
684
+
685
+
686
+	/**
687
+	 * displayViewDetailsButton
688
+	 *
689
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
690
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
691
+	 *                    either because they are sold out, expired, or not yet on sale.
692
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
693
+	 * @return string
694
+	 * @throws EE_Error
695
+	 */
696
+	public function displayViewDetailsButton($DWMTS = false)
697
+	{
698
+		if (! $this->event->get_permalink()) {
699
+			EE_Error::add_error(
700
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
701
+				__FILE__,
702
+				__FUNCTION__,
703
+				__LINE__
704
+			);
705
+		}
706
+		$view_details_btn = '<form method="POST" action="';
707
+		$view_details_btn .= apply_filters(
708
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
709
+			$this->event->get_permalink(),
710
+			$this->event
711
+		);
712
+		$view_details_btn .= '"';
713
+		// open link in new window ?
714
+		$view_details_btn .= apply_filters(
715
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
716
+			$this->isIframe(),
717
+			$this
718
+		)
719
+			? ' target="_blank"'
720
+			: '';
721
+		$view_details_btn .= '>';
722
+		$btn_text         = apply_filters(
723
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
724
+			esc_html__('View Details', 'event_espresso'),
725
+			$this->event
726
+		);
727
+		$view_details_btn .= '<input id="ticket-selector-submit-'
728
+							 . $this->event->ID()
729
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
730
+							 . $btn_text
731
+							 . '" />';
732
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
733
+		if ($DWMTS) {
734
+			$view_details_btn .= $this->formClose();
735
+			$view_details_btn .= $this->ticketSelectorEndDiv();
736
+			$view_details_btn .= '<br/>';
737
+		} else {
738
+			$view_details_btn .= $this->clearTicketSelector();
739
+			$view_details_btn .= '<br/>';
740
+			$view_details_btn .= $this->formClose();
741
+		}
742
+		return $view_details_btn;
743
+	}
744
+
745
+
746
+
747
+	/**
748
+	 * @return string
749
+	 */
750
+	public function ticketSelectorEndDiv()
751
+	{
752
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 * @return string
759
+	 */
760
+	public function clearTicketSelector()
761
+	{
762
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
763
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
764
+	}
765
+
766
+
767
+
768
+	/**
769
+	 * @access        public
770
+	 * @return        string
771
+	 */
772
+	public function formClose()
773
+	{
774
+		return '</form>';
775
+	}
776 776
 
777 777
 
778 778
 
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 use InvalidArgumentException;
20 20
 use WP_Post;
21 21
 
22
-defined('EVENT_ESPRESSO_VERSION')|| exit('No direct script access allowed');
22
+defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
23 23
 
24 24
 
25 25
 
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
             }
141 141
         } else {
142 142
             $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
143
-            $dev_msg  = $user_msg . __(
143
+            $dev_msg  = $user_msg.__(
144 144
                     'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
145 145
                     'event_espresso'
146 146
                 );
147
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
147
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
148 148
             return false;
149 149
         }
150 150
         return true;
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         // reset filter for displaying submit button
209 209
         remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
210 210
         // poke and prod incoming event till it tells us what it is
211
-        if (! $this->setEvent($event)) {
211
+        if ( ! $this->setEvent($event)) {
212 212
             return false;
213 213
         }
214 214
         // begin gathering template arguments by getting event status
@@ -238,14 +238,14 @@  discard block
 block discarded – undo
238 238
             return $this->noTicketAvailableMessage();
239 239
         }
240 240
         // redirecting to another site for registration ??
241
-        $external_url = (string)$this->event->external_url();
241
+        $external_url = (string) $this->event->external_url();
242 242
         // if redirecting to another site for registration, then we don't load the TS
243 243
         $ticket_selector = $external_url
244 244
             ? $this->externalEventRegistration()
245 245
             : $this->loadTicketSelector($tickets, $template_args);
246 246
         // now set up the form (but not for the admin)
247 247
         $ticket_selector = $this->display_full_ui()
248
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
248
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
249 249
             : $ticket_selector;
250 250
         // submit button and form close tag
251 251
         $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
@@ -295,10 +295,10 @@  discard block
 block discarded – undo
295 295
      */
296 296
     protected function expiredEventMessage()
297 297
     {
298
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
298
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
299 299
                 'We\'re sorry, but all tickets sales have ended because the event is expired.',
300 300
                 'event_espresso'
301
-            ) . '</span></div><!-- .ee-event-expired-notice -->';
301
+            ).'</span></div><!-- .ee-event-expired-notice -->';
302 302
     }
303 303
 
304 304
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         }
330 330
         return '
331 331
             <div class="ee-event-expired-notice">
332
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
332
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
333 333
             </div><!-- .ee-event-expired-notice -->';
334 334
     }
335 335
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                 '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
363 363
             );
364 364
         }
365
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
365
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
366 366
     }
367 367
 
368 368
 
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
          * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
431 431
          * @param int $EVT_ID The Event ID
432 432
          */
433
-        $template_args['anchor_id']    = apply_filters(
433
+        $template_args['anchor_id'] = apply_filters(
434 434
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
435
-            '#tkt-slctr-tbl-' . $this->event->ID(),
435
+            '#tkt-slctr-tbl-'.$this->event->ID(),
436 436
             $this->event->ID()
437 437
         );
438 438
         $template_args['tickets']      = $tickets;
@@ -522,29 +522,29 @@  discard block
 block discarded – undo
522 522
     {
523 523
         // if redirecting, we don't need any anything else
524 524
         if ($external_url) {
525
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
525
+            $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"';
526 526
             // open link in new window ?
527
-            $html       .= apply_filters(
527
+            $html .= apply_filters(
528 528
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
529 529
                 $this->isIframe(),
530 530
                 $this
531 531
             )
532 532
                 ? ' target="_blank"'
533 533
                 : '';
534
-            $html       .= '>';
534
+            $html .= '>';
535 535
             $query_args = EEH_URL::get_query_string($external_url);
536
-            foreach ((array)$query_args as $query_arg => $value) {
537
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
536
+            foreach ((array) $query_args as $query_arg => $value) {
537
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
538 538
             }
539 539
             return $html;
540 540
         }
541 541
         // if there is no submit button, then don't start building a form
542 542
         // because the "View Details" button will build its own form
543
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
543
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
544 544
             return '';
545 545
         }
546 546
         $checkout_url = EEH_Event_View::event_link_url($ID);
547
-        if (! $checkout_url) {
547
+        if ( ! $checkout_url) {
548 548
             EE_Error::add_error(
549 549
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
550 550
                 __FILE__,
@@ -555,8 +555,8 @@  discard block
 block discarded – undo
555 555
         // set no cache headers and constants
556 556
         EE_System::do_not_cache();
557 557
         $extra_params = $this->iframe ? ' target="_blank"' : '';
558
-        $html         = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
559
-        $html         .= '<input type="hidden" name="ee" value="process_ticket_selections">';
558
+        $html         = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>';
559
+        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
560 560
         $html         = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
561 561
         return $html;
562 562
     }
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                 $html .= empty($external_url)
581 581
                     ? $this->ticketSelectorEndDiv()
582 582
                     : $this->clearTicketSelector();
583
-                $html .= '<br/>' . $this->formClose();
583
+                $html .= '<br/>'.$this->formClose();
584 584
             } elseif ($this->getMaxAttendees() === 1) {
585 585
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
586 586
                 if ($this->event->is_sold_out()) {
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
                 // no submit or view details button, and no additional content
639 639
                 $html .= $this->ticketSelectorEndDiv();
640 640
             }
641
-            if (! $this->iframe && ! is_archive()) {
641
+            if ( ! $this->iframe && ! is_archive()) {
642 642
                 $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
643 643
             }
644 644
         }
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
      */
659 659
     public function displayRegisterNowButton()
660 660
     {
661
-        $btn_text     = apply_filters(
661
+        $btn_text = apply_filters(
662 662
             'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
663 663
             __('Register Now', 'event_espresso'),
664 664
             $this->event
@@ -666,14 +666,14 @@  discard block
 block discarded – undo
666 666
         $external_url = $this->event->external_url();
667 667
         $html         = EEH_HTML::div(
668 668
             '',
669
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
669
+            'ticket-selector-submit-'.$this->event->ID().'-btn-wrap',
670 670
             'ticket-selector-submit-btn-wrap'
671 671
         );
672
-        $html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
672
+        $html         .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
673 673
         $html         .= ' class="ticket-selector-submit-btn ';
674 674
         $html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
675
-        $html         .= ' type="submit" value="' . $btn_text . '" />';
676
-        $html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
675
+        $html         .= ' type="submit" value="'.$btn_text.'" />';
676
+        $html         .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';
677 677
         $html         .= apply_filters(
678 678
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
679 679
             '',
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
      */
696 696
     public function displayViewDetailsButton($DWMTS = false)
697 697
     {
698
-        if (! $this->event->get_permalink()) {
698
+        if ( ! $this->event->get_permalink()) {
699 699
             EE_Error::add_error(
700 700
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
701 701
                 __FILE__,
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
             ? ' target="_blank"'
720 720
             : '';
721 721
         $view_details_btn .= '>';
722
-        $btn_text         = apply_filters(
722
+        $btn_text = apply_filters(
723 723
             'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
724 724
             esc_html__('View Details', 'event_espresso'),
725 725
             $this->event
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
      */
750 750
     public function ticketSelectorEndDiv()
751 751
     {
752
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
752
+        return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';
753 753
     }
754 754
 
755 755
 
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +3690 added lines, -3690 removed lines patch added patch discarded remove patch
@@ -30,2301 +30,2301 @@  discard block
 block discarded – undo
30 30
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
31 31
 {
32 32
 
33
-    /**
34
-     * @var EE_Registration
35
-     */
36
-    private $_registration;
37
-
38
-    /**
39
-     * @var EE_Event
40
-     */
41
-    private $_reg_event;
42
-
43
-    /**
44
-     * @var EE_Session
45
-     */
46
-    private $_session;
47
-
48
-    private static $_reg_status;
49
-
50
-    /**
51
-     * Form for displaying the custom questions for this registration.
52
-     * This gets used a few times throughout the request so its best to cache it
53
-     *
54
-     * @var EE_Registration_Custom_Questions_Form
55
-     */
56
-    protected $_reg_custom_questions_form = null;
57
-
58
-
59
-    /**
60
-     *        constructor
61
-     *
62
-     * @Constructor
63
-     * @access public
64
-     * @param bool $routing
65
-     * @return Registrations_Admin_Page
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        parent::__construct($routing);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'));
71
-    }
72
-
73
-
74
-    public function wp_loaded()
75
-    {
76
-        // when adding a new registration...
77
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
-            EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
80
-                 || absint($this->_req_data['processing_registration']) !== 1
81
-            ) {
82
-                // and it's NOT the attendee information reg step
83
-                // force cookie expiration by setting time to last week
84
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
-                // and update the global
86
-                $_COOKIE['ee_registration_added'] = 0;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-    protected function _init_page_props()
93
-    {
94
-        $this->page_slug        = REG_PG_SLUG;
95
-        $this->_admin_base_url  = REG_ADMIN_URL;
96
-        $this->_admin_base_path = REG_ADMIN;
97
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
98
-        $this->_cpt_routes      = array(
99
-            'add_new_attendee' => 'espresso_attendees',
100
-            'edit_attendee'    => 'espresso_attendees',
101
-            'insert_attendee'  => 'espresso_attendees',
102
-            'update_attendee'  => 'espresso_attendees',
103
-        );
104
-        $this->_cpt_model_names = array(
105
-            'add_new_attendee' => 'EEM_Attendee',
106
-            'edit_attendee'    => 'EEM_Attendee',
107
-        );
108
-        $this->_cpt_edit_routes = array(
109
-            'espresso_attendees' => 'edit_attendee',
110
-        );
111
-        $this->_pagenow_map     = array(
112
-            'add_new_attendee' => 'post-new.php',
113
-            'edit_attendee'    => 'post.php',
114
-            'trash'            => 'post.php',
115
-        );
116
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
-        //add filters so that the comment urls don't take users to a confusing 404 page
118
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
-    }
120
-
121
-
122
-    public function clear_comment_link($link, $comment, $args)
123
-    {
124
-        //gotta make sure this only happens on this route
125
-        $post_type = get_post_type($comment->comment_post_ID);
126
-        if ($post_type === 'espresso_attendees') {
127
-            return '#commentsdiv';
128
-        }
129
-        return $link;
130
-    }
131
-
132
-
133
-    protected function _ajax_hooks()
134
-    {
135
-        //todo: all hooks for registrations ajax goes in here
136
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
-    }
138
-
139
-
140
-    protected function _define_page_props()
141
-    {
142
-        $this->_admin_page_title = $this->page_label;
143
-        $this->_labels           = array(
144
-            'buttons'                      => array(
145
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
-            ),
154
-            'publishbox'                   => array(
155
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
-            ),
158
-            'hide_add_button_on_cpt_route' => array(
159
-                'edit_attendee' => true,
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     *        grab url requests and route them
167
-     *
168
-     * @access private
169
-     * @return void
170
-     */
171
-    public function _set_page_routes()
172
-    {
173
-        $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
-            ? $this->_req_data['_REG_ID'] : 0;
176
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
178
-            : $reg_id;
179
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
-            ? $this->_req_data['ATT_ID'] : 0;
181
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
-            ? $this->_req_data['post']
183
-            : $att_id;
184
-        $this->_page_routes = array(
185
-            'default'                            => array(
186
-                'func'       => '_registrations_overview_list_table',
187
-                'capability' => 'ee_read_registrations',
188
-            ),
189
-            'view_registration'                  => array(
190
-                'func'       => '_registration_details',
191
-                'capability' => 'ee_read_registration',
192
-                'obj_id'     => $reg_id,
193
-            ),
194
-            'edit_registration'                  => array(
195
-                'func'               => '_update_attendee_registration_form',
196
-                'noheader'           => true,
197
-                'headers_sent_route' => 'view_registration',
198
-                'capability'         => 'ee_edit_registration',
199
-                'obj_id'             => $reg_id,
200
-                '_REG_ID'            => $reg_id,
201
-            ),
202
-            'trash_registrations'                => array(
203
-                'func'       => '_trash_or_restore_registrations',
204
-                'args'       => array('trash' => true),
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'restore_registrations'              => array(
209
-                'func'       => '_trash_or_restore_registrations',
210
-                'args'       => array('trash' => false),
211
-                'noheader'   => true,
212
-                'capability' => 'ee_delete_registrations',
213
-            ),
214
-            'delete_registrations'               => array(
215
-                'func'       => '_delete_registrations',
216
-                'noheader'   => true,
217
-                'capability' => 'ee_delete_registrations',
218
-            ),
219
-            'new_registration'                   => array(
220
-                'func'       => 'new_registration',
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'process_reg_step'                   => array(
224
-                'func'       => 'process_reg_step',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registrations',
227
-            ),
228
-            'redirect_to_txn'                    => array(
229
-                'func'       => 'redirect_to_txn',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registrations',
232
-            ),
233
-            'change_reg_status'                  => array(
234
-                'func'       => '_change_reg_status',
235
-                'noheader'   => true,
236
-                'capability' => 'ee_edit_registration',
237
-                'obj_id'     => $reg_id,
238
-            ),
239
-            'approve_registration'               => array(
240
-                'func'       => 'approve_registration',
241
-                'noheader'   => true,
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_and_notify_registration'    => array(
246
-                'func'       => 'approve_registration',
247
-                'noheader'   => true,
248
-                'args'       => array(true),
249
-                'capability' => 'ee_edit_registration',
250
-                'obj_id'     => $reg_id,
251
-            ),
252
-            'approve_registrations'               => array(
253
-                'func'       => 'bulk_action_on_registrations',
254
-                'noheader'   => true,
255
-                'capability' => 'ee_edit_registrations',
256
-                'args' => array('approve')
257
-            ),
258
-            'approve_and_notify_registrations'               => array(
259
-                'func'       => 'bulk_action_on_registrations',
260
-                'noheader'   => true,
261
-                'capability' => 'ee_edit_registrations',
262
-                'args' => array('approve', true)
263
-            ),
264
-            'decline_registration'               => array(
265
-                'func'       => 'decline_registration',
266
-                'noheader'   => true,
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_and_notify_registration'    => array(
271
-                'func'       => 'decline_registration',
272
-                'noheader'   => true,
273
-                'args'       => array(true),
274
-                'capability' => 'ee_edit_registration',
275
-                'obj_id'     => $reg_id,
276
-            ),
277
-            'decline_registrations'               => array(
278
-                'func'       => 'bulk_action_on_registrations',
279
-                'noheader'   => true,
280
-                'capability' => 'ee_edit_registrations',
281
-                'args' => array('decline')
282
-            ),
283
-            'decline_and_notify_registrations'    => array(
284
-                'func'       => 'bulk_action_on_registrations',
285
-                'noheader'   => true,
286
-                'capability' => 'ee_edit_registrations',
287
-                'args' => array('decline', true)
288
-            ),
289
-            'pending_registration'               => array(
290
-                'func'       => 'pending_registration',
291
-                'noheader'   => true,
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_and_notify_registration'    => array(
296
-                'func'       => 'pending_registration',
297
-                'noheader'   => true,
298
-                'args'       => array(true),
299
-                'capability' => 'ee_edit_registration',
300
-                'obj_id'     => $reg_id,
301
-            ),
302
-            'pending_registrations'               => array(
303
-                'func'       => 'bulk_action_on_registrations',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-                'args' => array('pending')
307
-            ),
308
-            'pending_and_notify_registrations'    => array(
309
-                'func'       => 'bulk_action_on_registrations',
310
-                'noheader'   => true,
311
-                'capability' => 'ee_edit_registrations',
312
-                'args' => array('pending', true)
313
-            ),
314
-            'no_approve_registration'            => array(
315
-                'func'       => 'not_approve_registration',
316
-                'noheader'   => true,
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_and_notify_registration' => array(
321
-                'func'       => 'not_approve_registration',
322
-                'noheader'   => true,
323
-                'args'       => array(true),
324
-                'capability' => 'ee_edit_registration',
325
-                'obj_id'     => $reg_id,
326
-            ),
327
-            'no_approve_registrations'            => array(
328
-                'func'       => 'bulk_action_on_registrations',
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_registrations',
331
-                'args' => array('not_approve')
332
-            ),
333
-            'no_approve_and_notify_registrations' => array(
334
-                'func'       => 'bulk_action_on_registrations',
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_registrations',
337
-                'args' => array('not_approve', true)
338
-            ),
339
-            'cancel_registration'                => array(
340
-                'func'       => 'cancel_registration',
341
-                'noheader'   => true,
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_and_notify_registration'     => array(
346
-                'func'       => 'cancel_registration',
347
-                'noheader'   => true,
348
-                'args'       => array(true),
349
-                'capability' => 'ee_edit_registration',
350
-                'obj_id'     => $reg_id,
351
-            ),
352
-            'cancel_registrations'                => array(
353
-                'func'       => 'bulk_action_on_registrations',
354
-                'noheader'   => true,
355
-                'capability' => 'ee_edit_registrations',
356
-                'args' => array('cancel')
357
-            ),
358
-            'cancel_and_notify_registrations'     => array(
359
-                'func'       => 'bulk_action_on_registrations',
360
-                'noheader'   => true,
361
-                'capability' => 'ee_edit_registrations',
362
-                'args' => array('cancel', true)
363
-            ),
364
-            'wait_list_registration' => array(
365
-                'func'       => 'wait_list_registration',
366
-                'noheader'   => true,
367
-                'capability' => 'ee_edit_registration',
368
-                'obj_id'     => $reg_id,
369
-            ),
370
-            'wait_list_and_notify_registration' => array(
371
-                'func'       => 'wait_list_registration',
372
-                'noheader'   => true,
373
-                'args'       => array(true),
374
-                'capability' => 'ee_edit_registration',
375
-                'obj_id'     => $reg_id,
376
-            ),
377
-            'contact_list'                       => array(
378
-                'func'       => '_attendee_contact_list_table',
379
-                'capability' => 'ee_read_contacts',
380
-            ),
381
-            'add_new_attendee'                   => array(
382
-                'func' => '_create_new_cpt_item',
383
-                'args' => array(
384
-                    'new_attendee' => true,
385
-                    'capability'   => 'ee_edit_contacts',
386
-                ),
387
-            ),
388
-            'edit_attendee'                      => array(
389
-                'func'       => '_edit_cpt_item',
390
-                'capability' => 'ee_edit_contacts',
391
-                'obj_id'     => $att_id,
392
-            ),
393
-            'duplicate_attendee'                 => array(
394
-                'func'       => '_duplicate_attendee',
395
-                'noheader'   => true,
396
-                'capability' => 'ee_edit_contacts',
397
-                'obj_id'     => $att_id,
398
-            ),
399
-            'insert_attendee'                    => array(
400
-                'func'       => '_insert_or_update_attendee',
401
-                'args'       => array(
402
-                    'new_attendee' => true,
403
-                ),
404
-                'noheader'   => true,
405
-                'capability' => 'ee_edit_contacts',
406
-            ),
407
-            'update_attendee'                    => array(
408
-                'func'       => '_insert_or_update_attendee',
409
-                'args'       => array(
410
-                    'new_attendee' => false,
411
-                ),
412
-                'noheader'   => true,
413
-                'capability' => 'ee_edit_contacts',
414
-                'obj_id'     => $att_id,
415
-            ),
416
-            'trash_attendees' => array(
417
-                'func' => '_trash_or_restore_attendees',
418
-                'args' => array(
419
-                    'trash' => 'true'
420
-                ),
421
-                'noheader' => true,
422
-                'capability' => 'ee_delete_contacts'
423
-            ),
424
-            'trash_attendee'                    => array(
425
-                'func'       => '_trash_or_restore_attendees',
426
-                'args'       => array(
427
-                    'trash' => true,
428
-                ),
429
-                'noheader'   => true,
430
-                'capability' => 'ee_delete_contacts',
431
-                'obj_id'     => $att_id,
432
-            ),
433
-            'restore_attendees'                  => array(
434
-                'func'       => '_trash_or_restore_attendees',
435
-                'args'       => array(
436
-                    'trash' => false,
437
-                ),
438
-                'noheader'   => true,
439
-                'capability' => 'ee_delete_contacts',
440
-                'obj_id'     => $att_id,
441
-            ),
442
-            'resend_registration'                => array(
443
-                'func'       => '_resend_registration',
444
-                'noheader'   => true,
445
-                'capability' => 'ee_send_message',
446
-            ),
447
-            'registrations_report'               => array(
448
-                'func'       => '_registrations_report',
449
-                'noheader'   => true,
450
-                'capability' => 'ee_read_registrations',
451
-            ),
452
-            'contact_list_export'                => array(
453
-                'func'       => '_contact_list_export',
454
-                'noheader'   => true,
455
-                'capability' => 'export',
456
-            ),
457
-            'contact_list_report'                => array(
458
-                'func'       => '_contact_list_report',
459
-                'noheader'   => true,
460
-                'capability' => 'ee_read_contacts',
461
-            ),
462
-        );
463
-    }
464
-
465
-
466
-    protected function _set_page_config()
467
-    {
468
-        $this->_page_config = array(
469
-            'default'           => array(
470
-                'nav'           => array(
471
-                    'label' => esc_html__('Overview', 'event_espresso'),
472
-                    'order' => 5,
473
-                ),
474
-                'help_tabs'     => array(
475
-                    'registrations_overview_help_tab'                       => array(
476
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
-                        'filename' => 'registrations_overview',
478
-                    ),
479
-                    'registrations_overview_table_column_headings_help_tab' => array(
480
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
-                        'filename' => 'registrations_overview_table_column_headings',
482
-                    ),
483
-                    'registrations_overview_filters_help_tab'               => array(
484
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
-                        'filename' => 'registrations_overview_filters',
486
-                    ),
487
-                    'registrations_overview_views_help_tab'                 => array(
488
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
489
-                        'filename' => 'registrations_overview_views',
490
-                    ),
491
-                    'registrations_regoverview_other_help_tab'              => array(
492
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
-                        'filename' => 'registrations_overview_other',
494
-                    ),
495
-                ),
496
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
497
-                'qtips'         => array('Registration_List_Table_Tips'),
498
-                'list_table'    => 'EE_Registrations_List_Table',
499
-                'require_nonce' => false,
500
-            ),
501
-            'view_registration' => array(
502
-                'nav'           => array(
503
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
504
-                    'order'      => 15,
505
-                    'url'        => isset($this->_req_data['_REG_ID'])
506
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
-                        : $this->_admin_base_url,
508
-                    'persistent' => false,
509
-                ),
510
-                'help_tabs'     => array(
511
-                    'registrations_details_help_tab'                    => array(
512
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
513
-                        'filename' => 'registrations_details',
514
-                    ),
515
-                    'registrations_details_table_help_tab'              => array(
516
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
-                        'filename' => 'registrations_details_table',
518
-                    ),
519
-                    'registrations_details_form_answers_help_tab'       => array(
520
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
-                        'filename' => 'registrations_details_form_answers',
522
-                    ),
523
-                    'registrations_details_registrant_details_help_tab' => array(
524
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
525
-                        'filename' => 'registrations_details_registrant_details',
526
-                    ),
527
-                ),
528
-                'help_tour'     => array('Registration_Details_Help_Tour'),
529
-                'metaboxes'     => array_merge(
530
-                    $this->_default_espresso_metaboxes,
531
-                    array('_registration_details_metaboxes')
532
-                ),
533
-                'require_nonce' => false,
534
-            ),
535
-            'new_registration'  => array(
536
-                'nav'           => array(
537
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
-                    'url'        => '#',
539
-                    'order'      => 15,
540
-                    'persistent' => false,
541
-                ),
542
-                'metaboxes'     => $this->_default_espresso_metaboxes,
543
-                'labels'        => array(
544
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
-                ),
546
-                'require_nonce' => false,
547
-            ),
548
-            'add_new_attendee'  => array(
549
-                'nav'           => array(
550
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
551
-                    'order'      => 15,
552
-                    'persistent' => false,
553
-                ),
554
-                'metaboxes'     => array_merge(
555
-                    $this->_default_espresso_metaboxes,
556
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
557
-                ),
558
-                'require_nonce' => false,
559
-            ),
560
-            'edit_attendee'     => array(
561
-                'nav'           => array(
562
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
-                    'order'      => 15,
564
-                    'persistent' => false,
565
-                    'url'        => isset($this->_req_data['ATT_ID'])
566
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
-                        : $this->_admin_base_url,
568
-                ),
569
-                'metaboxes'     => array('attendee_editor_metaboxes'),
570
-                'require_nonce' => false,
571
-            ),
572
-            'contact_list'      => array(
573
-                'nav'           => array(
574
-                    'label' => esc_html__('Contact List', 'event_espresso'),
575
-                    'order' => 20,
576
-                ),
577
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
578
-                'help_tabs'     => array(
579
-                    'registrations_contact_list_help_tab'                       => array(
580
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
-                        'filename' => 'registrations_contact_list',
582
-                    ),
583
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
584
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
-                        'filename' => 'registrations_contact_list_table_column_headings',
586
-                    ),
587
-                    'registrations_contact_list_views_help_tab'                 => array(
588
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
-                        'filename' => 'registrations_contact_list_views',
590
-                    ),
591
-                    'registrations_contact_list_other_help_tab'                 => array(
592
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
-                        'filename' => 'registrations_contact_list_other',
594
-                    ),
595
-                ),
596
-                'help_tour'     => array('Contact_List_Help_Tour'),
597
-                'metaboxes'     => array(),
598
-                'require_nonce' => false,
599
-            ),
600
-            //override default cpt routes
601
-            'create_new'        => '',
602
-            'edit'              => '',
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * The below methods aren't used by this class currently
609
-     */
610
-    protected function _add_screen_options()
611
-    {
612
-    }
613
-
614
-
615
-    protected function _add_feature_pointers()
616
-    {
617
-    }
618
-
619
-
620
-    public function admin_init()
621
-    {
622
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
-            'click "Update Registration Questions" to save your changes',
624
-            'event_espresso'
625
-        );
626
-    }
627
-
628
-
629
-    public function admin_notices()
630
-    {
631
-    }
632
-
633
-
634
-    public function admin_footer_scripts()
635
-    {
636
-    }
637
-
638
-
639
-    /**
640
-     *        get list of registration statuses
641
-     *
642
-     * @access private
643
-     * @return void
644
-     * @throws EE_Error
645
-     */
646
-    private function _get_registration_status_array()
647
-    {
648
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
649
-    }
650
-
651
-
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_per_page_screen_option();
655
-    }
656
-
657
-
658
-    protected function _add_screen_options_contact_list()
659
-    {
660
-        $page_title              = $this->_admin_page_title;
661
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
662
-        $this->_per_page_screen_option();
663
-        $this->_admin_page_title = $page_title;
664
-    }
665
-
666
-
667
-    public function load_scripts_styles()
668
-    {
669
-        //style
670
-        wp_register_style(
671
-            'espresso_reg',
672
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
673
-            array('ee-admin-css'),
674
-            EVENT_ESPRESSO_VERSION
675
-        );
676
-        wp_enqueue_style('espresso_reg');
677
-        //script
678
-        wp_register_script(
679
-            'espresso_reg',
680
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
681
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682
-            EVENT_ESPRESSO_VERSION,
683
-            true
684
-        );
685
-        wp_enqueue_script('espresso_reg');
686
-    }
687
-
688
-
689
-    public function load_scripts_styles_edit_attendee()
690
-    {
691
-        //stuff to only show up on our attendee edit details page.
692
-        $attendee_details_translations = array(
693
-            'att_publish_text' => sprintf(
694
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
695
-                $this->_cpt_model_obj->get_datetime('ATT_created')
696
-            ),
697
-        );
698
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
699
-        wp_enqueue_script('jquery-validate');
700
-    }
701
-
702
-
703
-    public function load_scripts_styles_view_registration()
704
-    {
705
-        //styles
706
-        wp_enqueue_style('espresso-ui-theme');
707
-        //scripts
708
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
709
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
710
-    }
711
-
712
-
713
-    public function load_scripts_styles_contact_list()
714
-    {
715
-        wp_deregister_style('espresso_reg');
716
-        wp_register_style(
717
-            'espresso_att',
718
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
719
-            array('ee-admin-css'),
720
-            EVENT_ESPRESSO_VERSION
721
-        );
722
-        wp_enqueue_style('espresso_att');
723
-    }
724
-
725
-
726
-    public function load_scripts_styles_new_registration()
727
-    {
728
-        wp_register_script(
729
-            'ee-spco-for-admin',
730
-            REG_ASSETS_URL . 'spco_for_admin.js',
731
-            array('underscore', 'jquery'),
732
-            EVENT_ESPRESSO_VERSION,
733
-            true
734
-        );
735
-        wp_enqueue_script('ee-spco-for-admin');
736
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
737
-        EE_Form_Section_Proper::wp_enqueue_scripts();
738
-        EED_Ticket_Selector::load_tckt_slctr_assets();
739
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
740
-    }
741
-
742
-
743
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
744
-    {
745
-        add_filter('FHEE_load_EE_messages', '__return_true');
746
-    }
747
-
748
-
749
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
750
-    {
751
-        add_filter('FHEE_load_EE_messages', '__return_true');
752
-    }
753
-
754
-
755
-    protected function _set_list_table_views_default()
756
-    {
757
-        //for notification related bulk actions we need to make sure only active messengers have an option.
758
-        EED_Messages::set_autoloaders();
759
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
760
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
761
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
762
-        //key= bulk_action_slug, value= message type.
763
-        $match_array = array(
764
-            'approve_registrations'    => 'registration',
765
-            'decline_registrations'    => 'declined_registration',
766
-            'pending_registrations'    => 'pending_approval',
767
-            'no_approve_registrations' => 'not_approved_registration',
768
-            'cancel_registrations'     => 'cancelled_registration',
769
-        );
770
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
771
-            'ee_send_message',
772
-            'batch_send_messages'
773
-        );
774
-        /** setup reg status bulk actions **/
775
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
776
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
777
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
778
-                    'Approve and Notify Registrations',
779
-                    'event_espresso'
780
-                );
781
-        }
782
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
783
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
784
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
785
-                    'Decline and Notify Registrations',
786
-                    'event_espresso'
787
-                );
788
-        }
789
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
790
-            'Set Registrations to Pending Payment',
791
-            'event_espresso'
792
-        );
793
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
794
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
795
-                    'Set Registrations to Pending Payment and Notify',
796
-                    'event_espresso'
797
-                );
798
-        }
799
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
800
-            'Set Registrations to Not Approved',
801
-            'event_espresso'
802
-        );
803
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
804
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
805
-                    'Set Registrations to Not Approved and Notify',
806
-                    'event_espresso'
807
-                );
808
-        }
809
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
810
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
811
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
812
-                    'Cancel Registrations and Notify',
813
-                    'event_espresso'
814
-                );
815
-        }
816
-        $def_reg_status_actions = apply_filters(
817
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
818
-            $def_reg_status_actions,
819
-            $active_mts,
820
-            $can_send
821
-        );
822
-
823
-        $this->_views = array(
824
-            'all'   => array(
825
-                'slug'        => 'all',
826
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => array_merge($def_reg_status_actions, array(
829
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
-                )),
831
-            ),
832
-            'month' => array(
833
-                'slug'        => 'month',
834
-                'label'       => esc_html__('This Month', 'event_espresso'),
835
-                'count'       => 0,
836
-                'bulk_action' => array_merge($def_reg_status_actions, array(
837
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
838
-                )),
839
-            ),
840
-            'today' => array(
841
-                'slug'        => 'today',
842
-                'label'       => sprintf(
843
-                    esc_html__('Today - %s', 'event_espresso'),
844
-                    date('M d, Y', current_time('timestamp'))
845
-                ),
846
-                'count'       => 0,
847
-                'bulk_action' => array_merge($def_reg_status_actions, array(
848
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
849
-                )),
850
-            ),
851
-        );
852
-        if (EE_Registry::instance()->CAP->current_user_can(
853
-            'ee_delete_registrations',
854
-            'espresso_registrations_delete_registration'
855
-        )) {
856
-            $this->_views['incomplete'] = array(
857
-                'slug'        => 'incomplete',
858
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
859
-                'count'       => 0,
860
-                'bulk_action' => array(
861
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862
-                ),
863
-            );
864
-            $this->_views['trash']      = array(
865
-                'slug'        => 'trash',
866
-                'label'       => esc_html__('Trash', 'event_espresso'),
867
-                'count'       => 0,
868
-                'bulk_action' => array(
869
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
870
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
871
-                ),
872
-            );
873
-        }
874
-    }
875
-
876
-
877
-    protected function _set_list_table_views_contact_list()
878
-    {
879
-        $this->_views = array(
880
-            'in_use' => array(
881
-                'slug'        => 'in_use',
882
-                'label'       => esc_html__('In Use', 'event_espresso'),
883
-                'count'       => 0,
884
-                'bulk_action' => array(
885
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
886
-                ),
887
-            ),
888
-        );
889
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
890
-            'espresso_registrations_trash_attendees')
891
-        ) {
892
-            $this->_views['trash'] = array(
893
-                'slug'        => 'trash',
894
-                'label'       => esc_html__('Trash', 'event_espresso'),
895
-                'count'       => 0,
896
-                'bulk_action' => array(
897
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
-                ),
899
-            );
900
-        }
901
-    }
902
-
903
-
904
-    protected function _registration_legend_items()
905
-    {
906
-        $fc_items = array(
907
-            'star-icon'        => array(
908
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
-            ),
911
-            'view_details'     => array(
912
-                'class' => 'dashicons dashicons-clipboard',
913
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
-            ),
915
-            'edit_attendee'    => array(
916
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
-            ),
919
-            'view_transaction' => array(
920
-                'class' => 'dashicons dashicons-cart',
921
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
-            ),
923
-            'view_invoice'     => array(
924
-                'class' => 'dashicons dashicons-media-spreadsheet',
925
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
-            ),
927
-        );
928
-        if (EE_Registry::instance()->CAP->current_user_can(
929
-            'ee_send_message',
930
-            'espresso_registrations_resend_registration'
931
-        )) {
932
-            $fc_items['resend_registration'] = array(
933
-                'class' => 'dashicons dashicons-email-alt',
934
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
-            );
936
-        } else {
937
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
-        }
939
-        if (EE_Registry::instance()->CAP->current_user_can(
940
-            'ee_read_global_messages',
941
-            'view_filtered_messages'
942
-        )) {
943
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
-                $fc_items['view_related_messages'] = array(
946
-                    'class' => $related_for_icon['css_class'],
947
-                    'desc'  => $related_for_icon['label'],
948
-                );
949
-            }
950
-        }
951
-        $sc_items = array(
952
-            'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_approved,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_pending_payment,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_wait_list,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_incomplete,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_not_approved,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-            'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
-                'desc'  => EEH_Template::pretty_status(
995
-                    EEM_Registration::status_id_declined,
996
-                    false,
997
-                    'sentence'
998
-                ),
999
-            ),
1000
-            'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
-                'desc'  => EEH_Template::pretty_status(
1003
-                    EEM_Registration::status_id_cancelled,
1004
-                    false,
1005
-                    'sentence'
1006
-                ),
1007
-            ),
1008
-        );
1009
-        return array_merge($fc_items, $sc_items);
1010
-    }
1011
-
1012
-
1013
-
1014
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1015
-    /**
1016
-     * @throws \EE_Error
1017
-     */
1018
-    protected function _registrations_overview_list_table()
1019
-    {
1020
-        $this->_template_args['admin_page_header'] = '';
1021
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1022
-            ? absint($this->_req_data['event_id'])
1023
-            : 0;
1024
-        if ($EVT_ID) {
1025
-            if (EE_Registry::instance()->CAP->current_user_can(
1026
-                'ee_edit_registrations',
1027
-                'espresso_registrations_new_registration',
1028
-                $EVT_ID
1029
-            )) {
1030
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1031
-                    'new_registration',
1032
-                    'add-registrant',
1033
-                    array('event_id' => $EVT_ID),
1034
-                    'add-new-h2'
1035
-                );
1036
-            }
1037
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1038
-            if ($event instanceof EE_Event) {
1039
-                $this->_template_args['admin_page_header'] = sprintf(
1040
-                    esc_html__(
1041
-                        '%s Viewing registrations for the event: %s%s',
1042
-                        'event_espresso'
1043
-                    ),
1044
-                    '<h3 style="line-height:1.5em;">',
1045
-                    '<br /><a href="'
1046
-                        . EE_Admin_Page::add_query_args_and_nonce(
1047
-                            array(
1048
-                                'action' => 'edit',
1049
-                                'post'   => $event->ID(),
1050
-                            ),
1051
-                            EVENTS_ADMIN_URL
1052
-                        )
1053
-                        . '">&nbsp;'
1054
-                        . $event->get('EVT_name')
1055
-                        . '&nbsp;</a>&nbsp;',
1056
-                    '</h3>'
1057
-                );
1058
-            }
1059
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1060
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1061
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1062
-                $this->_template_args['admin_page_header'] = substr(
1063
-                    $this->_template_args['admin_page_header'],
1064
-                    0,
1065
-                    -5
1066
-                );
1067
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1068
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1069
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1070
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1071
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1072
-            }
1073
-        }
1074
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1075
-        $this->display_admin_list_table_page_with_no_sidebar();
1076
-    }
1077
-
1078
-
1079
-    /**
1080
-     * This sets the _registration property for the registration details screen
1081
-     *
1082
-     * @access private
1083
-     * @return bool
1084
-     * @throws EE_Error
1085
-     * @throws InvalidArgumentException
1086
-     * @throws InvalidDataTypeException
1087
-     * @throws InvalidInterfaceException
1088
-     */
1089
-    private function _set_registration_object()
1090
-    {
1091
-        //get out if we've already set the object
1092
-        if ($this->_registration instanceof EE_Registration) {
1093
-            return true;
1094
-        }
1095
-        $REG    = EEM_Registration::instance();
1096
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1097
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1098
-            return true;
1099
-        } else {
1100
-            $error_msg = sprintf(
1101
-                esc_html__(
1102
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1103
-                    'event_espresso'
1104
-                ),
1105
-                $REG_ID
1106
-            );
1107
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1108
-            $this->_registration = null;
1109
-            return false;
1110
-        }
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     * Used to retrieve registrations for the list table.
1116
-     *
1117
-     * @param int  $per_page
1118
-     * @param bool $count
1119
-     * @param bool $this_month
1120
-     * @param bool $today
1121
-     * @return EE_Registration[]|int
1122
-     * @throws EE_Error
1123
-     * @throws InvalidArgumentException
1124
-     * @throws InvalidDataTypeException
1125
-     * @throws InvalidInterfaceException
1126
-     */
1127
-    public function get_registrations(
1128
-        $per_page = 10,
1129
-        $count = false,
1130
-        $this_month = false,
1131
-        $today = false
1132
-    ) {
1133
-        if ($this_month) {
1134
-            $this->_req_data['status'] = 'month';
1135
-        }
1136
-        if ($today) {
1137
-            $this->_req_data['status'] = 'today';
1138
-        }
1139
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1140
-        /**
1141
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1142
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1143
-         * @see EEM_Base::get_all()
1144
-         */
1145
-        $query_params['group_by'] = '';
1146
-
1147
-        return $count
1148
-            ? EEM_Registration::instance()->count($query_params)
1149
-            /** @type EE_Registration[] */
1150
-            : EEM_Registration::instance()->get_all($query_params);
1151
-    }
1152
-
1153
-
1154
-    /**
1155
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1156
-     * Note: this listens to values on the request for some of the query parameters.
1157
-     *
1158
-     * @param array $request
1159
-     * @param int   $per_page
1160
-     * @param bool  $count
1161
-     * @return array
1162
-     * @throws EE_Error
1163
-     */
1164
-    protected function _get_registration_query_parameters(
1165
-        $request = array(),
1166
-        $per_page = 10,
1167
-        $count = false
1168
-    ) {
1169
-
1170
-        $query_params = array(
1171
-            0                          => $this->_get_where_conditions_for_registrations_query(
1172
-                $request
1173
-            ),
1174
-            'caps'                     => EEM_Registration::caps_read_admin,
1175
-            'default_where_conditions' => 'this_model_only',
1176
-        );
1177
-        if (! $count) {
1178
-            $query_params = array_merge(
1179
-                $query_params,
1180
-                $this->_get_orderby_for_registrations_query(),
1181
-                $this->_get_limit($per_page)
1182
-            );
1183
-        }
1184
-
1185
-        return $query_params;
1186
-    }
1187
-
1188
-
1189
-    /**
1190
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1191
-     *
1192
-     * @param array $request usually the same as $this->_req_data but not necessarily
1193
-     * @return array
1194
-     */
1195
-    protected function _add_event_id_to_where_conditions(array $request)
1196
-    {
1197
-        $where = array();
1198
-        if (! empty($request['event_id'])) {
1199
-            $where['EVT_ID'] = absint($request['event_id']);
1200
-        }
1201
-        return $where;
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1207
-     *
1208
-     * @param array $request usually the same as $this->_req_data but not necessarily
1209
-     * @return array
1210
-     */
1211
-    protected function _add_category_id_to_where_conditions(array $request)
1212
-    {
1213
-        $where = array();
1214
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1215
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1216
-        }
1217
-        return $where;
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1223
-     *
1224
-     * @param array $request usually the same as $this->_req_data but not necessarily
1225
-     * @return array
1226
-     */
1227
-    protected function _add_datetime_id_to_where_conditions(array $request)
1228
-    {
1229
-        $where = array();
1230
-        if (! empty($request['datetime_id'])) {
1231
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1232
-        }
1233
-        if (! empty($request['DTT_ID'])) {
1234
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1235
-        }
1236
-        return $where;
1237
-    }
1238
-
1239
-
1240
-    /**
1241
-     * Adds the correct registration status to the where conditions for the registrations query.
1242
-     *
1243
-     * @param array $request usually the same as $this->_req_data but not necessarily
1244
-     * @return array
1245
-     */
1246
-    protected function _add_registration_status_to_where_conditions(array $request)
1247
-    {
1248
-        $where = array();
1249
-        $view = EEH_Array::is_set($request, 'status', '');
1250
-        $registration_status = ! empty($request['_reg_status'])
1251
-            ? sanitize_text_field($request['_reg_status'])
1252
-            : '';
1253
-
1254
-        /*
33
+	/**
34
+	 * @var EE_Registration
35
+	 */
36
+	private $_registration;
37
+
38
+	/**
39
+	 * @var EE_Event
40
+	 */
41
+	private $_reg_event;
42
+
43
+	/**
44
+	 * @var EE_Session
45
+	 */
46
+	private $_session;
47
+
48
+	private static $_reg_status;
49
+
50
+	/**
51
+	 * Form for displaying the custom questions for this registration.
52
+	 * This gets used a few times throughout the request so its best to cache it
53
+	 *
54
+	 * @var EE_Registration_Custom_Questions_Form
55
+	 */
56
+	protected $_reg_custom_questions_form = null;
57
+
58
+
59
+	/**
60
+	 *        constructor
61
+	 *
62
+	 * @Constructor
63
+	 * @access public
64
+	 * @param bool $routing
65
+	 * @return Registrations_Admin_Page
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		parent::__construct($routing);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'));
71
+	}
72
+
73
+
74
+	public function wp_loaded()
75
+	{
76
+		// when adding a new registration...
77
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
+			EE_System::do_not_cache();
79
+			if (! isset($this->_req_data['processing_registration'])
80
+				 || absint($this->_req_data['processing_registration']) !== 1
81
+			) {
82
+				// and it's NOT the attendee information reg step
83
+				// force cookie expiration by setting time to last week
84
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
+				// and update the global
86
+				$_COOKIE['ee_registration_added'] = 0;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+	protected function _init_page_props()
93
+	{
94
+		$this->page_slug        = REG_PG_SLUG;
95
+		$this->_admin_base_url  = REG_ADMIN_URL;
96
+		$this->_admin_base_path = REG_ADMIN;
97
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
98
+		$this->_cpt_routes      = array(
99
+			'add_new_attendee' => 'espresso_attendees',
100
+			'edit_attendee'    => 'espresso_attendees',
101
+			'insert_attendee'  => 'espresso_attendees',
102
+			'update_attendee'  => 'espresso_attendees',
103
+		);
104
+		$this->_cpt_model_names = array(
105
+			'add_new_attendee' => 'EEM_Attendee',
106
+			'edit_attendee'    => 'EEM_Attendee',
107
+		);
108
+		$this->_cpt_edit_routes = array(
109
+			'espresso_attendees' => 'edit_attendee',
110
+		);
111
+		$this->_pagenow_map     = array(
112
+			'add_new_attendee' => 'post-new.php',
113
+			'edit_attendee'    => 'post.php',
114
+			'trash'            => 'post.php',
115
+		);
116
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
+		//add filters so that the comment urls don't take users to a confusing 404 page
118
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
+	}
120
+
121
+
122
+	public function clear_comment_link($link, $comment, $args)
123
+	{
124
+		//gotta make sure this only happens on this route
125
+		$post_type = get_post_type($comment->comment_post_ID);
126
+		if ($post_type === 'espresso_attendees') {
127
+			return '#commentsdiv';
128
+		}
129
+		return $link;
130
+	}
131
+
132
+
133
+	protected function _ajax_hooks()
134
+	{
135
+		//todo: all hooks for registrations ajax goes in here
136
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
+	}
138
+
139
+
140
+	protected function _define_page_props()
141
+	{
142
+		$this->_admin_page_title = $this->page_label;
143
+		$this->_labels           = array(
144
+			'buttons'                      => array(
145
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
+			),
154
+			'publishbox'                   => array(
155
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
+			),
158
+			'hide_add_button_on_cpt_route' => array(
159
+				'edit_attendee' => true,
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 *        grab url requests and route them
167
+	 *
168
+	 * @access private
169
+	 * @return void
170
+	 */
171
+	public function _set_page_routes()
172
+	{
173
+		$this->_get_registration_status_array();
174
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
+			? $this->_req_data['_REG_ID'] : 0;
176
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
+			? $this->_req_data['reg_status_change_form']['REG_ID']
178
+			: $reg_id;
179
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
+			? $this->_req_data['ATT_ID'] : 0;
181
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
+			? $this->_req_data['post']
183
+			: $att_id;
184
+		$this->_page_routes = array(
185
+			'default'                            => array(
186
+				'func'       => '_registrations_overview_list_table',
187
+				'capability' => 'ee_read_registrations',
188
+			),
189
+			'view_registration'                  => array(
190
+				'func'       => '_registration_details',
191
+				'capability' => 'ee_read_registration',
192
+				'obj_id'     => $reg_id,
193
+			),
194
+			'edit_registration'                  => array(
195
+				'func'               => '_update_attendee_registration_form',
196
+				'noheader'           => true,
197
+				'headers_sent_route' => 'view_registration',
198
+				'capability'         => 'ee_edit_registration',
199
+				'obj_id'             => $reg_id,
200
+				'_REG_ID'            => $reg_id,
201
+			),
202
+			'trash_registrations'                => array(
203
+				'func'       => '_trash_or_restore_registrations',
204
+				'args'       => array('trash' => true),
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'restore_registrations'              => array(
209
+				'func'       => '_trash_or_restore_registrations',
210
+				'args'       => array('trash' => false),
211
+				'noheader'   => true,
212
+				'capability' => 'ee_delete_registrations',
213
+			),
214
+			'delete_registrations'               => array(
215
+				'func'       => '_delete_registrations',
216
+				'noheader'   => true,
217
+				'capability' => 'ee_delete_registrations',
218
+			),
219
+			'new_registration'                   => array(
220
+				'func'       => 'new_registration',
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'process_reg_step'                   => array(
224
+				'func'       => 'process_reg_step',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registrations',
227
+			),
228
+			'redirect_to_txn'                    => array(
229
+				'func'       => 'redirect_to_txn',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registrations',
232
+			),
233
+			'change_reg_status'                  => array(
234
+				'func'       => '_change_reg_status',
235
+				'noheader'   => true,
236
+				'capability' => 'ee_edit_registration',
237
+				'obj_id'     => $reg_id,
238
+			),
239
+			'approve_registration'               => array(
240
+				'func'       => 'approve_registration',
241
+				'noheader'   => true,
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_and_notify_registration'    => array(
246
+				'func'       => 'approve_registration',
247
+				'noheader'   => true,
248
+				'args'       => array(true),
249
+				'capability' => 'ee_edit_registration',
250
+				'obj_id'     => $reg_id,
251
+			),
252
+			'approve_registrations'               => array(
253
+				'func'       => 'bulk_action_on_registrations',
254
+				'noheader'   => true,
255
+				'capability' => 'ee_edit_registrations',
256
+				'args' => array('approve')
257
+			),
258
+			'approve_and_notify_registrations'               => array(
259
+				'func'       => 'bulk_action_on_registrations',
260
+				'noheader'   => true,
261
+				'capability' => 'ee_edit_registrations',
262
+				'args' => array('approve', true)
263
+			),
264
+			'decline_registration'               => array(
265
+				'func'       => 'decline_registration',
266
+				'noheader'   => true,
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_and_notify_registration'    => array(
271
+				'func'       => 'decline_registration',
272
+				'noheader'   => true,
273
+				'args'       => array(true),
274
+				'capability' => 'ee_edit_registration',
275
+				'obj_id'     => $reg_id,
276
+			),
277
+			'decline_registrations'               => array(
278
+				'func'       => 'bulk_action_on_registrations',
279
+				'noheader'   => true,
280
+				'capability' => 'ee_edit_registrations',
281
+				'args' => array('decline')
282
+			),
283
+			'decline_and_notify_registrations'    => array(
284
+				'func'       => 'bulk_action_on_registrations',
285
+				'noheader'   => true,
286
+				'capability' => 'ee_edit_registrations',
287
+				'args' => array('decline', true)
288
+			),
289
+			'pending_registration'               => array(
290
+				'func'       => 'pending_registration',
291
+				'noheader'   => true,
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_and_notify_registration'    => array(
296
+				'func'       => 'pending_registration',
297
+				'noheader'   => true,
298
+				'args'       => array(true),
299
+				'capability' => 'ee_edit_registration',
300
+				'obj_id'     => $reg_id,
301
+			),
302
+			'pending_registrations'               => array(
303
+				'func'       => 'bulk_action_on_registrations',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+				'args' => array('pending')
307
+			),
308
+			'pending_and_notify_registrations'    => array(
309
+				'func'       => 'bulk_action_on_registrations',
310
+				'noheader'   => true,
311
+				'capability' => 'ee_edit_registrations',
312
+				'args' => array('pending', true)
313
+			),
314
+			'no_approve_registration'            => array(
315
+				'func'       => 'not_approve_registration',
316
+				'noheader'   => true,
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_and_notify_registration' => array(
321
+				'func'       => 'not_approve_registration',
322
+				'noheader'   => true,
323
+				'args'       => array(true),
324
+				'capability' => 'ee_edit_registration',
325
+				'obj_id'     => $reg_id,
326
+			),
327
+			'no_approve_registrations'            => array(
328
+				'func'       => 'bulk_action_on_registrations',
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_registrations',
331
+				'args' => array('not_approve')
332
+			),
333
+			'no_approve_and_notify_registrations' => array(
334
+				'func'       => 'bulk_action_on_registrations',
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_registrations',
337
+				'args' => array('not_approve', true)
338
+			),
339
+			'cancel_registration'                => array(
340
+				'func'       => 'cancel_registration',
341
+				'noheader'   => true,
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_and_notify_registration'     => array(
346
+				'func'       => 'cancel_registration',
347
+				'noheader'   => true,
348
+				'args'       => array(true),
349
+				'capability' => 'ee_edit_registration',
350
+				'obj_id'     => $reg_id,
351
+			),
352
+			'cancel_registrations'                => array(
353
+				'func'       => 'bulk_action_on_registrations',
354
+				'noheader'   => true,
355
+				'capability' => 'ee_edit_registrations',
356
+				'args' => array('cancel')
357
+			),
358
+			'cancel_and_notify_registrations'     => array(
359
+				'func'       => 'bulk_action_on_registrations',
360
+				'noheader'   => true,
361
+				'capability' => 'ee_edit_registrations',
362
+				'args' => array('cancel', true)
363
+			),
364
+			'wait_list_registration' => array(
365
+				'func'       => 'wait_list_registration',
366
+				'noheader'   => true,
367
+				'capability' => 'ee_edit_registration',
368
+				'obj_id'     => $reg_id,
369
+			),
370
+			'wait_list_and_notify_registration' => array(
371
+				'func'       => 'wait_list_registration',
372
+				'noheader'   => true,
373
+				'args'       => array(true),
374
+				'capability' => 'ee_edit_registration',
375
+				'obj_id'     => $reg_id,
376
+			),
377
+			'contact_list'                       => array(
378
+				'func'       => '_attendee_contact_list_table',
379
+				'capability' => 'ee_read_contacts',
380
+			),
381
+			'add_new_attendee'                   => array(
382
+				'func' => '_create_new_cpt_item',
383
+				'args' => array(
384
+					'new_attendee' => true,
385
+					'capability'   => 'ee_edit_contacts',
386
+				),
387
+			),
388
+			'edit_attendee'                      => array(
389
+				'func'       => '_edit_cpt_item',
390
+				'capability' => 'ee_edit_contacts',
391
+				'obj_id'     => $att_id,
392
+			),
393
+			'duplicate_attendee'                 => array(
394
+				'func'       => '_duplicate_attendee',
395
+				'noheader'   => true,
396
+				'capability' => 'ee_edit_contacts',
397
+				'obj_id'     => $att_id,
398
+			),
399
+			'insert_attendee'                    => array(
400
+				'func'       => '_insert_or_update_attendee',
401
+				'args'       => array(
402
+					'new_attendee' => true,
403
+				),
404
+				'noheader'   => true,
405
+				'capability' => 'ee_edit_contacts',
406
+			),
407
+			'update_attendee'                    => array(
408
+				'func'       => '_insert_or_update_attendee',
409
+				'args'       => array(
410
+					'new_attendee' => false,
411
+				),
412
+				'noheader'   => true,
413
+				'capability' => 'ee_edit_contacts',
414
+				'obj_id'     => $att_id,
415
+			),
416
+			'trash_attendees' => array(
417
+				'func' => '_trash_or_restore_attendees',
418
+				'args' => array(
419
+					'trash' => 'true'
420
+				),
421
+				'noheader' => true,
422
+				'capability' => 'ee_delete_contacts'
423
+			),
424
+			'trash_attendee'                    => array(
425
+				'func'       => '_trash_or_restore_attendees',
426
+				'args'       => array(
427
+					'trash' => true,
428
+				),
429
+				'noheader'   => true,
430
+				'capability' => 'ee_delete_contacts',
431
+				'obj_id'     => $att_id,
432
+			),
433
+			'restore_attendees'                  => array(
434
+				'func'       => '_trash_or_restore_attendees',
435
+				'args'       => array(
436
+					'trash' => false,
437
+				),
438
+				'noheader'   => true,
439
+				'capability' => 'ee_delete_contacts',
440
+				'obj_id'     => $att_id,
441
+			),
442
+			'resend_registration'                => array(
443
+				'func'       => '_resend_registration',
444
+				'noheader'   => true,
445
+				'capability' => 'ee_send_message',
446
+			),
447
+			'registrations_report'               => array(
448
+				'func'       => '_registrations_report',
449
+				'noheader'   => true,
450
+				'capability' => 'ee_read_registrations',
451
+			),
452
+			'contact_list_export'                => array(
453
+				'func'       => '_contact_list_export',
454
+				'noheader'   => true,
455
+				'capability' => 'export',
456
+			),
457
+			'contact_list_report'                => array(
458
+				'func'       => '_contact_list_report',
459
+				'noheader'   => true,
460
+				'capability' => 'ee_read_contacts',
461
+			),
462
+		);
463
+	}
464
+
465
+
466
+	protected function _set_page_config()
467
+	{
468
+		$this->_page_config = array(
469
+			'default'           => array(
470
+				'nav'           => array(
471
+					'label' => esc_html__('Overview', 'event_espresso'),
472
+					'order' => 5,
473
+				),
474
+				'help_tabs'     => array(
475
+					'registrations_overview_help_tab'                       => array(
476
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
+						'filename' => 'registrations_overview',
478
+					),
479
+					'registrations_overview_table_column_headings_help_tab' => array(
480
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
+						'filename' => 'registrations_overview_table_column_headings',
482
+					),
483
+					'registrations_overview_filters_help_tab'               => array(
484
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
+						'filename' => 'registrations_overview_filters',
486
+					),
487
+					'registrations_overview_views_help_tab'                 => array(
488
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
489
+						'filename' => 'registrations_overview_views',
490
+					),
491
+					'registrations_regoverview_other_help_tab'              => array(
492
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
+						'filename' => 'registrations_overview_other',
494
+					),
495
+				),
496
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
497
+				'qtips'         => array('Registration_List_Table_Tips'),
498
+				'list_table'    => 'EE_Registrations_List_Table',
499
+				'require_nonce' => false,
500
+			),
501
+			'view_registration' => array(
502
+				'nav'           => array(
503
+					'label'      => esc_html__('REG Details', 'event_espresso'),
504
+					'order'      => 15,
505
+					'url'        => isset($this->_req_data['_REG_ID'])
506
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
+						: $this->_admin_base_url,
508
+					'persistent' => false,
509
+				),
510
+				'help_tabs'     => array(
511
+					'registrations_details_help_tab'                    => array(
512
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
513
+						'filename' => 'registrations_details',
514
+					),
515
+					'registrations_details_table_help_tab'              => array(
516
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
+						'filename' => 'registrations_details_table',
518
+					),
519
+					'registrations_details_form_answers_help_tab'       => array(
520
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
+						'filename' => 'registrations_details_form_answers',
522
+					),
523
+					'registrations_details_registrant_details_help_tab' => array(
524
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
525
+						'filename' => 'registrations_details_registrant_details',
526
+					),
527
+				),
528
+				'help_tour'     => array('Registration_Details_Help_Tour'),
529
+				'metaboxes'     => array_merge(
530
+					$this->_default_espresso_metaboxes,
531
+					array('_registration_details_metaboxes')
532
+				),
533
+				'require_nonce' => false,
534
+			),
535
+			'new_registration'  => array(
536
+				'nav'           => array(
537
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
+					'url'        => '#',
539
+					'order'      => 15,
540
+					'persistent' => false,
541
+				),
542
+				'metaboxes'     => $this->_default_espresso_metaboxes,
543
+				'labels'        => array(
544
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
+				),
546
+				'require_nonce' => false,
547
+			),
548
+			'add_new_attendee'  => array(
549
+				'nav'           => array(
550
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
551
+					'order'      => 15,
552
+					'persistent' => false,
553
+				),
554
+				'metaboxes'     => array_merge(
555
+					$this->_default_espresso_metaboxes,
556
+					array('_publish_post_box', 'attendee_editor_metaboxes')
557
+				),
558
+				'require_nonce' => false,
559
+			),
560
+			'edit_attendee'     => array(
561
+				'nav'           => array(
562
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
+					'order'      => 15,
564
+					'persistent' => false,
565
+					'url'        => isset($this->_req_data['ATT_ID'])
566
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
+						: $this->_admin_base_url,
568
+				),
569
+				'metaboxes'     => array('attendee_editor_metaboxes'),
570
+				'require_nonce' => false,
571
+			),
572
+			'contact_list'      => array(
573
+				'nav'           => array(
574
+					'label' => esc_html__('Contact List', 'event_espresso'),
575
+					'order' => 20,
576
+				),
577
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
578
+				'help_tabs'     => array(
579
+					'registrations_contact_list_help_tab'                       => array(
580
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
+						'filename' => 'registrations_contact_list',
582
+					),
583
+					'registrations_contact-list_table_column_headings_help_tab' => array(
584
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
+						'filename' => 'registrations_contact_list_table_column_headings',
586
+					),
587
+					'registrations_contact_list_views_help_tab'                 => array(
588
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
+						'filename' => 'registrations_contact_list_views',
590
+					),
591
+					'registrations_contact_list_other_help_tab'                 => array(
592
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
+						'filename' => 'registrations_contact_list_other',
594
+					),
595
+				),
596
+				'help_tour'     => array('Contact_List_Help_Tour'),
597
+				'metaboxes'     => array(),
598
+				'require_nonce' => false,
599
+			),
600
+			//override default cpt routes
601
+			'create_new'        => '',
602
+			'edit'              => '',
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * The below methods aren't used by this class currently
609
+	 */
610
+	protected function _add_screen_options()
611
+	{
612
+	}
613
+
614
+
615
+	protected function _add_feature_pointers()
616
+	{
617
+	}
618
+
619
+
620
+	public function admin_init()
621
+	{
622
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
+			'click "Update Registration Questions" to save your changes',
624
+			'event_espresso'
625
+		);
626
+	}
627
+
628
+
629
+	public function admin_notices()
630
+	{
631
+	}
632
+
633
+
634
+	public function admin_footer_scripts()
635
+	{
636
+	}
637
+
638
+
639
+	/**
640
+	 *        get list of registration statuses
641
+	 *
642
+	 * @access private
643
+	 * @return void
644
+	 * @throws EE_Error
645
+	 */
646
+	private function _get_registration_status_array()
647
+	{
648
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
649
+	}
650
+
651
+
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_per_page_screen_option();
655
+	}
656
+
657
+
658
+	protected function _add_screen_options_contact_list()
659
+	{
660
+		$page_title              = $this->_admin_page_title;
661
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
662
+		$this->_per_page_screen_option();
663
+		$this->_admin_page_title = $page_title;
664
+	}
665
+
666
+
667
+	public function load_scripts_styles()
668
+	{
669
+		//style
670
+		wp_register_style(
671
+			'espresso_reg',
672
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
673
+			array('ee-admin-css'),
674
+			EVENT_ESPRESSO_VERSION
675
+		);
676
+		wp_enqueue_style('espresso_reg');
677
+		//script
678
+		wp_register_script(
679
+			'espresso_reg',
680
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
681
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682
+			EVENT_ESPRESSO_VERSION,
683
+			true
684
+		);
685
+		wp_enqueue_script('espresso_reg');
686
+	}
687
+
688
+
689
+	public function load_scripts_styles_edit_attendee()
690
+	{
691
+		//stuff to only show up on our attendee edit details page.
692
+		$attendee_details_translations = array(
693
+			'att_publish_text' => sprintf(
694
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
695
+				$this->_cpt_model_obj->get_datetime('ATT_created')
696
+			),
697
+		);
698
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
699
+		wp_enqueue_script('jquery-validate');
700
+	}
701
+
702
+
703
+	public function load_scripts_styles_view_registration()
704
+	{
705
+		//styles
706
+		wp_enqueue_style('espresso-ui-theme');
707
+		//scripts
708
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
709
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
710
+	}
711
+
712
+
713
+	public function load_scripts_styles_contact_list()
714
+	{
715
+		wp_deregister_style('espresso_reg');
716
+		wp_register_style(
717
+			'espresso_att',
718
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
719
+			array('ee-admin-css'),
720
+			EVENT_ESPRESSO_VERSION
721
+		);
722
+		wp_enqueue_style('espresso_att');
723
+	}
724
+
725
+
726
+	public function load_scripts_styles_new_registration()
727
+	{
728
+		wp_register_script(
729
+			'ee-spco-for-admin',
730
+			REG_ASSETS_URL . 'spco_for_admin.js',
731
+			array('underscore', 'jquery'),
732
+			EVENT_ESPRESSO_VERSION,
733
+			true
734
+		);
735
+		wp_enqueue_script('ee-spco-for-admin');
736
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
737
+		EE_Form_Section_Proper::wp_enqueue_scripts();
738
+		EED_Ticket_Selector::load_tckt_slctr_assets();
739
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
740
+	}
741
+
742
+
743
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
744
+	{
745
+		add_filter('FHEE_load_EE_messages', '__return_true');
746
+	}
747
+
748
+
749
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
750
+	{
751
+		add_filter('FHEE_load_EE_messages', '__return_true');
752
+	}
753
+
754
+
755
+	protected function _set_list_table_views_default()
756
+	{
757
+		//for notification related bulk actions we need to make sure only active messengers have an option.
758
+		EED_Messages::set_autoloaders();
759
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
760
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
761
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
762
+		//key= bulk_action_slug, value= message type.
763
+		$match_array = array(
764
+			'approve_registrations'    => 'registration',
765
+			'decline_registrations'    => 'declined_registration',
766
+			'pending_registrations'    => 'pending_approval',
767
+			'no_approve_registrations' => 'not_approved_registration',
768
+			'cancel_registrations'     => 'cancelled_registration',
769
+		);
770
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
771
+			'ee_send_message',
772
+			'batch_send_messages'
773
+		);
774
+		/** setup reg status bulk actions **/
775
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
776
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
777
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
778
+					'Approve and Notify Registrations',
779
+					'event_espresso'
780
+				);
781
+		}
782
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
783
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
784
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
785
+					'Decline and Notify Registrations',
786
+					'event_espresso'
787
+				);
788
+		}
789
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
790
+			'Set Registrations to Pending Payment',
791
+			'event_espresso'
792
+		);
793
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
794
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
795
+					'Set Registrations to Pending Payment and Notify',
796
+					'event_espresso'
797
+				);
798
+		}
799
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
800
+			'Set Registrations to Not Approved',
801
+			'event_espresso'
802
+		);
803
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
804
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
805
+					'Set Registrations to Not Approved and Notify',
806
+					'event_espresso'
807
+				);
808
+		}
809
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
810
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
811
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
812
+					'Cancel Registrations and Notify',
813
+					'event_espresso'
814
+				);
815
+		}
816
+		$def_reg_status_actions = apply_filters(
817
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
818
+			$def_reg_status_actions,
819
+			$active_mts,
820
+			$can_send
821
+		);
822
+
823
+		$this->_views = array(
824
+			'all'   => array(
825
+				'slug'        => 'all',
826
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => array_merge($def_reg_status_actions, array(
829
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
+				)),
831
+			),
832
+			'month' => array(
833
+				'slug'        => 'month',
834
+				'label'       => esc_html__('This Month', 'event_espresso'),
835
+				'count'       => 0,
836
+				'bulk_action' => array_merge($def_reg_status_actions, array(
837
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
838
+				)),
839
+			),
840
+			'today' => array(
841
+				'slug'        => 'today',
842
+				'label'       => sprintf(
843
+					esc_html__('Today - %s', 'event_espresso'),
844
+					date('M d, Y', current_time('timestamp'))
845
+				),
846
+				'count'       => 0,
847
+				'bulk_action' => array_merge($def_reg_status_actions, array(
848
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
849
+				)),
850
+			),
851
+		);
852
+		if (EE_Registry::instance()->CAP->current_user_can(
853
+			'ee_delete_registrations',
854
+			'espresso_registrations_delete_registration'
855
+		)) {
856
+			$this->_views['incomplete'] = array(
857
+				'slug'        => 'incomplete',
858
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
859
+				'count'       => 0,
860
+				'bulk_action' => array(
861
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862
+				),
863
+			);
864
+			$this->_views['trash']      = array(
865
+				'slug'        => 'trash',
866
+				'label'       => esc_html__('Trash', 'event_espresso'),
867
+				'count'       => 0,
868
+				'bulk_action' => array(
869
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
870
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
871
+				),
872
+			);
873
+		}
874
+	}
875
+
876
+
877
+	protected function _set_list_table_views_contact_list()
878
+	{
879
+		$this->_views = array(
880
+			'in_use' => array(
881
+				'slug'        => 'in_use',
882
+				'label'       => esc_html__('In Use', 'event_espresso'),
883
+				'count'       => 0,
884
+				'bulk_action' => array(
885
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
886
+				),
887
+			),
888
+		);
889
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
890
+			'espresso_registrations_trash_attendees')
891
+		) {
892
+			$this->_views['trash'] = array(
893
+				'slug'        => 'trash',
894
+				'label'       => esc_html__('Trash', 'event_espresso'),
895
+				'count'       => 0,
896
+				'bulk_action' => array(
897
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
+				),
899
+			);
900
+		}
901
+	}
902
+
903
+
904
+	protected function _registration_legend_items()
905
+	{
906
+		$fc_items = array(
907
+			'star-icon'        => array(
908
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
+			),
911
+			'view_details'     => array(
912
+				'class' => 'dashicons dashicons-clipboard',
913
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
+			),
915
+			'edit_attendee'    => array(
916
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
+			),
919
+			'view_transaction' => array(
920
+				'class' => 'dashicons dashicons-cart',
921
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
+			),
923
+			'view_invoice'     => array(
924
+				'class' => 'dashicons dashicons-media-spreadsheet',
925
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
+			),
927
+		);
928
+		if (EE_Registry::instance()->CAP->current_user_can(
929
+			'ee_send_message',
930
+			'espresso_registrations_resend_registration'
931
+		)) {
932
+			$fc_items['resend_registration'] = array(
933
+				'class' => 'dashicons dashicons-email-alt',
934
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
+			);
936
+		} else {
937
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
+		}
939
+		if (EE_Registry::instance()->CAP->current_user_can(
940
+			'ee_read_global_messages',
941
+			'view_filtered_messages'
942
+		)) {
943
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
+				$fc_items['view_related_messages'] = array(
946
+					'class' => $related_for_icon['css_class'],
947
+					'desc'  => $related_for_icon['label'],
948
+				);
949
+			}
950
+		}
951
+		$sc_items = array(
952
+			'approved_status'   => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_approved,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'pending_status'    => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_pending_payment,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'wait_list'         => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_wait_list,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'incomplete_status' => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_incomplete,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'not_approved'      => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_not_approved,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+			'declined_status'   => array(
993
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
+				'desc'  => EEH_Template::pretty_status(
995
+					EEM_Registration::status_id_declined,
996
+					false,
997
+					'sentence'
998
+				),
999
+			),
1000
+			'cancelled_status'  => array(
1001
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
+				'desc'  => EEH_Template::pretty_status(
1003
+					EEM_Registration::status_id_cancelled,
1004
+					false,
1005
+					'sentence'
1006
+				),
1007
+			),
1008
+		);
1009
+		return array_merge($fc_items, $sc_items);
1010
+	}
1011
+
1012
+
1013
+
1014
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1015
+	/**
1016
+	 * @throws \EE_Error
1017
+	 */
1018
+	protected function _registrations_overview_list_table()
1019
+	{
1020
+		$this->_template_args['admin_page_header'] = '';
1021
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1022
+			? absint($this->_req_data['event_id'])
1023
+			: 0;
1024
+		if ($EVT_ID) {
1025
+			if (EE_Registry::instance()->CAP->current_user_can(
1026
+				'ee_edit_registrations',
1027
+				'espresso_registrations_new_registration',
1028
+				$EVT_ID
1029
+			)) {
1030
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1031
+					'new_registration',
1032
+					'add-registrant',
1033
+					array('event_id' => $EVT_ID),
1034
+					'add-new-h2'
1035
+				);
1036
+			}
1037
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1038
+			if ($event instanceof EE_Event) {
1039
+				$this->_template_args['admin_page_header'] = sprintf(
1040
+					esc_html__(
1041
+						'%s Viewing registrations for the event: %s%s',
1042
+						'event_espresso'
1043
+					),
1044
+					'<h3 style="line-height:1.5em;">',
1045
+					'<br /><a href="'
1046
+						. EE_Admin_Page::add_query_args_and_nonce(
1047
+							array(
1048
+								'action' => 'edit',
1049
+								'post'   => $event->ID(),
1050
+							),
1051
+							EVENTS_ADMIN_URL
1052
+						)
1053
+						. '">&nbsp;'
1054
+						. $event->get('EVT_name')
1055
+						. '&nbsp;</a>&nbsp;',
1056
+					'</h3>'
1057
+				);
1058
+			}
1059
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1060
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1061
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1062
+				$this->_template_args['admin_page_header'] = substr(
1063
+					$this->_template_args['admin_page_header'],
1064
+					0,
1065
+					-5
1066
+				);
1067
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1068
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1069
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1070
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1071
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1072
+			}
1073
+		}
1074
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1075
+		$this->display_admin_list_table_page_with_no_sidebar();
1076
+	}
1077
+
1078
+
1079
+	/**
1080
+	 * This sets the _registration property for the registration details screen
1081
+	 *
1082
+	 * @access private
1083
+	 * @return bool
1084
+	 * @throws EE_Error
1085
+	 * @throws InvalidArgumentException
1086
+	 * @throws InvalidDataTypeException
1087
+	 * @throws InvalidInterfaceException
1088
+	 */
1089
+	private function _set_registration_object()
1090
+	{
1091
+		//get out if we've already set the object
1092
+		if ($this->_registration instanceof EE_Registration) {
1093
+			return true;
1094
+		}
1095
+		$REG    = EEM_Registration::instance();
1096
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1097
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1098
+			return true;
1099
+		} else {
1100
+			$error_msg = sprintf(
1101
+				esc_html__(
1102
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1103
+					'event_espresso'
1104
+				),
1105
+				$REG_ID
1106
+			);
1107
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1108
+			$this->_registration = null;
1109
+			return false;
1110
+		}
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 * Used to retrieve registrations for the list table.
1116
+	 *
1117
+	 * @param int  $per_page
1118
+	 * @param bool $count
1119
+	 * @param bool $this_month
1120
+	 * @param bool $today
1121
+	 * @return EE_Registration[]|int
1122
+	 * @throws EE_Error
1123
+	 * @throws InvalidArgumentException
1124
+	 * @throws InvalidDataTypeException
1125
+	 * @throws InvalidInterfaceException
1126
+	 */
1127
+	public function get_registrations(
1128
+		$per_page = 10,
1129
+		$count = false,
1130
+		$this_month = false,
1131
+		$today = false
1132
+	) {
1133
+		if ($this_month) {
1134
+			$this->_req_data['status'] = 'month';
1135
+		}
1136
+		if ($today) {
1137
+			$this->_req_data['status'] = 'today';
1138
+		}
1139
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1140
+		/**
1141
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1142
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1143
+		 * @see EEM_Base::get_all()
1144
+		 */
1145
+		$query_params['group_by'] = '';
1146
+
1147
+		return $count
1148
+			? EEM_Registration::instance()->count($query_params)
1149
+			/** @type EE_Registration[] */
1150
+			: EEM_Registration::instance()->get_all($query_params);
1151
+	}
1152
+
1153
+
1154
+	/**
1155
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1156
+	 * Note: this listens to values on the request for some of the query parameters.
1157
+	 *
1158
+	 * @param array $request
1159
+	 * @param int   $per_page
1160
+	 * @param bool  $count
1161
+	 * @return array
1162
+	 * @throws EE_Error
1163
+	 */
1164
+	protected function _get_registration_query_parameters(
1165
+		$request = array(),
1166
+		$per_page = 10,
1167
+		$count = false
1168
+	) {
1169
+
1170
+		$query_params = array(
1171
+			0                          => $this->_get_where_conditions_for_registrations_query(
1172
+				$request
1173
+			),
1174
+			'caps'                     => EEM_Registration::caps_read_admin,
1175
+			'default_where_conditions' => 'this_model_only',
1176
+		);
1177
+		if (! $count) {
1178
+			$query_params = array_merge(
1179
+				$query_params,
1180
+				$this->_get_orderby_for_registrations_query(),
1181
+				$this->_get_limit($per_page)
1182
+			);
1183
+		}
1184
+
1185
+		return $query_params;
1186
+	}
1187
+
1188
+
1189
+	/**
1190
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1191
+	 *
1192
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1193
+	 * @return array
1194
+	 */
1195
+	protected function _add_event_id_to_where_conditions(array $request)
1196
+	{
1197
+		$where = array();
1198
+		if (! empty($request['event_id'])) {
1199
+			$where['EVT_ID'] = absint($request['event_id']);
1200
+		}
1201
+		return $where;
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1207
+	 *
1208
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1209
+	 * @return array
1210
+	 */
1211
+	protected function _add_category_id_to_where_conditions(array $request)
1212
+	{
1213
+		$where = array();
1214
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1215
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1216
+		}
1217
+		return $where;
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1223
+	 *
1224
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1225
+	 * @return array
1226
+	 */
1227
+	protected function _add_datetime_id_to_where_conditions(array $request)
1228
+	{
1229
+		$where = array();
1230
+		if (! empty($request['datetime_id'])) {
1231
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1232
+		}
1233
+		if (! empty($request['DTT_ID'])) {
1234
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1235
+		}
1236
+		return $where;
1237
+	}
1238
+
1239
+
1240
+	/**
1241
+	 * Adds the correct registration status to the where conditions for the registrations query.
1242
+	 *
1243
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1244
+	 * @return array
1245
+	 */
1246
+	protected function _add_registration_status_to_where_conditions(array $request)
1247
+	{
1248
+		$where = array();
1249
+		$view = EEH_Array::is_set($request, 'status', '');
1250
+		$registration_status = ! empty($request['_reg_status'])
1251
+			? sanitize_text_field($request['_reg_status'])
1252
+			: '';
1253
+
1254
+		/*
1255 1255
          * If filtering by registration status, then we show registrations matching that status.
1256 1256
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1257 1257
          * UNLESS viewing trashed registrations.
1258 1258
          */
1259
-        if (! empty($registration_status)) {
1260
-            $where['STS_ID'] = $registration_status;
1261
-        } else {
1262
-            //make sure we exclude incomplete registrations, but only if not trashed.
1263
-            if ($view === 'trash') {
1264
-                $where['REG_deleted'] = true;
1265
-            } elseif ($view === 'incomplete') {
1266
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1267
-            } else {
1268
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1269
-            }
1270
-        }
1271
-        return $where;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * Adds any provided date restraints to the where conditions for the registrations query.
1277
-     *
1278
-     * @param array $request usually the same as $this->_req_data but not necessarily
1279
-     * @return array
1280
-     * @throws EE_Error
1281
-     * @throws InvalidArgumentException
1282
-     * @throws InvalidDataTypeException
1283
-     * @throws InvalidInterfaceException
1284
-     */
1285
-    protected function _add_date_to_where_conditions(array $request)
1286
-    {
1287
-        $where = array();
1288
-        $view = EEH_Array::is_set($request, 'status', '');
1289
-        $month_range             = ! empty($request['month_range'])
1290
-            ? sanitize_text_field($request['month_range'])
1291
-            : '';
1292
-        $retrieve_for_today      = $view === 'today';
1293
-        $retrieve_for_this_month = $view === 'month';
1294
-
1295
-        if ($retrieve_for_today) {
1296
-            $now               = date('Y-m-d', current_time('timestamp'));
1297
-            $where['REG_date'] = array(
1298
-                'BETWEEN',
1299
-                array(
1300
-                    EEM_Registration::instance()->convert_datetime_for_query(
1301
-                        'REG_date',
1302
-                        $now . ' 00:00:00',
1303
-                        'Y-m-d H:i:s'
1304
-                    ),
1305
-                    EEM_Registration::instance()->convert_datetime_for_query(
1306
-                        'REG_date',
1307
-                        $now . ' 23:59:59',
1308
-                        'Y-m-d H:i:s'
1309
-                    ),
1310
-                ),
1311
-            );
1312
-        } elseif ($retrieve_for_this_month) {
1313
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1314
-            $days_this_month        = date('t', current_time('timestamp'));
1315
-            $where['REG_date']      = array(
1316
-                'BETWEEN',
1317
-                array(
1318
-                    EEM_Registration::instance()->convert_datetime_for_query(
1319
-                        'REG_date',
1320
-                        $current_year_and_month . '-01 00:00:00',
1321
-                        'Y-m-d H:i:s'
1322
-                    ),
1323
-                    EEM_Registration::instance()->convert_datetime_for_query(
1324
-                        'REG_date',
1325
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1326
-                        'Y-m-d H:i:s'
1327
-                    ),
1328
-                ),
1329
-            );
1330
-        } elseif ($month_range) {
1331
-            $pieces          = explode(' ', $month_range, 3);
1332
-            $month_requested = ! empty($pieces[0])
1333
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1334
-                : '';
1335
-            $year_requested  = ! empty($pieces[1])
1336
-                ? $pieces[1]
1337
-                : '';
1338
-            //if there is not a month or year then we can't go further
1339
-            if ($month_requested && $year_requested) {
1340
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1341
-                $where['REG_date'] = array(
1342
-                    'BETWEEN',
1343
-                    array(
1344
-                        EEM_Registration::instance()->convert_datetime_for_query(
1345
-                            'REG_date',
1346
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1347
-                            'Y-m-d H:i:s'
1348
-                        ),
1349
-                        EEM_Registration::instance()->convert_datetime_for_query(
1350
-                            'REG_date',
1351
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1352
-                            'Y-m-d H:i:s'
1353
-                        ),
1354
-                    ),
1355
-                );
1356
-            }
1357
-        }
1358
-        return $where;
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * Adds any provided search restraints to the where conditions for the registrations query
1364
-     *
1365
-     * @param array $request usually the same as $this->_req_data but not necessarily
1366
-     * @return array
1367
-     */
1368
-    protected function _add_search_to_where_conditions(array $request)
1369
-    {
1370
-        $where = array();
1371
-        if (! empty($request['s'])) {
1372
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1373
-            $where['OR*search_conditions'] = array(
1374
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1375
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1376
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1377
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1378
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1379
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1380
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1381
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1382
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1383
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1384
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1385
-                'REG_final_price'                         => array('LIKE', $search_string),
1386
-                'REG_code'                                => array('LIKE', $search_string),
1387
-                'REG_count'                               => array('LIKE', $search_string),
1388
-                'REG_group_size'                          => array('LIKE', $search_string),
1389
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1390
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1391
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1392
-            );
1393
-        }
1394
-        return $where;
1395
-    }
1396
-
1397
-
1398
-    /**
1399
-     * Sets up the where conditions for the registrations query.
1400
-     *
1401
-     * @param array $request
1402
-     * @return array
1403
-     * @throws EE_Error
1404
-     */
1405
-    protected function _get_where_conditions_for_registrations_query($request)
1406
-    {
1407
-        return apply_filters(
1408
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1409
-            array_merge(
1410
-                $this->_add_event_id_to_where_conditions($request),
1411
-                $this->_add_category_id_to_where_conditions($request),
1412
-                $this->_add_datetime_id_to_where_conditions($request),
1413
-                $this->_add_registration_status_to_where_conditions($request),
1414
-                $this->_add_date_to_where_conditions($request),
1415
-                $this->_add_search_to_where_conditions($request)
1416
-            ),
1417
-            $request
1418
-        );
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * Sets up the orderby for the registrations query.
1424
-     *
1425
-     * @return array
1426
-     */
1427
-    protected function _get_orderby_for_registrations_query()
1428
-    {
1429
-        $orderby_field = ! empty($this->_req_data['orderby'])
1430
-            ? sanitize_text_field($this->_req_data['orderby'])
1431
-            : '';
1432
-        switch ($orderby_field) {
1433
-            case '_REG_ID':
1434
-                $orderby_field = 'REG_ID';
1435
-                break;
1436
-            case '_Reg_status':
1437
-                $orderby_field = 'STS_ID';
1438
-                break;
1439
-            case 'ATT_fname':
1440
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1441
-                break;
1442
-            case 'ATT_lname':
1443
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1444
-                break;
1445
-            case 'event_name':
1446
-                $orderby_field = 'Event.EVT_name';
1447
-                break;
1448
-            case 'DTT_EVT_start':
1449
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1450
-                break;
1451
-            default: //'REG_date'
1452
-                $orderby_field = 'REG_date';
1453
-        }
1454
-
1455
-        //order
1456
-        $order = ! empty($this->_req_data['order'])
1457
-            ? sanitize_text_field($this->_req_data['order'])
1458
-            : 'DESC';
1459
-
1460
-        //mutate orderby_field
1461
-        $orderby_field = array_combine(
1462
-            (array) $orderby_field,
1463
-            array_fill(0, count($orderby_field), $order)
1464
-        );
1465
-        //because there are many registrations with the same date, define
1466
-        //a secondary way to order them, otherwise MySQL seems to be a bit random
1467
-        if (empty($order['REG_ID'])) {
1468
-            $orderby_field['REG_ID'] = $order;
1469
-        }
1470
-        return array('order_by' => $orderby_field);
1471
-    }
1472
-
1473
-
1474
-    /**
1475
-     * Sets up the limit for the registrations query.
1476
-     *
1477
-     * @param $per_page
1478
-     * @return array
1479
-     */
1480
-    protected function _get_limit($per_page)
1481
-    {
1482
-        $current_page = ! empty($this->_req_data['paged'])
1483
-            ? absint($this->_req_data['paged'])
1484
-            : 1;
1485
-        $per_page     = ! empty($this->_req_data['perpage'])
1486
-            ? $this->_req_data['perpage']
1487
-            : $per_page;
1488
-
1489
-        //-1 means return all results so get out if that's set.
1490
-        if ((int)$per_page === -1) {
1491
-            return array();
1492
-        }
1493
-        $per_page = absint($per_page);
1494
-        $offset   = ($current_page - 1) * $per_page;
1495
-        return array('limit' => array($offset, $per_page));
1496
-    }
1497
-
1498
-
1499
-    public function get_registration_status_array()
1500
-    {
1501
-        return self::$_reg_status;
1502
-    }
1503
-
1504
-
1505
-
1506
-
1507
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1508
-    /**
1509
-     *        generates HTML for the View Registration Details Admin page
1510
-     *
1511
-     * @access protected
1512
-     * @return void
1513
-     * @throws DomainException
1514
-     * @throws EE_Error
1515
-     * @throws InvalidArgumentException
1516
-     * @throws InvalidDataTypeException
1517
-     * @throws InvalidInterfaceException
1518
-     * @throws EntityNotFoundException
1519
-     */
1520
-    protected function _registration_details()
1521
-    {
1522
-        $this->_template_args = array();
1523
-        $this->_set_registration_object();
1524
-        if (is_object($this->_registration)) {
1525
-            $transaction                                   = $this->_registration->transaction()
1526
-                ? $this->_registration->transaction()
1527
-                : EE_Transaction::new_instance();
1528
-            $this->_session                                = $transaction->session_data();
1529
-            $event_id                                      = $this->_registration->event_ID();
1530
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1531
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1532
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1533
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1534
-            $this->_template_args['grand_total']           = $transaction->total();
1535
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1536
-            // link back to overview
1537
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1538
-            $this->_template_args['registration']                = $this->_registration;
1539
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1540
-                array(
1541
-                    'action'   => 'default',
1542
-                    'event_id' => $event_id,
1543
-                ),
1544
-                REG_ADMIN_URL
1545
-            );
1546
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1547
-                array(
1548
-                    'action' => 'default',
1549
-                    'EVT_ID' => $event_id,
1550
-                    'page'   => 'espresso_transactions',
1551
-                ),
1552
-                admin_url('admin.php')
1553
-            );
1554
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1555
-                array(
1556
-                    'page'   => 'espresso_events',
1557
-                    'action' => 'edit',
1558
-                    'post'   => $event_id,
1559
-                ),
1560
-                admin_url('admin.php')
1561
-            );
1562
-            //next and previous links
1563
-            $next_reg                                      = $this->_registration->next(
1564
-                null,
1565
-                array(),
1566
-                'REG_ID'
1567
-            );
1568
-            $this->_template_args['next_registration']     = $next_reg
1569
-                ? $this->_next_link(
1570
-                    EE_Admin_Page::add_query_args_and_nonce(
1571
-                        array(
1572
-                            'action'  => 'view_registration',
1573
-                            '_REG_ID' => $next_reg['REG_ID'],
1574
-                        ),
1575
-                        REG_ADMIN_URL
1576
-                    ),
1577
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1578
-                )
1579
-                : '';
1580
-            $previous_reg                                  = $this->_registration->previous(
1581
-                null,
1582
-                array(),
1583
-                'REG_ID'
1584
-            );
1585
-            $this->_template_args['previous_registration'] = $previous_reg
1586
-                ? $this->_previous_link(
1587
-                    EE_Admin_Page::add_query_args_and_nonce(
1588
-                        array(
1589
-                            'action'  => 'view_registration',
1590
-                            '_REG_ID' => $previous_reg['REG_ID'],
1591
-                        ),
1592
-                        REG_ADMIN_URL
1593
-                    ),
1594
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1595
-                )
1596
-                : '';
1597
-            // grab header
1598
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1599
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1600
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1601
-                $template_path,
1602
-                $this->_template_args,
1603
-                true
1604
-            );
1605
-        } else {
1606
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1607
-        }
1608
-        // the details template wrapper
1609
-        $this->display_admin_page_with_sidebar();
1610
-    }
1611
-
1612
-
1613
-    protected function _registration_details_metaboxes()
1614
-    {
1615
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1616
-        $this->_set_registration_object();
1617
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1618
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1619
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1620
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1621
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1622
-        if ($attendee instanceof EE_Attendee
1623
-            && EE_Registry::instance()->CAP->current_user_can(
1624
-                'ee_edit_registration',
1625
-                'edit-reg-questions-mbox',
1626
-                $this->_registration->ID()
1627
-            )
1628
-        ) {
1629
-            add_meta_box(
1630
-                'edit-reg-questions-mbox',
1631
-                esc_html__('Registration Form Answers', 'event_espresso'),
1632
-                array($this, '_reg_questions_meta_box'),
1633
-                $this->wp_page_slug,
1634
-                'normal',
1635
-                'high'
1636
-            );
1637
-        }
1638
-        add_meta_box(
1639
-            'edit-reg-registrant-mbox',
1640
-            esc_html__('Contact Details', 'event_espresso'),
1641
-            array($this, '_reg_registrant_side_meta_box'),
1642
-            $this->wp_page_slug,
1643
-            'side',
1644
-            'high'
1645
-        );
1646
-        if ($this->_registration->group_size() > 1) {
1647
-            add_meta_box(
1648
-                'edit-reg-attendees-mbox',
1649
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1650
-                array($this, '_reg_attendees_meta_box'),
1651
-                $this->wp_page_slug,
1652
-                'normal',
1653
-                'high'
1654
-            );
1655
-        }
1656
-    }
1657
-
1658
-
1659
-    /**
1660
-     * set_reg_status_buttons_metabox
1661
-     *
1662
-     * @access protected
1663
-     * @return string
1664
-     * @throws \EE_Error
1665
-     */
1666
-    public function set_reg_status_buttons_metabox()
1667
-    {
1668
-        $this->_set_registration_object();
1669
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1670
-        echo $change_reg_status_form->form_open(
1671
-            self::add_query_args_and_nonce(
1672
-                array(
1673
-                    'action' => 'change_reg_status',
1674
-                ),
1675
-                REG_ADMIN_URL
1676
-            )
1677
-        );
1678
-        echo $change_reg_status_form->get_html();
1679
-        echo $change_reg_status_form->form_close();
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     * @return EE_Form_Section_Proper
1685
-     * @throws EE_Error
1686
-     * @throws InvalidArgumentException
1687
-     * @throws InvalidDataTypeException
1688
-     * @throws InvalidInterfaceException
1689
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1690
-     */
1691
-    protected function _generate_reg_status_change_form()
1692
-    {
1693
-        return new EE_Form_Section_Proper(array(
1694
-            'name'            => 'reg_status_change_form',
1695
-            'html_id'         => 'reg-status-change-form',
1696
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1697
-            'subsections'     => array(
1698
-                'return'             => new EE_Hidden_Input(array(
1699
-                    'name'    => 'return',
1700
-                    'default' => 'view_registration',
1701
-                )),
1702
-                'REG_ID'             => new EE_Hidden_Input(array(
1703
-                    'name'    => 'REG_ID',
1704
-                    'default' => $this->_registration->ID(),
1705
-                )),
1706
-                'current_status'     => new EE_Form_Section_HTML(
1707
-                    EEH_HTML::tr(
1708
-                        EEH_HTML::th(
1709
-                            EEH_HTML::label(
1710
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1711
-                                )
1712
-                            )
1713
-                        )
1714
-                        . EEH_HTML::td(
1715
-                            EEH_HTML::strong(
1716
-                                $this->_registration->pretty_status(),
1717
-                                '',
1718
-                                'status-' . $this->_registration->status_ID(),
1719
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1720
-                            )
1721
-                        )
1722
-                    )
1723
-                ),
1724
-                'reg_status'         => new EE_Select_Input(
1725
-                    $this->_get_reg_statuses(),
1726
-                    array(
1727
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1728
-                        'default'         => $this->_registration->status_ID(),
1729
-                    )
1730
-                ),
1731
-                'send_notifications' => new EE_Yes_No_Input(
1732
-                    array(
1733
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1734
-                        'default'         => false,
1735
-                        'html_help_text'  => esc_html__(
1736
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1737
-                            'event_espresso'
1738
-                        ),
1739
-                    )
1740
-                ),
1741
-                'submit'             => new EE_Submit_Input(
1742
-                    array(
1743
-                        'html_class'      => 'button-primary',
1744
-                        'html_label_text' => '&nbsp;',
1745
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1746
-                    )
1747
-                ),
1748
-            ),
1749
-        ));
1750
-    }
1751
-
1752
-
1753
-    /**
1754
-     * Returns an array of all the buttons for the various statuses and switch status actions
1755
-     *
1756
-     * @return array
1757
-     * @throws EE_Error
1758
-     * @throws InvalidArgumentException
1759
-     * @throws InvalidDataTypeException
1760
-     * @throws InvalidInterfaceException
1761
-     * @throws EntityNotFoundException
1762
-     */
1763
-    protected function _get_reg_statuses()
1764
-    {
1765
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1766
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1767
-        // get current reg status
1768
-        $current_status = $this->_registration->status_ID();
1769
-        // is registration for free event? This will determine whether to display the pending payment option
1770
-        if (
1771
-            $current_status !== EEM_Registration::status_id_pending_payment
1772
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1773
-        ) {
1774
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1775
-        }
1776
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1777
-    }
1778
-
1779
-
1780
-    /**
1781
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1782
-     *
1783
-     * @param bool $status REG status given for changing registrations to.
1784
-     * @param bool $notify Whether to send messages notifications or not.
1785
-     * @return array (array with reg_id(s) updated and whether update was successful.
1786
-     * @throws EE_Error
1787
-     * @throws InvalidArgumentException
1788
-     * @throws InvalidDataTypeException
1789
-     * @throws InvalidInterfaceException
1790
-     * @throws ReflectionException
1791
-     * @throws RuntimeException
1792
-     * @throws EntityNotFoundException
1793
-     */
1794
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1795
-    {
1796
-        if (isset($this->_req_data['reg_status_change_form'])) {
1797
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1798
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1799
-                : array();
1800
-        } else {
1801
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1802
-                ? (array)$this->_req_data['_REG_ID']
1803
-                : array();
1804
-        }
1805
-        // sanitize $REG_IDs
1806
-        $REG_IDs = array_map('absint', $REG_IDs);
1807
-        // and remove empty entries
1808
-        $REG_IDs = array_filter($REG_IDs);
1809
-
1810
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1811
-
1812
-        /**
1813
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1814
-         * Currently this value is used downstream by the _process_resend_registration method.
1815
-         *
1816
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1817
-         * @param bool                     $status           The status registrations were changed to.
1818
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1819
-         * @param Registrations_Admin_Page $admin_page_object
1820
-         */
1821
-        $this->_req_data['_REG_ID'] = apply_filters(
1822
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1823
-            $result['REG_ID'],
1824
-            $status,
1825
-            $result['success'],
1826
-            $this
1827
-        );
1828
-
1829
-        //notify?
1830
-        if ($notify
1831
-            && $result['success']
1832
-            && ! empty($this->_req_data['_REG_ID'])
1833
-            && EE_Registry::instance()->CAP->current_user_can(
1834
-                'ee_send_message',
1835
-                'espresso_registrations_resend_registration'
1836
-            )
1837
-        ) {
1838
-            $this->_process_resend_registration();
1839
-        }
1840
-        return $result;
1841
-    }
1842
-
1843
-
1844
-    /**
1845
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1846
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1847
-     *
1848
-     * @param array  $REG_IDs
1849
-     * @param string $status
1850
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1851
-     *                        slug sent with setting the registration status.
1852
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1853
-     * @throws EE_Error
1854
-     * @throws InvalidArgumentException
1855
-     * @throws InvalidDataTypeException
1856
-     * @throws InvalidInterfaceException
1857
-     * @throws ReflectionException
1858
-     * @throws RuntimeException
1859
-     * @throws EntityNotFoundException
1860
-     */
1861
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1862
-    {
1863
-        $success = false;
1864
-        // typecast $REG_IDs
1865
-        $REG_IDs = (array)$REG_IDs;
1866
-        if ( ! empty($REG_IDs)) {
1867
-            $success = true;
1868
-            // set default status if none is passed
1869
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1870
-            $status_context = $notify
1871
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1872
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1873
-            //loop through REG_ID's and change status
1874
-            foreach ($REG_IDs as $REG_ID) {
1875
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1876
-                if ($registration instanceof EE_Registration) {
1877
-                    $registration->set_status(
1878
-                        $status,
1879
-                        false,
1880
-                        new Context(
1881
-                            $status_context,
1882
-                            esc_html__(
1883
-                                'Manually triggered status change on a Registration Admin Page route.',
1884
-                                'event_espresso'
1885
-                            )
1886
-                        )
1887
-                    );
1888
-                    $result = $registration->save();
1889
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1890
-                    $success = $result !== false ? $success : false;
1891
-                }
1892
-            }
1893
-        }
1894
-
1895
-        //return $success and processed registrations
1896
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     * Common logic for setting up success message and redirecting to appropriate route
1902
-     *
1903
-     * @param  string $STS_ID status id for the registration changed to
1904
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1905
-     * @return void
1906
-     * @throws EE_Error
1907
-     */
1908
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1909
-    {
1910
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1911
-            : array('success' => false);
1912
-        $success = isset($result['success']) && $result['success'];
1913
-        //setup success message
1914
-        if ($success) {
1915
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1916
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1917
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1918
-            } else {
1919
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1920
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1921
-            }
1922
-            EE_Error::add_success($msg);
1923
-        } else {
1924
-            EE_Error::add_error(
1925
-                esc_html__(
1926
-                    'Something went wrong, and the status was not changed',
1927
-                    'event_espresso'
1928
-                ), __FILE__, __LINE__, __FUNCTION__
1929
-            );
1930
-        }
1931
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1932
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1933
-        } else {
1934
-            $route = array('action' => 'default');
1935
-        }
1936
-        //unset nonces
1937
-        foreach ($this->_req_data as $ref => $value) {
1938
-            if (strpos($ref, 'nonce') !== false) {
1939
-                unset($this->_req_data[$ref]);
1940
-                continue;
1941
-            }
1942
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1943
-            $this->_req_data[$ref] = $value;
1944
-        }
1945
-        //merge request vars so that the reloaded list table contains any existing filter query params
1946
-        $route = array_merge($this->_req_data, $route);
1947
-        $this->_redirect_after_action($success, '', '', $route, true);
1948
-    }
1949
-
1950
-
1951
-    /**
1952
-     * incoming reg status change from reg details page.
1953
-     *
1954
-     * @return void
1955
-     */
1956
-    protected function _change_reg_status()
1957
-    {
1958
-        $this->_req_data['return'] = 'view_registration';
1959
-        //set notify based on whether the send notifications toggle is set or not
1960
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1961
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1962
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1963
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1964
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1965
-            case EEM_Registration::status_id_approved :
1966
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1967
-                $this->approve_registration($notify);
1968
-                break;
1969
-            case EEM_Registration::status_id_pending_payment :
1970
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1971
-                $this->pending_registration($notify);
1972
-                break;
1973
-            case EEM_Registration::status_id_not_approved :
1974
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1975
-                $this->not_approve_registration($notify);
1976
-                break;
1977
-            case EEM_Registration::status_id_declined :
1978
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1979
-                $this->decline_registration($notify);
1980
-                break;
1981
-            case EEM_Registration::status_id_cancelled :
1982
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1983
-                $this->cancel_registration($notify);
1984
-                break;
1985
-            case EEM_Registration::status_id_wait_list :
1986
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1987
-                $this->wait_list_registration($notify);
1988
-                break;
1989
-            case EEM_Registration::status_id_incomplete :
1990
-            default :
1991
-                $result['success'] = false;
1992
-                unset($this->_req_data['return']);
1993
-                $this->_reg_status_change_return('', false);
1994
-                break;
1995
-        }
1996
-    }
1997
-
1998
-
1999
-    /**
2000
-     * Callback for bulk action routes.
2001
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2002
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
2003
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2004
-     * when an action is happening on just a single registration).
2005
-     * @param      $action
2006
-     * @param bool $notify
2007
-     */
2008
-    protected function bulk_action_on_registrations($action, $notify = false) {
2009
-        do_action(
2010
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2011
-            $this,
2012
-            $action,
2013
-            $notify
2014
-        );
2015
-        $method = $action . '_registration';
2016
-        if (method_exists($this, $method)) {
2017
-            $this->$method($notify);
2018
-        }
2019
-    }
2020
-
2021
-
2022
-    /**
2023
-     * approve_registration
2024
-     *
2025
-     * @access protected
2026
-     * @param bool $notify whether or not to notify the registrant about their approval.
2027
-     * @return void
2028
-     */
2029
-    protected function approve_registration($notify = false)
2030
-    {
2031
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2032
-    }
2033
-
2034
-
2035
-    /**
2036
-     *        decline_registration
2037
-     *
2038
-     * @access protected
2039
-     * @param bool $notify whether or not to notify the registrant about their status change.
2040
-     * @return void
2041
-     */
2042
-    protected function decline_registration($notify = false)
2043
-    {
2044
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2045
-    }
2046
-
2047
-
2048
-    /**
2049
-     *        cancel_registration
2050
-     *
2051
-     * @access protected
2052
-     * @param bool $notify whether or not to notify the registrant about their status change.
2053
-     * @return void
2054
-     */
2055
-    protected function cancel_registration($notify = false)
2056
-    {
2057
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2058
-    }
2059
-
2060
-
2061
-    /**
2062
-     *        not_approve_registration
2063
-     *
2064
-     * @access protected
2065
-     * @param bool $notify whether or not to notify the registrant about their status change.
2066
-     * @return void
2067
-     */
2068
-    protected function not_approve_registration($notify = false)
2069
-    {
2070
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2071
-    }
2072
-
2073
-
2074
-    /**
2075
-     *        decline_registration
2076
-     *
2077
-     * @access protected
2078
-     * @param bool $notify whether or not to notify the registrant about their status change.
2079
-     * @return void
2080
-     */
2081
-    protected function pending_registration($notify = false)
2082
-    {
2083
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2084
-    }
2085
-
2086
-
2087
-    /**
2088
-     * waitlist_registration
2089
-     *
2090
-     * @access protected
2091
-     * @param bool $notify whether or not to notify the registrant about their status change.
2092
-     * @return void
2093
-     */
2094
-    protected function wait_list_registration($notify = false)
2095
-    {
2096
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2097
-    }
2098
-
2099
-
2100
-    /**
2101
-     *        generates HTML for the Registration main meta box
2102
-     *
2103
-     * @access public
2104
-     * @return void
2105
-     * @throws DomainException
2106
-     * @throws EE_Error
2107
-     * @throws InvalidArgumentException
2108
-     * @throws InvalidDataTypeException
2109
-     * @throws InvalidInterfaceException
2110
-     * @throws ReflectionException
2111
-     * @throws EntityNotFoundException
2112
-     */
2113
-    public function _reg_details_meta_box()
2114
-    {
2115
-        EEH_Autoloader::register_line_item_display_autoloaders();
2116
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2117
-        EE_Registry::instance()->load_helper('Line_Item');
2118
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2119
-            : EE_Transaction::new_instance();
2120
-        $this->_session = $transaction->session_data();
2121
-        $filters        = new EE_Line_Item_Filter_Collection();
2122
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2123
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2124
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2125
-            $transaction->total_line_item());
2126
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2127
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2128
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2129
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2130
-            $filtered_line_item_tree,
2131
-            array('EE_Registration' => $this->_registration)
2132
-        );
2133
-        $attendee                                = $this->_registration->attendee();
2134
-        if (EE_Registry::instance()->CAP->current_user_can(
2135
-            'ee_read_transaction',
2136
-            'espresso_transactions_view_transaction'
2137
-        )) {
2138
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2139
-                EE_Admin_Page::add_query_args_and_nonce(
2140
-                    array(
2141
-                        'action' => 'view_transaction',
2142
-                        'TXN_ID' => $transaction->ID(),
2143
-                    ),
2144
-                    TXN_ADMIN_URL
2145
-                ),
2146
-                esc_html__(' View Transaction', 'event_espresso'),
2147
-                'button secondary-button right',
2148
-                'dashicons dashicons-cart'
2149
-            );
2150
-        } else {
2151
-            $this->_template_args['view_transaction_button'] = '';
2152
-        }
2153
-        if ($attendee instanceof EE_Attendee
2154
-            && EE_Registry::instance()->CAP->current_user_can(
2155
-                'ee_send_message',
2156
-                'espresso_registrations_resend_registration'
2157
-            )
2158
-        ) {
2159
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2160
-                EE_Admin_Page::add_query_args_and_nonce(
2161
-                    array(
2162
-                        'action'      => 'resend_registration',
2163
-                        '_REG_ID'     => $this->_registration->ID(),
2164
-                        'redirect_to' => 'view_registration',
2165
-                    ),
2166
-                    REG_ADMIN_URL
2167
-                ),
2168
-                esc_html__(' Resend Registration', 'event_espresso'),
2169
-                'button secondary-button right',
2170
-                'dashicons dashicons-email-alt'
2171
-            );
2172
-        } else {
2173
-            $this->_template_args['resend_registration_button'] = '';
2174
-        }
2175
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2176
-        $payment                               = $transaction->get_first_related('Payment');
2177
-        $payment                               = ! $payment instanceof EE_Payment
2178
-            ? EE_Payment::new_instance()
2179
-            : $payment;
2180
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2181
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2182
-            ? EE_Payment_Method::new_instance()
2183
-            : $payment_method;
2184
-        $reg_details                           = array(
2185
-            'payment_method'       => $payment_method->name(),
2186
-            'response_msg'         => $payment->gateway_response(),
2187
-            'registration_id'      => $this->_registration->get('REG_code'),
2188
-            'registration_session' => $this->_registration->session_ID(),
2189
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2190
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2191
-        );
2192
-        if (isset($reg_details['registration_id'])) {
2193
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2194
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2195
-                'Registration ID',
2196
-                'event_espresso'
2197
-            );
2198
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2199
-        }
2200
-        if (isset($reg_details['payment_method'])) {
2201
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2202
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2203
-                'Most Recent Payment Method',
2204
-                'event_espresso'
2205
-            );
2206
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2207
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2208
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2209
-                'Payment method response',
2210
-                'event_espresso'
2211
-            );
2212
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2213
-        }
2214
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2215
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2216
-            'Registration Session',
2217
-            'event_espresso'
2218
-        );
2219
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2220
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2221
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2222
-            'Registration placed from IP',
2223
-            'event_espresso'
2224
-        );
2225
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2226
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2227
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2228
-            'event_espresso');
2229
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2230
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2231
-            array(
2232
-                'action'   => 'default',
2233
-                'event_id' => $this->_registration->event_ID(),
2234
-            ),
2235
-            REG_ADMIN_URL
2236
-        );
2237
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2238
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2239
-        $template_path                                                        =
2240
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2241
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2242
-    }
2243
-
2244
-
2245
-    /**
2246
-     * generates HTML for the Registration Questions meta box.
2247
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2248
-     * otherwise uses new forms system
2249
-     *
2250
-     * @access public
2251
-     * @return void
2252
-     * @throws DomainException
2253
-     * @throws EE_Error
2254
-     */
2255
-    public function _reg_questions_meta_box()
2256
-    {
2257
-        //allow someone to override this method entirely
2258
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2259
-            $this->_registration)) {
2260
-            $form                                              = $this->_get_reg_custom_questions_form(
2261
-                $this->_registration->ID()
2262
-            );
2263
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2264
-                ? $form->get_html_and_js()
2265
-                : '';
2266
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2267
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2268
-            $template_path                                     =
2269
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2270
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2271
-        }
2272
-    }
2273
-
2274
-
2275
-    /**
2276
-     * form_before_question_group
2277
-     *
2278
-     * @deprecated    as of 4.8.32.rc.000
2279
-     * @access        public
2280
-     * @param        string $output
2281
-     * @return        string
2282
-     */
2283
-    public function form_before_question_group($output)
2284
-    {
2285
-        EE_Error::doing_it_wrong(
2286
-            __CLASS__ . '::' . __FUNCTION__,
2287
-            esc_html__(
2288
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2289
-                'event_espresso'
2290
-            ),
2291
-            '4.8.32.rc.000'
2292
-        );
2293
-        return '
1259
+		if (! empty($registration_status)) {
1260
+			$where['STS_ID'] = $registration_status;
1261
+		} else {
1262
+			//make sure we exclude incomplete registrations, but only if not trashed.
1263
+			if ($view === 'trash') {
1264
+				$where['REG_deleted'] = true;
1265
+			} elseif ($view === 'incomplete') {
1266
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1267
+			} else {
1268
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1269
+			}
1270
+		}
1271
+		return $where;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1277
+	 *
1278
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1279
+	 * @return array
1280
+	 * @throws EE_Error
1281
+	 * @throws InvalidArgumentException
1282
+	 * @throws InvalidDataTypeException
1283
+	 * @throws InvalidInterfaceException
1284
+	 */
1285
+	protected function _add_date_to_where_conditions(array $request)
1286
+	{
1287
+		$where = array();
1288
+		$view = EEH_Array::is_set($request, 'status', '');
1289
+		$month_range             = ! empty($request['month_range'])
1290
+			? sanitize_text_field($request['month_range'])
1291
+			: '';
1292
+		$retrieve_for_today      = $view === 'today';
1293
+		$retrieve_for_this_month = $view === 'month';
1294
+
1295
+		if ($retrieve_for_today) {
1296
+			$now               = date('Y-m-d', current_time('timestamp'));
1297
+			$where['REG_date'] = array(
1298
+				'BETWEEN',
1299
+				array(
1300
+					EEM_Registration::instance()->convert_datetime_for_query(
1301
+						'REG_date',
1302
+						$now . ' 00:00:00',
1303
+						'Y-m-d H:i:s'
1304
+					),
1305
+					EEM_Registration::instance()->convert_datetime_for_query(
1306
+						'REG_date',
1307
+						$now . ' 23:59:59',
1308
+						'Y-m-d H:i:s'
1309
+					),
1310
+				),
1311
+			);
1312
+		} elseif ($retrieve_for_this_month) {
1313
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1314
+			$days_this_month        = date('t', current_time('timestamp'));
1315
+			$where['REG_date']      = array(
1316
+				'BETWEEN',
1317
+				array(
1318
+					EEM_Registration::instance()->convert_datetime_for_query(
1319
+						'REG_date',
1320
+						$current_year_and_month . '-01 00:00:00',
1321
+						'Y-m-d H:i:s'
1322
+					),
1323
+					EEM_Registration::instance()->convert_datetime_for_query(
1324
+						'REG_date',
1325
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1326
+						'Y-m-d H:i:s'
1327
+					),
1328
+				),
1329
+			);
1330
+		} elseif ($month_range) {
1331
+			$pieces          = explode(' ', $month_range, 3);
1332
+			$month_requested = ! empty($pieces[0])
1333
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1334
+				: '';
1335
+			$year_requested  = ! empty($pieces[1])
1336
+				? $pieces[1]
1337
+				: '';
1338
+			//if there is not a month or year then we can't go further
1339
+			if ($month_requested && $year_requested) {
1340
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1341
+				$where['REG_date'] = array(
1342
+					'BETWEEN',
1343
+					array(
1344
+						EEM_Registration::instance()->convert_datetime_for_query(
1345
+							'REG_date',
1346
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1347
+							'Y-m-d H:i:s'
1348
+						),
1349
+						EEM_Registration::instance()->convert_datetime_for_query(
1350
+							'REG_date',
1351
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1352
+							'Y-m-d H:i:s'
1353
+						),
1354
+					),
1355
+				);
1356
+			}
1357
+		}
1358
+		return $where;
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * Adds any provided search restraints to the where conditions for the registrations query
1364
+	 *
1365
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1366
+	 * @return array
1367
+	 */
1368
+	protected function _add_search_to_where_conditions(array $request)
1369
+	{
1370
+		$where = array();
1371
+		if (! empty($request['s'])) {
1372
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1373
+			$where['OR*search_conditions'] = array(
1374
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1375
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1376
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1377
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1378
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1379
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1380
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1381
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1382
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1383
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1384
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1385
+				'REG_final_price'                         => array('LIKE', $search_string),
1386
+				'REG_code'                                => array('LIKE', $search_string),
1387
+				'REG_count'                               => array('LIKE', $search_string),
1388
+				'REG_group_size'                          => array('LIKE', $search_string),
1389
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1390
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1391
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1392
+			);
1393
+		}
1394
+		return $where;
1395
+	}
1396
+
1397
+
1398
+	/**
1399
+	 * Sets up the where conditions for the registrations query.
1400
+	 *
1401
+	 * @param array $request
1402
+	 * @return array
1403
+	 * @throws EE_Error
1404
+	 */
1405
+	protected function _get_where_conditions_for_registrations_query($request)
1406
+	{
1407
+		return apply_filters(
1408
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1409
+			array_merge(
1410
+				$this->_add_event_id_to_where_conditions($request),
1411
+				$this->_add_category_id_to_where_conditions($request),
1412
+				$this->_add_datetime_id_to_where_conditions($request),
1413
+				$this->_add_registration_status_to_where_conditions($request),
1414
+				$this->_add_date_to_where_conditions($request),
1415
+				$this->_add_search_to_where_conditions($request)
1416
+			),
1417
+			$request
1418
+		);
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * Sets up the orderby for the registrations query.
1424
+	 *
1425
+	 * @return array
1426
+	 */
1427
+	protected function _get_orderby_for_registrations_query()
1428
+	{
1429
+		$orderby_field = ! empty($this->_req_data['orderby'])
1430
+			? sanitize_text_field($this->_req_data['orderby'])
1431
+			: '';
1432
+		switch ($orderby_field) {
1433
+			case '_REG_ID':
1434
+				$orderby_field = 'REG_ID';
1435
+				break;
1436
+			case '_Reg_status':
1437
+				$orderby_field = 'STS_ID';
1438
+				break;
1439
+			case 'ATT_fname':
1440
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1441
+				break;
1442
+			case 'ATT_lname':
1443
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1444
+				break;
1445
+			case 'event_name':
1446
+				$orderby_field = 'Event.EVT_name';
1447
+				break;
1448
+			case 'DTT_EVT_start':
1449
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1450
+				break;
1451
+			default: //'REG_date'
1452
+				$orderby_field = 'REG_date';
1453
+		}
1454
+
1455
+		//order
1456
+		$order = ! empty($this->_req_data['order'])
1457
+			? sanitize_text_field($this->_req_data['order'])
1458
+			: 'DESC';
1459
+
1460
+		//mutate orderby_field
1461
+		$orderby_field = array_combine(
1462
+			(array) $orderby_field,
1463
+			array_fill(0, count($orderby_field), $order)
1464
+		);
1465
+		//because there are many registrations with the same date, define
1466
+		//a secondary way to order them, otherwise MySQL seems to be a bit random
1467
+		if (empty($order['REG_ID'])) {
1468
+			$orderby_field['REG_ID'] = $order;
1469
+		}
1470
+		return array('order_by' => $orderby_field);
1471
+	}
1472
+
1473
+
1474
+	/**
1475
+	 * Sets up the limit for the registrations query.
1476
+	 *
1477
+	 * @param $per_page
1478
+	 * @return array
1479
+	 */
1480
+	protected function _get_limit($per_page)
1481
+	{
1482
+		$current_page = ! empty($this->_req_data['paged'])
1483
+			? absint($this->_req_data['paged'])
1484
+			: 1;
1485
+		$per_page     = ! empty($this->_req_data['perpage'])
1486
+			? $this->_req_data['perpage']
1487
+			: $per_page;
1488
+
1489
+		//-1 means return all results so get out if that's set.
1490
+		if ((int)$per_page === -1) {
1491
+			return array();
1492
+		}
1493
+		$per_page = absint($per_page);
1494
+		$offset   = ($current_page - 1) * $per_page;
1495
+		return array('limit' => array($offset, $per_page));
1496
+	}
1497
+
1498
+
1499
+	public function get_registration_status_array()
1500
+	{
1501
+		return self::$_reg_status;
1502
+	}
1503
+
1504
+
1505
+
1506
+
1507
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1508
+	/**
1509
+	 *        generates HTML for the View Registration Details Admin page
1510
+	 *
1511
+	 * @access protected
1512
+	 * @return void
1513
+	 * @throws DomainException
1514
+	 * @throws EE_Error
1515
+	 * @throws InvalidArgumentException
1516
+	 * @throws InvalidDataTypeException
1517
+	 * @throws InvalidInterfaceException
1518
+	 * @throws EntityNotFoundException
1519
+	 */
1520
+	protected function _registration_details()
1521
+	{
1522
+		$this->_template_args = array();
1523
+		$this->_set_registration_object();
1524
+		if (is_object($this->_registration)) {
1525
+			$transaction                                   = $this->_registration->transaction()
1526
+				? $this->_registration->transaction()
1527
+				: EE_Transaction::new_instance();
1528
+			$this->_session                                = $transaction->session_data();
1529
+			$event_id                                      = $this->_registration->event_ID();
1530
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1531
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1532
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1533
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1534
+			$this->_template_args['grand_total']           = $transaction->total();
1535
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1536
+			// link back to overview
1537
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1538
+			$this->_template_args['registration']                = $this->_registration;
1539
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1540
+				array(
1541
+					'action'   => 'default',
1542
+					'event_id' => $event_id,
1543
+				),
1544
+				REG_ADMIN_URL
1545
+			);
1546
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1547
+				array(
1548
+					'action' => 'default',
1549
+					'EVT_ID' => $event_id,
1550
+					'page'   => 'espresso_transactions',
1551
+				),
1552
+				admin_url('admin.php')
1553
+			);
1554
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1555
+				array(
1556
+					'page'   => 'espresso_events',
1557
+					'action' => 'edit',
1558
+					'post'   => $event_id,
1559
+				),
1560
+				admin_url('admin.php')
1561
+			);
1562
+			//next and previous links
1563
+			$next_reg                                      = $this->_registration->next(
1564
+				null,
1565
+				array(),
1566
+				'REG_ID'
1567
+			);
1568
+			$this->_template_args['next_registration']     = $next_reg
1569
+				? $this->_next_link(
1570
+					EE_Admin_Page::add_query_args_and_nonce(
1571
+						array(
1572
+							'action'  => 'view_registration',
1573
+							'_REG_ID' => $next_reg['REG_ID'],
1574
+						),
1575
+						REG_ADMIN_URL
1576
+					),
1577
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1578
+				)
1579
+				: '';
1580
+			$previous_reg                                  = $this->_registration->previous(
1581
+				null,
1582
+				array(),
1583
+				'REG_ID'
1584
+			);
1585
+			$this->_template_args['previous_registration'] = $previous_reg
1586
+				? $this->_previous_link(
1587
+					EE_Admin_Page::add_query_args_and_nonce(
1588
+						array(
1589
+							'action'  => 'view_registration',
1590
+							'_REG_ID' => $previous_reg['REG_ID'],
1591
+						),
1592
+						REG_ADMIN_URL
1593
+					),
1594
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1595
+				)
1596
+				: '';
1597
+			// grab header
1598
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1599
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1600
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1601
+				$template_path,
1602
+				$this->_template_args,
1603
+				true
1604
+			);
1605
+		} else {
1606
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1607
+		}
1608
+		// the details template wrapper
1609
+		$this->display_admin_page_with_sidebar();
1610
+	}
1611
+
1612
+
1613
+	protected function _registration_details_metaboxes()
1614
+	{
1615
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1616
+		$this->_set_registration_object();
1617
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1618
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1619
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1620
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1621
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1622
+		if ($attendee instanceof EE_Attendee
1623
+			&& EE_Registry::instance()->CAP->current_user_can(
1624
+				'ee_edit_registration',
1625
+				'edit-reg-questions-mbox',
1626
+				$this->_registration->ID()
1627
+			)
1628
+		) {
1629
+			add_meta_box(
1630
+				'edit-reg-questions-mbox',
1631
+				esc_html__('Registration Form Answers', 'event_espresso'),
1632
+				array($this, '_reg_questions_meta_box'),
1633
+				$this->wp_page_slug,
1634
+				'normal',
1635
+				'high'
1636
+			);
1637
+		}
1638
+		add_meta_box(
1639
+			'edit-reg-registrant-mbox',
1640
+			esc_html__('Contact Details', 'event_espresso'),
1641
+			array($this, '_reg_registrant_side_meta_box'),
1642
+			$this->wp_page_slug,
1643
+			'side',
1644
+			'high'
1645
+		);
1646
+		if ($this->_registration->group_size() > 1) {
1647
+			add_meta_box(
1648
+				'edit-reg-attendees-mbox',
1649
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1650
+				array($this, '_reg_attendees_meta_box'),
1651
+				$this->wp_page_slug,
1652
+				'normal',
1653
+				'high'
1654
+			);
1655
+		}
1656
+	}
1657
+
1658
+
1659
+	/**
1660
+	 * set_reg_status_buttons_metabox
1661
+	 *
1662
+	 * @access protected
1663
+	 * @return string
1664
+	 * @throws \EE_Error
1665
+	 */
1666
+	public function set_reg_status_buttons_metabox()
1667
+	{
1668
+		$this->_set_registration_object();
1669
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1670
+		echo $change_reg_status_form->form_open(
1671
+			self::add_query_args_and_nonce(
1672
+				array(
1673
+					'action' => 'change_reg_status',
1674
+				),
1675
+				REG_ADMIN_URL
1676
+			)
1677
+		);
1678
+		echo $change_reg_status_form->get_html();
1679
+		echo $change_reg_status_form->form_close();
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 * @return EE_Form_Section_Proper
1685
+	 * @throws EE_Error
1686
+	 * @throws InvalidArgumentException
1687
+	 * @throws InvalidDataTypeException
1688
+	 * @throws InvalidInterfaceException
1689
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1690
+	 */
1691
+	protected function _generate_reg_status_change_form()
1692
+	{
1693
+		return new EE_Form_Section_Proper(array(
1694
+			'name'            => 'reg_status_change_form',
1695
+			'html_id'         => 'reg-status-change-form',
1696
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1697
+			'subsections'     => array(
1698
+				'return'             => new EE_Hidden_Input(array(
1699
+					'name'    => 'return',
1700
+					'default' => 'view_registration',
1701
+				)),
1702
+				'REG_ID'             => new EE_Hidden_Input(array(
1703
+					'name'    => 'REG_ID',
1704
+					'default' => $this->_registration->ID(),
1705
+				)),
1706
+				'current_status'     => new EE_Form_Section_HTML(
1707
+					EEH_HTML::tr(
1708
+						EEH_HTML::th(
1709
+							EEH_HTML::label(
1710
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1711
+								)
1712
+							)
1713
+						)
1714
+						. EEH_HTML::td(
1715
+							EEH_HTML::strong(
1716
+								$this->_registration->pretty_status(),
1717
+								'',
1718
+								'status-' . $this->_registration->status_ID(),
1719
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1720
+							)
1721
+						)
1722
+					)
1723
+				),
1724
+				'reg_status'         => new EE_Select_Input(
1725
+					$this->_get_reg_statuses(),
1726
+					array(
1727
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1728
+						'default'         => $this->_registration->status_ID(),
1729
+					)
1730
+				),
1731
+				'send_notifications' => new EE_Yes_No_Input(
1732
+					array(
1733
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1734
+						'default'         => false,
1735
+						'html_help_text'  => esc_html__(
1736
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1737
+							'event_espresso'
1738
+						),
1739
+					)
1740
+				),
1741
+				'submit'             => new EE_Submit_Input(
1742
+					array(
1743
+						'html_class'      => 'button-primary',
1744
+						'html_label_text' => '&nbsp;',
1745
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1746
+					)
1747
+				),
1748
+			),
1749
+		));
1750
+	}
1751
+
1752
+
1753
+	/**
1754
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1755
+	 *
1756
+	 * @return array
1757
+	 * @throws EE_Error
1758
+	 * @throws InvalidArgumentException
1759
+	 * @throws InvalidDataTypeException
1760
+	 * @throws InvalidInterfaceException
1761
+	 * @throws EntityNotFoundException
1762
+	 */
1763
+	protected function _get_reg_statuses()
1764
+	{
1765
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1766
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1767
+		// get current reg status
1768
+		$current_status = $this->_registration->status_ID();
1769
+		// is registration for free event? This will determine whether to display the pending payment option
1770
+		if (
1771
+			$current_status !== EEM_Registration::status_id_pending_payment
1772
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1773
+		) {
1774
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1775
+		}
1776
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1777
+	}
1778
+
1779
+
1780
+	/**
1781
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1782
+	 *
1783
+	 * @param bool $status REG status given for changing registrations to.
1784
+	 * @param bool $notify Whether to send messages notifications or not.
1785
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1786
+	 * @throws EE_Error
1787
+	 * @throws InvalidArgumentException
1788
+	 * @throws InvalidDataTypeException
1789
+	 * @throws InvalidInterfaceException
1790
+	 * @throws ReflectionException
1791
+	 * @throws RuntimeException
1792
+	 * @throws EntityNotFoundException
1793
+	 */
1794
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1795
+	{
1796
+		if (isset($this->_req_data['reg_status_change_form'])) {
1797
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1798
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1799
+				: array();
1800
+		} else {
1801
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1802
+				? (array)$this->_req_data['_REG_ID']
1803
+				: array();
1804
+		}
1805
+		// sanitize $REG_IDs
1806
+		$REG_IDs = array_map('absint', $REG_IDs);
1807
+		// and remove empty entries
1808
+		$REG_IDs = array_filter($REG_IDs);
1809
+
1810
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1811
+
1812
+		/**
1813
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1814
+		 * Currently this value is used downstream by the _process_resend_registration method.
1815
+		 *
1816
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1817
+		 * @param bool                     $status           The status registrations were changed to.
1818
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1819
+		 * @param Registrations_Admin_Page $admin_page_object
1820
+		 */
1821
+		$this->_req_data['_REG_ID'] = apply_filters(
1822
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1823
+			$result['REG_ID'],
1824
+			$status,
1825
+			$result['success'],
1826
+			$this
1827
+		);
1828
+
1829
+		//notify?
1830
+		if ($notify
1831
+			&& $result['success']
1832
+			&& ! empty($this->_req_data['_REG_ID'])
1833
+			&& EE_Registry::instance()->CAP->current_user_can(
1834
+				'ee_send_message',
1835
+				'espresso_registrations_resend_registration'
1836
+			)
1837
+		) {
1838
+			$this->_process_resend_registration();
1839
+		}
1840
+		return $result;
1841
+	}
1842
+
1843
+
1844
+	/**
1845
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1846
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1847
+	 *
1848
+	 * @param array  $REG_IDs
1849
+	 * @param string $status
1850
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1851
+	 *                        slug sent with setting the registration status.
1852
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1853
+	 * @throws EE_Error
1854
+	 * @throws InvalidArgumentException
1855
+	 * @throws InvalidDataTypeException
1856
+	 * @throws InvalidInterfaceException
1857
+	 * @throws ReflectionException
1858
+	 * @throws RuntimeException
1859
+	 * @throws EntityNotFoundException
1860
+	 */
1861
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1862
+	{
1863
+		$success = false;
1864
+		// typecast $REG_IDs
1865
+		$REG_IDs = (array)$REG_IDs;
1866
+		if ( ! empty($REG_IDs)) {
1867
+			$success = true;
1868
+			// set default status if none is passed
1869
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1870
+			$status_context = $notify
1871
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1872
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1873
+			//loop through REG_ID's and change status
1874
+			foreach ($REG_IDs as $REG_ID) {
1875
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1876
+				if ($registration instanceof EE_Registration) {
1877
+					$registration->set_status(
1878
+						$status,
1879
+						false,
1880
+						new Context(
1881
+							$status_context,
1882
+							esc_html__(
1883
+								'Manually triggered status change on a Registration Admin Page route.',
1884
+								'event_espresso'
1885
+							)
1886
+						)
1887
+					);
1888
+					$result = $registration->save();
1889
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1890
+					$success = $result !== false ? $success : false;
1891
+				}
1892
+			}
1893
+		}
1894
+
1895
+		//return $success and processed registrations
1896
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 * Common logic for setting up success message and redirecting to appropriate route
1902
+	 *
1903
+	 * @param  string $STS_ID status id for the registration changed to
1904
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1905
+	 * @return void
1906
+	 * @throws EE_Error
1907
+	 */
1908
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1909
+	{
1910
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1911
+			: array('success' => false);
1912
+		$success = isset($result['success']) && $result['success'];
1913
+		//setup success message
1914
+		if ($success) {
1915
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1916
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1917
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1918
+			} else {
1919
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1920
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1921
+			}
1922
+			EE_Error::add_success($msg);
1923
+		} else {
1924
+			EE_Error::add_error(
1925
+				esc_html__(
1926
+					'Something went wrong, and the status was not changed',
1927
+					'event_espresso'
1928
+				), __FILE__, __LINE__, __FUNCTION__
1929
+			);
1930
+		}
1931
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1932
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1933
+		} else {
1934
+			$route = array('action' => 'default');
1935
+		}
1936
+		//unset nonces
1937
+		foreach ($this->_req_data as $ref => $value) {
1938
+			if (strpos($ref, 'nonce') !== false) {
1939
+				unset($this->_req_data[$ref]);
1940
+				continue;
1941
+			}
1942
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1943
+			$this->_req_data[$ref] = $value;
1944
+		}
1945
+		//merge request vars so that the reloaded list table contains any existing filter query params
1946
+		$route = array_merge($this->_req_data, $route);
1947
+		$this->_redirect_after_action($success, '', '', $route, true);
1948
+	}
1949
+
1950
+
1951
+	/**
1952
+	 * incoming reg status change from reg details page.
1953
+	 *
1954
+	 * @return void
1955
+	 */
1956
+	protected function _change_reg_status()
1957
+	{
1958
+		$this->_req_data['return'] = 'view_registration';
1959
+		//set notify based on whether the send notifications toggle is set or not
1960
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1961
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1962
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1963
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1964
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1965
+			case EEM_Registration::status_id_approved :
1966
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1967
+				$this->approve_registration($notify);
1968
+				break;
1969
+			case EEM_Registration::status_id_pending_payment :
1970
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1971
+				$this->pending_registration($notify);
1972
+				break;
1973
+			case EEM_Registration::status_id_not_approved :
1974
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1975
+				$this->not_approve_registration($notify);
1976
+				break;
1977
+			case EEM_Registration::status_id_declined :
1978
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1979
+				$this->decline_registration($notify);
1980
+				break;
1981
+			case EEM_Registration::status_id_cancelled :
1982
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1983
+				$this->cancel_registration($notify);
1984
+				break;
1985
+			case EEM_Registration::status_id_wait_list :
1986
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1987
+				$this->wait_list_registration($notify);
1988
+				break;
1989
+			case EEM_Registration::status_id_incomplete :
1990
+			default :
1991
+				$result['success'] = false;
1992
+				unset($this->_req_data['return']);
1993
+				$this->_reg_status_change_return('', false);
1994
+				break;
1995
+		}
1996
+	}
1997
+
1998
+
1999
+	/**
2000
+	 * Callback for bulk action routes.
2001
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2002
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
2003
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2004
+	 * when an action is happening on just a single registration).
2005
+	 * @param      $action
2006
+	 * @param bool $notify
2007
+	 */
2008
+	protected function bulk_action_on_registrations($action, $notify = false) {
2009
+		do_action(
2010
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2011
+			$this,
2012
+			$action,
2013
+			$notify
2014
+		);
2015
+		$method = $action . '_registration';
2016
+		if (method_exists($this, $method)) {
2017
+			$this->$method($notify);
2018
+		}
2019
+	}
2020
+
2021
+
2022
+	/**
2023
+	 * approve_registration
2024
+	 *
2025
+	 * @access protected
2026
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2027
+	 * @return void
2028
+	 */
2029
+	protected function approve_registration($notify = false)
2030
+	{
2031
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2032
+	}
2033
+
2034
+
2035
+	/**
2036
+	 *        decline_registration
2037
+	 *
2038
+	 * @access protected
2039
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2040
+	 * @return void
2041
+	 */
2042
+	protected function decline_registration($notify = false)
2043
+	{
2044
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2045
+	}
2046
+
2047
+
2048
+	/**
2049
+	 *        cancel_registration
2050
+	 *
2051
+	 * @access protected
2052
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2053
+	 * @return void
2054
+	 */
2055
+	protected function cancel_registration($notify = false)
2056
+	{
2057
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2058
+	}
2059
+
2060
+
2061
+	/**
2062
+	 *        not_approve_registration
2063
+	 *
2064
+	 * @access protected
2065
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2066
+	 * @return void
2067
+	 */
2068
+	protected function not_approve_registration($notify = false)
2069
+	{
2070
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2071
+	}
2072
+
2073
+
2074
+	/**
2075
+	 *        decline_registration
2076
+	 *
2077
+	 * @access protected
2078
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2079
+	 * @return void
2080
+	 */
2081
+	protected function pending_registration($notify = false)
2082
+	{
2083
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2084
+	}
2085
+
2086
+
2087
+	/**
2088
+	 * waitlist_registration
2089
+	 *
2090
+	 * @access protected
2091
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2092
+	 * @return void
2093
+	 */
2094
+	protected function wait_list_registration($notify = false)
2095
+	{
2096
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2097
+	}
2098
+
2099
+
2100
+	/**
2101
+	 *        generates HTML for the Registration main meta box
2102
+	 *
2103
+	 * @access public
2104
+	 * @return void
2105
+	 * @throws DomainException
2106
+	 * @throws EE_Error
2107
+	 * @throws InvalidArgumentException
2108
+	 * @throws InvalidDataTypeException
2109
+	 * @throws InvalidInterfaceException
2110
+	 * @throws ReflectionException
2111
+	 * @throws EntityNotFoundException
2112
+	 */
2113
+	public function _reg_details_meta_box()
2114
+	{
2115
+		EEH_Autoloader::register_line_item_display_autoloaders();
2116
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2117
+		EE_Registry::instance()->load_helper('Line_Item');
2118
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2119
+			: EE_Transaction::new_instance();
2120
+		$this->_session = $transaction->session_data();
2121
+		$filters        = new EE_Line_Item_Filter_Collection();
2122
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2123
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2124
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2125
+			$transaction->total_line_item());
2126
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2127
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2128
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2129
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2130
+			$filtered_line_item_tree,
2131
+			array('EE_Registration' => $this->_registration)
2132
+		);
2133
+		$attendee                                = $this->_registration->attendee();
2134
+		if (EE_Registry::instance()->CAP->current_user_can(
2135
+			'ee_read_transaction',
2136
+			'espresso_transactions_view_transaction'
2137
+		)) {
2138
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2139
+				EE_Admin_Page::add_query_args_and_nonce(
2140
+					array(
2141
+						'action' => 'view_transaction',
2142
+						'TXN_ID' => $transaction->ID(),
2143
+					),
2144
+					TXN_ADMIN_URL
2145
+				),
2146
+				esc_html__(' View Transaction', 'event_espresso'),
2147
+				'button secondary-button right',
2148
+				'dashicons dashicons-cart'
2149
+			);
2150
+		} else {
2151
+			$this->_template_args['view_transaction_button'] = '';
2152
+		}
2153
+		if ($attendee instanceof EE_Attendee
2154
+			&& EE_Registry::instance()->CAP->current_user_can(
2155
+				'ee_send_message',
2156
+				'espresso_registrations_resend_registration'
2157
+			)
2158
+		) {
2159
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2160
+				EE_Admin_Page::add_query_args_and_nonce(
2161
+					array(
2162
+						'action'      => 'resend_registration',
2163
+						'_REG_ID'     => $this->_registration->ID(),
2164
+						'redirect_to' => 'view_registration',
2165
+					),
2166
+					REG_ADMIN_URL
2167
+				),
2168
+				esc_html__(' Resend Registration', 'event_espresso'),
2169
+				'button secondary-button right',
2170
+				'dashicons dashicons-email-alt'
2171
+			);
2172
+		} else {
2173
+			$this->_template_args['resend_registration_button'] = '';
2174
+		}
2175
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2176
+		$payment                               = $transaction->get_first_related('Payment');
2177
+		$payment                               = ! $payment instanceof EE_Payment
2178
+			? EE_Payment::new_instance()
2179
+			: $payment;
2180
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2181
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2182
+			? EE_Payment_Method::new_instance()
2183
+			: $payment_method;
2184
+		$reg_details                           = array(
2185
+			'payment_method'       => $payment_method->name(),
2186
+			'response_msg'         => $payment->gateway_response(),
2187
+			'registration_id'      => $this->_registration->get('REG_code'),
2188
+			'registration_session' => $this->_registration->session_ID(),
2189
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2190
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2191
+		);
2192
+		if (isset($reg_details['registration_id'])) {
2193
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2194
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2195
+				'Registration ID',
2196
+				'event_espresso'
2197
+			);
2198
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2199
+		}
2200
+		if (isset($reg_details['payment_method'])) {
2201
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2202
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2203
+				'Most Recent Payment Method',
2204
+				'event_espresso'
2205
+			);
2206
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2207
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2208
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2209
+				'Payment method response',
2210
+				'event_espresso'
2211
+			);
2212
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2213
+		}
2214
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2215
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2216
+			'Registration Session',
2217
+			'event_espresso'
2218
+		);
2219
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2220
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2221
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2222
+			'Registration placed from IP',
2223
+			'event_espresso'
2224
+		);
2225
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2226
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2227
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2228
+			'event_espresso');
2229
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2230
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2231
+			array(
2232
+				'action'   => 'default',
2233
+				'event_id' => $this->_registration->event_ID(),
2234
+			),
2235
+			REG_ADMIN_URL
2236
+		);
2237
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2238
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2239
+		$template_path                                                        =
2240
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2241
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2242
+	}
2243
+
2244
+
2245
+	/**
2246
+	 * generates HTML for the Registration Questions meta box.
2247
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2248
+	 * otherwise uses new forms system
2249
+	 *
2250
+	 * @access public
2251
+	 * @return void
2252
+	 * @throws DomainException
2253
+	 * @throws EE_Error
2254
+	 */
2255
+	public function _reg_questions_meta_box()
2256
+	{
2257
+		//allow someone to override this method entirely
2258
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2259
+			$this->_registration)) {
2260
+			$form                                              = $this->_get_reg_custom_questions_form(
2261
+				$this->_registration->ID()
2262
+			);
2263
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2264
+				? $form->get_html_and_js()
2265
+				: '';
2266
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2267
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2268
+			$template_path                                     =
2269
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2270
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2271
+		}
2272
+	}
2273
+
2274
+
2275
+	/**
2276
+	 * form_before_question_group
2277
+	 *
2278
+	 * @deprecated    as of 4.8.32.rc.000
2279
+	 * @access        public
2280
+	 * @param        string $output
2281
+	 * @return        string
2282
+	 */
2283
+	public function form_before_question_group($output)
2284
+	{
2285
+		EE_Error::doing_it_wrong(
2286
+			__CLASS__ . '::' . __FUNCTION__,
2287
+			esc_html__(
2288
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2289
+				'event_espresso'
2290
+			),
2291
+			'4.8.32.rc.000'
2292
+		);
2293
+		return '
2294 2294
 	<table class="form-table ee-width-100">
2295 2295
 		<tbody>
2296 2296
 			';
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * form_after_question_group
2302
-     *
2303
-     * @deprecated    as of 4.8.32.rc.000
2304
-     * @access        public
2305
-     * @param        string $output
2306
-     * @return        string
2307
-     */
2308
-    public function form_after_question_group($output)
2309
-    {
2310
-        EE_Error::doing_it_wrong(
2311
-            __CLASS__ . '::' . __FUNCTION__,
2312
-            esc_html__(
2313
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2314
-                'event_espresso'
2315
-            ),
2316
-            '4.8.32.rc.000'
2317
-        );
2318
-        return '
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * form_after_question_group
2302
+	 *
2303
+	 * @deprecated    as of 4.8.32.rc.000
2304
+	 * @access        public
2305
+	 * @param        string $output
2306
+	 * @return        string
2307
+	 */
2308
+	public function form_after_question_group($output)
2309
+	{
2310
+		EE_Error::doing_it_wrong(
2311
+			__CLASS__ . '::' . __FUNCTION__,
2312
+			esc_html__(
2313
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2314
+				'event_espresso'
2315
+			),
2316
+			'4.8.32.rc.000'
2317
+		);
2318
+		return '
2319 2319
 			<tr class="hide-if-no-js">
2320 2320
 				<th> </th>
2321 2321
 				<td class="reg-admin-edit-attendee-question-td">
2322 2322
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2323
-               . esc_attr__('click to edit question', 'event_espresso')
2324
-               . '">
2323
+			   . esc_attr__('click to edit question', 'event_espresso')
2324
+			   . '">
2325 2325
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2326
-               . esc_html__('edit the above question group', 'event_espresso')
2327
-               . '</span>
2326
+			   . esc_html__('edit the above question group', 'event_espresso')
2327
+			   . '</span>
2328 2328
 						<div class="dashicons dashicons-edit"></div>
2329 2329
 					</a>
2330 2330
 				</td>
@@ -2332,579 +2332,579 @@  discard block
 block discarded – undo
2332 2332
 		</tbody>
2333 2333
 	</table>
2334 2334
 ';
2335
-    }
2336
-
2337
-
2338
-    /**
2339
-     * form_form_field_label_wrap
2340
-     *
2341
-     * @deprecated    as of 4.8.32.rc.000
2342
-     * @access        public
2343
-     * @param        string $label
2344
-     * @return        string
2345
-     */
2346
-    public function form_form_field_label_wrap($label)
2347
-    {
2348
-        EE_Error::doing_it_wrong(
2349
-            __CLASS__ . '::' . __FUNCTION__,
2350
-            esc_html__(
2351
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2352
-                'event_espresso'
2353
-            ),
2354
-            '4.8.32.rc.000'
2355
-        );
2356
-        return '
2335
+	}
2336
+
2337
+
2338
+	/**
2339
+	 * form_form_field_label_wrap
2340
+	 *
2341
+	 * @deprecated    as of 4.8.32.rc.000
2342
+	 * @access        public
2343
+	 * @param        string $label
2344
+	 * @return        string
2345
+	 */
2346
+	public function form_form_field_label_wrap($label)
2347
+	{
2348
+		EE_Error::doing_it_wrong(
2349
+			__CLASS__ . '::' . __FUNCTION__,
2350
+			esc_html__(
2351
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2352
+				'event_espresso'
2353
+			),
2354
+			'4.8.32.rc.000'
2355
+		);
2356
+		return '
2357 2357
 			<tr>
2358 2358
 				<th>
2359 2359
 					' . $label . '
2360 2360
 				</th>';
2361
-    }
2362
-
2363
-
2364
-    /**
2365
-     * form_form_field_input__wrap
2366
-     *
2367
-     * @deprecated    as of 4.8.32.rc.000
2368
-     * @access        public
2369
-     * @param        string $input
2370
-     * @return        string
2371
-     */
2372
-    public function form_form_field_input__wrap($input)
2373
-    {
2374
-        EE_Error::doing_it_wrong(
2375
-            __CLASS__ . '::' . __FUNCTION__,
2376
-            esc_html__(
2377
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2378
-                'event_espresso'
2379
-            ),
2380
-            '4.8.32.rc.000'
2381
-        );
2382
-        return '
2361
+	}
2362
+
2363
+
2364
+	/**
2365
+	 * form_form_field_input__wrap
2366
+	 *
2367
+	 * @deprecated    as of 4.8.32.rc.000
2368
+	 * @access        public
2369
+	 * @param        string $input
2370
+	 * @return        string
2371
+	 */
2372
+	public function form_form_field_input__wrap($input)
2373
+	{
2374
+		EE_Error::doing_it_wrong(
2375
+			__CLASS__ . '::' . __FUNCTION__,
2376
+			esc_html__(
2377
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2378
+				'event_espresso'
2379
+			),
2380
+			'4.8.32.rc.000'
2381
+		);
2382
+		return '
2383 2383
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2384 2384
 					' . $input . '
2385 2385
 				</td>
2386 2386
 			</tr>';
2387
-    }
2388
-
2389
-
2390
-    /**
2391
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2392
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2393
-     * to display the page
2394
-     *
2395
-     * @access protected
2396
-     * @return void
2397
-     * @throws EE_Error
2398
-     */
2399
-    protected function _update_attendee_registration_form()
2400
-    {
2401
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2402
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2403
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2404
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2405
-            if ($success) {
2406
-                $what  = esc_html__('Registration Form', 'event_espresso');
2407
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2408
-                    : array('action' => 'default');
2409
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2410
-            }
2411
-        }
2412
-    }
2413
-
2414
-
2415
-    /**
2416
-     * Gets the form for saving registrations custom questions (if done
2417
-     * previously retrieves the cached form object, which may have validation errors in it)
2418
-     *
2419
-     * @param int $REG_ID
2420
-     * @return EE_Registration_Custom_Questions_Form
2421
-     * @throws EE_Error
2422
-     * @throws InvalidArgumentException
2423
-     * @throws InvalidDataTypeException
2424
-     * @throws InvalidInterfaceException
2425
-     */
2426
-    protected function _get_reg_custom_questions_form($REG_ID)
2427
-    {
2428
-        if ( ! $this->_reg_custom_questions_form) {
2429
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2430
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2431
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2432
-            );
2433
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2434
-        }
2435
-        return $this->_reg_custom_questions_form;
2436
-    }
2437
-
2438
-
2439
-    /**
2440
-     * Saves
2441
-     *
2442
-     * @access private
2443
-     * @param bool $REG_ID
2444
-     * @return bool
2445
-     * @throws EE_Error
2446
-     * @throws InvalidArgumentException
2447
-     * @throws InvalidDataTypeException
2448
-     * @throws InvalidInterfaceException
2449
-     */
2450
-    private function _save_reg_custom_questions_form($REG_ID = false)
2451
-    {
2452
-        if ( ! $REG_ID) {
2453
-            EE_Error::add_error(
2454
-                esc_html__(
2455
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2456
-                __FILE__, __FUNCTION__, __LINE__
2457
-            );
2458
-        }
2459
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2460
-        $form->receive_form_submission($this->_req_data);
2461
-        $success = false;
2462
-        if ($form->is_valid()) {
2463
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2464
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2465
-                    $where_conditions    = array(
2466
-                        'QST_ID' => $question_id,
2467
-                        'REG_ID' => $REG_ID,
2468
-                    );
2469
-                    $possibly_new_values = array(
2470
-                        'ANS_value' => $input->normalized_value(),
2471
-                    );
2472
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2473
-                    if ($answer instanceof EE_Answer) {
2474
-                        $success = $answer->save($possibly_new_values);
2475
-                    } else {
2476
-                        //insert it then
2477
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2478
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2479
-                        $success     = $answer->save();
2480
-                    }
2481
-                }
2482
-            }
2483
-        } else {
2484
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2485
-        }
2486
-        return $success;
2487
-    }
2488
-
2489
-
2490
-    /**
2491
-     *        generates HTML for the Registration main meta box
2492
-     *
2493
-     * @access public
2494
-     * @return void
2495
-     * @throws DomainException
2496
-     * @throws EE_Error
2497
-     * @throws InvalidArgumentException
2498
-     * @throws InvalidDataTypeException
2499
-     * @throws InvalidInterfaceException
2500
-     */
2501
-    public function _reg_attendees_meta_box()
2502
-    {
2503
-        $REG = EEM_Registration::instance();
2504
-        //get all other registrations on this transaction, and cache
2505
-        //the attendees for them so we don't have to run another query using force_join
2506
-        $registrations                           = $REG->get_all(array(
2507
-            array(
2508
-                'TXN_ID' => $this->_registration->transaction_ID(),
2509
-                'REG_ID' => array('!=', $this->_registration->ID()),
2510
-            ),
2511
-            'force_join' => array('Attendee'),
2512
-        ));
2513
-        $this->_template_args['attendees']       = array();
2514
-        $this->_template_args['attendee_notice'] = '';
2515
-        if (empty($registrations)
2516
-            || (is_array($registrations)
2517
-                && ! EEH_Array::get_one_item_from_array($registrations))
2518
-        ) {
2519
-            EE_Error::add_error(
2520
-                esc_html__(
2521
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2522
-                    'event_espresso'
2523
-                ), __FILE__, __FUNCTION__, __LINE__
2524
-            );
2525
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2526
-        } else {
2527
-            $att_nmbr = 1;
2528
-            foreach ($registrations as $registration) {
2529
-                /* @var $registration EE_Registration */
2530
-                $attendee                                                    = $registration->attendee()
2531
-                    ? $registration->attendee()
2532
-                    : EEM_Attendee::instance()
2533
-                                  ->create_default_object();
2534
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2535
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2536
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2537
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2538
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2539
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2540
-                    ', ',
2541
-                    $attendee->full_address_as_array()
2542
-                );
2543
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2544
-                    array(
2545
-                        'action' => 'edit_attendee',
2546
-                        'post'   => $attendee->ID(),
2547
-                    ),
2548
-                    REG_ADMIN_URL
2549
-                );
2550
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2551
-                $att_nmbr++;
2552
-            }
2553
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2554
-        }
2555
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2556
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2557
-    }
2558
-
2559
-
2560
-    /**
2561
-     *        generates HTML for the Edit Registration side meta box
2562
-     *
2563
-     * @access public
2564
-     * @return void
2565
-     * @throws DomainException
2566
-     * @throws EE_Error
2567
-     * @throws InvalidArgumentException
2568
-     * @throws InvalidDataTypeException
2569
-     * @throws InvalidInterfaceException
2570
-     */
2571
-    public function _reg_registrant_side_meta_box()
2572
-    {
2573
-        /*@var $attendee EE_Attendee */
2574
-        $att_check = $this->_registration->attendee();
2575
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2576
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2577
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2578
-        //primary registration object (that way we know if we need to show create button or not)
2579
-        if ( ! $this->_registration->is_primary_registrant()) {
2580
-            $primary_registration = $this->_registration->get_primary_registration();
2581
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2582
-                : null;
2583
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2584
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2585
-                //custom attendee object so let's not worry about the primary reg.
2586
-                $primary_registration = null;
2587
-            }
2588
-        } else {
2589
-            $primary_registration = null;
2590
-        }
2591
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2592
-        $this->_template_args['fname']             = $attendee->fname();
2593
-        $this->_template_args['lname']             = $attendee->lname();
2594
-        $this->_template_args['email']             = $attendee->email();
2595
-        $this->_template_args['phone']             = $attendee->phone();
2596
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2597
-        //edit link
2598
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2599
-            'action' => 'edit_attendee',
2600
-            'post'   => $attendee->ID(),
2601
-        ), REG_ADMIN_URL);
2602
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2603
-        //create link
2604
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2605
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2606
-                'action'  => 'duplicate_attendee',
2607
-                '_REG_ID' => $this->_registration->ID(),
2608
-            ), REG_ADMIN_URL) : '';
2609
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2610
-        $this->_template_args['att_check']    = $att_check;
2611
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2612
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2613
-    }
2614
-
2615
-
2616
-    /**
2617
-     * trash or restore registrations
2618
-     *
2619
-     * @param  boolean $trash whether to archive or restore
2620
-     * @return void
2621
-     * @throws EE_Error
2622
-     * @throws InvalidArgumentException
2623
-     * @throws InvalidDataTypeException
2624
-     * @throws InvalidInterfaceException
2625
-     * @throws RuntimeException
2626
-     * @access protected
2627
-     */
2628
-    protected function _trash_or_restore_registrations($trash = true)
2629
-    {
2630
-        //if empty _REG_ID then get out because there's nothing to do
2631
-        if (empty($this->_req_data['_REG_ID'])) {
2632
-            EE_Error::add_error(
2633
-                sprintf(
2634
-                    esc_html__(
2635
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2636
-                        'event_espresso'
2637
-                    ),
2638
-                    $trash ? 'trash' : 'restore'
2639
-                ),
2640
-                __FILE__, __LINE__, __FUNCTION__
2641
-            );
2642
-            $this->_redirect_after_action(false, '', '', array(), true);
2643
-        }
2644
-        $success = 0;
2645
-        $overwrite_msgs = false;
2646
-        //Checkboxes
2647
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2648
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2649
-        }
2650
-        $reg_count = count($this->_req_data['_REG_ID']);
2651
-        // cycle thru checkboxes
2652
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2653
-            /** @var EE_Registration $REG */
2654
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2655
-            $payments = $REG->registration_payments();
2656
-            if (! empty($payments)) {
2657
-                $name = $REG->attendee() instanceof EE_Attendee
2658
-                    ? $REG->attendee()->full_name()
2659
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2660
-                $overwrite_msgs = true;
2661
-                EE_Error::add_error(
2662
-                    sprintf(
2663
-                        esc_html__(
2664
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2665
-                            'event_espresso'
2666
-                        ),
2667
-                        $name
2668
-                    ),
2669
-                    __FILE__, __FUNCTION__, __LINE__
2670
-                );
2671
-                //can't trash this registration because it has payments.
2672
-                continue;
2673
-            }
2674
-            $updated = $trash ? $REG->delete() : $REG->restore();
2675
-            if ($updated) {
2676
-                $success++;
2677
-            }
2678
-        }
2679
-        $this->_redirect_after_action(
2680
-            $success === $reg_count, // were ALL registrations affected?
2681
-            $success > 1
2682
-                ? esc_html__('Registrations', 'event_espresso')
2683
-                : esc_html__('Registration', 'event_espresso'),
2684
-            $trash
2685
-                ? esc_html__('moved to the trash', 'event_espresso')
2686
-                : esc_html__('restored', 'event_espresso'),
2687
-            array('action' => 'default'),
2688
-            $overwrite_msgs
2689
-        );
2690
-    }
2691
-
2692
-
2693
-    /**
2694
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2695
-     * registration but also.
2696
-     * 1. Removing relations to EE_Attendee
2697
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2698
-     * ALSO trashed.
2699
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2700
-     * 4. Removing relationships between all tickets and the related registrations
2701
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2702
-     * 6. Deleting permanently any related Checkins.
2703
-     *
2704
-     * @return void
2705
-     * @throws EE_Error
2706
-     * @throws InvalidArgumentException
2707
-     * @throws InvalidDataTypeException
2708
-     * @throws InvalidInterfaceException
2709
-     */
2710
-    protected function _delete_registrations()
2711
-    {
2712
-        $REG_MDL = EEM_Registration::instance();
2713
-        $success = 1;
2714
-        //Checkboxes
2715
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2716
-            // if array has more than one element than success message should be plural
2717
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2718
-            // cycle thru checkboxes
2719
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2720
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2721
-                if ( ! $REG instanceof EE_Registration) {
2722
-                    continue;
2723
-                }
2724
-                $deleted = $this->_delete_registration($REG);
2725
-                if ( ! $deleted) {
2726
-                    $success = 0;
2727
-                }
2728
-            }
2729
-        } else {
2730
-            // grab single id and delete
2731
-            $REG_ID  = $this->_req_data['_REG_ID'];
2732
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2733
-            $deleted = $this->_delete_registration($REG);
2734
-            if ( ! $deleted) {
2735
-                $success = 0;
2736
-            }
2737
-        }
2738
-        $what        = $success > 1
2739
-            ? esc_html__('Registrations', 'event_espresso')
2740
-            : esc_html__('Registration', 'event_espresso');
2741
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2742
-        $this->_redirect_after_action(
2743
-            $success,
2744
-            $what,
2745
-            $action_desc,
2746
-            array('action' => 'default'),
2747
-            true
2748
-        );
2749
-    }
2750
-
2751
-
2752
-    /**
2753
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2754
-     * models get affected.
2755
-     *
2756
-     * @param  EE_Registration $REG registration to be deleted permenantly
2757
-     * @return bool true = successful deletion, false = fail.
2758
-     * @throws EE_Error
2759
-     */
2760
-    protected function _delete_registration(EE_Registration $REG)
2761
-    {
2762
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2763
-        //registrations on the transaction that are NOT trashed.
2764
-        $TXN         = $REG->get_first_related('Transaction');
2765
-        $REGS        = $TXN->get_many_related('Registration');
2766
-        $all_trashed = true;
2767
-        foreach ($REGS as $registration) {
2768
-            if ( ! $registration->get('REG_deleted')) {
2769
-                $all_trashed = false;
2770
-            }
2771
-        }
2772
-        if ( ! $all_trashed) {
2773
-            EE_Error::add_error(
2774
-                esc_html__(
2775
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2776
-                    'event_espresso'
2777
-                ),
2778
-                __FILE__, __FUNCTION__, __LINE__
2779
-            );
2780
-            return false;
2781
-        }
2782
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2783
-        //separately from THIS one).
2784
-        foreach ($REGS as $registration) {
2785
-            //delete related answers
2786
-            $registration->delete_related_permanently('Answer');
2787
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2788
-            $attendee = $registration->get_first_related('Attendee');
2789
-            if ($attendee instanceof EE_Attendee) {
2790
-                $registration->_remove_relation_to($attendee, 'Attendee');
2791
-            }
2792
-            //now remove relationships to tickets on this registration.
2793
-            $registration->_remove_relations('Ticket');
2794
-            //now delete permanently the checkins related to this registration.
2795
-            $registration->delete_related_permanently('Checkin');
2796
-            if ($registration->ID() === $REG->ID()) {
2797
-                continue;
2798
-            } //we don't want to delete permanently the existing registration just yet.
2799
-            //remove relation to transaction for these registrations if NOT the existing registrations
2800
-            $registration->_remove_relations('Transaction');
2801
-            //delete permanently any related messages.
2802
-            $registration->delete_related_permanently('Message');
2803
-            //now delete this registration permanently
2804
-            $registration->delete_permanently();
2805
-        }
2806
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2807
-        // (the transaction and line items should be all that's left).
2808
-        // delete the line items related to the transaction for this registration.
2809
-        $TXN->delete_related_permanently('Line_Item');
2810
-        //we need to remove all the relationships on the transaction
2811
-        $TXN->delete_related_permanently('Payment');
2812
-        $TXN->delete_related_permanently('Extra_Meta');
2813
-        $TXN->delete_related_permanently('Message');
2814
-        //now we can delete this REG permanently (and the transaction of course)
2815
-        $REG->delete_related_permanently('Transaction');
2816
-        return $REG->delete_permanently();
2817
-    }
2818
-
2819
-
2820
-    /**
2821
-     *    generates HTML for the Register New Attendee Admin page
2822
-     *
2823
-     * @access private
2824
-     * @throws DomainException
2825
-     * @throws EE_Error
2826
-     */
2827
-    public function new_registration()
2828
-    {
2829
-        if ( ! $this->_set_reg_event()) {
2830
-            throw new EE_Error(
2831
-                esc_html__(
2832
-                    'Unable to continue with registering because there is no Event ID in the request',
2833
-                    'event_espresso'
2834
-                )
2835
-            );
2836
-        }
2837
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2838
-        // gotta start with a clean slate if we're not coming here via ajax
2839
-        if ( ! defined('DOING_AJAX')
2840
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2841
-        ) {
2842
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2843
-        }
2844
-        $this->_template_args['event_name'] = '';
2845
-        // event name
2846
-        if ($this->_reg_event) {
2847
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2848
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2849
-                'action' => 'edit',
2850
-                'post'   => $this->_reg_event->ID(),
2851
-            ), EVENTS_ADMIN_URL);
2852
-            $edit_event_lnk                     = '<a href="'
2853
-                                                  . $edit_event_url
2854
-                                                  . '" title="'
2855
-                                                  . esc_attr__('Edit ', 'event_espresso')
2856
-                                                  . $this->_reg_event->name()
2857
-                                                  . '">'
2858
-                                                  . esc_html__('Edit Event', 'event_espresso')
2859
-                                                  . '</a>';
2860
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2861
-                                                   . $edit_event_lnk
2862
-                                                   . '</span>';
2863
-        }
2864
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2865
-        if (defined('DOING_AJAX')) {
2866
-            $this->_return_json();
2867
-        }
2868
-        // grab header
2869
-        $template_path                              =
2870
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2871
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2872
-            $this->_template_args, true);
2873
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2874
-        // the details template wrapper
2875
-        $this->display_admin_page_with_sidebar();
2876
-    }
2877
-
2878
-
2879
-    /**
2880
-     * This returns the content for a registration step
2881
-     *
2882
-     * @access protected
2883
-     * @return string html
2884
-     * @throws DomainException
2885
-     * @throws EE_Error
2886
-     * @throws InvalidArgumentException
2887
-     * @throws InvalidDataTypeException
2888
-     * @throws InvalidInterfaceException
2889
-     */
2890
-    protected function _get_registration_step_content()
2891
-    {
2892
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2893
-            $warning_msg = sprintf(
2894
-                esc_html__(
2895
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2896
-                    'event_espresso'
2897
-                ),
2898
-                '<br />',
2899
-                '<h3 class="important-notice">',
2900
-                '</h3>',
2901
-                '<div class="float-right">',
2902
-                '<span id="redirect_timer" class="important-notice">30</span>',
2903
-                '</div>',
2904
-                '<b>',
2905
-                '</b>'
2906
-            );
2907
-            return '
2387
+	}
2388
+
2389
+
2390
+	/**
2391
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2392
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2393
+	 * to display the page
2394
+	 *
2395
+	 * @access protected
2396
+	 * @return void
2397
+	 * @throws EE_Error
2398
+	 */
2399
+	protected function _update_attendee_registration_form()
2400
+	{
2401
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2402
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2403
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2404
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2405
+			if ($success) {
2406
+				$what  = esc_html__('Registration Form', 'event_espresso');
2407
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2408
+					: array('action' => 'default');
2409
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2410
+			}
2411
+		}
2412
+	}
2413
+
2414
+
2415
+	/**
2416
+	 * Gets the form for saving registrations custom questions (if done
2417
+	 * previously retrieves the cached form object, which may have validation errors in it)
2418
+	 *
2419
+	 * @param int $REG_ID
2420
+	 * @return EE_Registration_Custom_Questions_Form
2421
+	 * @throws EE_Error
2422
+	 * @throws InvalidArgumentException
2423
+	 * @throws InvalidDataTypeException
2424
+	 * @throws InvalidInterfaceException
2425
+	 */
2426
+	protected function _get_reg_custom_questions_form($REG_ID)
2427
+	{
2428
+		if ( ! $this->_reg_custom_questions_form) {
2429
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2430
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2431
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2432
+			);
2433
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2434
+		}
2435
+		return $this->_reg_custom_questions_form;
2436
+	}
2437
+
2438
+
2439
+	/**
2440
+	 * Saves
2441
+	 *
2442
+	 * @access private
2443
+	 * @param bool $REG_ID
2444
+	 * @return bool
2445
+	 * @throws EE_Error
2446
+	 * @throws InvalidArgumentException
2447
+	 * @throws InvalidDataTypeException
2448
+	 * @throws InvalidInterfaceException
2449
+	 */
2450
+	private function _save_reg_custom_questions_form($REG_ID = false)
2451
+	{
2452
+		if ( ! $REG_ID) {
2453
+			EE_Error::add_error(
2454
+				esc_html__(
2455
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2456
+				__FILE__, __FUNCTION__, __LINE__
2457
+			);
2458
+		}
2459
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2460
+		$form->receive_form_submission($this->_req_data);
2461
+		$success = false;
2462
+		if ($form->is_valid()) {
2463
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2464
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2465
+					$where_conditions    = array(
2466
+						'QST_ID' => $question_id,
2467
+						'REG_ID' => $REG_ID,
2468
+					);
2469
+					$possibly_new_values = array(
2470
+						'ANS_value' => $input->normalized_value(),
2471
+					);
2472
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2473
+					if ($answer instanceof EE_Answer) {
2474
+						$success = $answer->save($possibly_new_values);
2475
+					} else {
2476
+						//insert it then
2477
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2478
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2479
+						$success     = $answer->save();
2480
+					}
2481
+				}
2482
+			}
2483
+		} else {
2484
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2485
+		}
2486
+		return $success;
2487
+	}
2488
+
2489
+
2490
+	/**
2491
+	 *        generates HTML for the Registration main meta box
2492
+	 *
2493
+	 * @access public
2494
+	 * @return void
2495
+	 * @throws DomainException
2496
+	 * @throws EE_Error
2497
+	 * @throws InvalidArgumentException
2498
+	 * @throws InvalidDataTypeException
2499
+	 * @throws InvalidInterfaceException
2500
+	 */
2501
+	public function _reg_attendees_meta_box()
2502
+	{
2503
+		$REG = EEM_Registration::instance();
2504
+		//get all other registrations on this transaction, and cache
2505
+		//the attendees for them so we don't have to run another query using force_join
2506
+		$registrations                           = $REG->get_all(array(
2507
+			array(
2508
+				'TXN_ID' => $this->_registration->transaction_ID(),
2509
+				'REG_ID' => array('!=', $this->_registration->ID()),
2510
+			),
2511
+			'force_join' => array('Attendee'),
2512
+		));
2513
+		$this->_template_args['attendees']       = array();
2514
+		$this->_template_args['attendee_notice'] = '';
2515
+		if (empty($registrations)
2516
+			|| (is_array($registrations)
2517
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2518
+		) {
2519
+			EE_Error::add_error(
2520
+				esc_html__(
2521
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2522
+					'event_espresso'
2523
+				), __FILE__, __FUNCTION__, __LINE__
2524
+			);
2525
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2526
+		} else {
2527
+			$att_nmbr = 1;
2528
+			foreach ($registrations as $registration) {
2529
+				/* @var $registration EE_Registration */
2530
+				$attendee                                                    = $registration->attendee()
2531
+					? $registration->attendee()
2532
+					: EEM_Attendee::instance()
2533
+								  ->create_default_object();
2534
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2535
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2536
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2537
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2538
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2539
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2540
+					', ',
2541
+					$attendee->full_address_as_array()
2542
+				);
2543
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2544
+					array(
2545
+						'action' => 'edit_attendee',
2546
+						'post'   => $attendee->ID(),
2547
+					),
2548
+					REG_ADMIN_URL
2549
+				);
2550
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2551
+				$att_nmbr++;
2552
+			}
2553
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2554
+		}
2555
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2556
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2557
+	}
2558
+
2559
+
2560
+	/**
2561
+	 *        generates HTML for the Edit Registration side meta box
2562
+	 *
2563
+	 * @access public
2564
+	 * @return void
2565
+	 * @throws DomainException
2566
+	 * @throws EE_Error
2567
+	 * @throws InvalidArgumentException
2568
+	 * @throws InvalidDataTypeException
2569
+	 * @throws InvalidInterfaceException
2570
+	 */
2571
+	public function _reg_registrant_side_meta_box()
2572
+	{
2573
+		/*@var $attendee EE_Attendee */
2574
+		$att_check = $this->_registration->attendee();
2575
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2576
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2577
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2578
+		//primary registration object (that way we know if we need to show create button or not)
2579
+		if ( ! $this->_registration->is_primary_registrant()) {
2580
+			$primary_registration = $this->_registration->get_primary_registration();
2581
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2582
+				: null;
2583
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2584
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2585
+				//custom attendee object so let's not worry about the primary reg.
2586
+				$primary_registration = null;
2587
+			}
2588
+		} else {
2589
+			$primary_registration = null;
2590
+		}
2591
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2592
+		$this->_template_args['fname']             = $attendee->fname();
2593
+		$this->_template_args['lname']             = $attendee->lname();
2594
+		$this->_template_args['email']             = $attendee->email();
2595
+		$this->_template_args['phone']             = $attendee->phone();
2596
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2597
+		//edit link
2598
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2599
+			'action' => 'edit_attendee',
2600
+			'post'   => $attendee->ID(),
2601
+		), REG_ADMIN_URL);
2602
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2603
+		//create link
2604
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2605
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2606
+				'action'  => 'duplicate_attendee',
2607
+				'_REG_ID' => $this->_registration->ID(),
2608
+			), REG_ADMIN_URL) : '';
2609
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2610
+		$this->_template_args['att_check']    = $att_check;
2611
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2612
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2613
+	}
2614
+
2615
+
2616
+	/**
2617
+	 * trash or restore registrations
2618
+	 *
2619
+	 * @param  boolean $trash whether to archive or restore
2620
+	 * @return void
2621
+	 * @throws EE_Error
2622
+	 * @throws InvalidArgumentException
2623
+	 * @throws InvalidDataTypeException
2624
+	 * @throws InvalidInterfaceException
2625
+	 * @throws RuntimeException
2626
+	 * @access protected
2627
+	 */
2628
+	protected function _trash_or_restore_registrations($trash = true)
2629
+	{
2630
+		//if empty _REG_ID then get out because there's nothing to do
2631
+		if (empty($this->_req_data['_REG_ID'])) {
2632
+			EE_Error::add_error(
2633
+				sprintf(
2634
+					esc_html__(
2635
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2636
+						'event_espresso'
2637
+					),
2638
+					$trash ? 'trash' : 'restore'
2639
+				),
2640
+				__FILE__, __LINE__, __FUNCTION__
2641
+			);
2642
+			$this->_redirect_after_action(false, '', '', array(), true);
2643
+		}
2644
+		$success = 0;
2645
+		$overwrite_msgs = false;
2646
+		//Checkboxes
2647
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2648
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2649
+		}
2650
+		$reg_count = count($this->_req_data['_REG_ID']);
2651
+		// cycle thru checkboxes
2652
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2653
+			/** @var EE_Registration $REG */
2654
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2655
+			$payments = $REG->registration_payments();
2656
+			if (! empty($payments)) {
2657
+				$name = $REG->attendee() instanceof EE_Attendee
2658
+					? $REG->attendee()->full_name()
2659
+					: esc_html__('Unknown Attendee', 'event_espresso');
2660
+				$overwrite_msgs = true;
2661
+				EE_Error::add_error(
2662
+					sprintf(
2663
+						esc_html__(
2664
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2665
+							'event_espresso'
2666
+						),
2667
+						$name
2668
+					),
2669
+					__FILE__, __FUNCTION__, __LINE__
2670
+				);
2671
+				//can't trash this registration because it has payments.
2672
+				continue;
2673
+			}
2674
+			$updated = $trash ? $REG->delete() : $REG->restore();
2675
+			if ($updated) {
2676
+				$success++;
2677
+			}
2678
+		}
2679
+		$this->_redirect_after_action(
2680
+			$success === $reg_count, // were ALL registrations affected?
2681
+			$success > 1
2682
+				? esc_html__('Registrations', 'event_espresso')
2683
+				: esc_html__('Registration', 'event_espresso'),
2684
+			$trash
2685
+				? esc_html__('moved to the trash', 'event_espresso')
2686
+				: esc_html__('restored', 'event_espresso'),
2687
+			array('action' => 'default'),
2688
+			$overwrite_msgs
2689
+		);
2690
+	}
2691
+
2692
+
2693
+	/**
2694
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2695
+	 * registration but also.
2696
+	 * 1. Removing relations to EE_Attendee
2697
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2698
+	 * ALSO trashed.
2699
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2700
+	 * 4. Removing relationships between all tickets and the related registrations
2701
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2702
+	 * 6. Deleting permanently any related Checkins.
2703
+	 *
2704
+	 * @return void
2705
+	 * @throws EE_Error
2706
+	 * @throws InvalidArgumentException
2707
+	 * @throws InvalidDataTypeException
2708
+	 * @throws InvalidInterfaceException
2709
+	 */
2710
+	protected function _delete_registrations()
2711
+	{
2712
+		$REG_MDL = EEM_Registration::instance();
2713
+		$success = 1;
2714
+		//Checkboxes
2715
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2716
+			// if array has more than one element than success message should be plural
2717
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2718
+			// cycle thru checkboxes
2719
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2720
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2721
+				if ( ! $REG instanceof EE_Registration) {
2722
+					continue;
2723
+				}
2724
+				$deleted = $this->_delete_registration($REG);
2725
+				if ( ! $deleted) {
2726
+					$success = 0;
2727
+				}
2728
+			}
2729
+		} else {
2730
+			// grab single id and delete
2731
+			$REG_ID  = $this->_req_data['_REG_ID'];
2732
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2733
+			$deleted = $this->_delete_registration($REG);
2734
+			if ( ! $deleted) {
2735
+				$success = 0;
2736
+			}
2737
+		}
2738
+		$what        = $success > 1
2739
+			? esc_html__('Registrations', 'event_espresso')
2740
+			: esc_html__('Registration', 'event_espresso');
2741
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2742
+		$this->_redirect_after_action(
2743
+			$success,
2744
+			$what,
2745
+			$action_desc,
2746
+			array('action' => 'default'),
2747
+			true
2748
+		);
2749
+	}
2750
+
2751
+
2752
+	/**
2753
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2754
+	 * models get affected.
2755
+	 *
2756
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2757
+	 * @return bool true = successful deletion, false = fail.
2758
+	 * @throws EE_Error
2759
+	 */
2760
+	protected function _delete_registration(EE_Registration $REG)
2761
+	{
2762
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2763
+		//registrations on the transaction that are NOT trashed.
2764
+		$TXN         = $REG->get_first_related('Transaction');
2765
+		$REGS        = $TXN->get_many_related('Registration');
2766
+		$all_trashed = true;
2767
+		foreach ($REGS as $registration) {
2768
+			if ( ! $registration->get('REG_deleted')) {
2769
+				$all_trashed = false;
2770
+			}
2771
+		}
2772
+		if ( ! $all_trashed) {
2773
+			EE_Error::add_error(
2774
+				esc_html__(
2775
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2776
+					'event_espresso'
2777
+				),
2778
+				__FILE__, __FUNCTION__, __LINE__
2779
+			);
2780
+			return false;
2781
+		}
2782
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2783
+		//separately from THIS one).
2784
+		foreach ($REGS as $registration) {
2785
+			//delete related answers
2786
+			$registration->delete_related_permanently('Answer');
2787
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2788
+			$attendee = $registration->get_first_related('Attendee');
2789
+			if ($attendee instanceof EE_Attendee) {
2790
+				$registration->_remove_relation_to($attendee, 'Attendee');
2791
+			}
2792
+			//now remove relationships to tickets on this registration.
2793
+			$registration->_remove_relations('Ticket');
2794
+			//now delete permanently the checkins related to this registration.
2795
+			$registration->delete_related_permanently('Checkin');
2796
+			if ($registration->ID() === $REG->ID()) {
2797
+				continue;
2798
+			} //we don't want to delete permanently the existing registration just yet.
2799
+			//remove relation to transaction for these registrations if NOT the existing registrations
2800
+			$registration->_remove_relations('Transaction');
2801
+			//delete permanently any related messages.
2802
+			$registration->delete_related_permanently('Message');
2803
+			//now delete this registration permanently
2804
+			$registration->delete_permanently();
2805
+		}
2806
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2807
+		// (the transaction and line items should be all that's left).
2808
+		// delete the line items related to the transaction for this registration.
2809
+		$TXN->delete_related_permanently('Line_Item');
2810
+		//we need to remove all the relationships on the transaction
2811
+		$TXN->delete_related_permanently('Payment');
2812
+		$TXN->delete_related_permanently('Extra_Meta');
2813
+		$TXN->delete_related_permanently('Message');
2814
+		//now we can delete this REG permanently (and the transaction of course)
2815
+		$REG->delete_related_permanently('Transaction');
2816
+		return $REG->delete_permanently();
2817
+	}
2818
+
2819
+
2820
+	/**
2821
+	 *    generates HTML for the Register New Attendee Admin page
2822
+	 *
2823
+	 * @access private
2824
+	 * @throws DomainException
2825
+	 * @throws EE_Error
2826
+	 */
2827
+	public function new_registration()
2828
+	{
2829
+		if ( ! $this->_set_reg_event()) {
2830
+			throw new EE_Error(
2831
+				esc_html__(
2832
+					'Unable to continue with registering because there is no Event ID in the request',
2833
+					'event_espresso'
2834
+				)
2835
+			);
2836
+		}
2837
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2838
+		// gotta start with a clean slate if we're not coming here via ajax
2839
+		if ( ! defined('DOING_AJAX')
2840
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2841
+		) {
2842
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2843
+		}
2844
+		$this->_template_args['event_name'] = '';
2845
+		// event name
2846
+		if ($this->_reg_event) {
2847
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2848
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2849
+				'action' => 'edit',
2850
+				'post'   => $this->_reg_event->ID(),
2851
+			), EVENTS_ADMIN_URL);
2852
+			$edit_event_lnk                     = '<a href="'
2853
+												  . $edit_event_url
2854
+												  . '" title="'
2855
+												  . esc_attr__('Edit ', 'event_espresso')
2856
+												  . $this->_reg_event->name()
2857
+												  . '">'
2858
+												  . esc_html__('Edit Event', 'event_espresso')
2859
+												  . '</a>';
2860
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2861
+												   . $edit_event_lnk
2862
+												   . '</span>';
2863
+		}
2864
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2865
+		if (defined('DOING_AJAX')) {
2866
+			$this->_return_json();
2867
+		}
2868
+		// grab header
2869
+		$template_path                              =
2870
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2871
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2872
+			$this->_template_args, true);
2873
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2874
+		// the details template wrapper
2875
+		$this->display_admin_page_with_sidebar();
2876
+	}
2877
+
2878
+
2879
+	/**
2880
+	 * This returns the content for a registration step
2881
+	 *
2882
+	 * @access protected
2883
+	 * @return string html
2884
+	 * @throws DomainException
2885
+	 * @throws EE_Error
2886
+	 * @throws InvalidArgumentException
2887
+	 * @throws InvalidDataTypeException
2888
+	 * @throws InvalidInterfaceException
2889
+	 */
2890
+	protected function _get_registration_step_content()
2891
+	{
2892
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2893
+			$warning_msg = sprintf(
2894
+				esc_html__(
2895
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2896
+					'event_espresso'
2897
+				),
2898
+				'<br />',
2899
+				'<h3 class="important-notice">',
2900
+				'</h3>',
2901
+				'<div class="float-right">',
2902
+				'<span id="redirect_timer" class="important-notice">30</span>',
2903
+				'</div>',
2904
+				'<b>',
2905
+				'</b>'
2906
+			);
2907
+			return '
2908 2908
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2909 2909
 	<script >
2910 2910
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2917,847 +2917,847 @@  discard block
 block discarded – undo
2917 2917
 	        }
2918 2918
 	    }, 800 );
2919 2919
 	</script >';
2920
-        }
2921
-        $template_args = array(
2922
-            'title'                    => '',
2923
-            'content'                  => '',
2924
-            'step_button_text'         => '',
2925
-            'show_notification_toggle' => false,
2926
-        );
2927
-        //to indicate we're processing a new registration
2928
-        $hidden_fields = array(
2929
-            'processing_registration' => array(
2930
-                'type'  => 'hidden',
2931
-                'value' => 0,
2932
-            ),
2933
-            'event_id'                => array(
2934
-                'type'  => 'hidden',
2935
-                'value' => $this->_reg_event->ID(),
2936
-            ),
2937
-        );
2938
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2939
-        $cart = EE_Registry::instance()->SSN->cart();
2940
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2941
-        switch ($step) {
2942
-            case 'ticket' :
2943
-                $hidden_fields['processing_registration']['value'] = 1;
2944
-                $template_args['title']                            = esc_html__(
2945
-                    'Step One: Select the Ticket for this registration',
2946
-                    'event_espresso'
2947
-                );
2948
-                $template_args['content']                          =
2949
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2950
-                $template_args['step_button_text']                 = esc_html__(
2951
-                    'Add Tickets and Continue to Registrant Details',
2952
-                    'event_espresso'
2953
-                );
2954
-                $template_args['show_notification_toggle']         = false;
2955
-                break;
2956
-            case 'questions' :
2957
-                $hidden_fields['processing_registration']['value'] = 2;
2958
-                $template_args['title']                            = esc_html__(
2959
-                    'Step Two: Add Registrant Details for this Registration',
2960
-                    'event_espresso'
2961
-                );
2962
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2963
-                // properly by the first process_reg_step run.
2964
-                $template_args['content']                  =
2965
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2966
-                $template_args['step_button_text']         = esc_html__(
2967
-                    'Save Registration and Continue to Details',
2968
-                    'event_espresso'
2969
-                );
2970
-                $template_args['show_notification_toggle'] = true;
2971
-                break;
2972
-        }
2973
-        //we come back to the process_registration_step route.
2974
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2975
-        return EEH_Template::display_template(
2976
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2977
-            $template_args,
2978
-            true
2979
-        );
2980
-    }
2981
-
2982
-
2983
-    /**
2984
-     *        set_reg_event
2985
-     *
2986
-     * @access private
2987
-     * @return bool
2988
-     * @throws EE_Error
2989
-     * @throws InvalidArgumentException
2990
-     * @throws InvalidDataTypeException
2991
-     * @throws InvalidInterfaceException
2992
-     */
2993
-    private function _set_reg_event()
2994
-    {
2995
-        if (is_object($this->_reg_event)) {
2996
-            return true;
2997
-        }
2998
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2999
-        if ( ! $EVT_ID) {
3000
-            return false;
3001
-        }
3002
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3003
-        return true;
3004
-    }
3005
-
3006
-
3007
-    /**
3008
-     * process_reg_step
3009
-     *
3010
-     * @access        public
3011
-     * @return string
3012
-     * @throws DomainException
3013
-     * @throws EE_Error
3014
-     * @throws InvalidArgumentException
3015
-     * @throws InvalidDataTypeException
3016
-     * @throws InvalidInterfaceException
3017
-     * @throws ReflectionException
3018
-     * @throws RuntimeException
3019
-     */
3020
-    public function process_reg_step()
3021
-    {
3022
-        EE_System::do_not_cache();
3023
-        $this->_set_reg_event();
3024
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3025
-        EE_Registry::instance()->REQ->set('uts', time());
3026
-        //what step are we on?
3027
-        $cart = EE_Registry::instance()->SSN->cart();
3028
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3029
-        //if doing ajax then we need to verify the nonce
3030
-        if (defined('DOING_AJAX')) {
3031
-            $nonce = isset($this->_req_data[$this->_req_nonce])
3032
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3033
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3034
-        }
3035
-        switch ($step) {
3036
-            case 'ticket' :
3037
-                //process ticket selection
3038
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3039
-                if ($success) {
3040
-                    EE_Error::add_success(
3041
-                        esc_html__(
3042
-                            'Tickets Selected. Now complete the registration.',
3043
-                            'event_espresso'
3044
-                        )
3045
-                    );
3046
-                } else {
3047
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3048
-                }
3049
-                if (defined('DOING_AJAX')) {
3050
-                    $this->new_registration(); //display next step
3051
-                } else {
3052
-                    $query_args = array(
3053
-                        'action'                  => 'new_registration',
3054
-                        'processing_registration' => 1,
3055
-                        'event_id'                => $this->_reg_event->ID(),
3056
-                        'uts'                     => time(),
3057
-                    );
3058
-                    $this->_redirect_after_action(
3059
-                        false,
3060
-                        '',
3061
-                        '',
3062
-                        $query_args,
3063
-                        true
3064
-                    );
3065
-                }
3066
-                break;
3067
-            case 'questions' :
3068
-                if (! isset(
3069
-                    $this->_req_data['txn_reg_status_change'],
3070
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
3071
-                ) {
3072
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3073
-                }
3074
-                //process registration
3075
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3076
-                if ($cart instanceof EE_Cart) {
3077
-                    $grand_total = $cart->get_cart_grand_total();
3078
-                    if ($grand_total instanceof EE_Line_Item) {
3079
-                        $grand_total->save_this_and_descendants_to_txn();
3080
-                    }
3081
-                }
3082
-                if ( ! $transaction instanceof EE_Transaction) {
3083
-                    $query_args = array(
3084
-                        'action'                  => 'new_registration',
3085
-                        'processing_registration' => 2,
3086
-                        'event_id'                => $this->_reg_event->ID(),
3087
-                        'uts'                     => time(),
3088
-                    );
3089
-                    if (defined('DOING_AJAX')) {
3090
-                        //display registration form again because there are errors (maybe validation?)
3091
-                        $this->new_registration();
3092
-                        return;
3093
-                    } else {
3094
-                        $this->_redirect_after_action(
3095
-                            false,
3096
-                            '',
3097
-                            '',
3098
-                            $query_args,
3099
-                            true
3100
-                        );
3101
-                        return;
3102
-                    }
3103
-                }
3104
-                // maybe update status, and make sure to save transaction if not done already
3105
-                if ( ! $transaction->update_status_based_on_total_paid()) {
3106
-                    $transaction->save();
3107
-                }
3108
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3109
-                $this->_req_data = array();
3110
-                $query_args      = array(
3111
-                    'action'        => 'redirect_to_txn',
3112
-                    'TXN_ID'        => $transaction->ID(),
3113
-                    'EVT_ID'        => $this->_reg_event->ID(),
3114
-                    'event_name'    => urlencode($this->_reg_event->name()),
3115
-                    'redirect_from' => 'new_registration',
3116
-                );
3117
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3118
-                break;
3119
-        }
3120
-        //what are you looking here for?  Should be nothing to do at this point.
3121
-    }
3122
-
3123
-
3124
-    /**
3125
-     * redirect_to_txn
3126
-     *
3127
-     * @access public
3128
-     * @return void
3129
-     * @throws EE_Error
3130
-     * @throws InvalidArgumentException
3131
-     * @throws InvalidDataTypeException
3132
-     * @throws InvalidInterfaceException
3133
-     */
3134
-    public function redirect_to_txn()
3135
-    {
3136
-        EE_System::do_not_cache();
3137
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3138
-        $query_args = array(
3139
-            'action' => 'view_transaction',
3140
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3141
-            'page'   => 'espresso_transactions',
3142
-        );
3143
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3144
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3145
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3146
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3147
-        }
3148
-        EE_Error::add_success(
3149
-            esc_html__(
3150
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3151
-                'event_espresso'
3152
-            )
3153
-        );
3154
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3155
-    }
3156
-
3157
-
3158
-    /**
3159
-     *        generates HTML for the Attendee Contact List
3160
-     *
3161
-     * @access protected
3162
-     * @return void
3163
-     */
3164
-    protected function _attendee_contact_list_table()
3165
-    {
3166
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3167
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3168
-        $this->display_admin_list_table_page_with_no_sidebar();
3169
-    }
3170
-
3171
-
3172
-    /**
3173
-     *        get_attendees
3174
-     *
3175
-     * @param      $per_page
3176
-     * @param bool $count whether to return count or data.
3177
-     * @param bool $trash
3178
-     * @return array
3179
-     * @throws EE_Error
3180
-     * @throws InvalidArgumentException
3181
-     * @throws InvalidDataTypeException
3182
-     * @throws InvalidInterfaceException
3183
-     * @access public
3184
-     */
3185
-    public function get_attendees($per_page, $count = false, $trash = false)
3186
-    {
3187
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3188
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3189
-        $ATT_MDL                    = EEM_Attendee::instance();
3190
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3191
-        switch ($this->_req_data['orderby']) {
3192
-            case 'ATT_ID':
3193
-                $orderby = 'ATT_ID';
3194
-                break;
3195
-            case 'ATT_fname':
3196
-                $orderby = 'ATT_fname';
3197
-                break;
3198
-            case 'ATT_email':
3199
-                $orderby = 'ATT_email';
3200
-                break;
3201
-            case 'ATT_city':
3202
-                $orderby = 'ATT_city';
3203
-                break;
3204
-            case 'STA_ID':
3205
-                $orderby = 'STA_ID';
3206
-                break;
3207
-            case 'CNT_ID':
3208
-                $orderby = 'CNT_ID';
3209
-                break;
3210
-            default:
3211
-                $orderby = 'ATT_lname';
3212
-        }
3213
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3214
-            ? $this->_req_data['order']
3215
-            : 'ASC';
3216
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3217
-            ? $this->_req_data['paged']
3218
-            : 1;
3219
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3220
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3221
-            ? $this->_req_data['perpage']
3222
-            : $per_page;
3223
-        $_where       = array();
3224
-        if ( ! empty($this->_req_data['s'])) {
3225
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3226
-            $_where['OR'] = array(
3227
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3228
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3229
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3230
-                'ATT_fname'                         => array('LIKE', $sstr),
3231
-                'ATT_lname'                         => array('LIKE', $sstr),
3232
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3233
-                'ATT_email'                         => array('LIKE', $sstr),
3234
-                'ATT_address'                       => array('LIKE', $sstr),
3235
-                'ATT_address2'                      => array('LIKE', $sstr),
3236
-                'ATT_city'                          => array('LIKE', $sstr),
3237
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3238
-                'State.STA_name'                    => array('LIKE', $sstr),
3239
-                'ATT_phone'                         => array('LIKE', $sstr),
3240
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3241
-                'Registration.REG_code'             => array('LIKE', $sstr),
3242
-                'Registration.REG_count'            => array('LIKE', $sstr),
3243
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3244
-            );
3245
-        }
3246
-        $offset = ($current_page - 1) * $per_page;
3247
-        $limit  = $count ? null : array($offset, $per_page);
3248
-        if ($trash) {
3249
-            $_where['status'] = array('!=', 'publish');
3250
-            $all_attendees    = $count
3251
-                ? $ATT_MDL->count(array(
3252
-                    $_where,
3253
-                    'order_by' => array($orderby => $sort),
3254
-                    'limit'    => $limit,
3255
-                ), 'ATT_ID', true)
3256
-                : $ATT_MDL->get_all(array(
3257
-                    $_where,
3258
-                    'order_by' => array($orderby => $sort),
3259
-                    'limit'    => $limit,
3260
-                ));
3261
-        } else {
3262
-            $_where['status'] = array('IN', array('publish'));
3263
-            $all_attendees    = $count
3264
-                ? $ATT_MDL->count(array(
3265
-                    $_where,
3266
-                    'order_by' => array($orderby => $sort),
3267
-                    'limit'    => $limit,
3268
-                ), 'ATT_ID', true)
3269
-                : $ATT_MDL->get_all(array(
3270
-                    $_where,
3271
-                    'order_by' => array($orderby => $sort),
3272
-                    'limit'    => $limit,
3273
-                ));
3274
-        }
3275
-        return $all_attendees;
3276
-    }
3277
-
3278
-
3279
-    /**
3280
-     * This is just taking care of resending the registration confirmation
3281
-     *
3282
-     * @access protected
3283
-     * @return void
3284
-     */
3285
-    protected function _resend_registration()
3286
-    {
3287
-        $this->_process_resend_registration();
3288
-        $query_args = isset($this->_req_data['redirect_to'])
3289
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3290
-            : array('action' => 'default');
3291
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3292
-    }
3293
-
3294
-    /**
3295
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3296
-     * to use when selecting registrations
3297
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3298
-     *                                                     the query parameters from the request
3299
-     * @return void ends the request with a redirect or download
3300
-     */
3301
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3302
-    {
3303
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3304
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3305
-                array(
3306
-                    'page'        => 'espresso_batch',
3307
-                    'batch'       => 'file',
3308
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3309
-                    'filters'     => urlencode(
3310
-                        serialize(
3311
-                            call_user_func(
3312
-                                array( $this, $method_name_for_getting_query_params ),
3313
-                                EEH_Array::is_set(
3314
-                                    $this->_req_data,
3315
-                                    'filters',
3316
-                                    array()
3317
-                                )
3318
-                            )
3319
-                        )
3320
-                ),
3321
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3322
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3323
-                'return_url'  => urlencode($this->_req_data['return_url']),
3324
-            )));
3325
-        } else {
3326
-            $new_request_args = array(
3327
-                'export' => 'report',
3328
-                'action' => 'registrations_report_for_event',
3329
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3330
-            );
3331
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3332
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3333
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3334
-                $EE_Export = EE_Export::instance($this->_req_data);
3335
-                $EE_Export->export();
3336
-            }
3337
-        }
3338
-    }
3339
-
3340
-
3341
-
3342
-    /**
3343
-     * Creates a registration report using only query parameters in the request
3344
-     * @return void
3345
-     */
3346
-    public function _registrations_report()
3347
-    {
3348
-        $this->_registrations_report_base('_get_registration_query_parameters');
3349
-    }
3350
-
3351
-
3352
-    public function _contact_list_export()
3353
-    {
3354
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3355
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3356
-            $EE_Export = EE_Export::instance($this->_req_data);
3357
-            $EE_Export->export_attendees();
3358
-        }
3359
-    }
3360
-
3361
-
3362
-    public function _contact_list_report()
3363
-    {
3364
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3365
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3366
-                'page'        => 'espresso_batch',
3367
-                'batch'       => 'file',
3368
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3369
-                'return_url'  => urlencode($this->_req_data['return_url']),
3370
-            )));
3371
-        } else {
3372
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3373
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3374
-                $EE_Export = EE_Export::instance($this->_req_data);
3375
-                $EE_Export->report_attendees();
3376
-            }
3377
-        }
3378
-    }
3379
-
3380
-
3381
-
3382
-
3383
-
3384
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3385
-    /**
3386
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3387
-     *
3388
-     * @return void
3389
-     * @throws EE_Error
3390
-     * @throws InvalidArgumentException
3391
-     * @throws InvalidDataTypeException
3392
-     * @throws InvalidInterfaceException
3393
-     */
3394
-    protected function _duplicate_attendee()
3395
-    {
3396
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3397
-        //verify we have necessary info
3398
-        if (empty($this->_req_data['_REG_ID'])) {
3399
-            EE_Error::add_error(
3400
-                esc_html__(
3401
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3402
-                    'event_espresso'
3403
-                ), __FILE__, __LINE__, __FUNCTION__
3404
-            );
3405
-            $query_args = array('action' => $action);
3406
-            $this->_redirect_after_action('', '', '', $query_args, true);
3407
-        }
3408
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3409
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3410
-        $attendee     = $registration->attendee();
3411
-        //remove relation of existing attendee on registration
3412
-        $registration->_remove_relation_to($attendee, 'Attendee');
3413
-        //new attendee
3414
-        $new_attendee = clone $attendee;
3415
-        $new_attendee->set('ATT_ID', 0);
3416
-        $new_attendee->save();
3417
-        //add new attendee to reg
3418
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3419
-        EE_Error::add_success(
3420
-            esc_html__(
3421
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3422
-                'event_espresso'
3423
-            )
3424
-        );
3425
-        //redirect to edit page for attendee
3426
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3427
-        $this->_redirect_after_action('', '', '', $query_args, true);
3428
-    }
3429
-
3430
-
3431
-    /**
3432
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3433
-     * @param int      $post_id
3434
-     * @param WP_POST $post
3435
-     * @throws DomainException
3436
-     * @throws EE_Error
3437
-     * @throws InvalidArgumentException
3438
-     * @throws InvalidDataTypeException
3439
-     * @throws InvalidInterfaceException
3440
-     * @throws LogicException
3441
-     * @throws InvalidFormSubmissionException
3442
-     */
3443
-    protected function _insert_update_cpt_item($post_id, $post)
3444
-    {
3445
-        $success  = true;
3446
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3447
-            ? EEM_Attendee::instance()->get_one_by_ID($post_id)
3448
-            : null;
3449
-        //for attendee updates
3450
-        if ($attendee instanceof EE_Attendee) {
3451
-            //note we should only be UPDATING attendees at this point.
3452
-            $updated_fields = array(
3453
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3454
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3455
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3456
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3457
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3458
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3459
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3460
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3461
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3462
-            );
3463
-            foreach ($updated_fields as $field => $value) {
3464
-                $attendee->set($field, $value);
3465
-            }
3466
-
3467
-            //process contact details metabox form handler (which will also save the attendee)
3468
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3469
-            $success = $contact_details_form->process($this->_req_data);
3470
-
3471
-            $attendee_update_callbacks = apply_filters(
3472
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3473
-                array()
3474
-            );
3475
-            foreach ($attendee_update_callbacks as $a_callback) {
3476
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3477
-                    throw new EE_Error(
3478
-                        sprintf(
3479
-                            esc_html__(
3480
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3481
-                                'event_espresso'
3482
-                            ),
3483
-                            $a_callback
3484
-                        )
3485
-                    );
3486
-                }
3487
-            }
3488
-        }
3489
-
3490
-        if ($success === false) {
3491
-            EE_Error::add_error(
3492
-                esc_html__(
3493
-                    'Something went wrong with updating the meta table data for the registration.',
3494
-                    'event_espresso'
3495
-                ),
3496
-                __FILE__, __FUNCTION__, __LINE__
3497
-            );
3498
-        }
3499
-    }
3500
-
3501
-
3502
-    public function trash_cpt_item($post_id)
3503
-    {
3504
-    }
3505
-
3506
-
3507
-    public function delete_cpt_item($post_id)
3508
-    {
3509
-    }
3510
-
3511
-
3512
-    public function restore_cpt_item($post_id)
3513
-    {
3514
-    }
3515
-
3516
-
3517
-    protected function _restore_cpt_item($post_id, $revision_id)
3518
-    {
3519
-    }
3520
-
3521
-
3522
-    public function attendee_editor_metaboxes()
3523
-    {
3524
-        $this->verify_cpt_object();
3525
-        remove_meta_box(
3526
-            'postexcerpt',
3527
-            esc_html__('Excerpt', 'event_espresso'),
3528
-            'post_excerpt_meta_box',
3529
-            $this->_cpt_routes[$this->_req_action],
3530
-            'normal',
3531
-            'core'
3532
-        );
3533
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3534
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3535
-            add_meta_box(
3536
-                'postexcerpt',
3537
-                esc_html__('Short Biography', 'event_espresso'),
3538
-                'post_excerpt_meta_box',
3539
-                $this->_cpt_routes[$this->_req_action],
3540
-                'normal'
3541
-            );
3542
-        }
3543
-        if (post_type_supports('espresso_attendees', 'comments')) {
3544
-            add_meta_box(
3545
-                'commentsdiv',
3546
-                esc_html__('Notes on the Contact', 'event_espresso'),
3547
-                'post_comment_meta_box',
3548
-                $this->_cpt_routes[$this->_req_action],
3549
-                'normal',
3550
-                'core'
3551
-            );
3552
-        }
3553
-        add_meta_box(
3554
-            'attendee_contact_info',
3555
-            esc_html__('Contact Info', 'event_espresso'),
3556
-            array($this, 'attendee_contact_info'),
3557
-            $this->_cpt_routes[$this->_req_action],
3558
-            'side',
3559
-            'core'
3560
-        );
3561
-        add_meta_box(
3562
-            'attendee_details_address',
3563
-            esc_html__('Address Details', 'event_espresso'),
3564
-            array($this, 'attendee_address_details'),
3565
-            $this->_cpt_routes[$this->_req_action],
3566
-            'normal',
3567
-            'core'
3568
-        );
3569
-        add_meta_box(
3570
-            'attendee_registrations',
3571
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3572
-            array($this, 'attendee_registrations_meta_box'),
3573
-            $this->_cpt_routes[$this->_req_action],
3574
-            'normal',
3575
-            'high'
3576
-        );
3577
-    }
3578
-
3579
-
3580
-    /**
3581
-     * Metabox for attendee contact info
3582
-     *
3583
-     * @param  WP_Post $post wp post object
3584
-     * @return string attendee contact info ( and form )
3585
-     * @throws EE_Error
3586
-     * @throws InvalidArgumentException
3587
-     * @throws InvalidDataTypeException
3588
-     * @throws InvalidInterfaceException
3589
-     * @throws LogicException
3590
-     * @throws DomainException
3591
-     */
3592
-    public function attendee_contact_info($post)
3593
-    {
3594
-        //get attendee object ( should already have it )
3595
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3596
-        $form->enqueueStylesAndScripts();
3597
-        echo $form->display();
3598
-    }
3599
-
3600
-
3601
-    /**
3602
-     * Return form handler for the contact details metabox
3603
-     *
3604
-     * @param EE_Attendee $attendee
3605
-     * @return AttendeeContactDetailsMetaboxFormHandler
3606
-     * @throws DomainException
3607
-     * @throws InvalidArgumentException
3608
-     * @throws InvalidDataTypeException
3609
-     * @throws InvalidInterfaceException
3610
-     */
3611
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3612
-    {
3613
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3614
-    }
3615
-
3616
-
3617
-    /**
3618
-     * Metabox for attendee details
3619
-     *
3620
-     * @param  WP_Post $post wp post object
3621
-     * @throws DomainException
3622
-     */
3623
-    public function attendee_address_details($post)
3624
-    {
3625
-        //get attendee object (should already have it)
3626
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3627
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3628
-            new EE_Question_Form_Input(
3629
-                EE_Question::new_instance(
3630
-                    array(
3631
-                        'QST_ID'           => 0,
3632
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3633
-                        'QST_system'       => 'admin-state',
3634
-                    )
3635
-                ),
3636
-                EE_Answer::new_instance(
3637
-                    array(
3638
-                        'ANS_ID'    => 0,
3639
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3640
-                    )
3641
-                ),
3642
-                array(
3643
-                    'input_id'       => 'STA_ID',
3644
-                    'input_name'     => 'STA_ID',
3645
-                    'input_prefix'   => '',
3646
-                    'append_qstn_id' => false,
3647
-                )
3648
-            )
3649
-        );
3650
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3651
-            new EE_Question_Form_Input(
3652
-                EE_Question::new_instance(
3653
-                    array(
3654
-                        'QST_ID'           => 0,
3655
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3656
-                        'QST_system'       => 'admin-country',
3657
-                    )
3658
-                ),
3659
-                EE_Answer::new_instance(
3660
-                    array(
3661
-                        'ANS_ID'    => 0,
3662
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3663
-                    )
3664
-                ),
3665
-                array(
3666
-                    'input_id'       => 'CNT_ISO',
3667
-                    'input_name'     => 'CNT_ISO',
3668
-                    'input_prefix'   => '',
3669
-                    'append_qstn_id' => false,
3670
-                )
3671
-            )
3672
-        );
3673
-        $template                             =
3674
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3675
-        EEH_Template::display_template($template, $this->_template_args);
3676
-    }
3677
-
3678
-
3679
-    /**
3680
-     *        _attendee_details
3681
-     *
3682
-     * @access protected
3683
-     * @param $post
3684
-     * @return void
3685
-     * @throws DomainException
3686
-     * @throws EE_Error
3687
-     */
3688
-    public function attendee_registrations_meta_box($post)
3689
-    {
3690
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3691
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3692
-        $template                              =
3693
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3694
-        EEH_Template::display_template($template, $this->_template_args);
3695
-    }
3696
-
3697
-
3698
-    /**
3699
-     * add in the form fields for the attendee edit
3700
-     *
3701
-     * @param  WP_Post $post wp post object
3702
-     * @return string html for new form.
3703
-     * @throws DomainException
3704
-     */
3705
-    public function after_title_form_fields($post)
3706
-    {
3707
-        if ($post->post_type == 'espresso_attendees') {
3708
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3709
-            $template_args['attendee'] = $this->_cpt_model_obj;
3710
-            EEH_Template::display_template($template, $template_args);
3711
-        }
3712
-    }
3713
-
3714
-
3715
-    /**
3716
-     *        _trash_or_restore_attendee
3717
-     *
3718
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3719
-     * @return void
3720
-     * @throws EE_Error
3721
-     * @throws InvalidArgumentException
3722
-     * @throws InvalidDataTypeException
3723
-     * @throws InvalidInterfaceException
3724
-     * @access protected
3725
-     */
3726
-    protected function _trash_or_restore_attendees($trash = true)
3727
-    {
3728
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3729
-        $ATT_MDL = EEM_Attendee::instance();
3730
-        $success = 1;
3731
-        //Checkboxes
3732
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3733
-            // if array has more than one element than success message should be plural
3734
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3735
-            // cycle thru checkboxes
3736
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3737
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3738
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3739
-                if ( ! $updated) {
3740
-                    $success = 0;
3741
-                }
3742
-            }
3743
-        } else {
3744
-            // grab single id and delete
3745
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3746
-            //get attendee
3747
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3748
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3749
-            $updated = $att->save();
3750
-            if ( ! $updated) {
3751
-                $success = 0;
3752
-            }
3753
-        }
3754
-        $what        = $success > 1
3755
-            ? esc_html__('Contacts', 'event_espresso')
3756
-            : esc_html__('Contact', 'event_espresso');
3757
-        $action_desc = $trash
3758
-            ? esc_html__('moved to the trash', 'event_espresso')
3759
-            : esc_html__('restored', 'event_espresso');
3760
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3761
-    }
2920
+		}
2921
+		$template_args = array(
2922
+			'title'                    => '',
2923
+			'content'                  => '',
2924
+			'step_button_text'         => '',
2925
+			'show_notification_toggle' => false,
2926
+		);
2927
+		//to indicate we're processing a new registration
2928
+		$hidden_fields = array(
2929
+			'processing_registration' => array(
2930
+				'type'  => 'hidden',
2931
+				'value' => 0,
2932
+			),
2933
+			'event_id'                => array(
2934
+				'type'  => 'hidden',
2935
+				'value' => $this->_reg_event->ID(),
2936
+			),
2937
+		);
2938
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2939
+		$cart = EE_Registry::instance()->SSN->cart();
2940
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2941
+		switch ($step) {
2942
+			case 'ticket' :
2943
+				$hidden_fields['processing_registration']['value'] = 1;
2944
+				$template_args['title']                            = esc_html__(
2945
+					'Step One: Select the Ticket for this registration',
2946
+					'event_espresso'
2947
+				);
2948
+				$template_args['content']                          =
2949
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2950
+				$template_args['step_button_text']                 = esc_html__(
2951
+					'Add Tickets and Continue to Registrant Details',
2952
+					'event_espresso'
2953
+				);
2954
+				$template_args['show_notification_toggle']         = false;
2955
+				break;
2956
+			case 'questions' :
2957
+				$hidden_fields['processing_registration']['value'] = 2;
2958
+				$template_args['title']                            = esc_html__(
2959
+					'Step Two: Add Registrant Details for this Registration',
2960
+					'event_espresso'
2961
+				);
2962
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2963
+				// properly by the first process_reg_step run.
2964
+				$template_args['content']                  =
2965
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2966
+				$template_args['step_button_text']         = esc_html__(
2967
+					'Save Registration and Continue to Details',
2968
+					'event_espresso'
2969
+				);
2970
+				$template_args['show_notification_toggle'] = true;
2971
+				break;
2972
+		}
2973
+		//we come back to the process_registration_step route.
2974
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2975
+		return EEH_Template::display_template(
2976
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2977
+			$template_args,
2978
+			true
2979
+		);
2980
+	}
2981
+
2982
+
2983
+	/**
2984
+	 *        set_reg_event
2985
+	 *
2986
+	 * @access private
2987
+	 * @return bool
2988
+	 * @throws EE_Error
2989
+	 * @throws InvalidArgumentException
2990
+	 * @throws InvalidDataTypeException
2991
+	 * @throws InvalidInterfaceException
2992
+	 */
2993
+	private function _set_reg_event()
2994
+	{
2995
+		if (is_object($this->_reg_event)) {
2996
+			return true;
2997
+		}
2998
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2999
+		if ( ! $EVT_ID) {
3000
+			return false;
3001
+		}
3002
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3003
+		return true;
3004
+	}
3005
+
3006
+
3007
+	/**
3008
+	 * process_reg_step
3009
+	 *
3010
+	 * @access        public
3011
+	 * @return string
3012
+	 * @throws DomainException
3013
+	 * @throws EE_Error
3014
+	 * @throws InvalidArgumentException
3015
+	 * @throws InvalidDataTypeException
3016
+	 * @throws InvalidInterfaceException
3017
+	 * @throws ReflectionException
3018
+	 * @throws RuntimeException
3019
+	 */
3020
+	public function process_reg_step()
3021
+	{
3022
+		EE_System::do_not_cache();
3023
+		$this->_set_reg_event();
3024
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3025
+		EE_Registry::instance()->REQ->set('uts', time());
3026
+		//what step are we on?
3027
+		$cart = EE_Registry::instance()->SSN->cart();
3028
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3029
+		//if doing ajax then we need to verify the nonce
3030
+		if (defined('DOING_AJAX')) {
3031
+			$nonce = isset($this->_req_data[$this->_req_nonce])
3032
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3033
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3034
+		}
3035
+		switch ($step) {
3036
+			case 'ticket' :
3037
+				//process ticket selection
3038
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3039
+				if ($success) {
3040
+					EE_Error::add_success(
3041
+						esc_html__(
3042
+							'Tickets Selected. Now complete the registration.',
3043
+							'event_espresso'
3044
+						)
3045
+					);
3046
+				} else {
3047
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3048
+				}
3049
+				if (defined('DOING_AJAX')) {
3050
+					$this->new_registration(); //display next step
3051
+				} else {
3052
+					$query_args = array(
3053
+						'action'                  => 'new_registration',
3054
+						'processing_registration' => 1,
3055
+						'event_id'                => $this->_reg_event->ID(),
3056
+						'uts'                     => time(),
3057
+					);
3058
+					$this->_redirect_after_action(
3059
+						false,
3060
+						'',
3061
+						'',
3062
+						$query_args,
3063
+						true
3064
+					);
3065
+				}
3066
+				break;
3067
+			case 'questions' :
3068
+				if (! isset(
3069
+					$this->_req_data['txn_reg_status_change'],
3070
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
3071
+				) {
3072
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3073
+				}
3074
+				//process registration
3075
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3076
+				if ($cart instanceof EE_Cart) {
3077
+					$grand_total = $cart->get_cart_grand_total();
3078
+					if ($grand_total instanceof EE_Line_Item) {
3079
+						$grand_total->save_this_and_descendants_to_txn();
3080
+					}
3081
+				}
3082
+				if ( ! $transaction instanceof EE_Transaction) {
3083
+					$query_args = array(
3084
+						'action'                  => 'new_registration',
3085
+						'processing_registration' => 2,
3086
+						'event_id'                => $this->_reg_event->ID(),
3087
+						'uts'                     => time(),
3088
+					);
3089
+					if (defined('DOING_AJAX')) {
3090
+						//display registration form again because there are errors (maybe validation?)
3091
+						$this->new_registration();
3092
+						return;
3093
+					} else {
3094
+						$this->_redirect_after_action(
3095
+							false,
3096
+							'',
3097
+							'',
3098
+							$query_args,
3099
+							true
3100
+						);
3101
+						return;
3102
+					}
3103
+				}
3104
+				// maybe update status, and make sure to save transaction if not done already
3105
+				if ( ! $transaction->update_status_based_on_total_paid()) {
3106
+					$transaction->save();
3107
+				}
3108
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3109
+				$this->_req_data = array();
3110
+				$query_args      = array(
3111
+					'action'        => 'redirect_to_txn',
3112
+					'TXN_ID'        => $transaction->ID(),
3113
+					'EVT_ID'        => $this->_reg_event->ID(),
3114
+					'event_name'    => urlencode($this->_reg_event->name()),
3115
+					'redirect_from' => 'new_registration',
3116
+				);
3117
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3118
+				break;
3119
+		}
3120
+		//what are you looking here for?  Should be nothing to do at this point.
3121
+	}
3122
+
3123
+
3124
+	/**
3125
+	 * redirect_to_txn
3126
+	 *
3127
+	 * @access public
3128
+	 * @return void
3129
+	 * @throws EE_Error
3130
+	 * @throws InvalidArgumentException
3131
+	 * @throws InvalidDataTypeException
3132
+	 * @throws InvalidInterfaceException
3133
+	 */
3134
+	public function redirect_to_txn()
3135
+	{
3136
+		EE_System::do_not_cache();
3137
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3138
+		$query_args = array(
3139
+			'action' => 'view_transaction',
3140
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3141
+			'page'   => 'espresso_transactions',
3142
+		);
3143
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3144
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3145
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3146
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3147
+		}
3148
+		EE_Error::add_success(
3149
+			esc_html__(
3150
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3151
+				'event_espresso'
3152
+			)
3153
+		);
3154
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3155
+	}
3156
+
3157
+
3158
+	/**
3159
+	 *        generates HTML for the Attendee Contact List
3160
+	 *
3161
+	 * @access protected
3162
+	 * @return void
3163
+	 */
3164
+	protected function _attendee_contact_list_table()
3165
+	{
3166
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3167
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3168
+		$this->display_admin_list_table_page_with_no_sidebar();
3169
+	}
3170
+
3171
+
3172
+	/**
3173
+	 *        get_attendees
3174
+	 *
3175
+	 * @param      $per_page
3176
+	 * @param bool $count whether to return count or data.
3177
+	 * @param bool $trash
3178
+	 * @return array
3179
+	 * @throws EE_Error
3180
+	 * @throws InvalidArgumentException
3181
+	 * @throws InvalidDataTypeException
3182
+	 * @throws InvalidInterfaceException
3183
+	 * @access public
3184
+	 */
3185
+	public function get_attendees($per_page, $count = false, $trash = false)
3186
+	{
3187
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3188
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3189
+		$ATT_MDL                    = EEM_Attendee::instance();
3190
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3191
+		switch ($this->_req_data['orderby']) {
3192
+			case 'ATT_ID':
3193
+				$orderby = 'ATT_ID';
3194
+				break;
3195
+			case 'ATT_fname':
3196
+				$orderby = 'ATT_fname';
3197
+				break;
3198
+			case 'ATT_email':
3199
+				$orderby = 'ATT_email';
3200
+				break;
3201
+			case 'ATT_city':
3202
+				$orderby = 'ATT_city';
3203
+				break;
3204
+			case 'STA_ID':
3205
+				$orderby = 'STA_ID';
3206
+				break;
3207
+			case 'CNT_ID':
3208
+				$orderby = 'CNT_ID';
3209
+				break;
3210
+			default:
3211
+				$orderby = 'ATT_lname';
3212
+		}
3213
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3214
+			? $this->_req_data['order']
3215
+			: 'ASC';
3216
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3217
+			? $this->_req_data['paged']
3218
+			: 1;
3219
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3220
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3221
+			? $this->_req_data['perpage']
3222
+			: $per_page;
3223
+		$_where       = array();
3224
+		if ( ! empty($this->_req_data['s'])) {
3225
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3226
+			$_where['OR'] = array(
3227
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3228
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3229
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3230
+				'ATT_fname'                         => array('LIKE', $sstr),
3231
+				'ATT_lname'                         => array('LIKE', $sstr),
3232
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3233
+				'ATT_email'                         => array('LIKE', $sstr),
3234
+				'ATT_address'                       => array('LIKE', $sstr),
3235
+				'ATT_address2'                      => array('LIKE', $sstr),
3236
+				'ATT_city'                          => array('LIKE', $sstr),
3237
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3238
+				'State.STA_name'                    => array('LIKE', $sstr),
3239
+				'ATT_phone'                         => array('LIKE', $sstr),
3240
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3241
+				'Registration.REG_code'             => array('LIKE', $sstr),
3242
+				'Registration.REG_count'            => array('LIKE', $sstr),
3243
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3244
+			);
3245
+		}
3246
+		$offset = ($current_page - 1) * $per_page;
3247
+		$limit  = $count ? null : array($offset, $per_page);
3248
+		if ($trash) {
3249
+			$_where['status'] = array('!=', 'publish');
3250
+			$all_attendees    = $count
3251
+				? $ATT_MDL->count(array(
3252
+					$_where,
3253
+					'order_by' => array($orderby => $sort),
3254
+					'limit'    => $limit,
3255
+				), 'ATT_ID', true)
3256
+				: $ATT_MDL->get_all(array(
3257
+					$_where,
3258
+					'order_by' => array($orderby => $sort),
3259
+					'limit'    => $limit,
3260
+				));
3261
+		} else {
3262
+			$_where['status'] = array('IN', array('publish'));
3263
+			$all_attendees    = $count
3264
+				? $ATT_MDL->count(array(
3265
+					$_where,
3266
+					'order_by' => array($orderby => $sort),
3267
+					'limit'    => $limit,
3268
+				), 'ATT_ID', true)
3269
+				: $ATT_MDL->get_all(array(
3270
+					$_where,
3271
+					'order_by' => array($orderby => $sort),
3272
+					'limit'    => $limit,
3273
+				));
3274
+		}
3275
+		return $all_attendees;
3276
+	}
3277
+
3278
+
3279
+	/**
3280
+	 * This is just taking care of resending the registration confirmation
3281
+	 *
3282
+	 * @access protected
3283
+	 * @return void
3284
+	 */
3285
+	protected function _resend_registration()
3286
+	{
3287
+		$this->_process_resend_registration();
3288
+		$query_args = isset($this->_req_data['redirect_to'])
3289
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3290
+			: array('action' => 'default');
3291
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3292
+	}
3293
+
3294
+	/**
3295
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3296
+	 * to use when selecting registrations
3297
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3298
+	 *                                                     the query parameters from the request
3299
+	 * @return void ends the request with a redirect or download
3300
+	 */
3301
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3302
+	{
3303
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3304
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3305
+				array(
3306
+					'page'        => 'espresso_batch',
3307
+					'batch'       => 'file',
3308
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3309
+					'filters'     => urlencode(
3310
+						serialize(
3311
+							call_user_func(
3312
+								array( $this, $method_name_for_getting_query_params ),
3313
+								EEH_Array::is_set(
3314
+									$this->_req_data,
3315
+									'filters',
3316
+									array()
3317
+								)
3318
+							)
3319
+						)
3320
+				),
3321
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3322
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3323
+				'return_url'  => urlencode($this->_req_data['return_url']),
3324
+			)));
3325
+		} else {
3326
+			$new_request_args = array(
3327
+				'export' => 'report',
3328
+				'action' => 'registrations_report_for_event',
3329
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3330
+			);
3331
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3332
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3333
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3334
+				$EE_Export = EE_Export::instance($this->_req_data);
3335
+				$EE_Export->export();
3336
+			}
3337
+		}
3338
+	}
3339
+
3340
+
3341
+
3342
+	/**
3343
+	 * Creates a registration report using only query parameters in the request
3344
+	 * @return void
3345
+	 */
3346
+	public function _registrations_report()
3347
+	{
3348
+		$this->_registrations_report_base('_get_registration_query_parameters');
3349
+	}
3350
+
3351
+
3352
+	public function _contact_list_export()
3353
+	{
3354
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3355
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3356
+			$EE_Export = EE_Export::instance($this->_req_data);
3357
+			$EE_Export->export_attendees();
3358
+		}
3359
+	}
3360
+
3361
+
3362
+	public function _contact_list_report()
3363
+	{
3364
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3365
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3366
+				'page'        => 'espresso_batch',
3367
+				'batch'       => 'file',
3368
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3369
+				'return_url'  => urlencode($this->_req_data['return_url']),
3370
+			)));
3371
+		} else {
3372
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3373
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3374
+				$EE_Export = EE_Export::instance($this->_req_data);
3375
+				$EE_Export->report_attendees();
3376
+			}
3377
+		}
3378
+	}
3379
+
3380
+
3381
+
3382
+
3383
+
3384
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3385
+	/**
3386
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3387
+	 *
3388
+	 * @return void
3389
+	 * @throws EE_Error
3390
+	 * @throws InvalidArgumentException
3391
+	 * @throws InvalidDataTypeException
3392
+	 * @throws InvalidInterfaceException
3393
+	 */
3394
+	protected function _duplicate_attendee()
3395
+	{
3396
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3397
+		//verify we have necessary info
3398
+		if (empty($this->_req_data['_REG_ID'])) {
3399
+			EE_Error::add_error(
3400
+				esc_html__(
3401
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3402
+					'event_espresso'
3403
+				), __FILE__, __LINE__, __FUNCTION__
3404
+			);
3405
+			$query_args = array('action' => $action);
3406
+			$this->_redirect_after_action('', '', '', $query_args, true);
3407
+		}
3408
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3409
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3410
+		$attendee     = $registration->attendee();
3411
+		//remove relation of existing attendee on registration
3412
+		$registration->_remove_relation_to($attendee, 'Attendee');
3413
+		//new attendee
3414
+		$new_attendee = clone $attendee;
3415
+		$new_attendee->set('ATT_ID', 0);
3416
+		$new_attendee->save();
3417
+		//add new attendee to reg
3418
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3419
+		EE_Error::add_success(
3420
+			esc_html__(
3421
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3422
+				'event_espresso'
3423
+			)
3424
+		);
3425
+		//redirect to edit page for attendee
3426
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3427
+		$this->_redirect_after_action('', '', '', $query_args, true);
3428
+	}
3429
+
3430
+
3431
+	/**
3432
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3433
+	 * @param int      $post_id
3434
+	 * @param WP_POST $post
3435
+	 * @throws DomainException
3436
+	 * @throws EE_Error
3437
+	 * @throws InvalidArgumentException
3438
+	 * @throws InvalidDataTypeException
3439
+	 * @throws InvalidInterfaceException
3440
+	 * @throws LogicException
3441
+	 * @throws InvalidFormSubmissionException
3442
+	 */
3443
+	protected function _insert_update_cpt_item($post_id, $post)
3444
+	{
3445
+		$success  = true;
3446
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3447
+			? EEM_Attendee::instance()->get_one_by_ID($post_id)
3448
+			: null;
3449
+		//for attendee updates
3450
+		if ($attendee instanceof EE_Attendee) {
3451
+			//note we should only be UPDATING attendees at this point.
3452
+			$updated_fields = array(
3453
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3454
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3455
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3456
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3457
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3458
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3459
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3460
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3461
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3462
+			);
3463
+			foreach ($updated_fields as $field => $value) {
3464
+				$attendee->set($field, $value);
3465
+			}
3466
+
3467
+			//process contact details metabox form handler (which will also save the attendee)
3468
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3469
+			$success = $contact_details_form->process($this->_req_data);
3470
+
3471
+			$attendee_update_callbacks = apply_filters(
3472
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3473
+				array()
3474
+			);
3475
+			foreach ($attendee_update_callbacks as $a_callback) {
3476
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3477
+					throw new EE_Error(
3478
+						sprintf(
3479
+							esc_html__(
3480
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3481
+								'event_espresso'
3482
+							),
3483
+							$a_callback
3484
+						)
3485
+					);
3486
+				}
3487
+			}
3488
+		}
3489
+
3490
+		if ($success === false) {
3491
+			EE_Error::add_error(
3492
+				esc_html__(
3493
+					'Something went wrong with updating the meta table data for the registration.',
3494
+					'event_espresso'
3495
+				),
3496
+				__FILE__, __FUNCTION__, __LINE__
3497
+			);
3498
+		}
3499
+	}
3500
+
3501
+
3502
+	public function trash_cpt_item($post_id)
3503
+	{
3504
+	}
3505
+
3506
+
3507
+	public function delete_cpt_item($post_id)
3508
+	{
3509
+	}
3510
+
3511
+
3512
+	public function restore_cpt_item($post_id)
3513
+	{
3514
+	}
3515
+
3516
+
3517
+	protected function _restore_cpt_item($post_id, $revision_id)
3518
+	{
3519
+	}
3520
+
3521
+
3522
+	public function attendee_editor_metaboxes()
3523
+	{
3524
+		$this->verify_cpt_object();
3525
+		remove_meta_box(
3526
+			'postexcerpt',
3527
+			esc_html__('Excerpt', 'event_espresso'),
3528
+			'post_excerpt_meta_box',
3529
+			$this->_cpt_routes[$this->_req_action],
3530
+			'normal',
3531
+			'core'
3532
+		);
3533
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3534
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3535
+			add_meta_box(
3536
+				'postexcerpt',
3537
+				esc_html__('Short Biography', 'event_espresso'),
3538
+				'post_excerpt_meta_box',
3539
+				$this->_cpt_routes[$this->_req_action],
3540
+				'normal'
3541
+			);
3542
+		}
3543
+		if (post_type_supports('espresso_attendees', 'comments')) {
3544
+			add_meta_box(
3545
+				'commentsdiv',
3546
+				esc_html__('Notes on the Contact', 'event_espresso'),
3547
+				'post_comment_meta_box',
3548
+				$this->_cpt_routes[$this->_req_action],
3549
+				'normal',
3550
+				'core'
3551
+			);
3552
+		}
3553
+		add_meta_box(
3554
+			'attendee_contact_info',
3555
+			esc_html__('Contact Info', 'event_espresso'),
3556
+			array($this, 'attendee_contact_info'),
3557
+			$this->_cpt_routes[$this->_req_action],
3558
+			'side',
3559
+			'core'
3560
+		);
3561
+		add_meta_box(
3562
+			'attendee_details_address',
3563
+			esc_html__('Address Details', 'event_espresso'),
3564
+			array($this, 'attendee_address_details'),
3565
+			$this->_cpt_routes[$this->_req_action],
3566
+			'normal',
3567
+			'core'
3568
+		);
3569
+		add_meta_box(
3570
+			'attendee_registrations',
3571
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3572
+			array($this, 'attendee_registrations_meta_box'),
3573
+			$this->_cpt_routes[$this->_req_action],
3574
+			'normal',
3575
+			'high'
3576
+		);
3577
+	}
3578
+
3579
+
3580
+	/**
3581
+	 * Metabox for attendee contact info
3582
+	 *
3583
+	 * @param  WP_Post $post wp post object
3584
+	 * @return string attendee contact info ( and form )
3585
+	 * @throws EE_Error
3586
+	 * @throws InvalidArgumentException
3587
+	 * @throws InvalidDataTypeException
3588
+	 * @throws InvalidInterfaceException
3589
+	 * @throws LogicException
3590
+	 * @throws DomainException
3591
+	 */
3592
+	public function attendee_contact_info($post)
3593
+	{
3594
+		//get attendee object ( should already have it )
3595
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3596
+		$form->enqueueStylesAndScripts();
3597
+		echo $form->display();
3598
+	}
3599
+
3600
+
3601
+	/**
3602
+	 * Return form handler for the contact details metabox
3603
+	 *
3604
+	 * @param EE_Attendee $attendee
3605
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3606
+	 * @throws DomainException
3607
+	 * @throws InvalidArgumentException
3608
+	 * @throws InvalidDataTypeException
3609
+	 * @throws InvalidInterfaceException
3610
+	 */
3611
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3612
+	{
3613
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3614
+	}
3615
+
3616
+
3617
+	/**
3618
+	 * Metabox for attendee details
3619
+	 *
3620
+	 * @param  WP_Post $post wp post object
3621
+	 * @throws DomainException
3622
+	 */
3623
+	public function attendee_address_details($post)
3624
+	{
3625
+		//get attendee object (should already have it)
3626
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3627
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3628
+			new EE_Question_Form_Input(
3629
+				EE_Question::new_instance(
3630
+					array(
3631
+						'QST_ID'           => 0,
3632
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3633
+						'QST_system'       => 'admin-state',
3634
+					)
3635
+				),
3636
+				EE_Answer::new_instance(
3637
+					array(
3638
+						'ANS_ID'    => 0,
3639
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3640
+					)
3641
+				),
3642
+				array(
3643
+					'input_id'       => 'STA_ID',
3644
+					'input_name'     => 'STA_ID',
3645
+					'input_prefix'   => '',
3646
+					'append_qstn_id' => false,
3647
+				)
3648
+			)
3649
+		);
3650
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3651
+			new EE_Question_Form_Input(
3652
+				EE_Question::new_instance(
3653
+					array(
3654
+						'QST_ID'           => 0,
3655
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3656
+						'QST_system'       => 'admin-country',
3657
+					)
3658
+				),
3659
+				EE_Answer::new_instance(
3660
+					array(
3661
+						'ANS_ID'    => 0,
3662
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3663
+					)
3664
+				),
3665
+				array(
3666
+					'input_id'       => 'CNT_ISO',
3667
+					'input_name'     => 'CNT_ISO',
3668
+					'input_prefix'   => '',
3669
+					'append_qstn_id' => false,
3670
+				)
3671
+			)
3672
+		);
3673
+		$template                             =
3674
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3675
+		EEH_Template::display_template($template, $this->_template_args);
3676
+	}
3677
+
3678
+
3679
+	/**
3680
+	 *        _attendee_details
3681
+	 *
3682
+	 * @access protected
3683
+	 * @param $post
3684
+	 * @return void
3685
+	 * @throws DomainException
3686
+	 * @throws EE_Error
3687
+	 */
3688
+	public function attendee_registrations_meta_box($post)
3689
+	{
3690
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3691
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3692
+		$template                              =
3693
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3694
+		EEH_Template::display_template($template, $this->_template_args);
3695
+	}
3696
+
3697
+
3698
+	/**
3699
+	 * add in the form fields for the attendee edit
3700
+	 *
3701
+	 * @param  WP_Post $post wp post object
3702
+	 * @return string html for new form.
3703
+	 * @throws DomainException
3704
+	 */
3705
+	public function after_title_form_fields($post)
3706
+	{
3707
+		if ($post->post_type == 'espresso_attendees') {
3708
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3709
+			$template_args['attendee'] = $this->_cpt_model_obj;
3710
+			EEH_Template::display_template($template, $template_args);
3711
+		}
3712
+	}
3713
+
3714
+
3715
+	/**
3716
+	 *        _trash_or_restore_attendee
3717
+	 *
3718
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3719
+	 * @return void
3720
+	 * @throws EE_Error
3721
+	 * @throws InvalidArgumentException
3722
+	 * @throws InvalidDataTypeException
3723
+	 * @throws InvalidInterfaceException
3724
+	 * @access protected
3725
+	 */
3726
+	protected function _trash_or_restore_attendees($trash = true)
3727
+	{
3728
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3729
+		$ATT_MDL = EEM_Attendee::instance();
3730
+		$success = 1;
3731
+		//Checkboxes
3732
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3733
+			// if array has more than one element than success message should be plural
3734
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3735
+			// cycle thru checkboxes
3736
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3737
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3738
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3739
+				if ( ! $updated) {
3740
+					$success = 0;
3741
+				}
3742
+			}
3743
+		} else {
3744
+			// grab single id and delete
3745
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3746
+			//get attendee
3747
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3748
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3749
+			$updated = $att->save();
3750
+			if ( ! $updated) {
3751
+				$success = 0;
3752
+			}
3753
+		}
3754
+		$what        = $success > 1
3755
+			? esc_html__('Contacts', 'event_espresso')
3756
+			: esc_html__('Contact', 'event_espresso');
3757
+		$action_desc = $trash
3758
+			? esc_html__('moved to the trash', 'event_espresso')
3759
+			: esc_html__('restored', 'event_espresso');
3760
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3761
+	}
3762 3762
 
3763 3763
 }
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         // when adding a new registration...
77 77
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78 78
             EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
79
+            if ( ! isset($this->_req_data['processing_registration'])
80 80
                  || absint($this->_req_data['processing_registration']) !== 1
81 81
             ) {
82 82
                 // and it's NOT the attendee information reg step
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     public function _set_page_routes()
172 172
     {
173 173
         $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
174
+        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175 175
             ? $this->_req_data['_REG_ID'] : 0;
176 176
         $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177 177
             ? $this->_req_data['reg_status_change_form']['REG_ID']
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
         //style
670 670
         wp_register_style(
671 671
             'espresso_reg',
672
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
672
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
673 673
             array('ee-admin-css'),
674 674
             EVENT_ESPRESSO_VERSION
675 675
         );
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
         //script
678 678
         wp_register_script(
679 679
             'espresso_reg',
680
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
680
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
681 681
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682 682
             EVENT_ESPRESSO_VERSION,
683 683
             true
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
         wp_deregister_style('espresso_reg');
716 716
         wp_register_style(
717 717
             'espresso_att',
718
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
718
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
719 719
             array('ee-admin-css'),
720 720
             EVENT_ESPRESSO_VERSION
721 721
         );
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
     {
728 728
         wp_register_script(
729 729
             'ee-spco-for-admin',
730
-            REG_ASSETS_URL . 'spco_for_admin.js',
730
+            REG_ASSETS_URL.'spco_for_admin.js',
731 731
             array('underscore', 'jquery'),
732 732
             EVENT_ESPRESSO_VERSION,
733 733
             true
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862 862
                 ),
863 863
             );
864
-            $this->_views['trash']      = array(
864
+            $this->_views['trash'] = array(
865 865
                 'slug'        => 'trash',
866 866
                 'label'       => esc_html__('Trash', 'event_espresso'),
867 867
                 'count'       => 0,
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         }
951 951
         $sc_items = array(
952 952
             'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
954 954
                 'desc'  => EEH_Template::pretty_status(
955 955
                     EEM_Registration::status_id_approved,
956 956
                     false,
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
                 ),
959 959
             ),
960 960
             'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
962 962
                 'desc'  => EEH_Template::pretty_status(
963 963
                     EEM_Registration::status_id_pending_payment,
964 964
                     false,
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
                 ),
967 967
             ),
968 968
             'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
970 970
                 'desc'  => EEH_Template::pretty_status(
971 971
                     EEM_Registration::status_id_wait_list,
972 972
                     false,
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 ),
975 975
             ),
976 976
             'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
978 978
                 'desc'  => EEH_Template::pretty_status(
979 979
                     EEM_Registration::status_id_incomplete,
980 980
                     false,
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 ),
983 983
             ),
984 984
             'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
986 986
                 'desc'  => EEH_Template::pretty_status(
987 987
                     EEM_Registration::status_id_not_approved,
988 988
                     false,
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
                 ),
991 991
             ),
992 992
             'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
994 994
                 'desc'  => EEH_Template::pretty_status(
995 995
                     EEM_Registration::status_id_declined,
996 996
                     false,
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
                 ),
999 999
             ),
1000 1000
             'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1002 1002
                 'desc'  => EEH_Template::pretty_status(
1003 1003
                     EEM_Registration::status_id_cancelled,
1004 1004
                     false,
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
                 'espresso_registrations_new_registration',
1028 1028
                 $EVT_ID
1029 1029
             )) {
1030
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1030
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1031 1031
                     'new_registration',
1032 1032
                     'add-registrant',
1033 1033
                     array('event_id' => $EVT_ID),
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1068 1068
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1069 1069
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1070
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1070
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1071 1071
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1072 1072
             }
1073 1073
         }
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
             'caps'                     => EEM_Registration::caps_read_admin,
1175 1175
             'default_where_conditions' => 'this_model_only',
1176 1176
         );
1177
-        if (! $count) {
1177
+        if ( ! $count) {
1178 1178
             $query_params = array_merge(
1179 1179
                 $query_params,
1180 1180
                 $this->_get_orderby_for_registrations_query(),
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
     protected function _add_event_id_to_where_conditions(array $request)
1196 1196
     {
1197 1197
         $where = array();
1198
-        if (! empty($request['event_id'])) {
1198
+        if ( ! empty($request['event_id'])) {
1199 1199
             $where['EVT_ID'] = absint($request['event_id']);
1200 1200
         }
1201 1201
         return $where;
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
     protected function _add_category_id_to_where_conditions(array $request)
1212 1212
     {
1213 1213
         $where = array();
1214
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1214
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1215 1215
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1216 1216
         }
1217 1217
         return $where;
@@ -1227,10 +1227,10 @@  discard block
 block discarded – undo
1227 1227
     protected function _add_datetime_id_to_where_conditions(array $request)
1228 1228
     {
1229 1229
         $where = array();
1230
-        if (! empty($request['datetime_id'])) {
1230
+        if ( ! empty($request['datetime_id'])) {
1231 1231
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1232 1232
         }
1233
-        if (! empty($request['DTT_ID'])) {
1233
+        if ( ! empty($request['DTT_ID'])) {
1234 1234
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1235 1235
         }
1236 1236
         return $where;
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1257 1257
          * UNLESS viewing trashed registrations.
1258 1258
          */
1259
-        if (! empty($registration_status)) {
1259
+        if ( ! empty($registration_status)) {
1260 1260
             $where['STS_ID'] = $registration_status;
1261 1261
         } else {
1262 1262
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1299,12 +1299,12 @@  discard block
 block discarded – undo
1299 1299
                 array(
1300 1300
                     EEM_Registration::instance()->convert_datetime_for_query(
1301 1301
                         'REG_date',
1302
-                        $now . ' 00:00:00',
1302
+                        $now.' 00:00:00',
1303 1303
                         'Y-m-d H:i:s'
1304 1304
                     ),
1305 1305
                     EEM_Registration::instance()->convert_datetime_for_query(
1306 1306
                         'REG_date',
1307
-                        $now . ' 23:59:59',
1307
+                        $now.' 23:59:59',
1308 1308
                         'Y-m-d H:i:s'
1309 1309
                     ),
1310 1310
                 ),
@@ -1317,12 +1317,12 @@  discard block
 block discarded – undo
1317 1317
                 array(
1318 1318
                     EEM_Registration::instance()->convert_datetime_for_query(
1319 1319
                         'REG_date',
1320
-                        $current_year_and_month . '-01 00:00:00',
1320
+                        $current_year_and_month.'-01 00:00:00',
1321 1321
                         'Y-m-d H:i:s'
1322 1322
                     ),
1323 1323
                     EEM_Registration::instance()->convert_datetime_for_query(
1324 1324
                         'REG_date',
1325
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1325
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1326 1326
                         'Y-m-d H:i:s'
1327 1327
                     ),
1328 1328
                 ),
@@ -1337,18 +1337,18 @@  discard block
 block discarded – undo
1337 1337
                 : '';
1338 1338
             //if there is not a month or year then we can't go further
1339 1339
             if ($month_requested && $year_requested) {
1340
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1340
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1341 1341
                 $where['REG_date'] = array(
1342 1342
                     'BETWEEN',
1343 1343
                     array(
1344 1344
                         EEM_Registration::instance()->convert_datetime_for_query(
1345 1345
                             'REG_date',
1346
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1346
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1347 1347
                             'Y-m-d H:i:s'
1348 1348
                         ),
1349 1349
                         EEM_Registration::instance()->convert_datetime_for_query(
1350 1350
                             'REG_date',
1351
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1351
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1352 1352
                             'Y-m-d H:i:s'
1353 1353
                         ),
1354 1354
                     ),
@@ -1368,8 +1368,8 @@  discard block
 block discarded – undo
1368 1368
     protected function _add_search_to_where_conditions(array $request)
1369 1369
     {
1370 1370
         $where = array();
1371
-        if (! empty($request['s'])) {
1372
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1371
+        if ( ! empty($request['s'])) {
1372
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1373 1373
             $where['OR*search_conditions'] = array(
1374 1374
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1375 1375
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             : $per_page;
1488 1488
 
1489 1489
         //-1 means return all results so get out if that's set.
1490
-        if ((int)$per_page === -1) {
1490
+        if ((int) $per_page === -1) {
1491 1491
             return array();
1492 1492
         }
1493 1493
         $per_page = absint($per_page);
@@ -1543,7 +1543,7 @@  discard block
 block discarded – undo
1543 1543
                 ),
1544 1544
                 REG_ADMIN_URL
1545 1545
             );
1546
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1546
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1547 1547
                 array(
1548 1548
                     'action' => 'default',
1549 1549
                     'EVT_ID' => $event_id,
@@ -1551,7 +1551,7 @@  discard block
 block discarded – undo
1551 1551
                 ),
1552 1552
                 admin_url('admin.php')
1553 1553
             );
1554
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1554
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1555 1555
                 array(
1556 1556
                     'page'   => 'espresso_events',
1557 1557
                     'action' => 'edit',
@@ -1560,12 +1560,12 @@  discard block
 block discarded – undo
1560 1560
                 admin_url('admin.php')
1561 1561
             );
1562 1562
             //next and previous links
1563
-            $next_reg                                      = $this->_registration->next(
1563
+            $next_reg = $this->_registration->next(
1564 1564
                 null,
1565 1565
                 array(),
1566 1566
                 'REG_ID'
1567 1567
             );
1568
-            $this->_template_args['next_registration']     = $next_reg
1568
+            $this->_template_args['next_registration'] = $next_reg
1569 1569
                 ? $this->_next_link(
1570 1570
                     EE_Admin_Page::add_query_args_and_nonce(
1571 1571
                         array(
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1578 1578
                 )
1579 1579
                 : '';
1580
-            $previous_reg                                  = $this->_registration->previous(
1580
+            $previous_reg = $this->_registration->previous(
1581 1581
                 null,
1582 1582
                 array(),
1583 1583
                 'REG_ID'
@@ -1595,7 +1595,7 @@  discard block
 block discarded – undo
1595 1595
                 )
1596 1596
                 : '';
1597 1597
             // grab header
1598
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1598
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1599 1599
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1600 1600
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1601 1601
                 $template_path,
@@ -1715,7 +1715,7 @@  discard block
 block discarded – undo
1715 1715
                             EEH_HTML::strong(
1716 1716
                                 $this->_registration->pretty_status(),
1717 1717
                                 '',
1718
-                                'status-' . $this->_registration->status_ID(),
1718
+                                'status-'.$this->_registration->status_ID(),
1719 1719
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1720 1720
                             )
1721 1721
                         )
@@ -1795,11 +1795,11 @@  discard block
 block discarded – undo
1795 1795
     {
1796 1796
         if (isset($this->_req_data['reg_status_change_form'])) {
1797 1797
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1798
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1798
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1799 1799
                 : array();
1800 1800
         } else {
1801 1801
             $REG_IDs = isset($this->_req_data['_REG_ID'])
1802
-                ? (array)$this->_req_data['_REG_ID']
1802
+                ? (array) $this->_req_data['_REG_ID']
1803 1803
                 : array();
1804 1804
         }
1805 1805
         // sanitize $REG_IDs
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
     {
1863 1863
         $success = false;
1864 1864
         // typecast $REG_IDs
1865
-        $REG_IDs = (array)$REG_IDs;
1865
+        $REG_IDs = (array) $REG_IDs;
1866 1866
         if ( ! empty($REG_IDs)) {
1867 1867
             $success = true;
1868 1868
             // set default status if none is passed
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
             $action,
2013 2013
             $notify
2014 2014
         );
2015
-        $method = $action . '_registration';
2015
+        $method = $action.'_registration';
2016 2016
         if (method_exists($this, $method)) {
2017 2017
             $this->$method($notify);
2018 2018
         }
@@ -2130,7 +2130,7 @@  discard block
 block discarded – undo
2130 2130
             $filtered_line_item_tree,
2131 2131
             array('EE_Registration' => $this->_registration)
2132 2132
         );
2133
-        $attendee                                = $this->_registration->attendee();
2133
+        $attendee = $this->_registration->attendee();
2134 2134
         if (EE_Registry::instance()->CAP->current_user_can(
2135 2135
             'ee_read_transaction',
2136 2136
             'espresso_transactions_view_transaction'
@@ -2209,7 +2209,7 @@  discard block
 block discarded – undo
2209 2209
                 'Payment method response',
2210 2210
                 'event_espresso'
2211 2211
             );
2212
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2212
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2213 2213
         }
2214 2214
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2215 2215
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2237,7 +2237,7 @@  discard block
 block discarded – undo
2237 2237
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2238 2238
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2239 2239
         $template_path                                                        =
2240
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2240
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2241 2241
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2242 2242
     }
2243 2243
 
@@ -2266,7 +2266,7 @@  discard block
 block discarded – undo
2266 2266
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2267 2267
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2268 2268
             $template_path                                     =
2269
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2269
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2270 2270
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2271 2271
         }
2272 2272
     }
@@ -2283,7 +2283,7 @@  discard block
 block discarded – undo
2283 2283
     public function form_before_question_group($output)
2284 2284
     {
2285 2285
         EE_Error::doing_it_wrong(
2286
-            __CLASS__ . '::' . __FUNCTION__,
2286
+            __CLASS__.'::'.__FUNCTION__,
2287 2287
             esc_html__(
2288 2288
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2289 2289
                 'event_espresso'
@@ -2308,7 +2308,7 @@  discard block
 block discarded – undo
2308 2308
     public function form_after_question_group($output)
2309 2309
     {
2310 2310
         EE_Error::doing_it_wrong(
2311
-            __CLASS__ . '::' . __FUNCTION__,
2311
+            __CLASS__.'::'.__FUNCTION__,
2312 2312
             esc_html__(
2313 2313
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2314 2314
                 'event_espresso'
@@ -2346,7 +2346,7 @@  discard block
 block discarded – undo
2346 2346
     public function form_form_field_label_wrap($label)
2347 2347
     {
2348 2348
         EE_Error::doing_it_wrong(
2349
-            __CLASS__ . '::' . __FUNCTION__,
2349
+            __CLASS__.'::'.__FUNCTION__,
2350 2350
             esc_html__(
2351 2351
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2352 2352
                 'event_espresso'
@@ -2356,7 +2356,7 @@  discard block
 block discarded – undo
2356 2356
         return '
2357 2357
 			<tr>
2358 2358
 				<th>
2359
-					' . $label . '
2359
+					' . $label.'
2360 2360
 				</th>';
2361 2361
     }
2362 2362
 
@@ -2372,7 +2372,7 @@  discard block
 block discarded – undo
2372 2372
     public function form_form_field_input__wrap($input)
2373 2373
     {
2374 2374
         EE_Error::doing_it_wrong(
2375
-            __CLASS__ . '::' . __FUNCTION__,
2375
+            __CLASS__.'::'.__FUNCTION__,
2376 2376
             esc_html__(
2377 2377
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2378 2378
                 'event_espresso'
@@ -2381,7 +2381,7 @@  discard block
 block discarded – undo
2381 2381
         );
2382 2382
         return '
2383 2383
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2384
-					' . $input . '
2384
+					' . $input.'
2385 2385
 				</td>
2386 2386
 			</tr>';
2387 2387
     }
@@ -2426,7 +2426,7 @@  discard block
 block discarded – undo
2426 2426
     protected function _get_reg_custom_questions_form($REG_ID)
2427 2427
     {
2428 2428
         if ( ! $this->_reg_custom_questions_form) {
2429
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2429
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2430 2430
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2431 2431
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2432 2432
             );
@@ -2462,7 +2462,7 @@  discard block
 block discarded – undo
2462 2462
         if ($form->is_valid()) {
2463 2463
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2464 2464
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2465
-                    $where_conditions    = array(
2465
+                    $where_conditions = array(
2466 2466
                         'QST_ID' => $question_id,
2467 2467
                         'REG_ID' => $REG_ID,
2468 2468
                     );
@@ -2503,7 +2503,7 @@  discard block
 block discarded – undo
2503 2503
         $REG = EEM_Registration::instance();
2504 2504
         //get all other registrations on this transaction, and cache
2505 2505
         //the attendees for them so we don't have to run another query using force_join
2506
-        $registrations                           = $REG->get_all(array(
2506
+        $registrations = $REG->get_all(array(
2507 2507
             array(
2508 2508
                 'TXN_ID' => $this->_registration->transaction_ID(),
2509 2509
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2527,7 +2527,7 @@  discard block
 block discarded – undo
2527 2527
             $att_nmbr = 1;
2528 2528
             foreach ($registrations as $registration) {
2529 2529
                 /* @var $registration EE_Registration */
2530
-                $attendee                                                    = $registration->attendee()
2530
+                $attendee = $registration->attendee()
2531 2531
                     ? $registration->attendee()
2532 2532
                     : EEM_Attendee::instance()
2533 2533
                                   ->create_default_object();
@@ -2540,19 +2540,19 @@  discard block
 block discarded – undo
2540 2540
                     ', ',
2541 2541
                     $attendee->full_address_as_array()
2542 2542
                 );
2543
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2543
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2544 2544
                     array(
2545 2545
                         'action' => 'edit_attendee',
2546 2546
                         'post'   => $attendee->ID(),
2547 2547
                     ),
2548 2548
                     REG_ADMIN_URL
2549 2549
                 );
2550
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2550
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2551 2551
                 $att_nmbr++;
2552 2552
             }
2553 2553
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2554 2554
         }
2555
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2555
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2556 2556
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2557 2557
     }
2558 2558
 
@@ -2595,20 +2595,20 @@  discard block
 block discarded – undo
2595 2595
         $this->_template_args['phone']             = $attendee->phone();
2596 2596
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2597 2597
         //edit link
2598
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2598
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2599 2599
             'action' => 'edit_attendee',
2600 2600
             'post'   => $attendee->ID(),
2601 2601
         ), REG_ADMIN_URL);
2602 2602
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2603 2603
         //create link
2604
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2604
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2605 2605
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2606 2606
                 'action'  => 'duplicate_attendee',
2607 2607
                 '_REG_ID' => $this->_registration->ID(),
2608 2608
             ), REG_ADMIN_URL) : '';
2609 2609
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2610 2610
         $this->_template_args['att_check']    = $att_check;
2611
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2611
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2612 2612
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2613 2613
     }
2614 2614
 
@@ -2653,7 +2653,7 @@  discard block
 block discarded – undo
2653 2653
             /** @var EE_Registration $REG */
2654 2654
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2655 2655
             $payments = $REG->registration_payments();
2656
-            if (! empty($payments)) {
2656
+            if ( ! empty($payments)) {
2657 2657
                 $name = $REG->attendee() instanceof EE_Attendee
2658 2658
                     ? $REG->attendee()->full_name()
2659 2659
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2849,7 +2849,7 @@  discard block
 block discarded – undo
2849 2849
                 'action' => 'edit',
2850 2850
                 'post'   => $this->_reg_event->ID(),
2851 2851
             ), EVENTS_ADMIN_URL);
2852
-            $edit_event_lnk                     = '<a href="'
2852
+            $edit_event_lnk = '<a href="'
2853 2853
                                                   . $edit_event_url
2854 2854
                                                   . '" title="'
2855 2855
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2867,7 +2867,7 @@  discard block
 block discarded – undo
2867 2867
         }
2868 2868
         // grab header
2869 2869
         $template_path                              =
2870
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2870
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2871 2871
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2872 2872
             $this->_template_args, true);
2873 2873
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2905,7 +2905,7 @@  discard block
 block discarded – undo
2905 2905
                 '</b>'
2906 2906
             );
2907 2907
             return '
2908
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2908
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2909 2909
 	<script >
2910 2910
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2911 2911
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2973,7 +2973,7 @@  discard block
 block discarded – undo
2973 2973
         //we come back to the process_registration_step route.
2974 2974
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2975 2975
         return EEH_Template::display_template(
2976
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2976
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2977 2977
             $template_args,
2978 2978
             true
2979 2979
         );
@@ -2995,7 +2995,7 @@  discard block
 block discarded – undo
2995 2995
         if (is_object($this->_reg_event)) {
2996 2996
             return true;
2997 2997
         }
2998
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2998
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2999 2999
         if ( ! $EVT_ID) {
3000 3000
             return false;
3001 3001
         }
@@ -3065,7 +3065,7 @@  discard block
 block discarded – undo
3065 3065
                 }
3066 3066
                 break;
3067 3067
             case 'questions' :
3068
-                if (! isset(
3068
+                if ( ! isset(
3069 3069
                     $this->_req_data['txn_reg_status_change'],
3070 3070
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
3071 3071
                 ) {
@@ -3185,7 +3185,7 @@  discard block
 block discarded – undo
3185 3185
     public function get_attendees($per_page, $count = false, $trash = false)
3186 3186
     {
3187 3187
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3188
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3188
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3189 3189
         $ATT_MDL                    = EEM_Attendee::instance();
3190 3190
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3191 3191
         switch ($this->_req_data['orderby']) {
@@ -3222,7 +3222,7 @@  discard block
 block discarded – undo
3222 3222
             : $per_page;
3223 3223
         $_where       = array();
3224 3224
         if ( ! empty($this->_req_data['s'])) {
3225
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3225
+            $sstr         = '%'.$this->_req_data['s'].'%';
3226 3226
             $_where['OR'] = array(
3227 3227
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3228 3228
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3298,9 +3298,9 @@  discard block
 block discarded – undo
3298 3298
      *                                                     the query parameters from the request
3299 3299
      * @return void ends the request with a redirect or download
3300 3300
      */
3301
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3301
+    public function _registrations_report_base($method_name_for_getting_query_params)
3302 3302
     {
3303
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3303
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3304 3304
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3305 3305
                 array(
3306 3306
                     'page'        => 'espresso_batch',
@@ -3309,7 +3309,7 @@  discard block
 block discarded – undo
3309 3309
                     'filters'     => urlencode(
3310 3310
                         serialize(
3311 3311
                             call_user_func(
3312
-                                array( $this, $method_name_for_getting_query_params ),
3312
+                                array($this, $method_name_for_getting_query_params),
3313 3313
                                 EEH_Array::is_set(
3314 3314
                                     $this->_req_data,
3315 3315
                                     'filters',
@@ -3329,8 +3329,8 @@  discard block
 block discarded – undo
3329 3329
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3330 3330
             );
3331 3331
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3332
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3333
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3332
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3333
+                require_once(EE_CLASSES.'EE_Export.class.php');
3334 3334
                 $EE_Export = EE_Export::instance($this->_req_data);
3335 3335
                 $EE_Export->export();
3336 3336
             }
@@ -3351,8 +3351,8 @@  discard block
 block discarded – undo
3351 3351
 
3352 3352
     public function _contact_list_export()
3353 3353
     {
3354
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3355
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3354
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3355
+            require_once(EE_CLASSES.'EE_Export.class.php');
3356 3356
             $EE_Export = EE_Export::instance($this->_req_data);
3357 3357
             $EE_Export->export_attendees();
3358 3358
         }
@@ -3369,8 +3369,8 @@  discard block
 block discarded – undo
3369 3369
                 'return_url'  => urlencode($this->_req_data['return_url']),
3370 3370
             )));
3371 3371
         } else {
3372
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3373
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3372
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3373
+                require_once(EE_CLASSES.'EE_Export.class.php');
3374 3374
                 $EE_Export = EE_Export::instance($this->_req_data);
3375 3375
                 $EE_Export->report_attendees();
3376 3376
             }
@@ -3452,7 +3452,7 @@  discard block
 block discarded – undo
3452 3452
             $updated_fields = array(
3453 3453
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3454 3454
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3455
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3455
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3456 3456
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3457 3457
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3458 3458
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3670,8 +3670,8 @@  discard block
 block discarded – undo
3670 3670
                 )
3671 3671
             )
3672 3672
         );
3673
-        $template                             =
3674
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3673
+        $template =
3674
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3675 3675
         EEH_Template::display_template($template, $this->_template_args);
3676 3676
     }
3677 3677
 
@@ -3690,7 +3690,7 @@  discard block
 block discarded – undo
3690 3690
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3691 3691
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3692 3692
         $template                              =
3693
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3693
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3694 3694
         EEH_Template::display_template($template, $this->_template_args);
3695 3695
     }
3696 3696
 
@@ -3705,7 +3705,7 @@  discard block
 block discarded – undo
3705 3705
     public function after_title_form_fields($post)
3706 3706
     {
3707 3707
         if ($post->post_type == 'espresso_attendees') {
3708
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3708
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3709 3709
             $template_args['attendee'] = $this->_cpt_model_obj;
3710 3710
             EEH_Template::display_template($template, $template_args);
3711 3711
         }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderFactory;
5 5
 use EventEspresso\core\services\loaders\LoaderInterface;
6 6
 
7
-if (! defined('EVENT_ESPRESSO_VERSION')) {
7
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8 8
     exit('No direct script access allowed');
9 9
 }
10 10
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     public static function instance(EE_Request $request = null, EE_Response $response = null)
131 131
     {
132 132
         // check if class object is instantiated, and instantiated properly
133
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
+        if ( ! self::$_instance instanceof EE_Dependency_Map) {
134 134
             self::$_instance = new EE_Dependency_Map($request, $response);
135 135
         }
136 136
         return self::$_instance;
@@ -185,16 +185,16 @@  discard block
 block discarded – undo
185 185
     ) {
186 186
         $class = trim($class, '\\');
187 187
         $registered = false;
188
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
189
-            self::$_instance->_dependency_map[ $class ] = array();
188
+        if (empty(self::$_instance->_dependency_map[$class])) {
189
+            self::$_instance->_dependency_map[$class] = array();
190 190
         }
191 191
         // we need to make sure that any aliases used when registering a dependency
192 192
         // get resolved to the correct class name
193
-        foreach ((array)$dependencies as $dependency => $load_source) {
193
+        foreach ((array) $dependencies as $dependency => $load_source) {
194 194
             $alias = self::$_instance->get_alias($dependency);
195 195
             if (
196 196
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
197
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
198 198
             ) {
199 199
                 unset($dependencies[$dependency]);
200 200
                 $dependencies[$alias] = $load_source;
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
208 208
         // Union is way faster than array_merge() but should be used with caution...
209 209
         // especially with numerically indexed arrays
210
-        $dependencies += self::$_instance->_dependency_map[ $class ];
210
+        $dependencies += self::$_instance->_dependency_map[$class];
211 211
         // now we need to ensure that the resulting dependencies
212 212
         // array only has the entries that are required for the class
213 213
         // so first count how many dependencies were originally registered for the class
214
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
214
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
215 215
         // if that count is non-zero (meaning dependencies were already registered)
216
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
216
+        self::$_instance->_dependency_map[$class] = $dependency_count
217 217
             // then truncate the  final array to match that count
218 218
             ? array_slice($dependencies, 0, $dependency_count)
219 219
             // otherwise just take the incoming array because nothing previously existed
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public static function register_class_loader($class_name, $loader = 'load_core')
233 233
     {
234
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235 235
             throw new DomainException(
236 236
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237 237
             );
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
             );
256 256
         }
257 257
         $class_name = self::$_instance->get_alias($class_name);
258
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
258
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
259 259
             self::$_instance->_class_loaders[$class_name] = $loader;
260 260
             return true;
261 261
         }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
     public function class_loader($class_name)
341 341
     {
342 342
         // all legacy models use load_model()
343
-        if(strpos($class_name, 'EEM_') === 0){
343
+        if (strpos($class_name, 'EEM_') === 0) {
344 344
             return 'load_model';
345 345
         }
346 346
         $class_name = $this->get_alias($class_name);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
     public function add_alias($class_name, $alias, $for_class = '')
370 370
     {
371 371
         if ($for_class !== '') {
372
-            if (! isset($this->_aliases[$for_class])) {
372
+            if ( ! isset($this->_aliases[$for_class])) {
373 373
                 $this->_aliases[$for_class] = array();
374 374
             }
375 375
             $this->_aliases[$for_class][$class_name] = $alias;
@@ -415,10 +415,10 @@  discard block
 block discarded – undo
415 415
      */
416 416
     public function get_alias($class_name = '', $for_class = '')
417 417
     {
418
-        if (! $this->has_alias($class_name, $for_class)) {
418
+        if ( ! $this->has_alias($class_name, $for_class)) {
419 419
             return $class_name;
420 420
         }
421
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
421
+        if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) {
422 422
             return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423 423
         }
424 424
         return $this->get_alias($this->_aliases[$class_name]);
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
             'EE_Front_Controller'                  => 'load_core',
680 680
             'EE_Module_Request_Router'             => 'load_core',
681 681
             'EE_Registry'                          => 'load_core',
682
-            'EE_Request'                           => function () use (&$request) {
682
+            'EE_Request'                           => function() use (&$request) {
683 683
                 return $request;
684 684
             },
685
-            'EE_Response'                          => function () use (&$response) {
685
+            'EE_Response'                          => function() use (&$response) {
686 686
                 return $response;
687 687
             },
688 688
             'EE_Request_Handler'                   => 'load_core',
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
705 705
             'EE_Message_Template_Group_Collection' => 'load_lib',
706 706
             'EE_Payment_Method_Manager'            => 'load_lib',
707
-            'EE_Messages_Generator'                => function () {
707
+            'EE_Messages_Generator'                => function() {
708 708
                 return EE_Registry::instance()->load_lib(
709 709
                     'Messages_Generator',
710 710
                     array(),
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
                     false
713 713
                 );
714 714
             },
715
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
715
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
716 716
                 return EE_Registry::instance()->load_lib(
717 717
                     'Messages_Template_Defaults',
718 718
                     $arguments,
@@ -725,22 +725,22 @@  discard block
 block discarded – undo
725 725
             // 'EEM_Message_Template_Group'           => 'load_model',
726 726
             // 'EEM_Message_Template'                 => 'load_model',
727 727
             //load_helper
728
-            'EEH_Parse_Shortcodes'                 => function () {
728
+            'EEH_Parse_Shortcodes'                 => function() {
729 729
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
730 730
                     return new EEH_Parse_Shortcodes();
731 731
                 }
732 732
                 return null;
733 733
             },
734
-            'EE_Template_Config'                   => function () {
734
+            'EE_Template_Config'                   => function() {
735 735
                 return EE_Config::instance()->template_settings;
736 736
             },
737
-            'EE_Currency_Config'                   => function () {
737
+            'EE_Currency_Config'                   => function() {
738 738
                 return EE_Config::instance()->currency;
739 739
             },
740
-            'EE_Registration_Config'                   => function () {
740
+            'EE_Registration_Config'                   => function() {
741 741
                 return EE_Config::instance()->registration;
742 742
             },
743
-            'EventEspresso\core\services\loaders\Loader' => function () {
743
+            'EventEspresso\core\services\loaders\Loader' => function() {
744 744
                 return LoaderFactory::getLoader();
745 745
             },
746 746
         );
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
             'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
794 794
             'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
795 795
         );
796
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
796
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
797 797
             $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
798 798
         }
799 799
     }
Please login to merge, or discard this patch.
Indentation   +795 added lines, -795 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderInterface;
6 6
 
7 7
 if (! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -22,800 +22,800 @@  discard block
 block discarded – undo
22 22
 class EE_Dependency_Map
23 23
 {
24 24
 
25
-    /**
26
-     * This means that the requested class dependency is not present in the dependency map
27
-     */
28
-    const not_registered = 0;
29
-
30
-    /**
31
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
32
-     */
33
-    const load_new_object = 1;
34
-
35
-    /**
36
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
37
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
38
-     */
39
-    const load_from_cache = 2;
40
-
41
-    /**
42
-     * When registering a dependency,
43
-     * this indicates to keep any existing dependencies that already exist,
44
-     * and simply discard any new dependencies declared in the incoming data
45
-     */
46
-    const KEEP_EXISTING_DEPENDENCIES = 0;
47
-
48
-    /**
49
-     * When registering a dependency,
50
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
51
-     */
52
-    const OVERWRITE_DEPENDENCIES = 1;
53
-
54
-
55
-
56
-    /**
57
-     * @type EE_Dependency_Map $_instance
58
-     */
59
-    protected static $_instance;
60
-
61
-    /**
62
-     * @type EE_Request $request
63
-     */
64
-    protected $_request;
65
-
66
-    /**
67
-     * @type EE_Response $response
68
-     */
69
-    protected $_response;
70
-
71
-    /**
72
-     * @type LoaderInterface $loader
73
-     */
74
-    protected $loader;
75
-
76
-    /**
77
-     * @type array $_dependency_map
78
-     */
79
-    protected $_dependency_map = array();
80
-
81
-    /**
82
-     * @type array $_class_loaders
83
-     */
84
-    protected $_class_loaders = array();
85
-
86
-    /**
87
-     * @type array $_aliases
88
-     */
89
-    protected $_aliases = array();
90
-
91
-
92
-
93
-    /**
94
-     * EE_Dependency_Map constructor.
95
-     *
96
-     * @param EE_Request  $request
97
-     * @param EE_Response $response
98
-     */
99
-    protected function __construct(EE_Request $request, EE_Response $response)
100
-    {
101
-        $this->_request = $request;
102
-        $this->_response = $response;
103
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
104
-        do_action('EE_Dependency_Map____construct');
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @throws InvalidDataTypeException
111
-     * @throws InvalidInterfaceException
112
-     * @throws InvalidArgumentException
113
-     */
114
-    public function initialize()
115
-    {
116
-        $this->_register_core_dependencies();
117
-        $this->_register_core_class_loaders();
118
-        $this->_register_core_aliases();
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * @singleton method used to instantiate class object
125
-     * @access    public
126
-     * @param EE_Request  $request
127
-     * @param EE_Response $response
128
-     * @return EE_Dependency_Map
129
-     */
130
-    public static function instance(EE_Request $request = null, EE_Response $response = null)
131
-    {
132
-        // check if class object is instantiated, and instantiated properly
133
-        if (! self::$_instance instanceof EE_Dependency_Map) {
134
-            self::$_instance = new EE_Dependency_Map($request, $response);
135
-        }
136
-        return self::$_instance;
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * @param LoaderInterface $loader
143
-     */
144
-    public function setLoader(LoaderInterface $loader)
145
-    {
146
-        $this->loader = $loader;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param string $class
153
-     * @param array  $dependencies
154
-     * @param int    $overwrite
155
-     * @return bool
156
-     */
157
-    public static function register_dependencies(
158
-        $class,
159
-        array $dependencies,
160
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
161
-    ) {
162
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Assigns an array of class names and corresponding load sources (new or cached)
169
-     * to the class specified by the first parameter.
170
-     * IMPORTANT !!!
171
-     * The order of elements in the incoming $dependencies array MUST match
172
-     * the order of the constructor parameters for the class in question.
173
-     * This is especially important when overriding any existing dependencies that are registered.
174
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
175
-     *
176
-     * @param string $class
177
-     * @param array  $dependencies
178
-     * @param int    $overwrite
179
-     * @return bool
180
-     */
181
-    public function registerDependencies(
182
-        $class,
183
-        array $dependencies,
184
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
185
-    ) {
186
-        $class = trim($class, '\\');
187
-        $registered = false;
188
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
189
-            self::$_instance->_dependency_map[ $class ] = array();
190
-        }
191
-        // we need to make sure that any aliases used when registering a dependency
192
-        // get resolved to the correct class name
193
-        foreach ((array)$dependencies as $dependency => $load_source) {
194
-            $alias = self::$_instance->get_alias($dependency);
195
-            if (
196
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
198
-            ) {
199
-                unset($dependencies[$dependency]);
200
-                $dependencies[$alias] = $load_source;
201
-                $registered = true;
202
-            }
203
-        }
204
-        // now add our two lists of dependencies together.
205
-        // using Union (+=) favours the arrays in precedence from left to right,
206
-        // so $dependencies is NOT overwritten because it is listed first
207
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
208
-        // Union is way faster than array_merge() but should be used with caution...
209
-        // especially with numerically indexed arrays
210
-        $dependencies += self::$_instance->_dependency_map[ $class ];
211
-        // now we need to ensure that the resulting dependencies
212
-        // array only has the entries that are required for the class
213
-        // so first count how many dependencies were originally registered for the class
214
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
215
-        // if that count is non-zero (meaning dependencies were already registered)
216
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
217
-            // then truncate the  final array to match that count
218
-            ? array_slice($dependencies, 0, $dependency_count)
219
-            // otherwise just take the incoming array because nothing previously existed
220
-            : $dependencies;
221
-        return $registered;
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * @param string $class_name
228
-     * @param string $loader
229
-     * @return bool
230
-     * @throws DomainException
231
-     */
232
-    public static function register_class_loader($class_name, $loader = 'load_core')
233
-    {
234
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235
-            throw new DomainException(
236
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237
-            );
238
-        }
239
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
240
-        if (
241
-            ! is_callable($loader)
242
-            && (
243
-                strpos($loader, 'load_') !== 0
244
-                || ! method_exists('EE_Registry', $loader)
245
-            )
246
-        ) {
247
-            throw new DomainException(
248
-                sprintf(
249
-                    esc_html__(
250
-                        '"%1$s" is not a valid loader method on EE_Registry.',
251
-                        'event_espresso'
252
-                    ),
253
-                    $loader
254
-                )
255
-            );
256
-        }
257
-        $class_name = self::$_instance->get_alias($class_name);
258
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
259
-            self::$_instance->_class_loaders[$class_name] = $loader;
260
-            return true;
261
-        }
262
-        return false;
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * @return array
269
-     */
270
-    public function dependency_map()
271
-    {
272
-        return $this->_dependency_map;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * returns TRUE if dependency map contains a listing for the provided class name
279
-     *
280
-     * @param string $class_name
281
-     * @return boolean
282
-     */
283
-    public function has($class_name = '')
284
-    {
285
-        // all legacy models have the same dependencies
286
-        if (strpos($class_name, 'EEM_') === 0) {
287
-            $class_name = 'LEGACY_MODELS';
288
-        }
289
-        return isset($this->_dependency_map[$class_name]) ? true : false;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
296
-     *
297
-     * @param string $class_name
298
-     * @param string $dependency
299
-     * @return bool
300
-     */
301
-    public function has_dependency_for_class($class_name = '', $dependency = '')
302
-    {
303
-        // all legacy models have the same dependencies
304
-        if (strpos($class_name, 'EEM_') === 0) {
305
-            $class_name = 'LEGACY_MODELS';
306
-        }
307
-        $dependency = $this->get_alias($dependency);
308
-        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
309
-            ? true
310
-            : false;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
317
-     *
318
-     * @param string $class_name
319
-     * @param string $dependency
320
-     * @return int
321
-     */
322
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
323
-    {
324
-        // all legacy models have the same dependencies
325
-        if (strpos($class_name, 'EEM_') === 0) {
326
-            $class_name = 'LEGACY_MODELS';
327
-        }
328
-        $dependency = $this->get_alias($dependency);
329
-        return $this->has_dependency_for_class($class_name, $dependency)
330
-            ? $this->_dependency_map[$class_name][$dependency]
331
-            : EE_Dependency_Map::not_registered;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param string $class_name
338
-     * @return string | Closure
339
-     */
340
-    public function class_loader($class_name)
341
-    {
342
-        // all legacy models use load_model()
343
-        if(strpos($class_name, 'EEM_') === 0){
344
-            return 'load_model';
345
-        }
346
-        $class_name = $this->get_alias($class_name);
347
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @return array
354
-     */
355
-    public function class_loaders()
356
-    {
357
-        return $this->_class_loaders;
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * adds an alias for a classname
364
-     *
365
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
366
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
367
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
368
-     */
369
-    public function add_alias($class_name, $alias, $for_class = '')
370
-    {
371
-        if ($for_class !== '') {
372
-            if (! isset($this->_aliases[$for_class])) {
373
-                $this->_aliases[$for_class] = array();
374
-            }
375
-            $this->_aliases[$for_class][$class_name] = $alias;
376
-        }
377
-        $this->_aliases[$class_name] = $alias;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * returns TRUE if the provided class name has an alias
384
-     *
385
-     * @param string $class_name
386
-     * @param string $for_class
387
-     * @return bool
388
-     */
389
-    public function has_alias($class_name = '', $for_class = '')
390
-    {
391
-        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
392
-               || (
393
-                   isset($this->_aliases[$class_name])
394
-                   && ! is_array($this->_aliases[$class_name])
395
-               );
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * returns alias for class name if one exists, otherwise returns the original classname
402
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
403
-     *  for example:
404
-     *      if the following two entries were added to the _aliases array:
405
-     *          array(
406
-     *              'interface_alias'           => 'some\namespace\interface'
407
-     *              'some\namespace\interface'  => 'some\namespace\classname'
408
-     *          )
409
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
410
-     *      to load an instance of 'some\namespace\classname'
411
-     *
412
-     * @param string $class_name
413
-     * @param string $for_class
414
-     * @return string
415
-     */
416
-    public function get_alias($class_name = '', $for_class = '')
417
-    {
418
-        if (! $this->has_alias($class_name, $for_class)) {
419
-            return $class_name;
420
-        }
421
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
422
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423
-        }
424
-        return $this->get_alias($this->_aliases[$class_name]);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
-     * This is done by using the following class constants:
433
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
435
-     */
436
-    protected function _register_core_dependencies()
437
-    {
438
-        $this->_dependency_map = array(
439
-            'EE_Request_Handler'                                                                                          => array(
440
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
441
-            ),
442
-            'EE_System'                                                                                                   => array(
443
-                'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
444
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
445
-                'EE_Capabilities'                            => EE_Dependency_Map::load_from_cache,
446
-                'EE_Request'                                 => EE_Dependency_Map::load_from_cache,
447
-                'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
448
-            ),
449
-            'EE_Session'                                                                                                  => array(
450
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
451
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
452
-            ),
453
-            'EE_Cart'                                                                                                     => array(
454
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
455
-            ),
456
-            'EE_Front_Controller'                                                                                         => array(
457
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
458
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
459
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
460
-            ),
461
-            'EE_Messenger_Collection_Loader'                                                                              => array(
462
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
463
-            ),
464
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
465
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
466
-            ),
467
-            'EE_Message_Resource_Manager'                                                                                 => array(
468
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
469
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
470
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
471
-            ),
472
-            'EE_Message_Factory'                                                                                          => array(
473
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
474
-            ),
475
-            'EE_messages'                                                                                                 => array(
476
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
-            ),
478
-            'EE_Messages_Generator'                                                                                       => array(
479
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
480
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
481
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
482
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
483
-            ),
484
-            'EE_Messages_Processor'                                                                                       => array(
485
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EE_Messages_Queue'                                                                                           => array(
488
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
489
-            ),
490
-            'EE_Messages_Template_Defaults'                                                                               => array(
491
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
492
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
493
-            ),
494
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
495
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
496
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
497
-            ),
498
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
499
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
500
-            ),
501
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
502
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
503
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
504
-            ),
505
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
506
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
507
-            ),
508
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
509
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
510
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
511
-            ),
512
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
513
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
514
-            ),
515
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
516
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
517
-            ),
518
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
519
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
522
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
525
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
528
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
531
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
534
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
537
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
540
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
543
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
546
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
549
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
552
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EE_Data_Migration_Class_Base'                                                                                => array(
555
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
556
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
557
-            ),
558
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
559
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
560
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
561
-            ),
562
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
563
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
567
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
-            ),
570
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
571
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
-            ),
574
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
575
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
-            ),
582
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
583
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
587
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
-            ),
590
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
591
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
-            ),
594
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
595
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
596
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
599
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
600
-            ),
601
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
602
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
603
-            ),
604
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
605
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
606
-            ),
607
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
608
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
611
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
-            ),
613
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
614
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
-            ),
616
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
617
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
-            ),
619
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
620
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
621
-            ),
622
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
623
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
624
-            ),
625
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
626
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
627
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
628
-            ),
629
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
630
-                null,
631
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
632
-            ),
633
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
634
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
635
-            ),
636
-            'LEGACY_MODELS'                                                   => array(
637
-                null,
638
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
639
-            ),
640
-            'EE_Module_Request_Router' => array(
641
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
642
-            ),
643
-            'EE_Registration_Processor' => array(
644
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-        );
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * Registers how core classes are loaded.
653
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
654
-     *        'EE_Request_Handler' => 'load_core'
655
-     *        'EE_Messages_Queue'  => 'load_lib'
656
-     *        'EEH_Debug_Tools'    => 'load_helper'
657
-     * or, if greater control is required, by providing a custom closure. For example:
658
-     *        'Some_Class' => function () {
659
-     *            return new Some_Class();
660
-     *        },
661
-     * This is required for instantiating dependencies
662
-     * where an interface has been type hinted in a class constructor. For example:
663
-     *        'Required_Interface' => function () {
664
-     *            return new A_Class_That_Implements_Required_Interface();
665
-     *        },
666
-     *
667
-     * @throws InvalidInterfaceException
668
-     * @throws InvalidDataTypeException
669
-     * @throws InvalidArgumentException
670
-     */
671
-    protected function _register_core_class_loaders()
672
-    {
673
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
674
-        //be used in a closure.
675
-        $request = &$this->_request;
676
-        $response = &$this->_response;
677
-        // $loader = &$this->loader;
678
-        $this->_class_loaders = array(
679
-            //load_core
680
-            'EE_Capabilities'                      => 'load_core',
681
-            'EE_Encryption'                        => 'load_core',
682
-            'EE_Front_Controller'                  => 'load_core',
683
-            'EE_Module_Request_Router'             => 'load_core',
684
-            'EE_Registry'                          => 'load_core',
685
-            'EE_Request'                           => function () use (&$request) {
686
-                return $request;
687
-            },
688
-            'EE_Response'                          => function () use (&$response) {
689
-                return $response;
690
-            },
691
-            'EE_Request_Handler'                   => 'load_core',
692
-            'EE_Session'                           => 'load_core',
693
-            'EE_Cron_Tasks'                        => 'load_core',
694
-            'EE_System'                            => 'load_core',
695
-            'EE_Maintenance_Mode'                  => 'load_core',
696
-            'EE_Register_CPTs'                     => 'load_core',
697
-            'EE_Admin'                             => 'load_core',
698
-            //load_lib
699
-            'EE_Message_Resource_Manager'          => 'load_lib',
700
-            'EE_Message_Type_Collection'           => 'load_lib',
701
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
702
-            'EE_Messenger_Collection'              => 'load_lib',
703
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
704
-            'EE_Messages_Processor'                => 'load_lib',
705
-            'EE_Message_Repository'                => 'load_lib',
706
-            'EE_Messages_Queue'                    => 'load_lib',
707
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
708
-            'EE_Message_Template_Group_Collection' => 'load_lib',
709
-            'EE_Payment_Method_Manager'            => 'load_lib',
710
-            'EE_Messages_Generator'                => function () {
711
-                return EE_Registry::instance()->load_lib(
712
-                    'Messages_Generator',
713
-                    array(),
714
-                    false,
715
-                    false
716
-                );
717
-            },
718
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
719
-                return EE_Registry::instance()->load_lib(
720
-                    'Messages_Template_Defaults',
721
-                    $arguments,
722
-                    false,
723
-                    false
724
-                );
725
-            },
726
-            //load_model
727
-            // 'EEM_Attendee'                         => 'load_model',
728
-            // 'EEM_Message_Template_Group'           => 'load_model',
729
-            // 'EEM_Message_Template'                 => 'load_model',
730
-            //load_helper
731
-            'EEH_Parse_Shortcodes'                 => function () {
732
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
733
-                    return new EEH_Parse_Shortcodes();
734
-                }
735
-                return null;
736
-            },
737
-            'EE_Template_Config'                   => function () {
738
-                return EE_Config::instance()->template_settings;
739
-            },
740
-            'EE_Currency_Config'                   => function () {
741
-                return EE_Config::instance()->currency;
742
-            },
743
-            'EE_Registration_Config'                   => function () {
744
-                return EE_Config::instance()->registration;
745
-            },
746
-            'EventEspresso\core\services\loaders\Loader' => function () {
747
-                return LoaderFactory::getLoader();
748
-            },
749
-        );
750
-    }
751
-
752
-
753
-
754
-    /**
755
-     * can be used for supplying alternate names for classes,
756
-     * or for connecting interface names to instantiable classes
757
-     */
758
-    protected function _register_core_aliases()
759
-    {
760
-        $this->_aliases = array(
761
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
762
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
763
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
764
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
765
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
766
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
767
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
768
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
769
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
770
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
771
-            'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
772
-            'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
773
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
774
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
775
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
776
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
777
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
778
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
779
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
780
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
781
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
782
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
783
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
784
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
785
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
786
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
787
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
788
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
789
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
790
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
791
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
792
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
793
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
794
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
795
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
796
-            'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
797
-            'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
798
-        );
799
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
800
-            $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
801
-        }
802
-    }
803
-
804
-
805
-
806
-    /**
807
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
808
-     * request Primarily used by unit tests.
809
-     *
810
-     * @throws InvalidDataTypeException
811
-     * @throws InvalidInterfaceException
812
-     * @throws InvalidArgumentException
813
-     */
814
-    public function reset()
815
-    {
816
-        $this->_register_core_class_loaders();
817
-        $this->_register_core_dependencies();
818
-    }
25
+	/**
26
+	 * This means that the requested class dependency is not present in the dependency map
27
+	 */
28
+	const not_registered = 0;
29
+
30
+	/**
31
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
32
+	 */
33
+	const load_new_object = 1;
34
+
35
+	/**
36
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
37
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
38
+	 */
39
+	const load_from_cache = 2;
40
+
41
+	/**
42
+	 * When registering a dependency,
43
+	 * this indicates to keep any existing dependencies that already exist,
44
+	 * and simply discard any new dependencies declared in the incoming data
45
+	 */
46
+	const KEEP_EXISTING_DEPENDENCIES = 0;
47
+
48
+	/**
49
+	 * When registering a dependency,
50
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
51
+	 */
52
+	const OVERWRITE_DEPENDENCIES = 1;
53
+
54
+
55
+
56
+	/**
57
+	 * @type EE_Dependency_Map $_instance
58
+	 */
59
+	protected static $_instance;
60
+
61
+	/**
62
+	 * @type EE_Request $request
63
+	 */
64
+	protected $_request;
65
+
66
+	/**
67
+	 * @type EE_Response $response
68
+	 */
69
+	protected $_response;
70
+
71
+	/**
72
+	 * @type LoaderInterface $loader
73
+	 */
74
+	protected $loader;
75
+
76
+	/**
77
+	 * @type array $_dependency_map
78
+	 */
79
+	protected $_dependency_map = array();
80
+
81
+	/**
82
+	 * @type array $_class_loaders
83
+	 */
84
+	protected $_class_loaders = array();
85
+
86
+	/**
87
+	 * @type array $_aliases
88
+	 */
89
+	protected $_aliases = array();
90
+
91
+
92
+
93
+	/**
94
+	 * EE_Dependency_Map constructor.
95
+	 *
96
+	 * @param EE_Request  $request
97
+	 * @param EE_Response $response
98
+	 */
99
+	protected function __construct(EE_Request $request, EE_Response $response)
100
+	{
101
+		$this->_request = $request;
102
+		$this->_response = $response;
103
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
104
+		do_action('EE_Dependency_Map____construct');
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @throws InvalidDataTypeException
111
+	 * @throws InvalidInterfaceException
112
+	 * @throws InvalidArgumentException
113
+	 */
114
+	public function initialize()
115
+	{
116
+		$this->_register_core_dependencies();
117
+		$this->_register_core_class_loaders();
118
+		$this->_register_core_aliases();
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * @singleton method used to instantiate class object
125
+	 * @access    public
126
+	 * @param EE_Request  $request
127
+	 * @param EE_Response $response
128
+	 * @return EE_Dependency_Map
129
+	 */
130
+	public static function instance(EE_Request $request = null, EE_Response $response = null)
131
+	{
132
+		// check if class object is instantiated, and instantiated properly
133
+		if (! self::$_instance instanceof EE_Dependency_Map) {
134
+			self::$_instance = new EE_Dependency_Map($request, $response);
135
+		}
136
+		return self::$_instance;
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * @param LoaderInterface $loader
143
+	 */
144
+	public function setLoader(LoaderInterface $loader)
145
+	{
146
+		$this->loader = $loader;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param string $class
153
+	 * @param array  $dependencies
154
+	 * @param int    $overwrite
155
+	 * @return bool
156
+	 */
157
+	public static function register_dependencies(
158
+		$class,
159
+		array $dependencies,
160
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
161
+	) {
162
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Assigns an array of class names and corresponding load sources (new or cached)
169
+	 * to the class specified by the first parameter.
170
+	 * IMPORTANT !!!
171
+	 * The order of elements in the incoming $dependencies array MUST match
172
+	 * the order of the constructor parameters for the class in question.
173
+	 * This is especially important when overriding any existing dependencies that are registered.
174
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
175
+	 *
176
+	 * @param string $class
177
+	 * @param array  $dependencies
178
+	 * @param int    $overwrite
179
+	 * @return bool
180
+	 */
181
+	public function registerDependencies(
182
+		$class,
183
+		array $dependencies,
184
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
185
+	) {
186
+		$class = trim($class, '\\');
187
+		$registered = false;
188
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
189
+			self::$_instance->_dependency_map[ $class ] = array();
190
+		}
191
+		// we need to make sure that any aliases used when registering a dependency
192
+		// get resolved to the correct class name
193
+		foreach ((array)$dependencies as $dependency => $load_source) {
194
+			$alias = self::$_instance->get_alias($dependency);
195
+			if (
196
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
198
+			) {
199
+				unset($dependencies[$dependency]);
200
+				$dependencies[$alias] = $load_source;
201
+				$registered = true;
202
+			}
203
+		}
204
+		// now add our two lists of dependencies together.
205
+		// using Union (+=) favours the arrays in precedence from left to right,
206
+		// so $dependencies is NOT overwritten because it is listed first
207
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
208
+		// Union is way faster than array_merge() but should be used with caution...
209
+		// especially with numerically indexed arrays
210
+		$dependencies += self::$_instance->_dependency_map[ $class ];
211
+		// now we need to ensure that the resulting dependencies
212
+		// array only has the entries that are required for the class
213
+		// so first count how many dependencies were originally registered for the class
214
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
215
+		// if that count is non-zero (meaning dependencies were already registered)
216
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
217
+			// then truncate the  final array to match that count
218
+			? array_slice($dependencies, 0, $dependency_count)
219
+			// otherwise just take the incoming array because nothing previously existed
220
+			: $dependencies;
221
+		return $registered;
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * @param string $class_name
228
+	 * @param string $loader
229
+	 * @return bool
230
+	 * @throws DomainException
231
+	 */
232
+	public static function register_class_loader($class_name, $loader = 'load_core')
233
+	{
234
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235
+			throw new DomainException(
236
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237
+			);
238
+		}
239
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
240
+		if (
241
+			! is_callable($loader)
242
+			&& (
243
+				strpos($loader, 'load_') !== 0
244
+				|| ! method_exists('EE_Registry', $loader)
245
+			)
246
+		) {
247
+			throw new DomainException(
248
+				sprintf(
249
+					esc_html__(
250
+						'"%1$s" is not a valid loader method on EE_Registry.',
251
+						'event_espresso'
252
+					),
253
+					$loader
254
+				)
255
+			);
256
+		}
257
+		$class_name = self::$_instance->get_alias($class_name);
258
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
259
+			self::$_instance->_class_loaders[$class_name] = $loader;
260
+			return true;
261
+		}
262
+		return false;
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * @return array
269
+	 */
270
+	public function dependency_map()
271
+	{
272
+		return $this->_dependency_map;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * returns TRUE if dependency map contains a listing for the provided class name
279
+	 *
280
+	 * @param string $class_name
281
+	 * @return boolean
282
+	 */
283
+	public function has($class_name = '')
284
+	{
285
+		// all legacy models have the same dependencies
286
+		if (strpos($class_name, 'EEM_') === 0) {
287
+			$class_name = 'LEGACY_MODELS';
288
+		}
289
+		return isset($this->_dependency_map[$class_name]) ? true : false;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
296
+	 *
297
+	 * @param string $class_name
298
+	 * @param string $dependency
299
+	 * @return bool
300
+	 */
301
+	public function has_dependency_for_class($class_name = '', $dependency = '')
302
+	{
303
+		// all legacy models have the same dependencies
304
+		if (strpos($class_name, 'EEM_') === 0) {
305
+			$class_name = 'LEGACY_MODELS';
306
+		}
307
+		$dependency = $this->get_alias($dependency);
308
+		return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
309
+			? true
310
+			: false;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
317
+	 *
318
+	 * @param string $class_name
319
+	 * @param string $dependency
320
+	 * @return int
321
+	 */
322
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
323
+	{
324
+		// all legacy models have the same dependencies
325
+		if (strpos($class_name, 'EEM_') === 0) {
326
+			$class_name = 'LEGACY_MODELS';
327
+		}
328
+		$dependency = $this->get_alias($dependency);
329
+		return $this->has_dependency_for_class($class_name, $dependency)
330
+			? $this->_dependency_map[$class_name][$dependency]
331
+			: EE_Dependency_Map::not_registered;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param string $class_name
338
+	 * @return string | Closure
339
+	 */
340
+	public function class_loader($class_name)
341
+	{
342
+		// all legacy models use load_model()
343
+		if(strpos($class_name, 'EEM_') === 0){
344
+			return 'load_model';
345
+		}
346
+		$class_name = $this->get_alias($class_name);
347
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @return array
354
+	 */
355
+	public function class_loaders()
356
+	{
357
+		return $this->_class_loaders;
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * adds an alias for a classname
364
+	 *
365
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
366
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
367
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
368
+	 */
369
+	public function add_alias($class_name, $alias, $for_class = '')
370
+	{
371
+		if ($for_class !== '') {
372
+			if (! isset($this->_aliases[$for_class])) {
373
+				$this->_aliases[$for_class] = array();
374
+			}
375
+			$this->_aliases[$for_class][$class_name] = $alias;
376
+		}
377
+		$this->_aliases[$class_name] = $alias;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * returns TRUE if the provided class name has an alias
384
+	 *
385
+	 * @param string $class_name
386
+	 * @param string $for_class
387
+	 * @return bool
388
+	 */
389
+	public function has_alias($class_name = '', $for_class = '')
390
+	{
391
+		return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
392
+			   || (
393
+				   isset($this->_aliases[$class_name])
394
+				   && ! is_array($this->_aliases[$class_name])
395
+			   );
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * returns alias for class name if one exists, otherwise returns the original classname
402
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
403
+	 *  for example:
404
+	 *      if the following two entries were added to the _aliases array:
405
+	 *          array(
406
+	 *              'interface_alias'           => 'some\namespace\interface'
407
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
408
+	 *          )
409
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
410
+	 *      to load an instance of 'some\namespace\classname'
411
+	 *
412
+	 * @param string $class_name
413
+	 * @param string $for_class
414
+	 * @return string
415
+	 */
416
+	public function get_alias($class_name = '', $for_class = '')
417
+	{
418
+		if (! $this->has_alias($class_name, $for_class)) {
419
+			return $class_name;
420
+		}
421
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
422
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423
+		}
424
+		return $this->get_alias($this->_aliases[$class_name]);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
+	 * This is done by using the following class constants:
433
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
435
+	 */
436
+	protected function _register_core_dependencies()
437
+	{
438
+		$this->_dependency_map = array(
439
+			'EE_Request_Handler'                                                                                          => array(
440
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
441
+			),
442
+			'EE_System'                                                                                                   => array(
443
+				'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
444
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
445
+				'EE_Capabilities'                            => EE_Dependency_Map::load_from_cache,
446
+				'EE_Request'                                 => EE_Dependency_Map::load_from_cache,
447
+				'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
448
+			),
449
+			'EE_Session'                                                                                                  => array(
450
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
451
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
452
+			),
453
+			'EE_Cart'                                                                                                     => array(
454
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
455
+			),
456
+			'EE_Front_Controller'                                                                                         => array(
457
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
458
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
459
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
460
+			),
461
+			'EE_Messenger_Collection_Loader'                                                                              => array(
462
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
463
+			),
464
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
465
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
466
+			),
467
+			'EE_Message_Resource_Manager'                                                                                 => array(
468
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
469
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
470
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
471
+			),
472
+			'EE_Message_Factory'                                                                                          => array(
473
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
474
+			),
475
+			'EE_messages'                                                                                                 => array(
476
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
+			),
478
+			'EE_Messages_Generator'                                                                                       => array(
479
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
480
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
481
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
482
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
483
+			),
484
+			'EE_Messages_Processor'                                                                                       => array(
485
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EE_Messages_Queue'                                                                                           => array(
488
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
489
+			),
490
+			'EE_Messages_Template_Defaults'                                                                               => array(
491
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
492
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
493
+			),
494
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
495
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
496
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
497
+			),
498
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
499
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
500
+			),
501
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
502
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
503
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
504
+			),
505
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
506
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
507
+			),
508
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
509
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
510
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
511
+			),
512
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
513
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
514
+			),
515
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
516
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
517
+			),
518
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
519
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
522
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
525
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
528
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
531
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
534
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
537
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
540
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
543
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
546
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
549
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
552
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EE_Data_Migration_Class_Base'                                                                                => array(
555
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
556
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
557
+			),
558
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
559
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
560
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
561
+			),
562
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
563
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
567
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
+			),
570
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
571
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
+			),
574
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
575
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
+			),
582
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
583
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
587
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
+			),
590
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
591
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
+			),
594
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
595
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
596
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
599
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
600
+			),
601
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
602
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
603
+			),
604
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
605
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
606
+			),
607
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
608
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
611
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
+			),
613
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
614
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
+			),
616
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
617
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
+			),
619
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
620
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
621
+			),
622
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
623
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
624
+			),
625
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
626
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
627
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
628
+			),
629
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
630
+				null,
631
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
632
+			),
633
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
634
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
635
+			),
636
+			'LEGACY_MODELS'                                                   => array(
637
+				null,
638
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
639
+			),
640
+			'EE_Module_Request_Router' => array(
641
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
642
+			),
643
+			'EE_Registration_Processor' => array(
644
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+		);
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * Registers how core classes are loaded.
653
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
654
+	 *        'EE_Request_Handler' => 'load_core'
655
+	 *        'EE_Messages_Queue'  => 'load_lib'
656
+	 *        'EEH_Debug_Tools'    => 'load_helper'
657
+	 * or, if greater control is required, by providing a custom closure. For example:
658
+	 *        'Some_Class' => function () {
659
+	 *            return new Some_Class();
660
+	 *        },
661
+	 * This is required for instantiating dependencies
662
+	 * where an interface has been type hinted in a class constructor. For example:
663
+	 *        'Required_Interface' => function () {
664
+	 *            return new A_Class_That_Implements_Required_Interface();
665
+	 *        },
666
+	 *
667
+	 * @throws InvalidInterfaceException
668
+	 * @throws InvalidDataTypeException
669
+	 * @throws InvalidArgumentException
670
+	 */
671
+	protected function _register_core_class_loaders()
672
+	{
673
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
674
+		//be used in a closure.
675
+		$request = &$this->_request;
676
+		$response = &$this->_response;
677
+		// $loader = &$this->loader;
678
+		$this->_class_loaders = array(
679
+			//load_core
680
+			'EE_Capabilities'                      => 'load_core',
681
+			'EE_Encryption'                        => 'load_core',
682
+			'EE_Front_Controller'                  => 'load_core',
683
+			'EE_Module_Request_Router'             => 'load_core',
684
+			'EE_Registry'                          => 'load_core',
685
+			'EE_Request'                           => function () use (&$request) {
686
+				return $request;
687
+			},
688
+			'EE_Response'                          => function () use (&$response) {
689
+				return $response;
690
+			},
691
+			'EE_Request_Handler'                   => 'load_core',
692
+			'EE_Session'                           => 'load_core',
693
+			'EE_Cron_Tasks'                        => 'load_core',
694
+			'EE_System'                            => 'load_core',
695
+			'EE_Maintenance_Mode'                  => 'load_core',
696
+			'EE_Register_CPTs'                     => 'load_core',
697
+			'EE_Admin'                             => 'load_core',
698
+			//load_lib
699
+			'EE_Message_Resource_Manager'          => 'load_lib',
700
+			'EE_Message_Type_Collection'           => 'load_lib',
701
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
702
+			'EE_Messenger_Collection'              => 'load_lib',
703
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
704
+			'EE_Messages_Processor'                => 'load_lib',
705
+			'EE_Message_Repository'                => 'load_lib',
706
+			'EE_Messages_Queue'                    => 'load_lib',
707
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
708
+			'EE_Message_Template_Group_Collection' => 'load_lib',
709
+			'EE_Payment_Method_Manager'            => 'load_lib',
710
+			'EE_Messages_Generator'                => function () {
711
+				return EE_Registry::instance()->load_lib(
712
+					'Messages_Generator',
713
+					array(),
714
+					false,
715
+					false
716
+				);
717
+			},
718
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
719
+				return EE_Registry::instance()->load_lib(
720
+					'Messages_Template_Defaults',
721
+					$arguments,
722
+					false,
723
+					false
724
+				);
725
+			},
726
+			//load_model
727
+			// 'EEM_Attendee'                         => 'load_model',
728
+			// 'EEM_Message_Template_Group'           => 'load_model',
729
+			// 'EEM_Message_Template'                 => 'load_model',
730
+			//load_helper
731
+			'EEH_Parse_Shortcodes'                 => function () {
732
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
733
+					return new EEH_Parse_Shortcodes();
734
+				}
735
+				return null;
736
+			},
737
+			'EE_Template_Config'                   => function () {
738
+				return EE_Config::instance()->template_settings;
739
+			},
740
+			'EE_Currency_Config'                   => function () {
741
+				return EE_Config::instance()->currency;
742
+			},
743
+			'EE_Registration_Config'                   => function () {
744
+				return EE_Config::instance()->registration;
745
+			},
746
+			'EventEspresso\core\services\loaders\Loader' => function () {
747
+				return LoaderFactory::getLoader();
748
+			},
749
+		);
750
+	}
751
+
752
+
753
+
754
+	/**
755
+	 * can be used for supplying alternate names for classes,
756
+	 * or for connecting interface names to instantiable classes
757
+	 */
758
+	protected function _register_core_aliases()
759
+	{
760
+		$this->_aliases = array(
761
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
762
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
763
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
764
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
765
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
766
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
767
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
768
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
769
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
770
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
771
+			'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
772
+			'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
773
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
774
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
775
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
776
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
777
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
778
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
779
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
780
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
781
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
782
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
783
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
784
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
785
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
786
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
787
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
788
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
789
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
790
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
791
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
792
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
793
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
794
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
795
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
796
+			'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
797
+			'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
798
+		);
799
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
800
+			$this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
801
+		}
802
+	}
803
+
804
+
805
+
806
+	/**
807
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
808
+	 * request Primarily used by unit tests.
809
+	 *
810
+	 * @throws InvalidDataTypeException
811
+	 * @throws InvalidInterfaceException
812
+	 * @throws InvalidArgumentException
813
+	 */
814
+	public function reset()
815
+	{
816
+		$this->_register_core_class_loaders();
817
+		$this->_register_core_dependencies();
818
+	}
819 819
 
820 820
 
821 821
 }
Please login to merge, or discard this patch.