Completed
Branch master (d2f79a)
by
unknown
07:00 queued 14s
created
caffeinated/admin/new/tickets/Tickets_Admin_Page.core.php 2 patches
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -11,314 +11,314 @@
 block discarded – undo
11 11
  */
12 12
 class Tickets_Admin_Page extends EE_Admin_Page
13 13
 {
14
-    protected function _init_page_props()
15
-    {
16
-        $this->page_slug = TICKETS_PG_SLUG;
17
-        $this->page_label = TICKETS_LABEL;
18
-        $this->_admin_base_url = TICKETS_ADMIN_URL;
19
-        $this->_admin_base_path = TICKETS_ADMIN;
20
-    }
21
-
22
-
23
-    protected function _ajax_hooks()
24
-    {
25
-    }
26
-
27
-
28
-    protected function _define_page_props()
29
-    {
30
-        $this->_admin_page_title = TICKETS_LABEL;
31
-        $this->_labels = array(
32
-            'buttons' => array(
33
-                'add'    => esc_html__('Add New Default Ticket', 'event_espresso'),
34
-                'edit'   => esc_html__('Edit Default Ticket', 'event_espresso'),
35
-                'delete' => esc_html__('Delete Default Ticket', 'event_espresso'),
36
-            ),
37
-        );
38
-    }
39
-
40
-
41
-    protected function _set_page_routes()
42
-    {
43
-
44
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
45
-            ? $this->_req_data['TKT_ID'] : 0;
46
-
47
-        $this->_page_routes = array(
48
-            'default'         => array(
49
-                'func'       => '_tickets_overview_list_table',
50
-                'capability' => 'ee_read_default_tickets',
51
-            ),
52
-            'trash_ticket'    => array(
53
-                'func'       => '_trash_or_restore_ticket',
54
-                'noheader'   => true,
55
-                'args'       => array('trash' => true),
56
-                'capability' => 'ee_delete_default_ticket',
57
-                'obj_id'     => $tkt_id,
58
-            ),
59
-            'trash_tickets'   => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'noheader'   => true,
62
-                'args'       => array('trash' => true),
63
-                'capability' => 'ee_delete_default_tickets',
64
-            ),
65
-            'restore_ticket'  => array(
66
-                'func'       => '_trash_or_restore_ticket',
67
-                'noheader'   => true,
68
-                'capability' => 'ee_delete_default_ticket',
69
-                'obj_id'     => $tkt_id,
70
-            ),
71
-            'restore_tickets' => array(
72
-                'func'       => '_trash_or_restore_ticket',
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_default_tickets',
75
-            ),
76
-            'delete_ticket'   => array(
77
-                'func'       => '_delete_ticket',
78
-                'noheader'   => true,
79
-                'capability' => 'ee_delete_default_ticket',
80
-                'obj_id'     => $tkt_id,
81
-            ),
82
-            'delete_tickets'  => array(
83
-                'func'       => '_delete_ticket',
84
-                'noheader'   => true,
85
-                'capability' => 'ee_delete_default_tickets',
86
-            ),
87
-        );
88
-    }
89
-
90
-
91
-    protected function _set_page_config()
92
-    {
93
-        $this->_page_config = array(
94
-            'default' => array(
95
-                'nav'           => array(
96
-                    'label' => esc_html__('Default Tickets', 'event_espresso'),
97
-                    'order' => 10,
98
-                ),
99
-                'list_table'    => 'Tickets_List_Table',
100
-                'require_nonce' => false,
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-    protected function _add_screen_options()
107
-    {
108
-    }
109
-
110
-    protected function _add_screen_options_default()
111
-    {
112
-        $this->_per_page_screen_option();
113
-    }
114
-
115
-
116
-    protected function _add_feature_pointers()
117
-    {
118
-    }
119
-
120
-    public function load_scripts_styles()
121
-    {
122
-    }
123
-
124
-    public function load_scripts_styles_default()
125
-    {
126
-    }
127
-
128
-    public function admin_footer_scripts()
129
-    {
130
-    }
131
-
132
-    public function admin_init()
133
-    {
134
-    }
135
-
136
-    public function admin_notices()
137
-    {
138
-    }
139
-
140
-
141
-    public function _set_list_table_views_default()
142
-    {
143
-        $this->_views = array(
144
-            'all'     => array(
145
-                'slug'        => 'all',
146
-                'label'       => esc_html__('All', 'event_espresso'),
147
-                'count'       => 0,
148
-                'bulk_action' => array(
149
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
150
-                ),
151
-            ),
152
-            'trashed' => array(
153
-                'slug'        => 'trashed',
154
-                'label'       => esc_html__('Trash', 'event_espresso'),
155
-                'count'       => 0,
156
-                'bulk_action' => array(
157
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
158
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
159
-                ),
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    public function _tickets_overview_list_table()
166
-    {
167
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
168
-        $this->display_admin_list_table_page_with_no_sidebar();
169
-    }
170
-
171
-
172
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
173
-    {
174
-
175
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
176
-        $order = empty($this->_req_data['order']) ? 'ASC' : $order;
177
-
178
-        switch ($orderby) {
179
-            case 'TKT_name':
180
-                $orderby = array('TKT_name' => $order);
181
-                break;
182
-
183
-            case 'TKT_price':
184
-                $orderby = array('TKT_price' => $order);
185
-                break;
186
-
187
-            case 'TKT_uses':
188
-                $orderby = array('TKT_uses' => $order);
189
-                break;
190
-
191
-            case 'TKT_min':
192
-                $orderby = array('TKT_min' => $order);
193
-                break;
194
-
195
-            case 'TKT_max':
196
-                $orderby = array('TKT_max' => $order);
197
-                break;
198
-
199
-            case 'TKT_qty':
200
-                $orderby = array('TKT_qty' => $order);
201
-                break;
202
-        }
203
-
204
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
205
-            ? $this->_req_data['paged'] : 1;
206
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
207
-            ? $this->_req_data['perpage'] : $per_page;
208
-
209
-        $_where = array(
210
-            'TKT_is_default' => 1,
211
-            'TKT_deleted'    => $trashed,
212
-        );
213
-
214
-        $offset = ($current_page - 1) * $per_page;
215
-        $limit = array($offset, $per_page);
216
-
217
-        if (isset($this->_req_data['s'])) {
218
-            $sstr = '%' . $this->_req_data['s'] . '%';
219
-            $_where['OR'] = array(
220
-                'TKT_name'        => array('LIKE', $sstr),
221
-                'TKT_description' => array('LIKE', $sstr),
222
-            );
223
-        }
224
-
225
-        $query_params = array(
226
-            $_where,
227
-            'order_by' => $orderby,
228
-            'limit'    => $limit,
229
-            'group_by' => 'TKT_ID',
230
-        );
231
-
232
-        if ($count) {
233
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
234
-        } else {
235
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
236
-        }
237
-    }
238
-
239
-
240
-    protected function _trash_or_restore_ticket($trash = false)
241
-    {
242
-        $success = 1;
243
-
244
-        $TKT = EEM_Ticket::instance();
245
-
246
-        // checkboxes?
247
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
248
-            // if array has more than one element then success message should be plural
249
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
250
-
251
-            // cycle thru the boxes
252
-            $checkboxes = $this->_req_data['checkbox'];
253
-            foreach (array_keys($checkboxes) as $TKT_ID) {
254
-                if ($trash) {
255
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
256
-                        $success = 0;
257
-                    }
258
-                    continue;
259
-                }
260
-                if (! $TKT->restore_by_ID($TKT_ID)) {
261
-                    $success = 0;
262
-                }
263
-            }
264
-        } else {
265
-            // grab single id and trash
266
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
267
-
268
-            if ($trash) {
269
-                if (! $TKT->delete_by_ID($TKT_ID)) {
270
-                    $success = 0;
271
-                }
272
-            } else {
273
-                if (! $TKT->restore_by_ID($TKT_ID)) {
274
-                    $success = 0;
275
-                }
276
-            }
277
-        }
278
-
279
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
280
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, array());
281
-    }
282
-
283
-
284
-    protected function _delete_ticket()
285
-    {
286
-        $success = 1;
287
-
288
-        $TKT = EEM_Ticket::instance();
289
-
290
-        // checkboxes?
291
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
292
-            // if array has more than one element then success message should be plural
293
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
294
-
295
-            // cycle thru the boxes
296
-            $checkboxes = $this->_req_data['checkbox'];
297
-            foreach (array_keys($checkboxes) as $TKT_ID) {
298
-                // delete
299
-                if (! $this->_delete_the_ticket($TKT_ID)) {
300
-                    $success = 0;
301
-                }
302
-            }
303
-        } else {
304
-            // grab single id and trash
305
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
306
-            if (! $this->_delete_the_ticket($TKT_ID)) {
307
-                $success = 0;
308
-            }
309
-        }
310
-
311
-        $action_desc = 'deleted';
312
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, array());
313
-    }
314
-
315
-
316
-    protected function _delete_the_ticket($TKT_ID)
317
-    {
318
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
319
-
320
-        // delete all related prices first
321
-        $tkt->delete_related_permanently('Price');
322
-        return $tkt->delete_permanently();
323
-    }
14
+	protected function _init_page_props()
15
+	{
16
+		$this->page_slug = TICKETS_PG_SLUG;
17
+		$this->page_label = TICKETS_LABEL;
18
+		$this->_admin_base_url = TICKETS_ADMIN_URL;
19
+		$this->_admin_base_path = TICKETS_ADMIN;
20
+	}
21
+
22
+
23
+	protected function _ajax_hooks()
24
+	{
25
+	}
26
+
27
+
28
+	protected function _define_page_props()
29
+	{
30
+		$this->_admin_page_title = TICKETS_LABEL;
31
+		$this->_labels = array(
32
+			'buttons' => array(
33
+				'add'    => esc_html__('Add New Default Ticket', 'event_espresso'),
34
+				'edit'   => esc_html__('Edit Default Ticket', 'event_espresso'),
35
+				'delete' => esc_html__('Delete Default Ticket', 'event_espresso'),
36
+			),
37
+		);
38
+	}
39
+
40
+
41
+	protected function _set_page_routes()
42
+	{
43
+
44
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
45
+			? $this->_req_data['TKT_ID'] : 0;
46
+
47
+		$this->_page_routes = array(
48
+			'default'         => array(
49
+				'func'       => '_tickets_overview_list_table',
50
+				'capability' => 'ee_read_default_tickets',
51
+			),
52
+			'trash_ticket'    => array(
53
+				'func'       => '_trash_or_restore_ticket',
54
+				'noheader'   => true,
55
+				'args'       => array('trash' => true),
56
+				'capability' => 'ee_delete_default_ticket',
57
+				'obj_id'     => $tkt_id,
58
+			),
59
+			'trash_tickets'   => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'noheader'   => true,
62
+				'args'       => array('trash' => true),
63
+				'capability' => 'ee_delete_default_tickets',
64
+			),
65
+			'restore_ticket'  => array(
66
+				'func'       => '_trash_or_restore_ticket',
67
+				'noheader'   => true,
68
+				'capability' => 'ee_delete_default_ticket',
69
+				'obj_id'     => $tkt_id,
70
+			),
71
+			'restore_tickets' => array(
72
+				'func'       => '_trash_or_restore_ticket',
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_default_tickets',
75
+			),
76
+			'delete_ticket'   => array(
77
+				'func'       => '_delete_ticket',
78
+				'noheader'   => true,
79
+				'capability' => 'ee_delete_default_ticket',
80
+				'obj_id'     => $tkt_id,
81
+			),
82
+			'delete_tickets'  => array(
83
+				'func'       => '_delete_ticket',
84
+				'noheader'   => true,
85
+				'capability' => 'ee_delete_default_tickets',
86
+			),
87
+		);
88
+	}
89
+
90
+
91
+	protected function _set_page_config()
92
+	{
93
+		$this->_page_config = array(
94
+			'default' => array(
95
+				'nav'           => array(
96
+					'label' => esc_html__('Default Tickets', 'event_espresso'),
97
+					'order' => 10,
98
+				),
99
+				'list_table'    => 'Tickets_List_Table',
100
+				'require_nonce' => false,
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+	protected function _add_screen_options()
107
+	{
108
+	}
109
+
110
+	protected function _add_screen_options_default()
111
+	{
112
+		$this->_per_page_screen_option();
113
+	}
114
+
115
+
116
+	protected function _add_feature_pointers()
117
+	{
118
+	}
119
+
120
+	public function load_scripts_styles()
121
+	{
122
+	}
123
+
124
+	public function load_scripts_styles_default()
125
+	{
126
+	}
127
+
128
+	public function admin_footer_scripts()
129
+	{
130
+	}
131
+
132
+	public function admin_init()
133
+	{
134
+	}
135
+
136
+	public function admin_notices()
137
+	{
138
+	}
139
+
140
+
141
+	public function _set_list_table_views_default()
142
+	{
143
+		$this->_views = array(
144
+			'all'     => array(
145
+				'slug'        => 'all',
146
+				'label'       => esc_html__('All', 'event_espresso'),
147
+				'count'       => 0,
148
+				'bulk_action' => array(
149
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
150
+				),
151
+			),
152
+			'trashed' => array(
153
+				'slug'        => 'trashed',
154
+				'label'       => esc_html__('Trash', 'event_espresso'),
155
+				'count'       => 0,
156
+				'bulk_action' => array(
157
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
158
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
159
+				),
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	public function _tickets_overview_list_table()
166
+	{
167
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
168
+		$this->display_admin_list_table_page_with_no_sidebar();
169
+	}
170
+
171
+
172
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
173
+	{
174
+
175
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
176
+		$order = empty($this->_req_data['order']) ? 'ASC' : $order;
177
+
178
+		switch ($orderby) {
179
+			case 'TKT_name':
180
+				$orderby = array('TKT_name' => $order);
181
+				break;
182
+
183
+			case 'TKT_price':
184
+				$orderby = array('TKT_price' => $order);
185
+				break;
186
+
187
+			case 'TKT_uses':
188
+				$orderby = array('TKT_uses' => $order);
189
+				break;
190
+
191
+			case 'TKT_min':
192
+				$orderby = array('TKT_min' => $order);
193
+				break;
194
+
195
+			case 'TKT_max':
196
+				$orderby = array('TKT_max' => $order);
197
+				break;
198
+
199
+			case 'TKT_qty':
200
+				$orderby = array('TKT_qty' => $order);
201
+				break;
202
+		}
203
+
204
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
205
+			? $this->_req_data['paged'] : 1;
206
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
207
+			? $this->_req_data['perpage'] : $per_page;
208
+
209
+		$_where = array(
210
+			'TKT_is_default' => 1,
211
+			'TKT_deleted'    => $trashed,
212
+		);
213
+
214
+		$offset = ($current_page - 1) * $per_page;
215
+		$limit = array($offset, $per_page);
216
+
217
+		if (isset($this->_req_data['s'])) {
218
+			$sstr = '%' . $this->_req_data['s'] . '%';
219
+			$_where['OR'] = array(
220
+				'TKT_name'        => array('LIKE', $sstr),
221
+				'TKT_description' => array('LIKE', $sstr),
222
+			);
223
+		}
224
+
225
+		$query_params = array(
226
+			$_where,
227
+			'order_by' => $orderby,
228
+			'limit'    => $limit,
229
+			'group_by' => 'TKT_ID',
230
+		);
231
+
232
+		if ($count) {
233
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
234
+		} else {
235
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
236
+		}
237
+	}
238
+
239
+
240
+	protected function _trash_or_restore_ticket($trash = false)
241
+	{
242
+		$success = 1;
243
+
244
+		$TKT = EEM_Ticket::instance();
245
+
246
+		// checkboxes?
247
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
248
+			// if array has more than one element then success message should be plural
249
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
250
+
251
+			// cycle thru the boxes
252
+			$checkboxes = $this->_req_data['checkbox'];
253
+			foreach (array_keys($checkboxes) as $TKT_ID) {
254
+				if ($trash) {
255
+					if (! $TKT->delete_by_ID($TKT_ID)) {
256
+						$success = 0;
257
+					}
258
+					continue;
259
+				}
260
+				if (! $TKT->restore_by_ID($TKT_ID)) {
261
+					$success = 0;
262
+				}
263
+			}
264
+		} else {
265
+			// grab single id and trash
266
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
267
+
268
+			if ($trash) {
269
+				if (! $TKT->delete_by_ID($TKT_ID)) {
270
+					$success = 0;
271
+				}
272
+			} else {
273
+				if (! $TKT->restore_by_ID($TKT_ID)) {
274
+					$success = 0;
275
+				}
276
+			}
277
+		}
278
+
279
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
280
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, array());
281
+	}
282
+
283
+
284
+	protected function _delete_ticket()
285
+	{
286
+		$success = 1;
287
+
288
+		$TKT = EEM_Ticket::instance();
289
+
290
+		// checkboxes?
291
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
292
+			// if array has more than one element then success message should be plural
293
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
294
+
295
+			// cycle thru the boxes
296
+			$checkboxes = $this->_req_data['checkbox'];
297
+			foreach (array_keys($checkboxes) as $TKT_ID) {
298
+				// delete
299
+				if (! $this->_delete_the_ticket($TKT_ID)) {
300
+					$success = 0;
301
+				}
302
+			}
303
+		} else {
304
+			// grab single id and trash
305
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
306
+			if (! $this->_delete_the_ticket($TKT_ID)) {
307
+				$success = 0;
308
+			}
309
+		}
310
+
311
+		$action_desc = 'deleted';
312
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, array());
313
+	}
314
+
315
+
316
+	protected function _delete_the_ticket($TKT_ID)
317
+	{
318
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
319
+
320
+		// delete all related prices first
321
+		$tkt->delete_related_permanently('Price');
322
+		return $tkt->delete_permanently();
323
+	}
324 324
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $limit = array($offset, $per_page);
216 216
 
217 217
         if (isset($this->_req_data['s'])) {
218
-            $sstr = '%' . $this->_req_data['s'] . '%';
218
+            $sstr = '%'.$this->_req_data['s'].'%';
219 219
             $_where['OR'] = array(
220 220
                 'TKT_name'        => array('LIKE', $sstr),
221 221
                 'TKT_description' => array('LIKE', $sstr),
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         $TKT = EEM_Ticket::instance();
245 245
 
246 246
         // checkboxes?
247
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
247
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
248 248
             // if array has more than one element then success message should be plural
249 249
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
250 250
 
@@ -252,12 +252,12 @@  discard block
 block discarded – undo
252 252
             $checkboxes = $this->_req_data['checkbox'];
253 253
             foreach (array_keys($checkboxes) as $TKT_ID) {
254 254
                 if ($trash) {
255
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
255
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
256 256
                         $success = 0;
257 257
                     }
258 258
                     continue;
259 259
                 }
260
-                if (! $TKT->restore_by_ID($TKT_ID)) {
260
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
261 261
                     $success = 0;
262 262
                 }
263 263
             }
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
             $TKT_ID = absint($this->_req_data['TKT_ID']);
267 267
 
268 268
             if ($trash) {
269
-                if (! $TKT->delete_by_ID($TKT_ID)) {
269
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
270 270
                     $success = 0;
271 271
                 }
272 272
             } else {
273
-                if (! $TKT->restore_by_ID($TKT_ID)) {
273
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
274 274
                     $success = 0;
275 275
                 }
276 276
             }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
         $TKT = EEM_Ticket::instance();
289 289
 
290 290
         // checkboxes?
291
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
291
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
292 292
             // if array has more than one element then success message should be plural
293 293
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
294 294
 
@@ -296,14 +296,14 @@  discard block
 block discarded – undo
296 296
             $checkboxes = $this->_req_data['checkbox'];
297 297
             foreach (array_keys($checkboxes) as $TKT_ID) {
298 298
                 // delete
299
-                if (! $this->_delete_the_ticket($TKT_ID)) {
299
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
300 300
                     $success = 0;
301 301
                 }
302 302
             }
303 303
         } else {
304 304
             // grab single id and trash
305 305
             $TKT_ID = absint($this->_req_data['TKT_ID']);
306
-            if (! $this->_delete_the_ticket($TKT_ID)) {
306
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
307 307
                 $success = 0;
308 308
             }
309 309
         }
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3680 added lines, -3680 removed lines patch added patch discarded remove patch
@@ -21,2225 +21,2225 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
23 23
 {
24
-    /**
25
-     * @var EE_Registration
26
-     */
27
-    private $_registration;
28
-
29
-    /**
30
-     * @var EE_Event
31
-     */
32
-    private $_reg_event;
33
-
34
-    /**
35
-     * @var EE_Session
36
-     */
37
-    private $_session;
38
-
39
-    /**
40
-     * @var array
41
-     */
42
-    private static $_reg_status;
43
-
44
-    /**
45
-     * Form for displaying the custom questions for this registration.
46
-     * This gets used a few times throughout the request so its best to cache it
47
-     *
48
-     * @var EE_Registration_Custom_Questions_Form
49
-     */
50
-    protected $_reg_custom_questions_form = null;
51
-
52
-    /**
53
-     * @var EEM_Registration $registration_model
54
-     */
55
-    private $registration_model;
56
-
57
-    /**
58
-     * @var EEM_Attendee $attendee_model
59
-     */
60
-    private $attendee_model;
61
-
62
-    /**
63
-     * @var EEM_Event $event_model
64
-     */
65
-    private $event_model;
66
-
67
-    /**
68
-     * @var EEM_Status $status_model
69
-     */
70
-    private $status_model;
71
-
72
-
73
-    /**
74
-     * @param bool $routing
75
-     * @throws EE_Error
76
-     * @throws InvalidArgumentException
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidInterfaceException
79
-     * @throws ReflectionException
80
-     */
81
-    public function __construct($routing = true)
82
-    {
83
-        parent::__construct($routing);
84
-        add_action('wp_loaded', [$this, 'wp_loaded']);
85
-    }
86
-
87
-
88
-    /**
89
-     * @return EEM_Registration
90
-     * @throws InvalidArgumentException
91
-     * @throws InvalidDataTypeException
92
-     * @throws InvalidInterfaceException
93
-     * @since 4.10.2.p
94
-     */
95
-    protected function getRegistrationModel()
96
-    {
97
-        if (! $this->registration_model instanceof EEM_Registration) {
98
-            $this->registration_model = $this->getLoader()->getShared('EEM_Registration');
99
-        }
100
-        return $this->registration_model;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return EEM_Attendee
106
-     * @throws InvalidArgumentException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     * @since 4.10.2.p
110
-     */
111
-    protected function getAttendeeModel()
112
-    {
113
-        if (! $this->attendee_model instanceof EEM_Attendee) {
114
-            $this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
115
-        }
116
-        return $this->attendee_model;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return EEM_Event
122
-     * @throws InvalidArgumentException
123
-     * @throws InvalidDataTypeException
124
-     * @throws InvalidInterfaceException
125
-     * @since 4.10.2.p
126
-     */
127
-    protected function getEventModel()
128
-    {
129
-        if (! $this->event_model instanceof EEM_Event) {
130
-            $this->event_model = $this->getLoader()->getShared('EEM_Event');
131
-        }
132
-        return $this->event_model;
133
-    }
134
-
135
-
136
-    /**
137
-     * @return EEM_Status
138
-     * @throws InvalidArgumentException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidInterfaceException
141
-     * @since 4.10.2.p
142
-     */
143
-    protected function getStatusModel()
144
-    {
145
-        if (! $this->status_model instanceof EEM_Status) {
146
-            $this->status_model = $this->getLoader()->getShared('EEM_Status');
147
-        }
148
-        return $this->status_model;
149
-    }
150
-
151
-
152
-    public function wp_loaded()
153
-    {
154
-        // when adding a new registration...
155
-        $action = $this->request->getRequestParam('action');
156
-        if ($action === 'new_registration') {
157
-            EE_System::do_not_cache();
158
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
159
-                // and it's NOT the attendee information reg step
160
-                // force cookie expiration by setting time to last week
161
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
162
-                // and update the global
163
-                $_COOKIE['ee_registration_added'] = 0;
164
-            }
165
-        }
166
-    }
167
-
168
-
169
-    protected function _init_page_props()
170
-    {
171
-        $this->page_slug        = REG_PG_SLUG;
172
-        $this->_admin_base_url  = REG_ADMIN_URL;
173
-        $this->_admin_base_path = REG_ADMIN;
174
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
175
-        $this->_cpt_routes      = [
176
-            'add_new_attendee' => 'espresso_attendees',
177
-            'edit_attendee'    => 'espresso_attendees',
178
-            'insert_attendee'  => 'espresso_attendees',
179
-            'update_attendee'  => 'espresso_attendees',
180
-        ];
181
-        $this->_cpt_model_names = [
182
-            'add_new_attendee' => 'EEM_Attendee',
183
-            'edit_attendee'    => 'EEM_Attendee',
184
-        ];
185
-        $this->_cpt_edit_routes = [
186
-            'espresso_attendees' => 'edit_attendee',
187
-        ];
188
-        $this->_pagenow_map     = [
189
-            'add_new_attendee' => 'post-new.php',
190
-            'edit_attendee'    => 'post.php',
191
-            'trash'            => 'post.php',
192
-        ];
193
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
194
-        // add filters so that the comment urls don't take users to a confusing 404 page
195
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
196
-    }
197
-
198
-
199
-    /**
200
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
201
-     * @param WP_Comment $comment The current comment object.
202
-     * @return string
203
-     */
204
-    public function clear_comment_link($link, WP_Comment $comment)
205
-    {
206
-        // gotta make sure this only happens on this route
207
-        $post_type = get_post_type($comment->comment_post_ID);
208
-        if ($post_type === 'espresso_attendees') {
209
-            return '#commentsdiv';
210
-        }
211
-        return $link;
212
-    }
213
-
214
-
215
-    protected function _ajax_hooks()
216
-    {
217
-        // todo: all hooks for registrations ajax goes in here
218
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
219
-    }
220
-
221
-
222
-    protected function _define_page_props()
223
-    {
224
-        $this->_admin_page_title = $this->page_label;
225
-        $this->_labels           = [
226
-            'buttons'                      => [
227
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
228
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
229
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
230
-                'csv_reg_report'      => esc_html__('Registrations CSV Report', 'event_espresso'),
231
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
-            ],
234
-            'publishbox'                   => [
235
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
-            ],
238
-            'hide_add_button_on_cpt_route' => [
239
-                'edit_attendee' => true,
240
-            ],
241
-        ];
242
-    }
243
-
244
-
245
-    /**
246
-     * grab url requests and route them
247
-     *
248
-     * @return void
249
-     * @throws EE_Error
250
-     */
251
-    public function _set_page_routes()
252
-    {
253
-        $this->_get_registration_status_array();
254
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
-        $this->_page_routes = [
259
-            'default'                             => [
260
-                'func'       => [$this, '_registrations_overview_list_table'],
261
-                'capability' => 'ee_read_registrations',
262
-            ],
263
-            'view_registration'                   => [
264
-                'func'       => '_registration_details',
265
-                'capability' => 'ee_read_registration',
266
-                'obj_id'     => $REG_ID,
267
-            ],
268
-            'edit_registration'                   => [
269
-                'func'               => '_update_attendee_registration_form',
270
-                'noheader'           => true,
271
-                'headers_sent_route' => 'view_registration',
272
-                'capability'         => 'ee_edit_registration',
273
-                'obj_id'             => $REG_ID,
274
-                '_REG_ID'            => $REG_ID,
275
-            ],
276
-            'trash_registrations'                 => [
277
-                'func'       => '_trash_or_restore_registrations',
278
-                'args'       => ['trash' => true],
279
-                'noheader'   => true,
280
-                'capability' => 'ee_delete_registrations',
281
-            ],
282
-            'restore_registrations'               => [
283
-                'func'       => '_trash_or_restore_registrations',
284
-                'args'       => ['trash' => false],
285
-                'noheader'   => true,
286
-                'capability' => 'ee_delete_registrations',
287
-            ],
288
-            'delete_registrations'                => [
289
-                'func'       => '_delete_registrations',
290
-                'noheader'   => true,
291
-                'capability' => 'ee_delete_registrations',
292
-            ],
293
-            'new_registration'                    => [
294
-                'func'       => 'new_registration',
295
-                'capability' => 'ee_edit_registrations',
296
-            ],
297
-            'process_reg_step'                    => [
298
-                'func'       => 'process_reg_step',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-            ],
302
-            'redirect_to_txn'                     => [
303
-                'func'       => 'redirect_to_txn',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-            ],
307
-            'change_reg_status'                   => [
308
-                'func'       => '_change_reg_status',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $REG_ID,
312
-            ],
313
-            'approve_registration'                => [
314
-                'func'       => 'approve_registration',
315
-                'noheader'   => true,
316
-                'capability' => 'ee_edit_registration',
317
-                'obj_id'     => $REG_ID,
318
-            ],
319
-            'approve_and_notify_registration'     => [
320
-                'func'       => 'approve_registration',
321
-                'noheader'   => true,
322
-                'args'       => [true],
323
-                'capability' => 'ee_edit_registration',
324
-                'obj_id'     => $REG_ID,
325
-            ],
326
-            'approve_registrations'               => [
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args'       => ['approve'],
331
-            ],
332
-            'approve_and_notify_registrations'    => [
333
-                'func'       => 'bulk_action_on_registrations',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registrations',
336
-                'args'       => ['approve', true],
337
-            ],
338
-            'decline_registration'                => [
339
-                'func'       => 'decline_registration',
340
-                'noheader'   => true,
341
-                'capability' => 'ee_edit_registration',
342
-                'obj_id'     => $REG_ID,
343
-            ],
344
-            'decline_and_notify_registration'     => [
345
-                'func'       => 'decline_registration',
346
-                'noheader'   => true,
347
-                'args'       => [true],
348
-                'capability' => 'ee_edit_registration',
349
-                'obj_id'     => $REG_ID,
350
-            ],
351
-            'decline_registrations'               => [
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args'       => ['decline'],
356
-            ],
357
-            'decline_and_notify_registrations'    => [
358
-                'func'       => 'bulk_action_on_registrations',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registrations',
361
-                'args'       => ['decline', true],
362
-            ],
363
-            'pending_registration'                => [
364
-                'func'       => 'pending_registration',
365
-                'noheader'   => true,
366
-                'capability' => 'ee_edit_registration',
367
-                'obj_id'     => $REG_ID,
368
-            ],
369
-            'pending_and_notify_registration'     => [
370
-                'func'       => 'pending_registration',
371
-                'noheader'   => true,
372
-                'args'       => [true],
373
-                'capability' => 'ee_edit_registration',
374
-                'obj_id'     => $REG_ID,
375
-            ],
376
-            'pending_registrations'               => [
377
-                'func'       => 'bulk_action_on_registrations',
378
-                'noheader'   => true,
379
-                'capability' => 'ee_edit_registrations',
380
-                'args'       => ['pending'],
381
-            ],
382
-            'pending_and_notify_registrations'    => [
383
-                'func'       => 'bulk_action_on_registrations',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_registrations',
386
-                'args'       => ['pending', true],
387
-            ],
388
-            'no_approve_registration'             => [
389
-                'func'       => 'not_approve_registration',
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_registration',
392
-                'obj_id'     => $REG_ID,
393
-            ],
394
-            'no_approve_and_notify_registration'  => [
395
-                'func'       => 'not_approve_registration',
396
-                'noheader'   => true,
397
-                'args'       => [true],
398
-                'capability' => 'ee_edit_registration',
399
-                'obj_id'     => $REG_ID,
400
-            ],
401
-            'no_approve_registrations'            => [
402
-                'func'       => 'bulk_action_on_registrations',
403
-                'noheader'   => true,
404
-                'capability' => 'ee_edit_registrations',
405
-                'args'       => ['not_approve'],
406
-            ],
407
-            'no_approve_and_notify_registrations' => [
408
-                'func'       => 'bulk_action_on_registrations',
409
-                'noheader'   => true,
410
-                'capability' => 'ee_edit_registrations',
411
-                'args'       => ['not_approve', true],
412
-            ],
413
-            'cancel_registration'                 => [
414
-                'func'       => 'cancel_registration',
415
-                'noheader'   => true,
416
-                'capability' => 'ee_edit_registration',
417
-                'obj_id'     => $REG_ID,
418
-            ],
419
-            'cancel_and_notify_registration'      => [
420
-                'func'       => 'cancel_registration',
421
-                'noheader'   => true,
422
-                'args'       => [true],
423
-                'capability' => 'ee_edit_registration',
424
-                'obj_id'     => $REG_ID,
425
-            ],
426
-            'cancel_registrations'                => [
427
-                'func'       => 'bulk_action_on_registrations',
428
-                'noheader'   => true,
429
-                'capability' => 'ee_edit_registrations',
430
-                'args'       => ['cancel'],
431
-            ],
432
-            'cancel_and_notify_registrations'     => [
433
-                'func'       => 'bulk_action_on_registrations',
434
-                'noheader'   => true,
435
-                'capability' => 'ee_edit_registrations',
436
-                'args'       => ['cancel', true],
437
-            ],
438
-            'wait_list_registration'              => [
439
-                'func'       => 'wait_list_registration',
440
-                'noheader'   => true,
441
-                'capability' => 'ee_edit_registration',
442
-                'obj_id'     => $REG_ID,
443
-            ],
444
-            'wait_list_and_notify_registration'   => [
445
-                'func'       => 'wait_list_registration',
446
-                'noheader'   => true,
447
-                'args'       => [true],
448
-                'capability' => 'ee_edit_registration',
449
-                'obj_id'     => $REG_ID,
450
-            ],
451
-            'contact_list'                        => [
452
-                'func'       => '_attendee_contact_list_table',
453
-                'capability' => 'ee_read_contacts',
454
-            ],
455
-            'add_new_attendee'                    => [
456
-                'func' => '_create_new_cpt_item',
457
-                'args' => [
458
-                    'new_attendee' => true,
459
-                    'capability'   => 'ee_edit_contacts',
460
-                ],
461
-            ],
462
-            'edit_attendee'                       => [
463
-                'func'       => '_edit_cpt_item',
464
-                'capability' => 'ee_edit_contacts',
465
-                'obj_id'     => $ATT_ID,
466
-            ],
467
-            'duplicate_attendee'                  => [
468
-                'func'       => '_duplicate_attendee',
469
-                'noheader'   => true,
470
-                'capability' => 'ee_edit_contacts',
471
-                'obj_id'     => $ATT_ID,
472
-            ],
473
-            'insert_attendee'                     => [
474
-                'func'       => '_insert_or_update_attendee',
475
-                'args'       => [
476
-                    'new_attendee' => true,
477
-                ],
478
-                'noheader'   => true,
479
-                'capability' => 'ee_edit_contacts',
480
-            ],
481
-            'update_attendee'                     => [
482
-                'func'       => '_insert_or_update_attendee',
483
-                'args'       => [
484
-                    'new_attendee' => false,
485
-                ],
486
-                'noheader'   => true,
487
-                'capability' => 'ee_edit_contacts',
488
-                'obj_id'     => $ATT_ID,
489
-            ],
490
-            'trash_attendees'                     => [
491
-                'func'       => '_trash_or_restore_attendees',
492
-                'args'       => [
493
-                    'trash' => 'true',
494
-                ],
495
-                'noheader'   => true,
496
-                'capability' => 'ee_delete_contacts',
497
-            ],
498
-            'trash_attendee'                      => [
499
-                'func'       => '_trash_or_restore_attendees',
500
-                'args'       => [
501
-                    'trash' => true,
502
-                ],
503
-                'noheader'   => true,
504
-                'capability' => 'ee_delete_contacts',
505
-                'obj_id'     => $ATT_ID,
506
-            ],
507
-            'restore_attendees'                   => [
508
-                'func'       => '_trash_or_restore_attendees',
509
-                'args'       => [
510
-                    'trash' => false,
511
-                ],
512
-                'noheader'   => true,
513
-                'capability' => 'ee_delete_contacts',
514
-                'obj_id'     => $ATT_ID,
515
-            ],
516
-            'resend_registration'                 => [
517
-                'func'       => '_resend_registration',
518
-                'noheader'   => true,
519
-                'capability' => 'ee_send_message',
520
-            ],
521
-            'registrations_report'                => [
522
-                'func'       => [$this, '_registrations_report'],
523
-                'noheader'   => true,
524
-                'capability' => 'ee_read_registrations',
525
-            ],
526
-            'contact_list_export'                 => [
527
-                'func'       => '_contact_list_export',
528
-                'noheader'   => true,
529
-                'capability' => 'export',
530
-            ],
531
-            'contact_list_report'                 => [
532
-                'func'       => '_contact_list_report',
533
-                'noheader'   => true,
534
-                'capability' => 'ee_read_contacts',
535
-            ],
536
-        ];
537
-    }
538
-
539
-
540
-    protected function _set_page_config()
541
-    {
542
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
-        $this->_page_config = [
545
-            'default'           => [
546
-                'nav'           => [
547
-                    'label' => esc_html__('Overview', 'event_espresso'),
548
-                    'order' => 5,
549
-                ],
550
-                'help_tabs'     => [
551
-                    'registrations_overview_help_tab'                       => [
552
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
-                        'filename' => 'registrations_overview',
554
-                    ],
555
-                    'registrations_overview_table_column_headings_help_tab' => [
556
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
-                        'filename' => 'registrations_overview_table_column_headings',
558
-                    ],
559
-                    'registrations_overview_filters_help_tab'               => [
560
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
-                        'filename' => 'registrations_overview_filters',
562
-                    ],
563
-                    'registrations_overview_views_help_tab'                 => [
564
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
565
-                        'filename' => 'registrations_overview_views',
566
-                    ],
567
-                    'registrations_regoverview_other_help_tab'              => [
568
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
-                        'filename' => 'registrations_overview_other',
570
-                    ],
571
-                ],
572
-                'qtips'         => ['Registration_List_Table_Tips'],
573
-                'list_table'    => 'EE_Registrations_List_Table',
574
-                'require_nonce' => false,
575
-            ],
576
-            'view_registration' => [
577
-                'nav'           => [
578
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
579
-                    'order'      => 15,
580
-                    'url'        => $REG_ID
581
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
-                        : $this->_admin_base_url,
583
-                    'persistent' => false,
584
-                ],
585
-                'help_tabs'     => [
586
-                    'registrations_details_help_tab'                    => [
587
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
588
-                        'filename' => 'registrations_details',
589
-                    ],
590
-                    'registrations_details_table_help_tab'              => [
591
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
-                        'filename' => 'registrations_details_table',
593
-                    ],
594
-                    'registrations_details_form_answers_help_tab'       => [
595
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
-                        'filename' => 'registrations_details_form_answers',
597
-                    ],
598
-                    'registrations_details_registrant_details_help_tab' => [
599
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
600
-                        'filename' => 'registrations_details_registrant_details',
601
-                    ],
602
-                ],
603
-                'metaboxes'     => array_merge(
604
-                    $this->_default_espresso_metaboxes,
605
-                    ['_registration_details_metaboxes']
606
-                ),
607
-                'require_nonce' => false,
608
-            ],
609
-            'new_registration'  => [
610
-                'nav'           => [
611
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
-                    'url'        => '#',
613
-                    'order'      => 15,
614
-                    'persistent' => false,
615
-                ],
616
-                'metaboxes'     => $this->_default_espresso_metaboxes,
617
-                'labels'        => [
618
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
-                ],
620
-                'require_nonce' => false,
621
-            ],
622
-            'add_new_attendee'  => [
623
-                'nav'           => [
624
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
625
-                    'order'      => 15,
626
-                    'persistent' => false,
627
-                ],
628
-                'metaboxes'     => array_merge(
629
-                    $this->_default_espresso_metaboxes,
630
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
631
-                ),
632
-                'require_nonce' => false,
633
-            ],
634
-            'edit_attendee'     => [
635
-                'nav'           => [
636
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
-                    'order'      => 15,
638
-                    'persistent' => false,
639
-                    'url'        => $ATT_ID
640
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
-                        : $this->_admin_base_url,
642
-                ],
643
-                'metaboxes'     => ['attendee_editor_metaboxes'],
644
-                'require_nonce' => false,
645
-            ],
646
-            'contact_list'      => [
647
-                'nav'           => [
648
-                    'label' => esc_html__('Contact List', 'event_espresso'),
649
-                    'order' => 20,
650
-                ],
651
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
652
-                'help_tabs'     => [
653
-                    'registrations_contact_list_help_tab'                       => [
654
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
655
-                        'filename' => 'registrations_contact_list',
656
-                    ],
657
-                    'registrations_contact-list_table_column_headings_help_tab' => [
658
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
659
-                        'filename' => 'registrations_contact_list_table_column_headings',
660
-                    ],
661
-                    'registrations_contact_list_views_help_tab'                 => [
662
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
663
-                        'filename' => 'registrations_contact_list_views',
664
-                    ],
665
-                    'registrations_contact_list_other_help_tab'                 => [
666
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
667
-                        'filename' => 'registrations_contact_list_other',
668
-                    ],
669
-                ],
670
-                'metaboxes'     => [],
671
-                'require_nonce' => false,
672
-            ],
673
-            // override default cpt routes
674
-            'create_new'        => '',
675
-            'edit'              => '',
676
-        ];
677
-    }
678
-
679
-
680
-    /**
681
-     * The below methods aren't used by this class currently
682
-     */
683
-    protected function _add_screen_options()
684
-    {
685
-    }
686
-
687
-
688
-    protected function _add_feature_pointers()
689
-    {
690
-    }
691
-
692
-
693
-    public function admin_init()
694
-    {
695
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
696
-            'click "Update Registration Questions" to save your changes',
697
-            'event_espresso'
698
-        );
699
-    }
700
-
701
-
702
-    public function admin_notices()
703
-    {
704
-    }
705
-
706
-
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
710
-
711
-
712
-    /**
713
-     * get list of registration statuses
714
-     *
715
-     * @return void
716
-     * @throws EE_Error
717
-     */
718
-    private function _get_registration_status_array()
719
-    {
720
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
721
-    }
722
-
723
-
724
-    /**
725
-     * @throws InvalidArgumentException
726
-     * @throws InvalidDataTypeException
727
-     * @throws InvalidInterfaceException
728
-     * @since 4.10.2.p
729
-     */
730
-    protected function _add_screen_options_default()
731
-    {
732
-        $this->_per_page_screen_option();
733
-    }
734
-
735
-
736
-    /**
737
-     * @throws InvalidArgumentException
738
-     * @throws InvalidDataTypeException
739
-     * @throws InvalidInterfaceException
740
-     * @since 4.10.2.p
741
-     */
742
-    protected function _add_screen_options_contact_list()
743
-    {
744
-        $page_title              = $this->_admin_page_title;
745
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
746
-        $this->_per_page_screen_option();
747
-        $this->_admin_page_title = $page_title;
748
-    }
749
-
750
-
751
-    public function load_scripts_styles()
752
-    {
753
-        // style
754
-        wp_register_style(
755
-            'espresso_reg',
756
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
757
-            ['ee-admin-css'],
758
-            EVENT_ESPRESSO_VERSION
759
-        );
760
-        wp_enqueue_style('espresso_reg');
761
-        // script
762
-        wp_register_script(
763
-            'espresso_reg',
764
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
765
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
766
-            EVENT_ESPRESSO_VERSION,
767
-            true
768
-        );
769
-        wp_enqueue_script('espresso_reg');
770
-    }
771
-
772
-
773
-    /**
774
-     * @throws EE_Error
775
-     * @throws InvalidArgumentException
776
-     * @throws InvalidDataTypeException
777
-     * @throws InvalidInterfaceException
778
-     * @throws ReflectionException
779
-     * @since 4.10.2.p
780
-     */
781
-    public function load_scripts_styles_edit_attendee()
782
-    {
783
-        // stuff to only show up on our attendee edit details page.
784
-        $attendee_details_translations = [
785
-            'att_publish_text' => sprintf(
786
-            /* translators: The date and time */
787
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
788
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
789
-            ),
790
-        ];
791
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
792
-        wp_enqueue_script('jquery-validate');
793
-    }
794
-
795
-
796
-    /**
797
-     * @throws EE_Error
798
-     * @throws InvalidArgumentException
799
-     * @throws InvalidDataTypeException
800
-     * @throws InvalidInterfaceException
801
-     * @throws ReflectionException
802
-     * @since 4.10.2.p
803
-     */
804
-    public function load_scripts_styles_view_registration()
805
-    {
806
-        // styles
807
-        wp_enqueue_style('espresso-ui-theme');
808
-        // scripts
809
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
810
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
811
-    }
812
-
813
-
814
-    public function load_scripts_styles_contact_list()
815
-    {
816
-        wp_dequeue_style('espresso_reg');
817
-        wp_register_style(
818
-            'espresso_att',
819
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
820
-            ['ee-admin-css'],
821
-            EVENT_ESPRESSO_VERSION
822
-        );
823
-        wp_enqueue_style('espresso_att');
824
-    }
825
-
826
-
827
-    public function load_scripts_styles_new_registration()
828
-    {
829
-        wp_register_script(
830
-            'ee-spco-for-admin',
831
-            REG_ASSETS_URL . 'spco_for_admin.js',
832
-            ['underscore', 'jquery'],
833
-            EVENT_ESPRESSO_VERSION,
834
-            true
835
-        );
836
-        wp_enqueue_script('ee-spco-for-admin');
837
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
838
-        EE_Form_Section_Proper::wp_enqueue_scripts();
839
-        EED_Ticket_Selector::load_tckt_slctr_assets();
840
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
841
-    }
842
-
843
-
844
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
845
-    {
846
-        add_filter('FHEE_load_EE_messages', '__return_true');
847
-    }
848
-
849
-
850
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
851
-    {
852
-        add_filter('FHEE_load_EE_messages', '__return_true');
853
-    }
854
-
855
-
856
-    /**
857
-     * @throws EE_Error
858
-     * @throws InvalidArgumentException
859
-     * @throws InvalidDataTypeException
860
-     * @throws InvalidInterfaceException
861
-     * @throws ReflectionException
862
-     * @since 4.10.2.p
863
-     */
864
-    protected function _set_list_table_views_default()
865
-    {
866
-        // for notification related bulk actions we need to make sure only active messengers have an option.
867
-        EED_Messages::set_autoloaders();
868
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
869
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
870
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
871
-        // key= bulk_action_slug, value= message type.
872
-        $match_array = [
873
-            'approve_registrations'    => 'registration',
874
-            'decline_registrations'    => 'declined_registration',
875
-            'pending_registrations'    => 'pending_approval',
876
-            'no_approve_registrations' => 'not_approved_registration',
877
-            'cancel_registrations'     => 'cancelled_registration',
878
-        ];
879
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
880
-            'ee_send_message',
881
-            'batch_send_messages'
882
-        );
883
-        /** setup reg status bulk actions **/
884
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
885
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
886
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
887
-                'Approve and Notify Registrations',
888
-                'event_espresso'
889
-            );
890
-        }
891
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
892
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
893
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
894
-                'Decline and Notify Registrations',
895
-                'event_espresso'
896
-            );
897
-        }
898
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
899
-            'Set Registrations to Pending Payment',
900
-            'event_espresso'
901
-        );
902
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
903
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
904
-                'Set Registrations to Pending Payment and Notify',
905
-                'event_espresso'
906
-            );
907
-        }
908
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
909
-            'Set Registrations to Not Approved',
910
-            'event_espresso'
911
-        );
912
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
913
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
914
-                'Set Registrations to Not Approved and Notify',
915
-                'event_espresso'
916
-            );
917
-        }
918
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
919
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
920
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
921
-                'Cancel Registrations and Notify',
922
-                'event_espresso'
923
-            );
924
-        }
925
-        $def_reg_status_actions = apply_filters(
926
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
927
-            $def_reg_status_actions,
928
-            $active_mts,
929
-            $can_send
930
-        );
931
-
932
-        $this->_views = [
933
-            'all'   => [
934
-                'slug'        => 'all',
935
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
936
-                'count'       => 0,
937
-                'bulk_action' => array_merge(
938
-                    $def_reg_status_actions,
939
-                    [
940
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
941
-                    ]
942
-                ),
943
-            ],
944
-            'month' => [
945
-                'slug'        => 'month',
946
-                'label'       => esc_html__('This Month', 'event_espresso'),
947
-                'count'       => 0,
948
-                'bulk_action' => array_merge(
949
-                    $def_reg_status_actions,
950
-                    [
951
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
952
-                    ]
953
-                ),
954
-            ],
955
-            'today' => [
956
-                'slug'        => 'today',
957
-                'label'       => sprintf(
958
-                    esc_html__('Today - %s', 'event_espresso'),
959
-                    date('M d, Y', current_time('timestamp'))
960
-                ),
961
-                'count'       => 0,
962
-                'bulk_action' => array_merge(
963
-                    $def_reg_status_actions,
964
-                    [
965
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
966
-                    ]
967
-                ),
968
-            ],
969
-        ];
970
-        if (
971
-            EE_Registry::instance()->CAP->current_user_can(
972
-                'ee_delete_registrations',
973
-                'espresso_registrations_delete_registration'
974
-            )
975
-        ) {
976
-            $this->_views['incomplete'] = [
977
-                'slug'        => 'incomplete',
978
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
979
-                'count'       => 0,
980
-                'bulk_action' => [
981
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
-                ],
983
-            ];
984
-            $this->_views['trash']      = [
985
-                'slug'        => 'trash',
986
-                'label'       => esc_html__('Trash', 'event_espresso'),
987
-                'count'       => 0,
988
-                'bulk_action' => [
989
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
-                ],
992
-            ];
993
-        }
994
-    }
995
-
996
-
997
-    protected function _set_list_table_views_contact_list()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'        => 'in_use',
1002
-                'label'       => esc_html__('In Use', 'event_espresso'),
1003
-                'count'       => 0,
1004
-                'bulk_action' => [
1005
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
-                ],
1007
-            ],
1008
-        ];
1009
-        if (
1010
-            EE_Registry::instance()->CAP->current_user_can(
1011
-                'ee_delete_contacts',
1012
-                'espresso_registrations_trash_attendees'
1013
-            )
1014
-        ) {
1015
-            $this->_views['trash'] = [
1016
-                'slug'        => 'trash',
1017
-                'label'       => esc_html__('Trash', 'event_espresso'),
1018
-                'count'       => 0,
1019
-                'bulk_action' => [
1020
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1021
-                ],
1022
-            ];
1023
-        }
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * @return array
1029
-     * @throws EE_Error
1030
-     */
1031
-    protected function _registration_legend_items()
1032
-    {
1033
-        $fc_items = [
1034
-            'star-icon'        => [
1035
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1037
-            ],
1038
-            'view_details'     => [
1039
-                'class' => 'dashicons dashicons-clipboard',
1040
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1041
-            ],
1042
-            'edit_attendee'    => [
1043
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1044
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1045
-            ],
1046
-            'view_transaction' => [
1047
-                'class' => 'dashicons dashicons-cart',
1048
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1049
-            ],
1050
-            'view_invoice'     => [
1051
-                'class' => 'dashicons dashicons-media-spreadsheet',
1052
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1053
-            ],
1054
-        ];
1055
-        if (
1056
-            EE_Registry::instance()->CAP->current_user_can(
1057
-                'ee_send_message',
1058
-                'espresso_registrations_resend_registration'
1059
-            )
1060
-        ) {
1061
-            $fc_items['resend_registration'] = [
1062
-                'class' => 'dashicons dashicons-email-alt',
1063
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1064
-            ];
1065
-        } else {
1066
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1067
-        }
1068
-        if (
1069
-            EE_Registry::instance()->CAP->current_user_can(
1070
-                'ee_read_global_messages',
1071
-                'view_filtered_messages'
1072
-            )
1073
-        ) {
1074
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1075
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1076
-                $fc_items['view_related_messages'] = [
1077
-                    'class' => $related_for_icon['css_class'],
1078
-                    'desc'  => $related_for_icon['label'],
1079
-                ];
1080
-            }
1081
-        }
1082
-        $sc_items = [
1083
-            'approved_status'   => [
1084
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1085
-                'desc'  => EEH_Template::pretty_status(
1086
-                    EEM_Registration::status_id_approved,
1087
-                    false,
1088
-                    'sentence'
1089
-                ),
1090
-            ],
1091
-            'pending_status'    => [
1092
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1093
-                'desc'  => EEH_Template::pretty_status(
1094
-                    EEM_Registration::status_id_pending_payment,
1095
-                    false,
1096
-                    'sentence'
1097
-                ),
1098
-            ],
1099
-            'wait_list'         => [
1100
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1101
-                'desc'  => EEH_Template::pretty_status(
1102
-                    EEM_Registration::status_id_wait_list,
1103
-                    false,
1104
-                    'sentence'
1105
-                ),
1106
-            ],
1107
-            'incomplete_status' => [
1108
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1109
-                'desc'  => EEH_Template::pretty_status(
1110
-                    EEM_Registration::status_id_incomplete,
1111
-                    false,
1112
-                    'sentence'
1113
-                ),
1114
-            ],
1115
-            'not_approved'      => [
1116
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1117
-                'desc'  => EEH_Template::pretty_status(
1118
-                    EEM_Registration::status_id_not_approved,
1119
-                    false,
1120
-                    'sentence'
1121
-                ),
1122
-            ],
1123
-            'declined_status'   => [
1124
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1125
-                'desc'  => EEH_Template::pretty_status(
1126
-                    EEM_Registration::status_id_declined,
1127
-                    false,
1128
-                    'sentence'
1129
-                ),
1130
-            ],
1131
-            'cancelled_status'  => [
1132
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1133
-                'desc'  => EEH_Template::pretty_status(
1134
-                    EEM_Registration::status_id_cancelled,
1135
-                    false,
1136
-                    'sentence'
1137
-                ),
1138
-            ],
1139
-        ];
1140
-        return array_merge($fc_items, $sc_items);
1141
-    }
1142
-
1143
-
1144
-
1145
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1146
-
1147
-
1148
-    /**
1149
-     * @throws DomainException
1150
-     * @throws EE_Error
1151
-     * @throws InvalidArgumentException
1152
-     * @throws InvalidDataTypeException
1153
-     * @throws InvalidInterfaceException
1154
-     */
1155
-    protected function _registrations_overview_list_table()
1156
-    {
1157
-        $this->appendAddNewRegistrationButtonToPageTitle();
1158
-        $header_text                  = '';
1159
-        $admin_page_header_decorators = [
1160
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
-        ];
1165
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
-            $filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1167
-            $header_text             = $filter_header_decorator->getHeaderText($header_text);
1168
-        }
1169
-        $this->_template_args['admin_page_header'] = $header_text;
1170
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1171
-        $this->display_admin_list_table_page_with_no_sidebar();
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * @throws EE_Error
1177
-     * @throws InvalidArgumentException
1178
-     * @throws InvalidDataTypeException
1179
-     * @throws InvalidInterfaceException
1180
-     */
1181
-    private function appendAddNewRegistrationButtonToPageTitle()
1182
-    {
1183
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1184
-        if (
1185
-            $EVT_ID
1186
-            && EE_Registry::instance()->CAP->current_user_can(
1187
-                'ee_edit_registrations',
1188
-                'espresso_registrations_new_registration',
1189
-                $EVT_ID
1190
-            )
1191
-        ) {
1192
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1193
-                'new_registration',
1194
-                'add-registrant',
1195
-                ['event_id' => $EVT_ID],
1196
-                'add-new-h2'
1197
-            );
1198
-        }
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * This sets the _registration property for the registration details screen
1204
-     *
1205
-     * @return void
1206
-     * @throws EE_Error
1207
-     * @throws InvalidArgumentException
1208
-     * @throws InvalidDataTypeException
1209
-     * @throws InvalidInterfaceException
1210
-     */
1211
-    private function _set_registration_object()
1212
-    {
1213
-        // get out if we've already set the object
1214
-        if ($this->_registration instanceof EE_Registration) {
1215
-            return;
1216
-        }
1217
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1218
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1219
-            return;
1220
-        }
1221
-        $error_msg = sprintf(
1222
-            esc_html__(
1223
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1224
-                'event_espresso'
1225
-            ),
1226
-            $REG_ID
1227
-        );
1228
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1229
-        $this->_registration = null;
1230
-    }
1231
-
1232
-
1233
-    /**
1234
-     * Used to retrieve registrations for the list table.
1235
-     *
1236
-     * @param int  $per_page
1237
-     * @param bool $count
1238
-     * @param bool $this_month
1239
-     * @param bool $today
1240
-     * @return EE_Registration[]|int
1241
-     * @throws EE_Error
1242
-     * @throws InvalidArgumentException
1243
-     * @throws InvalidDataTypeException
1244
-     * @throws InvalidInterfaceException
1245
-     */
1246
-    public function get_registrations(
1247
-        $per_page = 10,
1248
-        $count = false,
1249
-        $this_month = false,
1250
-        $today = false
1251
-    ) {
1252
-        if ($this_month) {
1253
-            $this->request->setRequestParam('status', 'month');
1254
-        }
1255
-        if ($today) {
1256
-            $this->request->setRequestParam('status', 'today');
1257
-        }
1258
-        $query_params = $this->_get_registration_query_parameters([], $per_page, $count);
1259
-        /**
1260
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1261
-         *
1262
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1263
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1264
-         *                      or if you have the development copy of EE you can view this at the path:
1265
-         *                      /docs/G--Model-System/model-query-params.md
1266
-         */
1267
-        $query_params['group_by'] = '';
1268
-
1269
-        return $count
1270
-            ? $this->getRegistrationModel()->count($query_params)
1271
-            /** @type EE_Registration[] */
1272
-            : $this->getRegistrationModel()->get_all($query_params);
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1278
-     * Note: this listens to values on the request for some of the query parameters.
1279
-     *
1280
-     * @param array $request
1281
-     * @param int   $per_page
1282
-     * @param bool  $count
1283
-     * @return array
1284
-     * @throws EE_Error
1285
-     * @throws InvalidArgumentException
1286
-     * @throws InvalidDataTypeException
1287
-     * @throws InvalidInterfaceException
1288
-     */
1289
-    protected function _get_registration_query_parameters(
1290
-        $request = [],
1291
-        $per_page = 10,
1292
-        $count = false
1293
-    ) {
1294
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1295
-        $list_table_query_builder = $this->getLoader()->getNew(
1296
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1297
-            [null, null, $request]
1298
-        );
1299
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1300
-    }
1301
-
1302
-
1303
-    public function get_registration_status_array()
1304
-    {
1305
-        return self::$_reg_status;
1306
-    }
1307
-
1308
-
1309
-
1310
-
1311
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1312
-    /**
1313
-     * generates HTML for the View Registration Details Admin page
1314
-     *
1315
-     * @return void
1316
-     * @throws DomainException
1317
-     * @throws EE_Error
1318
-     * @throws InvalidArgumentException
1319
-     * @throws InvalidDataTypeException
1320
-     * @throws InvalidInterfaceException
1321
-     * @throws EntityNotFoundException
1322
-     * @throws ReflectionException
1323
-     */
1324
-    protected function _registration_details()
1325
-    {
1326
-        $this->_template_args = [];
1327
-        $this->_set_registration_object();
1328
-        if (is_object($this->_registration)) {
1329
-            $transaction                                   = $this->_registration->transaction()
1330
-                ? $this->_registration->transaction()
1331
-                : EE_Transaction::new_instance();
1332
-            $this->_session                                = $transaction->session_data();
1333
-            $event_id                                      = $this->_registration->event_ID();
1334
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1335
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1336
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1337
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1338
-            $this->_template_args['grand_total']           = $transaction->total();
1339
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1340
-            // link back to overview
1341
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1342
-            $this->_template_args['registration']                = $this->_registration;
1343
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
-                [
1345
-                    'action'   => 'default',
1346
-                    'event_id' => $event_id,
1347
-                ],
1348
-                REG_ADMIN_URL
1349
-            );
1350
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1351
-                [
1352
-                    'action' => 'default',
1353
-                    'EVT_ID' => $event_id,
1354
-                    'page'   => 'espresso_transactions',
1355
-                ],
1356
-                admin_url('admin.php')
1357
-            );
1358
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1359
-                [
1360
-                    'page'   => 'espresso_events',
1361
-                    'action' => 'edit',
1362
-                    'post'   => $event_id,
1363
-                ],
1364
-                admin_url('admin.php')
1365
-            );
1366
-            // next and previous links
1367
-            $next_reg                                      = $this->_registration->next(
1368
-                null,
1369
-                [],
1370
-                'REG_ID'
1371
-            );
1372
-            $this->_template_args['next_registration']     = $next_reg
1373
-                ? $this->_next_link(
1374
-                    EE_Admin_Page::add_query_args_and_nonce(
1375
-                        [
1376
-                            'action'  => 'view_registration',
1377
-                            '_REG_ID' => $next_reg['REG_ID'],
1378
-                        ],
1379
-                        REG_ADMIN_URL
1380
-                    ),
1381
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1382
-                )
1383
-                : '';
1384
-            $previous_reg                                  = $this->_registration->previous(
1385
-                null,
1386
-                [],
1387
-                'REG_ID'
1388
-            );
1389
-            $this->_template_args['previous_registration'] = $previous_reg
1390
-                ? $this->_previous_link(
1391
-                    EE_Admin_Page::add_query_args_and_nonce(
1392
-                        [
1393
-                            'action'  => 'view_registration',
1394
-                            '_REG_ID' => $previous_reg['REG_ID'],
1395
-                        ],
1396
-                        REG_ADMIN_URL
1397
-                    ),
1398
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1399
-                )
1400
-                : '';
1401
-            // grab header
1402
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1403
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1404
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1405
-                $template_path,
1406
-                $this->_template_args,
1407
-                true
1408
-            );
1409
-        } else {
1410
-            $this->_template_args['admin_page_header'] = '';
1411
-            $this->_display_espresso_notices();
1412
-        }
1413
-        // the details template wrapper
1414
-        $this->display_admin_page_with_sidebar();
1415
-    }
1416
-
1417
-
1418
-    /**
1419
-     * @throws EE_Error
1420
-     * @throws InvalidArgumentException
1421
-     * @throws InvalidDataTypeException
1422
-     * @throws InvalidInterfaceException
1423
-     * @throws ReflectionException
1424
-     * @since 4.10.2.p
1425
-     */
1426
-    protected function _registration_details_metaboxes()
1427
-    {
1428
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1429
-        $this->_set_registration_object();
1430
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1431
-        add_meta_box(
1432
-            'edit-reg-status-mbox',
1433
-            esc_html__('Registration Status', 'event_espresso'),
1434
-            [$this, 'set_reg_status_buttons_metabox'],
1435
-            $this->_wp_page_slug,
1436
-            'normal',
1437
-            'high'
1438
-        );
1439
-        add_meta_box(
1440
-            'edit-reg-details-mbox',
1441
-            esc_html__('Registration Details', 'event_espresso'),
1442
-            [$this, '_reg_details_meta_box'],
1443
-            $this->_wp_page_slug,
1444
-            'normal',
1445
-            'high'
1446
-        );
1447
-        if (
1448
-            $attendee instanceof EE_Attendee
1449
-            && EE_Registry::instance()->CAP->current_user_can(
1450
-                'ee_read_registration',
1451
-                'edit-reg-questions-mbox',
1452
-                $this->_registration->ID()
1453
-            )
1454
-        ) {
1455
-            add_meta_box(
1456
-                'edit-reg-questions-mbox',
1457
-                esc_html__('Registration Form Answers', 'event_espresso'),
1458
-                [$this, '_reg_questions_meta_box'],
1459
-                $this->_wp_page_slug,
1460
-                'normal',
1461
-                'high'
1462
-            );
1463
-        }
1464
-        add_meta_box(
1465
-            'edit-reg-registrant-mbox',
1466
-            esc_html__('Contact Details', 'event_espresso'),
1467
-            [$this, '_reg_registrant_side_meta_box'],
1468
-            $this->_wp_page_slug,
1469
-            'side',
1470
-            'high'
1471
-        );
1472
-        if ($this->_registration->group_size() > 1) {
1473
-            add_meta_box(
1474
-                'edit-reg-attendees-mbox',
1475
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1476
-                [$this, '_reg_attendees_meta_box'],
1477
-                $this->_wp_page_slug,
1478
-                'normal',
1479
-                'high'
1480
-            );
1481
-        }
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * set_reg_status_buttons_metabox
1487
-     *
1488
-     * @return void
1489
-     * @throws EE_Error
1490
-     * @throws EntityNotFoundException
1491
-     * @throws InvalidArgumentException
1492
-     * @throws InvalidDataTypeException
1493
-     * @throws InvalidInterfaceException
1494
-     * @throws ReflectionException
1495
-     */
1496
-    public function set_reg_status_buttons_metabox()
1497
-    {
1498
-        $this->_set_registration_object();
1499
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1500
-        $output                 = $change_reg_status_form->form_open(
1501
-            self::add_query_args_and_nonce(
1502
-                [
1503
-                    'action' => 'change_reg_status',
1504
-                ],
1505
-                REG_ADMIN_URL
1506
-            )
1507
-        );
1508
-        $output                 .= $change_reg_status_form->get_html();
1509
-        $output                 .= $change_reg_status_form->form_close();
1510
-        echo wp_kses($output, AllowedTags::getWithFormTags());
1511
-    }
1512
-
1513
-
1514
-    /**
1515
-     * @return EE_Form_Section_Proper
1516
-     * @throws EE_Error
1517
-     * @throws InvalidArgumentException
1518
-     * @throws InvalidDataTypeException
1519
-     * @throws InvalidInterfaceException
1520
-     * @throws EntityNotFoundException
1521
-     * @throws ReflectionException
1522
-     */
1523
-    protected function _generate_reg_status_change_form()
1524
-    {
1525
-        $reg_status_change_form_array = [
1526
-            'name'            => 'reg_status_change_form',
1527
-            'html_id'         => 'reg-status-change-form',
1528
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1529
-            'subsections'     => [
1530
-                'return'         => new EE_Hidden_Input(
1531
-                    [
1532
-                        'name'    => 'return',
1533
-                        'default' => 'view_registration',
1534
-                    ]
1535
-                ),
1536
-                'REG_ID'         => new EE_Hidden_Input(
1537
-                    [
1538
-                        'name'    => 'REG_ID',
1539
-                        'default' => $this->_registration->ID(),
1540
-                    ]
1541
-                ),
1542
-                'current_status' => new EE_Form_Section_HTML(
1543
-                    EEH_HTML::table(
1544
-                        EEH_HTML::tr(
1545
-                            EEH_HTML::th(
1546
-                                EEH_HTML::label(
1547
-                                    EEH_HTML::strong(
1548
-                                        esc_html__('Current Registration Status', 'event_espresso')
1549
-                                    )
1550
-                                )
1551
-                            )
1552
-                            . EEH_HTML::td(
1553
-                                EEH_HTML::strong(
1554
-                                    $this->_registration->pretty_status(),
1555
-                                    '',
1556
-                                    'status-' . $this->_registration->status_ID(),
1557
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1558
-                                )
1559
-                            )
1560
-                        )
1561
-                    )
1562
-                ),
1563
-            ],
1564
-        ];
1565
-        if (
1566
-            EE_Registry::instance()->CAP->current_user_can(
1567
-                'ee_edit_registration',
1568
-                'toggle_registration_status',
1569
-                $this->_registration->ID()
1570
-            )
1571
-        ) {
1572
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1573
-                $this->_get_reg_statuses(),
1574
-                [
1575
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1576
-                    'default'         => $this->_registration->status_ID(),
1577
-                ]
1578
-            );
1579
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1580
-                [
1581
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1582
-                    'default'         => false,
1583
-                    'html_help_text'  => esc_html__(
1584
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1585
-                        'event_espresso'
1586
-                    ),
1587
-                ]
1588
-            );
1589
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1590
-                [
1591
-                    'html_class'      => 'button-primary',
1592
-                    'html_label_text' => '&nbsp;',
1593
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1594
-                ]
1595
-            );
1596
-        }
1597
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     * Returns an array of all the buttons for the various statuses and switch status actions
1603
-     *
1604
-     * @return array
1605
-     * @throws EE_Error
1606
-     * @throws InvalidArgumentException
1607
-     * @throws InvalidDataTypeException
1608
-     * @throws InvalidInterfaceException
1609
-     * @throws EntityNotFoundException
1610
-     */
1611
-    protected function _get_reg_statuses()
1612
-    {
1613
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1614
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1615
-        // get current reg status
1616
-        $current_status = $this->_registration->status_ID();
1617
-        // is registration for free event? This will determine whether to display the pending payment option
1618
-        if (
1619
-            $current_status !== EEM_Registration::status_id_pending_payment
1620
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1621
-        ) {
1622
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1623
-        }
1624
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1625
-    }
1626
-
1627
-
1628
-    /**
1629
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1630
-     *
1631
-     * @param bool $status REG status given for changing registrations to.
1632
-     * @param bool $notify Whether to send messages notifications or not.
1633
-     * @return array (array with reg_id(s) updated and whether update was successful.
1634
-     * @throws DomainException
1635
-     * @throws EE_Error
1636
-     * @throws EntityNotFoundException
1637
-     * @throws InvalidArgumentException
1638
-     * @throws InvalidDataTypeException
1639
-     * @throws InvalidInterfaceException
1640
-     * @throws ReflectionException
1641
-     * @throws RuntimeException
1642
-     */
1643
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1644
-    {
1645
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1646
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1647
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1648
-
1649
-        // sanitize $REG_IDs
1650
-        $REG_IDs = array_map('absint', $REG_IDs);
1651
-        // and remove empty entries
1652
-        $REG_IDs = array_filter($REG_IDs);
1653
-
1654
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1655
-
1656
-        /**
1657
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1658
-         * Currently this value is used downstream by the _process_resend_registration method.
1659
-         *
1660
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1661
-         * @param bool                     $status           The status registrations were changed to.
1662
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1663
-         * @param Registrations_Admin_Page $admin_page
1664
-         */
1665
-        $REG_ID = apply_filters(
1666
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1667
-            $result['REG_ID'],
1668
-            $status,
1669
-            $result['success'],
1670
-            $this
1671
-        );
1672
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1673
-
1674
-        // notify?
1675
-        if (
1676
-            $notify
1677
-            && $result['success']
1678
-            && ! empty($REG_ID)
1679
-            && EE_Registry::instance()->CAP->current_user_can(
1680
-                'ee_send_message',
1681
-                'espresso_registrations_resend_registration'
1682
-            )
1683
-        ) {
1684
-            $this->_process_resend_registration();
1685
-        }
1686
-        return $result;
1687
-    }
1688
-
1689
-
1690
-    /**
1691
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1692
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1693
-     *
1694
-     * @param array  $REG_IDs
1695
-     * @param string $status
1696
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1697
-     *                       slug sent with setting the registration status.
1698
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1699
-     * @throws EE_Error
1700
-     * @throws InvalidArgumentException
1701
-     * @throws InvalidDataTypeException
1702
-     * @throws InvalidInterfaceException
1703
-     * @throws ReflectionException
1704
-     * @throws RuntimeException
1705
-     * @throws EntityNotFoundException
1706
-     * @throws DomainException
1707
-     */
1708
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1709
-    {
1710
-        $success = false;
1711
-        // typecast $REG_IDs
1712
-        $REG_IDs = (array) $REG_IDs;
1713
-        if (! empty($REG_IDs)) {
1714
-            $success = true;
1715
-            // set default status if none is passed
1716
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1717
-            $status_context = $notify
1718
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1719
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1720
-            // loop through REG_ID's and change status
1721
-            foreach ($REG_IDs as $REG_ID) {
1722
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1723
-                if ($registration instanceof EE_Registration) {
1724
-                    $registration->set_status(
1725
-                        $status,
1726
-                        false,
1727
-                        new Context(
1728
-                            $status_context,
1729
-                            esc_html__(
1730
-                                'Manually triggered status change on a Registration Admin Page route.',
1731
-                                'event_espresso'
1732
-                            )
1733
-                        )
1734
-                    );
1735
-                    $result = $registration->save();
1736
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1737
-                    $success = $result !== false ? $success : false;
1738
-                }
1739
-            }
1740
-        }
1741
-
1742
-        // return $success and processed registrations
1743
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1744
-    }
1745
-
1746
-
1747
-    /**
1748
-     * Common logic for setting up success message and redirecting to appropriate route
1749
-     *
1750
-     * @param string $STS_ID status id for the registration changed to
1751
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1752
-     * @return void
1753
-     * @throws DomainException
1754
-     * @throws EE_Error
1755
-     * @throws EntityNotFoundException
1756
-     * @throws InvalidArgumentException
1757
-     * @throws InvalidDataTypeException
1758
-     * @throws InvalidInterfaceException
1759
-     * @throws ReflectionException
1760
-     * @throws RuntimeException
1761
-     */
1762
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1763
-    {
1764
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1765
-            : ['success' => false];
1766
-        $success = isset($result['success']) && $result['success'];
1767
-        // setup success message
1768
-        if ($success) {
1769
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1770
-                $msg = sprintf(
1771
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1772
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
-                );
1774
-            } else {
1775
-                $msg = sprintf(
1776
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1777
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1778
-                );
1779
-            }
1780
-            EE_Error::add_success($msg);
1781
-        } else {
1782
-            EE_Error::add_error(
1783
-                esc_html__(
1784
-                    'Something went wrong, and the status was not changed',
1785
-                    'event_espresso'
1786
-                ),
1787
-                __FILE__,
1788
-                __LINE__,
1789
-                __FUNCTION__
1790
-            );
1791
-        }
1792
-        $return = $this->request->getRequestParam('return');
1793
-        $route  = $return === 'view_registration'
1794
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1795
-            : ['action' => 'default'];
1796
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1797
-        $this->_redirect_after_action($success, '', '', $route, true);
1798
-    }
1799
-
1800
-
1801
-    /**
1802
-     * incoming reg status change from reg details page.
1803
-     *
1804
-     * @return void
1805
-     * @throws EE_Error
1806
-     * @throws EntityNotFoundException
1807
-     * @throws InvalidArgumentException
1808
-     * @throws InvalidDataTypeException
1809
-     * @throws InvalidInterfaceException
1810
-     * @throws ReflectionException
1811
-     * @throws RuntimeException
1812
-     * @throws DomainException
1813
-     */
1814
-    protected function _change_reg_status()
1815
-    {
1816
-        $this->request->setRequestParam('return', 'view_registration');
1817
-        // set notify based on whether the send notifications toggle is set or not
1818
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1819
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1820
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1821
-        switch ($reg_status) {
1822
-            case EEM_Registration::status_id_approved:
1823
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1824
-                $this->approve_registration($notify);
1825
-                break;
1826
-            case EEM_Registration::status_id_pending_payment:
1827
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1828
-                $this->pending_registration($notify);
1829
-                break;
1830
-            case EEM_Registration::status_id_not_approved:
1831
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1832
-                $this->not_approve_registration($notify);
1833
-                break;
1834
-            case EEM_Registration::status_id_declined:
1835
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1836
-                $this->decline_registration($notify);
1837
-                break;
1838
-            case EEM_Registration::status_id_cancelled:
1839
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1840
-                $this->cancel_registration($notify);
1841
-                break;
1842
-            case EEM_Registration::status_id_wait_list:
1843
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1844
-                $this->wait_list_registration($notify);
1845
-                break;
1846
-            case EEM_Registration::status_id_incomplete:
1847
-            default:
1848
-                $this->request->unSetRequestParam('return');
1849
-                $this->_reg_status_change_return('');
1850
-                break;
1851
-        }
1852
-    }
1853
-
1854
-
1855
-    /**
1856
-     * Callback for bulk action routes.
1857
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1858
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1859
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1860
-     * when an action is happening on just a single registration).
1861
-     *
1862
-     * @param      $action
1863
-     * @param bool $notify
1864
-     */
1865
-    protected function bulk_action_on_registrations($action, $notify = false)
1866
-    {
1867
-        do_action(
1868
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1869
-            $this,
1870
-            $action,
1871
-            $notify
1872
-        );
1873
-        $method = $action . '_registration';
1874
-        if (method_exists($this, $method)) {
1875
-            $this->$method($notify);
1876
-        }
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * approve_registration
1882
-     *
1883
-     * @param bool $notify whether or not to notify the registrant about their approval.
1884
-     * @return void
1885
-     * @throws EE_Error
1886
-     * @throws EntityNotFoundException
1887
-     * @throws InvalidArgumentException
1888
-     * @throws InvalidDataTypeException
1889
-     * @throws InvalidInterfaceException
1890
-     * @throws ReflectionException
1891
-     * @throws RuntimeException
1892
-     * @throws DomainException
1893
-     */
1894
-    protected function approve_registration($notify = false)
1895
-    {
1896
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     * decline_registration
1902
-     *
1903
-     * @param bool $notify whether or not to notify the registrant about their status change.
1904
-     * @return void
1905
-     * @throws EE_Error
1906
-     * @throws EntityNotFoundException
1907
-     * @throws InvalidArgumentException
1908
-     * @throws InvalidDataTypeException
1909
-     * @throws InvalidInterfaceException
1910
-     * @throws ReflectionException
1911
-     * @throws RuntimeException
1912
-     * @throws DomainException
1913
-     */
1914
-    protected function decline_registration($notify = false)
1915
-    {
1916
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     * cancel_registration
1922
-     *
1923
-     * @param bool $notify whether or not to notify the registrant about their status change.
1924
-     * @return void
1925
-     * @throws EE_Error
1926
-     * @throws EntityNotFoundException
1927
-     * @throws InvalidArgumentException
1928
-     * @throws InvalidDataTypeException
1929
-     * @throws InvalidInterfaceException
1930
-     * @throws ReflectionException
1931
-     * @throws RuntimeException
1932
-     * @throws DomainException
1933
-     */
1934
-    protected function cancel_registration($notify = false)
1935
-    {
1936
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1937
-    }
1938
-
1939
-
1940
-    /**
1941
-     * not_approve_registration
1942
-     *
1943
-     * @param bool $notify whether or not to notify the registrant about their status change.
1944
-     * @return void
1945
-     * @throws EE_Error
1946
-     * @throws EntityNotFoundException
1947
-     * @throws InvalidArgumentException
1948
-     * @throws InvalidDataTypeException
1949
-     * @throws InvalidInterfaceException
1950
-     * @throws ReflectionException
1951
-     * @throws RuntimeException
1952
-     * @throws DomainException
1953
-     */
1954
-    protected function not_approve_registration($notify = false)
1955
-    {
1956
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1957
-    }
1958
-
1959
-
1960
-    /**
1961
-     * decline_registration
1962
-     *
1963
-     * @param bool $notify whether or not to notify the registrant about their status change.
1964
-     * @return void
1965
-     * @throws EE_Error
1966
-     * @throws EntityNotFoundException
1967
-     * @throws InvalidArgumentException
1968
-     * @throws InvalidDataTypeException
1969
-     * @throws InvalidInterfaceException
1970
-     * @throws ReflectionException
1971
-     * @throws RuntimeException
1972
-     * @throws DomainException
1973
-     */
1974
-    protected function pending_registration($notify = false)
1975
-    {
1976
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1977
-    }
1978
-
1979
-
1980
-    /**
1981
-     * waitlist_registration
1982
-     *
1983
-     * @param bool $notify whether or not to notify the registrant about their status change.
1984
-     * @return void
1985
-     * @throws EE_Error
1986
-     * @throws EntityNotFoundException
1987
-     * @throws InvalidArgumentException
1988
-     * @throws InvalidDataTypeException
1989
-     * @throws InvalidInterfaceException
1990
-     * @throws ReflectionException
1991
-     * @throws RuntimeException
1992
-     * @throws DomainException
1993
-     */
1994
-    protected function wait_list_registration($notify = false)
1995
-    {
1996
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
-    }
1998
-
1999
-
2000
-    /**
2001
-     * generates HTML for the Registration main meta box
2002
-     *
2003
-     * @return void
2004
-     * @throws DomainException
2005
-     * @throws EE_Error
2006
-     * @throws InvalidArgumentException
2007
-     * @throws InvalidDataTypeException
2008
-     * @throws InvalidInterfaceException
2009
-     * @throws ReflectionException
2010
-     * @throws EntityNotFoundException
2011
-     */
2012
-    public function _reg_details_meta_box()
2013
-    {
2014
-        EEH_Autoloader::register_line_item_display_autoloaders();
2015
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2016
-        EE_Registry::instance()->load_helper('Line_Item');
2017
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2018
-            : EE_Transaction::new_instance();
2019
-        $this->_session = $transaction->session_data();
2020
-        $filters        = new EE_Line_Item_Filter_Collection();
2021
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2022
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2023
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2024
-            $filters,
2025
-            $transaction->total_line_item()
2026
-        );
2027
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2028
-        $line_item_display                       = new EE_Line_Item_Display(
2029
-            'reg_admin_table',
2030
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2031
-        );
2032
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2033
-            $filtered_line_item_tree,
2034
-            ['EE_Registration' => $this->_registration]
2035
-        );
2036
-        $attendee                                = $this->_registration->attendee();
2037
-        if (
2038
-            EE_Registry::instance()->CAP->current_user_can(
2039
-                'ee_read_transaction',
2040
-                'espresso_transactions_view_transaction'
2041
-            )
2042
-        ) {
2043
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2044
-                EE_Admin_Page::add_query_args_and_nonce(
2045
-                    [
2046
-                        'action' => 'view_transaction',
2047
-                        'TXN_ID' => $transaction->ID(),
2048
-                    ],
2049
-                    TXN_ADMIN_URL
2050
-                ),
2051
-                esc_html__(' View Transaction', 'event_espresso'),
2052
-                'button secondary-button right',
2053
-                'dashicons dashicons-cart'
2054
-            );
2055
-        } else {
2056
-            $this->_template_args['view_transaction_button'] = '';
2057
-        }
2058
-        if (
2059
-            $attendee instanceof EE_Attendee
2060
-            && EE_Registry::instance()->CAP->current_user_can(
2061
-                'ee_send_message',
2062
-                'espresso_registrations_resend_registration'
2063
-            )
2064
-        ) {
2065
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2066
-                EE_Admin_Page::add_query_args_and_nonce(
2067
-                    [
2068
-                        'action'      => 'resend_registration',
2069
-                        '_REG_ID'     => $this->_registration->ID(),
2070
-                        'redirect_to' => 'view_registration',
2071
-                    ],
2072
-                    REG_ADMIN_URL
2073
-                ),
2074
-                esc_html__(' Resend Registration', 'event_espresso'),
2075
-                'button secondary-button right',
2076
-                'dashicons dashicons-email-alt'
2077
-            );
2078
-        } else {
2079
-            $this->_template_args['resend_registration_button'] = '';
2080
-        }
2081
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2082
-        $payment                               = $transaction->get_first_related('Payment');
2083
-        $payment                               = ! $payment instanceof EE_Payment
2084
-            ? EE_Payment::new_instance()
2085
-            : $payment;
2086
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2087
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2088
-            ? EE_Payment_Method::new_instance()
2089
-            : $payment_method;
2090
-        $reg_details                           = [
2091
-            'payment_method'       => $payment_method->name(),
2092
-            'response_msg'         => $payment->gateway_response(),
2093
-            'registration_id'      => $this->_registration->get('REG_code'),
2094
-            'registration_session' => $this->_registration->session_ID(),
2095
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2096
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2097
-        ];
2098
-        if (isset($reg_details['registration_id'])) {
2099
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2100
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2101
-                'Registration ID',
2102
-                'event_espresso'
2103
-            );
2104
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2105
-        }
2106
-        if (isset($reg_details['payment_method'])) {
2107
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2108
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2109
-                'Most Recent Payment Method',
2110
-                'event_espresso'
2111
-            );
2112
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2113
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2114
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2115
-                'Payment method response',
2116
-                'event_espresso'
2117
-            );
2118
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2119
-        }
2120
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2121
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2122
-            'Registration Session',
2123
-            'event_espresso'
2124
-        );
2125
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2126
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2127
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2128
-            'Registration placed from IP',
2129
-            'event_espresso'
2130
-        );
2131
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2132
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2133
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2134
-            'Registrant User Agent',
2135
-            'event_espresso'
2136
-        );
2137
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2138
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2139
-            [
2140
-                'action'   => 'default',
2141
-                'event_id' => $this->_registration->event_ID(),
2142
-            ],
2143
-            REG_ADMIN_URL
2144
-        );
2145
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2146
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2147
-        $template_path                                                        =
2148
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2149
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2150
-    }
2151
-
2152
-
2153
-    /**
2154
-     * generates HTML for the Registration Questions meta box.
2155
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2156
-     * otherwise uses new forms system
2157
-     *
2158
-     * @return void
2159
-     * @throws DomainException
2160
-     * @throws EE_Error
2161
-     * @throws InvalidArgumentException
2162
-     * @throws InvalidDataTypeException
2163
-     * @throws InvalidInterfaceException
2164
-     * @throws ReflectionException
2165
-     */
2166
-    public function _reg_questions_meta_box()
2167
-    {
2168
-        // allow someone to override this method entirely
2169
-        if (
2170
-            apply_filters(
2171
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2172
-                true,
2173
-                $this,
2174
-                $this->_registration
2175
-            )
2176
-        ) {
2177
-            $form                                              = $this->_get_reg_custom_questions_form(
2178
-                $this->_registration->ID()
2179
-            );
2180
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2181
-                ? $form->get_html_and_js()
2182
-                : '';
2183
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2184
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2185
-            $template_path                                     =
2186
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2187
-            EEH_Template::display_template($template_path, $this->_template_args);
2188
-        }
2189
-    }
2190
-
2191
-
2192
-    /**
2193
-     * form_before_question_group
2194
-     *
2195
-     * @param string $output
2196
-     * @return        string
2197
-     * @deprecated    as of 4.8.32.rc.000
2198
-     */
2199
-    public function form_before_question_group($output)
2200
-    {
2201
-        EE_Error::doing_it_wrong(
2202
-            __CLASS__ . '::' . __FUNCTION__,
2203
-            esc_html__(
2204
-                '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.',
2205
-                'event_espresso'
2206
-            ),
2207
-            '4.8.32.rc.000'
2208
-        );
2209
-        return '
24
+	/**
25
+	 * @var EE_Registration
26
+	 */
27
+	private $_registration;
28
+
29
+	/**
30
+	 * @var EE_Event
31
+	 */
32
+	private $_reg_event;
33
+
34
+	/**
35
+	 * @var EE_Session
36
+	 */
37
+	private $_session;
38
+
39
+	/**
40
+	 * @var array
41
+	 */
42
+	private static $_reg_status;
43
+
44
+	/**
45
+	 * Form for displaying the custom questions for this registration.
46
+	 * This gets used a few times throughout the request so its best to cache it
47
+	 *
48
+	 * @var EE_Registration_Custom_Questions_Form
49
+	 */
50
+	protected $_reg_custom_questions_form = null;
51
+
52
+	/**
53
+	 * @var EEM_Registration $registration_model
54
+	 */
55
+	private $registration_model;
56
+
57
+	/**
58
+	 * @var EEM_Attendee $attendee_model
59
+	 */
60
+	private $attendee_model;
61
+
62
+	/**
63
+	 * @var EEM_Event $event_model
64
+	 */
65
+	private $event_model;
66
+
67
+	/**
68
+	 * @var EEM_Status $status_model
69
+	 */
70
+	private $status_model;
71
+
72
+
73
+	/**
74
+	 * @param bool $routing
75
+	 * @throws EE_Error
76
+	 * @throws InvalidArgumentException
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidInterfaceException
79
+	 * @throws ReflectionException
80
+	 */
81
+	public function __construct($routing = true)
82
+	{
83
+		parent::__construct($routing);
84
+		add_action('wp_loaded', [$this, 'wp_loaded']);
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return EEM_Registration
90
+	 * @throws InvalidArgumentException
91
+	 * @throws InvalidDataTypeException
92
+	 * @throws InvalidInterfaceException
93
+	 * @since 4.10.2.p
94
+	 */
95
+	protected function getRegistrationModel()
96
+	{
97
+		if (! $this->registration_model instanceof EEM_Registration) {
98
+			$this->registration_model = $this->getLoader()->getShared('EEM_Registration');
99
+		}
100
+		return $this->registration_model;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return EEM_Attendee
106
+	 * @throws InvalidArgumentException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 * @since 4.10.2.p
110
+	 */
111
+	protected function getAttendeeModel()
112
+	{
113
+		if (! $this->attendee_model instanceof EEM_Attendee) {
114
+			$this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
115
+		}
116
+		return $this->attendee_model;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return EEM_Event
122
+	 * @throws InvalidArgumentException
123
+	 * @throws InvalidDataTypeException
124
+	 * @throws InvalidInterfaceException
125
+	 * @since 4.10.2.p
126
+	 */
127
+	protected function getEventModel()
128
+	{
129
+		if (! $this->event_model instanceof EEM_Event) {
130
+			$this->event_model = $this->getLoader()->getShared('EEM_Event');
131
+		}
132
+		return $this->event_model;
133
+	}
134
+
135
+
136
+	/**
137
+	 * @return EEM_Status
138
+	 * @throws InvalidArgumentException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidInterfaceException
141
+	 * @since 4.10.2.p
142
+	 */
143
+	protected function getStatusModel()
144
+	{
145
+		if (! $this->status_model instanceof EEM_Status) {
146
+			$this->status_model = $this->getLoader()->getShared('EEM_Status');
147
+		}
148
+		return $this->status_model;
149
+	}
150
+
151
+
152
+	public function wp_loaded()
153
+	{
154
+		// when adding a new registration...
155
+		$action = $this->request->getRequestParam('action');
156
+		if ($action === 'new_registration') {
157
+			EE_System::do_not_cache();
158
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
159
+				// and it's NOT the attendee information reg step
160
+				// force cookie expiration by setting time to last week
161
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
162
+				// and update the global
163
+				$_COOKIE['ee_registration_added'] = 0;
164
+			}
165
+		}
166
+	}
167
+
168
+
169
+	protected function _init_page_props()
170
+	{
171
+		$this->page_slug        = REG_PG_SLUG;
172
+		$this->_admin_base_url  = REG_ADMIN_URL;
173
+		$this->_admin_base_path = REG_ADMIN;
174
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
175
+		$this->_cpt_routes      = [
176
+			'add_new_attendee' => 'espresso_attendees',
177
+			'edit_attendee'    => 'espresso_attendees',
178
+			'insert_attendee'  => 'espresso_attendees',
179
+			'update_attendee'  => 'espresso_attendees',
180
+		];
181
+		$this->_cpt_model_names = [
182
+			'add_new_attendee' => 'EEM_Attendee',
183
+			'edit_attendee'    => 'EEM_Attendee',
184
+		];
185
+		$this->_cpt_edit_routes = [
186
+			'espresso_attendees' => 'edit_attendee',
187
+		];
188
+		$this->_pagenow_map     = [
189
+			'add_new_attendee' => 'post-new.php',
190
+			'edit_attendee'    => 'post.php',
191
+			'trash'            => 'post.php',
192
+		];
193
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
194
+		// add filters so that the comment urls don't take users to a confusing 404 page
195
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
196
+	}
197
+
198
+
199
+	/**
200
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
201
+	 * @param WP_Comment $comment The current comment object.
202
+	 * @return string
203
+	 */
204
+	public function clear_comment_link($link, WP_Comment $comment)
205
+	{
206
+		// gotta make sure this only happens on this route
207
+		$post_type = get_post_type($comment->comment_post_ID);
208
+		if ($post_type === 'espresso_attendees') {
209
+			return '#commentsdiv';
210
+		}
211
+		return $link;
212
+	}
213
+
214
+
215
+	protected function _ajax_hooks()
216
+	{
217
+		// todo: all hooks for registrations ajax goes in here
218
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
219
+	}
220
+
221
+
222
+	protected function _define_page_props()
223
+	{
224
+		$this->_admin_page_title = $this->page_label;
225
+		$this->_labels           = [
226
+			'buttons'                      => [
227
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
228
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
229
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
230
+				'csv_reg_report'      => esc_html__('Registrations CSV Report', 'event_espresso'),
231
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
+			],
234
+			'publishbox'                   => [
235
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
+			],
238
+			'hide_add_button_on_cpt_route' => [
239
+				'edit_attendee' => true,
240
+			],
241
+		];
242
+	}
243
+
244
+
245
+	/**
246
+	 * grab url requests and route them
247
+	 *
248
+	 * @return void
249
+	 * @throws EE_Error
250
+	 */
251
+	public function _set_page_routes()
252
+	{
253
+		$this->_get_registration_status_array();
254
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
+		$this->_page_routes = [
259
+			'default'                             => [
260
+				'func'       => [$this, '_registrations_overview_list_table'],
261
+				'capability' => 'ee_read_registrations',
262
+			],
263
+			'view_registration'                   => [
264
+				'func'       => '_registration_details',
265
+				'capability' => 'ee_read_registration',
266
+				'obj_id'     => $REG_ID,
267
+			],
268
+			'edit_registration'                   => [
269
+				'func'               => '_update_attendee_registration_form',
270
+				'noheader'           => true,
271
+				'headers_sent_route' => 'view_registration',
272
+				'capability'         => 'ee_edit_registration',
273
+				'obj_id'             => $REG_ID,
274
+				'_REG_ID'            => $REG_ID,
275
+			],
276
+			'trash_registrations'                 => [
277
+				'func'       => '_trash_or_restore_registrations',
278
+				'args'       => ['trash' => true],
279
+				'noheader'   => true,
280
+				'capability' => 'ee_delete_registrations',
281
+			],
282
+			'restore_registrations'               => [
283
+				'func'       => '_trash_or_restore_registrations',
284
+				'args'       => ['trash' => false],
285
+				'noheader'   => true,
286
+				'capability' => 'ee_delete_registrations',
287
+			],
288
+			'delete_registrations'                => [
289
+				'func'       => '_delete_registrations',
290
+				'noheader'   => true,
291
+				'capability' => 'ee_delete_registrations',
292
+			],
293
+			'new_registration'                    => [
294
+				'func'       => 'new_registration',
295
+				'capability' => 'ee_edit_registrations',
296
+			],
297
+			'process_reg_step'                    => [
298
+				'func'       => 'process_reg_step',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+			],
302
+			'redirect_to_txn'                     => [
303
+				'func'       => 'redirect_to_txn',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+			],
307
+			'change_reg_status'                   => [
308
+				'func'       => '_change_reg_status',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $REG_ID,
312
+			],
313
+			'approve_registration'                => [
314
+				'func'       => 'approve_registration',
315
+				'noheader'   => true,
316
+				'capability' => 'ee_edit_registration',
317
+				'obj_id'     => $REG_ID,
318
+			],
319
+			'approve_and_notify_registration'     => [
320
+				'func'       => 'approve_registration',
321
+				'noheader'   => true,
322
+				'args'       => [true],
323
+				'capability' => 'ee_edit_registration',
324
+				'obj_id'     => $REG_ID,
325
+			],
326
+			'approve_registrations'               => [
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args'       => ['approve'],
331
+			],
332
+			'approve_and_notify_registrations'    => [
333
+				'func'       => 'bulk_action_on_registrations',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registrations',
336
+				'args'       => ['approve', true],
337
+			],
338
+			'decline_registration'                => [
339
+				'func'       => 'decline_registration',
340
+				'noheader'   => true,
341
+				'capability' => 'ee_edit_registration',
342
+				'obj_id'     => $REG_ID,
343
+			],
344
+			'decline_and_notify_registration'     => [
345
+				'func'       => 'decline_registration',
346
+				'noheader'   => true,
347
+				'args'       => [true],
348
+				'capability' => 'ee_edit_registration',
349
+				'obj_id'     => $REG_ID,
350
+			],
351
+			'decline_registrations'               => [
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args'       => ['decline'],
356
+			],
357
+			'decline_and_notify_registrations'    => [
358
+				'func'       => 'bulk_action_on_registrations',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registrations',
361
+				'args'       => ['decline', true],
362
+			],
363
+			'pending_registration'                => [
364
+				'func'       => 'pending_registration',
365
+				'noheader'   => true,
366
+				'capability' => 'ee_edit_registration',
367
+				'obj_id'     => $REG_ID,
368
+			],
369
+			'pending_and_notify_registration'     => [
370
+				'func'       => 'pending_registration',
371
+				'noheader'   => true,
372
+				'args'       => [true],
373
+				'capability' => 'ee_edit_registration',
374
+				'obj_id'     => $REG_ID,
375
+			],
376
+			'pending_registrations'               => [
377
+				'func'       => 'bulk_action_on_registrations',
378
+				'noheader'   => true,
379
+				'capability' => 'ee_edit_registrations',
380
+				'args'       => ['pending'],
381
+			],
382
+			'pending_and_notify_registrations'    => [
383
+				'func'       => 'bulk_action_on_registrations',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_registrations',
386
+				'args'       => ['pending', true],
387
+			],
388
+			'no_approve_registration'             => [
389
+				'func'       => 'not_approve_registration',
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_registration',
392
+				'obj_id'     => $REG_ID,
393
+			],
394
+			'no_approve_and_notify_registration'  => [
395
+				'func'       => 'not_approve_registration',
396
+				'noheader'   => true,
397
+				'args'       => [true],
398
+				'capability' => 'ee_edit_registration',
399
+				'obj_id'     => $REG_ID,
400
+			],
401
+			'no_approve_registrations'            => [
402
+				'func'       => 'bulk_action_on_registrations',
403
+				'noheader'   => true,
404
+				'capability' => 'ee_edit_registrations',
405
+				'args'       => ['not_approve'],
406
+			],
407
+			'no_approve_and_notify_registrations' => [
408
+				'func'       => 'bulk_action_on_registrations',
409
+				'noheader'   => true,
410
+				'capability' => 'ee_edit_registrations',
411
+				'args'       => ['not_approve', true],
412
+			],
413
+			'cancel_registration'                 => [
414
+				'func'       => 'cancel_registration',
415
+				'noheader'   => true,
416
+				'capability' => 'ee_edit_registration',
417
+				'obj_id'     => $REG_ID,
418
+			],
419
+			'cancel_and_notify_registration'      => [
420
+				'func'       => 'cancel_registration',
421
+				'noheader'   => true,
422
+				'args'       => [true],
423
+				'capability' => 'ee_edit_registration',
424
+				'obj_id'     => $REG_ID,
425
+			],
426
+			'cancel_registrations'                => [
427
+				'func'       => 'bulk_action_on_registrations',
428
+				'noheader'   => true,
429
+				'capability' => 'ee_edit_registrations',
430
+				'args'       => ['cancel'],
431
+			],
432
+			'cancel_and_notify_registrations'     => [
433
+				'func'       => 'bulk_action_on_registrations',
434
+				'noheader'   => true,
435
+				'capability' => 'ee_edit_registrations',
436
+				'args'       => ['cancel', true],
437
+			],
438
+			'wait_list_registration'              => [
439
+				'func'       => 'wait_list_registration',
440
+				'noheader'   => true,
441
+				'capability' => 'ee_edit_registration',
442
+				'obj_id'     => $REG_ID,
443
+			],
444
+			'wait_list_and_notify_registration'   => [
445
+				'func'       => 'wait_list_registration',
446
+				'noheader'   => true,
447
+				'args'       => [true],
448
+				'capability' => 'ee_edit_registration',
449
+				'obj_id'     => $REG_ID,
450
+			],
451
+			'contact_list'                        => [
452
+				'func'       => '_attendee_contact_list_table',
453
+				'capability' => 'ee_read_contacts',
454
+			],
455
+			'add_new_attendee'                    => [
456
+				'func' => '_create_new_cpt_item',
457
+				'args' => [
458
+					'new_attendee' => true,
459
+					'capability'   => 'ee_edit_contacts',
460
+				],
461
+			],
462
+			'edit_attendee'                       => [
463
+				'func'       => '_edit_cpt_item',
464
+				'capability' => 'ee_edit_contacts',
465
+				'obj_id'     => $ATT_ID,
466
+			],
467
+			'duplicate_attendee'                  => [
468
+				'func'       => '_duplicate_attendee',
469
+				'noheader'   => true,
470
+				'capability' => 'ee_edit_contacts',
471
+				'obj_id'     => $ATT_ID,
472
+			],
473
+			'insert_attendee'                     => [
474
+				'func'       => '_insert_or_update_attendee',
475
+				'args'       => [
476
+					'new_attendee' => true,
477
+				],
478
+				'noheader'   => true,
479
+				'capability' => 'ee_edit_contacts',
480
+			],
481
+			'update_attendee'                     => [
482
+				'func'       => '_insert_or_update_attendee',
483
+				'args'       => [
484
+					'new_attendee' => false,
485
+				],
486
+				'noheader'   => true,
487
+				'capability' => 'ee_edit_contacts',
488
+				'obj_id'     => $ATT_ID,
489
+			],
490
+			'trash_attendees'                     => [
491
+				'func'       => '_trash_or_restore_attendees',
492
+				'args'       => [
493
+					'trash' => 'true',
494
+				],
495
+				'noheader'   => true,
496
+				'capability' => 'ee_delete_contacts',
497
+			],
498
+			'trash_attendee'                      => [
499
+				'func'       => '_trash_or_restore_attendees',
500
+				'args'       => [
501
+					'trash' => true,
502
+				],
503
+				'noheader'   => true,
504
+				'capability' => 'ee_delete_contacts',
505
+				'obj_id'     => $ATT_ID,
506
+			],
507
+			'restore_attendees'                   => [
508
+				'func'       => '_trash_or_restore_attendees',
509
+				'args'       => [
510
+					'trash' => false,
511
+				],
512
+				'noheader'   => true,
513
+				'capability' => 'ee_delete_contacts',
514
+				'obj_id'     => $ATT_ID,
515
+			],
516
+			'resend_registration'                 => [
517
+				'func'       => '_resend_registration',
518
+				'noheader'   => true,
519
+				'capability' => 'ee_send_message',
520
+			],
521
+			'registrations_report'                => [
522
+				'func'       => [$this, '_registrations_report'],
523
+				'noheader'   => true,
524
+				'capability' => 'ee_read_registrations',
525
+			],
526
+			'contact_list_export'                 => [
527
+				'func'       => '_contact_list_export',
528
+				'noheader'   => true,
529
+				'capability' => 'export',
530
+			],
531
+			'contact_list_report'                 => [
532
+				'func'       => '_contact_list_report',
533
+				'noheader'   => true,
534
+				'capability' => 'ee_read_contacts',
535
+			],
536
+		];
537
+	}
538
+
539
+
540
+	protected function _set_page_config()
541
+	{
542
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
+		$this->_page_config = [
545
+			'default'           => [
546
+				'nav'           => [
547
+					'label' => esc_html__('Overview', 'event_espresso'),
548
+					'order' => 5,
549
+				],
550
+				'help_tabs'     => [
551
+					'registrations_overview_help_tab'                       => [
552
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
+						'filename' => 'registrations_overview',
554
+					],
555
+					'registrations_overview_table_column_headings_help_tab' => [
556
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
+						'filename' => 'registrations_overview_table_column_headings',
558
+					],
559
+					'registrations_overview_filters_help_tab'               => [
560
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
+						'filename' => 'registrations_overview_filters',
562
+					],
563
+					'registrations_overview_views_help_tab'                 => [
564
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
565
+						'filename' => 'registrations_overview_views',
566
+					],
567
+					'registrations_regoverview_other_help_tab'              => [
568
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
+						'filename' => 'registrations_overview_other',
570
+					],
571
+				],
572
+				'qtips'         => ['Registration_List_Table_Tips'],
573
+				'list_table'    => 'EE_Registrations_List_Table',
574
+				'require_nonce' => false,
575
+			],
576
+			'view_registration' => [
577
+				'nav'           => [
578
+					'label'      => esc_html__('REG Details', 'event_espresso'),
579
+					'order'      => 15,
580
+					'url'        => $REG_ID
581
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
+						: $this->_admin_base_url,
583
+					'persistent' => false,
584
+				],
585
+				'help_tabs'     => [
586
+					'registrations_details_help_tab'                    => [
587
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
588
+						'filename' => 'registrations_details',
589
+					],
590
+					'registrations_details_table_help_tab'              => [
591
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
+						'filename' => 'registrations_details_table',
593
+					],
594
+					'registrations_details_form_answers_help_tab'       => [
595
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
+						'filename' => 'registrations_details_form_answers',
597
+					],
598
+					'registrations_details_registrant_details_help_tab' => [
599
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
600
+						'filename' => 'registrations_details_registrant_details',
601
+					],
602
+				],
603
+				'metaboxes'     => array_merge(
604
+					$this->_default_espresso_metaboxes,
605
+					['_registration_details_metaboxes']
606
+				),
607
+				'require_nonce' => false,
608
+			],
609
+			'new_registration'  => [
610
+				'nav'           => [
611
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
+					'url'        => '#',
613
+					'order'      => 15,
614
+					'persistent' => false,
615
+				],
616
+				'metaboxes'     => $this->_default_espresso_metaboxes,
617
+				'labels'        => [
618
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
+				],
620
+				'require_nonce' => false,
621
+			],
622
+			'add_new_attendee'  => [
623
+				'nav'           => [
624
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
625
+					'order'      => 15,
626
+					'persistent' => false,
627
+				],
628
+				'metaboxes'     => array_merge(
629
+					$this->_default_espresso_metaboxes,
630
+					['_publish_post_box', 'attendee_editor_metaboxes']
631
+				),
632
+				'require_nonce' => false,
633
+			],
634
+			'edit_attendee'     => [
635
+				'nav'           => [
636
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
+					'order'      => 15,
638
+					'persistent' => false,
639
+					'url'        => $ATT_ID
640
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
+						: $this->_admin_base_url,
642
+				],
643
+				'metaboxes'     => ['attendee_editor_metaboxes'],
644
+				'require_nonce' => false,
645
+			],
646
+			'contact_list'      => [
647
+				'nav'           => [
648
+					'label' => esc_html__('Contact List', 'event_espresso'),
649
+					'order' => 20,
650
+				],
651
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
652
+				'help_tabs'     => [
653
+					'registrations_contact_list_help_tab'                       => [
654
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
655
+						'filename' => 'registrations_contact_list',
656
+					],
657
+					'registrations_contact-list_table_column_headings_help_tab' => [
658
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
659
+						'filename' => 'registrations_contact_list_table_column_headings',
660
+					],
661
+					'registrations_contact_list_views_help_tab'                 => [
662
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
663
+						'filename' => 'registrations_contact_list_views',
664
+					],
665
+					'registrations_contact_list_other_help_tab'                 => [
666
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
667
+						'filename' => 'registrations_contact_list_other',
668
+					],
669
+				],
670
+				'metaboxes'     => [],
671
+				'require_nonce' => false,
672
+			],
673
+			// override default cpt routes
674
+			'create_new'        => '',
675
+			'edit'              => '',
676
+		];
677
+	}
678
+
679
+
680
+	/**
681
+	 * The below methods aren't used by this class currently
682
+	 */
683
+	protected function _add_screen_options()
684
+	{
685
+	}
686
+
687
+
688
+	protected function _add_feature_pointers()
689
+	{
690
+	}
691
+
692
+
693
+	public function admin_init()
694
+	{
695
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
696
+			'click "Update Registration Questions" to save your changes',
697
+			'event_espresso'
698
+		);
699
+	}
700
+
701
+
702
+	public function admin_notices()
703
+	{
704
+	}
705
+
706
+
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710
+
711
+
712
+	/**
713
+	 * get list of registration statuses
714
+	 *
715
+	 * @return void
716
+	 * @throws EE_Error
717
+	 */
718
+	private function _get_registration_status_array()
719
+	{
720
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
721
+	}
722
+
723
+
724
+	/**
725
+	 * @throws InvalidArgumentException
726
+	 * @throws InvalidDataTypeException
727
+	 * @throws InvalidInterfaceException
728
+	 * @since 4.10.2.p
729
+	 */
730
+	protected function _add_screen_options_default()
731
+	{
732
+		$this->_per_page_screen_option();
733
+	}
734
+
735
+
736
+	/**
737
+	 * @throws InvalidArgumentException
738
+	 * @throws InvalidDataTypeException
739
+	 * @throws InvalidInterfaceException
740
+	 * @since 4.10.2.p
741
+	 */
742
+	protected function _add_screen_options_contact_list()
743
+	{
744
+		$page_title              = $this->_admin_page_title;
745
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
746
+		$this->_per_page_screen_option();
747
+		$this->_admin_page_title = $page_title;
748
+	}
749
+
750
+
751
+	public function load_scripts_styles()
752
+	{
753
+		// style
754
+		wp_register_style(
755
+			'espresso_reg',
756
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
757
+			['ee-admin-css'],
758
+			EVENT_ESPRESSO_VERSION
759
+		);
760
+		wp_enqueue_style('espresso_reg');
761
+		// script
762
+		wp_register_script(
763
+			'espresso_reg',
764
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
765
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
766
+			EVENT_ESPRESSO_VERSION,
767
+			true
768
+		);
769
+		wp_enqueue_script('espresso_reg');
770
+	}
771
+
772
+
773
+	/**
774
+	 * @throws EE_Error
775
+	 * @throws InvalidArgumentException
776
+	 * @throws InvalidDataTypeException
777
+	 * @throws InvalidInterfaceException
778
+	 * @throws ReflectionException
779
+	 * @since 4.10.2.p
780
+	 */
781
+	public function load_scripts_styles_edit_attendee()
782
+	{
783
+		// stuff to only show up on our attendee edit details page.
784
+		$attendee_details_translations = [
785
+			'att_publish_text' => sprintf(
786
+			/* translators: The date and time */
787
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
788
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
789
+			),
790
+		];
791
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
792
+		wp_enqueue_script('jquery-validate');
793
+	}
794
+
795
+
796
+	/**
797
+	 * @throws EE_Error
798
+	 * @throws InvalidArgumentException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws InvalidInterfaceException
801
+	 * @throws ReflectionException
802
+	 * @since 4.10.2.p
803
+	 */
804
+	public function load_scripts_styles_view_registration()
805
+	{
806
+		// styles
807
+		wp_enqueue_style('espresso-ui-theme');
808
+		// scripts
809
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
810
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
811
+	}
812
+
813
+
814
+	public function load_scripts_styles_contact_list()
815
+	{
816
+		wp_dequeue_style('espresso_reg');
817
+		wp_register_style(
818
+			'espresso_att',
819
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
820
+			['ee-admin-css'],
821
+			EVENT_ESPRESSO_VERSION
822
+		);
823
+		wp_enqueue_style('espresso_att');
824
+	}
825
+
826
+
827
+	public function load_scripts_styles_new_registration()
828
+	{
829
+		wp_register_script(
830
+			'ee-spco-for-admin',
831
+			REG_ASSETS_URL . 'spco_for_admin.js',
832
+			['underscore', 'jquery'],
833
+			EVENT_ESPRESSO_VERSION,
834
+			true
835
+		);
836
+		wp_enqueue_script('ee-spco-for-admin');
837
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
838
+		EE_Form_Section_Proper::wp_enqueue_scripts();
839
+		EED_Ticket_Selector::load_tckt_slctr_assets();
840
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
841
+	}
842
+
843
+
844
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
845
+	{
846
+		add_filter('FHEE_load_EE_messages', '__return_true');
847
+	}
848
+
849
+
850
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
851
+	{
852
+		add_filter('FHEE_load_EE_messages', '__return_true');
853
+	}
854
+
855
+
856
+	/**
857
+	 * @throws EE_Error
858
+	 * @throws InvalidArgumentException
859
+	 * @throws InvalidDataTypeException
860
+	 * @throws InvalidInterfaceException
861
+	 * @throws ReflectionException
862
+	 * @since 4.10.2.p
863
+	 */
864
+	protected function _set_list_table_views_default()
865
+	{
866
+		// for notification related bulk actions we need to make sure only active messengers have an option.
867
+		EED_Messages::set_autoloaders();
868
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
869
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
870
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
871
+		// key= bulk_action_slug, value= message type.
872
+		$match_array = [
873
+			'approve_registrations'    => 'registration',
874
+			'decline_registrations'    => 'declined_registration',
875
+			'pending_registrations'    => 'pending_approval',
876
+			'no_approve_registrations' => 'not_approved_registration',
877
+			'cancel_registrations'     => 'cancelled_registration',
878
+		];
879
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
880
+			'ee_send_message',
881
+			'batch_send_messages'
882
+		);
883
+		/** setup reg status bulk actions **/
884
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
885
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
886
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
887
+				'Approve and Notify Registrations',
888
+				'event_espresso'
889
+			);
890
+		}
891
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
892
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
893
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
894
+				'Decline and Notify Registrations',
895
+				'event_espresso'
896
+			);
897
+		}
898
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
899
+			'Set Registrations to Pending Payment',
900
+			'event_espresso'
901
+		);
902
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
903
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
904
+				'Set Registrations to Pending Payment and Notify',
905
+				'event_espresso'
906
+			);
907
+		}
908
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
909
+			'Set Registrations to Not Approved',
910
+			'event_espresso'
911
+		);
912
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
913
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
914
+				'Set Registrations to Not Approved and Notify',
915
+				'event_espresso'
916
+			);
917
+		}
918
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
919
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
920
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
921
+				'Cancel Registrations and Notify',
922
+				'event_espresso'
923
+			);
924
+		}
925
+		$def_reg_status_actions = apply_filters(
926
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
927
+			$def_reg_status_actions,
928
+			$active_mts,
929
+			$can_send
930
+		);
931
+
932
+		$this->_views = [
933
+			'all'   => [
934
+				'slug'        => 'all',
935
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
936
+				'count'       => 0,
937
+				'bulk_action' => array_merge(
938
+					$def_reg_status_actions,
939
+					[
940
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
941
+					]
942
+				),
943
+			],
944
+			'month' => [
945
+				'slug'        => 'month',
946
+				'label'       => esc_html__('This Month', 'event_espresso'),
947
+				'count'       => 0,
948
+				'bulk_action' => array_merge(
949
+					$def_reg_status_actions,
950
+					[
951
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
952
+					]
953
+				),
954
+			],
955
+			'today' => [
956
+				'slug'        => 'today',
957
+				'label'       => sprintf(
958
+					esc_html__('Today - %s', 'event_espresso'),
959
+					date('M d, Y', current_time('timestamp'))
960
+				),
961
+				'count'       => 0,
962
+				'bulk_action' => array_merge(
963
+					$def_reg_status_actions,
964
+					[
965
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
966
+					]
967
+				),
968
+			],
969
+		];
970
+		if (
971
+			EE_Registry::instance()->CAP->current_user_can(
972
+				'ee_delete_registrations',
973
+				'espresso_registrations_delete_registration'
974
+			)
975
+		) {
976
+			$this->_views['incomplete'] = [
977
+				'slug'        => 'incomplete',
978
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
979
+				'count'       => 0,
980
+				'bulk_action' => [
981
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
+				],
983
+			];
984
+			$this->_views['trash']      = [
985
+				'slug'        => 'trash',
986
+				'label'       => esc_html__('Trash', 'event_espresso'),
987
+				'count'       => 0,
988
+				'bulk_action' => [
989
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
+				],
992
+			];
993
+		}
994
+	}
995
+
996
+
997
+	protected function _set_list_table_views_contact_list()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'        => 'in_use',
1002
+				'label'       => esc_html__('In Use', 'event_espresso'),
1003
+				'count'       => 0,
1004
+				'bulk_action' => [
1005
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
+				],
1007
+			],
1008
+		];
1009
+		if (
1010
+			EE_Registry::instance()->CAP->current_user_can(
1011
+				'ee_delete_contacts',
1012
+				'espresso_registrations_trash_attendees'
1013
+			)
1014
+		) {
1015
+			$this->_views['trash'] = [
1016
+				'slug'        => 'trash',
1017
+				'label'       => esc_html__('Trash', 'event_espresso'),
1018
+				'count'       => 0,
1019
+				'bulk_action' => [
1020
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1021
+				],
1022
+			];
1023
+		}
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * @return array
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	protected function _registration_legend_items()
1032
+	{
1033
+		$fc_items = [
1034
+			'star-icon'        => [
1035
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1037
+			],
1038
+			'view_details'     => [
1039
+				'class' => 'dashicons dashicons-clipboard',
1040
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1041
+			],
1042
+			'edit_attendee'    => [
1043
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1044
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1045
+			],
1046
+			'view_transaction' => [
1047
+				'class' => 'dashicons dashicons-cart',
1048
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1049
+			],
1050
+			'view_invoice'     => [
1051
+				'class' => 'dashicons dashicons-media-spreadsheet',
1052
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1053
+			],
1054
+		];
1055
+		if (
1056
+			EE_Registry::instance()->CAP->current_user_can(
1057
+				'ee_send_message',
1058
+				'espresso_registrations_resend_registration'
1059
+			)
1060
+		) {
1061
+			$fc_items['resend_registration'] = [
1062
+				'class' => 'dashicons dashicons-email-alt',
1063
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1064
+			];
1065
+		} else {
1066
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1067
+		}
1068
+		if (
1069
+			EE_Registry::instance()->CAP->current_user_can(
1070
+				'ee_read_global_messages',
1071
+				'view_filtered_messages'
1072
+			)
1073
+		) {
1074
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1075
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1076
+				$fc_items['view_related_messages'] = [
1077
+					'class' => $related_for_icon['css_class'],
1078
+					'desc'  => $related_for_icon['label'],
1079
+				];
1080
+			}
1081
+		}
1082
+		$sc_items = [
1083
+			'approved_status'   => [
1084
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1085
+				'desc'  => EEH_Template::pretty_status(
1086
+					EEM_Registration::status_id_approved,
1087
+					false,
1088
+					'sentence'
1089
+				),
1090
+			],
1091
+			'pending_status'    => [
1092
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1093
+				'desc'  => EEH_Template::pretty_status(
1094
+					EEM_Registration::status_id_pending_payment,
1095
+					false,
1096
+					'sentence'
1097
+				),
1098
+			],
1099
+			'wait_list'         => [
1100
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1101
+				'desc'  => EEH_Template::pretty_status(
1102
+					EEM_Registration::status_id_wait_list,
1103
+					false,
1104
+					'sentence'
1105
+				),
1106
+			],
1107
+			'incomplete_status' => [
1108
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1109
+				'desc'  => EEH_Template::pretty_status(
1110
+					EEM_Registration::status_id_incomplete,
1111
+					false,
1112
+					'sentence'
1113
+				),
1114
+			],
1115
+			'not_approved'      => [
1116
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1117
+				'desc'  => EEH_Template::pretty_status(
1118
+					EEM_Registration::status_id_not_approved,
1119
+					false,
1120
+					'sentence'
1121
+				),
1122
+			],
1123
+			'declined_status'   => [
1124
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1125
+				'desc'  => EEH_Template::pretty_status(
1126
+					EEM_Registration::status_id_declined,
1127
+					false,
1128
+					'sentence'
1129
+				),
1130
+			],
1131
+			'cancelled_status'  => [
1132
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1133
+				'desc'  => EEH_Template::pretty_status(
1134
+					EEM_Registration::status_id_cancelled,
1135
+					false,
1136
+					'sentence'
1137
+				),
1138
+			],
1139
+		];
1140
+		return array_merge($fc_items, $sc_items);
1141
+	}
1142
+
1143
+
1144
+
1145
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1146
+
1147
+
1148
+	/**
1149
+	 * @throws DomainException
1150
+	 * @throws EE_Error
1151
+	 * @throws InvalidArgumentException
1152
+	 * @throws InvalidDataTypeException
1153
+	 * @throws InvalidInterfaceException
1154
+	 */
1155
+	protected function _registrations_overview_list_table()
1156
+	{
1157
+		$this->appendAddNewRegistrationButtonToPageTitle();
1158
+		$header_text                  = '';
1159
+		$admin_page_header_decorators = [
1160
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
+		];
1165
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
+			$filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1167
+			$header_text             = $filter_header_decorator->getHeaderText($header_text);
1168
+		}
1169
+		$this->_template_args['admin_page_header'] = $header_text;
1170
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1171
+		$this->display_admin_list_table_page_with_no_sidebar();
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * @throws EE_Error
1177
+	 * @throws InvalidArgumentException
1178
+	 * @throws InvalidDataTypeException
1179
+	 * @throws InvalidInterfaceException
1180
+	 */
1181
+	private function appendAddNewRegistrationButtonToPageTitle()
1182
+	{
1183
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1184
+		if (
1185
+			$EVT_ID
1186
+			&& EE_Registry::instance()->CAP->current_user_can(
1187
+				'ee_edit_registrations',
1188
+				'espresso_registrations_new_registration',
1189
+				$EVT_ID
1190
+			)
1191
+		) {
1192
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1193
+				'new_registration',
1194
+				'add-registrant',
1195
+				['event_id' => $EVT_ID],
1196
+				'add-new-h2'
1197
+			);
1198
+		}
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * This sets the _registration property for the registration details screen
1204
+	 *
1205
+	 * @return void
1206
+	 * @throws EE_Error
1207
+	 * @throws InvalidArgumentException
1208
+	 * @throws InvalidDataTypeException
1209
+	 * @throws InvalidInterfaceException
1210
+	 */
1211
+	private function _set_registration_object()
1212
+	{
1213
+		// get out if we've already set the object
1214
+		if ($this->_registration instanceof EE_Registration) {
1215
+			return;
1216
+		}
1217
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1218
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1219
+			return;
1220
+		}
1221
+		$error_msg = sprintf(
1222
+			esc_html__(
1223
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1224
+				'event_espresso'
1225
+			),
1226
+			$REG_ID
1227
+		);
1228
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1229
+		$this->_registration = null;
1230
+	}
1231
+
1232
+
1233
+	/**
1234
+	 * Used to retrieve registrations for the list table.
1235
+	 *
1236
+	 * @param int  $per_page
1237
+	 * @param bool $count
1238
+	 * @param bool $this_month
1239
+	 * @param bool $today
1240
+	 * @return EE_Registration[]|int
1241
+	 * @throws EE_Error
1242
+	 * @throws InvalidArgumentException
1243
+	 * @throws InvalidDataTypeException
1244
+	 * @throws InvalidInterfaceException
1245
+	 */
1246
+	public function get_registrations(
1247
+		$per_page = 10,
1248
+		$count = false,
1249
+		$this_month = false,
1250
+		$today = false
1251
+	) {
1252
+		if ($this_month) {
1253
+			$this->request->setRequestParam('status', 'month');
1254
+		}
1255
+		if ($today) {
1256
+			$this->request->setRequestParam('status', 'today');
1257
+		}
1258
+		$query_params = $this->_get_registration_query_parameters([], $per_page, $count);
1259
+		/**
1260
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1261
+		 *
1262
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1263
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1264
+		 *                      or if you have the development copy of EE you can view this at the path:
1265
+		 *                      /docs/G--Model-System/model-query-params.md
1266
+		 */
1267
+		$query_params['group_by'] = '';
1268
+
1269
+		return $count
1270
+			? $this->getRegistrationModel()->count($query_params)
1271
+			/** @type EE_Registration[] */
1272
+			: $this->getRegistrationModel()->get_all($query_params);
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1278
+	 * Note: this listens to values on the request for some of the query parameters.
1279
+	 *
1280
+	 * @param array $request
1281
+	 * @param int   $per_page
1282
+	 * @param bool  $count
1283
+	 * @return array
1284
+	 * @throws EE_Error
1285
+	 * @throws InvalidArgumentException
1286
+	 * @throws InvalidDataTypeException
1287
+	 * @throws InvalidInterfaceException
1288
+	 */
1289
+	protected function _get_registration_query_parameters(
1290
+		$request = [],
1291
+		$per_page = 10,
1292
+		$count = false
1293
+	) {
1294
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1295
+		$list_table_query_builder = $this->getLoader()->getNew(
1296
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1297
+			[null, null, $request]
1298
+		);
1299
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1300
+	}
1301
+
1302
+
1303
+	public function get_registration_status_array()
1304
+	{
1305
+		return self::$_reg_status;
1306
+	}
1307
+
1308
+
1309
+
1310
+
1311
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1312
+	/**
1313
+	 * generates HTML for the View Registration Details Admin page
1314
+	 *
1315
+	 * @return void
1316
+	 * @throws DomainException
1317
+	 * @throws EE_Error
1318
+	 * @throws InvalidArgumentException
1319
+	 * @throws InvalidDataTypeException
1320
+	 * @throws InvalidInterfaceException
1321
+	 * @throws EntityNotFoundException
1322
+	 * @throws ReflectionException
1323
+	 */
1324
+	protected function _registration_details()
1325
+	{
1326
+		$this->_template_args = [];
1327
+		$this->_set_registration_object();
1328
+		if (is_object($this->_registration)) {
1329
+			$transaction                                   = $this->_registration->transaction()
1330
+				? $this->_registration->transaction()
1331
+				: EE_Transaction::new_instance();
1332
+			$this->_session                                = $transaction->session_data();
1333
+			$event_id                                      = $this->_registration->event_ID();
1334
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1335
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1336
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1337
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1338
+			$this->_template_args['grand_total']           = $transaction->total();
1339
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1340
+			// link back to overview
1341
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1342
+			$this->_template_args['registration']                = $this->_registration;
1343
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
+				[
1345
+					'action'   => 'default',
1346
+					'event_id' => $event_id,
1347
+				],
1348
+				REG_ADMIN_URL
1349
+			);
1350
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1351
+				[
1352
+					'action' => 'default',
1353
+					'EVT_ID' => $event_id,
1354
+					'page'   => 'espresso_transactions',
1355
+				],
1356
+				admin_url('admin.php')
1357
+			);
1358
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1359
+				[
1360
+					'page'   => 'espresso_events',
1361
+					'action' => 'edit',
1362
+					'post'   => $event_id,
1363
+				],
1364
+				admin_url('admin.php')
1365
+			);
1366
+			// next and previous links
1367
+			$next_reg                                      = $this->_registration->next(
1368
+				null,
1369
+				[],
1370
+				'REG_ID'
1371
+			);
1372
+			$this->_template_args['next_registration']     = $next_reg
1373
+				? $this->_next_link(
1374
+					EE_Admin_Page::add_query_args_and_nonce(
1375
+						[
1376
+							'action'  => 'view_registration',
1377
+							'_REG_ID' => $next_reg['REG_ID'],
1378
+						],
1379
+						REG_ADMIN_URL
1380
+					),
1381
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1382
+				)
1383
+				: '';
1384
+			$previous_reg                                  = $this->_registration->previous(
1385
+				null,
1386
+				[],
1387
+				'REG_ID'
1388
+			);
1389
+			$this->_template_args['previous_registration'] = $previous_reg
1390
+				? $this->_previous_link(
1391
+					EE_Admin_Page::add_query_args_and_nonce(
1392
+						[
1393
+							'action'  => 'view_registration',
1394
+							'_REG_ID' => $previous_reg['REG_ID'],
1395
+						],
1396
+						REG_ADMIN_URL
1397
+					),
1398
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1399
+				)
1400
+				: '';
1401
+			// grab header
1402
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1403
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1404
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1405
+				$template_path,
1406
+				$this->_template_args,
1407
+				true
1408
+			);
1409
+		} else {
1410
+			$this->_template_args['admin_page_header'] = '';
1411
+			$this->_display_espresso_notices();
1412
+		}
1413
+		// the details template wrapper
1414
+		$this->display_admin_page_with_sidebar();
1415
+	}
1416
+
1417
+
1418
+	/**
1419
+	 * @throws EE_Error
1420
+	 * @throws InvalidArgumentException
1421
+	 * @throws InvalidDataTypeException
1422
+	 * @throws InvalidInterfaceException
1423
+	 * @throws ReflectionException
1424
+	 * @since 4.10.2.p
1425
+	 */
1426
+	protected function _registration_details_metaboxes()
1427
+	{
1428
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1429
+		$this->_set_registration_object();
1430
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1431
+		add_meta_box(
1432
+			'edit-reg-status-mbox',
1433
+			esc_html__('Registration Status', 'event_espresso'),
1434
+			[$this, 'set_reg_status_buttons_metabox'],
1435
+			$this->_wp_page_slug,
1436
+			'normal',
1437
+			'high'
1438
+		);
1439
+		add_meta_box(
1440
+			'edit-reg-details-mbox',
1441
+			esc_html__('Registration Details', 'event_espresso'),
1442
+			[$this, '_reg_details_meta_box'],
1443
+			$this->_wp_page_slug,
1444
+			'normal',
1445
+			'high'
1446
+		);
1447
+		if (
1448
+			$attendee instanceof EE_Attendee
1449
+			&& EE_Registry::instance()->CAP->current_user_can(
1450
+				'ee_read_registration',
1451
+				'edit-reg-questions-mbox',
1452
+				$this->_registration->ID()
1453
+			)
1454
+		) {
1455
+			add_meta_box(
1456
+				'edit-reg-questions-mbox',
1457
+				esc_html__('Registration Form Answers', 'event_espresso'),
1458
+				[$this, '_reg_questions_meta_box'],
1459
+				$this->_wp_page_slug,
1460
+				'normal',
1461
+				'high'
1462
+			);
1463
+		}
1464
+		add_meta_box(
1465
+			'edit-reg-registrant-mbox',
1466
+			esc_html__('Contact Details', 'event_espresso'),
1467
+			[$this, '_reg_registrant_side_meta_box'],
1468
+			$this->_wp_page_slug,
1469
+			'side',
1470
+			'high'
1471
+		);
1472
+		if ($this->_registration->group_size() > 1) {
1473
+			add_meta_box(
1474
+				'edit-reg-attendees-mbox',
1475
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1476
+				[$this, '_reg_attendees_meta_box'],
1477
+				$this->_wp_page_slug,
1478
+				'normal',
1479
+				'high'
1480
+			);
1481
+		}
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * set_reg_status_buttons_metabox
1487
+	 *
1488
+	 * @return void
1489
+	 * @throws EE_Error
1490
+	 * @throws EntityNotFoundException
1491
+	 * @throws InvalidArgumentException
1492
+	 * @throws InvalidDataTypeException
1493
+	 * @throws InvalidInterfaceException
1494
+	 * @throws ReflectionException
1495
+	 */
1496
+	public function set_reg_status_buttons_metabox()
1497
+	{
1498
+		$this->_set_registration_object();
1499
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1500
+		$output                 = $change_reg_status_form->form_open(
1501
+			self::add_query_args_and_nonce(
1502
+				[
1503
+					'action' => 'change_reg_status',
1504
+				],
1505
+				REG_ADMIN_URL
1506
+			)
1507
+		);
1508
+		$output                 .= $change_reg_status_form->get_html();
1509
+		$output                 .= $change_reg_status_form->form_close();
1510
+		echo wp_kses($output, AllowedTags::getWithFormTags());
1511
+	}
1512
+
1513
+
1514
+	/**
1515
+	 * @return EE_Form_Section_Proper
1516
+	 * @throws EE_Error
1517
+	 * @throws InvalidArgumentException
1518
+	 * @throws InvalidDataTypeException
1519
+	 * @throws InvalidInterfaceException
1520
+	 * @throws EntityNotFoundException
1521
+	 * @throws ReflectionException
1522
+	 */
1523
+	protected function _generate_reg_status_change_form()
1524
+	{
1525
+		$reg_status_change_form_array = [
1526
+			'name'            => 'reg_status_change_form',
1527
+			'html_id'         => 'reg-status-change-form',
1528
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1529
+			'subsections'     => [
1530
+				'return'         => new EE_Hidden_Input(
1531
+					[
1532
+						'name'    => 'return',
1533
+						'default' => 'view_registration',
1534
+					]
1535
+				),
1536
+				'REG_ID'         => new EE_Hidden_Input(
1537
+					[
1538
+						'name'    => 'REG_ID',
1539
+						'default' => $this->_registration->ID(),
1540
+					]
1541
+				),
1542
+				'current_status' => new EE_Form_Section_HTML(
1543
+					EEH_HTML::table(
1544
+						EEH_HTML::tr(
1545
+							EEH_HTML::th(
1546
+								EEH_HTML::label(
1547
+									EEH_HTML::strong(
1548
+										esc_html__('Current Registration Status', 'event_espresso')
1549
+									)
1550
+								)
1551
+							)
1552
+							. EEH_HTML::td(
1553
+								EEH_HTML::strong(
1554
+									$this->_registration->pretty_status(),
1555
+									'',
1556
+									'status-' . $this->_registration->status_ID(),
1557
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1558
+								)
1559
+							)
1560
+						)
1561
+					)
1562
+				),
1563
+			],
1564
+		];
1565
+		if (
1566
+			EE_Registry::instance()->CAP->current_user_can(
1567
+				'ee_edit_registration',
1568
+				'toggle_registration_status',
1569
+				$this->_registration->ID()
1570
+			)
1571
+		) {
1572
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1573
+				$this->_get_reg_statuses(),
1574
+				[
1575
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1576
+					'default'         => $this->_registration->status_ID(),
1577
+				]
1578
+			);
1579
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1580
+				[
1581
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1582
+					'default'         => false,
1583
+					'html_help_text'  => esc_html__(
1584
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1585
+						'event_espresso'
1586
+					),
1587
+				]
1588
+			);
1589
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1590
+				[
1591
+					'html_class'      => 'button-primary',
1592
+					'html_label_text' => '&nbsp;',
1593
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1594
+				]
1595
+			);
1596
+		}
1597
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1603
+	 *
1604
+	 * @return array
1605
+	 * @throws EE_Error
1606
+	 * @throws InvalidArgumentException
1607
+	 * @throws InvalidDataTypeException
1608
+	 * @throws InvalidInterfaceException
1609
+	 * @throws EntityNotFoundException
1610
+	 */
1611
+	protected function _get_reg_statuses()
1612
+	{
1613
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1614
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1615
+		// get current reg status
1616
+		$current_status = $this->_registration->status_ID();
1617
+		// is registration for free event? This will determine whether to display the pending payment option
1618
+		if (
1619
+			$current_status !== EEM_Registration::status_id_pending_payment
1620
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1621
+		) {
1622
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1623
+		}
1624
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1625
+	}
1626
+
1627
+
1628
+	/**
1629
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1630
+	 *
1631
+	 * @param bool $status REG status given for changing registrations to.
1632
+	 * @param bool $notify Whether to send messages notifications or not.
1633
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1634
+	 * @throws DomainException
1635
+	 * @throws EE_Error
1636
+	 * @throws EntityNotFoundException
1637
+	 * @throws InvalidArgumentException
1638
+	 * @throws InvalidDataTypeException
1639
+	 * @throws InvalidInterfaceException
1640
+	 * @throws ReflectionException
1641
+	 * @throws RuntimeException
1642
+	 */
1643
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1644
+	{
1645
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1646
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1647
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1648
+
1649
+		// sanitize $REG_IDs
1650
+		$REG_IDs = array_map('absint', $REG_IDs);
1651
+		// and remove empty entries
1652
+		$REG_IDs = array_filter($REG_IDs);
1653
+
1654
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1655
+
1656
+		/**
1657
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1658
+		 * Currently this value is used downstream by the _process_resend_registration method.
1659
+		 *
1660
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1661
+		 * @param bool                     $status           The status registrations were changed to.
1662
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1663
+		 * @param Registrations_Admin_Page $admin_page
1664
+		 */
1665
+		$REG_ID = apply_filters(
1666
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1667
+			$result['REG_ID'],
1668
+			$status,
1669
+			$result['success'],
1670
+			$this
1671
+		);
1672
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1673
+
1674
+		// notify?
1675
+		if (
1676
+			$notify
1677
+			&& $result['success']
1678
+			&& ! empty($REG_ID)
1679
+			&& EE_Registry::instance()->CAP->current_user_can(
1680
+				'ee_send_message',
1681
+				'espresso_registrations_resend_registration'
1682
+			)
1683
+		) {
1684
+			$this->_process_resend_registration();
1685
+		}
1686
+		return $result;
1687
+	}
1688
+
1689
+
1690
+	/**
1691
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1692
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1693
+	 *
1694
+	 * @param array  $REG_IDs
1695
+	 * @param string $status
1696
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1697
+	 *                       slug sent with setting the registration status.
1698
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1699
+	 * @throws EE_Error
1700
+	 * @throws InvalidArgumentException
1701
+	 * @throws InvalidDataTypeException
1702
+	 * @throws InvalidInterfaceException
1703
+	 * @throws ReflectionException
1704
+	 * @throws RuntimeException
1705
+	 * @throws EntityNotFoundException
1706
+	 * @throws DomainException
1707
+	 */
1708
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1709
+	{
1710
+		$success = false;
1711
+		// typecast $REG_IDs
1712
+		$REG_IDs = (array) $REG_IDs;
1713
+		if (! empty($REG_IDs)) {
1714
+			$success = true;
1715
+			// set default status if none is passed
1716
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1717
+			$status_context = $notify
1718
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1719
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1720
+			// loop through REG_ID's and change status
1721
+			foreach ($REG_IDs as $REG_ID) {
1722
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1723
+				if ($registration instanceof EE_Registration) {
1724
+					$registration->set_status(
1725
+						$status,
1726
+						false,
1727
+						new Context(
1728
+							$status_context,
1729
+							esc_html__(
1730
+								'Manually triggered status change on a Registration Admin Page route.',
1731
+								'event_espresso'
1732
+							)
1733
+						)
1734
+					);
1735
+					$result = $registration->save();
1736
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1737
+					$success = $result !== false ? $success : false;
1738
+				}
1739
+			}
1740
+		}
1741
+
1742
+		// return $success and processed registrations
1743
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1744
+	}
1745
+
1746
+
1747
+	/**
1748
+	 * Common logic for setting up success message and redirecting to appropriate route
1749
+	 *
1750
+	 * @param string $STS_ID status id for the registration changed to
1751
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1752
+	 * @return void
1753
+	 * @throws DomainException
1754
+	 * @throws EE_Error
1755
+	 * @throws EntityNotFoundException
1756
+	 * @throws InvalidArgumentException
1757
+	 * @throws InvalidDataTypeException
1758
+	 * @throws InvalidInterfaceException
1759
+	 * @throws ReflectionException
1760
+	 * @throws RuntimeException
1761
+	 */
1762
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1763
+	{
1764
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1765
+			: ['success' => false];
1766
+		$success = isset($result['success']) && $result['success'];
1767
+		// setup success message
1768
+		if ($success) {
1769
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1770
+				$msg = sprintf(
1771
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1772
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
+				);
1774
+			} else {
1775
+				$msg = sprintf(
1776
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1777
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1778
+				);
1779
+			}
1780
+			EE_Error::add_success($msg);
1781
+		} else {
1782
+			EE_Error::add_error(
1783
+				esc_html__(
1784
+					'Something went wrong, and the status was not changed',
1785
+					'event_espresso'
1786
+				),
1787
+				__FILE__,
1788
+				__LINE__,
1789
+				__FUNCTION__
1790
+			);
1791
+		}
1792
+		$return = $this->request->getRequestParam('return');
1793
+		$route  = $return === 'view_registration'
1794
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1795
+			: ['action' => 'default'];
1796
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1797
+		$this->_redirect_after_action($success, '', '', $route, true);
1798
+	}
1799
+
1800
+
1801
+	/**
1802
+	 * incoming reg status change from reg details page.
1803
+	 *
1804
+	 * @return void
1805
+	 * @throws EE_Error
1806
+	 * @throws EntityNotFoundException
1807
+	 * @throws InvalidArgumentException
1808
+	 * @throws InvalidDataTypeException
1809
+	 * @throws InvalidInterfaceException
1810
+	 * @throws ReflectionException
1811
+	 * @throws RuntimeException
1812
+	 * @throws DomainException
1813
+	 */
1814
+	protected function _change_reg_status()
1815
+	{
1816
+		$this->request->setRequestParam('return', 'view_registration');
1817
+		// set notify based on whether the send notifications toggle is set or not
1818
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1819
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1820
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1821
+		switch ($reg_status) {
1822
+			case EEM_Registration::status_id_approved:
1823
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1824
+				$this->approve_registration($notify);
1825
+				break;
1826
+			case EEM_Registration::status_id_pending_payment:
1827
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1828
+				$this->pending_registration($notify);
1829
+				break;
1830
+			case EEM_Registration::status_id_not_approved:
1831
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1832
+				$this->not_approve_registration($notify);
1833
+				break;
1834
+			case EEM_Registration::status_id_declined:
1835
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1836
+				$this->decline_registration($notify);
1837
+				break;
1838
+			case EEM_Registration::status_id_cancelled:
1839
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1840
+				$this->cancel_registration($notify);
1841
+				break;
1842
+			case EEM_Registration::status_id_wait_list:
1843
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1844
+				$this->wait_list_registration($notify);
1845
+				break;
1846
+			case EEM_Registration::status_id_incomplete:
1847
+			default:
1848
+				$this->request->unSetRequestParam('return');
1849
+				$this->_reg_status_change_return('');
1850
+				break;
1851
+		}
1852
+	}
1853
+
1854
+
1855
+	/**
1856
+	 * Callback for bulk action routes.
1857
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1858
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1859
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1860
+	 * when an action is happening on just a single registration).
1861
+	 *
1862
+	 * @param      $action
1863
+	 * @param bool $notify
1864
+	 */
1865
+	protected function bulk_action_on_registrations($action, $notify = false)
1866
+	{
1867
+		do_action(
1868
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1869
+			$this,
1870
+			$action,
1871
+			$notify
1872
+		);
1873
+		$method = $action . '_registration';
1874
+		if (method_exists($this, $method)) {
1875
+			$this->$method($notify);
1876
+		}
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * approve_registration
1882
+	 *
1883
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1884
+	 * @return void
1885
+	 * @throws EE_Error
1886
+	 * @throws EntityNotFoundException
1887
+	 * @throws InvalidArgumentException
1888
+	 * @throws InvalidDataTypeException
1889
+	 * @throws InvalidInterfaceException
1890
+	 * @throws ReflectionException
1891
+	 * @throws RuntimeException
1892
+	 * @throws DomainException
1893
+	 */
1894
+	protected function approve_registration($notify = false)
1895
+	{
1896
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 * decline_registration
1902
+	 *
1903
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1904
+	 * @return void
1905
+	 * @throws EE_Error
1906
+	 * @throws EntityNotFoundException
1907
+	 * @throws InvalidArgumentException
1908
+	 * @throws InvalidDataTypeException
1909
+	 * @throws InvalidInterfaceException
1910
+	 * @throws ReflectionException
1911
+	 * @throws RuntimeException
1912
+	 * @throws DomainException
1913
+	 */
1914
+	protected function decline_registration($notify = false)
1915
+	{
1916
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 * cancel_registration
1922
+	 *
1923
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1924
+	 * @return void
1925
+	 * @throws EE_Error
1926
+	 * @throws EntityNotFoundException
1927
+	 * @throws InvalidArgumentException
1928
+	 * @throws InvalidDataTypeException
1929
+	 * @throws InvalidInterfaceException
1930
+	 * @throws ReflectionException
1931
+	 * @throws RuntimeException
1932
+	 * @throws DomainException
1933
+	 */
1934
+	protected function cancel_registration($notify = false)
1935
+	{
1936
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1937
+	}
1938
+
1939
+
1940
+	/**
1941
+	 * not_approve_registration
1942
+	 *
1943
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1944
+	 * @return void
1945
+	 * @throws EE_Error
1946
+	 * @throws EntityNotFoundException
1947
+	 * @throws InvalidArgumentException
1948
+	 * @throws InvalidDataTypeException
1949
+	 * @throws InvalidInterfaceException
1950
+	 * @throws ReflectionException
1951
+	 * @throws RuntimeException
1952
+	 * @throws DomainException
1953
+	 */
1954
+	protected function not_approve_registration($notify = false)
1955
+	{
1956
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1957
+	}
1958
+
1959
+
1960
+	/**
1961
+	 * decline_registration
1962
+	 *
1963
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1964
+	 * @return void
1965
+	 * @throws EE_Error
1966
+	 * @throws EntityNotFoundException
1967
+	 * @throws InvalidArgumentException
1968
+	 * @throws InvalidDataTypeException
1969
+	 * @throws InvalidInterfaceException
1970
+	 * @throws ReflectionException
1971
+	 * @throws RuntimeException
1972
+	 * @throws DomainException
1973
+	 */
1974
+	protected function pending_registration($notify = false)
1975
+	{
1976
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1977
+	}
1978
+
1979
+
1980
+	/**
1981
+	 * waitlist_registration
1982
+	 *
1983
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1984
+	 * @return void
1985
+	 * @throws EE_Error
1986
+	 * @throws EntityNotFoundException
1987
+	 * @throws InvalidArgumentException
1988
+	 * @throws InvalidDataTypeException
1989
+	 * @throws InvalidInterfaceException
1990
+	 * @throws ReflectionException
1991
+	 * @throws RuntimeException
1992
+	 * @throws DomainException
1993
+	 */
1994
+	protected function wait_list_registration($notify = false)
1995
+	{
1996
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
+	}
1998
+
1999
+
2000
+	/**
2001
+	 * generates HTML for the Registration main meta box
2002
+	 *
2003
+	 * @return void
2004
+	 * @throws DomainException
2005
+	 * @throws EE_Error
2006
+	 * @throws InvalidArgumentException
2007
+	 * @throws InvalidDataTypeException
2008
+	 * @throws InvalidInterfaceException
2009
+	 * @throws ReflectionException
2010
+	 * @throws EntityNotFoundException
2011
+	 */
2012
+	public function _reg_details_meta_box()
2013
+	{
2014
+		EEH_Autoloader::register_line_item_display_autoloaders();
2015
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2016
+		EE_Registry::instance()->load_helper('Line_Item');
2017
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2018
+			: EE_Transaction::new_instance();
2019
+		$this->_session = $transaction->session_data();
2020
+		$filters        = new EE_Line_Item_Filter_Collection();
2021
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2022
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2023
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2024
+			$filters,
2025
+			$transaction->total_line_item()
2026
+		);
2027
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2028
+		$line_item_display                       = new EE_Line_Item_Display(
2029
+			'reg_admin_table',
2030
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2031
+		);
2032
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2033
+			$filtered_line_item_tree,
2034
+			['EE_Registration' => $this->_registration]
2035
+		);
2036
+		$attendee                                = $this->_registration->attendee();
2037
+		if (
2038
+			EE_Registry::instance()->CAP->current_user_can(
2039
+				'ee_read_transaction',
2040
+				'espresso_transactions_view_transaction'
2041
+			)
2042
+		) {
2043
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2044
+				EE_Admin_Page::add_query_args_and_nonce(
2045
+					[
2046
+						'action' => 'view_transaction',
2047
+						'TXN_ID' => $transaction->ID(),
2048
+					],
2049
+					TXN_ADMIN_URL
2050
+				),
2051
+				esc_html__(' View Transaction', 'event_espresso'),
2052
+				'button secondary-button right',
2053
+				'dashicons dashicons-cart'
2054
+			);
2055
+		} else {
2056
+			$this->_template_args['view_transaction_button'] = '';
2057
+		}
2058
+		if (
2059
+			$attendee instanceof EE_Attendee
2060
+			&& EE_Registry::instance()->CAP->current_user_can(
2061
+				'ee_send_message',
2062
+				'espresso_registrations_resend_registration'
2063
+			)
2064
+		) {
2065
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2066
+				EE_Admin_Page::add_query_args_and_nonce(
2067
+					[
2068
+						'action'      => 'resend_registration',
2069
+						'_REG_ID'     => $this->_registration->ID(),
2070
+						'redirect_to' => 'view_registration',
2071
+					],
2072
+					REG_ADMIN_URL
2073
+				),
2074
+				esc_html__(' Resend Registration', 'event_espresso'),
2075
+				'button secondary-button right',
2076
+				'dashicons dashicons-email-alt'
2077
+			);
2078
+		} else {
2079
+			$this->_template_args['resend_registration_button'] = '';
2080
+		}
2081
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2082
+		$payment                               = $transaction->get_first_related('Payment');
2083
+		$payment                               = ! $payment instanceof EE_Payment
2084
+			? EE_Payment::new_instance()
2085
+			: $payment;
2086
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2087
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2088
+			? EE_Payment_Method::new_instance()
2089
+			: $payment_method;
2090
+		$reg_details                           = [
2091
+			'payment_method'       => $payment_method->name(),
2092
+			'response_msg'         => $payment->gateway_response(),
2093
+			'registration_id'      => $this->_registration->get('REG_code'),
2094
+			'registration_session' => $this->_registration->session_ID(),
2095
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2096
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2097
+		];
2098
+		if (isset($reg_details['registration_id'])) {
2099
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2100
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2101
+				'Registration ID',
2102
+				'event_espresso'
2103
+			);
2104
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2105
+		}
2106
+		if (isset($reg_details['payment_method'])) {
2107
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2108
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2109
+				'Most Recent Payment Method',
2110
+				'event_espresso'
2111
+			);
2112
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2113
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2114
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2115
+				'Payment method response',
2116
+				'event_espresso'
2117
+			);
2118
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2119
+		}
2120
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2121
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2122
+			'Registration Session',
2123
+			'event_espresso'
2124
+		);
2125
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2126
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2127
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2128
+			'Registration placed from IP',
2129
+			'event_espresso'
2130
+		);
2131
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2132
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2133
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2134
+			'Registrant User Agent',
2135
+			'event_espresso'
2136
+		);
2137
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2138
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2139
+			[
2140
+				'action'   => 'default',
2141
+				'event_id' => $this->_registration->event_ID(),
2142
+			],
2143
+			REG_ADMIN_URL
2144
+		);
2145
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2146
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2147
+		$template_path                                                        =
2148
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2149
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2150
+	}
2151
+
2152
+
2153
+	/**
2154
+	 * generates HTML for the Registration Questions meta box.
2155
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2156
+	 * otherwise uses new forms system
2157
+	 *
2158
+	 * @return void
2159
+	 * @throws DomainException
2160
+	 * @throws EE_Error
2161
+	 * @throws InvalidArgumentException
2162
+	 * @throws InvalidDataTypeException
2163
+	 * @throws InvalidInterfaceException
2164
+	 * @throws ReflectionException
2165
+	 */
2166
+	public function _reg_questions_meta_box()
2167
+	{
2168
+		// allow someone to override this method entirely
2169
+		if (
2170
+			apply_filters(
2171
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2172
+				true,
2173
+				$this,
2174
+				$this->_registration
2175
+			)
2176
+		) {
2177
+			$form                                              = $this->_get_reg_custom_questions_form(
2178
+				$this->_registration->ID()
2179
+			);
2180
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2181
+				? $form->get_html_and_js()
2182
+				: '';
2183
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2184
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2185
+			$template_path                                     =
2186
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2187
+			EEH_Template::display_template($template_path, $this->_template_args);
2188
+		}
2189
+	}
2190
+
2191
+
2192
+	/**
2193
+	 * form_before_question_group
2194
+	 *
2195
+	 * @param string $output
2196
+	 * @return        string
2197
+	 * @deprecated    as of 4.8.32.rc.000
2198
+	 */
2199
+	public function form_before_question_group($output)
2200
+	{
2201
+		EE_Error::doing_it_wrong(
2202
+			__CLASS__ . '::' . __FUNCTION__,
2203
+			esc_html__(
2204
+				'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.',
2205
+				'event_espresso'
2206
+			),
2207
+			'4.8.32.rc.000'
2208
+		);
2209
+		return '
2210 2210
 	<table class="form-table ee-width-100">
2211 2211
 		<tbody>
2212 2212
 			';
2213
-    }
2214
-
2215
-
2216
-    /**
2217
-     * form_after_question_group
2218
-     *
2219
-     * @param string $output
2220
-     * @return        string
2221
-     * @deprecated    as of 4.8.32.rc.000
2222
-     */
2223
-    public function form_after_question_group($output)
2224
-    {
2225
-        EE_Error::doing_it_wrong(
2226
-            __CLASS__ . '::' . __FUNCTION__,
2227
-            esc_html__(
2228
-                '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.',
2229
-                'event_espresso'
2230
-            ),
2231
-            '4.8.32.rc.000'
2232
-        );
2233
-        return '
2213
+	}
2214
+
2215
+
2216
+	/**
2217
+	 * form_after_question_group
2218
+	 *
2219
+	 * @param string $output
2220
+	 * @return        string
2221
+	 * @deprecated    as of 4.8.32.rc.000
2222
+	 */
2223
+	public function form_after_question_group($output)
2224
+	{
2225
+		EE_Error::doing_it_wrong(
2226
+			__CLASS__ . '::' . __FUNCTION__,
2227
+			esc_html__(
2228
+				'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.',
2229
+				'event_espresso'
2230
+			),
2231
+			'4.8.32.rc.000'
2232
+		);
2233
+		return '
2234 2234
 			<tr class="hide-if-no-js">
2235 2235
 				<th> </th>
2236 2236
 				<td class="reg-admin-edit-attendee-question-td">
2237 2237
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="'
2238
-               . esc_attr__('click to edit question', 'event_espresso')
2239
-               . '">
2238
+			   . esc_attr__('click to edit question', 'event_espresso')
2239
+			   . '">
2240 2240
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2241
-               . esc_html__('edit the above question group', 'event_espresso')
2242
-               . '</span>
2241
+			   . esc_html__('edit the above question group', 'event_espresso')
2242
+			   . '</span>
2243 2243
 						<div class="dashicons dashicons-edit"></div>
2244 2244
 					</a>
2245 2245
 				</td>
@@ -2247,641 +2247,641 @@  discard block
 block discarded – undo
2247 2247
 		</tbody>
2248 2248
 	</table>
2249 2249
 ';
2250
-    }
2251
-
2252
-
2253
-    /**
2254
-     * form_form_field_label_wrap
2255
-     *
2256
-     * @param string $label
2257
-     * @return        string
2258
-     * @deprecated    as of 4.8.32.rc.000
2259
-     */
2260
-    public function form_form_field_label_wrap($label)
2261
-    {
2262
-        EE_Error::doing_it_wrong(
2263
-            __CLASS__ . '::' . __FUNCTION__,
2264
-            esc_html__(
2265
-                '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.',
2266
-                'event_espresso'
2267
-            ),
2268
-            '4.8.32.rc.000'
2269
-        );
2270
-        return '
2250
+	}
2251
+
2252
+
2253
+	/**
2254
+	 * form_form_field_label_wrap
2255
+	 *
2256
+	 * @param string $label
2257
+	 * @return        string
2258
+	 * @deprecated    as of 4.8.32.rc.000
2259
+	 */
2260
+	public function form_form_field_label_wrap($label)
2261
+	{
2262
+		EE_Error::doing_it_wrong(
2263
+			__CLASS__ . '::' . __FUNCTION__,
2264
+			esc_html__(
2265
+				'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.',
2266
+				'event_espresso'
2267
+			),
2268
+			'4.8.32.rc.000'
2269
+		);
2270
+		return '
2271 2271
 			<tr>
2272 2272
 				<th>
2273 2273
 					' . $label . '
2274 2274
 				</th>';
2275
-    }
2276
-
2277
-
2278
-    /**
2279
-     * form_form_field_input__wrap
2280
-     *
2281
-     * @param string $input
2282
-     * @return        string
2283
-     * @deprecated    as of 4.8.32.rc.000
2284
-     */
2285
-    public function form_form_field_input__wrap($input)
2286
-    {
2287
-        EE_Error::doing_it_wrong(
2288
-            __CLASS__ . '::' . __FUNCTION__,
2289
-            esc_html__(
2290
-                '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.',
2291
-                'event_espresso'
2292
-            ),
2293
-            '4.8.32.rc.000'
2294
-        );
2295
-        return '
2275
+	}
2276
+
2277
+
2278
+	/**
2279
+	 * form_form_field_input__wrap
2280
+	 *
2281
+	 * @param string $input
2282
+	 * @return        string
2283
+	 * @deprecated    as of 4.8.32.rc.000
2284
+	 */
2285
+	public function form_form_field_input__wrap($input)
2286
+	{
2287
+		EE_Error::doing_it_wrong(
2288
+			__CLASS__ . '::' . __FUNCTION__,
2289
+			esc_html__(
2290
+				'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.',
2291
+				'event_espresso'
2292
+			),
2293
+			'4.8.32.rc.000'
2294
+		);
2295
+		return '
2296 2296
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2297 2297
 					' . $input . '
2298 2298
 				</td>
2299 2299
 			</tr>';
2300
-    }
2301
-
2302
-
2303
-    /**
2304
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2305
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2306
-     * to display the page
2307
-     *
2308
-     * @return void
2309
-     * @throws EE_Error
2310
-     * @throws InvalidArgumentException
2311
-     * @throws InvalidDataTypeException
2312
-     * @throws InvalidInterfaceException
2313
-     * @throws ReflectionException
2314
-     */
2315
-    protected function _update_attendee_registration_form()
2316
-    {
2317
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2318
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2319
-            $REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2320
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2321
-            if ($success) {
2322
-                $what  = esc_html__('Registration Form', 'event_espresso');
2323
-                $route = $REG_ID
2324
-                    ? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2325
-                    : ['action' => 'default'];
2326
-                $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2327
-            }
2328
-        }
2329
-    }
2330
-
2331
-
2332
-    /**
2333
-     * Gets the form for saving registrations custom questions (if done
2334
-     * previously retrieves the cached form object, which may have validation errors in it)
2335
-     *
2336
-     * @param int $REG_ID
2337
-     * @return EE_Registration_Custom_Questions_Form
2338
-     * @throws EE_Error
2339
-     * @throws InvalidArgumentException
2340
-     * @throws InvalidDataTypeException
2341
-     * @throws InvalidInterfaceException
2342
-     * @throws ReflectionException
2343
-     */
2344
-    protected function _get_reg_custom_questions_form($REG_ID)
2345
-    {
2346
-        if (! $this->_reg_custom_questions_form) {
2347
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
-            );
2351
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
-        }
2353
-        return $this->_reg_custom_questions_form;
2354
-    }
2355
-
2356
-
2357
-    /**
2358
-     * Saves
2359
-     *
2360
-     * @param bool $REG_ID
2361
-     * @return bool
2362
-     * @throws EE_Error
2363
-     * @throws InvalidArgumentException
2364
-     * @throws InvalidDataTypeException
2365
-     * @throws InvalidInterfaceException
2366
-     * @throws ReflectionException
2367
-     */
2368
-    private function _save_reg_custom_questions_form($REG_ID = 0)
2369
-    {
2370
-        if (! $REG_ID) {
2371
-            EE_Error::add_error(
2372
-                esc_html__(
2373
-                    'An error occurred. No registration ID was received.',
2374
-                    'event_espresso'
2375
-                ),
2376
-                __FILE__,
2377
-                __FUNCTION__,
2378
-                __LINE__
2379
-            );
2380
-        }
2381
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2382
-        $form->receive_form_submission($this->request->requestParams());
2383
-        $success = false;
2384
-        if ($form->is_valid()) {
2385
-            foreach ($form->subforms() as $question_group_form) {
2386
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2387
-                    $where_conditions    = [
2388
-                        'QST_ID' => $question_id,
2389
-                        'REG_ID' => $REG_ID,
2390
-                    ];
2391
-                    $possibly_new_values = [
2392
-                        'ANS_value' => $input->normalized_value(),
2393
-                    ];
2394
-                    $answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2395
-                    if ($answer instanceof EE_Answer) {
2396
-                        $success = $answer->save($possibly_new_values);
2397
-                    } else {
2398
-                        // insert it then
2399
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2400
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2401
-                        $success     = $answer->save();
2402
-                    }
2403
-                }
2404
-            }
2405
-        } else {
2406
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2407
-        }
2408
-        return $success;
2409
-    }
2410
-
2411
-
2412
-    /**
2413
-     * generates HTML for the Registration main meta box
2414
-     *
2415
-     * @return void
2416
-     * @throws DomainException
2417
-     * @throws EE_Error
2418
-     * @throws InvalidArgumentException
2419
-     * @throws InvalidDataTypeException
2420
-     * @throws InvalidInterfaceException
2421
-     * @throws ReflectionException
2422
-     */
2423
-    public function _reg_attendees_meta_box()
2424
-    {
2425
-        $REG = $this->getRegistrationModel();
2426
-        // get all other registrations on this transaction, and cache
2427
-        // the attendees for them so we don't have to run another query using force_join
2428
-        $registrations                           = $REG->get_all(
2429
-            [
2430
-                [
2431
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2432
-                    'REG_ID' => ['!=', $this->_registration->ID()],
2433
-                ],
2434
-                'force_join'               => ['Attendee'],
2435
-                'default_where_conditions' => 'other_models_only',
2436
-            ]
2437
-        );
2438
-        $this->_template_args['attendees']       = [];
2439
-        $this->_template_args['attendee_notice'] = '';
2440
-        if (
2441
-            empty($registrations)
2442
-            || (is_array($registrations)
2443
-                && ! EEH_Array::get_one_item_from_array($registrations))
2444
-        ) {
2445
-            EE_Error::add_error(
2446
-                esc_html__(
2447
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2448
-                    'event_espresso'
2449
-                ),
2450
-                __FILE__,
2451
-                __FUNCTION__,
2452
-                __LINE__
2453
-            );
2454
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2455
-        } else {
2456
-            $att_nmbr = 1;
2457
-            foreach ($registrations as $registration) {
2458
-                /* @var $registration EE_Registration */
2459
-                $attendee                                                      = $registration->attendee()
2460
-                    ? $registration->attendee()
2461
-                    : $this->getAttendeeModel()->create_default_object();
2462
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2463
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2468
-                    ', ',
2469
-                    $attendee->full_address_as_array()
2470
-                );
2471
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2472
-                    [
2473
-                        'action' => 'edit_attendee',
2474
-                        'post'   => $attendee->ID(),
2475
-                    ],
2476
-                    REG_ADMIN_URL
2477
-                );
2478
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2479
-                    $registration->event_obj() instanceof EE_Event
2480
-                        ? $registration->event_obj()->name()
2481
-                        : '';
2482
-                $att_nmbr++;
2483
-            }
2484
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
-        }
2486
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
-        EEH_Template::display_template($template_path, $this->_template_args);
2488
-    }
2489
-
2490
-
2491
-    /**
2492
-     * generates HTML for the Edit Registration side meta box
2493
-     *
2494
-     * @return void
2495
-     * @throws DomainException
2496
-     * @throws EE_Error
2497
-     * @throws InvalidArgumentException
2498
-     * @throws InvalidDataTypeException
2499
-     * @throws InvalidInterfaceException
2500
-     * @throws ReflectionException
2501
-     */
2502
-    public function _reg_registrant_side_meta_box()
2503
-    {
2504
-        /*@var $attendee EE_Attendee */
2505
-        $att_check = $this->_registration->attendee();
2506
-        $attendee  = $att_check instanceof EE_Attendee
2507
-            ? $att_check
2508
-            : $this->getAttendeeModel()->create_default_object();
2509
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2510
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2511
-        // primary registration object (that way we know if we need to show create button or not)
2512
-        if (! $this->_registration->is_primary_registrant()) {
2513
-            $primary_registration = $this->_registration->get_primary_registration();
2514
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2515
-                : null;
2516
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2517
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2518
-                // custom attendee object so let's not worry about the primary reg.
2519
-                $primary_registration = null;
2520
-            }
2521
-        } else {
2522
-            $primary_registration = null;
2523
-        }
2524
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2525
-        $this->_template_args['fname']             = $attendee->fname();
2526
-        $this->_template_args['lname']             = $attendee->lname();
2527
-        $this->_template_args['email']             = $attendee->email();
2528
-        $this->_template_args['phone']             = $attendee->phone();
2529
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2530
-        // edit link
2531
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2532
-            [
2533
-                'action' => 'edit_attendee',
2534
-                'post'   => $attendee->ID(),
2535
-            ],
2536
-            REG_ADMIN_URL
2537
-        );
2538
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2539
-        // create link
2540
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2541
-            ? EE_Admin_Page::add_query_args_and_nonce(
2542
-                [
2543
-                    'action'  => 'duplicate_attendee',
2544
-                    '_REG_ID' => $this->_registration->ID(),
2545
-                ],
2546
-                REG_ADMIN_URL
2547
-            ) : '';
2548
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2549
-        $this->_template_args['att_check']    = $att_check;
2550
-        $template_path                        =
2551
-            REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
-        EEH_Template::display_template($template_path, $this->_template_args);
2553
-    }
2554
-
2555
-
2556
-    /**
2557
-     * trash or restore registrations
2558
-     *
2559
-     * @param boolean $trash whether to archive or restore
2560
-     * @return void
2561
-     * @throws DomainException
2562
-     * @throws EE_Error
2563
-     * @throws EntityNotFoundException
2564
-     * @throws InvalidArgumentException
2565
-     * @throws InvalidDataTypeException
2566
-     * @throws InvalidInterfaceException
2567
-     * @throws ReflectionException
2568
-     * @throws RuntimeException
2569
-     * @throws UnexpectedEntityException
2570
-     */
2571
-    protected function _trash_or_restore_registrations($trash = true)
2572
-    {
2573
-        // if empty _REG_ID then get out because there's nothing to do
2574
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2575
-        if (empty($REG_IDs)) {
2576
-            EE_Error::add_error(
2577
-                sprintf(
2578
-                    esc_html__(
2579
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2580
-                        'event_espresso'
2581
-                    ),
2582
-                    $trash ? 'trash' : 'restore'
2583
-                ),
2584
-                __FILE__,
2585
-                __LINE__,
2586
-                __FUNCTION__
2587
-            );
2588
-            $this->_redirect_after_action(false, '', '', [], true);
2589
-        }
2590
-        $success        = 0;
2591
-        $overwrite_msgs = false;
2592
-        // Checkboxes
2593
-        $reg_count = count($REG_IDs);
2594
-        // cycle thru checkboxes
2595
-        foreach ($REG_IDs as $REG_ID) {
2596
-            /** @var EE_Registration $REG */
2597
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2598
-            $payments = $REG->registration_payments();
2599
-            if (! empty($payments)) {
2600
-                $name           = $REG->attendee() instanceof EE_Attendee
2601
-                    ? $REG->attendee()->full_name()
2602
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2603
-                $overwrite_msgs = true;
2604
-                EE_Error::add_error(
2605
-                    sprintf(
2606
-                        esc_html__(
2607
-                            '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.',
2608
-                            'event_espresso'
2609
-                        ),
2610
-                        $name
2611
-                    ),
2612
-                    __FILE__,
2613
-                    __FUNCTION__,
2614
-                    __LINE__
2615
-                );
2616
-                // can't trash this registration because it has payments.
2617
-                continue;
2618
-            }
2619
-            $updated = $trash ? $REG->delete() : $REG->restore();
2620
-            if ($updated) {
2621
-                $success++;
2622
-            }
2623
-        }
2624
-        $this->_redirect_after_action(
2625
-            $success === $reg_count, // were ALL registrations affected?
2626
-            $success > 1
2627
-                ? esc_html__('Registrations', 'event_espresso')
2628
-                : esc_html__('Registration', 'event_espresso'),
2629
-            $trash
2630
-                ? esc_html__('moved to the trash', 'event_espresso')
2631
-                : esc_html__('restored', 'event_espresso'),
2632
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2633
-            $overwrite_msgs
2634
-        );
2635
-    }
2636
-
2637
-
2638
-    /**
2639
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2640
-     * registration but also.
2641
-     * 1. Removing relations to EE_Attendee
2642
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2643
-     * ALSO trashed.
2644
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2645
-     * 4. Removing relationships between all tickets and the related registrations
2646
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2647
-     * 6. Deleting permanently any related Checkins.
2648
-     *
2649
-     * @return void
2650
-     * @throws EE_Error
2651
-     * @throws InvalidArgumentException
2652
-     * @throws InvalidDataTypeException
2653
-     * @throws InvalidInterfaceException
2654
-     * @throws ReflectionException
2655
-     */
2656
-    protected function _delete_registrations()
2657
-    {
2658
-        $REG_MDL = $this->getRegistrationModel();
2659
-        $success = 0;
2660
-        // Checkboxes
2661
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2662
-
2663
-        if (! empty($REG_IDs)) {
2664
-            // if array has more than one element than success message should be plural
2665
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2666
-            // cycle thru checkboxes
2667
-            foreach ($REG_IDs as $REG_ID) {
2668
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2669
-                if (! $REG instanceof EE_Registration) {
2670
-                    continue;
2671
-                }
2672
-                $deleted = $this->_delete_registration($REG);
2673
-                if (! $deleted) {
2674
-                    $success = 0;
2675
-                }
2676
-            }
2677
-        }
2678
-
2679
-        $what        = $success > 1
2680
-            ? esc_html__('Registrations', 'event_espresso')
2681
-            : esc_html__('Registration', 'event_espresso');
2682
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2683
-        $this->_redirect_after_action(
2684
-            $success,
2685
-            $what,
2686
-            $action_desc,
2687
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2688
-            true
2689
-        );
2690
-    }
2691
-
2692
-
2693
-    /**
2694
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2695
-     * models get affected.
2696
-     *
2697
-     * @param EE_Registration $REG registration to be deleted permanently
2698
-     * @return bool true = successful deletion, false = fail.
2699
-     * @throws EE_Error
2700
-     * @throws InvalidArgumentException
2701
-     * @throws InvalidDataTypeException
2702
-     * @throws InvalidInterfaceException
2703
-     * @throws ReflectionException
2704
-     */
2705
-    protected function _delete_registration(EE_Registration $REG)
2706
-    {
2707
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2708
-        // registrations on the transaction that are NOT trashed.
2709
-        $TXN = $REG->get_first_related('Transaction');
2710
-        if (! $TXN instanceof EE_Transaction) {
2711
-            EE_Error::add_error(
2712
-                sprintf(
2713
-                    esc_html__(
2714
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2715
-                        'event_espresso'
2716
-                    ),
2717
-                    $REG->id()
2718
-                ),
2719
-                __FILE__,
2720
-                __FUNCTION__,
2721
-                __LINE__
2722
-            );
2723
-            return false;
2724
-        }
2725
-        $REGS        = $TXN->get_many_related('Registration');
2726
-        $all_trashed = true;
2727
-        foreach ($REGS as $registration) {
2728
-            if (! $registration->get('REG_deleted')) {
2729
-                $all_trashed = false;
2730
-            }
2731
-        }
2732
-        if (! $all_trashed) {
2733
-            EE_Error::add_error(
2734
-                esc_html__(
2735
-                    '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.',
2736
-                    'event_espresso'
2737
-                ),
2738
-                __FILE__,
2739
-                __FUNCTION__,
2740
-                __LINE__
2741
-            );
2742
-            return false;
2743
-        }
2744
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2745
-        // separately from THIS one).
2746
-        foreach ($REGS as $registration) {
2747
-            // delete related answers
2748
-            $registration->delete_related_permanently('Answer');
2749
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2750
-            $attendee = $registration->get_first_related('Attendee');
2751
-            if ($attendee instanceof EE_Attendee) {
2752
-                $registration->_remove_relation_to($attendee, 'Attendee');
2753
-            }
2754
-            // now remove relationships to tickets on this registration.
2755
-            $registration->_remove_relations('Ticket');
2756
-            // now delete permanently the checkins related to this registration.
2757
-            $registration->delete_related_permanently('Checkin');
2758
-            if ($registration->ID() === $REG->ID()) {
2759
-                continue;
2760
-            } //we don't want to delete permanently the existing registration just yet.
2761
-            // remove relation to transaction for these registrations if NOT the existing registrations
2762
-            $registration->_remove_relations('Transaction');
2763
-            // delete permanently any related messages.
2764
-            $registration->delete_related_permanently('Message');
2765
-            // now delete this registration permanently
2766
-            $registration->delete_permanently();
2767
-        }
2768
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2769
-        // (the transaction and line items should be all that's left).
2770
-        // delete the line items related to the transaction for this registration.
2771
-        $TXN->delete_related_permanently('Line_Item');
2772
-        // we need to remove all the relationships on the transaction
2773
-        $TXN->delete_related_permanently('Payment');
2774
-        $TXN->delete_related_permanently('Extra_Meta');
2775
-        $TXN->delete_related_permanently('Message');
2776
-        // now we can delete this REG permanently (and the transaction of course)
2777
-        $REG->delete_related_permanently('Transaction');
2778
-        return $REG->delete_permanently();
2779
-    }
2780
-
2781
-
2782
-    /**
2783
-     *    generates HTML for the Register New Attendee Admin page
2784
-     *
2785
-     * @throws DomainException
2786
-     * @throws EE_Error
2787
-     * @throws InvalidArgumentException
2788
-     * @throws InvalidDataTypeException
2789
-     * @throws InvalidInterfaceException
2790
-     * @throws ReflectionException
2791
-     */
2792
-    public function new_registration()
2793
-    {
2794
-        if (! $this->_set_reg_event()) {
2795
-            throw new EE_Error(
2796
-                esc_html__(
2797
-                    'Unable to continue with registering because there is no Event ID in the request',
2798
-                    'event_espresso'
2799
-                )
2800
-            );
2801
-        }
2802
-        /** @var CurrentPage $current_page */
2803
-        $current_page = $this->loader->getShared(CurrentPage::class);
2804
-        $current_page->setEspressoPage(true);
2805
-        // gotta start with a clean slate if we're not coming here via ajax
2806
-        if (
2807
-            ! $this->request->isAjax()
2808
-            && (
2809
-                ! $this->request->requestParamIsSet('processing_registration')
2810
-                || $this->request->requestParamIsSet('step_error')
2811
-            )
2812
-        ) {
2813
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2814
-        }
2815
-        $this->_template_args['event_name'] = '';
2816
-        // event name
2817
-        if ($this->_reg_event) {
2818
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2819
-            $edit_event_url                     = self::add_query_args_and_nonce(
2820
-                [
2821
-                    'action' => 'edit',
2822
-                    'post'   => $this->_reg_event->ID(),
2823
-                ],
2824
-                EVENTS_ADMIN_URL
2825
-            );
2826
-            $edit_event_lnk                     = '<a href="'
2827
-                                                  . $edit_event_url
2828
-                                                  . '" aria-label="'
2829
-                                                  . esc_attr__('Edit ', 'event_espresso')
2830
-                                                  . $this->_reg_event->name()
2831
-                                                  . '">'
2832
-                                                  . esc_html__('Edit Event', 'event_espresso')
2833
-                                                  . '</a>';
2834
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2835
-                                                   . $edit_event_lnk
2836
-                                                   . '</span>';
2837
-        }
2838
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2839
-        if ($this->request->isAjax()) {
2840
-            $this->_return_json();
2841
-        }
2842
-        // grab header
2843
-        $template_path                              =
2844
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2845
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2846
-            $template_path,
2847
-            $this->_template_args,
2848
-            true
2849
-        );
2850
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2851
-        // the details template wrapper
2852
-        $this->display_admin_page_with_sidebar();
2853
-    }
2854
-
2855
-
2856
-    /**
2857
-     * This returns the content for a registration step
2858
-     *
2859
-     * @return string html
2860
-     * @throws DomainException
2861
-     * @throws EE_Error
2862
-     * @throws InvalidArgumentException
2863
-     * @throws InvalidDataTypeException
2864
-     * @throws InvalidInterfaceException
2865
-     * @throws ReflectionException
2866
-     */
2867
-    protected function _get_registration_step_content()
2868
-    {
2869
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2870
-            $warning_msg = sprintf(
2871
-                esc_html__(
2872
-                    '%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',
2873
-                    'event_espresso'
2874
-                ),
2875
-                '<br />',
2876
-                '<h3 class="important-notice">',
2877
-                '</h3>',
2878
-                '<div class="float-right">',
2879
-                '<span id="redirect_timer" class="important-notice">30</span>',
2880
-                '</div>',
2881
-                '<b>',
2882
-                '</b>'
2883
-            );
2884
-            return '
2300
+	}
2301
+
2302
+
2303
+	/**
2304
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2305
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2306
+	 * to display the page
2307
+	 *
2308
+	 * @return void
2309
+	 * @throws EE_Error
2310
+	 * @throws InvalidArgumentException
2311
+	 * @throws InvalidDataTypeException
2312
+	 * @throws InvalidInterfaceException
2313
+	 * @throws ReflectionException
2314
+	 */
2315
+	protected function _update_attendee_registration_form()
2316
+	{
2317
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2318
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2319
+			$REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2320
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2321
+			if ($success) {
2322
+				$what  = esc_html__('Registration Form', 'event_espresso');
2323
+				$route = $REG_ID
2324
+					? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2325
+					: ['action' => 'default'];
2326
+				$this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2327
+			}
2328
+		}
2329
+	}
2330
+
2331
+
2332
+	/**
2333
+	 * Gets the form for saving registrations custom questions (if done
2334
+	 * previously retrieves the cached form object, which may have validation errors in it)
2335
+	 *
2336
+	 * @param int $REG_ID
2337
+	 * @return EE_Registration_Custom_Questions_Form
2338
+	 * @throws EE_Error
2339
+	 * @throws InvalidArgumentException
2340
+	 * @throws InvalidDataTypeException
2341
+	 * @throws InvalidInterfaceException
2342
+	 * @throws ReflectionException
2343
+	 */
2344
+	protected function _get_reg_custom_questions_form($REG_ID)
2345
+	{
2346
+		if (! $this->_reg_custom_questions_form) {
2347
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
+			);
2351
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
+		}
2353
+		return $this->_reg_custom_questions_form;
2354
+	}
2355
+
2356
+
2357
+	/**
2358
+	 * Saves
2359
+	 *
2360
+	 * @param bool $REG_ID
2361
+	 * @return bool
2362
+	 * @throws EE_Error
2363
+	 * @throws InvalidArgumentException
2364
+	 * @throws InvalidDataTypeException
2365
+	 * @throws InvalidInterfaceException
2366
+	 * @throws ReflectionException
2367
+	 */
2368
+	private function _save_reg_custom_questions_form($REG_ID = 0)
2369
+	{
2370
+		if (! $REG_ID) {
2371
+			EE_Error::add_error(
2372
+				esc_html__(
2373
+					'An error occurred. No registration ID was received.',
2374
+					'event_espresso'
2375
+				),
2376
+				__FILE__,
2377
+				__FUNCTION__,
2378
+				__LINE__
2379
+			);
2380
+		}
2381
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2382
+		$form->receive_form_submission($this->request->requestParams());
2383
+		$success = false;
2384
+		if ($form->is_valid()) {
2385
+			foreach ($form->subforms() as $question_group_form) {
2386
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2387
+					$where_conditions    = [
2388
+						'QST_ID' => $question_id,
2389
+						'REG_ID' => $REG_ID,
2390
+					];
2391
+					$possibly_new_values = [
2392
+						'ANS_value' => $input->normalized_value(),
2393
+					];
2394
+					$answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2395
+					if ($answer instanceof EE_Answer) {
2396
+						$success = $answer->save($possibly_new_values);
2397
+					} else {
2398
+						// insert it then
2399
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2400
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2401
+						$success     = $answer->save();
2402
+					}
2403
+				}
2404
+			}
2405
+		} else {
2406
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2407
+		}
2408
+		return $success;
2409
+	}
2410
+
2411
+
2412
+	/**
2413
+	 * generates HTML for the Registration main meta box
2414
+	 *
2415
+	 * @return void
2416
+	 * @throws DomainException
2417
+	 * @throws EE_Error
2418
+	 * @throws InvalidArgumentException
2419
+	 * @throws InvalidDataTypeException
2420
+	 * @throws InvalidInterfaceException
2421
+	 * @throws ReflectionException
2422
+	 */
2423
+	public function _reg_attendees_meta_box()
2424
+	{
2425
+		$REG = $this->getRegistrationModel();
2426
+		// get all other registrations on this transaction, and cache
2427
+		// the attendees for them so we don't have to run another query using force_join
2428
+		$registrations                           = $REG->get_all(
2429
+			[
2430
+				[
2431
+					'TXN_ID' => $this->_registration->transaction_ID(),
2432
+					'REG_ID' => ['!=', $this->_registration->ID()],
2433
+				],
2434
+				'force_join'               => ['Attendee'],
2435
+				'default_where_conditions' => 'other_models_only',
2436
+			]
2437
+		);
2438
+		$this->_template_args['attendees']       = [];
2439
+		$this->_template_args['attendee_notice'] = '';
2440
+		if (
2441
+			empty($registrations)
2442
+			|| (is_array($registrations)
2443
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2444
+		) {
2445
+			EE_Error::add_error(
2446
+				esc_html__(
2447
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2448
+					'event_espresso'
2449
+				),
2450
+				__FILE__,
2451
+				__FUNCTION__,
2452
+				__LINE__
2453
+			);
2454
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2455
+		} else {
2456
+			$att_nmbr = 1;
2457
+			foreach ($registrations as $registration) {
2458
+				/* @var $registration EE_Registration */
2459
+				$attendee                                                      = $registration->attendee()
2460
+					? $registration->attendee()
2461
+					: $this->getAttendeeModel()->create_default_object();
2462
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2463
+				$this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2464
+				$this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2465
+				$this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2466
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2467
+				$this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2468
+					', ',
2469
+					$attendee->full_address_as_array()
2470
+				);
2471
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2472
+					[
2473
+						'action' => 'edit_attendee',
2474
+						'post'   => $attendee->ID(),
2475
+					],
2476
+					REG_ADMIN_URL
2477
+				);
2478
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2479
+					$registration->event_obj() instanceof EE_Event
2480
+						? $registration->event_obj()->name()
2481
+						: '';
2482
+				$att_nmbr++;
2483
+			}
2484
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
+		}
2486
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
+		EEH_Template::display_template($template_path, $this->_template_args);
2488
+	}
2489
+
2490
+
2491
+	/**
2492
+	 * generates HTML for the Edit Registration side meta box
2493
+	 *
2494
+	 * @return void
2495
+	 * @throws DomainException
2496
+	 * @throws EE_Error
2497
+	 * @throws InvalidArgumentException
2498
+	 * @throws InvalidDataTypeException
2499
+	 * @throws InvalidInterfaceException
2500
+	 * @throws ReflectionException
2501
+	 */
2502
+	public function _reg_registrant_side_meta_box()
2503
+	{
2504
+		/*@var $attendee EE_Attendee */
2505
+		$att_check = $this->_registration->attendee();
2506
+		$attendee  = $att_check instanceof EE_Attendee
2507
+			? $att_check
2508
+			: $this->getAttendeeModel()->create_default_object();
2509
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2510
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2511
+		// primary registration object (that way we know if we need to show create button or not)
2512
+		if (! $this->_registration->is_primary_registrant()) {
2513
+			$primary_registration = $this->_registration->get_primary_registration();
2514
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2515
+				: null;
2516
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2517
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2518
+				// custom attendee object so let's not worry about the primary reg.
2519
+				$primary_registration = null;
2520
+			}
2521
+		} else {
2522
+			$primary_registration = null;
2523
+		}
2524
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2525
+		$this->_template_args['fname']             = $attendee->fname();
2526
+		$this->_template_args['lname']             = $attendee->lname();
2527
+		$this->_template_args['email']             = $attendee->email();
2528
+		$this->_template_args['phone']             = $attendee->phone();
2529
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2530
+		// edit link
2531
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2532
+			[
2533
+				'action' => 'edit_attendee',
2534
+				'post'   => $attendee->ID(),
2535
+			],
2536
+			REG_ADMIN_URL
2537
+		);
2538
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2539
+		// create link
2540
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2541
+			? EE_Admin_Page::add_query_args_and_nonce(
2542
+				[
2543
+					'action'  => 'duplicate_attendee',
2544
+					'_REG_ID' => $this->_registration->ID(),
2545
+				],
2546
+				REG_ADMIN_URL
2547
+			) : '';
2548
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2549
+		$this->_template_args['att_check']    = $att_check;
2550
+		$template_path                        =
2551
+			REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
+		EEH_Template::display_template($template_path, $this->_template_args);
2553
+	}
2554
+
2555
+
2556
+	/**
2557
+	 * trash or restore registrations
2558
+	 *
2559
+	 * @param boolean $trash whether to archive or restore
2560
+	 * @return void
2561
+	 * @throws DomainException
2562
+	 * @throws EE_Error
2563
+	 * @throws EntityNotFoundException
2564
+	 * @throws InvalidArgumentException
2565
+	 * @throws InvalidDataTypeException
2566
+	 * @throws InvalidInterfaceException
2567
+	 * @throws ReflectionException
2568
+	 * @throws RuntimeException
2569
+	 * @throws UnexpectedEntityException
2570
+	 */
2571
+	protected function _trash_or_restore_registrations($trash = true)
2572
+	{
2573
+		// if empty _REG_ID then get out because there's nothing to do
2574
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2575
+		if (empty($REG_IDs)) {
2576
+			EE_Error::add_error(
2577
+				sprintf(
2578
+					esc_html__(
2579
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2580
+						'event_espresso'
2581
+					),
2582
+					$trash ? 'trash' : 'restore'
2583
+				),
2584
+				__FILE__,
2585
+				__LINE__,
2586
+				__FUNCTION__
2587
+			);
2588
+			$this->_redirect_after_action(false, '', '', [], true);
2589
+		}
2590
+		$success        = 0;
2591
+		$overwrite_msgs = false;
2592
+		// Checkboxes
2593
+		$reg_count = count($REG_IDs);
2594
+		// cycle thru checkboxes
2595
+		foreach ($REG_IDs as $REG_ID) {
2596
+			/** @var EE_Registration $REG */
2597
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2598
+			$payments = $REG->registration_payments();
2599
+			if (! empty($payments)) {
2600
+				$name           = $REG->attendee() instanceof EE_Attendee
2601
+					? $REG->attendee()->full_name()
2602
+					: esc_html__('Unknown Attendee', 'event_espresso');
2603
+				$overwrite_msgs = true;
2604
+				EE_Error::add_error(
2605
+					sprintf(
2606
+						esc_html__(
2607
+							'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.',
2608
+							'event_espresso'
2609
+						),
2610
+						$name
2611
+					),
2612
+					__FILE__,
2613
+					__FUNCTION__,
2614
+					__LINE__
2615
+				);
2616
+				// can't trash this registration because it has payments.
2617
+				continue;
2618
+			}
2619
+			$updated = $trash ? $REG->delete() : $REG->restore();
2620
+			if ($updated) {
2621
+				$success++;
2622
+			}
2623
+		}
2624
+		$this->_redirect_after_action(
2625
+			$success === $reg_count, // were ALL registrations affected?
2626
+			$success > 1
2627
+				? esc_html__('Registrations', 'event_espresso')
2628
+				: esc_html__('Registration', 'event_espresso'),
2629
+			$trash
2630
+				? esc_html__('moved to the trash', 'event_espresso')
2631
+				: esc_html__('restored', 'event_espresso'),
2632
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2633
+			$overwrite_msgs
2634
+		);
2635
+	}
2636
+
2637
+
2638
+	/**
2639
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2640
+	 * registration but also.
2641
+	 * 1. Removing relations to EE_Attendee
2642
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2643
+	 * ALSO trashed.
2644
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2645
+	 * 4. Removing relationships between all tickets and the related registrations
2646
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2647
+	 * 6. Deleting permanently any related Checkins.
2648
+	 *
2649
+	 * @return void
2650
+	 * @throws EE_Error
2651
+	 * @throws InvalidArgumentException
2652
+	 * @throws InvalidDataTypeException
2653
+	 * @throws InvalidInterfaceException
2654
+	 * @throws ReflectionException
2655
+	 */
2656
+	protected function _delete_registrations()
2657
+	{
2658
+		$REG_MDL = $this->getRegistrationModel();
2659
+		$success = 0;
2660
+		// Checkboxes
2661
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2662
+
2663
+		if (! empty($REG_IDs)) {
2664
+			// if array has more than one element than success message should be plural
2665
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2666
+			// cycle thru checkboxes
2667
+			foreach ($REG_IDs as $REG_ID) {
2668
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2669
+				if (! $REG instanceof EE_Registration) {
2670
+					continue;
2671
+				}
2672
+				$deleted = $this->_delete_registration($REG);
2673
+				if (! $deleted) {
2674
+					$success = 0;
2675
+				}
2676
+			}
2677
+		}
2678
+
2679
+		$what        = $success > 1
2680
+			? esc_html__('Registrations', 'event_espresso')
2681
+			: esc_html__('Registration', 'event_espresso');
2682
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2683
+		$this->_redirect_after_action(
2684
+			$success,
2685
+			$what,
2686
+			$action_desc,
2687
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2688
+			true
2689
+		);
2690
+	}
2691
+
2692
+
2693
+	/**
2694
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2695
+	 * models get affected.
2696
+	 *
2697
+	 * @param EE_Registration $REG registration to be deleted permanently
2698
+	 * @return bool true = successful deletion, false = fail.
2699
+	 * @throws EE_Error
2700
+	 * @throws InvalidArgumentException
2701
+	 * @throws InvalidDataTypeException
2702
+	 * @throws InvalidInterfaceException
2703
+	 * @throws ReflectionException
2704
+	 */
2705
+	protected function _delete_registration(EE_Registration $REG)
2706
+	{
2707
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2708
+		// registrations on the transaction that are NOT trashed.
2709
+		$TXN = $REG->get_first_related('Transaction');
2710
+		if (! $TXN instanceof EE_Transaction) {
2711
+			EE_Error::add_error(
2712
+				sprintf(
2713
+					esc_html__(
2714
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2715
+						'event_espresso'
2716
+					),
2717
+					$REG->id()
2718
+				),
2719
+				__FILE__,
2720
+				__FUNCTION__,
2721
+				__LINE__
2722
+			);
2723
+			return false;
2724
+		}
2725
+		$REGS        = $TXN->get_many_related('Registration');
2726
+		$all_trashed = true;
2727
+		foreach ($REGS as $registration) {
2728
+			if (! $registration->get('REG_deleted')) {
2729
+				$all_trashed = false;
2730
+			}
2731
+		}
2732
+		if (! $all_trashed) {
2733
+			EE_Error::add_error(
2734
+				esc_html__(
2735
+					'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.',
2736
+					'event_espresso'
2737
+				),
2738
+				__FILE__,
2739
+				__FUNCTION__,
2740
+				__LINE__
2741
+			);
2742
+			return false;
2743
+		}
2744
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2745
+		// separately from THIS one).
2746
+		foreach ($REGS as $registration) {
2747
+			// delete related answers
2748
+			$registration->delete_related_permanently('Answer');
2749
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2750
+			$attendee = $registration->get_first_related('Attendee');
2751
+			if ($attendee instanceof EE_Attendee) {
2752
+				$registration->_remove_relation_to($attendee, 'Attendee');
2753
+			}
2754
+			// now remove relationships to tickets on this registration.
2755
+			$registration->_remove_relations('Ticket');
2756
+			// now delete permanently the checkins related to this registration.
2757
+			$registration->delete_related_permanently('Checkin');
2758
+			if ($registration->ID() === $REG->ID()) {
2759
+				continue;
2760
+			} //we don't want to delete permanently the existing registration just yet.
2761
+			// remove relation to transaction for these registrations if NOT the existing registrations
2762
+			$registration->_remove_relations('Transaction');
2763
+			// delete permanently any related messages.
2764
+			$registration->delete_related_permanently('Message');
2765
+			// now delete this registration permanently
2766
+			$registration->delete_permanently();
2767
+		}
2768
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2769
+		// (the transaction and line items should be all that's left).
2770
+		// delete the line items related to the transaction for this registration.
2771
+		$TXN->delete_related_permanently('Line_Item');
2772
+		// we need to remove all the relationships on the transaction
2773
+		$TXN->delete_related_permanently('Payment');
2774
+		$TXN->delete_related_permanently('Extra_Meta');
2775
+		$TXN->delete_related_permanently('Message');
2776
+		// now we can delete this REG permanently (and the transaction of course)
2777
+		$REG->delete_related_permanently('Transaction');
2778
+		return $REG->delete_permanently();
2779
+	}
2780
+
2781
+
2782
+	/**
2783
+	 *    generates HTML for the Register New Attendee Admin page
2784
+	 *
2785
+	 * @throws DomainException
2786
+	 * @throws EE_Error
2787
+	 * @throws InvalidArgumentException
2788
+	 * @throws InvalidDataTypeException
2789
+	 * @throws InvalidInterfaceException
2790
+	 * @throws ReflectionException
2791
+	 */
2792
+	public function new_registration()
2793
+	{
2794
+		if (! $this->_set_reg_event()) {
2795
+			throw new EE_Error(
2796
+				esc_html__(
2797
+					'Unable to continue with registering because there is no Event ID in the request',
2798
+					'event_espresso'
2799
+				)
2800
+			);
2801
+		}
2802
+		/** @var CurrentPage $current_page */
2803
+		$current_page = $this->loader->getShared(CurrentPage::class);
2804
+		$current_page->setEspressoPage(true);
2805
+		// gotta start with a clean slate if we're not coming here via ajax
2806
+		if (
2807
+			! $this->request->isAjax()
2808
+			&& (
2809
+				! $this->request->requestParamIsSet('processing_registration')
2810
+				|| $this->request->requestParamIsSet('step_error')
2811
+			)
2812
+		) {
2813
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2814
+		}
2815
+		$this->_template_args['event_name'] = '';
2816
+		// event name
2817
+		if ($this->_reg_event) {
2818
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2819
+			$edit_event_url                     = self::add_query_args_and_nonce(
2820
+				[
2821
+					'action' => 'edit',
2822
+					'post'   => $this->_reg_event->ID(),
2823
+				],
2824
+				EVENTS_ADMIN_URL
2825
+			);
2826
+			$edit_event_lnk                     = '<a href="'
2827
+												  . $edit_event_url
2828
+												  . '" aria-label="'
2829
+												  . esc_attr__('Edit ', 'event_espresso')
2830
+												  . $this->_reg_event->name()
2831
+												  . '">'
2832
+												  . esc_html__('Edit Event', 'event_espresso')
2833
+												  . '</a>';
2834
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2835
+												   . $edit_event_lnk
2836
+												   . '</span>';
2837
+		}
2838
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2839
+		if ($this->request->isAjax()) {
2840
+			$this->_return_json();
2841
+		}
2842
+		// grab header
2843
+		$template_path                              =
2844
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2845
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2846
+			$template_path,
2847
+			$this->_template_args,
2848
+			true
2849
+		);
2850
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2851
+		// the details template wrapper
2852
+		$this->display_admin_page_with_sidebar();
2853
+	}
2854
+
2855
+
2856
+	/**
2857
+	 * This returns the content for a registration step
2858
+	 *
2859
+	 * @return string html
2860
+	 * @throws DomainException
2861
+	 * @throws EE_Error
2862
+	 * @throws InvalidArgumentException
2863
+	 * @throws InvalidDataTypeException
2864
+	 * @throws InvalidInterfaceException
2865
+	 * @throws ReflectionException
2866
+	 */
2867
+	protected function _get_registration_step_content()
2868
+	{
2869
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2870
+			$warning_msg = sprintf(
2871
+				esc_html__(
2872
+					'%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',
2873
+					'event_espresso'
2874
+				),
2875
+				'<br />',
2876
+				'<h3 class="important-notice">',
2877
+				'</h3>',
2878
+				'<div class="float-right">',
2879
+				'<span id="redirect_timer" class="important-notice">30</span>',
2880
+				'</div>',
2881
+				'<b>',
2882
+				'</b>'
2883
+			);
2884
+			return '
2885 2885
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2886 2886
 	<script >
2887 2887
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2894,846 +2894,846 @@  discard block
 block discarded – undo
2894 2894
 	        }
2895 2895
 	    }, 800 );
2896 2896
 	</script >';
2897
-        }
2898
-        $template_args = [
2899
-            'title'                    => '',
2900
-            'content'                  => '',
2901
-            'step_button_text'         => '',
2902
-            'show_notification_toggle' => false,
2903
-        ];
2904
-        // to indicate we're processing a new registration
2905
-        $hidden_fields = [
2906
-            'processing_registration' => [
2907
-                'type'  => 'hidden',
2908
-                'value' => 0,
2909
-            ],
2910
-            'event_id'                => [
2911
-                'type'  => 'hidden',
2912
-                'value' => $this->_reg_event->ID(),
2913
-            ],
2914
-        ];
2915
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2916
-        $cart = EE_Registry::instance()->SSN->cart();
2917
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2918
-        switch ($step) {
2919
-            case 'ticket':
2920
-                $hidden_fields['processing_registration']['value'] = 1;
2921
-                $template_args['title']                            = esc_html__(
2922
-                    'Step One: Select the Ticket for this registration',
2923
-                    'event_espresso'
2924
-                );
2925
-                $template_args['content']                          =
2926
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2927
-                $template_args['content']                          .= '</div>';
2928
-                $template_args['step_button_text']                 = esc_html__(
2929
-                    'Add Tickets and Continue to Registrant Details',
2930
-                    'event_espresso'
2931
-                );
2932
-                $template_args['show_notification_toggle']         = false;
2933
-                break;
2934
-            case 'questions':
2935
-                $hidden_fields['processing_registration']['value'] = 2;
2936
-                $template_args['title']                            = esc_html__(
2937
-                    'Step Two: Add Registrant Details for this Registration',
2938
-                    'event_espresso'
2939
-                );
2940
-                // in theory, we should be able to run EED_SPCO at this point
2941
-                // because the cart should have been set up properly by the first process_reg_step run.
2942
-                $template_args['content']                  =
2943
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2944
-                $template_args['step_button_text']         = esc_html__(
2945
-                    'Save Registration and Continue to Details',
2946
-                    'event_espresso'
2947
-                );
2948
-                $template_args['show_notification_toggle'] = true;
2949
-                break;
2950
-        }
2951
-        // we come back to the process_registration_step route.
2952
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2953
-        return EEH_Template::display_template(
2954
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2955
-            $template_args,
2956
-            true
2957
-        );
2958
-    }
2959
-
2960
-
2961
-    /**
2962
-     * set_reg_event
2963
-     *
2964
-     * @return bool
2965
-     * @throws EE_Error
2966
-     * @throws InvalidArgumentException
2967
-     * @throws InvalidDataTypeException
2968
-     * @throws InvalidInterfaceException
2969
-     */
2970
-    private function _set_reg_event()
2971
-    {
2972
-        if (is_object($this->_reg_event)) {
2973
-            return true;
2974
-        }
2975
-
2976
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2977
-        if (! $EVT_ID) {
2978
-            return false;
2979
-        }
2980
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2981
-        return true;
2982
-    }
2983
-
2984
-
2985
-    /**
2986
-     * process_reg_step
2987
-     *
2988
-     * @return void
2989
-     * @throws DomainException
2990
-     * @throws EE_Error
2991
-     * @throws InvalidArgumentException
2992
-     * @throws InvalidDataTypeException
2993
-     * @throws InvalidInterfaceException
2994
-     * @throws ReflectionException
2995
-     * @throws RuntimeException
2996
-     */
2997
-    public function process_reg_step()
2998
-    {
2999
-        EE_System::do_not_cache();
3000
-        $this->_set_reg_event();
3001
-        /** @var CurrentPage $current_page */
3002
-        $current_page = $this->loader->getShared(CurrentPage::class);
3003
-        $current_page->setEspressoPage(true);
3004
-        $this->request->setRequestParam('uts', time());
3005
-        // what step are we on?
3006
-        $cart = EE_Registry::instance()->SSN->cart();
3007
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3008
-        // if doing ajax then we need to verify the nonce
3009
-        if ($this->request->isAjax()) {
3010
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
3011
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3012
-        }
3013
-        switch ($step) {
3014
-            case 'ticket':
3015
-                // process ticket selection
3016
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3017
-                if ($success) {
3018
-                    EE_Error::add_success(
3019
-                        esc_html__(
3020
-                            'Tickets Selected. Now complete the registration.',
3021
-                            'event_espresso'
3022
-                        )
3023
-                    );
3024
-                } else {
3025
-                    $this->request->setRequestParam('step_error', true);
3026
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3027
-                }
3028
-                if ($this->request->isAjax()) {
3029
-                    $this->new_registration(); // display next step
3030
-                } else {
3031
-                    $query_args = [
3032
-                        'action'                  => 'new_registration',
3033
-                        'processing_registration' => 1,
3034
-                        'event_id'                => $this->_reg_event->ID(),
3035
-                        'uts'                     => time(),
3036
-                    ];
3037
-                    $this->_redirect_after_action(
3038
-                        false,
3039
-                        '',
3040
-                        '',
3041
-                        $query_args,
3042
-                        true
3043
-                    );
3044
-                }
3045
-                break;
3046
-            case 'questions':
3047
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3048
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3049
-                }
3050
-                // process registration
3051
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3052
-                if ($cart instanceof EE_Cart) {
3053
-                    $grand_total = $cart->get_grand_total();
3054
-                    if ($grand_total instanceof EE_Line_Item) {
3055
-                        $grand_total->save_this_and_descendants_to_txn();
3056
-                    }
3057
-                }
3058
-                if (! $transaction instanceof EE_Transaction) {
3059
-                    $query_args = [
3060
-                        'action'                  => 'new_registration',
3061
-                        'processing_registration' => 2,
3062
-                        'event_id'                => $this->_reg_event->ID(),
3063
-                        'uts'                     => time(),
3064
-                    ];
3065
-                    if ($this->request->isAjax()) {
3066
-                        // display registration form again because there are errors (maybe validation?)
3067
-                        $this->new_registration();
3068
-                        return;
3069
-                    }
3070
-                    $this->_redirect_after_action(
3071
-                        false,
3072
-                        '',
3073
-                        '',
3074
-                        $query_args,
3075
-                        true
3076
-                    );
3077
-                    return;
3078
-                }
3079
-                // maybe update status, and make sure to save transaction if not done already
3080
-                if (! $transaction->update_status_based_on_total_paid()) {
3081
-                    $transaction->save();
3082
-                }
3083
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3084
-                $query_args = [
3085
-                    'action'        => 'redirect_to_txn',
3086
-                    'TXN_ID'        => $transaction->ID(),
3087
-                    'EVT_ID'        => $this->_reg_event->ID(),
3088
-                    'event_name'    => urlencode($this->_reg_event->name()),
3089
-                    'redirect_from' => 'new_registration',
3090
-                ];
3091
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3092
-                break;
3093
-        }
3094
-        // what are you looking here for?  Should be nothing to do at this point.
3095
-    }
3096
-
3097
-
3098
-    /**
3099
-     * redirect_to_txn
3100
-     *
3101
-     * @return void
3102
-     * @throws EE_Error
3103
-     * @throws InvalidArgumentException
3104
-     * @throws InvalidDataTypeException
3105
-     * @throws InvalidInterfaceException
3106
-     * @throws ReflectionException
3107
-     */
3108
-    public function redirect_to_txn()
3109
-    {
3110
-        EE_System::do_not_cache();
3111
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3112
-        $query_args = [
3113
-            'action' => 'view_transaction',
3114
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3115
-            'page'   => 'espresso_transactions',
3116
-        ];
3117
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3118
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3119
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3120
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3121
-        }
3122
-        EE_Error::add_success(
3123
-            esc_html__(
3124
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3125
-                'event_espresso'
3126
-            )
3127
-        );
3128
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3129
-    }
3130
-
3131
-
3132
-    /**
3133
-     * generates HTML for the Attendee Contact List
3134
-     *
3135
-     * @return void
3136
-     * @throws DomainException
3137
-     * @throws EE_Error
3138
-     */
3139
-    protected function _attendee_contact_list_table()
3140
-    {
3141
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3142
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3143
-        $this->display_admin_list_table_page_with_no_sidebar();
3144
-    }
3145
-
3146
-
3147
-    /**
3148
-     * get_attendees
3149
-     *
3150
-     * @param      $per_page
3151
-     * @param bool $count whether to return count or data.
3152
-     * @param bool $trash
3153
-     * @return array|int
3154
-     * @throws EE_Error
3155
-     * @throws InvalidArgumentException
3156
-     * @throws InvalidDataTypeException
3157
-     * @throws InvalidInterfaceException
3158
-     */
3159
-    public function get_attendees($per_page, $count = false, $trash = false)
3160
-    {
3161
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3162
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3163
-        $orderby = $this->request->getRequestParam('orderby');
3164
-        switch ($orderby) {
3165
-            case 'ATT_ID':
3166
-            case 'ATT_fname':
3167
-            case 'ATT_email':
3168
-            case 'ATT_city':
3169
-            case 'STA_ID':
3170
-            case 'CNT_ID':
3171
-                break;
3172
-            case 'Registration_Count':
3173
-                $orderby = 'Registration_Count';
3174
-                break;
3175
-            default:
3176
-                $orderby = 'ATT_lname';
3177
-        }
3178
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3179
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3180
-        $per_page     = absint($per_page) ? $per_page : 10;
3181
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3182
-        $_where       = [];
3183
-        $search_term  = $this->request->getRequestParam('s');
3184
-        if ($search_term) {
3185
-            $search_term  = '%' . $search_term . '%';
3186
-            $_where['OR'] = [
3187
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3188
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3189
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3190
-                'ATT_fname'                         => ['LIKE', $search_term],
3191
-                'ATT_lname'                         => ['LIKE', $search_term],
3192
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3193
-                'ATT_email'                         => ['LIKE', $search_term],
3194
-                'ATT_address'                       => ['LIKE', $search_term],
3195
-                'ATT_address2'                      => ['LIKE', $search_term],
3196
-                'ATT_city'                          => ['LIKE', $search_term],
3197
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3198
-                'State.STA_name'                    => ['LIKE', $search_term],
3199
-                'ATT_phone'                         => ['LIKE', $search_term],
3200
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3201
-                'Registration.REG_code'             => ['LIKE', $search_term],
3202
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3203
-            ];
3204
-        }
3205
-        $offset     = ($current_page - 1) * $per_page;
3206
-        $limit      = $count ? null : [$offset, $per_page];
3207
-        $query_args = [
3208
-            $_where,
3209
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3210
-            'limit'         => $limit,
3211
-        ];
3212
-        if (! $count) {
3213
-            $query_args['order_by'] = [$orderby => $sort];
3214
-        }
3215
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3216
-        return $count
3217
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3218
-            : $this->getAttendeeModel()->get_all($query_args);
3219
-    }
3220
-
3221
-
3222
-    /**
3223
-     * This is just taking care of resending the registration confirmation
3224
-     *
3225
-     * @return void
3226
-     * @throws EE_Error
3227
-     * @throws InvalidArgumentException
3228
-     * @throws InvalidDataTypeException
3229
-     * @throws InvalidInterfaceException
3230
-     * @throws ReflectionException
3231
-     */
3232
-    protected function _resend_registration()
3233
-    {
3234
-        $this->_process_resend_registration();
3235
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3236
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3237
-        $query_args  = $redirect_to
3238
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3239
-            : ['action' => 'default'];
3240
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3241
-    }
3242
-
3243
-
3244
-    /**
3245
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3246
-     * to use when selecting registrations
3247
-     *
3248
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3249
-     *                                                     the query parameters from the request
3250
-     * @return void ends the request with a redirect or download
3251
-     */
3252
-    public function _registrations_report_base($method_name_for_getting_query_params)
3253
-    {
3254
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3255
-            ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3256
-            : null;
3257
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3258
-            $filters = $this->request->getRequestParam('filters', [], DataType::STRING, true);
3259
-            $report_params  = $this->$method_name_for_getting_query_params($filters);
3260
-            wp_redirect(
3261
-                EE_Admin_Page::add_query_args_and_nonce(
3262
-                    [
3263
-                        'page'        => 'espresso_batch',
3264
-                        'batch'       => 'file',
3265
-                        'EVT_ID'      => $EVT_ID,
3266
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3267
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', DataType::URL)),
3268
-                        'filters'     => urlencode(serialize($report_params)),
3269
-                        'use_filters' => $this->request->getRequestParam('use_filters', false, DataType::BOOL)
3270
-                    ]
3271
-                )
3272
-            );
3273
-        } else {
3274
-            // Pull the current request params
3275
-            $request_args = $this->request->requestParams();
3276
-            // Set the required request_args to be passed to the export
3277
-            $required_request_args = [
3278
-                'export' => 'report',
3279
-                'action' => 'registrations_report_for_event',
3280
-                'EVT_ID' => $EVT_ID,
3281
-            ];
3282
-            // Merge required request args, overriding any currently set
3283
-            $request_args = array_merge($request_args, $required_request_args);
3284
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3285
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3286
-                $EE_Export = EE_Export::instance($request_args);
3287
-                $EE_Export->export();
3288
-            }
3289
-        }
3290
-    }
3291
-
3292
-
3293
-    /**
3294
-     * Creates a registration report using only query parameters in the request
3295
-     *
3296
-     * @return void
3297
-     */
3298
-    public function _registrations_report()
3299
-    {
3300
-        $this->_registrations_report_base('_get_registration_query_parameters');
3301
-    }
3302
-
3303
-
3304
-    public function _contact_list_export()
3305
-    {
3306
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3307
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3308
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3309
-            $EE_Export->export_attendees();
3310
-        }
3311
-    }
3312
-
3313
-
3314
-    public function _contact_list_report()
3315
-    {
3316
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3317
-            wp_redirect(
3318
-                EE_Admin_Page::add_query_args_and_nonce(
3319
-                    [
3320
-                        'page'        => 'espresso_batch',
3321
-                        'batch'       => 'file',
3322
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3323
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3324
-                    ]
3325
-                )
3326
-            );
3327
-        } else {
3328
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3329
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3330
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3331
-                $EE_Export->report_attendees();
3332
-            }
3333
-        }
3334
-    }
3335
-
3336
-
3337
-
3338
-
3339
-
3340
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3341
-    /**
3342
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3343
-     *
3344
-     * @return void
3345
-     * @throws EE_Error
3346
-     * @throws InvalidArgumentException
3347
-     * @throws InvalidDataTypeException
3348
-     * @throws InvalidInterfaceException
3349
-     * @throws ReflectionException
3350
-     */
3351
-    protected function _duplicate_attendee()
3352
-    {
3353
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3354
-        $action = $this->request->getRequestParam('return', 'default');
3355
-        // verify we have necessary info
3356
-        if (! $REG_ID) {
3357
-            EE_Error::add_error(
3358
-                esc_html__(
3359
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3360
-                    'event_espresso'
3361
-                ),
3362
-                __FILE__,
3363
-                __LINE__,
3364
-                __FUNCTION__
3365
-            );
3366
-            $query_args = ['action' => $action];
3367
-            $this->_redirect_after_action('', '', '', $query_args, true);
3368
-        }
3369
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3370
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3371
-        if (! $registration instanceof EE_Registration) {
3372
-            throw new RuntimeException(
3373
-                sprintf(
3374
-                    esc_html__(
3375
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3376
-                        'event_espresso'
3377
-                    ),
3378
-                    $REG_ID
3379
-                )
3380
-            );
3381
-        }
3382
-        $attendee = $registration->attendee();
3383
-        // remove relation of existing attendee on registration
3384
-        $registration->_remove_relation_to($attendee, 'Attendee');
3385
-        // new attendee
3386
-        $new_attendee = clone $attendee;
3387
-        $new_attendee->set('ATT_ID', 0);
3388
-        $new_attendee->save();
3389
-        // add new attendee to reg
3390
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3391
-        EE_Error::add_success(
3392
-            esc_html__(
3393
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3394
-                'event_espresso'
3395
-            )
3396
-        );
3397
-        // redirect to edit page for attendee
3398
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3399
-        $this->_redirect_after_action('', '', '', $query_args, true);
3400
-    }
3401
-
3402
-
3403
-    /**
3404
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3405
-     *
3406
-     * @param int     $post_id
3407
-     * @param WP_Post $post
3408
-     * @throws DomainException
3409
-     * @throws EE_Error
3410
-     * @throws InvalidArgumentException
3411
-     * @throws InvalidDataTypeException
3412
-     * @throws InvalidInterfaceException
3413
-     * @throws LogicException
3414
-     * @throws InvalidFormSubmissionException
3415
-     * @throws ReflectionException
3416
-     */
3417
-    protected function _insert_update_cpt_item($post_id, $post)
3418
-    {
3419
-        $success  = true;
3420
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3421
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3422
-            : null;
3423
-        // for attendee updates
3424
-        if ($attendee instanceof EE_Attendee) {
3425
-            // note we should only be UPDATING attendees at this point.
3426
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3427
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3428
-            $updated_fields = [
3429
-                'ATT_fname'     => $fname,
3430
-                'ATT_lname'     => $lname,
3431
-                'ATT_full_name' => "{$fname} {$lname}",
3432
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3433
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3434
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3435
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3436
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3437
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3438
-            ];
3439
-            foreach ($updated_fields as $field => $value) {
3440
-                $attendee->set($field, $value);
3441
-            }
3442
-
3443
-            // process contact details metabox form handler (which will also save the attendee)
3444
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3445
-            $success              = $contact_details_form->process($this->request->requestParams());
3446
-
3447
-            $attendee_update_callbacks = apply_filters(
3448
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3449
-                []
3450
-            );
3451
-            foreach ($attendee_update_callbacks as $a_callback) {
3452
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3453
-                    throw new EE_Error(
3454
-                        sprintf(
3455
-                            esc_html__(
3456
-                                '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.',
3457
-                                'event_espresso'
3458
-                            ),
3459
-                            $a_callback
3460
-                        )
3461
-                    );
3462
-                }
3463
-            }
3464
-        }
3465
-
3466
-        if ($success === false) {
3467
-            EE_Error::add_error(
3468
-                esc_html__(
3469
-                    'Something went wrong with updating the meta table data for the registration.',
3470
-                    'event_espresso'
3471
-                ),
3472
-                __FILE__,
3473
-                __FUNCTION__,
3474
-                __LINE__
3475
-            );
3476
-        }
3477
-    }
3478
-
3479
-
3480
-    public function trash_cpt_item($post_id)
3481
-    {
3482
-    }
3483
-
3484
-
3485
-    public function delete_cpt_item($post_id)
3486
-    {
3487
-    }
3488
-
3489
-
3490
-    public function restore_cpt_item($post_id)
3491
-    {
3492
-    }
3493
-
3494
-
3495
-    protected function _restore_cpt_item($post_id, $revision_id)
3496
-    {
3497
-    }
3498
-
3499
-
3500
-    /**
3501
-     * @throws EE_Error
3502
-     * @throws ReflectionException
3503
-     * @since 4.10.2.p
3504
-     */
3505
-    public function attendee_editor_metaboxes()
3506
-    {
3507
-        $this->verify_cpt_object();
3508
-        remove_meta_box(
3509
-            'postexcerpt',
3510
-            $this->_cpt_routes[ $this->_req_action ],
3511
-            'normal'
3512
-        );
3513
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3514
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3515
-            add_meta_box(
3516
-                'postexcerpt',
3517
-                esc_html__('Short Biography', 'event_espresso'),
3518
-                'post_excerpt_meta_box',
3519
-                $this->_cpt_routes[ $this->_req_action ],
3520
-                'normal'
3521
-            );
3522
-        }
3523
-        if (post_type_supports('espresso_attendees', 'comments')) {
3524
-            add_meta_box(
3525
-                'commentsdiv',
3526
-                esc_html__('Notes on the Contact', 'event_espresso'),
3527
-                'post_comment_meta_box',
3528
-                $this->_cpt_routes[ $this->_req_action ],
3529
-                'normal',
3530
-                'core'
3531
-            );
3532
-        }
3533
-        add_meta_box(
3534
-            'attendee_contact_info',
3535
-            esc_html__('Contact Info', 'event_espresso'),
3536
-            [$this, 'attendee_contact_info'],
3537
-            $this->_cpt_routes[ $this->_req_action ],
3538
-            'side',
3539
-            'core'
3540
-        );
3541
-        add_meta_box(
3542
-            'attendee_details_address',
3543
-            esc_html__('Address Details', 'event_espresso'),
3544
-            [$this, 'attendee_address_details'],
3545
-            $this->_cpt_routes[ $this->_req_action ],
3546
-            'normal',
3547
-            'core'
3548
-        );
3549
-        add_meta_box(
3550
-            'attendee_registrations',
3551
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3552
-            [$this, 'attendee_registrations_meta_box'],
3553
-            $this->_cpt_routes[ $this->_req_action ],
3554
-            'normal',
3555
-            'high'
3556
-        );
3557
-    }
3558
-
3559
-
3560
-    /**
3561
-     * Metabox for attendee contact info
3562
-     *
3563
-     * @param WP_Post $post wp post object
3564
-     * @return void attendee contact info ( and form )
3565
-     * @throws EE_Error
3566
-     * @throws InvalidArgumentException
3567
-     * @throws InvalidDataTypeException
3568
-     * @throws InvalidInterfaceException
3569
-     * @throws LogicException
3570
-     * @throws DomainException
3571
-     */
3572
-    public function attendee_contact_info($post)
3573
-    {
3574
-        // get attendee object ( should already have it )
3575
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3576
-        $form->enqueueStylesAndScripts();
3577
-        echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3578
-    }
3579
-
3580
-
3581
-    /**
3582
-     * Return form handler for the contact details metabox
3583
-     *
3584
-     * @param EE_Attendee $attendee
3585
-     * @return AttendeeContactDetailsMetaboxFormHandler
3586
-     * @throws DomainException
3587
-     * @throws InvalidArgumentException
3588
-     * @throws InvalidDataTypeException
3589
-     * @throws InvalidInterfaceException
3590
-     */
3591
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3592
-    {
3593
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3594
-    }
3595
-
3596
-
3597
-    /**
3598
-     * Metabox for attendee details
3599
-     *
3600
-     * @param WP_Post $post wp post object
3601
-     * @throws EE_Error
3602
-     * @throws ReflectionException
3603
-     */
3604
-    public function attendee_address_details($post)
3605
-    {
3606
-        // get attendee object (should already have it)
3607
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3608
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3609
-            new EE_Question_Form_Input(
3610
-                EE_Question::new_instance(
3611
-                    [
3612
-                        'QST_ID'           => 0,
3613
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3614
-                        'QST_system'       => 'admin-state',
3615
-                    ]
3616
-                ),
3617
-                EE_Answer::new_instance(
3618
-                    [
3619
-                        'ANS_ID'    => 0,
3620
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3621
-                    ]
3622
-                ),
3623
-                [
3624
-                    'input_id'       => 'STA_ID',
3625
-                    'input_name'     => 'STA_ID',
3626
-                    'input_prefix'   => '',
3627
-                    'append_qstn_id' => false,
3628
-                ]
3629
-            )
3630
-        );
3631
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3632
-            new EE_Question_Form_Input(
3633
-                EE_Question::new_instance(
3634
-                    [
3635
-                        'QST_ID'           => 0,
3636
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3637
-                        'QST_system'       => 'admin-country',
3638
-                    ]
3639
-                ),
3640
-                EE_Answer::new_instance(
3641
-                    [
3642
-                        'ANS_ID'    => 0,
3643
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3644
-                    ]
3645
-                ),
3646
-                [
3647
-                    'input_id'       => 'CNT_ISO',
3648
-                    'input_name'     => 'CNT_ISO',
3649
-                    'input_prefix'   => '',
3650
-                    'append_qstn_id' => false,
3651
-                ]
3652
-            )
3653
-        );
3654
-        $template                             =
3655
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3656
-        EEH_Template::display_template($template, $this->_template_args);
3657
-    }
3658
-
3659
-
3660
-    /**
3661
-     * _attendee_details
3662
-     *
3663
-     * @param $post
3664
-     * @return void
3665
-     * @throws DomainException
3666
-     * @throws EE_Error
3667
-     * @throws InvalidArgumentException
3668
-     * @throws InvalidDataTypeException
3669
-     * @throws InvalidInterfaceException
3670
-     * @throws ReflectionException
3671
-     */
3672
-    public function attendee_registrations_meta_box($post)
3673
-    {
3674
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3675
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3676
-        $template                              =
3677
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3678
-        EEH_Template::display_template($template, $this->_template_args);
3679
-    }
3680
-
3681
-
3682
-    /**
3683
-     * add in the form fields for the attendee edit
3684
-     *
3685
-     * @param WP_Post $post wp post object
3686
-     * @return void echos html for new form.
3687
-     * @throws DomainException
3688
-     */
3689
-    public function after_title_form_fields($post)
3690
-    {
3691
-        if ($post->post_type === 'espresso_attendees') {
3692
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3693
-            $template_args['attendee'] = $this->_cpt_model_obj;
3694
-            EEH_Template::display_template($template, $template_args);
3695
-        }
3696
-    }
3697
-
3698
-
3699
-    /**
3700
-     * _trash_or_restore_attendee
3701
-     *
3702
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3703
-     * @return void
3704
-     * @throws EE_Error
3705
-     * @throws InvalidArgumentException
3706
-     * @throws InvalidDataTypeException
3707
-     * @throws InvalidInterfaceException
3708
-     */
3709
-    protected function _trash_or_restore_attendees($trash = true)
3710
-    {
3711
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3712
-        $status = $trash ? 'trash' : 'publish';
3713
-        // Checkboxes
3714
-        if ($this->request->requestParamIsSet('checkbox')) {
3715
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3716
-            // if array has more than one element than success message should be plural
3717
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3718
-            // cycle thru checkboxes
3719
-            foreach ($ATT_IDs as $ATT_ID) {
3720
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3721
-                if (! $updated) {
3722
-                    $success = 0;
3723
-                }
3724
-            }
3725
-        } else {
3726
-            // grab single id and delete
3727
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3728
-            // update attendee
3729
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3730
-        }
3731
-        $what        = $success > 1
3732
-            ? esc_html__('Contacts', 'event_espresso')
3733
-            : esc_html__('Contact', 'event_espresso');
3734
-        $action_desc = $trash
3735
-            ? esc_html__('moved to the trash', 'event_espresso')
3736
-            : esc_html__('restored', 'event_espresso');
3737
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3738
-    }
2897
+		}
2898
+		$template_args = [
2899
+			'title'                    => '',
2900
+			'content'                  => '',
2901
+			'step_button_text'         => '',
2902
+			'show_notification_toggle' => false,
2903
+		];
2904
+		// to indicate we're processing a new registration
2905
+		$hidden_fields = [
2906
+			'processing_registration' => [
2907
+				'type'  => 'hidden',
2908
+				'value' => 0,
2909
+			],
2910
+			'event_id'                => [
2911
+				'type'  => 'hidden',
2912
+				'value' => $this->_reg_event->ID(),
2913
+			],
2914
+		];
2915
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2916
+		$cart = EE_Registry::instance()->SSN->cart();
2917
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2918
+		switch ($step) {
2919
+			case 'ticket':
2920
+				$hidden_fields['processing_registration']['value'] = 1;
2921
+				$template_args['title']                            = esc_html__(
2922
+					'Step One: Select the Ticket for this registration',
2923
+					'event_espresso'
2924
+				);
2925
+				$template_args['content']                          =
2926
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2927
+				$template_args['content']                          .= '</div>';
2928
+				$template_args['step_button_text']                 = esc_html__(
2929
+					'Add Tickets and Continue to Registrant Details',
2930
+					'event_espresso'
2931
+				);
2932
+				$template_args['show_notification_toggle']         = false;
2933
+				break;
2934
+			case 'questions':
2935
+				$hidden_fields['processing_registration']['value'] = 2;
2936
+				$template_args['title']                            = esc_html__(
2937
+					'Step Two: Add Registrant Details for this Registration',
2938
+					'event_espresso'
2939
+				);
2940
+				// in theory, we should be able to run EED_SPCO at this point
2941
+				// because the cart should have been set up properly by the first process_reg_step run.
2942
+				$template_args['content']                  =
2943
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2944
+				$template_args['step_button_text']         = esc_html__(
2945
+					'Save Registration and Continue to Details',
2946
+					'event_espresso'
2947
+				);
2948
+				$template_args['show_notification_toggle'] = true;
2949
+				break;
2950
+		}
2951
+		// we come back to the process_registration_step route.
2952
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2953
+		return EEH_Template::display_template(
2954
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2955
+			$template_args,
2956
+			true
2957
+		);
2958
+	}
2959
+
2960
+
2961
+	/**
2962
+	 * set_reg_event
2963
+	 *
2964
+	 * @return bool
2965
+	 * @throws EE_Error
2966
+	 * @throws InvalidArgumentException
2967
+	 * @throws InvalidDataTypeException
2968
+	 * @throws InvalidInterfaceException
2969
+	 */
2970
+	private function _set_reg_event()
2971
+	{
2972
+		if (is_object($this->_reg_event)) {
2973
+			return true;
2974
+		}
2975
+
2976
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2977
+		if (! $EVT_ID) {
2978
+			return false;
2979
+		}
2980
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2981
+		return true;
2982
+	}
2983
+
2984
+
2985
+	/**
2986
+	 * process_reg_step
2987
+	 *
2988
+	 * @return void
2989
+	 * @throws DomainException
2990
+	 * @throws EE_Error
2991
+	 * @throws InvalidArgumentException
2992
+	 * @throws InvalidDataTypeException
2993
+	 * @throws InvalidInterfaceException
2994
+	 * @throws ReflectionException
2995
+	 * @throws RuntimeException
2996
+	 */
2997
+	public function process_reg_step()
2998
+	{
2999
+		EE_System::do_not_cache();
3000
+		$this->_set_reg_event();
3001
+		/** @var CurrentPage $current_page */
3002
+		$current_page = $this->loader->getShared(CurrentPage::class);
3003
+		$current_page->setEspressoPage(true);
3004
+		$this->request->setRequestParam('uts', time());
3005
+		// what step are we on?
3006
+		$cart = EE_Registry::instance()->SSN->cart();
3007
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3008
+		// if doing ajax then we need to verify the nonce
3009
+		if ($this->request->isAjax()) {
3010
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
3011
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3012
+		}
3013
+		switch ($step) {
3014
+			case 'ticket':
3015
+				// process ticket selection
3016
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3017
+				if ($success) {
3018
+					EE_Error::add_success(
3019
+						esc_html__(
3020
+							'Tickets Selected. Now complete the registration.',
3021
+							'event_espresso'
3022
+						)
3023
+					);
3024
+				} else {
3025
+					$this->request->setRequestParam('step_error', true);
3026
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3027
+				}
3028
+				if ($this->request->isAjax()) {
3029
+					$this->new_registration(); // display next step
3030
+				} else {
3031
+					$query_args = [
3032
+						'action'                  => 'new_registration',
3033
+						'processing_registration' => 1,
3034
+						'event_id'                => $this->_reg_event->ID(),
3035
+						'uts'                     => time(),
3036
+					];
3037
+					$this->_redirect_after_action(
3038
+						false,
3039
+						'',
3040
+						'',
3041
+						$query_args,
3042
+						true
3043
+					);
3044
+				}
3045
+				break;
3046
+			case 'questions':
3047
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3048
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3049
+				}
3050
+				// process registration
3051
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3052
+				if ($cart instanceof EE_Cart) {
3053
+					$grand_total = $cart->get_grand_total();
3054
+					if ($grand_total instanceof EE_Line_Item) {
3055
+						$grand_total->save_this_and_descendants_to_txn();
3056
+					}
3057
+				}
3058
+				if (! $transaction instanceof EE_Transaction) {
3059
+					$query_args = [
3060
+						'action'                  => 'new_registration',
3061
+						'processing_registration' => 2,
3062
+						'event_id'                => $this->_reg_event->ID(),
3063
+						'uts'                     => time(),
3064
+					];
3065
+					if ($this->request->isAjax()) {
3066
+						// display registration form again because there are errors (maybe validation?)
3067
+						$this->new_registration();
3068
+						return;
3069
+					}
3070
+					$this->_redirect_after_action(
3071
+						false,
3072
+						'',
3073
+						'',
3074
+						$query_args,
3075
+						true
3076
+					);
3077
+					return;
3078
+				}
3079
+				// maybe update status, and make sure to save transaction if not done already
3080
+				if (! $transaction->update_status_based_on_total_paid()) {
3081
+					$transaction->save();
3082
+				}
3083
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3084
+				$query_args = [
3085
+					'action'        => 'redirect_to_txn',
3086
+					'TXN_ID'        => $transaction->ID(),
3087
+					'EVT_ID'        => $this->_reg_event->ID(),
3088
+					'event_name'    => urlencode($this->_reg_event->name()),
3089
+					'redirect_from' => 'new_registration',
3090
+				];
3091
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3092
+				break;
3093
+		}
3094
+		// what are you looking here for?  Should be nothing to do at this point.
3095
+	}
3096
+
3097
+
3098
+	/**
3099
+	 * redirect_to_txn
3100
+	 *
3101
+	 * @return void
3102
+	 * @throws EE_Error
3103
+	 * @throws InvalidArgumentException
3104
+	 * @throws InvalidDataTypeException
3105
+	 * @throws InvalidInterfaceException
3106
+	 * @throws ReflectionException
3107
+	 */
3108
+	public function redirect_to_txn()
3109
+	{
3110
+		EE_System::do_not_cache();
3111
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3112
+		$query_args = [
3113
+			'action' => 'view_transaction',
3114
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3115
+			'page'   => 'espresso_transactions',
3116
+		];
3117
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3118
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3119
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3120
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3121
+		}
3122
+		EE_Error::add_success(
3123
+			esc_html__(
3124
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3125
+				'event_espresso'
3126
+			)
3127
+		);
3128
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3129
+	}
3130
+
3131
+
3132
+	/**
3133
+	 * generates HTML for the Attendee Contact List
3134
+	 *
3135
+	 * @return void
3136
+	 * @throws DomainException
3137
+	 * @throws EE_Error
3138
+	 */
3139
+	protected function _attendee_contact_list_table()
3140
+	{
3141
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3142
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3143
+		$this->display_admin_list_table_page_with_no_sidebar();
3144
+	}
3145
+
3146
+
3147
+	/**
3148
+	 * get_attendees
3149
+	 *
3150
+	 * @param      $per_page
3151
+	 * @param bool $count whether to return count or data.
3152
+	 * @param bool $trash
3153
+	 * @return array|int
3154
+	 * @throws EE_Error
3155
+	 * @throws InvalidArgumentException
3156
+	 * @throws InvalidDataTypeException
3157
+	 * @throws InvalidInterfaceException
3158
+	 */
3159
+	public function get_attendees($per_page, $count = false, $trash = false)
3160
+	{
3161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3162
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3163
+		$orderby = $this->request->getRequestParam('orderby');
3164
+		switch ($orderby) {
3165
+			case 'ATT_ID':
3166
+			case 'ATT_fname':
3167
+			case 'ATT_email':
3168
+			case 'ATT_city':
3169
+			case 'STA_ID':
3170
+			case 'CNT_ID':
3171
+				break;
3172
+			case 'Registration_Count':
3173
+				$orderby = 'Registration_Count';
3174
+				break;
3175
+			default:
3176
+				$orderby = 'ATT_lname';
3177
+		}
3178
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3179
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3180
+		$per_page     = absint($per_page) ? $per_page : 10;
3181
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3182
+		$_where       = [];
3183
+		$search_term  = $this->request->getRequestParam('s');
3184
+		if ($search_term) {
3185
+			$search_term  = '%' . $search_term . '%';
3186
+			$_where['OR'] = [
3187
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3188
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3189
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3190
+				'ATT_fname'                         => ['LIKE', $search_term],
3191
+				'ATT_lname'                         => ['LIKE', $search_term],
3192
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3193
+				'ATT_email'                         => ['LIKE', $search_term],
3194
+				'ATT_address'                       => ['LIKE', $search_term],
3195
+				'ATT_address2'                      => ['LIKE', $search_term],
3196
+				'ATT_city'                          => ['LIKE', $search_term],
3197
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3198
+				'State.STA_name'                    => ['LIKE', $search_term],
3199
+				'ATT_phone'                         => ['LIKE', $search_term],
3200
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3201
+				'Registration.REG_code'             => ['LIKE', $search_term],
3202
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3203
+			];
3204
+		}
3205
+		$offset     = ($current_page - 1) * $per_page;
3206
+		$limit      = $count ? null : [$offset, $per_page];
3207
+		$query_args = [
3208
+			$_where,
3209
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3210
+			'limit'         => $limit,
3211
+		];
3212
+		if (! $count) {
3213
+			$query_args['order_by'] = [$orderby => $sort];
3214
+		}
3215
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3216
+		return $count
3217
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3218
+			: $this->getAttendeeModel()->get_all($query_args);
3219
+	}
3220
+
3221
+
3222
+	/**
3223
+	 * This is just taking care of resending the registration confirmation
3224
+	 *
3225
+	 * @return void
3226
+	 * @throws EE_Error
3227
+	 * @throws InvalidArgumentException
3228
+	 * @throws InvalidDataTypeException
3229
+	 * @throws InvalidInterfaceException
3230
+	 * @throws ReflectionException
3231
+	 */
3232
+	protected function _resend_registration()
3233
+	{
3234
+		$this->_process_resend_registration();
3235
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3236
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3237
+		$query_args  = $redirect_to
3238
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3239
+			: ['action' => 'default'];
3240
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3241
+	}
3242
+
3243
+
3244
+	/**
3245
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3246
+	 * to use when selecting registrations
3247
+	 *
3248
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3249
+	 *                                                     the query parameters from the request
3250
+	 * @return void ends the request with a redirect or download
3251
+	 */
3252
+	public function _registrations_report_base($method_name_for_getting_query_params)
3253
+	{
3254
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3255
+			? $this->request->getRequestParam('EVT_ID', 0, 'int')
3256
+			: null;
3257
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3258
+			$filters = $this->request->getRequestParam('filters', [], DataType::STRING, true);
3259
+			$report_params  = $this->$method_name_for_getting_query_params($filters);
3260
+			wp_redirect(
3261
+				EE_Admin_Page::add_query_args_and_nonce(
3262
+					[
3263
+						'page'        => 'espresso_batch',
3264
+						'batch'       => 'file',
3265
+						'EVT_ID'      => $EVT_ID,
3266
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3267
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', DataType::URL)),
3268
+						'filters'     => urlencode(serialize($report_params)),
3269
+						'use_filters' => $this->request->getRequestParam('use_filters', false, DataType::BOOL)
3270
+					]
3271
+				)
3272
+			);
3273
+		} else {
3274
+			// Pull the current request params
3275
+			$request_args = $this->request->requestParams();
3276
+			// Set the required request_args to be passed to the export
3277
+			$required_request_args = [
3278
+				'export' => 'report',
3279
+				'action' => 'registrations_report_for_event',
3280
+				'EVT_ID' => $EVT_ID,
3281
+			];
3282
+			// Merge required request args, overriding any currently set
3283
+			$request_args = array_merge($request_args, $required_request_args);
3284
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3285
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3286
+				$EE_Export = EE_Export::instance($request_args);
3287
+				$EE_Export->export();
3288
+			}
3289
+		}
3290
+	}
3291
+
3292
+
3293
+	/**
3294
+	 * Creates a registration report using only query parameters in the request
3295
+	 *
3296
+	 * @return void
3297
+	 */
3298
+	public function _registrations_report()
3299
+	{
3300
+		$this->_registrations_report_base('_get_registration_query_parameters');
3301
+	}
3302
+
3303
+
3304
+	public function _contact_list_export()
3305
+	{
3306
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3307
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3308
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3309
+			$EE_Export->export_attendees();
3310
+		}
3311
+	}
3312
+
3313
+
3314
+	public function _contact_list_report()
3315
+	{
3316
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3317
+			wp_redirect(
3318
+				EE_Admin_Page::add_query_args_and_nonce(
3319
+					[
3320
+						'page'        => 'espresso_batch',
3321
+						'batch'       => 'file',
3322
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3323
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3324
+					]
3325
+				)
3326
+			);
3327
+		} else {
3328
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3329
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3330
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3331
+				$EE_Export->report_attendees();
3332
+			}
3333
+		}
3334
+	}
3335
+
3336
+
3337
+
3338
+
3339
+
3340
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3341
+	/**
3342
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3343
+	 *
3344
+	 * @return void
3345
+	 * @throws EE_Error
3346
+	 * @throws InvalidArgumentException
3347
+	 * @throws InvalidDataTypeException
3348
+	 * @throws InvalidInterfaceException
3349
+	 * @throws ReflectionException
3350
+	 */
3351
+	protected function _duplicate_attendee()
3352
+	{
3353
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3354
+		$action = $this->request->getRequestParam('return', 'default');
3355
+		// verify we have necessary info
3356
+		if (! $REG_ID) {
3357
+			EE_Error::add_error(
3358
+				esc_html__(
3359
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3360
+					'event_espresso'
3361
+				),
3362
+				__FILE__,
3363
+				__LINE__,
3364
+				__FUNCTION__
3365
+			);
3366
+			$query_args = ['action' => $action];
3367
+			$this->_redirect_after_action('', '', '', $query_args, true);
3368
+		}
3369
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3370
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3371
+		if (! $registration instanceof EE_Registration) {
3372
+			throw new RuntimeException(
3373
+				sprintf(
3374
+					esc_html__(
3375
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3376
+						'event_espresso'
3377
+					),
3378
+					$REG_ID
3379
+				)
3380
+			);
3381
+		}
3382
+		$attendee = $registration->attendee();
3383
+		// remove relation of existing attendee on registration
3384
+		$registration->_remove_relation_to($attendee, 'Attendee');
3385
+		// new attendee
3386
+		$new_attendee = clone $attendee;
3387
+		$new_attendee->set('ATT_ID', 0);
3388
+		$new_attendee->save();
3389
+		// add new attendee to reg
3390
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3391
+		EE_Error::add_success(
3392
+			esc_html__(
3393
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3394
+				'event_espresso'
3395
+			)
3396
+		);
3397
+		// redirect to edit page for attendee
3398
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3399
+		$this->_redirect_after_action('', '', '', $query_args, true);
3400
+	}
3401
+
3402
+
3403
+	/**
3404
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3405
+	 *
3406
+	 * @param int     $post_id
3407
+	 * @param WP_Post $post
3408
+	 * @throws DomainException
3409
+	 * @throws EE_Error
3410
+	 * @throws InvalidArgumentException
3411
+	 * @throws InvalidDataTypeException
3412
+	 * @throws InvalidInterfaceException
3413
+	 * @throws LogicException
3414
+	 * @throws InvalidFormSubmissionException
3415
+	 * @throws ReflectionException
3416
+	 */
3417
+	protected function _insert_update_cpt_item($post_id, $post)
3418
+	{
3419
+		$success  = true;
3420
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3421
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3422
+			: null;
3423
+		// for attendee updates
3424
+		if ($attendee instanceof EE_Attendee) {
3425
+			// note we should only be UPDATING attendees at this point.
3426
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3427
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3428
+			$updated_fields = [
3429
+				'ATT_fname'     => $fname,
3430
+				'ATT_lname'     => $lname,
3431
+				'ATT_full_name' => "{$fname} {$lname}",
3432
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3433
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3434
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3435
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3436
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3437
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3438
+			];
3439
+			foreach ($updated_fields as $field => $value) {
3440
+				$attendee->set($field, $value);
3441
+			}
3442
+
3443
+			// process contact details metabox form handler (which will also save the attendee)
3444
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3445
+			$success              = $contact_details_form->process($this->request->requestParams());
3446
+
3447
+			$attendee_update_callbacks = apply_filters(
3448
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3449
+				[]
3450
+			);
3451
+			foreach ($attendee_update_callbacks as $a_callback) {
3452
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3453
+					throw new EE_Error(
3454
+						sprintf(
3455
+							esc_html__(
3456
+								'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.',
3457
+								'event_espresso'
3458
+							),
3459
+							$a_callback
3460
+						)
3461
+					);
3462
+				}
3463
+			}
3464
+		}
3465
+
3466
+		if ($success === false) {
3467
+			EE_Error::add_error(
3468
+				esc_html__(
3469
+					'Something went wrong with updating the meta table data for the registration.',
3470
+					'event_espresso'
3471
+				),
3472
+				__FILE__,
3473
+				__FUNCTION__,
3474
+				__LINE__
3475
+			);
3476
+		}
3477
+	}
3478
+
3479
+
3480
+	public function trash_cpt_item($post_id)
3481
+	{
3482
+	}
3483
+
3484
+
3485
+	public function delete_cpt_item($post_id)
3486
+	{
3487
+	}
3488
+
3489
+
3490
+	public function restore_cpt_item($post_id)
3491
+	{
3492
+	}
3493
+
3494
+
3495
+	protected function _restore_cpt_item($post_id, $revision_id)
3496
+	{
3497
+	}
3498
+
3499
+
3500
+	/**
3501
+	 * @throws EE_Error
3502
+	 * @throws ReflectionException
3503
+	 * @since 4.10.2.p
3504
+	 */
3505
+	public function attendee_editor_metaboxes()
3506
+	{
3507
+		$this->verify_cpt_object();
3508
+		remove_meta_box(
3509
+			'postexcerpt',
3510
+			$this->_cpt_routes[ $this->_req_action ],
3511
+			'normal'
3512
+		);
3513
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3514
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3515
+			add_meta_box(
3516
+				'postexcerpt',
3517
+				esc_html__('Short Biography', 'event_espresso'),
3518
+				'post_excerpt_meta_box',
3519
+				$this->_cpt_routes[ $this->_req_action ],
3520
+				'normal'
3521
+			);
3522
+		}
3523
+		if (post_type_supports('espresso_attendees', 'comments')) {
3524
+			add_meta_box(
3525
+				'commentsdiv',
3526
+				esc_html__('Notes on the Contact', 'event_espresso'),
3527
+				'post_comment_meta_box',
3528
+				$this->_cpt_routes[ $this->_req_action ],
3529
+				'normal',
3530
+				'core'
3531
+			);
3532
+		}
3533
+		add_meta_box(
3534
+			'attendee_contact_info',
3535
+			esc_html__('Contact Info', 'event_espresso'),
3536
+			[$this, 'attendee_contact_info'],
3537
+			$this->_cpt_routes[ $this->_req_action ],
3538
+			'side',
3539
+			'core'
3540
+		);
3541
+		add_meta_box(
3542
+			'attendee_details_address',
3543
+			esc_html__('Address Details', 'event_espresso'),
3544
+			[$this, 'attendee_address_details'],
3545
+			$this->_cpt_routes[ $this->_req_action ],
3546
+			'normal',
3547
+			'core'
3548
+		);
3549
+		add_meta_box(
3550
+			'attendee_registrations',
3551
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3552
+			[$this, 'attendee_registrations_meta_box'],
3553
+			$this->_cpt_routes[ $this->_req_action ],
3554
+			'normal',
3555
+			'high'
3556
+		);
3557
+	}
3558
+
3559
+
3560
+	/**
3561
+	 * Metabox for attendee contact info
3562
+	 *
3563
+	 * @param WP_Post $post wp post object
3564
+	 * @return void attendee contact info ( and form )
3565
+	 * @throws EE_Error
3566
+	 * @throws InvalidArgumentException
3567
+	 * @throws InvalidDataTypeException
3568
+	 * @throws InvalidInterfaceException
3569
+	 * @throws LogicException
3570
+	 * @throws DomainException
3571
+	 */
3572
+	public function attendee_contact_info($post)
3573
+	{
3574
+		// get attendee object ( should already have it )
3575
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3576
+		$form->enqueueStylesAndScripts();
3577
+		echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3578
+	}
3579
+
3580
+
3581
+	/**
3582
+	 * Return form handler for the contact details metabox
3583
+	 *
3584
+	 * @param EE_Attendee $attendee
3585
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3586
+	 * @throws DomainException
3587
+	 * @throws InvalidArgumentException
3588
+	 * @throws InvalidDataTypeException
3589
+	 * @throws InvalidInterfaceException
3590
+	 */
3591
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3592
+	{
3593
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3594
+	}
3595
+
3596
+
3597
+	/**
3598
+	 * Metabox for attendee details
3599
+	 *
3600
+	 * @param WP_Post $post wp post object
3601
+	 * @throws EE_Error
3602
+	 * @throws ReflectionException
3603
+	 */
3604
+	public function attendee_address_details($post)
3605
+	{
3606
+		// get attendee object (should already have it)
3607
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3608
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3609
+			new EE_Question_Form_Input(
3610
+				EE_Question::new_instance(
3611
+					[
3612
+						'QST_ID'           => 0,
3613
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3614
+						'QST_system'       => 'admin-state',
3615
+					]
3616
+				),
3617
+				EE_Answer::new_instance(
3618
+					[
3619
+						'ANS_ID'    => 0,
3620
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3621
+					]
3622
+				),
3623
+				[
3624
+					'input_id'       => 'STA_ID',
3625
+					'input_name'     => 'STA_ID',
3626
+					'input_prefix'   => '',
3627
+					'append_qstn_id' => false,
3628
+				]
3629
+			)
3630
+		);
3631
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3632
+			new EE_Question_Form_Input(
3633
+				EE_Question::new_instance(
3634
+					[
3635
+						'QST_ID'           => 0,
3636
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3637
+						'QST_system'       => 'admin-country',
3638
+					]
3639
+				),
3640
+				EE_Answer::new_instance(
3641
+					[
3642
+						'ANS_ID'    => 0,
3643
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3644
+					]
3645
+				),
3646
+				[
3647
+					'input_id'       => 'CNT_ISO',
3648
+					'input_name'     => 'CNT_ISO',
3649
+					'input_prefix'   => '',
3650
+					'append_qstn_id' => false,
3651
+				]
3652
+			)
3653
+		);
3654
+		$template                             =
3655
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3656
+		EEH_Template::display_template($template, $this->_template_args);
3657
+	}
3658
+
3659
+
3660
+	/**
3661
+	 * _attendee_details
3662
+	 *
3663
+	 * @param $post
3664
+	 * @return void
3665
+	 * @throws DomainException
3666
+	 * @throws EE_Error
3667
+	 * @throws InvalidArgumentException
3668
+	 * @throws InvalidDataTypeException
3669
+	 * @throws InvalidInterfaceException
3670
+	 * @throws ReflectionException
3671
+	 */
3672
+	public function attendee_registrations_meta_box($post)
3673
+	{
3674
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3675
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3676
+		$template                              =
3677
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3678
+		EEH_Template::display_template($template, $this->_template_args);
3679
+	}
3680
+
3681
+
3682
+	/**
3683
+	 * add in the form fields for the attendee edit
3684
+	 *
3685
+	 * @param WP_Post $post wp post object
3686
+	 * @return void echos html for new form.
3687
+	 * @throws DomainException
3688
+	 */
3689
+	public function after_title_form_fields($post)
3690
+	{
3691
+		if ($post->post_type === 'espresso_attendees') {
3692
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3693
+			$template_args['attendee'] = $this->_cpt_model_obj;
3694
+			EEH_Template::display_template($template, $template_args);
3695
+		}
3696
+	}
3697
+
3698
+
3699
+	/**
3700
+	 * _trash_or_restore_attendee
3701
+	 *
3702
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3703
+	 * @return void
3704
+	 * @throws EE_Error
3705
+	 * @throws InvalidArgumentException
3706
+	 * @throws InvalidDataTypeException
3707
+	 * @throws InvalidInterfaceException
3708
+	 */
3709
+	protected function _trash_or_restore_attendees($trash = true)
3710
+	{
3711
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3712
+		$status = $trash ? 'trash' : 'publish';
3713
+		// Checkboxes
3714
+		if ($this->request->requestParamIsSet('checkbox')) {
3715
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3716
+			// if array has more than one element than success message should be plural
3717
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3718
+			// cycle thru checkboxes
3719
+			foreach ($ATT_IDs as $ATT_ID) {
3720
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3721
+				if (! $updated) {
3722
+					$success = 0;
3723
+				}
3724
+			}
3725
+		} else {
3726
+			// grab single id and delete
3727
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3728
+			// update attendee
3729
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3730
+		}
3731
+		$what        = $success > 1
3732
+			? esc_html__('Contacts', 'event_espresso')
3733
+			: esc_html__('Contact', 'event_espresso');
3734
+		$action_desc = $trash
3735
+			? esc_html__('moved to the trash', 'event_espresso')
3736
+			: esc_html__('restored', 'event_espresso');
3737
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3738
+	}
3739 3739
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +4640 added lines, -4640 removed lines patch added patch discarded remove patch
@@ -17,2682 +17,2682 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Messages_Admin_Page extends EE_Admin_Page
19 19
 {
20
-    /**
21
-     * @var EEM_Message
22
-     */
23
-    private $MSG_MODEL;
24
-
25
-    /**
26
-     * @var EEM_Message_Template
27
-     */
28
-    private $MTP_MODEL;
29
-
30
-    /**
31
-     * @var EEM_Message_Template_Group
32
-     */
33
-    private $MTG_MODEL;
34
-
35
-    /**
36
-     * @var EE_Message_Resource_Manager $_message_resource_manager
37
-     */
38
-    protected $_message_resource_manager;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $_active_message_type_name = '';
44
-
45
-    /**
46
-     * @var string
47
-     */
48
-    protected $_active_messenger_name = '';
49
-
50
-    /**
51
-     * @var EE_messenger $_active_messenger
52
-     */
53
-    protected $_active_messenger;
54
-
55
-    protected $_activate_meta_box_type;
56
-
57
-    protected $_current_message_meta_box;
58
-
59
-    protected $_current_message_meta_box_object;
60
-
61
-    protected $_context_switcher;
62
-
63
-    protected $_shortcodes           = [];
64
-
65
-    protected $_active_messengers    = [];
66
-
67
-    protected $_active_message_types = [];
68
-
69
-    /**
70
-     * @var EE_Message_Template_Group $_message_template_group
71
-     */
72
-    protected $_message_template_group;
73
-
74
-    protected $_m_mt_settings = [];
75
-
76
-
77
-    /**
78
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
-     * IF there is no group then it gets automatically set to the Default template pack.
80
-     *
81
-     * @since 4.5.0
82
-     *
83
-     * @var EE_Messages_Template_Pack
84
-     */
85
-    protected $_template_pack;
86
-
87
-
88
-    /**
89
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
-     * group is.  If there is no group then it automatically gets set to default.
91
-     *
92
-     * @since 4.5.0
93
-     *
94
-     * @var string
95
-     */
96
-    protected $_variation;
97
-
98
-
99
-    /**
100
-     * @param bool $routing
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    public function __construct($routing = true)
105
-    {
106
-        // make sure messages autoloader is running
107
-        EED_Messages::set_autoloaders();
108
-        parent::__construct($routing);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Message
114
-     * @throws EE_Error
115
-     */
116
-    public function getMsgModel()
117
-    {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
119
-            $this->MSG_MODEL = EEM_Message::instance();
120
-        }
121
-        return $this->MSG_MODEL;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return EEM_Message_Template
127
-     * @throws EE_Error
128
-     */
129
-    public function getMtpModel()
130
-    {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
-            $this->MTP_MODEL = EEM_Message_Template::instance();
133
-        }
134
-        return $this->MTP_MODEL;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return EEM_Message_Template_Group
140
-     * @throws EE_Error
141
-     */
142
-    public function getMtgModel()
143
-    {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
-        }
147
-        return $this->MTG_MODEL;
148
-    }
149
-
150
-
151
-    /**
152
-     * @throws EE_Error
153
-     * @throws ReflectionException
154
-     */
155
-    protected function _init_page_props()
156
-    {
157
-        $this->page_slug        = EE_MSG_PG_SLUG;
158
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
-        $this->_admin_base_path = EE_MSG_ADMIN;
161
-
162
-        $messenger    = $this->request->getRequestParam('messenger', '');
163
-        $message_type = $this->request->getRequestParam('message_type', '');
164
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
-
167
-        $this->_load_message_resource_manager();
168
-    }
169
-
170
-
171
-    /**
172
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
-     *
174
-     * @throws EE_Error
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     * @throws InvalidArgumentException
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _load_message_resource_manager()
181
-    {
182
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
-    }
184
-
185
-
186
-    /**
187
-     * @return array
188
-     * @throws EE_Error
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     * @deprecated 4.9.9.rc.014
193
-     */
194
-    public function get_messengers_for_list_table()
195
-    {
196
-        EE_Error::doing_it_wrong(
197
-            __METHOD__,
198
-            sprintf(
199
-                esc_html__(
200
-                    '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',
201
-                    'event_espresso'
202
-                ),
203
-                'Messages_Admin_Page::get_messengers_select_input()'
204
-            ),
205
-            '4.9.9.rc.014'
206
-        );
207
-
208
-        $m_values          = [];
209
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
-        // setup messengers for selects
211
-        $i = 1;
212
-        foreach ($active_messengers as $active_messenger) {
213
-            if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
-                $i++;
217
-            }
218
-        }
219
-
220
-        return $m_values;
221
-    }
222
-
223
-
224
-    /**
225
-     * @return array
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @deprecated 4.9.9.rc.014
231
-     */
232
-    public function get_message_types_for_list_table()
233
-    {
234
-        EE_Error::doing_it_wrong(
235
-            __METHOD__,
236
-            sprintf(
237
-                esc_html__(
238
-                    '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',
239
-                    'event_espresso'
240
-                ),
241
-                'Messages_Admin_Page::get_message_types_select_input()'
242
-            ),
243
-            '4.9.9.rc.014'
244
-        );
245
-
246
-        $mt_values       = [];
247
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
-        $i               = 1;
249
-        foreach ($active_messages as $active_message) {
250
-            if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
-                $i++;
254
-            }
255
-        }
256
-
257
-        return $mt_values;
258
-    }
259
-
260
-
261
-    /**
262
-     * @return array
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @deprecated 4.9.9.rc.014
268
-     */
269
-    public function get_contexts_for_message_types_for_list_table()
270
-    {
271
-        EE_Error::doing_it_wrong(
272
-            __METHOD__,
273
-            sprintf(
274
-                esc_html__(
275
-                    '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',
276
-                    'event_espresso'
277
-                ),
278
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
-            ),
280
-            '4.9.9.rc.014'
281
-        );
282
-
283
-        $contexts                = [];
284
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
-        foreach ($active_message_contexts as $active_message) {
286
-            if ($active_message instanceof EE_Message) {
287
-                $message_type = $active_message->message_type_object();
288
-                if ($message_type instanceof EE_message_type) {
289
-                    $message_type_contexts = $message_type->get_contexts();
290
-                    foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
292
-                    }
293
-                }
294
-            }
295
-        }
296
-
297
-        return $contexts;
298
-    }
299
-
300
-
301
-    /**
302
-     * Generate select input with provided messenger options array.
303
-     *
304
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
-     *                                 labels.
306
-     * @return string
307
-     * @throws EE_Error
308
-     */
309
-    public function get_messengers_select_input($messenger_options)
310
-    {
311
-        // if empty or just one value then just return an empty string
312
-        if (
313
-            empty($messenger_options)
314
-            || ! is_array($messenger_options)
315
-            || count($messenger_options) === 1
316
-        ) {
317
-            return '';
318
-        }
319
-        // merge in default
320
-        $messenger_options = array_merge(
321
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
-            $messenger_options
323
-        );
324
-        $input             = new EE_Select_Input(
325
-            $messenger_options,
326
-            [
327
-                'html_name'  => 'ee_messenger_filter_by',
328
-                'html_id'    => 'ee_messenger_filter_by',
329
-                'html_class' => 'wide',
330
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
-            ]
332
-        );
333
-
334
-        return $input->get_html_for_input();
335
-    }
336
-
337
-
338
-    /**
339
-     * Generate select input with provided message type options array.
340
-     *
341
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
-     *                                    message type labels
343
-     * @return string
344
-     * @throws EE_Error
345
-     */
346
-    public function get_message_types_select_input($message_type_options)
347
-    {
348
-        // if empty or count of options is 1 then just return an empty string
349
-        if (
350
-            empty($message_type_options)
351
-            || ! is_array($message_type_options)
352
-            || count($message_type_options) === 1
353
-        ) {
354
-            return '';
355
-        }
356
-        // merge in default
357
-        $message_type_options = array_merge(
358
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
-            $message_type_options
360
-        );
361
-        $input                = new EE_Select_Input(
362
-            $message_type_options,
363
-            [
364
-                'html_name'  => 'ee_message_type_filter_by',
365
-                'html_id'    => 'ee_message_type_filter_by',
366
-                'html_class' => 'wide',
367
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
-            ]
369
-        );
370
-
371
-        return $input->get_html_for_input();
372
-    }
373
-
374
-
375
-    /**
376
-     * Generate select input with provide message type contexts array.
377
-     *
378
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
-     *                               context label.
380
-     * @return string
381
-     * @throws EE_Error
382
-     */
383
-    public function get_contexts_for_message_types_select_input($context_options)
384
-    {
385
-        // if empty or count of options is one then just return empty string
386
-        if (
387
-            empty($context_options)
388
-            || ! is_array($context_options)
389
-            || count($context_options) === 1
390
-        ) {
391
-            return '';
392
-        }
393
-        // merge in default
394
-        $context_options = array_merge(
395
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
-            $context_options
397
-        );
398
-        $input           = new EE_Select_Input(
399
-            $context_options,
400
-            [
401
-                'html_name'  => 'ee_context_filter_by',
402
-                'html_id'    => 'ee_context_filter_by',
403
-                'html_class' => 'wide',
404
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
-            ]
406
-        );
407
-
408
-        return $input->get_html_for_input();
409
-    }
410
-
411
-
412
-    protected function _ajax_hooks()
413
-    {
414
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
-    }
421
-
422
-
423
-    protected function _define_page_props()
424
-    {
425
-        $this->_admin_page_title = $this->page_label;
426
-        $this->_labels           = [
427
-            'buttons'    => [
428
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
-            ],
432
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
-        ];
434
-    }
435
-
436
-
437
-    /**
438
-     *        an array for storing key => value pairs of request actions and their corresponding methods
439
-     *
440
-     * @access protected
441
-     * @return void
442
-     */
443
-    protected function _set_page_routes()
444
-    {
445
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
-
449
-        $this->_page_routes = [
450
-            'default'                          => [
451
-                'func'       => '_message_queue_list_table',
452
-                'capability' => 'ee_read_global_messages',
453
-            ],
454
-            'global_mtps'                      => [
455
-                'func'       => '_ee_default_messages_overview_list_table',
456
-                'capability' => 'ee_read_global_messages',
457
-            ],
458
-            'custom_mtps'                      => [
459
-                'func'       => '_custom_mtps_preview',
460
-                'capability' => 'ee_read_messages',
461
-            ],
462
-            'add_new_message_template'         => [
463
-                'func'       => 'add_message_template',
464
-                'capability' => 'ee_edit_messages',
465
-                'noheader'   => true,
466
-            ],
467
-            'edit_message_template'            => [
468
-                'func'       => '_edit_message_template',
469
-                'capability' => 'ee_edit_message',
470
-                'obj_id'     => $GRP_ID,
471
-            ],
472
-            'preview_message'                  => [
473
-                'func'               => '_preview_message',
474
-                'capability'         => 'ee_read_message',
475
-                'obj_id'             => $GRP_ID,
476
-                'noheader'           => true,
477
-                'headers_sent_route' => 'display_preview_message',
478
-            ],
479
-            'display_preview_message'          => [
480
-                'func'       => '_display_preview_message',
481
-                'capability' => 'ee_read_message',
482
-                'obj_id'     => $GRP_ID,
483
-            ],
484
-            'insert_message_template'          => [
485
-                'func'       => '_insert_or_update_message_template',
486
-                'capability' => 'ee_edit_messages',
487
-                'args'       => ['new' => true],
488
-                'noheader'   => true,
489
-            ],
490
-            'update_message_template'          => [
491
-                'func'       => '_insert_or_update_message_template',
492
-                'capability' => 'ee_edit_message',
493
-                'obj_id'     => $GRP_ID,
494
-                'args'       => ['new' => false],
495
-                'noheader'   => true,
496
-            ],
497
-            'trash_message_template'           => [
498
-                'func'       => '_trash_or_restore_message_template',
499
-                'capability' => 'ee_delete_message',
500
-                'obj_id'     => $GRP_ID,
501
-                'args'       => ['trash' => true, 'all' => true],
502
-                'noheader'   => true,
503
-            ],
504
-            'trash_message_template_context'   => [
505
-                'func'       => '_trash_or_restore_message_template',
506
-                'capability' => 'ee_delete_message',
507
-                'obj_id'     => $GRP_ID,
508
-                'args'       => ['trash' => true],
509
-                'noheader'   => true,
510
-            ],
511
-            'restore_message_template'         => [
512
-                'func'       => '_trash_or_restore_message_template',
513
-                'capability' => 'ee_delete_message',
514
-                'obj_id'     => $GRP_ID,
515
-                'args'       => ['trash' => false, 'all' => true],
516
-                'noheader'   => true,
517
-            ],
518
-            'restore_message_template_context' => [
519
-                'func'       => '_trash_or_restore_message_template',
520
-                'capability' => 'ee_delete_message',
521
-                'obj_id'     => $GRP_ID,
522
-                'args'       => ['trash' => false],
523
-                'noheader'   => true,
524
-            ],
525
-            'delete_message_template'          => [
526
-                'func'       => '_delete_message_template',
527
-                'capability' => 'ee_delete_message',
528
-                'obj_id'     => $GRP_ID,
529
-                'noheader'   => true,
530
-            ],
531
-            'reset_to_default'                 => [
532
-                'func'       => '_reset_to_default_template',
533
-                'capability' => 'ee_edit_message',
534
-                'obj_id'     => $GRP_ID,
535
-                'noheader'   => true,
536
-            ],
537
-            'settings'                         => [
538
-                'func'       => '_settings',
539
-                'capability' => 'manage_options',
540
-            ],
541
-            'update_global_settings'           => [
542
-                'func'       => '_update_global_settings',
543
-                'capability' => 'manage_options',
544
-                'noheader'   => true,
545
-            ],
546
-            'generate_now'                     => [
547
-                'func'       => '_generate_now',
548
-                'capability' => 'ee_send_message',
549
-                'noheader'   => true,
550
-            ],
551
-            'generate_and_send_now'            => [
552
-                'func'       => '_generate_and_send_now',
553
-                'capability' => 'ee_send_message',
554
-                'noheader'   => true,
555
-            ],
556
-            'queue_for_resending'              => [
557
-                'func'       => '_queue_for_resending',
558
-                'capability' => 'ee_send_message',
559
-                'noheader'   => true,
560
-            ],
561
-            'send_now'                         => [
562
-                'func'       => '_send_now',
563
-                'capability' => 'ee_send_message',
564
-                'noheader'   => true,
565
-            ],
566
-            'delete_ee_message'                => [
567
-                'func'       => '_delete_ee_messages',
568
-                'capability' => 'ee_delete_messages',
569
-                'noheader'   => true,
570
-            ],
571
-            'delete_ee_messages'               => [
572
-                'func'       => '_delete_ee_messages',
573
-                'capability' => 'ee_delete_messages',
574
-                'noheader'   => true,
575
-                'obj_id'     => $MSG_ID,
576
-            ],
577
-        ];
578
-    }
579
-
580
-
581
-    protected function _set_page_config()
582
-    {
583
-        $this->_page_config = [
584
-            'default'                  => [
585
-                'nav'           => [
586
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
587
-                    'order' => 10,
588
-                ],
589
-                'list_table'    => 'EE_Message_List_Table',
590
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
-                'require_nonce' => false,
592
-            ],
593
-            'global_mtps'              => [
594
-                'nav'           => [
595
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
-                    'order' => 20,
597
-                ],
598
-                'list_table'    => 'Messages_Template_List_Table',
599
-                'help_tabs'     => [
600
-                    'messages_overview_help_tab'                                => [
601
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
-                        'filename' => 'messages_overview',
603
-                    ],
604
-                    'messages_overview_messages_table_column_headings_help_tab' => [
605
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
-                        'filename' => 'messages_overview_table_column_headings',
607
-                    ],
608
-                    'messages_overview_messages_filters_help_tab'               => [
609
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
610
-                        'filename' => 'messages_overview_filters',
611
-                    ],
612
-                    'messages_overview_messages_views_help_tab'                 => [
613
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
614
-                        'filename' => 'messages_overview_views',
615
-                    ],
616
-                    'message_overview_message_types_help_tab'                   => [
617
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
618
-                        'filename' => 'messages_overview_types',
619
-                    ],
620
-                    'messages_overview_messengers_help_tab'                     => [
621
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
622
-                        'filename' => 'messages_overview_messengers',
623
-                    ],
624
-                ],
625
-                'require_nonce' => false,
626
-            ],
627
-            'custom_mtps'              => [
628
-                'nav'           => [
629
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
-                    'order' => 30,
631
-                ],
632
-                'help_tabs'     => [],
633
-                'require_nonce' => false,
634
-            ],
635
-            'add_new_message_template' => [
636
-                'nav'           => [
637
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
-                    'order'      => 5,
639
-                    'persistent' => false,
640
-                ],
641
-                'require_nonce' => false,
642
-            ],
643
-            'edit_message_template'    => [
644
-                'labels'        => [
645
-                    'buttons'    => [
646
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
-                    ],
648
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
-                ],
650
-                'nav'           => [
651
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
-                    'order'      => 5,
653
-                    'persistent' => false,
654
-                    'url'        => '',
655
-                ],
656
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
-                'has_metaboxes' => true,
658
-                'help_tabs'     => [
659
-                    'edit_message_template'            => [
660
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
-                        'callback' => 'edit_message_template_help_tab',
662
-                    ],
663
-                    'message_templates_help_tab'       => [
664
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
665
-                        'filename' => 'messages_templates',
666
-                    ],
667
-                    'message_template_shortcodes'      => [
668
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
-                        'callback' => 'message_template_shortcodes_help_tab',
670
-                    ],
671
-                    'message_preview_help_tab'         => [
672
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
673
-                        'filename' => 'messages_preview',
674
-                    ],
675
-                    'messages_overview_other_help_tab' => [
676
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
677
-                        'filename' => 'messages_overview_other',
678
-                    ],
679
-                ],
680
-                'require_nonce' => false,
681
-            ],
682
-            'display_preview_message'  => [
683
-                'nav'           => [
684
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
685
-                    'order'      => 5,
686
-                    'url'        => '',
687
-                    'persistent' => false,
688
-                ],
689
-                'help_tabs'     => [
690
-                    'preview_message' => [
691
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
692
-                        'callback' => 'preview_message_help_tab',
693
-                    ],
694
-                ],
695
-                'require_nonce' => false,
696
-            ],
697
-            'settings'                 => [
698
-                'nav'           => [
699
-                    'label' => esc_html__('Settings', 'event_espresso'),
700
-                    'order' => 40,
701
-                ],
702
-                'metaboxes'     => ['_messages_settings_metaboxes'],
703
-                'help_tabs'     => [
704
-                    'messages_settings_help_tab'               => [
705
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
-                        'filename' => 'messages_settings',
707
-                    ],
708
-                    'messages_settings_message_types_help_tab' => [
709
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
-                        'filename' => 'messages_settings_message_types',
711
-                    ],
712
-                    'messages_settings_messengers_help_tab'    => [
713
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
-                        'filename' => 'messages_settings_messengers',
715
-                    ],
716
-                ],
717
-                'require_nonce' => false,
718
-            ],
719
-        ];
720
-    }
721
-
722
-
723
-    protected function _add_screen_options()
724
-    {
725
-        // todo
726
-    }
727
-
728
-
729
-    protected function _add_screen_options_global_mtps()
730
-    {
731
-        /**
732
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
734
-         */
735
-        $page_title              = $this->_admin_page_title;
736
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
-        $this->_per_page_screen_option();
738
-        $this->_admin_page_title = $page_title;
739
-    }
740
-
741
-
742
-    protected function _add_screen_options_default()
743
-    {
744
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
-        $this->_per_page_screen_option();
746
-    }
747
-
748
-
749
-    // none of the below group are currently used for Messages
750
-    protected function _add_feature_pointers()
751
-    {
752
-    }
753
-
754
-
755
-    public function admin_init()
756
-    {
757
-    }
758
-
759
-
760
-    public function admin_notices()
761
-    {
762
-    }
763
-
764
-
765
-    public function admin_footer_scripts()
766
-    {
767
-    }
768
-
769
-
770
-    public function messages_help_tab()
771
-    {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
-    }
774
-
775
-
776
-    public function messengers_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
-    }
780
-
781
-
782
-    public function message_types_help_tab()
783
-    {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
-    }
786
-
787
-
788
-    public function messages_overview_help_tab()
789
-    {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
-    }
792
-
793
-
794
-    public function message_templates_help_tab()
795
-    {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
-    }
798
-
799
-
800
-    public function edit_message_template_help_tab()
801
-    {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
-                        . esc_attr__('Editor Title', 'event_espresso')
804
-                        . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
807
-                        . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
810
-                        . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
813
-                        . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
-                        . esc_attr__('Publish Metabox', 'event_espresso')
816
-                        . '" />';
817
-        EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
-            $args
820
-        );
821
-    }
822
-
823
-
824
-    /**
825
-     * @throws ReflectionException
826
-     * @throws EE_Error
827
-     */
828
-    public function message_template_shortcodes_help_tab()
829
-    {
830
-        $this->_set_shortcodes();
831
-        $args['shortcodes'] = $this->_shortcodes;
832
-        EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
-            $args
835
-        );
836
-    }
837
-
838
-
839
-    public function preview_message_help_tab()
840
-    {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
-    }
843
-
844
-
845
-    public function settings_help_tab()
846
-    {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
-        $args['img3'] = '<div class="switch">'
852
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
-                        . ' type="checkbox" checked>'
854
-                        . '<label for="ee-on-off-toggle-on"></label>'
855
-                        . '</div>';
856
-        $args['img4'] = '<div class="switch">'
857
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
-                        . ' type="checkbox">'
859
-                        . '<label for="ee-on-off-toggle-on"></label>'
860
-                        . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
-    }
863
-
864
-
865
-    public function load_scripts_styles()
866
-    {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
-        wp_enqueue_style('espresso_ee_msg');
869
-
870
-        wp_register_script(
871
-            'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
874
-            EVENT_ESPRESSO_VERSION,
875
-            true
876
-        );
877
-        wp_register_script(
878
-            'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
-            ['ee-dialog'],
881
-            EVENT_ESPRESSO_VERSION
882
-        );
883
-    }
884
-
885
-
886
-    public function load_scripts_styles_default()
887
-    {
888
-        wp_enqueue_script('ee-msg-list-table-js');
889
-    }
890
-
891
-
892
-    public function wp_editor_css($mce_css)
893
-    {
894
-        // if we're on the edit_message_template route
895
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
-            $message_type_name = $this->_active_message_type_name;
897
-
898
-            // we're going to REPLACE the existing mce css
899
-            // we need to get the css file location from the active messenger
900
-            $mce_css = $this->_active_messenger->get_variation(
901
-                $this->_template_pack,
902
-                $message_type_name,
903
-                true,
904
-                'wpeditor',
905
-                $this->_variation
906
-            );
907
-        }
908
-
909
-        return $mce_css;
910
-    }
911
-
912
-
913
-    /**
914
-     * @throws EE_Error
915
-     * @throws ReflectionException
916
-     */
917
-    public function load_scripts_styles_edit_message_template()
918
-    {
919
-
920
-        $this->_set_shortcodes();
921
-
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
-            esc_html__(
924
-                '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.',
925
-                'event_espresso'
926
-            ),
927
-            $this->_message_template_group->messenger_obj()->label['singular'],
928
-            $this->_message_template_group->message_type_obj()->label['singular']
929
-        );
930
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
-            '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?',
932
-            'event_espresso'
933
-        );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
-            'event_espresso'
937
-        );
938
-
939
-        wp_register_script(
940
-            'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
-            ['jquery'],
943
-            EVENT_ESPRESSO_VERSION
944
-        );
945
-
946
-        wp_enqueue_script('ee_admin_js');
947
-        wp_enqueue_script('ee_msgs_edit_js');
948
-
949
-        // add in special css for tiny_mce
950
-        add_filter('mce_css', [$this, 'wp_editor_css']);
951
-    }
952
-
953
-
954
-    /**
955
-     * @throws EE_Error
956
-     * @throws ReflectionException
957
-     */
958
-    public function load_scripts_styles_display_preview_message()
959
-    {
960
-        $this->_set_message_template_group();
961
-        if ($this->_active_messenger_name) {
962
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
-                $this->_active_messenger_name
964
-            );
965
-        }
966
-
967
-        wp_enqueue_style(
968
-            'espresso_preview_css',
969
-            $this->_active_messenger->get_variation(
970
-                $this->_template_pack,
971
-                $this->_active_message_type_name,
972
-                true,
973
-                'preview',
974
-                $this->_variation
975
-            )
976
-        );
977
-    }
978
-
979
-
980
-    public function load_scripts_styles_settings()
981
-    {
982
-        wp_register_style(
983
-            'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
-            [],
986
-            EVENT_ESPRESSO_VERSION
987
-        );
988
-        wp_enqueue_style('ee-text-links');
989
-        wp_enqueue_style('ee-message-settings');
990
-        wp_enqueue_script('ee-messages-settings');
991
-    }
992
-
993
-
994
-    /**
995
-     * set views array for List Table
996
-     */
997
-    public function _set_list_table_views_global_mtps()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'  => 'in_use',
1002
-                'label' => esc_html__('In Use', 'event_espresso'),
1003
-                'count' => 0,
1004
-            ],
1005
-        ];
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Set views array for the Custom Template List Table
1011
-     */
1012
-    public function _set_list_table_views_custom_mtps()
1013
-    {
1014
-        $this->_set_list_table_views_global_mtps();
1015
-        $this->_views['in_use']['bulk_action'] = [
1016
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
-        ];
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * set views array for message queue list table
1023
-     *
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidInterfaceException
1026
-     * @throws InvalidArgumentException
1027
-     * @throws EE_Error
1028
-     * @throws ReflectionException
1029
-     */
1030
-    public function _set_list_table_views_default()
1031
-    {
1032
-        EE_Registry::instance()->load_helper('Template');
1033
-
1034
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
-            'ee_send_message',
1036
-            'message_list_table_bulk_actions'
1037
-        )
1038
-            ? [
1039
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
-            ]
1044
-            : [];
1045
-
1046
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_delete_messages',
1048
-            'message_list_table_bulk_actions'
1049
-        )
1050
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
-            : [];
1052
-
1053
-
1054
-        $this->_views = [
1055
-            'all' => [
1056
-                'slug'        => 'all',
1057
-                'label'       => esc_html__('All', 'event_espresso'),
1058
-                'count'       => 0,
1059
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
-            ],
1061
-        ];
1062
-
1063
-
1064
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
-                continue;
1067
-            }
1068
-            $status_bulk_actions = $common_bulk_actions;
1069
-            // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1071
-                switch ($status) {
1072
-                    case EEM_Message::status_idle:
1073
-                    case EEM_Message::status_resend:
1074
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
-                        break;
1076
-
1077
-                    case EEM_Message::status_failed:
1078
-                    case EEM_Message::status_debug_only:
1079
-                    case EEM_Message::status_messenger_executing:
1080
-                        $status_bulk_actions = [];
1081
-                        break;
1082
-
1083
-                    case EEM_Message::status_incomplete:
1084
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
-                        break;
1086
-
1087
-                    case EEM_Message::status_retry:
1088
-                    case EEM_Message::status_sent:
1089
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
-                        break;
1091
-                }
1092
-            }
1093
-
1094
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1095
-            if ($status === EEM_Message::status_messenger_executing) {
1096
-                continue;
1097
-            }
1098
-
1099
-            $this->_views[ strtolower($status) ] = [
1100
-                'slug'        => strtolower($status),
1101
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
-                'count'       => 0,
1103
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
-            ];
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * @throws EE_Error
1111
-     */
1112
-    protected function _ee_default_messages_overview_list_table()
1113
-    {
1114
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * @throws EE_Error
1121
-     * @throws ReflectionException
1122
-     */
1123
-    protected function _message_queue_list_table()
1124
-    {
1125
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
-        $this->_template_args['per_column']        = 6;
1127
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
-        $this->_template_args['before_list_table'] = '<h3>'
1129
-                                                     . $this->getMsgModel()->get_pretty_label_for_results()
1130
-                                                     . '</h3>';
1131
-        $this->display_admin_list_table_page_with_no_sidebar();
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * @throws EE_Error
1137
-     */
1138
-    protected function _message_legend_items()
1139
-    {
1140
-
1141
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
-        $action_items       = [];
1143
-
1144
-        foreach ($action_css_classes as $action_item => $action_details) {
1145
-            if ($action_item === 'see_notifications_for') {
1146
-                continue;
1147
-            }
1148
-            $action_items[ $action_item ] = [
1149
-                'class' => $action_details['css_class'],
1150
-                'desc'  => $action_details['label'],
1151
-            ];
1152
-        }
1153
-
1154
-        /** @var array $status_items status legend setup */
1155
-        $status_items = [
1156
-            'sent_status'                => [
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
-            ],
1160
-            'idle_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
-            ],
1164
-            'failed_status'              => [
1165
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
-            ],
1168
-            'messenger_executing_status' => [
1169
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
-            ],
1172
-            'resend_status'              => [
1173
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
-            ],
1176
-            'incomplete_status'          => [
1177
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
-            ],
1180
-            'retry_status'               => [
1181
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
-            ],
1184
-        ];
1185
-        if (EEM_Message::debug()) {
1186
-            $status_items['debug_only_status'] = [
1187
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
-            ];
1190
-        }
1191
-
1192
-        return array_merge($action_items, $status_items);
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * @throws EE_Error
1198
-     */
1199
-    protected function _custom_mtps_preview()
1200
-    {
1201
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
-                                                . ' alt="' . esc_attr__(
1204
-                                                    'Preview Custom Message Templates screenshot',
1205
-                                                    'event_espresso'
1206
-                                                ) . '" />';
1207
-        $this->_template_args['preview_text'] = '<strong>'
1208
-                                                . esc_html__(
1209
-                                                    '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.',
1210
-                                                    'event_espresso'
1211
-                                                )
1212
-                                                . '</strong>';
1213
-
1214
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * get_message_templates
1220
-     * This gets all the message templates for listing on the overview list.
1221
-     *
1222
-     * @access public
1223
-     * @param int    $per_page the amount of templates groups to show per page
1224
-     * @param string $type     the current _view we're getting templates for
1225
-     * @param bool   $count    return count?
1226
-     * @param bool   $all      disregard any paging info (get all data);
1227
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     * @throws InvalidArgumentException
1231
-     * @throws InvalidDataTypeException
1232
-     * @throws InvalidInterfaceException
1233
-     */
1234
-    public function get_message_templates(
1235
-        $per_page = 10,
1236
-        $type = 'in_use',
1237
-        $count = false,
1238
-        $all = false,
1239
-        $global = true
1240
-    ) {
1241
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
-        $this->request->setRequestParam('orderby', $orderby);
1243
-
1244
-        $order        = $this->request->getRequestParam('order', 'ASC');
1245
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
-
1248
-        $offset = ($current_page - 1) * $per_page;
1249
-        $limit  = $all ? null : [$offset, $per_page];
1250
-
1251
-        // options will match what is in the _views array property
1252
-        return $type === 'in_use'
1253
-            ? $this->getMtgModel()->get_all_active_message_templates(
1254
-                $orderby,
1255
-                $order,
1256
-                $limit,
1257
-                $count,
1258
-                $global,
1259
-                true
1260
-            )
1261
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
-                $orderby,
1263
-                $order,
1264
-                $limit,
1265
-                $count,
1266
-                $global
1267
-            );
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     * filters etc might need a list of installed message_types
1273
-     *
1274
-     * @return array an array of message type objects
1275
-     */
1276
-    public function get_installed_message_types()
1277
-    {
1278
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
-        $installed               = [];
1280
-
1281
-        foreach ($installed_message_types as $message_type) {
1282
-            $installed[ $message_type->name ] = $message_type;
1283
-        }
1284
-
1285
-        return $installed;
1286
-    }
1287
-
1288
-
1289
-    /**
1290
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1291
-     *
1292
-     * @param string $message_type
1293
-     * @param string $messenger
1294
-     * @param string $GRP_ID
1295
-     *
1296
-     * @throws EE_error
1297
-     * @throws ReflectionException
1298
-     */
1299
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
-    {
1301
-        // set values override any request data
1302
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
-
1306
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
-        if (empty($message_type) || empty($messenger)) {
1308
-            throw new EE_Error(
1309
-                esc_html__(
1310
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
-                    'event_espresso'
1312
-                )
1313
-            );
1314
-        }
1315
-
1316
-        // we need the GRP_ID for the template being used as the base for the new template
1317
-        if (empty($GRP_ID)) {
1318
-            throw new EE_Error(
1319
-                esc_html__(
1320
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
-                    'event_espresso'
1322
-                )
1323
-            );
1324
-        }
1325
-
1326
-        // let's just make sure the template gets generated!
1327
-
1328
-        // we need to reassign some variables for what the insert is expecting
1329
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1330
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1331
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
-
1333
-        $this->_insert_or_update_message_template(true);
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * @param string $message_type     message type slug
1339
-     * @param string $messenger        messenger slug
1340
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
-     *                                 off of.
1342
-     * @throws EE_error
1343
-     * @throws ReflectionException
1344
-     * @deprecated 4.10.29.p
1345
-     */
1346
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
-    {
1348
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1349
-    }
1350
-
1351
-
1352
-    /**
1353
-     * _edit_message_template
1354
-     *
1355
-     * @access protected
1356
-     * @return void
1357
-     * @throws InvalidIdentifierException
1358
-     * @throws DomainException
1359
-     * @throws EE_Error
1360
-     * @throws InvalidArgumentException
1361
-     * @throws ReflectionException
1362
-     * @throws InvalidDataTypeException
1363
-     * @throws InvalidInterfaceException
1364
-     */
1365
-    protected function _edit_message_template()
1366
-    {
1367
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
-        $template_fields = '';
1369
-        $sidebar_fields  = '';
1370
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
-        // valid html in the templates.
1372
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
-
1374
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
-
1377
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1378
-        $message_template_group = $this->_message_template_group;
1379
-        $c_label                = $message_template_group->context_label();
1380
-        $c_config               = $message_template_group->contexts_config();
1381
-
1382
-        reset($c_config);
1383
-        $context = $this->request->getRequestParam('context', key($c_config));
1384
-        $context = strtolower($context);
1385
-
1386
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
-
1388
-        $edit_message_template_form_url = add_query_arg(
1389
-            ['action' => $action, 'noheader' => true],
1390
-            EE_MSG_ADMIN_URL
1391
-        );
1392
-
1393
-        // set active messenger for this view
1394
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
-            $message_template_group->messenger()
1396
-        );
1397
-        $this->_active_message_type_name = $message_template_group->message_type();
1398
-
1399
-
1400
-        // Do we have any validation errors?
1401
-        $validators = $this->_get_transient();
1402
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
-
1404
-
1405
-        // we need to assemble the title from Various details
1406
-        $context_label = sprintf(
1407
-            esc_html__('(%s %s)', 'event_espresso'),
1408
-            $c_config[ $context ]['label'],
1409
-            ucwords($c_label['label'])
1410
-        );
1411
-
1412
-        $title = sprintf(
1413
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1414
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1415
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1416
-            $context_label
1417
-        );
1418
-
1419
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1420
-        $this->_template_args['message_template'] = $message_template_group;
1421
-        $this->_template_args['is_extra_fields']  = false;
1422
-
1423
-
1424
-        // let's get EEH_MSG_Template so we can get template form fields
1425
-        $template_field_structure = EEH_MSG_Template::get_fields(
1426
-            $message_template_group->messenger(),
1427
-            $message_template_group->message_type()
1428
-        );
1429
-
1430
-        if (! $template_field_structure) {
1431
-            $template_field_structure = false;
1432
-            $template_fields          = esc_html__(
1433
-                'There was an error in assembling the fields for this display (you should see an error message)',
1434
-                'event_espresso'
1435
-            );
1436
-        }
1437
-
1438
-
1439
-        $message_templates = $message_template_group->context_templates();
1440
-
1441
-
1442
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
-        // will get handled in the "extra" array.
1444
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
-                unset($template_field_structure[ $context ][ $reference_field ]);
1447
-            }
1448
-        }
1449
-
1450
-        // let's loop through the template_field_structure and actually assemble the input fields!
1451
-        if (! empty($template_field_structure)) {
1452
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
-                // the extra array and reset them.
1455
-                if ($template_field === 'extra') {
1456
-                    $this->_template_args['is_extra_fields'] = true;
1457
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1459
-                        $content          = $message_template instanceof EE_Message_Template
1460
-                            ? $message_template->get('MTP_content')
1461
-                            : '';
1462
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1463
-                            // let's verify if we need this extra field via the shortcodes parameter.
1464
-                            $continue = false;
1465
-                            if (isset($extra_array['shortcodes_required'])) {
1466
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
-                                        $continue = true;
1469
-                                    }
1470
-                                }
1471
-                                if ($continue) {
1472
-                                    continue;
1473
-                                }
1474
-                            }
1475
-
1476
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1477
-
1478
-                            $template_form_fields[ $field_id ]         = $extra_array;
1479
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
-                                                                         . $reference_field
1481
-                                                                         . '][content]['
1482
-                                                                         . $extra_field . ']';
1483
-                            $css_class                                 = isset($extra_array['css_class'])
1484
-                                ? $extra_array['css_class']
1485
-                                : '';
1486
-
1487
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
-                                                                              && in_array($extra_field, $v_fields, true)
1489
-                                                                              && (
1490
-                                                                                  is_array($validators[ $extra_field ])
1491
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1492
-                                                                              )
1493
-                                ? 'validate-error ' . $css_class
1494
-                                : $css_class;
1495
-
1496
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
-                                                                          && isset($content[ $extra_field ])
1498
-                                ? $content[ $extra_field ]
1499
-                                : '';
1500
-
1501
-                            // do we have a validation error?  if we do then let's use that value instead
1502
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
-                                ? $validators[ $extra_field ]['value']
1504
-                                : $template_form_fields[ $field_id ]['value'];
1505
-
1506
-
1507
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
-
1509
-                            // shortcode selector
1510
-                            $field_name_to_use                                   = $extra_field === 'main'
1511
-                                ? 'content'
1512
-                                : $extra_field;
1513
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
-                                $field_name_to_use,
1515
-                                $field_id
1516
-                            );
1517
-                        }
1518
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
-                        $template_field_template_name_id = $reference_field . '-name';
1520
-
1521
-                        $template_form_fields[ $template_field_MTP_id ] = [
1522
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
-                            'label'      => null,
1524
-                            'input'      => 'hidden',
1525
-                            'type'       => 'int',
1526
-                            'required'   => false,
1527
-                            'validation' => false,
1528
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
-                            'css_class'  => '',
1530
-                            'format'     => '%d',
1531
-                            'db-col'     => 'MTP_ID',
1532
-                        ];
1533
-
1534
-                        $template_form_fields[ $template_field_template_name_id ] = [
1535
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
-                            'label'      => null,
1537
-                            'input'      => 'hidden',
1538
-                            'type'       => 'string',
1539
-                            'required'   => false,
1540
-                            'validation' => true,
1541
-                            'value'      => $reference_field,
1542
-                            'css_class'  => '',
1543
-                            'format'     => '%s',
1544
-                            'db-col'     => 'MTP_template_field',
1545
-                        ];
1546
-                    }
1547
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
-                } else {
1549
-                    $field_id                                   = $template_field . '-content';
1550
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1551
-                    $template_form_fields[ $field_id ]['name']  =
1552
-                        'MTP_template_fields[' . $template_field . '][content]';
1553
-                    $message_template                           =
1554
-                        isset($message_templates[ $context ][ $template_field ])
1555
-                            ? $message_templates[ $context ][ $template_field ]
1556
-                            : null;
1557
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
-                                                                  && is_array($message_templates[ $context ])
1559
-                                                                  && $message_template instanceof EE_Message_Template
1560
-                        ? $message_template->get('MTP_content')
1561
-                        : '';
1562
-
1563
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1564
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
-                        ? $validators[ $template_field ]['value']
1566
-                        : $template_form_fields[ $field_id ]['value'];
1567
-
1568
-
1569
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
-                    $css_class                                      = isset($field_setup_array['css_class'])
1571
-                        ? $field_setup_array['css_class']
1572
-                        : '';
1573
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
-                                                                      && in_array($template_field, $v_fields, true)
1575
-                                                                      && isset($validators[ $template_field ]['msg'])
1576
-                        ? 'validate-error ' . $css_class
1577
-                        : $css_class;
1578
-
1579
-                    // shortcode selector
1580
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
-                        $template_field,
1582
-                        $field_id
1583
-                    );
1584
-                }
1585
-
1586
-                // k took care of content field(s) now let's take care of others.
1587
-
1588
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
-                $template_field_field_template_name_id = $template_field . '-name';
1590
-
1591
-                // foreach template field there are actually two form fields created
1592
-                $template_form_fields[ $template_field_MTP_id ] = [
1593
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
-                    'label'      => null,
1595
-                    'input'      => 'hidden',
1596
-                    'type'       => 'int',
1597
-                    'required'   => false,
1598
-                    'validation' => true,
1599
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
-                    'css_class'  => '',
1601
-                    'format'     => '%d',
1602
-                    'db-col'     => 'MTP_ID',
1603
-                ];
1604
-
1605
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1606
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
-                    'label'      => null,
1608
-                    'input'      => 'hidden',
1609
-                    'type'       => 'string',
1610
-                    'required'   => false,
1611
-                    'validation' => true,
1612
-                    'value'      => $template_field,
1613
-                    'css_class'  => '',
1614
-                    'format'     => '%s',
1615
-                    'db-col'     => 'MTP_template_field',
1616
-                ];
1617
-            }
1618
-
1619
-            // add other fields
1620
-            $template_form_fields['ee-msg-current-context'] = [
1621
-                'name'       => 'MTP_context',
1622
-                'label'      => null,
1623
-                'input'      => 'hidden',
1624
-                'type'       => 'string',
1625
-                'required'   => false,
1626
-                'validation' => true,
1627
-                'value'      => $context,
1628
-                'css_class'  => '',
1629
-                'format'     => '%s',
1630
-                'db-col'     => 'MTP_context',
1631
-            ];
1632
-
1633
-            $template_form_fields['ee-msg-grp-id'] = [
1634
-                'name'       => 'GRP_ID',
1635
-                'label'      => null,
1636
-                'input'      => 'hidden',
1637
-                'type'       => 'int',
1638
-                'required'   => false,
1639
-                'validation' => true,
1640
-                'value'      => $GRP_ID,
1641
-                'css_class'  => '',
1642
-                'format'     => '%d',
1643
-                'db-col'     => 'GRP_ID',
1644
-            ];
1645
-
1646
-            $template_form_fields['ee-msg-messenger'] = [
1647
-                'name'       => 'MTP_messenger',
1648
-                'label'      => null,
1649
-                'input'      => 'hidden',
1650
-                'type'       => 'string',
1651
-                'required'   => false,
1652
-                'validation' => true,
1653
-                'value'      => $message_template_group->messenger(),
1654
-                'css_class'  => '',
1655
-                'format'     => '%s',
1656
-                'db-col'     => 'MTP_messenger',
1657
-            ];
1658
-
1659
-            $template_form_fields['ee-msg-message-type'] = [
1660
-                'name'       => 'MTP_message_type',
1661
-                'label'      => null,
1662
-                'input'      => 'hidden',
1663
-                'type'       => 'string',
1664
-                'required'   => false,
1665
-                'validation' => true,
1666
-                'value'      => $message_template_group->message_type(),
1667
-                'css_class'  => '',
1668
-                'format'     => '%s',
1669
-                'db-col'     => 'MTP_message_type',
1670
-            ];
1671
-
1672
-            $sidebar_form_fields['ee-msg-is-global'] = [
1673
-                'name'       => 'MTP_is_global',
1674
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1675
-                'input'      => 'hidden',
1676
-                'type'       => 'int',
1677
-                'required'   => false,
1678
-                'validation' => true,
1679
-                'value'      => $message_template_group->get('MTP_is_global'),
1680
-                'css_class'  => '',
1681
-                'format'     => '%d',
1682
-                'db-col'     => 'MTP_is_global',
1683
-            ];
1684
-
1685
-            $sidebar_form_fields['ee-msg-is-override'] = [
1686
-                'name'       => 'MTP_is_override',
1687
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
-                'type'       => 'int',
1690
-                'required'   => false,
1691
-                'validation' => true,
1692
-                'value'      => $message_template_group->get('MTP_is_override'),
1693
-                'css_class'  => '',
1694
-                'format'     => '%d',
1695
-                'db-col'     => 'MTP_is_override',
1696
-            ];
1697
-
1698
-            $sidebar_form_fields['ee-msg-is-active'] = [
1699
-                'name'       => 'MTP_is_active',
1700
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1701
-                'input'      => 'hidden',
1702
-                'type'       => 'int',
1703
-                'required'   => false,
1704
-                'validation' => true,
1705
-                'value'      => $message_template_group->is_active(),
1706
-                'css_class'  => '',
1707
-                'format'     => '%d',
1708
-                'db-col'     => 'MTP_is_active',
1709
-            ];
1710
-
1711
-            $sidebar_form_fields['ee-msg-deleted'] = [
1712
-                'name'       => 'MTP_deleted',
1713
-                'label'      => null,
1714
-                'input'      => 'hidden',
1715
-                'type'       => 'int',
1716
-                'required'   => false,
1717
-                'validation' => true,
1718
-                'value'      => $message_template_group->get('MTP_deleted'),
1719
-                'css_class'  => '',
1720
-                'format'     => '%d',
1721
-                'db-col'     => 'MTP_deleted',
1722
-            ];
1723
-            $sidebar_form_fields['ee-msg-author']  = [
1724
-                'name'       => 'MTP_user_id',
1725
-                'label'      => esc_html__('Author', 'event_espresso'),
1726
-                'input'      => 'hidden',
1727
-                'type'       => 'int',
1728
-                'required'   => false,
1729
-                'validation' => false,
1730
-                'value'      => $message_template_group->user(),
1731
-                'format'     => '%d',
1732
-                'db-col'     => 'MTP_user_id',
1733
-            ];
1734
-
1735
-            $sidebar_form_fields['ee-msg-route'] = [
1736
-                'name'  => 'action',
1737
-                'input' => 'hidden',
1738
-                'type'  => 'string',
1739
-                'value' => $action,
1740
-            ];
1741
-
1742
-            $sidebar_form_fields['ee-msg-id']        = [
1743
-                'name'  => 'id',
1744
-                'input' => 'hidden',
1745
-                'type'  => 'int',
1746
-                'value' => $GRP_ID,
1747
-            ];
1748
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
-                'name'  => $action . '_nonce',
1750
-                'input' => 'hidden',
1751
-                'type'  => 'string',
1752
-                'value' => wp_create_nonce($action . '_nonce'),
1753
-            ];
1754
-
1755
-            $template_switch = $this->request->getRequestParam('template_switch');
1756
-            if ($template_switch) {
1757
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1758
-                    'name'  => 'template_switch',
1759
-                    'input' => 'hidden',
1760
-                    'type'  => 'int',
1761
-                    'value' => 1,
1762
-                ];
1763
-            }
1764
-
1765
-
1766
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
-        } //end if ( !empty($template_field_structure) )
1769
-
1770
-        // set extra content for publish box
1771
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
-        $this->_set_publish_post_box_vars(
1773
-            'id',
1774
-            $GRP_ID,
1775
-            false,
1776
-            add_query_arg(
1777
-                ['action' => 'global_mtps'],
1778
-                $this->_admin_base_url
1779
-            )
1780
-        );
1781
-
1782
-        // add preview button
1783
-        $preview_url    = parent::add_query_args_and_nonce(
1784
-            [
1785
-                'message_type' => $message_template_group->message_type(),
1786
-                'messenger'    => $message_template_group->messenger(),
1787
-                'context'      => $context,
1788
-                'GRP_ID'       => $GRP_ID,
1789
-                'evt_id'       => $EVT_ID ?: false,
1790
-                'action'       => 'preview_message',
1791
-            ],
1792
-            $this->_admin_base_url
1793
-        );
1794
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
-                          . esc_html__('Preview', 'event_espresso')
1796
-                          . '</a>';
1797
-
1798
-
1799
-        // setup context switcher
1800
-        $this->_set_context_switcher(
1801
-            $message_template_group,
1802
-            [
1803
-                'page'    => 'espresso_messages',
1804
-                'action'  => 'edit_message_template',
1805
-                'id'      => $GRP_ID,
1806
-                'evt_id'  => $EVT_ID,
1807
-                'context' => $context,
1808
-                'extra'   => $preview_button,
1809
-            ]
1810
-        );
1811
-
1812
-
1813
-        // main box
1814
-        $this->_template_args['template_fields']                         = $template_fields;
1815
-        $this->_template_args['sidebar_box_id']                          = 'details';
1816
-        $this->_template_args['action']                                  = $action;
1817
-        $this->_template_args['context']                                 = $context;
1818
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
-        $this->_template_args['learn_more_about_message_templates_link'] =
1820
-            $this->_learn_more_about_message_templates_link();
1821
-
1822
-
1823
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
-            $message_template_group,
1826
-            $context,
1827
-            $context_label
1828
-        );
1829
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
-
1832
-        $this->_template_path = $this->_template_args['GRP_ID']
1833
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
-
1836
-        // send along EE_Message_Template_Group object for further template use.
1837
-        $this->_template_args['MTP'] = $message_template_group;
1838
-
1839
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
-            $this->_template_path,
1841
-            $this->_template_args,
1842
-            true
1843
-        );
1844
-
1845
-
1846
-        // finally, let's set the admin_page title
1847
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
-
1849
-
1850
-        // we need to take care of setting the shortcodes property for use elsewhere.
1851
-        $this->_set_shortcodes();
1852
-
1853
-
1854
-        // final template wrapper
1855
-        $this->display_admin_page_with_sidebar();
1856
-    }
1857
-
1858
-
1859
-    public function filter_tinymce_init($mceInit, $editor_id)
1860
-    {
1861
-        return $mceInit;
1862
-    }
1863
-
1864
-
1865
-    public function add_context_switcher()
1866
-    {
1867
-        return $this->_context_switcher;
1868
-    }
1869
-
1870
-
1871
-    /**
1872
-     * Adds the activation/deactivation toggle for the message template context.
1873
-     *
1874
-     * @param EE_Message_Template_Group $message_template_group
1875
-     * @param string                    $context
1876
-     * @param string                    $context_label
1877
-     * @return string
1878
-     * @throws DomainException
1879
-     * @throws EE_Error
1880
-     * @throws InvalidIdentifierException
1881
-     * @throws ReflectionException
1882
-     */
1883
-    protected function add_active_context_element(
1884
-        EE_Message_Template_Group $message_template_group,
1885
-        $context,
1886
-        $context_label
1887
-    ) {
1888
-        $template_args = [
1889
-            'context'                   => $context,
1890
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
-            'is_active'                 => $message_template_group->is_context_active($context),
1892
-            'on_off_action'             => $message_template_group->is_context_active($context)
1893
-                ? 'context-off'
1894
-                : 'context-on',
1895
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
-            'message_template_group_id' => $message_template_group->ID(),
1897
-        ];
1898
-        return EEH_Template::display_template(
1899
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
-            $template_args,
1901
-            true
1902
-        );
1903
-    }
1904
-
1905
-
1906
-    /**
1907
-     * Ajax callback for `toggle_context_template` ajax action.
1908
-     * Handles toggling the message context on or off.
1909
-     *
1910
-     * @throws EE_Error
1911
-     * @throws InvalidArgumentException
1912
-     * @throws InvalidDataTypeException
1913
-     * @throws InvalidIdentifierException
1914
-     * @throws InvalidInterfaceException
1915
-     */
1916
-    public function toggle_context_template()
1917
-    {
1918
-        $success = true;
1919
-        // check for required data
1920
-        if (
1921
-            ! (
1922
-                $this->request->requestParamIsSet('message_template_group_id')
1923
-                && $this->request->requestParamIsSet('context')
1924
-                && $this->request->requestParamIsSet('status')
1925
-            )
1926
-        ) {
1927
-            EE_Error::add_error(
1928
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
-                __FILE__,
1930
-                __FUNCTION__,
1931
-                __LINE__
1932
-            );
1933
-            $success = false;
1934
-        }
1935
-
1936
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
-        $context = $this->request->getRequestParam('context', '');
1938
-        $status  = $this->request->getRequestParam('status', '');
1939
-
1940
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
-
1942
-        if ($status !== 'off' && $status !== 'on') {
1943
-            EE_Error::add_error(
1944
-                sprintf(
1945
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
-                    $status
1947
-                ),
1948
-                __FILE__,
1949
-                __FUNCTION__,
1950
-                __LINE__
1951
-            );
1952
-            $success = false;
1953
-        }
1954
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
-            EE_Error::add_error(
1958
-                sprintf(
1959
-                    esc_html__(
1960
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
-                        'event_espresso'
1962
-                    ),
1963
-                    $message_template_group_id,
1964
-                    'EE_Message_Template_Group'
1965
-                ),
1966
-                __FILE__,
1967
-                __FUNCTION__,
1968
-                __LINE__
1969
-            );
1970
-            $success = false;
1971
-        }
1972
-        if ($success) {
1973
-            $success = $status === 'off'
1974
-                ? $message_template_group->deactivate_context($context)
1975
-                : $message_template_group->activate_context($context);
1976
-        }
1977
-        $this->_template_args['success'] = $success;
1978
-        $this->_return_json();
1979
-    }
1980
-
1981
-
1982
-    public function _add_form_element_before()
1983
-    {
1984
-        return '<form method="post" action="'
1985
-               . $this->_template_args['edit_message_template_form_url']
1986
-               . '" id="ee-msg-edit-frm">';
1987
-    }
1988
-
1989
-
1990
-    public function _add_form_element_after()
1991
-    {
1992
-        return '</form>';
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * This executes switching the template pack for a message template.
1998
-     *
1999
-     * @throws EE_Error
2000
-     * @throws InvalidDataTypeException
2001
-     * @throws InvalidInterfaceException
2002
-     * @throws InvalidArgumentException
2003
-     * @throws ReflectionException
2004
-     * @since 4.5.0
2005
-     */
2006
-    public function switch_template_pack()
2007
-    {
2008
-
2009
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2011
-
2012
-        // verify we have needed values.
2013
-        if (empty($GRP_ID) || empty($template_pack)) {
2014
-            $this->_template_args['error'] = true;
2015
-            EE_Error::add_error(
2016
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
-                __FILE__,
2018
-                __FUNCTION__,
2019
-                __LINE__
2020
-            );
2021
-        } else {
2022
-            // get template, set the new template_pack and then reset to default
2023
-            /** @var EE_Message_Template_Group $message_template_group */
2024
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
-
2026
-            $message_template_group->set_template_pack_name($template_pack);
2027
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2029
-
2030
-            $query_args = $this->_reset_to_default_template();
2031
-
2032
-            if (empty($query_args['id'])) {
2033
-                EE_Error::add_error(
2034
-                    esc_html__(
2035
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
-                        'event_espresso'
2037
-                    ),
2038
-                    __FILE__,
2039
-                    __FUNCTION__,
2040
-                    __LINE__
2041
-                );
2042
-                $this->_template_args['error'] = true;
2043
-            } else {
2044
-                $template_label       = $message_template_group->get_template_pack()->label;
2045
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
-                EE_Error::add_success(
2047
-                    sprintf(
2048
-                        esc_html__(
2049
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
-                            'event_espresso'
2051
-                        ),
2052
-                        $template_label,
2053
-                        $template_pack_labels->template_pack
2054
-                    )
2055
-                );
2056
-                // generate the redirect url for js.
2057
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
-
2059
-                $this->_template_args['data']['redirect_url'] = $url;
2060
-                $this->_template_args['success']              = true;
2061
-            }
2062
-
2063
-            $this->_return_json();
2064
-        }
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
-     * they want.
2071
-     *
2072
-     * @access protected
2073
-     * @return array|void
2074
-     * @throws EE_Error
2075
-     * @throws InvalidArgumentException
2076
-     * @throws InvalidDataTypeException
2077
-     * @throws InvalidInterfaceException
2078
-     * @throws ReflectionException
2079
-     */
2080
-    protected function _reset_to_default_template()
2081
-    {
2082
-        $templates    = [];
2083
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
-        $messenger    = $this->request->getRequestParam('msgr');
2085
-        $message_type = $this->request->getRequestParam('mt');
2086
-        // we need to make sure we've got the info we need.
2087
-        if (! ($GRP_ID && $messenger && $message_type)) {
2088
-            EE_Error::add_error(
2089
-                esc_html__(
2090
-                    '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.',
2091
-                    'event_espresso'
2092
-                ),
2093
-                __FILE__,
2094
-                __FUNCTION__,
2095
-                __LINE__
2096
-            );
2097
-        }
2098
-
2099
-        // all templates will be reset to whatever the defaults are
2100
-        // for the global template matching the messenger and message type.
2101
-        $success = ! empty($GRP_ID);
2102
-
2103
-        if ($success) {
2104
-            // let's first determine if the incoming template is a global template,
2105
-            // if it isn't then we need to get the global template matching messenger and message type.
2106
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
-
2108
-
2109
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
-
2112
-            if ($success) {
2113
-                // if successfully deleted, lets generate the new ones.
2114
-                // Note. We set GLOBAL to true, because resets on ANY template
2115
-                // will use the related global template defaults for regeneration.
2116
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2117
-                // HOWEVER, we DO keep the template pack and template variation set
2118
-                // for the current custom template when resetting.
2119
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
-            }
2121
-        }
2122
-
2123
-        // any error messages?
2124
-        if (! $success) {
2125
-            EE_Error::add_error(
2126
-                esc_html__(
2127
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2128
-                    'event_espresso'
2129
-                ),
2130
-                __FILE__,
2131
-                __FUNCTION__,
2132
-                __LINE__
2133
-            );
2134
-        }
2135
-
2136
-        // all good, let's add a success message!
2137
-        if ($success && ! empty($templates)) {
2138
-            // the info for the template we generated is the first element in the returned array
2139
-            EE_Error::overwrite_success();
2140
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
-        }
2142
-
2143
-
2144
-        $query_args = [
2145
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
-        ];
2149
-
2150
-        // if called via ajax then we return query args otherwise redirect
2151
-        if ($this->request->isAjax()) {
2152
-            return $query_args;
2153
-        }
2154
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2155
-    }
2156
-
2157
-
2158
-    /**
2159
-     * Retrieve and set the message preview for display.
2160
-     *
2161
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
-     * @return string
2163
-     * @throws ReflectionException
2164
-     * @throws EE_Error
2165
-     * @throws InvalidArgumentException
2166
-     * @throws InvalidDataTypeException
2167
-     * @throws InvalidInterfaceException
2168
-     */
2169
-    public function _preview_message($send = false)
2170
-    {
2171
-        // first make sure we've got the necessary parameters
2172
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
-            EE_Error::add_error(
2175
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
-                __FILE__,
2177
-                __FUNCTION__,
2178
-                __LINE__
2179
-            );
2180
-        }
2181
-
2182
-        $context = $this->request->getRequestParam('context');
2183
-        // get the preview!
2184
-        $preview = EED_Messages::preview_message(
2185
-            $this->_active_message_type_name,
2186
-            $context,
2187
-            $this->_active_messenger_name,
2188
-            $send
2189
-        );
2190
-
2191
-        if ($send) {
2192
-            return $preview;
2193
-        }
2194
-
2195
-        // if we have an evt_id set on the request, use it.
2196
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
-
2198
-        // let's add a button to go back to the edit view
2199
-        $query_args             = [
2200
-            'id'      => $GRP_ID,
2201
-            'evt_id'  => $EVT_ID,
2202
-            'context' => $context,
2203
-            'action'  => 'edit_message_template',
2204
-        ];
2205
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
-        $preview_button         = '<a href="'
2207
-                                  . $go_back_url
2208
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2209
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2210
-                                  . '</a>';
2211
-        $message_types          = $this->get_installed_message_types();
2212
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2214
-            ? ucwords($active_messenger->label['singular'])
2215
-            : esc_html__('Unknown Messenger', 'event_espresso');
2216
-        // let's provide a helpful title for context
2217
-        $preview_title = sprintf(
2218
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
-            $active_messenger_label,
2220
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
-        );
2222
-        if (empty($preview)) {
2223
-            $this->noEventsErrorMessage();
2224
-        }
2225
-        // setup display of preview.
2226
-        $this->_admin_page_title                    = $preview_title;
2227
-        $this->_template_args['admin_page_title']   = $preview_title;
2228
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
-        $this->_template_args['data']['force_json'] = true;
2230
-
2231
-        return '';
2232
-    }
2233
-
2234
-
2235
-    /**
2236
-     * Used to set an error if there are no events available for generating a preview/test send.
2237
-     *
2238
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
-     */
2240
-    protected function noEventsErrorMessage($test_send = false)
2241
-    {
2242
-        $events_url = parent::add_query_args_and_nonce(
2243
-            [
2244
-                'action' => 'default',
2245
-                'page'   => 'espresso_events',
2246
-            ],
2247
-            admin_url('admin.php')
2248
-        );
2249
-        $message    = $test_send
2250
-            ? esc_html__(
2251
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
-                'event_espresso'
2253
-            )
2254
-            : esc_html__(
2255
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
-                'event_espresso'
2257
-            );
2258
-
2259
-        EE_Error::add_attention(
2260
-            sprintf(
2261
-                $message,
2262
-                "<a href='" . esc_url_raw($events_url) . "'>",
2263
-                '</a>'
2264
-            )
2265
-        );
2266
-    }
2267
-
2268
-
2269
-    /**
2270
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
-     * gets called automatically.
2272
-     *
2273
-     * @return void
2274
-     * @throws EE_Error
2275
-     * @since 4.5.0
2276
-     *
2277
-     */
2278
-    protected function _display_preview_message()
2279
-    {
2280
-        $this->display_admin_page_with_no_sidebar();
2281
-    }
2282
-
2283
-
2284
-    /**
2285
-     * registers metaboxes that should show up on the "edit_message_template" page
2286
-     *
2287
-     * @access protected
2288
-     * @return void
2289
-     */
2290
-    protected function _register_edit_meta_boxes()
2291
-    {
2292
-        add_meta_box(
2293
-            'mtp_valid_shortcodes',
2294
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2295
-            [$this, 'shortcode_meta_box'],
2296
-            $this->_current_screen->id,
2297
-            'side'
2298
-        );
2299
-        add_meta_box(
2300
-            'mtp_extra_actions',
2301
-            esc_html__('Extra Actions', 'event_espresso'),
2302
-            [$this, 'extra_actions_meta_box'],
2303
-            $this->_current_screen->id,
2304
-            'side',
2305
-            'high'
2306
-        );
2307
-        add_meta_box(
2308
-            'mtp_templates',
2309
-            esc_html__('Template Styles', 'event_espresso'),
2310
-            [$this, 'template_pack_meta_box'],
2311
-            $this->_current_screen->id,
2312
-            'side',
2313
-            'high'
2314
-        );
2315
-    }
2316
-
2317
-
2318
-    /**
2319
-     * metabox content for all template pack and variation selection.
2320
-     *
2321
-     * @return void
2322
-     * @throws DomainException
2323
-     * @throws EE_Error
2324
-     * @throws InvalidArgumentException
2325
-     * @throws ReflectionException
2326
-     * @throws InvalidDataTypeException
2327
-     * @throws InvalidInterfaceException
2328
-     * @since 4.5.0
2329
-     */
2330
-    public function template_pack_meta_box()
2331
-    {
2332
-        $this->_set_message_template_group();
2333
-
2334
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
-
2336
-        $tp_select_values = [];
2337
-
2338
-        foreach ($tp_collection as $tp) {
2339
-            // only include template packs that support this messenger and message type!
2340
-            $supports = $tp->get_supports();
2341
-            if (
2342
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2343
-                || ! in_array(
2344
-                    $this->_message_template_group->message_type(),
2345
-                    $supports[ $this->_message_template_group->messenger() ],
2346
-                    true
2347
-                )
2348
-            ) {
2349
-                // not supported
2350
-                continue;
2351
-            }
2352
-
2353
-            $tp_select_values[] = [
2354
-                'text' => $tp->label,
2355
-                'id'   => $tp->dbref,
2356
-            ];
2357
-        }
2358
-
2359
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
-        // the default template pack.  This still allows for the odd template pack to override.
2361
-        if (empty($tp_select_values)) {
2362
-            $tp_select_values[] = [
2363
-                'text' => esc_html__('Default', 'event_espresso'),
2364
-                'id'   => 'default',
2365
-            ];
2366
-        }
2367
-
2368
-        // setup variation select values for the currently selected template.
2369
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
-            $this->_message_template_group->messenger(),
2371
-            $this->_message_template_group->message_type()
2372
-        );
2373
-        $variations_select_values = [];
2374
-        foreach ($variations as $variation => $label) {
2375
-            $variations_select_values[] = [
2376
-                'text' => $label,
2377
-                'id'   => $variation,
2378
-            ];
2379
-        }
2380
-
2381
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
-
2383
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
-            'MTP_template_pack',
2385
-            $tp_select_values,
2386
-            $this->_message_template_group->get_template_pack_name()
2387
-        );
2388
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
-            'MTP_template_variation',
2390
-            $variations_select_values,
2391
-            $this->_message_template_group->get_template_pack_variation()
2392
-        );
2393
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
-
2398
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
-
2400
-        EEH_Template::display_template($template, $template_args);
2401
-    }
2402
-
2403
-
2404
-    /**
2405
-     * This meta box holds any extra actions related to Message Templates
2406
-     * For now, this includes Resetting templates to defaults and sending a test email.
2407
-     *
2408
-     * @access  public
2409
-     * @return void
2410
-     * @throws EE_Error
2411
-     */
2412
-    public function extra_actions_meta_box()
2413
-    {
2414
-        $template_form_fields = [];
2415
-
2416
-        $extra_args = [
2417
-            'msgr'   => $this->_message_template_group->messenger(),
2418
-            'mt'     => $this->_message_template_group->message_type(),
2419
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
-        ];
2421
-        // first we need to see if there are any fields
2422
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
-
2424
-        if (! empty($fields)) {
2425
-            // yup there be fields
2426
-            foreach ($fields as $field => $config) {
2427
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
-                $default  = isset($config['default']) ? $config['default'] : '';
2430
-                $default  = isset($config['value']) ? $config['value'] : $default;
2431
-
2432
-                // if type is hidden and the value is empty
2433
-                // something may have gone wrong so let's correct with the defaults
2434
-                $fix                = $config['input'] === 'hidden'
2435
-                                      && isset($existing[ $field ])
2436
-                                      && empty($existing[ $field ])
2437
-                    ? $default
2438
-                    : '';
2439
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
-                    ? $existing[ $field ]
2441
-                    : $fix;
2442
-
2443
-                $template_form_fields[ $field_id ] = [
2444
-                    'name'       => 'test_settings_fld[' . $field . ']',
2445
-                    'label'      => $config['label'],
2446
-                    'input'      => $config['input'],
2447
-                    'type'       => $config['type'],
2448
-                    'required'   => $config['required'],
2449
-                    'validation' => $config['validation'],
2450
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
-                    'css_class'  => $config['css_class'],
2452
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2453
-                    'default'    => $default,
2454
-                    'format'     => $config['format'],
2455
-                ];
2456
-            }
2457
-        }
2458
-
2459
-        $test_settings_html = ! empty($template_form_fields)
2460
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
-            : '';
2462
-
2463
-        // print out $test_settings_fields
2464
-        if (! empty($test_settings_html)) {
2465
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
-            $test_settings_html .= 'name="test_button" value="';
2467
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2469
-        }
2470
-
2471
-        // and button
2472
-        $test_settings_html .= '<p>';
2473
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
-        $test_settings_html .= '</p>';
2475
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
-        $test_settings_html .= $this->get_action_link_or_button(
2477
-            'reset_to_default',
2478
-            'reset',
2479
-            $extra_args,
2480
-            'button-primary reset-default-button'
2481
-        );
2482
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2483
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
-    }
2485
-
2486
-
2487
-    /**
2488
-     * This returns the shortcode selector skeleton for a given context and field.
2489
-     *
2490
-     * @param string $field           The name of the field retrieving shortcodes for.
2491
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
-     * @return string
2493
-     * @throws DomainException
2494
-     * @throws EE_Error
2495
-     * @throws InvalidArgumentException
2496
-     * @throws ReflectionException
2497
-     * @throws InvalidDataTypeException
2498
-     * @throws InvalidInterfaceException
2499
-     * @since 4.9.rc.000
2500
-     */
2501
-    protected function _get_shortcode_selector($field, $linked_input_id)
2502
-    {
2503
-        $template_args = [
2504
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2505
-            'fieldname'       => $field,
2506
-            'linked_input_id' => $linked_input_id,
2507
-        ];
2508
-
2509
-        return EEH_Template::display_template(
2510
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
-            $template_args,
2512
-            true
2513
-        );
2514
-    }
2515
-
2516
-
2517
-    /**
2518
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
-     * page)
2520
-     *
2521
-     * @access public
2522
-     * @return void
2523
-     * @throws EE_Error
2524
-     * @throws InvalidArgumentException
2525
-     * @throws ReflectionException
2526
-     * @throws InvalidDataTypeException
2527
-     * @throws InvalidInterfaceException
2528
-     */
2529
-    public function shortcode_meta_box()
2530
-    {
2531
-        $shortcodes = $this->_get_shortcodes([], false);
2532
-        // just make sure the shortcodes property is set
2533
-        // $messenger = $this->_message_template_group->messenger_obj();
2534
-        // now let's set the content depending on the status of the shortcodes array
2535
-        if (empty($shortcodes)) {
2536
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
-            return;
2538
-        }
2539
-        ?>
20
+	/**
21
+	 * @var EEM_Message
22
+	 */
23
+	private $MSG_MODEL;
24
+
25
+	/**
26
+	 * @var EEM_Message_Template
27
+	 */
28
+	private $MTP_MODEL;
29
+
30
+	/**
31
+	 * @var EEM_Message_Template_Group
32
+	 */
33
+	private $MTG_MODEL;
34
+
35
+	/**
36
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
37
+	 */
38
+	protected $_message_resource_manager;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $_active_message_type_name = '';
44
+
45
+	/**
46
+	 * @var string
47
+	 */
48
+	protected $_active_messenger_name = '';
49
+
50
+	/**
51
+	 * @var EE_messenger $_active_messenger
52
+	 */
53
+	protected $_active_messenger;
54
+
55
+	protected $_activate_meta_box_type;
56
+
57
+	protected $_current_message_meta_box;
58
+
59
+	protected $_current_message_meta_box_object;
60
+
61
+	protected $_context_switcher;
62
+
63
+	protected $_shortcodes           = [];
64
+
65
+	protected $_active_messengers    = [];
66
+
67
+	protected $_active_message_types = [];
68
+
69
+	/**
70
+	 * @var EE_Message_Template_Group $_message_template_group
71
+	 */
72
+	protected $_message_template_group;
73
+
74
+	protected $_m_mt_settings = [];
75
+
76
+
77
+	/**
78
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
+	 * IF there is no group then it gets automatically set to the Default template pack.
80
+	 *
81
+	 * @since 4.5.0
82
+	 *
83
+	 * @var EE_Messages_Template_Pack
84
+	 */
85
+	protected $_template_pack;
86
+
87
+
88
+	/**
89
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
+	 * group is.  If there is no group then it automatically gets set to default.
91
+	 *
92
+	 * @since 4.5.0
93
+	 *
94
+	 * @var string
95
+	 */
96
+	protected $_variation;
97
+
98
+
99
+	/**
100
+	 * @param bool $routing
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	public function __construct($routing = true)
105
+	{
106
+		// make sure messages autoloader is running
107
+		EED_Messages::set_autoloaders();
108
+		parent::__construct($routing);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Message
114
+	 * @throws EE_Error
115
+	 */
116
+	public function getMsgModel()
117
+	{
118
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
119
+			$this->MSG_MODEL = EEM_Message::instance();
120
+		}
121
+		return $this->MSG_MODEL;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return EEM_Message_Template
127
+	 * @throws EE_Error
128
+	 */
129
+	public function getMtpModel()
130
+	{
131
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
+			$this->MTP_MODEL = EEM_Message_Template::instance();
133
+		}
134
+		return $this->MTP_MODEL;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return EEM_Message_Template_Group
140
+	 * @throws EE_Error
141
+	 */
142
+	public function getMtgModel()
143
+	{
144
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
+		}
147
+		return $this->MTG_MODEL;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	protected function _init_page_props()
156
+	{
157
+		$this->page_slug        = EE_MSG_PG_SLUG;
158
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
+		$this->_admin_base_path = EE_MSG_ADMIN;
161
+
162
+		$messenger    = $this->request->getRequestParam('messenger', '');
163
+		$message_type = $this->request->getRequestParam('message_type', '');
164
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
+
167
+		$this->_load_message_resource_manager();
168
+	}
169
+
170
+
171
+	/**
172
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
+	 *
174
+	 * @throws EE_Error
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _load_message_resource_manager()
181
+	{
182
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return array
188
+	 * @throws EE_Error
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 * @deprecated 4.9.9.rc.014
193
+	 */
194
+	public function get_messengers_for_list_table()
195
+	{
196
+		EE_Error::doing_it_wrong(
197
+			__METHOD__,
198
+			sprintf(
199
+				esc_html__(
200
+					'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',
201
+					'event_espresso'
202
+				),
203
+				'Messages_Admin_Page::get_messengers_select_input()'
204
+			),
205
+			'4.9.9.rc.014'
206
+		);
207
+
208
+		$m_values          = [];
209
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
+		// setup messengers for selects
211
+		$i = 1;
212
+		foreach ($active_messengers as $active_messenger) {
213
+			if ($active_messenger instanceof EE_Message) {
214
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
215
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
+				$i++;
217
+			}
218
+		}
219
+
220
+		return $m_values;
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return array
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @deprecated 4.9.9.rc.014
231
+	 */
232
+	public function get_message_types_for_list_table()
233
+	{
234
+		EE_Error::doing_it_wrong(
235
+			__METHOD__,
236
+			sprintf(
237
+				esc_html__(
238
+					'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',
239
+					'event_espresso'
240
+				),
241
+				'Messages_Admin_Page::get_message_types_select_input()'
242
+			),
243
+			'4.9.9.rc.014'
244
+		);
245
+
246
+		$mt_values       = [];
247
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
+		$i               = 1;
249
+		foreach ($active_messages as $active_message) {
250
+			if ($active_message instanceof EE_Message) {
251
+				$mt_values[ $i ]['id']   = $active_message->message_type();
252
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
+				$i++;
254
+			}
255
+		}
256
+
257
+		return $mt_values;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @deprecated 4.9.9.rc.014
268
+	 */
269
+	public function get_contexts_for_message_types_for_list_table()
270
+	{
271
+		EE_Error::doing_it_wrong(
272
+			__METHOD__,
273
+			sprintf(
274
+				esc_html__(
275
+					'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',
276
+					'event_espresso'
277
+				),
278
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
+			),
280
+			'4.9.9.rc.014'
281
+		);
282
+
283
+		$contexts                = [];
284
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
+		foreach ($active_message_contexts as $active_message) {
286
+			if ($active_message instanceof EE_Message) {
287
+				$message_type = $active_message->message_type_object();
288
+				if ($message_type instanceof EE_message_type) {
289
+					$message_type_contexts = $message_type->get_contexts();
290
+					foreach ($message_type_contexts as $context => $context_details) {
291
+						$contexts[ $context ] = $context_details['label'];
292
+					}
293
+				}
294
+			}
295
+		}
296
+
297
+		return $contexts;
298
+	}
299
+
300
+
301
+	/**
302
+	 * Generate select input with provided messenger options array.
303
+	 *
304
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
+	 *                                 labels.
306
+	 * @return string
307
+	 * @throws EE_Error
308
+	 */
309
+	public function get_messengers_select_input($messenger_options)
310
+	{
311
+		// if empty or just one value then just return an empty string
312
+		if (
313
+			empty($messenger_options)
314
+			|| ! is_array($messenger_options)
315
+			|| count($messenger_options) === 1
316
+		) {
317
+			return '';
318
+		}
319
+		// merge in default
320
+		$messenger_options = array_merge(
321
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
+			$messenger_options
323
+		);
324
+		$input             = new EE_Select_Input(
325
+			$messenger_options,
326
+			[
327
+				'html_name'  => 'ee_messenger_filter_by',
328
+				'html_id'    => 'ee_messenger_filter_by',
329
+				'html_class' => 'wide',
330
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
+			]
332
+		);
333
+
334
+		return $input->get_html_for_input();
335
+	}
336
+
337
+
338
+	/**
339
+	 * Generate select input with provided message type options array.
340
+	 *
341
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
+	 *                                    message type labels
343
+	 * @return string
344
+	 * @throws EE_Error
345
+	 */
346
+	public function get_message_types_select_input($message_type_options)
347
+	{
348
+		// if empty or count of options is 1 then just return an empty string
349
+		if (
350
+			empty($message_type_options)
351
+			|| ! is_array($message_type_options)
352
+			|| count($message_type_options) === 1
353
+		) {
354
+			return '';
355
+		}
356
+		// merge in default
357
+		$message_type_options = array_merge(
358
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
+			$message_type_options
360
+		);
361
+		$input                = new EE_Select_Input(
362
+			$message_type_options,
363
+			[
364
+				'html_name'  => 'ee_message_type_filter_by',
365
+				'html_id'    => 'ee_message_type_filter_by',
366
+				'html_class' => 'wide',
367
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
+			]
369
+		);
370
+
371
+		return $input->get_html_for_input();
372
+	}
373
+
374
+
375
+	/**
376
+	 * Generate select input with provide message type contexts array.
377
+	 *
378
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
+	 *                               context label.
380
+	 * @return string
381
+	 * @throws EE_Error
382
+	 */
383
+	public function get_contexts_for_message_types_select_input($context_options)
384
+	{
385
+		// if empty or count of options is one then just return empty string
386
+		if (
387
+			empty($context_options)
388
+			|| ! is_array($context_options)
389
+			|| count($context_options) === 1
390
+		) {
391
+			return '';
392
+		}
393
+		// merge in default
394
+		$context_options = array_merge(
395
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
+			$context_options
397
+		);
398
+		$input           = new EE_Select_Input(
399
+			$context_options,
400
+			[
401
+				'html_name'  => 'ee_context_filter_by',
402
+				'html_id'    => 'ee_context_filter_by',
403
+				'html_class' => 'wide',
404
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
+			]
406
+		);
407
+
408
+		return $input->get_html_for_input();
409
+	}
410
+
411
+
412
+	protected function _ajax_hooks()
413
+	{
414
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
+	}
421
+
422
+
423
+	protected function _define_page_props()
424
+	{
425
+		$this->_admin_page_title = $this->page_label;
426
+		$this->_labels           = [
427
+			'buttons'    => [
428
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
+			],
432
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
+		];
434
+	}
435
+
436
+
437
+	/**
438
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
439
+	 *
440
+	 * @access protected
441
+	 * @return void
442
+	 */
443
+	protected function _set_page_routes()
444
+	{
445
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
+
449
+		$this->_page_routes = [
450
+			'default'                          => [
451
+				'func'       => '_message_queue_list_table',
452
+				'capability' => 'ee_read_global_messages',
453
+			],
454
+			'global_mtps'                      => [
455
+				'func'       => '_ee_default_messages_overview_list_table',
456
+				'capability' => 'ee_read_global_messages',
457
+			],
458
+			'custom_mtps'                      => [
459
+				'func'       => '_custom_mtps_preview',
460
+				'capability' => 'ee_read_messages',
461
+			],
462
+			'add_new_message_template'         => [
463
+				'func'       => 'add_message_template',
464
+				'capability' => 'ee_edit_messages',
465
+				'noheader'   => true,
466
+			],
467
+			'edit_message_template'            => [
468
+				'func'       => '_edit_message_template',
469
+				'capability' => 'ee_edit_message',
470
+				'obj_id'     => $GRP_ID,
471
+			],
472
+			'preview_message'                  => [
473
+				'func'               => '_preview_message',
474
+				'capability'         => 'ee_read_message',
475
+				'obj_id'             => $GRP_ID,
476
+				'noheader'           => true,
477
+				'headers_sent_route' => 'display_preview_message',
478
+			],
479
+			'display_preview_message'          => [
480
+				'func'       => '_display_preview_message',
481
+				'capability' => 'ee_read_message',
482
+				'obj_id'     => $GRP_ID,
483
+			],
484
+			'insert_message_template'          => [
485
+				'func'       => '_insert_or_update_message_template',
486
+				'capability' => 'ee_edit_messages',
487
+				'args'       => ['new' => true],
488
+				'noheader'   => true,
489
+			],
490
+			'update_message_template'          => [
491
+				'func'       => '_insert_or_update_message_template',
492
+				'capability' => 'ee_edit_message',
493
+				'obj_id'     => $GRP_ID,
494
+				'args'       => ['new' => false],
495
+				'noheader'   => true,
496
+			],
497
+			'trash_message_template'           => [
498
+				'func'       => '_trash_or_restore_message_template',
499
+				'capability' => 'ee_delete_message',
500
+				'obj_id'     => $GRP_ID,
501
+				'args'       => ['trash' => true, 'all' => true],
502
+				'noheader'   => true,
503
+			],
504
+			'trash_message_template_context'   => [
505
+				'func'       => '_trash_or_restore_message_template',
506
+				'capability' => 'ee_delete_message',
507
+				'obj_id'     => $GRP_ID,
508
+				'args'       => ['trash' => true],
509
+				'noheader'   => true,
510
+			],
511
+			'restore_message_template'         => [
512
+				'func'       => '_trash_or_restore_message_template',
513
+				'capability' => 'ee_delete_message',
514
+				'obj_id'     => $GRP_ID,
515
+				'args'       => ['trash' => false, 'all' => true],
516
+				'noheader'   => true,
517
+			],
518
+			'restore_message_template_context' => [
519
+				'func'       => '_trash_or_restore_message_template',
520
+				'capability' => 'ee_delete_message',
521
+				'obj_id'     => $GRP_ID,
522
+				'args'       => ['trash' => false],
523
+				'noheader'   => true,
524
+			],
525
+			'delete_message_template'          => [
526
+				'func'       => '_delete_message_template',
527
+				'capability' => 'ee_delete_message',
528
+				'obj_id'     => $GRP_ID,
529
+				'noheader'   => true,
530
+			],
531
+			'reset_to_default'                 => [
532
+				'func'       => '_reset_to_default_template',
533
+				'capability' => 'ee_edit_message',
534
+				'obj_id'     => $GRP_ID,
535
+				'noheader'   => true,
536
+			],
537
+			'settings'                         => [
538
+				'func'       => '_settings',
539
+				'capability' => 'manage_options',
540
+			],
541
+			'update_global_settings'           => [
542
+				'func'       => '_update_global_settings',
543
+				'capability' => 'manage_options',
544
+				'noheader'   => true,
545
+			],
546
+			'generate_now'                     => [
547
+				'func'       => '_generate_now',
548
+				'capability' => 'ee_send_message',
549
+				'noheader'   => true,
550
+			],
551
+			'generate_and_send_now'            => [
552
+				'func'       => '_generate_and_send_now',
553
+				'capability' => 'ee_send_message',
554
+				'noheader'   => true,
555
+			],
556
+			'queue_for_resending'              => [
557
+				'func'       => '_queue_for_resending',
558
+				'capability' => 'ee_send_message',
559
+				'noheader'   => true,
560
+			],
561
+			'send_now'                         => [
562
+				'func'       => '_send_now',
563
+				'capability' => 'ee_send_message',
564
+				'noheader'   => true,
565
+			],
566
+			'delete_ee_message'                => [
567
+				'func'       => '_delete_ee_messages',
568
+				'capability' => 'ee_delete_messages',
569
+				'noheader'   => true,
570
+			],
571
+			'delete_ee_messages'               => [
572
+				'func'       => '_delete_ee_messages',
573
+				'capability' => 'ee_delete_messages',
574
+				'noheader'   => true,
575
+				'obj_id'     => $MSG_ID,
576
+			],
577
+		];
578
+	}
579
+
580
+
581
+	protected function _set_page_config()
582
+	{
583
+		$this->_page_config = [
584
+			'default'                  => [
585
+				'nav'           => [
586
+					'label' => esc_html__('Message Activity', 'event_espresso'),
587
+					'order' => 10,
588
+				],
589
+				'list_table'    => 'EE_Message_List_Table',
590
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
+				'require_nonce' => false,
592
+			],
593
+			'global_mtps'              => [
594
+				'nav'           => [
595
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
+					'order' => 20,
597
+				],
598
+				'list_table'    => 'Messages_Template_List_Table',
599
+				'help_tabs'     => [
600
+					'messages_overview_help_tab'                                => [
601
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
+						'filename' => 'messages_overview',
603
+					],
604
+					'messages_overview_messages_table_column_headings_help_tab' => [
605
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
+						'filename' => 'messages_overview_table_column_headings',
607
+					],
608
+					'messages_overview_messages_filters_help_tab'               => [
609
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
610
+						'filename' => 'messages_overview_filters',
611
+					],
612
+					'messages_overview_messages_views_help_tab'                 => [
613
+						'title'    => esc_html__('Message Views', 'event_espresso'),
614
+						'filename' => 'messages_overview_views',
615
+					],
616
+					'message_overview_message_types_help_tab'                   => [
617
+						'title'    => esc_html__('Message Types', 'event_espresso'),
618
+						'filename' => 'messages_overview_types',
619
+					],
620
+					'messages_overview_messengers_help_tab'                     => [
621
+						'title'    => esc_html__('Messengers', 'event_espresso'),
622
+						'filename' => 'messages_overview_messengers',
623
+					],
624
+				],
625
+				'require_nonce' => false,
626
+			],
627
+			'custom_mtps'              => [
628
+				'nav'           => [
629
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
+					'order' => 30,
631
+				],
632
+				'help_tabs'     => [],
633
+				'require_nonce' => false,
634
+			],
635
+			'add_new_message_template' => [
636
+				'nav'           => [
637
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
+					'order'      => 5,
639
+					'persistent' => false,
640
+				],
641
+				'require_nonce' => false,
642
+			],
643
+			'edit_message_template'    => [
644
+				'labels'        => [
645
+					'buttons'    => [
646
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
+					],
648
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
+				],
650
+				'nav'           => [
651
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
+					'order'      => 5,
653
+					'persistent' => false,
654
+					'url'        => '',
655
+				],
656
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
+				'has_metaboxes' => true,
658
+				'help_tabs'     => [
659
+					'edit_message_template'            => [
660
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
+						'callback' => 'edit_message_template_help_tab',
662
+					],
663
+					'message_templates_help_tab'       => [
664
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
665
+						'filename' => 'messages_templates',
666
+					],
667
+					'message_template_shortcodes'      => [
668
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
+						'callback' => 'message_template_shortcodes_help_tab',
670
+					],
671
+					'message_preview_help_tab'         => [
672
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
673
+						'filename' => 'messages_preview',
674
+					],
675
+					'messages_overview_other_help_tab' => [
676
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
677
+						'filename' => 'messages_overview_other',
678
+					],
679
+				],
680
+				'require_nonce' => false,
681
+			],
682
+			'display_preview_message'  => [
683
+				'nav'           => [
684
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
685
+					'order'      => 5,
686
+					'url'        => '',
687
+					'persistent' => false,
688
+				],
689
+				'help_tabs'     => [
690
+					'preview_message' => [
691
+						'title'    => esc_html__('About Previews', 'event_espresso'),
692
+						'callback' => 'preview_message_help_tab',
693
+					],
694
+				],
695
+				'require_nonce' => false,
696
+			],
697
+			'settings'                 => [
698
+				'nav'           => [
699
+					'label' => esc_html__('Settings', 'event_espresso'),
700
+					'order' => 40,
701
+				],
702
+				'metaboxes'     => ['_messages_settings_metaboxes'],
703
+				'help_tabs'     => [
704
+					'messages_settings_help_tab'               => [
705
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
+						'filename' => 'messages_settings',
707
+					],
708
+					'messages_settings_message_types_help_tab' => [
709
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
+						'filename' => 'messages_settings_message_types',
711
+					],
712
+					'messages_settings_messengers_help_tab'    => [
713
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
+						'filename' => 'messages_settings_messengers',
715
+					],
716
+				],
717
+				'require_nonce' => false,
718
+			],
719
+		];
720
+	}
721
+
722
+
723
+	protected function _add_screen_options()
724
+	{
725
+		// todo
726
+	}
727
+
728
+
729
+	protected function _add_screen_options_global_mtps()
730
+	{
731
+		/**
732
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
734
+		 */
735
+		$page_title              = $this->_admin_page_title;
736
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
+		$this->_per_page_screen_option();
738
+		$this->_admin_page_title = $page_title;
739
+	}
740
+
741
+
742
+	protected function _add_screen_options_default()
743
+	{
744
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
+		$this->_per_page_screen_option();
746
+	}
747
+
748
+
749
+	// none of the below group are currently used for Messages
750
+	protected function _add_feature_pointers()
751
+	{
752
+	}
753
+
754
+
755
+	public function admin_init()
756
+	{
757
+	}
758
+
759
+
760
+	public function admin_notices()
761
+	{
762
+	}
763
+
764
+
765
+	public function admin_footer_scripts()
766
+	{
767
+	}
768
+
769
+
770
+	public function messages_help_tab()
771
+	{
772
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
+	}
774
+
775
+
776
+	public function messengers_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
+	}
780
+
781
+
782
+	public function message_types_help_tab()
783
+	{
784
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
+	}
786
+
787
+
788
+	public function messages_overview_help_tab()
789
+	{
790
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
+	}
792
+
793
+
794
+	public function message_templates_help_tab()
795
+	{
796
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
+	}
798
+
799
+
800
+	public function edit_message_template_help_tab()
801
+	{
802
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
+						. esc_attr__('Editor Title', 'event_espresso')
804
+						. '" />';
805
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
807
+						. '" />';
808
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
810
+						. '" />';
811
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
813
+						. '" />';
814
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
+						. esc_attr__('Publish Metabox', 'event_espresso')
816
+						. '" />';
817
+		EEH_Template::display_template(
818
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
+			$args
820
+		);
821
+	}
822
+
823
+
824
+	/**
825
+	 * @throws ReflectionException
826
+	 * @throws EE_Error
827
+	 */
828
+	public function message_template_shortcodes_help_tab()
829
+	{
830
+		$this->_set_shortcodes();
831
+		$args['shortcodes'] = $this->_shortcodes;
832
+		EEH_Template::display_template(
833
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
+			$args
835
+		);
836
+	}
837
+
838
+
839
+	public function preview_message_help_tab()
840
+	{
841
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
+	}
843
+
844
+
845
+	public function settings_help_tab()
846
+	{
847
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
+		$args['img3'] = '<div class="switch">'
852
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
+						. ' type="checkbox" checked>'
854
+						. '<label for="ee-on-off-toggle-on"></label>'
855
+						. '</div>';
856
+		$args['img4'] = '<div class="switch">'
857
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
+						. ' type="checkbox">'
859
+						. '<label for="ee-on-off-toggle-on"></label>'
860
+						. '</div>';
861
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
+	}
863
+
864
+
865
+	public function load_scripts_styles()
866
+	{
867
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
+		wp_enqueue_style('espresso_ee_msg');
869
+
870
+		wp_register_script(
871
+			'ee-messages-settings',
872
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
874
+			EVENT_ESPRESSO_VERSION,
875
+			true
876
+		);
877
+		wp_register_script(
878
+			'ee-msg-list-table-js',
879
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
+			['ee-dialog'],
881
+			EVENT_ESPRESSO_VERSION
882
+		);
883
+	}
884
+
885
+
886
+	public function load_scripts_styles_default()
887
+	{
888
+		wp_enqueue_script('ee-msg-list-table-js');
889
+	}
890
+
891
+
892
+	public function wp_editor_css($mce_css)
893
+	{
894
+		// if we're on the edit_message_template route
895
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
+			$message_type_name = $this->_active_message_type_name;
897
+
898
+			// we're going to REPLACE the existing mce css
899
+			// we need to get the css file location from the active messenger
900
+			$mce_css = $this->_active_messenger->get_variation(
901
+				$this->_template_pack,
902
+				$message_type_name,
903
+				true,
904
+				'wpeditor',
905
+				$this->_variation
906
+			);
907
+		}
908
+
909
+		return $mce_css;
910
+	}
911
+
912
+
913
+	/**
914
+	 * @throws EE_Error
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function load_scripts_styles_edit_message_template()
918
+	{
919
+
920
+		$this->_set_shortcodes();
921
+
922
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
+			esc_html__(
924
+				'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.',
925
+				'event_espresso'
926
+			),
927
+			$this->_message_template_group->messenger_obj()->label['singular'],
928
+			$this->_message_template_group->message_type_obj()->label['singular']
929
+		);
930
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
+			'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?',
932
+			'event_espresso'
933
+		);
934
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
+			'event_espresso'
937
+		);
938
+
939
+		wp_register_script(
940
+			'ee_msgs_edit_js',
941
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
+			['jquery'],
943
+			EVENT_ESPRESSO_VERSION
944
+		);
945
+
946
+		wp_enqueue_script('ee_admin_js');
947
+		wp_enqueue_script('ee_msgs_edit_js');
948
+
949
+		// add in special css for tiny_mce
950
+		add_filter('mce_css', [$this, 'wp_editor_css']);
951
+	}
952
+
953
+
954
+	/**
955
+	 * @throws EE_Error
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function load_scripts_styles_display_preview_message()
959
+	{
960
+		$this->_set_message_template_group();
961
+		if ($this->_active_messenger_name) {
962
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
+				$this->_active_messenger_name
964
+			);
965
+		}
966
+
967
+		wp_enqueue_style(
968
+			'espresso_preview_css',
969
+			$this->_active_messenger->get_variation(
970
+				$this->_template_pack,
971
+				$this->_active_message_type_name,
972
+				true,
973
+				'preview',
974
+				$this->_variation
975
+			)
976
+		);
977
+	}
978
+
979
+
980
+	public function load_scripts_styles_settings()
981
+	{
982
+		wp_register_style(
983
+			'ee-message-settings',
984
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
+			[],
986
+			EVENT_ESPRESSO_VERSION
987
+		);
988
+		wp_enqueue_style('ee-text-links');
989
+		wp_enqueue_style('ee-message-settings');
990
+		wp_enqueue_script('ee-messages-settings');
991
+	}
992
+
993
+
994
+	/**
995
+	 * set views array for List Table
996
+	 */
997
+	public function _set_list_table_views_global_mtps()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'  => 'in_use',
1002
+				'label' => esc_html__('In Use', 'event_espresso'),
1003
+				'count' => 0,
1004
+			],
1005
+		];
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Set views array for the Custom Template List Table
1011
+	 */
1012
+	public function _set_list_table_views_custom_mtps()
1013
+	{
1014
+		$this->_set_list_table_views_global_mtps();
1015
+		$this->_views['in_use']['bulk_action'] = [
1016
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
+		];
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * set views array for message queue list table
1023
+	 *
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidInterfaceException
1026
+	 * @throws InvalidArgumentException
1027
+	 * @throws EE_Error
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	public function _set_list_table_views_default()
1031
+	{
1032
+		EE_Registry::instance()->load_helper('Template');
1033
+
1034
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
+			'ee_send_message',
1036
+			'message_list_table_bulk_actions'
1037
+		)
1038
+			? [
1039
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
+			]
1044
+			: [];
1045
+
1046
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_delete_messages',
1048
+			'message_list_table_bulk_actions'
1049
+		)
1050
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
+			: [];
1052
+
1053
+
1054
+		$this->_views = [
1055
+			'all' => [
1056
+				'slug'        => 'all',
1057
+				'label'       => esc_html__('All', 'event_espresso'),
1058
+				'count'       => 0,
1059
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
+			],
1061
+		];
1062
+
1063
+
1064
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
+				continue;
1067
+			}
1068
+			$status_bulk_actions = $common_bulk_actions;
1069
+			// unset bulk actions not applying to status
1070
+			if (! empty($status_bulk_actions)) {
1071
+				switch ($status) {
1072
+					case EEM_Message::status_idle:
1073
+					case EEM_Message::status_resend:
1074
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
+						break;
1076
+
1077
+					case EEM_Message::status_failed:
1078
+					case EEM_Message::status_debug_only:
1079
+					case EEM_Message::status_messenger_executing:
1080
+						$status_bulk_actions = [];
1081
+						break;
1082
+
1083
+					case EEM_Message::status_incomplete:
1084
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
+						break;
1086
+
1087
+					case EEM_Message::status_retry:
1088
+					case EEM_Message::status_sent:
1089
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
+						break;
1091
+				}
1092
+			}
1093
+
1094
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1095
+			if ($status === EEM_Message::status_messenger_executing) {
1096
+				continue;
1097
+			}
1098
+
1099
+			$this->_views[ strtolower($status) ] = [
1100
+				'slug'        => strtolower($status),
1101
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
+				'count'       => 0,
1103
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
+			];
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	protected function _ee_default_messages_overview_list_table()
1113
+	{
1114
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * @throws EE_Error
1121
+	 * @throws ReflectionException
1122
+	 */
1123
+	protected function _message_queue_list_table()
1124
+	{
1125
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
+		$this->_template_args['per_column']        = 6;
1127
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
+		$this->_template_args['before_list_table'] = '<h3>'
1129
+													 . $this->getMsgModel()->get_pretty_label_for_results()
1130
+													 . '</h3>';
1131
+		$this->display_admin_list_table_page_with_no_sidebar();
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * @throws EE_Error
1137
+	 */
1138
+	protected function _message_legend_items()
1139
+	{
1140
+
1141
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
+		$action_items       = [];
1143
+
1144
+		foreach ($action_css_classes as $action_item => $action_details) {
1145
+			if ($action_item === 'see_notifications_for') {
1146
+				continue;
1147
+			}
1148
+			$action_items[ $action_item ] = [
1149
+				'class' => $action_details['css_class'],
1150
+				'desc'  => $action_details['label'],
1151
+			];
1152
+		}
1153
+
1154
+		/** @var array $status_items status legend setup */
1155
+		$status_items = [
1156
+			'sent_status'                => [
1157
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
+			],
1160
+			'idle_status'                => [
1161
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
+			],
1164
+			'failed_status'              => [
1165
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
+			],
1168
+			'messenger_executing_status' => [
1169
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
+			],
1172
+			'resend_status'              => [
1173
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
+			],
1176
+			'incomplete_status'          => [
1177
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
+			],
1180
+			'retry_status'               => [
1181
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
+			],
1184
+		];
1185
+		if (EEM_Message::debug()) {
1186
+			$status_items['debug_only_status'] = [
1187
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
+			];
1190
+		}
1191
+
1192
+		return array_merge($action_items, $status_items);
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * @throws EE_Error
1198
+	 */
1199
+	protected function _custom_mtps_preview()
1200
+	{
1201
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
+												. ' alt="' . esc_attr__(
1204
+													'Preview Custom Message Templates screenshot',
1205
+													'event_espresso'
1206
+												) . '" />';
1207
+		$this->_template_args['preview_text'] = '<strong>'
1208
+												. esc_html__(
1209
+													'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.',
1210
+													'event_espresso'
1211
+												)
1212
+												. '</strong>';
1213
+
1214
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * get_message_templates
1220
+	 * This gets all the message templates for listing on the overview list.
1221
+	 *
1222
+	 * @access public
1223
+	 * @param int    $per_page the amount of templates groups to show per page
1224
+	 * @param string $type     the current _view we're getting templates for
1225
+	 * @param bool   $count    return count?
1226
+	 * @param bool   $all      disregard any paging info (get all data);
1227
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 * @throws InvalidArgumentException
1231
+	 * @throws InvalidDataTypeException
1232
+	 * @throws InvalidInterfaceException
1233
+	 */
1234
+	public function get_message_templates(
1235
+		$per_page = 10,
1236
+		$type = 'in_use',
1237
+		$count = false,
1238
+		$all = false,
1239
+		$global = true
1240
+	) {
1241
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
+		$this->request->setRequestParam('orderby', $orderby);
1243
+
1244
+		$order        = $this->request->getRequestParam('order', 'ASC');
1245
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
+
1248
+		$offset = ($current_page - 1) * $per_page;
1249
+		$limit  = $all ? null : [$offset, $per_page];
1250
+
1251
+		// options will match what is in the _views array property
1252
+		return $type === 'in_use'
1253
+			? $this->getMtgModel()->get_all_active_message_templates(
1254
+				$orderby,
1255
+				$order,
1256
+				$limit,
1257
+				$count,
1258
+				$global,
1259
+				true
1260
+			)
1261
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
+				$orderby,
1263
+				$order,
1264
+				$limit,
1265
+				$count,
1266
+				$global
1267
+			);
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 * filters etc might need a list of installed message_types
1273
+	 *
1274
+	 * @return array an array of message type objects
1275
+	 */
1276
+	public function get_installed_message_types()
1277
+	{
1278
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
+		$installed               = [];
1280
+
1281
+		foreach ($installed_message_types as $message_type) {
1282
+			$installed[ $message_type->name ] = $message_type;
1283
+		}
1284
+
1285
+		return $installed;
1286
+	}
1287
+
1288
+
1289
+	/**
1290
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1291
+	 *
1292
+	 * @param string $message_type
1293
+	 * @param string $messenger
1294
+	 * @param string $GRP_ID
1295
+	 *
1296
+	 * @throws EE_error
1297
+	 * @throws ReflectionException
1298
+	 */
1299
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
+	{
1301
+		// set values override any request data
1302
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
+
1306
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
+		if (empty($message_type) || empty($messenger)) {
1308
+			throw new EE_Error(
1309
+				esc_html__(
1310
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
+					'event_espresso'
1312
+				)
1313
+			);
1314
+		}
1315
+
1316
+		// we need the GRP_ID for the template being used as the base for the new template
1317
+		if (empty($GRP_ID)) {
1318
+			throw new EE_Error(
1319
+				esc_html__(
1320
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
+					'event_espresso'
1322
+				)
1323
+			);
1324
+		}
1325
+
1326
+		// let's just make sure the template gets generated!
1327
+
1328
+		// we need to reassign some variables for what the insert is expecting
1329
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1330
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1331
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
+
1333
+		$this->_insert_or_update_message_template(true);
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * @param string $message_type     message type slug
1339
+	 * @param string $messenger        messenger slug
1340
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
+	 *                                 off of.
1342
+	 * @throws EE_error
1343
+	 * @throws ReflectionException
1344
+	 * @deprecated 4.10.29.p
1345
+	 */
1346
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
+	{
1348
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1349
+	}
1350
+
1351
+
1352
+	/**
1353
+	 * _edit_message_template
1354
+	 *
1355
+	 * @access protected
1356
+	 * @return void
1357
+	 * @throws InvalidIdentifierException
1358
+	 * @throws DomainException
1359
+	 * @throws EE_Error
1360
+	 * @throws InvalidArgumentException
1361
+	 * @throws ReflectionException
1362
+	 * @throws InvalidDataTypeException
1363
+	 * @throws InvalidInterfaceException
1364
+	 */
1365
+	protected function _edit_message_template()
1366
+	{
1367
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
+		$template_fields = '';
1369
+		$sidebar_fields  = '';
1370
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
+		// valid html in the templates.
1372
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
+
1374
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
+
1377
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1378
+		$message_template_group = $this->_message_template_group;
1379
+		$c_label                = $message_template_group->context_label();
1380
+		$c_config               = $message_template_group->contexts_config();
1381
+
1382
+		reset($c_config);
1383
+		$context = $this->request->getRequestParam('context', key($c_config));
1384
+		$context = strtolower($context);
1385
+
1386
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
+
1388
+		$edit_message_template_form_url = add_query_arg(
1389
+			['action' => $action, 'noheader' => true],
1390
+			EE_MSG_ADMIN_URL
1391
+		);
1392
+
1393
+		// set active messenger for this view
1394
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
+			$message_template_group->messenger()
1396
+		);
1397
+		$this->_active_message_type_name = $message_template_group->message_type();
1398
+
1399
+
1400
+		// Do we have any validation errors?
1401
+		$validators = $this->_get_transient();
1402
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
+
1404
+
1405
+		// we need to assemble the title from Various details
1406
+		$context_label = sprintf(
1407
+			esc_html__('(%s %s)', 'event_espresso'),
1408
+			$c_config[ $context ]['label'],
1409
+			ucwords($c_label['label'])
1410
+		);
1411
+
1412
+		$title = sprintf(
1413
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1414
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1415
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1416
+			$context_label
1417
+		);
1418
+
1419
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1420
+		$this->_template_args['message_template'] = $message_template_group;
1421
+		$this->_template_args['is_extra_fields']  = false;
1422
+
1423
+
1424
+		// let's get EEH_MSG_Template so we can get template form fields
1425
+		$template_field_structure = EEH_MSG_Template::get_fields(
1426
+			$message_template_group->messenger(),
1427
+			$message_template_group->message_type()
1428
+		);
1429
+
1430
+		if (! $template_field_structure) {
1431
+			$template_field_structure = false;
1432
+			$template_fields          = esc_html__(
1433
+				'There was an error in assembling the fields for this display (you should see an error message)',
1434
+				'event_espresso'
1435
+			);
1436
+		}
1437
+
1438
+
1439
+		$message_templates = $message_template_group->context_templates();
1440
+
1441
+
1442
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
+		// will get handled in the "extra" array.
1444
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
+				unset($template_field_structure[ $context ][ $reference_field ]);
1447
+			}
1448
+		}
1449
+
1450
+		// let's loop through the template_field_structure and actually assemble the input fields!
1451
+		if (! empty($template_field_structure)) {
1452
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
+				// the extra array and reset them.
1455
+				if ($template_field === 'extra') {
1456
+					$this->_template_args['is_extra_fields'] = true;
1457
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
+						$message_template = $message_templates[ $context ][ $reference_field ];
1459
+						$content          = $message_template instanceof EE_Message_Template
1460
+							? $message_template->get('MTP_content')
1461
+							: '';
1462
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1463
+							// let's verify if we need this extra field via the shortcodes parameter.
1464
+							$continue = false;
1465
+							if (isset($extra_array['shortcodes_required'])) {
1466
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
+										$continue = true;
1469
+									}
1470
+								}
1471
+								if ($continue) {
1472
+									continue;
1473
+								}
1474
+							}
1475
+
1476
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1477
+
1478
+							$template_form_fields[ $field_id ]         = $extra_array;
1479
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
+																		 . $reference_field
1481
+																		 . '][content]['
1482
+																		 . $extra_field . ']';
1483
+							$css_class                                 = isset($extra_array['css_class'])
1484
+								? $extra_array['css_class']
1485
+								: '';
1486
+
1487
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
+																			  && in_array($extra_field, $v_fields, true)
1489
+																			  && (
1490
+																				  is_array($validators[ $extra_field ])
1491
+																				  && isset($validators[ $extra_field ]['msg'])
1492
+																			  )
1493
+								? 'validate-error ' . $css_class
1494
+								: $css_class;
1495
+
1496
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
+																		  && isset($content[ $extra_field ])
1498
+								? $content[ $extra_field ]
1499
+								: '';
1500
+
1501
+							// do we have a validation error?  if we do then let's use that value instead
1502
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
+								? $validators[ $extra_field ]['value']
1504
+								: $template_form_fields[ $field_id ]['value'];
1505
+
1506
+
1507
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
+
1509
+							// shortcode selector
1510
+							$field_name_to_use                                   = $extra_field === 'main'
1511
+								? 'content'
1512
+								: $extra_field;
1513
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
+								$field_name_to_use,
1515
+								$field_id
1516
+							);
1517
+						}
1518
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
+						$template_field_template_name_id = $reference_field . '-name';
1520
+
1521
+						$template_form_fields[ $template_field_MTP_id ] = [
1522
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
+							'label'      => null,
1524
+							'input'      => 'hidden',
1525
+							'type'       => 'int',
1526
+							'required'   => false,
1527
+							'validation' => false,
1528
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
+							'css_class'  => '',
1530
+							'format'     => '%d',
1531
+							'db-col'     => 'MTP_ID',
1532
+						];
1533
+
1534
+						$template_form_fields[ $template_field_template_name_id ] = [
1535
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
+							'label'      => null,
1537
+							'input'      => 'hidden',
1538
+							'type'       => 'string',
1539
+							'required'   => false,
1540
+							'validation' => true,
1541
+							'value'      => $reference_field,
1542
+							'css_class'  => '',
1543
+							'format'     => '%s',
1544
+							'db-col'     => 'MTP_template_field',
1545
+						];
1546
+					}
1547
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
+				} else {
1549
+					$field_id                                   = $template_field . '-content';
1550
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1551
+					$template_form_fields[ $field_id ]['name']  =
1552
+						'MTP_template_fields[' . $template_field . '][content]';
1553
+					$message_template                           =
1554
+						isset($message_templates[ $context ][ $template_field ])
1555
+							? $message_templates[ $context ][ $template_field ]
1556
+							: null;
1557
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
+																  && is_array($message_templates[ $context ])
1559
+																  && $message_template instanceof EE_Message_Template
1560
+						? $message_template->get('MTP_content')
1561
+						: '';
1562
+
1563
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1564
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
+						? $validators[ $template_field ]['value']
1566
+						: $template_form_fields[ $field_id ]['value'];
1567
+
1568
+
1569
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
+					$css_class                                      = isset($field_setup_array['css_class'])
1571
+						? $field_setup_array['css_class']
1572
+						: '';
1573
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
+																	  && in_array($template_field, $v_fields, true)
1575
+																	  && isset($validators[ $template_field ]['msg'])
1576
+						? 'validate-error ' . $css_class
1577
+						: $css_class;
1578
+
1579
+					// shortcode selector
1580
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
+						$template_field,
1582
+						$field_id
1583
+					);
1584
+				}
1585
+
1586
+				// k took care of content field(s) now let's take care of others.
1587
+
1588
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
+				$template_field_field_template_name_id = $template_field . '-name';
1590
+
1591
+				// foreach template field there are actually two form fields created
1592
+				$template_form_fields[ $template_field_MTP_id ] = [
1593
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
+					'label'      => null,
1595
+					'input'      => 'hidden',
1596
+					'type'       => 'int',
1597
+					'required'   => false,
1598
+					'validation' => true,
1599
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
+					'css_class'  => '',
1601
+					'format'     => '%d',
1602
+					'db-col'     => 'MTP_ID',
1603
+				];
1604
+
1605
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1606
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
+					'label'      => null,
1608
+					'input'      => 'hidden',
1609
+					'type'       => 'string',
1610
+					'required'   => false,
1611
+					'validation' => true,
1612
+					'value'      => $template_field,
1613
+					'css_class'  => '',
1614
+					'format'     => '%s',
1615
+					'db-col'     => 'MTP_template_field',
1616
+				];
1617
+			}
1618
+
1619
+			// add other fields
1620
+			$template_form_fields['ee-msg-current-context'] = [
1621
+				'name'       => 'MTP_context',
1622
+				'label'      => null,
1623
+				'input'      => 'hidden',
1624
+				'type'       => 'string',
1625
+				'required'   => false,
1626
+				'validation' => true,
1627
+				'value'      => $context,
1628
+				'css_class'  => '',
1629
+				'format'     => '%s',
1630
+				'db-col'     => 'MTP_context',
1631
+			];
1632
+
1633
+			$template_form_fields['ee-msg-grp-id'] = [
1634
+				'name'       => 'GRP_ID',
1635
+				'label'      => null,
1636
+				'input'      => 'hidden',
1637
+				'type'       => 'int',
1638
+				'required'   => false,
1639
+				'validation' => true,
1640
+				'value'      => $GRP_ID,
1641
+				'css_class'  => '',
1642
+				'format'     => '%d',
1643
+				'db-col'     => 'GRP_ID',
1644
+			];
1645
+
1646
+			$template_form_fields['ee-msg-messenger'] = [
1647
+				'name'       => 'MTP_messenger',
1648
+				'label'      => null,
1649
+				'input'      => 'hidden',
1650
+				'type'       => 'string',
1651
+				'required'   => false,
1652
+				'validation' => true,
1653
+				'value'      => $message_template_group->messenger(),
1654
+				'css_class'  => '',
1655
+				'format'     => '%s',
1656
+				'db-col'     => 'MTP_messenger',
1657
+			];
1658
+
1659
+			$template_form_fields['ee-msg-message-type'] = [
1660
+				'name'       => 'MTP_message_type',
1661
+				'label'      => null,
1662
+				'input'      => 'hidden',
1663
+				'type'       => 'string',
1664
+				'required'   => false,
1665
+				'validation' => true,
1666
+				'value'      => $message_template_group->message_type(),
1667
+				'css_class'  => '',
1668
+				'format'     => '%s',
1669
+				'db-col'     => 'MTP_message_type',
1670
+			];
1671
+
1672
+			$sidebar_form_fields['ee-msg-is-global'] = [
1673
+				'name'       => 'MTP_is_global',
1674
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1675
+				'input'      => 'hidden',
1676
+				'type'       => 'int',
1677
+				'required'   => false,
1678
+				'validation' => true,
1679
+				'value'      => $message_template_group->get('MTP_is_global'),
1680
+				'css_class'  => '',
1681
+				'format'     => '%d',
1682
+				'db-col'     => 'MTP_is_global',
1683
+			];
1684
+
1685
+			$sidebar_form_fields['ee-msg-is-override'] = [
1686
+				'name'       => 'MTP_is_override',
1687
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
+				'type'       => 'int',
1690
+				'required'   => false,
1691
+				'validation' => true,
1692
+				'value'      => $message_template_group->get('MTP_is_override'),
1693
+				'css_class'  => '',
1694
+				'format'     => '%d',
1695
+				'db-col'     => 'MTP_is_override',
1696
+			];
1697
+
1698
+			$sidebar_form_fields['ee-msg-is-active'] = [
1699
+				'name'       => 'MTP_is_active',
1700
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1701
+				'input'      => 'hidden',
1702
+				'type'       => 'int',
1703
+				'required'   => false,
1704
+				'validation' => true,
1705
+				'value'      => $message_template_group->is_active(),
1706
+				'css_class'  => '',
1707
+				'format'     => '%d',
1708
+				'db-col'     => 'MTP_is_active',
1709
+			];
1710
+
1711
+			$sidebar_form_fields['ee-msg-deleted'] = [
1712
+				'name'       => 'MTP_deleted',
1713
+				'label'      => null,
1714
+				'input'      => 'hidden',
1715
+				'type'       => 'int',
1716
+				'required'   => false,
1717
+				'validation' => true,
1718
+				'value'      => $message_template_group->get('MTP_deleted'),
1719
+				'css_class'  => '',
1720
+				'format'     => '%d',
1721
+				'db-col'     => 'MTP_deleted',
1722
+			];
1723
+			$sidebar_form_fields['ee-msg-author']  = [
1724
+				'name'       => 'MTP_user_id',
1725
+				'label'      => esc_html__('Author', 'event_espresso'),
1726
+				'input'      => 'hidden',
1727
+				'type'       => 'int',
1728
+				'required'   => false,
1729
+				'validation' => false,
1730
+				'value'      => $message_template_group->user(),
1731
+				'format'     => '%d',
1732
+				'db-col'     => 'MTP_user_id',
1733
+			];
1734
+
1735
+			$sidebar_form_fields['ee-msg-route'] = [
1736
+				'name'  => 'action',
1737
+				'input' => 'hidden',
1738
+				'type'  => 'string',
1739
+				'value' => $action,
1740
+			];
1741
+
1742
+			$sidebar_form_fields['ee-msg-id']        = [
1743
+				'name'  => 'id',
1744
+				'input' => 'hidden',
1745
+				'type'  => 'int',
1746
+				'value' => $GRP_ID,
1747
+			];
1748
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
+				'name'  => $action . '_nonce',
1750
+				'input' => 'hidden',
1751
+				'type'  => 'string',
1752
+				'value' => wp_create_nonce($action . '_nonce'),
1753
+			];
1754
+
1755
+			$template_switch = $this->request->getRequestParam('template_switch');
1756
+			if ($template_switch) {
1757
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1758
+					'name'  => 'template_switch',
1759
+					'input' => 'hidden',
1760
+					'type'  => 'int',
1761
+					'value' => 1,
1762
+				];
1763
+			}
1764
+
1765
+
1766
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
+		} //end if ( !empty($template_field_structure) )
1769
+
1770
+		// set extra content for publish box
1771
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
+		$this->_set_publish_post_box_vars(
1773
+			'id',
1774
+			$GRP_ID,
1775
+			false,
1776
+			add_query_arg(
1777
+				['action' => 'global_mtps'],
1778
+				$this->_admin_base_url
1779
+			)
1780
+		);
1781
+
1782
+		// add preview button
1783
+		$preview_url    = parent::add_query_args_and_nonce(
1784
+			[
1785
+				'message_type' => $message_template_group->message_type(),
1786
+				'messenger'    => $message_template_group->messenger(),
1787
+				'context'      => $context,
1788
+				'GRP_ID'       => $GRP_ID,
1789
+				'evt_id'       => $EVT_ID ?: false,
1790
+				'action'       => 'preview_message',
1791
+			],
1792
+			$this->_admin_base_url
1793
+		);
1794
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
+						  . esc_html__('Preview', 'event_espresso')
1796
+						  . '</a>';
1797
+
1798
+
1799
+		// setup context switcher
1800
+		$this->_set_context_switcher(
1801
+			$message_template_group,
1802
+			[
1803
+				'page'    => 'espresso_messages',
1804
+				'action'  => 'edit_message_template',
1805
+				'id'      => $GRP_ID,
1806
+				'evt_id'  => $EVT_ID,
1807
+				'context' => $context,
1808
+				'extra'   => $preview_button,
1809
+			]
1810
+		);
1811
+
1812
+
1813
+		// main box
1814
+		$this->_template_args['template_fields']                         = $template_fields;
1815
+		$this->_template_args['sidebar_box_id']                          = 'details';
1816
+		$this->_template_args['action']                                  = $action;
1817
+		$this->_template_args['context']                                 = $context;
1818
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
+		$this->_template_args['learn_more_about_message_templates_link'] =
1820
+			$this->_learn_more_about_message_templates_link();
1821
+
1822
+
1823
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
+			$message_template_group,
1826
+			$context,
1827
+			$context_label
1828
+		);
1829
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
+
1832
+		$this->_template_path = $this->_template_args['GRP_ID']
1833
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
+
1836
+		// send along EE_Message_Template_Group object for further template use.
1837
+		$this->_template_args['MTP'] = $message_template_group;
1838
+
1839
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
+			$this->_template_path,
1841
+			$this->_template_args,
1842
+			true
1843
+		);
1844
+
1845
+
1846
+		// finally, let's set the admin_page title
1847
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
+
1849
+
1850
+		// we need to take care of setting the shortcodes property for use elsewhere.
1851
+		$this->_set_shortcodes();
1852
+
1853
+
1854
+		// final template wrapper
1855
+		$this->display_admin_page_with_sidebar();
1856
+	}
1857
+
1858
+
1859
+	public function filter_tinymce_init($mceInit, $editor_id)
1860
+	{
1861
+		return $mceInit;
1862
+	}
1863
+
1864
+
1865
+	public function add_context_switcher()
1866
+	{
1867
+		return $this->_context_switcher;
1868
+	}
1869
+
1870
+
1871
+	/**
1872
+	 * Adds the activation/deactivation toggle for the message template context.
1873
+	 *
1874
+	 * @param EE_Message_Template_Group $message_template_group
1875
+	 * @param string                    $context
1876
+	 * @param string                    $context_label
1877
+	 * @return string
1878
+	 * @throws DomainException
1879
+	 * @throws EE_Error
1880
+	 * @throws InvalidIdentifierException
1881
+	 * @throws ReflectionException
1882
+	 */
1883
+	protected function add_active_context_element(
1884
+		EE_Message_Template_Group $message_template_group,
1885
+		$context,
1886
+		$context_label
1887
+	) {
1888
+		$template_args = [
1889
+			'context'                   => $context,
1890
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
+			'is_active'                 => $message_template_group->is_context_active($context),
1892
+			'on_off_action'             => $message_template_group->is_context_active($context)
1893
+				? 'context-off'
1894
+				: 'context-on',
1895
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
+			'message_template_group_id' => $message_template_group->ID(),
1897
+		];
1898
+		return EEH_Template::display_template(
1899
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
+			$template_args,
1901
+			true
1902
+		);
1903
+	}
1904
+
1905
+
1906
+	/**
1907
+	 * Ajax callback for `toggle_context_template` ajax action.
1908
+	 * Handles toggling the message context on or off.
1909
+	 *
1910
+	 * @throws EE_Error
1911
+	 * @throws InvalidArgumentException
1912
+	 * @throws InvalidDataTypeException
1913
+	 * @throws InvalidIdentifierException
1914
+	 * @throws InvalidInterfaceException
1915
+	 */
1916
+	public function toggle_context_template()
1917
+	{
1918
+		$success = true;
1919
+		// check for required data
1920
+		if (
1921
+			! (
1922
+				$this->request->requestParamIsSet('message_template_group_id')
1923
+				&& $this->request->requestParamIsSet('context')
1924
+				&& $this->request->requestParamIsSet('status')
1925
+			)
1926
+		) {
1927
+			EE_Error::add_error(
1928
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
+				__FILE__,
1930
+				__FUNCTION__,
1931
+				__LINE__
1932
+			);
1933
+			$success = false;
1934
+		}
1935
+
1936
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
+		$context = $this->request->getRequestParam('context', '');
1938
+		$status  = $this->request->getRequestParam('status', '');
1939
+
1940
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
+
1942
+		if ($status !== 'off' && $status !== 'on') {
1943
+			EE_Error::add_error(
1944
+				sprintf(
1945
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
+					$status
1947
+				),
1948
+				__FILE__,
1949
+				__FUNCTION__,
1950
+				__LINE__
1951
+			);
1952
+			$success = false;
1953
+		}
1954
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
+			EE_Error::add_error(
1958
+				sprintf(
1959
+					esc_html__(
1960
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
+						'event_espresso'
1962
+					),
1963
+					$message_template_group_id,
1964
+					'EE_Message_Template_Group'
1965
+				),
1966
+				__FILE__,
1967
+				__FUNCTION__,
1968
+				__LINE__
1969
+			);
1970
+			$success = false;
1971
+		}
1972
+		if ($success) {
1973
+			$success = $status === 'off'
1974
+				? $message_template_group->deactivate_context($context)
1975
+				: $message_template_group->activate_context($context);
1976
+		}
1977
+		$this->_template_args['success'] = $success;
1978
+		$this->_return_json();
1979
+	}
1980
+
1981
+
1982
+	public function _add_form_element_before()
1983
+	{
1984
+		return '<form method="post" action="'
1985
+			   . $this->_template_args['edit_message_template_form_url']
1986
+			   . '" id="ee-msg-edit-frm">';
1987
+	}
1988
+
1989
+
1990
+	public function _add_form_element_after()
1991
+	{
1992
+		return '</form>';
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * This executes switching the template pack for a message template.
1998
+	 *
1999
+	 * @throws EE_Error
2000
+	 * @throws InvalidDataTypeException
2001
+	 * @throws InvalidInterfaceException
2002
+	 * @throws InvalidArgumentException
2003
+	 * @throws ReflectionException
2004
+	 * @since 4.5.0
2005
+	 */
2006
+	public function switch_template_pack()
2007
+	{
2008
+
2009
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2011
+
2012
+		// verify we have needed values.
2013
+		if (empty($GRP_ID) || empty($template_pack)) {
2014
+			$this->_template_args['error'] = true;
2015
+			EE_Error::add_error(
2016
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
+				__FILE__,
2018
+				__FUNCTION__,
2019
+				__LINE__
2020
+			);
2021
+		} else {
2022
+			// get template, set the new template_pack and then reset to default
2023
+			/** @var EE_Message_Template_Group $message_template_group */
2024
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
+
2026
+			$message_template_group->set_template_pack_name($template_pack);
2027
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2029
+
2030
+			$query_args = $this->_reset_to_default_template();
2031
+
2032
+			if (empty($query_args['id'])) {
2033
+				EE_Error::add_error(
2034
+					esc_html__(
2035
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
+						'event_espresso'
2037
+					),
2038
+					__FILE__,
2039
+					__FUNCTION__,
2040
+					__LINE__
2041
+				);
2042
+				$this->_template_args['error'] = true;
2043
+			} else {
2044
+				$template_label       = $message_template_group->get_template_pack()->label;
2045
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
+				EE_Error::add_success(
2047
+					sprintf(
2048
+						esc_html__(
2049
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
+							'event_espresso'
2051
+						),
2052
+						$template_label,
2053
+						$template_pack_labels->template_pack
2054
+					)
2055
+				);
2056
+				// generate the redirect url for js.
2057
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
+
2059
+				$this->_template_args['data']['redirect_url'] = $url;
2060
+				$this->_template_args['success']              = true;
2061
+			}
2062
+
2063
+			$this->_return_json();
2064
+		}
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
+	 * they want.
2071
+	 *
2072
+	 * @access protected
2073
+	 * @return array|void
2074
+	 * @throws EE_Error
2075
+	 * @throws InvalidArgumentException
2076
+	 * @throws InvalidDataTypeException
2077
+	 * @throws InvalidInterfaceException
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	protected function _reset_to_default_template()
2081
+	{
2082
+		$templates    = [];
2083
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
+		$messenger    = $this->request->getRequestParam('msgr');
2085
+		$message_type = $this->request->getRequestParam('mt');
2086
+		// we need to make sure we've got the info we need.
2087
+		if (! ($GRP_ID && $messenger && $message_type)) {
2088
+			EE_Error::add_error(
2089
+				esc_html__(
2090
+					'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.',
2091
+					'event_espresso'
2092
+				),
2093
+				__FILE__,
2094
+				__FUNCTION__,
2095
+				__LINE__
2096
+			);
2097
+		}
2098
+
2099
+		// all templates will be reset to whatever the defaults are
2100
+		// for the global template matching the messenger and message type.
2101
+		$success = ! empty($GRP_ID);
2102
+
2103
+		if ($success) {
2104
+			// let's first determine if the incoming template is a global template,
2105
+			// if it isn't then we need to get the global template matching messenger and message type.
2106
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
+
2108
+
2109
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
+
2112
+			if ($success) {
2113
+				// if successfully deleted, lets generate the new ones.
2114
+				// Note. We set GLOBAL to true, because resets on ANY template
2115
+				// will use the related global template defaults for regeneration.
2116
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2117
+				// HOWEVER, we DO keep the template pack and template variation set
2118
+				// for the current custom template when resetting.
2119
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
+			}
2121
+		}
2122
+
2123
+		// any error messages?
2124
+		if (! $success) {
2125
+			EE_Error::add_error(
2126
+				esc_html__(
2127
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2128
+					'event_espresso'
2129
+				),
2130
+				__FILE__,
2131
+				__FUNCTION__,
2132
+				__LINE__
2133
+			);
2134
+		}
2135
+
2136
+		// all good, let's add a success message!
2137
+		if ($success && ! empty($templates)) {
2138
+			// the info for the template we generated is the first element in the returned array
2139
+			EE_Error::overwrite_success();
2140
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
+		}
2142
+
2143
+
2144
+		$query_args = [
2145
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
+		];
2149
+
2150
+		// if called via ajax then we return query args otherwise redirect
2151
+		if ($this->request->isAjax()) {
2152
+			return $query_args;
2153
+		}
2154
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2155
+	}
2156
+
2157
+
2158
+	/**
2159
+	 * Retrieve and set the message preview for display.
2160
+	 *
2161
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
+	 * @return string
2163
+	 * @throws ReflectionException
2164
+	 * @throws EE_Error
2165
+	 * @throws InvalidArgumentException
2166
+	 * @throws InvalidDataTypeException
2167
+	 * @throws InvalidInterfaceException
2168
+	 */
2169
+	public function _preview_message($send = false)
2170
+	{
2171
+		// first make sure we've got the necessary parameters
2172
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
+			EE_Error::add_error(
2175
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
+				__FILE__,
2177
+				__FUNCTION__,
2178
+				__LINE__
2179
+			);
2180
+		}
2181
+
2182
+		$context = $this->request->getRequestParam('context');
2183
+		// get the preview!
2184
+		$preview = EED_Messages::preview_message(
2185
+			$this->_active_message_type_name,
2186
+			$context,
2187
+			$this->_active_messenger_name,
2188
+			$send
2189
+		);
2190
+
2191
+		if ($send) {
2192
+			return $preview;
2193
+		}
2194
+
2195
+		// if we have an evt_id set on the request, use it.
2196
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
+
2198
+		// let's add a button to go back to the edit view
2199
+		$query_args             = [
2200
+			'id'      => $GRP_ID,
2201
+			'evt_id'  => $EVT_ID,
2202
+			'context' => $context,
2203
+			'action'  => 'edit_message_template',
2204
+		];
2205
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
+		$preview_button         = '<a href="'
2207
+								  . $go_back_url
2208
+								  . '" class="button-secondary messages-preview-go-back-button">'
2209
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2210
+								  . '</a>';
2211
+		$message_types          = $this->get_installed_message_types();
2212
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2214
+			? ucwords($active_messenger->label['singular'])
2215
+			: esc_html__('Unknown Messenger', 'event_espresso');
2216
+		// let's provide a helpful title for context
2217
+		$preview_title = sprintf(
2218
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
+			$active_messenger_label,
2220
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
+		);
2222
+		if (empty($preview)) {
2223
+			$this->noEventsErrorMessage();
2224
+		}
2225
+		// setup display of preview.
2226
+		$this->_admin_page_title                    = $preview_title;
2227
+		$this->_template_args['admin_page_title']   = $preview_title;
2228
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
+		$this->_template_args['data']['force_json'] = true;
2230
+
2231
+		return '';
2232
+	}
2233
+
2234
+
2235
+	/**
2236
+	 * Used to set an error if there are no events available for generating a preview/test send.
2237
+	 *
2238
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
+	 */
2240
+	protected function noEventsErrorMessage($test_send = false)
2241
+	{
2242
+		$events_url = parent::add_query_args_and_nonce(
2243
+			[
2244
+				'action' => 'default',
2245
+				'page'   => 'espresso_events',
2246
+			],
2247
+			admin_url('admin.php')
2248
+		);
2249
+		$message    = $test_send
2250
+			? esc_html__(
2251
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
+				'event_espresso'
2253
+			)
2254
+			: esc_html__(
2255
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
+				'event_espresso'
2257
+			);
2258
+
2259
+		EE_Error::add_attention(
2260
+			sprintf(
2261
+				$message,
2262
+				"<a href='" . esc_url_raw($events_url) . "'>",
2263
+				'</a>'
2264
+			)
2265
+		);
2266
+	}
2267
+
2268
+
2269
+	/**
2270
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
+	 * gets called automatically.
2272
+	 *
2273
+	 * @return void
2274
+	 * @throws EE_Error
2275
+	 * @since 4.5.0
2276
+	 *
2277
+	 */
2278
+	protected function _display_preview_message()
2279
+	{
2280
+		$this->display_admin_page_with_no_sidebar();
2281
+	}
2282
+
2283
+
2284
+	/**
2285
+	 * registers metaboxes that should show up on the "edit_message_template" page
2286
+	 *
2287
+	 * @access protected
2288
+	 * @return void
2289
+	 */
2290
+	protected function _register_edit_meta_boxes()
2291
+	{
2292
+		add_meta_box(
2293
+			'mtp_valid_shortcodes',
2294
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2295
+			[$this, 'shortcode_meta_box'],
2296
+			$this->_current_screen->id,
2297
+			'side'
2298
+		);
2299
+		add_meta_box(
2300
+			'mtp_extra_actions',
2301
+			esc_html__('Extra Actions', 'event_espresso'),
2302
+			[$this, 'extra_actions_meta_box'],
2303
+			$this->_current_screen->id,
2304
+			'side',
2305
+			'high'
2306
+		);
2307
+		add_meta_box(
2308
+			'mtp_templates',
2309
+			esc_html__('Template Styles', 'event_espresso'),
2310
+			[$this, 'template_pack_meta_box'],
2311
+			$this->_current_screen->id,
2312
+			'side',
2313
+			'high'
2314
+		);
2315
+	}
2316
+
2317
+
2318
+	/**
2319
+	 * metabox content for all template pack and variation selection.
2320
+	 *
2321
+	 * @return void
2322
+	 * @throws DomainException
2323
+	 * @throws EE_Error
2324
+	 * @throws InvalidArgumentException
2325
+	 * @throws ReflectionException
2326
+	 * @throws InvalidDataTypeException
2327
+	 * @throws InvalidInterfaceException
2328
+	 * @since 4.5.0
2329
+	 */
2330
+	public function template_pack_meta_box()
2331
+	{
2332
+		$this->_set_message_template_group();
2333
+
2334
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
+
2336
+		$tp_select_values = [];
2337
+
2338
+		foreach ($tp_collection as $tp) {
2339
+			// only include template packs that support this messenger and message type!
2340
+			$supports = $tp->get_supports();
2341
+			if (
2342
+				! isset($supports[ $this->_message_template_group->messenger() ])
2343
+				|| ! in_array(
2344
+					$this->_message_template_group->message_type(),
2345
+					$supports[ $this->_message_template_group->messenger() ],
2346
+					true
2347
+				)
2348
+			) {
2349
+				// not supported
2350
+				continue;
2351
+			}
2352
+
2353
+			$tp_select_values[] = [
2354
+				'text' => $tp->label,
2355
+				'id'   => $tp->dbref,
2356
+			];
2357
+		}
2358
+
2359
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
+		// the default template pack.  This still allows for the odd template pack to override.
2361
+		if (empty($tp_select_values)) {
2362
+			$tp_select_values[] = [
2363
+				'text' => esc_html__('Default', 'event_espresso'),
2364
+				'id'   => 'default',
2365
+			];
2366
+		}
2367
+
2368
+		// setup variation select values for the currently selected template.
2369
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
+			$this->_message_template_group->messenger(),
2371
+			$this->_message_template_group->message_type()
2372
+		);
2373
+		$variations_select_values = [];
2374
+		foreach ($variations as $variation => $label) {
2375
+			$variations_select_values[] = [
2376
+				'text' => $label,
2377
+				'id'   => $variation,
2378
+			];
2379
+		}
2380
+
2381
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
+
2383
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
+			'MTP_template_pack',
2385
+			$tp_select_values,
2386
+			$this->_message_template_group->get_template_pack_name()
2387
+		);
2388
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
+			'MTP_template_variation',
2390
+			$variations_select_values,
2391
+			$this->_message_template_group->get_template_pack_variation()
2392
+		);
2393
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
+
2398
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
+
2400
+		EEH_Template::display_template($template, $template_args);
2401
+	}
2402
+
2403
+
2404
+	/**
2405
+	 * This meta box holds any extra actions related to Message Templates
2406
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2407
+	 *
2408
+	 * @access  public
2409
+	 * @return void
2410
+	 * @throws EE_Error
2411
+	 */
2412
+	public function extra_actions_meta_box()
2413
+	{
2414
+		$template_form_fields = [];
2415
+
2416
+		$extra_args = [
2417
+			'msgr'   => $this->_message_template_group->messenger(),
2418
+			'mt'     => $this->_message_template_group->message_type(),
2419
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
+		];
2421
+		// first we need to see if there are any fields
2422
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
+
2424
+		if (! empty($fields)) {
2425
+			// yup there be fields
2426
+			foreach ($fields as $field => $config) {
2427
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
+				$default  = isset($config['default']) ? $config['default'] : '';
2430
+				$default  = isset($config['value']) ? $config['value'] : $default;
2431
+
2432
+				// if type is hidden and the value is empty
2433
+				// something may have gone wrong so let's correct with the defaults
2434
+				$fix                = $config['input'] === 'hidden'
2435
+									  && isset($existing[ $field ])
2436
+									  && empty($existing[ $field ])
2437
+					? $default
2438
+					: '';
2439
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
+					? $existing[ $field ]
2441
+					: $fix;
2442
+
2443
+				$template_form_fields[ $field_id ] = [
2444
+					'name'       => 'test_settings_fld[' . $field . ']',
2445
+					'label'      => $config['label'],
2446
+					'input'      => $config['input'],
2447
+					'type'       => $config['type'],
2448
+					'required'   => $config['required'],
2449
+					'validation' => $config['validation'],
2450
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
+					'css_class'  => $config['css_class'],
2452
+					'options'    => isset($config['options']) ? $config['options'] : [],
2453
+					'default'    => $default,
2454
+					'format'     => $config['format'],
2455
+				];
2456
+			}
2457
+		}
2458
+
2459
+		$test_settings_html = ! empty($template_form_fields)
2460
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
+			: '';
2462
+
2463
+		// print out $test_settings_fields
2464
+		if (! empty($test_settings_html)) {
2465
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
+			$test_settings_html .= 'name="test_button" value="';
2467
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2469
+		}
2470
+
2471
+		// and button
2472
+		$test_settings_html .= '<p>';
2473
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
+		$test_settings_html .= '</p>';
2475
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
+		$test_settings_html .= $this->get_action_link_or_button(
2477
+			'reset_to_default',
2478
+			'reset',
2479
+			$extra_args,
2480
+			'button-primary reset-default-button'
2481
+		);
2482
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2483
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
+	}
2485
+
2486
+
2487
+	/**
2488
+	 * This returns the shortcode selector skeleton for a given context and field.
2489
+	 *
2490
+	 * @param string $field           The name of the field retrieving shortcodes for.
2491
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
+	 * @return string
2493
+	 * @throws DomainException
2494
+	 * @throws EE_Error
2495
+	 * @throws InvalidArgumentException
2496
+	 * @throws ReflectionException
2497
+	 * @throws InvalidDataTypeException
2498
+	 * @throws InvalidInterfaceException
2499
+	 * @since 4.9.rc.000
2500
+	 */
2501
+	protected function _get_shortcode_selector($field, $linked_input_id)
2502
+	{
2503
+		$template_args = [
2504
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2505
+			'fieldname'       => $field,
2506
+			'linked_input_id' => $linked_input_id,
2507
+		];
2508
+
2509
+		return EEH_Template::display_template(
2510
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
+			$template_args,
2512
+			true
2513
+		);
2514
+	}
2515
+
2516
+
2517
+	/**
2518
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
+	 * page)
2520
+	 *
2521
+	 * @access public
2522
+	 * @return void
2523
+	 * @throws EE_Error
2524
+	 * @throws InvalidArgumentException
2525
+	 * @throws ReflectionException
2526
+	 * @throws InvalidDataTypeException
2527
+	 * @throws InvalidInterfaceException
2528
+	 */
2529
+	public function shortcode_meta_box()
2530
+	{
2531
+		$shortcodes = $this->_get_shortcodes([], false);
2532
+		// just make sure the shortcodes property is set
2533
+		// $messenger = $this->_message_template_group->messenger_obj();
2534
+		// now let's set the content depending on the status of the shortcodes array
2535
+		if (empty($shortcodes)) {
2536
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
+			return;
2538
+		}
2539
+		?>
2540 2540
         <div style="float:right; margin-top:10px">
2541 2541
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2542
-            ?>
2542
+			?>
2543 2543
         </div>
2544 2544
         <p class="small-text">
2545 2545
             <?php printf(
2546
-                esc_html__(
2547
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
-                    'event_espresso'
2549
-                ),
2550
-                '<span class="dashicons dashicons-menu"></span>'
2551
-            ); ?>
2546
+				esc_html__(
2547
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
+					'event_espresso'
2549
+				),
2550
+				'<span class="dashicons dashicons-menu"></span>'
2551
+			); ?>
2552 2552
         </p>
2553 2553
         <?php
2554
-    }
2555
-
2556
-
2557
-    /**
2558
-     * used to set the $_shortcodes property for when its needed elsewhere.
2559
-     *
2560
-     * @access protected
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     * @throws InvalidArgumentException
2564
-     * @throws ReflectionException
2565
-     * @throws InvalidDataTypeException
2566
-     * @throws InvalidInterfaceException
2567
-     */
2568
-    protected function _set_shortcodes()
2569
-    {
2570
-
2571
-        // no need to run this if the property is already set
2572
-        if (! empty($this->_shortcodes)) {
2573
-            return;
2574
-        }
2575
-
2576
-        $this->_shortcodes = $this->_get_shortcodes();
2577
-    }
2578
-
2579
-
2580
-    /**
2581
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
-     * property)
2583
-     *
2584
-     * @access  protected
2585
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
-     *                         for. Defaults to all (for the given context)
2587
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
-     *                         true just an array of shortcode/label pairs.
2590
-     * @throws EE_Error
2591
-     * @throws InvalidArgumentException
2592
-     * @throws ReflectionException
2593
-     * @throws InvalidDataTypeException
2594
-     * @throws InvalidInterfaceException
2595
-     */
2596
-    protected function _get_shortcodes($fields = [], $merged = true)
2597
-    {
2598
-        $this->_set_message_template_group();
2599
-
2600
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2601
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
-        if (empty($GRP_ID)) {
2603
-            return [];
2604
-        }
2605
-        $context = $this->request->getRequestParam(
2606
-            'messenger',
2607
-            key($this->_message_template_group->contexts_config())
2608
-        );
2609
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
-    }
2611
-
2612
-
2613
-    /**
2614
-     * This sets the _message_template property (containing the called message_template object)
2615
-     *
2616
-     * @access protected
2617
-     * @return void
2618
-     * @throws EE_Error
2619
-     * @throws InvalidArgumentException
2620
-     * @throws ReflectionException
2621
-     * @throws InvalidDataTypeException
2622
-     * @throws InvalidInterfaceException
2623
-     */
2624
-    protected function _set_message_template_group()
2625
-    {
2626
-        // get out if this is already set.
2627
-        if (! empty($this->_message_template_group)) {
2628
-            return;
2629
-        }
2630
-
2631
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
-
2634
-        // let's get the message templates
2635
-        $this->_message_template_group = ! empty($GRP_ID)
2636
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
-            : $this->getMtgModel()->create_default_object();
2638
-
2639
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2640
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * sets up a context switcher for edit forms
2646
-     *
2647
-     * @access  protected
2648
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
-     * @param array                     $args                  various things the context switcher needs.
2650
-     * @throws EE_Error
2651
-     */
2652
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
-    {
2654
-        $context_details = $template_group_object->contexts_config();
2655
-        $context_label   = $template_group_object->context_label();
2656
-        ob_start();
2657
-        ?>
2554
+	}
2555
+
2556
+
2557
+	/**
2558
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2559
+	 *
2560
+	 * @access protected
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 * @throws InvalidArgumentException
2564
+	 * @throws ReflectionException
2565
+	 * @throws InvalidDataTypeException
2566
+	 * @throws InvalidInterfaceException
2567
+	 */
2568
+	protected function _set_shortcodes()
2569
+	{
2570
+
2571
+		// no need to run this if the property is already set
2572
+		if (! empty($this->_shortcodes)) {
2573
+			return;
2574
+		}
2575
+
2576
+		$this->_shortcodes = $this->_get_shortcodes();
2577
+	}
2578
+
2579
+
2580
+	/**
2581
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
+	 * property)
2583
+	 *
2584
+	 * @access  protected
2585
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
+	 *                         for. Defaults to all (for the given context)
2587
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
+	 *                         true just an array of shortcode/label pairs.
2590
+	 * @throws EE_Error
2591
+	 * @throws InvalidArgumentException
2592
+	 * @throws ReflectionException
2593
+	 * @throws InvalidDataTypeException
2594
+	 * @throws InvalidInterfaceException
2595
+	 */
2596
+	protected function _get_shortcodes($fields = [], $merged = true)
2597
+	{
2598
+		$this->_set_message_template_group();
2599
+
2600
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2601
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
+		if (empty($GRP_ID)) {
2603
+			return [];
2604
+		}
2605
+		$context = $this->request->getRequestParam(
2606
+			'messenger',
2607
+			key($this->_message_template_group->contexts_config())
2608
+		);
2609
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
+	}
2611
+
2612
+
2613
+	/**
2614
+	 * This sets the _message_template property (containing the called message_template object)
2615
+	 *
2616
+	 * @access protected
2617
+	 * @return void
2618
+	 * @throws EE_Error
2619
+	 * @throws InvalidArgumentException
2620
+	 * @throws ReflectionException
2621
+	 * @throws InvalidDataTypeException
2622
+	 * @throws InvalidInterfaceException
2623
+	 */
2624
+	protected function _set_message_template_group()
2625
+	{
2626
+		// get out if this is already set.
2627
+		if (! empty($this->_message_template_group)) {
2628
+			return;
2629
+		}
2630
+
2631
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
+
2634
+		// let's get the message templates
2635
+		$this->_message_template_group = ! empty($GRP_ID)
2636
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
+			: $this->getMtgModel()->create_default_object();
2638
+
2639
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2640
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * sets up a context switcher for edit forms
2646
+	 *
2647
+	 * @access  protected
2648
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
+	 * @param array                     $args                  various things the context switcher needs.
2650
+	 * @throws EE_Error
2651
+	 */
2652
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
+	{
2654
+		$context_details = $template_group_object->contexts_config();
2655
+		$context_label   = $template_group_object->context_label();
2656
+		ob_start();
2657
+		?>
2658 2658
         <div class="ee-msg-switcher-container">
2659 2659
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2660 2660
                 <?php
2661
-                foreach ($args as $name => $value) {
2662
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2663
-                        continue;
2664
-                    }
2665
-                    ?>
2661
+				foreach ($args as $name => $value) {
2662
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2663
+						continue;
2664
+					}
2665
+					?>
2666 2666
                     <input type="hidden"
2667 2667
                            name="<?php echo esc_attr($name); ?>"
2668 2668
                            value="<?php echo esc_attr($value); ?>"
2669 2669
                     />
2670 2670
                     <?php
2671
-                }
2672
-                // setup nonce_url
2673
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
-                ?>
2671
+				}
2672
+				// setup nonce_url
2673
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
+				?>
2676 2676
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2677 2677
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2678 2678
                 </label>
2679 2679
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2680 2680
                     <?php
2681
-                    $context_templates = $template_group_object->context_templates();
2682
-                    if (is_array($context_templates)) :
2683
-                        foreach ($context_templates as $context => $template_fields) :
2684
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2685
-                            ?>
2681
+					$context_templates = $template_group_object->context_templates();
2682
+					if (is_array($context_templates)) :
2683
+						foreach ($context_templates as $context => $template_fields) :
2684
+							$checked = ($context === $args['context']) ? 'selected' : '';
2685
+							?>
2686 2686
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2687 2687
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690
-                    endif; ?>
2690
+					endif; ?>
2691 2691
                 </select>
2692 2692
                 <?php $button_text = sprintf(
2693
-                    esc_html__('Switch %s', 'event_espresso'),
2694
-                    ucwords($context_label['label'])
2695
-                ); ?>
2693
+					esc_html__('Switch %s', 'event_espresso'),
2694
+					ucwords($context_label['label'])
2695
+				); ?>
2696 2696
                 <input class='button-secondary'
2697 2697
                        id="submit-msg-context-switcher-sbmt"
2698 2698
                        type="submit"
@@ -2702,1994 +2702,1994 @@  discard block
 block discarded – undo
2702 2702
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2703 2703
         </div> <!-- end .ee-msg-switcher-container -->
2704 2704
         <?php
2705
-        $this->_context_switcher = ob_get_clean();
2706
-    }
2707
-
2708
-
2709
-    /**
2710
-     * @param bool $new
2711
-     * @throws EE_Error
2712
-     * @throws ReflectionException
2713
-     */
2714
-    protected function _insert_or_update_message_template($new = false)
2715
-    {
2716
-        $form_data    = $this->getMessageTemplateFormData();
2717
-        $GRP_ID       = $form_data['GRP_ID'];
2718
-        $messenger    = $form_data['MTP_messenger'];
2719
-        $message_type = $form_data['MTP_message_type'];
2720
-        $context      = $form_data['MTP_context'];
2721
-
2722
-        // if this is "new" then we need to generate the default contexts
2723
-        // for the selected messenger/message_type for user to edit.
2724
-        [$success, $query_args] = $new
2725
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
-
2728
-        $success     = $success ? 1 : 0;
2729
-        $action_desc = $new ? 'created' : 'updated';
2730
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
-
2733
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * retrieve and sanitize form data
2739
-     *
2740
-     * @return array
2741
-     * @since 4.10.29.p
2742
-     */
2743
-    protected function getMessageTemplateFormData()
2744
-    {
2745
-        return [
2746
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
-        ];
2756
-    }
2757
-
2758
-
2759
-    /**
2760
-     * @param int    $GRP_ID
2761
-     * @param string $messenger
2762
-     * @param string $message_type
2763
-     * @return array no return on AJAX requests
2764
-     * @throws EE_Error
2765
-     * @throws ReflectionException
2766
-     * @since 4.10.29.p
2767
-     */
2768
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
-    {
2770
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
-        $success       = ! empty($new_templates);
2772
-
2773
-        // we return things differently if doing ajax
2774
-        if ($this->request->isAjax()) {
2775
-            $this->_template_args['success'] = $success;
2776
-            $this->_template_args['error']   = ! $success;
2777
-            $this->_template_args['content'] = '';
2778
-            $this->_template_args['data']    = [
2779
-                'grpID'        => $new_templates['GRP_ID'],
2780
-                'templateName' => $new_templates['template_name'],
2781
-            ];
2782
-            if ($success) {
2783
-                EE_Error::overwrite_success();
2784
-                EE_Error::add_success(
2785
-                    esc_html__(
2786
-                        '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.',
2787
-                        'event_espresso'
2788
-                    )
2789
-                );
2790
-            }
2791
-            $this->_return_json();
2792
-        }
2793
-        return [
2794
-            $success,
2795
-            // 'query_args'
2796
-            [
2797
-                'id'      => $new_templates['GRP_ID'],
2798
-                'context' => $new_templates['MTP_context'],
2799
-                'action'  => 'edit_message_template',
2800
-            ],
2801
-        ];
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * @param int    $GRP_ID
2807
-     * @param string $messenger
2808
-     * @param string $message_type
2809
-     * @param string $context
2810
-     * @param array  $form_data
2811
-     * @return array
2812
-     * @throws EE_Error
2813
-     * @since 4.10.29.p
2814
-     */
2815
-    private function updateExistingTemplates(
2816
-        $GRP_ID,
2817
-        $messenger,
2818
-        $message_type,
2819
-        $context,
2820
-        array $form_data
2821
-    ) {
2822
-        $success         = false;
2823
-        $template_fields = $this->getTemplateFields();
2824
-        if ($template_fields) {
2825
-            // if field data is valid, then success will be true
2826
-            $success = $this->validateTemplateFields(
2827
-                $messenger,
2828
-                $message_type,
2829
-                $context,
2830
-                $template_fields
2831
-            );
2832
-            if ($success) {
2833
-                $field_data = [];
2834
-                foreach ($template_fields as $template_field => $content) {
2835
-                    // combine top-level form data with content for this field
2836
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
-                }
2839
-                // we can use the last set_column_values for the MTPG update
2840
-                // (because its the same for all of these specific MTPs)
2841
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
-            }
2843
-        }
2844
-
2845
-        return [
2846
-            $success,
2847
-            // 'query_args'
2848
-            [
2849
-                'id'      => $GRP_ID,
2850
-                'context' => $context,
2851
-                'action'  => 'edit_message_template',
2852
-            ],
2853
-        ];
2854
-    }
2855
-
2856
-
2857
-    /**
2858
-     * @return array
2859
-     * @since 4.10.29.p
2860
-     */
2861
-    private function getTemplateFields()
2862
-    {
2863
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
-        if (empty($template_fields)) {
2865
-            EE_Error::add_error(
2866
-                esc_html__(
2867
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
-                    'event_espresso'
2869
-                ),
2870
-                __FILE__,
2871
-                __FUNCTION__,
2872
-                __LINE__
2873
-            );
2874
-            return null;
2875
-        }
2876
-        // messages content is expected to be escaped
2877
-        return EEH_Array::addSlashesRecursively($template_fields);
2878
-    }
2879
-
2880
-
2881
-    /**
2882
-     * @param string $messenger
2883
-     * @param string $message_type
2884
-     * @param string $context
2885
-     * @param array  $template_fields
2886
-     * @return bool
2887
-     * @throws EE_Error
2888
-     * @since   4.10.29.p
2889
-     */
2890
-    private function validateTemplateFields(
2891
-        $messenger,
2892
-        $message_type,
2893
-        $context,
2894
-        array $template_fields
2895
-    ) {
2896
-        // first validate all fields!
2897
-        // this filter allows client code to add its own validation to the template fields as well.
2898
-        // returning an empty array means everything passed validation.
2899
-        // errors in validation should be represented in an array with the following shape:
2900
-        // array(
2901
-        //   'fieldname' => array(
2902
-        //          'msg' => 'error message'
2903
-        //          'value' => 'value for field producing error'
2904
-        // )
2905
-        $custom_validation = (array) apply_filters(
2906
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
-            [],
2908
-            $template_fields,
2909
-            $context,
2910
-            $messenger,
2911
-            $message_type
2912
-        );
2913
-
2914
-        $system_validation = $this->getMtgModel()->validate(
2915
-            $template_fields,
2916
-            $context,
2917
-            $messenger,
2918
-            $message_type
2919
-        );
2920
-
2921
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
-        $validates         = array_merge($custom_validation, $system_validation);
2923
-
2924
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
-        //  WE need to make sure there is no actual error messages in validates.
2927
-        if (empty($validates)) {
2928
-            return true;
2929
-        }
2930
-
2931
-        // add the transient so when the form loads we know which fields to highlight
2932
-        $this->_add_transient('edit_message_template', $validates);
2933
-        // setup notices
2934
-        foreach ($validates as $error) {
2935
-            if (isset($error['msg'])) {
2936
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
-            }
2938
-        }
2939
-        return false;
2940
-    }
2941
-
2942
-
2943
-    /**
2944
-     * @param array $field_data
2945
-     * @param array $form_data
2946
-     * @return array
2947
-     * @since   4.10.29.p
2948
-     */
2949
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
-    {
2951
-        return $form_data + [
2952
-                'MTP_ID'             => $field_data['MTP_ID'],
2953
-                'MTP_template_field' => $field_data['name'],
2954
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2956
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
-                    : $field_data['content'],
2958
-            ];
2959
-    }
2960
-
2961
-
2962
-    /**
2963
-     * @param string $template_field
2964
-     * @param array  $form_data
2965
-     * @return bool
2966
-     * @throws EE_Error
2967
-     * @since 4.10.29.p
2968
-     */
2969
-    private function updateMessageTemplates($template_field, array $form_data)
2970
-    {
2971
-        $MTP_ID                  = $form_data['MTP_ID'];
2972
-        $message_template_fields = [
2973
-            'GRP_ID'             => $form_data['GRP_ID'],
2974
-            'MTP_template_field' => $form_data['MTP_template_field'],
2975
-            'MTP_context'        => $form_data['MTP_context'],
2976
-            'MTP_content'        => $form_data['MTP_content'],
2977
-        ];
2978
-
2979
-        $hasMtpID = ! empty($MTP_ID);
2980
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2981
-        // this has already been through the template field validator and sanitized, so it will be
2982
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
-        // message template field in a messenger/message type and existing users don't have the
2984
-        // default setup for it.
2985
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
-        $updated = $hasMtpID
2987
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
-            : $this->getMtpModel()->insert($message_template_fields);
2989
-
2990
-        $insert_failed = ! $hasMtpID && ! $updated;
2991
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
-        $update_failed = $hasMtpID && $updated === false;
2994
-
2995
-        if ($insert_failed || $update_failed) {
2996
-            EE_Error::add_error(
2997
-                sprintf(
2998
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
-                    $template_field
3000
-                ),
3001
-                __FILE__,
3002
-                __FUNCTION__,
3003
-                __LINE__
3004
-            );
3005
-            return false;
3006
-        }
3007
-        return true;
3008
-    }
3009
-
3010
-
3011
-    /**
3012
-     * @param array $form_data
3013
-     * @return bool
3014
-     * @throws EE_Error
3015
-     * @since 4.10.29.p
3016
-     */
3017
-    private function updateMessageTemplateGroup(array $form_data)
3018
-    {
3019
-        $GRP_ID  = $form_data['GRP_ID'];
3020
-        $updated = $this->getMtgModel()->update(
3021
-        // fields and values
3022
-            [
3023
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3024
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3025
-                'MTP_message_type' => $form_data['MTP_message_type'],
3026
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3027
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3028
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3029
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3030
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
-                'MTP_description'  => $this->request->getRequestParam(
3032
-                    'ee_msg_non_global_fields[MTP_description]',
3033
-                    ''
3034
-                ),
3035
-            ],
3036
-            // where
3037
-            [['GRP_ID' => $GRP_ID]]
3038
-        );
3039
-
3040
-        if ($updated === false) {
3041
-            EE_Error::add_error(
3042
-                sprintf(
3043
-                    esc_html__(
3044
-                        'The Message Template Group (%d) was NOT updated for some reason',
3045
-                        'event_espresso'
3046
-                    ),
3047
-                    $form_data['GRP_ID']
3048
-                ),
3049
-                __FILE__,
3050
-                __FUNCTION__,
3051
-                __LINE__
3052
-            );
3053
-            return false;
3054
-        }
3055
-        // k now we need to ensure the template_pack and template_variation fields are set.
3056
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
-
3059
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3061
-            $message_template_group->set_template_pack_name($template_pack);
3062
-            $message_template_group->set_template_pack_variation($template_variation);
3063
-        }
3064
-        return true;
3065
-    }
3066
-
3067
-
3068
-    /**
3069
-     * recursively runs wp_kses() on message template content in a model safe manner
3070
-     *
3071
-     * @param array|string $content
3072
-     * @return array|string
3073
-     * @since   4.10.29.p
3074
-     */
3075
-    private function sanitizeMessageTemplateContent($content)
3076
-    {
3077
-        if (is_array($content)) {
3078
-            foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
-            }
3081
-            return $content;
3082
-        }
3083
-        // remove slashes so wp_kses() works properly
3084
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3085
-        // so attributes using single quotes always appear invalid.
3086
-        $content = stripslashes($content);
3087
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3088
-        // But currently the models expect slashed data, so after wp_kses()
3089
-        // runs we need to re-slash the data. Sheesh.
3090
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
-        return addslashes($content);
3092
-    }
3093
-
3094
-
3095
-    /**
3096
-     * @param string $messenger
3097
-     * @param string $message_type
3098
-     * @param string $context
3099
-     * @return string
3100
-     * @since 4.10.29.p
3101
-     */
3102
-    private function generateUpdateDescription($messenger, $message_type, $context)
3103
-    {
3104
-        // need the message type and messenger objects to be able to use the labels for the notices
3105
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
-        $messenger_label  = $messenger_object instanceof EE_messenger
3107
-            ? ucwords($messenger_object->label['singular'])
3108
-            : '';
3109
-
3110
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
-        $message_type_label  = $message_type_object instanceof EE_message_type
3112
-            ? ucwords($message_type_object->label['singular'])
3113
-            : '';
3114
-
3115
-        $context   = ucwords(str_replace('_', ' ', $context));
3116
-        $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
-            : '';
3119
-        $item_desc .= 'Message Template';
3120
-        return $item_desc;
3121
-    }
3122
-
3123
-
3124
-    /**
3125
-     * @param string $messenger
3126
-     * @param string $message_type
3127
-     * @param string $context
3128
-     * @return bool
3129
-     * @throws EE_Error
3130
-     * @throws ReflectionException
3131
-     * @since 4.10.29.p
3132
-     */
3133
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
-    {
3135
-        // was a test send triggered?
3136
-        if ($this->request->requestParamIsSet('test_button')) {
3137
-            EE_Error::overwrite_success();
3138
-            $this->_do_test_send($context, $messenger, $message_type);
3139
-            return true;
3140
-        }
3141
-        return false;
3142
-    }
3143
-
3144
-
3145
-    /**
3146
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
-     *
3148
-     * @param string $context      what context being tested
3149
-     * @param string $messenger    messenger being tested
3150
-     * @param string $message_type message type being tested
3151
-     * @throws EE_Error
3152
-     * @throws InvalidArgumentException
3153
-     * @throws InvalidDataTypeException
3154
-     * @throws InvalidInterfaceException
3155
-     * @throws ReflectionException
3156
-     */
3157
-    protected function _do_test_send($context, $messenger, $message_type)
3158
-    {
3159
-        // set things up for preview
3160
-        $this->request->setRequestParam('messenger', $messenger);
3161
-        $this->request->setRequestParam('message_type', $message_type);
3162
-        $this->request->setRequestParam('context', $context);
3163
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
-
3166
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
-
3169
-        // let's save any existing fields that might be required by the messenger
3170
-        if (
3171
-            ! empty($test_settings_fld)
3172
-            && $active_messenger instanceof EE_messenger
3173
-            && apply_filters(
3174
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
-                true,
3176
-                $test_settings_fld,
3177
-                $active_messenger
3178
-            )
3179
-        ) {
3180
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3181
-        }
3182
-
3183
-        /**
3184
-         * Use filter to add additional controls on whether message can send or not
3185
-         */
3186
-        if (
3187
-            apply_filters(
3188
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
-                true,
3190
-                $context,
3191
-                $this->request->requestParams(),
3192
-                $messenger,
3193
-                $message_type
3194
-            )
3195
-        ) {
3196
-            if (EEM_Event::instance()->count() > 0) {
3197
-                $success = $this->_preview_message(true);
3198
-                if ($success) {
3199
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
-                } else {
3201
-                    EE_Error::add_error(
3202
-                        esc_html__('The test message was not sent', 'event_espresso'),
3203
-                        __FILE__,
3204
-                        __FUNCTION__,
3205
-                        __LINE__
3206
-                    );
3207
-                }
3208
-            } else {
3209
-                $this->noEventsErrorMessage(true);
3210
-            }
3211
-        }
3212
-    }
3213
-
3214
-
3215
-    /**
3216
-     * _generate_new_templates
3217
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
-     * for the event.
3220
-     *
3221
-     *
3222
-     * @param string $messenger      the messenger we are generating templates for
3223
-     * @param array  $message_types  array of message types that the templates are generated for.
3224
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
-     *                               indicate the message_template_group being used as the base.
3226
-     *
3227
-     * @param bool   $global
3228
-     *
3229
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
-     *                               encountering problems.
3231
-     * @throws EE_Error
3232
-     * @throws ReflectionException
3233
-     */
3234
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
-    {
3236
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
-        // just don't generate any templates.
3238
-        if (empty($message_types)) {
3239
-            return [];
3240
-        }
3241
-
3242
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
-        return $templates[0];
3244
-    }
3245
-
3246
-
3247
-    /**
3248
-     * [_trash_or_restore_message_template]
3249
-     *
3250
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
-     *                        an individual context (FALSE).
3253
-     * @return void
3254
-     * @throws EE_Error
3255
-     * @throws InvalidArgumentException
3256
-     * @throws InvalidDataTypeException
3257
-     * @throws InvalidInterfaceException
3258
-     */
3259
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
-    {
3261
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
-
3263
-        $success = 1;
3264
-
3265
-        // incoming GRP_IDs
3266
-        if ($all) {
3267
-            // Checkboxes
3268
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3270
-                // if array has more than one element then success message should be plural.
3271
-                // todo: what about nonce?
3272
-                $success = count($checkboxes) > 1 ? 2 : 1;
3273
-
3274
-                // cycle through checkboxes
3275
-                foreach (array_keys($checkboxes) as $GRP_ID) {
3276
-                    $trashed_or_restored = $trash
3277
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3280
-                        $success = 0;
3281
-                    }
3282
-                }
3283
-            } else {
3284
-                // grab single GRP_ID and handle
3285
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3287
-                    $trashed_or_restored = $trash
3288
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3291
-                        $success = 0;
3292
-                    }
3293
-                } else {
3294
-                    $success = 0;
3295
-                }
3296
-            }
3297
-        }
3298
-
3299
-        $action_desc = $trash
3300
-            ? esc_html__('moved to the trash', 'event_espresso')
3301
-            : esc_html__('restored', 'event_espresso');
3302
-
3303
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
-
3306
-        $item_desc = $all ? _n(
3307
-            'Message Template Group',
3308
-            'Message Template Groups',
3309
-            $success,
3310
-            'event_espresso'
3311
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
-
3313
-        $item_desc = $template_switch
3314
-            ? _n('template', 'templates', $success, 'event_espresso')
3315
-            : $item_desc;
3316
-
3317
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
-    }
3319
-
3320
-
3321
-    /**
3322
-     * [_delete_message_template]
3323
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
-     *
3325
-     * @return void
3326
-     * @throws EE_Error
3327
-     * @throws InvalidArgumentException
3328
-     * @throws InvalidDataTypeException
3329
-     * @throws InvalidInterfaceException
3330
-     * @throws ReflectionException
3331
-     */
3332
-    protected function _delete_message_template()
3333
-    {
3334
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
-
3336
-        // checkboxes
3337
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3339
-            // if array has more than one element then success message should be plural
3340
-            $success = count($checkboxes) > 1 ? 2 : 1;
3341
-
3342
-            // cycle through bulk action checkboxes
3343
-            foreach (array_keys($checkboxes) as $GRP_ID) {
3344
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
-            }
3346
-        } else {
3347
-            // grab single grp_id and delete
3348
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3350
-        }
3351
-
3352
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
-    }
3354
-
3355
-
3356
-    /**
3357
-     * helper for permanently deleting a mtP group and all related message_templates
3358
-     *
3359
-     * @param int  $GRP_ID        The group being deleted
3360
-     * @param bool $include_group whether to delete the Message Template Group as well.
3361
-     * @return bool boolean to indicate the success of the deletes or not.
3362
-     * @throws EE_Error
3363
-     * @throws InvalidArgumentException
3364
-     * @throws InvalidDataTypeException
3365
-     * @throws InvalidInterfaceException
3366
-     * @throws ReflectionException
3367
-     * @throws ReflectionException
3368
-     */
3369
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
-    {
3371
-        $success = true;
3372
-        // first let's GET this group
3373
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
-        // then delete permanently all the related Message Templates
3375
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3376
-
3377
-        if ($deleted === 0) {
3378
-            $success = false;
3379
-        }
3380
-
3381
-        // now delete permanently this particular group
3382
-
3383
-        if ($include_group && ! $MTG->delete_permanently()) {
3384
-            $success = false;
3385
-        }
3386
-
3387
-        return $success;
3388
-    }
3389
-
3390
-
3391
-    /**
3392
-     *    _learn_more_about_message_templates_link
3393
-     *
3394
-     * @access protected
3395
-     * @return string
3396
-     */
3397
-    protected function _learn_more_about_message_templates_link()
3398
-    {
3399
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3401
-               . '</a>';
3402
-    }
3403
-
3404
-
3405
-    /**
3406
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
-     * ajax and other routes.
3408
-     *
3409
-     * @return void
3410
-     * @throws DomainException
3411
-     * @throws EE_Error
3412
-     */
3413
-    protected function _settings()
3414
-    {
3415
-        $this->_set_m_mt_settings();
3416
-
3417
-        // let's setup the messenger tabs
3418
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
-            $this->_m_mt_settings['messenger_tabs'],
3420
-            'messenger_links',
3421
-            '|',
3422
-            $this->request->getRequestParam('selected_messenger', 'email')
3423
-        );
3424
-
3425
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
-
3428
-        $this->display_admin_page_with_sidebar();
3429
-    }
3430
-
3431
-
3432
-    /**
3433
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
-     *
3435
-     * @access protected
3436
-     * @return void
3437
-     * @throws DomainException
3438
-     */
3439
-    protected function _set_m_mt_settings()
3440
-    {
3441
-        // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3443
-            return;
3444
-        }
3445
-
3446
-        // get all installed messengers and message_types
3447
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3448
-        $message_types = $this->_message_resource_manager->installed_message_types();
3449
-
3450
-
3451
-        // assemble the array for the _tab_text_links helper
3452
-
3453
-        foreach ($messengers as $messenger) {
3454
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
-                'label' => ucwords($messenger->label['singular']),
3456
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
-                    ? 'messenger-active'
3458
-                    : '',
3459
-                'href'  => $messenger->name,
3460
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
-                'slug'  => $messenger->name,
3462
-                'obj'   => $messenger,
3463
-            ];
3464
-
3465
-
3466
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3467
-
3468
-            foreach ($message_types as $message_type) {
3469
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
-                // it shouldn't show in either the inactive OR active metabox.
3471
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
-                    continue;
3473
-                }
3474
-
3475
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
-                    $messenger->name,
3477
-                    $message_type->name
3478
-                )
3479
-                    ? 'active'
3480
-                    : 'inactive';
3481
-
3482
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
-                    'label'    => ucwords($message_type->label['singular']),
3484
-                    'class'    => 'message-type-' . $a_or_i,
3485
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
-                    'title'    => $a_or_i === 'active'
3489
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
-                    'content'  => $a_or_i === 'active'
3492
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3493
-                        : $this->_message_type_settings_content($message_type, $messenger),
3494
-                    'slug'     => $message_type->name,
3495
-                    'active'   => $a_or_i === 'active',
3496
-                    'obj'      => $message_type,
3497
-                ];
3498
-            }
3499
-        }
3500
-    }
3501
-
3502
-
3503
-    /**
3504
-     * This just prepares the content for the message type settings
3505
-     *
3506
-     * @param EE_message_type $message_type The message type object
3507
-     * @param EE_messenger    $messenger    The messenger object
3508
-     * @param boolean         $active       Whether the message type is active or not
3509
-     * @return string html output for the content
3510
-     * @throws DomainException
3511
-     */
3512
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
-    {
3514
-        // get message type fields
3515
-        $fields                                         = $message_type->get_admin_settings_fields();
3516
-        $settings_template_args['template_form_fields'] = '';
3517
-
3518
-        if (! empty($fields) && $active) {
3519
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
-            foreach ($fields as $fldname => $fldprops) {
3521
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
-                $template_form_field[ $field_id ] = [
3523
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3524
-                    'label'      => $fldprops['label'],
3525
-                    'input'      => $fldprops['field_type'],
3526
-                    'type'       => $fldprops['value_type'],
3527
-                    'required'   => $fldprops['required'],
3528
-                    'validation' => $fldprops['validation'],
3529
-                    'value'      => isset($existing_settings[ $fldname ])
3530
-                        ? $existing_settings[ $fldname ]
3531
-                        : $fldprops['default'],
3532
-                    'options'    => isset($fldprops['options'])
3533
-                        ? $fldprops['options']
3534
-                        : [],
3535
-                    'default'    => isset($existing_settings[ $fldname ])
3536
-                        ? $existing_settings[ $fldname ]
3537
-                        : $fldprops['default'],
3538
-                    'css_class'  => 'no-drag',
3539
-                    'format'     => $fldprops['format'],
3540
-                ];
3541
-            }
3542
-
3543
-
3544
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
-                ? $this->_generate_admin_form_fields(
3546
-                    $template_form_field,
3547
-                    'string',
3548
-                    'ee_mt_activate_form'
3549
-                )
3550
-                : '';
3551
-        }
3552
-
3553
-        $settings_template_args['description'] = $message_type->description;
3554
-        // we also need some hidden fields
3555
-        $hidden_fields = [
3556
-            'message_type_settings[messenger]' . $message_type->name    => [
3557
-                'type'  => 'hidden',
3558
-                'value' => $messenger->name,
3559
-            ],
3560
-            'message_type_settings[message_type]' . $message_type->name => [
3561
-                'type'  => 'hidden',
3562
-                'value' => $message_type->name,
3563
-            ],
3564
-            'type' . $message_type->name                                => [
3565
-                'type'  => 'hidden',
3566
-                'value' => 'message_type',
3567
-            ],
3568
-        ];
3569
-
3570
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
-            $hidden_fields,
3572
-            'array'
3573
-        );
3574
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
-            ? ' hidden'
3576
-            : '';
3577
-
3578
-
3579
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
-        return EEH_Template::display_template($template, $settings_template_args, true);
3581
-    }
3582
-
3583
-
3584
-    /**
3585
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
-     *
3587
-     * @access protected
3588
-     * @return void
3589
-     * @throws DomainException
3590
-     */
3591
-    protected function _messages_settings_metaboxes()
3592
-    {
3593
-        $this->_set_m_mt_settings();
3594
-        $m_boxes         = $mt_boxes = [];
3595
-        $m_template_args = $mt_template_args = [];
3596
-
3597
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
-
3599
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
-
3605
-                // messenger meta boxes
3606
-                $active         = $selected_messenger === $messenger;
3607
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
-                    : '';
3610
-
3611
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
-                    esc_html__('%s Settings', 'event_espresso'),
3613
-                    $tab_array['label']
3614
-                );
3615
-
3616
-                $m_template_args[ $messenger . '_a_box' ] = [
3617
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
-                    'inactive_message_types' => isset(
3619
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
-                    )
3621
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
-                        : '',
3623
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
-                    'hidden'                 => $active ? '' : ' hidden',
3625
-                    'hide_on_message'        => $hide_on_message,
3626
-                    'messenger'              => $messenger,
3627
-                    'active'                 => $active,
3628
-                ];
3629
-
3630
-                // message type meta boxes
3631
-                // (which is really just the inactive container for each messenger
3632
-                // showing inactive message types for that messenger)
3633
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
-                $mt_template_args[ $messenger . '_i_box' ] = [
3635
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
-                    'inactive_message_types' => isset(
3637
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
-                    )
3639
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
-                        : '',
3641
-                    'hidden'                 => $active ? '' : ' hidden',
3642
-                    'hide_on_message'        => $hide_on_message,
3643
-                    'hide_off_message'       => $hide_off_message,
3644
-                    'messenger'              => $messenger,
3645
-                    'active'                 => $active,
3646
-                ];
3647
-            }
3648
-        }
3649
-
3650
-
3651
-        // register messenger metaboxes
3652
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
-        foreach ($m_boxes as $box => $label) {
3654
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
-            $msgr          = str_replace('_a_box', '', $box);
3656
-            add_meta_box(
3657
-                'espresso_' . $msgr . '_settings',
3658
-                $label,
3659
-                function ($post, $metabox) {
3660
-                    EEH_Template::display_template(
3661
-                        $metabox['args']['template_path'],
3662
-                        $metabox['args']['template_args']
3663
-                    );
3664
-                },
3665
-                $this->_current_screen->id,
3666
-                'normal',
3667
-                'high',
3668
-                $callback_args
3669
-            );
3670
-        }
3671
-
3672
-        // register message type metaboxes
3673
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
-        foreach ($mt_boxes as $box => $label) {
3675
-            $callback_args = [
3676
-                'template_path' => $mt_template_path,
3677
-                'template_args' => $mt_template_args[ $box ],
3678
-            ];
3679
-            $mt            = str_replace('_i_box', '', $box);
3680
-            add_meta_box(
3681
-                'espresso_' . $mt . '_inactive_mts',
3682
-                $label,
3683
-                function ($post, $metabox) {
3684
-                    EEH_Template::display_template(
3685
-                        $metabox['args']['template_path'],
3686
-                        $metabox['args']['template_args']
3687
-                    );
3688
-                },
3689
-                $this->_current_screen->id,
3690
-                'side',
3691
-                'high',
3692
-                $callback_args
3693
-            );
3694
-        }
3695
-
3696
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3697
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
-        if (is_main_site()) {
3699
-            add_meta_box(
3700
-                'espresso_global_message_settings',
3701
-                esc_html__('Global Message Settings', 'event_espresso'),
3702
-                [$this, 'global_messages_settings_metabox_content'],
3703
-                $this->_current_screen->id,
3704
-                'normal',
3705
-                'low',
3706
-                []
3707
-            );
3708
-        }
3709
-    }
3710
-
3711
-
3712
-    /**
3713
-     *  This generates the content for the global messages settings metabox.
3714
-     *
3715
-     * @return void
3716
-     * @throws EE_Error
3717
-     * @throws InvalidArgumentException
3718
-     * @throws ReflectionException
3719
-     * @throws InvalidDataTypeException
3720
-     * @throws InvalidInterfaceException
3721
-     */
3722
-    public function global_messages_settings_metabox_content()
3723
-    {
3724
-        $form = $this->_generate_global_settings_form();
3725
-        echo wp_kses(
3726
-            $form->form_open(
3727
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
-                'POST'
3729
-            ),
3730
-            AllowedTags::getWithFormTags()
3731
-        );
3732
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
-    }
3735
-
3736
-
3737
-    /**
3738
-     * This generates and returns the form object for the global messages settings.
3739
-     *
3740
-     * @return EE_Form_Section_Proper
3741
-     * @throws EE_Error
3742
-     * @throws InvalidArgumentException
3743
-     * @throws ReflectionException
3744
-     * @throws InvalidDataTypeException
3745
-     * @throws InvalidInterfaceException
3746
-     */
3747
-    protected function _generate_global_settings_form()
3748
-    {
3749
-        /** @var EE_Network_Core_Config $network_config */
3750
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3751
-
3752
-        return new EE_Form_Section_Proper(
3753
-            [
3754
-                'name'            => 'global_messages_settings',
3755
-                'html_id'         => 'global_messages_settings',
3756
-                'html_class'      => 'form-table',
3757
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
-                'subsections'     => apply_filters(
3759
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
-                    [
3761
-                        'do_messages_on_same_request' => new EE_Select_Input(
3762
-                            [
3763
-                                true  => esc_html__('On the same request', 'event_espresso'),
3764
-                                false => esc_html__('On a separate request', 'event_espresso'),
3765
-                            ],
3766
-                            [
3767
-                                'default'         => $network_config->do_messages_on_same_request,
3768
-                                'html_label_text' => esc_html__(
3769
-                                    'Generate and send all messages:',
3770
-                                    'event_espresso'
3771
-                                ),
3772
-                                'html_help_text'  => esc_html__(
3773
-                                    '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.',
3774
-                                    'event_espresso'
3775
-                                ),
3776
-                            ]
3777
-                        ),
3778
-                        'delete_threshold'            => new EE_Select_Input(
3779
-                            [
3780
-                                0  => esc_html__('Forever', 'event_espresso'),
3781
-                                3  => esc_html__('3 Months', 'event_espresso'),
3782
-                                6  => esc_html__('6 Months', 'event_espresso'),
3783
-                                9  => esc_html__('9 Months', 'event_espresso'),
3784
-                                12 => esc_html__('12 Months', 'event_espresso'),
3785
-                                24 => esc_html__('24 Months', 'event_espresso'),
3786
-                                36 => esc_html__('36 Months', 'event_espresso'),
3787
-                            ],
3788
-                            [
3789
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
-                                'html_help_text'  => esc_html__(
3792
-                                    'You can control how long a record of processed messages is kept via this option.',
3793
-                                    'event_espresso'
3794
-                                ),
3795
-                            ]
3796
-                        ),
3797
-                        'update_settings'             => new EE_Submit_Input(
3798
-                            [
3799
-                                'default'         => esc_html__('Update', 'event_espresso'),
3800
-                                'html_label_text' => '',
3801
-                            ]
3802
-                        ),
3803
-                    ]
3804
-                ),
3805
-            ]
3806
-        );
3807
-    }
3808
-
3809
-
3810
-    /**
3811
-     * This handles updating the global settings set on the admin page.
3812
-     *
3813
-     * @throws EE_Error
3814
-     * @throws InvalidDataTypeException
3815
-     * @throws InvalidInterfaceException
3816
-     * @throws InvalidArgumentException
3817
-     * @throws ReflectionException
3818
-     */
3819
-    protected function _update_global_settings()
3820
-    {
3821
-        /** @var EE_Network_Core_Config $network_config */
3822
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3823
-        $messages_config = EE_Registry::instance()->CFG->messages;
3824
-        $form            = $this->_generate_global_settings_form();
3825
-        if ($form->was_submitted()) {
3826
-            $form->receive_form_submission();
3827
-            if ($form->is_valid()) {
3828
-                $valid_data = $form->valid_data();
3829
-                foreach ($valid_data as $property => $value) {
3830
-                    $setter = 'set_' . $property;
3831
-                    if (method_exists($network_config, $setter)) {
3832
-                        $network_config->{$setter}($value);
3833
-                    } elseif (
3834
-                        property_exists($network_config, $property)
3835
-                        && $network_config->{$property} !== $value
3836
-                    ) {
3837
-                        $network_config->{$property} = $value;
3838
-                    } elseif (
3839
-                        property_exists($messages_config, $property)
3840
-                        && $messages_config->{$property} !== $value
3841
-                    ) {
3842
-                        $messages_config->{$property} = $value;
3843
-                    }
3844
-                }
3845
-                // only update if the form submission was valid!
3846
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
-                EE_Registry::instance()->CFG->update_espresso_config();
3848
-                EE_Error::overwrite_success();
3849
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
-            }
3851
-        }
3852
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
-    }
3854
-
3855
-
3856
-    /**
3857
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
-     *
3859
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
-     * @return string html formatted tabs
3861
-     * @throws DomainException
3862
-     */
3863
-    protected function _get_mt_tabs($tab_array)
3864
-    {
3865
-        $tab_array = (array) $tab_array;
3866
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
-        $tabs      = '';
3868
-
3869
-        foreach ($tab_array as $tab) {
3870
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3871
-        }
3872
-
3873
-        return $tabs;
3874
-    }
3875
-
3876
-
3877
-    /**
3878
-     * This prepares the content of the messenger meta box admin settings
3879
-     *
3880
-     * @param EE_messenger $messenger The messenger we're setting up content for
3881
-     * @return string html formatted content
3882
-     * @throws DomainException
3883
-     */
3884
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3885
-    {
3886
-
3887
-        $fields                                         = $messenger->get_admin_settings_fields();
3888
-        $settings_template_args['template_form_fields'] = '';
3889
-
3890
-        // is $messenger active?
3891
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
-
3893
-
3894
-        if (! empty($fields)) {
3895
-            $existing_settings = $messenger->get_existing_admin_settings();
3896
-
3897
-            foreach ($fields as $fldname => $fldprops) {
3898
-                $field_id                         = $messenger->name . '-' . $fldname;
3899
-                $template_form_field[ $field_id ] = [
3900
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3901
-                    'label'      => $fldprops['label'],
3902
-                    'input'      => $fldprops['field_type'],
3903
-                    'type'       => $fldprops['value_type'],
3904
-                    'required'   => $fldprops['required'],
3905
-                    'validation' => $fldprops['validation'],
3906
-                    'value'      => isset($existing_settings[ $field_id ])
3907
-                        ? $existing_settings[ $field_id ]
3908
-                        : $fldprops['default'],
3909
-                    'css_class'  => '',
3910
-                    'format'     => $fldprops['format'],
3911
-                ];
3912
-            }
3913
-
3914
-
3915
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
-                : '';
3918
-        }
3919
-
3920
-        // we also need some hidden fields
3921
-        $settings_template_args['hidden_fields'] = [
3922
-            'messenger_settings[messenger]' . $messenger->name => [
3923
-                'type'  => 'hidden',
3924
-                'value' => $messenger->name,
3925
-            ],
3926
-            'type' . $messenger->name                          => [
3927
-                'type'  => 'hidden',
3928
-                'value' => 'messenger',
3929
-            ],
3930
-        ];
3931
-
3932
-        // make sure any active message types that are existing are included in the hidden fields
3933
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
-                    'type'  => 'hidden',
3937
-                    'value' => $mt,
3938
-                ];
3939
-            }
3940
-        }
3941
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
-            $settings_template_args['hidden_fields'],
3943
-            'array'
3944
-        );
3945
-        $active                                  =
3946
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3947
-
3948
-        $settings_template_args['messenger']           = $messenger->name;
3949
-        $settings_template_args['description']         = $messenger->description;
3950
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
-
3952
-
3953
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
-            $messenger->name
3955
-        )
3956
-            ? $settings_template_args['show_hide_edit_form']
3957
-            : ' hidden';
3958
-
3959
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
-            ? ' hidden'
3961
-            : $settings_template_args['show_hide_edit_form'];
3962
-
3963
-
3964
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
-        $settings_template_args['on_off_status'] = $active;
3967
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
-        return EEH_Template::display_template(
3969
-            $template,
3970
-            $settings_template_args,
3971
-            true
3972
-        );
3973
-    }
3974
-
3975
-
3976
-    /**
3977
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3978
-     *
3979
-     * @throws DomainException
3980
-     * @throws EE_Error
3981
-     * @throws InvalidDataTypeException
3982
-     * @throws InvalidInterfaceException
3983
-     * @throws InvalidArgumentException
3984
-     * @throws ReflectionException
3985
-     */
3986
-    public function activate_messenger_toggle()
3987
-    {
3988
-        $success = true;
3989
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
-        // let's check that we have required data
3991
-
3992
-        if (! $this->_active_messenger_name) {
3993
-            EE_Error::add_error(
3994
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
-                __FILE__,
3996
-                __FUNCTION__,
3997
-                __LINE__
3998
-            );
3999
-            $success = false;
4000
-        }
4001
-
4002
-        // do a nonce check here since we're not arriving via a normal route
4003
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
-
4006
-        $this->_verify_nonce($nonce, $nonce_ref);
4007
-
4008
-
4009
-        $status = $this->request->getRequestParam('status');
4010
-        if (! $status) {
4011
-            EE_Error::add_error(
4012
-                esc_html__(
4013
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
-                    'event_espresso'
4015
-                ),
4016
-                __FILE__,
4017
-                __FUNCTION__,
4018
-                __LINE__
4019
-            );
4020
-            $success = false;
4021
-        }
4022
-
4023
-        // do check to verify we have a valid status.
4024
-        if ($status !== 'off' && $status !== 'on') {
4025
-            EE_Error::add_error(
4026
-                sprintf(
4027
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
-                    $status
4029
-                ),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4034
-            $success = false;
4035
-        }
4036
-
4037
-        if ($success) {
4038
-            // made it here?  Stop dawdling then!!
4039
-            $success = $status === 'off'
4040
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4041
-                : $this->_activate_messenger($this->_active_messenger_name);
4042
-        }
4043
-
4044
-        $this->_template_args['success'] = $success;
4045
-
4046
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
-        $this->_return_json();
4048
-    }
4049
-
4050
-
4051
-    /**
4052
-     * used by ajax from the messages settings page to activate|deactivate a message type
4053
-     *
4054
-     * @throws DomainException
4055
-     * @throws EE_Error
4056
-     * @throws ReflectionException
4057
-     * @throws InvalidDataTypeException
4058
-     * @throws InvalidInterfaceException
4059
-     * @throws InvalidArgumentException
4060
-     */
4061
-    public function activate_mt_toggle()
4062
-    {
4063
-        $success = true;
4064
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
-
4066
-        // let's make sure we have the necessary data
4067
-        if (! $this->_active_message_type_name) {
4068
-            EE_Error::add_error(
4069
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
-                __FILE__,
4071
-                __FUNCTION__,
4072
-                __LINE__
4073
-            );
4074
-            $success = false;
4075
-        }
4076
-
4077
-        if (! $this->_active_messenger_name) {
4078
-            EE_Error::add_error(
4079
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
-                __FILE__,
4081
-                __FUNCTION__,
4082
-                __LINE__
4083
-            );
4084
-            $success = false;
4085
-        }
4086
-
4087
-        $status = $this->request->getRequestParam('status');
4088
-        if (! $status) {
4089
-            EE_Error::add_error(
4090
-                esc_html__(
4091
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
-                    'event_espresso'
4093
-                ),
4094
-                __FILE__,
4095
-                __FUNCTION__,
4096
-                __LINE__
4097
-            );
4098
-            $success = false;
4099
-        }
4100
-
4101
-
4102
-        // do check to verify we have a valid status.
4103
-        if ($status !== 'activate' && $status !== 'deactivate') {
4104
-            EE_Error::add_error(
4105
-                sprintf(
4106
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
-                    $status
4108
-                ),
4109
-                __FILE__,
4110
-                __FUNCTION__,
4111
-                __LINE__
4112
-            );
4113
-            $success = false;
4114
-        }
4115
-
4116
-
4117
-        // do a nonce check here since we're not arriving via a normal route
4118
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4119
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
-
4121
-        if ($success) {
4122
-            // made it here? um, what are you waiting for then?
4123
-            $success = $status === 'deactivate'
4124
-                ? $this->_deactivate_message_type_for_messenger(
4125
-                    $this->_active_messenger_name,
4126
-                    $this->_active_message_type_name
4127
-                )
4128
-                : $this->_activate_message_type_for_messenger(
4129
-                    $this->_active_messenger_name,
4130
-                    $this->_active_message_type_name
4131
-                );
4132
-        }
4133
-
4134
-        $this->_template_args['success'] = $success;
4135
-        $this->_return_json();
4136
-    }
4137
-
4138
-
4139
-    /**
4140
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4141
-     *
4142
-     * @param string $messenger_name The name of the messenger being activated
4143
-     * @return bool
4144
-     * @throws DomainException
4145
-     * @throws EE_Error
4146
-     * @throws InvalidArgumentException
4147
-     * @throws ReflectionException
4148
-     * @throws InvalidDataTypeException
4149
-     * @throws InvalidInterfaceException
4150
-     */
4151
-    protected function _activate_messenger($messenger_name)
4152
-    {
4153
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
-            ? $active_messenger->get_default_message_types()
4156
-            : [];
4157
-
4158
-        // ensure is active
4159
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
-
4161
-        // set response_data for reload
4162
-        foreach ($message_types_to_activate as $message_type_name) {
4163
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
-            if (
4165
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4166
-                    $messenger_name,
4167
-                    $message_type_name
4168
-                )
4169
-                && $message_type instanceof EE_message_type
4170
-            ) {
4171
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4172
-                if ($message_type->get_admin_settings_fields()) {
4173
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
-                }
4175
-            }
4176
-        }
4177
-
4178
-        // add success message for activating messenger
4179
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
-    }
4181
-
4182
-
4183
-    /**
4184
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
-     *
4186
-     * @param string $messenger_name The name of the messenger being activated
4187
-     * @return bool
4188
-     * @throws DomainException
4189
-     * @throws EE_Error
4190
-     * @throws InvalidArgumentException
4191
-     * @throws ReflectionException
4192
-     * @throws InvalidDataTypeException
4193
-     * @throws InvalidInterfaceException
4194
-     */
4195
-    protected function _deactivate_messenger($messenger_name)
4196
-    {
4197
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
-
4200
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
-    }
4202
-
4203
-
4204
-    /**
4205
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
-     *
4207
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
-     * @param string $message_type_name The name of the message type being activated for the messenger
4209
-     * @return bool
4210
-     * @throws DomainException
4211
-     * @throws EE_Error
4212
-     * @throws InvalidArgumentException
4213
-     * @throws ReflectionException
4214
-     * @throws InvalidDataTypeException
4215
-     * @throws InvalidInterfaceException
4216
-     */
4217
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
-    {
4219
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
-
4222
-        // ensure is active
4223
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
-
4225
-        // set response for load
4226
-        if (
4227
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4228
-                $messenger_name,
4229
-                $message_type_name
4230
-            )
4231
-        ) {
4232
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4233
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4234
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
-            }
4236
-        }
4237
-
4238
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
-            $active_messenger,
4240
-            $message_type_to_activate
4241
-        );
4242
-    }
4243
-
4244
-
4245
-    /**
4246
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
-     *
4248
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
-     * @return bool
4251
-     * @throws DomainException
4252
-     * @throws EE_Error
4253
-     * @throws InvalidArgumentException
4254
-     * @throws ReflectionException
4255
-     * @throws InvalidDataTypeException
4256
-     * @throws InvalidInterfaceException
4257
-     */
4258
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
-    {
4260
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
-
4265
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
-            $active_messenger,
4267
-            $message_type_to_deactivate
4268
-        );
4269
-    }
4270
-
4271
-
4272
-    /**
4273
-     * This just initializes the defaults for activating messenger and message type responses.
4274
-     */
4275
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
-    {
4277
-        $this->_template_args['data']['active_mts'] = [];
4278
-        $this->_template_args['data']['mt_reload']  = [];
4279
-    }
4280
-
4281
-
4282
-    /**
4283
-     * Setup appropriate response for activating a messenger and/or message types
4284
-     *
4285
-     * @param EE_messenger         $messenger
4286
-     * @param EE_message_type|null $message_type
4287
-     * @return bool
4288
-     * @throws DomainException
4289
-     * @throws EE_Error
4290
-     * @throws InvalidArgumentException
4291
-     * @throws ReflectionException
4292
-     * @throws InvalidDataTypeException
4293
-     * @throws InvalidInterfaceException
4294
-     */
4295
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
-        $messenger,
4297
-        EE_Message_Type $message_type = null
4298
-    ) {
4299
-        // if $messenger isn't a valid messenger object then get out.
4300
-        if (! $messenger instanceof EE_Messenger) {
4301
-            EE_Error::add_error(
4302
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
-                __FILE__,
4304
-                __FUNCTION__,
4305
-                __LINE__
4306
-            );
4307
-            return false;
4308
-        }
4309
-        // activated
4310
-        if ($this->_template_args['data']['active_mts']) {
4311
-            EE_Error::overwrite_success();
4312
-            // activated a message type with the messenger
4313
-            if ($message_type instanceof EE_message_type) {
4314
-                EE_Error::add_success(
4315
-                    sprintf(
4316
-                        esc_html__(
4317
-                            '%s message type has been successfully activated with the %s messenger',
4318
-                            'event_espresso'
4319
-                        ),
4320
-                        ucwords($message_type->label['singular']),
4321
-                        ucwords($messenger->label['singular'])
4322
-                    )
4323
-                );
4324
-
4325
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4326
-                if ($message_type->name === 'invoice') {
4327
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
-                    if ($pm instanceof EE_Payment_Method) {
4330
-                        EE_Error::add_attention(
4331
-                            esc_html__(
4332
-                                '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.',
4333
-                                'event_espresso'
4334
-                            )
4335
-                        );
4336
-                    }
4337
-                }
4338
-                // just toggles the entire messenger
4339
-            } else {
4340
-                EE_Error::add_success(
4341
-                    sprintf(
4342
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
-                        ucwords($messenger->label['singular'])
4344
-                    )
4345
-                );
4346
-            }
4347
-
4348
-            return true;
4349
-
4350
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
-            // in which case we just give a success message for the messenger being successfully activated.
4353
-        } else {
4354
-            if (! $messenger->get_default_message_types()) {
4355
-                // messenger doesn't have any default message types so still a success.
4356
-                EE_Error::add_success(
4357
-                    sprintf(
4358
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
-                        ucwords($messenger->label['singular'])
4360
-                    )
4361
-                );
4362
-
4363
-                return true;
4364
-            } else {
4365
-                EE_Error::add_error(
4366
-                    $message_type instanceof EE_message_type
4367
-                    ? sprintf(
4368
-                        esc_html__(
4369
-                            '%s message type was not successfully activated with the %s messenger',
4370
-                            'event_espresso'
4371
-                        ),
4372
-                        ucwords($message_type->label['singular']),
4373
-                        ucwords($messenger->label['singular'])
4374
-                    )
4375
-                    : sprintf(
4376
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
-                        ucwords($messenger->label['singular'])
4378
-                    ),
4379
-                    __FILE__,
4380
-                    __FUNCTION__,
4381
-                    __LINE__
4382
-                );
4383
-
4384
-                return false;
4385
-            }
4386
-        }
4387
-    }
4388
-
4389
-
4390
-    /**
4391
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
-     *
4393
-     * @param EE_messenger         $messenger
4394
-     * @param EE_message_type|null $message_type
4395
-     * @return bool
4396
-     * @throws DomainException
4397
-     * @throws EE_Error
4398
-     * @throws InvalidArgumentException
4399
-     * @throws ReflectionException
4400
-     * @throws InvalidDataTypeException
4401
-     * @throws InvalidInterfaceException
4402
-     */
4403
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
-        $messenger,
4405
-        EE_message_type $message_type = null
4406
-    ) {
4407
-        EE_Error::overwrite_success();
4408
-
4409
-        // if $messenger isn't a valid messenger object then get out.
4410
-        if (! $messenger instanceof EE_Messenger) {
4411
-            EE_Error::add_error(
4412
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
-                __FILE__,
4414
-                __FUNCTION__,
4415
-                __LINE__
4416
-            );
4417
-
4418
-            return false;
4419
-        }
4420
-
4421
-        if ($message_type instanceof EE_message_type) {
4422
-            $message_type_name = $message_type->name;
4423
-            EE_Error::add_success(
4424
-                sprintf(
4425
-                    esc_html__(
4426
-                        '%s message type has been successfully deactivated for the %s messenger.',
4427
-                        'event_espresso'
4428
-                    ),
4429
-                    ucwords($message_type->label['singular']),
4430
-                    ucwords($messenger->label['singular'])
4431
-                )
4432
-            );
4433
-        } else {
4434
-            $message_type_name = '';
4435
-            EE_Error::add_success(
4436
-                sprintf(
4437
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
-                    ucwords($messenger->label['singular'])
4439
-                )
4440
-            );
4441
-        }
4442
-
4443
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
-        if (
4445
-            $messenger->name === 'html'
4446
-            && (
4447
-                is_null($message_type)
4448
-                || $message_type_name === 'invoice'
4449
-            )
4450
-        ) {
4451
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
-            if ($count_updated > 0) {
4454
-                $msg = $message_type_name === 'invoice'
4455
-                    ? esc_html__(
4456
-                        '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.',
4457
-                        'event_espresso'
4458
-                    )
4459
-                    : esc_html__(
4460
-                        '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.',
4461
-                        'event_espresso'
4462
-                    );
4463
-                EE_Error::add_attention($msg);
4464
-            }
4465
-        }
4466
-
4467
-        return true;
4468
-    }
4469
-
4470
-
4471
-    /**
4472
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
-     *
4474
-     * @throws DomainException
4475
-     * @throws EE_Error
4476
-     * @throws EE_Error
4477
-     */
4478
-    public function update_mt_form()
4479
-    {
4480
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
-            EE_Error::add_error(
4482
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
-                __FILE__,
4484
-                __FUNCTION__,
4485
-                __LINE__
4486
-            );
4487
-            $this->_return_json();
4488
-        }
4489
-
4490
-        $message_types = $this->get_installed_message_types();
4491
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4492
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
-
4495
-        $this->_template_args['success'] = true;
4496
-        $this->_template_args['content'] = $content;
4497
-        $this->_return_json();
4498
-    }
4499
-
4500
-
4501
-    /**
4502
-     * this handles saving the settings for a messenger or message type
4503
-     *
4504
-     * @throws EE_Error
4505
-     * @throws EE_Error
4506
-     */
4507
-    public function save_settings()
4508
-    {
4509
-        $type = $this->request->getRequestParam('type');
4510
-        if (! $type) {
4511
-            EE_Error::add_error(
4512
-                esc_html__(
4513
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
-                    'event_espresso'
4515
-                ),
4516
-                __FILE__,
4517
-                __FUNCTION__,
4518
-                __LINE__
4519
-            );
4520
-            $this->_template_args['error'] = true;
4521
-            $this->_return_json();
4522
-        }
4523
-
4524
-
4525
-        if ($type === 'messenger') {
4526
-            // this should be an array.
4527
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
-            $messenger = $settings['messenger'];
4529
-            // remove messenger and message_types from settings array
4530
-            unset($settings['messenger'], $settings['message_types']);
4531
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
-        } elseif ($type === 'message_type') {
4533
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
-            $messenger    = $settings['messenger'];
4535
-            $message_type = $settings['message_type'];
4536
-            // remove messenger and message_types from settings array
4537
-            unset($settings['messenger'], $settings['message_types']);
4538
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
-        }
4540
-
4541
-        // okay we should have the data all setup.  Now we just update!
4542
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4543
-
4544
-        if ($success) {
4545
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
-        } else {
4547
-            EE_Error::add_error(
4548
-                esc_html__('Settings did not get updated', 'event_espresso'),
4549
-                __FILE__,
4550
-                __FUNCTION__,
4551
-                __LINE__
4552
-            );
4553
-        }
4554
-
4555
-        $this->_template_args['success'] = $success;
4556
-        $this->_return_json();
4557
-    }
4558
-
4559
-
4560
-
4561
-
4562
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4563
-
4564
-
4565
-    /**
4566
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
-     * However, this does not send immediately, it just queues for sending.
4568
-     *
4569
-     * @throws EE_Error
4570
-     * @throws InvalidDataTypeException
4571
-     * @throws InvalidInterfaceException
4572
-     * @throws InvalidArgumentException
4573
-     * @throws ReflectionException
4574
-     * @since 4.9.0
4575
-     */
4576
-    protected function _generate_now()
4577
-    {
4578
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
-        $this->_redirect_after_action(false, '', '', [], true);
4580
-    }
4581
-
4582
-
4583
-    /**
4584
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4586
-     *
4587
-     * @throws EE_Error
4588
-     * @throws InvalidDataTypeException
4589
-     * @throws InvalidInterfaceException
4590
-     * @throws InvalidArgumentException
4591
-     * @throws ReflectionException
4592
-     * @since 4.9.0
4593
-     */
4594
-    protected function _generate_and_send_now()
4595
-    {
4596
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
-        $this->_redirect_after_action(false, '', '', [], true);
4598
-    }
4599
-
4600
-
4601
-    /**
4602
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
-     *
4604
-     * @throws EE_Error
4605
-     * @throws InvalidDataTypeException
4606
-     * @throws InvalidInterfaceException
4607
-     * @throws InvalidArgumentException
4608
-     * @throws ReflectionException
4609
-     * @since 4.9.0
4610
-     */
4611
-    protected function _queue_for_resending()
4612
-    {
4613
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
-        $this->_redirect_after_action(false, '', '', [], true);
4615
-    }
4616
-
4617
-
4618
-    /**
4619
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
-     *
4621
-     * @throws EE_Error
4622
-     * @throws InvalidDataTypeException
4623
-     * @throws InvalidInterfaceException
4624
-     * @throws InvalidArgumentException
4625
-     * @throws ReflectionException
4626
-     * @since 4.9.0
4627
-     */
4628
-    protected function _send_now()
4629
-    {
4630
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
-        $this->_redirect_after_action(false, '', '', [], true);
4632
-    }
4633
-
4634
-
4635
-    /**
4636
-     * Deletes EE_messages for IDs in the request.
4637
-     *
4638
-     * @throws EE_Error
4639
-     * @throws InvalidDataTypeException
4640
-     * @throws InvalidInterfaceException
4641
-     * @throws InvalidArgumentException
4642
-     * @since 4.9.0
4643
-     */
4644
-    protected function _delete_ee_messages()
4645
-    {
4646
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4647
-        $deleted_count = 0;
4648
-        foreach ($MSG_IDs as $MSG_ID) {
4649
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
-                $deleted_count++;
4651
-            }
4652
-        }
4653
-        if ($deleted_count) {
4654
-            EE_Error::add_success(
4655
-                esc_html(
4656
-                    _n(
4657
-                        'Message successfully deleted',
4658
-                        'Messages successfully deleted',
4659
-                        $deleted_count,
4660
-                        'event_espresso'
4661
-                    )
4662
-                )
4663
-            );
4664
-        } else {
4665
-            EE_Error::add_error(
4666
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
-                __FILE__,
4668
-                __FUNCTION__,
4669
-                __LINE__
4670
-            );
4671
-        }
4672
-        $this->_redirect_after_action(false, '', '', [], true);
4673
-    }
4674
-
4675
-
4676
-    /**
4677
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
-     *
4679
-     * @return array
4680
-     * @since 4.9.0
4681
-     */
4682
-    protected function _get_msg_ids_from_request()
4683
-    {
4684
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
-        if (empty($MSG_IDs)) {
4686
-            return [];
4687
-        }
4688
-        // if 'MSG_ID' was just a single ID (not an array)
4689
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
-            ? $MSG_IDs
4693
-            : array_keys($MSG_IDs);
4694
-    }
2705
+		$this->_context_switcher = ob_get_clean();
2706
+	}
2707
+
2708
+
2709
+	/**
2710
+	 * @param bool $new
2711
+	 * @throws EE_Error
2712
+	 * @throws ReflectionException
2713
+	 */
2714
+	protected function _insert_or_update_message_template($new = false)
2715
+	{
2716
+		$form_data    = $this->getMessageTemplateFormData();
2717
+		$GRP_ID       = $form_data['GRP_ID'];
2718
+		$messenger    = $form_data['MTP_messenger'];
2719
+		$message_type = $form_data['MTP_message_type'];
2720
+		$context      = $form_data['MTP_context'];
2721
+
2722
+		// if this is "new" then we need to generate the default contexts
2723
+		// for the selected messenger/message_type for user to edit.
2724
+		[$success, $query_args] = $new
2725
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
+
2728
+		$success     = $success ? 1 : 0;
2729
+		$action_desc = $new ? 'created' : 'updated';
2730
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
+
2733
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * retrieve and sanitize form data
2739
+	 *
2740
+	 * @return array
2741
+	 * @since 4.10.29.p
2742
+	 */
2743
+	protected function getMessageTemplateFormData()
2744
+	{
2745
+		return [
2746
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
+		];
2756
+	}
2757
+
2758
+
2759
+	/**
2760
+	 * @param int    $GRP_ID
2761
+	 * @param string $messenger
2762
+	 * @param string $message_type
2763
+	 * @return array no return on AJAX requests
2764
+	 * @throws EE_Error
2765
+	 * @throws ReflectionException
2766
+	 * @since 4.10.29.p
2767
+	 */
2768
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
+	{
2770
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
+		$success       = ! empty($new_templates);
2772
+
2773
+		// we return things differently if doing ajax
2774
+		if ($this->request->isAjax()) {
2775
+			$this->_template_args['success'] = $success;
2776
+			$this->_template_args['error']   = ! $success;
2777
+			$this->_template_args['content'] = '';
2778
+			$this->_template_args['data']    = [
2779
+				'grpID'        => $new_templates['GRP_ID'],
2780
+				'templateName' => $new_templates['template_name'],
2781
+			];
2782
+			if ($success) {
2783
+				EE_Error::overwrite_success();
2784
+				EE_Error::add_success(
2785
+					esc_html__(
2786
+						'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.',
2787
+						'event_espresso'
2788
+					)
2789
+				);
2790
+			}
2791
+			$this->_return_json();
2792
+		}
2793
+		return [
2794
+			$success,
2795
+			// 'query_args'
2796
+			[
2797
+				'id'      => $new_templates['GRP_ID'],
2798
+				'context' => $new_templates['MTP_context'],
2799
+				'action'  => 'edit_message_template',
2800
+			],
2801
+		];
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * @param int    $GRP_ID
2807
+	 * @param string $messenger
2808
+	 * @param string $message_type
2809
+	 * @param string $context
2810
+	 * @param array  $form_data
2811
+	 * @return array
2812
+	 * @throws EE_Error
2813
+	 * @since 4.10.29.p
2814
+	 */
2815
+	private function updateExistingTemplates(
2816
+		$GRP_ID,
2817
+		$messenger,
2818
+		$message_type,
2819
+		$context,
2820
+		array $form_data
2821
+	) {
2822
+		$success         = false;
2823
+		$template_fields = $this->getTemplateFields();
2824
+		if ($template_fields) {
2825
+			// if field data is valid, then success will be true
2826
+			$success = $this->validateTemplateFields(
2827
+				$messenger,
2828
+				$message_type,
2829
+				$context,
2830
+				$template_fields
2831
+			);
2832
+			if ($success) {
2833
+				$field_data = [];
2834
+				foreach ($template_fields as $template_field => $content) {
2835
+					// combine top-level form data with content for this field
2836
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
+				}
2839
+				// we can use the last set_column_values for the MTPG update
2840
+				// (because its the same for all of these specific MTPs)
2841
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
+			}
2843
+		}
2844
+
2845
+		return [
2846
+			$success,
2847
+			// 'query_args'
2848
+			[
2849
+				'id'      => $GRP_ID,
2850
+				'context' => $context,
2851
+				'action'  => 'edit_message_template',
2852
+			],
2853
+		];
2854
+	}
2855
+
2856
+
2857
+	/**
2858
+	 * @return array
2859
+	 * @since 4.10.29.p
2860
+	 */
2861
+	private function getTemplateFields()
2862
+	{
2863
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
+		if (empty($template_fields)) {
2865
+			EE_Error::add_error(
2866
+				esc_html__(
2867
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
+					'event_espresso'
2869
+				),
2870
+				__FILE__,
2871
+				__FUNCTION__,
2872
+				__LINE__
2873
+			);
2874
+			return null;
2875
+		}
2876
+		// messages content is expected to be escaped
2877
+		return EEH_Array::addSlashesRecursively($template_fields);
2878
+	}
2879
+
2880
+
2881
+	/**
2882
+	 * @param string $messenger
2883
+	 * @param string $message_type
2884
+	 * @param string $context
2885
+	 * @param array  $template_fields
2886
+	 * @return bool
2887
+	 * @throws EE_Error
2888
+	 * @since   4.10.29.p
2889
+	 */
2890
+	private function validateTemplateFields(
2891
+		$messenger,
2892
+		$message_type,
2893
+		$context,
2894
+		array $template_fields
2895
+	) {
2896
+		// first validate all fields!
2897
+		// this filter allows client code to add its own validation to the template fields as well.
2898
+		// returning an empty array means everything passed validation.
2899
+		// errors in validation should be represented in an array with the following shape:
2900
+		// array(
2901
+		//   'fieldname' => array(
2902
+		//          'msg' => 'error message'
2903
+		//          'value' => 'value for field producing error'
2904
+		// )
2905
+		$custom_validation = (array) apply_filters(
2906
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
+			[],
2908
+			$template_fields,
2909
+			$context,
2910
+			$messenger,
2911
+			$message_type
2912
+		);
2913
+
2914
+		$system_validation = $this->getMtgModel()->validate(
2915
+			$template_fields,
2916
+			$context,
2917
+			$messenger,
2918
+			$message_type
2919
+		);
2920
+
2921
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
+		$validates         = array_merge($custom_validation, $system_validation);
2923
+
2924
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
+		//  WE need to make sure there is no actual error messages in validates.
2927
+		if (empty($validates)) {
2928
+			return true;
2929
+		}
2930
+
2931
+		// add the transient so when the form loads we know which fields to highlight
2932
+		$this->_add_transient('edit_message_template', $validates);
2933
+		// setup notices
2934
+		foreach ($validates as $error) {
2935
+			if (isset($error['msg'])) {
2936
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
+			}
2938
+		}
2939
+		return false;
2940
+	}
2941
+
2942
+
2943
+	/**
2944
+	 * @param array $field_data
2945
+	 * @param array $form_data
2946
+	 * @return array
2947
+	 * @since   4.10.29.p
2948
+	 */
2949
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
+	{
2951
+		return $form_data + [
2952
+				'MTP_ID'             => $field_data['MTP_ID'],
2953
+				'MTP_template_field' => $field_data['name'],
2954
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2956
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
+					: $field_data['content'],
2958
+			];
2959
+	}
2960
+
2961
+
2962
+	/**
2963
+	 * @param string $template_field
2964
+	 * @param array  $form_data
2965
+	 * @return bool
2966
+	 * @throws EE_Error
2967
+	 * @since 4.10.29.p
2968
+	 */
2969
+	private function updateMessageTemplates($template_field, array $form_data)
2970
+	{
2971
+		$MTP_ID                  = $form_data['MTP_ID'];
2972
+		$message_template_fields = [
2973
+			'GRP_ID'             => $form_data['GRP_ID'],
2974
+			'MTP_template_field' => $form_data['MTP_template_field'],
2975
+			'MTP_context'        => $form_data['MTP_context'],
2976
+			'MTP_content'        => $form_data['MTP_content'],
2977
+		];
2978
+
2979
+		$hasMtpID = ! empty($MTP_ID);
2980
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2981
+		// this has already been through the template field validator and sanitized, so it will be
2982
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
+		// message template field in a messenger/message type and existing users don't have the
2984
+		// default setup for it.
2985
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
+		$updated = $hasMtpID
2987
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
+			: $this->getMtpModel()->insert($message_template_fields);
2989
+
2990
+		$insert_failed = ! $hasMtpID && ! $updated;
2991
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
+		$update_failed = $hasMtpID && $updated === false;
2994
+
2995
+		if ($insert_failed || $update_failed) {
2996
+			EE_Error::add_error(
2997
+				sprintf(
2998
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
+					$template_field
3000
+				),
3001
+				__FILE__,
3002
+				__FUNCTION__,
3003
+				__LINE__
3004
+			);
3005
+			return false;
3006
+		}
3007
+		return true;
3008
+	}
3009
+
3010
+
3011
+	/**
3012
+	 * @param array $form_data
3013
+	 * @return bool
3014
+	 * @throws EE_Error
3015
+	 * @since 4.10.29.p
3016
+	 */
3017
+	private function updateMessageTemplateGroup(array $form_data)
3018
+	{
3019
+		$GRP_ID  = $form_data['GRP_ID'];
3020
+		$updated = $this->getMtgModel()->update(
3021
+		// fields and values
3022
+			[
3023
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3024
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3025
+				'MTP_message_type' => $form_data['MTP_message_type'],
3026
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3027
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3028
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3029
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3030
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
+				'MTP_description'  => $this->request->getRequestParam(
3032
+					'ee_msg_non_global_fields[MTP_description]',
3033
+					''
3034
+				),
3035
+			],
3036
+			// where
3037
+			[['GRP_ID' => $GRP_ID]]
3038
+		);
3039
+
3040
+		if ($updated === false) {
3041
+			EE_Error::add_error(
3042
+				sprintf(
3043
+					esc_html__(
3044
+						'The Message Template Group (%d) was NOT updated for some reason',
3045
+						'event_espresso'
3046
+					),
3047
+					$form_data['GRP_ID']
3048
+				),
3049
+				__FILE__,
3050
+				__FUNCTION__,
3051
+				__LINE__
3052
+			);
3053
+			return false;
3054
+		}
3055
+		// k now we need to ensure the template_pack and template_variation fields are set.
3056
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
+
3059
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3061
+			$message_template_group->set_template_pack_name($template_pack);
3062
+			$message_template_group->set_template_pack_variation($template_variation);
3063
+		}
3064
+		return true;
3065
+	}
3066
+
3067
+
3068
+	/**
3069
+	 * recursively runs wp_kses() on message template content in a model safe manner
3070
+	 *
3071
+	 * @param array|string $content
3072
+	 * @return array|string
3073
+	 * @since   4.10.29.p
3074
+	 */
3075
+	private function sanitizeMessageTemplateContent($content)
3076
+	{
3077
+		if (is_array($content)) {
3078
+			foreach ($content as $key => $value) {
3079
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
+			}
3081
+			return $content;
3082
+		}
3083
+		// remove slashes so wp_kses() works properly
3084
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3085
+		// so attributes using single quotes always appear invalid.
3086
+		$content = stripslashes($content);
3087
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3088
+		// But currently the models expect slashed data, so after wp_kses()
3089
+		// runs we need to re-slash the data. Sheesh.
3090
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
+		return addslashes($content);
3092
+	}
3093
+
3094
+
3095
+	/**
3096
+	 * @param string $messenger
3097
+	 * @param string $message_type
3098
+	 * @param string $context
3099
+	 * @return string
3100
+	 * @since 4.10.29.p
3101
+	 */
3102
+	private function generateUpdateDescription($messenger, $message_type, $context)
3103
+	{
3104
+		// need the message type and messenger objects to be able to use the labels for the notices
3105
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
+		$messenger_label  = $messenger_object instanceof EE_messenger
3107
+			? ucwords($messenger_object->label['singular'])
3108
+			: '';
3109
+
3110
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
+		$message_type_label  = $message_type_object instanceof EE_message_type
3112
+			? ucwords($message_type_object->label['singular'])
3113
+			: '';
3114
+
3115
+		$context   = ucwords(str_replace('_', ' ', $context));
3116
+		$item_desc = $messenger_label && $message_type_label
3117
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
+			: '';
3119
+		$item_desc .= 'Message Template';
3120
+		return $item_desc;
3121
+	}
3122
+
3123
+
3124
+	/**
3125
+	 * @param string $messenger
3126
+	 * @param string $message_type
3127
+	 * @param string $context
3128
+	 * @return bool
3129
+	 * @throws EE_Error
3130
+	 * @throws ReflectionException
3131
+	 * @since 4.10.29.p
3132
+	 */
3133
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
+	{
3135
+		// was a test send triggered?
3136
+		if ($this->request->requestParamIsSet('test_button')) {
3137
+			EE_Error::overwrite_success();
3138
+			$this->_do_test_send($context, $messenger, $message_type);
3139
+			return true;
3140
+		}
3141
+		return false;
3142
+	}
3143
+
3144
+
3145
+	/**
3146
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
+	 *
3148
+	 * @param string $context      what context being tested
3149
+	 * @param string $messenger    messenger being tested
3150
+	 * @param string $message_type message type being tested
3151
+	 * @throws EE_Error
3152
+	 * @throws InvalidArgumentException
3153
+	 * @throws InvalidDataTypeException
3154
+	 * @throws InvalidInterfaceException
3155
+	 * @throws ReflectionException
3156
+	 */
3157
+	protected function _do_test_send($context, $messenger, $message_type)
3158
+	{
3159
+		// set things up for preview
3160
+		$this->request->setRequestParam('messenger', $messenger);
3161
+		$this->request->setRequestParam('message_type', $message_type);
3162
+		$this->request->setRequestParam('context', $context);
3163
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
+
3166
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
+
3169
+		// let's save any existing fields that might be required by the messenger
3170
+		if (
3171
+			! empty($test_settings_fld)
3172
+			&& $active_messenger instanceof EE_messenger
3173
+			&& apply_filters(
3174
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
+				true,
3176
+				$test_settings_fld,
3177
+				$active_messenger
3178
+			)
3179
+		) {
3180
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3181
+		}
3182
+
3183
+		/**
3184
+		 * Use filter to add additional controls on whether message can send or not
3185
+		 */
3186
+		if (
3187
+			apply_filters(
3188
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
+				true,
3190
+				$context,
3191
+				$this->request->requestParams(),
3192
+				$messenger,
3193
+				$message_type
3194
+			)
3195
+		) {
3196
+			if (EEM_Event::instance()->count() > 0) {
3197
+				$success = $this->_preview_message(true);
3198
+				if ($success) {
3199
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
+				} else {
3201
+					EE_Error::add_error(
3202
+						esc_html__('The test message was not sent', 'event_espresso'),
3203
+						__FILE__,
3204
+						__FUNCTION__,
3205
+						__LINE__
3206
+					);
3207
+				}
3208
+			} else {
3209
+				$this->noEventsErrorMessage(true);
3210
+			}
3211
+		}
3212
+	}
3213
+
3214
+
3215
+	/**
3216
+	 * _generate_new_templates
3217
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
+	 * for the event.
3220
+	 *
3221
+	 *
3222
+	 * @param string $messenger      the messenger we are generating templates for
3223
+	 * @param array  $message_types  array of message types that the templates are generated for.
3224
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
+	 *                               indicate the message_template_group being used as the base.
3226
+	 *
3227
+	 * @param bool   $global
3228
+	 *
3229
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
+	 *                               encountering problems.
3231
+	 * @throws EE_Error
3232
+	 * @throws ReflectionException
3233
+	 */
3234
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
+	{
3236
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
+		// just don't generate any templates.
3238
+		if (empty($message_types)) {
3239
+			return [];
3240
+		}
3241
+
3242
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
+		return $templates[0];
3244
+	}
3245
+
3246
+
3247
+	/**
3248
+	 * [_trash_or_restore_message_template]
3249
+	 *
3250
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
+	 *                        an individual context (FALSE).
3253
+	 * @return void
3254
+	 * @throws EE_Error
3255
+	 * @throws InvalidArgumentException
3256
+	 * @throws InvalidDataTypeException
3257
+	 * @throws InvalidInterfaceException
3258
+	 */
3259
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
+	{
3261
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
+
3263
+		$success = 1;
3264
+
3265
+		// incoming GRP_IDs
3266
+		if ($all) {
3267
+			// Checkboxes
3268
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
+			if (! empty($checkboxes)) {
3270
+				// if array has more than one element then success message should be plural.
3271
+				// todo: what about nonce?
3272
+				$success = count($checkboxes) > 1 ? 2 : 1;
3273
+
3274
+				// cycle through checkboxes
3275
+				foreach (array_keys($checkboxes) as $GRP_ID) {
3276
+					$trashed_or_restored = $trash
3277
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
+					if (! $trashed_or_restored) {
3280
+						$success = 0;
3281
+					}
3282
+				}
3283
+			} else {
3284
+				// grab single GRP_ID and handle
3285
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
+				if (! empty($GRP_ID)) {
3287
+					$trashed_or_restored = $trash
3288
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
+					if (! $trashed_or_restored) {
3291
+						$success = 0;
3292
+					}
3293
+				} else {
3294
+					$success = 0;
3295
+				}
3296
+			}
3297
+		}
3298
+
3299
+		$action_desc = $trash
3300
+			? esc_html__('moved to the trash', 'event_espresso')
3301
+			: esc_html__('restored', 'event_espresso');
3302
+
3303
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
+
3306
+		$item_desc = $all ? _n(
3307
+			'Message Template Group',
3308
+			'Message Template Groups',
3309
+			$success,
3310
+			'event_espresso'
3311
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
+
3313
+		$item_desc = $template_switch
3314
+			? _n('template', 'templates', $success, 'event_espresso')
3315
+			: $item_desc;
3316
+
3317
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
+	}
3319
+
3320
+
3321
+	/**
3322
+	 * [_delete_message_template]
3323
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
+	 *
3325
+	 * @return void
3326
+	 * @throws EE_Error
3327
+	 * @throws InvalidArgumentException
3328
+	 * @throws InvalidDataTypeException
3329
+	 * @throws InvalidInterfaceException
3330
+	 * @throws ReflectionException
3331
+	 */
3332
+	protected function _delete_message_template()
3333
+	{
3334
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
+
3336
+		// checkboxes
3337
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
+		if (! empty($checkboxes)) {
3339
+			// if array has more than one element then success message should be plural
3340
+			$success = count($checkboxes) > 1 ? 2 : 1;
3341
+
3342
+			// cycle through bulk action checkboxes
3343
+			foreach (array_keys($checkboxes) as $GRP_ID) {
3344
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
+			}
3346
+		} else {
3347
+			// grab single grp_id and delete
3348
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3350
+		}
3351
+
3352
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
+	}
3354
+
3355
+
3356
+	/**
3357
+	 * helper for permanently deleting a mtP group and all related message_templates
3358
+	 *
3359
+	 * @param int  $GRP_ID        The group being deleted
3360
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3361
+	 * @return bool boolean to indicate the success of the deletes or not.
3362
+	 * @throws EE_Error
3363
+	 * @throws InvalidArgumentException
3364
+	 * @throws InvalidDataTypeException
3365
+	 * @throws InvalidInterfaceException
3366
+	 * @throws ReflectionException
3367
+	 * @throws ReflectionException
3368
+	 */
3369
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
+	{
3371
+		$success = true;
3372
+		// first let's GET this group
3373
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
+		// then delete permanently all the related Message Templates
3375
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3376
+
3377
+		if ($deleted === 0) {
3378
+			$success = false;
3379
+		}
3380
+
3381
+		// now delete permanently this particular group
3382
+
3383
+		if ($include_group && ! $MTG->delete_permanently()) {
3384
+			$success = false;
3385
+		}
3386
+
3387
+		return $success;
3388
+	}
3389
+
3390
+
3391
+	/**
3392
+	 *    _learn_more_about_message_templates_link
3393
+	 *
3394
+	 * @access protected
3395
+	 * @return string
3396
+	 */
3397
+	protected function _learn_more_about_message_templates_link()
3398
+	{
3399
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3401
+			   . '</a>';
3402
+	}
3403
+
3404
+
3405
+	/**
3406
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
+	 * ajax and other routes.
3408
+	 *
3409
+	 * @return void
3410
+	 * @throws DomainException
3411
+	 * @throws EE_Error
3412
+	 */
3413
+	protected function _settings()
3414
+	{
3415
+		$this->_set_m_mt_settings();
3416
+
3417
+		// let's setup the messenger tabs
3418
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
+			$this->_m_mt_settings['messenger_tabs'],
3420
+			'messenger_links',
3421
+			'|',
3422
+			$this->request->getRequestParam('selected_messenger', 'email')
3423
+		);
3424
+
3425
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
+
3428
+		$this->display_admin_page_with_sidebar();
3429
+	}
3430
+
3431
+
3432
+	/**
3433
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
+	 *
3435
+	 * @access protected
3436
+	 * @return void
3437
+	 * @throws DomainException
3438
+	 */
3439
+	protected function _set_m_mt_settings()
3440
+	{
3441
+		// first if this is already set then lets get out no need to regenerate data.
3442
+		if (! empty($this->_m_mt_settings)) {
3443
+			return;
3444
+		}
3445
+
3446
+		// get all installed messengers and message_types
3447
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3448
+		$message_types = $this->_message_resource_manager->installed_message_types();
3449
+
3450
+
3451
+		// assemble the array for the _tab_text_links helper
3452
+
3453
+		foreach ($messengers as $messenger) {
3454
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+				'label' => ucwords($messenger->label['singular']),
3456
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
+					? 'messenger-active'
3458
+					: '',
3459
+				'href'  => $messenger->name,
3460
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
+				'slug'  => $messenger->name,
3462
+				'obj'   => $messenger,
3463
+			];
3464
+
3465
+
3466
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3467
+
3468
+			foreach ($message_types as $message_type) {
3469
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
+				// it shouldn't show in either the inactive OR active metabox.
3471
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
+					continue;
3473
+				}
3474
+
3475
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
+					$messenger->name,
3477
+					$message_type->name
3478
+				)
3479
+					? 'active'
3480
+					: 'inactive';
3481
+
3482
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
+					'label'    => ucwords($message_type->label['singular']),
3484
+					'class'    => 'message-type-' . $a_or_i,
3485
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
+					'title'    => $a_or_i === 'active'
3489
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
+					'content'  => $a_or_i === 'active'
3492
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3493
+						: $this->_message_type_settings_content($message_type, $messenger),
3494
+					'slug'     => $message_type->name,
3495
+					'active'   => $a_or_i === 'active',
3496
+					'obj'      => $message_type,
3497
+				];
3498
+			}
3499
+		}
3500
+	}
3501
+
3502
+
3503
+	/**
3504
+	 * This just prepares the content for the message type settings
3505
+	 *
3506
+	 * @param EE_message_type $message_type The message type object
3507
+	 * @param EE_messenger    $messenger    The messenger object
3508
+	 * @param boolean         $active       Whether the message type is active or not
3509
+	 * @return string html output for the content
3510
+	 * @throws DomainException
3511
+	 */
3512
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
+	{
3514
+		// get message type fields
3515
+		$fields                                         = $message_type->get_admin_settings_fields();
3516
+		$settings_template_args['template_form_fields'] = '';
3517
+
3518
+		if (! empty($fields) && $active) {
3519
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
+			foreach ($fields as $fldname => $fldprops) {
3521
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
+				$template_form_field[ $field_id ] = [
3523
+					'name'       => 'message_type_settings[' . $fldname . ']',
3524
+					'label'      => $fldprops['label'],
3525
+					'input'      => $fldprops['field_type'],
3526
+					'type'       => $fldprops['value_type'],
3527
+					'required'   => $fldprops['required'],
3528
+					'validation' => $fldprops['validation'],
3529
+					'value'      => isset($existing_settings[ $fldname ])
3530
+						? $existing_settings[ $fldname ]
3531
+						: $fldprops['default'],
3532
+					'options'    => isset($fldprops['options'])
3533
+						? $fldprops['options']
3534
+						: [],
3535
+					'default'    => isset($existing_settings[ $fldname ])
3536
+						? $existing_settings[ $fldname ]
3537
+						: $fldprops['default'],
3538
+					'css_class'  => 'no-drag',
3539
+					'format'     => $fldprops['format'],
3540
+				];
3541
+			}
3542
+
3543
+
3544
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
+				? $this->_generate_admin_form_fields(
3546
+					$template_form_field,
3547
+					'string',
3548
+					'ee_mt_activate_form'
3549
+				)
3550
+				: '';
3551
+		}
3552
+
3553
+		$settings_template_args['description'] = $message_type->description;
3554
+		// we also need some hidden fields
3555
+		$hidden_fields = [
3556
+			'message_type_settings[messenger]' . $message_type->name    => [
3557
+				'type'  => 'hidden',
3558
+				'value' => $messenger->name,
3559
+			],
3560
+			'message_type_settings[message_type]' . $message_type->name => [
3561
+				'type'  => 'hidden',
3562
+				'value' => $message_type->name,
3563
+			],
3564
+			'type' . $message_type->name                                => [
3565
+				'type'  => 'hidden',
3566
+				'value' => 'message_type',
3567
+			],
3568
+		];
3569
+
3570
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
+			$hidden_fields,
3572
+			'array'
3573
+		);
3574
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
+			? ' hidden'
3576
+			: '';
3577
+
3578
+
3579
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
+		return EEH_Template::display_template($template, $settings_template_args, true);
3581
+	}
3582
+
3583
+
3584
+	/**
3585
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
+	 *
3587
+	 * @access protected
3588
+	 * @return void
3589
+	 * @throws DomainException
3590
+	 */
3591
+	protected function _messages_settings_metaboxes()
3592
+	{
3593
+		$this->_set_m_mt_settings();
3594
+		$m_boxes         = $mt_boxes = [];
3595
+		$m_template_args = $mt_template_args = [];
3596
+
3597
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
+
3599
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
+
3605
+				// messenger meta boxes
3606
+				$active         = $selected_messenger === $messenger;
3607
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
+					: '';
3610
+
3611
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
+					esc_html__('%s Settings', 'event_espresso'),
3613
+					$tab_array['label']
3614
+				);
3615
+
3616
+				$m_template_args[ $messenger . '_a_box' ] = [
3617
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
+					'inactive_message_types' => isset(
3619
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
+					)
3621
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
+						: '',
3623
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
+					'hidden'                 => $active ? '' : ' hidden',
3625
+					'hide_on_message'        => $hide_on_message,
3626
+					'messenger'              => $messenger,
3627
+					'active'                 => $active,
3628
+				];
3629
+
3630
+				// message type meta boxes
3631
+				// (which is really just the inactive container for each messenger
3632
+				// showing inactive message types for that messenger)
3633
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
+				$mt_template_args[ $messenger . '_i_box' ] = [
3635
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
+					'inactive_message_types' => isset(
3637
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
+					)
3639
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
+						: '',
3641
+					'hidden'                 => $active ? '' : ' hidden',
3642
+					'hide_on_message'        => $hide_on_message,
3643
+					'hide_off_message'       => $hide_off_message,
3644
+					'messenger'              => $messenger,
3645
+					'active'                 => $active,
3646
+				];
3647
+			}
3648
+		}
3649
+
3650
+
3651
+		// register messenger metaboxes
3652
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
+		foreach ($m_boxes as $box => $label) {
3654
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
+			$msgr          = str_replace('_a_box', '', $box);
3656
+			add_meta_box(
3657
+				'espresso_' . $msgr . '_settings',
3658
+				$label,
3659
+				function ($post, $metabox) {
3660
+					EEH_Template::display_template(
3661
+						$metabox['args']['template_path'],
3662
+						$metabox['args']['template_args']
3663
+					);
3664
+				},
3665
+				$this->_current_screen->id,
3666
+				'normal',
3667
+				'high',
3668
+				$callback_args
3669
+			);
3670
+		}
3671
+
3672
+		// register message type metaboxes
3673
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
+		foreach ($mt_boxes as $box => $label) {
3675
+			$callback_args = [
3676
+				'template_path' => $mt_template_path,
3677
+				'template_args' => $mt_template_args[ $box ],
3678
+			];
3679
+			$mt            = str_replace('_i_box', '', $box);
3680
+			add_meta_box(
3681
+				'espresso_' . $mt . '_inactive_mts',
3682
+				$label,
3683
+				function ($post, $metabox) {
3684
+					EEH_Template::display_template(
3685
+						$metabox['args']['template_path'],
3686
+						$metabox['args']['template_args']
3687
+					);
3688
+				},
3689
+				$this->_current_screen->id,
3690
+				'side',
3691
+				'high',
3692
+				$callback_args
3693
+			);
3694
+		}
3695
+
3696
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3697
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
+		if (is_main_site()) {
3699
+			add_meta_box(
3700
+				'espresso_global_message_settings',
3701
+				esc_html__('Global Message Settings', 'event_espresso'),
3702
+				[$this, 'global_messages_settings_metabox_content'],
3703
+				$this->_current_screen->id,
3704
+				'normal',
3705
+				'low',
3706
+				[]
3707
+			);
3708
+		}
3709
+	}
3710
+
3711
+
3712
+	/**
3713
+	 *  This generates the content for the global messages settings metabox.
3714
+	 *
3715
+	 * @return void
3716
+	 * @throws EE_Error
3717
+	 * @throws InvalidArgumentException
3718
+	 * @throws ReflectionException
3719
+	 * @throws InvalidDataTypeException
3720
+	 * @throws InvalidInterfaceException
3721
+	 */
3722
+	public function global_messages_settings_metabox_content()
3723
+	{
3724
+		$form = $this->_generate_global_settings_form();
3725
+		echo wp_kses(
3726
+			$form->form_open(
3727
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
+				'POST'
3729
+			),
3730
+			AllowedTags::getWithFormTags()
3731
+		);
3732
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
+	}
3735
+
3736
+
3737
+	/**
3738
+	 * This generates and returns the form object for the global messages settings.
3739
+	 *
3740
+	 * @return EE_Form_Section_Proper
3741
+	 * @throws EE_Error
3742
+	 * @throws InvalidArgumentException
3743
+	 * @throws ReflectionException
3744
+	 * @throws InvalidDataTypeException
3745
+	 * @throws InvalidInterfaceException
3746
+	 */
3747
+	protected function _generate_global_settings_form()
3748
+	{
3749
+		/** @var EE_Network_Core_Config $network_config */
3750
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3751
+
3752
+		return new EE_Form_Section_Proper(
3753
+			[
3754
+				'name'            => 'global_messages_settings',
3755
+				'html_id'         => 'global_messages_settings',
3756
+				'html_class'      => 'form-table',
3757
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
+				'subsections'     => apply_filters(
3759
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
+					[
3761
+						'do_messages_on_same_request' => new EE_Select_Input(
3762
+							[
3763
+								true  => esc_html__('On the same request', 'event_espresso'),
3764
+								false => esc_html__('On a separate request', 'event_espresso'),
3765
+							],
3766
+							[
3767
+								'default'         => $network_config->do_messages_on_same_request,
3768
+								'html_label_text' => esc_html__(
3769
+									'Generate and send all messages:',
3770
+									'event_espresso'
3771
+								),
3772
+								'html_help_text'  => esc_html__(
3773
+									'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.',
3774
+									'event_espresso'
3775
+								),
3776
+							]
3777
+						),
3778
+						'delete_threshold'            => new EE_Select_Input(
3779
+							[
3780
+								0  => esc_html__('Forever', 'event_espresso'),
3781
+								3  => esc_html__('3 Months', 'event_espresso'),
3782
+								6  => esc_html__('6 Months', 'event_espresso'),
3783
+								9  => esc_html__('9 Months', 'event_espresso'),
3784
+								12 => esc_html__('12 Months', 'event_espresso'),
3785
+								24 => esc_html__('24 Months', 'event_espresso'),
3786
+								36 => esc_html__('36 Months', 'event_espresso'),
3787
+							],
3788
+							[
3789
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
+								'html_help_text'  => esc_html__(
3792
+									'You can control how long a record of processed messages is kept via this option.',
3793
+									'event_espresso'
3794
+								),
3795
+							]
3796
+						),
3797
+						'update_settings'             => new EE_Submit_Input(
3798
+							[
3799
+								'default'         => esc_html__('Update', 'event_espresso'),
3800
+								'html_label_text' => '',
3801
+							]
3802
+						),
3803
+					]
3804
+				),
3805
+			]
3806
+		);
3807
+	}
3808
+
3809
+
3810
+	/**
3811
+	 * This handles updating the global settings set on the admin page.
3812
+	 *
3813
+	 * @throws EE_Error
3814
+	 * @throws InvalidDataTypeException
3815
+	 * @throws InvalidInterfaceException
3816
+	 * @throws InvalidArgumentException
3817
+	 * @throws ReflectionException
3818
+	 */
3819
+	protected function _update_global_settings()
3820
+	{
3821
+		/** @var EE_Network_Core_Config $network_config */
3822
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3823
+		$messages_config = EE_Registry::instance()->CFG->messages;
3824
+		$form            = $this->_generate_global_settings_form();
3825
+		if ($form->was_submitted()) {
3826
+			$form->receive_form_submission();
3827
+			if ($form->is_valid()) {
3828
+				$valid_data = $form->valid_data();
3829
+				foreach ($valid_data as $property => $value) {
3830
+					$setter = 'set_' . $property;
3831
+					if (method_exists($network_config, $setter)) {
3832
+						$network_config->{$setter}($value);
3833
+					} elseif (
3834
+						property_exists($network_config, $property)
3835
+						&& $network_config->{$property} !== $value
3836
+					) {
3837
+						$network_config->{$property} = $value;
3838
+					} elseif (
3839
+						property_exists($messages_config, $property)
3840
+						&& $messages_config->{$property} !== $value
3841
+					) {
3842
+						$messages_config->{$property} = $value;
3843
+					}
3844
+				}
3845
+				// only update if the form submission was valid!
3846
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
+				EE_Registry::instance()->CFG->update_espresso_config();
3848
+				EE_Error::overwrite_success();
3849
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
+			}
3851
+		}
3852
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
+	}
3854
+
3855
+
3856
+	/**
3857
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
+	 *
3859
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
+	 * @return string html formatted tabs
3861
+	 * @throws DomainException
3862
+	 */
3863
+	protected function _get_mt_tabs($tab_array)
3864
+	{
3865
+		$tab_array = (array) $tab_array;
3866
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
+		$tabs      = '';
3868
+
3869
+		foreach ($tab_array as $tab) {
3870
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3871
+		}
3872
+
3873
+		return $tabs;
3874
+	}
3875
+
3876
+
3877
+	/**
3878
+	 * This prepares the content of the messenger meta box admin settings
3879
+	 *
3880
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3881
+	 * @return string html formatted content
3882
+	 * @throws DomainException
3883
+	 */
3884
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3885
+	{
3886
+
3887
+		$fields                                         = $messenger->get_admin_settings_fields();
3888
+		$settings_template_args['template_form_fields'] = '';
3889
+
3890
+		// is $messenger active?
3891
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
+
3893
+
3894
+		if (! empty($fields)) {
3895
+			$existing_settings = $messenger->get_existing_admin_settings();
3896
+
3897
+			foreach ($fields as $fldname => $fldprops) {
3898
+				$field_id                         = $messenger->name . '-' . $fldname;
3899
+				$template_form_field[ $field_id ] = [
3900
+					'name'       => 'messenger_settings[' . $field_id . ']',
3901
+					'label'      => $fldprops['label'],
3902
+					'input'      => $fldprops['field_type'],
3903
+					'type'       => $fldprops['value_type'],
3904
+					'required'   => $fldprops['required'],
3905
+					'validation' => $fldprops['validation'],
3906
+					'value'      => isset($existing_settings[ $field_id ])
3907
+						? $existing_settings[ $field_id ]
3908
+						: $fldprops['default'],
3909
+					'css_class'  => '',
3910
+					'format'     => $fldprops['format'],
3911
+				];
3912
+			}
3913
+
3914
+
3915
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
+				: '';
3918
+		}
3919
+
3920
+		// we also need some hidden fields
3921
+		$settings_template_args['hidden_fields'] = [
3922
+			'messenger_settings[messenger]' . $messenger->name => [
3923
+				'type'  => 'hidden',
3924
+				'value' => $messenger->name,
3925
+			],
3926
+			'type' . $messenger->name                          => [
3927
+				'type'  => 'hidden',
3928
+				'value' => 'messenger',
3929
+			],
3930
+		];
3931
+
3932
+		// make sure any active message types that are existing are included in the hidden fields
3933
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
+					'type'  => 'hidden',
3937
+					'value' => $mt,
3938
+				];
3939
+			}
3940
+		}
3941
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
+			$settings_template_args['hidden_fields'],
3943
+			'array'
3944
+		);
3945
+		$active                                  =
3946
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3947
+
3948
+		$settings_template_args['messenger']           = $messenger->name;
3949
+		$settings_template_args['description']         = $messenger->description;
3950
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
+
3952
+
3953
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
+			$messenger->name
3955
+		)
3956
+			? $settings_template_args['show_hide_edit_form']
3957
+			: ' hidden';
3958
+
3959
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
+			? ' hidden'
3961
+			: $settings_template_args['show_hide_edit_form'];
3962
+
3963
+
3964
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
+		$settings_template_args['on_off_status'] = $active;
3967
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
+		return EEH_Template::display_template(
3969
+			$template,
3970
+			$settings_template_args,
3971
+			true
3972
+		);
3973
+	}
3974
+
3975
+
3976
+	/**
3977
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3978
+	 *
3979
+	 * @throws DomainException
3980
+	 * @throws EE_Error
3981
+	 * @throws InvalidDataTypeException
3982
+	 * @throws InvalidInterfaceException
3983
+	 * @throws InvalidArgumentException
3984
+	 * @throws ReflectionException
3985
+	 */
3986
+	public function activate_messenger_toggle()
3987
+	{
3988
+		$success = true;
3989
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
+		// let's check that we have required data
3991
+
3992
+		if (! $this->_active_messenger_name) {
3993
+			EE_Error::add_error(
3994
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
+				__FILE__,
3996
+				__FUNCTION__,
3997
+				__LINE__
3998
+			);
3999
+			$success = false;
4000
+		}
4001
+
4002
+		// do a nonce check here since we're not arriving via a normal route
4003
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
+
4006
+		$this->_verify_nonce($nonce, $nonce_ref);
4007
+
4008
+
4009
+		$status = $this->request->getRequestParam('status');
4010
+		if (! $status) {
4011
+			EE_Error::add_error(
4012
+				esc_html__(
4013
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
+					'event_espresso'
4015
+				),
4016
+				__FILE__,
4017
+				__FUNCTION__,
4018
+				__LINE__
4019
+			);
4020
+			$success = false;
4021
+		}
4022
+
4023
+		// do check to verify we have a valid status.
4024
+		if ($status !== 'off' && $status !== 'on') {
4025
+			EE_Error::add_error(
4026
+				sprintf(
4027
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
+					$status
4029
+				),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034
+			$success = false;
4035
+		}
4036
+
4037
+		if ($success) {
4038
+			// made it here?  Stop dawdling then!!
4039
+			$success = $status === 'off'
4040
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4041
+				: $this->_activate_messenger($this->_active_messenger_name);
4042
+		}
4043
+
4044
+		$this->_template_args['success'] = $success;
4045
+
4046
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
+		$this->_return_json();
4048
+	}
4049
+
4050
+
4051
+	/**
4052
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4053
+	 *
4054
+	 * @throws DomainException
4055
+	 * @throws EE_Error
4056
+	 * @throws ReflectionException
4057
+	 * @throws InvalidDataTypeException
4058
+	 * @throws InvalidInterfaceException
4059
+	 * @throws InvalidArgumentException
4060
+	 */
4061
+	public function activate_mt_toggle()
4062
+	{
4063
+		$success = true;
4064
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
+
4066
+		// let's make sure we have the necessary data
4067
+		if (! $this->_active_message_type_name) {
4068
+			EE_Error::add_error(
4069
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
+				__FILE__,
4071
+				__FUNCTION__,
4072
+				__LINE__
4073
+			);
4074
+			$success = false;
4075
+		}
4076
+
4077
+		if (! $this->_active_messenger_name) {
4078
+			EE_Error::add_error(
4079
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
+				__FILE__,
4081
+				__FUNCTION__,
4082
+				__LINE__
4083
+			);
4084
+			$success = false;
4085
+		}
4086
+
4087
+		$status = $this->request->getRequestParam('status');
4088
+		if (! $status) {
4089
+			EE_Error::add_error(
4090
+				esc_html__(
4091
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
+					'event_espresso'
4093
+				),
4094
+				__FILE__,
4095
+				__FUNCTION__,
4096
+				__LINE__
4097
+			);
4098
+			$success = false;
4099
+		}
4100
+
4101
+
4102
+		// do check to verify we have a valid status.
4103
+		if ($status !== 'activate' && $status !== 'deactivate') {
4104
+			EE_Error::add_error(
4105
+				sprintf(
4106
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
+					$status
4108
+				),
4109
+				__FILE__,
4110
+				__FUNCTION__,
4111
+				__LINE__
4112
+			);
4113
+			$success = false;
4114
+		}
4115
+
4116
+
4117
+		// do a nonce check here since we're not arriving via a normal route
4118
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4119
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
+
4121
+		if ($success) {
4122
+			// made it here? um, what are you waiting for then?
4123
+			$success = $status === 'deactivate'
4124
+				? $this->_deactivate_message_type_for_messenger(
4125
+					$this->_active_messenger_name,
4126
+					$this->_active_message_type_name
4127
+				)
4128
+				: $this->_activate_message_type_for_messenger(
4129
+					$this->_active_messenger_name,
4130
+					$this->_active_message_type_name
4131
+				);
4132
+		}
4133
+
4134
+		$this->_template_args['success'] = $success;
4135
+		$this->_return_json();
4136
+	}
4137
+
4138
+
4139
+	/**
4140
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4141
+	 *
4142
+	 * @param string $messenger_name The name of the messenger being activated
4143
+	 * @return bool
4144
+	 * @throws DomainException
4145
+	 * @throws EE_Error
4146
+	 * @throws InvalidArgumentException
4147
+	 * @throws ReflectionException
4148
+	 * @throws InvalidDataTypeException
4149
+	 * @throws InvalidInterfaceException
4150
+	 */
4151
+	protected function _activate_messenger($messenger_name)
4152
+	{
4153
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
+			? $active_messenger->get_default_message_types()
4156
+			: [];
4157
+
4158
+		// ensure is active
4159
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
+
4161
+		// set response_data for reload
4162
+		foreach ($message_types_to_activate as $message_type_name) {
4163
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
+			if (
4165
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4166
+					$messenger_name,
4167
+					$message_type_name
4168
+				)
4169
+				&& $message_type instanceof EE_message_type
4170
+			) {
4171
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4172
+				if ($message_type->get_admin_settings_fields()) {
4173
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
+				}
4175
+			}
4176
+		}
4177
+
4178
+		// add success message for activating messenger
4179
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
+	}
4181
+
4182
+
4183
+	/**
4184
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
+	 *
4186
+	 * @param string $messenger_name The name of the messenger being activated
4187
+	 * @return bool
4188
+	 * @throws DomainException
4189
+	 * @throws EE_Error
4190
+	 * @throws InvalidArgumentException
4191
+	 * @throws ReflectionException
4192
+	 * @throws InvalidDataTypeException
4193
+	 * @throws InvalidInterfaceException
4194
+	 */
4195
+	protected function _deactivate_messenger($messenger_name)
4196
+	{
4197
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
+
4200
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
+	}
4202
+
4203
+
4204
+	/**
4205
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
+	 *
4207
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4209
+	 * @return bool
4210
+	 * @throws DomainException
4211
+	 * @throws EE_Error
4212
+	 * @throws InvalidArgumentException
4213
+	 * @throws ReflectionException
4214
+	 * @throws InvalidDataTypeException
4215
+	 * @throws InvalidInterfaceException
4216
+	 */
4217
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
+	{
4219
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
+
4222
+		// ensure is active
4223
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
+
4225
+		// set response for load
4226
+		if (
4227
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4228
+				$messenger_name,
4229
+				$message_type_name
4230
+			)
4231
+		) {
4232
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4233
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4234
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
+			}
4236
+		}
4237
+
4238
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
+			$active_messenger,
4240
+			$message_type_to_activate
4241
+		);
4242
+	}
4243
+
4244
+
4245
+	/**
4246
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
+	 *
4248
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
+	 * @return bool
4251
+	 * @throws DomainException
4252
+	 * @throws EE_Error
4253
+	 * @throws InvalidArgumentException
4254
+	 * @throws ReflectionException
4255
+	 * @throws InvalidDataTypeException
4256
+	 * @throws InvalidInterfaceException
4257
+	 */
4258
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
+	{
4260
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
+
4265
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
+			$active_messenger,
4267
+			$message_type_to_deactivate
4268
+		);
4269
+	}
4270
+
4271
+
4272
+	/**
4273
+	 * This just initializes the defaults for activating messenger and message type responses.
4274
+	 */
4275
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
+	{
4277
+		$this->_template_args['data']['active_mts'] = [];
4278
+		$this->_template_args['data']['mt_reload']  = [];
4279
+	}
4280
+
4281
+
4282
+	/**
4283
+	 * Setup appropriate response for activating a messenger and/or message types
4284
+	 *
4285
+	 * @param EE_messenger         $messenger
4286
+	 * @param EE_message_type|null $message_type
4287
+	 * @return bool
4288
+	 * @throws DomainException
4289
+	 * @throws EE_Error
4290
+	 * @throws InvalidArgumentException
4291
+	 * @throws ReflectionException
4292
+	 * @throws InvalidDataTypeException
4293
+	 * @throws InvalidInterfaceException
4294
+	 */
4295
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
+		$messenger,
4297
+		EE_Message_Type $message_type = null
4298
+	) {
4299
+		// if $messenger isn't a valid messenger object then get out.
4300
+		if (! $messenger instanceof EE_Messenger) {
4301
+			EE_Error::add_error(
4302
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
+				__FILE__,
4304
+				__FUNCTION__,
4305
+				__LINE__
4306
+			);
4307
+			return false;
4308
+		}
4309
+		// activated
4310
+		if ($this->_template_args['data']['active_mts']) {
4311
+			EE_Error::overwrite_success();
4312
+			// activated a message type with the messenger
4313
+			if ($message_type instanceof EE_message_type) {
4314
+				EE_Error::add_success(
4315
+					sprintf(
4316
+						esc_html__(
4317
+							'%s message type has been successfully activated with the %s messenger',
4318
+							'event_espresso'
4319
+						),
4320
+						ucwords($message_type->label['singular']),
4321
+						ucwords($messenger->label['singular'])
4322
+					)
4323
+				);
4324
+
4325
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4326
+				if ($message_type->name === 'invoice') {
4327
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
+					if ($pm instanceof EE_Payment_Method) {
4330
+						EE_Error::add_attention(
4331
+							esc_html__(
4332
+								'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.',
4333
+								'event_espresso'
4334
+							)
4335
+						);
4336
+					}
4337
+				}
4338
+				// just toggles the entire messenger
4339
+			} else {
4340
+				EE_Error::add_success(
4341
+					sprintf(
4342
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
+						ucwords($messenger->label['singular'])
4344
+					)
4345
+				);
4346
+			}
4347
+
4348
+			return true;
4349
+
4350
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
+			// in which case we just give a success message for the messenger being successfully activated.
4353
+		} else {
4354
+			if (! $messenger->get_default_message_types()) {
4355
+				// messenger doesn't have any default message types so still a success.
4356
+				EE_Error::add_success(
4357
+					sprintf(
4358
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
+						ucwords($messenger->label['singular'])
4360
+					)
4361
+				);
4362
+
4363
+				return true;
4364
+			} else {
4365
+				EE_Error::add_error(
4366
+					$message_type instanceof EE_message_type
4367
+					? sprintf(
4368
+						esc_html__(
4369
+							'%s message type was not successfully activated with the %s messenger',
4370
+							'event_espresso'
4371
+						),
4372
+						ucwords($message_type->label['singular']),
4373
+						ucwords($messenger->label['singular'])
4374
+					)
4375
+					: sprintf(
4376
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
+						ucwords($messenger->label['singular'])
4378
+					),
4379
+					__FILE__,
4380
+					__FUNCTION__,
4381
+					__LINE__
4382
+				);
4383
+
4384
+				return false;
4385
+			}
4386
+		}
4387
+	}
4388
+
4389
+
4390
+	/**
4391
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
+	 *
4393
+	 * @param EE_messenger         $messenger
4394
+	 * @param EE_message_type|null $message_type
4395
+	 * @return bool
4396
+	 * @throws DomainException
4397
+	 * @throws EE_Error
4398
+	 * @throws InvalidArgumentException
4399
+	 * @throws ReflectionException
4400
+	 * @throws InvalidDataTypeException
4401
+	 * @throws InvalidInterfaceException
4402
+	 */
4403
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
+		$messenger,
4405
+		EE_message_type $message_type = null
4406
+	) {
4407
+		EE_Error::overwrite_success();
4408
+
4409
+		// if $messenger isn't a valid messenger object then get out.
4410
+		if (! $messenger instanceof EE_Messenger) {
4411
+			EE_Error::add_error(
4412
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
+				__FILE__,
4414
+				__FUNCTION__,
4415
+				__LINE__
4416
+			);
4417
+
4418
+			return false;
4419
+		}
4420
+
4421
+		if ($message_type instanceof EE_message_type) {
4422
+			$message_type_name = $message_type->name;
4423
+			EE_Error::add_success(
4424
+				sprintf(
4425
+					esc_html__(
4426
+						'%s message type has been successfully deactivated for the %s messenger.',
4427
+						'event_espresso'
4428
+					),
4429
+					ucwords($message_type->label['singular']),
4430
+					ucwords($messenger->label['singular'])
4431
+				)
4432
+			);
4433
+		} else {
4434
+			$message_type_name = '';
4435
+			EE_Error::add_success(
4436
+				sprintf(
4437
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
+					ucwords($messenger->label['singular'])
4439
+				)
4440
+			);
4441
+		}
4442
+
4443
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
+		if (
4445
+			$messenger->name === 'html'
4446
+			&& (
4447
+				is_null($message_type)
4448
+				|| $message_type_name === 'invoice'
4449
+			)
4450
+		) {
4451
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
+			if ($count_updated > 0) {
4454
+				$msg = $message_type_name === 'invoice'
4455
+					? esc_html__(
4456
+						'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.',
4457
+						'event_espresso'
4458
+					)
4459
+					: esc_html__(
4460
+						'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.',
4461
+						'event_espresso'
4462
+					);
4463
+				EE_Error::add_attention($msg);
4464
+			}
4465
+		}
4466
+
4467
+		return true;
4468
+	}
4469
+
4470
+
4471
+	/**
4472
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
+	 *
4474
+	 * @throws DomainException
4475
+	 * @throws EE_Error
4476
+	 * @throws EE_Error
4477
+	 */
4478
+	public function update_mt_form()
4479
+	{
4480
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
+			EE_Error::add_error(
4482
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
+				__FILE__,
4484
+				__FUNCTION__,
4485
+				__LINE__
4486
+			);
4487
+			$this->_return_json();
4488
+		}
4489
+
4490
+		$message_types = $this->get_installed_message_types();
4491
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4492
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
+
4495
+		$this->_template_args['success'] = true;
4496
+		$this->_template_args['content'] = $content;
4497
+		$this->_return_json();
4498
+	}
4499
+
4500
+
4501
+	/**
4502
+	 * this handles saving the settings for a messenger or message type
4503
+	 *
4504
+	 * @throws EE_Error
4505
+	 * @throws EE_Error
4506
+	 */
4507
+	public function save_settings()
4508
+	{
4509
+		$type = $this->request->getRequestParam('type');
4510
+		if (! $type) {
4511
+			EE_Error::add_error(
4512
+				esc_html__(
4513
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
+					'event_espresso'
4515
+				),
4516
+				__FILE__,
4517
+				__FUNCTION__,
4518
+				__LINE__
4519
+			);
4520
+			$this->_template_args['error'] = true;
4521
+			$this->_return_json();
4522
+		}
4523
+
4524
+
4525
+		if ($type === 'messenger') {
4526
+			// this should be an array.
4527
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
+			$messenger = $settings['messenger'];
4529
+			// remove messenger and message_types from settings array
4530
+			unset($settings['messenger'], $settings['message_types']);
4531
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
+		} elseif ($type === 'message_type') {
4533
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
+			$messenger    = $settings['messenger'];
4535
+			$message_type = $settings['message_type'];
4536
+			// remove messenger and message_types from settings array
4537
+			unset($settings['messenger'], $settings['message_types']);
4538
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
+		}
4540
+
4541
+		// okay we should have the data all setup.  Now we just update!
4542
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4543
+
4544
+		if ($success) {
4545
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
+		} else {
4547
+			EE_Error::add_error(
4548
+				esc_html__('Settings did not get updated', 'event_espresso'),
4549
+				__FILE__,
4550
+				__FUNCTION__,
4551
+				__LINE__
4552
+			);
4553
+		}
4554
+
4555
+		$this->_template_args['success'] = $success;
4556
+		$this->_return_json();
4557
+	}
4558
+
4559
+
4560
+
4561
+
4562
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4563
+
4564
+
4565
+	/**
4566
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
+	 * However, this does not send immediately, it just queues for sending.
4568
+	 *
4569
+	 * @throws EE_Error
4570
+	 * @throws InvalidDataTypeException
4571
+	 * @throws InvalidInterfaceException
4572
+	 * @throws InvalidArgumentException
4573
+	 * @throws ReflectionException
4574
+	 * @since 4.9.0
4575
+	 */
4576
+	protected function _generate_now()
4577
+	{
4578
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
+		$this->_redirect_after_action(false, '', '', [], true);
4580
+	}
4581
+
4582
+
4583
+	/**
4584
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4586
+	 *
4587
+	 * @throws EE_Error
4588
+	 * @throws InvalidDataTypeException
4589
+	 * @throws InvalidInterfaceException
4590
+	 * @throws InvalidArgumentException
4591
+	 * @throws ReflectionException
4592
+	 * @since 4.9.0
4593
+	 */
4594
+	protected function _generate_and_send_now()
4595
+	{
4596
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
+		$this->_redirect_after_action(false, '', '', [], true);
4598
+	}
4599
+
4600
+
4601
+	/**
4602
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
+	 *
4604
+	 * @throws EE_Error
4605
+	 * @throws InvalidDataTypeException
4606
+	 * @throws InvalidInterfaceException
4607
+	 * @throws InvalidArgumentException
4608
+	 * @throws ReflectionException
4609
+	 * @since 4.9.0
4610
+	 */
4611
+	protected function _queue_for_resending()
4612
+	{
4613
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
+		$this->_redirect_after_action(false, '', '', [], true);
4615
+	}
4616
+
4617
+
4618
+	/**
4619
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
+	 *
4621
+	 * @throws EE_Error
4622
+	 * @throws InvalidDataTypeException
4623
+	 * @throws InvalidInterfaceException
4624
+	 * @throws InvalidArgumentException
4625
+	 * @throws ReflectionException
4626
+	 * @since 4.9.0
4627
+	 */
4628
+	protected function _send_now()
4629
+	{
4630
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
+		$this->_redirect_after_action(false, '', '', [], true);
4632
+	}
4633
+
4634
+
4635
+	/**
4636
+	 * Deletes EE_messages for IDs in the request.
4637
+	 *
4638
+	 * @throws EE_Error
4639
+	 * @throws InvalidDataTypeException
4640
+	 * @throws InvalidInterfaceException
4641
+	 * @throws InvalidArgumentException
4642
+	 * @since 4.9.0
4643
+	 */
4644
+	protected function _delete_ee_messages()
4645
+	{
4646
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4647
+		$deleted_count = 0;
4648
+		foreach ($MSG_IDs as $MSG_ID) {
4649
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
+				$deleted_count++;
4651
+			}
4652
+		}
4653
+		if ($deleted_count) {
4654
+			EE_Error::add_success(
4655
+				esc_html(
4656
+					_n(
4657
+						'Message successfully deleted',
4658
+						'Messages successfully deleted',
4659
+						$deleted_count,
4660
+						'event_espresso'
4661
+					)
4662
+				)
4663
+			);
4664
+		} else {
4665
+			EE_Error::add_error(
4666
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
+				__FILE__,
4668
+				__FUNCTION__,
4669
+				__LINE__
4670
+			);
4671
+		}
4672
+		$this->_redirect_after_action(false, '', '', [], true);
4673
+	}
4674
+
4675
+
4676
+	/**
4677
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
+	 *
4679
+	 * @return array
4680
+	 * @since 4.9.0
4681
+	 */
4682
+	protected function _get_msg_ids_from_request()
4683
+	{
4684
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
+		if (empty($MSG_IDs)) {
4686
+			return [];
4687
+		}
4688
+		// if 'MSG_ID' was just a single ID (not an array)
4689
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
+			? $MSG_IDs
4693
+			: array_keys($MSG_IDs);
4694
+	}
4695 4695
 }
Please login to merge, or discard this patch.
espresso.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '7.2.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '7.2.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.41.rc.000');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.41.rc.000');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
+    if ( ! function_exists('espresso_duplicate_plugin_error')) {
42 42
         /**
43 43
          *    espresso_duplicate_plugin_error
44 44
          *    displays if more than one version of EE is activated at the same time
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64 64
     define('EE_MIN_PHP_VER_REQUIRED', '7.2.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66 66
         /**
67 67
          * espresso_minimum_php_version_error
68 68
          *
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
 
117 117
         register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
119
+        require_once __DIR__.'/core/bootstrap_espresso.php';
120 120
         bootstrap_espresso();
121 121
     }
122 122
 }
123
-if (! function_exists('espresso_deactivate_plugin')) {
123
+if ( ! function_exists('espresso_deactivate_plugin')) {
124 124
     /**
125 125
      *    deactivate_plugin
126 126
      * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
      */
132 132
     function espresso_deactivate_plugin($plugin_basename = '')
133 133
     {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
134
+        if ( ! function_exists('deactivate_plugins')) {
135
+            require_once ABSPATH.'wp-admin/includes/plugin.php';
136 136
         }
137 137
         unset($_GET['activate'], $_REQUEST['activate']);
138 138
         deactivate_plugins($plugin_basename);
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 1 patch
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -18,224 +18,224 @@
 block discarded – undo
18 18
  */
19 19
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
20 20
 {
21
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
22
-
23
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
24
-
25
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
26
-
27
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
28
-
29
-    /**
30
-     * numerical value used for sorting form steps
31
-     *
32
-     * @var int $order
33
-     */
34
-    private $order = 1;
35
-
36
-    /**
37
-     * a final URL with all form related parameters added
38
-     * that will be used to advance to the next step
39
-     *
40
-     * @var string $redirect_url
41
-     */
42
-    private $redirect_url = '';
43
-
44
-    /**
45
-     * URL params in key value pairs
46
-     *
47
-     * @var array $redirect_args
48
-     */
49
-    private $redirect_args = array();
50
-
51
-    /**
52
-     * Which step should be redirected to after form processing.
53
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
54
-     * If a form is invalid and requires errors to be corrected,
55
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
56
-     * Some form handlers do not have a form that is displayable,
57
-     * and only perform data processing, but if an error occurs,
58
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
59
-     * since the current step has no displayable content.
60
-     * if the form is completely finished, and needs to redirect to somewhere
61
-     * completely different, then this value will be REDIRECT_TO_OTHER
62
-     *
63
-     * @var string $redirect_to
64
-     */
65
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
66
-
67
-
68
-    /**
69
-     * SequentialStepForm constructor
70
-     *
71
-     * @param int              $order
72
-     * @param string           $form_name
73
-     * @param string           $admin_name
74
-     * @param string           $slug
75
-     * @param string           $form_action
76
-     * @param string           $form_config
77
-     * @param EE_Registry|null $registry
78
-     */
79
-    public function __construct(
80
-        $order,
81
-        $form_name,
82
-        $admin_name,
83
-        $slug,
84
-        $form_action = '',
85
-        $form_config = 'add_form_tags_and_submit',
86
-        ?EE_Registry $registry = null
87
-    ) {
88
-        $this->setOrder($order);
89
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * @return int
96
-     */
97
-    public function order()
98
-    {
99
-        return $this->order;
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * @param int $order
106
-     * @throws InvalidArgumentException
107
-     */
108
-    public function setOrder($order)
109
-    {
110
-        $order = absint($order);
111
-        if (! $order > 0) {
112
-            throw new InvalidArgumentException(
113
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
114
-            );
115
-        }
116
-        $this->order = $order;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * @return string
123
-     */
124
-    public function redirectUrl()
125
-    {
126
-        return ! empty($this->redirect_args)
127
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
128
-            : $this->redirect_url;
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @param string $redirect_url
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidArgumentException
137
-     */
138
-    public function setRedirectUrl($redirect_url)
139
-    {
140
-        if (! is_string($redirect_url)) {
141
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
142
-        }
143
-        if (empty($redirect_url)) {
144
-            throw new InvalidArgumentException(
145
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
146
-            );
147
-        }
148
-        $this->redirect_url = $redirect_url;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * @param array $redirect_args
155
-     * @throws InvalidDataTypeException
156
-     * @throws InvalidArgumentException
157
-     */
158
-    public function addRedirectArgs($redirect_args = array())
159
-    {
160
-        if (is_object($redirect_args)) {
161
-            throw new InvalidDataTypeException(
162
-                '$redirect_args',
163
-                $redirect_args,
164
-                'anything other than an object was expected.'
165
-            );
166
-        }
167
-        if (empty($redirect_args)) {
168
-            throw new InvalidArgumentException(
169
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
170
-            );
171
-        }
172
-        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * @param array $redirect_arg_keys_to_remove
179
-     * @throws InvalidDataTypeException
180
-     * @throws InvalidArgumentException
181
-     */
182
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
183
-    {
184
-        if (is_object($redirect_arg_keys_to_remove)) {
185
-            throw new InvalidDataTypeException(
186
-                '$redirect_arg_keys_to_remove',
187
-                $redirect_arg_keys_to_remove,
188
-                'anything other than an object was expected.'
189
-            );
190
-        }
191
-        if (empty($redirect_arg_keys_to_remove)) {
192
-            throw new InvalidArgumentException(
193
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
194
-            );
195
-        }
196
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
197
-            unset($this->redirect_args[ $redirect_arg_key ]);
198
-        }
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * @return string
205
-     */
206
-    public function redirectTo()
207
-    {
208
-        return $this->redirect_to;
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * @param string $redirect_to
215
-     * @throws InvalidDataTypeException
216
-     */
217
-    public function setRedirectTo($redirect_to)
218
-    {
219
-        if (
220
-            ! in_array(
221
-                $redirect_to,
222
-                array(
223
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
224
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
225
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
226
-                    SequentialStepForm::REDIRECT_TO_OTHER,
227
-                ),
228
-                true
229
-            )
230
-        ) {
231
-            throw new InvalidDataTypeException(
232
-                'setRedirectTo()',
233
-                $redirect_to,
234
-                'one of the SequentialStepForm class constants was expected.'
235
-            );
236
-        }
237
-        $this->redirect_to = $redirect_to;
238
-    }
21
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
22
+
23
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
24
+
25
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
26
+
27
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
28
+
29
+	/**
30
+	 * numerical value used for sorting form steps
31
+	 *
32
+	 * @var int $order
33
+	 */
34
+	private $order = 1;
35
+
36
+	/**
37
+	 * a final URL with all form related parameters added
38
+	 * that will be used to advance to the next step
39
+	 *
40
+	 * @var string $redirect_url
41
+	 */
42
+	private $redirect_url = '';
43
+
44
+	/**
45
+	 * URL params in key value pairs
46
+	 *
47
+	 * @var array $redirect_args
48
+	 */
49
+	private $redirect_args = array();
50
+
51
+	/**
52
+	 * Which step should be redirected to after form processing.
53
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
54
+	 * If a form is invalid and requires errors to be corrected,
55
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
56
+	 * Some form handlers do not have a form that is displayable,
57
+	 * and only perform data processing, but if an error occurs,
58
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
59
+	 * since the current step has no displayable content.
60
+	 * if the form is completely finished, and needs to redirect to somewhere
61
+	 * completely different, then this value will be REDIRECT_TO_OTHER
62
+	 *
63
+	 * @var string $redirect_to
64
+	 */
65
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
66
+
67
+
68
+	/**
69
+	 * SequentialStepForm constructor
70
+	 *
71
+	 * @param int              $order
72
+	 * @param string           $form_name
73
+	 * @param string           $admin_name
74
+	 * @param string           $slug
75
+	 * @param string           $form_action
76
+	 * @param string           $form_config
77
+	 * @param EE_Registry|null $registry
78
+	 */
79
+	public function __construct(
80
+		$order,
81
+		$form_name,
82
+		$admin_name,
83
+		$slug,
84
+		$form_action = '',
85
+		$form_config = 'add_form_tags_and_submit',
86
+		?EE_Registry $registry = null
87
+	) {
88
+		$this->setOrder($order);
89
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * @return int
96
+	 */
97
+	public function order()
98
+	{
99
+		return $this->order;
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * @param int $order
106
+	 * @throws InvalidArgumentException
107
+	 */
108
+	public function setOrder($order)
109
+	{
110
+		$order = absint($order);
111
+		if (! $order > 0) {
112
+			throw new InvalidArgumentException(
113
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
114
+			);
115
+		}
116
+		$this->order = $order;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * @return string
123
+	 */
124
+	public function redirectUrl()
125
+	{
126
+		return ! empty($this->redirect_args)
127
+			? add_query_arg($this->redirect_args, $this->redirect_url)
128
+			: $this->redirect_url;
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @param string $redirect_url
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidArgumentException
137
+	 */
138
+	public function setRedirectUrl($redirect_url)
139
+	{
140
+		if (! is_string($redirect_url)) {
141
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
142
+		}
143
+		if (empty($redirect_url)) {
144
+			throw new InvalidArgumentException(
145
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
146
+			);
147
+		}
148
+		$this->redirect_url = $redirect_url;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * @param array $redirect_args
155
+	 * @throws InvalidDataTypeException
156
+	 * @throws InvalidArgumentException
157
+	 */
158
+	public function addRedirectArgs($redirect_args = array())
159
+	{
160
+		if (is_object($redirect_args)) {
161
+			throw new InvalidDataTypeException(
162
+				'$redirect_args',
163
+				$redirect_args,
164
+				'anything other than an object was expected.'
165
+			);
166
+		}
167
+		if (empty($redirect_args)) {
168
+			throw new InvalidArgumentException(
169
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
170
+			);
171
+		}
172
+		$this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * @param array $redirect_arg_keys_to_remove
179
+	 * @throws InvalidDataTypeException
180
+	 * @throws InvalidArgumentException
181
+	 */
182
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
183
+	{
184
+		if (is_object($redirect_arg_keys_to_remove)) {
185
+			throw new InvalidDataTypeException(
186
+				'$redirect_arg_keys_to_remove',
187
+				$redirect_arg_keys_to_remove,
188
+				'anything other than an object was expected.'
189
+			);
190
+		}
191
+		if (empty($redirect_arg_keys_to_remove)) {
192
+			throw new InvalidArgumentException(
193
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
194
+			);
195
+		}
196
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
197
+			unset($this->redirect_args[ $redirect_arg_key ]);
198
+		}
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * @return string
205
+	 */
206
+	public function redirectTo()
207
+	{
208
+		return $this->redirect_to;
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * @param string $redirect_to
215
+	 * @throws InvalidDataTypeException
216
+	 */
217
+	public function setRedirectTo($redirect_to)
218
+	{
219
+		if (
220
+			! in_array(
221
+				$redirect_to,
222
+				array(
223
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
224
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
225
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
226
+					SequentialStepForm::REDIRECT_TO_OTHER,
227
+				),
228
+				true
229
+			)
230
+		) {
231
+			throw new InvalidDataTypeException(
232
+				'setRedirectTo()',
233
+				$redirect_to,
234
+				'one of the SequentialStepForm class constants was expected.'
235
+			);
236
+		}
237
+		$this->redirect_to = $redirect_to;
238
+	}
239 239
 }
240 240
 // End of file SequentialStepForm.php
241 241
 // Location: /SequentialStepForm.php
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Generated_From_Token.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -11,111 +11,111 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Message_Generated_From_Token extends EE_Message_To_Generate implements EEI_Has_Sending_Messenger
13 13
 {
14
-    /**
15
-     * Sending messenger
16
-     *
17
-     * @type EE_messenger | string
18
-     */
19
-    protected $_sending_messenger = '';
20
-
21
-
22
-    /**
23
-     * Holds the incoming token;
24
-     * @type string
25
-     */
26
-    public $token = '';
27
-
28
-
29
-    /**
30
-     * Constructor
31
-     *
32
-     * @param   string    $sending_messenger_slug     This is used to set what messenger is used to "send"
33
-     *                                                the EE_Message retrieved from the DB via the given token.
34
-     * @param   string $token                         This is a token for a Message that should already exist int the db.
35
-     *                                                This is then used to populate the properties in here.
36
-     * @param   EE_Message_Resource_Manager $message_resource_manager
37
-     */
38
-    public function __construct($token, $sending_messenger_slug, EE_Message_Resource_Manager $message_resource_manager)
39
-    {
40
-        $this->token = $token;
41
-        $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager);
42
-        $this->_message = $this->_generate_message();
43
-        // set params for parent from the message object
44
-        parent::__construct(
45
-            $this->_message->messenger(),
46
-            $this->_message->message_type(),
47
-            array(),
48
-            $this->_message->context(),
49
-            false
50
-        );
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * @param string                       $sending_messenger_slug
57
-     * @param \EE_Message_Resource_Manager $message_resource_manager
58
-     * @return \EE_messenger | string
59
-     */
60
-    protected function _set_sending_messenger(
61
-        $sending_messenger_slug,
62
-        EE_Message_Resource_Manager $message_resource_manager
63
-    ) {
64
-        $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug);
65
-        return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug;
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * @return EE_messenger
72
-     */
73
-    public function sending_messenger()
74
-    {
75
-        return $this->_sending_messenger;
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * generates an EE_Message using the supplied arguments and some defaults
82
-     *
83
-     * @param array $properties
84
-     * @return EE_Message
85
-     * @throws \EE_Error
86
-     */
87
-    protected function _generate_message($properties = array())
88
-    {
89
-        // a message was generated immediately but the parent class will call this again
90
-        if ($this->_message instanceof EE_Message) {
91
-            return $this->_message;
92
-        }
93
-        $message = EEM_Message::instance()->get_one_by_token($this->token);
94
-        if (! $message instanceof EE_Message) {
95
-            throw new EE_Error(
96
-                sprintf(
97
-                    esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'),
98
-                    $this->token
99
-                )
100
-            );
101
-        }
102
-        $message->set_STS_ID(EEM_Message::status_idle);
103
-
104
-        if (! $this->_sending_messenger instanceof EE_messenger) {
105
-            $message->set_STS_ID(EEM_Message::status_failed);
106
-            $message->set_error_message(
107
-                sprintf(
108
-                    esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'),
109
-                    $this->_sending_messenger
110
-                )
111
-            );
112
-        }
113
-
114
-        // set properties
115
-        $this->_valid = true;
116
-        $this->_messenger = $message->messenger_object();
117
-        $this->_message_type = $message->message_type_object();
118
-        $this->_send_now = $message->send_now();
119
-        return $message;
120
-    }
14
+	/**
15
+	 * Sending messenger
16
+	 *
17
+	 * @type EE_messenger | string
18
+	 */
19
+	protected $_sending_messenger = '';
20
+
21
+
22
+	/**
23
+	 * Holds the incoming token;
24
+	 * @type string
25
+	 */
26
+	public $token = '';
27
+
28
+
29
+	/**
30
+	 * Constructor
31
+	 *
32
+	 * @param   string    $sending_messenger_slug     This is used to set what messenger is used to "send"
33
+	 *                                                the EE_Message retrieved from the DB via the given token.
34
+	 * @param   string $token                         This is a token for a Message that should already exist int the db.
35
+	 *                                                This is then used to populate the properties in here.
36
+	 * @param   EE_Message_Resource_Manager $message_resource_manager
37
+	 */
38
+	public function __construct($token, $sending_messenger_slug, EE_Message_Resource_Manager $message_resource_manager)
39
+	{
40
+		$this->token = $token;
41
+		$this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager);
42
+		$this->_message = $this->_generate_message();
43
+		// set params for parent from the message object
44
+		parent::__construct(
45
+			$this->_message->messenger(),
46
+			$this->_message->message_type(),
47
+			array(),
48
+			$this->_message->context(),
49
+			false
50
+		);
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * @param string                       $sending_messenger_slug
57
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
58
+	 * @return \EE_messenger | string
59
+	 */
60
+	protected function _set_sending_messenger(
61
+		$sending_messenger_slug,
62
+		EE_Message_Resource_Manager $message_resource_manager
63
+	) {
64
+		$sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug);
65
+		return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug;
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * @return EE_messenger
72
+	 */
73
+	public function sending_messenger()
74
+	{
75
+		return $this->_sending_messenger;
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * generates an EE_Message using the supplied arguments and some defaults
82
+	 *
83
+	 * @param array $properties
84
+	 * @return EE_Message
85
+	 * @throws \EE_Error
86
+	 */
87
+	protected function _generate_message($properties = array())
88
+	{
89
+		// a message was generated immediately but the parent class will call this again
90
+		if ($this->_message instanceof EE_Message) {
91
+			return $this->_message;
92
+		}
93
+		$message = EEM_Message::instance()->get_one_by_token($this->token);
94
+		if (! $message instanceof EE_Message) {
95
+			throw new EE_Error(
96
+				sprintf(
97
+					esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'),
98
+					$this->token
99
+				)
100
+			);
101
+		}
102
+		$message->set_STS_ID(EEM_Message::status_idle);
103
+
104
+		if (! $this->_sending_messenger instanceof EE_messenger) {
105
+			$message->set_STS_ID(EEM_Message::status_failed);
106
+			$message->set_error_message(
107
+				sprintf(
108
+					esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'),
109
+					$this->_sending_messenger
110
+				)
111
+			);
112
+		}
113
+
114
+		// set properties
115
+		$this->_valid = true;
116
+		$this->_messenger = $message->messenger_object();
117
+		$this->_message_type = $message->message_type_object();
118
+		$this->_send_now = $message->send_now();
119
+		return $message;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Event_Strategy.core.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -9,244 +9,244 @@
 block discarded – undo
9 9
  */
10 10
 class EE_CPT_Event_Strategy
11 11
 {
12
-    /**
13
-     * the current page, if it utilizes CPTs
14
-     *
15
-     * @var object $CPT
16
-     */
17
-    protected $CPT;
18
-
19
-
20
-    /**
21
-     * @param array|WP_Query|null $wp_query
22
-     * @param array         $CPT
23
-     */
24
-    public function __construct($wp_query, array $CPT = [])
25
-    {
26
-        if ($wp_query instanceof WP_Query) {
27
-            $WP_Query  = $wp_query;
28
-            $this->CPT = $CPT;
29
-        } else {
30
-            $WP_Query  = $wp_query['WP_Query'] ?? null;
31
-            $this->CPT = $wp_query['CPT'] ?? null;
32
-        }
33
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
34
-        // here's the list of available filters in the WP_Query object
35
-        // 'posts_where'
36
-        // 'posts_where_paged'
37
-        // 'posts_groupby'
38
-        // 'posts_join_paged'
39
-        // 'posts_orderby'
40
-        // 'posts_distinct'
41
-        // 'post_limits'
42
-        // 'posts_fields'
43
-        // 'posts_join'
44
-        $this->_add_filters();
45
-        if ($WP_Query instanceof WP_Query) {
46
-            $WP_Query->is_espresso_event_single   = is_singular()
47
-                                                    && isset($WP_Query->query->post_type)
48
-                                                    && $WP_Query->query->post_type === 'espresso_events';
49
-            $WP_Query->is_espresso_event_archive  = is_post_type_archive('espresso_events');
50
-            $WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
51
-        }
52
-    }
53
-
54
-
55
-    /**
56
-     * When an instance of this class is created, we add our filters
57
-     * (which will get removed in case the next call to get_posts ISN'T
58
-     * for event CPTs)
59
-     */
60
-    protected function _add_filters()
61
-    {
62
-        add_filter('posts_fields', [$this, 'posts_fields'], 1, 2);
63
-        add_filter('posts_join', [$this, 'posts_join'], 1, 2);
64
-        add_filter('posts_where', [$this, 'posts_where'], 10, 2);
65
-        // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
66
-        add_filter('posts_orderby', [$this, 'posts_orderby'], 1, 2);
67
-        add_filter('posts_groupby', [$this, 'posts_groupby'], 1, 2);
68
-        add_action('posts_selection', [$this, 'remove_filters']);
69
-    }
70
-
71
-
72
-    /**
73
-     * public access to _remove_filters()
74
-     *
75
-     * @since 4.9.63.p
76
-     */
77
-    public function remove_filters()
78
-    {
79
-        $this->_remove_filters();
80
-    }
81
-
82
-
83
-    /**
84
-     * Should eb called when the last filter or hook is fired for this CPT strategy.
85
-     * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
86
-     * we don't want to join to the datetime table when querying for venues, do we!?)
87
-     */
88
-    protected function _remove_filters()
89
-    {
90
-        remove_filter('posts_fields', [$this, 'posts_fields'], 1);
91
-        remove_filter('posts_join', [$this, 'posts_join'], 1);
92
-        remove_filter('posts_where', [$this, 'posts_where']);
93
-        // remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
94
-        remove_filter('posts_orderby', [$this, 'posts_orderby'], 1);
95
-        remove_filter('posts_groupby', [$this, 'posts_groupby'], 1);
96
-        remove_action('posts_selection', [$this, 'remove_filters']);
97
-    }
98
-
99
-
100
-    /**
101
-     * @param string        $SQL
102
-     * @param WP_Query|null $wp_query
103
-     * @return    string
104
-     * @throws EE_Error
105
-     */
106
-    public function posts_fields(string $SQL, ?WP_Query $wp_query): string
107
-    {
108
-        if (
109
-            $wp_query instanceof WP_Query
110
-            && (
111
-                $wp_query->is_espresso_event_single
112
-                || $wp_query->is_espresso_event_archive
113
-                || $wp_query->is_espresso_event_taxonomy
114
-            )
115
-        ) {
116
-            // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
117
-            $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
118
-            if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
119
-                // because we only want to retrieve the next upcoming datetime for each event:
120
-                // add something like:
121
-                // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
122
-                // to WP Query SELECT statement
123
-                $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
124
-            }
125
-        }
126
-        return $SQL;
127
-    }
128
-
129
-
130
-    /**
131
-     * @param string        $SQL
132
-     * @param WP_Query|null $wp_query
133
-     * @return string
134
-     * @throws EE_Error
135
-     */
136
-    public function posts_join(string $SQL, ?WP_Query $wp_query): string
137
-    {
138
-        if (
139
-            $wp_query instanceof WP_Query
140
-            && (
141
-                $wp_query->is_espresso_event_single
142
-                || $wp_query->is_espresso_event_archive
143
-                || $wp_query->is_espresso_event_taxonomy
144
-            )
145
-        ) {
146
-            // adds something like:
147
-            // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
148
-            // to WP Query JOIN statement
149
-            $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
150
-                    . '.ID = ' . EEM_Datetime::instance()->table() . '.'
151
-                    . EEM_Event::instance()->primary_key_name() . ' ) ';
152
-        }
153
-        return $SQL;
154
-    }
155
-
156
-
157
-    /**
158
-     * @param string        $SQL
159
-     * @param WP_Query|null $wp_query
160
-     * @return string
161
-     * @throws EE_Error
162
-     */
163
-    public function posts_where(string $SQL, ?WP_Query $wp_query): string
164
-    {
165
-        if (
166
-            $wp_query instanceof WP_Query
167
-            && (
168
-                $wp_query->is_espresso_event_archive
169
-                || $wp_query->is_espresso_event_taxonomy
170
-            )
171
-        ) {
172
-            if (
173
-                ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
174
-                || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
175
-                || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
176
-            ) {
177
-                $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
178
-                        . current_time('mysql', true) . "' ";
179
-            }
180
-        }
181
-        return $SQL;
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string        $SQL
187
-     * @param WP_Query|null $wp_query
188
-     * @return string
189
-     */
190
-    public function posts_orderby(string $SQL, ?WP_Query $wp_query): string
191
-    {
192
-        if (
193
-            $wp_query instanceof WP_Query
194
-            && (
195
-                $wp_query->is_espresso_event_archive
196
-                || $wp_query->is_espresso_event_taxonomy
197
-            )
198
-        ) {
199
-            $SQL = ' event_start_date ASC ';
200
-        }
201
-        return $SQL;
202
-    }
203
-
204
-
205
-    /**
206
-     * @param string        $SQL
207
-     * @param WP_Query|null $wp_query
208
-     * @return string
209
-     */
210
-    public function posts_groupby(string $SQL, ?WP_Query $wp_query): string
211
-    {
212
-        if (
213
-            $wp_query instanceof WP_Query
214
-            && (
215
-                $wp_query->is_espresso_event_archive
216
-                || $wp_query->is_espresso_event_taxonomy
217
-            )
218
-        ) {
219
-            // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
220
-            // we're joining to the datetimes table, where there can be MANY datetimes for a single event,
221
-            // but we want to only show each event only once
222
-            // (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
223
-            global $wpdb;
224
-            $SQL = $wpdb->posts . '.ID ';
225
-        }
226
-        return $SQL;
227
-    }
228
-
229
-
230
-    /**
231
-     * @param array         $posts
232
-     * @param WP_Query|null $wp_query
233
-     * @return array
234
-     */
235
-    public function the_posts(array $posts, ?WP_Query $wp_query): array
236
-    {
237
-        return $posts;
238
-    }
239
-
240
-
241
-    /**
242
-     * @param mixed           $meta_value
243
-     * @param int|string      $post_id
244
-     * @param int|string      $meta_key
245
-     * @param bool|int|string $single
246
-     * @return mixed
247
-     */
248
-    public function get_EE_post_type_metadata($meta_value, $post_id, $meta_key, $single)
249
-    {
250
-        return $meta_value;
251
-    }
12
+	/**
13
+	 * the current page, if it utilizes CPTs
14
+	 *
15
+	 * @var object $CPT
16
+	 */
17
+	protected $CPT;
18
+
19
+
20
+	/**
21
+	 * @param array|WP_Query|null $wp_query
22
+	 * @param array         $CPT
23
+	 */
24
+	public function __construct($wp_query, array $CPT = [])
25
+	{
26
+		if ($wp_query instanceof WP_Query) {
27
+			$WP_Query  = $wp_query;
28
+			$this->CPT = $CPT;
29
+		} else {
30
+			$WP_Query  = $wp_query['WP_Query'] ?? null;
31
+			$this->CPT = $wp_query['CPT'] ?? null;
32
+		}
33
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
34
+		// here's the list of available filters in the WP_Query object
35
+		// 'posts_where'
36
+		// 'posts_where_paged'
37
+		// 'posts_groupby'
38
+		// 'posts_join_paged'
39
+		// 'posts_orderby'
40
+		// 'posts_distinct'
41
+		// 'post_limits'
42
+		// 'posts_fields'
43
+		// 'posts_join'
44
+		$this->_add_filters();
45
+		if ($WP_Query instanceof WP_Query) {
46
+			$WP_Query->is_espresso_event_single   = is_singular()
47
+													&& isset($WP_Query->query->post_type)
48
+													&& $WP_Query->query->post_type === 'espresso_events';
49
+			$WP_Query->is_espresso_event_archive  = is_post_type_archive('espresso_events');
50
+			$WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
51
+		}
52
+	}
53
+
54
+
55
+	/**
56
+	 * When an instance of this class is created, we add our filters
57
+	 * (which will get removed in case the next call to get_posts ISN'T
58
+	 * for event CPTs)
59
+	 */
60
+	protected function _add_filters()
61
+	{
62
+		add_filter('posts_fields', [$this, 'posts_fields'], 1, 2);
63
+		add_filter('posts_join', [$this, 'posts_join'], 1, 2);
64
+		add_filter('posts_where', [$this, 'posts_where'], 10, 2);
65
+		// add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
66
+		add_filter('posts_orderby', [$this, 'posts_orderby'], 1, 2);
67
+		add_filter('posts_groupby', [$this, 'posts_groupby'], 1, 2);
68
+		add_action('posts_selection', [$this, 'remove_filters']);
69
+	}
70
+
71
+
72
+	/**
73
+	 * public access to _remove_filters()
74
+	 *
75
+	 * @since 4.9.63.p
76
+	 */
77
+	public function remove_filters()
78
+	{
79
+		$this->_remove_filters();
80
+	}
81
+
82
+
83
+	/**
84
+	 * Should eb called when the last filter or hook is fired for this CPT strategy.
85
+	 * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
86
+	 * we don't want to join to the datetime table when querying for venues, do we!?)
87
+	 */
88
+	protected function _remove_filters()
89
+	{
90
+		remove_filter('posts_fields', [$this, 'posts_fields'], 1);
91
+		remove_filter('posts_join', [$this, 'posts_join'], 1);
92
+		remove_filter('posts_where', [$this, 'posts_where']);
93
+		// remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
94
+		remove_filter('posts_orderby', [$this, 'posts_orderby'], 1);
95
+		remove_filter('posts_groupby', [$this, 'posts_groupby'], 1);
96
+		remove_action('posts_selection', [$this, 'remove_filters']);
97
+	}
98
+
99
+
100
+	/**
101
+	 * @param string        $SQL
102
+	 * @param WP_Query|null $wp_query
103
+	 * @return    string
104
+	 * @throws EE_Error
105
+	 */
106
+	public function posts_fields(string $SQL, ?WP_Query $wp_query): string
107
+	{
108
+		if (
109
+			$wp_query instanceof WP_Query
110
+			&& (
111
+				$wp_query->is_espresso_event_single
112
+				|| $wp_query->is_espresso_event_archive
113
+				|| $wp_query->is_espresso_event_taxonomy
114
+			)
115
+		) {
116
+			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
117
+			$SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
118
+			if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
119
+				// because we only want to retrieve the next upcoming datetime for each event:
120
+				// add something like:
121
+				// ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
122
+				// to WP Query SELECT statement
123
+				$SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
124
+			}
125
+		}
126
+		return $SQL;
127
+	}
128
+
129
+
130
+	/**
131
+	 * @param string        $SQL
132
+	 * @param WP_Query|null $wp_query
133
+	 * @return string
134
+	 * @throws EE_Error
135
+	 */
136
+	public function posts_join(string $SQL, ?WP_Query $wp_query): string
137
+	{
138
+		if (
139
+			$wp_query instanceof WP_Query
140
+			&& (
141
+				$wp_query->is_espresso_event_single
142
+				|| $wp_query->is_espresso_event_archive
143
+				|| $wp_query->is_espresso_event_taxonomy
144
+			)
145
+		) {
146
+			// adds something like:
147
+			// " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
148
+			// to WP Query JOIN statement
149
+			$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
150
+					. '.ID = ' . EEM_Datetime::instance()->table() . '.'
151
+					. EEM_Event::instance()->primary_key_name() . ' ) ';
152
+		}
153
+		return $SQL;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param string        $SQL
159
+	 * @param WP_Query|null $wp_query
160
+	 * @return string
161
+	 * @throws EE_Error
162
+	 */
163
+	public function posts_where(string $SQL, ?WP_Query $wp_query): string
164
+	{
165
+		if (
166
+			$wp_query instanceof WP_Query
167
+			&& (
168
+				$wp_query->is_espresso_event_archive
169
+				|| $wp_query->is_espresso_event_taxonomy
170
+			)
171
+		) {
172
+			if (
173
+				! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
174
+				|| ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
175
+				|| ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
176
+			) {
177
+				$SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
178
+						. current_time('mysql', true) . "' ";
179
+			}
180
+		}
181
+		return $SQL;
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string        $SQL
187
+	 * @param WP_Query|null $wp_query
188
+	 * @return string
189
+	 */
190
+	public function posts_orderby(string $SQL, ?WP_Query $wp_query): string
191
+	{
192
+		if (
193
+			$wp_query instanceof WP_Query
194
+			&& (
195
+				$wp_query->is_espresso_event_archive
196
+				|| $wp_query->is_espresso_event_taxonomy
197
+			)
198
+		) {
199
+			$SQL = ' event_start_date ASC ';
200
+		}
201
+		return $SQL;
202
+	}
203
+
204
+
205
+	/**
206
+	 * @param string        $SQL
207
+	 * @param WP_Query|null $wp_query
208
+	 * @return string
209
+	 */
210
+	public function posts_groupby(string $SQL, ?WP_Query $wp_query): string
211
+	{
212
+		if (
213
+			$wp_query instanceof WP_Query
214
+			&& (
215
+				$wp_query->is_espresso_event_archive
216
+				|| $wp_query->is_espresso_event_taxonomy
217
+			)
218
+		) {
219
+			// TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
220
+			// we're joining to the datetimes table, where there can be MANY datetimes for a single event,
221
+			// but we want to only show each event only once
222
+			// (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
223
+			global $wpdb;
224
+			$SQL = $wpdb->posts . '.ID ';
225
+		}
226
+		return $SQL;
227
+	}
228
+
229
+
230
+	/**
231
+	 * @param array         $posts
232
+	 * @param WP_Query|null $wp_query
233
+	 * @return array
234
+	 */
235
+	public function the_posts(array $posts, ?WP_Query $wp_query): array
236
+	{
237
+		return $posts;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param mixed           $meta_value
243
+	 * @param int|string      $post_id
244
+	 * @param int|string      $meta_key
245
+	 * @param bool|int|string $single
246
+	 * @return mixed
247
+	 */
248
+	public function get_EE_post_type_metadata($meta_value, $post_id, $meta_key, $single)
249
+	{
250
+		return $meta_value;
251
+	}
252 252
 }
Please login to merge, or discard this patch.
admin/extend/registration_form/Extend_Registration_Form_Admin_Page.core.php 2 patches
Indentation   +1438 added lines, -1438 removed lines patch added patch discarded remove patch
@@ -14,1442 +14,1442 @@
 block discarded – undo
14 14
  */
15 15
 class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page
16 16
 {
17
-    /**
18
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
19
-     */
20
-    public function __construct($routing = true)
21
-    {
22
-        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/');
23
-        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/');
24
-        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
25
-        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/');
26
-        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
27
-        parent::__construct($routing);
28
-    }
29
-
30
-
31
-    /**
32
-     * @return void
33
-     */
34
-    protected function _extend_page_config()
35
-    {
36
-        $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
37
-        $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])
38
-            ? $this->_req_data['QST_ID'] : 0;
39
-        $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])
40
-            ? $this->_req_data['QSG_ID'] : 0;
41
-
42
-        $new_page_routes = array(
43
-            'question_groups'    => array(
44
-                'func'       => '_question_groups_overview_list_table',
45
-                'capability' => 'ee_read_question_groups',
46
-            ),
47
-            'add_question'       => array(
48
-                'func'       => '_edit_question',
49
-                'capability' => 'ee_edit_questions',
50
-            ),
51
-            'insert_question'    => array(
52
-                'func'       => '_insert_or_update_question',
53
-                'args'       => array('new_question' => true),
54
-                'capability' => 'ee_edit_questions',
55
-                'noheader'   => true,
56
-            ),
57
-            'duplicate_question' => array(
58
-                'func'       => '_duplicate_question',
59
-                'capability' => 'ee_edit_questions',
60
-                'noheader'   => true,
61
-            ),
62
-            'trash_question'     => array(
63
-                'func'       => '_trash_question',
64
-                'capability' => 'ee_delete_question',
65
-                'obj_id'     => $qst_id,
66
-                'noheader'   => true,
67
-            ),
68
-
69
-            'restore_question' => array(
70
-                'func'       => '_trash_or_restore_questions',
71
-                'capability' => 'ee_delete_question',
72
-                'obj_id'     => $qst_id,
73
-                'args'       => array('trash' => false),
74
-                'noheader'   => true,
75
-            ),
76
-
77
-            'delete_question' => array(
78
-                'func'       => '_delete_question',
79
-                'capability' => 'ee_delete_question',
80
-                'obj_id'     => $qst_id,
81
-                'noheader'   => true,
82
-            ),
83
-
84
-            'trash_questions' => array(
85
-                'func'       => '_trash_or_restore_questions',
86
-                'capability' => 'ee_delete_questions',
87
-                'args'       => array('trash' => true),
88
-                'noheader'   => true,
89
-            ),
90
-
91
-            'restore_questions' => array(
92
-                'func'       => '_trash_or_restore_questions',
93
-                'capability' => 'ee_delete_questions',
94
-                'args'       => array('trash' => false),
95
-                'noheader'   => true,
96
-            ),
97
-
98
-            'delete_questions' => array(
99
-                'func'       => '_delete_questions',
100
-                'args'       => array(),
101
-                'capability' => 'ee_delete_questions',
102
-                'noheader'   => true,
103
-            ),
104
-
105
-            'add_question_group' => array(
106
-                'func'       => '_edit_question_group',
107
-                'capability' => 'ee_edit_question_groups',
108
-            ),
109
-
110
-            'edit_question_group' => array(
111
-                'func'       => '_edit_question_group',
112
-                'capability' => 'ee_edit_question_group',
113
-                'obj_id'     => $qsg_id,
114
-                'args'       => array('edit'),
115
-            ),
116
-
117
-            'delete_question_groups' => array(
118
-                'func'       => '_delete_question_groups',
119
-                'capability' => 'ee_delete_question_groups',
120
-                'noheader'   => true,
121
-            ),
122
-
123
-            'delete_question_group' => array(
124
-                'func'       => '_delete_question_groups',
125
-                'capability' => 'ee_delete_question_group',
126
-                'obj_id'     => $qsg_id,
127
-                'noheader'   => true,
128
-            ),
129
-
130
-            'trash_question_group' => array(
131
-                'func'       => '_trash_or_restore_question_groups',
132
-                'args'       => array('trash' => true),
133
-                'capability' => 'ee_delete_question_group',
134
-                'obj_id'     => $qsg_id,
135
-                'noheader'   => true,
136
-            ),
137
-
138
-            'restore_question_group' => array(
139
-                'func'       => '_trash_or_restore_question_groups',
140
-                'args'       => array('trash' => false),
141
-                'capability' => 'ee_delete_question_group',
142
-                'obj_id'     => $qsg_id,
143
-                'noheader'   => true,
144
-            ),
145
-
146
-            'insert_question_group' => array(
147
-                'func'       => '_insert_or_update_question_group',
148
-                'args'       => array('new_question_group' => true),
149
-                'capability' => 'ee_edit_question_groups',
150
-                'noheader'   => true,
151
-            ),
152
-
153
-            'update_question_group' => array(
154
-                'func'       => '_insert_or_update_question_group',
155
-                'args'       => array('new_question_group' => false),
156
-                'capability' => 'ee_edit_question_group',
157
-                'obj_id'     => $qsg_id,
158
-                'noheader'   => true,
159
-            ),
160
-
161
-            'trash_question_groups' => array(
162
-                'func'       => '_trash_or_restore_question_groups',
163
-                'args'       => array('trash' => true),
164
-                'capability' => 'ee_delete_question_groups',
165
-                'noheader'   => array('trash' => false),
166
-            ),
167
-
168
-            'restore_question_groups' => array(
169
-                'func'       => '_trash_or_restore_question_groups',
170
-                'args'       => array('trash' => false),
171
-                'capability' => 'ee_delete_question_groups',
172
-                'noheader'   => true,
173
-            ),
174
-
175
-
176
-            'espresso_update_question_group_order' => array(
177
-                'func'       => 'update_question_group_order',
178
-                'capability' => 'ee_edit_question_groups',
179
-                'noheader'   => true,
180
-            ),
181
-
182
-            'view_reg_form_settings' => array(
183
-                'func'       => '_reg_form_settings',
184
-                'capability' => 'manage_options',
185
-            ),
186
-
187
-            'update_reg_form_settings' => array(
188
-                'func'       => '_update_reg_form_settings',
189
-                'capability' => 'manage_options',
190
-                'noheader'   => true,
191
-            ),
192
-        );
193
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
194
-
195
-        $new_page_config = array(
196
-
197
-            'question_groups' => array(
198
-                'nav'           => array(
199
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
200
-                    'order' => 20,
201
-                ),
202
-                'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
203
-                'help_tabs'     => array(
204
-                    'registration_form_question_groups_help_tab'                           => array(
205
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
206
-                        'filename' => 'registration_form_question_groups',
207
-                    ),
208
-                    'registration_form_question_groups_table_column_headings_help_tab'     => array(
209
-                        'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
210
-                        'filename' => 'registration_form_question_groups_table_column_headings',
211
-                    ),
212
-                    'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(
213
-                        'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
214
-                        'filename' => 'registration_form_question_groups_views_bulk_actions_search',
215
-                    ),
216
-                ),
217
-                'metaboxes'     => $this->_default_espresso_metaboxes,
218
-                'require_nonce' => false,
219
-                'qtips'         => array(
220
-                    'EE_Registration_Form_Tips',
221
-                ),
222
-            ),
223
-
224
-            'add_question' => array(
225
-                'nav'           => array(
226
-                    'label'      => esc_html__('Add Question', 'event_espresso'),
227
-                    'order'      => 5,
228
-                    'persistent' => false,
229
-                ),
230
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
231
-                'help_tabs'     => array(
232
-                    'registration_form_add_question_help_tab' => array(
233
-                        'title'    => esc_html__('Add Question', 'event_espresso'),
234
-                        'filename' => 'registration_form_add_question',
235
-                    ),
236
-                ),
237
-                'require_nonce' => false,
238
-            ),
239
-
240
-            'add_question_group' => array(
241
-                'nav'           => array(
242
-                    'label'      => esc_html__('Add Question Group', 'event_espresso'),
243
-                    'order'      => 5,
244
-                    'persistent' => false,
245
-                ),
246
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
247
-                'help_tabs'     => array(
248
-                    'registration_form_add_question_group_help_tab' => array(
249
-                        'title'    => esc_html__('Add Question Group', 'event_espresso'),
250
-                        'filename' => 'registration_form_add_question_group',
251
-                    ),
252
-                ),
253
-                'require_nonce' => false,
254
-            ),
255
-
256
-            'edit_question_group' => array(
257
-                'nav'           => array(
258
-                    'label'      => esc_html__('Edit Question Group', 'event_espresso'),
259
-                    'order'      => 5,
260
-                    'persistent' => false,
261
-                    'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(
262
-                        array('question_group_id' => $this->_req_data['question_group_id']),
263
-                        $this->_current_page_view_url
264
-                    ) : $this->_admin_base_url,
265
-                ),
266
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
267
-                'help_tabs'     => array(
268
-                    'registration_form_edit_question_group_help_tab' => array(
269
-                        'title'    => esc_html__('Edit Question Group', 'event_espresso'),
270
-                        'filename' => 'registration_form_edit_question_group',
271
-                    ),
272
-                ),
273
-                'require_nonce' => false,
274
-            ),
275
-
276
-            'view_reg_form_settings' => array(
277
-                'nav'           => array(
278
-                    'label' => esc_html__('Reg Form Settings', 'event_espresso'),
279
-                    'order' => 40,
280
-                ),
281
-                'labels'        => array(
282
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
283
-                ),
284
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
285
-                'help_tabs'     => array(
286
-                    'registration_form_reg_form_settings_help_tab' => array(
287
-                        'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
288
-                        'filename' => 'registration_form_reg_form_settings',
289
-                    ),
290
-                ),
291
-                'require_nonce' => false,
292
-            ),
293
-
294
-        );
295
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
296
-
297
-        // change the list table we're going to use so it's the NEW list table!
298
-        $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
299
-
300
-
301
-        // additional labels
302
-        $new_labels = array(
303
-            'add_question'          => esc_html__('Add New Question', 'event_espresso'),
304
-            'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
305
-            'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
306
-            'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
307
-            'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
308
-        );
309
-        $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
310
-    }
311
-
312
-
313
-    /**
314
-     * @return void
315
-     */
316
-    protected function _ajax_hooks()
317
-    {
318
-        add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order'));
319
-    }
320
-
321
-
322
-    /**
323
-     * @return void
324
-     */
325
-    public function load_scripts_styles_question_groups()
326
-    {
327
-        wp_enqueue_script('espresso_ajax_table_sorting');
328
-    }
329
-
330
-
331
-    /**
332
-     * @return void
333
-     */
334
-    public function load_scripts_styles_add_question_group()
335
-    {
336
-        $this->load_scripts_styles_forms();
337
-        $this->load_sortable_question_script();
338
-    }
339
-
340
-
341
-    /**
342
-     * @return void
343
-     */
344
-    public function load_scripts_styles_edit_question_group()
345
-    {
346
-        $this->load_scripts_styles_forms();
347
-        $this->load_sortable_question_script();
348
-    }
349
-
350
-
351
-    /**
352
-     * registers and enqueues script for questions
353
-     *
354
-     * @return void
355
-     */
356
-    public function load_sortable_question_script()
357
-    {
358
-        wp_register_script(
359
-            'ee-question-sortable',
360
-            REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
361
-            array('jquery-ui-sortable'),
362
-            EVENT_ESPRESSO_VERSION,
363
-            true
364
-        );
365
-        wp_enqueue_script('ee-question-sortable');
366
-    }
367
-
368
-
369
-    /**
370
-     * @return void
371
-     */
372
-    protected function _set_list_table_views_default()
373
-    {
374
-        $this->_views = array(
375
-            'all' => array(
376
-                'slug'        => 'all',
377
-                'label'       => esc_html__('View All Questions', 'event_espresso'),
378
-                'count'       => 0,
379
-                'bulk_action' => array(
380
-                    'trash_questions' => esc_html__('Trash', 'event_espresso'),
381
-                ),
382
-            ),
383
-        );
384
-
385
-        if (
386
-            EE_Registry::instance()->CAP->current_user_can(
387
-                'ee_delete_questions',
388
-                'espresso_registration_form_trash_questions'
389
-            )
390
-        ) {
391
-            $this->_views['trash'] = array(
392
-                'slug'        => 'trash',
393
-                'label'       => esc_html__('Trash', 'event_espresso'),
394
-                'count'       => 0,
395
-                'bulk_action' => array(
396
-                    'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
397
-                    'restore_questions' => esc_html__('Restore', 'event_espresso'),
398
-                ),
399
-            );
400
-        }
401
-    }
402
-
403
-
404
-    /**
405
-     * @return void
406
-     */
407
-    protected function _set_list_table_views_question_groups()
408
-    {
409
-        $this->_views = array(
410
-            'all' => array(
411
-                'slug'        => 'all',
412
-                'label'       => esc_html__('All', 'event_espresso'),
413
-                'count'       => 0,
414
-                'bulk_action' => array(
415
-                    'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
416
-                ),
417
-            ),
418
-        );
419
-
420
-        if (
421
-            EE_Registry::instance()->CAP->current_user_can(
422
-                'ee_delete_question_groups',
423
-                'espresso_registration_form_trash_question_groups'
424
-            )
425
-        ) {
426
-            $this->_views['trash'] = array(
427
-                'slug'        => 'trash',
428
-                'label'       => esc_html__('Trash', 'event_espresso'),
429
-                'count'       => 0,
430
-                'bulk_action' => array(
431
-                    'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
432
-                    'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
433
-                ),
434
-            );
435
-        }
436
-    }
437
-
438
-
439
-    /**
440
-     * @return void
441
-     * @throws EE_Error
442
-     * @throws InvalidArgumentException
443
-     * @throws InvalidDataTypeException
444
-     * @throws InvalidInterfaceException
445
-     */
446
-    protected function _questions_overview_list_table()
447
-    {
448
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
449
-            'add_question',
450
-            'add_question',
451
-            array(),
452
-            'add-new-h2'
453
-        );
454
-        parent::_questions_overview_list_table();
455
-    }
456
-
457
-
458
-    /**
459
-     * @return void
460
-     * @throws DomainException
461
-     * @throws EE_Error
462
-     * @throws InvalidArgumentException
463
-     * @throws InvalidDataTypeException
464
-     * @throws InvalidInterfaceException
465
-     */
466
-    protected function _question_groups_overview_list_table()
467
-    {
468
-        $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
469
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
470
-            'add_question_group',
471
-            'add_question_group',
472
-            array(),
473
-            'add-new-h2'
474
-        );
475
-        $this->display_admin_list_table_page_with_sidebar();
476
-    }
477
-
478
-
479
-    /**
480
-     * @return void
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     */
486
-    protected function _delete_question()
487
-    {
488
-        $success = $this->_delete_items($this->_question_model);
489
-        $this->_redirect_after_action(
490
-            $success,
491
-            $this->_question_model->item_name($success),
492
-            'deleted',
493
-            array('action' => 'default', 'status' => 'all')
494
-        );
495
-    }
496
-
497
-
498
-    /**
499
-     * @return void
500
-     * @throws EE_Error
501
-     * @throws InvalidArgumentException
502
-     * @throws InvalidDataTypeException
503
-     * @throws InvalidInterfaceException
504
-     */
505
-    protected function _delete_questions()
506
-    {
507
-        $success = $this->_delete_items($this->_question_model);
508
-        $this->_redirect_after_action(
509
-            $success,
510
-            $this->_question_model->item_name($success),
511
-            'deleted permanently',
512
-            array('action' => 'default', 'status' => 'trash')
513
-        );
514
-    }
515
-
516
-
517
-    /**
518
-     * Performs the deletion of a single or multiple questions or question groups.
519
-     *
520
-     * @param EEM_Soft_Delete_Base $model
521
-     * @return int number of items deleted permanently
522
-     * @throws EE_Error
523
-     * @throws InvalidArgumentException
524
-     * @throws InvalidDataTypeException
525
-     * @throws InvalidInterfaceException
526
-     */
527
-    private function _delete_items(EEM_Soft_Delete_Base $model)
528
-    {
529
-        $success = 0;
530
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
531
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
532
-            // if array has more than one element than success message should be plural
533
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
534
-            // cycle thru bulk action checkboxes
535
-            $checkboxes = $this->_req_data['checkbox'];
536
-            foreach (array_keys($checkboxes) as $ID) {
537
-                if (! $this->_delete_item($ID, $model)) {
538
-                    $success = 0;
539
-                }
540
-            }
541
-        } elseif (! empty($this->_req_data['QSG_ID'])) {
542
-            $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
543
-        } elseif (! empty($this->_req_data['QST_ID'])) {
544
-            $success = $this->_delete_item($this->_req_data['QST_ID'], $model);
545
-        } else {
546
-            EE_Error::add_error(
547
-                sprintf(
548
-                    esc_html__(
549
-                        "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
550
-                        "event_espresso"
551
-                    )
552
-                ),
553
-                __FILE__,
554
-                __FUNCTION__,
555
-                __LINE__
556
-            );
557
-        }
558
-        return $success;
559
-    }
560
-
561
-
562
-    /**
563
-     * Deletes the specified question (and its associated question options) or question group
564
-     *
565
-     * @param int                  $id
566
-     * @param EEM_Soft_Delete_Base $model
567
-     * @return boolean
568
-     * @throws EE_Error
569
-     * @throws InvalidArgumentException
570
-     * @throws InvalidDataTypeException
571
-     * @throws InvalidInterfaceException
572
-     */
573
-    protected function _delete_item($id, $model)
574
-    {
575
-        if ($model instanceof EEM_Question) {
576
-            EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id))));
577
-        }
578
-        return $model->delete_permanently_by_ID(absint($id));
579
-    }
580
-
581
-
582
-    /******************************    QUESTION GROUPS    ******************************/
583
-
584
-
585
-    /**
586
-     * @param string $type
587
-     * @return void
588
-     * @throws DomainException
589
-     * @throws EE_Error
590
-     * @throws InvalidArgumentException
591
-     * @throws InvalidDataTypeException
592
-     * @throws InvalidInterfaceException
593
-     */
594
-    protected function _edit_question_group($type = 'add')
595
-    {
596
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
597
-        $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])
598
-            ? absint($this->_req_data['QSG_ID'])
599
-            : false;
600
-
601
-        switch ($this->_req_action) {
602
-            case 'add_question_group':
603
-                $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
604
-                break;
605
-            case 'edit_question_group':
606
-                $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
607
-                break;
608
-            default:
609
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
610
-        }
611
-        // add ID to title if editing
612
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
613
-        if ($ID) {
614
-            /** @var EE_Question_Group $questionGroup */
615
-            $questionGroup = $this->_question_group_model->get_one_by_ID($ID);
616
-            $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID));
617
-            $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
618
-        } else {
619
-            /** @var EE_Question_Group $questionGroup */
620
-            $questionGroup = EEM_Question_Group::instance()->create_default_object();
621
-            $questionGroup->set_order_to_latest();
622
-            $this->_set_add_edit_form_tags('insert_question_group');
623
-        }
624
-        $this->_template_args['values'] = $this->_yes_no_values;
625
-        $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group();
626
-        $this->_template_args['QSG_ID'] = $ID ? $ID : true;
627
-        $this->_template_args['question_group'] = $questionGroup;
628
-
629
-        $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url);
630
-        $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL);
631
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
632
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
633
-            $this->_template_args,
634
-            true
635
-        );
636
-
637
-        // the details template wrapper
638
-        $this->display_admin_page_with_sidebar();
639
-    }
640
-
641
-
642
-    /**
643
-     * @return void
644
-     * @throws EE_Error
645
-     * @throws InvalidArgumentException
646
-     * @throws InvalidDataTypeException
647
-     * @throws InvalidInterfaceException
648
-     */
649
-    protected function _delete_question_groups()
650
-    {
651
-        $success = $this->_delete_items($this->_question_group_model);
652
-        $this->_redirect_after_action(
653
-            $success,
654
-            $this->_question_group_model->item_name($success),
655
-            'deleted permanently',
656
-            array('action' => 'question_groups', 'status' => 'trash')
657
-        );
658
-    }
659
-
660
-
661
-    /**
662
-     * @param bool $new_question_group
663
-     * @throws EE_Error
664
-     * @throws InvalidArgumentException
665
-     * @throws InvalidDataTypeException
666
-     * @throws InvalidInterfaceException
667
-     */
668
-    protected function _insert_or_update_question_group($new_question_group = true)
669
-    {
670
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
671
-        $set_column_values = $this->_set_column_values_for($this->_question_group_model);
672
-
673
-        // make sure identifier is unique
674
-        $identifier_value = $set_column_values['QSG_identifier'] ?? '';
675
-        $where_values = ['QSG_identifier' => $identifier_value ];
676
-        if (! $new_question_group && isset($set_column_values['QSG_ID'])) {
677
-            $where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']];
678
-        }
679
-        $identifier_exists = ! empty($identifier_value) && $this->_question_group_model->count([$where_values]) > 0;
680
-        if ($identifier_exists) {
681
-            $set_column_values['QSG_identifier'] .= uniqid('id', true);
682
-        }
683
-
684
-        if ($new_question_group) {
685
-            $QSG_ID = $this->_question_group_model->insert($set_column_values);
686
-            $success = $QSG_ID ? 1 : 0;
687
-            if ($success === 0) {
688
-                EE_Error::add_error(
689
-                    esc_html__('Something went wrong saving the question group.', 'event_espresso'),
690
-                    __FILE__,
691
-                    __FUNCTION__,
692
-                    __LINE__
693
-                );
694
-                $this->_redirect_after_action(
695
-                    false,
696
-                    '',
697
-                    '',
698
-                    array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
699
-                    true
700
-                );
701
-            }
702
-        } else {
703
-            $QSG_ID = absint($this->_req_data['QSG_ID']);
704
-            unset($set_column_values['QSG_ID']);
705
-            $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID)));
706
-        }
707
-
708
-        $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
709
-            EEM_Attendee::system_question_phone
710
-        );
711
-        // update the existing related questions
712
-        // BUT FIRST...  delete the phone question from the Question_Group_Question
713
-        // if it is being added to this question group (therefore removed from the existing group)
714
-        if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
715
-            // delete where QST ID = system phone question ID and Question Group ID is NOT this group
716
-            EEM_Question_Group_Question::instance()->delete(
717
-                array(
718
-                    array(
719
-                        'QST_ID' => $phone_question_id,
720
-                        'QSG_ID' => array('!=', $QSG_ID),
721
-                    ),
722
-                )
723
-            );
724
-        }
725
-        /** @type EE_Question_Group $question_group */
726
-        $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
727
-        $questions = $question_group->questions();
728
-        // make sure system phone question is added to list of questions for this group
729
-        if (! isset($questions[ $phone_question_id ])) {
730
-            $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
731
-        }
732
-
733
-        foreach ($questions as $question_ID => $question) {
734
-            // first we always check for order.
735
-            if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
736
-                // update question order
737
-                $question_group->update_question_order(
738
-                    $question_ID,
739
-                    $this->_req_data['question_orders'][ $question_ID ]
740
-                );
741
-            }
742
-
743
-            // then we always check if adding or removing.
744
-            if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
745
-                $question_group->add_question($question_ID);
746
-            } else {
747
-                // not found, remove it (but only if not a system question for the personal group
748
-                // with the exception of lname system question - we allow removal of it)
749
-                if (
750
-                    in_array(
751
-                        $question->system_ID(),
752
-                        EEM_Question::instance()->required_system_questions_in_system_question_group(
753
-                            $question_group->system_group()
754
-                        )
755
-                    )
756
-                ) {
757
-                    continue;
758
-                } else {
759
-                    $question_group->remove_question($question_ID);
760
-                }
761
-            }
762
-        }
763
-        // save new related questions
764
-        if (isset($this->_req_data['questions'])) {
765
-            foreach ($this->_req_data['questions'] as $QST_ID) {
766
-                $question_group->add_question($QST_ID);
767
-                if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
768
-                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
769
-                }
770
-            }
771
-        }
772
-
773
-        if ($success !== false) {
774
-            $msg = $new_question_group
775
-                ? sprintf(
776
-                    esc_html__('The %s has been created', 'event_espresso'),
777
-                    $this->_question_group_model->item_name()
778
-                )
779
-                : sprintf(
780
-                    esc_html__(
781
-                        'The %s has been updated',
782
-                        'event_espresso'
783
-                    ),
784
-                    $this->_question_group_model->item_name()
785
-                );
786
-            EE_Error::add_success($msg);
787
-        }
788
-        $this->_redirect_after_action(
789
-            false,
790
-            '',
791
-            '',
792
-            array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
793
-            true
794
-        );
795
-    }
796
-
797
-
798
-    /**
799
-     * duplicates a question and all its question options and redirects to the new question.
800
-     *
801
-     * @return void
802
-     * @throws EE_Error
803
-     * @throws InvalidArgumentException
804
-     * @throws ReflectionException
805
-     * @throws InvalidDataTypeException
806
-     * @throws InvalidInterfaceException
807
-     */
808
-    public function _duplicate_question()
809
-    {
810
-        $question_ID = (int) $this->_req_data['QST_ID'];
811
-        $question = EEM_Question::instance()->get_one_by_ID($question_ID);
812
-        if ($question instanceof EE_Question) {
813
-            $new_question = $question->duplicate();
814
-            if ($new_question instanceof EE_Question) {
815
-                $this->_redirect_after_action(
816
-                    true,
817
-                    esc_html__('Question', 'event_espresso'),
818
-                    esc_html__('Duplicated', 'event_espresso'),
819
-                    array('action' => 'edit_question', 'QST_ID' => $new_question->ID()),
820
-                    true
821
-                );
822
-            } else {
823
-                global $wpdb;
824
-                EE_Error::add_error(
825
-                    sprintf(
826
-                        esc_html__(
827
-                            'Could not duplicate question with ID %1$d because: %2$s',
828
-                            'event_espresso'
829
-                        ),
830
-                        $question_ID,
831
-                        $wpdb->last_error
832
-                    ),
833
-                    __FILE__,
834
-                    __FUNCTION__,
835
-                    __LINE__
836
-                );
837
-                $this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
838
-            }
839
-        } else {
840
-            EE_Error::add_error(
841
-                sprintf(
842
-                    esc_html__(
843
-                        'Could not duplicate question with ID %d because it didn\'t exist!',
844
-                        'event_espresso'
845
-                    ),
846
-                    $question_ID
847
-                ),
848
-                __FILE__,
849
-                __FUNCTION__,
850
-                __LINE__
851
-            );
852
-            $this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
853
-        }
854
-    }
855
-
856
-
857
-    /**
858
-     * @param bool $trash
859
-     * @throws EE_Error
860
-     */
861
-    protected function _trash_or_restore_question_groups($trash = true)
862
-    {
863
-        $this->_trash_or_restore_items($this->_question_group_model, $trash);
864
-    }
865
-
866
-
867
-    /**
868
-     *_trash_question
869
-     *
870
-     * @return void
871
-     * @throws EE_Error
872
-     */
873
-    protected function _trash_question()
874
-    {
875
-        $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);
876
-        $query_args = array('action' => 'default', 'status' => 'all');
877
-        $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
878
-    }
879
-
880
-
881
-    /**
882
-     * @param bool $trash
883
-     * @throws EE_Error
884
-     */
885
-    protected function _trash_or_restore_questions($trash = true)
886
-    {
887
-        $this->_trash_or_restore_items($this->_question_model, $trash);
888
-    }
889
-
890
-
891
-    /**
892
-     * Internally used to delete or restore items, using the request data. Meant to be
893
-     * flexible between question or question groups
894
-     *
895
-     * @param EEM_Soft_Delete_Base $model
896
-     * @param boolean              $trash whether to trash or restore
897
-     * @throws EE_Error
898
-     */
899
-    private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
900
-    {
901
-
902
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
903
-
904
-        $success = 1;
905
-        // Checkboxes
906
-        // echo "trash $trash";
907
-        // var_dump($this->_req_data['checkbox']);die;
908
-        if (isset($this->_req_data['checkbox'])) {
909
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
910
-                // if array has more than one element than success message should be plural
911
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
912
-                // cycle thru bulk action checkboxes
913
-                $checkboxes = $this->_req_data['checkbox'];
914
-                foreach (array_keys($checkboxes) as $ID) {
915
-                    if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
916
-                        $success = 0;
917
-                    }
918
-                }
919
-            } else {
920
-                // grab single id and delete
921
-                $ID = absint($this->_req_data['checkbox']);
922
-                if (! $model->delete_or_restore_by_ID($trash, $ID)) {
923
-                    $success = 0;
924
-                }
925
-            }
926
-        } else {
927
-            // delete via trash link
928
-            // grab single id and delete
929
-            $ID = absint($this->_req_data[ $model->primary_key_name() ]);
930
-            if (! $model->delete_or_restore_by_ID($trash, $ID)) {
931
-                $success = 0;
932
-            }
933
-        }
934
-
935
-
936
-        $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
937
-        // echo "action :$action";
938
-        // $action = 'questions' ? 'default' : $action;
939
-        if ($trash) {
940
-            $action_desc = 'trashed';
941
-            $status = 'trash';
942
-        } else {
943
-            $action_desc = 'restored';
944
-            $status = 'all';
945
-        }
946
-        $this->_redirect_after_action(
947
-            $success,
948
-            $model->item_name($success),
949
-            $action_desc,
950
-            array('action' => $action, 'status' => $status)
951
-        );
952
-    }
953
-
954
-
955
-    /**
956
-     * @param            $per_page
957
-     * @param int        $current_page
958
-     * @param bool|false $count
959
-     * @return EE_Soft_Delete_Base_Class[]|int
960
-     * @throws EE_Error
961
-     * @throws InvalidArgumentException
962
-     * @throws InvalidDataTypeException
963
-     * @throws InvalidInterfaceException
964
-     */
965
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
966
-    {
967
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
968
-
969
-        if ($count) {
970
-            // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
971
-            $where = isset($query_params[0]) ? array($query_params[0]) : array();
972
-            $results = $this->_question_model->count_deleted($where);
973
-        } else {
974
-            // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
975
-            $results = $this->_question_model->get_all_deleted($query_params);
976
-        }
977
-        return $results;
978
-    }
979
-
980
-
981
-    /**
982
-     * @param            $per_page
983
-     * @param int        $current_page
984
-     * @param bool|false $count
985
-     * @return EE_Soft_Delete_Base_Class[]|int
986
-     * @throws EE_Error
987
-     * @throws InvalidArgumentException
988
-     * @throws InvalidDataTypeException
989
-     * @throws InvalidInterfaceException
990
-     */
991
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
992
-    {
993
-        $questionGroupModel = EEM_Question_Group::instance();
994
-        $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
995
-        if ($count) {
996
-            $where = isset($query_params[0]) ? array($query_params[0]) : array();
997
-            $results = $questionGroupModel->count($where);
998
-        } else {
999
-            $results = $questionGroupModel->get_all($query_params);
1000
-        }
1001
-        return $results;
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * @param      $per_page
1007
-     * @param int  $current_page
1008
-     * @param bool $count
1009
-     * @return EE_Soft_Delete_Base_Class[]|int
1010
-     * @throws EE_Error
1011
-     * @throws InvalidArgumentException
1012
-     * @throws InvalidDataTypeException
1013
-     * @throws InvalidInterfaceException
1014
-     */
1015
-    public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
1016
-    {
1017
-        $questionGroupModel = EEM_Question_Group::instance();
1018
-        $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1019
-        if ($count) {
1020
-            $where = isset($query_params[0]) ? array($query_params[0]) : array();
1021
-            $query_params['limit'] = null;
1022
-            $results = $questionGroupModel->count_deleted($where);
1023
-        } else {
1024
-            $results = $questionGroupModel->get_all_deleted($query_params);
1025
-        }
1026
-        return $results;
1027
-    }
1028
-
1029
-
1030
-    /**
1031
-     * method for performing updates to question order
1032
-     *
1033
-     * @return void results array
1034
-     * @throws EE_Error
1035
-     * @throws InvalidArgumentException
1036
-     * @throws InvalidDataTypeException
1037
-     * @throws InvalidInterfaceException
1038
-     */
1039
-    public function update_question_group_order()
1040
-    {
1041
-
1042
-        $success = esc_html__('Question group order was updated successfully.', 'event_espresso');
1043
-
1044
-        // grab our row IDs
1045
-        $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
1046
-            ? explode(',', rtrim($this->_req_data['row_ids'], ','))
1047
-            : array();
1048
-
1049
-        $perpage = ! empty($this->_req_data['perpage'])
1050
-            ? (int) $this->_req_data['perpage']
1051
-            : null;
1052
-        $curpage = ! empty($this->_req_data['curpage'])
1053
-            ? (int) $this->_req_data['curpage']
1054
-            : null;
1055
-
1056
-        if (! empty($row_ids)) {
1057
-            // figure out where we start the row_id count at for the current page.
1058
-            $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1059
-
1060
-            $row_count = count($row_ids);
1061
-            for ($i = 0; $i < $row_count; $i++) {
1062
-                // Update the questions when re-ordering
1063
-                $updated = EEM_Question_Group::instance()->update(
1064
-                    array('QSG_order' => $qsgcount),
1065
-                    array(array('QSG_ID' => $row_ids[ $i ]))
1066
-                );
1067
-                if ($updated === false) {
1068
-                    $success = false;
1069
-                }
1070
-                $qsgcount++;
1071
-            }
1072
-        } else {
1073
-            $success = false;
1074
-        }
1075
-
1076
-        $errors = ! $success
1077
-            ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
1078
-            : false;
1079
-
1080
-        echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
1081
-        die();
1082
-    }
1083
-
1084
-
1085
-
1086
-    /***************************************       REGISTRATION SETTINGS       ***************************************/
1087
-
1088
-
1089
-    /**
1090
-     * @throws DomainException
1091
-     * @throws EE_Error
1092
-     * @throws InvalidArgumentException
1093
-     * @throws InvalidDataTypeException
1094
-     * @throws InvalidInterfaceException
1095
-     */
1096
-    protected function _reg_form_settings()
1097
-    {
1098
-        $this->_template_args['values'] = $this->_yes_no_values;
1099
-        add_action(
1100
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1101
-            array($this, 'email_validation_settings_form'),
1102
-            2
1103
-        );
1104
-        add_action(
1105
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1106
-            array($this, 'copy_attendee_info_settings_form'),
1107
-            4
1108
-        );
1109
-        $this->_template_args = (array) apply_filters(
1110
-            'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
1111
-            $this->_template_args
1112
-        );
1113
-        $this->_set_add_edit_form_tags('update_reg_form_settings');
1114
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1115
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1116
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1117
-            $this->_template_args,
1118
-            true
1119
-        );
1120
-        $this->display_admin_page_with_sidebar();
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     * @return void
1126
-     * @throws EE_Error
1127
-     * @throws InvalidArgumentException
1128
-     * @throws ReflectionException
1129
-     * @throws InvalidDataTypeException
1130
-     * @throws InvalidInterfaceException
1131
-     */
1132
-    protected function _update_reg_form_settings()
1133
-    {
1134
-        EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
1135
-            EE_Registry::instance()->CFG->registration
1136
-        );
1137
-        EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form(
1138
-            EE_Registry::instance()->CFG->registration
1139
-        );
1140
-        EE_Registry::instance()->CFG->registration = apply_filters(
1141
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
1142
-            EE_Registry::instance()->CFG->registration
1143
-        );
1144
-        $success = $this->_update_espresso_configuration(
1145
-            esc_html__('Registration Form Options', 'event_espresso'),
1146
-            EE_Registry::instance()->CFG,
1147
-            __FILE__,
1148
-            __FUNCTION__,
1149
-            __LINE__
1150
-        );
1151
-        $this->_redirect_after_action(
1152
-            $success,
1153
-            esc_html__('Registration Form Options', 'event_espresso'),
1154
-            'updated',
1155
-            array('action' => 'view_reg_form_settings')
1156
-        );
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * @return void
1162
-     * @throws EE_Error
1163
-     * @throws InvalidArgumentException
1164
-     * @throws InvalidDataTypeException
1165
-     * @throws InvalidInterfaceException
1166
-     */
1167
-    public function copy_attendee_info_settings_form()
1168
-    {
1169
-        echo wp_kses($this->_copy_attendee_info_settings_form()->get_html(), AllowedTags::getWithFormTags());
1170
-    }
1171
-
1172
-    /**
1173
-     * _copy_attendee_info_settings_form
1174
-     *
1175
-     * @access protected
1176
-     * @return EE_Form_Section_Proper
1177
-     * @throws \EE_Error
1178
-     */
1179
-    protected function _copy_attendee_info_settings_form()
1180
-    {
1181
-        return new EE_Form_Section_Proper(
1182
-            array(
1183
-                'name'            => 'copy_attendee_info_settings',
1184
-                'html_id'         => 'copy_attendee_info_settings',
1185
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1186
-                'subsections'     => apply_filters(
1187
-                    'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections',
1188
-                    array(
1189
-                        'copy_attendee_info_hdr'   => new EE_Form_Section_HTML(
1190
-                            EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso'))
1191
-                        ),
1192
-                        'copy_attendee_info' => new EE_Yes_No_Input(
1193
-                            array(
1194
-                                'html_label_text' => esc_html__(
1195
-                                    'Allow copy #1 attendee info to extra attendees?',
1196
-                                    'event_espresso'
1197
-                                ),
1198
-                                'html_help_text'  => esc_html__(
1199
-                                    'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.',
1200
-                                    'event_espresso'
1201
-                                ),
1202
-                                'default'         => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(),
1203
-                                'required'        => false,
1204
-                                'display_html_label_text' => false,
1205
-                            )
1206
-                        ),
1207
-                    )
1208
-                ),
1209
-            )
1210
-        );
1211
-    }
1212
-
1213
-    /**
1214
-     * @param EE_Registration_Config $EE_Registration_Config
1215
-     * @return EE_Registration_Config
1216
-     * @throws EE_Error
1217
-     * @throws InvalidArgumentException
1218
-     * @throws ReflectionException
1219
-     * @throws InvalidDataTypeException
1220
-     * @throws InvalidInterfaceException
1221
-     */
1222
-    public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config)
1223
-    {
1224
-        $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo();
1225
-        try {
1226
-            $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form();
1227
-            // if not displaying a form, then check for form submission
1228
-            if ($copy_attendee_info_settings_form->was_submitted()) {
1229
-                // capture form data
1230
-                $copy_attendee_info_settings_form->receive_form_submission();
1231
-                // validate form data
1232
-                if ($copy_attendee_info_settings_form->is_valid()) {
1233
-                    // grab validated data from form
1234
-                    $valid_data = $copy_attendee_info_settings_form->valid_data();
1235
-                    if (isset($valid_data['copy_attendee_info'])) {
1236
-                        $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']);
1237
-                    } else {
1238
-                        EE_Error::add_error(
1239
-                            esc_html__(
1240
-                                'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.',
1241
-                                'event_espresso'
1242
-                            ),
1243
-                            __FILE__,
1244
-                            __FUNCTION__,
1245
-                            __LINE__
1246
-                        );
1247
-                    }
1248
-                } else {
1249
-                    if ($copy_attendee_info_settings_form->submission_error_message() !== '') {
1250
-                        EE_Error::add_error(
1251
-                            $copy_attendee_info_settings_form->submission_error_message(),
1252
-                            __FILE__,
1253
-                            __FUNCTION__,
1254
-                            __LINE__
1255
-                        );
1256
-                    }
1257
-                }
1258
-            }
1259
-        } catch (EE_Error $e) {
1260
-            $e->get_error();
1261
-        }
1262
-        return $EE_Registration_Config;
1263
-    }
1264
-
1265
-
1266
-    /**
1267
-     * @return void
1268
-     * @throws EE_Error
1269
-     * @throws InvalidArgumentException
1270
-     * @throws InvalidDataTypeException
1271
-     * @throws InvalidInterfaceException
1272
-     */
1273
-    public function email_validation_settings_form()
1274
-    {
1275
-        echo wp_kses($this->_email_validation_settings_form()->get_html(), AllowedTags::getWithFormTags());
1276
-    }
1277
-
1278
-
1279
-    /**
1280
-     * _email_validation_settings_form
1281
-     *
1282
-     * @access protected
1283
-     * @return EE_Form_Section_Proper
1284
-     * @throws \EE_Error
1285
-     */
1286
-    protected function _email_validation_settings_form()
1287
-    {
1288
-        return new EE_Form_Section_Proper(
1289
-            array(
1290
-                'name'            => 'email_validation_settings',
1291
-                'html_id'         => 'email_validation_settings',
1292
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1293
-                'subsections'     => apply_filters(
1294
-                    'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
1295
-                    array(
1296
-                        'email_validation_hdr'   => new EE_Form_Section_HTML(
1297
-                            EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
1298
-                        ),
1299
-                        'email_validation_level' => new EE_Select_Input(
1300
-                            array(
1301
-                                'basic'      => esc_html__('Basic', 'event_espresso'),
1302
-                                'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
1303
-                                'i18n'       => esc_html__('International', 'event_espresso'),
1304
-                                'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
1305
-                            ),
1306
-                            array(
1307
-                                'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
1308
-                                                     . EEH_Template::get_help_tab_link('email_validation_info'),
1309
-                                'html_help_text'  => esc_html__(
1310
-                                    'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
1311
-                                    'event_espresso'
1312
-                                ),
1313
-                                'default'         => isset(
1314
-                                    EE_Registry::instance()->CFG->registration->email_validation_level
1315
-                                )
1316
-                                    ? EE_Registry::instance()->CFG->registration->email_validation_level
1317
-                                    : 'wp_default',
1318
-                                'required'        => false,
1319
-                            )
1320
-                        ),
1321
-                    )
1322
-                ),
1323
-            )
1324
-        );
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * @param EE_Registration_Config $EE_Registration_Config
1330
-     * @return EE_Registration_Config
1331
-     * @throws EE_Error
1332
-     * @throws InvalidArgumentException
1333
-     * @throws ReflectionException
1334
-     * @throws InvalidDataTypeException
1335
-     * @throws InvalidInterfaceException
1336
-     */
1337
-    public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1338
-    {
1339
-        $prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1340
-        try {
1341
-            $email_validation_settings_form = $this->_email_validation_settings_form();
1342
-            // if not displaying a form, then check for form submission
1343
-            if ($email_validation_settings_form->was_submitted()) {
1344
-                // capture form data
1345
-                $email_validation_settings_form->receive_form_submission();
1346
-                // validate form data
1347
-                if ($email_validation_settings_form->is_valid()) {
1348
-                    // grab validated data from form
1349
-                    $valid_data = $email_validation_settings_form->valid_data();
1350
-                    if (isset($valid_data['email_validation_level'])) {
1351
-                        $email_validation_level = $valid_data['email_validation_level'];
1352
-                        // now if they want to use international email addresses
1353
-                        if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1354
-                            // in case we need to reset their email validation level,
1355
-                            // make sure that the previous value wasn't already set to one of the i18n options.
1356
-                            if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') {
1357
-                                // if so, then reset it back to "basic" since that is the only other option that,
1358
-                                // despite offering poor validation, supports i18n email addresses
1359
-                                $prev_email_validation_level = 'basic';
1360
-                            }
1361
-                            // confirm our i18n email validation will work on the server
1362
-                            if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1363
-                                // or reset email validation level to previous value
1364
-                                $email_validation_level = $prev_email_validation_level;
1365
-                            }
1366
-                        }
1367
-                        $EE_Registration_Config->email_validation_level = $email_validation_level;
1368
-                    } else {
1369
-                        EE_Error::add_error(
1370
-                            esc_html__(
1371
-                                'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1372
-                                'event_espresso'
1373
-                            ),
1374
-                            __FILE__,
1375
-                            __FUNCTION__,
1376
-                            __LINE__
1377
-                        );
1378
-                    }
1379
-                } else {
1380
-                    if ($email_validation_settings_form->submission_error_message() !== '') {
1381
-                        EE_Error::add_error(
1382
-                            $email_validation_settings_form->submission_error_message(),
1383
-                            __FILE__,
1384
-                            __FUNCTION__,
1385
-                            __LINE__
1386
-                        );
1387
-                    }
1388
-                }
1389
-            }
1390
-        } catch (EE_Error $e) {
1391
-            $e->get_error();
1392
-        }
1393
-        return $EE_Registration_Config;
1394
-    }
1395
-
1396
-
1397
-    /**
1398
-     * confirms that the server's PHP version has the PCRE module enabled,
1399
-     * and that the PCRE version works with our i18n email validation
1400
-     *
1401
-     * @param EE_Registration_Config $EE_Registration_Config
1402
-     * @param string                 $email_validation_level
1403
-     * @return bool
1404
-     */
1405
-    private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1406
-    {
1407
-        // first check that PCRE is enabled
1408
-        if (! defined('PREG_BAD_UTF8_ERROR')) {
1409
-            EE_Error::add_error(
1410
-                sprintf(
1411
-                    esc_html__(
1412
-                        'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1413
-                        'event_espresso'
1414
-                    ),
1415
-                    '<br />'
1416
-                ),
1417
-                __FILE__,
1418
-                __FUNCTION__,
1419
-                __LINE__
1420
-            );
1421
-            return false;
1422
-        } else {
1423
-            // PCRE support is enabled, but let's still
1424
-            // perform a test to see if the server will support it.
1425
-            // but first, save the updated validation level to the config,
1426
-            // so that the validation strategy picks it up.
1427
-            // this will get bumped back down if it doesn't work
1428
-            $EE_Registration_Config->email_validation_level = $email_validation_level;
1429
-            try {
1430
-                $email_validator = new EE_Email_Validation_Strategy();
1431
-                $i18n_email_address = apply_filters(
1432
-                    'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1433
-                    'jägerjü[email protected]'
1434
-                );
1435
-                $email_validator->validate($i18n_email_address);
1436
-            } catch (Exception $e) {
1437
-                EE_Error::add_error(
1438
-                    sprintf(
1439
-                        esc_html__(
1440
-                            'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1441
-                            'event_espresso'
1442
-                        ),
1443
-                        '<br />',
1444
-                        '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>'
1445
-                    ),
1446
-                    __FILE__,
1447
-                    __FUNCTION__,
1448
-                    __LINE__
1449
-                );
1450
-                return false;
1451
-            }
1452
-        }
1453
-        return true;
1454
-    }
17
+	/**
18
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
19
+	 */
20
+	public function __construct($routing = true)
21
+	{
22
+		define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/');
23
+		define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/');
24
+		define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
25
+		define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/');
26
+		define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
27
+		parent::__construct($routing);
28
+	}
29
+
30
+
31
+	/**
32
+	 * @return void
33
+	 */
34
+	protected function _extend_page_config()
35
+	{
36
+		$this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
37
+		$qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])
38
+			? $this->_req_data['QST_ID'] : 0;
39
+		$qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])
40
+			? $this->_req_data['QSG_ID'] : 0;
41
+
42
+		$new_page_routes = array(
43
+			'question_groups'    => array(
44
+				'func'       => '_question_groups_overview_list_table',
45
+				'capability' => 'ee_read_question_groups',
46
+			),
47
+			'add_question'       => array(
48
+				'func'       => '_edit_question',
49
+				'capability' => 'ee_edit_questions',
50
+			),
51
+			'insert_question'    => array(
52
+				'func'       => '_insert_or_update_question',
53
+				'args'       => array('new_question' => true),
54
+				'capability' => 'ee_edit_questions',
55
+				'noheader'   => true,
56
+			),
57
+			'duplicate_question' => array(
58
+				'func'       => '_duplicate_question',
59
+				'capability' => 'ee_edit_questions',
60
+				'noheader'   => true,
61
+			),
62
+			'trash_question'     => array(
63
+				'func'       => '_trash_question',
64
+				'capability' => 'ee_delete_question',
65
+				'obj_id'     => $qst_id,
66
+				'noheader'   => true,
67
+			),
68
+
69
+			'restore_question' => array(
70
+				'func'       => '_trash_or_restore_questions',
71
+				'capability' => 'ee_delete_question',
72
+				'obj_id'     => $qst_id,
73
+				'args'       => array('trash' => false),
74
+				'noheader'   => true,
75
+			),
76
+
77
+			'delete_question' => array(
78
+				'func'       => '_delete_question',
79
+				'capability' => 'ee_delete_question',
80
+				'obj_id'     => $qst_id,
81
+				'noheader'   => true,
82
+			),
83
+
84
+			'trash_questions' => array(
85
+				'func'       => '_trash_or_restore_questions',
86
+				'capability' => 'ee_delete_questions',
87
+				'args'       => array('trash' => true),
88
+				'noheader'   => true,
89
+			),
90
+
91
+			'restore_questions' => array(
92
+				'func'       => '_trash_or_restore_questions',
93
+				'capability' => 'ee_delete_questions',
94
+				'args'       => array('trash' => false),
95
+				'noheader'   => true,
96
+			),
97
+
98
+			'delete_questions' => array(
99
+				'func'       => '_delete_questions',
100
+				'args'       => array(),
101
+				'capability' => 'ee_delete_questions',
102
+				'noheader'   => true,
103
+			),
104
+
105
+			'add_question_group' => array(
106
+				'func'       => '_edit_question_group',
107
+				'capability' => 'ee_edit_question_groups',
108
+			),
109
+
110
+			'edit_question_group' => array(
111
+				'func'       => '_edit_question_group',
112
+				'capability' => 'ee_edit_question_group',
113
+				'obj_id'     => $qsg_id,
114
+				'args'       => array('edit'),
115
+			),
116
+
117
+			'delete_question_groups' => array(
118
+				'func'       => '_delete_question_groups',
119
+				'capability' => 'ee_delete_question_groups',
120
+				'noheader'   => true,
121
+			),
122
+
123
+			'delete_question_group' => array(
124
+				'func'       => '_delete_question_groups',
125
+				'capability' => 'ee_delete_question_group',
126
+				'obj_id'     => $qsg_id,
127
+				'noheader'   => true,
128
+			),
129
+
130
+			'trash_question_group' => array(
131
+				'func'       => '_trash_or_restore_question_groups',
132
+				'args'       => array('trash' => true),
133
+				'capability' => 'ee_delete_question_group',
134
+				'obj_id'     => $qsg_id,
135
+				'noheader'   => true,
136
+			),
137
+
138
+			'restore_question_group' => array(
139
+				'func'       => '_trash_or_restore_question_groups',
140
+				'args'       => array('trash' => false),
141
+				'capability' => 'ee_delete_question_group',
142
+				'obj_id'     => $qsg_id,
143
+				'noheader'   => true,
144
+			),
145
+
146
+			'insert_question_group' => array(
147
+				'func'       => '_insert_or_update_question_group',
148
+				'args'       => array('new_question_group' => true),
149
+				'capability' => 'ee_edit_question_groups',
150
+				'noheader'   => true,
151
+			),
152
+
153
+			'update_question_group' => array(
154
+				'func'       => '_insert_or_update_question_group',
155
+				'args'       => array('new_question_group' => false),
156
+				'capability' => 'ee_edit_question_group',
157
+				'obj_id'     => $qsg_id,
158
+				'noheader'   => true,
159
+			),
160
+
161
+			'trash_question_groups' => array(
162
+				'func'       => '_trash_or_restore_question_groups',
163
+				'args'       => array('trash' => true),
164
+				'capability' => 'ee_delete_question_groups',
165
+				'noheader'   => array('trash' => false),
166
+			),
167
+
168
+			'restore_question_groups' => array(
169
+				'func'       => '_trash_or_restore_question_groups',
170
+				'args'       => array('trash' => false),
171
+				'capability' => 'ee_delete_question_groups',
172
+				'noheader'   => true,
173
+			),
174
+
175
+
176
+			'espresso_update_question_group_order' => array(
177
+				'func'       => 'update_question_group_order',
178
+				'capability' => 'ee_edit_question_groups',
179
+				'noheader'   => true,
180
+			),
181
+
182
+			'view_reg_form_settings' => array(
183
+				'func'       => '_reg_form_settings',
184
+				'capability' => 'manage_options',
185
+			),
186
+
187
+			'update_reg_form_settings' => array(
188
+				'func'       => '_update_reg_form_settings',
189
+				'capability' => 'manage_options',
190
+				'noheader'   => true,
191
+			),
192
+		);
193
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
194
+
195
+		$new_page_config = array(
196
+
197
+			'question_groups' => array(
198
+				'nav'           => array(
199
+					'label' => esc_html__('Question Groups', 'event_espresso'),
200
+					'order' => 20,
201
+				),
202
+				'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
203
+				'help_tabs'     => array(
204
+					'registration_form_question_groups_help_tab'                           => array(
205
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
206
+						'filename' => 'registration_form_question_groups',
207
+					),
208
+					'registration_form_question_groups_table_column_headings_help_tab'     => array(
209
+						'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
210
+						'filename' => 'registration_form_question_groups_table_column_headings',
211
+					),
212
+					'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(
213
+						'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
214
+						'filename' => 'registration_form_question_groups_views_bulk_actions_search',
215
+					),
216
+				),
217
+				'metaboxes'     => $this->_default_espresso_metaboxes,
218
+				'require_nonce' => false,
219
+				'qtips'         => array(
220
+					'EE_Registration_Form_Tips',
221
+				),
222
+			),
223
+
224
+			'add_question' => array(
225
+				'nav'           => array(
226
+					'label'      => esc_html__('Add Question', 'event_espresso'),
227
+					'order'      => 5,
228
+					'persistent' => false,
229
+				),
230
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
231
+				'help_tabs'     => array(
232
+					'registration_form_add_question_help_tab' => array(
233
+						'title'    => esc_html__('Add Question', 'event_espresso'),
234
+						'filename' => 'registration_form_add_question',
235
+					),
236
+				),
237
+				'require_nonce' => false,
238
+			),
239
+
240
+			'add_question_group' => array(
241
+				'nav'           => array(
242
+					'label'      => esc_html__('Add Question Group', 'event_espresso'),
243
+					'order'      => 5,
244
+					'persistent' => false,
245
+				),
246
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
247
+				'help_tabs'     => array(
248
+					'registration_form_add_question_group_help_tab' => array(
249
+						'title'    => esc_html__('Add Question Group', 'event_espresso'),
250
+						'filename' => 'registration_form_add_question_group',
251
+					),
252
+				),
253
+				'require_nonce' => false,
254
+			),
255
+
256
+			'edit_question_group' => array(
257
+				'nav'           => array(
258
+					'label'      => esc_html__('Edit Question Group', 'event_espresso'),
259
+					'order'      => 5,
260
+					'persistent' => false,
261
+					'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(
262
+						array('question_group_id' => $this->_req_data['question_group_id']),
263
+						$this->_current_page_view_url
264
+					) : $this->_admin_base_url,
265
+				),
266
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
267
+				'help_tabs'     => array(
268
+					'registration_form_edit_question_group_help_tab' => array(
269
+						'title'    => esc_html__('Edit Question Group', 'event_espresso'),
270
+						'filename' => 'registration_form_edit_question_group',
271
+					),
272
+				),
273
+				'require_nonce' => false,
274
+			),
275
+
276
+			'view_reg_form_settings' => array(
277
+				'nav'           => array(
278
+					'label' => esc_html__('Reg Form Settings', 'event_espresso'),
279
+					'order' => 40,
280
+				),
281
+				'labels'        => array(
282
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
283
+				),
284
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
285
+				'help_tabs'     => array(
286
+					'registration_form_reg_form_settings_help_tab' => array(
287
+						'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
288
+						'filename' => 'registration_form_reg_form_settings',
289
+					),
290
+				),
291
+				'require_nonce' => false,
292
+			),
293
+
294
+		);
295
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
296
+
297
+		// change the list table we're going to use so it's the NEW list table!
298
+		$this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
299
+
300
+
301
+		// additional labels
302
+		$new_labels = array(
303
+			'add_question'          => esc_html__('Add New Question', 'event_espresso'),
304
+			'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
305
+			'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
306
+			'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
307
+			'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
308
+		);
309
+		$this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
310
+	}
311
+
312
+
313
+	/**
314
+	 * @return void
315
+	 */
316
+	protected function _ajax_hooks()
317
+	{
318
+		add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order'));
319
+	}
320
+
321
+
322
+	/**
323
+	 * @return void
324
+	 */
325
+	public function load_scripts_styles_question_groups()
326
+	{
327
+		wp_enqueue_script('espresso_ajax_table_sorting');
328
+	}
329
+
330
+
331
+	/**
332
+	 * @return void
333
+	 */
334
+	public function load_scripts_styles_add_question_group()
335
+	{
336
+		$this->load_scripts_styles_forms();
337
+		$this->load_sortable_question_script();
338
+	}
339
+
340
+
341
+	/**
342
+	 * @return void
343
+	 */
344
+	public function load_scripts_styles_edit_question_group()
345
+	{
346
+		$this->load_scripts_styles_forms();
347
+		$this->load_sortable_question_script();
348
+	}
349
+
350
+
351
+	/**
352
+	 * registers and enqueues script for questions
353
+	 *
354
+	 * @return void
355
+	 */
356
+	public function load_sortable_question_script()
357
+	{
358
+		wp_register_script(
359
+			'ee-question-sortable',
360
+			REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
361
+			array('jquery-ui-sortable'),
362
+			EVENT_ESPRESSO_VERSION,
363
+			true
364
+		);
365
+		wp_enqueue_script('ee-question-sortable');
366
+	}
367
+
368
+
369
+	/**
370
+	 * @return void
371
+	 */
372
+	protected function _set_list_table_views_default()
373
+	{
374
+		$this->_views = array(
375
+			'all' => array(
376
+				'slug'        => 'all',
377
+				'label'       => esc_html__('View All Questions', 'event_espresso'),
378
+				'count'       => 0,
379
+				'bulk_action' => array(
380
+					'trash_questions' => esc_html__('Trash', 'event_espresso'),
381
+				),
382
+			),
383
+		);
384
+
385
+		if (
386
+			EE_Registry::instance()->CAP->current_user_can(
387
+				'ee_delete_questions',
388
+				'espresso_registration_form_trash_questions'
389
+			)
390
+		) {
391
+			$this->_views['trash'] = array(
392
+				'slug'        => 'trash',
393
+				'label'       => esc_html__('Trash', 'event_espresso'),
394
+				'count'       => 0,
395
+				'bulk_action' => array(
396
+					'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
397
+					'restore_questions' => esc_html__('Restore', 'event_espresso'),
398
+				),
399
+			);
400
+		}
401
+	}
402
+
403
+
404
+	/**
405
+	 * @return void
406
+	 */
407
+	protected function _set_list_table_views_question_groups()
408
+	{
409
+		$this->_views = array(
410
+			'all' => array(
411
+				'slug'        => 'all',
412
+				'label'       => esc_html__('All', 'event_espresso'),
413
+				'count'       => 0,
414
+				'bulk_action' => array(
415
+					'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
416
+				),
417
+			),
418
+		);
419
+
420
+		if (
421
+			EE_Registry::instance()->CAP->current_user_can(
422
+				'ee_delete_question_groups',
423
+				'espresso_registration_form_trash_question_groups'
424
+			)
425
+		) {
426
+			$this->_views['trash'] = array(
427
+				'slug'        => 'trash',
428
+				'label'       => esc_html__('Trash', 'event_espresso'),
429
+				'count'       => 0,
430
+				'bulk_action' => array(
431
+					'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
432
+					'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
433
+				),
434
+			);
435
+		}
436
+	}
437
+
438
+
439
+	/**
440
+	 * @return void
441
+	 * @throws EE_Error
442
+	 * @throws InvalidArgumentException
443
+	 * @throws InvalidDataTypeException
444
+	 * @throws InvalidInterfaceException
445
+	 */
446
+	protected function _questions_overview_list_table()
447
+	{
448
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
449
+			'add_question',
450
+			'add_question',
451
+			array(),
452
+			'add-new-h2'
453
+		);
454
+		parent::_questions_overview_list_table();
455
+	}
456
+
457
+
458
+	/**
459
+	 * @return void
460
+	 * @throws DomainException
461
+	 * @throws EE_Error
462
+	 * @throws InvalidArgumentException
463
+	 * @throws InvalidDataTypeException
464
+	 * @throws InvalidInterfaceException
465
+	 */
466
+	protected function _question_groups_overview_list_table()
467
+	{
468
+		$this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
469
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
470
+			'add_question_group',
471
+			'add_question_group',
472
+			array(),
473
+			'add-new-h2'
474
+		);
475
+		$this->display_admin_list_table_page_with_sidebar();
476
+	}
477
+
478
+
479
+	/**
480
+	 * @return void
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 */
486
+	protected function _delete_question()
487
+	{
488
+		$success = $this->_delete_items($this->_question_model);
489
+		$this->_redirect_after_action(
490
+			$success,
491
+			$this->_question_model->item_name($success),
492
+			'deleted',
493
+			array('action' => 'default', 'status' => 'all')
494
+		);
495
+	}
496
+
497
+
498
+	/**
499
+	 * @return void
500
+	 * @throws EE_Error
501
+	 * @throws InvalidArgumentException
502
+	 * @throws InvalidDataTypeException
503
+	 * @throws InvalidInterfaceException
504
+	 */
505
+	protected function _delete_questions()
506
+	{
507
+		$success = $this->_delete_items($this->_question_model);
508
+		$this->_redirect_after_action(
509
+			$success,
510
+			$this->_question_model->item_name($success),
511
+			'deleted permanently',
512
+			array('action' => 'default', 'status' => 'trash')
513
+		);
514
+	}
515
+
516
+
517
+	/**
518
+	 * Performs the deletion of a single or multiple questions or question groups.
519
+	 *
520
+	 * @param EEM_Soft_Delete_Base $model
521
+	 * @return int number of items deleted permanently
522
+	 * @throws EE_Error
523
+	 * @throws InvalidArgumentException
524
+	 * @throws InvalidDataTypeException
525
+	 * @throws InvalidInterfaceException
526
+	 */
527
+	private function _delete_items(EEM_Soft_Delete_Base $model)
528
+	{
529
+		$success = 0;
530
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
531
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
532
+			// if array has more than one element than success message should be plural
533
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
534
+			// cycle thru bulk action checkboxes
535
+			$checkboxes = $this->_req_data['checkbox'];
536
+			foreach (array_keys($checkboxes) as $ID) {
537
+				if (! $this->_delete_item($ID, $model)) {
538
+					$success = 0;
539
+				}
540
+			}
541
+		} elseif (! empty($this->_req_data['QSG_ID'])) {
542
+			$success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
543
+		} elseif (! empty($this->_req_data['QST_ID'])) {
544
+			$success = $this->_delete_item($this->_req_data['QST_ID'], $model);
545
+		} else {
546
+			EE_Error::add_error(
547
+				sprintf(
548
+					esc_html__(
549
+						"No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
550
+						"event_espresso"
551
+					)
552
+				),
553
+				__FILE__,
554
+				__FUNCTION__,
555
+				__LINE__
556
+			);
557
+		}
558
+		return $success;
559
+	}
560
+
561
+
562
+	/**
563
+	 * Deletes the specified question (and its associated question options) or question group
564
+	 *
565
+	 * @param int                  $id
566
+	 * @param EEM_Soft_Delete_Base $model
567
+	 * @return boolean
568
+	 * @throws EE_Error
569
+	 * @throws InvalidArgumentException
570
+	 * @throws InvalidDataTypeException
571
+	 * @throws InvalidInterfaceException
572
+	 */
573
+	protected function _delete_item($id, $model)
574
+	{
575
+		if ($model instanceof EEM_Question) {
576
+			EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id))));
577
+		}
578
+		return $model->delete_permanently_by_ID(absint($id));
579
+	}
580
+
581
+
582
+	/******************************    QUESTION GROUPS    ******************************/
583
+
584
+
585
+	/**
586
+	 * @param string $type
587
+	 * @return void
588
+	 * @throws DomainException
589
+	 * @throws EE_Error
590
+	 * @throws InvalidArgumentException
591
+	 * @throws InvalidDataTypeException
592
+	 * @throws InvalidInterfaceException
593
+	 */
594
+	protected function _edit_question_group($type = 'add')
595
+	{
596
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
597
+		$ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])
598
+			? absint($this->_req_data['QSG_ID'])
599
+			: false;
600
+
601
+		switch ($this->_req_action) {
602
+			case 'add_question_group':
603
+				$this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
604
+				break;
605
+			case 'edit_question_group':
606
+				$this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
607
+				break;
608
+			default:
609
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
610
+		}
611
+		// add ID to title if editing
612
+		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
613
+		if ($ID) {
614
+			/** @var EE_Question_Group $questionGroup */
615
+			$questionGroup = $this->_question_group_model->get_one_by_ID($ID);
616
+			$additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID));
617
+			$this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
618
+		} else {
619
+			/** @var EE_Question_Group $questionGroup */
620
+			$questionGroup = EEM_Question_Group::instance()->create_default_object();
621
+			$questionGroup->set_order_to_latest();
622
+			$this->_set_add_edit_form_tags('insert_question_group');
623
+		}
624
+		$this->_template_args['values'] = $this->_yes_no_values;
625
+		$this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group();
626
+		$this->_template_args['QSG_ID'] = $ID ? $ID : true;
627
+		$this->_template_args['question_group'] = $questionGroup;
628
+
629
+		$redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url);
630
+		$this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL);
631
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
632
+			REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
633
+			$this->_template_args,
634
+			true
635
+		);
636
+
637
+		// the details template wrapper
638
+		$this->display_admin_page_with_sidebar();
639
+	}
640
+
641
+
642
+	/**
643
+	 * @return void
644
+	 * @throws EE_Error
645
+	 * @throws InvalidArgumentException
646
+	 * @throws InvalidDataTypeException
647
+	 * @throws InvalidInterfaceException
648
+	 */
649
+	protected function _delete_question_groups()
650
+	{
651
+		$success = $this->_delete_items($this->_question_group_model);
652
+		$this->_redirect_after_action(
653
+			$success,
654
+			$this->_question_group_model->item_name($success),
655
+			'deleted permanently',
656
+			array('action' => 'question_groups', 'status' => 'trash')
657
+		);
658
+	}
659
+
660
+
661
+	/**
662
+	 * @param bool $new_question_group
663
+	 * @throws EE_Error
664
+	 * @throws InvalidArgumentException
665
+	 * @throws InvalidDataTypeException
666
+	 * @throws InvalidInterfaceException
667
+	 */
668
+	protected function _insert_or_update_question_group($new_question_group = true)
669
+	{
670
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
671
+		$set_column_values = $this->_set_column_values_for($this->_question_group_model);
672
+
673
+		// make sure identifier is unique
674
+		$identifier_value = $set_column_values['QSG_identifier'] ?? '';
675
+		$where_values = ['QSG_identifier' => $identifier_value ];
676
+		if (! $new_question_group && isset($set_column_values['QSG_ID'])) {
677
+			$where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']];
678
+		}
679
+		$identifier_exists = ! empty($identifier_value) && $this->_question_group_model->count([$where_values]) > 0;
680
+		if ($identifier_exists) {
681
+			$set_column_values['QSG_identifier'] .= uniqid('id', true);
682
+		}
683
+
684
+		if ($new_question_group) {
685
+			$QSG_ID = $this->_question_group_model->insert($set_column_values);
686
+			$success = $QSG_ID ? 1 : 0;
687
+			if ($success === 0) {
688
+				EE_Error::add_error(
689
+					esc_html__('Something went wrong saving the question group.', 'event_espresso'),
690
+					__FILE__,
691
+					__FUNCTION__,
692
+					__LINE__
693
+				);
694
+				$this->_redirect_after_action(
695
+					false,
696
+					'',
697
+					'',
698
+					array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
699
+					true
700
+				);
701
+			}
702
+		} else {
703
+			$QSG_ID = absint($this->_req_data['QSG_ID']);
704
+			unset($set_column_values['QSG_ID']);
705
+			$success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID)));
706
+		}
707
+
708
+		$phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
709
+			EEM_Attendee::system_question_phone
710
+		);
711
+		// update the existing related questions
712
+		// BUT FIRST...  delete the phone question from the Question_Group_Question
713
+		// if it is being added to this question group (therefore removed from the existing group)
714
+		if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
715
+			// delete where QST ID = system phone question ID and Question Group ID is NOT this group
716
+			EEM_Question_Group_Question::instance()->delete(
717
+				array(
718
+					array(
719
+						'QST_ID' => $phone_question_id,
720
+						'QSG_ID' => array('!=', $QSG_ID),
721
+					),
722
+				)
723
+			);
724
+		}
725
+		/** @type EE_Question_Group $question_group */
726
+		$question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
727
+		$questions = $question_group->questions();
728
+		// make sure system phone question is added to list of questions for this group
729
+		if (! isset($questions[ $phone_question_id ])) {
730
+			$questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
731
+		}
732
+
733
+		foreach ($questions as $question_ID => $question) {
734
+			// first we always check for order.
735
+			if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
736
+				// update question order
737
+				$question_group->update_question_order(
738
+					$question_ID,
739
+					$this->_req_data['question_orders'][ $question_ID ]
740
+				);
741
+			}
742
+
743
+			// then we always check if adding or removing.
744
+			if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
745
+				$question_group->add_question($question_ID);
746
+			} else {
747
+				// not found, remove it (but only if not a system question for the personal group
748
+				// with the exception of lname system question - we allow removal of it)
749
+				if (
750
+					in_array(
751
+						$question->system_ID(),
752
+						EEM_Question::instance()->required_system_questions_in_system_question_group(
753
+							$question_group->system_group()
754
+						)
755
+					)
756
+				) {
757
+					continue;
758
+				} else {
759
+					$question_group->remove_question($question_ID);
760
+				}
761
+			}
762
+		}
763
+		// save new related questions
764
+		if (isset($this->_req_data['questions'])) {
765
+			foreach ($this->_req_data['questions'] as $QST_ID) {
766
+				$question_group->add_question($QST_ID);
767
+				if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
768
+					$question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
769
+				}
770
+			}
771
+		}
772
+
773
+		if ($success !== false) {
774
+			$msg = $new_question_group
775
+				? sprintf(
776
+					esc_html__('The %s has been created', 'event_espresso'),
777
+					$this->_question_group_model->item_name()
778
+				)
779
+				: sprintf(
780
+					esc_html__(
781
+						'The %s has been updated',
782
+						'event_espresso'
783
+					),
784
+					$this->_question_group_model->item_name()
785
+				);
786
+			EE_Error::add_success($msg);
787
+		}
788
+		$this->_redirect_after_action(
789
+			false,
790
+			'',
791
+			'',
792
+			array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
793
+			true
794
+		);
795
+	}
796
+
797
+
798
+	/**
799
+	 * duplicates a question and all its question options and redirects to the new question.
800
+	 *
801
+	 * @return void
802
+	 * @throws EE_Error
803
+	 * @throws InvalidArgumentException
804
+	 * @throws ReflectionException
805
+	 * @throws InvalidDataTypeException
806
+	 * @throws InvalidInterfaceException
807
+	 */
808
+	public function _duplicate_question()
809
+	{
810
+		$question_ID = (int) $this->_req_data['QST_ID'];
811
+		$question = EEM_Question::instance()->get_one_by_ID($question_ID);
812
+		if ($question instanceof EE_Question) {
813
+			$new_question = $question->duplicate();
814
+			if ($new_question instanceof EE_Question) {
815
+				$this->_redirect_after_action(
816
+					true,
817
+					esc_html__('Question', 'event_espresso'),
818
+					esc_html__('Duplicated', 'event_espresso'),
819
+					array('action' => 'edit_question', 'QST_ID' => $new_question->ID()),
820
+					true
821
+				);
822
+			} else {
823
+				global $wpdb;
824
+				EE_Error::add_error(
825
+					sprintf(
826
+						esc_html__(
827
+							'Could not duplicate question with ID %1$d because: %2$s',
828
+							'event_espresso'
829
+						),
830
+						$question_ID,
831
+						$wpdb->last_error
832
+					),
833
+					__FILE__,
834
+					__FUNCTION__,
835
+					__LINE__
836
+				);
837
+				$this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
838
+			}
839
+		} else {
840
+			EE_Error::add_error(
841
+				sprintf(
842
+					esc_html__(
843
+						'Could not duplicate question with ID %d because it didn\'t exist!',
844
+						'event_espresso'
845
+					),
846
+					$question_ID
847
+				),
848
+				__FILE__,
849
+				__FUNCTION__,
850
+				__LINE__
851
+			);
852
+			$this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
853
+		}
854
+	}
855
+
856
+
857
+	/**
858
+	 * @param bool $trash
859
+	 * @throws EE_Error
860
+	 */
861
+	protected function _trash_or_restore_question_groups($trash = true)
862
+	{
863
+		$this->_trash_or_restore_items($this->_question_group_model, $trash);
864
+	}
865
+
866
+
867
+	/**
868
+	 *_trash_question
869
+	 *
870
+	 * @return void
871
+	 * @throws EE_Error
872
+	 */
873
+	protected function _trash_question()
874
+	{
875
+		$success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);
876
+		$query_args = array('action' => 'default', 'status' => 'all');
877
+		$this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
878
+	}
879
+
880
+
881
+	/**
882
+	 * @param bool $trash
883
+	 * @throws EE_Error
884
+	 */
885
+	protected function _trash_or_restore_questions($trash = true)
886
+	{
887
+		$this->_trash_or_restore_items($this->_question_model, $trash);
888
+	}
889
+
890
+
891
+	/**
892
+	 * Internally used to delete or restore items, using the request data. Meant to be
893
+	 * flexible between question or question groups
894
+	 *
895
+	 * @param EEM_Soft_Delete_Base $model
896
+	 * @param boolean              $trash whether to trash or restore
897
+	 * @throws EE_Error
898
+	 */
899
+	private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
900
+	{
901
+
902
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
903
+
904
+		$success = 1;
905
+		// Checkboxes
906
+		// echo "trash $trash";
907
+		// var_dump($this->_req_data['checkbox']);die;
908
+		if (isset($this->_req_data['checkbox'])) {
909
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
910
+				// if array has more than one element than success message should be plural
911
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
912
+				// cycle thru bulk action checkboxes
913
+				$checkboxes = $this->_req_data['checkbox'];
914
+				foreach (array_keys($checkboxes) as $ID) {
915
+					if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
916
+						$success = 0;
917
+					}
918
+				}
919
+			} else {
920
+				// grab single id and delete
921
+				$ID = absint($this->_req_data['checkbox']);
922
+				if (! $model->delete_or_restore_by_ID($trash, $ID)) {
923
+					$success = 0;
924
+				}
925
+			}
926
+		} else {
927
+			// delete via trash link
928
+			// grab single id and delete
929
+			$ID = absint($this->_req_data[ $model->primary_key_name() ]);
930
+			if (! $model->delete_or_restore_by_ID($trash, $ID)) {
931
+				$success = 0;
932
+			}
933
+		}
934
+
935
+
936
+		$action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
937
+		// echo "action :$action";
938
+		// $action = 'questions' ? 'default' : $action;
939
+		if ($trash) {
940
+			$action_desc = 'trashed';
941
+			$status = 'trash';
942
+		} else {
943
+			$action_desc = 'restored';
944
+			$status = 'all';
945
+		}
946
+		$this->_redirect_after_action(
947
+			$success,
948
+			$model->item_name($success),
949
+			$action_desc,
950
+			array('action' => $action, 'status' => $status)
951
+		);
952
+	}
953
+
954
+
955
+	/**
956
+	 * @param            $per_page
957
+	 * @param int        $current_page
958
+	 * @param bool|false $count
959
+	 * @return EE_Soft_Delete_Base_Class[]|int
960
+	 * @throws EE_Error
961
+	 * @throws InvalidArgumentException
962
+	 * @throws InvalidDataTypeException
963
+	 * @throws InvalidInterfaceException
964
+	 */
965
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
966
+	{
967
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
968
+
969
+		if ($count) {
970
+			// note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
971
+			$where = isset($query_params[0]) ? array($query_params[0]) : array();
972
+			$results = $this->_question_model->count_deleted($where);
973
+		} else {
974
+			// note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
975
+			$results = $this->_question_model->get_all_deleted($query_params);
976
+		}
977
+		return $results;
978
+	}
979
+
980
+
981
+	/**
982
+	 * @param            $per_page
983
+	 * @param int        $current_page
984
+	 * @param bool|false $count
985
+	 * @return EE_Soft_Delete_Base_Class[]|int
986
+	 * @throws EE_Error
987
+	 * @throws InvalidArgumentException
988
+	 * @throws InvalidDataTypeException
989
+	 * @throws InvalidInterfaceException
990
+	 */
991
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
992
+	{
993
+		$questionGroupModel = EEM_Question_Group::instance();
994
+		$query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
995
+		if ($count) {
996
+			$where = isset($query_params[0]) ? array($query_params[0]) : array();
997
+			$results = $questionGroupModel->count($where);
998
+		} else {
999
+			$results = $questionGroupModel->get_all($query_params);
1000
+		}
1001
+		return $results;
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * @param      $per_page
1007
+	 * @param int  $current_page
1008
+	 * @param bool $count
1009
+	 * @return EE_Soft_Delete_Base_Class[]|int
1010
+	 * @throws EE_Error
1011
+	 * @throws InvalidArgumentException
1012
+	 * @throws InvalidDataTypeException
1013
+	 * @throws InvalidInterfaceException
1014
+	 */
1015
+	public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
1016
+	{
1017
+		$questionGroupModel = EEM_Question_Group::instance();
1018
+		$query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1019
+		if ($count) {
1020
+			$where = isset($query_params[0]) ? array($query_params[0]) : array();
1021
+			$query_params['limit'] = null;
1022
+			$results = $questionGroupModel->count_deleted($where);
1023
+		} else {
1024
+			$results = $questionGroupModel->get_all_deleted($query_params);
1025
+		}
1026
+		return $results;
1027
+	}
1028
+
1029
+
1030
+	/**
1031
+	 * method for performing updates to question order
1032
+	 *
1033
+	 * @return void results array
1034
+	 * @throws EE_Error
1035
+	 * @throws InvalidArgumentException
1036
+	 * @throws InvalidDataTypeException
1037
+	 * @throws InvalidInterfaceException
1038
+	 */
1039
+	public function update_question_group_order()
1040
+	{
1041
+
1042
+		$success = esc_html__('Question group order was updated successfully.', 'event_espresso');
1043
+
1044
+		// grab our row IDs
1045
+		$row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
1046
+			? explode(',', rtrim($this->_req_data['row_ids'], ','))
1047
+			: array();
1048
+
1049
+		$perpage = ! empty($this->_req_data['perpage'])
1050
+			? (int) $this->_req_data['perpage']
1051
+			: null;
1052
+		$curpage = ! empty($this->_req_data['curpage'])
1053
+			? (int) $this->_req_data['curpage']
1054
+			: null;
1055
+
1056
+		if (! empty($row_ids)) {
1057
+			// figure out where we start the row_id count at for the current page.
1058
+			$qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1059
+
1060
+			$row_count = count($row_ids);
1061
+			for ($i = 0; $i < $row_count; $i++) {
1062
+				// Update the questions when re-ordering
1063
+				$updated = EEM_Question_Group::instance()->update(
1064
+					array('QSG_order' => $qsgcount),
1065
+					array(array('QSG_ID' => $row_ids[ $i ]))
1066
+				);
1067
+				if ($updated === false) {
1068
+					$success = false;
1069
+				}
1070
+				$qsgcount++;
1071
+			}
1072
+		} else {
1073
+			$success = false;
1074
+		}
1075
+
1076
+		$errors = ! $success
1077
+			? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
1078
+			: false;
1079
+
1080
+		echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
1081
+		die();
1082
+	}
1083
+
1084
+
1085
+
1086
+	/***************************************       REGISTRATION SETTINGS       ***************************************/
1087
+
1088
+
1089
+	/**
1090
+	 * @throws DomainException
1091
+	 * @throws EE_Error
1092
+	 * @throws InvalidArgumentException
1093
+	 * @throws InvalidDataTypeException
1094
+	 * @throws InvalidInterfaceException
1095
+	 */
1096
+	protected function _reg_form_settings()
1097
+	{
1098
+		$this->_template_args['values'] = $this->_yes_no_values;
1099
+		add_action(
1100
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1101
+			array($this, 'email_validation_settings_form'),
1102
+			2
1103
+		);
1104
+		add_action(
1105
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1106
+			array($this, 'copy_attendee_info_settings_form'),
1107
+			4
1108
+		);
1109
+		$this->_template_args = (array) apply_filters(
1110
+			'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
1111
+			$this->_template_args
1112
+		);
1113
+		$this->_set_add_edit_form_tags('update_reg_form_settings');
1114
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1115
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1116
+			REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1117
+			$this->_template_args,
1118
+			true
1119
+		);
1120
+		$this->display_admin_page_with_sidebar();
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 * @return void
1126
+	 * @throws EE_Error
1127
+	 * @throws InvalidArgumentException
1128
+	 * @throws ReflectionException
1129
+	 * @throws InvalidDataTypeException
1130
+	 * @throws InvalidInterfaceException
1131
+	 */
1132
+	protected function _update_reg_form_settings()
1133
+	{
1134
+		EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
1135
+			EE_Registry::instance()->CFG->registration
1136
+		);
1137
+		EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form(
1138
+			EE_Registry::instance()->CFG->registration
1139
+		);
1140
+		EE_Registry::instance()->CFG->registration = apply_filters(
1141
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
1142
+			EE_Registry::instance()->CFG->registration
1143
+		);
1144
+		$success = $this->_update_espresso_configuration(
1145
+			esc_html__('Registration Form Options', 'event_espresso'),
1146
+			EE_Registry::instance()->CFG,
1147
+			__FILE__,
1148
+			__FUNCTION__,
1149
+			__LINE__
1150
+		);
1151
+		$this->_redirect_after_action(
1152
+			$success,
1153
+			esc_html__('Registration Form Options', 'event_espresso'),
1154
+			'updated',
1155
+			array('action' => 'view_reg_form_settings')
1156
+		);
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * @return void
1162
+	 * @throws EE_Error
1163
+	 * @throws InvalidArgumentException
1164
+	 * @throws InvalidDataTypeException
1165
+	 * @throws InvalidInterfaceException
1166
+	 */
1167
+	public function copy_attendee_info_settings_form()
1168
+	{
1169
+		echo wp_kses($this->_copy_attendee_info_settings_form()->get_html(), AllowedTags::getWithFormTags());
1170
+	}
1171
+
1172
+	/**
1173
+	 * _copy_attendee_info_settings_form
1174
+	 *
1175
+	 * @access protected
1176
+	 * @return EE_Form_Section_Proper
1177
+	 * @throws \EE_Error
1178
+	 */
1179
+	protected function _copy_attendee_info_settings_form()
1180
+	{
1181
+		return new EE_Form_Section_Proper(
1182
+			array(
1183
+				'name'            => 'copy_attendee_info_settings',
1184
+				'html_id'         => 'copy_attendee_info_settings',
1185
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1186
+				'subsections'     => apply_filters(
1187
+					'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections',
1188
+					array(
1189
+						'copy_attendee_info_hdr'   => new EE_Form_Section_HTML(
1190
+							EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso'))
1191
+						),
1192
+						'copy_attendee_info' => new EE_Yes_No_Input(
1193
+							array(
1194
+								'html_label_text' => esc_html__(
1195
+									'Allow copy #1 attendee info to extra attendees?',
1196
+									'event_espresso'
1197
+								),
1198
+								'html_help_text'  => esc_html__(
1199
+									'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.',
1200
+									'event_espresso'
1201
+								),
1202
+								'default'         => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(),
1203
+								'required'        => false,
1204
+								'display_html_label_text' => false,
1205
+							)
1206
+						),
1207
+					)
1208
+				),
1209
+			)
1210
+		);
1211
+	}
1212
+
1213
+	/**
1214
+	 * @param EE_Registration_Config $EE_Registration_Config
1215
+	 * @return EE_Registration_Config
1216
+	 * @throws EE_Error
1217
+	 * @throws InvalidArgumentException
1218
+	 * @throws ReflectionException
1219
+	 * @throws InvalidDataTypeException
1220
+	 * @throws InvalidInterfaceException
1221
+	 */
1222
+	public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config)
1223
+	{
1224
+		$prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo();
1225
+		try {
1226
+			$copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form();
1227
+			// if not displaying a form, then check for form submission
1228
+			if ($copy_attendee_info_settings_form->was_submitted()) {
1229
+				// capture form data
1230
+				$copy_attendee_info_settings_form->receive_form_submission();
1231
+				// validate form data
1232
+				if ($copy_attendee_info_settings_form->is_valid()) {
1233
+					// grab validated data from form
1234
+					$valid_data = $copy_attendee_info_settings_form->valid_data();
1235
+					if (isset($valid_data['copy_attendee_info'])) {
1236
+						$EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']);
1237
+					} else {
1238
+						EE_Error::add_error(
1239
+							esc_html__(
1240
+								'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.',
1241
+								'event_espresso'
1242
+							),
1243
+							__FILE__,
1244
+							__FUNCTION__,
1245
+							__LINE__
1246
+						);
1247
+					}
1248
+				} else {
1249
+					if ($copy_attendee_info_settings_form->submission_error_message() !== '') {
1250
+						EE_Error::add_error(
1251
+							$copy_attendee_info_settings_form->submission_error_message(),
1252
+							__FILE__,
1253
+							__FUNCTION__,
1254
+							__LINE__
1255
+						);
1256
+					}
1257
+				}
1258
+			}
1259
+		} catch (EE_Error $e) {
1260
+			$e->get_error();
1261
+		}
1262
+		return $EE_Registration_Config;
1263
+	}
1264
+
1265
+
1266
+	/**
1267
+	 * @return void
1268
+	 * @throws EE_Error
1269
+	 * @throws InvalidArgumentException
1270
+	 * @throws InvalidDataTypeException
1271
+	 * @throws InvalidInterfaceException
1272
+	 */
1273
+	public function email_validation_settings_form()
1274
+	{
1275
+		echo wp_kses($this->_email_validation_settings_form()->get_html(), AllowedTags::getWithFormTags());
1276
+	}
1277
+
1278
+
1279
+	/**
1280
+	 * _email_validation_settings_form
1281
+	 *
1282
+	 * @access protected
1283
+	 * @return EE_Form_Section_Proper
1284
+	 * @throws \EE_Error
1285
+	 */
1286
+	protected function _email_validation_settings_form()
1287
+	{
1288
+		return new EE_Form_Section_Proper(
1289
+			array(
1290
+				'name'            => 'email_validation_settings',
1291
+				'html_id'         => 'email_validation_settings',
1292
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1293
+				'subsections'     => apply_filters(
1294
+					'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
1295
+					array(
1296
+						'email_validation_hdr'   => new EE_Form_Section_HTML(
1297
+							EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
1298
+						),
1299
+						'email_validation_level' => new EE_Select_Input(
1300
+							array(
1301
+								'basic'      => esc_html__('Basic', 'event_espresso'),
1302
+								'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
1303
+								'i18n'       => esc_html__('International', 'event_espresso'),
1304
+								'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
1305
+							),
1306
+							array(
1307
+								'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
1308
+													 . EEH_Template::get_help_tab_link('email_validation_info'),
1309
+								'html_help_text'  => esc_html__(
1310
+									'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
1311
+									'event_espresso'
1312
+								),
1313
+								'default'         => isset(
1314
+									EE_Registry::instance()->CFG->registration->email_validation_level
1315
+								)
1316
+									? EE_Registry::instance()->CFG->registration->email_validation_level
1317
+									: 'wp_default',
1318
+								'required'        => false,
1319
+							)
1320
+						),
1321
+					)
1322
+				),
1323
+			)
1324
+		);
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * @param EE_Registration_Config $EE_Registration_Config
1330
+	 * @return EE_Registration_Config
1331
+	 * @throws EE_Error
1332
+	 * @throws InvalidArgumentException
1333
+	 * @throws ReflectionException
1334
+	 * @throws InvalidDataTypeException
1335
+	 * @throws InvalidInterfaceException
1336
+	 */
1337
+	public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1338
+	{
1339
+		$prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1340
+		try {
1341
+			$email_validation_settings_form = $this->_email_validation_settings_form();
1342
+			// if not displaying a form, then check for form submission
1343
+			if ($email_validation_settings_form->was_submitted()) {
1344
+				// capture form data
1345
+				$email_validation_settings_form->receive_form_submission();
1346
+				// validate form data
1347
+				if ($email_validation_settings_form->is_valid()) {
1348
+					// grab validated data from form
1349
+					$valid_data = $email_validation_settings_form->valid_data();
1350
+					if (isset($valid_data['email_validation_level'])) {
1351
+						$email_validation_level = $valid_data['email_validation_level'];
1352
+						// now if they want to use international email addresses
1353
+						if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1354
+							// in case we need to reset their email validation level,
1355
+							// make sure that the previous value wasn't already set to one of the i18n options.
1356
+							if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') {
1357
+								// if so, then reset it back to "basic" since that is the only other option that,
1358
+								// despite offering poor validation, supports i18n email addresses
1359
+								$prev_email_validation_level = 'basic';
1360
+							}
1361
+							// confirm our i18n email validation will work on the server
1362
+							if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1363
+								// or reset email validation level to previous value
1364
+								$email_validation_level = $prev_email_validation_level;
1365
+							}
1366
+						}
1367
+						$EE_Registration_Config->email_validation_level = $email_validation_level;
1368
+					} else {
1369
+						EE_Error::add_error(
1370
+							esc_html__(
1371
+								'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1372
+								'event_espresso'
1373
+							),
1374
+							__FILE__,
1375
+							__FUNCTION__,
1376
+							__LINE__
1377
+						);
1378
+					}
1379
+				} else {
1380
+					if ($email_validation_settings_form->submission_error_message() !== '') {
1381
+						EE_Error::add_error(
1382
+							$email_validation_settings_form->submission_error_message(),
1383
+							__FILE__,
1384
+							__FUNCTION__,
1385
+							__LINE__
1386
+						);
1387
+					}
1388
+				}
1389
+			}
1390
+		} catch (EE_Error $e) {
1391
+			$e->get_error();
1392
+		}
1393
+		return $EE_Registration_Config;
1394
+	}
1395
+
1396
+
1397
+	/**
1398
+	 * confirms that the server's PHP version has the PCRE module enabled,
1399
+	 * and that the PCRE version works with our i18n email validation
1400
+	 *
1401
+	 * @param EE_Registration_Config $EE_Registration_Config
1402
+	 * @param string                 $email_validation_level
1403
+	 * @return bool
1404
+	 */
1405
+	private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1406
+	{
1407
+		// first check that PCRE is enabled
1408
+		if (! defined('PREG_BAD_UTF8_ERROR')) {
1409
+			EE_Error::add_error(
1410
+				sprintf(
1411
+					esc_html__(
1412
+						'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1413
+						'event_espresso'
1414
+					),
1415
+					'<br />'
1416
+				),
1417
+				__FILE__,
1418
+				__FUNCTION__,
1419
+				__LINE__
1420
+			);
1421
+			return false;
1422
+		} else {
1423
+			// PCRE support is enabled, but let's still
1424
+			// perform a test to see if the server will support it.
1425
+			// but first, save the updated validation level to the config,
1426
+			// so that the validation strategy picks it up.
1427
+			// this will get bumped back down if it doesn't work
1428
+			$EE_Registration_Config->email_validation_level = $email_validation_level;
1429
+			try {
1430
+				$email_validator = new EE_Email_Validation_Strategy();
1431
+				$i18n_email_address = apply_filters(
1432
+					'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1433
+					'jägerjü[email protected]'
1434
+				);
1435
+				$email_validator->validate($i18n_email_address);
1436
+			} catch (Exception $e) {
1437
+				EE_Error::add_error(
1438
+					sprintf(
1439
+						esc_html__(
1440
+							'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1441
+							'event_espresso'
1442
+						),
1443
+						'<br />',
1444
+						'<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>'
1445
+					),
1446
+					__FILE__,
1447
+					__FUNCTION__,
1448
+					__LINE__
1449
+				);
1450
+				return false;
1451
+			}
1452
+		}
1453
+		return true;
1454
+	}
1455 1455
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
      */
20 20
     public function __construct($routing = true)
21 21
     {
22
-        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/');
23
-        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/');
24
-        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
25
-        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/');
26
-        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
22
+        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form/');
23
+        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets/');
24
+        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/');
25
+        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates/');
26
+        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/');
27 27
         parent::__construct($routing);
28 28
     }
29 29
 
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
     {
358 358
         wp_register_script(
359 359
             'ee-question-sortable',
360
-            REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
360
+            REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js',
361 361
             array('jquery-ui-sortable'),
362 362
             EVENT_ESPRESSO_VERSION,
363 363
             true
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
      */
446 446
     protected function _questions_overview_list_table()
447 447
     {
448
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
448
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
449 449
             'add_question',
450 450
             'add_question',
451 451
             array(),
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
     protected function _question_groups_overview_list_table()
467 467
     {
468 468
         $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
469
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
469
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
470 470
             'add_question_group',
471 471
             'add_question_group',
472 472
             array(),
@@ -528,19 +528,19 @@  discard block
 block discarded – undo
528 528
     {
529 529
         $success = 0;
530 530
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
531
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
531
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
532 532
             // if array has more than one element than success message should be plural
533 533
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
534 534
             // cycle thru bulk action checkboxes
535 535
             $checkboxes = $this->_req_data['checkbox'];
536 536
             foreach (array_keys($checkboxes) as $ID) {
537
-                if (! $this->_delete_item($ID, $model)) {
537
+                if ( ! $this->_delete_item($ID, $model)) {
538 538
                     $success = 0;
539 539
                 }
540 540
             }
541
-        } elseif (! empty($this->_req_data['QSG_ID'])) {
541
+        } elseif ( ! empty($this->_req_data['QSG_ID'])) {
542 542
             $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
543
-        } elseif (! empty($this->_req_data['QST_ID'])) {
543
+        } elseif ( ! empty($this->_req_data['QST_ID'])) {
544 544
             $success = $this->_delete_item($this->_req_data['QST_ID'], $model);
545 545
         } else {
546 546
             EE_Error::add_error(
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
                 $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
610 610
         }
611 611
         // add ID to title if editing
612
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
612
+        $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title;
613 613
         if ($ID) {
614 614
             /** @var EE_Question_Group $questionGroup */
615 615
             $questionGroup = $this->_question_group_model->get_one_by_ID($ID);
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
         $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url);
630 630
         $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL);
631 631
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
632
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
632
+            REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php',
633 633
             $this->_template_args,
634 634
             true
635 635
         );
@@ -672,8 +672,8 @@  discard block
 block discarded – undo
672 672
 
673 673
         // make sure identifier is unique
674 674
         $identifier_value = $set_column_values['QSG_identifier'] ?? '';
675
-        $where_values = ['QSG_identifier' => $identifier_value ];
676
-        if (! $new_question_group && isset($set_column_values['QSG_ID'])) {
675
+        $where_values = ['QSG_identifier' => $identifier_value];
676
+        if ( ! $new_question_group && isset($set_column_values['QSG_ID'])) {
677 677
             $where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']];
678 678
         }
679 679
         $identifier_exists = ! empty($identifier_value) && $this->_question_group_model->count([$where_values]) > 0;
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
         // update the existing related questions
712 712
         // BUT FIRST...  delete the phone question from the Question_Group_Question
713 713
         // if it is being added to this question group (therefore removed from the existing group)
714
-        if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
714
+        if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) {
715 715
             // delete where QST ID = system phone question ID and Question Group ID is NOT this group
716 716
             EEM_Question_Group_Question::instance()->delete(
717 717
                 array(
@@ -726,22 +726,22 @@  discard block
 block discarded – undo
726 726
         $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
727 727
         $questions = $question_group->questions();
728 728
         // make sure system phone question is added to list of questions for this group
729
-        if (! isset($questions[ $phone_question_id ])) {
730
-            $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
729
+        if ( ! isset($questions[$phone_question_id])) {
730
+            $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
731 731
         }
732 732
 
733 733
         foreach ($questions as $question_ID => $question) {
734 734
             // first we always check for order.
735
-            if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
735
+            if ( ! empty($this->_req_data['question_orders'][$question_ID])) {
736 736
                 // update question order
737 737
                 $question_group->update_question_order(
738 738
                     $question_ID,
739
-                    $this->_req_data['question_orders'][ $question_ID ]
739
+                    $this->_req_data['question_orders'][$question_ID]
740 740
                 );
741 741
             }
742 742
 
743 743
             // then we always check if adding or removing.
744
-            if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
744
+            if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) {
745 745
                 $question_group->add_question($question_ID);
746 746
             } else {
747 747
                 // not found, remove it (but only if not a system question for the personal group
@@ -764,8 +764,8 @@  discard block
 block discarded – undo
764 764
         if (isset($this->_req_data['questions'])) {
765 765
             foreach ($this->_req_data['questions'] as $QST_ID) {
766 766
                 $question_group->add_question($QST_ID);
767
-                if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
768
-                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
767
+                if (isset($this->_req_data['question_orders'][$QST_ID])) {
768
+                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]);
769 769
                 }
770 770
             }
771 771
         }
@@ -906,34 +906,34 @@  discard block
 block discarded – undo
906 906
         // echo "trash $trash";
907 907
         // var_dump($this->_req_data['checkbox']);die;
908 908
         if (isset($this->_req_data['checkbox'])) {
909
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
909
+            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
910 910
                 // if array has more than one element than success message should be plural
911 911
                 $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
912 912
                 // cycle thru bulk action checkboxes
913 913
                 $checkboxes = $this->_req_data['checkbox'];
914 914
                 foreach (array_keys($checkboxes) as $ID) {
915
-                    if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
915
+                    if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) {
916 916
                         $success = 0;
917 917
                     }
918 918
                 }
919 919
             } else {
920 920
                 // grab single id and delete
921 921
                 $ID = absint($this->_req_data['checkbox']);
922
-                if (! $model->delete_or_restore_by_ID($trash, $ID)) {
922
+                if ( ! $model->delete_or_restore_by_ID($trash, $ID)) {
923 923
                     $success = 0;
924 924
                 }
925 925
             }
926 926
         } else {
927 927
             // delete via trash link
928 928
             // grab single id and delete
929
-            $ID = absint($this->_req_data[ $model->primary_key_name() ]);
930
-            if (! $model->delete_or_restore_by_ID($trash, $ID)) {
929
+            $ID = absint($this->_req_data[$model->primary_key_name()]);
930
+            if ( ! $model->delete_or_restore_by_ID($trash, $ID)) {
931 931
                 $success = 0;
932 932
             }
933 933
         }
934 934
 
935 935
 
936
-        $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
936
+        $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; // strtolower( $model->item_name(2) );
937 937
         // echo "action :$action";
938 938
         // $action = 'questions' ? 'default' : $action;
939 939
         if ($trash) {
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
             ? (int) $this->_req_data['curpage']
1054 1054
             : null;
1055 1055
 
1056
-        if (! empty($row_ids)) {
1056
+        if ( ! empty($row_ids)) {
1057 1057
             // figure out where we start the row_id count at for the current page.
1058 1058
             $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1059 1059
 
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
                 // Update the questions when re-ordering
1063 1063
                 $updated = EEM_Question_Group::instance()->update(
1064 1064
                     array('QSG_order' => $qsgcount),
1065
-                    array(array('QSG_ID' => $row_ids[ $i ]))
1065
+                    array(array('QSG_ID' => $row_ids[$i]))
1066 1066
                 );
1067 1067
                 if ($updated === false) {
1068 1068
                     $success = false;
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
         $this->_set_add_edit_form_tags('update_reg_form_settings');
1114 1114
         $this->_set_publish_post_box_vars(null, false, false, null, false);
1115 1115
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1116
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1116
+            REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php',
1117 1117
             $this->_template_args,
1118 1118
             true
1119 1119
         );
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
                                 $prev_email_validation_level = 'basic';
1360 1360
                             }
1361 1361
                             // confirm our i18n email validation will work on the server
1362
-                            if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1362
+                            if ( ! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1363 1363
                                 // or reset email validation level to previous value
1364 1364
                                 $email_validation_level = $prev_email_validation_level;
1365 1365
                             }
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
     private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1406 1406
     {
1407 1407
         // first check that PCRE is enabled
1408
-        if (! defined('PREG_BAD_UTF8_ERROR')) {
1408
+        if ( ! defined('PREG_BAD_UTF8_ERROR')) {
1409 1409
             EE_Error::add_error(
1410 1410
                 sprintf(
1411 1411
                     esc_html__(
Please login to merge, or discard this patch.
modules/ticket_selector/TicketDetails.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -19,193 +19,193 @@
 block discarded – undo
19 19
  */
20 20
 class TicketDetails
21 21
 {
22
-    /**
23
-     * @var EE_Ticket $ticket
24
-     */
25
-    protected $ticket;
26
-
27
-    /**
28
-     * @var EE_Ticket_Selector_Config $template_settings
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var string $date_format
34
-     */
35
-    protected $date_format;
36
-
37
-    /**
38
-     * @var string $time_format
39
-     */
40
-    protected $time_format;
41
-
42
-    /**
43
-     * @var bool $event_is_expired
44
-     */
45
-    protected $event_is_expired;
46
-
47
-
48
-    /**
49
-     * TicketDetails constructor.
50
-     *
51
-     * @param EE_Ticket                 $ticket
52
-     * @param EE_Ticket_Selector_Config $template_settings
53
-     * @param array                     $template_args
54
-     */
55
-    public function __construct(
56
-        EE_Ticket $ticket,
57
-        EE_Ticket_Selector_Config $template_settings,
58
-        array $template_args
59
-    ) {
60
-        $this->ticket            = $ticket;
61
-        $this->template_settings = $template_settings;
62
-        $this->date_format       = $template_args['date_format'];
63
-        $this->time_format       = $template_args['time_format'];
64
-        $this->event_is_expired  = $template_args['event_is_expired'];
65
-    }
66
-
67
-
68
-    /**
69
-     * @return EE_Ticket
70
-     */
71
-    public function getTicket(): EE_Ticket
72
-    {
73
-        return $this->ticket;
74
-    }
75
-
76
-
77
-    /**
78
-     * @return bool
79
-     */
80
-    public function showTicketDetails(): bool
81
-    {
82
-        return $this->template_settings->show_ticket_details;
83
-    }
84
-
85
-
86
-    /**
87
-     * @return EE_Ticket_Selector_Config
88
-     */
89
-    public function getTemplateSettings(): EE_Ticket_Selector_Config
90
-    {
91
-        return $this->template_settings;
92
-    }
93
-
94
-
95
-    /**
96
-     * @return string
97
-     */
98
-    public function getDateFormat(): string
99
-    {
100
-        return $this->date_format;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return string
106
-     */
107
-    public function getTimeFormat(): string
108
-    {
109
-        return $this->time_format;
110
-    }
111
-
112
-
113
-    /**
114
-     * @return string
115
-     * @throws EE_Error
116
-     * @throws ReflectionException
117
-     */
118
-    public function getShowHideLinks(): string
119
-    {
120
-        if (! $this->showTicketDetails()) {
121
-            return '';
122
-        }
123
-        return EEH_HTML::link(
124
-                '',
125
-                sprintf(esc_html__('show%1$sdetails%1$s+', 'event_espresso'), '&nbsp;'),
126
-                esc_attr(
127
-                    apply_filters(
128
-                        'FHEE__ticket_selector_chart_template__show_ticket_details_link_title',
129
-                        esc_html__('click to show additional ticket details', 'event_espresso')
130
-                    )
131
-                ),
132
-                "display-{$this->cssId()}",
133
-                'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
134
-                '',
135
-                'rel="' . $this->cssId() . '"'
136
-            ) . EEH_HTML::link(
137
-                '',
138
-                sprintf(esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
139
-                esc_attr(
140
-                    apply_filters(
141
-                        'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title',
142
-                        esc_html__('click to hide additional ticket details', 'event_espresso')
143
-                    )
144
-                ),
145
-                "hide-{$this->cssId()}",
146
-                'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
147
-                'display:none;',
148
-                'rel="' . $this->cssId() . '"'
149
-            );
150
-    }
151
-
152
-
153
-    /**
154
-     * @return string
155
-     * @throws EE_Error
156
-     * @throws ReflectionException
157
-     */
158
-    public function cssId(): string
159
-    {
160
-        return apply_filters(
161
-            'FHEE__ticket_selector_chart_template__ticket_details_css_id',
162
-            "tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}"
163
-        );
164
-    }
165
-
166
-
167
-    /**
168
-     * @param float|string $ticket_price
169
-     * @param int|string   $remaining
170
-     * @param int|string   $cols
171
-     * @return string
172
-     * @throws EE_Error
173
-     * @throws ReflectionException
174
-     */
175
-    public function display(
176
-        $ticket_price = 0.00,
177
-        $remaining = EE_INF,
178
-        $cols = 2
179
-    ): string {
180
-        $template_args                             = [];
181
-        $template_args['ticket']                   = $this->ticket;
182
-        $template_args['ticket_price']             = $ticket_price;
183
-        $template_args['remaining']                = $remaining;
184
-        $template_args['cols']                     = $cols;
185
-        $template_args['show_ticket_details']      = $this->template_settings->show_ticket_details;
186
-        $template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns;
187
-        $template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details');
188
-        $template_args['ticket_details_css_id']    = $this->cssId();
189
-        $template_args['display_ticket_price']     = $ticket_price !== 0
190
-                                                     && apply_filters(
191
-                                                         'FHEE__ticket_selector_chart_template__display_ticket_price_details',
192
-                                                         true
193
-                                                     );
194
-        $template_args['price_breakdown_heading']  = apply_filters(
195
-            'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
196
-            esc_html__('Price', 'event_espresso')
197
-        );
198
-        $template_args['date_format']              = $this->date_format;
199
-        $template_args['time_format']              = $this->time_format;
200
-        $template_args['event_is_expired']         = $this->event_is_expired;
201
-
202
-        return EEH_Template::locate_template(
203
-            apply_filters(
204
-                'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
205
-                TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
206
-                $this->ticket
207
-            ),
208
-            $template_args
209
-        );
210
-    }
22
+	/**
23
+	 * @var EE_Ticket $ticket
24
+	 */
25
+	protected $ticket;
26
+
27
+	/**
28
+	 * @var EE_Ticket_Selector_Config $template_settings
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var string $date_format
34
+	 */
35
+	protected $date_format;
36
+
37
+	/**
38
+	 * @var string $time_format
39
+	 */
40
+	protected $time_format;
41
+
42
+	/**
43
+	 * @var bool $event_is_expired
44
+	 */
45
+	protected $event_is_expired;
46
+
47
+
48
+	/**
49
+	 * TicketDetails constructor.
50
+	 *
51
+	 * @param EE_Ticket                 $ticket
52
+	 * @param EE_Ticket_Selector_Config $template_settings
53
+	 * @param array                     $template_args
54
+	 */
55
+	public function __construct(
56
+		EE_Ticket $ticket,
57
+		EE_Ticket_Selector_Config $template_settings,
58
+		array $template_args
59
+	) {
60
+		$this->ticket            = $ticket;
61
+		$this->template_settings = $template_settings;
62
+		$this->date_format       = $template_args['date_format'];
63
+		$this->time_format       = $template_args['time_format'];
64
+		$this->event_is_expired  = $template_args['event_is_expired'];
65
+	}
66
+
67
+
68
+	/**
69
+	 * @return EE_Ticket
70
+	 */
71
+	public function getTicket(): EE_Ticket
72
+	{
73
+		return $this->ticket;
74
+	}
75
+
76
+
77
+	/**
78
+	 * @return bool
79
+	 */
80
+	public function showTicketDetails(): bool
81
+	{
82
+		return $this->template_settings->show_ticket_details;
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return EE_Ticket_Selector_Config
88
+	 */
89
+	public function getTemplateSettings(): EE_Ticket_Selector_Config
90
+	{
91
+		return $this->template_settings;
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return string
97
+	 */
98
+	public function getDateFormat(): string
99
+	{
100
+		return $this->date_format;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return string
106
+	 */
107
+	public function getTimeFormat(): string
108
+	{
109
+		return $this->time_format;
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return string
115
+	 * @throws EE_Error
116
+	 * @throws ReflectionException
117
+	 */
118
+	public function getShowHideLinks(): string
119
+	{
120
+		if (! $this->showTicketDetails()) {
121
+			return '';
122
+		}
123
+		return EEH_HTML::link(
124
+				'',
125
+				sprintf(esc_html__('show%1$sdetails%1$s+', 'event_espresso'), '&nbsp;'),
126
+				esc_attr(
127
+					apply_filters(
128
+						'FHEE__ticket_selector_chart_template__show_ticket_details_link_title',
129
+						esc_html__('click to show additional ticket details', 'event_espresso')
130
+					)
131
+				),
132
+				"display-{$this->cssId()}",
133
+				'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
134
+				'',
135
+				'rel="' . $this->cssId() . '"'
136
+			) . EEH_HTML::link(
137
+				'',
138
+				sprintf(esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
139
+				esc_attr(
140
+					apply_filters(
141
+						'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title',
142
+						esc_html__('click to hide additional ticket details', 'event_espresso')
143
+					)
144
+				),
145
+				"hide-{$this->cssId()}",
146
+				'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
147
+				'display:none;',
148
+				'rel="' . $this->cssId() . '"'
149
+			);
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return string
155
+	 * @throws EE_Error
156
+	 * @throws ReflectionException
157
+	 */
158
+	public function cssId(): string
159
+	{
160
+		return apply_filters(
161
+			'FHEE__ticket_selector_chart_template__ticket_details_css_id',
162
+			"tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}"
163
+		);
164
+	}
165
+
166
+
167
+	/**
168
+	 * @param float|string $ticket_price
169
+	 * @param int|string   $remaining
170
+	 * @param int|string   $cols
171
+	 * @return string
172
+	 * @throws EE_Error
173
+	 * @throws ReflectionException
174
+	 */
175
+	public function display(
176
+		$ticket_price = 0.00,
177
+		$remaining = EE_INF,
178
+		$cols = 2
179
+	): string {
180
+		$template_args                             = [];
181
+		$template_args['ticket']                   = $this->ticket;
182
+		$template_args['ticket_price']             = $ticket_price;
183
+		$template_args['remaining']                = $remaining;
184
+		$template_args['cols']                     = $cols;
185
+		$template_args['show_ticket_details']      = $this->template_settings->show_ticket_details;
186
+		$template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns;
187
+		$template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details');
188
+		$template_args['ticket_details_css_id']    = $this->cssId();
189
+		$template_args['display_ticket_price']     = $ticket_price !== 0
190
+													 && apply_filters(
191
+														 'FHEE__ticket_selector_chart_template__display_ticket_price_details',
192
+														 true
193
+													 );
194
+		$template_args['price_breakdown_heading']  = apply_filters(
195
+			'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
196
+			esc_html__('Price', 'event_espresso')
197
+		);
198
+		$template_args['date_format']              = $this->date_format;
199
+		$template_args['time_format']              = $this->time_format;
200
+		$template_args['event_is_expired']         = $this->event_is_expired;
201
+
202
+		return EEH_Template::locate_template(
203
+			apply_filters(
204
+				'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
205
+				TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
206
+				$this->ticket
207
+			),
208
+			$template_args
209
+		);
210
+	}
211 211
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      */
118 118
     public function getShowHideLinks(): string
119 119
     {
120
-        if (! $this->showTicketDetails()) {
120
+        if ( ! $this->showTicketDetails()) {
121 121
             return '';
122 122
         }
123 123
         return EEH_HTML::link(
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
                 "display-{$this->cssId()}",
133 133
                 'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
134 134
                 '',
135
-                'rel="' . $this->cssId() . '"'
136
-            ) . EEH_HTML::link(
135
+                'rel="'.$this->cssId().'"'
136
+            ).EEH_HTML::link(
137 137
                 '',
138 138
                 sprintf(esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
139 139
                 esc_attr(
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                 "hide-{$this->cssId()}",
146 146
                 'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
147 147
                 'display:none;',
148
-                'rel="' . $this->cssId() . '"'
148
+                'rel="'.$this->cssId().'"'
149 149
             );
150 150
     }
151 151
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                                                          'FHEE__ticket_selector_chart_template__display_ticket_price_details',
192 192
                                                          true
193 193
                                                      );
194
-        $template_args['price_breakdown_heading']  = apply_filters(
194
+        $template_args['price_breakdown_heading'] = apply_filters(
195 195
             'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
196 196
             esc_html__('Price', 'event_espresso')
197 197
         );
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
         return EEH_Template::locate_template(
203 203
             apply_filters(
204 204
                 'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
205
-                TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
205
+                TICKET_SELECTOR_TEMPLATES_PATH.'ticket_details.template.php',
206 206
                 $this->ticket
207 207
             ),
208 208
             $template_args
Please login to merge, or discard this patch.