Completed
Branch BUG-10569-fix-meta-cap-grants (526031)
by
unknown
23:23 queued 11:51
created
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2687 added lines, -2687 removed lines patch added patch discarded remove patch
@@ -15,2694 +15,2694 @@
 block discarded – undo
15 15
 class Events_Admin_Page extends EE_Admin_Page_CPT
16 16
 {
17 17
 
18
-    /**
19
-     * This will hold the event object for event_details screen.
20
-     *
21
-     * @access protected
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-
44
-    /**
45
-     * @var EE_Event
46
-     */
47
-    protected $_cpt_model_obj = false;
48
-
49
-
50
-    /**
51
-     * Initialize page props for this admin page group.
52
-     */
53
-    protected function _init_page_props()
54
-    {
55
-        $this->page_slug = EVENTS_PG_SLUG;
56
-        $this->page_label = EVENTS_LABEL;
57
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
58
-        $this->_admin_base_path = EVENTS_ADMIN;
59
-        $this->_cpt_model_names = array(
60
-            'create_new' => 'EEM_Event',
61
-            'edit'       => 'EEM_Event',
62
-        );
63
-        $this->_cpt_edit_routes = array(
64
-            'espresso_events' => 'edit',
65
-        );
66
-        add_action(
67
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
-            array($this, 'verify_event_edit'), 10, 2
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * Sets the ajax hooks used for this admin page group.
75
-     */
76
-    protected function _ajax_hooks()
77
-    {
78
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets the page properties for this admin page group.
84
-     */
85
-    protected function _define_page_props()
86
-    {
87
-        $this->_admin_page_title = EVENTS_LABEL;
88
-        $this->_labels = array(
89
-            'buttons'      => array(
90
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
91
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
92
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
93
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
94
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
95
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
96
-            ),
97
-            'editor_title' => array(
98
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
99
-            ),
100
-            'publishbox'   => array(
101
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
102
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
103
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
104
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
105
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
106
-            ),
107
-        );
108
-    }
109
-
110
-
111
-    /**
112
-     * Sets the page routes property for this admin page group.
113
-     */
114
-    protected function _set_page_routes()
115
-    {
116
-        //load formatter helper
117
-        //load field generator helper
118
-        //is there a evt_id in the request?
119
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
120
-            ? $this->_req_data['EVT_ID']
121
-            : 0;
122
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
123
-        $this->_page_routes = array(
124
-            'default'                       => array(
125
-                'func'       => '_events_overview_list_table',
126
-                'capability' => 'ee_read_events',
127
-            ),
128
-            'create_new'                    => array(
129
-                'func'       => '_create_new_cpt_item',
130
-                'capability' => 'ee_edit_events',
131
-            ),
132
-            'edit'                          => array(
133
-                'func'       => '_edit_cpt_item',
134
-                'capability' => 'ee_edit_event',
135
-                'obj_id'     => $evt_id,
136
-            ),
137
-            'copy_event'                    => array(
138
-                'func'       => '_copy_events',
139
-                'capability' => 'ee_edit_event',
140
-                'obj_id'     => $evt_id,
141
-                'noheader'   => true,
142
-            ),
143
-            'trash_event'                   => array(
144
-                'func'       => '_trash_or_restore_event',
145
-                'args'       => array('event_status' => 'trash'),
146
-                'capability' => 'ee_delete_event',
147
-                'obj_id'     => $evt_id,
148
-                'noheader'   => true,
149
-            ),
150
-            'trash_events'                  => array(
151
-                'func'       => '_trash_or_restore_events',
152
-                'args'       => array('event_status' => 'trash'),
153
-                'capability' => 'ee_delete_events',
154
-                'noheader'   => true,
155
-            ),
156
-            'restore_event'                 => array(
157
-                'func'       => '_trash_or_restore_event',
158
-                'args'       => array('event_status' => 'draft'),
159
-                'capability' => 'ee_delete_event',
160
-                'obj_id'     => $evt_id,
161
-                'noheader'   => true,
162
-            ),
163
-            'restore_events'                => array(
164
-                'func'       => '_trash_or_restore_events',
165
-                'args'       => array('event_status' => 'draft'),
166
-                'capability' => 'ee_delete_events',
167
-                'noheader'   => true,
168
-            ),
169
-            'delete_event'                  => array(
170
-                'func'       => '_delete_event',
171
-                'capability' => 'ee_delete_event',
172
-                'obj_id'     => $evt_id,
173
-                'noheader'   => true,
174
-            ),
175
-            'delete_events'                 => array(
176
-                'func'       => '_delete_events',
177
-                'capability' => 'ee_delete_events',
178
-                'noheader'   => true,
179
-            ),
180
-            'view_report'                   => array(
181
-                'func'      => '_view_report',
182
-                'capablity' => 'ee_edit_events',
183
-            ),
184
-            'default_event_settings'        => array(
185
-                'func'       => '_default_event_settings',
186
-                'capability' => 'manage_options',
187
-            ),
188
-            'update_default_event_settings' => array(
189
-                'func'       => '_update_default_event_settings',
190
-                'capability' => 'manage_options',
191
-                'noheader'   => true,
192
-            ),
193
-            'template_settings'             => array(
194
-                'func'       => '_template_settings',
195
-                'capability' => 'manage_options',
196
-            ),
197
-            //event category tab related
198
-            'add_category'                  => array(
199
-                'func'       => '_category_details',
200
-                'capability' => 'ee_edit_event_category',
201
-                'args'       => array('add'),
202
-            ),
203
-            'edit_category'                 => array(
204
-                'func'       => '_category_details',
205
-                'capability' => 'ee_edit_event_category',
206
-                'args'       => array('edit'),
207
-            ),
208
-            'delete_categories'             => array(
209
-                'func'       => '_delete_categories',
210
-                'capability' => 'ee_delete_event_category',
211
-                'noheader'   => true,
212
-            ),
213
-            'delete_category'               => array(
214
-                'func'       => '_delete_categories',
215
-                'capability' => 'ee_delete_event_category',
216
-                'noheader'   => true,
217
-            ),
218
-            'insert_category'               => array(
219
-                'func'       => '_insert_or_update_category',
220
-                'args'       => array('new_category' => true),
221
-                'capability' => 'ee_edit_event_category',
222
-                'noheader'   => true,
223
-            ),
224
-            'update_category'               => array(
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => array('new_category' => false),
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ),
230
-            'category_list'                 => array(
231
-                'func'       => '_category_list_table',
232
-                'capability' => 'ee_manage_event_categories',
233
-            ),
234
-        );
235
-    }
236
-
237
-
238
-    /**
239
-     * Set the _page_config property for this admin page group.
240
-     */
241
-    protected function _set_page_config()
242
-    {
243
-        $this->_page_config = array(
244
-            'default'                => array(
245
-                'nav'           => array(
246
-                    'label' => esc_html__('Overview', 'event_espresso'),
247
-                    'order' => 10,
248
-                ),
249
-                'list_table'    => 'Events_Admin_List_Table',
250
-                'help_tabs'     => array(
251
-                    'events_overview_help_tab'                       => array(
252
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
253
-                        'filename' => 'events_overview',
254
-                    ),
255
-                    'events_overview_table_column_headings_help_tab' => array(
256
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
257
-                        'filename' => 'events_overview_table_column_headings',
258
-                    ),
259
-                    'events_overview_filters_help_tab'               => array(
260
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
261
-                        'filename' => 'events_overview_filters',
262
-                    ),
263
-                    'events_overview_view_help_tab'                  => array(
264
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
265
-                        'filename' => 'events_overview_views',
266
-                    ),
267
-                    'events_overview_other_help_tab'                 => array(
268
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
269
-                        'filename' => 'events_overview_other',
270
-                    ),
271
-                ),
272
-                'help_tour'     => array(
273
-                    'Event_Overview_Help_Tour',
274
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
275
-                ),
276
-                'qtips'         => array(
277
-                    'EE_Event_List_Table_Tips',
278
-                ),
279
-                'require_nonce' => false,
280
-            ),
281
-            'create_new'             => array(
282
-                'nav'           => array(
283
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
284
-                    'order'      => 5,
285
-                    'persistent' => false,
286
-                ),
287
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
288
-                'help_tabs'     => array(
289
-                    'event_editor_help_tab'                            => array(
290
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
291
-                        'filename' => 'event_editor',
292
-                    ),
293
-                    'event_editor_title_richtexteditor_help_tab'       => array(
294
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
295
-                        'filename' => 'event_editor_title_richtexteditor',
296
-                    ),
297
-                    'event_editor_venue_details_help_tab'              => array(
298
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
299
-                        'filename' => 'event_editor_venue_details',
300
-                    ),
301
-                    'event_editor_event_datetimes_help_tab'            => array(
302
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
303
-                        'filename' => 'event_editor_event_datetimes',
304
-                    ),
305
-                    'event_editor_event_tickets_help_tab'              => array(
306
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
307
-                        'filename' => 'event_editor_event_tickets',
308
-                    ),
309
-                    'event_editor_event_registration_options_help_tab' => array(
310
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
311
-                        'filename' => 'event_editor_event_registration_options',
312
-                    ),
313
-                    'event_editor_tags_categories_help_tab'            => array(
314
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
315
-                        'filename' => 'event_editor_tags_categories',
316
-                    ),
317
-                    'event_editor_questions_registrants_help_tab'      => array(
318
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
319
-                        'filename' => 'event_editor_questions_registrants',
320
-                    ),
321
-                    'event_editor_save_new_event_help_tab'             => array(
322
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
323
-                        'filename' => 'event_editor_save_new_event',
324
-                    ),
325
-                    'event_editor_other_help_tab'                      => array(
326
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
327
-                        'filename' => 'event_editor_other',
328
-                    ),
329
-                ),
330
-                'help_tour'     => array(
331
-                    'Event_Editor_Help_Tour',
332
-                ),
333
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
334
-                'require_nonce' => false,
335
-            ),
336
-            'edit'                   => array(
337
-                'nav'           => array(
338
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
339
-                    'order'      => 5,
340
-                    'persistent' => false,
341
-                    'url'        => isset($this->_req_data['post'])
342
-                        ? EE_Admin_Page::add_query_args_and_nonce(
343
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
344
-                            $this->_current_page_view_url
345
-                        )
346
-                        : $this->_admin_base_url,
347
-                ),
348
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
349
-                'help_tabs'     => array(
350
-                    'event_editor_help_tab'                            => array(
351
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
352
-                        'filename' => 'event_editor',
353
-                    ),
354
-                    'event_editor_title_richtexteditor_help_tab'       => array(
355
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
356
-                        'filename' => 'event_editor_title_richtexteditor',
357
-                    ),
358
-                    'event_editor_venue_details_help_tab'              => array(
359
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
360
-                        'filename' => 'event_editor_venue_details',
361
-                    ),
362
-                    'event_editor_event_datetimes_help_tab'            => array(
363
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
364
-                        'filename' => 'event_editor_event_datetimes',
365
-                    ),
366
-                    'event_editor_event_tickets_help_tab'              => array(
367
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
368
-                        'filename' => 'event_editor_event_tickets',
369
-                    ),
370
-                    'event_editor_event_registration_options_help_tab' => array(
371
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
372
-                        'filename' => 'event_editor_event_registration_options',
373
-                    ),
374
-                    'event_editor_tags_categories_help_tab'            => array(
375
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
376
-                        'filename' => 'event_editor_tags_categories',
377
-                    ),
378
-                    'event_editor_questions_registrants_help_tab'      => array(
379
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
380
-                        'filename' => 'event_editor_questions_registrants',
381
-                    ),
382
-                    'event_editor_save_new_event_help_tab'             => array(
383
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
384
-                        'filename' => 'event_editor_save_new_event',
385
-                    ),
386
-                    'event_editor_other_help_tab'                      => array(
387
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
388
-                        'filename' => 'event_editor_other',
389
-                    ),
390
-                ),
391
-                /*'help_tour' => array(
18
+	/**
19
+	 * This will hold the event object for event_details screen.
20
+	 *
21
+	 * @access protected
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+
44
+	/**
45
+	 * @var EE_Event
46
+	 */
47
+	protected $_cpt_model_obj = false;
48
+
49
+
50
+	/**
51
+	 * Initialize page props for this admin page group.
52
+	 */
53
+	protected function _init_page_props()
54
+	{
55
+		$this->page_slug = EVENTS_PG_SLUG;
56
+		$this->page_label = EVENTS_LABEL;
57
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
58
+		$this->_admin_base_path = EVENTS_ADMIN;
59
+		$this->_cpt_model_names = array(
60
+			'create_new' => 'EEM_Event',
61
+			'edit'       => 'EEM_Event',
62
+		);
63
+		$this->_cpt_edit_routes = array(
64
+			'espresso_events' => 'edit',
65
+		);
66
+		add_action(
67
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
+			array($this, 'verify_event_edit'), 10, 2
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * Sets the ajax hooks used for this admin page group.
75
+	 */
76
+	protected function _ajax_hooks()
77
+	{
78
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets the page properties for this admin page group.
84
+	 */
85
+	protected function _define_page_props()
86
+	{
87
+		$this->_admin_page_title = EVENTS_LABEL;
88
+		$this->_labels = array(
89
+			'buttons'      => array(
90
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
91
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
92
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
93
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
94
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
95
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
96
+			),
97
+			'editor_title' => array(
98
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
99
+			),
100
+			'publishbox'   => array(
101
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
102
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
103
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
104
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
105
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
106
+			),
107
+		);
108
+	}
109
+
110
+
111
+	/**
112
+	 * Sets the page routes property for this admin page group.
113
+	 */
114
+	protected function _set_page_routes()
115
+	{
116
+		//load formatter helper
117
+		//load field generator helper
118
+		//is there a evt_id in the request?
119
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
120
+			? $this->_req_data['EVT_ID']
121
+			: 0;
122
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
123
+		$this->_page_routes = array(
124
+			'default'                       => array(
125
+				'func'       => '_events_overview_list_table',
126
+				'capability' => 'ee_read_events',
127
+			),
128
+			'create_new'                    => array(
129
+				'func'       => '_create_new_cpt_item',
130
+				'capability' => 'ee_edit_events',
131
+			),
132
+			'edit'                          => array(
133
+				'func'       => '_edit_cpt_item',
134
+				'capability' => 'ee_edit_event',
135
+				'obj_id'     => $evt_id,
136
+			),
137
+			'copy_event'                    => array(
138
+				'func'       => '_copy_events',
139
+				'capability' => 'ee_edit_event',
140
+				'obj_id'     => $evt_id,
141
+				'noheader'   => true,
142
+			),
143
+			'trash_event'                   => array(
144
+				'func'       => '_trash_or_restore_event',
145
+				'args'       => array('event_status' => 'trash'),
146
+				'capability' => 'ee_delete_event',
147
+				'obj_id'     => $evt_id,
148
+				'noheader'   => true,
149
+			),
150
+			'trash_events'                  => array(
151
+				'func'       => '_trash_or_restore_events',
152
+				'args'       => array('event_status' => 'trash'),
153
+				'capability' => 'ee_delete_events',
154
+				'noheader'   => true,
155
+			),
156
+			'restore_event'                 => array(
157
+				'func'       => '_trash_or_restore_event',
158
+				'args'       => array('event_status' => 'draft'),
159
+				'capability' => 'ee_delete_event',
160
+				'obj_id'     => $evt_id,
161
+				'noheader'   => true,
162
+			),
163
+			'restore_events'                => array(
164
+				'func'       => '_trash_or_restore_events',
165
+				'args'       => array('event_status' => 'draft'),
166
+				'capability' => 'ee_delete_events',
167
+				'noheader'   => true,
168
+			),
169
+			'delete_event'                  => array(
170
+				'func'       => '_delete_event',
171
+				'capability' => 'ee_delete_event',
172
+				'obj_id'     => $evt_id,
173
+				'noheader'   => true,
174
+			),
175
+			'delete_events'                 => array(
176
+				'func'       => '_delete_events',
177
+				'capability' => 'ee_delete_events',
178
+				'noheader'   => true,
179
+			),
180
+			'view_report'                   => array(
181
+				'func'      => '_view_report',
182
+				'capablity' => 'ee_edit_events',
183
+			),
184
+			'default_event_settings'        => array(
185
+				'func'       => '_default_event_settings',
186
+				'capability' => 'manage_options',
187
+			),
188
+			'update_default_event_settings' => array(
189
+				'func'       => '_update_default_event_settings',
190
+				'capability' => 'manage_options',
191
+				'noheader'   => true,
192
+			),
193
+			'template_settings'             => array(
194
+				'func'       => '_template_settings',
195
+				'capability' => 'manage_options',
196
+			),
197
+			//event category tab related
198
+			'add_category'                  => array(
199
+				'func'       => '_category_details',
200
+				'capability' => 'ee_edit_event_category',
201
+				'args'       => array('add'),
202
+			),
203
+			'edit_category'                 => array(
204
+				'func'       => '_category_details',
205
+				'capability' => 'ee_edit_event_category',
206
+				'args'       => array('edit'),
207
+			),
208
+			'delete_categories'             => array(
209
+				'func'       => '_delete_categories',
210
+				'capability' => 'ee_delete_event_category',
211
+				'noheader'   => true,
212
+			),
213
+			'delete_category'               => array(
214
+				'func'       => '_delete_categories',
215
+				'capability' => 'ee_delete_event_category',
216
+				'noheader'   => true,
217
+			),
218
+			'insert_category'               => array(
219
+				'func'       => '_insert_or_update_category',
220
+				'args'       => array('new_category' => true),
221
+				'capability' => 'ee_edit_event_category',
222
+				'noheader'   => true,
223
+			),
224
+			'update_category'               => array(
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => array('new_category' => false),
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			),
230
+			'category_list'                 => array(
231
+				'func'       => '_category_list_table',
232
+				'capability' => 'ee_manage_event_categories',
233
+			),
234
+		);
235
+	}
236
+
237
+
238
+	/**
239
+	 * Set the _page_config property for this admin page group.
240
+	 */
241
+	protected function _set_page_config()
242
+	{
243
+		$this->_page_config = array(
244
+			'default'                => array(
245
+				'nav'           => array(
246
+					'label' => esc_html__('Overview', 'event_espresso'),
247
+					'order' => 10,
248
+				),
249
+				'list_table'    => 'Events_Admin_List_Table',
250
+				'help_tabs'     => array(
251
+					'events_overview_help_tab'                       => array(
252
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
253
+						'filename' => 'events_overview',
254
+					),
255
+					'events_overview_table_column_headings_help_tab' => array(
256
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
257
+						'filename' => 'events_overview_table_column_headings',
258
+					),
259
+					'events_overview_filters_help_tab'               => array(
260
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
261
+						'filename' => 'events_overview_filters',
262
+					),
263
+					'events_overview_view_help_tab'                  => array(
264
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
265
+						'filename' => 'events_overview_views',
266
+					),
267
+					'events_overview_other_help_tab'                 => array(
268
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
269
+						'filename' => 'events_overview_other',
270
+					),
271
+				),
272
+				'help_tour'     => array(
273
+					'Event_Overview_Help_Tour',
274
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
275
+				),
276
+				'qtips'         => array(
277
+					'EE_Event_List_Table_Tips',
278
+				),
279
+				'require_nonce' => false,
280
+			),
281
+			'create_new'             => array(
282
+				'nav'           => array(
283
+					'label'      => esc_html__('Add Event', 'event_espresso'),
284
+					'order'      => 5,
285
+					'persistent' => false,
286
+				),
287
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
288
+				'help_tabs'     => array(
289
+					'event_editor_help_tab'                            => array(
290
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
291
+						'filename' => 'event_editor',
292
+					),
293
+					'event_editor_title_richtexteditor_help_tab'       => array(
294
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
295
+						'filename' => 'event_editor_title_richtexteditor',
296
+					),
297
+					'event_editor_venue_details_help_tab'              => array(
298
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
299
+						'filename' => 'event_editor_venue_details',
300
+					),
301
+					'event_editor_event_datetimes_help_tab'            => array(
302
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
303
+						'filename' => 'event_editor_event_datetimes',
304
+					),
305
+					'event_editor_event_tickets_help_tab'              => array(
306
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
307
+						'filename' => 'event_editor_event_tickets',
308
+					),
309
+					'event_editor_event_registration_options_help_tab' => array(
310
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
311
+						'filename' => 'event_editor_event_registration_options',
312
+					),
313
+					'event_editor_tags_categories_help_tab'            => array(
314
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
315
+						'filename' => 'event_editor_tags_categories',
316
+					),
317
+					'event_editor_questions_registrants_help_tab'      => array(
318
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
319
+						'filename' => 'event_editor_questions_registrants',
320
+					),
321
+					'event_editor_save_new_event_help_tab'             => array(
322
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
323
+						'filename' => 'event_editor_save_new_event',
324
+					),
325
+					'event_editor_other_help_tab'                      => array(
326
+						'title'    => esc_html__('Event Other', 'event_espresso'),
327
+						'filename' => 'event_editor_other',
328
+					),
329
+				),
330
+				'help_tour'     => array(
331
+					'Event_Editor_Help_Tour',
332
+				),
333
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
334
+				'require_nonce' => false,
335
+			),
336
+			'edit'                   => array(
337
+				'nav'           => array(
338
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
339
+					'order'      => 5,
340
+					'persistent' => false,
341
+					'url'        => isset($this->_req_data['post'])
342
+						? EE_Admin_Page::add_query_args_and_nonce(
343
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
344
+							$this->_current_page_view_url
345
+						)
346
+						: $this->_admin_base_url,
347
+				),
348
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
349
+				'help_tabs'     => array(
350
+					'event_editor_help_tab'                            => array(
351
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
352
+						'filename' => 'event_editor',
353
+					),
354
+					'event_editor_title_richtexteditor_help_tab'       => array(
355
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
356
+						'filename' => 'event_editor_title_richtexteditor',
357
+					),
358
+					'event_editor_venue_details_help_tab'              => array(
359
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
360
+						'filename' => 'event_editor_venue_details',
361
+					),
362
+					'event_editor_event_datetimes_help_tab'            => array(
363
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
364
+						'filename' => 'event_editor_event_datetimes',
365
+					),
366
+					'event_editor_event_tickets_help_tab'              => array(
367
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
368
+						'filename' => 'event_editor_event_tickets',
369
+					),
370
+					'event_editor_event_registration_options_help_tab' => array(
371
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
372
+						'filename' => 'event_editor_event_registration_options',
373
+					),
374
+					'event_editor_tags_categories_help_tab'            => array(
375
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
376
+						'filename' => 'event_editor_tags_categories',
377
+					),
378
+					'event_editor_questions_registrants_help_tab'      => array(
379
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
380
+						'filename' => 'event_editor_questions_registrants',
381
+					),
382
+					'event_editor_save_new_event_help_tab'             => array(
383
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
384
+						'filename' => 'event_editor_save_new_event',
385
+					),
386
+					'event_editor_other_help_tab'                      => array(
387
+						'title'    => esc_html__('Event Other', 'event_espresso'),
388
+						'filename' => 'event_editor_other',
389
+					),
390
+				),
391
+				/*'help_tour' => array(
392 392
 					'Event_Edit_Help_Tour'
393 393
 				),*/
394
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
395
-                'require_nonce' => false,
396
-            ),
397
-            'default_event_settings' => array(
398
-                'nav'           => array(
399
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
400
-                    'order' => 40,
401
-                ),
402
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
403
-                'labels'        => array(
404
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
405
-                ),
406
-                'help_tabs'     => array(
407
-                    'default_settings_help_tab'        => array(
408
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
409
-                        'filename' => 'events_default_settings',
410
-                    ),
411
-                    'default_settings_status_help_tab' => array(
412
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
413
-                        'filename' => 'events_default_settings_status',
414
-                    ),
415
-                    'default_maximum_tickets_help_tab' => array(
416
-                        'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
417
-                        'filename' => 'events_default_settings_max_tickets',
418
-                    )
419
-                ),
420
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
421
-                'require_nonce' => false,
422
-            ),
423
-            //template settings
424
-            'template_settings'      => array(
425
-                'nav'           => array(
426
-                    'label' => esc_html__('Templates', 'event_espresso'),
427
-                    'order' => 30,
428
-                ),
429
-                'metaboxes'     => $this->_default_espresso_metaboxes,
430
-                'help_tabs'     => array(
431
-                    'general_settings_templates_help_tab' => array(
432
-                        'title'    => esc_html__('Templates', 'event_espresso'),
433
-                        'filename' => 'general_settings_templates',
434
-                    ),
435
-                ),
436
-                'help_tour'     => array('Templates_Help_Tour'),
437
-                'require_nonce' => false,
438
-            ),
439
-            //event category stuff
440
-            'add_category'           => array(
441
-                'nav'           => array(
442
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
443
-                    'order'      => 15,
444
-                    'persistent' => false,
445
-                ),
446
-                'help_tabs'     => array(
447
-                    'add_category_help_tab' => array(
448
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
449
-                        'filename' => 'events_add_category',
450
-                    ),
451
-                ),
452
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
453
-                'metaboxes'     => array('_publish_post_box'),
454
-                'require_nonce' => false,
455
-            ),
456
-            'edit_category'          => array(
457
-                'nav'           => array(
458
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
459
-                    'order'      => 15,
460
-                    'persistent' => false,
461
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
462
-                        ? add_query_arg(
463
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
464
-                            $this->_current_page_view_url
465
-                        )
466
-                        : $this->_admin_base_url,
467
-                ),
468
-                'help_tabs'     => array(
469
-                    'edit_category_help_tab' => array(
470
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
-                        'filename' => 'events_edit_category',
472
-                    ),
473
-                ),
474
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
475
-                'metaboxes'     => array('_publish_post_box'),
476
-                'require_nonce' => false,
477
-            ),
478
-            'category_list'          => array(
479
-                'nav'           => array(
480
-                    'label' => esc_html__('Categories', 'event_espresso'),
481
-                    'order' => 20,
482
-                ),
483
-                'list_table'    => 'Event_Categories_Admin_List_Table',
484
-                'help_tabs'     => array(
485
-                    'events_categories_help_tab'                       => array(
486
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
487
-                        'filename' => 'events_categories',
488
-                    ),
489
-                    'events_categories_table_column_headings_help_tab' => array(
490
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
491
-                        'filename' => 'events_categories_table_column_headings',
492
-                    ),
493
-                    'events_categories_view_help_tab'                  => array(
494
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
495
-                        'filename' => 'events_categories_views',
496
-                    ),
497
-                    'events_categories_other_help_tab'                 => array(
498
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
499
-                        'filename' => 'events_categories_other',
500
-                    ),
501
-                ),
502
-                'help_tour'     => array(
503
-                    'Event_Categories_Help_Tour',
504
-                ),
505
-                'metaboxes'     => $this->_default_espresso_metaboxes,
506
-                'require_nonce' => false,
507
-            ),
508
-        );
509
-    }
510
-
511
-
512
-    /**
513
-     * Used to register any global screen options if necessary for every route in this admin page group.
514
-     */
515
-    protected function _add_screen_options()
516
-    {
517
-    }
518
-
519
-
520
-    /**
521
-     * Implementing the screen options for the 'default' route.
522
-     */
523
-    protected function _add_screen_options_default()
524
-    {
525
-        $this->_per_page_screen_option();
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing screen options for the category list route.
531
-     */
532
-    protected function _add_screen_options_category_list()
533
-    {
534
-        $page_title = $this->_admin_page_title;
535
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
536
-        $this->_per_page_screen_option();
537
-        $this->_admin_page_title = $page_title;
538
-    }
539
-
540
-
541
-    /**
542
-     * Used to register any global feature pointers for the admin page group.
543
-     */
544
-    protected function _add_feature_pointers()
545
-    {
546
-    }
547
-
548
-
549
-    /**
550
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
551
-     */
552
-    public function load_scripts_styles()
553
-    {
554
-        wp_register_style(
555
-            'events-admin-css',
556
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
557
-            array(),
558
-            EVENT_ESPRESSO_VERSION
559
-        );
560
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561
-        wp_enqueue_style('events-admin-css');
562
-        wp_enqueue_style('ee-cat-admin');
563
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
564
-        //registers for all views
565
-        //scripts
566
-        wp_register_script(
567
-            'event_editor_js',
568
-            EVENTS_ASSETS_URL . 'event_editor.js',
569
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570
-            EVENT_ESPRESSO_VERSION,
571
-            true
572
-        );
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * Enqueuing scripts and styles specific to this view
579
-     */
580
-    public function load_scripts_styles_create_new()
581
-    {
582
-        $this->load_scripts_styles_edit();
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     * Enqueuing scripts and styles specific to this view
589
-     */
590
-    public function load_scripts_styles_edit()
591
-    {
592
-        //styles
593
-        wp_enqueue_style('espresso-ui-theme');
594
-        wp_register_style(
595
-            'event-editor-css',
596
-            EVENTS_ASSETS_URL . 'event-editor.css',
597
-            array('ee-admin-css'),
598
-            EVENT_ESPRESSO_VERSION
599
-        );
600
-        wp_enqueue_style('event-editor-css');
601
-        //scripts
602
-        wp_register_script(
603
-            'event-datetime-metabox',
604
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
605
-            array('event_editor_js', 'ee-datepicker'),
606
-            EVENT_ESPRESSO_VERSION
607
-        );
608
-        wp_enqueue_script('event-datetime-metabox');
609
-    }
610
-
611
-
612
-    /**
613
-     * Populating the _views property for the category list table view.
614
-     */
615
-    protected function _set_list_table_views_category_list()
616
-    {
617
-        $this->_views = array(
618
-            'all' => array(
619
-                'slug'        => 'all',
620
-                'label'       => esc_html__('All', 'event_espresso'),
621
-                'count'       => 0,
622
-                'bulk_action' => array(
623
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
624
-                ),
625
-            ),
626
-        );
627
-    }
628
-
629
-
630
-    /**
631
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
632
-     */
633
-    public function admin_init()
634
-    {
635
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
636
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
637
-            'event_espresso'
638
-        );
639
-    }
640
-
641
-
642
-    /**
643
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page group.
644
-     */
645
-    public function admin_notices()
646
-    {
647
-    }
648
-
649
-
650
-    /**
651
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
652
-     * this admin page group.
653
-     */
654
-    public function admin_footer_scripts()
655
-    {
656
-    }
657
-
658
-
659
-
660
-    /**
661
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
662
-     * warning (via EE_Error::add_error());
663
-     *
664
-     * @param  EE_Event $event Event object
665
-     * @param string    $req_type
666
-     * @return void
667
-     * @throws EE_Error
668
-     * @access public
669
-     */
670
-    public function verify_event_edit($event = null, $req_type = '')
671
-    {
672
-        // don't need to do this when processing
673
-        if(!empty($req_type)) {
674
-            return;
675
-        }
676
-        // no event?
677
-        if (empty($event)) {
678
-            // set event
679
-            $event = $this->_cpt_model_obj;
680
-        }
681
-        // STILL no event?
682
-        if (! $event instanceof EE_Event) {
683
-            return;
684
-        }
685
-        $orig_status = $event->status();
686
-        // first check if event is active.
687
-        if (
688
-            $orig_status === EEM_Event::cancelled
689
-            || $orig_status === EEM_Event::postponed
690
-            || $event->is_expired()
691
-            || $event->is_inactive()
692
-        ) {
693
-            return;
694
-        }
695
-        //made it here so it IS active... next check that any of the tickets are sold.
696
-        if ($event->is_sold_out(true)) {
697
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
698
-                EE_Error::add_attention(
699
-                    sprintf(
700
-                        esc_html__(
701
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
702
-                            'event_espresso'
703
-                        ),
704
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
705
-                    )
706
-                );
707
-            }
708
-            return;
709
-        } else if ($orig_status === EEM_Event::sold_out) {
710
-            EE_Error::add_attention(
711
-                sprintf(
712
-                    esc_html__(
713
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
714
-                        'event_espresso'
715
-                    ),
716
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
717
-                )
718
-            );
719
-        }
720
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
721
-        if ( ! $event->tickets_on_sale()) {
722
-            return;
723
-        }
724
-        //made it here so show warning
725
-        $this->_edit_event_warning();
726
-    }
727
-
728
-
729
-
730
-    /**
731
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
732
-     * When needed, hook this into a EE_Error::add_error() notice.
733
-     *
734
-     * @access protected
735
-     * @return void
736
-     */
737
-    protected function _edit_event_warning()
738
-    {
739
-        // we don't want to add warnings during these requests
740
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
741
-            return;
742
-        }
743
-        EE_Error::add_attention(
744
-            esc_html__(
745
-                'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
746
-                'event_espresso'
747
-            )
748
-        );
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * When a user is creating a new event, notify them if they haven't set their timezone.
755
-     * Otherwise, do the normal logic
756
-     *
757
-     * @return string
758
-     * @throws \EE_Error
759
-     */
760
-    protected function _create_new_cpt_item()
761
-    {
762
-        $has_timezone_string = get_option('timezone_string');
763
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
764
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
765
-            EE_Error::add_attention(
766
-                sprintf(
767
-                    __(
768
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
769
-                        'event_espresso'
770
-                    ),
771
-                    '<br>',
772
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
773
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
774
-                    . '</select>',
775
-                    '<button class="button button-secondary timezone-submit">',
776
-                    '</button><span class="spinner"></span>'
777
-                ),
778
-                __FILE__,
779
-                __FUNCTION__,
780
-                __LINE__
781
-            );
782
-        }
783
-        return parent::_create_new_cpt_item();
784
-    }
785
-
786
-
787
-    /**
788
-     * Sets the _views property for the default route in this admin page group.
789
-     */
790
-    protected function _set_list_table_views_default()
791
-    {
792
-        $this->_views = array(
793
-            'all'   => array(
794
-                'slug'        => 'all',
795
-                'label'       => esc_html__('View All Events', 'event_espresso'),
796
-                'count'       => 0,
797
-                'bulk_action' => array(
798
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
799
-                ),
800
-            ),
801
-            'draft' => array(
802
-                'slug'        => 'draft',
803
-                'label'       => esc_html__('Draft', 'event_espresso'),
804
-                'count'       => 0,
805
-                'bulk_action' => array(
806
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
-                ),
808
-            ),
809
-        );
810
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
811
-            $this->_views['trash'] = array(
812
-                'slug'        => 'trash',
813
-                'label'       => esc_html__('Trash', 'event_espresso'),
814
-                'count'       => 0,
815
-                'bulk_action' => array(
816
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
817
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
818
-                ),
819
-            );
820
-        }
821
-    }
822
-
823
-
824
-
825
-    /**
826
-     * Provides the legend item array for the default list table view.
827
-     * @return array
828
-     */
829
-    protected function _event_legend_items()
830
-    {
831
-        $items = array(
832
-            'view_details'   => array(
833
-                'class' => 'dashicons dashicons-search',
834
-                'desc'  => esc_html__('View Event', 'event_espresso'),
835
-            ),
836
-            'edit_event'     => array(
837
-                'class' => 'ee-icon ee-icon-calendar-edit',
838
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
839
-            ),
840
-            'view_attendees' => array(
841
-                'class' => 'dashicons dashicons-groups',
842
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
843
-            ),
844
-        );
845
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
846
-        $statuses = array(
847
-            'sold_out_status'  => array(
848
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
849
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
850
-            ),
851
-            'active_status'    => array(
852
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
853
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
854
-            ),
855
-            'upcoming_status'  => array(
856
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
857
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
858
-            ),
859
-            'postponed_status' => array(
860
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
861
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
862
-            ),
863
-            'cancelled_status' => array(
864
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
865
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
866
-            ),
867
-            'expired_status'   => array(
868
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
869
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
870
-            ),
871
-            'inactive_status'  => array(
872
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
873
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
874
-            ),
875
-        );
876
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
877
-        return array_merge($items, $statuses);
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     * @return EEM_Event
884
-     */
885
-    private function _event_model()
886
-    {
887
-        if ( ! $this->_event_model instanceof EEM_Event) {
888
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
889
-        }
890
-        return $this->_event_model;
891
-    }
892
-
893
-
894
-
895
-    /**
896
-     * Adds extra buttons to the WP CPT permalink field row.
897
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
898
-     *
899
-     * @param  string $return    the current html
900
-     * @param  int    $id        the post id for the page
901
-     * @param  string $new_title What the title is
902
-     * @param  string $new_slug  what the slug is
903
-     * @return string            The new html string for the permalink area
904
-     */
905
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
906
-    {
907
-        //make sure this is only when editing
908
-        if ( ! empty($id)) {
909
-            $post = get_post($id);
910
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
911
-                       . esc_html__('Shortcode', 'event_espresso')
912
-                       . '</a> ';
913
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
914
-                       . $post->ID
915
-                       . ']">';
916
-        }
917
-        return $return;
918
-    }
919
-
920
-
921
-
922
-    /**
923
-     * _events_overview_list_table
924
-     * This contains the logic for showing the events_overview list
925
-     *
926
-     * @access protected
927
-     * @return void
928
-     * @throws \EE_Error
929
-     */
930
-    protected function _events_overview_list_table()
931
-    {
932
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
933
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
934
-            ? (array)$this->_template_args['after_list_table']
935
-            : array();
936
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
937
-                                                                              . EEH_Template::get_button_or_link(
938
-                get_post_type_archive_link('espresso_events'),
939
-                esc_html__("View Event Archive Page", "event_espresso"),
940
-                'button'
941
-            );
942
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
943
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
944
-                'create_new',
945
-                'add',
946
-                array(),
947
-                'add-new-h2'
948
-            );
949
-        $this->display_admin_list_table_page_with_no_sidebar();
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * this allows for extra misc actions in the default WP publish box
956
-     *
957
-     * @return void
958
-     */
959
-    public function extra_misc_actions_publish_box()
960
-    {
961
-        $this->_generate_publish_box_extra_content();
962
-    }
963
-
964
-
965
-
966
-    /**
967
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been saved.
968
-     * Typically you would use this to save any additional data.
969
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
970
-     * ALSO very important.  When a post transitions from scheduled to published,
971
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from other meta saves.
972
-     * So MAKE sure that you handle this accordingly.
973
-     *
974
-     * @access protected
975
-     * @abstract
976
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
977
-     * @param  object $post    The post object of the cpt that was saved.
978
-     * @return void
979
-     * @throws \EE_Error
980
-     */
981
-    protected function _insert_update_cpt_item($post_id, $post)
982
-    {
983
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
984
-            //get out we're not processing an event save.
985
-            return;
986
-        }
987
-        $event_values = array(
988
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
989
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
990
-            'EVT_additional_limit'            => min(
991
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
992
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
993
-            ),
994
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
995
-                ? $this->_req_data['EVT_default_registration_status']
996
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
997
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
998
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
999
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1000
-                ? $this->_req_data['timezone_string'] : null,
1001
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1002
-                ? $this->_req_data['externalURL'] : null,
1003
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1004
-                ? $this->_req_data['event_phone'] : null,
1005
-        );
1006
-        //update event
1007
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1008
-        //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1009
-        $get_one_where = array(
1010
-            $this->_event_model()->primary_key_name() => $post_id,
1011
-            'OR' => array(
1012
-                'status' => $post->post_status,
1013
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1014
-                // but the returned object here has a status of "publish", so use the original post status as well
1015
-                'status*1' => $this->_req_data['original_post_status'],
1016
-            )
1017
-        );
1018
-        $event = $this->_event_model()->get_one(array($get_one_where));
1019
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1020
-        $event_update_callbacks = apply_filters(
1021
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1022
-            array(
1023
-                array($this, '_default_venue_update'),
1024
-                array($this, '_default_tickets_update')
1025
-            )
1026
-        );
1027
-        $att_success = true;
1028
-        foreach ($event_update_callbacks as $e_callback) {
1029
-            $_success = $e_callback($event, $this->_req_data);
1030
-            //if ANY of these updates fail then we want the appropriate global error message
1031
-            $att_success = ! $att_success ? $att_success : $_success;
1032
-        }
1033
-        //any errors?
1034
-        if ($success && false === $att_success) {
1035
-            EE_Error::add_error(
1036
-                esc_html__(
1037
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1038
-                    'event_espresso'
1039
-                ),
1040
-                __FILE__,
1041
-                __FUNCTION__,
1042
-                __LINE__
1043
-            );
1044
-        } else if ($success === false) {
1045
-            EE_Error::add_error(
1046
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1047
-                __FILE__,
1048
-                __FUNCTION__,
1049
-                __LINE__
1050
-            );
1051
-        }
1052
-    }
1053
-
1054
-
1055
-
1056
-    /**
1057
-     * @see parent::restore_item()
1058
-     * @param int $post_id
1059
-     * @param int $revision_id
1060
-     */
1061
-    protected function _restore_cpt_item($post_id, $revision_id)
1062
-    {
1063
-        //copy existing event meta to new post
1064
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1065
-        if ($post_evt instanceof EE_Event) {
1066
-            //meta revision restore
1067
-            $post_evt->restore_revision($revision_id);
1068
-            //related objs restore
1069
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1070
-        }
1071
-    }
1072
-
1073
-
1074
-
1075
-    /**
1076
-     * Attach the venue to the Event
1077
-     *
1078
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1079
-     * @param  array     $data   The request data from the form
1080
-     * @return bool           Success or fail.
1081
-     */
1082
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1083
-    {
1084
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1085
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1086
-        $rows_affected = null;
1087
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1088
-        // very important.  If we don't have a venue name...
1089
-        // then we'll get out because not necessary to create empty venue
1090
-        if (empty($data['venue_title'])) {
1091
-            return false;
1092
-        }
1093
-        $venue_array = array(
1094
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1095
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1096
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1097
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1098
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1099
-                : null,
1100
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1101
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1102
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1103
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1104
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1105
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1106
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1107
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1108
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1109
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1110
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1111
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1112
-            'status'              => 'publish',
1113
-        );
1114
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1115
-        if ( ! empty($venue_id)) {
1116
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1117
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1118
-            //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1119
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1120
-            return $rows_affected > 0 ? true : false;
1121
-        } else {
1122
-            //we insert the venue
1123
-            $venue_id = $venue_model->insert($venue_array);
1124
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1125
-            return ! empty($venue_id) ? true : false;
1126
-        }
1127
-        //when we have the ancestor come in it's already been handled by the revision save.
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1134
-     *
1135
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1136
-     * @param  array    $data   The request data from the form
1137
-     * @return array
1138
-     */
1139
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1140
-    {
1141
-        $success = true;
1142
-        $saved_dtt = null;
1143
-        $saved_tickets = array();
1144
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1145
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1146
-            //trim all values to ensure any excess whitespace is removed.
1147
-            $dtt = array_map('trim', $dtt);
1148
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1149
-                : $dtt['DTT_EVT_start'];
1150
-            $datetime_values = array(
1151
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1152
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1153
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1154
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1155
-                'DTT_order'     => $row,
1156
-            );
1157
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1158
-            if ( ! empty($dtt['DTT_ID'])) {
1159
-                $DTM = EE_Registry::instance()
1160
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1161
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1162
-                $DTM->set_date_format($incoming_date_formats[0]);
1163
-                $DTM->set_time_format($incoming_date_formats[1]);
1164
-                foreach ($datetime_values as $field => $value) {
1165
-                    $DTM->set($field, $value);
1166
-                }
1167
-                //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1168
-                $saved_dtts[$DTM->ID()] = $DTM;
1169
-            } else {
1170
-                $DTM = EE_Registry::instance()->load_class(
1171
-                    'Datetime',
1172
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1173
-                    false,
1174
-                    false
1175
-                );
1176
-                foreach ($datetime_values as $field => $value) {
1177
-                    $DTM->set($field, $value);
1178
-                }
1179
-            }
1180
-            $DTM->save();
1181
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1182
-            //load DTT helper
1183
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1184
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1185
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1186
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1187
-                $DTT->save();
1188
-            }
1189
-            //now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1190
-            $saved_dtt = $DTT;
1191
-            $success = ! $success ? $success : $DTT;
1192
-            //if ANY of these updates fail then we want the appropriate global error message.
1193
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1194
-        }
1195
-        //no dtts get deleted so we don't do any of that logic here.
1196
-        //update tickets next
1197
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1198
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1199
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1200
-            $update_prices = false;
1201
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1202
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1203
-            // trim inputs to ensure any excess whitespace is removed.
1204
-            $tkt = array_map('trim', $tkt);
1205
-            if (empty($tkt['TKT_start_date'])) {
1206
-                //let's use now in the set timezone.
1207
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1208
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1209
-            }
1210
-            if (empty($tkt['TKT_end_date'])) {
1211
-                //use the start date of the first datetime
1212
-                $dtt = $evtobj->first_datetime();
1213
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1214
-                    $incoming_date_formats[0],
1215
-                    $incoming_date_formats[1]
1216
-                );
1217
-            }
1218
-            $TKT_values = array(
1219
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1220
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1221
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1222
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1223
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1224
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1225
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1226
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1227
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1228
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1229
-                'TKT_row'         => $row,
1230
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1231
-                'TKT_price'       => $ticket_price,
1232
-            );
1233
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1234
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1235
-                $TKT_values['TKT_ID'] = 0;
1236
-                $TKT_values['TKT_is_default'] = 0;
1237
-                $TKT_values['TKT_price'] = $ticket_price;
1238
-                $update_prices = true;
1239
-            }
1240
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1241
-            //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1242
-            //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1243
-            if ( ! empty($tkt['TKT_ID'])) {
1244
-                $TKT = EE_Registry::instance()
1245
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1246
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1247
-                if ($TKT instanceof EE_Ticket) {
1248
-                    $ticket_sold = $TKT->count_related(
1249
-                        'Registration',
1250
-                        array(
1251
-                            array(
1252
-                                'STS_ID' => array(
1253
-                                    'NOT IN',
1254
-                                    array(EEM_Registration::status_id_incomplete),
1255
-                                ),
1256
-                            ),
1257
-                        )
1258
-                    ) > 0 ? true : false;
1259
-                    //let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1260
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1261
-                                      && ! $TKT->get(
1262
-                        'TKT_deleted'
1263
-                    ) ? true : false;
1264
-                    $TKT->set_date_format($incoming_date_formats[0]);
1265
-                    $TKT->set_time_format($incoming_date_formats[1]);
1266
-                    //set new values
1267
-                    foreach ($TKT_values as $field => $value) {
1268
-                        if ($field == 'TKT_qty') {
1269
-                            $TKT->set_qty($value);
1270
-                        } else {
1271
-                            $TKT->set($field, $value);
1272
-                        }
1273
-                    }
1274
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1275
-                    if ($create_new_TKT) {
1276
-                        //archive the old ticket first
1277
-                        $TKT->set('TKT_deleted', 1);
1278
-                        $TKT->save();
1279
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1280
-                        $saved_tickets[$TKT->ID()] = $TKT;
1281
-                        //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1282
-                        $TKT = clone $TKT;
1283
-                        $TKT->set('TKT_ID', 0);
1284
-                        $TKT->set('TKT_deleted', 0);
1285
-                        $TKT->set('TKT_price', $ticket_price);
1286
-                        $TKT->set('TKT_sold', 0);
1287
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1288
-                        $update_prices = true;
1289
-                    }
1290
-                    //make sure price is set if it hasn't been already
1291
-                    $TKT->set('TKT_price', $ticket_price);
1292
-                }
1293
-            } else {
1294
-                //no TKT_id so a new TKT
1295
-                $TKT_values['TKT_price'] = $ticket_price;
1296
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1297
-                if ($TKT instanceof EE_Ticket) {
1298
-                    //need to reset values to properly account for the date formats
1299
-                    $TKT->set_date_format($incoming_date_formats[0]);
1300
-                    $TKT->set_time_format($incoming_date_formats[1]);
1301
-                    $TKT->set_timezone($evtobj->get_timezone());
1302
-                    //set new values
1303
-                    foreach ($TKT_values as $field => $value) {
1304
-                        if ($field == 'TKT_qty') {
1305
-                            $TKT->set_qty($value);
1306
-                        } else {
1307
-                            $TKT->set($field, $value);
1308
-                        }
1309
-                    }
1310
-                    $update_prices = true;
1311
-                }
1312
-            }
1313
-            // cap ticket qty by datetime reg limits
1314
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1315
-            //update ticket.
1316
-            $TKT->save();
1317
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1318
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1319
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1320
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1321
-                $TKT->save();
1322
-            }
1323
-            //initially let's add the ticket to the dtt
1324
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1325
-            $saved_tickets[$TKT->ID()] = $TKT;
1326
-            //add prices to ticket
1327
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1328
-        }
1329
-        //however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1330
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1331
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1332
-        foreach ($tickets_removed as $id) {
1333
-            $id = absint($id);
1334
-            //get the ticket for this id
1335
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1336
-            //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1337
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1338
-            foreach ($dtts as $dtt) {
1339
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1340
-            }
1341
-            //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1342
-            $tkt_to_remove->delete_related_permanently('Price');
1343
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1344
-            $tkt_to_remove->delete_permanently();
1345
-        }
1346
-        return array($saved_dtt, $saved_tickets);
1347
-    }
1348
-
1349
-
1350
-
1351
-    /**
1352
-     * This attaches a list of given prices to a ticket.
1353
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1354
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1355
-     * price info and prices are automatically "archived" via the ticket.
1356
-     *
1357
-     * @access  private
1358
-     * @param array     $prices     Array of prices from the form.
1359
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1360
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1361
-     * @return  void
1362
-     */
1363
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1364
-    {
1365
-        foreach ($prices as $row => $prc) {
1366
-            $PRC_values = array(
1367
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1368
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1369
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1370
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1371
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1372
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1373
-                'PRC_order'      => $row,
1374
-            );
1375
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1376
-                $PRC_values['PRC_ID'] = 0;
1377
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1378
-            } else {
1379
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1380
-                //update this price with new values
1381
-                foreach ($PRC_values as $field => $newprc) {
1382
-                    $PRC->set($field, $newprc);
1383
-                }
1384
-                $PRC->save();
1385
-            }
1386
-            $ticket->_add_relation_to($PRC, 'Price');
1387
-        }
1388
-    }
1389
-
1390
-
1391
-
1392
-    /**
1393
-     * Add in our autosave ajax handlers
1394
-     *
1395
-     */
1396
-    protected function _ee_autosave_create_new()
1397
-    {
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * More autosave handlers.
1403
-     */
1404
-    protected function _ee_autosave_edit()
1405
-    {
1406
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1407
-    }
1408
-
1409
-
1410
-
1411
-    /**
1412
-     *    _generate_publish_box_extra_content
1413
-     */
1414
-    private function _generate_publish_box_extra_content()
1415
-    {
1416
-        //load formatter helper
1417
-        //args for getting related registrations
1418
-        $approved_query_args = array(
1419
-            array(
1420
-                'REG_deleted' => 0,
1421
-                'STS_ID'      => EEM_Registration::status_id_approved,
1422
-            ),
1423
-        );
1424
-        $not_approved_query_args = array(
1425
-            array(
1426
-                'REG_deleted' => 0,
1427
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1428
-            ),
1429
-        );
1430
-        $pending_payment_query_args = array(
1431
-            array(
1432
-                'REG_deleted' => 0,
1433
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1434
-            ),
1435
-        );
1436
-        // publish box
1437
-        $publish_box_extra_args = array(
1438
-            'view_approved_reg_url'        => add_query_arg(
1439
-                array(
1440
-                    'action'      => 'default',
1441
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1442
-                    '_reg_status' => EEM_Registration::status_id_approved,
1443
-                ),
1444
-                REG_ADMIN_URL
1445
-            ),
1446
-            'view_not_approved_reg_url'    => add_query_arg(
1447
-                array(
1448
-                    'action'      => 'default',
1449
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1450
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1451
-                ),
1452
-                REG_ADMIN_URL
1453
-            ),
1454
-            'view_pending_payment_reg_url' => add_query_arg(
1455
-                array(
1456
-                    'action'      => 'default',
1457
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1458
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1459
-                ),
1460
-                REG_ADMIN_URL
1461
-            ),
1462
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1463
-                'Registration',
1464
-                $approved_query_args
1465
-            ),
1466
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1467
-                'Registration',
1468
-                $not_approved_query_args
1469
-            ),
1470
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1471
-                'Registration',
1472
-                $pending_payment_query_args
1473
-            ),
1474
-            'misc_pub_section_class'       => apply_filters(
1475
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1476
-                'misc-pub-section'
1477
-            ),
1478
-        );
1479
-        ob_start();
1480
-        do_action(
1481
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1482
-            $this->_cpt_model_obj
1483
-        );
1484
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1485
-        // load template
1486
-        EEH_Template::display_template(
1487
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1488
-            $publish_box_extra_args
1489
-        );
1490
-    }
1491
-
1492
-
1493
-
1494
-    /**
1495
-     * @return EE_Event
1496
-     */
1497
-    public function get_event_object()
1498
-    {
1499
-        return $this->_cpt_model_obj;
1500
-    }
1501
-
1502
-
1503
-
1504
-
1505
-    /** METABOXES * */
1506
-    /**
1507
-     * _register_event_editor_meta_boxes
1508
-     * add all metaboxes related to the event_editor
1509
-     *
1510
-     * @return void
1511
-     */
1512
-    protected function _register_event_editor_meta_boxes()
1513
-    {
1514
-        $this->verify_cpt_object();
1515
-        add_meta_box(
1516
-            'espresso_event_editor_tickets',
1517
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1518
-            array($this, 'ticket_metabox'),
1519
-            $this->page_slug,
1520
-            'normal',
1521
-            'high'
1522
-        );
1523
-        add_meta_box(
1524
-            'espresso_event_editor_event_options',
1525
-            esc_html__('Event Registration Options', 'event_espresso'),
1526
-            array($this, 'registration_options_meta_box'),
1527
-            $this->page_slug,
1528
-            'side',
1529
-            'default'
1530
-        );
1531
-        // NOTE: if you're looking for other metaboxes in here,
1532
-        // where a metabox has a related management page in the admin
1533
-        // you will find it setup in the related management page's "_Hooks" file.
1534
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1535
-    }
1536
-
1537
-
1538
-    /**
1539
-     * @throws DomainException
1540
-     * @throws EE_Error
1541
-     */
1542
-    public function ticket_metabox()
1543
-    {
1544
-        $existing_datetime_ids = $existing_ticket_ids = array();
1545
-        //defaults for template args
1546
-        $template_args = array(
1547
-            'existing_datetime_ids'    => '',
1548
-            'event_datetime_help_link' => '',
1549
-            'ticket_options_help_link' => '',
1550
-            'time'                     => null,
1551
-            'ticket_rows'              => '',
1552
-            'existing_ticket_ids'      => '',
1553
-            'total_ticket_rows'        => 1,
1554
-            'ticket_js_structure'      => '',
1555
-            'trash_icon'               => 'ee-lock-icon',
1556
-            'disabled'                 => '',
1557
-        );
1558
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1559
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1560
-        /**
1561
-         * 1. Start with retrieving Datetimes
1562
-         * 2. Fore each datetime get related tickets
1563
-         * 3. For each ticket get related prices
1564
-         */
1565
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1566
-        /** @type EE_Datetime $first_datetime */
1567
-        $first_datetime = reset($times);
1568
-        //do we get related tickets?
1569
-        if ($first_datetime instanceof EE_Datetime
1570
-            && $first_datetime->ID() !== 0
1571
-        ) {
1572
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1573
-            $template_args['time'] = $first_datetime;
1574
-            $related_tickets = $first_datetime->tickets(
1575
-                array(
1576
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1577
-                    'default_where_conditions' => 'none',
1578
-                )
1579
-            );
1580
-            if ( ! empty($related_tickets)) {
1581
-                $template_args['total_ticket_rows'] = count($related_tickets);
1582
-                $row = 0;
1583
-                foreach ($related_tickets as $ticket) {
1584
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1585
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1586
-                    $row++;
1587
-                }
1588
-            } else {
1589
-                $template_args['total_ticket_rows'] = 1;
1590
-                /** @type EE_Ticket $ticket */
1591
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1592
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1593
-            }
1594
-        } else {
1595
-            $template_args['time'] = $times[0];
1596
-            /** @type EE_Ticket $ticket */
1597
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1598
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1599
-            // NOTE: we're just sending the first default row
1600
-            // (decaf can't manage default tickets so this should be sufficient);
1601
-        }
1602
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1603
-            'event_editor_event_datetimes_help_tab'
1604
-        );
1605
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1606
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1607
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1608
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1609
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1610
-            true
1611
-        );
1612
-        $template = apply_filters(
1613
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1614
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1615
-        );
1616
-        EEH_Template::display_template($template, $template_args);
1617
-    }
1618
-
1619
-
1620
-
1621
-    /**
1622
-     * Setup an individual ticket form for the decaf event editor page
1623
-     *
1624
-     * @access private
1625
-     * @param  EE_Ticket $ticket   the ticket object
1626
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1627
-     * @param int        $row
1628
-     * @return string generated html for the ticket row.
1629
-     */
1630
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1631
-    {
1632
-        $template_args = array(
1633
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1634
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1635
-                : '',
1636
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1637
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1638
-            'TKT_name'            => $ticket->get('TKT_name'),
1639
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1640
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1641
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1642
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1643
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1644
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1645
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1646
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1647
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1648
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1649
-                : ' disabled=disabled',
1650
-        );
1651
-        $price = $ticket->ID() !== 0
1652
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1653
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1654
-        $price_args = array(
1655
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1656
-            'PRC_amount'            => $price->get('PRC_amount'),
1657
-            'PRT_ID'                => $price->get('PRT_ID'),
1658
-            'PRC_ID'                => $price->get('PRC_ID'),
1659
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1660
-        );
1661
-        //make sure we have default start and end dates if skeleton
1662
-        //handle rows that should NOT be empty
1663
-        if (empty($template_args['TKT_start_date'])) {
1664
-            //if empty then the start date will be now.
1665
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1666
-        }
1667
-        if (empty($template_args['TKT_end_date'])) {
1668
-            //get the earliest datetime (if present);
1669
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1670
-                ? $this->_cpt_model_obj->get_first_related(
1671
-                    'Datetime',
1672
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1673
-                )
1674
-                : null;
1675
-            if ( ! empty($earliest_dtt)) {
1676
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1677
-            } else {
1678
-                $template_args['TKT_end_date'] = date(
1679
-                    'Y-m-d h:i a',
1680
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1681
-                );
1682
-            }
1683
-        }
1684
-        $template_args = array_merge($template_args, $price_args);
1685
-        $template = apply_filters(
1686
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1687
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1688
-            $ticket
1689
-        );
1690
-        return EEH_Template::display_template($template, $template_args, true);
1691
-    }
1692
-
1693
-
1694
-    /**
1695
-     * @throws DomainException
1696
-     */
1697
-    public function registration_options_meta_box()
1698
-    {
1699
-        $yes_no_values = array(
1700
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1701
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1702
-        );
1703
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1704
-            array(
1705
-                EEM_Registration::status_id_cancelled,
1706
-                EEM_Registration::status_id_declined,
1707
-                EEM_Registration::status_id_incomplete,
1708
-            ),
1709
-            true
1710
-        );
1711
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1712
-        $template_args['_event'] = $this->_cpt_model_obj;
1713
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1714
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1715
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1716
-            'default_reg_status',
1717
-            $default_reg_status_values,
1718
-            $this->_cpt_model_obj->default_registration_status()
1719
-        );
1720
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1721
-            'display_desc',
1722
-            $yes_no_values,
1723
-            $this->_cpt_model_obj->display_description()
1724
-        );
1725
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1726
-            'display_ticket_selector',
1727
-            $yes_no_values,
1728
-            $this->_cpt_model_obj->display_ticket_selector(),
1729
-            '',
1730
-            '',
1731
-            false
1732
-        );
1733
-        $template_args['additional_registration_options'] = apply_filters(
1734
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1735
-            '',
1736
-            $template_args,
1737
-            $yes_no_values,
1738
-            $default_reg_status_values
1739
-        );
1740
-        EEH_Template::display_template(
1741
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1742
-            $template_args
1743
-        );
1744
-    }
1745
-
1746
-
1747
-
1748
-    /**
1749
-     * _get_events()
1750
-     * This method simply returns all the events (for the given _view and paging)
1751
-     *
1752
-     * @access public
1753
-     * @param int  $per_page     count of items per page (20 default);
1754
-     * @param int  $current_page what is the current page being viewed.
1755
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1756
-     *                           If FALSE then we return an array of event objects
1757
-     *                           that match the given _view and paging parameters.
1758
-     * @return array an array of event objects.
1759
-     */
1760
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1761
-    {
1762
-        $EEME = $this->_event_model();
1763
-        $offset = ($current_page - 1) * $per_page;
1764
-        $limit = $count ? null : $offset . ',' . $per_page;
1765
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1766
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1767
-        if (isset($this->_req_data['month_range'])) {
1768
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1769
-            //simulate the FIRST day of the month, that fixes issues for months like February
1770
-            //where PHP doesn't know what to assume for date.
1771
-            //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1772
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1773
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1774
-        }
1775
-        $where = array();
1776
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1777
-        //determine what post_status our condition will have for the query.
1778
-        switch ($status) {
1779
-            case 'month' :
1780
-            case 'today' :
1781
-            case null :
1782
-            case 'all' :
1783
-                break;
1784
-            case 'draft' :
1785
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1786
-                break;
1787
-            default :
1788
-                $where['status'] = $status;
1789
-        }
1790
-        //categories?
1791
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1792
-            ? $this->_req_data['EVT_CAT'] : null;
1793
-        if ( ! empty ($category)) {
1794
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1795
-            $where['Term_Taxonomy.term_id'] = $category;
1796
-        }
1797
-        //date where conditions
1798
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1799
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1800
-            $DateTime = new DateTime(
1801
-                $year_r . '-' . $month_r . '-01 00:00:00',
1802
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1803
-            );
1804
-            $start = $DateTime->format(implode(' ', $start_formats));
1805
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1806
-                ->format('t'))->setTime(23, 59, 59)
1807
-                            ->format(implode(' ', $start_formats));
1808
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1809
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1810
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1811
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1812
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1813
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1814
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1815
-            $now = date('Y-m-01');
1816
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1817
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1818
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1819
-                            ->setTime(23, 59, 59)
1820
-                            ->format(implode(' ', $start_formats));
1821
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1822
-        }
1823
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1824
-            $where['EVT_wp_user'] = get_current_user_id();
1825
-        } else {
1826
-            if ( ! isset($where['status'])) {
1827
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1828
-                    $where['OR'] = array(
1829
-                        'status*restrict_private' => array('!=', 'private'),
1830
-                        'AND'                     => array(
1831
-                            'status*inclusive' => array('=', 'private'),
1832
-                            'EVT_wp_user'      => get_current_user_id(),
1833
-                        ),
1834
-                    );
1835
-                }
1836
-            }
1837
-        }
1838
-        if (isset($this->_req_data['EVT_wp_user'])) {
1839
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1840
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1841
-            ) {
1842
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1843
-            }
1844
-        }
1845
-        //search query handling
1846
-        if (isset($this->_req_data['s'])) {
1847
-            $search_string = '%' . $this->_req_data['s'] . '%';
1848
-            $where['OR'] = array(
1849
-                'EVT_name'       => array('LIKE', $search_string),
1850
-                'EVT_desc'       => array('LIKE', $search_string),
1851
-                'EVT_short_desc' => array('LIKE', $search_string),
1852
-            );
1853
-        }
1854
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1855
-        $query_params = apply_filters(
1856
-            'FHEE__Events_Admin_Page__get_events__query_params',
1857
-            array(
1858
-                $where,
1859
-                'limit'    => $limit,
1860
-                'order_by' => $orderby,
1861
-                'order'    => $order,
1862
-                'group_by' => 'EVT_ID',
1863
-            ),
1864
-            $this->_req_data
1865
-        );
1866
-        //let's first check if we have special requests coming in.
1867
-        if (isset($this->_req_data['active_status'])) {
1868
-            switch ($this->_req_data['active_status']) {
1869
-                case 'upcoming' :
1870
-                    return $EEME->get_upcoming_events($query_params, $count);
1871
-                    break;
1872
-                case 'expired' :
1873
-                    return $EEME->get_expired_events($query_params, $count);
1874
-                    break;
1875
-                case 'active' :
1876
-                    return $EEME->get_active_events($query_params, $count);
1877
-                    break;
1878
-                case 'inactive' :
1879
-                    return $EEME->get_inactive_events($query_params, $count);
1880
-                    break;
1881
-            }
1882
-        }
1883
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1884
-        return $events;
1885
-    }
1886
-
1887
-
1888
-
1889
-    /**
1890
-     * handling for WordPress CPT actions (trash, restore, delete)
1891
-     *
1892
-     * @param string $post_id
1893
-     */
1894
-    public function trash_cpt_item($post_id)
1895
-    {
1896
-        $this->_req_data['EVT_ID'] = $post_id;
1897
-        $this->_trash_or_restore_event('trash', false);
1898
-    }
1899
-
1900
-
1901
-
1902
-    /**
1903
-     * @param string $post_id
1904
-     */
1905
-    public function restore_cpt_item($post_id)
1906
-    {
1907
-        $this->_req_data['EVT_ID'] = $post_id;
1908
-        $this->_trash_or_restore_event('draft', false);
1909
-    }
1910
-
1911
-
1912
-
1913
-    /**
1914
-     * @param string $post_id
1915
-     */
1916
-    public function delete_cpt_item($post_id)
1917
-    {
1918
-        $this->_req_data['EVT_ID'] = $post_id;
1919
-        $this->_delete_event(false);
1920
-    }
1921
-
1922
-
1923
-
1924
-    /**
1925
-     * _trash_or_restore_event
1926
-     *
1927
-     * @access protected
1928
-     * @param  string $event_status
1929
-     * @param bool    $redirect_after
1930
-     */
1931
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1932
-    {
1933
-        //determine the event id and set to array.
1934
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1935
-        // loop thru events
1936
-        if ($EVT_ID) {
1937
-            // clean status
1938
-            $event_status = sanitize_key($event_status);
1939
-            // grab status
1940
-            if ( ! empty($event_status)) {
1941
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1942
-            } else {
1943
-                $success = false;
1944
-                $msg = esc_html__(
1945
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1946
-                    'event_espresso'
1947
-                );
1948
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1949
-            }
1950
-        } else {
1951
-            $success = false;
1952
-            $msg = esc_html__(
1953
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1954
-                'event_espresso'
1955
-            );
1956
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1957
-        }
1958
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1959
-        if ($redirect_after) {
1960
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1961
-        }
1962
-    }
1963
-
1964
-
1965
-
1966
-    /**
1967
-     * _trash_or_restore_events
1968
-     *
1969
-     * @access protected
1970
-     * @param  string $event_status
1971
-     * @return void
1972
-     */
1973
-    protected function _trash_or_restore_events($event_status = 'trash')
1974
-    {
1975
-        // clean status
1976
-        $event_status = sanitize_key($event_status);
1977
-        // grab status
1978
-        if ( ! empty($event_status)) {
1979
-            $success = true;
1980
-            //determine the event id and set to array.
1981
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1982
-            // loop thru events
1983
-            foreach ($EVT_IDs as $EVT_ID) {
1984
-                if ($EVT_ID = absint($EVT_ID)) {
1985
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1986
-                    $success = $results !== false ? $success : false;
1987
-                } else {
1988
-                    $msg = sprintf(
1989
-                        esc_html__(
1990
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1991
-                            'event_espresso'
1992
-                        ),
1993
-                        $EVT_ID
1994
-                    );
1995
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1996
-                    $success = false;
1997
-                }
1998
-            }
1999
-        } else {
2000
-            $success = false;
2001
-            $msg = esc_html__(
2002
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2003
-                'event_espresso'
2004
-            );
2005
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2006
-        }
2007
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2008
-        $success = $success ? 2 : false;
2009
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2010
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2011
-    }
2012
-
2013
-
2014
-
2015
-    /**
2016
-     * _trash_or_restore_events
2017
-     *
2018
-     * @access  private
2019
-     * @param  int    $EVT_ID
2020
-     * @param  string $event_status
2021
-     * @return bool
2022
-     */
2023
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2024
-    {
2025
-        // grab event id
2026
-        if ( ! $EVT_ID) {
2027
-            $msg = esc_html__(
2028
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2029
-                'event_espresso'
2030
-            );
2031
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2032
-            return false;
2033
-        }
2034
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2035
-        // clean status
2036
-        $event_status = sanitize_key($event_status);
2037
-        // grab status
2038
-        if (empty($event_status)) {
2039
-            $msg = esc_html__(
2040
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2041
-                'event_espresso'
2042
-            );
2043
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2044
-            return false;
2045
-        }
2046
-        // was event trashed or restored ?
2047
-        switch ($event_status) {
2048
-            case 'draft' :
2049
-                $action = 'restored from the trash';
2050
-                $hook = 'AHEE_event_restored_from_trash';
2051
-                break;
2052
-            case 'trash' :
2053
-                $action = 'moved to the trash';
2054
-                $hook = 'AHEE_event_moved_to_trash';
2055
-                break;
2056
-            default :
2057
-                $action = 'updated';
2058
-                $hook = false;
2059
-        }
2060
-        //use class to change status
2061
-        $this->_cpt_model_obj->set_status($event_status);
2062
-        $success = $this->_cpt_model_obj->save();
2063
-        if ($success === false) {
2064
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2065
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2066
-            return false;
2067
-        }
2068
-        if ($hook) {
2069
-            do_action($hook);
2070
-        }
2071
-        return true;
2072
-    }
2073
-
2074
-
2075
-
2076
-    /**
2077
-     * _delete_event
2078
-     *
2079
-     * @access protected
2080
-     * @param bool $redirect_after
2081
-     */
2082
-    protected function _delete_event($redirect_after = true)
2083
-    {
2084
-        //determine the event id and set to array.
2085
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2086
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2087
-        // loop thru events
2088
-        if ($EVT_ID) {
2089
-            $success = $this->_permanently_delete_event($EVT_ID);
2090
-            // get list of events with no prices
2091
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2092
-            // remove this event from the list of events with no prices
2093
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2094
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2095
-            }
2096
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2097
-        } else {
2098
-            $success = false;
2099
-            $msg = esc_html__(
2100
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2101
-                'event_espresso'
2102
-            );
2103
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2104
-        }
2105
-        if ($redirect_after) {
2106
-            $this->_redirect_after_action(
2107
-                $success,
2108
-                'Event',
2109
-                'deleted',
2110
-                array('action' => 'default', 'status' => 'trash')
2111
-            );
2112
-        }
2113
-    }
2114
-
2115
-
2116
-
2117
-    /**
2118
-     * _delete_events
2119
-     *
2120
-     * @access protected
2121
-     * @return void
2122
-     */
2123
-    protected function _delete_events()
2124
-    {
2125
-        $success = true;
2126
-        // get list of events with no prices
2127
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2128
-        //determine the event id and set to array.
2129
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2130
-        // loop thru events
2131
-        foreach ($EVT_IDs as $EVT_ID) {
2132
-            $EVT_ID = absint($EVT_ID);
2133
-            if ($EVT_ID) {
2134
-                $results = $this->_permanently_delete_event($EVT_ID);
2135
-                $success = $results !== false ? $success : false;
2136
-                // remove this event from the list of events with no prices
2137
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2138
-            } else {
2139
-                $success = false;
2140
-                $msg = esc_html__(
2141
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2142
-                    'event_espresso'
2143
-                );
2144
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
-            }
2146
-        }
2147
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2148
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2149
-        $success = $success ? 2 : false;
2150
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2151
-    }
2152
-
2153
-
2154
-
2155
-    /**
2156
-     * _permanently_delete_event
2157
-     *
2158
-     * @access  private
2159
-     * @param  int $EVT_ID
2160
-     * @return bool
2161
-     */
2162
-    private function _permanently_delete_event($EVT_ID = 0)
2163
-    {
2164
-        // grab event id
2165
-        if ( ! $EVT_ID) {
2166
-            $msg = esc_html__(
2167
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2168
-                'event_espresso'
2169
-            );
2170
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
-            return false;
2172
-        }
2173
-        if (
2174
-            ! $this->_cpt_model_obj instanceof EE_Event
2175
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2176
-        ) {
2177
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2178
-        }
2179
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2180
-            return false;
2181
-        }
2182
-        //need to delete related tickets and prices first.
2183
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2184
-        foreach ($datetimes as $datetime) {
2185
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2186
-            $tickets = $datetime->get_many_related('Ticket');
2187
-            foreach ($tickets as $ticket) {
2188
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2189
-                $ticket->delete_related_permanently('Price');
2190
-                $ticket->delete_permanently();
2191
-            }
2192
-            $datetime->delete();
2193
-        }
2194
-        //what about related venues or terms?
2195
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2196
-        foreach ($venues as $venue) {
2197
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2198
-        }
2199
-        //any attached question groups?
2200
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2201
-        if ( ! empty($question_groups)) {
2202
-            foreach ($question_groups as $question_group) {
2203
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2204
-            }
2205
-        }
2206
-        //Message Template Groups
2207
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2208
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2209
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2210
-        foreach ($term_taxonomies as $term_taxonomy) {
2211
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2212
-        }
2213
-        $success = $this->_cpt_model_obj->delete_permanently();
2214
-        // did it all go as planned ?
2215
-        if ($success) {
2216
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2217
-            EE_Error::add_success($msg);
2218
-        } else {
2219
-            $msg = sprintf(
2220
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2221
-                $EVT_ID
2222
-            );
2223
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2224
-            return false;
2225
-        }
2226
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2227
-        return true;
2228
-    }
2229
-
2230
-
2231
-
2232
-    /**
2233
-     * get total number of events
2234
-     *
2235
-     * @access public
2236
-     * @return int
2237
-     */
2238
-    public function total_events()
2239
-    {
2240
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2241
-        return $count;
2242
-    }
2243
-
2244
-
2245
-
2246
-    /**
2247
-     * get total number of draft events
2248
-     *
2249
-     * @access public
2250
-     * @return int
2251
-     */
2252
-    public function total_events_draft()
2253
-    {
2254
-        $where = array(
2255
-            'status' => array('IN', array('draft', 'auto-draft')),
2256
-        );
2257
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2258
-        return $count;
2259
-    }
2260
-
2261
-
2262
-
2263
-    /**
2264
-     * get total number of trashed events
2265
-     *
2266
-     * @access public
2267
-     * @return int
2268
-     */
2269
-    public function total_trashed_events()
2270
-    {
2271
-        $where = array(
2272
-            'status' => 'trash',
2273
-        );
2274
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2275
-        return $count;
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     *    _default_event_settings
2281
-     *    This generates the Default Settings Tab
2282
-     *
2283
-     * @return void
2284
-     * @throws EE_Error
2285
-     */
2286
-    protected function _default_event_settings()
2287
-    {
2288
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2289
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2290
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2291
-        $this->display_admin_page_with_sidebar();
2292
-    }
2293
-
2294
-
2295
-    /**
2296
-     * Return the form for event settings.
2297
-     * @return EE_Form_Section_Proper
2298
-     */
2299
-    protected function _default_event_settings_form()
2300
-    {
2301
-        $registration_config = EE_Registry::instance()->CFG->registration;
2302
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2303
-        //exclude
2304
-            array(
2305
-                EEM_Registration::status_id_cancelled,
2306
-                EEM_Registration::status_id_declined,
2307
-                EEM_Registration::status_id_incomplete,
2308
-                EEM_Registration::status_id_wait_list,
2309
-            ),
2310
-            true
2311
-        );
2312
-        return new EE_Form_Section_Proper(
2313
-            array(
2314
-                'name' => 'update_default_event_settings',
2315
-                'html_id' => 'update_default_event_settings',
2316
-                'html_class' => 'form-table',
2317
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2318
-                'subsections' => apply_filters(
2319
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2320
-                    array(
2321
-                        'default_reg_status' => new EE_Select_Input(
2322
-                            $registration_stati_for_selection,
2323
-                            array(
2324
-                                'default' => isset($registration_config->default_STS_ID)
2325
-                                             && array_key_exists(
2326
-                                                $registration_config->default_STS_ID,
2327
-                                                $registration_stati_for_selection
2328
-                                             )
2329
-                                            ? sanitize_text_field($registration_config->default_STS_ID)
2330
-                                            : EEM_Registration::status_id_pending_payment,
2331
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2332
-                                                    . EEH_Template::get_help_tab_link(
2333
-                                                        'default_settings_status_help_tab'
2334
-                                                    ),
2335
-                                'html_help_text' => esc_html__(
2336
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2337
-                                    'event_espresso'
2338
-                                )
2339
-                            )
2340
-                        ),
2341
-                        'default_max_tickets' => new EE_Integer_Input(
2342
-                            array(
2343
-                                'default' => isset($registration_config->default_maximum_number_of_tickets)
2344
-                                    ? $registration_config->default_maximum_number_of_tickets
2345
-                                    : EEM_Event::get_default_additional_limit(),
2346
-                                'html_label_text' => esc_html__(
2347
-                                    'Default Maximum Tickets Allowed Per Order:',
2348
-                                    'event_espresso'
2349
-                                ) . EEH_Template::get_help_tab_link(
2350
-                                    'default_maximum_tickets_help_tab"'
2351
-                                    ),
2352
-                                'html_help_text' => esc_html__(
2353
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2354
-                                    'event_espresso'
2355
-                                )
2356
-                            )
2357
-                        )
2358
-                    )
2359
-                )
2360
-            )
2361
-        );
2362
-    }
2363
-
2364
-
2365
-    /**
2366
-     * _update_default_event_settings
2367
-     *
2368
-     * @access protected
2369
-     * @return void
2370
-     * @throws EE_Error
2371
-     */
2372
-    protected function _update_default_event_settings()
2373
-    {
2374
-        $registration_config = EE_Registry::instance()->CFG->registration;
2375
-        $form = $this->_default_event_settings_form();
2376
-        if ($form->was_submitted()) {
2377
-            $form->receive_form_submission();
2378
-            if ($form->is_valid()) {
2379
-                $valid_data = $form->valid_data();
2380
-                if (isset($valid_data['default_reg_status'])) {
2381
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2382
-                }
2383
-                if (isset($valid_data['default_max_tickets'])) {
2384
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2385
-                }
2386
-                //update because data was valid!
2387
-                EE_Registry::instance()->CFG->update_espresso_config();
2388
-                EE_Error::overwrite_success();
2389
-                EE_Error::add_success(
2390
-                    __('Default Event Settings were updated', 'event_espresso')
2391
-                );
2392
-            }
2393
-        }
2394
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2395
-    }
2396
-
2397
-
2398
-
2399
-    /*************        Templates        *************/
2400
-    protected function _template_settings()
2401
-    {
2402
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2403
-        $this->_template_args['preview_img'] = '<img src="'
2404
-                                               . EVENTS_ASSETS_URL
2405
-                                               . DS
2406
-                                               . 'images'
2407
-                                               . DS
2408
-                                               . 'caffeinated_template_features.jpg" alt="'
2409
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2410
-                                               . '" />';
2411
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2412
-                'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2413
-                'event_espresso'
2414
-            ) . '</strong>';
2415
-        $this->display_admin_caf_preview_page('template_settings_tab');
2416
-    }
2417
-
2418
-
2419
-    /** Event Category Stuff **/
2420
-    /**
2421
-     * set the _category property with the category object for the loaded page.
2422
-     *
2423
-     * @access private
2424
-     * @return void
2425
-     */
2426
-    private function _set_category_object()
2427
-    {
2428
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2429
-            return;
2430
-        } //already have the category object so get out.
2431
-        //set default category object
2432
-        $this->_set_empty_category_object();
2433
-        //only set if we've got an id
2434
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2435
-            return;
2436
-        }
2437
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2438
-        $term = get_term($category_id, 'espresso_event_categories');
2439
-        if ( ! empty($term)) {
2440
-            $this->_category->category_name = $term->name;
2441
-            $this->_category->category_identifier = $term->slug;
2442
-            $this->_category->category_desc = $term->description;
2443
-            $this->_category->id = $term->term_id;
2444
-            $this->_category->parent = $term->parent;
2445
-        }
2446
-    }
2447
-
2448
-
2449
-    /**
2450
-     * Clears out category properties.
2451
-     */
2452
-    private function _set_empty_category_object()
2453
-    {
2454
-        $this->_category = new stdClass();
2455
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2456
-        $this->_category->id = $this->_category->parent = 0;
2457
-    }
2458
-
2459
-
2460
-    /**
2461
-     * @throws EE_Error
2462
-     */
2463
-    protected function _category_list_table()
2464
-    {
2465
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2466
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2467
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2468
-                'add_category',
2469
-                'add_category',
2470
-                array(),
2471
-                'add-new-h2'
2472
-            );
2473
-        $this->display_admin_list_table_page_with_sidebar();
2474
-    }
2475
-
2476
-
2477
-
2478
-    /**
2479
-     * Output category details view.
2480
-     */
2481
-    protected function _category_details($view)
2482
-    {
2483
-        //load formatter helper
2484
-        //load field generator helper
2485
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2486
-        $this->_set_add_edit_form_tags($route);
2487
-        $this->_set_category_object();
2488
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2489
-        $delete_action = 'delete_category';
2490
-        //custom redirect
2491
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2492
-            array('action' => 'category_list'),
2493
-            $this->_admin_base_url
2494
-        );
2495
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2496
-        //take care of contents
2497
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2498
-        $this->display_admin_page_with_sidebar();
2499
-    }
2500
-
2501
-
2502
-
2503
-    /**
2504
-     * Output category details content.
2505
-     */
2506
-    protected function _category_details_content()
2507
-    {
2508
-        $editor_args['category_desc'] = array(
2509
-            'type'          => 'wp_editor',
2510
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2511
-            'class'         => 'my_editor_custom',
2512
-            'wpeditor_args' => array('media_buttons' => false),
2513
-        );
2514
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2515
-        $all_terms = get_terms(
2516
-            array('espresso_event_categories'),
2517
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2518
-        );
2519
-        //setup category select for term parents.
2520
-        $category_select_values[] = array(
2521
-            'text' => esc_html__('No Parent', 'event_espresso'),
2522
-            'id'   => 0,
2523
-        );
2524
-        foreach ($all_terms as $term) {
2525
-            $category_select_values[] = array(
2526
-                'text' => $term->name,
2527
-                'id'   => $term->term_id,
2528
-            );
2529
-        }
2530
-        $category_select = EEH_Form_Fields::select_input(
2531
-            'category_parent',
2532
-            $category_select_values,
2533
-            $this->_category->parent
2534
-        );
2535
-        $template_args = array(
2536
-            'category'                 => $this->_category,
2537
-            'category_select'          => $category_select,
2538
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2539
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2540
-            'disable'                  => '',
2541
-            'disabled_message'         => false,
2542
-        );
2543
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2544
-        return EEH_Template::display_template($template, $template_args, true);
2545
-    }
2546
-
2547
-
2548
-    /**
2549
-     * Handles deleting categories.
2550
-     */
2551
-    protected function _delete_categories()
2552
-    {
2553
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2554
-            : (array)$this->_req_data['category_id'];
2555
-        foreach ($cat_ids as $cat_id) {
2556
-            $this->_delete_category($cat_id);
2557
-        }
2558
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2559
-        $query_args = array(
2560
-            'action' => 'category_list',
2561
-        );
2562
-        $this->_redirect_after_action(0, '', '', $query_args);
2563
-    }
2564
-
2565
-
2566
-
2567
-    /**
2568
-     * Handles deleting specific category.
2569
-     * @param int $cat_id
2570
-     */
2571
-    protected function _delete_category($cat_id)
2572
-    {
2573
-        $cat_id = absint($cat_id);
2574
-        wp_delete_term($cat_id, 'espresso_event_categories');
2575
-    }
2576
-
2577
-
2578
-
2579
-    /**
2580
-     * Handles triggering the update or insertion of a new category.
2581
-     * @param bool $new_category  true means we're triggering the insert of a new category.
2582
-     */
2583
-    protected function _insert_or_update_category($new_category)
2584
-    {
2585
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2586
-        $success = 0; //we already have a success message so lets not send another.
2587
-        if ($cat_id) {
2588
-            $query_args = array(
2589
-                'action'     => 'edit_category',
2590
-                'EVT_CAT_ID' => $cat_id,
2591
-            );
2592
-        } else {
2593
-            $query_args = array('action' => 'add_category');
2594
-        }
2595
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2596
-    }
2597
-
2598
-
2599
-
2600
-    /**
2601
-     * Inserts or updates category
2602
-     * @param bool $update (true indicates we're updating a category).
2603
-     * @return bool|mixed|string
2604
-     */
2605
-    private function _insert_category($update = false)
2606
-    {
2607
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2608
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2609
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2610
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2611
-        if (empty($category_name)) {
2612
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2613
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2614
-            return false;
2615
-        }
2616
-        $term_args = array(
2617
-            'name'        => $category_name,
2618
-            'description' => $category_desc,
2619
-            'parent'      => $category_parent,
2620
-        );
2621
-        //was the category_identifier input disabled?
2622
-        if (isset($this->_req_data['category_identifier'])) {
2623
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2624
-        }
2625
-        $insert_ids = $update
2626
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2627
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2628
-        if ( ! is_array($insert_ids)) {
2629
-            $msg = esc_html__(
2630
-                'An error occurred and the category has not been saved to the database.',
2631
-                'event_espresso'
2632
-            );
2633
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2634
-        } else {
2635
-            $cat_id = $insert_ids['term_id'];
2636
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2637
-            EE_Error::add_success($msg);
2638
-        }
2639
-        return $cat_id;
2640
-    }
2641
-
2642
-
2643
-
2644
-    /**
2645
-     * Gets categories or count of categories matching the arguments in the request.
2646
-     * @param int  $per_page
2647
-     * @param int  $current_page
2648
-     * @param bool $count
2649
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2650
-     */
2651
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2652
-    {
2653
-        //testing term stuff
2654
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2655
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2656
-        $limit = ($current_page - 1) * $per_page;
2657
-        $where = array('taxonomy' => 'espresso_event_categories');
2658
-        if (isset($this->_req_data['s'])) {
2659
-            $sstr = '%' . $this->_req_data['s'] . '%';
2660
-            $where['OR'] = array(
2661
-                'Term.name'   => array('LIKE', $sstr),
2662
-                'description' => array('LIKE', $sstr),
2663
-            );
2664
-        }
2665
-        $query_params = array(
2666
-            $where,
2667
-            'order_by'   => array($orderby => $order),
2668
-            'limit'      => $limit . ',' . $per_page,
2669
-            'force_join' => array('Term'),
2670
-        );
2671
-        $categories = $count
2672
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2673
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2674
-        return $categories;
2675
-    }
2676
-
2677
-    /* end category stuff */
2678
-    /**************/
2679
-
2680
-
2681
-    /**
2682
-     * Callback for the `ee_save_timezone_setting` ajax action.
2683
-     * @throws EE_Error
2684
-     */
2685
-    public function save_timezonestring_setting()
2686
-    {
2687
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2688
-            ? $this->_req_data['timezone_selected']
2689
-            : '';
2690
-        if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2691
-        {
2692
-            EE_Error::add_error(
2693
-                esc_html('An invalid timezone string submitted.', 'event_espresso'),
2694
-                __FILE__, __FUNCTION__, __LINE__
2695
-            );
2696
-            $this->_template_args['error'] = true;
2697
-            $this->_return_json();
2698
-        }
2699
-
2700
-        update_option('timezone_string', $timezone_string);
2701
-        EE_Error::add_success(
2702
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2703
-        );
2704
-        $this->_template_args['success'] = true;
2705
-        $this->_return_json(true, array('action' => 'create_new'));
2706
-    }
394
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
395
+				'require_nonce' => false,
396
+			),
397
+			'default_event_settings' => array(
398
+				'nav'           => array(
399
+					'label' => esc_html__('Default Settings', 'event_espresso'),
400
+					'order' => 40,
401
+				),
402
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
403
+				'labels'        => array(
404
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
405
+				),
406
+				'help_tabs'     => array(
407
+					'default_settings_help_tab'        => array(
408
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
409
+						'filename' => 'events_default_settings',
410
+					),
411
+					'default_settings_status_help_tab' => array(
412
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
413
+						'filename' => 'events_default_settings_status',
414
+					),
415
+					'default_maximum_tickets_help_tab' => array(
416
+						'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
417
+						'filename' => 'events_default_settings_max_tickets',
418
+					)
419
+				),
420
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
421
+				'require_nonce' => false,
422
+			),
423
+			//template settings
424
+			'template_settings'      => array(
425
+				'nav'           => array(
426
+					'label' => esc_html__('Templates', 'event_espresso'),
427
+					'order' => 30,
428
+				),
429
+				'metaboxes'     => $this->_default_espresso_metaboxes,
430
+				'help_tabs'     => array(
431
+					'general_settings_templates_help_tab' => array(
432
+						'title'    => esc_html__('Templates', 'event_espresso'),
433
+						'filename' => 'general_settings_templates',
434
+					),
435
+				),
436
+				'help_tour'     => array('Templates_Help_Tour'),
437
+				'require_nonce' => false,
438
+			),
439
+			//event category stuff
440
+			'add_category'           => array(
441
+				'nav'           => array(
442
+					'label'      => esc_html__('Add Category', 'event_espresso'),
443
+					'order'      => 15,
444
+					'persistent' => false,
445
+				),
446
+				'help_tabs'     => array(
447
+					'add_category_help_tab' => array(
448
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
449
+						'filename' => 'events_add_category',
450
+					),
451
+				),
452
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
453
+				'metaboxes'     => array('_publish_post_box'),
454
+				'require_nonce' => false,
455
+			),
456
+			'edit_category'          => array(
457
+				'nav'           => array(
458
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
459
+					'order'      => 15,
460
+					'persistent' => false,
461
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
462
+						? add_query_arg(
463
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
464
+							$this->_current_page_view_url
465
+						)
466
+						: $this->_admin_base_url,
467
+				),
468
+				'help_tabs'     => array(
469
+					'edit_category_help_tab' => array(
470
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
+						'filename' => 'events_edit_category',
472
+					),
473
+				),
474
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
475
+				'metaboxes'     => array('_publish_post_box'),
476
+				'require_nonce' => false,
477
+			),
478
+			'category_list'          => array(
479
+				'nav'           => array(
480
+					'label' => esc_html__('Categories', 'event_espresso'),
481
+					'order' => 20,
482
+				),
483
+				'list_table'    => 'Event_Categories_Admin_List_Table',
484
+				'help_tabs'     => array(
485
+					'events_categories_help_tab'                       => array(
486
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
487
+						'filename' => 'events_categories',
488
+					),
489
+					'events_categories_table_column_headings_help_tab' => array(
490
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
491
+						'filename' => 'events_categories_table_column_headings',
492
+					),
493
+					'events_categories_view_help_tab'                  => array(
494
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
495
+						'filename' => 'events_categories_views',
496
+					),
497
+					'events_categories_other_help_tab'                 => array(
498
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
499
+						'filename' => 'events_categories_other',
500
+					),
501
+				),
502
+				'help_tour'     => array(
503
+					'Event_Categories_Help_Tour',
504
+				),
505
+				'metaboxes'     => $this->_default_espresso_metaboxes,
506
+				'require_nonce' => false,
507
+			),
508
+		);
509
+	}
510
+
511
+
512
+	/**
513
+	 * Used to register any global screen options if necessary for every route in this admin page group.
514
+	 */
515
+	protected function _add_screen_options()
516
+	{
517
+	}
518
+
519
+
520
+	/**
521
+	 * Implementing the screen options for the 'default' route.
522
+	 */
523
+	protected function _add_screen_options_default()
524
+	{
525
+		$this->_per_page_screen_option();
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing screen options for the category list route.
531
+	 */
532
+	protected function _add_screen_options_category_list()
533
+	{
534
+		$page_title = $this->_admin_page_title;
535
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
536
+		$this->_per_page_screen_option();
537
+		$this->_admin_page_title = $page_title;
538
+	}
539
+
540
+
541
+	/**
542
+	 * Used to register any global feature pointers for the admin page group.
543
+	 */
544
+	protected function _add_feature_pointers()
545
+	{
546
+	}
547
+
548
+
549
+	/**
550
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
551
+	 */
552
+	public function load_scripts_styles()
553
+	{
554
+		wp_register_style(
555
+			'events-admin-css',
556
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
557
+			array(),
558
+			EVENT_ESPRESSO_VERSION
559
+		);
560
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561
+		wp_enqueue_style('events-admin-css');
562
+		wp_enqueue_style('ee-cat-admin');
563
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
564
+		//registers for all views
565
+		//scripts
566
+		wp_register_script(
567
+			'event_editor_js',
568
+			EVENTS_ASSETS_URL . 'event_editor.js',
569
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570
+			EVENT_ESPRESSO_VERSION,
571
+			true
572
+		);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * Enqueuing scripts and styles specific to this view
579
+	 */
580
+	public function load_scripts_styles_create_new()
581
+	{
582
+		$this->load_scripts_styles_edit();
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 * Enqueuing scripts and styles specific to this view
589
+	 */
590
+	public function load_scripts_styles_edit()
591
+	{
592
+		//styles
593
+		wp_enqueue_style('espresso-ui-theme');
594
+		wp_register_style(
595
+			'event-editor-css',
596
+			EVENTS_ASSETS_URL . 'event-editor.css',
597
+			array('ee-admin-css'),
598
+			EVENT_ESPRESSO_VERSION
599
+		);
600
+		wp_enqueue_style('event-editor-css');
601
+		//scripts
602
+		wp_register_script(
603
+			'event-datetime-metabox',
604
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
605
+			array('event_editor_js', 'ee-datepicker'),
606
+			EVENT_ESPRESSO_VERSION
607
+		);
608
+		wp_enqueue_script('event-datetime-metabox');
609
+	}
610
+
611
+
612
+	/**
613
+	 * Populating the _views property for the category list table view.
614
+	 */
615
+	protected function _set_list_table_views_category_list()
616
+	{
617
+		$this->_views = array(
618
+			'all' => array(
619
+				'slug'        => 'all',
620
+				'label'       => esc_html__('All', 'event_espresso'),
621
+				'count'       => 0,
622
+				'bulk_action' => array(
623
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
624
+				),
625
+			),
626
+		);
627
+	}
628
+
629
+
630
+	/**
631
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
632
+	 */
633
+	public function admin_init()
634
+	{
635
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
636
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
637
+			'event_espresso'
638
+		);
639
+	}
640
+
641
+
642
+	/**
643
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page group.
644
+	 */
645
+	public function admin_notices()
646
+	{
647
+	}
648
+
649
+
650
+	/**
651
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
652
+	 * this admin page group.
653
+	 */
654
+	public function admin_footer_scripts()
655
+	{
656
+	}
657
+
658
+
659
+
660
+	/**
661
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
662
+	 * warning (via EE_Error::add_error());
663
+	 *
664
+	 * @param  EE_Event $event Event object
665
+	 * @param string    $req_type
666
+	 * @return void
667
+	 * @throws EE_Error
668
+	 * @access public
669
+	 */
670
+	public function verify_event_edit($event = null, $req_type = '')
671
+	{
672
+		// don't need to do this when processing
673
+		if(!empty($req_type)) {
674
+			return;
675
+		}
676
+		// no event?
677
+		if (empty($event)) {
678
+			// set event
679
+			$event = $this->_cpt_model_obj;
680
+		}
681
+		// STILL no event?
682
+		if (! $event instanceof EE_Event) {
683
+			return;
684
+		}
685
+		$orig_status = $event->status();
686
+		// first check if event is active.
687
+		if (
688
+			$orig_status === EEM_Event::cancelled
689
+			|| $orig_status === EEM_Event::postponed
690
+			|| $event->is_expired()
691
+			|| $event->is_inactive()
692
+		) {
693
+			return;
694
+		}
695
+		//made it here so it IS active... next check that any of the tickets are sold.
696
+		if ($event->is_sold_out(true)) {
697
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
698
+				EE_Error::add_attention(
699
+					sprintf(
700
+						esc_html__(
701
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
702
+							'event_espresso'
703
+						),
704
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
705
+					)
706
+				);
707
+			}
708
+			return;
709
+		} else if ($orig_status === EEM_Event::sold_out) {
710
+			EE_Error::add_attention(
711
+				sprintf(
712
+					esc_html__(
713
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
714
+						'event_espresso'
715
+					),
716
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
717
+				)
718
+			);
719
+		}
720
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
721
+		if ( ! $event->tickets_on_sale()) {
722
+			return;
723
+		}
724
+		//made it here so show warning
725
+		$this->_edit_event_warning();
726
+	}
727
+
728
+
729
+
730
+	/**
731
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
732
+	 * When needed, hook this into a EE_Error::add_error() notice.
733
+	 *
734
+	 * @access protected
735
+	 * @return void
736
+	 */
737
+	protected function _edit_event_warning()
738
+	{
739
+		// we don't want to add warnings during these requests
740
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
741
+			return;
742
+		}
743
+		EE_Error::add_attention(
744
+			esc_html__(
745
+				'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
746
+				'event_espresso'
747
+			)
748
+		);
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
755
+	 * Otherwise, do the normal logic
756
+	 *
757
+	 * @return string
758
+	 * @throws \EE_Error
759
+	 */
760
+	protected function _create_new_cpt_item()
761
+	{
762
+		$has_timezone_string = get_option('timezone_string');
763
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
764
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
765
+			EE_Error::add_attention(
766
+				sprintf(
767
+					__(
768
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
769
+						'event_espresso'
770
+					),
771
+					'<br>',
772
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
773
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
774
+					. '</select>',
775
+					'<button class="button button-secondary timezone-submit">',
776
+					'</button><span class="spinner"></span>'
777
+				),
778
+				__FILE__,
779
+				__FUNCTION__,
780
+				__LINE__
781
+			);
782
+		}
783
+		return parent::_create_new_cpt_item();
784
+	}
785
+
786
+
787
+	/**
788
+	 * Sets the _views property for the default route in this admin page group.
789
+	 */
790
+	protected function _set_list_table_views_default()
791
+	{
792
+		$this->_views = array(
793
+			'all'   => array(
794
+				'slug'        => 'all',
795
+				'label'       => esc_html__('View All Events', 'event_espresso'),
796
+				'count'       => 0,
797
+				'bulk_action' => array(
798
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
799
+				),
800
+			),
801
+			'draft' => array(
802
+				'slug'        => 'draft',
803
+				'label'       => esc_html__('Draft', 'event_espresso'),
804
+				'count'       => 0,
805
+				'bulk_action' => array(
806
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
+				),
808
+			),
809
+		);
810
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
811
+			$this->_views['trash'] = array(
812
+				'slug'        => 'trash',
813
+				'label'       => esc_html__('Trash', 'event_espresso'),
814
+				'count'       => 0,
815
+				'bulk_action' => array(
816
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
817
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
818
+				),
819
+			);
820
+		}
821
+	}
822
+
823
+
824
+
825
+	/**
826
+	 * Provides the legend item array for the default list table view.
827
+	 * @return array
828
+	 */
829
+	protected function _event_legend_items()
830
+	{
831
+		$items = array(
832
+			'view_details'   => array(
833
+				'class' => 'dashicons dashicons-search',
834
+				'desc'  => esc_html__('View Event', 'event_espresso'),
835
+			),
836
+			'edit_event'     => array(
837
+				'class' => 'ee-icon ee-icon-calendar-edit',
838
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
839
+			),
840
+			'view_attendees' => array(
841
+				'class' => 'dashicons dashicons-groups',
842
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
843
+			),
844
+		);
845
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
846
+		$statuses = array(
847
+			'sold_out_status'  => array(
848
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
849
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
850
+			),
851
+			'active_status'    => array(
852
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
853
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
854
+			),
855
+			'upcoming_status'  => array(
856
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
857
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
858
+			),
859
+			'postponed_status' => array(
860
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
861
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
862
+			),
863
+			'cancelled_status' => array(
864
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
865
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
866
+			),
867
+			'expired_status'   => array(
868
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
869
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
870
+			),
871
+			'inactive_status'  => array(
872
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
873
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
874
+			),
875
+		);
876
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
877
+		return array_merge($items, $statuses);
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 * @return EEM_Event
884
+	 */
885
+	private function _event_model()
886
+	{
887
+		if ( ! $this->_event_model instanceof EEM_Event) {
888
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
889
+		}
890
+		return $this->_event_model;
891
+	}
892
+
893
+
894
+
895
+	/**
896
+	 * Adds extra buttons to the WP CPT permalink field row.
897
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
898
+	 *
899
+	 * @param  string $return    the current html
900
+	 * @param  int    $id        the post id for the page
901
+	 * @param  string $new_title What the title is
902
+	 * @param  string $new_slug  what the slug is
903
+	 * @return string            The new html string for the permalink area
904
+	 */
905
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
906
+	{
907
+		//make sure this is only when editing
908
+		if ( ! empty($id)) {
909
+			$post = get_post($id);
910
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
911
+					   . esc_html__('Shortcode', 'event_espresso')
912
+					   . '</a> ';
913
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
914
+					   . $post->ID
915
+					   . ']">';
916
+		}
917
+		return $return;
918
+	}
919
+
920
+
921
+
922
+	/**
923
+	 * _events_overview_list_table
924
+	 * This contains the logic for showing the events_overview list
925
+	 *
926
+	 * @access protected
927
+	 * @return void
928
+	 * @throws \EE_Error
929
+	 */
930
+	protected function _events_overview_list_table()
931
+	{
932
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
933
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
934
+			? (array)$this->_template_args['after_list_table']
935
+			: array();
936
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
937
+																			  . EEH_Template::get_button_or_link(
938
+				get_post_type_archive_link('espresso_events'),
939
+				esc_html__("View Event Archive Page", "event_espresso"),
940
+				'button'
941
+			);
942
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
943
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
944
+				'create_new',
945
+				'add',
946
+				array(),
947
+				'add-new-h2'
948
+			);
949
+		$this->display_admin_list_table_page_with_no_sidebar();
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * this allows for extra misc actions in the default WP publish box
956
+	 *
957
+	 * @return void
958
+	 */
959
+	public function extra_misc_actions_publish_box()
960
+	{
961
+		$this->_generate_publish_box_extra_content();
962
+	}
963
+
964
+
965
+
966
+	/**
967
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been saved.
968
+	 * Typically you would use this to save any additional data.
969
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
970
+	 * ALSO very important.  When a post transitions from scheduled to published,
971
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from other meta saves.
972
+	 * So MAKE sure that you handle this accordingly.
973
+	 *
974
+	 * @access protected
975
+	 * @abstract
976
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
977
+	 * @param  object $post    The post object of the cpt that was saved.
978
+	 * @return void
979
+	 * @throws \EE_Error
980
+	 */
981
+	protected function _insert_update_cpt_item($post_id, $post)
982
+	{
983
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
984
+			//get out we're not processing an event save.
985
+			return;
986
+		}
987
+		$event_values = array(
988
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
989
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
990
+			'EVT_additional_limit'            => min(
991
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
992
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
993
+			),
994
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
995
+				? $this->_req_data['EVT_default_registration_status']
996
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
997
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
998
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
999
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1000
+				? $this->_req_data['timezone_string'] : null,
1001
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1002
+				? $this->_req_data['externalURL'] : null,
1003
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1004
+				? $this->_req_data['event_phone'] : null,
1005
+		);
1006
+		//update event
1007
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1008
+		//get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1009
+		$get_one_where = array(
1010
+			$this->_event_model()->primary_key_name() => $post_id,
1011
+			'OR' => array(
1012
+				'status' => $post->post_status,
1013
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1014
+				// but the returned object here has a status of "publish", so use the original post status as well
1015
+				'status*1' => $this->_req_data['original_post_status'],
1016
+			)
1017
+		);
1018
+		$event = $this->_event_model()->get_one(array($get_one_where));
1019
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1020
+		$event_update_callbacks = apply_filters(
1021
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1022
+			array(
1023
+				array($this, '_default_venue_update'),
1024
+				array($this, '_default_tickets_update')
1025
+			)
1026
+		);
1027
+		$att_success = true;
1028
+		foreach ($event_update_callbacks as $e_callback) {
1029
+			$_success = $e_callback($event, $this->_req_data);
1030
+			//if ANY of these updates fail then we want the appropriate global error message
1031
+			$att_success = ! $att_success ? $att_success : $_success;
1032
+		}
1033
+		//any errors?
1034
+		if ($success && false === $att_success) {
1035
+			EE_Error::add_error(
1036
+				esc_html__(
1037
+					'Event Details saved successfully but something went wrong with saving attachments.',
1038
+					'event_espresso'
1039
+				),
1040
+				__FILE__,
1041
+				__FUNCTION__,
1042
+				__LINE__
1043
+			);
1044
+		} else if ($success === false) {
1045
+			EE_Error::add_error(
1046
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1047
+				__FILE__,
1048
+				__FUNCTION__,
1049
+				__LINE__
1050
+			);
1051
+		}
1052
+	}
1053
+
1054
+
1055
+
1056
+	/**
1057
+	 * @see parent::restore_item()
1058
+	 * @param int $post_id
1059
+	 * @param int $revision_id
1060
+	 */
1061
+	protected function _restore_cpt_item($post_id, $revision_id)
1062
+	{
1063
+		//copy existing event meta to new post
1064
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1065
+		if ($post_evt instanceof EE_Event) {
1066
+			//meta revision restore
1067
+			$post_evt->restore_revision($revision_id);
1068
+			//related objs restore
1069
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1070
+		}
1071
+	}
1072
+
1073
+
1074
+
1075
+	/**
1076
+	 * Attach the venue to the Event
1077
+	 *
1078
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1079
+	 * @param  array     $data   The request data from the form
1080
+	 * @return bool           Success or fail.
1081
+	 */
1082
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1083
+	{
1084
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1085
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1086
+		$rows_affected = null;
1087
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1088
+		// very important.  If we don't have a venue name...
1089
+		// then we'll get out because not necessary to create empty venue
1090
+		if (empty($data['venue_title'])) {
1091
+			return false;
1092
+		}
1093
+		$venue_array = array(
1094
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1095
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1096
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1097
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1098
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1099
+				: null,
1100
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1101
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1102
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1103
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1104
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1105
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1106
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1107
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1108
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1109
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1110
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1111
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1112
+			'status'              => 'publish',
1113
+		);
1114
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1115
+		if ( ! empty($venue_id)) {
1116
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1117
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1118
+			//we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1119
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1120
+			return $rows_affected > 0 ? true : false;
1121
+		} else {
1122
+			//we insert the venue
1123
+			$venue_id = $venue_model->insert($venue_array);
1124
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1125
+			return ! empty($venue_id) ? true : false;
1126
+		}
1127
+		//when we have the ancestor come in it's already been handled by the revision save.
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1134
+	 *
1135
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1136
+	 * @param  array    $data   The request data from the form
1137
+	 * @return array
1138
+	 */
1139
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1140
+	{
1141
+		$success = true;
1142
+		$saved_dtt = null;
1143
+		$saved_tickets = array();
1144
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1145
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1146
+			//trim all values to ensure any excess whitespace is removed.
1147
+			$dtt = array_map('trim', $dtt);
1148
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1149
+				: $dtt['DTT_EVT_start'];
1150
+			$datetime_values = array(
1151
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1152
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1153
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1154
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1155
+				'DTT_order'     => $row,
1156
+			);
1157
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1158
+			if ( ! empty($dtt['DTT_ID'])) {
1159
+				$DTM = EE_Registry::instance()
1160
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1161
+								  ->get_one_by_ID($dtt['DTT_ID']);
1162
+				$DTM->set_date_format($incoming_date_formats[0]);
1163
+				$DTM->set_time_format($incoming_date_formats[1]);
1164
+				foreach ($datetime_values as $field => $value) {
1165
+					$DTM->set($field, $value);
1166
+				}
1167
+				//make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1168
+				$saved_dtts[$DTM->ID()] = $DTM;
1169
+			} else {
1170
+				$DTM = EE_Registry::instance()->load_class(
1171
+					'Datetime',
1172
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1173
+					false,
1174
+					false
1175
+				);
1176
+				foreach ($datetime_values as $field => $value) {
1177
+					$DTM->set($field, $value);
1178
+				}
1179
+			}
1180
+			$DTM->save();
1181
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1182
+			//load DTT helper
1183
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1184
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1185
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1186
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1187
+				$DTT->save();
1188
+			}
1189
+			//now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1190
+			$saved_dtt = $DTT;
1191
+			$success = ! $success ? $success : $DTT;
1192
+			//if ANY of these updates fail then we want the appropriate global error message.
1193
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1194
+		}
1195
+		//no dtts get deleted so we don't do any of that logic here.
1196
+		//update tickets next
1197
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1198
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1199
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1200
+			$update_prices = false;
1201
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1202
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1203
+			// trim inputs to ensure any excess whitespace is removed.
1204
+			$tkt = array_map('trim', $tkt);
1205
+			if (empty($tkt['TKT_start_date'])) {
1206
+				//let's use now in the set timezone.
1207
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1208
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1209
+			}
1210
+			if (empty($tkt['TKT_end_date'])) {
1211
+				//use the start date of the first datetime
1212
+				$dtt = $evtobj->first_datetime();
1213
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1214
+					$incoming_date_formats[0],
1215
+					$incoming_date_formats[1]
1216
+				);
1217
+			}
1218
+			$TKT_values = array(
1219
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1220
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1221
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1222
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1223
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1224
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1225
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1226
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1227
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1228
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1229
+				'TKT_row'         => $row,
1230
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1231
+				'TKT_price'       => $ticket_price,
1232
+			);
1233
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1234
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1235
+				$TKT_values['TKT_ID'] = 0;
1236
+				$TKT_values['TKT_is_default'] = 0;
1237
+				$TKT_values['TKT_price'] = $ticket_price;
1238
+				$update_prices = true;
1239
+			}
1240
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1241
+			//we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1242
+			//keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1243
+			if ( ! empty($tkt['TKT_ID'])) {
1244
+				$TKT = EE_Registry::instance()
1245
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1246
+								  ->get_one_by_ID($tkt['TKT_ID']);
1247
+				if ($TKT instanceof EE_Ticket) {
1248
+					$ticket_sold = $TKT->count_related(
1249
+						'Registration',
1250
+						array(
1251
+							array(
1252
+								'STS_ID' => array(
1253
+									'NOT IN',
1254
+									array(EEM_Registration::status_id_incomplete),
1255
+								),
1256
+							),
1257
+						)
1258
+					) > 0 ? true : false;
1259
+					//let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1260
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1261
+									  && ! $TKT->get(
1262
+						'TKT_deleted'
1263
+					) ? true : false;
1264
+					$TKT->set_date_format($incoming_date_formats[0]);
1265
+					$TKT->set_time_format($incoming_date_formats[1]);
1266
+					//set new values
1267
+					foreach ($TKT_values as $field => $value) {
1268
+						if ($field == 'TKT_qty') {
1269
+							$TKT->set_qty($value);
1270
+						} else {
1271
+							$TKT->set($field, $value);
1272
+						}
1273
+					}
1274
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1275
+					if ($create_new_TKT) {
1276
+						//archive the old ticket first
1277
+						$TKT->set('TKT_deleted', 1);
1278
+						$TKT->save();
1279
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1280
+						$saved_tickets[$TKT->ID()] = $TKT;
1281
+						//create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1282
+						$TKT = clone $TKT;
1283
+						$TKT->set('TKT_ID', 0);
1284
+						$TKT->set('TKT_deleted', 0);
1285
+						$TKT->set('TKT_price', $ticket_price);
1286
+						$TKT->set('TKT_sold', 0);
1287
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1288
+						$update_prices = true;
1289
+					}
1290
+					//make sure price is set if it hasn't been already
1291
+					$TKT->set('TKT_price', $ticket_price);
1292
+				}
1293
+			} else {
1294
+				//no TKT_id so a new TKT
1295
+				$TKT_values['TKT_price'] = $ticket_price;
1296
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1297
+				if ($TKT instanceof EE_Ticket) {
1298
+					//need to reset values to properly account for the date formats
1299
+					$TKT->set_date_format($incoming_date_formats[0]);
1300
+					$TKT->set_time_format($incoming_date_formats[1]);
1301
+					$TKT->set_timezone($evtobj->get_timezone());
1302
+					//set new values
1303
+					foreach ($TKT_values as $field => $value) {
1304
+						if ($field == 'TKT_qty') {
1305
+							$TKT->set_qty($value);
1306
+						} else {
1307
+							$TKT->set($field, $value);
1308
+						}
1309
+					}
1310
+					$update_prices = true;
1311
+				}
1312
+			}
1313
+			// cap ticket qty by datetime reg limits
1314
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1315
+			//update ticket.
1316
+			$TKT->save();
1317
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1318
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1319
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1320
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1321
+				$TKT->save();
1322
+			}
1323
+			//initially let's add the ticket to the dtt
1324
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1325
+			$saved_tickets[$TKT->ID()] = $TKT;
1326
+			//add prices to ticket
1327
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1328
+		}
1329
+		//however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1330
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1331
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1332
+		foreach ($tickets_removed as $id) {
1333
+			$id = absint($id);
1334
+			//get the ticket for this id
1335
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1336
+			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1337
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1338
+			foreach ($dtts as $dtt) {
1339
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1340
+			}
1341
+			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1342
+			$tkt_to_remove->delete_related_permanently('Price');
1343
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1344
+			$tkt_to_remove->delete_permanently();
1345
+		}
1346
+		return array($saved_dtt, $saved_tickets);
1347
+	}
1348
+
1349
+
1350
+
1351
+	/**
1352
+	 * This attaches a list of given prices to a ticket.
1353
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1354
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1355
+	 * price info and prices are automatically "archived" via the ticket.
1356
+	 *
1357
+	 * @access  private
1358
+	 * @param array     $prices     Array of prices from the form.
1359
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1360
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1361
+	 * @return  void
1362
+	 */
1363
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1364
+	{
1365
+		foreach ($prices as $row => $prc) {
1366
+			$PRC_values = array(
1367
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1368
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1369
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1370
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1371
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1372
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1373
+				'PRC_order'      => $row,
1374
+			);
1375
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1376
+				$PRC_values['PRC_ID'] = 0;
1377
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1378
+			} else {
1379
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1380
+				//update this price with new values
1381
+				foreach ($PRC_values as $field => $newprc) {
1382
+					$PRC->set($field, $newprc);
1383
+				}
1384
+				$PRC->save();
1385
+			}
1386
+			$ticket->_add_relation_to($PRC, 'Price');
1387
+		}
1388
+	}
1389
+
1390
+
1391
+
1392
+	/**
1393
+	 * Add in our autosave ajax handlers
1394
+	 *
1395
+	 */
1396
+	protected function _ee_autosave_create_new()
1397
+	{
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * More autosave handlers.
1403
+	 */
1404
+	protected function _ee_autosave_edit()
1405
+	{
1406
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1407
+	}
1408
+
1409
+
1410
+
1411
+	/**
1412
+	 *    _generate_publish_box_extra_content
1413
+	 */
1414
+	private function _generate_publish_box_extra_content()
1415
+	{
1416
+		//load formatter helper
1417
+		//args for getting related registrations
1418
+		$approved_query_args = array(
1419
+			array(
1420
+				'REG_deleted' => 0,
1421
+				'STS_ID'      => EEM_Registration::status_id_approved,
1422
+			),
1423
+		);
1424
+		$not_approved_query_args = array(
1425
+			array(
1426
+				'REG_deleted' => 0,
1427
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1428
+			),
1429
+		);
1430
+		$pending_payment_query_args = array(
1431
+			array(
1432
+				'REG_deleted' => 0,
1433
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1434
+			),
1435
+		);
1436
+		// publish box
1437
+		$publish_box_extra_args = array(
1438
+			'view_approved_reg_url'        => add_query_arg(
1439
+				array(
1440
+					'action'      => 'default',
1441
+					'event_id'    => $this->_cpt_model_obj->ID(),
1442
+					'_reg_status' => EEM_Registration::status_id_approved,
1443
+				),
1444
+				REG_ADMIN_URL
1445
+			),
1446
+			'view_not_approved_reg_url'    => add_query_arg(
1447
+				array(
1448
+					'action'      => 'default',
1449
+					'event_id'    => $this->_cpt_model_obj->ID(),
1450
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1451
+				),
1452
+				REG_ADMIN_URL
1453
+			),
1454
+			'view_pending_payment_reg_url' => add_query_arg(
1455
+				array(
1456
+					'action'      => 'default',
1457
+					'event_id'    => $this->_cpt_model_obj->ID(),
1458
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1459
+				),
1460
+				REG_ADMIN_URL
1461
+			),
1462
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1463
+				'Registration',
1464
+				$approved_query_args
1465
+			),
1466
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1467
+				'Registration',
1468
+				$not_approved_query_args
1469
+			),
1470
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1471
+				'Registration',
1472
+				$pending_payment_query_args
1473
+			),
1474
+			'misc_pub_section_class'       => apply_filters(
1475
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1476
+				'misc-pub-section'
1477
+			),
1478
+		);
1479
+		ob_start();
1480
+		do_action(
1481
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1482
+			$this->_cpt_model_obj
1483
+		);
1484
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1485
+		// load template
1486
+		EEH_Template::display_template(
1487
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1488
+			$publish_box_extra_args
1489
+		);
1490
+	}
1491
+
1492
+
1493
+
1494
+	/**
1495
+	 * @return EE_Event
1496
+	 */
1497
+	public function get_event_object()
1498
+	{
1499
+		return $this->_cpt_model_obj;
1500
+	}
1501
+
1502
+
1503
+
1504
+
1505
+	/** METABOXES * */
1506
+	/**
1507
+	 * _register_event_editor_meta_boxes
1508
+	 * add all metaboxes related to the event_editor
1509
+	 *
1510
+	 * @return void
1511
+	 */
1512
+	protected function _register_event_editor_meta_boxes()
1513
+	{
1514
+		$this->verify_cpt_object();
1515
+		add_meta_box(
1516
+			'espresso_event_editor_tickets',
1517
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1518
+			array($this, 'ticket_metabox'),
1519
+			$this->page_slug,
1520
+			'normal',
1521
+			'high'
1522
+		);
1523
+		add_meta_box(
1524
+			'espresso_event_editor_event_options',
1525
+			esc_html__('Event Registration Options', 'event_espresso'),
1526
+			array($this, 'registration_options_meta_box'),
1527
+			$this->page_slug,
1528
+			'side',
1529
+			'default'
1530
+		);
1531
+		// NOTE: if you're looking for other metaboxes in here,
1532
+		// where a metabox has a related management page in the admin
1533
+		// you will find it setup in the related management page's "_Hooks" file.
1534
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1535
+	}
1536
+
1537
+
1538
+	/**
1539
+	 * @throws DomainException
1540
+	 * @throws EE_Error
1541
+	 */
1542
+	public function ticket_metabox()
1543
+	{
1544
+		$existing_datetime_ids = $existing_ticket_ids = array();
1545
+		//defaults for template args
1546
+		$template_args = array(
1547
+			'existing_datetime_ids'    => '',
1548
+			'event_datetime_help_link' => '',
1549
+			'ticket_options_help_link' => '',
1550
+			'time'                     => null,
1551
+			'ticket_rows'              => '',
1552
+			'existing_ticket_ids'      => '',
1553
+			'total_ticket_rows'        => 1,
1554
+			'ticket_js_structure'      => '',
1555
+			'trash_icon'               => 'ee-lock-icon',
1556
+			'disabled'                 => '',
1557
+		);
1558
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1559
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1560
+		/**
1561
+		 * 1. Start with retrieving Datetimes
1562
+		 * 2. Fore each datetime get related tickets
1563
+		 * 3. For each ticket get related prices
1564
+		 */
1565
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1566
+		/** @type EE_Datetime $first_datetime */
1567
+		$first_datetime = reset($times);
1568
+		//do we get related tickets?
1569
+		if ($first_datetime instanceof EE_Datetime
1570
+			&& $first_datetime->ID() !== 0
1571
+		) {
1572
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1573
+			$template_args['time'] = $first_datetime;
1574
+			$related_tickets = $first_datetime->tickets(
1575
+				array(
1576
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1577
+					'default_where_conditions' => 'none',
1578
+				)
1579
+			);
1580
+			if ( ! empty($related_tickets)) {
1581
+				$template_args['total_ticket_rows'] = count($related_tickets);
1582
+				$row = 0;
1583
+				foreach ($related_tickets as $ticket) {
1584
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1585
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1586
+					$row++;
1587
+				}
1588
+			} else {
1589
+				$template_args['total_ticket_rows'] = 1;
1590
+				/** @type EE_Ticket $ticket */
1591
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1592
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1593
+			}
1594
+		} else {
1595
+			$template_args['time'] = $times[0];
1596
+			/** @type EE_Ticket $ticket */
1597
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1598
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1599
+			// NOTE: we're just sending the first default row
1600
+			// (decaf can't manage default tickets so this should be sufficient);
1601
+		}
1602
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1603
+			'event_editor_event_datetimes_help_tab'
1604
+		);
1605
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1606
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1607
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1608
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1609
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1610
+			true
1611
+		);
1612
+		$template = apply_filters(
1613
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1614
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1615
+		);
1616
+		EEH_Template::display_template($template, $template_args);
1617
+	}
1618
+
1619
+
1620
+
1621
+	/**
1622
+	 * Setup an individual ticket form for the decaf event editor page
1623
+	 *
1624
+	 * @access private
1625
+	 * @param  EE_Ticket $ticket   the ticket object
1626
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1627
+	 * @param int        $row
1628
+	 * @return string generated html for the ticket row.
1629
+	 */
1630
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1631
+	{
1632
+		$template_args = array(
1633
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1634
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1635
+				: '',
1636
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1637
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1638
+			'TKT_name'            => $ticket->get('TKT_name'),
1639
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1640
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1641
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1642
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1643
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1644
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1645
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1646
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1647
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1648
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1649
+				: ' disabled=disabled',
1650
+		);
1651
+		$price = $ticket->ID() !== 0
1652
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1653
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1654
+		$price_args = array(
1655
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1656
+			'PRC_amount'            => $price->get('PRC_amount'),
1657
+			'PRT_ID'                => $price->get('PRT_ID'),
1658
+			'PRC_ID'                => $price->get('PRC_ID'),
1659
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1660
+		);
1661
+		//make sure we have default start and end dates if skeleton
1662
+		//handle rows that should NOT be empty
1663
+		if (empty($template_args['TKT_start_date'])) {
1664
+			//if empty then the start date will be now.
1665
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1666
+		}
1667
+		if (empty($template_args['TKT_end_date'])) {
1668
+			//get the earliest datetime (if present);
1669
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1670
+				? $this->_cpt_model_obj->get_first_related(
1671
+					'Datetime',
1672
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1673
+				)
1674
+				: null;
1675
+			if ( ! empty($earliest_dtt)) {
1676
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1677
+			} else {
1678
+				$template_args['TKT_end_date'] = date(
1679
+					'Y-m-d h:i a',
1680
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1681
+				);
1682
+			}
1683
+		}
1684
+		$template_args = array_merge($template_args, $price_args);
1685
+		$template = apply_filters(
1686
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1687
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1688
+			$ticket
1689
+		);
1690
+		return EEH_Template::display_template($template, $template_args, true);
1691
+	}
1692
+
1693
+
1694
+	/**
1695
+	 * @throws DomainException
1696
+	 */
1697
+	public function registration_options_meta_box()
1698
+	{
1699
+		$yes_no_values = array(
1700
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1701
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1702
+		);
1703
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1704
+			array(
1705
+				EEM_Registration::status_id_cancelled,
1706
+				EEM_Registration::status_id_declined,
1707
+				EEM_Registration::status_id_incomplete,
1708
+			),
1709
+			true
1710
+		);
1711
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1712
+		$template_args['_event'] = $this->_cpt_model_obj;
1713
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1714
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1715
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1716
+			'default_reg_status',
1717
+			$default_reg_status_values,
1718
+			$this->_cpt_model_obj->default_registration_status()
1719
+		);
1720
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1721
+			'display_desc',
1722
+			$yes_no_values,
1723
+			$this->_cpt_model_obj->display_description()
1724
+		);
1725
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1726
+			'display_ticket_selector',
1727
+			$yes_no_values,
1728
+			$this->_cpt_model_obj->display_ticket_selector(),
1729
+			'',
1730
+			'',
1731
+			false
1732
+		);
1733
+		$template_args['additional_registration_options'] = apply_filters(
1734
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1735
+			'',
1736
+			$template_args,
1737
+			$yes_no_values,
1738
+			$default_reg_status_values
1739
+		);
1740
+		EEH_Template::display_template(
1741
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1742
+			$template_args
1743
+		);
1744
+	}
1745
+
1746
+
1747
+
1748
+	/**
1749
+	 * _get_events()
1750
+	 * This method simply returns all the events (for the given _view and paging)
1751
+	 *
1752
+	 * @access public
1753
+	 * @param int  $per_page     count of items per page (20 default);
1754
+	 * @param int  $current_page what is the current page being viewed.
1755
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1756
+	 *                           If FALSE then we return an array of event objects
1757
+	 *                           that match the given _view and paging parameters.
1758
+	 * @return array an array of event objects.
1759
+	 */
1760
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1761
+	{
1762
+		$EEME = $this->_event_model();
1763
+		$offset = ($current_page - 1) * $per_page;
1764
+		$limit = $count ? null : $offset . ',' . $per_page;
1765
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1766
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1767
+		if (isset($this->_req_data['month_range'])) {
1768
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1769
+			//simulate the FIRST day of the month, that fixes issues for months like February
1770
+			//where PHP doesn't know what to assume for date.
1771
+			//@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1772
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1773
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1774
+		}
1775
+		$where = array();
1776
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1777
+		//determine what post_status our condition will have for the query.
1778
+		switch ($status) {
1779
+			case 'month' :
1780
+			case 'today' :
1781
+			case null :
1782
+			case 'all' :
1783
+				break;
1784
+			case 'draft' :
1785
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1786
+				break;
1787
+			default :
1788
+				$where['status'] = $status;
1789
+		}
1790
+		//categories?
1791
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1792
+			? $this->_req_data['EVT_CAT'] : null;
1793
+		if ( ! empty ($category)) {
1794
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1795
+			$where['Term_Taxonomy.term_id'] = $category;
1796
+		}
1797
+		//date where conditions
1798
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1799
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1800
+			$DateTime = new DateTime(
1801
+				$year_r . '-' . $month_r . '-01 00:00:00',
1802
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1803
+			);
1804
+			$start = $DateTime->format(implode(' ', $start_formats));
1805
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1806
+				->format('t'))->setTime(23, 59, 59)
1807
+							->format(implode(' ', $start_formats));
1808
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1809
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1810
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1811
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1812
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1813
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1814
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1815
+			$now = date('Y-m-01');
1816
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1817
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1818
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1819
+							->setTime(23, 59, 59)
1820
+							->format(implode(' ', $start_formats));
1821
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1822
+		}
1823
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1824
+			$where['EVT_wp_user'] = get_current_user_id();
1825
+		} else {
1826
+			if ( ! isset($where['status'])) {
1827
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1828
+					$where['OR'] = array(
1829
+						'status*restrict_private' => array('!=', 'private'),
1830
+						'AND'                     => array(
1831
+							'status*inclusive' => array('=', 'private'),
1832
+							'EVT_wp_user'      => get_current_user_id(),
1833
+						),
1834
+					);
1835
+				}
1836
+			}
1837
+		}
1838
+		if (isset($this->_req_data['EVT_wp_user'])) {
1839
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1840
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1841
+			) {
1842
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1843
+			}
1844
+		}
1845
+		//search query handling
1846
+		if (isset($this->_req_data['s'])) {
1847
+			$search_string = '%' . $this->_req_data['s'] . '%';
1848
+			$where['OR'] = array(
1849
+				'EVT_name'       => array('LIKE', $search_string),
1850
+				'EVT_desc'       => array('LIKE', $search_string),
1851
+				'EVT_short_desc' => array('LIKE', $search_string),
1852
+			);
1853
+		}
1854
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1855
+		$query_params = apply_filters(
1856
+			'FHEE__Events_Admin_Page__get_events__query_params',
1857
+			array(
1858
+				$where,
1859
+				'limit'    => $limit,
1860
+				'order_by' => $orderby,
1861
+				'order'    => $order,
1862
+				'group_by' => 'EVT_ID',
1863
+			),
1864
+			$this->_req_data
1865
+		);
1866
+		//let's first check if we have special requests coming in.
1867
+		if (isset($this->_req_data['active_status'])) {
1868
+			switch ($this->_req_data['active_status']) {
1869
+				case 'upcoming' :
1870
+					return $EEME->get_upcoming_events($query_params, $count);
1871
+					break;
1872
+				case 'expired' :
1873
+					return $EEME->get_expired_events($query_params, $count);
1874
+					break;
1875
+				case 'active' :
1876
+					return $EEME->get_active_events($query_params, $count);
1877
+					break;
1878
+				case 'inactive' :
1879
+					return $EEME->get_inactive_events($query_params, $count);
1880
+					break;
1881
+			}
1882
+		}
1883
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1884
+		return $events;
1885
+	}
1886
+
1887
+
1888
+
1889
+	/**
1890
+	 * handling for WordPress CPT actions (trash, restore, delete)
1891
+	 *
1892
+	 * @param string $post_id
1893
+	 */
1894
+	public function trash_cpt_item($post_id)
1895
+	{
1896
+		$this->_req_data['EVT_ID'] = $post_id;
1897
+		$this->_trash_or_restore_event('trash', false);
1898
+	}
1899
+
1900
+
1901
+
1902
+	/**
1903
+	 * @param string $post_id
1904
+	 */
1905
+	public function restore_cpt_item($post_id)
1906
+	{
1907
+		$this->_req_data['EVT_ID'] = $post_id;
1908
+		$this->_trash_or_restore_event('draft', false);
1909
+	}
1910
+
1911
+
1912
+
1913
+	/**
1914
+	 * @param string $post_id
1915
+	 */
1916
+	public function delete_cpt_item($post_id)
1917
+	{
1918
+		$this->_req_data['EVT_ID'] = $post_id;
1919
+		$this->_delete_event(false);
1920
+	}
1921
+
1922
+
1923
+
1924
+	/**
1925
+	 * _trash_or_restore_event
1926
+	 *
1927
+	 * @access protected
1928
+	 * @param  string $event_status
1929
+	 * @param bool    $redirect_after
1930
+	 */
1931
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1932
+	{
1933
+		//determine the event id and set to array.
1934
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1935
+		// loop thru events
1936
+		if ($EVT_ID) {
1937
+			// clean status
1938
+			$event_status = sanitize_key($event_status);
1939
+			// grab status
1940
+			if ( ! empty($event_status)) {
1941
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1942
+			} else {
1943
+				$success = false;
1944
+				$msg = esc_html__(
1945
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1946
+					'event_espresso'
1947
+				);
1948
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1949
+			}
1950
+		} else {
1951
+			$success = false;
1952
+			$msg = esc_html__(
1953
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1954
+				'event_espresso'
1955
+			);
1956
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1957
+		}
1958
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1959
+		if ($redirect_after) {
1960
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1961
+		}
1962
+	}
1963
+
1964
+
1965
+
1966
+	/**
1967
+	 * _trash_or_restore_events
1968
+	 *
1969
+	 * @access protected
1970
+	 * @param  string $event_status
1971
+	 * @return void
1972
+	 */
1973
+	protected function _trash_or_restore_events($event_status = 'trash')
1974
+	{
1975
+		// clean status
1976
+		$event_status = sanitize_key($event_status);
1977
+		// grab status
1978
+		if ( ! empty($event_status)) {
1979
+			$success = true;
1980
+			//determine the event id and set to array.
1981
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1982
+			// loop thru events
1983
+			foreach ($EVT_IDs as $EVT_ID) {
1984
+				if ($EVT_ID = absint($EVT_ID)) {
1985
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1986
+					$success = $results !== false ? $success : false;
1987
+				} else {
1988
+					$msg = sprintf(
1989
+						esc_html__(
1990
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1991
+							'event_espresso'
1992
+						),
1993
+						$EVT_ID
1994
+					);
1995
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1996
+					$success = false;
1997
+				}
1998
+			}
1999
+		} else {
2000
+			$success = false;
2001
+			$msg = esc_html__(
2002
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2003
+				'event_espresso'
2004
+			);
2005
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2006
+		}
2007
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2008
+		$success = $success ? 2 : false;
2009
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2010
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2011
+	}
2012
+
2013
+
2014
+
2015
+	/**
2016
+	 * _trash_or_restore_events
2017
+	 *
2018
+	 * @access  private
2019
+	 * @param  int    $EVT_ID
2020
+	 * @param  string $event_status
2021
+	 * @return bool
2022
+	 */
2023
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2024
+	{
2025
+		// grab event id
2026
+		if ( ! $EVT_ID) {
2027
+			$msg = esc_html__(
2028
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2029
+				'event_espresso'
2030
+			);
2031
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2032
+			return false;
2033
+		}
2034
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2035
+		// clean status
2036
+		$event_status = sanitize_key($event_status);
2037
+		// grab status
2038
+		if (empty($event_status)) {
2039
+			$msg = esc_html__(
2040
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2041
+				'event_espresso'
2042
+			);
2043
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2044
+			return false;
2045
+		}
2046
+		// was event trashed or restored ?
2047
+		switch ($event_status) {
2048
+			case 'draft' :
2049
+				$action = 'restored from the trash';
2050
+				$hook = 'AHEE_event_restored_from_trash';
2051
+				break;
2052
+			case 'trash' :
2053
+				$action = 'moved to the trash';
2054
+				$hook = 'AHEE_event_moved_to_trash';
2055
+				break;
2056
+			default :
2057
+				$action = 'updated';
2058
+				$hook = false;
2059
+		}
2060
+		//use class to change status
2061
+		$this->_cpt_model_obj->set_status($event_status);
2062
+		$success = $this->_cpt_model_obj->save();
2063
+		if ($success === false) {
2064
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2065
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2066
+			return false;
2067
+		}
2068
+		if ($hook) {
2069
+			do_action($hook);
2070
+		}
2071
+		return true;
2072
+	}
2073
+
2074
+
2075
+
2076
+	/**
2077
+	 * _delete_event
2078
+	 *
2079
+	 * @access protected
2080
+	 * @param bool $redirect_after
2081
+	 */
2082
+	protected function _delete_event($redirect_after = true)
2083
+	{
2084
+		//determine the event id and set to array.
2085
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2086
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2087
+		// loop thru events
2088
+		if ($EVT_ID) {
2089
+			$success = $this->_permanently_delete_event($EVT_ID);
2090
+			// get list of events with no prices
2091
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2092
+			// remove this event from the list of events with no prices
2093
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2094
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2095
+			}
2096
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2097
+		} else {
2098
+			$success = false;
2099
+			$msg = esc_html__(
2100
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2101
+				'event_espresso'
2102
+			);
2103
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2104
+		}
2105
+		if ($redirect_after) {
2106
+			$this->_redirect_after_action(
2107
+				$success,
2108
+				'Event',
2109
+				'deleted',
2110
+				array('action' => 'default', 'status' => 'trash')
2111
+			);
2112
+		}
2113
+	}
2114
+
2115
+
2116
+
2117
+	/**
2118
+	 * _delete_events
2119
+	 *
2120
+	 * @access protected
2121
+	 * @return void
2122
+	 */
2123
+	protected function _delete_events()
2124
+	{
2125
+		$success = true;
2126
+		// get list of events with no prices
2127
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2128
+		//determine the event id and set to array.
2129
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2130
+		// loop thru events
2131
+		foreach ($EVT_IDs as $EVT_ID) {
2132
+			$EVT_ID = absint($EVT_ID);
2133
+			if ($EVT_ID) {
2134
+				$results = $this->_permanently_delete_event($EVT_ID);
2135
+				$success = $results !== false ? $success : false;
2136
+				// remove this event from the list of events with no prices
2137
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2138
+			} else {
2139
+				$success = false;
2140
+				$msg = esc_html__(
2141
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2142
+					'event_espresso'
2143
+				);
2144
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
+			}
2146
+		}
2147
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2148
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2149
+		$success = $success ? 2 : false;
2150
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2151
+	}
2152
+
2153
+
2154
+
2155
+	/**
2156
+	 * _permanently_delete_event
2157
+	 *
2158
+	 * @access  private
2159
+	 * @param  int $EVT_ID
2160
+	 * @return bool
2161
+	 */
2162
+	private function _permanently_delete_event($EVT_ID = 0)
2163
+	{
2164
+		// grab event id
2165
+		if ( ! $EVT_ID) {
2166
+			$msg = esc_html__(
2167
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2168
+				'event_espresso'
2169
+			);
2170
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
+			return false;
2172
+		}
2173
+		if (
2174
+			! $this->_cpt_model_obj instanceof EE_Event
2175
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2176
+		) {
2177
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2178
+		}
2179
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2180
+			return false;
2181
+		}
2182
+		//need to delete related tickets and prices first.
2183
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2184
+		foreach ($datetimes as $datetime) {
2185
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2186
+			$tickets = $datetime->get_many_related('Ticket');
2187
+			foreach ($tickets as $ticket) {
2188
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2189
+				$ticket->delete_related_permanently('Price');
2190
+				$ticket->delete_permanently();
2191
+			}
2192
+			$datetime->delete();
2193
+		}
2194
+		//what about related venues or terms?
2195
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2196
+		foreach ($venues as $venue) {
2197
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2198
+		}
2199
+		//any attached question groups?
2200
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2201
+		if ( ! empty($question_groups)) {
2202
+			foreach ($question_groups as $question_group) {
2203
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2204
+			}
2205
+		}
2206
+		//Message Template Groups
2207
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2208
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2209
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2210
+		foreach ($term_taxonomies as $term_taxonomy) {
2211
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2212
+		}
2213
+		$success = $this->_cpt_model_obj->delete_permanently();
2214
+		// did it all go as planned ?
2215
+		if ($success) {
2216
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2217
+			EE_Error::add_success($msg);
2218
+		} else {
2219
+			$msg = sprintf(
2220
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2221
+				$EVT_ID
2222
+			);
2223
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2224
+			return false;
2225
+		}
2226
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2227
+		return true;
2228
+	}
2229
+
2230
+
2231
+
2232
+	/**
2233
+	 * get total number of events
2234
+	 *
2235
+	 * @access public
2236
+	 * @return int
2237
+	 */
2238
+	public function total_events()
2239
+	{
2240
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2241
+		return $count;
2242
+	}
2243
+
2244
+
2245
+
2246
+	/**
2247
+	 * get total number of draft events
2248
+	 *
2249
+	 * @access public
2250
+	 * @return int
2251
+	 */
2252
+	public function total_events_draft()
2253
+	{
2254
+		$where = array(
2255
+			'status' => array('IN', array('draft', 'auto-draft')),
2256
+		);
2257
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2258
+		return $count;
2259
+	}
2260
+
2261
+
2262
+
2263
+	/**
2264
+	 * get total number of trashed events
2265
+	 *
2266
+	 * @access public
2267
+	 * @return int
2268
+	 */
2269
+	public function total_trashed_events()
2270
+	{
2271
+		$where = array(
2272
+			'status' => 'trash',
2273
+		);
2274
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2275
+		return $count;
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 *    _default_event_settings
2281
+	 *    This generates the Default Settings Tab
2282
+	 *
2283
+	 * @return void
2284
+	 * @throws EE_Error
2285
+	 */
2286
+	protected function _default_event_settings()
2287
+	{
2288
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2289
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2290
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2291
+		$this->display_admin_page_with_sidebar();
2292
+	}
2293
+
2294
+
2295
+	/**
2296
+	 * Return the form for event settings.
2297
+	 * @return EE_Form_Section_Proper
2298
+	 */
2299
+	protected function _default_event_settings_form()
2300
+	{
2301
+		$registration_config = EE_Registry::instance()->CFG->registration;
2302
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2303
+		//exclude
2304
+			array(
2305
+				EEM_Registration::status_id_cancelled,
2306
+				EEM_Registration::status_id_declined,
2307
+				EEM_Registration::status_id_incomplete,
2308
+				EEM_Registration::status_id_wait_list,
2309
+			),
2310
+			true
2311
+		);
2312
+		return new EE_Form_Section_Proper(
2313
+			array(
2314
+				'name' => 'update_default_event_settings',
2315
+				'html_id' => 'update_default_event_settings',
2316
+				'html_class' => 'form-table',
2317
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2318
+				'subsections' => apply_filters(
2319
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2320
+					array(
2321
+						'default_reg_status' => new EE_Select_Input(
2322
+							$registration_stati_for_selection,
2323
+							array(
2324
+								'default' => isset($registration_config->default_STS_ID)
2325
+											 && array_key_exists(
2326
+												$registration_config->default_STS_ID,
2327
+												$registration_stati_for_selection
2328
+											 )
2329
+											? sanitize_text_field($registration_config->default_STS_ID)
2330
+											: EEM_Registration::status_id_pending_payment,
2331
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2332
+													. EEH_Template::get_help_tab_link(
2333
+														'default_settings_status_help_tab'
2334
+													),
2335
+								'html_help_text' => esc_html__(
2336
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2337
+									'event_espresso'
2338
+								)
2339
+							)
2340
+						),
2341
+						'default_max_tickets' => new EE_Integer_Input(
2342
+							array(
2343
+								'default' => isset($registration_config->default_maximum_number_of_tickets)
2344
+									? $registration_config->default_maximum_number_of_tickets
2345
+									: EEM_Event::get_default_additional_limit(),
2346
+								'html_label_text' => esc_html__(
2347
+									'Default Maximum Tickets Allowed Per Order:',
2348
+									'event_espresso'
2349
+								) . EEH_Template::get_help_tab_link(
2350
+									'default_maximum_tickets_help_tab"'
2351
+									),
2352
+								'html_help_text' => esc_html__(
2353
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2354
+									'event_espresso'
2355
+								)
2356
+							)
2357
+						)
2358
+					)
2359
+				)
2360
+			)
2361
+		);
2362
+	}
2363
+
2364
+
2365
+	/**
2366
+	 * _update_default_event_settings
2367
+	 *
2368
+	 * @access protected
2369
+	 * @return void
2370
+	 * @throws EE_Error
2371
+	 */
2372
+	protected function _update_default_event_settings()
2373
+	{
2374
+		$registration_config = EE_Registry::instance()->CFG->registration;
2375
+		$form = $this->_default_event_settings_form();
2376
+		if ($form->was_submitted()) {
2377
+			$form->receive_form_submission();
2378
+			if ($form->is_valid()) {
2379
+				$valid_data = $form->valid_data();
2380
+				if (isset($valid_data['default_reg_status'])) {
2381
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2382
+				}
2383
+				if (isset($valid_data['default_max_tickets'])) {
2384
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2385
+				}
2386
+				//update because data was valid!
2387
+				EE_Registry::instance()->CFG->update_espresso_config();
2388
+				EE_Error::overwrite_success();
2389
+				EE_Error::add_success(
2390
+					__('Default Event Settings were updated', 'event_espresso')
2391
+				);
2392
+			}
2393
+		}
2394
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2395
+	}
2396
+
2397
+
2398
+
2399
+	/*************        Templates        *************/
2400
+	protected function _template_settings()
2401
+	{
2402
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2403
+		$this->_template_args['preview_img'] = '<img src="'
2404
+											   . EVENTS_ASSETS_URL
2405
+											   . DS
2406
+											   . 'images'
2407
+											   . DS
2408
+											   . 'caffeinated_template_features.jpg" alt="'
2409
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2410
+											   . '" />';
2411
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2412
+				'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2413
+				'event_espresso'
2414
+			) . '</strong>';
2415
+		$this->display_admin_caf_preview_page('template_settings_tab');
2416
+	}
2417
+
2418
+
2419
+	/** Event Category Stuff **/
2420
+	/**
2421
+	 * set the _category property with the category object for the loaded page.
2422
+	 *
2423
+	 * @access private
2424
+	 * @return void
2425
+	 */
2426
+	private function _set_category_object()
2427
+	{
2428
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2429
+			return;
2430
+		} //already have the category object so get out.
2431
+		//set default category object
2432
+		$this->_set_empty_category_object();
2433
+		//only set if we've got an id
2434
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2435
+			return;
2436
+		}
2437
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2438
+		$term = get_term($category_id, 'espresso_event_categories');
2439
+		if ( ! empty($term)) {
2440
+			$this->_category->category_name = $term->name;
2441
+			$this->_category->category_identifier = $term->slug;
2442
+			$this->_category->category_desc = $term->description;
2443
+			$this->_category->id = $term->term_id;
2444
+			$this->_category->parent = $term->parent;
2445
+		}
2446
+	}
2447
+
2448
+
2449
+	/**
2450
+	 * Clears out category properties.
2451
+	 */
2452
+	private function _set_empty_category_object()
2453
+	{
2454
+		$this->_category = new stdClass();
2455
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2456
+		$this->_category->id = $this->_category->parent = 0;
2457
+	}
2458
+
2459
+
2460
+	/**
2461
+	 * @throws EE_Error
2462
+	 */
2463
+	protected function _category_list_table()
2464
+	{
2465
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2466
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2467
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2468
+				'add_category',
2469
+				'add_category',
2470
+				array(),
2471
+				'add-new-h2'
2472
+			);
2473
+		$this->display_admin_list_table_page_with_sidebar();
2474
+	}
2475
+
2476
+
2477
+
2478
+	/**
2479
+	 * Output category details view.
2480
+	 */
2481
+	protected function _category_details($view)
2482
+	{
2483
+		//load formatter helper
2484
+		//load field generator helper
2485
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2486
+		$this->_set_add_edit_form_tags($route);
2487
+		$this->_set_category_object();
2488
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2489
+		$delete_action = 'delete_category';
2490
+		//custom redirect
2491
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2492
+			array('action' => 'category_list'),
2493
+			$this->_admin_base_url
2494
+		);
2495
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2496
+		//take care of contents
2497
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2498
+		$this->display_admin_page_with_sidebar();
2499
+	}
2500
+
2501
+
2502
+
2503
+	/**
2504
+	 * Output category details content.
2505
+	 */
2506
+	protected function _category_details_content()
2507
+	{
2508
+		$editor_args['category_desc'] = array(
2509
+			'type'          => 'wp_editor',
2510
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2511
+			'class'         => 'my_editor_custom',
2512
+			'wpeditor_args' => array('media_buttons' => false),
2513
+		);
2514
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2515
+		$all_terms = get_terms(
2516
+			array('espresso_event_categories'),
2517
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2518
+		);
2519
+		//setup category select for term parents.
2520
+		$category_select_values[] = array(
2521
+			'text' => esc_html__('No Parent', 'event_espresso'),
2522
+			'id'   => 0,
2523
+		);
2524
+		foreach ($all_terms as $term) {
2525
+			$category_select_values[] = array(
2526
+				'text' => $term->name,
2527
+				'id'   => $term->term_id,
2528
+			);
2529
+		}
2530
+		$category_select = EEH_Form_Fields::select_input(
2531
+			'category_parent',
2532
+			$category_select_values,
2533
+			$this->_category->parent
2534
+		);
2535
+		$template_args = array(
2536
+			'category'                 => $this->_category,
2537
+			'category_select'          => $category_select,
2538
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2539
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2540
+			'disable'                  => '',
2541
+			'disabled_message'         => false,
2542
+		);
2543
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2544
+		return EEH_Template::display_template($template, $template_args, true);
2545
+	}
2546
+
2547
+
2548
+	/**
2549
+	 * Handles deleting categories.
2550
+	 */
2551
+	protected function _delete_categories()
2552
+	{
2553
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2554
+			: (array)$this->_req_data['category_id'];
2555
+		foreach ($cat_ids as $cat_id) {
2556
+			$this->_delete_category($cat_id);
2557
+		}
2558
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2559
+		$query_args = array(
2560
+			'action' => 'category_list',
2561
+		);
2562
+		$this->_redirect_after_action(0, '', '', $query_args);
2563
+	}
2564
+
2565
+
2566
+
2567
+	/**
2568
+	 * Handles deleting specific category.
2569
+	 * @param int $cat_id
2570
+	 */
2571
+	protected function _delete_category($cat_id)
2572
+	{
2573
+		$cat_id = absint($cat_id);
2574
+		wp_delete_term($cat_id, 'espresso_event_categories');
2575
+	}
2576
+
2577
+
2578
+
2579
+	/**
2580
+	 * Handles triggering the update or insertion of a new category.
2581
+	 * @param bool $new_category  true means we're triggering the insert of a new category.
2582
+	 */
2583
+	protected function _insert_or_update_category($new_category)
2584
+	{
2585
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2586
+		$success = 0; //we already have a success message so lets not send another.
2587
+		if ($cat_id) {
2588
+			$query_args = array(
2589
+				'action'     => 'edit_category',
2590
+				'EVT_CAT_ID' => $cat_id,
2591
+			);
2592
+		} else {
2593
+			$query_args = array('action' => 'add_category');
2594
+		}
2595
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2596
+	}
2597
+
2598
+
2599
+
2600
+	/**
2601
+	 * Inserts or updates category
2602
+	 * @param bool $update (true indicates we're updating a category).
2603
+	 * @return bool|mixed|string
2604
+	 */
2605
+	private function _insert_category($update = false)
2606
+	{
2607
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2608
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2609
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2610
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2611
+		if (empty($category_name)) {
2612
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2613
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2614
+			return false;
2615
+		}
2616
+		$term_args = array(
2617
+			'name'        => $category_name,
2618
+			'description' => $category_desc,
2619
+			'parent'      => $category_parent,
2620
+		);
2621
+		//was the category_identifier input disabled?
2622
+		if (isset($this->_req_data['category_identifier'])) {
2623
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2624
+		}
2625
+		$insert_ids = $update
2626
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2627
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2628
+		if ( ! is_array($insert_ids)) {
2629
+			$msg = esc_html__(
2630
+				'An error occurred and the category has not been saved to the database.',
2631
+				'event_espresso'
2632
+			);
2633
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2634
+		} else {
2635
+			$cat_id = $insert_ids['term_id'];
2636
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2637
+			EE_Error::add_success($msg);
2638
+		}
2639
+		return $cat_id;
2640
+	}
2641
+
2642
+
2643
+
2644
+	/**
2645
+	 * Gets categories or count of categories matching the arguments in the request.
2646
+	 * @param int  $per_page
2647
+	 * @param int  $current_page
2648
+	 * @param bool $count
2649
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2650
+	 */
2651
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2652
+	{
2653
+		//testing term stuff
2654
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2655
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2656
+		$limit = ($current_page - 1) * $per_page;
2657
+		$where = array('taxonomy' => 'espresso_event_categories');
2658
+		if (isset($this->_req_data['s'])) {
2659
+			$sstr = '%' . $this->_req_data['s'] . '%';
2660
+			$where['OR'] = array(
2661
+				'Term.name'   => array('LIKE', $sstr),
2662
+				'description' => array('LIKE', $sstr),
2663
+			);
2664
+		}
2665
+		$query_params = array(
2666
+			$where,
2667
+			'order_by'   => array($orderby => $order),
2668
+			'limit'      => $limit . ',' . $per_page,
2669
+			'force_join' => array('Term'),
2670
+		);
2671
+		$categories = $count
2672
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2673
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2674
+		return $categories;
2675
+	}
2676
+
2677
+	/* end category stuff */
2678
+	/**************/
2679
+
2680
+
2681
+	/**
2682
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2683
+	 * @throws EE_Error
2684
+	 */
2685
+	public function save_timezonestring_setting()
2686
+	{
2687
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2688
+			? $this->_req_data['timezone_selected']
2689
+			: '';
2690
+		if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2691
+		{
2692
+			EE_Error::add_error(
2693
+				esc_html('An invalid timezone string submitted.', 'event_espresso'),
2694
+				__FILE__, __FUNCTION__, __LINE__
2695
+			);
2696
+			$this->_template_args['error'] = true;
2697
+			$this->_return_json();
2698
+		}
2699
+
2700
+		update_option('timezone_string', $timezone_string);
2701
+		EE_Error::add_success(
2702
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2703
+		);
2704
+		$this->_template_args['success'] = true;
2705
+		$this->_return_json(true, array('action' => 'create_new'));
2706
+	}
2707 2707
 }
2708 2708
 //end class Events_Admin_Page
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
     {
554 554
         wp_register_style(
555 555
             'events-admin-css',
556
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
556
+            EVENTS_ASSETS_URL.'events-admin-page.css',
557 557
             array(),
558 558
             EVENT_ESPRESSO_VERSION
559 559
         );
560
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
560
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561 561
         wp_enqueue_style('events-admin-css');
562 562
         wp_enqueue_style('ee-cat-admin');
563 563
         //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         //scripts
566 566
         wp_register_script(
567 567
             'event_editor_js',
568
-            EVENTS_ASSETS_URL . 'event_editor.js',
568
+            EVENTS_ASSETS_URL.'event_editor.js',
569 569
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570 570
             EVENT_ESPRESSO_VERSION,
571 571
             true
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
         wp_enqueue_style('espresso-ui-theme');
594 594
         wp_register_style(
595 595
             'event-editor-css',
596
-            EVENTS_ASSETS_URL . 'event-editor.css',
596
+            EVENTS_ASSETS_URL.'event-editor.css',
597 597
             array('ee-admin-css'),
598 598
             EVENT_ESPRESSO_VERSION
599 599
         );
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
         //scripts
602 602
         wp_register_script(
603 603
             'event-datetime-metabox',
604
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
604
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
605 605
             array('event_editor_js', 'ee-datepicker'),
606 606
             EVENT_ESPRESSO_VERSION
607 607
         );
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
     public function verify_event_edit($event = null, $req_type = '')
671 671
     {
672 672
         // don't need to do this when processing
673
-        if(!empty($req_type)) {
673
+        if ( ! empty($req_type)) {
674 674
             return;
675 675
         }
676 676
         // no event?
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
             $event = $this->_cpt_model_obj;
680 680
         }
681 681
         // STILL no event?
682
-        if (! $event instanceof EE_Event) {
682
+        if ( ! $event instanceof EE_Event) {
683 683
             return;
684 684
         }
685 685
         $orig_status = $event->status();
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
     {
762 762
         $has_timezone_string = get_option('timezone_string');
763 763
         //only nag them about setting their timezone if it's their first event, and they haven't already done it
764
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
764
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
765 765
             EE_Error::add_attention(
766 766
                 sprintf(
767 767
                     __(
@@ -845,31 +845,31 @@  discard block
 block discarded – undo
845 845
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
846 846
         $statuses = array(
847 847
             'sold_out_status'  => array(
848
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
848
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
849 849
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
850 850
             ),
851 851
             'active_status'    => array(
852
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
852
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
853 853
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
854 854
             ),
855 855
             'upcoming_status'  => array(
856
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
856
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
857 857
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
858 858
             ),
859 859
             'postponed_status' => array(
860
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
860
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
861 861
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
862 862
             ),
863 863
             'cancelled_status' => array(
864
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
864
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
865 865
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
866 866
             ),
867 867
             'expired_status'   => array(
868
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
868
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
869 869
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
870 870
             ),
871 871
             'inactive_status'  => array(
872
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
872
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
873 873
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
874 874
             ),
875 875
         );
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
     {
932 932
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
933 933
         $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
934
-            ? (array)$this->_template_args['after_list_table']
934
+            ? (array) $this->_template_args['after_list_table']
935 935
             : array();
936 936
         $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
937 937
                                                                               . EEH_Template::get_button_or_link(
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
                 'button'
941 941
             );
942 942
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
943
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
943
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
944 944
                 'create_new',
945 945
                 'add',
946 946
                 array(),
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
      */
1082 1082
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1083 1083
     {
1084
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1084
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1085 1085
         $venue_model = EE_Registry::instance()->load_model('Venue');
1086 1086
         $rows_affected = null;
1087 1087
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1205,7 +1205,7 @@  discard block
 block discarded – undo
1205 1205
             if (empty($tkt['TKT_start_date'])) {
1206 1206
                 //let's use now in the set timezone.
1207 1207
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1208
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1208
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1209 1209
             }
1210 1210
             if (empty($tkt['TKT_end_date'])) {
1211 1211
                 //use the start date of the first datetime
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1485 1485
         // load template
1486 1486
         EEH_Template::display_template(
1487
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1487
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1488 1488
             $publish_box_extra_args
1489 1489
         );
1490 1490
     }
@@ -1611,7 +1611,7 @@  discard block
 block discarded – undo
1611 1611
         );
1612 1612
         $template = apply_filters(
1613 1613
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1614
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1614
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1615 1615
         );
1616 1616
         EEH_Template::display_template($template, $template_args);
1617 1617
     }
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1631 1631
     {
1632 1632
         $template_args = array(
1633
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1633
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1634 1634
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1635 1635
                 : '',
1636 1636
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1684,7 +1684,7 @@  discard block
 block discarded – undo
1684 1684
         $template_args = array_merge($template_args, $price_args);
1685 1685
         $template = apply_filters(
1686 1686
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1687
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1687
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1688 1688
             $ticket
1689 1689
         );
1690 1690
         return EEH_Template::display_template($template, $template_args, true);
@@ -1738,7 +1738,7 @@  discard block
 block discarded – undo
1738 1738
             $default_reg_status_values
1739 1739
         );
1740 1740
         EEH_Template::display_template(
1741
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1741
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1742 1742
             $template_args
1743 1743
         );
1744 1744
     }
@@ -1761,7 +1761,7 @@  discard block
 block discarded – undo
1761 1761
     {
1762 1762
         $EEME = $this->_event_model();
1763 1763
         $offset = ($current_page - 1) * $per_page;
1764
-        $limit = $count ? null : $offset . ',' . $per_page;
1764
+        $limit = $count ? null : $offset.','.$per_page;
1765 1765
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1766 1766
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1767 1767
         if (isset($this->_req_data['month_range'])) {
@@ -1798,7 +1798,7 @@  discard block
 block discarded – undo
1798 1798
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1799 1799
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1800 1800
             $DateTime = new DateTime(
1801
-                $year_r . '-' . $month_r . '-01 00:00:00',
1801
+                $year_r.'-'.$month_r.'-01 00:00:00',
1802 1802
                 new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1803 1803
             );
1804 1804
             $start = $DateTime->format(implode(' ', $start_formats));
@@ -1844,7 +1844,7 @@  discard block
 block discarded – undo
1844 1844
         }
1845 1845
         //search query handling
1846 1846
         if (isset($this->_req_data['s'])) {
1847
-            $search_string = '%' . $this->_req_data['s'] . '%';
1847
+            $search_string = '%'.$this->_req_data['s'].'%';
1848 1848
             $where['OR'] = array(
1849 1849
                 'EVT_name'       => array('LIKE', $search_string),
1850 1850
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1978,7 +1978,7 @@  discard block
 block discarded – undo
1978 1978
         if ( ! empty($event_status)) {
1979 1979
             $success = true;
1980 1980
             //determine the event id and set to array.
1981
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1981
+            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1982 1982
             // loop thru events
1983 1983
             foreach ($EVT_IDs as $EVT_ID) {
1984 1984
                 if ($EVT_ID = absint($EVT_ID)) {
@@ -2126,7 +2126,7 @@  discard block
 block discarded – undo
2126 2126
         // get list of events with no prices
2127 2127
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2128 2128
         //determine the event id and set to array.
2129
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2129
+        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2130 2130
         // loop thru events
2131 2131
         foreach ($EVT_IDs as $EVT_ID) {
2132 2132
             $EVT_ID = absint($EVT_ID);
@@ -2346,7 +2346,7 @@  discard block
 block discarded – undo
2346 2346
                                 'html_label_text' => esc_html__(
2347 2347
                                     'Default Maximum Tickets Allowed Per Order:',
2348 2348
                                     'event_espresso'
2349
-                                ) . EEH_Template::get_help_tab_link(
2349
+                                ).EEH_Template::get_help_tab_link(
2350 2350
                                     'default_maximum_tickets_help_tab"'
2351 2351
                                     ),
2352 2352
                                 'html_help_text' => esc_html__(
@@ -2408,10 +2408,10 @@  discard block
 block discarded – undo
2408 2408
                                                . 'caffeinated_template_features.jpg" alt="'
2409 2409
                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2410 2410
                                                . '" />';
2411
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2411
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__(
2412 2412
                 'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2413 2413
                 'event_espresso'
2414
-            ) . '</strong>';
2414
+            ).'</strong>';
2415 2415
         $this->display_admin_caf_preview_page('template_settings_tab');
2416 2416
     }
2417 2417
 
@@ -2464,7 +2464,7 @@  discard block
 block discarded – undo
2464 2464
     {
2465 2465
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2466 2466
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2467
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2467
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2468 2468
                 'add_category',
2469 2469
                 'add_category',
2470 2470
                 array(),
@@ -2540,7 +2540,7 @@  discard block
 block discarded – undo
2540 2540
             'disable'                  => '',
2541 2541
             'disabled_message'         => false,
2542 2542
         );
2543
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2543
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2544 2544
         return EEH_Template::display_template($template, $template_args, true);
2545 2545
     }
2546 2546
 
@@ -2550,8 +2550,8 @@  discard block
 block discarded – undo
2550 2550
      */
2551 2551
     protected function _delete_categories()
2552 2552
     {
2553
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2554
-            : (array)$this->_req_data['category_id'];
2553
+        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2554
+            : (array) $this->_req_data['category_id'];
2555 2555
         foreach ($cat_ids as $cat_id) {
2556 2556
             $this->_delete_category($cat_id);
2557 2557
         }
@@ -2656,7 +2656,7 @@  discard block
 block discarded – undo
2656 2656
         $limit = ($current_page - 1) * $per_page;
2657 2657
         $where = array('taxonomy' => 'espresso_event_categories');
2658 2658
         if (isset($this->_req_data['s'])) {
2659
-            $sstr = '%' . $this->_req_data['s'] . '%';
2659
+            $sstr = '%'.$this->_req_data['s'].'%';
2660 2660
             $where['OR'] = array(
2661 2661
                 'Term.name'   => array('LIKE', $sstr),
2662 2662
                 'description' => array('LIKE', $sstr),
@@ -2665,7 +2665,7 @@  discard block
 block discarded – undo
2665 2665
         $query_params = array(
2666 2666
             $where,
2667 2667
             'order_by'   => array($orderby => $order),
2668
-            'limit'      => $limit . ',' . $per_page,
2668
+            'limit'      => $limit.','.$per_page,
2669 2669
             'force_join' => array('Term'),
2670 2670
         );
2671 2671
         $categories = $count
@@ -2687,7 +2687,7 @@  discard block
 block discarded – undo
2687 2687
         $timezone_string = isset($this->_req_data['timezone_selected'])
2688 2688
             ? $this->_req_data['timezone_selected']
2689 2689
             : '';
2690
-        if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2690
+        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2691 2691
         {
2692 2692
             EE_Error::add_error(
2693 2693
                 esc_html('An invalid timezone string submitted.', 'event_espresso'),
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3427 added lines, -3427 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -23,2113 +23,2113 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
-            ? $this->_req_data['ATT_ID'] : 0;
171
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
-            ? $this->_req_data['post']
173
-            : $att_id;
174
-        $this->_page_routes = array(
175
-            'default'                            => array(
176
-                'func'       => '_registrations_overview_list_table',
177
-                'capability' => 'ee_read_registrations',
178
-            ),
179
-            'view_registration'                  => array(
180
-                'func'       => '_registration_details',
181
-                'capability' => 'ee_read_registration',
182
-                'obj_id'     => $reg_id,
183
-            ),
184
-            'edit_registration'                  => array(
185
-                'func'               => '_update_attendee_registration_form',
186
-                'noheader'           => true,
187
-                'headers_sent_route' => 'view_registration',
188
-                'capability'         => 'ee_edit_registration',
189
-                'obj_id'             => $reg_id,
190
-                '_REG_ID'            => $reg_id,
191
-            ),
192
-            'trash_registrations'                => array(
193
-                'func'       => '_trash_or_restore_registrations',
194
-                'args'       => array('trash' => true),
195
-                'noheader'   => true,
196
-                'capability' => 'ee_delete_registrations',
197
-            ),
198
-            'restore_registrations'              => array(
199
-                'func'       => '_trash_or_restore_registrations',
200
-                'args'       => array('trash' => false),
201
-                'noheader'   => true,
202
-                'capability' => 'ee_delete_registrations',
203
-            ),
204
-            'delete_registrations'               => array(
205
-                'func'       => '_delete_registrations',
206
-                'noheader'   => true,
207
-                'capability' => 'ee_delete_registrations',
208
-            ),
209
-            'new_registration'                   => array(
210
-                'func'       => 'new_registration',
211
-                'capability' => 'ee_edit_registrations',
212
-            ),
213
-            'process_reg_step'                   => array(
214
-                'func'       => 'process_reg_step',
215
-                'noheader'   => true,
216
-                'capability' => 'ee_edit_registrations',
217
-            ),
218
-            'redirect_to_txn'                    => array(
219
-                'func'       => 'redirect_to_txn',
220
-                'noheader'   => true,
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'change_reg_status'                  => array(
224
-                'func'       => '_change_reg_status',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registration',
227
-                'obj_id'     => $reg_id,
228
-            ),
229
-            'approve_registration'               => array(
230
-                'func'       => 'approve_registration',
231
-                'noheader'   => true,
232
-                'capability' => 'ee_edit_registration',
233
-                'obj_id'     => $reg_id,
234
-            ),
235
-            'approve_and_notify_registration'    => array(
236
-                'func'       => 'approve_registration',
237
-                'noheader'   => true,
238
-                'args'       => array(true),
239
-                'capability' => 'ee_edit_registration',
240
-                'obj_id'     => $reg_id,
241
-            ),
242
-            'decline_registration'               => array(
243
-                'func'       => 'decline_registration',
244
-                'noheader'   => true,
245
-                'capability' => 'ee_edit_registration',
246
-                'obj_id'     => $reg_id,
247
-            ),
248
-            'decline_and_notify_registration'    => array(
249
-                'func'       => 'decline_registration',
250
-                'noheader'   => true,
251
-                'args'       => array(true),
252
-                'capability' => 'ee_edit_registration',
253
-                'obj_id'     => $reg_id,
254
-            ),
255
-            'pending_registration'               => array(
256
-                'func'       => 'pending_registration',
257
-                'noheader'   => true,
258
-                'capability' => 'ee_edit_registration',
259
-                'obj_id'     => $reg_id,
260
-            ),
261
-            'pending_and_notify_registration'    => array(
262
-                'func'       => 'pending_registration',
263
-                'noheader'   => true,
264
-                'args'       => array(true),
265
-                'capability' => 'ee_edit_registration',
266
-                'obj_id'     => $reg_id,
267
-            ),
268
-            'no_approve_registration'            => array(
269
-                'func'       => 'not_approve_registration',
270
-                'noheader'   => true,
271
-                'capability' => 'ee_edit_registration',
272
-                'obj_id'     => $reg_id,
273
-            ),
274
-            'no_approve_and_notify_registration' => array(
275
-                'func'       => 'not_approve_registration',
276
-                'noheader'   => true,
277
-                'args'       => array(true),
278
-                'capability' => 'ee_edit_registration',
279
-                'obj_id'     => $reg_id,
280
-            ),
281
-            'cancel_registration'                => array(
282
-                'func'       => 'cancel_registration',
283
-                'noheader'   => true,
284
-                'capability' => 'ee_edit_registration',
285
-                'obj_id'     => $reg_id,
286
-            ),
287
-            'cancel_and_notify_registration'     => array(
288
-                'func'       => 'cancel_registration',
289
-                'noheader'   => true,
290
-                'args'       => array(true),
291
-                'capability' => 'ee_edit_registration',
292
-                'obj_id'     => $reg_id,
293
-            ),
294
-            'wait_list_registration' => array(
295
-                'func'       => 'wait_list_registration',
296
-                'noheader'   => true,
297
-                'capability' => 'ee_edit_registration',
298
-                'obj_id'     => $reg_id,
299
-            ),
300
-            'contact_list'                       => array(
301
-                'func'       => '_attendee_contact_list_table',
302
-                'capability' => 'ee_read_contacts',
303
-            ),
304
-            'add_new_attendee'                   => array(
305
-                'func' => '_create_new_cpt_item',
306
-                'args' => array(
307
-                    'new_attendee' => true,
308
-                    'capability'   => 'ee_edit_contacts',
309
-                ),
310
-            ),
311
-            'edit_attendee'                      => array(
312
-                'func'       => '_edit_cpt_item',
313
-                'capability' => 'ee_edit_contacts',
314
-                'obj_id'     => $att_id,
315
-            ),
316
-            'duplicate_attendee'                 => array(
317
-                'func'       => '_duplicate_attendee',
318
-                'noheader'   => true,
319
-                'capability' => 'ee_edit_contacts',
320
-                'obj_id'     => $att_id,
321
-            ),
322
-            'insert_attendee'                    => array(
323
-                'func'       => '_insert_or_update_attendee',
324
-                'args'       => array(
325
-                    'new_attendee' => true,
326
-                ),
327
-                'noheader'   => true,
328
-                'capability' => 'ee_edit_contacts',
329
-            ),
330
-            'update_attendee'                    => array(
331
-                'func'       => '_insert_or_update_attendee',
332
-                'args'       => array(
333
-                    'new_attendee' => false,
334
-                ),
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_contacts',
337
-                'obj_id'     => $att_id,
338
-            ),
339
-            'trash_attendee'                    => array(
340
-                'func'       => '_trash_or_restore_attendees',
341
-                'args'       => array(
342
-                    'trash' => true,
343
-                ),
344
-                'noheader'   => true,
345
-                'capability' => 'ee_delete_contacts',
346
-                'obj_id'     => $att_id,
347
-            ),
348
-            'restore_attendees'                  => array(
349
-                'func'       => '_trash_or_restore_attendees',
350
-                'args'       => array(
351
-                    'trash' => false,
352
-                ),
353
-                'noheader'   => true,
354
-                'capability' => 'ee_delete_contacts',
355
-                'obj_id'     => $att_id,
356
-            ),
357
-            'resend_registration'                => array(
358
-                'func'       => '_resend_registration',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_send_message',
361
-            ),
362
-            'registrations_report'               => array(
363
-                'func'       => '_registrations_report',
364
-                'noheader'   => true,
365
-                'capability' => 'ee_read_registrations',
366
-            ),
367
-            'contact_list_export'                => array(
368
-                'func'       => '_contact_list_export',
369
-                'noheader'   => true,
370
-                'capability' => 'export',
371
-            ),
372
-            'contact_list_report'                => array(
373
-                'func'       => '_contact_list_report',
374
-                'noheader'   => true,
375
-                'capability' => 'ee_read_contacts',
376
-            ),
377
-        );
378
-    }
379
-
380
-
381
-    protected function _set_page_config()
382
-    {
383
-        $this->_page_config = array(
384
-            'default'           => array(
385
-                'nav'           => array(
386
-                    'label' => esc_html__('Overview', 'event_espresso'),
387
-                    'order' => 5,
388
-                ),
389
-                'help_tabs'     => array(
390
-                    'registrations_overview_help_tab'                       => array(
391
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
392
-                        'filename' => 'registrations_overview',
393
-                    ),
394
-                    'registrations_overview_table_column_headings_help_tab' => array(
395
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
396
-                        'filename' => 'registrations_overview_table_column_headings',
397
-                    ),
398
-                    'registrations_overview_filters_help_tab'               => array(
399
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
400
-                        'filename' => 'registrations_overview_filters',
401
-                    ),
402
-                    'registrations_overview_views_help_tab'                 => array(
403
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
404
-                        'filename' => 'registrations_overview_views',
405
-                    ),
406
-                    'registrations_regoverview_other_help_tab'              => array(
407
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
408
-                        'filename' => 'registrations_overview_other',
409
-                    ),
410
-                ),
411
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
412
-                'qtips'         => array('Registration_List_Table_Tips'),
413
-                'list_table'    => 'EE_Registrations_List_Table',
414
-                'require_nonce' => false,
415
-            ),
416
-            'view_registration' => array(
417
-                'nav'           => array(
418
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
419
-                    'order'      => 15,
420
-                    'url'        => isset($this->_req_data['_REG_ID'])
421
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
422
-                        : $this->_admin_base_url,
423
-                    'persistent' => false,
424
-                ),
425
-                'help_tabs'     => array(
426
-                    'registrations_details_help_tab'                    => array(
427
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
428
-                        'filename' => 'registrations_details',
429
-                    ),
430
-                    'registrations_details_table_help_tab'              => array(
431
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
432
-                        'filename' => 'registrations_details_table',
433
-                    ),
434
-                    'registrations_details_form_answers_help_tab'       => array(
435
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
436
-                        'filename' => 'registrations_details_form_answers',
437
-                    ),
438
-                    'registrations_details_registrant_details_help_tab' => array(
439
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
440
-                        'filename' => 'registrations_details_registrant_details',
441
-                    ),
442
-                ),
443
-                'help_tour'     => array('Registration_Details_Help_Tour'),
444
-                'metaboxes'     => array_merge(
445
-                    $this->_default_espresso_metaboxes,
446
-                    array('_registration_details_metaboxes')
447
-                ),
448
-                'require_nonce' => false,
449
-            ),
450
-            'new_registration'  => array(
451
-                'nav'           => array(
452
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
453
-                    'url'        => '#',
454
-                    'order'      => 15,
455
-                    'persistent' => false,
456
-                ),
457
-                'metaboxes'     => $this->_default_espresso_metaboxes,
458
-                'labels'        => array(
459
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
460
-                ),
461
-                'require_nonce' => false,
462
-            ),
463
-            'add_new_attendee'  => array(
464
-                'nav'           => array(
465
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
466
-                    'order'      => 15,
467
-                    'persistent' => false,
468
-                ),
469
-                'metaboxes'     => array_merge(
470
-                    $this->_default_espresso_metaboxes,
471
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
472
-                ),
473
-                'require_nonce' => false,
474
-            ),
475
-            'edit_attendee'     => array(
476
-                'nav'           => array(
477
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
478
-                    'order'      => 15,
479
-                    'persistent' => false,
480
-                    'url'        => isset($this->_req_data['ATT_ID'])
481
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
482
-                        : $this->_admin_base_url,
483
-                ),
484
-                'metaboxes'     => array('attendee_editor_metaboxes'),
485
-                'require_nonce' => false,
486
-            ),
487
-            'contact_list'      => array(
488
-                'nav'           => array(
489
-                    'label' => esc_html__('Contact List', 'event_espresso'),
490
-                    'order' => 20,
491
-                ),
492
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
493
-                'help_tabs'     => array(
494
-                    'registrations_contact_list_help_tab'                       => array(
495
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
496
-                        'filename' => 'registrations_contact_list',
497
-                    ),
498
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
499
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
500
-                        'filename' => 'registrations_contact_list_table_column_headings',
501
-                    ),
502
-                    'registrations_contact_list_views_help_tab'                 => array(
503
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
504
-                        'filename' => 'registrations_contact_list_views',
505
-                    ),
506
-                    'registrations_contact_list_other_help_tab'                 => array(
507
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
508
-                        'filename' => 'registrations_contact_list_other',
509
-                    ),
510
-                ),
511
-                'help_tour'     => array('Contact_List_Help_Tour'),
512
-                'metaboxes'     => array(),
513
-                'require_nonce' => false,
514
-            ),
515
-            //override default cpt routes
516
-            'create_new'        => '',
517
-            'edit'              => '',
518
-        );
519
-    }
520
-
521
-
522
-    /**
523
-     * The below methods aren't used by this class currently
524
-     */
525
-    protected function _add_screen_options()
526
-    {
527
-    }
528
-
529
-
530
-    protected function _add_feature_pointers()
531
-    {
532
-    }
533
-
534
-
535
-    public function admin_init()
536
-    {
537
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
538
-            'click "Update Registration Questions" to save your changes',
539
-            'event_espresso'
540
-        );
541
-    }
542
-
543
-
544
-    public function admin_notices()
545
-    {
546
-    }
547
-
548
-
549
-    public function admin_footer_scripts()
550
-    {
551
-    }
552
-
553
-
554
-    /**
555
-     *        get list of registration statuses
556
-     *
557
-     * @access private
558
-     * @return void
559
-     */
560
-    private function _get_registration_status_array()
561
-    {
562
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
563
-    }
564
-
565
-
566
-    protected function _add_screen_options_default()
567
-    {
568
-        $this->_per_page_screen_option();
569
-    }
570
-
571
-
572
-    protected function _add_screen_options_contact_list()
573
-    {
574
-        $page_title              = $this->_admin_page_title;
575
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
576
-        $this->_per_page_screen_option();
577
-        $this->_admin_page_title = $page_title;
578
-    }
579
-
580
-
581
-    public function load_scripts_styles()
582
-    {
583
-        //style
584
-        wp_register_style(
585
-            'espresso_reg',
586
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
587
-            array('ee-admin-css'),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_enqueue_style('espresso_reg');
591
-        //script
592
-        wp_register_script(
593
-            'espresso_reg',
594
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
595
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
596
-            EVENT_ESPRESSO_VERSION,
597
-            true
598
-        );
599
-        wp_enqueue_script('espresso_reg');
600
-    }
601
-
602
-
603
-    public function load_scripts_styles_edit_attendee()
604
-    {
605
-        //stuff to only show up on our attendee edit details page.
606
-        $attendee_details_translations = array(
607
-            'att_publish_text' => sprintf(
608
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
609
-                $this->_cpt_model_obj->get_datetime('ATT_created')
610
-            ),
611
-        );
612
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
613
-        wp_enqueue_script('jquery-validate');
614
-    }
615
-
616
-
617
-    public function load_scripts_styles_view_registration()
618
-    {
619
-        //styles
620
-        wp_enqueue_style('espresso-ui-theme');
621
-        //scripts
622
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
623
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
624
-    }
625
-
626
-
627
-    public function load_scripts_styles_contact_list()
628
-    {
629
-        wp_deregister_style('espresso_reg');
630
-        wp_register_style(
631
-            'espresso_att',
632
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
633
-            array('ee-admin-css'),
634
-            EVENT_ESPRESSO_VERSION
635
-        );
636
-        wp_enqueue_style('espresso_att');
637
-    }
638
-
639
-
640
-    public function load_scripts_styles_new_registration()
641
-    {
642
-        wp_register_script(
643
-            'ee-spco-for-admin',
644
-            REG_ASSETS_URL . 'spco_for_admin.js',
645
-            array('underscore', 'jquery'),
646
-            EVENT_ESPRESSO_VERSION,
647
-            true
648
-        );
649
-        wp_enqueue_script('ee-spco-for-admin');
650
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
651
-        EE_Form_Section_Proper::wp_enqueue_scripts();
652
-        EED_Ticket_Selector::load_tckt_slctr_assets();
653
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
654
-    }
655
-
656
-
657
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
658
-    {
659
-        add_filter('FHEE_load_EE_messages', '__return_true');
660
-    }
661
-
662
-
663
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
664
-    {
665
-        add_filter('FHEE_load_EE_messages', '__return_true');
666
-    }
667
-
668
-
669
-    protected function _set_list_table_views_default()
670
-    {
671
-        //for notification related bulk actions we need to make sure only active messengers have an option.
672
-        EED_Messages::set_autoloaders();
673
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
674
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
675
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
676
-        //key= bulk_action_slug, value= message type.
677
-        $match_array = array(
678
-            'approve_registration'    => 'registration',
679
-            'decline_registration'    => 'declined_registration',
680
-            'pending_registration'    => 'pending_approval',
681
-            'no_approve_registration' => 'not_approved_registration',
682
-            'cancel_registration'     => 'cancelled_registration',
683
-        );
684
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
685
-            'ee_send_message',
686
-            'batch_send_messages'
687
-        );
688
-        /** setup reg status bulk actions **/
689
-        $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
690
-        if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) {
691
-                $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
692
-                    'event_espresso');
693
-        }
694
-        $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
695
-        if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) {
696
-                $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
697
-                    'event_espresso');
698
-        }
699
-        $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
700
-        if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) {
701
-                $def_reg_status_actions['pending_and_notify_registration'] = __(
702
-                    'Set Registrations to Pending Payment and Notify',
703
-                    'event_espresso'
704
-                );
705
-        }
706
-        $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
707
-        if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) {
708
-                $def_reg_status_actions['no_approve_and_notify_registration'] = __(
709
-                    'Set Registrations to Not Approved and Notify',
710
-                    'event_espresso'
711
-                );
712
-        }
713
-        $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
714
-        if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) {
715
-                $def_reg_status_actions['cancel_and_notify_registration'] = __(
716
-                    'Cancel Registrations and Notify',
717
-                    'event_espresso'
718
-                );
719
-        }
720
-        $def_reg_status_actions = apply_filters(
721
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
722
-            $def_reg_status_actions,
723
-            $active_mts
724
-        );
725
-
726
-        $this->_views = array(
727
-            'all'   => array(
728
-                'slug'        => 'all',
729
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
730
-                'count'       => 0,
731
-                'bulk_action' => array_merge($def_reg_status_actions, array(
732
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
733
-                )),
734
-            ),
735
-            'month' => array(
736
-                'slug'        => 'month',
737
-                'label'       => esc_html__('This Month', 'event_espresso'),
738
-                'count'       => 0,
739
-                'bulk_action' => array_merge($def_reg_status_actions, array(
740
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
741
-                )),
742
-            ),
743
-            'today' => array(
744
-                'slug'        => 'today',
745
-                'label'       => sprintf(
746
-                    esc_html__('Today - %s', 'event_espresso'),
747
-                    date('M d, Y', current_time('timestamp'))
748
-                ),
749
-                'count'       => 0,
750
-                'bulk_action' => array_merge($def_reg_status_actions, array(
751
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
752
-                )),
753
-            ),
754
-        );
755
-        if (EE_Registry::instance()->CAP->current_user_can(
756
-            'ee_delete_registrations',
757
-            'espresso_registrations_delete_registration'
758
-        )) {
759
-            $this->_views['incomplete'] = array(
760
-                'slug'        => 'incomplete',
761
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
762
-                'count'       => 0,
763
-                'bulk_action' => array(
764
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
765
-                ),
766
-            );
767
-            $this->_views['trash']      = array(
768
-                'slug'        => 'trash',
769
-                'label'       => esc_html__('Trash', 'event_espresso'),
770
-                'count'       => 0,
771
-                'bulk_action' => array(
772
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
773
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
774
-                ),
775
-            );
776
-        }
777
-    }
778
-
779
-
780
-    protected function _set_list_table_views_contact_list()
781
-    {
782
-        $this->_views = array(
783
-            'in_use' => array(
784
-                'slug'        => 'in_use',
785
-                'label'       => esc_html__('In Use', 'event_espresso'),
786
-                'count'       => 0,
787
-                'bulk_action' => array(
788
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
789
-                ),
790
-            ),
791
-        );
792
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
793
-            'espresso_registrations_trash_attendees')
794
-        ) {
795
-            $this->_views['trash'] = array(
796
-                'slug'        => 'trash',
797
-                'label'       => esc_html__('Trash', 'event_espresso'),
798
-                'count'       => 0,
799
-                'bulk_action' => array(
800
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
801
-                ),
802
-            );
803
-        }
804
-    }
805
-
806
-
807
-    protected function _registration_legend_items()
808
-    {
809
-        $fc_items = array(
810
-            'star-icon'        => array(
811
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
812
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
813
-            ),
814
-            'view_details'     => array(
815
-                'class' => 'dashicons dashicons-clipboard',
816
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
817
-            ),
818
-            'edit_attendee'    => array(
819
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
820
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
821
-            ),
822
-            'view_transaction' => array(
823
-                'class' => 'dashicons dashicons-cart',
824
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
825
-            ),
826
-            'view_invoice'     => array(
827
-                'class' => 'dashicons dashicons-media-spreadsheet',
828
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
829
-            ),
830
-        );
831
-        if (EE_Registry::instance()->CAP->current_user_can(
832
-            'ee_send_message',
833
-            'espresso_registrations_resend_registration'
834
-        )) {
835
-            $fc_items['resend_registration'] = array(
836
-                'class' => 'dashicons dashicons-email-alt',
837
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
838
-            );
839
-        } else {
840
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
841
-        }
842
-        if (EE_Registry::instance()->CAP->current_user_can(
843
-            'ee_read_global_messages',
844
-            'view_filtered_messages'
845
-        )) {
846
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
847
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
848
-                $fc_items['view_related_messages'] = array(
849
-                    'class' => $related_for_icon['css_class'],
850
-                    'desc'  => $related_for_icon['label'],
851
-                );
852
-            }
853
-        }
854
-        $sc_items = array(
855
-            'approved_status'   => array(
856
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
857
-                'desc'  => EEH_Template::pretty_status(
858
-                    EEM_Registration::status_id_approved,
859
-                    false,
860
-                    'sentence'
861
-                ),
862
-            ),
863
-            'pending_status'    => array(
864
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
865
-                'desc'  => EEH_Template::pretty_status(
866
-                    EEM_Registration::status_id_pending_payment,
867
-                    false,
868
-                    'sentence'
869
-                ),
870
-            ),
871
-            'wait_list'         => array(
872
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
873
-                'desc'  => EEH_Template::pretty_status(
874
-                    EEM_Registration::status_id_wait_list,
875
-                    false,
876
-                    'sentence'
877
-                ),
878
-            ),
879
-            'incomplete_status' => array(
880
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
881
-                'desc'  => EEH_Template::pretty_status(
882
-                    EEM_Registration::status_id_incomplete,
883
-                    false,
884
-                    'sentence'
885
-                ),
886
-            ),
887
-            'not_approved'      => array(
888
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
889
-                'desc'  => EEH_Template::pretty_status(
890
-                    EEM_Registration::status_id_not_approved,
891
-                    false,
892
-                    'sentence'
893
-                ),
894
-            ),
895
-            'declined_status'   => array(
896
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
897
-                'desc'  => EEH_Template::pretty_status(
898
-                    EEM_Registration::status_id_declined,
899
-                    false,
900
-                    'sentence'
901
-                ),
902
-            ),
903
-            'cancelled_status'  => array(
904
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
905
-                'desc'  => EEH_Template::pretty_status(
906
-                    EEM_Registration::status_id_cancelled,
907
-                    false,
908
-                    'sentence'
909
-                ),
910
-            ),
911
-        );
912
-        return array_merge($fc_items, $sc_items);
913
-    }
914
-
915
-
916
-
917
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
918
-    /**
919
-     * @throws \EE_Error
920
-     */
921
-    protected function _registrations_overview_list_table()
922
-    {
923
-        $this->_template_args['admin_page_header'] = '';
924
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
925
-            ? absint($this->_req_data['event_id'])
926
-            : 0;
927
-        if ($EVT_ID) {
928
-            if (EE_Registry::instance()->CAP->current_user_can(
929
-                'ee_edit_registrations',
930
-                'espresso_registrations_new_registration',
931
-                $EVT_ID
932
-            )) {
933
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
934
-                    'new_registration',
935
-                    'add-registrant',
936
-                    array('event_id' => $EVT_ID),
937
-                    'add-new-h2'
938
-                );
939
-            }
940
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
941
-            if ($event instanceof EE_Event) {
942
-                $this->_template_args['admin_page_header'] = sprintf(
943
-                    esc_html__(
944
-                        '%s Viewing registrations for the event: %s%s',
945
-                        'event_espresso'
946
-                    ),
947
-                    '<h3 style="line-height:1.5em;">',
948
-                    '<br /><a href="'
949
-                        . EE_Admin_Page::add_query_args_and_nonce(
950
-                            array(
951
-                                'action' => 'edit',
952
-                                'post'   => $event->ID(),
953
-                            ),
954
-                            EVENTS_ADMIN_URL
955
-                        )
956
-                        . '">&nbsp;'
957
-                        . $event->get('EVT_name')
958
-                        . '&nbsp;</a>&nbsp;',
959
-                    '</h3>'
960
-                );
961
-            }
962
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
963
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
964
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
965
-                $this->_template_args['admin_page_header'] = substr(
966
-                    $this->_template_args['admin_page_header'],
967
-                    0,
968
-                    -5
969
-                );
970
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
971
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
972
-                $this->_template_args['admin_page_header'] .= $datetime->name();
973
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
974
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
975
-            }
976
-        }
977
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
978
-        $this->display_admin_list_table_page_with_no_sidebar();
979
-    }
980
-
981
-
982
-    /**
983
-     * This sets the _registration property for the registration details screen
984
-     *
985
-     * @access private
986
-     * @return bool
987
-     */
988
-    private function _set_registration_object()
989
-    {
990
-        //get out if we've already set the object
991
-        if (is_object($this->_registration)) {
992
-            return true;
993
-        }
994
-        $REG    = EEM_Registration::instance();
995
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
996
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
997
-            return true;
998
-        } else {
999
-            $error_msg = sprintf(
1000
-                esc_html__(
1001
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1002
-                    'event_espresso'
1003
-                ),
1004
-                $REG_ID
1005
-            );
1006
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1007
-            $this->_registration = null;
1008
-            return false;
1009
-        }
1010
-    }
1011
-
1012
-
1013
-    /**
1014
-     * Used to retrieve registrations for the list table.
1015
-     *
1016
-     * @param int  $per_page
1017
-     * @param bool $count
1018
-     * @param bool $this_month
1019
-     * @param bool $today
1020
-     * @return EE_Registration[]|int
1021
-     * @throws EE_Error
1022
-     */
1023
-    public function get_registrations(
1024
-        $per_page = 10,
1025
-        $count = false,
1026
-        $this_month = false,
1027
-        $today = false
1028
-    ) {
1029
-        if ($this_month) {
1030
-            $this->_req_data['status'] = 'month';
1031
-        }
1032
-        if ($today) {
1033
-            $this->_req_data['status'] = 'today';
1034
-        }
1035
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1036
-        /**
1037
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1038
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1039
-         * @see EEM_Base::get_all()
1040
-         */
1041
-        $query_params['group_by'] = '';
1042
-
1043
-        return $count
1044
-            ? EEM_Registration::instance()->count($query_params)
1045
-            /** @type EE_Registration[] */
1046
-            : EEM_Registration::instance()->get_all($query_params);
1047
-    }
1048
-
1049
-
1050
-
1051
-    /**
1052
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1053
-     * Note: this listens to values on the request for some of the query parameters.
1054
-     *
1055
-     * @param array $request
1056
-     * @param int    $per_page
1057
-     * @param bool   $count
1058
-     * @return array
1059
-     */
1060
-    protected function _get_registration_query_parameters(
1061
-        $request = array(),
1062
-        $per_page = 10,
1063
-        $count = false
1064
-    ) {
1065
-
1066
-        $query_params = array(
1067
-            0                          => $this->_get_where_conditions_for_registrations_query(
1068
-                $request
1069
-            ),
1070
-            'caps'                     => EEM_Registration::caps_read_admin,
1071
-            'default_where_conditions' => 'this_model_only',
1072
-        );
1073
-        if (! $count) {
1074
-            $query_params = array_merge(
1075
-                $query_params,
1076
-                $this->_get_orderby_for_registrations_query(),
1077
-                $this->_get_limit($per_page)
1078
-            );
1079
-        }
1080
-
1081
-        return $query_params;
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1087
-     *
1088
-     * @param array $request usually the same as $this->_req_data but not necessarily
1089
-     * @return array
1090
-     */
1091
-    protected function _add_event_id_to_where_conditions(array $request)
1092
-    {
1093
-        $where = array();
1094
-        if (! empty($request['event_id'])) {
1095
-            $where['EVT_ID'] = absint($request['event_id']);
1096
-        }
1097
-        return $where;
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1103
-     *
1104
-     * @param array $request usually the same as $this->_req_data but not necessarily
1105
-     * @return array
1106
-     */
1107
-    protected function _add_category_id_to_where_conditions(array $request)
1108
-    {
1109
-        $where = array();
1110
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1111
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1112
-        }
1113
-        return $where;
1114
-    }
1115
-
1116
-
1117
-    /**
1118
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1119
-     *
1120
-     * @param array $request usually the same as $this->_req_data but not necessarily
1121
-     * @return array
1122
-     */
1123
-    protected function _add_datetime_id_to_where_conditions(array $request)
1124
-    {
1125
-        $where = array();
1126
-        if (! empty($request['datetime_id'])) {
1127
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1128
-        }
1129
-        if (! empty($request['DTT_ID'])) {
1130
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1131
-        }
1132
-        return $where;
1133
-    }
1134
-
1135
-
1136
-    /**
1137
-     * Adds the correct registration status to the where conditions for the registrations query.
1138
-     *
1139
-     * @param array $request usually the same as $this->_req_data but not necessarily
1140
-     * @return array
1141
-     */
1142
-    protected function _add_registration_status_to_where_conditions(array $request)
1143
-    {
1144
-        $where = array();
1145
-        $view = EEH_Array::is_set($request, 'status', '');
1146
-        $registration_status = ! empty($request['_reg_status'])
1147
-            ? sanitize_text_field($request['_reg_status'])
1148
-            : '';
1149
-
1150
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if (! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
+			? $this->_req_data['ATT_ID'] : 0;
171
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
+			? $this->_req_data['post']
173
+			: $att_id;
174
+		$this->_page_routes = array(
175
+			'default'                            => array(
176
+				'func'       => '_registrations_overview_list_table',
177
+				'capability' => 'ee_read_registrations',
178
+			),
179
+			'view_registration'                  => array(
180
+				'func'       => '_registration_details',
181
+				'capability' => 'ee_read_registration',
182
+				'obj_id'     => $reg_id,
183
+			),
184
+			'edit_registration'                  => array(
185
+				'func'               => '_update_attendee_registration_form',
186
+				'noheader'           => true,
187
+				'headers_sent_route' => 'view_registration',
188
+				'capability'         => 'ee_edit_registration',
189
+				'obj_id'             => $reg_id,
190
+				'_REG_ID'            => $reg_id,
191
+			),
192
+			'trash_registrations'                => array(
193
+				'func'       => '_trash_or_restore_registrations',
194
+				'args'       => array('trash' => true),
195
+				'noheader'   => true,
196
+				'capability' => 'ee_delete_registrations',
197
+			),
198
+			'restore_registrations'              => array(
199
+				'func'       => '_trash_or_restore_registrations',
200
+				'args'       => array('trash' => false),
201
+				'noheader'   => true,
202
+				'capability' => 'ee_delete_registrations',
203
+			),
204
+			'delete_registrations'               => array(
205
+				'func'       => '_delete_registrations',
206
+				'noheader'   => true,
207
+				'capability' => 'ee_delete_registrations',
208
+			),
209
+			'new_registration'                   => array(
210
+				'func'       => 'new_registration',
211
+				'capability' => 'ee_edit_registrations',
212
+			),
213
+			'process_reg_step'                   => array(
214
+				'func'       => 'process_reg_step',
215
+				'noheader'   => true,
216
+				'capability' => 'ee_edit_registrations',
217
+			),
218
+			'redirect_to_txn'                    => array(
219
+				'func'       => 'redirect_to_txn',
220
+				'noheader'   => true,
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'change_reg_status'                  => array(
224
+				'func'       => '_change_reg_status',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registration',
227
+				'obj_id'     => $reg_id,
228
+			),
229
+			'approve_registration'               => array(
230
+				'func'       => 'approve_registration',
231
+				'noheader'   => true,
232
+				'capability' => 'ee_edit_registration',
233
+				'obj_id'     => $reg_id,
234
+			),
235
+			'approve_and_notify_registration'    => array(
236
+				'func'       => 'approve_registration',
237
+				'noheader'   => true,
238
+				'args'       => array(true),
239
+				'capability' => 'ee_edit_registration',
240
+				'obj_id'     => $reg_id,
241
+			),
242
+			'decline_registration'               => array(
243
+				'func'       => 'decline_registration',
244
+				'noheader'   => true,
245
+				'capability' => 'ee_edit_registration',
246
+				'obj_id'     => $reg_id,
247
+			),
248
+			'decline_and_notify_registration'    => array(
249
+				'func'       => 'decline_registration',
250
+				'noheader'   => true,
251
+				'args'       => array(true),
252
+				'capability' => 'ee_edit_registration',
253
+				'obj_id'     => $reg_id,
254
+			),
255
+			'pending_registration'               => array(
256
+				'func'       => 'pending_registration',
257
+				'noheader'   => true,
258
+				'capability' => 'ee_edit_registration',
259
+				'obj_id'     => $reg_id,
260
+			),
261
+			'pending_and_notify_registration'    => array(
262
+				'func'       => 'pending_registration',
263
+				'noheader'   => true,
264
+				'args'       => array(true),
265
+				'capability' => 'ee_edit_registration',
266
+				'obj_id'     => $reg_id,
267
+			),
268
+			'no_approve_registration'            => array(
269
+				'func'       => 'not_approve_registration',
270
+				'noheader'   => true,
271
+				'capability' => 'ee_edit_registration',
272
+				'obj_id'     => $reg_id,
273
+			),
274
+			'no_approve_and_notify_registration' => array(
275
+				'func'       => 'not_approve_registration',
276
+				'noheader'   => true,
277
+				'args'       => array(true),
278
+				'capability' => 'ee_edit_registration',
279
+				'obj_id'     => $reg_id,
280
+			),
281
+			'cancel_registration'                => array(
282
+				'func'       => 'cancel_registration',
283
+				'noheader'   => true,
284
+				'capability' => 'ee_edit_registration',
285
+				'obj_id'     => $reg_id,
286
+			),
287
+			'cancel_and_notify_registration'     => array(
288
+				'func'       => 'cancel_registration',
289
+				'noheader'   => true,
290
+				'args'       => array(true),
291
+				'capability' => 'ee_edit_registration',
292
+				'obj_id'     => $reg_id,
293
+			),
294
+			'wait_list_registration' => array(
295
+				'func'       => 'wait_list_registration',
296
+				'noheader'   => true,
297
+				'capability' => 'ee_edit_registration',
298
+				'obj_id'     => $reg_id,
299
+			),
300
+			'contact_list'                       => array(
301
+				'func'       => '_attendee_contact_list_table',
302
+				'capability' => 'ee_read_contacts',
303
+			),
304
+			'add_new_attendee'                   => array(
305
+				'func' => '_create_new_cpt_item',
306
+				'args' => array(
307
+					'new_attendee' => true,
308
+					'capability'   => 'ee_edit_contacts',
309
+				),
310
+			),
311
+			'edit_attendee'                      => array(
312
+				'func'       => '_edit_cpt_item',
313
+				'capability' => 'ee_edit_contacts',
314
+				'obj_id'     => $att_id,
315
+			),
316
+			'duplicate_attendee'                 => array(
317
+				'func'       => '_duplicate_attendee',
318
+				'noheader'   => true,
319
+				'capability' => 'ee_edit_contacts',
320
+				'obj_id'     => $att_id,
321
+			),
322
+			'insert_attendee'                    => array(
323
+				'func'       => '_insert_or_update_attendee',
324
+				'args'       => array(
325
+					'new_attendee' => true,
326
+				),
327
+				'noheader'   => true,
328
+				'capability' => 'ee_edit_contacts',
329
+			),
330
+			'update_attendee'                    => array(
331
+				'func'       => '_insert_or_update_attendee',
332
+				'args'       => array(
333
+					'new_attendee' => false,
334
+				),
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_contacts',
337
+				'obj_id'     => $att_id,
338
+			),
339
+			'trash_attendee'                    => array(
340
+				'func'       => '_trash_or_restore_attendees',
341
+				'args'       => array(
342
+					'trash' => true,
343
+				),
344
+				'noheader'   => true,
345
+				'capability' => 'ee_delete_contacts',
346
+				'obj_id'     => $att_id,
347
+			),
348
+			'restore_attendees'                  => array(
349
+				'func'       => '_trash_or_restore_attendees',
350
+				'args'       => array(
351
+					'trash' => false,
352
+				),
353
+				'noheader'   => true,
354
+				'capability' => 'ee_delete_contacts',
355
+				'obj_id'     => $att_id,
356
+			),
357
+			'resend_registration'                => array(
358
+				'func'       => '_resend_registration',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_send_message',
361
+			),
362
+			'registrations_report'               => array(
363
+				'func'       => '_registrations_report',
364
+				'noheader'   => true,
365
+				'capability' => 'ee_read_registrations',
366
+			),
367
+			'contact_list_export'                => array(
368
+				'func'       => '_contact_list_export',
369
+				'noheader'   => true,
370
+				'capability' => 'export',
371
+			),
372
+			'contact_list_report'                => array(
373
+				'func'       => '_contact_list_report',
374
+				'noheader'   => true,
375
+				'capability' => 'ee_read_contacts',
376
+			),
377
+		);
378
+	}
379
+
380
+
381
+	protected function _set_page_config()
382
+	{
383
+		$this->_page_config = array(
384
+			'default'           => array(
385
+				'nav'           => array(
386
+					'label' => esc_html__('Overview', 'event_espresso'),
387
+					'order' => 5,
388
+				),
389
+				'help_tabs'     => array(
390
+					'registrations_overview_help_tab'                       => array(
391
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
392
+						'filename' => 'registrations_overview',
393
+					),
394
+					'registrations_overview_table_column_headings_help_tab' => array(
395
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
396
+						'filename' => 'registrations_overview_table_column_headings',
397
+					),
398
+					'registrations_overview_filters_help_tab'               => array(
399
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
400
+						'filename' => 'registrations_overview_filters',
401
+					),
402
+					'registrations_overview_views_help_tab'                 => array(
403
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
404
+						'filename' => 'registrations_overview_views',
405
+					),
406
+					'registrations_regoverview_other_help_tab'              => array(
407
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
408
+						'filename' => 'registrations_overview_other',
409
+					),
410
+				),
411
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
412
+				'qtips'         => array('Registration_List_Table_Tips'),
413
+				'list_table'    => 'EE_Registrations_List_Table',
414
+				'require_nonce' => false,
415
+			),
416
+			'view_registration' => array(
417
+				'nav'           => array(
418
+					'label'      => esc_html__('REG Details', 'event_espresso'),
419
+					'order'      => 15,
420
+					'url'        => isset($this->_req_data['_REG_ID'])
421
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
422
+						: $this->_admin_base_url,
423
+					'persistent' => false,
424
+				),
425
+				'help_tabs'     => array(
426
+					'registrations_details_help_tab'                    => array(
427
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
428
+						'filename' => 'registrations_details',
429
+					),
430
+					'registrations_details_table_help_tab'              => array(
431
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
432
+						'filename' => 'registrations_details_table',
433
+					),
434
+					'registrations_details_form_answers_help_tab'       => array(
435
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
436
+						'filename' => 'registrations_details_form_answers',
437
+					),
438
+					'registrations_details_registrant_details_help_tab' => array(
439
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
440
+						'filename' => 'registrations_details_registrant_details',
441
+					),
442
+				),
443
+				'help_tour'     => array('Registration_Details_Help_Tour'),
444
+				'metaboxes'     => array_merge(
445
+					$this->_default_espresso_metaboxes,
446
+					array('_registration_details_metaboxes')
447
+				),
448
+				'require_nonce' => false,
449
+			),
450
+			'new_registration'  => array(
451
+				'nav'           => array(
452
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
453
+					'url'        => '#',
454
+					'order'      => 15,
455
+					'persistent' => false,
456
+				),
457
+				'metaboxes'     => $this->_default_espresso_metaboxes,
458
+				'labels'        => array(
459
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
460
+				),
461
+				'require_nonce' => false,
462
+			),
463
+			'add_new_attendee'  => array(
464
+				'nav'           => array(
465
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
466
+					'order'      => 15,
467
+					'persistent' => false,
468
+				),
469
+				'metaboxes'     => array_merge(
470
+					$this->_default_espresso_metaboxes,
471
+					array('_publish_post_box', 'attendee_editor_metaboxes')
472
+				),
473
+				'require_nonce' => false,
474
+			),
475
+			'edit_attendee'     => array(
476
+				'nav'           => array(
477
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
478
+					'order'      => 15,
479
+					'persistent' => false,
480
+					'url'        => isset($this->_req_data['ATT_ID'])
481
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
482
+						: $this->_admin_base_url,
483
+				),
484
+				'metaboxes'     => array('attendee_editor_metaboxes'),
485
+				'require_nonce' => false,
486
+			),
487
+			'contact_list'      => array(
488
+				'nav'           => array(
489
+					'label' => esc_html__('Contact List', 'event_espresso'),
490
+					'order' => 20,
491
+				),
492
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
493
+				'help_tabs'     => array(
494
+					'registrations_contact_list_help_tab'                       => array(
495
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
496
+						'filename' => 'registrations_contact_list',
497
+					),
498
+					'registrations_contact-list_table_column_headings_help_tab' => array(
499
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
500
+						'filename' => 'registrations_contact_list_table_column_headings',
501
+					),
502
+					'registrations_contact_list_views_help_tab'                 => array(
503
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
504
+						'filename' => 'registrations_contact_list_views',
505
+					),
506
+					'registrations_contact_list_other_help_tab'                 => array(
507
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
508
+						'filename' => 'registrations_contact_list_other',
509
+					),
510
+				),
511
+				'help_tour'     => array('Contact_List_Help_Tour'),
512
+				'metaboxes'     => array(),
513
+				'require_nonce' => false,
514
+			),
515
+			//override default cpt routes
516
+			'create_new'        => '',
517
+			'edit'              => '',
518
+		);
519
+	}
520
+
521
+
522
+	/**
523
+	 * The below methods aren't used by this class currently
524
+	 */
525
+	protected function _add_screen_options()
526
+	{
527
+	}
528
+
529
+
530
+	protected function _add_feature_pointers()
531
+	{
532
+	}
533
+
534
+
535
+	public function admin_init()
536
+	{
537
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
538
+			'click "Update Registration Questions" to save your changes',
539
+			'event_espresso'
540
+		);
541
+	}
542
+
543
+
544
+	public function admin_notices()
545
+	{
546
+	}
547
+
548
+
549
+	public function admin_footer_scripts()
550
+	{
551
+	}
552
+
553
+
554
+	/**
555
+	 *        get list of registration statuses
556
+	 *
557
+	 * @access private
558
+	 * @return void
559
+	 */
560
+	private function _get_registration_status_array()
561
+	{
562
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
563
+	}
564
+
565
+
566
+	protected function _add_screen_options_default()
567
+	{
568
+		$this->_per_page_screen_option();
569
+	}
570
+
571
+
572
+	protected function _add_screen_options_contact_list()
573
+	{
574
+		$page_title              = $this->_admin_page_title;
575
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
576
+		$this->_per_page_screen_option();
577
+		$this->_admin_page_title = $page_title;
578
+	}
579
+
580
+
581
+	public function load_scripts_styles()
582
+	{
583
+		//style
584
+		wp_register_style(
585
+			'espresso_reg',
586
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
587
+			array('ee-admin-css'),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_enqueue_style('espresso_reg');
591
+		//script
592
+		wp_register_script(
593
+			'espresso_reg',
594
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
595
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
596
+			EVENT_ESPRESSO_VERSION,
597
+			true
598
+		);
599
+		wp_enqueue_script('espresso_reg');
600
+	}
601
+
602
+
603
+	public function load_scripts_styles_edit_attendee()
604
+	{
605
+		//stuff to only show up on our attendee edit details page.
606
+		$attendee_details_translations = array(
607
+			'att_publish_text' => sprintf(
608
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
609
+				$this->_cpt_model_obj->get_datetime('ATT_created')
610
+			),
611
+		);
612
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
613
+		wp_enqueue_script('jquery-validate');
614
+	}
615
+
616
+
617
+	public function load_scripts_styles_view_registration()
618
+	{
619
+		//styles
620
+		wp_enqueue_style('espresso-ui-theme');
621
+		//scripts
622
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
623
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
624
+	}
625
+
626
+
627
+	public function load_scripts_styles_contact_list()
628
+	{
629
+		wp_deregister_style('espresso_reg');
630
+		wp_register_style(
631
+			'espresso_att',
632
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
633
+			array('ee-admin-css'),
634
+			EVENT_ESPRESSO_VERSION
635
+		);
636
+		wp_enqueue_style('espresso_att');
637
+	}
638
+
639
+
640
+	public function load_scripts_styles_new_registration()
641
+	{
642
+		wp_register_script(
643
+			'ee-spco-for-admin',
644
+			REG_ASSETS_URL . 'spco_for_admin.js',
645
+			array('underscore', 'jquery'),
646
+			EVENT_ESPRESSO_VERSION,
647
+			true
648
+		);
649
+		wp_enqueue_script('ee-spco-for-admin');
650
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
651
+		EE_Form_Section_Proper::wp_enqueue_scripts();
652
+		EED_Ticket_Selector::load_tckt_slctr_assets();
653
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
654
+	}
655
+
656
+
657
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
658
+	{
659
+		add_filter('FHEE_load_EE_messages', '__return_true');
660
+	}
661
+
662
+
663
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
664
+	{
665
+		add_filter('FHEE_load_EE_messages', '__return_true');
666
+	}
667
+
668
+
669
+	protected function _set_list_table_views_default()
670
+	{
671
+		//for notification related bulk actions we need to make sure only active messengers have an option.
672
+		EED_Messages::set_autoloaders();
673
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
674
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
675
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
676
+		//key= bulk_action_slug, value= message type.
677
+		$match_array = array(
678
+			'approve_registration'    => 'registration',
679
+			'decline_registration'    => 'declined_registration',
680
+			'pending_registration'    => 'pending_approval',
681
+			'no_approve_registration' => 'not_approved_registration',
682
+			'cancel_registration'     => 'cancelled_registration',
683
+		);
684
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
685
+			'ee_send_message',
686
+			'batch_send_messages'
687
+		);
688
+		/** setup reg status bulk actions **/
689
+		$def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
690
+		if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) {
691
+				$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
692
+					'event_espresso');
693
+		}
694
+		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
695
+		if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) {
696
+				$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
697
+					'event_espresso');
698
+		}
699
+		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
700
+		if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) {
701
+				$def_reg_status_actions['pending_and_notify_registration'] = __(
702
+					'Set Registrations to Pending Payment and Notify',
703
+					'event_espresso'
704
+				);
705
+		}
706
+		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
707
+		if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) {
708
+				$def_reg_status_actions['no_approve_and_notify_registration'] = __(
709
+					'Set Registrations to Not Approved and Notify',
710
+					'event_espresso'
711
+				);
712
+		}
713
+		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
714
+		if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) {
715
+				$def_reg_status_actions['cancel_and_notify_registration'] = __(
716
+					'Cancel Registrations and Notify',
717
+					'event_espresso'
718
+				);
719
+		}
720
+		$def_reg_status_actions = apply_filters(
721
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
722
+			$def_reg_status_actions,
723
+			$active_mts
724
+		);
725
+
726
+		$this->_views = array(
727
+			'all'   => array(
728
+				'slug'        => 'all',
729
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
730
+				'count'       => 0,
731
+				'bulk_action' => array_merge($def_reg_status_actions, array(
732
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
733
+				)),
734
+			),
735
+			'month' => array(
736
+				'slug'        => 'month',
737
+				'label'       => esc_html__('This Month', 'event_espresso'),
738
+				'count'       => 0,
739
+				'bulk_action' => array_merge($def_reg_status_actions, array(
740
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
741
+				)),
742
+			),
743
+			'today' => array(
744
+				'slug'        => 'today',
745
+				'label'       => sprintf(
746
+					esc_html__('Today - %s', 'event_espresso'),
747
+					date('M d, Y', current_time('timestamp'))
748
+				),
749
+				'count'       => 0,
750
+				'bulk_action' => array_merge($def_reg_status_actions, array(
751
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
752
+				)),
753
+			),
754
+		);
755
+		if (EE_Registry::instance()->CAP->current_user_can(
756
+			'ee_delete_registrations',
757
+			'espresso_registrations_delete_registration'
758
+		)) {
759
+			$this->_views['incomplete'] = array(
760
+				'slug'        => 'incomplete',
761
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
762
+				'count'       => 0,
763
+				'bulk_action' => array(
764
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
765
+				),
766
+			);
767
+			$this->_views['trash']      = array(
768
+				'slug'        => 'trash',
769
+				'label'       => esc_html__('Trash', 'event_espresso'),
770
+				'count'       => 0,
771
+				'bulk_action' => array(
772
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
773
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
774
+				),
775
+			);
776
+		}
777
+	}
778
+
779
+
780
+	protected function _set_list_table_views_contact_list()
781
+	{
782
+		$this->_views = array(
783
+			'in_use' => array(
784
+				'slug'        => 'in_use',
785
+				'label'       => esc_html__('In Use', 'event_espresso'),
786
+				'count'       => 0,
787
+				'bulk_action' => array(
788
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
789
+				),
790
+			),
791
+		);
792
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
793
+			'espresso_registrations_trash_attendees')
794
+		) {
795
+			$this->_views['trash'] = array(
796
+				'slug'        => 'trash',
797
+				'label'       => esc_html__('Trash', 'event_espresso'),
798
+				'count'       => 0,
799
+				'bulk_action' => array(
800
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
801
+				),
802
+			);
803
+		}
804
+	}
805
+
806
+
807
+	protected function _registration_legend_items()
808
+	{
809
+		$fc_items = array(
810
+			'star-icon'        => array(
811
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
812
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
813
+			),
814
+			'view_details'     => array(
815
+				'class' => 'dashicons dashicons-clipboard',
816
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
817
+			),
818
+			'edit_attendee'    => array(
819
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
820
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
821
+			),
822
+			'view_transaction' => array(
823
+				'class' => 'dashicons dashicons-cart',
824
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
825
+			),
826
+			'view_invoice'     => array(
827
+				'class' => 'dashicons dashicons-media-spreadsheet',
828
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
829
+			),
830
+		);
831
+		if (EE_Registry::instance()->CAP->current_user_can(
832
+			'ee_send_message',
833
+			'espresso_registrations_resend_registration'
834
+		)) {
835
+			$fc_items['resend_registration'] = array(
836
+				'class' => 'dashicons dashicons-email-alt',
837
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
838
+			);
839
+		} else {
840
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
841
+		}
842
+		if (EE_Registry::instance()->CAP->current_user_can(
843
+			'ee_read_global_messages',
844
+			'view_filtered_messages'
845
+		)) {
846
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
847
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
848
+				$fc_items['view_related_messages'] = array(
849
+					'class' => $related_for_icon['css_class'],
850
+					'desc'  => $related_for_icon['label'],
851
+				);
852
+			}
853
+		}
854
+		$sc_items = array(
855
+			'approved_status'   => array(
856
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
857
+				'desc'  => EEH_Template::pretty_status(
858
+					EEM_Registration::status_id_approved,
859
+					false,
860
+					'sentence'
861
+				),
862
+			),
863
+			'pending_status'    => array(
864
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
865
+				'desc'  => EEH_Template::pretty_status(
866
+					EEM_Registration::status_id_pending_payment,
867
+					false,
868
+					'sentence'
869
+				),
870
+			),
871
+			'wait_list'         => array(
872
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
873
+				'desc'  => EEH_Template::pretty_status(
874
+					EEM_Registration::status_id_wait_list,
875
+					false,
876
+					'sentence'
877
+				),
878
+			),
879
+			'incomplete_status' => array(
880
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
881
+				'desc'  => EEH_Template::pretty_status(
882
+					EEM_Registration::status_id_incomplete,
883
+					false,
884
+					'sentence'
885
+				),
886
+			),
887
+			'not_approved'      => array(
888
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
889
+				'desc'  => EEH_Template::pretty_status(
890
+					EEM_Registration::status_id_not_approved,
891
+					false,
892
+					'sentence'
893
+				),
894
+			),
895
+			'declined_status'   => array(
896
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
897
+				'desc'  => EEH_Template::pretty_status(
898
+					EEM_Registration::status_id_declined,
899
+					false,
900
+					'sentence'
901
+				),
902
+			),
903
+			'cancelled_status'  => array(
904
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
905
+				'desc'  => EEH_Template::pretty_status(
906
+					EEM_Registration::status_id_cancelled,
907
+					false,
908
+					'sentence'
909
+				),
910
+			),
911
+		);
912
+		return array_merge($fc_items, $sc_items);
913
+	}
914
+
915
+
916
+
917
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
918
+	/**
919
+	 * @throws \EE_Error
920
+	 */
921
+	protected function _registrations_overview_list_table()
922
+	{
923
+		$this->_template_args['admin_page_header'] = '';
924
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
925
+			? absint($this->_req_data['event_id'])
926
+			: 0;
927
+		if ($EVT_ID) {
928
+			if (EE_Registry::instance()->CAP->current_user_can(
929
+				'ee_edit_registrations',
930
+				'espresso_registrations_new_registration',
931
+				$EVT_ID
932
+			)) {
933
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
934
+					'new_registration',
935
+					'add-registrant',
936
+					array('event_id' => $EVT_ID),
937
+					'add-new-h2'
938
+				);
939
+			}
940
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
941
+			if ($event instanceof EE_Event) {
942
+				$this->_template_args['admin_page_header'] = sprintf(
943
+					esc_html__(
944
+						'%s Viewing registrations for the event: %s%s',
945
+						'event_espresso'
946
+					),
947
+					'<h3 style="line-height:1.5em;">',
948
+					'<br /><a href="'
949
+						. EE_Admin_Page::add_query_args_and_nonce(
950
+							array(
951
+								'action' => 'edit',
952
+								'post'   => $event->ID(),
953
+							),
954
+							EVENTS_ADMIN_URL
955
+						)
956
+						. '">&nbsp;'
957
+						. $event->get('EVT_name')
958
+						. '&nbsp;</a>&nbsp;',
959
+					'</h3>'
960
+				);
961
+			}
962
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
963
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
964
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
965
+				$this->_template_args['admin_page_header'] = substr(
966
+					$this->_template_args['admin_page_header'],
967
+					0,
968
+					-5
969
+				);
970
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
971
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
972
+				$this->_template_args['admin_page_header'] .= $datetime->name();
973
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
974
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
975
+			}
976
+		}
977
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
978
+		$this->display_admin_list_table_page_with_no_sidebar();
979
+	}
980
+
981
+
982
+	/**
983
+	 * This sets the _registration property for the registration details screen
984
+	 *
985
+	 * @access private
986
+	 * @return bool
987
+	 */
988
+	private function _set_registration_object()
989
+	{
990
+		//get out if we've already set the object
991
+		if (is_object($this->_registration)) {
992
+			return true;
993
+		}
994
+		$REG    = EEM_Registration::instance();
995
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
996
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
997
+			return true;
998
+		} else {
999
+			$error_msg = sprintf(
1000
+				esc_html__(
1001
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1002
+					'event_espresso'
1003
+				),
1004
+				$REG_ID
1005
+			);
1006
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1007
+			$this->_registration = null;
1008
+			return false;
1009
+		}
1010
+	}
1011
+
1012
+
1013
+	/**
1014
+	 * Used to retrieve registrations for the list table.
1015
+	 *
1016
+	 * @param int  $per_page
1017
+	 * @param bool $count
1018
+	 * @param bool $this_month
1019
+	 * @param bool $today
1020
+	 * @return EE_Registration[]|int
1021
+	 * @throws EE_Error
1022
+	 */
1023
+	public function get_registrations(
1024
+		$per_page = 10,
1025
+		$count = false,
1026
+		$this_month = false,
1027
+		$today = false
1028
+	) {
1029
+		if ($this_month) {
1030
+			$this->_req_data['status'] = 'month';
1031
+		}
1032
+		if ($today) {
1033
+			$this->_req_data['status'] = 'today';
1034
+		}
1035
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1036
+		/**
1037
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1038
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1039
+		 * @see EEM_Base::get_all()
1040
+		 */
1041
+		$query_params['group_by'] = '';
1042
+
1043
+		return $count
1044
+			? EEM_Registration::instance()->count($query_params)
1045
+			/** @type EE_Registration[] */
1046
+			: EEM_Registration::instance()->get_all($query_params);
1047
+	}
1048
+
1049
+
1050
+
1051
+	/**
1052
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1053
+	 * Note: this listens to values on the request for some of the query parameters.
1054
+	 *
1055
+	 * @param array $request
1056
+	 * @param int    $per_page
1057
+	 * @param bool   $count
1058
+	 * @return array
1059
+	 */
1060
+	protected function _get_registration_query_parameters(
1061
+		$request = array(),
1062
+		$per_page = 10,
1063
+		$count = false
1064
+	) {
1065
+
1066
+		$query_params = array(
1067
+			0                          => $this->_get_where_conditions_for_registrations_query(
1068
+				$request
1069
+			),
1070
+			'caps'                     => EEM_Registration::caps_read_admin,
1071
+			'default_where_conditions' => 'this_model_only',
1072
+		);
1073
+		if (! $count) {
1074
+			$query_params = array_merge(
1075
+				$query_params,
1076
+				$this->_get_orderby_for_registrations_query(),
1077
+				$this->_get_limit($per_page)
1078
+			);
1079
+		}
1080
+
1081
+		return $query_params;
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1087
+	 *
1088
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1089
+	 * @return array
1090
+	 */
1091
+	protected function _add_event_id_to_where_conditions(array $request)
1092
+	{
1093
+		$where = array();
1094
+		if (! empty($request['event_id'])) {
1095
+			$where['EVT_ID'] = absint($request['event_id']);
1096
+		}
1097
+		return $where;
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1103
+	 *
1104
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1105
+	 * @return array
1106
+	 */
1107
+	protected function _add_category_id_to_where_conditions(array $request)
1108
+	{
1109
+		$where = array();
1110
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1111
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1112
+		}
1113
+		return $where;
1114
+	}
1115
+
1116
+
1117
+	/**
1118
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1119
+	 *
1120
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1121
+	 * @return array
1122
+	 */
1123
+	protected function _add_datetime_id_to_where_conditions(array $request)
1124
+	{
1125
+		$where = array();
1126
+		if (! empty($request['datetime_id'])) {
1127
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1128
+		}
1129
+		if (! empty($request['DTT_ID'])) {
1130
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1131
+		}
1132
+		return $where;
1133
+	}
1134
+
1135
+
1136
+	/**
1137
+	 * Adds the correct registration status to the where conditions for the registrations query.
1138
+	 *
1139
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1140
+	 * @return array
1141
+	 */
1142
+	protected function _add_registration_status_to_where_conditions(array $request)
1143
+	{
1144
+		$where = array();
1145
+		$view = EEH_Array::is_set($request, 'status', '');
1146
+		$registration_status = ! empty($request['_reg_status'])
1147
+			? sanitize_text_field($request['_reg_status'])
1148
+			: '';
1149
+
1150
+		/*
1151 1151
          * If filtering by registration status, then we show registrations matching that status.
1152 1152
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1153 1153
          * UNLESS viewing trashed registrations.
1154 1154
          */
1155
-        if (! empty($registration_status)) {
1156
-            $where['STS_ID'] = $registration_status;
1157
-        } else {
1158
-            //make sure we exclude incomplete registrations, but only if not trashed.
1159
-            if ($view === 'trash') {
1160
-                $where['REG_deleted'] = true;
1161
-            } elseif ($view === 'incomplete') {
1162
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1163
-            } else {
1164
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1165
-            }
1166
-        }
1167
-        return $where;
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * Adds any provided date restraints to the where conditions for the registrations query.
1173
-     *
1174
-     * @param array $request usually the same as $this->_req_data but not necessarily
1175
-     * @return array
1176
-     * @throws EE_Error
1177
-     */
1178
-    protected function _add_date_to_where_conditions(array $request)
1179
-    {
1180
-        $where = array();
1181
-        $view = EEH_Array::is_set($request, 'status', '');
1182
-        $month_range             = ! empty($request['month_range'])
1183
-            ? sanitize_text_field($request['month_range'])
1184
-            : '';
1185
-        $retrieve_for_today      = $view === 'today';
1186
-        $retrieve_for_this_month = $view === 'month';
1187
-
1188
-        if ($retrieve_for_today) {
1189
-            $now               = date('Y-m-d', current_time('timestamp'));
1190
-            $where['REG_date'] = array(
1191
-                'BETWEEN',
1192
-                array(
1193
-                    EEM_Registration::instance()->convert_datetime_for_query(
1194
-                        'REG_date',
1195
-                        $now . ' 00:00:00',
1196
-                        'Y-m-d H:i:s'
1197
-                    ),
1198
-                    EEM_Registration::instance()->convert_datetime_for_query(
1199
-                        'REG_date',
1200
-                        $now . ' 23:59:59',
1201
-                        'Y-m-d H:i:s'
1202
-                    ),
1203
-                ),
1204
-            );
1205
-        } elseif ($retrieve_for_this_month) {
1206
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1207
-            $days_this_month        = date('t', current_time('timestamp'));
1208
-            $where['REG_date']      = array(
1209
-                'BETWEEN',
1210
-                array(
1211
-                    EEM_Registration::instance()->convert_datetime_for_query(
1212
-                        'REG_date',
1213
-                        $current_year_and_month . '-01 00:00:00',
1214
-                        'Y-m-d H:i:s'
1215
-                    ),
1216
-                    EEM_Registration::instance()->convert_datetime_for_query(
1217
-                        'REG_date',
1218
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1219
-                        'Y-m-d H:i:s'
1220
-                    ),
1221
-                ),
1222
-            );
1223
-        } elseif ($month_range) {
1224
-            $pieces          = explode(' ', $month_range, 3);
1225
-            $month_requested = ! empty($pieces[0])
1226
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1227
-                : '';
1228
-            $year_requested  = ! empty($pieces[1])
1229
-                ? $pieces[1]
1230
-                : '';
1231
-            //if there is not a month or year then we can't go further
1232
-            if ($month_requested && $year_requested) {
1233
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1234
-                $where['REG_date'] = array(
1235
-                    'BETWEEN',
1236
-                    array(
1237
-                        EEM_Registration::instance()->convert_datetime_for_query(
1238
-                            'REG_date',
1239
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1240
-                            'Y-m-d H:i:s'
1241
-                        ),
1242
-                        EEM_Registration::instance()->convert_datetime_for_query(
1243
-                            'REG_date',
1244
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1245
-                            'Y-m-d H:i:s'
1246
-                        ),
1247
-                    ),
1248
-                );
1249
-            }
1250
-        }
1251
-        return $where;
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     * Adds any provided search restraints to the where conditions for the registrations query
1257
-     *
1258
-     * @param array $request usually the same as $this->_req_data but not necessarily
1259
-     * @return array
1260
-     */
1261
-    protected function _add_search_to_where_conditions(array $request)
1262
-    {
1263
-        $where = array();
1264
-        if (! empty($request['s'])) {
1265
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1266
-            $where['OR*search_conditions'] = array(
1267
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1268
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1269
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1270
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1271
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1272
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1273
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1274
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1275
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1276
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1277
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1278
-                'REG_final_price'                         => array('LIKE', $search_string),
1279
-                'REG_code'                                => array('LIKE', $search_string),
1280
-                'REG_count'                               => array('LIKE', $search_string),
1281
-                'REG_group_size'                          => array('LIKE', $search_string),
1282
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1283
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1284
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1285
-            );
1286
-        }
1287
-        return $where;
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * Sets up the where conditions for the registrations query.
1293
-     *
1294
-     * @param array $request
1295
-     * @return array
1296
-     * @throws EE_Error
1297
-     */
1298
-    protected function _get_where_conditions_for_registrations_query($request)
1299
-    {
1300
-        return apply_filters(
1301
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1302
-            array_merge(
1303
-                $this->_add_event_id_to_where_conditions($request),
1304
-                $this->_add_category_id_to_where_conditions($request),
1305
-                $this->_add_datetime_id_to_where_conditions($request),
1306
-                $this->_add_registration_status_to_where_conditions($request),
1307
-                $this->_add_date_to_where_conditions($request),
1308
-                $this->_add_search_to_where_conditions($request)
1309
-            ),
1310
-            $request
1311
-        );
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Sets up the orderby for the registrations query.
1317
-     *
1318
-     * @return array
1319
-     */
1320
-    protected function _get_orderby_for_registrations_query()
1321
-    {
1322
-        $orderby_field = ! empty($this->_req_data['orderby'])
1323
-            ? sanitize_text_field($this->_req_data['orderby'])
1324
-            : '';
1325
-        switch ($orderby_field) {
1326
-            case '_REG_ID':
1327
-                $orderby_field = 'REG_ID';
1328
-                break;
1329
-            case '_Reg_status':
1330
-                $orderby_field = 'STS_ID';
1331
-                break;
1332
-            case 'ATT_fname':
1333
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1334
-                break;
1335
-            case 'ATT_lname':
1336
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1337
-                break;
1338
-            case 'event_name':
1339
-                $orderby_field = 'Event.EVT_name';
1340
-                break;
1341
-            case 'DTT_EVT_start':
1342
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1343
-                break;
1344
-            default: //'REG_date'
1345
-                $orderby_field = 'REG_date';
1346
-        }
1347
-
1348
-        //order
1349
-        $order = ! empty($this->_req_data['order'])
1350
-            ? sanitize_text_field($this->_req_data['order'])
1351
-            : 'DESC';
1352
-
1353
-        //mutate orderby_field
1354
-        $orderby_field = array_combine(
1355
-            (array) $orderby_field,
1356
-            array_fill(0, count($orderby_field), $order)
1357
-        );
1358
-        return array('order_by' => $orderby_field);
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * Sets up the limit for the registrations query.
1364
-     *
1365
-     * @param $per_page
1366
-     * @return array
1367
-     */
1368
-    protected function _get_limit($per_page)
1369
-    {
1370
-        $current_page = ! empty($this->_req_data['paged'])
1371
-            ? absint($this->_req_data['paged'])
1372
-            : 1;
1373
-        $per_page     = ! empty($this->_req_data['perpage'])
1374
-            ? $this->_req_data['perpage']
1375
-            : $per_page;
1376
-
1377
-        //-1 means return all results so get out if that's set.
1378
-        if ((int)$per_page === -1) {
1379
-            return array();
1380
-        }
1381
-        $per_page = absint($per_page);
1382
-        $offset   = ($current_page - 1) * $per_page;
1383
-        return array('limit' => array($offset, $per_page));
1384
-    }
1385
-
1386
-
1387
-    public function get_registration_status_array()
1388
-    {
1389
-        return self::$_reg_status;
1390
-    }
1391
-
1392
-
1393
-
1394
-
1395
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1396
-    /**
1397
-     *        generates HTML for the View Registration Details Admin page
1398
-     *
1399
-     * @access protected
1400
-     * @return void
1401
-     * @throws DomainException
1402
-     * @throws EE_Error
1403
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1404
-     */
1405
-    protected function _registration_details()
1406
-    {
1407
-        $this->_template_args = array();
1408
-        $this->_set_registration_object();
1409
-        if (is_object($this->_registration)) {
1410
-            $transaction                                   = $this->_registration->transaction()
1411
-                ? $this->_registration->transaction()
1412
-                : EE_Transaction::new_instance();
1413
-            $this->_session                                = $transaction->session_data();
1414
-            $event_id                                      = $this->_registration->event_ID();
1415
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1416
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1417
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1418
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1419
-            $this->_template_args['grand_total']           = $transaction->total();
1420
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1421
-            // link back to overview
1422
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1423
-            $this->_template_args['registration']                = $this->_registration;
1424
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1425
-                array(
1426
-                    'action'   => 'default',
1427
-                    'event_id' => $event_id,
1428
-                ),
1429
-                REG_ADMIN_URL
1430
-            );
1431
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1432
-                array(
1433
-                    'action' => 'default',
1434
-                    'EVT_ID' => $event_id,
1435
-                    'page'   => 'espresso_transactions',
1436
-                ),
1437
-                admin_url('admin.php')
1438
-            );
1439
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1440
-                array(
1441
-                    'page'   => 'espresso_events',
1442
-                    'action' => 'edit',
1443
-                    'post'   => $event_id,
1444
-                ),
1445
-                admin_url('admin.php')
1446
-            );
1447
-            //next and previous links
1448
-            $next_reg                                      = $this->_registration->next(
1449
-                null,
1450
-                array(),
1451
-                'REG_ID'
1452
-            );
1453
-            $this->_template_args['next_registration']     = $next_reg
1454
-                ? $this->_next_link(
1455
-                    EE_Admin_Page::add_query_args_and_nonce(
1456
-                        array(
1457
-                            'action'  => 'view_registration',
1458
-                            '_REG_ID' => $next_reg['REG_ID'],
1459
-                        ),
1460
-                        REG_ADMIN_URL
1461
-                    ),
1462
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1463
-                )
1464
-                : '';
1465
-            $previous_reg                                  = $this->_registration->previous(
1466
-                null,
1467
-                array(),
1468
-                'REG_ID'
1469
-            );
1470
-            $this->_template_args['previous_registration'] = $previous_reg
1471
-                ? $this->_previous_link(
1472
-                    EE_Admin_Page::add_query_args_and_nonce(
1473
-                        array(
1474
-                            'action'  => 'view_registration',
1475
-                            '_REG_ID' => $previous_reg['REG_ID'],
1476
-                        ),
1477
-                        REG_ADMIN_URL
1478
-                    ),
1479
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1480
-                )
1481
-                : '';
1482
-            // grab header
1483
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1484
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1485
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1486
-                $template_path,
1487
-                $this->_template_args,
1488
-                true
1489
-            );
1490
-        } else {
1491
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1492
-        }
1493
-        // the details template wrapper
1494
-        $this->display_admin_page_with_sidebar();
1495
-    }
1496
-
1497
-
1498
-    protected function _registration_details_metaboxes()
1499
-    {
1500
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1501
-        $this->_set_registration_object();
1502
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1503
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1504
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1505
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1506
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1507
-        if ($attendee instanceof EE_Attendee
1508
-            && EE_Registry::instance()->CAP->current_user_can(
1509
-                'ee_edit_registration',
1510
-                'edit-reg-questions-mbox'
1511
-            )
1512
-        ) {
1513
-            add_meta_box(
1514
-                'edit-reg-questions-mbox',
1515
-                esc_html__('Registration Form Answers', 'event_espresso'),
1516
-                array($this, '_reg_questions_meta_box'),
1517
-                $this->wp_page_slug,
1518
-                'normal',
1519
-                'high'
1520
-            );
1521
-        }
1522
-        add_meta_box(
1523
-            'edit-reg-registrant-mbox',
1524
-            esc_html__('Contact Details', 'event_espresso'),
1525
-            array($this, '_reg_registrant_side_meta_box'),
1526
-            $this->wp_page_slug,
1527
-            'side',
1528
-            'high'
1529
-        );
1530
-        if ($this->_registration->group_size() > 1) {
1531
-            add_meta_box(
1532
-                'edit-reg-attendees-mbox',
1533
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1534
-                array($this, '_reg_attendees_meta_box'),
1535
-                $this->wp_page_slug,
1536
-                'normal',
1537
-                'high'
1538
-            );
1539
-        }
1540
-    }
1541
-
1542
-
1543
-    /**
1544
-     * set_reg_status_buttons_metabox
1545
-     *
1546
-     * @access protected
1547
-     * @return string
1548
-     * @throws \EE_Error
1549
-     */
1550
-    public function set_reg_status_buttons_metabox()
1551
-    {
1552
-        $this->_set_registration_object();
1553
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1554
-        echo $change_reg_status_form->form_open(
1555
-            self::add_query_args_and_nonce(
1556
-                array(
1557
-                    'action' => 'change_reg_status',
1558
-                ),
1559
-                REG_ADMIN_URL
1560
-            )
1561
-        );
1562
-        echo $change_reg_status_form->get_html();
1563
-        echo $change_reg_status_form->form_close();
1564
-    }
1565
-
1566
-
1567
-
1568
-    /**
1569
-     * @return EE_Form_Section_Proper
1570
-     * @throws EE_Error
1571
-     */
1572
-    protected function _generate_reg_status_change_form()
1573
-    {
1574
-        return new EE_Form_Section_Proper(array(
1575
-            'name'            => 'reg_status_change_form',
1576
-            'html_id'         => 'reg-status-change-form',
1577
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1578
-            'subsections'     => array(
1579
-                'return'             => new EE_Hidden_Input(array(
1580
-                    'name'    => 'return',
1581
-                    'default' => 'view_registration',
1582
-                )),
1583
-                'REG_ID'             => new EE_Hidden_Input(array(
1584
-                    'name'    => 'REG_ID',
1585
-                    'default' => $this->_registration->ID(),
1586
-                )),
1587
-                'current_status'     => new EE_Form_Section_HTML(
1588
-                    EEH_HTML::tr(
1589
-                        EEH_HTML::th(
1590
-                            EEH_HTML::label(
1591
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1592
-                                )
1593
-                            )
1594
-                        )
1595
-                        . EEH_HTML::td(
1596
-                            EEH_HTML::strong(
1597
-                                $this->_registration->pretty_status(),
1598
-                                '',
1599
-                                'status-' . $this->_registration->status_ID(),
1600
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1601
-                            )
1602
-                        )
1603
-                    )
1604
-                ),
1605
-                'reg_status'         => new EE_Select_Input(
1606
-                    $this->_get_reg_statuses(),
1607
-                    array(
1608
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1609
-                        'default'         => $this->_registration->status_ID(),
1610
-                    )
1611
-                ),
1612
-                'send_notifications' => new EE_Yes_No_Input(
1613
-                    array(
1614
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1615
-                        'default'         => false,
1616
-                        'html_help_text'  => esc_html__(
1617
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1618
-                            'event_espresso'
1619
-                        ),
1620
-                    )
1621
-                ),
1622
-                'submit'             => new EE_Submit_Input(
1623
-                    array(
1624
-                        'html_class'      => 'button-primary',
1625
-                        'html_label_text' => '&nbsp;',
1626
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1627
-                    )
1628
-                ),
1629
-            ),
1630
-        ));
1631
-    }
1632
-
1633
-
1634
-    /**
1635
-     * Returns an array of all the buttons for the various statuses and switch status actions
1636
-     *
1637
-     * @return array
1638
-     * @throws EE_Error
1639
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1640
-     */
1641
-    protected function _get_reg_statuses()
1642
-    {
1643
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1644
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1645
-        // get current reg status
1646
-        $current_status = $this->_registration->status_ID();
1647
-        // is registration for free event? This will determine whether to display the pending payment option
1648
-        if (
1649
-            $current_status !== EEM_Registration::status_id_pending_payment
1650
-            && $this->_registration->transaction()->is_free()
1651
-        ) {
1652
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1653
-        }
1654
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1655
-    }
1656
-
1657
-
1658
-
1659
-    /**
1660
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1661
-     *
1662
-     * @param bool $status REG status given for changing registrations to.
1663
-     * @param bool $notify Whether to send messages notifications or not.
1664
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1665
-     * @throws \EE_Error
1666
-     */
1667
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1668
-    {
1669
-        if (isset($this->_req_data['reg_status_change_form'])) {
1670
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1671
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
-        } else {
1673
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
-        }
1675
-        $success = $this->_set_registration_status($REG_IDs, $status);
1676
-        //notify?
1677
-        if ($success
1678
-            && $notify
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 $success;
1687
-    }
1688
-
1689
-
1690
-
1691
-    /**
1692
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
-     *
1695
-     * @param array $REG_IDs
1696
-     * @param bool  $status
1697
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
-     * @throws \RuntimeException
1699
-     * @throws \EE_Error
1700
-     *               the array of updated registrations).
1701
-     * @throws EE_Error
1702
-     * @throws RuntimeException
1703
-     */
1704
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1705
-    {
1706
-        $success = false;
1707
-        // typecast $REG_IDs
1708
-        $REG_IDs = (array)$REG_IDs;
1709
-        if ( ! empty($REG_IDs)) {
1710
-            $success = true;
1711
-            // set default status if none is passed
1712
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1713
-            // sanitize $REG_IDs
1714
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1715
-            //loop through REG_ID's and change status
1716
-            foreach ($REG_IDs as $REG_ID) {
1717
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1718
-                if ($registration instanceof EE_Registration) {
1719
-                    $registration->set_status($status);
1720
-                    $result = $registration->save();
1721
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1722
-                    $success = $result !== false ? $success : false;
1723
-                }
1724
-            }
1725
-        }
1726
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1727
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1728
-        //return $success and processed registrations
1729
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1730
-    }
1731
-
1732
-
1733
-    /**
1734
-     * Common logic for setting up success message and redirecting to appropriate route
1735
-     *
1736
-     * @param  string $STS_ID status id for the registration changed to
1737
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1738
-     * @return void
1739
-     */
1740
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1741
-    {
1742
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1743
-            : array('success' => false);
1744
-        $success = isset($result['success']) && $result['success'];
1745
-        //setup success message
1746
-        if ($success) {
1747
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1748
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1749
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1750
-            } else {
1751
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1752
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1753
-            }
1754
-            EE_Error::add_success($msg);
1755
-        } else {
1756
-            EE_Error::add_error(
1757
-                esc_html__(
1758
-                    'Something went wrong, and the status was not changed',
1759
-                    'event_espresso'
1760
-                ), __FILE__, __LINE__, __FUNCTION__
1761
-            );
1762
-        }
1763
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1764
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1765
-        } else {
1766
-            $route = array('action' => 'default');
1767
-        }
1768
-        //unset nonces
1769
-        foreach ($this->_req_data as $ref => $value) {
1770
-            if (strpos($ref, 'nonce') !== false) {
1771
-                unset($this->_req_data[$ref]);
1772
-                continue;
1773
-            }
1774
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1775
-            $this->_req_data[$ref] = $value;
1776
-        }
1777
-        //merge request vars so that the reloaded list table contains any existing filter query params
1778
-        $route = array_merge($this->_req_data, $route);
1779
-        $this->_redirect_after_action($success, '', '', $route, true);
1780
-    }
1781
-
1782
-
1783
-    /**
1784
-     * incoming reg status change from reg details page.
1785
-     *
1786
-     * @return void
1787
-     */
1788
-    protected function _change_reg_status()
1789
-    {
1790
-        $this->_req_data['return'] = 'view_registration';
1791
-        //set notify based on whether the send notifications toggle is set or not
1792
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1793
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1794
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1795
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1796
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1797
-            case EEM_Registration::status_id_approved :
1798
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1799
-                $this->approve_registration($notify);
1800
-                break;
1801
-            case EEM_Registration::status_id_pending_payment :
1802
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1803
-                $this->pending_registration($notify);
1804
-                break;
1805
-            case EEM_Registration::status_id_not_approved :
1806
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1807
-                $this->not_approve_registration($notify);
1808
-                break;
1809
-            case EEM_Registration::status_id_declined :
1810
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1811
-                $this->decline_registration($notify);
1812
-                break;
1813
-            case EEM_Registration::status_id_cancelled :
1814
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1815
-                $this->cancel_registration($notify);
1816
-                break;
1817
-            case EEM_Registration::status_id_wait_list :
1818
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1819
-                $this->wait_list_registration($notify);
1820
-                break;
1821
-            case EEM_Registration::status_id_incomplete :
1822
-            default :
1823
-                $result['success'] = false;
1824
-                unset($this->_req_data['return']);
1825
-                $this->_reg_status_change_return('', false);
1826
-                break;
1827
-        }
1828
-    }
1829
-
1830
-
1831
-    /**
1832
-     * approve_registration
1833
-     *
1834
-     * @access protected
1835
-     * @param bool $notify whether or not to notify the registrant about their approval.
1836
-     * @return void
1837
-     */
1838
-    protected function approve_registration($notify = false)
1839
-    {
1840
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1841
-    }
1842
-
1843
-
1844
-    /**
1845
-     *        decline_registration
1846
-     *
1847
-     * @access protected
1848
-     * @param bool $notify whether or not to notify the registrant about their status change.
1849
-     * @return void
1850
-     */
1851
-    protected function decline_registration($notify = false)
1852
-    {
1853
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1854
-    }
1855
-
1856
-
1857
-    /**
1858
-     *        cancel_registration
1859
-     *
1860
-     * @access protected
1861
-     * @param bool $notify whether or not to notify the registrant about their status change.
1862
-     * @return void
1863
-     */
1864
-    protected function cancel_registration($notify = false)
1865
-    {
1866
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1867
-    }
1868
-
1869
-
1870
-    /**
1871
-     *        not_approve_registration
1872
-     *
1873
-     * @access protected
1874
-     * @param bool $notify whether or not to notify the registrant about their status change.
1875
-     * @return void
1876
-     */
1877
-    protected function not_approve_registration($notify = false)
1878
-    {
1879
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1880
-    }
1881
-
1882
-
1883
-    /**
1884
-     *        decline_registration
1885
-     *
1886
-     * @access protected
1887
-     * @param bool $notify whether or not to notify the registrant about their status change.
1888
-     * @return void
1889
-     */
1890
-    protected function pending_registration($notify = false)
1891
-    {
1892
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1893
-    }
1894
-
1895
-
1896
-    /**
1897
-     * waitlist_registration
1898
-     *
1899
-     * @access protected
1900
-     * @param bool $notify whether or not to notify the registrant about their status change.
1901
-     * @return void
1902
-     */
1903
-    protected function wait_list_registration($notify = false)
1904
-    {
1905
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1906
-    }
1907
-
1908
-
1909
-    /**
1910
-     *        generates HTML for the Registration main meta box
1911
-     *
1912
-     * @access public
1913
-     * @return void
1914
-     * @throws DomainException
1915
-     * @throws EE_Error
1916
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1917
-     */
1918
-    public function _reg_details_meta_box()
1919
-    {
1920
-        EEH_Autoloader::register_line_item_display_autoloaders();
1921
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1922
-        EE_Registry::instance()->load_helper('Line_Item');
1923
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1924
-            : EE_Transaction::new_instance();
1925
-        $this->_session = $transaction->session_data();
1926
-        $filters        = new EE_Line_Item_Filter_Collection();
1927
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1928
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1929
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1930
-            $transaction->total_line_item());
1931
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
1932
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1933
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1934
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1935
-            $filtered_line_item_tree,
1936
-            array('EE_Registration' => $this->_registration)
1937
-        );
1938
-        $attendee                                = $this->_registration->attendee();
1939
-        if (EE_Registry::instance()->CAP->current_user_can(
1940
-            'ee_read_transaction',
1941
-            'espresso_transactions_view_transaction'
1942
-        )) {
1943
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1944
-                EE_Admin_Page::add_query_args_and_nonce(
1945
-                    array(
1946
-                        'action' => 'view_transaction',
1947
-                        'TXN_ID' => $transaction->ID(),
1948
-                    ),
1949
-                    TXN_ADMIN_URL
1950
-                ),
1951
-                esc_html__(' View Transaction', 'event_espresso'),
1952
-                'button secondary-button right',
1953
-                'dashicons dashicons-cart'
1954
-            );
1955
-        } else {
1956
-            $this->_template_args['view_transaction_button'] = '';
1957
-        }
1958
-        if ($attendee instanceof EE_Attendee
1959
-            && EE_Registry::instance()->CAP->current_user_can(
1960
-                'ee_send_message',
1961
-                'espresso_registrations_resend_registration'
1962
-            )
1963
-        ) {
1964
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1965
-                EE_Admin_Page::add_query_args_and_nonce(
1966
-                    array(
1967
-                        'action'      => 'resend_registration',
1968
-                        '_REG_ID'     => $this->_registration->ID(),
1969
-                        'redirect_to' => 'view_registration',
1970
-                    ),
1971
-                    REG_ADMIN_URL
1972
-                ),
1973
-                esc_html__(' Resend Registration', 'event_espresso'),
1974
-                'button secondary-button right',
1975
-                'dashicons dashicons-email-alt'
1976
-            );
1977
-        } else {
1978
-            $this->_template_args['resend_registration_button'] = '';
1979
-        }
1980
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1981
-        $payment                               = $transaction->get_first_related('Payment');
1982
-        $payment                               = ! $payment instanceof EE_Payment
1983
-            ? EE_Payment::new_instance()
1984
-            : $payment;
1985
-        $payment_method                        = $payment->get_first_related('Payment_Method');
1986
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
1987
-            ? EE_Payment_Method::new_instance()
1988
-            : $payment_method;
1989
-        $reg_details                           = array(
1990
-            'payment_method'       => $payment_method->name(),
1991
-            'response_msg'         => $payment->gateway_response(),
1992
-            'registration_id'      => $this->_registration->get('REG_code'),
1993
-            'registration_session' => $this->_registration->session_ID(),
1994
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1995
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1996
-        );
1997
-        if (isset($reg_details['registration_id'])) {
1998
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1999
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2000
-                'Registration ID',
2001
-                'event_espresso'
2002
-            );
2003
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2004
-        }
2005
-        if (isset($reg_details['payment_method'])) {
2006
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2007
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2008
-                'Most Recent Payment Method',
2009
-                'event_espresso'
2010
-            );
2011
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2012
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2013
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2014
-                'Payment method response',
2015
-                'event_espresso'
2016
-            );
2017
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2018
-        }
2019
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2020
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2021
-            'Registration Session',
2022
-            'event_espresso'
2023
-        );
2024
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2025
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2026
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2027
-            'Registration placed from IP',
2028
-            'event_espresso'
2029
-        );
2030
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2031
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2032
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2033
-            'event_espresso');
2034
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2035
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2036
-            array(
2037
-                'action'   => 'default',
2038
-                'event_id' => $this->_registration->event_ID(),
2039
-            ),
2040
-            REG_ADMIN_URL
2041
-        );
2042
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2043
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2044
-        $template_path                                                        =
2045
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2046
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     * generates HTML for the Registration Questions meta box.
2052
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2053
-     * otherwise uses new forms system
2054
-     *
2055
-     * @access public
2056
-     * @return void
2057
-     * @throws DomainException
2058
-     * @throws EE_Error
2059
-     */
2060
-    public function _reg_questions_meta_box()
2061
-    {
2062
-        //allow someone to override this method entirely
2063
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2064
-            $this->_registration)) {
2065
-            $form                                              = $this->_get_reg_custom_questions_form(
2066
-                $this->_registration->ID()
2067
-            );
2068
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2069
-                ? $form->get_html_and_js()
2070
-                : '';
2071
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2072
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2073
-            $template_path                                     =
2074
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2075
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2076
-        }
2077
-    }
2078
-
2079
-
2080
-    /**
2081
-     * form_before_question_group
2082
-     *
2083
-     * @deprecated    as of 4.8.32.rc.000
2084
-     * @access        public
2085
-     * @param        string $output
2086
-     * @return        string
2087
-     */
2088
-    public function form_before_question_group($output)
2089
-    {
2090
-        EE_Error::doing_it_wrong(
2091
-            __CLASS__ . '::' . __FUNCTION__,
2092
-            esc_html__(
2093
-                '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.',
2094
-                'event_espresso'
2095
-            ),
2096
-            '4.8.32.rc.000'
2097
-        );
2098
-        return '
1155
+		if (! empty($registration_status)) {
1156
+			$where['STS_ID'] = $registration_status;
1157
+		} else {
1158
+			//make sure we exclude incomplete registrations, but only if not trashed.
1159
+			if ($view === 'trash') {
1160
+				$where['REG_deleted'] = true;
1161
+			} elseif ($view === 'incomplete') {
1162
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1163
+			} else {
1164
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1165
+			}
1166
+		}
1167
+		return $where;
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1173
+	 *
1174
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1175
+	 * @return array
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	protected function _add_date_to_where_conditions(array $request)
1179
+	{
1180
+		$where = array();
1181
+		$view = EEH_Array::is_set($request, 'status', '');
1182
+		$month_range             = ! empty($request['month_range'])
1183
+			? sanitize_text_field($request['month_range'])
1184
+			: '';
1185
+		$retrieve_for_today      = $view === 'today';
1186
+		$retrieve_for_this_month = $view === 'month';
1187
+
1188
+		if ($retrieve_for_today) {
1189
+			$now               = date('Y-m-d', current_time('timestamp'));
1190
+			$where['REG_date'] = array(
1191
+				'BETWEEN',
1192
+				array(
1193
+					EEM_Registration::instance()->convert_datetime_for_query(
1194
+						'REG_date',
1195
+						$now . ' 00:00:00',
1196
+						'Y-m-d H:i:s'
1197
+					),
1198
+					EEM_Registration::instance()->convert_datetime_for_query(
1199
+						'REG_date',
1200
+						$now . ' 23:59:59',
1201
+						'Y-m-d H:i:s'
1202
+					),
1203
+				),
1204
+			);
1205
+		} elseif ($retrieve_for_this_month) {
1206
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1207
+			$days_this_month        = date('t', current_time('timestamp'));
1208
+			$where['REG_date']      = array(
1209
+				'BETWEEN',
1210
+				array(
1211
+					EEM_Registration::instance()->convert_datetime_for_query(
1212
+						'REG_date',
1213
+						$current_year_and_month . '-01 00:00:00',
1214
+						'Y-m-d H:i:s'
1215
+					),
1216
+					EEM_Registration::instance()->convert_datetime_for_query(
1217
+						'REG_date',
1218
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1219
+						'Y-m-d H:i:s'
1220
+					),
1221
+				),
1222
+			);
1223
+		} elseif ($month_range) {
1224
+			$pieces          = explode(' ', $month_range, 3);
1225
+			$month_requested = ! empty($pieces[0])
1226
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1227
+				: '';
1228
+			$year_requested  = ! empty($pieces[1])
1229
+				? $pieces[1]
1230
+				: '';
1231
+			//if there is not a month or year then we can't go further
1232
+			if ($month_requested && $year_requested) {
1233
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1234
+				$where['REG_date'] = array(
1235
+					'BETWEEN',
1236
+					array(
1237
+						EEM_Registration::instance()->convert_datetime_for_query(
1238
+							'REG_date',
1239
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1240
+							'Y-m-d H:i:s'
1241
+						),
1242
+						EEM_Registration::instance()->convert_datetime_for_query(
1243
+							'REG_date',
1244
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1245
+							'Y-m-d H:i:s'
1246
+						),
1247
+					),
1248
+				);
1249
+			}
1250
+		}
1251
+		return $where;
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 * Adds any provided search restraints to the where conditions for the registrations query
1257
+	 *
1258
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1259
+	 * @return array
1260
+	 */
1261
+	protected function _add_search_to_where_conditions(array $request)
1262
+	{
1263
+		$where = array();
1264
+		if (! empty($request['s'])) {
1265
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1266
+			$where['OR*search_conditions'] = array(
1267
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1268
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1269
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1270
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1271
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1272
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1273
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1274
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1275
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1276
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1277
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1278
+				'REG_final_price'                         => array('LIKE', $search_string),
1279
+				'REG_code'                                => array('LIKE', $search_string),
1280
+				'REG_count'                               => array('LIKE', $search_string),
1281
+				'REG_group_size'                          => array('LIKE', $search_string),
1282
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1283
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1284
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1285
+			);
1286
+		}
1287
+		return $where;
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * Sets up the where conditions for the registrations query.
1293
+	 *
1294
+	 * @param array $request
1295
+	 * @return array
1296
+	 * @throws EE_Error
1297
+	 */
1298
+	protected function _get_where_conditions_for_registrations_query($request)
1299
+	{
1300
+		return apply_filters(
1301
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1302
+			array_merge(
1303
+				$this->_add_event_id_to_where_conditions($request),
1304
+				$this->_add_category_id_to_where_conditions($request),
1305
+				$this->_add_datetime_id_to_where_conditions($request),
1306
+				$this->_add_registration_status_to_where_conditions($request),
1307
+				$this->_add_date_to_where_conditions($request),
1308
+				$this->_add_search_to_where_conditions($request)
1309
+			),
1310
+			$request
1311
+		);
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Sets up the orderby for the registrations query.
1317
+	 *
1318
+	 * @return array
1319
+	 */
1320
+	protected function _get_orderby_for_registrations_query()
1321
+	{
1322
+		$orderby_field = ! empty($this->_req_data['orderby'])
1323
+			? sanitize_text_field($this->_req_data['orderby'])
1324
+			: '';
1325
+		switch ($orderby_field) {
1326
+			case '_REG_ID':
1327
+				$orderby_field = 'REG_ID';
1328
+				break;
1329
+			case '_Reg_status':
1330
+				$orderby_field = 'STS_ID';
1331
+				break;
1332
+			case 'ATT_fname':
1333
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1334
+				break;
1335
+			case 'ATT_lname':
1336
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1337
+				break;
1338
+			case 'event_name':
1339
+				$orderby_field = 'Event.EVT_name';
1340
+				break;
1341
+			case 'DTT_EVT_start':
1342
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1343
+				break;
1344
+			default: //'REG_date'
1345
+				$orderby_field = 'REG_date';
1346
+		}
1347
+
1348
+		//order
1349
+		$order = ! empty($this->_req_data['order'])
1350
+			? sanitize_text_field($this->_req_data['order'])
1351
+			: 'DESC';
1352
+
1353
+		//mutate orderby_field
1354
+		$orderby_field = array_combine(
1355
+			(array) $orderby_field,
1356
+			array_fill(0, count($orderby_field), $order)
1357
+		);
1358
+		return array('order_by' => $orderby_field);
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * Sets up the limit for the registrations query.
1364
+	 *
1365
+	 * @param $per_page
1366
+	 * @return array
1367
+	 */
1368
+	protected function _get_limit($per_page)
1369
+	{
1370
+		$current_page = ! empty($this->_req_data['paged'])
1371
+			? absint($this->_req_data['paged'])
1372
+			: 1;
1373
+		$per_page     = ! empty($this->_req_data['perpage'])
1374
+			? $this->_req_data['perpage']
1375
+			: $per_page;
1376
+
1377
+		//-1 means return all results so get out if that's set.
1378
+		if ((int)$per_page === -1) {
1379
+			return array();
1380
+		}
1381
+		$per_page = absint($per_page);
1382
+		$offset   = ($current_page - 1) * $per_page;
1383
+		return array('limit' => array($offset, $per_page));
1384
+	}
1385
+
1386
+
1387
+	public function get_registration_status_array()
1388
+	{
1389
+		return self::$_reg_status;
1390
+	}
1391
+
1392
+
1393
+
1394
+
1395
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1396
+	/**
1397
+	 *        generates HTML for the View Registration Details Admin page
1398
+	 *
1399
+	 * @access protected
1400
+	 * @return void
1401
+	 * @throws DomainException
1402
+	 * @throws EE_Error
1403
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1404
+	 */
1405
+	protected function _registration_details()
1406
+	{
1407
+		$this->_template_args = array();
1408
+		$this->_set_registration_object();
1409
+		if (is_object($this->_registration)) {
1410
+			$transaction                                   = $this->_registration->transaction()
1411
+				? $this->_registration->transaction()
1412
+				: EE_Transaction::new_instance();
1413
+			$this->_session                                = $transaction->session_data();
1414
+			$event_id                                      = $this->_registration->event_ID();
1415
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1416
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1417
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1418
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1419
+			$this->_template_args['grand_total']           = $transaction->total();
1420
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1421
+			// link back to overview
1422
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1423
+			$this->_template_args['registration']                = $this->_registration;
1424
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1425
+				array(
1426
+					'action'   => 'default',
1427
+					'event_id' => $event_id,
1428
+				),
1429
+				REG_ADMIN_URL
1430
+			);
1431
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1432
+				array(
1433
+					'action' => 'default',
1434
+					'EVT_ID' => $event_id,
1435
+					'page'   => 'espresso_transactions',
1436
+				),
1437
+				admin_url('admin.php')
1438
+			);
1439
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1440
+				array(
1441
+					'page'   => 'espresso_events',
1442
+					'action' => 'edit',
1443
+					'post'   => $event_id,
1444
+				),
1445
+				admin_url('admin.php')
1446
+			);
1447
+			//next and previous links
1448
+			$next_reg                                      = $this->_registration->next(
1449
+				null,
1450
+				array(),
1451
+				'REG_ID'
1452
+			);
1453
+			$this->_template_args['next_registration']     = $next_reg
1454
+				? $this->_next_link(
1455
+					EE_Admin_Page::add_query_args_and_nonce(
1456
+						array(
1457
+							'action'  => 'view_registration',
1458
+							'_REG_ID' => $next_reg['REG_ID'],
1459
+						),
1460
+						REG_ADMIN_URL
1461
+					),
1462
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1463
+				)
1464
+				: '';
1465
+			$previous_reg                                  = $this->_registration->previous(
1466
+				null,
1467
+				array(),
1468
+				'REG_ID'
1469
+			);
1470
+			$this->_template_args['previous_registration'] = $previous_reg
1471
+				? $this->_previous_link(
1472
+					EE_Admin_Page::add_query_args_and_nonce(
1473
+						array(
1474
+							'action'  => 'view_registration',
1475
+							'_REG_ID' => $previous_reg['REG_ID'],
1476
+						),
1477
+						REG_ADMIN_URL
1478
+					),
1479
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1480
+				)
1481
+				: '';
1482
+			// grab header
1483
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1484
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1485
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1486
+				$template_path,
1487
+				$this->_template_args,
1488
+				true
1489
+			);
1490
+		} else {
1491
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1492
+		}
1493
+		// the details template wrapper
1494
+		$this->display_admin_page_with_sidebar();
1495
+	}
1496
+
1497
+
1498
+	protected function _registration_details_metaboxes()
1499
+	{
1500
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1501
+		$this->_set_registration_object();
1502
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1503
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1504
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1505
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1506
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1507
+		if ($attendee instanceof EE_Attendee
1508
+			&& EE_Registry::instance()->CAP->current_user_can(
1509
+				'ee_edit_registration',
1510
+				'edit-reg-questions-mbox'
1511
+			)
1512
+		) {
1513
+			add_meta_box(
1514
+				'edit-reg-questions-mbox',
1515
+				esc_html__('Registration Form Answers', 'event_espresso'),
1516
+				array($this, '_reg_questions_meta_box'),
1517
+				$this->wp_page_slug,
1518
+				'normal',
1519
+				'high'
1520
+			);
1521
+		}
1522
+		add_meta_box(
1523
+			'edit-reg-registrant-mbox',
1524
+			esc_html__('Contact Details', 'event_espresso'),
1525
+			array($this, '_reg_registrant_side_meta_box'),
1526
+			$this->wp_page_slug,
1527
+			'side',
1528
+			'high'
1529
+		);
1530
+		if ($this->_registration->group_size() > 1) {
1531
+			add_meta_box(
1532
+				'edit-reg-attendees-mbox',
1533
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1534
+				array($this, '_reg_attendees_meta_box'),
1535
+				$this->wp_page_slug,
1536
+				'normal',
1537
+				'high'
1538
+			);
1539
+		}
1540
+	}
1541
+
1542
+
1543
+	/**
1544
+	 * set_reg_status_buttons_metabox
1545
+	 *
1546
+	 * @access protected
1547
+	 * @return string
1548
+	 * @throws \EE_Error
1549
+	 */
1550
+	public function set_reg_status_buttons_metabox()
1551
+	{
1552
+		$this->_set_registration_object();
1553
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1554
+		echo $change_reg_status_form->form_open(
1555
+			self::add_query_args_and_nonce(
1556
+				array(
1557
+					'action' => 'change_reg_status',
1558
+				),
1559
+				REG_ADMIN_URL
1560
+			)
1561
+		);
1562
+		echo $change_reg_status_form->get_html();
1563
+		echo $change_reg_status_form->form_close();
1564
+	}
1565
+
1566
+
1567
+
1568
+	/**
1569
+	 * @return EE_Form_Section_Proper
1570
+	 * @throws EE_Error
1571
+	 */
1572
+	protected function _generate_reg_status_change_form()
1573
+	{
1574
+		return new EE_Form_Section_Proper(array(
1575
+			'name'            => 'reg_status_change_form',
1576
+			'html_id'         => 'reg-status-change-form',
1577
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1578
+			'subsections'     => array(
1579
+				'return'             => new EE_Hidden_Input(array(
1580
+					'name'    => 'return',
1581
+					'default' => 'view_registration',
1582
+				)),
1583
+				'REG_ID'             => new EE_Hidden_Input(array(
1584
+					'name'    => 'REG_ID',
1585
+					'default' => $this->_registration->ID(),
1586
+				)),
1587
+				'current_status'     => new EE_Form_Section_HTML(
1588
+					EEH_HTML::tr(
1589
+						EEH_HTML::th(
1590
+							EEH_HTML::label(
1591
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1592
+								)
1593
+							)
1594
+						)
1595
+						. EEH_HTML::td(
1596
+							EEH_HTML::strong(
1597
+								$this->_registration->pretty_status(),
1598
+								'',
1599
+								'status-' . $this->_registration->status_ID(),
1600
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1601
+							)
1602
+						)
1603
+					)
1604
+				),
1605
+				'reg_status'         => new EE_Select_Input(
1606
+					$this->_get_reg_statuses(),
1607
+					array(
1608
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1609
+						'default'         => $this->_registration->status_ID(),
1610
+					)
1611
+				),
1612
+				'send_notifications' => new EE_Yes_No_Input(
1613
+					array(
1614
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1615
+						'default'         => false,
1616
+						'html_help_text'  => esc_html__(
1617
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1618
+							'event_espresso'
1619
+						),
1620
+					)
1621
+				),
1622
+				'submit'             => new EE_Submit_Input(
1623
+					array(
1624
+						'html_class'      => 'button-primary',
1625
+						'html_label_text' => '&nbsp;',
1626
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1627
+					)
1628
+				),
1629
+			),
1630
+		));
1631
+	}
1632
+
1633
+
1634
+	/**
1635
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1636
+	 *
1637
+	 * @return array
1638
+	 * @throws EE_Error
1639
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1640
+	 */
1641
+	protected function _get_reg_statuses()
1642
+	{
1643
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1644
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1645
+		// get current reg status
1646
+		$current_status = $this->_registration->status_ID();
1647
+		// is registration for free event? This will determine whether to display the pending payment option
1648
+		if (
1649
+			$current_status !== EEM_Registration::status_id_pending_payment
1650
+			&& $this->_registration->transaction()->is_free()
1651
+		) {
1652
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1653
+		}
1654
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1655
+	}
1656
+
1657
+
1658
+
1659
+	/**
1660
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1661
+	 *
1662
+	 * @param bool $status REG status given for changing registrations to.
1663
+	 * @param bool $notify Whether to send messages notifications or not.
1664
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1665
+	 * @throws \EE_Error
1666
+	 */
1667
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1668
+	{
1669
+		if (isset($this->_req_data['reg_status_change_form'])) {
1670
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1671
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
+		} else {
1673
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
+		}
1675
+		$success = $this->_set_registration_status($REG_IDs, $status);
1676
+		//notify?
1677
+		if ($success
1678
+			&& $notify
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 $success;
1687
+	}
1688
+
1689
+
1690
+
1691
+	/**
1692
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
+	 *
1695
+	 * @param array $REG_IDs
1696
+	 * @param bool  $status
1697
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
+	 * @throws \RuntimeException
1699
+	 * @throws \EE_Error
1700
+	 *               the array of updated registrations).
1701
+	 * @throws EE_Error
1702
+	 * @throws RuntimeException
1703
+	 */
1704
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1705
+	{
1706
+		$success = false;
1707
+		// typecast $REG_IDs
1708
+		$REG_IDs = (array)$REG_IDs;
1709
+		if ( ! empty($REG_IDs)) {
1710
+			$success = true;
1711
+			// set default status if none is passed
1712
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1713
+			// sanitize $REG_IDs
1714
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1715
+			//loop through REG_ID's and change status
1716
+			foreach ($REG_IDs as $REG_ID) {
1717
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1718
+				if ($registration instanceof EE_Registration) {
1719
+					$registration->set_status($status);
1720
+					$result = $registration->save();
1721
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1722
+					$success = $result !== false ? $success : false;
1723
+				}
1724
+			}
1725
+		}
1726
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1727
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1728
+		//return $success and processed registrations
1729
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1730
+	}
1731
+
1732
+
1733
+	/**
1734
+	 * Common logic for setting up success message and redirecting to appropriate route
1735
+	 *
1736
+	 * @param  string $STS_ID status id for the registration changed to
1737
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1738
+	 * @return void
1739
+	 */
1740
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1741
+	{
1742
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1743
+			: array('success' => false);
1744
+		$success = isset($result['success']) && $result['success'];
1745
+		//setup success message
1746
+		if ($success) {
1747
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1748
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1749
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1750
+			} else {
1751
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1752
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1753
+			}
1754
+			EE_Error::add_success($msg);
1755
+		} else {
1756
+			EE_Error::add_error(
1757
+				esc_html__(
1758
+					'Something went wrong, and the status was not changed',
1759
+					'event_espresso'
1760
+				), __FILE__, __LINE__, __FUNCTION__
1761
+			);
1762
+		}
1763
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1764
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1765
+		} else {
1766
+			$route = array('action' => 'default');
1767
+		}
1768
+		//unset nonces
1769
+		foreach ($this->_req_data as $ref => $value) {
1770
+			if (strpos($ref, 'nonce') !== false) {
1771
+				unset($this->_req_data[$ref]);
1772
+				continue;
1773
+			}
1774
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1775
+			$this->_req_data[$ref] = $value;
1776
+		}
1777
+		//merge request vars so that the reloaded list table contains any existing filter query params
1778
+		$route = array_merge($this->_req_data, $route);
1779
+		$this->_redirect_after_action($success, '', '', $route, true);
1780
+	}
1781
+
1782
+
1783
+	/**
1784
+	 * incoming reg status change from reg details page.
1785
+	 *
1786
+	 * @return void
1787
+	 */
1788
+	protected function _change_reg_status()
1789
+	{
1790
+		$this->_req_data['return'] = 'view_registration';
1791
+		//set notify based on whether the send notifications toggle is set or not
1792
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1793
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1794
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1795
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1796
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1797
+			case EEM_Registration::status_id_approved :
1798
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1799
+				$this->approve_registration($notify);
1800
+				break;
1801
+			case EEM_Registration::status_id_pending_payment :
1802
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1803
+				$this->pending_registration($notify);
1804
+				break;
1805
+			case EEM_Registration::status_id_not_approved :
1806
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1807
+				$this->not_approve_registration($notify);
1808
+				break;
1809
+			case EEM_Registration::status_id_declined :
1810
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1811
+				$this->decline_registration($notify);
1812
+				break;
1813
+			case EEM_Registration::status_id_cancelled :
1814
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1815
+				$this->cancel_registration($notify);
1816
+				break;
1817
+			case EEM_Registration::status_id_wait_list :
1818
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1819
+				$this->wait_list_registration($notify);
1820
+				break;
1821
+			case EEM_Registration::status_id_incomplete :
1822
+			default :
1823
+				$result['success'] = false;
1824
+				unset($this->_req_data['return']);
1825
+				$this->_reg_status_change_return('', false);
1826
+				break;
1827
+		}
1828
+	}
1829
+
1830
+
1831
+	/**
1832
+	 * approve_registration
1833
+	 *
1834
+	 * @access protected
1835
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1836
+	 * @return void
1837
+	 */
1838
+	protected function approve_registration($notify = false)
1839
+	{
1840
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1841
+	}
1842
+
1843
+
1844
+	/**
1845
+	 *        decline_registration
1846
+	 *
1847
+	 * @access protected
1848
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1849
+	 * @return void
1850
+	 */
1851
+	protected function decline_registration($notify = false)
1852
+	{
1853
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1854
+	}
1855
+
1856
+
1857
+	/**
1858
+	 *        cancel_registration
1859
+	 *
1860
+	 * @access protected
1861
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1862
+	 * @return void
1863
+	 */
1864
+	protected function cancel_registration($notify = false)
1865
+	{
1866
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1867
+	}
1868
+
1869
+
1870
+	/**
1871
+	 *        not_approve_registration
1872
+	 *
1873
+	 * @access protected
1874
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1875
+	 * @return void
1876
+	 */
1877
+	protected function not_approve_registration($notify = false)
1878
+	{
1879
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1880
+	}
1881
+
1882
+
1883
+	/**
1884
+	 *        decline_registration
1885
+	 *
1886
+	 * @access protected
1887
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1888
+	 * @return void
1889
+	 */
1890
+	protected function pending_registration($notify = false)
1891
+	{
1892
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1893
+	}
1894
+
1895
+
1896
+	/**
1897
+	 * waitlist_registration
1898
+	 *
1899
+	 * @access protected
1900
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1901
+	 * @return void
1902
+	 */
1903
+	protected function wait_list_registration($notify = false)
1904
+	{
1905
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1906
+	}
1907
+
1908
+
1909
+	/**
1910
+	 *        generates HTML for the Registration main meta box
1911
+	 *
1912
+	 * @access public
1913
+	 * @return void
1914
+	 * @throws DomainException
1915
+	 * @throws EE_Error
1916
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1917
+	 */
1918
+	public function _reg_details_meta_box()
1919
+	{
1920
+		EEH_Autoloader::register_line_item_display_autoloaders();
1921
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1922
+		EE_Registry::instance()->load_helper('Line_Item');
1923
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1924
+			: EE_Transaction::new_instance();
1925
+		$this->_session = $transaction->session_data();
1926
+		$filters        = new EE_Line_Item_Filter_Collection();
1927
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1928
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1929
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1930
+			$transaction->total_line_item());
1931
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
1932
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1933
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1934
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1935
+			$filtered_line_item_tree,
1936
+			array('EE_Registration' => $this->_registration)
1937
+		);
1938
+		$attendee                                = $this->_registration->attendee();
1939
+		if (EE_Registry::instance()->CAP->current_user_can(
1940
+			'ee_read_transaction',
1941
+			'espresso_transactions_view_transaction'
1942
+		)) {
1943
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1944
+				EE_Admin_Page::add_query_args_and_nonce(
1945
+					array(
1946
+						'action' => 'view_transaction',
1947
+						'TXN_ID' => $transaction->ID(),
1948
+					),
1949
+					TXN_ADMIN_URL
1950
+				),
1951
+				esc_html__(' View Transaction', 'event_espresso'),
1952
+				'button secondary-button right',
1953
+				'dashicons dashicons-cart'
1954
+			);
1955
+		} else {
1956
+			$this->_template_args['view_transaction_button'] = '';
1957
+		}
1958
+		if ($attendee instanceof EE_Attendee
1959
+			&& EE_Registry::instance()->CAP->current_user_can(
1960
+				'ee_send_message',
1961
+				'espresso_registrations_resend_registration'
1962
+			)
1963
+		) {
1964
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1965
+				EE_Admin_Page::add_query_args_and_nonce(
1966
+					array(
1967
+						'action'      => 'resend_registration',
1968
+						'_REG_ID'     => $this->_registration->ID(),
1969
+						'redirect_to' => 'view_registration',
1970
+					),
1971
+					REG_ADMIN_URL
1972
+				),
1973
+				esc_html__(' Resend Registration', 'event_espresso'),
1974
+				'button secondary-button right',
1975
+				'dashicons dashicons-email-alt'
1976
+			);
1977
+		} else {
1978
+			$this->_template_args['resend_registration_button'] = '';
1979
+		}
1980
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1981
+		$payment                               = $transaction->get_first_related('Payment');
1982
+		$payment                               = ! $payment instanceof EE_Payment
1983
+			? EE_Payment::new_instance()
1984
+			: $payment;
1985
+		$payment_method                        = $payment->get_first_related('Payment_Method');
1986
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
1987
+			? EE_Payment_Method::new_instance()
1988
+			: $payment_method;
1989
+		$reg_details                           = array(
1990
+			'payment_method'       => $payment_method->name(),
1991
+			'response_msg'         => $payment->gateway_response(),
1992
+			'registration_id'      => $this->_registration->get('REG_code'),
1993
+			'registration_session' => $this->_registration->session_ID(),
1994
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1995
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1996
+		);
1997
+		if (isset($reg_details['registration_id'])) {
1998
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1999
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2000
+				'Registration ID',
2001
+				'event_espresso'
2002
+			);
2003
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2004
+		}
2005
+		if (isset($reg_details['payment_method'])) {
2006
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2007
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2008
+				'Most Recent Payment Method',
2009
+				'event_espresso'
2010
+			);
2011
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2012
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2013
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2014
+				'Payment method response',
2015
+				'event_espresso'
2016
+			);
2017
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2018
+		}
2019
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2020
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2021
+			'Registration Session',
2022
+			'event_espresso'
2023
+		);
2024
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2025
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2026
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2027
+			'Registration placed from IP',
2028
+			'event_espresso'
2029
+		);
2030
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2031
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2032
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2033
+			'event_espresso');
2034
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2035
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2036
+			array(
2037
+				'action'   => 'default',
2038
+				'event_id' => $this->_registration->event_ID(),
2039
+			),
2040
+			REG_ADMIN_URL
2041
+		);
2042
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2043
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2044
+		$template_path                                                        =
2045
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2046
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 * generates HTML for the Registration Questions meta box.
2052
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2053
+	 * otherwise uses new forms system
2054
+	 *
2055
+	 * @access public
2056
+	 * @return void
2057
+	 * @throws DomainException
2058
+	 * @throws EE_Error
2059
+	 */
2060
+	public function _reg_questions_meta_box()
2061
+	{
2062
+		//allow someone to override this method entirely
2063
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2064
+			$this->_registration)) {
2065
+			$form                                              = $this->_get_reg_custom_questions_form(
2066
+				$this->_registration->ID()
2067
+			);
2068
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2069
+				? $form->get_html_and_js()
2070
+				: '';
2071
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2072
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2073
+			$template_path                                     =
2074
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2075
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2076
+		}
2077
+	}
2078
+
2079
+
2080
+	/**
2081
+	 * form_before_question_group
2082
+	 *
2083
+	 * @deprecated    as of 4.8.32.rc.000
2084
+	 * @access        public
2085
+	 * @param        string $output
2086
+	 * @return        string
2087
+	 */
2088
+	public function form_before_question_group($output)
2089
+	{
2090
+		EE_Error::doing_it_wrong(
2091
+			__CLASS__ . '::' . __FUNCTION__,
2092
+			esc_html__(
2093
+				'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.',
2094
+				'event_espresso'
2095
+			),
2096
+			'4.8.32.rc.000'
2097
+		);
2098
+		return '
2099 2099
 	<table class="form-table ee-width-100">
2100 2100
 		<tbody>
2101 2101
 			';
2102
-    }
2103
-
2104
-
2105
-    /**
2106
-     * form_after_question_group
2107
-     *
2108
-     * @deprecated    as of 4.8.32.rc.000
2109
-     * @access        public
2110
-     * @param        string $output
2111
-     * @return        string
2112
-     */
2113
-    public function form_after_question_group($output)
2114
-    {
2115
-        EE_Error::doing_it_wrong(
2116
-            __CLASS__ . '::' . __FUNCTION__,
2117
-            esc_html__(
2118
-                '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.',
2119
-                'event_espresso'
2120
-            ),
2121
-            '4.8.32.rc.000'
2122
-        );
2123
-        return '
2102
+	}
2103
+
2104
+
2105
+	/**
2106
+	 * form_after_question_group
2107
+	 *
2108
+	 * @deprecated    as of 4.8.32.rc.000
2109
+	 * @access        public
2110
+	 * @param        string $output
2111
+	 * @return        string
2112
+	 */
2113
+	public function form_after_question_group($output)
2114
+	{
2115
+		EE_Error::doing_it_wrong(
2116
+			__CLASS__ . '::' . __FUNCTION__,
2117
+			esc_html__(
2118
+				'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.',
2119
+				'event_espresso'
2120
+			),
2121
+			'4.8.32.rc.000'
2122
+		);
2123
+		return '
2124 2124
 			<tr class="hide-if-no-js">
2125 2125
 				<th> </th>
2126 2126
 				<td class="reg-admin-edit-attendee-question-td">
2127 2127
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2128
-               . esc_attr__('click to edit question', 'event_espresso')
2129
-               . '">
2128
+			   . esc_attr__('click to edit question', 'event_espresso')
2129
+			   . '">
2130 2130
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2131
-               . esc_html__('edit the above question group', 'event_espresso')
2132
-               . '</span>
2131
+			   . esc_html__('edit the above question group', 'event_espresso')
2132
+			   . '</span>
2133 2133
 						<div class="dashicons dashicons-edit"></div>
2134 2134
 					</a>
2135 2135
 				</td>
@@ -2137,558 +2137,558 @@  discard block
 block discarded – undo
2137 2137
 		</tbody>
2138 2138
 	</table>
2139 2139
 ';
2140
-    }
2141
-
2142
-
2143
-    /**
2144
-     * form_form_field_label_wrap
2145
-     *
2146
-     * @deprecated    as of 4.8.32.rc.000
2147
-     * @access        public
2148
-     * @param        string $label
2149
-     * @return        string
2150
-     */
2151
-    public function form_form_field_label_wrap($label)
2152
-    {
2153
-        EE_Error::doing_it_wrong(
2154
-            __CLASS__ . '::' . __FUNCTION__,
2155
-            esc_html__(
2156
-                '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.',
2157
-                'event_espresso'
2158
-            ),
2159
-            '4.8.32.rc.000'
2160
-        );
2161
-        return '
2140
+	}
2141
+
2142
+
2143
+	/**
2144
+	 * form_form_field_label_wrap
2145
+	 *
2146
+	 * @deprecated    as of 4.8.32.rc.000
2147
+	 * @access        public
2148
+	 * @param        string $label
2149
+	 * @return        string
2150
+	 */
2151
+	public function form_form_field_label_wrap($label)
2152
+	{
2153
+		EE_Error::doing_it_wrong(
2154
+			__CLASS__ . '::' . __FUNCTION__,
2155
+			esc_html__(
2156
+				'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.',
2157
+				'event_espresso'
2158
+			),
2159
+			'4.8.32.rc.000'
2160
+		);
2161
+		return '
2162 2162
 			<tr>
2163 2163
 				<th>
2164 2164
 					' . $label . '
2165 2165
 				</th>';
2166
-    }
2167
-
2168
-
2169
-    /**
2170
-     * form_form_field_input__wrap
2171
-     *
2172
-     * @deprecated    as of 4.8.32.rc.000
2173
-     * @access        public
2174
-     * @param        string $input
2175
-     * @return        string
2176
-     */
2177
-    public function form_form_field_input__wrap($input)
2178
-    {
2179
-        EE_Error::doing_it_wrong(
2180
-            __CLASS__ . '::' . __FUNCTION__,
2181
-            esc_html__(
2182
-                '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.',
2183
-                'event_espresso'
2184
-            ),
2185
-            '4.8.32.rc.000'
2186
-        );
2187
-        return '
2166
+	}
2167
+
2168
+
2169
+	/**
2170
+	 * form_form_field_input__wrap
2171
+	 *
2172
+	 * @deprecated    as of 4.8.32.rc.000
2173
+	 * @access        public
2174
+	 * @param        string $input
2175
+	 * @return        string
2176
+	 */
2177
+	public function form_form_field_input__wrap($input)
2178
+	{
2179
+		EE_Error::doing_it_wrong(
2180
+			__CLASS__ . '::' . __FUNCTION__,
2181
+			esc_html__(
2182
+				'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.',
2183
+				'event_espresso'
2184
+			),
2185
+			'4.8.32.rc.000'
2186
+		);
2187
+		return '
2188 2188
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2189 2189
 					' . $input . '
2190 2190
 				</td>
2191 2191
 			</tr>';
2192
-    }
2193
-
2194
-
2195
-    /**
2196
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2197
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2198
-     * to display the page
2199
-     *
2200
-     * @access protected
2201
-     * @return void
2202
-     * @throws EE_Error
2203
-     */
2204
-    protected function _update_attendee_registration_form()
2205
-    {
2206
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2207
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2208
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2209
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2210
-            if ($success) {
2211
-                $what  = esc_html__('Registration Form', 'event_espresso');
2212
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2213
-                    : array('action' => 'default');
2214
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2215
-            }
2216
-        }
2217
-    }
2218
-
2219
-
2220
-    /**
2221
-     * Gets the form for saving registrations custom questions (if done
2222
-     * previously retrieves the cached form object, which may have validation errors in it)
2223
-     *
2224
-     * @param int $REG_ID
2225
-     * @return EE_Registration_Custom_Questions_Form
2226
-     * @throws EE_Error
2227
-     */
2228
-    protected function _get_reg_custom_questions_form($REG_ID)
2229
-    {
2230
-        if ( ! $this->_reg_custom_questions_form) {
2231
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2232
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2233
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2234
-            );
2235
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2236
-        }
2237
-        return $this->_reg_custom_questions_form;
2238
-    }
2239
-
2240
-
2241
-    /**
2242
-     * Saves
2243
-     *
2244
-     * @access private
2245
-     * @param bool $REG_ID
2246
-     * @return bool
2247
-     * @throws EE_Error
2248
-     */
2249
-    private function _save_reg_custom_questions_form($REG_ID = false)
2250
-    {
2251
-        if ( ! $REG_ID) {
2252
-            EE_Error::add_error(
2253
-                esc_html__(
2254
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2255
-                __FILE__, __FUNCTION__, __LINE__
2256
-            );
2257
-        }
2258
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2259
-        $form->receive_form_submission($this->_req_data);
2260
-        $success = false;
2261
-        if ($form->is_valid()) {
2262
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2263
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2264
-                    $where_conditions    = array(
2265
-                        'QST_ID' => $question_id,
2266
-                        'REG_ID' => $REG_ID,
2267
-                    );
2268
-                    $possibly_new_values = array(
2269
-                        'ANS_value' => $input->normalized_value(),
2270
-                    );
2271
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2272
-                    if ($answer instanceof EE_Answer) {
2273
-                        $success = $answer->save($possibly_new_values);
2274
-                    } else {
2275
-                        //insert it then
2276
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2277
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2278
-                        $success     = $answer->save();
2279
-                    }
2280
-                }
2281
-            }
2282
-        } else {
2283
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2284
-        }
2285
-        return $success;
2286
-    }
2287
-
2288
-
2289
-    /**
2290
-     *        generates HTML for the Registration main meta box
2291
-     *
2292
-     * @access public
2293
-     * @return void
2294
-     * @throws DomainException
2295
-     * @throws EE_Error
2296
-     */
2297
-    public function _reg_attendees_meta_box()
2298
-    {
2299
-        $REG = EEM_Registration::instance();
2300
-        //get all other registrations on this transaction, and cache
2301
-        //the attendees for them so we don't have to run another query using force_join
2302
-        $registrations                           = $REG->get_all(array(
2303
-            array(
2304
-                'TXN_ID' => $this->_registration->transaction_ID(),
2305
-                'REG_ID' => array('!=', $this->_registration->ID()),
2306
-            ),
2307
-            'force_join' => array('Attendee'),
2308
-        ));
2309
-        $this->_template_args['attendees']       = array();
2310
-        $this->_template_args['attendee_notice'] = '';
2311
-        if (empty($registrations)
2312
-            || (is_array($registrations)
2313
-                && ! EEH_Array::get_one_item_from_array($registrations))
2314
-        ) {
2315
-            EE_Error::add_error(
2316
-                esc_html__(
2317
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2318
-                    'event_espresso'
2319
-                ), __FILE__, __FUNCTION__, __LINE__
2320
-            );
2321
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2322
-        } else {
2323
-            $att_nmbr = 1;
2324
-            foreach ($registrations as $registration) {
2325
-                /* @var $registration EE_Registration */
2326
-                $attendee                                                    = $registration->attendee()
2327
-                    ? $registration->attendee()
2328
-                    : EEM_Attendee::instance()
2329
-                                  ->create_default_object();
2330
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2331
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2332
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2333
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2334
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2335
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2336
-                    ', ',
2337
-                    $attendee->full_address_as_array()
2338
-                );
2339
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2340
-                    array(
2341
-                        'action' => 'edit_attendee',
2342
-                        'post'   => $attendee->ID(),
2343
-                    ),
2344
-                    REG_ADMIN_URL
2345
-                );
2346
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2347
-                $att_nmbr++;
2348
-            }
2349
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2350
-        }
2351
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2352
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2353
-    }
2354
-
2355
-
2356
-    /**
2357
-     *        generates HTML for the Edit Registration side meta box
2358
-     *
2359
-     * @access public
2360
-     * @return void
2361
-     * @throws DomainException
2362
-     * @throws EE_Error
2363
-     */
2364
-    public function _reg_registrant_side_meta_box()
2365
-    {
2366
-        /*@var $attendee EE_Attendee */
2367
-        $att_check = $this->_registration->attendee();
2368
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2369
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2370
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2371
-        //primary registration object (that way we know if we need to show create button or not)
2372
-        if ( ! $this->_registration->is_primary_registrant()) {
2373
-            $primary_registration = $this->_registration->get_primary_registration();
2374
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2375
-                : null;
2376
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2377
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2378
-                //custom attendee object so let's not worry about the primary reg.
2379
-                $primary_registration = null;
2380
-            }
2381
-        } else {
2382
-            $primary_registration = null;
2383
-        }
2384
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2385
-        $this->_template_args['fname']             = $attendee->fname();
2386
-        $this->_template_args['lname']             = $attendee->lname();
2387
-        $this->_template_args['email']             = $attendee->email();
2388
-        $this->_template_args['phone']             = $attendee->phone();
2389
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2390
-        //edit link
2391
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2392
-            'action' => 'edit_attendee',
2393
-            'post'   => $attendee->ID(),
2394
-        ), REG_ADMIN_URL);
2395
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2396
-        //create link
2397
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2398
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2399
-                'action'  => 'duplicate_attendee',
2400
-                '_REG_ID' => $this->_registration->ID(),
2401
-            ), REG_ADMIN_URL) : '';
2402
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2403
-        $this->_template_args['att_check']    = $att_check;
2404
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2405
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2406
-    }
2407
-
2408
-
2409
-    /**
2410
-     * trash or restore registrations
2411
-     *
2412
-     * @param  boolean $trash whether to archive or restore
2413
-     * @return void
2414
-     * @throws EE_Error
2415
-     * @throws RuntimeException
2416
-     * @access protected
2417
-     */
2418
-    protected function _trash_or_restore_registrations($trash = true)
2419
-    {
2420
-        //if empty _REG_ID then get out because there's nothing to do
2421
-        if (empty($this->_req_data['_REG_ID'])) {
2422
-            EE_Error::add_error(
2423
-                sprintf(
2424
-                    esc_html__(
2425
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2426
-                        'event_espresso'
2427
-                    ),
2428
-                    $trash ? 'trash' : 'restore'
2429
-                ),
2430
-                __FILE__, __LINE__, __FUNCTION__
2431
-            );
2432
-            $this->_redirect_after_action(false, '', '', array(), true);
2433
-        }
2434
-        $success = 0;
2435
-        $overwrite_msgs = false;
2436
-        //Checkboxes
2437
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2438
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2439
-        }
2440
-        $reg_count = count($this->_req_data['_REG_ID']);
2441
-        // cycle thru checkboxes
2442
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2443
-            /** @var EE_Registration $REG */
2444
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2445
-            $payments = $REG->registration_payments();
2446
-            if (! empty($payments)) {
2447
-                $name = $REG->attendee() instanceof EE_Attendee
2448
-                    ? $REG->attendee()->full_name()
2449
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2450
-                $overwrite_msgs = true;
2451
-                EE_Error::add_error(
2452
-                    sprintf(
2453
-                        esc_html__(
2454
-                            '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.',
2455
-                            'event_espresso'
2456
-                        ),
2457
-                        $name
2458
-                    ),
2459
-                    __FILE__, __FUNCTION__, __LINE__
2460
-                );
2461
-                //can't trash this registration because it has payments.
2462
-                continue;
2463
-            }
2464
-            $updated = $trash ? $REG->delete() : $REG->restore();
2465
-            if ($updated) {
2466
-                $success++;
2467
-            }
2468
-        }
2469
-        $this->_redirect_after_action(
2470
-            $success === $reg_count, // were ALL registrations affected?
2471
-            $success > 1
2472
-                ? esc_html__('Registrations', 'event_espresso')
2473
-                : esc_html__('Registration', 'event_espresso'),
2474
-            $trash
2475
-                ? esc_html__('moved to the trash', 'event_espresso')
2476
-                : esc_html__('restored', 'event_espresso'),
2477
-            array('action' => 'default'),
2478
-            $overwrite_msgs
2479
-        );
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2485
-     * registration but also.
2486
-     * 1. Removing relations to EE_Attendee
2487
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2488
-     * ALSO trashed.
2489
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2490
-     * 4. Removing relationships between all tickets and the related registrations
2491
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2492
-     * 6. Deleting permanently any related Checkins.
2493
-     *
2494
-     * @return void
2495
-     * @throws EE_Error
2496
-     */
2497
-    protected function _delete_registrations()
2498
-    {
2499
-        $REG_MDL = EEM_Registration::instance();
2500
-        $success = 1;
2501
-        //Checkboxes
2502
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2503
-            // if array has more than one element than success message should be plural
2504
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2505
-            // cycle thru checkboxes
2506
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2507
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2508
-                if ( ! $REG instanceof EE_Registration) {
2509
-                    continue;
2510
-                }
2511
-                $deleted = $this->_delete_registration($REG);
2512
-                if ( ! $deleted) {
2513
-                    $success = 0;
2514
-                }
2515
-            }
2516
-        } else {
2517
-            // grab single id and delete
2518
-            $REG_ID  = $this->_req_data['_REG_ID'];
2519
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2520
-            $deleted = $this->_delete_registration($REG);
2521
-            if ( ! $deleted) {
2522
-                $success = 0;
2523
-            }
2524
-        }
2525
-        $what        = $success > 1
2526
-            ? esc_html__('Registrations', 'event_espresso')
2527
-            : esc_html__('Registration', 'event_espresso');
2528
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2529
-        $this->_redirect_after_action(
2530
-            $success,
2531
-            $what,
2532
-            $action_desc,
2533
-            array('action' => 'default'),
2534
-            true
2535
-        );
2536
-    }
2537
-
2538
-
2539
-    /**
2540
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2541
-     * models get affected.
2542
-     *
2543
-     * @param  EE_Registration $REG registration to be deleted permenantly
2544
-     * @return bool true = successful deletion, false = fail.
2545
-     * @throws EE_Error
2546
-     */
2547
-    protected function _delete_registration(EE_Registration $REG)
2548
-    {
2549
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2550
-        //registrations on the transaction that are NOT trashed.
2551
-        $TXN         = $REG->get_first_related('Transaction');
2552
-        $REGS        = $TXN->get_many_related('Registration');
2553
-        $all_trashed = true;
2554
-        foreach ($REGS as $registration) {
2555
-            if ( ! $registration->get('REG_deleted')) {
2556
-                $all_trashed = false;
2557
-            }
2558
-        }
2559
-        if ( ! $all_trashed) {
2560
-            EE_Error::add_error(
2561
-                esc_html__(
2562
-                    '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.',
2563
-                    'event_espresso'
2564
-                ),
2565
-                __FILE__, __FUNCTION__, __LINE__
2566
-            );
2567
-            return false;
2568
-        }
2569
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2570
-        //separately from THIS one).
2571
-        foreach ($REGS as $registration) {
2572
-            //delete related answers
2573
-            $registration->delete_related_permanently('Answer');
2574
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2575
-            $attendee = $registration->get_first_related('Attendee');
2576
-            if ($attendee instanceof EE_Attendee) {
2577
-                $registration->_remove_relation_to($attendee, 'Attendee');
2578
-            }
2579
-            //now remove relationships to tickets on this registration.
2580
-            $registration->_remove_relations('Ticket');
2581
-            //now delete permanently the checkins related to this registration.
2582
-            $registration->delete_related_permanently('Checkin');
2583
-            if ($registration->ID() === $REG->ID()) {
2584
-                continue;
2585
-            } //we don't want to delete permanently the existing registration just yet.
2586
-            //remove relation to transaction for these registrations if NOT the existing registrations
2587
-            $registration->_remove_relations('Transaction');
2588
-            //delete permanently any related messages.
2589
-            $registration->delete_related_permanently('Message');
2590
-            //now delete this registration permanently
2591
-            $registration->delete_permanently();
2592
-        }
2593
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2594
-        // (the transaction and line items should be all that's left).
2595
-        // delete the line items related to the transaction for this registration.
2596
-        $TXN->delete_related_permanently('Line_Item');
2597
-        //we need to remove all the relationships on the transaction
2598
-        $TXN->delete_related_permanently('Payment');
2599
-        $TXN->delete_related_permanently('Extra_Meta');
2600
-        $TXN->delete_related_permanently('Message');
2601
-        //now we can delete this REG permanently (and the transaction of course)
2602
-        $REG->delete_related_permanently('Transaction');
2603
-        return $REG->delete_permanently();
2604
-    }
2605
-
2606
-
2607
-    /**
2608
-     *    generates HTML for the Register New Attendee Admin page
2609
-     *
2610
-     * @access private
2611
-     * @throws DomainException
2612
-     * @throws EE_Error
2613
-     */
2614
-    public function new_registration()
2615
-    {
2616
-        if ( ! $this->_set_reg_event()) {
2617
-            throw new EE_Error(
2618
-                esc_html__(
2619
-                    'Unable to continue with registering because there is no Event ID in the request',
2620
-                    'event_espresso'
2621
-                )
2622
-            );
2623
-        }
2624
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2625
-        // gotta start with a clean slate if we're not coming here via ajax
2626
-        if ( ! defined('DOING_AJAX')
2627
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2628
-        ) {
2629
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2630
-        }
2631
-        $this->_template_args['event_name'] = '';
2632
-        // event name
2633
-        if ($this->_reg_event) {
2634
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2635
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2636
-                'action' => 'edit',
2637
-                'post'   => $this->_reg_event->ID(),
2638
-            ), EVENTS_ADMIN_URL);
2639
-            $edit_event_lnk                     = '<a href="'
2640
-                                                  . $edit_event_url
2641
-                                                  . '" title="'
2642
-                                                  . esc_attr__('Edit ', 'event_espresso')
2643
-                                                  . $this->_reg_event->name()
2644
-                                                  . '">'
2645
-                                                  . esc_html__('Edit Event', 'event_espresso')
2646
-                                                  . '</a>';
2647
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2648
-                                                   . $edit_event_lnk
2649
-                                                   . '</span>';
2650
-        }
2651
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2652
-        if (defined('DOING_AJAX')) {
2653
-            $this->_return_json();
2654
-        }
2655
-        // grab header
2656
-        $template_path                              =
2657
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2658
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2659
-            $this->_template_args, true);
2660
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2661
-        // the details template wrapper
2662
-        $this->display_admin_page_with_sidebar();
2663
-    }
2664
-
2665
-
2666
-    /**
2667
-     * This returns the content for a registration step
2668
-     *
2669
-     * @access protected
2670
-     * @return string html
2671
-     * @throws DomainException
2672
-     * @throws EE_Error
2673
-     */
2674
-    protected function _get_registration_step_content()
2675
-    {
2676
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2677
-            $warning_msg = sprintf(
2678
-                esc_html__(
2679
-                    '%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',
2680
-                    'event_espresso'
2681
-                ),
2682
-                '<br />',
2683
-                '<h3 class="important-notice">',
2684
-                '</h3>',
2685
-                '<div class="float-right">',
2686
-                '<span id="redirect_timer" class="important-notice">30</span>',
2687
-                '</div>',
2688
-                '<b>',
2689
-                '</b>'
2690
-            );
2691
-            return '
2192
+	}
2193
+
2194
+
2195
+	/**
2196
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2197
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2198
+	 * to display the page
2199
+	 *
2200
+	 * @access protected
2201
+	 * @return void
2202
+	 * @throws EE_Error
2203
+	 */
2204
+	protected function _update_attendee_registration_form()
2205
+	{
2206
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2207
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2208
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2209
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2210
+			if ($success) {
2211
+				$what  = esc_html__('Registration Form', 'event_espresso');
2212
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2213
+					: array('action' => 'default');
2214
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2215
+			}
2216
+		}
2217
+	}
2218
+
2219
+
2220
+	/**
2221
+	 * Gets the form for saving registrations custom questions (if done
2222
+	 * previously retrieves the cached form object, which may have validation errors in it)
2223
+	 *
2224
+	 * @param int $REG_ID
2225
+	 * @return EE_Registration_Custom_Questions_Form
2226
+	 * @throws EE_Error
2227
+	 */
2228
+	protected function _get_reg_custom_questions_form($REG_ID)
2229
+	{
2230
+		if ( ! $this->_reg_custom_questions_form) {
2231
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2232
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2233
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2234
+			);
2235
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2236
+		}
2237
+		return $this->_reg_custom_questions_form;
2238
+	}
2239
+
2240
+
2241
+	/**
2242
+	 * Saves
2243
+	 *
2244
+	 * @access private
2245
+	 * @param bool $REG_ID
2246
+	 * @return bool
2247
+	 * @throws EE_Error
2248
+	 */
2249
+	private function _save_reg_custom_questions_form($REG_ID = false)
2250
+	{
2251
+		if ( ! $REG_ID) {
2252
+			EE_Error::add_error(
2253
+				esc_html__(
2254
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2255
+				__FILE__, __FUNCTION__, __LINE__
2256
+			);
2257
+		}
2258
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2259
+		$form->receive_form_submission($this->_req_data);
2260
+		$success = false;
2261
+		if ($form->is_valid()) {
2262
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2263
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2264
+					$where_conditions    = array(
2265
+						'QST_ID' => $question_id,
2266
+						'REG_ID' => $REG_ID,
2267
+					);
2268
+					$possibly_new_values = array(
2269
+						'ANS_value' => $input->normalized_value(),
2270
+					);
2271
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2272
+					if ($answer instanceof EE_Answer) {
2273
+						$success = $answer->save($possibly_new_values);
2274
+					} else {
2275
+						//insert it then
2276
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2277
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2278
+						$success     = $answer->save();
2279
+					}
2280
+				}
2281
+			}
2282
+		} else {
2283
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2284
+		}
2285
+		return $success;
2286
+	}
2287
+
2288
+
2289
+	/**
2290
+	 *        generates HTML for the Registration main meta box
2291
+	 *
2292
+	 * @access public
2293
+	 * @return void
2294
+	 * @throws DomainException
2295
+	 * @throws EE_Error
2296
+	 */
2297
+	public function _reg_attendees_meta_box()
2298
+	{
2299
+		$REG = EEM_Registration::instance();
2300
+		//get all other registrations on this transaction, and cache
2301
+		//the attendees for them so we don't have to run another query using force_join
2302
+		$registrations                           = $REG->get_all(array(
2303
+			array(
2304
+				'TXN_ID' => $this->_registration->transaction_ID(),
2305
+				'REG_ID' => array('!=', $this->_registration->ID()),
2306
+			),
2307
+			'force_join' => array('Attendee'),
2308
+		));
2309
+		$this->_template_args['attendees']       = array();
2310
+		$this->_template_args['attendee_notice'] = '';
2311
+		if (empty($registrations)
2312
+			|| (is_array($registrations)
2313
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2314
+		) {
2315
+			EE_Error::add_error(
2316
+				esc_html__(
2317
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2318
+					'event_espresso'
2319
+				), __FILE__, __FUNCTION__, __LINE__
2320
+			);
2321
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2322
+		} else {
2323
+			$att_nmbr = 1;
2324
+			foreach ($registrations as $registration) {
2325
+				/* @var $registration EE_Registration */
2326
+				$attendee                                                    = $registration->attendee()
2327
+					? $registration->attendee()
2328
+					: EEM_Attendee::instance()
2329
+								  ->create_default_object();
2330
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2331
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2332
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2333
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2334
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2335
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2336
+					', ',
2337
+					$attendee->full_address_as_array()
2338
+				);
2339
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2340
+					array(
2341
+						'action' => 'edit_attendee',
2342
+						'post'   => $attendee->ID(),
2343
+					),
2344
+					REG_ADMIN_URL
2345
+				);
2346
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2347
+				$att_nmbr++;
2348
+			}
2349
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2350
+		}
2351
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2352
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2353
+	}
2354
+
2355
+
2356
+	/**
2357
+	 *        generates HTML for the Edit Registration side meta box
2358
+	 *
2359
+	 * @access public
2360
+	 * @return void
2361
+	 * @throws DomainException
2362
+	 * @throws EE_Error
2363
+	 */
2364
+	public function _reg_registrant_side_meta_box()
2365
+	{
2366
+		/*@var $attendee EE_Attendee */
2367
+		$att_check = $this->_registration->attendee();
2368
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2369
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2370
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2371
+		//primary registration object (that way we know if we need to show create button or not)
2372
+		if ( ! $this->_registration->is_primary_registrant()) {
2373
+			$primary_registration = $this->_registration->get_primary_registration();
2374
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2375
+				: null;
2376
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2377
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2378
+				//custom attendee object so let's not worry about the primary reg.
2379
+				$primary_registration = null;
2380
+			}
2381
+		} else {
2382
+			$primary_registration = null;
2383
+		}
2384
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2385
+		$this->_template_args['fname']             = $attendee->fname();
2386
+		$this->_template_args['lname']             = $attendee->lname();
2387
+		$this->_template_args['email']             = $attendee->email();
2388
+		$this->_template_args['phone']             = $attendee->phone();
2389
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2390
+		//edit link
2391
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2392
+			'action' => 'edit_attendee',
2393
+			'post'   => $attendee->ID(),
2394
+		), REG_ADMIN_URL);
2395
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2396
+		//create link
2397
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2398
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2399
+				'action'  => 'duplicate_attendee',
2400
+				'_REG_ID' => $this->_registration->ID(),
2401
+			), REG_ADMIN_URL) : '';
2402
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2403
+		$this->_template_args['att_check']    = $att_check;
2404
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2405
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2406
+	}
2407
+
2408
+
2409
+	/**
2410
+	 * trash or restore registrations
2411
+	 *
2412
+	 * @param  boolean $trash whether to archive or restore
2413
+	 * @return void
2414
+	 * @throws EE_Error
2415
+	 * @throws RuntimeException
2416
+	 * @access protected
2417
+	 */
2418
+	protected function _trash_or_restore_registrations($trash = true)
2419
+	{
2420
+		//if empty _REG_ID then get out because there's nothing to do
2421
+		if (empty($this->_req_data['_REG_ID'])) {
2422
+			EE_Error::add_error(
2423
+				sprintf(
2424
+					esc_html__(
2425
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2426
+						'event_espresso'
2427
+					),
2428
+					$trash ? 'trash' : 'restore'
2429
+				),
2430
+				__FILE__, __LINE__, __FUNCTION__
2431
+			);
2432
+			$this->_redirect_after_action(false, '', '', array(), true);
2433
+		}
2434
+		$success = 0;
2435
+		$overwrite_msgs = false;
2436
+		//Checkboxes
2437
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2438
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2439
+		}
2440
+		$reg_count = count($this->_req_data['_REG_ID']);
2441
+		// cycle thru checkboxes
2442
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2443
+			/** @var EE_Registration $REG */
2444
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2445
+			$payments = $REG->registration_payments();
2446
+			if (! empty($payments)) {
2447
+				$name = $REG->attendee() instanceof EE_Attendee
2448
+					? $REG->attendee()->full_name()
2449
+					: esc_html__('Unknown Attendee', 'event_espresso');
2450
+				$overwrite_msgs = true;
2451
+				EE_Error::add_error(
2452
+					sprintf(
2453
+						esc_html__(
2454
+							'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.',
2455
+							'event_espresso'
2456
+						),
2457
+						$name
2458
+					),
2459
+					__FILE__, __FUNCTION__, __LINE__
2460
+				);
2461
+				//can't trash this registration because it has payments.
2462
+				continue;
2463
+			}
2464
+			$updated = $trash ? $REG->delete() : $REG->restore();
2465
+			if ($updated) {
2466
+				$success++;
2467
+			}
2468
+		}
2469
+		$this->_redirect_after_action(
2470
+			$success === $reg_count, // were ALL registrations affected?
2471
+			$success > 1
2472
+				? esc_html__('Registrations', 'event_espresso')
2473
+				: esc_html__('Registration', 'event_espresso'),
2474
+			$trash
2475
+				? esc_html__('moved to the trash', 'event_espresso')
2476
+				: esc_html__('restored', 'event_espresso'),
2477
+			array('action' => 'default'),
2478
+			$overwrite_msgs
2479
+		);
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2485
+	 * registration but also.
2486
+	 * 1. Removing relations to EE_Attendee
2487
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2488
+	 * ALSO trashed.
2489
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2490
+	 * 4. Removing relationships between all tickets and the related registrations
2491
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2492
+	 * 6. Deleting permanently any related Checkins.
2493
+	 *
2494
+	 * @return void
2495
+	 * @throws EE_Error
2496
+	 */
2497
+	protected function _delete_registrations()
2498
+	{
2499
+		$REG_MDL = EEM_Registration::instance();
2500
+		$success = 1;
2501
+		//Checkboxes
2502
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2503
+			// if array has more than one element than success message should be plural
2504
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2505
+			// cycle thru checkboxes
2506
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2507
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2508
+				if ( ! $REG instanceof EE_Registration) {
2509
+					continue;
2510
+				}
2511
+				$deleted = $this->_delete_registration($REG);
2512
+				if ( ! $deleted) {
2513
+					$success = 0;
2514
+				}
2515
+			}
2516
+		} else {
2517
+			// grab single id and delete
2518
+			$REG_ID  = $this->_req_data['_REG_ID'];
2519
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2520
+			$deleted = $this->_delete_registration($REG);
2521
+			if ( ! $deleted) {
2522
+				$success = 0;
2523
+			}
2524
+		}
2525
+		$what        = $success > 1
2526
+			? esc_html__('Registrations', 'event_espresso')
2527
+			: esc_html__('Registration', 'event_espresso');
2528
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2529
+		$this->_redirect_after_action(
2530
+			$success,
2531
+			$what,
2532
+			$action_desc,
2533
+			array('action' => 'default'),
2534
+			true
2535
+		);
2536
+	}
2537
+
2538
+
2539
+	/**
2540
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2541
+	 * models get affected.
2542
+	 *
2543
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2544
+	 * @return bool true = successful deletion, false = fail.
2545
+	 * @throws EE_Error
2546
+	 */
2547
+	protected function _delete_registration(EE_Registration $REG)
2548
+	{
2549
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2550
+		//registrations on the transaction that are NOT trashed.
2551
+		$TXN         = $REG->get_first_related('Transaction');
2552
+		$REGS        = $TXN->get_many_related('Registration');
2553
+		$all_trashed = true;
2554
+		foreach ($REGS as $registration) {
2555
+			if ( ! $registration->get('REG_deleted')) {
2556
+				$all_trashed = false;
2557
+			}
2558
+		}
2559
+		if ( ! $all_trashed) {
2560
+			EE_Error::add_error(
2561
+				esc_html__(
2562
+					'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.',
2563
+					'event_espresso'
2564
+				),
2565
+				__FILE__, __FUNCTION__, __LINE__
2566
+			);
2567
+			return false;
2568
+		}
2569
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2570
+		//separately from THIS one).
2571
+		foreach ($REGS as $registration) {
2572
+			//delete related answers
2573
+			$registration->delete_related_permanently('Answer');
2574
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2575
+			$attendee = $registration->get_first_related('Attendee');
2576
+			if ($attendee instanceof EE_Attendee) {
2577
+				$registration->_remove_relation_to($attendee, 'Attendee');
2578
+			}
2579
+			//now remove relationships to tickets on this registration.
2580
+			$registration->_remove_relations('Ticket');
2581
+			//now delete permanently the checkins related to this registration.
2582
+			$registration->delete_related_permanently('Checkin');
2583
+			if ($registration->ID() === $REG->ID()) {
2584
+				continue;
2585
+			} //we don't want to delete permanently the existing registration just yet.
2586
+			//remove relation to transaction for these registrations if NOT the existing registrations
2587
+			$registration->_remove_relations('Transaction');
2588
+			//delete permanently any related messages.
2589
+			$registration->delete_related_permanently('Message');
2590
+			//now delete this registration permanently
2591
+			$registration->delete_permanently();
2592
+		}
2593
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2594
+		// (the transaction and line items should be all that's left).
2595
+		// delete the line items related to the transaction for this registration.
2596
+		$TXN->delete_related_permanently('Line_Item');
2597
+		//we need to remove all the relationships on the transaction
2598
+		$TXN->delete_related_permanently('Payment');
2599
+		$TXN->delete_related_permanently('Extra_Meta');
2600
+		$TXN->delete_related_permanently('Message');
2601
+		//now we can delete this REG permanently (and the transaction of course)
2602
+		$REG->delete_related_permanently('Transaction');
2603
+		return $REG->delete_permanently();
2604
+	}
2605
+
2606
+
2607
+	/**
2608
+	 *    generates HTML for the Register New Attendee Admin page
2609
+	 *
2610
+	 * @access private
2611
+	 * @throws DomainException
2612
+	 * @throws EE_Error
2613
+	 */
2614
+	public function new_registration()
2615
+	{
2616
+		if ( ! $this->_set_reg_event()) {
2617
+			throw new EE_Error(
2618
+				esc_html__(
2619
+					'Unable to continue with registering because there is no Event ID in the request',
2620
+					'event_espresso'
2621
+				)
2622
+			);
2623
+		}
2624
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2625
+		// gotta start with a clean slate if we're not coming here via ajax
2626
+		if ( ! defined('DOING_AJAX')
2627
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2628
+		) {
2629
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2630
+		}
2631
+		$this->_template_args['event_name'] = '';
2632
+		// event name
2633
+		if ($this->_reg_event) {
2634
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2635
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2636
+				'action' => 'edit',
2637
+				'post'   => $this->_reg_event->ID(),
2638
+			), EVENTS_ADMIN_URL);
2639
+			$edit_event_lnk                     = '<a href="'
2640
+												  . $edit_event_url
2641
+												  . '" title="'
2642
+												  . esc_attr__('Edit ', 'event_espresso')
2643
+												  . $this->_reg_event->name()
2644
+												  . '">'
2645
+												  . esc_html__('Edit Event', 'event_espresso')
2646
+												  . '</a>';
2647
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2648
+												   . $edit_event_lnk
2649
+												   . '</span>';
2650
+		}
2651
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2652
+		if (defined('DOING_AJAX')) {
2653
+			$this->_return_json();
2654
+		}
2655
+		// grab header
2656
+		$template_path                              =
2657
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2658
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2659
+			$this->_template_args, true);
2660
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2661
+		// the details template wrapper
2662
+		$this->display_admin_page_with_sidebar();
2663
+	}
2664
+
2665
+
2666
+	/**
2667
+	 * This returns the content for a registration step
2668
+	 *
2669
+	 * @access protected
2670
+	 * @return string html
2671
+	 * @throws DomainException
2672
+	 * @throws EE_Error
2673
+	 */
2674
+	protected function _get_registration_step_content()
2675
+	{
2676
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2677
+			$warning_msg = sprintf(
2678
+				esc_html__(
2679
+					'%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',
2680
+					'event_espresso'
2681
+				),
2682
+				'<br />',
2683
+				'<h3 class="important-notice">',
2684
+				'</h3>',
2685
+				'<div class="float-right">',
2686
+				'<span id="redirect_timer" class="important-notice">30</span>',
2687
+				'</div>',
2688
+				'<b>',
2689
+				'</b>'
2690
+			);
2691
+			return '
2692 2692
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2693 2693
 	<script >
2694 2694
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2701,792 +2701,792 @@  discard block
 block discarded – undo
2701 2701
 	        }
2702 2702
 	    }, 800 );
2703 2703
 	</script >';
2704
-        }
2705
-        $template_args = array(
2706
-            'title'                    => '',
2707
-            'content'                  => '',
2708
-            'step_button_text'         => '',
2709
-            'show_notification_toggle' => false,
2710
-        );
2711
-        //to indicate we're processing a new registration
2712
-        $hidden_fields = array(
2713
-            'processing_registration' => array(
2714
-                'type'  => 'hidden',
2715
-                'value' => 0,
2716
-            ),
2717
-            'event_id'                => array(
2718
-                'type'  => 'hidden',
2719
-                'value' => $this->_reg_event->ID(),
2720
-            ),
2721
-        );
2722
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2723
-        $cart = EE_Registry::instance()->SSN->cart();
2724
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2725
-        switch ($step) {
2726
-            case 'ticket' :
2727
-                $hidden_fields['processing_registration']['value'] = 1;
2728
-                $template_args['title']                            = esc_html__(
2729
-                    'Step One: Select the Ticket for this registration',
2730
-                    'event_espresso'
2731
-                );
2732
-                $template_args['content']                          =
2733
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2734
-                $template_args['step_button_text']                 = esc_html__(
2735
-                    'Add Tickets and Continue to Registrant Details',
2736
-                    'event_espresso'
2737
-                );
2738
-                $template_args['show_notification_toggle']         = false;
2739
-                break;
2740
-            case 'questions' :
2741
-                $hidden_fields['processing_registration']['value'] = 2;
2742
-                $template_args['title']                            = esc_html__(
2743
-                    'Step Two: Add Registrant Details for this Registration',
2744
-                    'event_espresso'
2745
-                );
2746
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2747
-                // properly by the first process_reg_step run.
2748
-                $template_args['content']                  =
2749
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2750
-                $template_args['step_button_text']         = esc_html__(
2751
-                    'Save Registration and Continue to Details',
2752
-                    'event_espresso'
2753
-                );
2754
-                $template_args['show_notification_toggle'] = true;
2755
-                break;
2756
-        }
2757
-        //we come back to the process_registration_step route.
2758
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2759
-        return EEH_Template::display_template(
2760
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2761
-            $template_args,
2762
-            true
2763
-        );
2764
-    }
2765
-
2766
-
2767
-    /**
2768
-     *        set_reg_event
2769
-     *
2770
-     * @access private
2771
-     * @return bool
2772
-     * @throws EE_Error
2773
-     */
2774
-    private function _set_reg_event()
2775
-    {
2776
-        if (is_object($this->_reg_event)) {
2777
-            return true;
2778
-        }
2779
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2780
-        if ( ! $EVT_ID) {
2781
-            return false;
2782
-        }
2783
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2784
-        return true;
2785
-    }
2786
-
2787
-
2788
-    /**
2789
-     * process_reg_step
2790
-     *
2791
-     * @access        public
2792
-     * @return string
2793
-     * @throws DomainException
2794
-     * @throws EE_Error
2795
-     * @throws RuntimeException
2796
-     */
2797
-    public function process_reg_step()
2798
-    {
2799
-        EE_System::do_not_cache();
2800
-        $this->_set_reg_event();
2801
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2802
-        EE_Registry::instance()->REQ->set('uts', time());
2803
-        //what step are we on?
2804
-        $cart = EE_Registry::instance()->SSN->cart();
2805
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2806
-        //if doing ajax then we need to verify the nonce
2807
-        if (defined('DOING_AJAX')) {
2808
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2809
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2810
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2811
-        }
2812
-        switch ($step) {
2813
-            case 'ticket' :
2814
-                //process ticket selection
2815
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2816
-                if ($success) {
2817
-                    EE_Error::add_success(
2818
-                        esc_html__(
2819
-                            'Tickets Selected. Now complete the registration.',
2820
-                            'event_espresso'
2821
-                        )
2822
-                    );
2823
-                } else {
2824
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2825
-                }
2826
-                if (defined('DOING_AJAX')) {
2827
-                    $this->new_registration(); //display next step
2828
-                } else {
2829
-                    $query_args = array(
2830
-                        'action'                  => 'new_registration',
2831
-                        'processing_registration' => 1,
2832
-                        'event_id'                => $this->_reg_event->ID(),
2833
-                        'uts'                     => time(),
2834
-                    );
2835
-                    $this->_redirect_after_action(
2836
-                        false,
2837
-                        '',
2838
-                        '',
2839
-                        $query_args,
2840
-                        true
2841
-                    );
2842
-                }
2843
-                break;
2844
-            case 'questions' :
2845
-                if (! isset(
2846
-                    $this->_req_data['txn_reg_status_change'],
2847
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
2848
-                ) {
2849
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2850
-                }
2851
-                //process registration
2852
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2853
-                if ($cart instanceof EE_Cart) {
2854
-                    $grand_total = $cart->get_cart_grand_total();
2855
-                    if ($grand_total instanceof EE_Line_Item) {
2856
-                        $grand_total->save_this_and_descendants_to_txn();
2857
-                    }
2858
-                }
2859
-                if ( ! $transaction instanceof EE_Transaction) {
2860
-                    $query_args = array(
2861
-                        'action'                  => 'new_registration',
2862
-                        'processing_registration' => 2,
2863
-                        'event_id'                => $this->_reg_event->ID(),
2864
-                        'uts'                     => time(),
2865
-                    );
2866
-                    if (defined('DOING_AJAX')) {
2867
-                        //display registration form again because there are errors (maybe validation?)
2868
-                        $this->new_registration();
2869
-                        return;
2870
-                    } else {
2871
-                        $this->_redirect_after_action(
2872
-                            false,
2873
-                            '',
2874
-                            '',
2875
-                            $query_args,
2876
-                            true
2877
-                        );
2878
-                        return;
2879
-                    }
2880
-                }
2881
-                // maybe update status, and make sure to save transaction if not done already
2882
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2883
-                    $transaction->save();
2884
-                }
2885
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2886
-                $this->_req_data = array();
2887
-                $query_args      = array(
2888
-                    'action'        => 'redirect_to_txn',
2889
-                    'TXN_ID'        => $transaction->ID(),
2890
-                    'EVT_ID'        => $this->_reg_event->ID(),
2891
-                    'event_name'    => urlencode($this->_reg_event->name()),
2892
-                    'redirect_from' => 'new_registration',
2893
-                );
2894
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2895
-                break;
2896
-        }
2897
-        //what are you looking here for?  Should be nothing to do at this point.
2898
-    }
2899
-
2900
-
2901
-    /**
2902
-     * redirect_to_txn
2903
-     *
2904
-     * @access public
2905
-     * @return void
2906
-     * @throws EE_Error
2907
-     */
2908
-    public function redirect_to_txn()
2909
-    {
2910
-        EE_System::do_not_cache();
2911
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2912
-        $query_args = array(
2913
-            'action' => 'view_transaction',
2914
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2915
-            'page'   => 'espresso_transactions',
2916
-        );
2917
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2918
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2919
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
2920
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
2921
-        }
2922
-        EE_Error::add_success(
2923
-            esc_html__(
2924
-                'Registration Created.  Please review the transaction and add any payments as necessary',
2925
-                'event_espresso'
2926
-            )
2927
-        );
2928
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2929
-    }
2930
-
2931
-
2932
-    /**
2933
-     *        generates HTML for the Attendee Contact List
2934
-     *
2935
-     * @access protected
2936
-     * @return void
2937
-     */
2938
-    protected function _attendee_contact_list_table()
2939
-    {
2940
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2941
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2942
-        $this->display_admin_list_table_page_with_no_sidebar();
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     *        get_attendees
2948
-     *
2949
-     * @param      $per_page
2950
-     * @param bool $count whether to return count or data.
2951
-     * @param bool $trash
2952
-     * @return array
2953
-     * @throws EE_Error
2954
-     * @access public
2955
-     */
2956
-    public function get_attendees($per_page, $count = false, $trash = false)
2957
-    {
2958
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2959
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2960
-        $ATT_MDL                    = EEM_Attendee::instance();
2961
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2962
-        switch ($this->_req_data['orderby']) {
2963
-            case 'ATT_ID':
2964
-                $orderby = 'ATT_ID';
2965
-                break;
2966
-            case 'ATT_fname':
2967
-                $orderby = 'ATT_fname';
2968
-                break;
2969
-            case 'ATT_email':
2970
-                $orderby = 'ATT_email';
2971
-                break;
2972
-            case 'ATT_city':
2973
-                $orderby = 'ATT_city';
2974
-                break;
2975
-            case 'STA_ID':
2976
-                $orderby = 'STA_ID';
2977
-                break;
2978
-            case 'CNT_ID':
2979
-                $orderby = 'CNT_ID';
2980
-                break;
2981
-            default:
2982
-                $orderby = 'ATT_lname';
2983
-        }
2984
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2985
-            ? $this->_req_data['order']
2986
-            : 'ASC';
2987
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2988
-            ? $this->_req_data['paged']
2989
-            : 1;
2990
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2991
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2992
-            ? $this->_req_data['perpage']
2993
-            : $per_page;
2994
-        $_where       = array();
2995
-        if ( ! empty($this->_req_data['s'])) {
2996
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2997
-            $_where['OR'] = array(
2998
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2999
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3000
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3001
-                'ATT_fname'                         => array('LIKE', $sstr),
3002
-                'ATT_lname'                         => array('LIKE', $sstr),
3003
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3004
-                'ATT_email'                         => array('LIKE', $sstr),
3005
-                'ATT_address'                       => array('LIKE', $sstr),
3006
-                'ATT_address2'                      => array('LIKE', $sstr),
3007
-                'ATT_city'                          => array('LIKE', $sstr),
3008
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3009
-                'State.STA_name'                    => array('LIKE', $sstr),
3010
-                'ATT_phone'                         => array('LIKE', $sstr),
3011
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3012
-                'Registration.REG_code'             => array('LIKE', $sstr),
3013
-                'Registration.REG_count'            => array('LIKE', $sstr),
3014
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3015
-            );
3016
-        }
3017
-        $offset = ($current_page - 1) * $per_page;
3018
-        $limit  = $count ? null : array($offset, $per_page);
3019
-        if ($trash) {
3020
-            $_where['status'] = array('!=', 'publish');
3021
-            $all_attendees    = $count
3022
-                ? $ATT_MDL->count(array(
3023
-                    $_where,
3024
-                    'order_by' => array($orderby => $sort),
3025
-                    'limit'    => $limit,
3026
-                ), 'ATT_ID', true)
3027
-                : $ATT_MDL->get_all(array(
3028
-                    $_where,
3029
-                    'order_by' => array($orderby => $sort),
3030
-                    'limit'    => $limit,
3031
-                ));
3032
-        } else {
3033
-            $_where['status'] = array('IN', array('publish'));
3034
-            $all_attendees    = $count
3035
-                ? $ATT_MDL->count(array(
3036
-                    $_where,
3037
-                    'order_by' => array($orderby => $sort),
3038
-                    'limit'    => $limit,
3039
-                ), 'ATT_ID', true)
3040
-                : $ATT_MDL->get_all(array(
3041
-                    $_where,
3042
-                    'order_by' => array($orderby => $sort),
3043
-                    'limit'    => $limit,
3044
-                ));
3045
-        }
3046
-        return $all_attendees;
3047
-    }
3048
-
3049
-
3050
-    /**
3051
-     * This is just taking care of resending the registration confirmation
3052
-     *
3053
-     * @access protected
3054
-     * @return void
3055
-     */
3056
-    protected function _resend_registration()
3057
-    {
3058
-        $this->_process_resend_registration();
3059
-        $query_args = isset($this->_req_data['redirect_to'])
3060
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3061
-            : array('action' => 'default');
3062
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3063
-    }
3064
-
3065
-    /**
3066
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3067
-     * to use when selecting registrations
3068
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3069
-     *                                                     the query parameters from the request
3070
-     * @return void ends the request with a redirect or download
3071
-     */
3072
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3073
-    {
3074
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3075
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3076
-                array(
3077
-                    'page'        => 'espresso_batch',
3078
-                    'batch'       => 'file',
3079
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3080
-                    'filters'     => urlencode(
3081
-                        serialize(
3082
-                            call_user_func(
3083
-                                array( $this, $method_name_for_getting_query_params ),
3084
-                                EEH_Array::is_set(
3085
-                                    $this->_req_data,
3086
-                                    'filters',
3087
-                                    array()
3088
-                                )
3089
-                            )
3090
-                        )
3091
-                ),
3092
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3093
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3094
-                'return_url'  => urlencode($this->_req_data['return_url']),
3095
-            )));
3096
-        } else {
3097
-            $new_request_args = array(
3098
-                'export' => 'report',
3099
-                'action' => 'registrations_report_for_event',
3100
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3101
-            );
3102
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3103
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3104
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3105
-                $EE_Export = EE_Export::instance($this->_req_data);
3106
-                $EE_Export->export();
3107
-            }
3108
-        }
3109
-    }
3110
-
3111
-
3112
-
3113
-    /**
3114
-     * Creates a registration report using only query parameters in the request
3115
-     * @return void
3116
-     */
3117
-    public function _registrations_report()
3118
-    {
3119
-        $this->_registrations_report_base('_get_registration_query_parameters');
3120
-    }
3121
-
3122
-
3123
-    public function _contact_list_export()
3124
-    {
3125
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3126
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3127
-            $EE_Export = EE_Export::instance($this->_req_data);
3128
-            $EE_Export->export_attendees();
3129
-        }
3130
-    }
3131
-
3132
-
3133
-    public function _contact_list_report()
3134
-    {
3135
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3136
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3137
-                'page'        => 'espresso_batch',
3138
-                'batch'       => 'file',
3139
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3140
-                'return_url'  => urlencode($this->_req_data['return_url']),
3141
-            )));
3142
-        } else {
3143
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3144
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3145
-                $EE_Export = EE_Export::instance($this->_req_data);
3146
-                $EE_Export->report_attendees();
3147
-            }
3148
-        }
3149
-    }
3150
-
3151
-
3152
-
3153
-
3154
-
3155
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3156
-    /**
3157
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3158
-     *
3159
-     * @return void
3160
-     * @throws EE_Error
3161
-     */
3162
-    protected function _duplicate_attendee()
3163
-    {
3164
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3165
-        //verify we have necessary info
3166
-        if (empty($this->_req_data['_REG_ID'])) {
3167
-            EE_Error::add_error(
3168
-                esc_html__(
3169
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3170
-                    'event_espresso'
3171
-                ), __FILE__, __LINE__, __FUNCTION__
3172
-            );
3173
-            $query_args = array('action' => $action);
3174
-            $this->_redirect_after_action('', '', '', $query_args, true);
3175
-        }
3176
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3177
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3178
-        $attendee     = $registration->attendee();
3179
-        //remove relation of existing attendee on registration
3180
-        $registration->_remove_relation_to($attendee, 'Attendee');
3181
-        //new attendee
3182
-        $new_attendee = clone $attendee;
3183
-        $new_attendee->set('ATT_ID', 0);
3184
-        $new_attendee->save();
3185
-        //add new attendee to reg
3186
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3187
-        EE_Error::add_success(
3188
-            esc_html__(
3189
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3190
-                'event_espresso'
3191
-            )
3192
-        );
3193
-        //redirect to edit page for attendee
3194
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3195
-        $this->_redirect_after_action('', '', '', $query_args, true);
3196
-    }
3197
-
3198
-
3199
-    //related to cpt routes
3200
-    protected function _insert_update_cpt_item($post_id, $post)
3201
-    {
3202
-        $success  = true;
3203
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3204
-        //for attendee updates
3205
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3206
-            //note we should only be UPDATING attendees at this point.
3207
-            $updated_fields = array(
3208
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3209
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3210
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3211
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3212
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3213
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3214
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3215
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3216
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3217
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3218
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3219
-            );
3220
-            foreach ($updated_fields as $field => $value) {
3221
-                $attendee->set($field, $value);
3222
-            }
3223
-            $success                   = $attendee->save();
3224
-            $attendee_update_callbacks = apply_filters(
3225
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3226
-                array()
3227
-            );
3228
-            foreach ($attendee_update_callbacks as $a_callback) {
3229
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3230
-                    throw new EE_Error(
3231
-                        sprintf(
3232
-                            esc_html__(
3233
-                                '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.',
3234
-                                'event_espresso'
3235
-                            ),
3236
-                            $a_callback
3237
-                        )
3238
-                    );
3239
-                }
3240
-            }
3241
-        }
3242
-        if ($success === false) {
3243
-            EE_Error::add_error(
3244
-                esc_html__(
3245
-                    'Something went wrong with updating the meta table data for the registration.',
3246
-                    'event_espresso'
3247
-                ),
3248
-                __FILE__, __FUNCTION__, __LINE__
3249
-            );
3250
-        }
3251
-    }
3252
-
3253
-
3254
-    public function trash_cpt_item($post_id)
3255
-    {
3256
-    }
3257
-
3258
-
3259
-    public function delete_cpt_item($post_id)
3260
-    {
3261
-    }
3262
-
3263
-
3264
-    public function restore_cpt_item($post_id)
3265
-    {
3266
-    }
3267
-
3268
-
3269
-    protected function _restore_cpt_item($post_id, $revision_id)
3270
-    {
3271
-    }
3272
-
3273
-
3274
-    public function attendee_editor_metaboxes()
3275
-    {
3276
-        $this->verify_cpt_object();
3277
-        remove_meta_box(
3278
-            'postexcerpt',
3279
-            esc_html__('Excerpt', 'event_espresso'),
3280
-            'post_excerpt_meta_box',
3281
-            $this->_cpt_routes[$this->_req_action],
3282
-            'normal',
3283
-            'core'
3284
-        );
3285
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3286
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3287
-            add_meta_box(
3288
-                'postexcerpt',
3289
-                esc_html__('Short Biography', 'event_espresso'),
3290
-                'post_excerpt_meta_box',
3291
-                $this->_cpt_routes[$this->_req_action],
3292
-                'normal'
3293
-            );
3294
-        }
3295
-        if (post_type_supports('espresso_attendees', 'comments')) {
3296
-            add_meta_box(
3297
-                'commentsdiv',
3298
-                esc_html__('Notes on the Contact', 'event_espresso'),
3299
-                'post_comment_meta_box',
3300
-                $this->_cpt_routes[$this->_req_action],
3301
-                'normal',
3302
-                'core'
3303
-            );
3304
-        }
3305
-        add_meta_box(
3306
-            'attendee_contact_info',
3307
-            esc_html__('Contact Info', 'event_espresso'),
3308
-            array($this, 'attendee_contact_info'),
3309
-            $this->_cpt_routes[$this->_req_action],
3310
-            'side',
3311
-            'core'
3312
-        );
3313
-        add_meta_box(
3314
-            'attendee_details_address',
3315
-            esc_html__('Address Details', 'event_espresso'),
3316
-            array($this, 'attendee_address_details'),
3317
-            $this->_cpt_routes[$this->_req_action],
3318
-            'normal',
3319
-            'core'
3320
-        );
3321
-        add_meta_box(
3322
-            'attendee_registrations',
3323
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3324
-            array($this, 'attendee_registrations_meta_box'),
3325
-            $this->_cpt_routes[$this->_req_action],
3326
-            'normal',
3327
-            'high'
3328
-        );
3329
-    }
3330
-
3331
-
3332
-    /**
3333
-     * Metabox for attendee contact info
3334
-     *
3335
-     * @param  WP_Post $post wp post object
3336
-     * @return string attendee contact info ( and form )
3337
-     * @throws DomainException
3338
-     */
3339
-    public function attendee_contact_info($post)
3340
-    {
3341
-        //get attendee object ( should already have it )
3342
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3343
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3344
-        EEH_Template::display_template($template, $this->_template_args);
3345
-    }
3346
-
3347
-
3348
-    /**
3349
-     * Metabox for attendee details
3350
-     *
3351
-     * @param  WP_Post $post wp post object
3352
-     * @return string attendee address details (and form)
3353
-     * @throws DomainException
3354
-     */
3355
-    public function attendee_address_details($post)
3356
-    {
3357
-        //get attendee object (should already have it)
3358
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3359
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3360
-            new EE_Question_Form_Input(
3361
-                EE_Question::new_instance(
3362
-                    array(
3363
-                        'QST_ID'           => 0,
3364
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3365
-                        'QST_system'       => 'admin-state',
3366
-                    )
3367
-                ),
3368
-                EE_Answer::new_instance(
3369
-                    array(
3370
-                        'ANS_ID'    => 0,
3371
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3372
-                    )
3373
-                ),
3374
-                array(
3375
-                    'input_id'       => 'STA_ID',
3376
-                    'input_name'     => 'STA_ID',
3377
-                    'input_prefix'   => '',
3378
-                    'append_qstn_id' => false,
3379
-                )
3380
-            )
3381
-        );
3382
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3383
-            new EE_Question_Form_Input(
3384
-                EE_Question::new_instance(
3385
-                    array(
3386
-                        'QST_ID'           => 0,
3387
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3388
-                        'QST_system'       => 'admin-country',
3389
-                    )
3390
-                ),
3391
-                EE_Answer::new_instance(
3392
-                    array(
3393
-                        'ANS_ID'    => 0,
3394
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3395
-                    )
3396
-                ),
3397
-                array(
3398
-                    'input_id'       => 'CNT_ISO',
3399
-                    'input_name'     => 'CNT_ISO',
3400
-                    'input_prefix'   => '',
3401
-                    'append_qstn_id' => false,
3402
-                )
3403
-            )
3404
-        );
3405
-        $template                             =
3406
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3407
-        EEH_Template::display_template($template, $this->_template_args);
3408
-    }
3409
-
3410
-
3411
-    /**
3412
-     *        _attendee_details
3413
-     *
3414
-     * @access protected
3415
-     * @param $post
3416
-     * @return void
3417
-     * @throws DomainException
3418
-     * @throws EE_Error
3419
-     */
3420
-    public function attendee_registrations_meta_box($post)
3421
-    {
3422
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3423
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3424
-        $template                              =
3425
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3426
-        EEH_Template::display_template($template, $this->_template_args);
3427
-    }
3428
-
3429
-
3430
-    /**
3431
-     * add in the form fields for the attendee edit
3432
-     *
3433
-     * @param  WP_Post $post wp post object
3434
-     * @return string html for new form.
3435
-     * @throws DomainException
3436
-     */
3437
-    public function after_title_form_fields($post)
3438
-    {
3439
-        if ($post->post_type == 'espresso_attendees') {
3440
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3441
-            $template_args['attendee'] = $this->_cpt_model_obj;
3442
-            EEH_Template::display_template($template, $template_args);
3443
-        }
3444
-    }
3445
-
3446
-
3447
-    /**
3448
-     *        _trash_or_restore_attendee
3449
-     *
3450
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3451
-     * @return void
3452
-     * @throws EE_Error
3453
-     * @access protected
3454
-     */
3455
-    protected function _trash_or_restore_attendees($trash = true)
3456
-    {
3457
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3458
-        $ATT_MDL = EEM_Attendee::instance();
3459
-        $success = 1;
3460
-        //Checkboxes
3461
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3462
-            // if array has more than one element than success message should be plural
3463
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3464
-            // cycle thru checkboxes
3465
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3466
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3467
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3468
-                if ( ! $updated) {
3469
-                    $success = 0;
3470
-                }
3471
-            }
3472
-        } else {
3473
-            // grab single id and delete
3474
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3475
-            //get attendee
3476
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3477
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3478
-            $updated = $att->save();
3479
-            if ( ! $updated) {
3480
-                $success = 0;
3481
-            }
3482
-        }
3483
-        $what        = $success > 1
3484
-            ? esc_html__('Contacts', 'event_espresso')
3485
-            : esc_html__('Contact', 'event_espresso');
3486
-        $action_desc = $trash
3487
-            ? esc_html__('moved to the trash', 'event_espresso')
3488
-            : esc_html__('restored', 'event_espresso');
3489
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3490
-    }
2704
+		}
2705
+		$template_args = array(
2706
+			'title'                    => '',
2707
+			'content'                  => '',
2708
+			'step_button_text'         => '',
2709
+			'show_notification_toggle' => false,
2710
+		);
2711
+		//to indicate we're processing a new registration
2712
+		$hidden_fields = array(
2713
+			'processing_registration' => array(
2714
+				'type'  => 'hidden',
2715
+				'value' => 0,
2716
+			),
2717
+			'event_id'                => array(
2718
+				'type'  => 'hidden',
2719
+				'value' => $this->_reg_event->ID(),
2720
+			),
2721
+		);
2722
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2723
+		$cart = EE_Registry::instance()->SSN->cart();
2724
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2725
+		switch ($step) {
2726
+			case 'ticket' :
2727
+				$hidden_fields['processing_registration']['value'] = 1;
2728
+				$template_args['title']                            = esc_html__(
2729
+					'Step One: Select the Ticket for this registration',
2730
+					'event_espresso'
2731
+				);
2732
+				$template_args['content']                          =
2733
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2734
+				$template_args['step_button_text']                 = esc_html__(
2735
+					'Add Tickets and Continue to Registrant Details',
2736
+					'event_espresso'
2737
+				);
2738
+				$template_args['show_notification_toggle']         = false;
2739
+				break;
2740
+			case 'questions' :
2741
+				$hidden_fields['processing_registration']['value'] = 2;
2742
+				$template_args['title']                            = esc_html__(
2743
+					'Step Two: Add Registrant Details for this Registration',
2744
+					'event_espresso'
2745
+				);
2746
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2747
+				// properly by the first process_reg_step run.
2748
+				$template_args['content']                  =
2749
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2750
+				$template_args['step_button_text']         = esc_html__(
2751
+					'Save Registration and Continue to Details',
2752
+					'event_espresso'
2753
+				);
2754
+				$template_args['show_notification_toggle'] = true;
2755
+				break;
2756
+		}
2757
+		//we come back to the process_registration_step route.
2758
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2759
+		return EEH_Template::display_template(
2760
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2761
+			$template_args,
2762
+			true
2763
+		);
2764
+	}
2765
+
2766
+
2767
+	/**
2768
+	 *        set_reg_event
2769
+	 *
2770
+	 * @access private
2771
+	 * @return bool
2772
+	 * @throws EE_Error
2773
+	 */
2774
+	private function _set_reg_event()
2775
+	{
2776
+		if (is_object($this->_reg_event)) {
2777
+			return true;
2778
+		}
2779
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2780
+		if ( ! $EVT_ID) {
2781
+			return false;
2782
+		}
2783
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2784
+		return true;
2785
+	}
2786
+
2787
+
2788
+	/**
2789
+	 * process_reg_step
2790
+	 *
2791
+	 * @access        public
2792
+	 * @return string
2793
+	 * @throws DomainException
2794
+	 * @throws EE_Error
2795
+	 * @throws RuntimeException
2796
+	 */
2797
+	public function process_reg_step()
2798
+	{
2799
+		EE_System::do_not_cache();
2800
+		$this->_set_reg_event();
2801
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2802
+		EE_Registry::instance()->REQ->set('uts', time());
2803
+		//what step are we on?
2804
+		$cart = EE_Registry::instance()->SSN->cart();
2805
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2806
+		//if doing ajax then we need to verify the nonce
2807
+		if (defined('DOING_AJAX')) {
2808
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2809
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2810
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2811
+		}
2812
+		switch ($step) {
2813
+			case 'ticket' :
2814
+				//process ticket selection
2815
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2816
+				if ($success) {
2817
+					EE_Error::add_success(
2818
+						esc_html__(
2819
+							'Tickets Selected. Now complete the registration.',
2820
+							'event_espresso'
2821
+						)
2822
+					);
2823
+				} else {
2824
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2825
+				}
2826
+				if (defined('DOING_AJAX')) {
2827
+					$this->new_registration(); //display next step
2828
+				} else {
2829
+					$query_args = array(
2830
+						'action'                  => 'new_registration',
2831
+						'processing_registration' => 1,
2832
+						'event_id'                => $this->_reg_event->ID(),
2833
+						'uts'                     => time(),
2834
+					);
2835
+					$this->_redirect_after_action(
2836
+						false,
2837
+						'',
2838
+						'',
2839
+						$query_args,
2840
+						true
2841
+					);
2842
+				}
2843
+				break;
2844
+			case 'questions' :
2845
+				if (! isset(
2846
+					$this->_req_data['txn_reg_status_change'],
2847
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
2848
+				) {
2849
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2850
+				}
2851
+				//process registration
2852
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2853
+				if ($cart instanceof EE_Cart) {
2854
+					$grand_total = $cart->get_cart_grand_total();
2855
+					if ($grand_total instanceof EE_Line_Item) {
2856
+						$grand_total->save_this_and_descendants_to_txn();
2857
+					}
2858
+				}
2859
+				if ( ! $transaction instanceof EE_Transaction) {
2860
+					$query_args = array(
2861
+						'action'                  => 'new_registration',
2862
+						'processing_registration' => 2,
2863
+						'event_id'                => $this->_reg_event->ID(),
2864
+						'uts'                     => time(),
2865
+					);
2866
+					if (defined('DOING_AJAX')) {
2867
+						//display registration form again because there are errors (maybe validation?)
2868
+						$this->new_registration();
2869
+						return;
2870
+					} else {
2871
+						$this->_redirect_after_action(
2872
+							false,
2873
+							'',
2874
+							'',
2875
+							$query_args,
2876
+							true
2877
+						);
2878
+						return;
2879
+					}
2880
+				}
2881
+				// maybe update status, and make sure to save transaction if not done already
2882
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2883
+					$transaction->save();
2884
+				}
2885
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2886
+				$this->_req_data = array();
2887
+				$query_args      = array(
2888
+					'action'        => 'redirect_to_txn',
2889
+					'TXN_ID'        => $transaction->ID(),
2890
+					'EVT_ID'        => $this->_reg_event->ID(),
2891
+					'event_name'    => urlencode($this->_reg_event->name()),
2892
+					'redirect_from' => 'new_registration',
2893
+				);
2894
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2895
+				break;
2896
+		}
2897
+		//what are you looking here for?  Should be nothing to do at this point.
2898
+	}
2899
+
2900
+
2901
+	/**
2902
+	 * redirect_to_txn
2903
+	 *
2904
+	 * @access public
2905
+	 * @return void
2906
+	 * @throws EE_Error
2907
+	 */
2908
+	public function redirect_to_txn()
2909
+	{
2910
+		EE_System::do_not_cache();
2911
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2912
+		$query_args = array(
2913
+			'action' => 'view_transaction',
2914
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2915
+			'page'   => 'espresso_transactions',
2916
+		);
2917
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2918
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2919
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
2920
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
2921
+		}
2922
+		EE_Error::add_success(
2923
+			esc_html__(
2924
+				'Registration Created.  Please review the transaction and add any payments as necessary',
2925
+				'event_espresso'
2926
+			)
2927
+		);
2928
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2929
+	}
2930
+
2931
+
2932
+	/**
2933
+	 *        generates HTML for the Attendee Contact List
2934
+	 *
2935
+	 * @access protected
2936
+	 * @return void
2937
+	 */
2938
+	protected function _attendee_contact_list_table()
2939
+	{
2940
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2941
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2942
+		$this->display_admin_list_table_page_with_no_sidebar();
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 *        get_attendees
2948
+	 *
2949
+	 * @param      $per_page
2950
+	 * @param bool $count whether to return count or data.
2951
+	 * @param bool $trash
2952
+	 * @return array
2953
+	 * @throws EE_Error
2954
+	 * @access public
2955
+	 */
2956
+	public function get_attendees($per_page, $count = false, $trash = false)
2957
+	{
2958
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2959
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2960
+		$ATT_MDL                    = EEM_Attendee::instance();
2961
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2962
+		switch ($this->_req_data['orderby']) {
2963
+			case 'ATT_ID':
2964
+				$orderby = 'ATT_ID';
2965
+				break;
2966
+			case 'ATT_fname':
2967
+				$orderby = 'ATT_fname';
2968
+				break;
2969
+			case 'ATT_email':
2970
+				$orderby = 'ATT_email';
2971
+				break;
2972
+			case 'ATT_city':
2973
+				$orderby = 'ATT_city';
2974
+				break;
2975
+			case 'STA_ID':
2976
+				$orderby = 'STA_ID';
2977
+				break;
2978
+			case 'CNT_ID':
2979
+				$orderby = 'CNT_ID';
2980
+				break;
2981
+			default:
2982
+				$orderby = 'ATT_lname';
2983
+		}
2984
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2985
+			? $this->_req_data['order']
2986
+			: 'ASC';
2987
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2988
+			? $this->_req_data['paged']
2989
+			: 1;
2990
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2991
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2992
+			? $this->_req_data['perpage']
2993
+			: $per_page;
2994
+		$_where       = array();
2995
+		if ( ! empty($this->_req_data['s'])) {
2996
+			$sstr         = '%' . $this->_req_data['s'] . '%';
2997
+			$_where['OR'] = array(
2998
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2999
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3000
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3001
+				'ATT_fname'                         => array('LIKE', $sstr),
3002
+				'ATT_lname'                         => array('LIKE', $sstr),
3003
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3004
+				'ATT_email'                         => array('LIKE', $sstr),
3005
+				'ATT_address'                       => array('LIKE', $sstr),
3006
+				'ATT_address2'                      => array('LIKE', $sstr),
3007
+				'ATT_city'                          => array('LIKE', $sstr),
3008
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3009
+				'State.STA_name'                    => array('LIKE', $sstr),
3010
+				'ATT_phone'                         => array('LIKE', $sstr),
3011
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3012
+				'Registration.REG_code'             => array('LIKE', $sstr),
3013
+				'Registration.REG_count'            => array('LIKE', $sstr),
3014
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3015
+			);
3016
+		}
3017
+		$offset = ($current_page - 1) * $per_page;
3018
+		$limit  = $count ? null : array($offset, $per_page);
3019
+		if ($trash) {
3020
+			$_where['status'] = array('!=', 'publish');
3021
+			$all_attendees    = $count
3022
+				? $ATT_MDL->count(array(
3023
+					$_where,
3024
+					'order_by' => array($orderby => $sort),
3025
+					'limit'    => $limit,
3026
+				), 'ATT_ID', true)
3027
+				: $ATT_MDL->get_all(array(
3028
+					$_where,
3029
+					'order_by' => array($orderby => $sort),
3030
+					'limit'    => $limit,
3031
+				));
3032
+		} else {
3033
+			$_where['status'] = array('IN', array('publish'));
3034
+			$all_attendees    = $count
3035
+				? $ATT_MDL->count(array(
3036
+					$_where,
3037
+					'order_by' => array($orderby => $sort),
3038
+					'limit'    => $limit,
3039
+				), 'ATT_ID', true)
3040
+				: $ATT_MDL->get_all(array(
3041
+					$_where,
3042
+					'order_by' => array($orderby => $sort),
3043
+					'limit'    => $limit,
3044
+				));
3045
+		}
3046
+		return $all_attendees;
3047
+	}
3048
+
3049
+
3050
+	/**
3051
+	 * This is just taking care of resending the registration confirmation
3052
+	 *
3053
+	 * @access protected
3054
+	 * @return void
3055
+	 */
3056
+	protected function _resend_registration()
3057
+	{
3058
+		$this->_process_resend_registration();
3059
+		$query_args = isset($this->_req_data['redirect_to'])
3060
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3061
+			: array('action' => 'default');
3062
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3063
+	}
3064
+
3065
+	/**
3066
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3067
+	 * to use when selecting registrations
3068
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3069
+	 *                                                     the query parameters from the request
3070
+	 * @return void ends the request with a redirect or download
3071
+	 */
3072
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3073
+	{
3074
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3075
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3076
+				array(
3077
+					'page'        => 'espresso_batch',
3078
+					'batch'       => 'file',
3079
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3080
+					'filters'     => urlencode(
3081
+						serialize(
3082
+							call_user_func(
3083
+								array( $this, $method_name_for_getting_query_params ),
3084
+								EEH_Array::is_set(
3085
+									$this->_req_data,
3086
+									'filters',
3087
+									array()
3088
+								)
3089
+							)
3090
+						)
3091
+				),
3092
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3093
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3094
+				'return_url'  => urlencode($this->_req_data['return_url']),
3095
+			)));
3096
+		} else {
3097
+			$new_request_args = array(
3098
+				'export' => 'report',
3099
+				'action' => 'registrations_report_for_event',
3100
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3101
+			);
3102
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3103
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3104
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3105
+				$EE_Export = EE_Export::instance($this->_req_data);
3106
+				$EE_Export->export();
3107
+			}
3108
+		}
3109
+	}
3110
+
3111
+
3112
+
3113
+	/**
3114
+	 * Creates a registration report using only query parameters in the request
3115
+	 * @return void
3116
+	 */
3117
+	public function _registrations_report()
3118
+	{
3119
+		$this->_registrations_report_base('_get_registration_query_parameters');
3120
+	}
3121
+
3122
+
3123
+	public function _contact_list_export()
3124
+	{
3125
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3126
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3127
+			$EE_Export = EE_Export::instance($this->_req_data);
3128
+			$EE_Export->export_attendees();
3129
+		}
3130
+	}
3131
+
3132
+
3133
+	public function _contact_list_report()
3134
+	{
3135
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3136
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3137
+				'page'        => 'espresso_batch',
3138
+				'batch'       => 'file',
3139
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3140
+				'return_url'  => urlencode($this->_req_data['return_url']),
3141
+			)));
3142
+		} else {
3143
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3144
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3145
+				$EE_Export = EE_Export::instance($this->_req_data);
3146
+				$EE_Export->report_attendees();
3147
+			}
3148
+		}
3149
+	}
3150
+
3151
+
3152
+
3153
+
3154
+
3155
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3156
+	/**
3157
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3158
+	 *
3159
+	 * @return void
3160
+	 * @throws EE_Error
3161
+	 */
3162
+	protected function _duplicate_attendee()
3163
+	{
3164
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3165
+		//verify we have necessary info
3166
+		if (empty($this->_req_data['_REG_ID'])) {
3167
+			EE_Error::add_error(
3168
+				esc_html__(
3169
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3170
+					'event_espresso'
3171
+				), __FILE__, __LINE__, __FUNCTION__
3172
+			);
3173
+			$query_args = array('action' => $action);
3174
+			$this->_redirect_after_action('', '', '', $query_args, true);
3175
+		}
3176
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3177
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3178
+		$attendee     = $registration->attendee();
3179
+		//remove relation of existing attendee on registration
3180
+		$registration->_remove_relation_to($attendee, 'Attendee');
3181
+		//new attendee
3182
+		$new_attendee = clone $attendee;
3183
+		$new_attendee->set('ATT_ID', 0);
3184
+		$new_attendee->save();
3185
+		//add new attendee to reg
3186
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3187
+		EE_Error::add_success(
3188
+			esc_html__(
3189
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3190
+				'event_espresso'
3191
+			)
3192
+		);
3193
+		//redirect to edit page for attendee
3194
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3195
+		$this->_redirect_after_action('', '', '', $query_args, true);
3196
+	}
3197
+
3198
+
3199
+	//related to cpt routes
3200
+	protected function _insert_update_cpt_item($post_id, $post)
3201
+	{
3202
+		$success  = true;
3203
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3204
+		//for attendee updates
3205
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3206
+			//note we should only be UPDATING attendees at this point.
3207
+			$updated_fields = array(
3208
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3209
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3210
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3211
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3212
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3213
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3214
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3215
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3216
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3217
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3218
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3219
+			);
3220
+			foreach ($updated_fields as $field => $value) {
3221
+				$attendee->set($field, $value);
3222
+			}
3223
+			$success                   = $attendee->save();
3224
+			$attendee_update_callbacks = apply_filters(
3225
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3226
+				array()
3227
+			);
3228
+			foreach ($attendee_update_callbacks as $a_callback) {
3229
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3230
+					throw new EE_Error(
3231
+						sprintf(
3232
+							esc_html__(
3233
+								'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.',
3234
+								'event_espresso'
3235
+							),
3236
+							$a_callback
3237
+						)
3238
+					);
3239
+				}
3240
+			}
3241
+		}
3242
+		if ($success === false) {
3243
+			EE_Error::add_error(
3244
+				esc_html__(
3245
+					'Something went wrong with updating the meta table data for the registration.',
3246
+					'event_espresso'
3247
+				),
3248
+				__FILE__, __FUNCTION__, __LINE__
3249
+			);
3250
+		}
3251
+	}
3252
+
3253
+
3254
+	public function trash_cpt_item($post_id)
3255
+	{
3256
+	}
3257
+
3258
+
3259
+	public function delete_cpt_item($post_id)
3260
+	{
3261
+	}
3262
+
3263
+
3264
+	public function restore_cpt_item($post_id)
3265
+	{
3266
+	}
3267
+
3268
+
3269
+	protected function _restore_cpt_item($post_id, $revision_id)
3270
+	{
3271
+	}
3272
+
3273
+
3274
+	public function attendee_editor_metaboxes()
3275
+	{
3276
+		$this->verify_cpt_object();
3277
+		remove_meta_box(
3278
+			'postexcerpt',
3279
+			esc_html__('Excerpt', 'event_espresso'),
3280
+			'post_excerpt_meta_box',
3281
+			$this->_cpt_routes[$this->_req_action],
3282
+			'normal',
3283
+			'core'
3284
+		);
3285
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3286
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3287
+			add_meta_box(
3288
+				'postexcerpt',
3289
+				esc_html__('Short Biography', 'event_espresso'),
3290
+				'post_excerpt_meta_box',
3291
+				$this->_cpt_routes[$this->_req_action],
3292
+				'normal'
3293
+			);
3294
+		}
3295
+		if (post_type_supports('espresso_attendees', 'comments')) {
3296
+			add_meta_box(
3297
+				'commentsdiv',
3298
+				esc_html__('Notes on the Contact', 'event_espresso'),
3299
+				'post_comment_meta_box',
3300
+				$this->_cpt_routes[$this->_req_action],
3301
+				'normal',
3302
+				'core'
3303
+			);
3304
+		}
3305
+		add_meta_box(
3306
+			'attendee_contact_info',
3307
+			esc_html__('Contact Info', 'event_espresso'),
3308
+			array($this, 'attendee_contact_info'),
3309
+			$this->_cpt_routes[$this->_req_action],
3310
+			'side',
3311
+			'core'
3312
+		);
3313
+		add_meta_box(
3314
+			'attendee_details_address',
3315
+			esc_html__('Address Details', 'event_espresso'),
3316
+			array($this, 'attendee_address_details'),
3317
+			$this->_cpt_routes[$this->_req_action],
3318
+			'normal',
3319
+			'core'
3320
+		);
3321
+		add_meta_box(
3322
+			'attendee_registrations',
3323
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3324
+			array($this, 'attendee_registrations_meta_box'),
3325
+			$this->_cpt_routes[$this->_req_action],
3326
+			'normal',
3327
+			'high'
3328
+		);
3329
+	}
3330
+
3331
+
3332
+	/**
3333
+	 * Metabox for attendee contact info
3334
+	 *
3335
+	 * @param  WP_Post $post wp post object
3336
+	 * @return string attendee contact info ( and form )
3337
+	 * @throws DomainException
3338
+	 */
3339
+	public function attendee_contact_info($post)
3340
+	{
3341
+		//get attendee object ( should already have it )
3342
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3343
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3344
+		EEH_Template::display_template($template, $this->_template_args);
3345
+	}
3346
+
3347
+
3348
+	/**
3349
+	 * Metabox for attendee details
3350
+	 *
3351
+	 * @param  WP_Post $post wp post object
3352
+	 * @return string attendee address details (and form)
3353
+	 * @throws DomainException
3354
+	 */
3355
+	public function attendee_address_details($post)
3356
+	{
3357
+		//get attendee object (should already have it)
3358
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3359
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3360
+			new EE_Question_Form_Input(
3361
+				EE_Question::new_instance(
3362
+					array(
3363
+						'QST_ID'           => 0,
3364
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3365
+						'QST_system'       => 'admin-state',
3366
+					)
3367
+				),
3368
+				EE_Answer::new_instance(
3369
+					array(
3370
+						'ANS_ID'    => 0,
3371
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3372
+					)
3373
+				),
3374
+				array(
3375
+					'input_id'       => 'STA_ID',
3376
+					'input_name'     => 'STA_ID',
3377
+					'input_prefix'   => '',
3378
+					'append_qstn_id' => false,
3379
+				)
3380
+			)
3381
+		);
3382
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3383
+			new EE_Question_Form_Input(
3384
+				EE_Question::new_instance(
3385
+					array(
3386
+						'QST_ID'           => 0,
3387
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3388
+						'QST_system'       => 'admin-country',
3389
+					)
3390
+				),
3391
+				EE_Answer::new_instance(
3392
+					array(
3393
+						'ANS_ID'    => 0,
3394
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3395
+					)
3396
+				),
3397
+				array(
3398
+					'input_id'       => 'CNT_ISO',
3399
+					'input_name'     => 'CNT_ISO',
3400
+					'input_prefix'   => '',
3401
+					'append_qstn_id' => false,
3402
+				)
3403
+			)
3404
+		);
3405
+		$template                             =
3406
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3407
+		EEH_Template::display_template($template, $this->_template_args);
3408
+	}
3409
+
3410
+
3411
+	/**
3412
+	 *        _attendee_details
3413
+	 *
3414
+	 * @access protected
3415
+	 * @param $post
3416
+	 * @return void
3417
+	 * @throws DomainException
3418
+	 * @throws EE_Error
3419
+	 */
3420
+	public function attendee_registrations_meta_box($post)
3421
+	{
3422
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3423
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3424
+		$template                              =
3425
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3426
+		EEH_Template::display_template($template, $this->_template_args);
3427
+	}
3428
+
3429
+
3430
+	/**
3431
+	 * add in the form fields for the attendee edit
3432
+	 *
3433
+	 * @param  WP_Post $post wp post object
3434
+	 * @return string html for new form.
3435
+	 * @throws DomainException
3436
+	 */
3437
+	public function after_title_form_fields($post)
3438
+	{
3439
+		if ($post->post_type == 'espresso_attendees') {
3440
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3441
+			$template_args['attendee'] = $this->_cpt_model_obj;
3442
+			EEH_Template::display_template($template, $template_args);
3443
+		}
3444
+	}
3445
+
3446
+
3447
+	/**
3448
+	 *        _trash_or_restore_attendee
3449
+	 *
3450
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3451
+	 * @return void
3452
+	 * @throws EE_Error
3453
+	 * @access protected
3454
+	 */
3455
+	protected function _trash_or_restore_attendees($trash = true)
3456
+	{
3457
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3458
+		$ATT_MDL = EEM_Attendee::instance();
3459
+		$success = 1;
3460
+		//Checkboxes
3461
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3462
+			// if array has more than one element than success message should be plural
3463
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3464
+			// cycle thru checkboxes
3465
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3466
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3467
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3468
+				if ( ! $updated) {
3469
+					$success = 0;
3470
+				}
3471
+			}
3472
+		} else {
3473
+			// grab single id and delete
3474
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3475
+			//get attendee
3476
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3477
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3478
+			$updated = $att->save();
3479
+			if ( ! $updated) {
3480
+				$success = 0;
3481
+			}
3482
+		}
3483
+		$what        = $success > 1
3484
+			? esc_html__('Contacts', 'event_espresso')
3485
+			: esc_html__('Contact', 'event_espresso');
3486
+		$action_desc = $trash
3487
+			? esc_html__('moved to the trash', 'event_espresso')
3488
+			: esc_html__('restored', 'event_espresso');
3489
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3490
+	}
3491 3491
 
3492 3492
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Pdf_messenger.class.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
10 10
 	exit('NO direct script access allowed');
11 11
 
12 12
 /**
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @subpackage		messages
21 21
  * @author			Darren Ethier
22 22
  */
23
-class EE_Pdf_messenger extends EE_messenger  {
23
+class EE_Pdf_messenger extends EE_messenger {
24 24
 
25 25
 
26 26
 	/**
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @see abstract declaration in EE_messenger for details.
94 94
 	 */
95 95
 	protected function _set_admin_pages() {
96
-		$this->admin_registered_pages = array( 'events_edit' => false );
96
+		$this->admin_registered_pages = array('events_edit' => false);
97 97
 	}
98 98
 
99 99
 
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
 	protected function _set_validator_config() {
114 114
 		$this->_validator_config = array(
115 115
 			'subject' => array(
116
-				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email','event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
116
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
117 117
 				),
118 118
 			'content' => array(
119
-				'shortcodes' => array( 'recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email','event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
119
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
120 120
 				),
121 121
 			'attendee_list' => array(
122 122
 				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 				'required' => array('[EVENT_LIST]')
128 128
 				),
129 129
 			'ticket_list' => array(
130
-				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list','primary_registration_details', 'recipient_details'),
130
+				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'),
131 131
 				'required' => array('[TICKET_LIST]')
132 132
 				),
133 133
 			'datetime_list' => array(
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	public  function enqueue_scripts_styles() {
149 149
 		parent::enqueue_scripts_styles();
150
-		do_action( 'AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
150
+		do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
151 151
 	}
152 152
 
153 153
 
@@ -273,18 +273,18 @@  discard block
 block discarded – undo
273 273
 	 */
274 274
 	protected function _send_message() {
275 275
 		$this->_template_args = array(
276
-			'page_title' => html_entity_decode( stripslashes( $this->_subject ), ENT_QUOTES, "UTF-8"),
277
-			'base_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation ),
278
-			'print_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation ),
279
-			'main_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation ),
280
-			'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',
281
-			'main_body' => apply_filters( 'FHEE__EE_Pdf_messenger___send_message__main_body', wpautop(stripslashes_deep( html_entity_decode($this->_content,  ENT_QUOTES,"UTF-8" ) )), $this->_content )
276
+			'page_title' => html_entity_decode(stripslashes($this->_subject), ENT_QUOTES, "UTF-8"),
277
+			'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation),
278
+			'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation),
279
+			'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation),
280
+			'extra_css' => EE_LIBRARIES_URL.'messages/defaults/default/variations/pdf_base_default.css',
281
+			'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))), $this->_content)
282 282
 			);
283 283
 		$this->_deregister_wp_hooks();
284
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) );
284
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
285 285
 		$content = $this->_get_main_template();
286 286
 //		die( $content );
287
-		$this->_do_pdf( $content );
287
+		$this->_do_pdf($content);
288 288
 		exit(0);
289 289
 	}
290 290
 
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
 
309 309
 		//just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
310 310
 		add_action('wp_head', 'wp_enqueue_scripts');
311
-		add_action( 'wp_footer', 'wp_print_footer_scripts' );
312
-		add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
311
+		add_action('wp_footer', 'wp_print_footer_scripts');
312
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
313 313
 	}
314 314
 
315 315
 
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 	 * @param bool $preview
323 323
 	 * @return string
324 324
 	 */
325
-	protected function _get_main_template( $preview = FALSE ) {
326
-		$wrapper_template = $this->_tmp_pack->get_wrapper( 'html', 'main' );
325
+	protected function _get_main_template($preview = FALSE) {
326
+		$wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main');
327 327
 		//add message type to template_args
328 328
 		$this->_template_args['message_type'] = $this->_incoming_message_type;
329
-		return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE );
329
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE);
330 330
 	}
331 331
 
332 332
 
@@ -339,15 +339,15 @@  discard block
 block discarded – undo
339 339
 	 *
340 340
 	 * @return void
341 341
 	 */
342
-	protected function _do_pdf( $content = '' ) {
343
-		$invoice_name = html_entity_decode( $this->_subject, ENT_QUOTES, "UTF-8");
342
+	protected function _do_pdf($content = '') {
343
+		$invoice_name = html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8");
344 344
 
345 345
 		//only load dompdf if nobody else has yet...
346
-		if( ! defined('DOMPDF_DIR')){
346
+		if ( ! defined('DOMPDF_DIR')) {
347 347
 			define('DOMPDF_ENABLE_REMOTE', TRUE);
348 348
 			define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
349 349
 			define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
350
-			require_once(EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php');
350
+			require_once(EE_THIRD_PARTY.'dompdf/dompdf_config.inc.php');
351 351
 		}
352 352
 		$dompdf = new DOMPDF();
353 353
 		if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) {
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		$dompdf->load_html($content);
357 357
 		$dompdf->render();
358 358
 		//forcing the browser to open a download dialog.
359
-		$dompdf->stream($invoice_name . ".pdf", array( 'Attachment' => TRUE ));
359
+		$dompdf->stream($invoice_name.".pdf", array('Attachment' => TRUE));
360 360
 	}
361 361
 
362 362
 
Please login to merge, or discard this patch.
admin_pages/general_settings/General_Settings_Admin_Page.core.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
      *
749 749
      * @access    public
750 750
      * @param    string $CNT_ISO
751
-     * @return mixed string | array
751
+     * @return string|null string | array
752 752
      * @throws DomainException
753 753
      */
754 754
     public function display_country_settings($CNT_ISO = '')
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
      *        delete_state
1065 1065
      *
1066 1066
      * @access    public
1067
-     * @return        boolean
1067
+     * @return        false|null
1068 1068
      */
1069 1069
     public function delete_state()
1070 1070
     {
Please login to merge, or discard this patch.
Indentation   +1371 added lines, -1371 removed lines patch added patch discarded remove patch
@@ -17,1386 +17,1386 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * _question_group
22
-     * holds the specific question group object for the question group details screen
23
-     *
24
-     * @var object
25
-     */
26
-    protected $_question_group;
27
-
28
-
29
-    /**
30
-     * Initialize basic properties.
31
-     */
32
-    protected function _init_page_props()
33
-    {
34
-        $this->page_slug        = GEN_SET_PG_SLUG;
35
-        $this->page_label       = GEN_SET_LABEL;
36
-        $this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
-        $this->_admin_base_path = GEN_SET_ADMIN;
38
-    }
39
-
40
-
41
-    /**
42
-     * Set ajax hooks
43
-     */
44
-    protected function _ajax_hooks()
45
-    {
46
-        add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
47
-        add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
48
-        add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
49
-        add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
50
-    }
51
-
52
-
53
-    /**
54
-     * More page properties initialization.
55
-     */
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = GEN_SET_LABEL;
59
-        $this->_labels           = array(
60
-            'publishbox' => __('Update Settings', 'event_espresso'),
61
-        );
62
-    }
63
-
64
-
65
-    /**
66
-     * Set page routes property.
67
-     */
68
-    protected function _set_page_routes()
69
-    {
70
-        $this->_page_routes = array(
71
-
72
-            'critical_pages'                => array(
73
-                'func'       => '_espresso_page_settings',
74
-                'capability' => 'manage_options',
75
-            ),
76
-            'update_espresso_page_settings' => array(
77
-                'func'       => '_update_espresso_page_settings',
78
-                'capability' => 'manage_options',
79
-                'noheader'   => true,
80
-            ),
81
-            'default'                       => array(
82
-                'func'       => '_your_organization_settings',
83
-                'capability' => 'manage_options',
84
-            ),
85
-
86
-            'update_your_organization_settings' => array(
87
-                'func'       => '_update_your_organization_settings',
88
-                'capability' => 'manage_options',
89
-                'noheader'   => true,
90
-            ),
91
-
92
-            'admin_option_settings' => array(
93
-                'func'       => '_admin_option_settings',
94
-                'capability' => 'manage_options',
95
-            ),
96
-
97
-            'update_admin_option_settings' => array(
98
-                'func'       => '_update_admin_option_settings',
99
-                'capability' => 'manage_options',
100
-                'noheader'   => true,
101
-            ),
102
-
103
-            'country_settings' => array(
104
-                'func'       => '_country_settings',
105
-                'capability' => 'manage_options',
106
-            ),
107
-
108
-            'update_country_settings' => array(
109
-                'func'       => '_update_country_settings',
110
-                'capability' => 'manage_options',
111
-                'noheader'   => true,
112
-            ),
113
-
114
-            'display_country_settings' => array(
115
-                'func'       => 'display_country_settings',
116
-                'capability' => 'manage_options',
117
-                'noheader'   => true,
118
-            ),
119
-
120
-            'add_new_state' => array(
121
-                'func'       => 'add_new_state',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ),
125
-
126
-            'delete_state' => array(
127
-                'func'       => 'delete_state',
128
-                'capability' => 'manage_options',
129
-                'noheader'   => true,
130
-            ),
131
-        );
132
-    }
133
-
134
-
135
-    /**
136
-     * Set page configuration property
137
-     */
138
-    protected function _set_page_config()
139
-    {
140
-        $this->_page_config = array(
141
-            'critical_pages'        => array(
142
-                'nav'           => array(
143
-                    'label' => __('Critical Pages', 'event_espresso'),
144
-                    'order' => 50,
145
-                ),
146
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
147
-                'help_tabs'     => array(
148
-                    'general_settings_critical_pages_help_tab' => array(
149
-                        'title'    => __('Critical Pages', 'event_espresso'),
150
-                        'filename' => 'general_settings_critical_pages',
151
-                    ),
152
-                ),
153
-                'help_tour'     => array('Critical_Pages_Help_Tour'),
154
-                'require_nonce' => false,
155
-            ),
156
-            'default'               => array(
157
-                'nav'           => array(
158
-                    'label' => __('Your Organization', 'event_espresso'),
159
-                    'order' => 20,
160
-                ),
161
-                'help_tabs'     => array(
162
-                    'general_settings_your_organization_help_tab' => array(
163
-                        'title'    => __('Your Organization', 'event_espresso'),
164
-                        'filename' => 'general_settings_your_organization',
165
-                    ),
166
-                ),
167
-                'help_tour'     => array('Your_Organization_Help_Tour'),
168
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
-                'require_nonce' => false,
170
-            ),
171
-            'admin_option_settings' => array(
172
-                'nav'           => array(
173
-                    'label' => __('Admin Options', 'event_espresso'),
174
-                    'order' => 60,
175
-                ),
176
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
177
-                'help_tabs'     => array(
178
-                    'general_settings_admin_options_help_tab' => array(
179
-                        'title'    => __('Admin Options', 'event_espresso'),
180
-                        'filename' => 'general_settings_admin_options',
181
-                    ),
182
-                ),
183
-                'help_tour'     => array('Admin_Options_Help_Tour'),
184
-                'require_nonce' => false,
185
-            ),
186
-            'country_settings'      => array(
187
-                'nav'           => array(
188
-                    'label' => __('Countries', 'event_espresso'),
189
-                    'order' => 70,
190
-                ),
191
-                'help_tabs'     => array(
192
-                    'general_settings_countries_help_tab' => array(
193
-                        'title'    => __('Countries', 'event_espresso'),
194
-                        'filename' => 'general_settings_countries',
195
-                    ),
196
-                ),
197
-                'help_tour'     => array('Countries_Help_Tour'),
198
-                'require_nonce' => false,
199
-            ),
200
-        );
201
-    }
202
-
203
-
204
-
205
-    protected function _add_screen_options()
206
-    {
207
-    }
208
-
209
-    protected function _add_feature_pointers()
210
-    {
211
-    }
212
-
213
-
214
-    /**
215
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
216
-     */
217
-    public function load_scripts_styles()
218
-    {
219
-        //styles
220
-        wp_enqueue_style('espresso-ui-theme');
221
-        //scripts
222
-        wp_enqueue_script('ee_admin_js');
223
-    }
224
-
225
-
226
-    /**
227
-     * Execute logic running on `admin_init`
228
-     */
229
-    public function admin_init()
230
-    {
231
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = __(
232
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
233
-            'event_espresso'
234
-        );
235
-        EE_Registry::$i18n_js_strings['error_occurred']          = __(
236
-            'An error occurred! Please refresh the page and try again.',
237
-            'event_espresso'
238
-        );
239
-        EE_Registry::$i18n_js_strings['confirm_delete_state']    = __(
240
-            'Are you sure you want to delete this State / Province?',
241
-            'event_espresso'
242
-        );
243
-        $protocol                                                = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
244
-        EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
245
-            'admin-ajax.php?page=espresso_general_settings',
246
-            $protocol
247
-        );
248
-    }
249
-
250
-    public function admin_notices()
251
-    {
252
-    }
253
-
254
-    public function admin_footer_scripts()
255
-    {
256
-    }
257
-
258
-
259
-    /**
260
-     * Enqueue scripts and styles for the default route.
261
-     */
262
-    public function load_scripts_styles_default()
263
-    {
264
-        //styles
265
-        wp_enqueue_style('thickbox');
266
-        //scripts
267
-        wp_enqueue_script('media-upload');
268
-        wp_enqueue_script('thickbox');
269
-        wp_register_script(
270
-            'organization_settings',
271
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
272
-            array('jquery', 'media-upload', 'thickbox'),
273
-            EVENT_ESPRESSO_VERSION,
274
-            true
275
-        );
276
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
277
-        wp_enqueue_script('organization_settings');
278
-        wp_enqueue_style('organization-css');
279
-        $confirm_image_delete = array(
280
-            'text' => __(
281
-                'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
282
-                'event_espresso'
283
-            ),
284
-        );
285
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
286
-    }
287
-
288
-
289
-    /**
290
-     * Enqueue scripts and styles for the country settings route.
291
-     */
292
-    public function load_scripts_styles_country_settings()
293
-    {
294
-        //scripts
295
-        wp_register_script(
296
-            'gen_settings_countries',
297
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
298
-            array('ee_admin_js'),
299
-            EVENT_ESPRESSO_VERSION,
300
-            true
301
-        );
302
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
303
-        wp_enqueue_script('gen_settings_countries');
304
-        wp_enqueue_style('organization-css');
305
-    }
306
-
307
-
308
-    /*************        Espresso Pages        *************/
309
-    /**
310
-     * _espresso_page_settings
311
-     *
312
-     * @throws \EE_Error
313
-     */
314
-    protected function _espresso_page_settings()
315
-    {
316
-        // Check to make sure all of the main pages are setup properly,
317
-        // if not create the default pages and display an admin notice
318
-        EEH_Activation::verify_default_pages_exist();
319
-        $this->_transient_garbage_collection();
320
-        $this->_template_args['values']             = $this->_yes_no_values;
321
-        $this->_template_args['reg_page_id']        = isset(EE_Registry::instance()->CFG->core->reg_page_id)
322
-            ? EE_Registry::instance()->CFG->core->reg_page_id
323
-            : null;
324
-        $this->_template_args['reg_page_obj']       = isset(EE_Registry::instance()->CFG->core->reg_page_id)
325
-            ? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
326
-            : false;
327
-        $this->_template_args['txn_page_id']        = isset(EE_Registry::instance()->CFG->core->txn_page_id)
328
-            ? EE_Registry::instance()->CFG->core->txn_page_id
329
-            : null;
330
-        $this->_template_args['txn_page_obj']       = isset(EE_Registry::instance()->CFG->core->txn_page_id)
331
-            ? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
332
-            : false;
333
-        $this->_template_args['thank_you_page_id']  = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
334
-            ? EE_Registry::instance()->CFG->core->thank_you_page_id
335
-            : null;
336
-        $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
337
-            ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
338
-            : false;
339
-        $this->_template_args['cancel_page_id']     = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
340
-            ? EE_Registry::instance()->CFG->core->cancel_page_id
341
-            : null;
342
-        $this->_template_args['cancel_page_obj']    = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
343
-            ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
344
-            : false;
345
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
346
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
347
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
348
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
349
-            $this->_template_args,
350
-            true
351
-        );
352
-        $this->display_admin_page_with_sidebar();
353
-    }
354
-
355
-
356
-    /**
357
-     * Handler for updating espresso page settings.
358
-     */
359
-    protected function _update_espresso_page_settings()
360
-    {
361
-        // capture incoming request data && set page IDs
362
-        EE_Registry::instance()->CFG->core->reg_page_id       = isset($this->_req_data['reg_page_id'])
363
-            ? absint($this->_req_data['reg_page_id'])
364
-            : EE_Registry::instance()->CFG->core->reg_page_id;
365
-        EE_Registry::instance()->CFG->core->txn_page_id       = isset($this->_req_data['txn_page_id'])
366
-            ? absint($this->_req_data['txn_page_id'])
367
-            : EE_Registry::instance()->CFG->core->txn_page_id;
368
-        EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
369
-            ? absint($this->_req_data['thank_you_page_id'])
370
-            : EE_Registry::instance()->CFG->core->thank_you_page_id;
371
-        EE_Registry::instance()->CFG->core->cancel_page_id    = isset($this->_req_data['cancel_page_id'])
372
-            ? absint($this->_req_data['cancel_page_id'])
373
-            : EE_Registry::instance()->CFG->core->cancel_page_id;
374
-
375
-        EE_Registry::instance()->CFG->core = apply_filters(
376
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
377
-            EE_Registry::instance()->CFG->core,
378
-            $this->_req_data
379
-        );
380
-        $what                              = __('Critical Pages & Shortcodes', 'event_espresso');
381
-        $this->_redirect_after_action(
382
-            $this->_update_espresso_configuration(
383
-                $what,
384
-                EE_Registry::instance()->CFG->core,
385
-                __FILE__,
386
-                __FUNCTION__,
387
-                __LINE__
388
-            ),
389
-            $what,
390
-            '',
391
-            array(
392
-                'action' => 'critical_pages',
393
-            ),
394
-            true
395
-        );
396
-    }
397
-
398
-
399
-    /*************        Your Organization        *************/
400
-
401
-
402
-    /**
403
-     * Output for the Your Organization settings route.
404
-     * @throws DomainException
405
-     * @throws EE_Error
406
-     */
407
-    protected function _your_organization_settings()
408
-    {
409
-
410
-        $this->_template_args['site_license_key']       = isset(
411
-            EE_Registry::instance()->NET_CFG->core->site_license_key
412
-        )
413
-            ? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key')
414
-            : '';
415
-        $this->_template_args['organization_name']      = isset(EE_Registry::instance()->CFG->organization->name)
416
-            ? EE_Registry::instance()->CFG->organization->get_pretty('name')
417
-            : '';
418
-        $this->_template_args['organization_address_1'] = isset(EE_Registry::instance()->CFG->organization->address_1)
419
-            ? EE_Registry::instance()->CFG->organization->get_pretty('address_1')
420
-            : '';
421
-        $this->_template_args['organization_address_2'] = isset(EE_Registry::instance()->CFG->organization->address_2)
422
-            ? EE_Registry::instance()->CFG->organization->get_pretty('address_2')
423
-            : '';
424
-        $this->_template_args['organization_city']      = isset(EE_Registry::instance()->CFG->organization->city)
425
-            ? EE_Registry::instance()->CFG->organization->get_pretty('city')
426
-            : '';
427
-        $this->_template_args['organization_zip']       = isset(EE_Registry::instance()->CFG->organization->zip)
428
-            ? EE_Registry::instance()->CFG->organization->get_pretty('zip')
429
-            : '';
430
-        $this->_template_args['organization_email']     = isset(EE_Registry::instance()->CFG->organization->email)
431
-            ? EE_Registry::instance()->CFG->organization->get_pretty('email')
432
-            : '';
433
-        $this->_template_args['organization_phone']     = isset(EE_Registry::instance()->CFG->organization->phone)
434
-            ? EE_Registry::instance()->CFG->organization->get_pretty('phone')
435
-            : '';
436
-        $this->_template_args['organization_vat']       = isset(EE_Registry::instance()->CFG->organization->vat)
437
-            ? EE_Registry::instance()->CFG->organization->get_pretty('vat')
438
-            : '';
439
-        $this->_template_args['currency_sign']          = isset(EE_Registry::instance()->CFG->currency->sign)
440
-            ? EE_Registry::instance()->CFG->currency->get_pretty('sign')
441
-            : '$';
442
-        $this->_template_args['organization_logo_url']  = isset(EE_Registry::instance()->CFG->organization->logo_url)
443
-            ? EE_Registry::instance()->CFG->organization->get_pretty('logo_url')
444
-            : false;
445
-        $this->_template_args['organization_facebook']  = isset(EE_Registry::instance()->CFG->organization->facebook)
446
-            ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
447
-            : '';
448
-        $this->_template_args['organization_twitter']   = isset(EE_Registry::instance()->CFG->organization->twitter)
449
-            ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
450
-            : '';
451
-        $this->_template_args['organization_linkedin']  = isset(EE_Registry::instance()->CFG->organization->linkedin)
452
-            ? EE_Registry::instance()->CFG->organization->get_pretty('linkedin')
453
-            : '';
454
-        $this->_template_args['organization_pinterest'] = isset(EE_Registry::instance()->CFG->organization->pinterest)
455
-            ? EE_Registry::instance()->CFG->organization->get_pretty('pinterest')
456
-            : '';
457
-        $this->_template_args['organization_google']    = isset(EE_Registry::instance()->CFG->organization->google)
458
-            ? EE_Registry::instance()->CFG->organization->get_pretty('google')
459
-            : '';
460
-        $this->_template_args['organization_instagram'] = isset(EE_Registry::instance()->CFG->organization->instagram)
461
-            ? EE_Registry::instance()->CFG->organization->get_pretty('instagram')
462
-            : '';
463
-        //UXIP settings
464
-        $this->_template_args['ee_ueip_optin'] = isset(EE_Registry::instance()->CFG->core->ee_ueip_optin)
465
-            ? EE_Registry::instance()->CFG->core->get_pretty('ee_ueip_optin')
466
-            : true;
467
-
468
-        $STA_ID                         = isset(EE_Registry::instance()->CFG->organization->STA_ID)
469
-            ? EE_Registry::instance()->CFG->organization->STA_ID
470
-            : 4;
471
-        $this->_template_args['states'] = new EE_Question_Form_Input(
472
-            EE_Question::new_instance(array(
473
-                'QST_ID'           => 0,
474
-                'QST_display_text' => __('State/Province', 'event_espresso'),
475
-                'QST_system'       => 'admin-state',
476
-            )),
477
-            EE_Answer::new_instance(array(
478
-                'ANS_ID'    => 0,
479
-                'ANS_value' => $STA_ID,
480
-            )),
481
-            array(
482
-                'input_id'       => 'organization_state',
483
-                'input_name'     => 'organization_state',
484
-                'input_prefix'   => '',
485
-                'append_qstn_id' => false,
486
-            )
487
-        );
488
-
489
-        $CNT_ISO                           = isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
490
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
491
-            : 'US';
492
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
493
-            EE_Question::new_instance(array(
494
-                'QST_ID'           => 0,
495
-                'QST_display_text' => __('Country', 'event_espresso'),
496
-                'QST_system'       => 'admin-country',
497
-            )),
498
-            EE_Answer::new_instance(array(
499
-                'ANS_ID'    => 0,
500
-                'ANS_value' => $CNT_ISO,
501
-            )),
502
-            array(
503
-                'input_id'       => 'organization_country',
504
-                'input_name'     => 'organization_country',
505
-                'input_prefix'   => '',
506
-                'append_qstn_id' => false,
507
-            )
508
-        );
509
-
510
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
511
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
512
-
513
-        //PUE verification stuff
514
-        $ver_option_key                                    = 'puvererr_' . basename(EE_PLUGIN_BASENAME);
515
-        $verify_fail                                       = get_option($ver_option_key);
516
-        $this->_template_args['site_license_key_verified'] = $verify_fail
517
-                                                             || ! empty($verify_fail)
518
-                                                             || (empty($this->_template_args['site_license_key'])
519
-                                                                 && empty($verify_fail)
520
-                                                             )
521
-            ? '<span class="dashicons dashicons-admin-network ee-icon-color-ee-red ee-icon-size-20"></span>'
522
-            : '<span class="dashicons dashicons-admin-network ee-icon-color-ee-green ee-icon-size-20"></span>';
523
-
524
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
525
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
526
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
527
-            GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php',
528
-            $this->_template_args,
529
-            true
530
-        );
531
-
532
-        $this->display_admin_page_with_sidebar();
533
-    }
534
-
535
-
536
-    /**
537
-     * Handler for updating organziation settings.
538
-     */
539
-    protected function _update_your_organization_settings()
540
-    {
541
-        if (is_main_site()) {
542
-            EE_Registry::instance()->NET_CFG->core->site_license_key = isset($this->_req_data['site_license_key'])
543
-                ? sanitize_text_field($this->_req_data['site_license_key'])
544
-                : EE_Registry::instance()->NET_CFG->core->site_license_key;
545
-        }
546
-        EE_Registry::instance()->CFG->organization->name      = isset($this->_req_data['organization_name'])
547
-            ? sanitize_text_field($this->_req_data['organization_name'])
548
-            : EE_Registry::instance()->CFG->organization->name;
549
-        EE_Registry::instance()->CFG->organization->address_1 = isset($this->_req_data['organization_address_1'])
550
-            ? sanitize_text_field($this->_req_data['organization_address_1'])
551
-            : EE_Registry::instance()->CFG->organization->address_1;
552
-        EE_Registry::instance()->CFG->organization->address_2 = isset($this->_req_data['organization_address_2'])
553
-            ? sanitize_text_field($this->_req_data['organization_address_2'])
554
-            : EE_Registry::instance()->CFG->organization->address_2;
555
-        EE_Registry::instance()->CFG->organization->city      = isset($this->_req_data['organization_city'])
556
-            ? sanitize_text_field($this->_req_data['organization_city'])
557
-            : EE_Registry::instance()->CFG->organization->city;
558
-        EE_Registry::instance()->CFG->organization->STA_ID    = isset($this->_req_data['organization_state'])
559
-            ? absint($this->_req_data['organization_state'])
560
-            : EE_Registry::instance()->CFG->organization->STA_ID;
561
-        EE_Registry::instance()->CFG->organization->CNT_ISO   = isset($this->_req_data['organization_country'])
562
-            ? sanitize_text_field($this->_req_data['organization_country'])
563
-            : EE_Registry::instance()->CFG->organization->CNT_ISO;
564
-        EE_Registry::instance()->CFG->organization->zip       = isset($this->_req_data['organization_zip'])
565
-            ? sanitize_text_field($this->_req_data['organization_zip'])
566
-            : EE_Registry::instance()->CFG->organization->zip;
567
-        EE_Registry::instance()->CFG->organization->email     = isset($this->_req_data['organization_email'])
568
-            ? sanitize_email($this->_req_data['organization_email'])
569
-            : EE_Registry::instance()->CFG->organization->email;
570
-        EE_Registry::instance()->CFG->organization->vat       = isset($this->_req_data['organization_vat'])
571
-            ? sanitize_text_field($this->_req_data['organization_vat'])
572
-            : EE_Registry::instance()->CFG->organization->vat;
573
-        EE_Registry::instance()->CFG->organization->phone     = isset($this->_req_data['organization_phone'])
574
-            ? sanitize_text_field($this->_req_data['organization_phone'])
575
-            : EE_Registry::instance()->CFG->organization->phone;
576
-        EE_Registry::instance()->CFG->organization->logo_url  = isset($this->_req_data['organization_logo_url'])
577
-            ? esc_url_raw($this->_req_data['organization_logo_url'])
578
-            : EE_Registry::instance()->CFG->organization->logo_url;
579
-        EE_Registry::instance()->CFG->organization->facebook  = isset($this->_req_data['organization_facebook'])
580
-            ? esc_url_raw($this->_req_data['organization_facebook'])
581
-            : EE_Registry::instance()->CFG->organization->facebook;
582
-        EE_Registry::instance()->CFG->organization->twitter   = isset($this->_req_data['organization_twitter'])
583
-            ? esc_url_raw($this->_req_data['organization_twitter'])
584
-            : EE_Registry::instance()->CFG->organization->twitter;
585
-        EE_Registry::instance()->CFG->organization->linkedin  = isset($this->_req_data['organization_linkedin'])
586
-            ? esc_url_raw($this->_req_data['organization_linkedin'])
587
-            : EE_Registry::instance()->CFG->organization->linkedin;
588
-        EE_Registry::instance()->CFG->organization->pinterest = isset($this->_req_data['organization_pinterest'])
589
-            ? esc_url_raw($this->_req_data['organization_pinterest'])
590
-            : EE_Registry::instance()->CFG->organization->pinterest;
591
-        EE_Registry::instance()->CFG->organization->google    = isset($this->_req_data['organization_google'])
592
-            ? esc_url_raw($this->_req_data['organization_google'])
593
-            : EE_Registry::instance()->CFG->organization->google;
594
-        EE_Registry::instance()->CFG->organization->instagram = isset($this->_req_data['organization_instagram'])
595
-            ? esc_url_raw($this->_req_data['organization_instagram'])
596
-            : EE_Registry::instance()->CFG->organization->instagram;
597
-        EE_Registry::instance()->CFG->core->ee_ueip_optin     = isset($this->_req_data['ueip_optin'])
598
-                                                                && ! empty($this->_req_data['ueip_optin'])
599
-            ? $this->_req_data['ueip_optin']
600
-            : EE_Registry::instance()->CFG->core->ee_ueip_optin;
601
-
602
-        EE_Registry::instance()->CFG->currency = new EE_Currency_Config(
603
-            EE_Registry::instance()->CFG->organization->CNT_ISO
604
-        );
605
-
606
-        EE_Registry::instance()->CFG = apply_filters(
607
-            'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
608
-            EE_Registry::instance()->CFG
609
-        );
610
-
611
-        $what    = 'Your Organization Settings';
612
-        $success = $this->_update_espresso_configuration(
613
-            $what,
614
-            EE_Registry::instance()->CFG,
615
-            __FILE__,
616
-            __FUNCTION__,
617
-            __LINE__
618
-        );
619
-
620
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default'));
621
-    }
622
-
623
-
624
-
625
-    /*************        Admin Options        *************/
626
-
627
-
628
-    /**
629
-     * _admin_option_settings
630
-     *
631
-     * @throws \EE_Error
632
-     * @throws \LogicException
633
-     */
634
-    protected function _admin_option_settings()
635
-    {
636
-        $this->_template_args['admin_page_content'] = '';
637
-        try {
638
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
639
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
640
-            $this->_template_args['values'] = $this->_yes_no_values;
641
-            // also need to account for the do_action that was in the old template
642
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
643
-            $this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
644
-        } catch (Exception $e) {
645
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
646
-        }
647
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
648
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
649
-        $this->display_admin_page_with_sidebar();
650
-    }
651
-
652
-
653
-    /**
654
-     * _update_admin_option_settings
655
-     *
656
-     * @throws \EE_Error
657
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
658
-     * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
659
-     * @throws \InvalidArgumentException
660
-     * @throws \LogicException
661
-     */
662
-    protected function _update_admin_option_settings()
663
-    {
664
-        try {
665
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
666
-            $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]);
667
-            EE_Registry::instance()->CFG->admin = apply_filters(
668
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
669
-                EE_Registry::instance()->CFG->admin
670
-            );
671
-        } catch (Exception $e) {
672
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
673
-        }
674
-        $this->_redirect_after_action(
675
-            apply_filters(
676
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
677
-                $this->_update_espresso_configuration(
678
-                    'Admin Options',
679
-                    EE_Registry::instance()->CFG->admin,
680
-                    __FILE__, __FUNCTION__, __LINE__
681
-                )
682
-            ),
683
-            'Admin Options',
684
-            'updated',
685
-            array('action' => 'admin_option_settings')
686
-        );
687
-
688
-    }
689
-
690
-
691
-    /*************        Countries        *************/
692
-
693
-
694
-    /**
695
-     * Output Country Settings view.
696
-     * @throws DomainException
697
-     * @throws EE_Error
698
-     */
699
-    protected function _country_settings()
700
-    {
701
-        $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
702
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
703
-            : 'US';
704
-        $CNT_ISO = isset($this->_req_data['country'])
705
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
706
-            : $CNT_ISO;
707
-
708
-        //load field generator helper
709
-
710
-        $this->_template_args['values'] = $this->_yes_no_values;
711
-
712
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
713
-            EE_Question::new_instance(array(
714
-                'QST_ID'           => 0,
715
-                'QST_display_text' => __('Select Country', 'event_espresso'),
716
-                'QST_system'       => 'admin-country',
717
-            )),
718
-            EE_Answer::new_instance(array(
719
-                'ANS_ID'    => 0,
720
-                'ANS_value' => $CNT_ISO,
721
-            )),
722
-            array(
723
-                'input_id'       => 'country',
724
-                'input_name'     => 'country',
725
-                'input_prefix'   => '',
726
-                'append_qstn_id' => false,
727
-            )
728
-        );
729
-
730
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
731
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
732
-        $this->_template_args['country_details_settings'] = $this->display_country_settings();
733
-        $this->_template_args['country_states_settings']  = $this->display_country_states();
734
-
735
-        $this->_set_add_edit_form_tags('update_country_settings');
736
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
737
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
738
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
739
-            $this->_template_args,
740
-            true
741
-        );
742
-        $this->display_admin_page_with_no_sidebar();
743
-    }
744
-
745
-
746
-    /**
747
-     *        display_country_settings
748
-     *
749
-     * @access    public
750
-     * @param    string $CNT_ISO
751
-     * @return mixed string | array
752
-     * @throws DomainException
753
-     */
754
-    public function display_country_settings($CNT_ISO = '')
755
-    {
756
-
757
-        $CNT_ISO = isset($this->_req_data['country'])
758
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
759
-            : $CNT_ISO;
760
-        if (! $CNT_ISO) {
761
-            return '';
762
-        }
763
-
764
-        // for ajax
765
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
766
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
767
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
768
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
769
-        $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
770
-
771
-        $country_input_types            = array(
772
-            'CNT_active'      => array(
773
-                'type'             => 'RADIO_BTN',
774
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
775
-                'class'            => '',
776
-                'options'          => $this->_yes_no_values,
777
-                'use_desc_4_label' => true,
778
-            ),
779
-            'CNT_ISO'         => array(
780
-                'type'       => 'TEXT',
781
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
782
-                'class'      => 'small-text',
783
-            ),
784
-            'CNT_ISO3'        => array(
785
-                'type'       => 'TEXT',
786
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
787
-                'class'      => 'small-text',
788
-            ),
789
-            'RGN_ID'          => array(
790
-                'type'       => 'TEXT',
791
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
792
-                'class'      => 'small-text',
793
-            ),
794
-            'CNT_name'        => array(
795
-                'type'       => 'TEXT',
796
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
797
-                'class'      => 'regular-text',
798
-            ),
799
-            'CNT_cur_code'    => array(
800
-                'type'       => 'TEXT',
801
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
802
-                'class'      => 'small-text',
803
-            ),
804
-            'CNT_cur_single'  => array(
805
-                'type'       => 'TEXT',
806
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
807
-                'class'      => 'medium-text',
808
-            ),
809
-            'CNT_cur_plural'  => array(
810
-                'type'       => 'TEXT',
811
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
812
-                'class'      => 'medium-text',
813
-            ),
814
-            'CNT_cur_sign'    => array(
815
-                'type'         => 'TEXT',
816
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
817
-                'class'        => 'small-text',
818
-                'htmlentities' => false,
819
-            ),
820
-            'CNT_cur_sign_b4' => array(
821
-                'type'             => 'RADIO_BTN',
822
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
823
-                'class'            => '',
824
-                'options'          => $this->_yes_no_values,
825
-                'use_desc_4_label' => true,
826
-            ),
827
-            'CNT_cur_dec_plc' => array(
828
-                'type'       => 'RADIO_BTN',
829
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
830
-                'class'      => '',
831
-                'options'    => array(
832
-                    array('id' => 0, 'text' => ''),
833
-                    array('id' => 1, 'text' => ''),
834
-                    array('id' => 2, 'text' => ''),
835
-                    array('id' => 3, 'text' => ''),
836
-                ),
837
-            ),
838
-            'CNT_cur_dec_mrk' => array(
839
-                'type'             => 'RADIO_BTN',
840
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
841
-                'class'            => '',
842
-                'options'          => array(
843
-                    array(
844
-                        'id'   => ',',
845
-                        'text' => __(', (comma)', 'event_espresso'),
846
-                    ),
847
-                    array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
848
-                ),
849
-                'use_desc_4_label' => true,
850
-            ),
851
-            'CNT_cur_thsnds'  => array(
852
-                'type'             => 'RADIO_BTN',
853
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
854
-                'class'            => '',
855
-                'options'          => array(
856
-                    array(
857
-                        'id'   => ',',
858
-                        'text' => __(', (comma)', 'event_espresso'),
859
-                    ),
860
-                    array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
861
-                ),
862
-                'use_desc_4_label' => true,
863
-            ),
864
-            'CNT_tel_code'    => array(
865
-                'type'       => 'TEXT',
866
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
867
-                'class'      => 'small-text',
868
-            ),
869
-            'CNT_is_EU'       => array(
870
-                'type'             => 'RADIO_BTN',
871
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
872
-                'class'            => '',
873
-                'options'          => $this->_yes_no_values,
874
-                'use_desc_4_label' => true,
875
-            ),
876
-        );
877
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
878
-            $country,
879
-            $country_input_types
880
-        );
881
-        $country_details_settings       = EEH_Template::display_template(
882
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
883
-            $this->_template_args,
884
-            true
885
-        );
886
-
887
-        if (defined('DOING_AJAX')) {
888
-            $notices = EE_Error::get_notices(false, false, false);
889
-            echo wp_json_encode(array(
890
-                'return_data' => $country_details_settings,
891
-                'success'     => $notices['success'],
892
-                'errors'      => $notices['errors'],
893
-            ));
894
-            die();
895
-        } else {
896
-            return $country_details_settings;
897
-        }
898
-    }
899
-
900
-
901
-    /**
902
-     *        display_country_states
903
-     *
904
-     * @access    public
905
-     * @param    string $CNT_ISO
906
-     * @return string
907
-     * @throws DomainException
908
-     */
909
-    public function display_country_states($CNT_ISO = '')
910
-    {
911
-
912
-        $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO;
913
-
914
-        if (! $CNT_ISO) {
915
-            return '';
916
-        }
917
-        // for ajax
918
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
919
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
920
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
921
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
922
-        $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
923
-
924
-        if ($states) {
925
-            foreach ($states as $STA_ID => $state) {
926
-                if ($state instanceof EE_State) {
927
-                    //STA_abbrev 	STA_name 	STA_active
928
-                    $state_input_types                                           = array(
929
-                        'STA_abbrev' => array(
930
-                            'type'       => 'TEXT',
931
-                            'input_name' => 'states[' . $STA_ID . ']',
932
-                            'class'      => 'mid-text',
933
-                        ),
934
-                        'STA_name'   => array(
935
-                            'type'       => 'TEXT',
936
-                            'input_name' => 'states[' . $STA_ID . ']',
937
-                            'class'      => 'regular-text',
938
-                        ),
939
-                        'STA_active' => array(
940
-                            'type'             => 'RADIO_BTN',
941
-                            'input_name'       => 'states[' . $STA_ID . ']',
942
-                            'options'          => $this->_yes_no_values,
943
-                            'use_desc_4_label' => true,
944
-                        ),
945
-                    );
946
-                    $this->_template_args['states'][$STA_ID]['inputs'] =
947
-                        EE_Question_Form_Input::generate_question_form_inputs_for_object(
948
-                            $state,
949
-                            $state_input_types
950
-                        );
951
-                    $query_args                                                  = array(
952
-                        'action'     => 'delete_state',
953
-                        'STA_ID'     => $STA_ID,
954
-                        'CNT_ISO'    => $CNT_ISO,
955
-                        'STA_abbrev' => $state->abbrev(),
956
-                    );
957
-                    $this->_template_args['states'][$STA_ID]['delete_state_url'] =
958
-                        EE_Admin_Page::add_query_args_and_nonce(
959
-                            $query_args,
960
-                            GEN_SET_ADMIN_URL
961
-                        );
962
-                }
963
-            }
964
-        } else {
965
-            $this->_template_args['states'] = false;
966
-        }
967
-
968
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
969
-            array('action' => 'add_new_state'),
970
-            GEN_SET_ADMIN_URL
971
-        );
972
-
973
-        $state_details_settings = EEH_Template::display_template(
974
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
975
-            $this->_template_args,
976
-            true
977
-        );
978
-
979
-        if (defined('DOING_AJAX')) {
980
-            $notices = EE_Error::get_notices(false, false, false);
981
-            echo wp_json_encode(array(
982
-                'return_data' => $state_details_settings,
983
-                'success'     => $notices['success'],
984
-                'errors'      => $notices['errors'],
985
-            ));
986
-            die();
987
-        } else {
988
-            return $state_details_settings;
989
-        }
990
-    }
991
-
992
-
993
-    /**
994
-     *        add_new_state
995
-     *
996
-     * @access    public
997
-     * @return void
998
-     * @throws EE_Error
999
-     */
1000
-    public function add_new_state()
1001
-    {
1002
-
1003
-        $success = true;
1004
-
1005
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
1006
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1007
-            : false;
1008
-        if (! $CNT_ISO) {
1009
-            EE_Error::add_error(
1010
-                __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1011
-                __FILE__,
1012
-                __FUNCTION__,
1013
-                __LINE__
1014
-            );
1015
-            $success = false;
1016
-        }
1017
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1018
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
1019
-            : false;
1020
-        if (! $STA_abbrev) {
1021
-            EE_Error::add_error(
1022
-                __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
1023
-                __FILE__,
1024
-                __FUNCTION__,
1025
-                __LINE__
1026
-            );
1027
-            $success = false;
1028
-        }
1029
-        $STA_name = isset($this->_req_data['STA_name'])
1030
-            ? sanitize_text_field($this->_req_data['STA_name'])
1031
-            : false;
1032
-        if (! $STA_name) {
1033
-            EE_Error::add_error(
1034
-                __('No State name or an invalid State name was received.', 'event_espresso'),
1035
-                __FILE__,
1036
-                __FUNCTION__,
1037
-                __LINE__
1038
-            );
1039
-            $success = false;
1040
-        }
1041
-
1042
-        if ($success) {
1043
-            $cols_n_values = array(
1044
-                'CNT_ISO'    => $CNT_ISO,
1045
-                'STA_abbrev' => $STA_abbrev,
1046
-                'STA_name'   => $STA_name,
1047
-                'STA_active' => true,
1048
-            );
1049
-            $success       = EEM_State::instance()->insert($cols_n_values);
1050
-            EE_Error::add_success(__('The State was added successfully.', 'event_espresso'));
1051
-        }
1052
-
1053
-        if (defined('DOING_AJAX')) {
1054
-            $notices = EE_Error::get_notices(false, false, false);
1055
-            echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
1056
-            die();
1057
-        } else {
1058
-            $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
1059
-        }
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     *        delete_state
1065
-     *
1066
-     * @access    public
1067
-     * @return        boolean
1068
-     */
1069
-    public function delete_state()
1070
-    {
1071
-        $CNT_ISO    = isset($this->_req_data['CNT_ISO'])
1072
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1073
-            : false;
1074
-        $STA_ID     = isset($this->_req_data['STA_ID'])
1075
-            ? sanitize_text_field($this->_req_data['STA_ID'])
1076
-            : false;
1077
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1078
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
1079
-            : false;
1080
-        if (! $STA_ID) {
1081
-            EE_Error::add_error(
1082
-                __('No State ID or an invalid State ID was received.', 'event_espresso'),
1083
-                __FILE__,
1084
-                __FUNCTION__,
1085
-                __LINE__
1086
-            );
1087
-            return false;
1088
-        }
1089
-
1090
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
1091
-        if ($success !== false) {
1092
-            do_action(
1093
-                'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1094
-                $CNT_ISO,
1095
-                $STA_ID,
1096
-                array('STA_abbrev' => $STA_abbrev)
1097
-            );
1098
-            EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso'));
1099
-        }
1100
-        if (defined('DOING_AJAX')) {
1101
-            $notices                = EE_Error::get_notices(false, false);
1102
-            $notices['return_data'] = true;
1103
-            echo wp_json_encode($notices);
1104
-            die();
1105
-        } else {
1106
-            $this->_redirect_after_action(
1107
-                $success,
1108
-                'State',
1109
-                'deleted',
1110
-                array('action' => 'country_settings')
1111
-            );
1112
-        }
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     *        _update_country_settings
1118
-     *
1119
-     * @access    protected
1120
-     * @return void
1121
-     * @throws EE_Error
1122
-     */
1123
-    protected function _update_country_settings()
1124
-    {
1125
-        // grab the country ISO code
1126
-        $CNT_ISO = isset($this->_req_data['country'])
1127
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
1128
-            : false;
1129
-        if (! $CNT_ISO) {
1130
-            EE_Error::add_error(
1131
-                __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1132
-                __FILE__,
1133
-                __FUNCTION__,
1134
-                __LINE__
1135
-            );
1136
-
1137
-            return;
1138
-        }
1139
-        $cols_n_values                    = array();
1140
-        $cols_n_values['CNT_ISO3']        = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])
1141
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']))
1142
-            : false;
1143
-        $cols_n_values['RGN_ID']          = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1144
-            ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1145
-            : null;
1146
-        $cols_n_values['CNT_name']        = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1147
-            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1148
-            : null;
1149
-        $cols_n_values['CNT_cur_code']    = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])
1150
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']))
1151
-            : 'USD';
1152
-        $cols_n_values['CNT_cur_single']  = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])
1153
-            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])
1154
-            : 'dollar';
1155
-        $cols_n_values['CNT_cur_plural']  = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])
1156
-            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])
1157
-            : 'dollars';
1158
-        $cols_n_values['CNT_cur_sign']    = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])
1159
-            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])
1160
-            : '$';
1161
-        $cols_n_values['CNT_cur_sign_b4'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])
1162
-            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])
1163
-            : true;
1164
-        $cols_n_values['CNT_cur_dec_plc'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])
1165
-            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])
1166
-            : 2;
1167
-        $cols_n_values['CNT_cur_dec_mrk'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])
1168
-            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])
1169
-            : '.';
1170
-        $cols_n_values['CNT_cur_thsnds']  = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])
1171
-            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])
1172
-            : ',';
1173
-        $cols_n_values['CNT_tel_code']    = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1174
-            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1175
-            : null;
1176
-        $cols_n_values['CNT_is_EU']       = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1177
-            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1178
-            : false;
1179
-        $cols_n_values['CNT_active']      = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1180
-            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1181
-            : false;
1182
-        // allow filtering of country data
1183
-        $cols_n_values = apply_filters(
1184
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1185
-            $cols_n_values
1186
-        );
1187
-
1188
-        // where values
1189
-        $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1190
-        // run the update
1191
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1192
-
1193
-        if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1194
-            // allow filtering of states data
1195
-            $states = apply_filters(
1196
-                'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1197
-                $this->_req_data['states']
1198
-            );
1199
-
1200
-            // loop thru state data ( looks like : states[75][STA_name] )
1201
-            foreach ($states as $STA_ID => $state) {
1202
-                $cols_n_values = array(
1203
-                    'CNT_ISO'    => $CNT_ISO,
1204
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1205
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1206
-                    'STA_active' => (bool)absint($state['STA_active']),
1207
-                );
1208
-                // where values
1209
-                $where_cols_n_values = array(array('STA_ID' => $STA_ID));
1210
-                // run the update
1211
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1212
-                if ($success !== false) {
1213
-                    do_action(
1214
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1215
-                        $CNT_ISO,
1216
-                        $STA_ID,
1217
-                        $cols_n_values
1218
-                    );
1219
-                }
1220
-            }
1221
-        }
1222
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1223
-        if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1224
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1225
-        ) {
1226
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1227
-            EE_Registry::instance()->CFG->update_espresso_config();
1228
-        }
1229
-
1230
-        if ($success !== false) {
1231
-            EE_Error::add_success(
1232
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1233
-            );
1234
-        }
1235
-        $this->_redirect_after_action(
1236
-            $success,
1237
-            '',
1238
-            '',
1239
-            array('action' => 'country_settings', 'country' => $CNT_ISO),
1240
-            true
1241
-        );
1242
-    }
1243
-
1244
-
1245
-    /**
1246
-     *        form_form_field_label_wrap
1247
-     *
1248
-     * @access        public
1249
-     * @param        string $label
1250
-     * @return        string
1251
-     */
1252
-    public function country_form_field_label_wrap($label, $required_text)
1253
-    {
1254
-        return '
20
+	/**
21
+	 * _question_group
22
+	 * holds the specific question group object for the question group details screen
23
+	 *
24
+	 * @var object
25
+	 */
26
+	protected $_question_group;
27
+
28
+
29
+	/**
30
+	 * Initialize basic properties.
31
+	 */
32
+	protected function _init_page_props()
33
+	{
34
+		$this->page_slug        = GEN_SET_PG_SLUG;
35
+		$this->page_label       = GEN_SET_LABEL;
36
+		$this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
+		$this->_admin_base_path = GEN_SET_ADMIN;
38
+	}
39
+
40
+
41
+	/**
42
+	 * Set ajax hooks
43
+	 */
44
+	protected function _ajax_hooks()
45
+	{
46
+		add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
47
+		add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
48
+		add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
49
+		add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
50
+	}
51
+
52
+
53
+	/**
54
+	 * More page properties initialization.
55
+	 */
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = GEN_SET_LABEL;
59
+		$this->_labels           = array(
60
+			'publishbox' => __('Update Settings', 'event_espresso'),
61
+		);
62
+	}
63
+
64
+
65
+	/**
66
+	 * Set page routes property.
67
+	 */
68
+	protected function _set_page_routes()
69
+	{
70
+		$this->_page_routes = array(
71
+
72
+			'critical_pages'                => array(
73
+				'func'       => '_espresso_page_settings',
74
+				'capability' => 'manage_options',
75
+			),
76
+			'update_espresso_page_settings' => array(
77
+				'func'       => '_update_espresso_page_settings',
78
+				'capability' => 'manage_options',
79
+				'noheader'   => true,
80
+			),
81
+			'default'                       => array(
82
+				'func'       => '_your_organization_settings',
83
+				'capability' => 'manage_options',
84
+			),
85
+
86
+			'update_your_organization_settings' => array(
87
+				'func'       => '_update_your_organization_settings',
88
+				'capability' => 'manage_options',
89
+				'noheader'   => true,
90
+			),
91
+
92
+			'admin_option_settings' => array(
93
+				'func'       => '_admin_option_settings',
94
+				'capability' => 'manage_options',
95
+			),
96
+
97
+			'update_admin_option_settings' => array(
98
+				'func'       => '_update_admin_option_settings',
99
+				'capability' => 'manage_options',
100
+				'noheader'   => true,
101
+			),
102
+
103
+			'country_settings' => array(
104
+				'func'       => '_country_settings',
105
+				'capability' => 'manage_options',
106
+			),
107
+
108
+			'update_country_settings' => array(
109
+				'func'       => '_update_country_settings',
110
+				'capability' => 'manage_options',
111
+				'noheader'   => true,
112
+			),
113
+
114
+			'display_country_settings' => array(
115
+				'func'       => 'display_country_settings',
116
+				'capability' => 'manage_options',
117
+				'noheader'   => true,
118
+			),
119
+
120
+			'add_new_state' => array(
121
+				'func'       => 'add_new_state',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			),
125
+
126
+			'delete_state' => array(
127
+				'func'       => 'delete_state',
128
+				'capability' => 'manage_options',
129
+				'noheader'   => true,
130
+			),
131
+		);
132
+	}
133
+
134
+
135
+	/**
136
+	 * Set page configuration property
137
+	 */
138
+	protected function _set_page_config()
139
+	{
140
+		$this->_page_config = array(
141
+			'critical_pages'        => array(
142
+				'nav'           => array(
143
+					'label' => __('Critical Pages', 'event_espresso'),
144
+					'order' => 50,
145
+				),
146
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
147
+				'help_tabs'     => array(
148
+					'general_settings_critical_pages_help_tab' => array(
149
+						'title'    => __('Critical Pages', 'event_espresso'),
150
+						'filename' => 'general_settings_critical_pages',
151
+					),
152
+				),
153
+				'help_tour'     => array('Critical_Pages_Help_Tour'),
154
+				'require_nonce' => false,
155
+			),
156
+			'default'               => array(
157
+				'nav'           => array(
158
+					'label' => __('Your Organization', 'event_espresso'),
159
+					'order' => 20,
160
+				),
161
+				'help_tabs'     => array(
162
+					'general_settings_your_organization_help_tab' => array(
163
+						'title'    => __('Your Organization', 'event_espresso'),
164
+						'filename' => 'general_settings_your_organization',
165
+					),
166
+				),
167
+				'help_tour'     => array('Your_Organization_Help_Tour'),
168
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
+				'require_nonce' => false,
170
+			),
171
+			'admin_option_settings' => array(
172
+				'nav'           => array(
173
+					'label' => __('Admin Options', 'event_espresso'),
174
+					'order' => 60,
175
+				),
176
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
177
+				'help_tabs'     => array(
178
+					'general_settings_admin_options_help_tab' => array(
179
+						'title'    => __('Admin Options', 'event_espresso'),
180
+						'filename' => 'general_settings_admin_options',
181
+					),
182
+				),
183
+				'help_tour'     => array('Admin_Options_Help_Tour'),
184
+				'require_nonce' => false,
185
+			),
186
+			'country_settings'      => array(
187
+				'nav'           => array(
188
+					'label' => __('Countries', 'event_espresso'),
189
+					'order' => 70,
190
+				),
191
+				'help_tabs'     => array(
192
+					'general_settings_countries_help_tab' => array(
193
+						'title'    => __('Countries', 'event_espresso'),
194
+						'filename' => 'general_settings_countries',
195
+					),
196
+				),
197
+				'help_tour'     => array('Countries_Help_Tour'),
198
+				'require_nonce' => false,
199
+			),
200
+		);
201
+	}
202
+
203
+
204
+
205
+	protected function _add_screen_options()
206
+	{
207
+	}
208
+
209
+	protected function _add_feature_pointers()
210
+	{
211
+	}
212
+
213
+
214
+	/**
215
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
216
+	 */
217
+	public function load_scripts_styles()
218
+	{
219
+		//styles
220
+		wp_enqueue_style('espresso-ui-theme');
221
+		//scripts
222
+		wp_enqueue_script('ee_admin_js');
223
+	}
224
+
225
+
226
+	/**
227
+	 * Execute logic running on `admin_init`
228
+	 */
229
+	public function admin_init()
230
+	{
231
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = __(
232
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
233
+			'event_espresso'
234
+		);
235
+		EE_Registry::$i18n_js_strings['error_occurred']          = __(
236
+			'An error occurred! Please refresh the page and try again.',
237
+			'event_espresso'
238
+		);
239
+		EE_Registry::$i18n_js_strings['confirm_delete_state']    = __(
240
+			'Are you sure you want to delete this State / Province?',
241
+			'event_espresso'
242
+		);
243
+		$protocol                                                = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
244
+		EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
245
+			'admin-ajax.php?page=espresso_general_settings',
246
+			$protocol
247
+		);
248
+	}
249
+
250
+	public function admin_notices()
251
+	{
252
+	}
253
+
254
+	public function admin_footer_scripts()
255
+	{
256
+	}
257
+
258
+
259
+	/**
260
+	 * Enqueue scripts and styles for the default route.
261
+	 */
262
+	public function load_scripts_styles_default()
263
+	{
264
+		//styles
265
+		wp_enqueue_style('thickbox');
266
+		//scripts
267
+		wp_enqueue_script('media-upload');
268
+		wp_enqueue_script('thickbox');
269
+		wp_register_script(
270
+			'organization_settings',
271
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
272
+			array('jquery', 'media-upload', 'thickbox'),
273
+			EVENT_ESPRESSO_VERSION,
274
+			true
275
+		);
276
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
277
+		wp_enqueue_script('organization_settings');
278
+		wp_enqueue_style('organization-css');
279
+		$confirm_image_delete = array(
280
+			'text' => __(
281
+				'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
282
+				'event_espresso'
283
+			),
284
+		);
285
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
286
+	}
287
+
288
+
289
+	/**
290
+	 * Enqueue scripts and styles for the country settings route.
291
+	 */
292
+	public function load_scripts_styles_country_settings()
293
+	{
294
+		//scripts
295
+		wp_register_script(
296
+			'gen_settings_countries',
297
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
298
+			array('ee_admin_js'),
299
+			EVENT_ESPRESSO_VERSION,
300
+			true
301
+		);
302
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
303
+		wp_enqueue_script('gen_settings_countries');
304
+		wp_enqueue_style('organization-css');
305
+	}
306
+
307
+
308
+	/*************        Espresso Pages        *************/
309
+	/**
310
+	 * _espresso_page_settings
311
+	 *
312
+	 * @throws \EE_Error
313
+	 */
314
+	protected function _espresso_page_settings()
315
+	{
316
+		// Check to make sure all of the main pages are setup properly,
317
+		// if not create the default pages and display an admin notice
318
+		EEH_Activation::verify_default_pages_exist();
319
+		$this->_transient_garbage_collection();
320
+		$this->_template_args['values']             = $this->_yes_no_values;
321
+		$this->_template_args['reg_page_id']        = isset(EE_Registry::instance()->CFG->core->reg_page_id)
322
+			? EE_Registry::instance()->CFG->core->reg_page_id
323
+			: null;
324
+		$this->_template_args['reg_page_obj']       = isset(EE_Registry::instance()->CFG->core->reg_page_id)
325
+			? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
326
+			: false;
327
+		$this->_template_args['txn_page_id']        = isset(EE_Registry::instance()->CFG->core->txn_page_id)
328
+			? EE_Registry::instance()->CFG->core->txn_page_id
329
+			: null;
330
+		$this->_template_args['txn_page_obj']       = isset(EE_Registry::instance()->CFG->core->txn_page_id)
331
+			? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
332
+			: false;
333
+		$this->_template_args['thank_you_page_id']  = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
334
+			? EE_Registry::instance()->CFG->core->thank_you_page_id
335
+			: null;
336
+		$this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
337
+			? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
338
+			: false;
339
+		$this->_template_args['cancel_page_id']     = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
340
+			? EE_Registry::instance()->CFG->core->cancel_page_id
341
+			: null;
342
+		$this->_template_args['cancel_page_obj']    = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
343
+			? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
344
+			: false;
345
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
346
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
347
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
348
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
349
+			$this->_template_args,
350
+			true
351
+		);
352
+		$this->display_admin_page_with_sidebar();
353
+	}
354
+
355
+
356
+	/**
357
+	 * Handler for updating espresso page settings.
358
+	 */
359
+	protected function _update_espresso_page_settings()
360
+	{
361
+		// capture incoming request data && set page IDs
362
+		EE_Registry::instance()->CFG->core->reg_page_id       = isset($this->_req_data['reg_page_id'])
363
+			? absint($this->_req_data['reg_page_id'])
364
+			: EE_Registry::instance()->CFG->core->reg_page_id;
365
+		EE_Registry::instance()->CFG->core->txn_page_id       = isset($this->_req_data['txn_page_id'])
366
+			? absint($this->_req_data['txn_page_id'])
367
+			: EE_Registry::instance()->CFG->core->txn_page_id;
368
+		EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
369
+			? absint($this->_req_data['thank_you_page_id'])
370
+			: EE_Registry::instance()->CFG->core->thank_you_page_id;
371
+		EE_Registry::instance()->CFG->core->cancel_page_id    = isset($this->_req_data['cancel_page_id'])
372
+			? absint($this->_req_data['cancel_page_id'])
373
+			: EE_Registry::instance()->CFG->core->cancel_page_id;
374
+
375
+		EE_Registry::instance()->CFG->core = apply_filters(
376
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
377
+			EE_Registry::instance()->CFG->core,
378
+			$this->_req_data
379
+		);
380
+		$what                              = __('Critical Pages & Shortcodes', 'event_espresso');
381
+		$this->_redirect_after_action(
382
+			$this->_update_espresso_configuration(
383
+				$what,
384
+				EE_Registry::instance()->CFG->core,
385
+				__FILE__,
386
+				__FUNCTION__,
387
+				__LINE__
388
+			),
389
+			$what,
390
+			'',
391
+			array(
392
+				'action' => 'critical_pages',
393
+			),
394
+			true
395
+		);
396
+	}
397
+
398
+
399
+	/*************        Your Organization        *************/
400
+
401
+
402
+	/**
403
+	 * Output for the Your Organization settings route.
404
+	 * @throws DomainException
405
+	 * @throws EE_Error
406
+	 */
407
+	protected function _your_organization_settings()
408
+	{
409
+
410
+		$this->_template_args['site_license_key']       = isset(
411
+			EE_Registry::instance()->NET_CFG->core->site_license_key
412
+		)
413
+			? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key')
414
+			: '';
415
+		$this->_template_args['organization_name']      = isset(EE_Registry::instance()->CFG->organization->name)
416
+			? EE_Registry::instance()->CFG->organization->get_pretty('name')
417
+			: '';
418
+		$this->_template_args['organization_address_1'] = isset(EE_Registry::instance()->CFG->organization->address_1)
419
+			? EE_Registry::instance()->CFG->organization->get_pretty('address_1')
420
+			: '';
421
+		$this->_template_args['organization_address_2'] = isset(EE_Registry::instance()->CFG->organization->address_2)
422
+			? EE_Registry::instance()->CFG->organization->get_pretty('address_2')
423
+			: '';
424
+		$this->_template_args['organization_city']      = isset(EE_Registry::instance()->CFG->organization->city)
425
+			? EE_Registry::instance()->CFG->organization->get_pretty('city')
426
+			: '';
427
+		$this->_template_args['organization_zip']       = isset(EE_Registry::instance()->CFG->organization->zip)
428
+			? EE_Registry::instance()->CFG->organization->get_pretty('zip')
429
+			: '';
430
+		$this->_template_args['organization_email']     = isset(EE_Registry::instance()->CFG->organization->email)
431
+			? EE_Registry::instance()->CFG->organization->get_pretty('email')
432
+			: '';
433
+		$this->_template_args['organization_phone']     = isset(EE_Registry::instance()->CFG->organization->phone)
434
+			? EE_Registry::instance()->CFG->organization->get_pretty('phone')
435
+			: '';
436
+		$this->_template_args['organization_vat']       = isset(EE_Registry::instance()->CFG->organization->vat)
437
+			? EE_Registry::instance()->CFG->organization->get_pretty('vat')
438
+			: '';
439
+		$this->_template_args['currency_sign']          = isset(EE_Registry::instance()->CFG->currency->sign)
440
+			? EE_Registry::instance()->CFG->currency->get_pretty('sign')
441
+			: '$';
442
+		$this->_template_args['organization_logo_url']  = isset(EE_Registry::instance()->CFG->organization->logo_url)
443
+			? EE_Registry::instance()->CFG->organization->get_pretty('logo_url')
444
+			: false;
445
+		$this->_template_args['organization_facebook']  = isset(EE_Registry::instance()->CFG->organization->facebook)
446
+			? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
447
+			: '';
448
+		$this->_template_args['organization_twitter']   = isset(EE_Registry::instance()->CFG->organization->twitter)
449
+			? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
450
+			: '';
451
+		$this->_template_args['organization_linkedin']  = isset(EE_Registry::instance()->CFG->organization->linkedin)
452
+			? EE_Registry::instance()->CFG->organization->get_pretty('linkedin')
453
+			: '';
454
+		$this->_template_args['organization_pinterest'] = isset(EE_Registry::instance()->CFG->organization->pinterest)
455
+			? EE_Registry::instance()->CFG->organization->get_pretty('pinterest')
456
+			: '';
457
+		$this->_template_args['organization_google']    = isset(EE_Registry::instance()->CFG->organization->google)
458
+			? EE_Registry::instance()->CFG->organization->get_pretty('google')
459
+			: '';
460
+		$this->_template_args['organization_instagram'] = isset(EE_Registry::instance()->CFG->organization->instagram)
461
+			? EE_Registry::instance()->CFG->organization->get_pretty('instagram')
462
+			: '';
463
+		//UXIP settings
464
+		$this->_template_args['ee_ueip_optin'] = isset(EE_Registry::instance()->CFG->core->ee_ueip_optin)
465
+			? EE_Registry::instance()->CFG->core->get_pretty('ee_ueip_optin')
466
+			: true;
467
+
468
+		$STA_ID                         = isset(EE_Registry::instance()->CFG->organization->STA_ID)
469
+			? EE_Registry::instance()->CFG->organization->STA_ID
470
+			: 4;
471
+		$this->_template_args['states'] = new EE_Question_Form_Input(
472
+			EE_Question::new_instance(array(
473
+				'QST_ID'           => 0,
474
+				'QST_display_text' => __('State/Province', 'event_espresso'),
475
+				'QST_system'       => 'admin-state',
476
+			)),
477
+			EE_Answer::new_instance(array(
478
+				'ANS_ID'    => 0,
479
+				'ANS_value' => $STA_ID,
480
+			)),
481
+			array(
482
+				'input_id'       => 'organization_state',
483
+				'input_name'     => 'organization_state',
484
+				'input_prefix'   => '',
485
+				'append_qstn_id' => false,
486
+			)
487
+		);
488
+
489
+		$CNT_ISO                           = isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
490
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
491
+			: 'US';
492
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
493
+			EE_Question::new_instance(array(
494
+				'QST_ID'           => 0,
495
+				'QST_display_text' => __('Country', 'event_espresso'),
496
+				'QST_system'       => 'admin-country',
497
+			)),
498
+			EE_Answer::new_instance(array(
499
+				'ANS_ID'    => 0,
500
+				'ANS_value' => $CNT_ISO,
501
+			)),
502
+			array(
503
+				'input_id'       => 'organization_country',
504
+				'input_name'     => 'organization_country',
505
+				'input_prefix'   => '',
506
+				'append_qstn_id' => false,
507
+			)
508
+		);
509
+
510
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
511
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
512
+
513
+		//PUE verification stuff
514
+		$ver_option_key                                    = 'puvererr_' . basename(EE_PLUGIN_BASENAME);
515
+		$verify_fail                                       = get_option($ver_option_key);
516
+		$this->_template_args['site_license_key_verified'] = $verify_fail
517
+															 || ! empty($verify_fail)
518
+															 || (empty($this->_template_args['site_license_key'])
519
+																 && empty($verify_fail)
520
+															 )
521
+			? '<span class="dashicons dashicons-admin-network ee-icon-color-ee-red ee-icon-size-20"></span>'
522
+			: '<span class="dashicons dashicons-admin-network ee-icon-color-ee-green ee-icon-size-20"></span>';
523
+
524
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
525
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
526
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
527
+			GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php',
528
+			$this->_template_args,
529
+			true
530
+		);
531
+
532
+		$this->display_admin_page_with_sidebar();
533
+	}
534
+
535
+
536
+	/**
537
+	 * Handler for updating organziation settings.
538
+	 */
539
+	protected function _update_your_organization_settings()
540
+	{
541
+		if (is_main_site()) {
542
+			EE_Registry::instance()->NET_CFG->core->site_license_key = isset($this->_req_data['site_license_key'])
543
+				? sanitize_text_field($this->_req_data['site_license_key'])
544
+				: EE_Registry::instance()->NET_CFG->core->site_license_key;
545
+		}
546
+		EE_Registry::instance()->CFG->organization->name      = isset($this->_req_data['organization_name'])
547
+			? sanitize_text_field($this->_req_data['organization_name'])
548
+			: EE_Registry::instance()->CFG->organization->name;
549
+		EE_Registry::instance()->CFG->organization->address_1 = isset($this->_req_data['organization_address_1'])
550
+			? sanitize_text_field($this->_req_data['organization_address_1'])
551
+			: EE_Registry::instance()->CFG->organization->address_1;
552
+		EE_Registry::instance()->CFG->organization->address_2 = isset($this->_req_data['organization_address_2'])
553
+			? sanitize_text_field($this->_req_data['organization_address_2'])
554
+			: EE_Registry::instance()->CFG->organization->address_2;
555
+		EE_Registry::instance()->CFG->organization->city      = isset($this->_req_data['organization_city'])
556
+			? sanitize_text_field($this->_req_data['organization_city'])
557
+			: EE_Registry::instance()->CFG->organization->city;
558
+		EE_Registry::instance()->CFG->organization->STA_ID    = isset($this->_req_data['organization_state'])
559
+			? absint($this->_req_data['organization_state'])
560
+			: EE_Registry::instance()->CFG->organization->STA_ID;
561
+		EE_Registry::instance()->CFG->organization->CNT_ISO   = isset($this->_req_data['organization_country'])
562
+			? sanitize_text_field($this->_req_data['organization_country'])
563
+			: EE_Registry::instance()->CFG->organization->CNT_ISO;
564
+		EE_Registry::instance()->CFG->organization->zip       = isset($this->_req_data['organization_zip'])
565
+			? sanitize_text_field($this->_req_data['organization_zip'])
566
+			: EE_Registry::instance()->CFG->organization->zip;
567
+		EE_Registry::instance()->CFG->organization->email     = isset($this->_req_data['organization_email'])
568
+			? sanitize_email($this->_req_data['organization_email'])
569
+			: EE_Registry::instance()->CFG->organization->email;
570
+		EE_Registry::instance()->CFG->organization->vat       = isset($this->_req_data['organization_vat'])
571
+			? sanitize_text_field($this->_req_data['organization_vat'])
572
+			: EE_Registry::instance()->CFG->organization->vat;
573
+		EE_Registry::instance()->CFG->organization->phone     = isset($this->_req_data['organization_phone'])
574
+			? sanitize_text_field($this->_req_data['organization_phone'])
575
+			: EE_Registry::instance()->CFG->organization->phone;
576
+		EE_Registry::instance()->CFG->organization->logo_url  = isset($this->_req_data['organization_logo_url'])
577
+			? esc_url_raw($this->_req_data['organization_logo_url'])
578
+			: EE_Registry::instance()->CFG->organization->logo_url;
579
+		EE_Registry::instance()->CFG->organization->facebook  = isset($this->_req_data['organization_facebook'])
580
+			? esc_url_raw($this->_req_data['organization_facebook'])
581
+			: EE_Registry::instance()->CFG->organization->facebook;
582
+		EE_Registry::instance()->CFG->organization->twitter   = isset($this->_req_data['organization_twitter'])
583
+			? esc_url_raw($this->_req_data['organization_twitter'])
584
+			: EE_Registry::instance()->CFG->organization->twitter;
585
+		EE_Registry::instance()->CFG->organization->linkedin  = isset($this->_req_data['organization_linkedin'])
586
+			? esc_url_raw($this->_req_data['organization_linkedin'])
587
+			: EE_Registry::instance()->CFG->organization->linkedin;
588
+		EE_Registry::instance()->CFG->organization->pinterest = isset($this->_req_data['organization_pinterest'])
589
+			? esc_url_raw($this->_req_data['organization_pinterest'])
590
+			: EE_Registry::instance()->CFG->organization->pinterest;
591
+		EE_Registry::instance()->CFG->organization->google    = isset($this->_req_data['organization_google'])
592
+			? esc_url_raw($this->_req_data['organization_google'])
593
+			: EE_Registry::instance()->CFG->organization->google;
594
+		EE_Registry::instance()->CFG->organization->instagram = isset($this->_req_data['organization_instagram'])
595
+			? esc_url_raw($this->_req_data['organization_instagram'])
596
+			: EE_Registry::instance()->CFG->organization->instagram;
597
+		EE_Registry::instance()->CFG->core->ee_ueip_optin     = isset($this->_req_data['ueip_optin'])
598
+																&& ! empty($this->_req_data['ueip_optin'])
599
+			? $this->_req_data['ueip_optin']
600
+			: EE_Registry::instance()->CFG->core->ee_ueip_optin;
601
+
602
+		EE_Registry::instance()->CFG->currency = new EE_Currency_Config(
603
+			EE_Registry::instance()->CFG->organization->CNT_ISO
604
+		);
605
+
606
+		EE_Registry::instance()->CFG = apply_filters(
607
+			'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
608
+			EE_Registry::instance()->CFG
609
+		);
610
+
611
+		$what    = 'Your Organization Settings';
612
+		$success = $this->_update_espresso_configuration(
613
+			$what,
614
+			EE_Registry::instance()->CFG,
615
+			__FILE__,
616
+			__FUNCTION__,
617
+			__LINE__
618
+		);
619
+
620
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'default'));
621
+	}
622
+
623
+
624
+
625
+	/*************        Admin Options        *************/
626
+
627
+
628
+	/**
629
+	 * _admin_option_settings
630
+	 *
631
+	 * @throws \EE_Error
632
+	 * @throws \LogicException
633
+	 */
634
+	protected function _admin_option_settings()
635
+	{
636
+		$this->_template_args['admin_page_content'] = '';
637
+		try {
638
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
639
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
640
+			$this->_template_args['values'] = $this->_yes_no_values;
641
+			// also need to account for the do_action that was in the old template
642
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
643
+			$this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
644
+		} catch (Exception $e) {
645
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
646
+		}
647
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
648
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
649
+		$this->display_admin_page_with_sidebar();
650
+	}
651
+
652
+
653
+	/**
654
+	 * _update_admin_option_settings
655
+	 *
656
+	 * @throws \EE_Error
657
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
658
+	 * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
659
+	 * @throws \InvalidArgumentException
660
+	 * @throws \LogicException
661
+	 */
662
+	protected function _update_admin_option_settings()
663
+	{
664
+		try {
665
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
666
+			$admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]);
667
+			EE_Registry::instance()->CFG->admin = apply_filters(
668
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
669
+				EE_Registry::instance()->CFG->admin
670
+			);
671
+		} catch (Exception $e) {
672
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
673
+		}
674
+		$this->_redirect_after_action(
675
+			apply_filters(
676
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
677
+				$this->_update_espresso_configuration(
678
+					'Admin Options',
679
+					EE_Registry::instance()->CFG->admin,
680
+					__FILE__, __FUNCTION__, __LINE__
681
+				)
682
+			),
683
+			'Admin Options',
684
+			'updated',
685
+			array('action' => 'admin_option_settings')
686
+		);
687
+
688
+	}
689
+
690
+
691
+	/*************        Countries        *************/
692
+
693
+
694
+	/**
695
+	 * Output Country Settings view.
696
+	 * @throws DomainException
697
+	 * @throws EE_Error
698
+	 */
699
+	protected function _country_settings()
700
+	{
701
+		$CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
702
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
703
+			: 'US';
704
+		$CNT_ISO = isset($this->_req_data['country'])
705
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
706
+			: $CNT_ISO;
707
+
708
+		//load field generator helper
709
+
710
+		$this->_template_args['values'] = $this->_yes_no_values;
711
+
712
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
713
+			EE_Question::new_instance(array(
714
+				'QST_ID'           => 0,
715
+				'QST_display_text' => __('Select Country', 'event_espresso'),
716
+				'QST_system'       => 'admin-country',
717
+			)),
718
+			EE_Answer::new_instance(array(
719
+				'ANS_ID'    => 0,
720
+				'ANS_value' => $CNT_ISO,
721
+			)),
722
+			array(
723
+				'input_id'       => 'country',
724
+				'input_name'     => 'country',
725
+				'input_prefix'   => '',
726
+				'append_qstn_id' => false,
727
+			)
728
+		);
729
+
730
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
731
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
732
+		$this->_template_args['country_details_settings'] = $this->display_country_settings();
733
+		$this->_template_args['country_states_settings']  = $this->display_country_states();
734
+
735
+		$this->_set_add_edit_form_tags('update_country_settings');
736
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
737
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
738
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
739
+			$this->_template_args,
740
+			true
741
+		);
742
+		$this->display_admin_page_with_no_sidebar();
743
+	}
744
+
745
+
746
+	/**
747
+	 *        display_country_settings
748
+	 *
749
+	 * @access    public
750
+	 * @param    string $CNT_ISO
751
+	 * @return mixed string | array
752
+	 * @throws DomainException
753
+	 */
754
+	public function display_country_settings($CNT_ISO = '')
755
+	{
756
+
757
+		$CNT_ISO = isset($this->_req_data['country'])
758
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
759
+			: $CNT_ISO;
760
+		if (! $CNT_ISO) {
761
+			return '';
762
+		}
763
+
764
+		// for ajax
765
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
766
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
767
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
768
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
769
+		$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
770
+
771
+		$country_input_types            = array(
772
+			'CNT_active'      => array(
773
+				'type'             => 'RADIO_BTN',
774
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
775
+				'class'            => '',
776
+				'options'          => $this->_yes_no_values,
777
+				'use_desc_4_label' => true,
778
+			),
779
+			'CNT_ISO'         => array(
780
+				'type'       => 'TEXT',
781
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
782
+				'class'      => 'small-text',
783
+			),
784
+			'CNT_ISO3'        => array(
785
+				'type'       => 'TEXT',
786
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
787
+				'class'      => 'small-text',
788
+			),
789
+			'RGN_ID'          => array(
790
+				'type'       => 'TEXT',
791
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
792
+				'class'      => 'small-text',
793
+			),
794
+			'CNT_name'        => array(
795
+				'type'       => 'TEXT',
796
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
797
+				'class'      => 'regular-text',
798
+			),
799
+			'CNT_cur_code'    => array(
800
+				'type'       => 'TEXT',
801
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
802
+				'class'      => 'small-text',
803
+			),
804
+			'CNT_cur_single'  => array(
805
+				'type'       => 'TEXT',
806
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
807
+				'class'      => 'medium-text',
808
+			),
809
+			'CNT_cur_plural'  => array(
810
+				'type'       => 'TEXT',
811
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
812
+				'class'      => 'medium-text',
813
+			),
814
+			'CNT_cur_sign'    => array(
815
+				'type'         => 'TEXT',
816
+				'input_name'   => 'cntry[' . $CNT_ISO . ']',
817
+				'class'        => 'small-text',
818
+				'htmlentities' => false,
819
+			),
820
+			'CNT_cur_sign_b4' => array(
821
+				'type'             => 'RADIO_BTN',
822
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
823
+				'class'            => '',
824
+				'options'          => $this->_yes_no_values,
825
+				'use_desc_4_label' => true,
826
+			),
827
+			'CNT_cur_dec_plc' => array(
828
+				'type'       => 'RADIO_BTN',
829
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
830
+				'class'      => '',
831
+				'options'    => array(
832
+					array('id' => 0, 'text' => ''),
833
+					array('id' => 1, 'text' => ''),
834
+					array('id' => 2, 'text' => ''),
835
+					array('id' => 3, 'text' => ''),
836
+				),
837
+			),
838
+			'CNT_cur_dec_mrk' => array(
839
+				'type'             => 'RADIO_BTN',
840
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
841
+				'class'            => '',
842
+				'options'          => array(
843
+					array(
844
+						'id'   => ',',
845
+						'text' => __(', (comma)', 'event_espresso'),
846
+					),
847
+					array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
848
+				),
849
+				'use_desc_4_label' => true,
850
+			),
851
+			'CNT_cur_thsnds'  => array(
852
+				'type'             => 'RADIO_BTN',
853
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
854
+				'class'            => '',
855
+				'options'          => array(
856
+					array(
857
+						'id'   => ',',
858
+						'text' => __(', (comma)', 'event_espresso'),
859
+					),
860
+					array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
861
+				),
862
+				'use_desc_4_label' => true,
863
+			),
864
+			'CNT_tel_code'    => array(
865
+				'type'       => 'TEXT',
866
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
867
+				'class'      => 'small-text',
868
+			),
869
+			'CNT_is_EU'       => array(
870
+				'type'             => 'RADIO_BTN',
871
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
872
+				'class'            => '',
873
+				'options'          => $this->_yes_no_values,
874
+				'use_desc_4_label' => true,
875
+			),
876
+		);
877
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
878
+			$country,
879
+			$country_input_types
880
+		);
881
+		$country_details_settings       = EEH_Template::display_template(
882
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
883
+			$this->_template_args,
884
+			true
885
+		);
886
+
887
+		if (defined('DOING_AJAX')) {
888
+			$notices = EE_Error::get_notices(false, false, false);
889
+			echo wp_json_encode(array(
890
+				'return_data' => $country_details_settings,
891
+				'success'     => $notices['success'],
892
+				'errors'      => $notices['errors'],
893
+			));
894
+			die();
895
+		} else {
896
+			return $country_details_settings;
897
+		}
898
+	}
899
+
900
+
901
+	/**
902
+	 *        display_country_states
903
+	 *
904
+	 * @access    public
905
+	 * @param    string $CNT_ISO
906
+	 * @return string
907
+	 * @throws DomainException
908
+	 */
909
+	public function display_country_states($CNT_ISO = '')
910
+	{
911
+
912
+		$CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO;
913
+
914
+		if (! $CNT_ISO) {
915
+			return '';
916
+		}
917
+		// for ajax
918
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
919
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
920
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
921
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
922
+		$states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
923
+
924
+		if ($states) {
925
+			foreach ($states as $STA_ID => $state) {
926
+				if ($state instanceof EE_State) {
927
+					//STA_abbrev 	STA_name 	STA_active
928
+					$state_input_types                                           = array(
929
+						'STA_abbrev' => array(
930
+							'type'       => 'TEXT',
931
+							'input_name' => 'states[' . $STA_ID . ']',
932
+							'class'      => 'mid-text',
933
+						),
934
+						'STA_name'   => array(
935
+							'type'       => 'TEXT',
936
+							'input_name' => 'states[' . $STA_ID . ']',
937
+							'class'      => 'regular-text',
938
+						),
939
+						'STA_active' => array(
940
+							'type'             => 'RADIO_BTN',
941
+							'input_name'       => 'states[' . $STA_ID . ']',
942
+							'options'          => $this->_yes_no_values,
943
+							'use_desc_4_label' => true,
944
+						),
945
+					);
946
+					$this->_template_args['states'][$STA_ID]['inputs'] =
947
+						EE_Question_Form_Input::generate_question_form_inputs_for_object(
948
+							$state,
949
+							$state_input_types
950
+						);
951
+					$query_args                                                  = array(
952
+						'action'     => 'delete_state',
953
+						'STA_ID'     => $STA_ID,
954
+						'CNT_ISO'    => $CNT_ISO,
955
+						'STA_abbrev' => $state->abbrev(),
956
+					);
957
+					$this->_template_args['states'][$STA_ID]['delete_state_url'] =
958
+						EE_Admin_Page::add_query_args_and_nonce(
959
+							$query_args,
960
+							GEN_SET_ADMIN_URL
961
+						);
962
+				}
963
+			}
964
+		} else {
965
+			$this->_template_args['states'] = false;
966
+		}
967
+
968
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
969
+			array('action' => 'add_new_state'),
970
+			GEN_SET_ADMIN_URL
971
+		);
972
+
973
+		$state_details_settings = EEH_Template::display_template(
974
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
975
+			$this->_template_args,
976
+			true
977
+		);
978
+
979
+		if (defined('DOING_AJAX')) {
980
+			$notices = EE_Error::get_notices(false, false, false);
981
+			echo wp_json_encode(array(
982
+				'return_data' => $state_details_settings,
983
+				'success'     => $notices['success'],
984
+				'errors'      => $notices['errors'],
985
+			));
986
+			die();
987
+		} else {
988
+			return $state_details_settings;
989
+		}
990
+	}
991
+
992
+
993
+	/**
994
+	 *        add_new_state
995
+	 *
996
+	 * @access    public
997
+	 * @return void
998
+	 * @throws EE_Error
999
+	 */
1000
+	public function add_new_state()
1001
+	{
1002
+
1003
+		$success = true;
1004
+
1005
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
1006
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1007
+			: false;
1008
+		if (! $CNT_ISO) {
1009
+			EE_Error::add_error(
1010
+				__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1011
+				__FILE__,
1012
+				__FUNCTION__,
1013
+				__LINE__
1014
+			);
1015
+			$success = false;
1016
+		}
1017
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
1018
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
1019
+			: false;
1020
+		if (! $STA_abbrev) {
1021
+			EE_Error::add_error(
1022
+				__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
1023
+				__FILE__,
1024
+				__FUNCTION__,
1025
+				__LINE__
1026
+			);
1027
+			$success = false;
1028
+		}
1029
+		$STA_name = isset($this->_req_data['STA_name'])
1030
+			? sanitize_text_field($this->_req_data['STA_name'])
1031
+			: false;
1032
+		if (! $STA_name) {
1033
+			EE_Error::add_error(
1034
+				__('No State name or an invalid State name was received.', 'event_espresso'),
1035
+				__FILE__,
1036
+				__FUNCTION__,
1037
+				__LINE__
1038
+			);
1039
+			$success = false;
1040
+		}
1041
+
1042
+		if ($success) {
1043
+			$cols_n_values = array(
1044
+				'CNT_ISO'    => $CNT_ISO,
1045
+				'STA_abbrev' => $STA_abbrev,
1046
+				'STA_name'   => $STA_name,
1047
+				'STA_active' => true,
1048
+			);
1049
+			$success       = EEM_State::instance()->insert($cols_n_values);
1050
+			EE_Error::add_success(__('The State was added successfully.', 'event_espresso'));
1051
+		}
1052
+
1053
+		if (defined('DOING_AJAX')) {
1054
+			$notices = EE_Error::get_notices(false, false, false);
1055
+			echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
1056
+			die();
1057
+		} else {
1058
+			$this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
1059
+		}
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 *        delete_state
1065
+	 *
1066
+	 * @access    public
1067
+	 * @return        boolean
1068
+	 */
1069
+	public function delete_state()
1070
+	{
1071
+		$CNT_ISO    = isset($this->_req_data['CNT_ISO'])
1072
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1073
+			: false;
1074
+		$STA_ID     = isset($this->_req_data['STA_ID'])
1075
+			? sanitize_text_field($this->_req_data['STA_ID'])
1076
+			: false;
1077
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
1078
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
1079
+			: false;
1080
+		if (! $STA_ID) {
1081
+			EE_Error::add_error(
1082
+				__('No State ID or an invalid State ID was received.', 'event_espresso'),
1083
+				__FILE__,
1084
+				__FUNCTION__,
1085
+				__LINE__
1086
+			);
1087
+			return false;
1088
+		}
1089
+
1090
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
1091
+		if ($success !== false) {
1092
+			do_action(
1093
+				'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1094
+				$CNT_ISO,
1095
+				$STA_ID,
1096
+				array('STA_abbrev' => $STA_abbrev)
1097
+			);
1098
+			EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso'));
1099
+		}
1100
+		if (defined('DOING_AJAX')) {
1101
+			$notices                = EE_Error::get_notices(false, false);
1102
+			$notices['return_data'] = true;
1103
+			echo wp_json_encode($notices);
1104
+			die();
1105
+		} else {
1106
+			$this->_redirect_after_action(
1107
+				$success,
1108
+				'State',
1109
+				'deleted',
1110
+				array('action' => 'country_settings')
1111
+			);
1112
+		}
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 *        _update_country_settings
1118
+	 *
1119
+	 * @access    protected
1120
+	 * @return void
1121
+	 * @throws EE_Error
1122
+	 */
1123
+	protected function _update_country_settings()
1124
+	{
1125
+		// grab the country ISO code
1126
+		$CNT_ISO = isset($this->_req_data['country'])
1127
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
1128
+			: false;
1129
+		if (! $CNT_ISO) {
1130
+			EE_Error::add_error(
1131
+				__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1132
+				__FILE__,
1133
+				__FUNCTION__,
1134
+				__LINE__
1135
+			);
1136
+
1137
+			return;
1138
+		}
1139
+		$cols_n_values                    = array();
1140
+		$cols_n_values['CNT_ISO3']        = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])
1141
+			? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']))
1142
+			: false;
1143
+		$cols_n_values['RGN_ID']          = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1144
+			? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1145
+			: null;
1146
+		$cols_n_values['CNT_name']        = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1147
+			? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1148
+			: null;
1149
+		$cols_n_values['CNT_cur_code']    = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])
1150
+			? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']))
1151
+			: 'USD';
1152
+		$cols_n_values['CNT_cur_single']  = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])
1153
+			? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])
1154
+			: 'dollar';
1155
+		$cols_n_values['CNT_cur_plural']  = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])
1156
+			? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])
1157
+			: 'dollars';
1158
+		$cols_n_values['CNT_cur_sign']    = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])
1159
+			? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])
1160
+			: '$';
1161
+		$cols_n_values['CNT_cur_sign_b4'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])
1162
+			? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])
1163
+			: true;
1164
+		$cols_n_values['CNT_cur_dec_plc'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])
1165
+			? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])
1166
+			: 2;
1167
+		$cols_n_values['CNT_cur_dec_mrk'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])
1168
+			? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])
1169
+			: '.';
1170
+		$cols_n_values['CNT_cur_thsnds']  = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])
1171
+			? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])
1172
+			: ',';
1173
+		$cols_n_values['CNT_tel_code']    = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1174
+			? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1175
+			: null;
1176
+		$cols_n_values['CNT_is_EU']       = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1177
+			? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1178
+			: false;
1179
+		$cols_n_values['CNT_active']      = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1180
+			? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1181
+			: false;
1182
+		// allow filtering of country data
1183
+		$cols_n_values = apply_filters(
1184
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1185
+			$cols_n_values
1186
+		);
1187
+
1188
+		// where values
1189
+		$where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1190
+		// run the update
1191
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1192
+
1193
+		if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1194
+			// allow filtering of states data
1195
+			$states = apply_filters(
1196
+				'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1197
+				$this->_req_data['states']
1198
+			);
1199
+
1200
+			// loop thru state data ( looks like : states[75][STA_name] )
1201
+			foreach ($states as $STA_ID => $state) {
1202
+				$cols_n_values = array(
1203
+					'CNT_ISO'    => $CNT_ISO,
1204
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1205
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1206
+					'STA_active' => (bool)absint($state['STA_active']),
1207
+				);
1208
+				// where values
1209
+				$where_cols_n_values = array(array('STA_ID' => $STA_ID));
1210
+				// run the update
1211
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1212
+				if ($success !== false) {
1213
+					do_action(
1214
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1215
+						$CNT_ISO,
1216
+						$STA_ID,
1217
+						$cols_n_values
1218
+					);
1219
+				}
1220
+			}
1221
+		}
1222
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1223
+		if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1224
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1225
+		) {
1226
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1227
+			EE_Registry::instance()->CFG->update_espresso_config();
1228
+		}
1229
+
1230
+		if ($success !== false) {
1231
+			EE_Error::add_success(
1232
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1233
+			);
1234
+		}
1235
+		$this->_redirect_after_action(
1236
+			$success,
1237
+			'',
1238
+			'',
1239
+			array('action' => 'country_settings', 'country' => $CNT_ISO),
1240
+			true
1241
+		);
1242
+	}
1243
+
1244
+
1245
+	/**
1246
+	 *        form_form_field_label_wrap
1247
+	 *
1248
+	 * @access        public
1249
+	 * @param        string $label
1250
+	 * @return        string
1251
+	 */
1252
+	public function country_form_field_label_wrap($label, $required_text)
1253
+	{
1254
+		return '
1255 1255
 			<tr>
1256 1256
 				<th>
1257 1257
 					' . $label . '
1258 1258
 				</th>';
1259
-    }
1260
-
1261
-
1262
-    /**
1263
-     *        form_form_field_input__wrap
1264
-     *
1265
-     * @access        public
1266
-     * @param        string $label
1267
-     * @return        string
1268
-     */
1269
-    public function country_form_field_input__wrap($input, $label)
1270
-    {
1271
-        return '
1259
+	}
1260
+
1261
+
1262
+	/**
1263
+	 *        form_form_field_input__wrap
1264
+	 *
1265
+	 * @access        public
1266
+	 * @param        string $label
1267
+	 * @return        string
1268
+	 */
1269
+	public function country_form_field_input__wrap($input, $label)
1270
+	{
1271
+		return '
1272 1272
 				<td class="general-settings-country-input-td">
1273 1273
 					' . $input . '
1274 1274
 				</td>
1275 1275
 			</tr>';
1276
-    }
1277
-
1278
-
1279
-    /**
1280
-     *        form_form_field_label_wrap
1281
-     *
1282
-     * @access        public
1283
-     * @param        string $label
1284
-     * @param        string $required_text
1285
-     * @return        string
1286
-     */
1287
-    public function state_form_field_label_wrap($label, $required_text)
1288
-    {
1289
-        return $required_text;
1290
-    }
1291
-
1292
-
1293
-    /**
1294
-     *        form_form_field_input__wrap
1295
-     *
1296
-     * @access        public
1297
-     * @param        string $label
1298
-     * @return        string
1299
-     */
1300
-    public function state_form_field_input__wrap($input, $label)
1301
-    {
1302
-        return '
1276
+	}
1277
+
1278
+
1279
+	/**
1280
+	 *        form_form_field_label_wrap
1281
+	 *
1282
+	 * @access        public
1283
+	 * @param        string $label
1284
+	 * @param        string $required_text
1285
+	 * @return        string
1286
+	 */
1287
+	public function state_form_field_label_wrap($label, $required_text)
1288
+	{
1289
+		return $required_text;
1290
+	}
1291
+
1292
+
1293
+	/**
1294
+	 *        form_form_field_input__wrap
1295
+	 *
1296
+	 * @access        public
1297
+	 * @param        string $label
1298
+	 * @return        string
1299
+	 */
1300
+	public function state_form_field_input__wrap($input, $label)
1301
+	{
1302
+		return '
1303 1303
 				<td class="general-settings-country-state-input-td">
1304 1304
 					' . $input . '
1305 1305
 				</td>';
1306
-    }
1307
-
1308
-
1309
-    /***********/
1310
-
1311
-
1312
-    /**
1313
-     * displays edit and view links for critical EE pages
1314
-     *
1315
-     * @access public
1316
-     * @param int $ee_page_id
1317
-     * @return string
1318
-     */
1319
-    public static function edit_view_links($ee_page_id)
1320
-    {
1321
-        $links = '<a href="'
1322
-                 . add_query_arg(
1323
-                     array('post' => $ee_page_id, 'action' => 'edit'),
1324
-                     admin_url('post.php')
1325
-                 )
1326
-                 . '" >'
1327
-                 . __('Edit', 'event_espresso')
1328
-                 . '</a>';
1329
-        $links .= ' &nbsp;|&nbsp; ';
1330
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1331
-
1332
-        return $links;
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * displays page and shortcode status for critical EE pages
1338
-     *
1339
-     * @param WP page object $ee_page
1340
-     * @return string
1341
-     */
1342
-    public static function page_and_shortcode_status($ee_page, $shortcode)
1343
-    {
1344
-
1345
-        // page status
1346
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1347
-            $pg_colour = 'green';
1348
-            $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1349
-        } else {
1350
-            $pg_colour = 'red';
1351
-            $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1352
-        }
1353
-
1354
-        // shortcode status
1355
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1356
-            $sc_colour = 'green';
1357
-            $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1358
-        } else {
1359
-            $sc_colour = 'red';
1360
-            $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1361
-        }
1362
-
1363
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1364
-               . $pg_status
1365
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1366
-    }
1367
-
1368
-
1369
-    /**
1370
-     * generates a dropdown of all parent pages - copied from WP core
1371
-     *
1372
-     * @param int $default
1373
-     * @param int $parent
1374
-     * @param int $level
1375
-     */
1376
-    public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1377
-    {
1378
-        global $wpdb;
1379
-        $items = $wpdb->get_results(
1380
-            $wpdb->prepare(
1381
-                "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1382
-                $parent
1383
-            )
1384
-        );
1385
-
1386
-        if ($items) {
1387
-            foreach ($items as $item) {
1388
-                $pad = str_repeat('&nbsp;', $level * 3);
1389
-                if ($item->ID == $default) {
1390
-                    $current = ' selected="selected"';
1391
-                } else {
1392
-                    $current = '';
1393
-                }
1394
-
1395
-                echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1396
-                     . esc_html($item->post_title)
1397
-                     . "</option>";
1398
-                parent_dropdown($default, $item->ID, $level + 1);
1399
-            }
1400
-        }
1401
-    }
1306
+	}
1307
+
1308
+
1309
+	/***********/
1310
+
1311
+
1312
+	/**
1313
+	 * displays edit and view links for critical EE pages
1314
+	 *
1315
+	 * @access public
1316
+	 * @param int $ee_page_id
1317
+	 * @return string
1318
+	 */
1319
+	public static function edit_view_links($ee_page_id)
1320
+	{
1321
+		$links = '<a href="'
1322
+				 . add_query_arg(
1323
+					 array('post' => $ee_page_id, 'action' => 'edit'),
1324
+					 admin_url('post.php')
1325
+				 )
1326
+				 . '" >'
1327
+				 . __('Edit', 'event_espresso')
1328
+				 . '</a>';
1329
+		$links .= ' &nbsp;|&nbsp; ';
1330
+		$links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1331
+
1332
+		return $links;
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * displays page and shortcode status for critical EE pages
1338
+	 *
1339
+	 * @param WP page object $ee_page
1340
+	 * @return string
1341
+	 */
1342
+	public static function page_and_shortcode_status($ee_page, $shortcode)
1343
+	{
1344
+
1345
+		// page status
1346
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1347
+			$pg_colour = 'green';
1348
+			$pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1349
+		} else {
1350
+			$pg_colour = 'red';
1351
+			$pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1352
+		}
1353
+
1354
+		// shortcode status
1355
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1356
+			$sc_colour = 'green';
1357
+			$sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1358
+		} else {
1359
+			$sc_colour = 'red';
1360
+			$sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1361
+		}
1362
+
1363
+		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1364
+			   . $pg_status
1365
+			   . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1366
+	}
1367
+
1368
+
1369
+	/**
1370
+	 * generates a dropdown of all parent pages - copied from WP core
1371
+	 *
1372
+	 * @param int $default
1373
+	 * @param int $parent
1374
+	 * @param int $level
1375
+	 */
1376
+	public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1377
+	{
1378
+		global $wpdb;
1379
+		$items = $wpdb->get_results(
1380
+			$wpdb->prepare(
1381
+				"SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1382
+				$parent
1383
+			)
1384
+		);
1385
+
1386
+		if ($items) {
1387
+			foreach ($items as $item) {
1388
+				$pad = str_repeat('&nbsp;', $level * 3);
1389
+				if ($item->ID == $default) {
1390
+					$current = ' selected="selected"';
1391
+				} else {
1392
+					$current = '';
1393
+				}
1394
+
1395
+				echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1396
+					 . esc_html($item->post_title)
1397
+					 . "</option>";
1398
+				parent_dropdown($default, $item->ID, $level + 1);
1399
+			}
1400
+		}
1401
+	}
1402 1402
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
             'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
233 233
             'event_espresso'
234 234
         );
235
-        EE_Registry::$i18n_js_strings['error_occurred']          = __(
235
+        EE_Registry::$i18n_js_strings['error_occurred'] = __(
236 236
             'An error occurred! Please refresh the page and try again.',
237 237
             'event_espresso'
238 238
         );
239
-        EE_Registry::$i18n_js_strings['confirm_delete_state']    = __(
239
+        EE_Registry::$i18n_js_strings['confirm_delete_state'] = __(
240 240
             'Are you sure you want to delete this State / Province?',
241 241
             'event_espresso'
242 242
         );
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
         wp_enqueue_script('thickbox');
269 269
         wp_register_script(
270 270
             'organization_settings',
271
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
271
+            GEN_SET_ASSETS_URL.'your_organization_settings.js',
272 272
             array('jquery', 'media-upload', 'thickbox'),
273 273
             EVENT_ESPRESSO_VERSION,
274 274
             true
275 275
         );
276
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
276
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION);
277 277
         wp_enqueue_script('organization_settings');
278 278
         wp_enqueue_style('organization-css');
279 279
         $confirm_image_delete = array(
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
         //scripts
295 295
         wp_register_script(
296 296
             'gen_settings_countries',
297
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
297
+            GEN_SET_ASSETS_URL.'gen_settings_countries.js',
298 298
             array('ee_admin_js'),
299 299
             EVENT_ESPRESSO_VERSION,
300 300
             true
301 301
         );
302
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
302
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION);
303 303
         wp_enqueue_script('gen_settings_countries');
304 304
         wp_enqueue_style('organization-css');
305 305
     }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
         $this->_set_add_edit_form_tags('update_espresso_page_settings');
346 346
         $this->_set_publish_post_box_vars(null, false, false, null, false);
347 347
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
348
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
348
+            GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php',
349 349
             $this->_template_args,
350 350
             true
351 351
         );
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
             EE_Registry::instance()->CFG->core,
378 378
             $this->_req_data
379 379
         );
380
-        $what                              = __('Critical Pages & Shortcodes', 'event_espresso');
380
+        $what = __('Critical Pages & Shortcodes', 'event_espresso');
381 381
         $this->_redirect_after_action(
382 382
             $this->_update_espresso_configuration(
383 383
                 $what,
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
     protected function _your_organization_settings()
408 408
     {
409 409
 
410
-        $this->_template_args['site_license_key']       = isset(
410
+        $this->_template_args['site_license_key'] = isset(
411 411
             EE_Registry::instance()->NET_CFG->core->site_license_key
412 412
         )
413 413
             ? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key')
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
         add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
512 512
 
513 513
         //PUE verification stuff
514
-        $ver_option_key                                    = 'puvererr_' . basename(EE_PLUGIN_BASENAME);
514
+        $ver_option_key                                    = 'puvererr_'.basename(EE_PLUGIN_BASENAME);
515 515
         $verify_fail                                       = get_option($ver_option_key);
516 516
         $this->_template_args['site_license_key_verified'] = $verify_fail
517 517
                                                              || ! empty($verify_fail)
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
         $this->_set_add_edit_form_tags('update_your_organization_settings');
525 525
         $this->_set_publish_post_box_vars(null, false, false, null, false);
526 526
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
527
-            GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php',
527
+            GEN_SET_TEMPLATE_PATH.'your_organization_settings.template.php',
528 528
             $this->_template_args,
529 529
             true
530 530
         );
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
         $this->_set_add_edit_form_tags('update_country_settings');
736 736
         $this->_set_publish_post_box_vars(null, false, false, null, false);
737 737
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
738
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
738
+            GEN_SET_TEMPLATE_PATH.'countries_settings.template.php',
739 739
             $this->_template_args,
740 740
             true
741 741
         );
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
         $CNT_ISO = isset($this->_req_data['country'])
758 758
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
759 759
             : $CNT_ISO;
760
-        if (! $CNT_ISO) {
760
+        if ( ! $CNT_ISO) {
761 761
             return '';
762 762
         }
763 763
 
@@ -768,65 +768,65 @@  discard block
 block discarded – undo
768 768
         add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
769 769
         $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
770 770
 
771
-        $country_input_types            = array(
771
+        $country_input_types = array(
772 772
             'CNT_active'      => array(
773 773
                 'type'             => 'RADIO_BTN',
774
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
774
+                'input_name'       => 'cntry['.$CNT_ISO.']',
775 775
                 'class'            => '',
776 776
                 'options'          => $this->_yes_no_values,
777 777
                 'use_desc_4_label' => true,
778 778
             ),
779 779
             'CNT_ISO'         => array(
780 780
                 'type'       => 'TEXT',
781
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
781
+                'input_name' => 'cntry['.$CNT_ISO.']',
782 782
                 'class'      => 'small-text',
783 783
             ),
784 784
             'CNT_ISO3'        => array(
785 785
                 'type'       => 'TEXT',
786
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
786
+                'input_name' => 'cntry['.$CNT_ISO.']',
787 787
                 'class'      => 'small-text',
788 788
             ),
789 789
             'RGN_ID'          => array(
790 790
                 'type'       => 'TEXT',
791
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
791
+                'input_name' => 'cntry['.$CNT_ISO.']',
792 792
                 'class'      => 'small-text',
793 793
             ),
794 794
             'CNT_name'        => array(
795 795
                 'type'       => 'TEXT',
796
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
796
+                'input_name' => 'cntry['.$CNT_ISO.']',
797 797
                 'class'      => 'regular-text',
798 798
             ),
799 799
             'CNT_cur_code'    => array(
800 800
                 'type'       => 'TEXT',
801
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
801
+                'input_name' => 'cntry['.$CNT_ISO.']',
802 802
                 'class'      => 'small-text',
803 803
             ),
804 804
             'CNT_cur_single'  => array(
805 805
                 'type'       => 'TEXT',
806
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
806
+                'input_name' => 'cntry['.$CNT_ISO.']',
807 807
                 'class'      => 'medium-text',
808 808
             ),
809 809
             'CNT_cur_plural'  => array(
810 810
                 'type'       => 'TEXT',
811
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
811
+                'input_name' => 'cntry['.$CNT_ISO.']',
812 812
                 'class'      => 'medium-text',
813 813
             ),
814 814
             'CNT_cur_sign'    => array(
815 815
                 'type'         => 'TEXT',
816
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
816
+                'input_name'   => 'cntry['.$CNT_ISO.']',
817 817
                 'class'        => 'small-text',
818 818
                 'htmlentities' => false,
819 819
             ),
820 820
             'CNT_cur_sign_b4' => array(
821 821
                 'type'             => 'RADIO_BTN',
822
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
822
+                'input_name'       => 'cntry['.$CNT_ISO.']',
823 823
                 'class'            => '',
824 824
                 'options'          => $this->_yes_no_values,
825 825
                 'use_desc_4_label' => true,
826 826
             ),
827 827
             'CNT_cur_dec_plc' => array(
828 828
                 'type'       => 'RADIO_BTN',
829
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
829
+                'input_name' => 'cntry['.$CNT_ISO.']',
830 830
                 'class'      => '',
831 831
                 'options'    => array(
832 832
                     array('id' => 0, 'text' => ''),
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
             ),
838 838
             'CNT_cur_dec_mrk' => array(
839 839
                 'type'             => 'RADIO_BTN',
840
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
840
+                'input_name'       => 'cntry['.$CNT_ISO.']',
841 841
                 'class'            => '',
842 842
                 'options'          => array(
843 843
                     array(
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
             ),
851 851
             'CNT_cur_thsnds'  => array(
852 852
                 'type'             => 'RADIO_BTN',
853
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
853
+                'input_name'       => 'cntry['.$CNT_ISO.']',
854 854
                 'class'            => '',
855 855
                 'options'          => array(
856 856
                     array(
@@ -863,12 +863,12 @@  discard block
 block discarded – undo
863 863
             ),
864 864
             'CNT_tel_code'    => array(
865 865
                 'type'       => 'TEXT',
866
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
866
+                'input_name' => 'cntry['.$CNT_ISO.']',
867 867
                 'class'      => 'small-text',
868 868
             ),
869 869
             'CNT_is_EU'       => array(
870 870
                 'type'             => 'RADIO_BTN',
871
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
871
+                'input_name'       => 'cntry['.$CNT_ISO.']',
872 872
                 'class'            => '',
873 873
                 'options'          => $this->_yes_no_values,
874 874
                 'use_desc_4_label' => true,
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
             $country,
879 879
             $country_input_types
880 880
         );
881
-        $country_details_settings       = EEH_Template::display_template(
882
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
881
+        $country_details_settings = EEH_Template::display_template(
882
+            GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php',
883 883
             $this->_template_args,
884 884
             true
885 885
         );
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
 
912 912
         $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO;
913 913
 
914
-        if (! $CNT_ISO) {
914
+        if ( ! $CNT_ISO) {
915 915
             return '';
916 916
         }
917 917
         // for ajax
@@ -925,20 +925,20 @@  discard block
 block discarded – undo
925 925
             foreach ($states as $STA_ID => $state) {
926 926
                 if ($state instanceof EE_State) {
927 927
                     //STA_abbrev 	STA_name 	STA_active
928
-                    $state_input_types                                           = array(
928
+                    $state_input_types = array(
929 929
                         'STA_abbrev' => array(
930 930
                             'type'       => 'TEXT',
931
-                            'input_name' => 'states[' . $STA_ID . ']',
931
+                            'input_name' => 'states['.$STA_ID.']',
932 932
                             'class'      => 'mid-text',
933 933
                         ),
934 934
                         'STA_name'   => array(
935 935
                             'type'       => 'TEXT',
936
-                            'input_name' => 'states[' . $STA_ID . ']',
936
+                            'input_name' => 'states['.$STA_ID.']',
937 937
                             'class'      => 'regular-text',
938 938
                         ),
939 939
                         'STA_active' => array(
940 940
                             'type'             => 'RADIO_BTN',
941
-                            'input_name'       => 'states[' . $STA_ID . ']',
941
+                            'input_name'       => 'states['.$STA_ID.']',
942 942
                             'options'          => $this->_yes_no_values,
943 943
                             'use_desc_4_label' => true,
944 944
                         ),
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
                             $state,
949 949
                             $state_input_types
950 950
                         );
951
-                    $query_args                                                  = array(
951
+                    $query_args = array(
952 952
                         'action'     => 'delete_state',
953 953
                         'STA_ID'     => $STA_ID,
954 954
                         'CNT_ISO'    => $CNT_ISO,
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
         );
972 972
 
973 973
         $state_details_settings = EEH_Template::display_template(
974
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
974
+            GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php',
975 975
             $this->_template_args,
976 976
             true
977 977
         );
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
         $CNT_ISO = isset($this->_req_data['CNT_ISO'])
1006 1006
             ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1007 1007
             : false;
1008
-        if (! $CNT_ISO) {
1008
+        if ( ! $CNT_ISO) {
1009 1009
             EE_Error::add_error(
1010 1010
                 __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1011 1011
                 __FILE__,
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1018 1018
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
1019 1019
             : false;
1020
-        if (! $STA_abbrev) {
1020
+        if ( ! $STA_abbrev) {
1021 1021
             EE_Error::add_error(
1022 1022
                 __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
1023 1023
                 __FILE__,
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
         $STA_name = isset($this->_req_data['STA_name'])
1030 1030
             ? sanitize_text_field($this->_req_data['STA_name'])
1031 1031
             : false;
1032
-        if (! $STA_name) {
1032
+        if ( ! $STA_name) {
1033 1033
             EE_Error::add_error(
1034 1034
                 __('No State name or an invalid State name was received.', 'event_espresso'),
1035 1035
                 __FILE__,
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
                 'STA_name'   => $STA_name,
1047 1047
                 'STA_active' => true,
1048 1048
             );
1049
-            $success       = EEM_State::instance()->insert($cols_n_values);
1049
+            $success = EEM_State::instance()->insert($cols_n_values);
1050 1050
             EE_Error::add_success(__('The State was added successfully.', 'event_espresso'));
1051 1051
         }
1052 1052
 
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1078 1078
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
1079 1079
             : false;
1080
-        if (! $STA_ID) {
1080
+        if ( ! $STA_ID) {
1081 1081
             EE_Error::add_error(
1082 1082
                 __('No State ID or an invalid State ID was received.', 'event_espresso'),
1083 1083
                 __FILE__,
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
         $CNT_ISO = isset($this->_req_data['country'])
1127 1127
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
1128 1128
             : false;
1129
-        if (! $CNT_ISO) {
1129
+        if ( ! $CNT_ISO) {
1130 1130
             EE_Error::add_error(
1131 1131
                 __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1132 1132
                 __FILE__,
@@ -1203,7 +1203,7 @@  discard block
 block discarded – undo
1203 1203
                     'CNT_ISO'    => $CNT_ISO,
1204 1204
                     'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1205 1205
                     'STA_name'   => sanitize_text_field($state['STA_name']),
1206
-                    'STA_active' => (bool)absint($state['STA_active']),
1206
+                    'STA_active' => (bool) absint($state['STA_active']),
1207 1207
                 );
1208 1208
                 // where values
1209 1209
                 $where_cols_n_values = array(array('STA_ID' => $STA_ID));
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
         return '
1255 1255
 			<tr>
1256 1256
 				<th>
1257
-					' . $label . '
1257
+					' . $label.'
1258 1258
 				</th>';
1259 1259
     }
1260 1260
 
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
     {
1271 1271
         return '
1272 1272
 				<td class="general-settings-country-input-td">
1273
-					' . $input . '
1273
+					' . $input.'
1274 1274
 				</td>
1275 1275
 			</tr>';
1276 1276
     }
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
     {
1302 1302
         return '
1303 1303
 				<td class="general-settings-country-state-input-td">
1304
-					' . $input . '
1304
+					' . $input.'
1305 1305
 				</td>';
1306 1306
     }
1307 1307
 
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
                  . __('Edit', 'event_espresso')
1328 1328
                  . '</a>';
1329 1329
         $links .= ' &nbsp;|&nbsp; ';
1330
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1330
+        $links .= '<a href="'.get_permalink($ee_page_id).'" >'.__('View', 'event_espresso').'</a>';
1331 1331
 
1332 1332
         return $links;
1333 1333
     }
@@ -1360,9 +1360,9 @@  discard block
 block discarded – undo
1360 1360
             $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1361 1361
         }
1362 1362
 
1363
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1363
+        return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>'
1364 1364
                . $pg_status
1365
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1365
+               . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>';
1366 1366
     }
1367 1367
 
1368 1368
 
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -23,449 +23,449 @@
 block discarded – undo
23 23
 class Registry
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Template_Config $template_config
28
-     */
29
-    protected $template_config;
30
-
31
-    /**
32
-     * @var EE_Currency_Config $currency_config
33
-     */
34
-    protected $currency_config;
35
-
36
-    /**
37
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
38
-     *
39
-     * @var array
40
-     */
41
-    protected $jsdata = array();
42
-
43
-
44
-    /**
45
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
46
-     * page source.
47
-     * @var array
48
-     */
49
-    protected $script_handles_with_data = array();
50
-
51
-
52
-
53
-    /**
54
-     * Registry constructor.
55
-     * Hooking into WP actions for script registry.
56
-     *
57
-     * @param EE_Template_Config $template_config
58
-     * @param EE_Currency_Config $currency_config
59
-     */
60
-    public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config)
61
-    {
62
-        $this->template_config = $template_config;
63
-        $this->currency_config = $currency_config;
64
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
65
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
66
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
67
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
68
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
69
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
70
-    }
71
-
72
-
73
-
74
-    /**
75
-     * Callback for the WP script actions.
76
-     * Used to register globally accessible core scripts.
77
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
78
-     */
79
-    public function scripts()
80
-    {
81
-        global $wp_version;
82
-        wp_register_script(
83
-            'eejs-core',
84
-            EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
85
-            array(),
86
-            EVENT_ESPRESSO_VERSION,
87
-            true
88
-        );
89
-        //only run this if WordPress 4.4.0 > is in use.
90
-        if (version_compare($wp_version, '4.4.0', '>')) {
91
-            //js.api
92
-            wp_register_script(
93
-                'eejs-api',
94
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
95
-                array('underscore', 'eejs-core'),
96
-                EVENT_ESPRESSO_VERSION,
97
-                true
98
-            );
99
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
100
-            $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
101
-        }
102
-        if (! is_admin()) {
103
-            $this->loadCoreCss();
104
-        }
105
-        $this->loadCoreJs();
106
-        $this->loadJqueryValidate();
107
-        $this->loadAccountingJs();
108
-        $this->loadQtipJs();
109
-    }
110
-
111
-
112
-
113
-    /**
114
-     * Call back for the script print in frontend and backend.
115
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
116
-     *
117
-     * @since 4.9.31.rc.015
118
-     */
119
-    public function enqueueData()
120
-    {
121
-        $this->removeAlreadyRegisteredDataForScriptHandles();
122
-        wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata));
123
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
124
-        $this->localizeAccountingJs();
125
-        $this->addRegisteredScriptHandlesWithData('eejs-core');
126
-        $this->addRegisteredScriptHandlesWithData('espresso_core');
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * Used to add data to eejs.data object.
133
-     * Note:  Overriding existing data is not allowed.
134
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
135
-     * If the data you add is something like this:
136
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
137
-     * It will be exposed in the page source as:
138
-     *  eejs.data.my_plugin_data.foo == gar
139
-     *
140
-     * @param string       $key   Key used to access your data
141
-     * @param string|array $value Value to attach to key
142
-     * @throws InvalidArgumentException
143
-     */
144
-    public function addData($key, $value)
145
-    {
146
-        if ($this->verifyDataNotExisting($key)) {
147
-            $this->jsdata[$key] = $value;
148
-        }
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
155
-     * elements in an array.
156
-     * When you use this method, the value you include will be appended to the end of an array on $key.
157
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
158
-     * object like this, eejs.data.test = [ my_data,
159
-     * ]
160
-     * If there has already been a scalar value attached to the data object given key, then
161
-     * this will throw an exception.
162
-     *
163
-     * @param string       $key   Key to attach data to.
164
-     * @param string|array $value Value being registered.
165
-     * @throws InvalidArgumentException
166
-     */
167
-    public function pushData($key, $value)
168
-    {
169
-        if (isset($this->jsdata[$key])
170
-            && ! is_array($this->jsdata[$key])
171
-        ) {
172
-            throw new invalidArgumentException(
173
-                sprintf(
174
-                    __(
175
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
26
+	/**
27
+	 * @var EE_Template_Config $template_config
28
+	 */
29
+	protected $template_config;
30
+
31
+	/**
32
+	 * @var EE_Currency_Config $currency_config
33
+	 */
34
+	protected $currency_config;
35
+
36
+	/**
37
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $jsdata = array();
42
+
43
+
44
+	/**
45
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
46
+	 * page source.
47
+	 * @var array
48
+	 */
49
+	protected $script_handles_with_data = array();
50
+
51
+
52
+
53
+	/**
54
+	 * Registry constructor.
55
+	 * Hooking into WP actions for script registry.
56
+	 *
57
+	 * @param EE_Template_Config $template_config
58
+	 * @param EE_Currency_Config $currency_config
59
+	 */
60
+	public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config)
61
+	{
62
+		$this->template_config = $template_config;
63
+		$this->currency_config = $currency_config;
64
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
65
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
66
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
67
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
68
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
69
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
70
+	}
71
+
72
+
73
+
74
+	/**
75
+	 * Callback for the WP script actions.
76
+	 * Used to register globally accessible core scripts.
77
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
78
+	 */
79
+	public function scripts()
80
+	{
81
+		global $wp_version;
82
+		wp_register_script(
83
+			'eejs-core',
84
+			EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
85
+			array(),
86
+			EVENT_ESPRESSO_VERSION,
87
+			true
88
+		);
89
+		//only run this if WordPress 4.4.0 > is in use.
90
+		if (version_compare($wp_version, '4.4.0', '>')) {
91
+			//js.api
92
+			wp_register_script(
93
+				'eejs-api',
94
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
95
+				array('underscore', 'eejs-core'),
96
+				EVENT_ESPRESSO_VERSION,
97
+				true
98
+			);
99
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
100
+			$this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
101
+		}
102
+		if (! is_admin()) {
103
+			$this->loadCoreCss();
104
+		}
105
+		$this->loadCoreJs();
106
+		$this->loadJqueryValidate();
107
+		$this->loadAccountingJs();
108
+		$this->loadQtipJs();
109
+	}
110
+
111
+
112
+
113
+	/**
114
+	 * Call back for the script print in frontend and backend.
115
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
116
+	 *
117
+	 * @since 4.9.31.rc.015
118
+	 */
119
+	public function enqueueData()
120
+	{
121
+		$this->removeAlreadyRegisteredDataForScriptHandles();
122
+		wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata));
123
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
124
+		$this->localizeAccountingJs();
125
+		$this->addRegisteredScriptHandlesWithData('eejs-core');
126
+		$this->addRegisteredScriptHandlesWithData('espresso_core');
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * Used to add data to eejs.data object.
133
+	 * Note:  Overriding existing data is not allowed.
134
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
135
+	 * If the data you add is something like this:
136
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
137
+	 * It will be exposed in the page source as:
138
+	 *  eejs.data.my_plugin_data.foo == gar
139
+	 *
140
+	 * @param string       $key   Key used to access your data
141
+	 * @param string|array $value Value to attach to key
142
+	 * @throws InvalidArgumentException
143
+	 */
144
+	public function addData($key, $value)
145
+	{
146
+		if ($this->verifyDataNotExisting($key)) {
147
+			$this->jsdata[$key] = $value;
148
+		}
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
155
+	 * elements in an array.
156
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
157
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
158
+	 * object like this, eejs.data.test = [ my_data,
159
+	 * ]
160
+	 * If there has already been a scalar value attached to the data object given key, then
161
+	 * this will throw an exception.
162
+	 *
163
+	 * @param string       $key   Key to attach data to.
164
+	 * @param string|array $value Value being registered.
165
+	 * @throws InvalidArgumentException
166
+	 */
167
+	public function pushData($key, $value)
168
+	{
169
+		if (isset($this->jsdata[$key])
170
+			&& ! is_array($this->jsdata[$key])
171
+		) {
172
+			throw new invalidArgumentException(
173
+				sprintf(
174
+					__(
175
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
176 176
                          push values to this data element when it is an array.',
177
-                        'event_espresso'
178
-                    ),
179
-                    $key,
180
-                    __METHOD__
181
-                )
182
-            );
183
-        }
184
-        $this->jsdata[$key][] = $value;
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * Used to set content used by javascript for a template.
191
-     * Note: Overrides of existing registered templates are not allowed.
192
-     *
193
-     * @param string $template_reference
194
-     * @param string $template_content
195
-     * @throws InvalidArgumentException
196
-     */
197
-    public function addTemplate($template_reference, $template_content)
198
-    {
199
-        if (! isset($this->jsdata['templates'])) {
200
-            $this->jsdata['templates'] = array();
201
-        }
202
-        //no overrides allowed.
203
-        if (isset($this->jsdata['templates'][$template_reference])) {
204
-            throw new invalidArgumentException(
205
-                sprintf(
206
-                    __(
207
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
208
-                        'event_espresso'
209
-                    ),
210
-                    $template_reference
211
-                )
212
-            );
213
-        }
214
-        $this->jsdata['templates'][$template_reference] = $template_content;
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * Retrieve the template content already registered for the given reference.
221
-     *
222
-     * @param string $template_reference
223
-     * @return string
224
-     */
225
-    public function getTemplate($template_reference)
226
-    {
227
-        return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
228
-            ? $this->jsdata['templates'][$template_reference]
229
-            : '';
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * Retrieve registered data.
236
-     *
237
-     * @param string $key Name of key to attach data to.
238
-     * @return mixed                If there is no for the given key, then false is returned.
239
-     */
240
-    public function getData($key)
241
-    {
242
-        return isset($this->jsdata[$key])
243
-            ? $this->jsdata[$key]
244
-            : false;
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * Verifies whether the given data exists already on the jsdata array.
251
-     * Overriding data is not allowed.
252
-     *
253
-     * @param string $key Index for data.
254
-     * @return bool        If valid then return true.
255
-     * @throws InvalidArgumentException if data already exists.
256
-     */
257
-    protected function verifyDataNotExisting($key)
258
-    {
259
-        if (isset($this->jsdata[$key])) {
260
-            if (is_array($this->jsdata[$key])) {
261
-                throw new InvalidArgumentException(
262
-                    sprintf(
263
-                        __(
264
-                            'The value for %1$s already exists in the Registry::eejs object.
177
+						'event_espresso'
178
+					),
179
+					$key,
180
+					__METHOD__
181
+				)
182
+			);
183
+		}
184
+		$this->jsdata[$key][] = $value;
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 * Used to set content used by javascript for a template.
191
+	 * Note: Overrides of existing registered templates are not allowed.
192
+	 *
193
+	 * @param string $template_reference
194
+	 * @param string $template_content
195
+	 * @throws InvalidArgumentException
196
+	 */
197
+	public function addTemplate($template_reference, $template_content)
198
+	{
199
+		if (! isset($this->jsdata['templates'])) {
200
+			$this->jsdata['templates'] = array();
201
+		}
202
+		//no overrides allowed.
203
+		if (isset($this->jsdata['templates'][$template_reference])) {
204
+			throw new invalidArgumentException(
205
+				sprintf(
206
+					__(
207
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
208
+						'event_espresso'
209
+					),
210
+					$template_reference
211
+				)
212
+			);
213
+		}
214
+		$this->jsdata['templates'][$template_reference] = $template_content;
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * Retrieve the template content already registered for the given reference.
221
+	 *
222
+	 * @param string $template_reference
223
+	 * @return string
224
+	 */
225
+	public function getTemplate($template_reference)
226
+	{
227
+		return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
228
+			? $this->jsdata['templates'][$template_reference]
229
+			: '';
230
+	}
231
+
232
+
233
+
234
+	/**
235
+	 * Retrieve registered data.
236
+	 *
237
+	 * @param string $key Name of key to attach data to.
238
+	 * @return mixed                If there is no for the given key, then false is returned.
239
+	 */
240
+	public function getData($key)
241
+	{
242
+		return isset($this->jsdata[$key])
243
+			? $this->jsdata[$key]
244
+			: false;
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * Verifies whether the given data exists already on the jsdata array.
251
+	 * Overriding data is not allowed.
252
+	 *
253
+	 * @param string $key Index for data.
254
+	 * @return bool        If valid then return true.
255
+	 * @throws InvalidArgumentException if data already exists.
256
+	 */
257
+	protected function verifyDataNotExisting($key)
258
+	{
259
+		if (isset($this->jsdata[$key])) {
260
+			if (is_array($this->jsdata[$key])) {
261
+				throw new InvalidArgumentException(
262
+					sprintf(
263
+						__(
264
+							'The value for %1$s already exists in the Registry::eejs object.
265 265
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
266 266
                             %2$s method to push your value to the array.',
267
-                            'event_espresso'
268
-                        ),
269
-                        $key,
270
-                        'pushData()'
271
-                    )
272
-                );
273
-            }
274
-            throw new InvalidArgumentException(
275
-                sprintf(
276
-                    __(
277
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
267
+							'event_espresso'
268
+						),
269
+						$key,
270
+						'pushData()'
271
+					)
272
+				);
273
+			}
274
+			throw new InvalidArgumentException(
275
+				sprintf(
276
+					__(
277
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
278 278
                         allowed.  Consider attaching your value to a different key',
279
-                        'event_espresso'
280
-                    ),
281
-                    $key
282
-                )
283
-            );
284
-        }
285
-        return true;
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * registers core default stylesheets
292
-     */
293
-    private function loadCoreCss()
294
-    {
295
-        if ($this->template_config->enable_default_style) {
296
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
297
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
298
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
299
-            wp_register_style(
300
-                'espresso_default',
301
-                $default_stylesheet_path,
302
-                array('dashicons'),
303
-                EVENT_ESPRESSO_VERSION
304
-            );
305
-            //Load custom style sheet if available
306
-            if ($this->template_config->custom_style_sheet !== null) {
307
-                wp_register_style(
308
-                    'espresso_custom_css',
309
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
310
-                    array('espresso_default'),
311
-                    EVENT_ESPRESSO_VERSION
312
-                );
313
-            }
314
-        }
315
-    }
316
-
317
-
318
-
319
-    /**
320
-     * registers core default javascript
321
-     */
322
-    private function loadCoreJs()
323
-    {
324
-        // load core js
325
-        wp_register_script(
326
-            'espresso_core',
327
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
328
-            array('jquery'),
329
-            EVENT_ESPRESSO_VERSION,
330
-            true
331
-        );
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * registers jQuery Validate for form validation
338
-     */
339
-    private function loadJqueryValidate()
340
-    {
341
-        // register jQuery Validate and additional methods
342
-        wp_register_script(
343
-            'jquery-validate',
344
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
345
-            array('jquery'),
346
-            '1.15.0',
347
-            true
348
-        );
349
-        wp_register_script(
350
-            'jquery-validate-extra-methods',
351
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
352
-            array('jquery', 'jquery-validate'),
353
-            '1.15.0',
354
-            true
355
-        );
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * registers accounting.js for performing client-side calculations
362
-     */
363
-    private function loadAccountingJs()
364
-    {
365
-        //accounting.js library
366
-        // @link http://josscrowcroft.github.io/accounting.js/
367
-        wp_register_script(
368
-            'ee-accounting-core',
369
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
370
-            array('underscore'),
371
-            '0.3.2',
372
-            true
373
-        );
374
-        wp_register_script(
375
-            'ee-accounting',
376
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
377
-            array('ee-accounting-core'),
378
-            EVENT_ESPRESSO_VERSION,
379
-            true
380
-        );
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * registers accounting.js for performing client-side calculations
387
-     */
388
-    private function localizeAccountingJs()
389
-    {
390
-        wp_localize_script(
391
-            'ee-accounting',
392
-            'EE_ACCOUNTING_CFG',
393
-            array(
394
-                'currency' => array(
395
-                    'symbol'    => $this->currency_config->sign,
396
-                    'format'    => array(
397
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
398
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
399
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
400
-                    ),
401
-                    'decimal'   => $this->currency_config->dec_mrk,
402
-                    'thousand'  => $this->currency_config->thsnds,
403
-                    'precision' => $this->currency_config->dec_plc,
404
-                ),
405
-                'number'   => array(
406
-                    'precision' => $this->currency_config->dec_plc,
407
-                    'thousand'  => $this->currency_config->thsnds,
408
-                    'decimal'   => $this->currency_config->dec_mrk,
409
-                ),
410
-            )
411
-        );
412
-        $this->addRegisteredScriptHandlesWithData('ee-accounting');
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * registers assets for cleaning your ears
419
-     */
420
-    private function loadQtipJs()
421
-    {
422
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
423
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
424
-        if (apply_filters('FHEE_load_qtip', false)) {
425
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
426
-        }
427
-    }
428
-
429
-
430
-    /**
431
-     * This is used to set registered script handles that have data.
432
-     * @param string $script_handle
433
-     */
434
-    private function addRegisteredScriptHandlesWithData($script_handle)
435
-    {
436
-        $this->script_handles_with_data[$script_handle] = $script_handle;
437
-    }
438
-
439
-
440
-    /**
441
-     * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
442
-     * Dependency stored in WP_Scripts if its set.
443
-     */
444
-    private function removeAlreadyRegisteredDataForScriptHandles()
445
-    {
446
-        if (empty($this->script_handles_with_data)) {
447
-            return;
448
-        }
449
-        foreach ($this->script_handles_with_data as $script_handle) {
450
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
451
-        }
452
-    }
453
-
454
-
455
-    /**
456
-     * Removes any data dependency registered in WP_Scripts if its set.
457
-     * @param string $script_handle
458
-     */
459
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
460
-    {
461
-        if (isset($this->script_handles_with_data[$script_handle])) {
462
-            global $wp_scripts;
463
-            if ($wp_scripts->get_data($script_handle, 'data')) {
464
-                unset($wp_scripts->registered[$script_handle]->extra['data']);
465
-                unset($this->script_handles_with_data[$script_handle]);
466
-            }
467
-        }
468
-    }
279
+						'event_espresso'
280
+					),
281
+					$key
282
+				)
283
+			);
284
+		}
285
+		return true;
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * registers core default stylesheets
292
+	 */
293
+	private function loadCoreCss()
294
+	{
295
+		if ($this->template_config->enable_default_style) {
296
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
297
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
298
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
299
+			wp_register_style(
300
+				'espresso_default',
301
+				$default_stylesheet_path,
302
+				array('dashicons'),
303
+				EVENT_ESPRESSO_VERSION
304
+			);
305
+			//Load custom style sheet if available
306
+			if ($this->template_config->custom_style_sheet !== null) {
307
+				wp_register_style(
308
+					'espresso_custom_css',
309
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
310
+					array('espresso_default'),
311
+					EVENT_ESPRESSO_VERSION
312
+				);
313
+			}
314
+		}
315
+	}
316
+
317
+
318
+
319
+	/**
320
+	 * registers core default javascript
321
+	 */
322
+	private function loadCoreJs()
323
+	{
324
+		// load core js
325
+		wp_register_script(
326
+			'espresso_core',
327
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
328
+			array('jquery'),
329
+			EVENT_ESPRESSO_VERSION,
330
+			true
331
+		);
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * registers jQuery Validate for form validation
338
+	 */
339
+	private function loadJqueryValidate()
340
+	{
341
+		// register jQuery Validate and additional methods
342
+		wp_register_script(
343
+			'jquery-validate',
344
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
345
+			array('jquery'),
346
+			'1.15.0',
347
+			true
348
+		);
349
+		wp_register_script(
350
+			'jquery-validate-extra-methods',
351
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
352
+			array('jquery', 'jquery-validate'),
353
+			'1.15.0',
354
+			true
355
+		);
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * registers accounting.js for performing client-side calculations
362
+	 */
363
+	private function loadAccountingJs()
364
+	{
365
+		//accounting.js library
366
+		// @link http://josscrowcroft.github.io/accounting.js/
367
+		wp_register_script(
368
+			'ee-accounting-core',
369
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
370
+			array('underscore'),
371
+			'0.3.2',
372
+			true
373
+		);
374
+		wp_register_script(
375
+			'ee-accounting',
376
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
377
+			array('ee-accounting-core'),
378
+			EVENT_ESPRESSO_VERSION,
379
+			true
380
+		);
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * registers accounting.js for performing client-side calculations
387
+	 */
388
+	private function localizeAccountingJs()
389
+	{
390
+		wp_localize_script(
391
+			'ee-accounting',
392
+			'EE_ACCOUNTING_CFG',
393
+			array(
394
+				'currency' => array(
395
+					'symbol'    => $this->currency_config->sign,
396
+					'format'    => array(
397
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
398
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
399
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
400
+					),
401
+					'decimal'   => $this->currency_config->dec_mrk,
402
+					'thousand'  => $this->currency_config->thsnds,
403
+					'precision' => $this->currency_config->dec_plc,
404
+				),
405
+				'number'   => array(
406
+					'precision' => $this->currency_config->dec_plc,
407
+					'thousand'  => $this->currency_config->thsnds,
408
+					'decimal'   => $this->currency_config->dec_mrk,
409
+				),
410
+			)
411
+		);
412
+		$this->addRegisteredScriptHandlesWithData('ee-accounting');
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * registers assets for cleaning your ears
419
+	 */
420
+	private function loadQtipJs()
421
+	{
422
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
423
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
424
+		if (apply_filters('FHEE_load_qtip', false)) {
425
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
426
+		}
427
+	}
428
+
429
+
430
+	/**
431
+	 * This is used to set registered script handles that have data.
432
+	 * @param string $script_handle
433
+	 */
434
+	private function addRegisteredScriptHandlesWithData($script_handle)
435
+	{
436
+		$this->script_handles_with_data[$script_handle] = $script_handle;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
442
+	 * Dependency stored in WP_Scripts if its set.
443
+	 */
444
+	private function removeAlreadyRegisteredDataForScriptHandles()
445
+	{
446
+		if (empty($this->script_handles_with_data)) {
447
+			return;
448
+		}
449
+		foreach ($this->script_handles_with_data as $script_handle) {
450
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
451
+		}
452
+	}
453
+
454
+
455
+	/**
456
+	 * Removes any data dependency registered in WP_Scripts if its set.
457
+	 * @param string $script_handle
458
+	 */
459
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
460
+	{
461
+		if (isset($this->script_handles_with_data[$script_handle])) {
462
+			global $wp_scripts;
463
+			if ($wp_scripts->get_data($script_handle, 'data')) {
464
+				unset($wp_scripts->registered[$script_handle]->extra['data']);
465
+				unset($this->script_handles_with_data[$script_handle]);
466
+			}
467
+		}
468
+	}
469 469
 
470 470
 
471 471
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -18,132 +18,132 @@
 block discarded – undo
18 18
 abstract class DomainBase
19 19
 {
20 20
 
21
-    /**
22
-     * Equivalent to `__FILE__` for main plugin file.
23
-     *
24
-     * @var string
25
-     */
26
-    private static $plugin_file = '';
27
-
28
-    /**
29
-     * String indicating version for plugin
30
-     *
31
-     * @var string
32
-     */
33
-    private static $version = '';
34
-
35
-    /**
36
-     * @var string $plugin_basename
37
-     */
38
-    private static $plugin_basename = '';
39
-
40
-    /**
41
-     * @var string $plugin_path
42
-     */
43
-    private static $plugin_path = '';
44
-
45
-    /**
46
-     * @var string $plugin_url
47
-     */
48
-    private static $plugin_url = '';
49
-
50
-
51
-
52
-    /**
53
-     * Initializes internal static properties.
54
-     *
55
-     * @param string $plugin_file
56
-     * @param string $version
57
-     */
58
-    public static function init($plugin_file, $version)
59
-    {
60
-        self::$plugin_file = $plugin_file;
61
-        self::$version = $version;
62
-        self::$plugin_basename = plugin_basename($plugin_file);
63
-        self::$plugin_path = plugin_dir_path($plugin_file);
64
-        self::$plugin_url = plugin_dir_url($plugin_file);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return string
71
-     * @throws DomainException
72
-     */
73
-    public static function pluginFile()
74
-    {
75
-        self::verifyInitialized(__METHOD__);
76
-        return self::$plugin_file;
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * @return string
83
-     * @throws DomainException
84
-     */
85
-    public static function pluginBasename()
86
-    {
87
-        self::verifyInitialized(__METHOD__);
88
-        return self::$plugin_basename;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * @return string
95
-     * @throws DomainException
96
-     */
97
-    public static function pluginPath()
98
-    {
99
-        self::verifyInitialized(__METHOD__);
100
-        return self::$plugin_path;
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @return string
107
-     * @throws DomainException
108
-     */
109
-    public static function pluginUrl()
110
-    {
111
-        self::verifyInitialized(__METHOD__);
112
-        return self::$plugin_url;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * @return string
119
-     * @throws DomainException
120
-     */
121
-    public static function version()
122
-    {
123
-        self::verifyInitialized(__METHOD__);
124
-        return self::$version;
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     * @param string $method
131
-     * @throws DomainException
132
-     */
133
-    private static function verifyInitialized($method)
134
-    {
135
-        if (self::$plugin_file === '') {
136
-            throw new DomainException(
137
-                sprintf(
138
-                    esc_html__(
139
-                        '%1$s needs to be called before %2$s can return a value.',
140
-                        'event_espresso'
141
-                    ),
142
-                    get_called_class() . '::init()',
143
-                    "{$method}()"
144
-                )
145
-            );
146
-        }
147
-    }
21
+	/**
22
+	 * Equivalent to `__FILE__` for main plugin file.
23
+	 *
24
+	 * @var string
25
+	 */
26
+	private static $plugin_file = '';
27
+
28
+	/**
29
+	 * String indicating version for plugin
30
+	 *
31
+	 * @var string
32
+	 */
33
+	private static $version = '';
34
+
35
+	/**
36
+	 * @var string $plugin_basename
37
+	 */
38
+	private static $plugin_basename = '';
39
+
40
+	/**
41
+	 * @var string $plugin_path
42
+	 */
43
+	private static $plugin_path = '';
44
+
45
+	/**
46
+	 * @var string $plugin_url
47
+	 */
48
+	private static $plugin_url = '';
49
+
50
+
51
+
52
+	/**
53
+	 * Initializes internal static properties.
54
+	 *
55
+	 * @param string $plugin_file
56
+	 * @param string $version
57
+	 */
58
+	public static function init($plugin_file, $version)
59
+	{
60
+		self::$plugin_file = $plugin_file;
61
+		self::$version = $version;
62
+		self::$plugin_basename = plugin_basename($plugin_file);
63
+		self::$plugin_path = plugin_dir_path($plugin_file);
64
+		self::$plugin_url = plugin_dir_url($plugin_file);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return string
71
+	 * @throws DomainException
72
+	 */
73
+	public static function pluginFile()
74
+	{
75
+		self::verifyInitialized(__METHOD__);
76
+		return self::$plugin_file;
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * @return string
83
+	 * @throws DomainException
84
+	 */
85
+	public static function pluginBasename()
86
+	{
87
+		self::verifyInitialized(__METHOD__);
88
+		return self::$plugin_basename;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * @return string
95
+	 * @throws DomainException
96
+	 */
97
+	public static function pluginPath()
98
+	{
99
+		self::verifyInitialized(__METHOD__);
100
+		return self::$plugin_path;
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @return string
107
+	 * @throws DomainException
108
+	 */
109
+	public static function pluginUrl()
110
+	{
111
+		self::verifyInitialized(__METHOD__);
112
+		return self::$plugin_url;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 * @throws DomainException
120
+	 */
121
+	public static function version()
122
+	{
123
+		self::verifyInitialized(__METHOD__);
124
+		return self::$version;
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 * @param string $method
131
+	 * @throws DomainException
132
+	 */
133
+	private static function verifyInitialized($method)
134
+	{
135
+		if (self::$plugin_file === '') {
136
+			throw new DomainException(
137
+				sprintf(
138
+					esc_html__(
139
+						'%1$s needs to be called before %2$s can return a value.',
140
+						'event_espresso'
141
+					),
142
+					get_called_class() . '::init()',
143
+					"{$method}()"
144
+				)
145
+			);
146
+		}
147
+	}
148 148
 
149 149
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@
 block discarded – undo
139 139
                         '%1$s needs to be called before %2$s can return a value.',
140 140
                         'event_espresso'
141 141
                     ),
142
-                    get_called_class() . '::init()',
142
+                    get_called_class().'::init()',
143 143
                     "{$method}()"
144 144
                 )
145 145
             );
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +637 added lines, -637 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
16 16
 
17 17
 if (! defined('EVENT_ESPRESSO_VERSION')) {
18
-    exit('No direct script access allowed');
18
+	exit('No direct script access allowed');
19 19
 }
20 20
 
21 21
 
@@ -34,642 +34,642 @@  discard block
 block discarded – undo
34 34
 abstract class FormHandler implements FormHandlerInterface
35 35
 {
36 36
 
37
-    /**
38
-     * will add opening and closing HTML form tags as well as a submit button
39
-     */
40
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
41
-
42
-    /**
43
-     * will add opening and closing HTML form tags but NOT a submit button
44
-     */
45
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
46
-
47
-    /**
48
-     * will NOT add opening and closing HTML form tags but will add a submit button
49
-     */
50
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
51
-
52
-    /**
53
-     * will NOT add opening and closing HTML form tags NOR a submit button
54
-     */
55
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
56
-
57
-    /**
58
-     * if set to false, then this form has no displayable content,
59
-     * and will only be used for processing data sent passed via GET or POST
60
-     * defaults to true ( ie: form has displayable content )
61
-     *
62
-     * @var boolean $displayable
63
-     */
64
-    private $displayable = true;
65
-
66
-    /**
67
-     * @var string $form_name
68
-     */
69
-    private $form_name;
70
-
71
-    /**
72
-     * @var string $admin_name
73
-     */
74
-    private $admin_name;
75
-
76
-    /**
77
-     * @var string $slug
78
-     */
79
-    private $slug;
80
-
81
-    /**
82
-     * @var string $submit_btn_text
83
-     */
84
-    private $submit_btn_text;
85
-
86
-    /**
87
-     * @var string $form_action
88
-     */
89
-    private $form_action;
90
-
91
-    /**
92
-     * form params in key value pairs
93
-     * can be added to form action URL or as hidden inputs
94
-     *
95
-     * @var array $form_args
96
-     */
97
-    private $form_args = array();
98
-
99
-    /**
100
-     * value of one of the string constant above
101
-     *
102
-     * @var string $form_config
103
-     */
104
-    private $form_config;
105
-
106
-    /**
107
-     * whether or not the form was determined to be invalid
108
-     *
109
-     * @var boolean $form_has_errors
110
-     */
111
-    private $form_has_errors;
112
-
113
-    /**
114
-     * the absolute top level form section being used on the page
115
-     *
116
-     * @var EE_Form_Section_Proper $form
117
-     */
118
-    private $form;
119
-
120
-    /**
121
-     * @var EE_Registry $registry
122
-     */
123
-    protected $registry;
124
-
125
-
126
-
127
-    /**
128
-     * Form constructor.
129
-     *
130
-     * @param string      $form_name
131
-     * @param string      $admin_name
132
-     * @param string      $slug
133
-     * @param string      $form_action
134
-     * @param string      $form_config
135
-     * @param EE_Registry $registry
136
-     * @throws InvalidDataTypeException
137
-     * @throws DomainException
138
-     * @throws InvalidArgumentException
139
-     */
140
-    public function __construct(
141
-        $form_name,
142
-        $admin_name,
143
-        $slug,
144
-        $form_action = '',
145
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
146
-        EE_Registry $registry
147
-    ) {
148
-        $this->setFormName($form_name);
149
-        $this->setAdminName($admin_name);
150
-        $this->setSlug($slug);
151
-        $this->setFormAction($form_action);
152
-        $this->setFormConfig($form_config);
153
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
154
-        $this->registry = $registry;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * @return array
161
-     */
162
-    public static function getFormConfigConstants()
163
-    {
164
-        return array(
165
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
166
-            FormHandler::ADD_FORM_TAGS_ONLY,
167
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
168
-            FormHandler::DO_NOT_SETUP_FORM,
169
-        );
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * @param bool $for_display
176
-     * @return EE_Form_Section_Proper
177
-     * @throws EE_Error
178
-     * @throws LogicException
179
-     */
180
-    public function form($for_display = false)
181
-    {
182
-        if (! $this->formIsValid()) {
183
-            return null;
184
-        }
185
-        if ($for_display) {
186
-            $form_config = $this->formConfig();
187
-            if (
188
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
189
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
190
-            ) {
191
-                $this->appendSubmitButton();
192
-                $this->clearFormButtonFloats();
193
-            }
194
-        }
195
-        return $this->form;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @return boolean
202
-     * @throws LogicException
203
-     */
204
-    public function formIsValid()
205
-    {
206
-        if (! $this->form instanceof EE_Form_Section_Proper) {
207
-            static $generated = false;
208
-            if (! $generated) {
209
-                $generated = true;
210
-                $form = apply_filters(
211
-                    'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
212
-                    $this->generate(),
213
-                    $this
214
-                );
215
-                if ($form instanceof EE_Form_Section_Proper) {
216
-                    $this->setForm($form);
217
-                }
218
-            }
219
-            return $this->verifyForm();
220
-        }
221
-        return true;
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * @return boolean
228
-     * @throws LogicException
229
-     */
230
-    public function verifyForm()
231
-    {
232
-        if ($this->form instanceof EE_Form_Section_Proper) {
233
-            return true;
234
-        }
235
-        throw new LogicException(
236
-            sprintf(
237
-                esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
238
-                $this->form_name
239
-            )
240
-        );
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * @param EE_Form_Section_Proper $form
247
-     */
248
-    public function setForm(EE_Form_Section_Proper $form)
249
-    {
250
-        $this->form = $form;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * @return boolean
257
-     */
258
-    public function displayable()
259
-    {
260
-        return $this->displayable;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @param boolean $displayable
267
-     */
268
-    public function setDisplayable($displayable = false)
269
-    {
270
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * a public name for the form that can be displayed on the frontend of a site
277
-     *
278
-     * @return string
279
-     */
280
-    public function formName()
281
-    {
282
-        return $this->form_name;
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * @param string $form_name
289
-     * @throws InvalidDataTypeException
290
-     */
291
-    public function setFormName($form_name)
292
-    {
293
-        if (! is_string($form_name)) {
294
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
295
-        }
296
-        $this->form_name = $form_name;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * a public name for the form that can be displayed, but only in the admin
303
-     *
304
-     * @return string
305
-     */
306
-    public function adminName()
307
-    {
308
-        return $this->admin_name;
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * @param string $admin_name
315
-     * @throws InvalidDataTypeException
316
-     */
317
-    public function setAdminName($admin_name)
318
-    {
319
-        if (! is_string($admin_name)) {
320
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
321
-        }
322
-        $this->admin_name = $admin_name;
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * a URL friendly string that can be used for identifying the form
329
-     *
330
-     * @return string
331
-     */
332
-    public function slug()
333
-    {
334
-        return $this->slug;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * @param string $slug
341
-     * @throws InvalidDataTypeException
342
-     */
343
-    public function setSlug($slug)
344
-    {
345
-        if (! is_string($slug)) {
346
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
347
-        }
348
-        $this->slug = $slug;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * @return string
355
-     */
356
-    public function submitBtnText()
357
-    {
358
-        return $this->submit_btn_text;
359
-    }
360
-
361
-
362
-
363
-    /**
364
-     * @param string $submit_btn_text
365
-     * @throws InvalidDataTypeException
366
-     * @throws InvalidArgumentException
367
-     */
368
-    public function setSubmitBtnText($submit_btn_text)
369
-    {
370
-        if (! is_string($submit_btn_text)) {
371
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
372
-        }
373
-        if (empty($submit_btn_text)) {
374
-            throw new InvalidArgumentException(
375
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
376
-            );
377
-        }
378
-        $this->submit_btn_text = $submit_btn_text;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * @return string
385
-     */
386
-    public function formAction()
387
-    {
388
-        return ! empty($this->form_args)
389
-            ? add_query_arg($this->form_args, $this->form_action)
390
-            : $this->form_action;
391
-    }
392
-
393
-
394
-
395
-    /**
396
-     * @param string $form_action
397
-     * @throws InvalidDataTypeException
398
-     */
399
-    public function setFormAction($form_action)
400
-    {
401
-        if (! is_string($form_action)) {
402
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
403
-        }
404
-        $this->form_action = $form_action;
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * @param array $form_args
411
-     * @throws InvalidDataTypeException
412
-     * @throws InvalidArgumentException
413
-     */
414
-    public function addFormActionArgs($form_args = array())
415
-    {
416
-        if (is_object($form_args)) {
417
-            throw new InvalidDataTypeException(
418
-                '$form_args',
419
-                $form_args,
420
-                'anything other than an object was expected.'
421
-            );
422
-        }
423
-        if (empty($form_args)) {
424
-            throw new InvalidArgumentException(
425
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
426
-            );
427
-        }
428
-        $this->form_args = array_merge($this->form_args, $form_args);
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * @return string
435
-     */
436
-    public function formConfig()
437
-    {
438
-        return $this->form_config;
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * @param string $form_config
445
-     * @throws DomainException
446
-     */
447
-    public function setFormConfig($form_config)
448
-    {
449
-        if (
450
-        ! in_array(
451
-            $form_config,
452
-            array(
453
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
454
-                FormHandler::ADD_FORM_TAGS_ONLY,
455
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
456
-                FormHandler::DO_NOT_SETUP_FORM,
457
-            ),
458
-            true
459
-        )
460
-        ) {
461
-            throw new DomainException(
462
-                sprintf(
463
-                    esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
464
-                        'event_espresso'),
465
-                    $form_config
466
-                )
467
-            );
468
-        }
469
-        $this->form_config = $form_config;
470
-    }
471
-
472
-
473
-
474
-    /**
475
-     * called after the form is instantiated
476
-     * and used for performing any logic that needs to occur early
477
-     * before any of the other methods are called.
478
-     * returns true if everything is ok to proceed,
479
-     * and false if no further form logic should be implemented
480
-     *
481
-     * @return boolean
482
-     */
483
-    public function initialize()
484
-    {
485
-        $this->form_has_errors = EE_Error::has_error(true);
486
-        return true;
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * used for setting up css and js
493
-     *
494
-     * @return void
495
-     * @throws LogicException
496
-     * @throws EE_Error
497
-     */
498
-    public function enqueueStylesAndScripts()
499
-    {
500
-        $this->form(false)->enqueue_js();
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * creates and returns the actual form
507
-     *
508
-     * @return EE_Form_Section_Proper
509
-     */
510
-    abstract public function generate();
511
-
512
-
513
-
514
-    /**
515
-     * creates and returns an EE_Submit_Input labeled "Submit"
516
-     *
517
-     * @param string $text
518
-     * @return EE_Submit_Input
519
-     */
520
-    public function generateSubmitButton($text = '')
521
-    {
522
-        $text = ! empty($text) ? $text : $this->submitBtnText();
523
-        return new EE_Submit_Input(
524
-            array(
525
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
526
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
527
-                'html_class'            => 'ee-form-submit',
528
-                'html_label'            => '&nbsp;',
529
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
530
-                'default'               => $text,
531
-            )
532
-        );
533
-    }
534
-
535
-
536
-
537
-    /**
538
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
539
-     *
540
-     * @param string $text
541
-     * @return void
542
-     * @throws LogicException
543
-     * @throws EE_Error
544
-     */
545
-    public function appendSubmitButton($text = '')
546
-    {
547
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
548
-            return;
549
-        }
550
-        $this->form->add_subsections(
551
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
552
-            null,
553
-            false
554
-        );
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * creates and returns an EE_Submit_Input labeled "Cancel"
561
-     *
562
-     * @param string $text
563
-     * @return EE_Submit_Input
564
-     */
565
-    public function generateCancelButton($text = '')
566
-    {
567
-        $cancel_button = new EE_Submit_Input(
568
-            array(
569
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
570
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
571
-                'html_class'            => 'ee-cancel-form',
572
-                'html_label'            => '&nbsp;',
573
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
574
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
575
-            )
576
-        );
577
-        $cancel_button->set_button_css_attributes(false);
578
-        return $cancel_button;
579
-    }
580
-
581
-
582
-
583
-    /**
584
-     * appends a float clearing div onto end of form
585
-     *
586
-     * @return void
587
-     * @throws EE_Error
588
-     */
589
-    public function clearFormButtonFloats()
590
-    {
591
-        $this->form->add_subsections(
592
-            array(
593
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
594
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
595
-                ),
596
-            ),
597
-            null,
598
-            false
599
-        );
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
606
-     * returns a string of HTML that can be directly echoed in a template
607
-     *
608
-     * @return string
609
-     * @throws LogicException
610
-     * @throws EE_Error
611
-     */
612
-    public function display()
613
-    {
614
-        $form_html = apply_filters(
615
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
616
-            ''
617
-        );
618
-        $form_config = $this->formConfig();
619
-        if (
620
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
-        ) {
623
-            $form_html .= $this->form()->form_open($this->formAction());
624
-        }
625
-        $form_html .= $this->form(true)->get_html($this->form_has_errors);
626
-        if (
627
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
628
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
629
-        ) {
630
-            $form_html .= $this->form()->form_close();
631
-        }
632
-        $form_html .= apply_filters(
633
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
634
-            ''
635
-        );
636
-        return $form_html;
637
-    }
638
-
639
-
640
-
641
-    /**
642
-     * handles processing the form submission
643
-     * returns true or false depending on whether the form was processed successfully or not
644
-     *
645
-     * @param array $submitted_form_data
646
-     * @return array
647
-     * @throws EE_Error
648
-     * @throws LogicException
649
-     * @throws InvalidFormSubmissionException
650
-     */
651
-    public function process($submitted_form_data = array())
652
-    {
653
-        if (! $this->form()->was_submitted($submitted_form_data)) {
654
-            throw new InvalidFormSubmissionException($this->form_name);
655
-        }
656
-        $this->form(true)->receive_form_submission($submitted_form_data);
657
-        if (! $this->form()->is_valid()) {
658
-            throw new InvalidFormSubmissionException(
659
-                $this->form_name,
660
-                sprintf(
661
-                    esc_html__(
662
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
663
-                        'event_espresso'
664
-                    ),
665
-                    $this->form_name,
666
-                    '<br />',
667
-                    $this->form()->submission_error_message()
668
-                )
669
-            );
670
-        }
671
-        return $this->form()->valid_data();
672
-    }
37
+	/**
38
+	 * will add opening and closing HTML form tags as well as a submit button
39
+	 */
40
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
41
+
42
+	/**
43
+	 * will add opening and closing HTML form tags but NOT a submit button
44
+	 */
45
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
46
+
47
+	/**
48
+	 * will NOT add opening and closing HTML form tags but will add a submit button
49
+	 */
50
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
51
+
52
+	/**
53
+	 * will NOT add opening and closing HTML form tags NOR a submit button
54
+	 */
55
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
56
+
57
+	/**
58
+	 * if set to false, then this form has no displayable content,
59
+	 * and will only be used for processing data sent passed via GET or POST
60
+	 * defaults to true ( ie: form has displayable content )
61
+	 *
62
+	 * @var boolean $displayable
63
+	 */
64
+	private $displayable = true;
65
+
66
+	/**
67
+	 * @var string $form_name
68
+	 */
69
+	private $form_name;
70
+
71
+	/**
72
+	 * @var string $admin_name
73
+	 */
74
+	private $admin_name;
75
+
76
+	/**
77
+	 * @var string $slug
78
+	 */
79
+	private $slug;
80
+
81
+	/**
82
+	 * @var string $submit_btn_text
83
+	 */
84
+	private $submit_btn_text;
85
+
86
+	/**
87
+	 * @var string $form_action
88
+	 */
89
+	private $form_action;
90
+
91
+	/**
92
+	 * form params in key value pairs
93
+	 * can be added to form action URL or as hidden inputs
94
+	 *
95
+	 * @var array $form_args
96
+	 */
97
+	private $form_args = array();
98
+
99
+	/**
100
+	 * value of one of the string constant above
101
+	 *
102
+	 * @var string $form_config
103
+	 */
104
+	private $form_config;
105
+
106
+	/**
107
+	 * whether or not the form was determined to be invalid
108
+	 *
109
+	 * @var boolean $form_has_errors
110
+	 */
111
+	private $form_has_errors;
112
+
113
+	/**
114
+	 * the absolute top level form section being used on the page
115
+	 *
116
+	 * @var EE_Form_Section_Proper $form
117
+	 */
118
+	private $form;
119
+
120
+	/**
121
+	 * @var EE_Registry $registry
122
+	 */
123
+	protected $registry;
124
+
125
+
126
+
127
+	/**
128
+	 * Form constructor.
129
+	 *
130
+	 * @param string      $form_name
131
+	 * @param string      $admin_name
132
+	 * @param string      $slug
133
+	 * @param string      $form_action
134
+	 * @param string      $form_config
135
+	 * @param EE_Registry $registry
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws DomainException
138
+	 * @throws InvalidArgumentException
139
+	 */
140
+	public function __construct(
141
+		$form_name,
142
+		$admin_name,
143
+		$slug,
144
+		$form_action = '',
145
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
146
+		EE_Registry $registry
147
+	) {
148
+		$this->setFormName($form_name);
149
+		$this->setAdminName($admin_name);
150
+		$this->setSlug($slug);
151
+		$this->setFormAction($form_action);
152
+		$this->setFormConfig($form_config);
153
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
154
+		$this->registry = $registry;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * @return array
161
+	 */
162
+	public static function getFormConfigConstants()
163
+	{
164
+		return array(
165
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
166
+			FormHandler::ADD_FORM_TAGS_ONLY,
167
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
168
+			FormHandler::DO_NOT_SETUP_FORM,
169
+		);
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * @param bool $for_display
176
+	 * @return EE_Form_Section_Proper
177
+	 * @throws EE_Error
178
+	 * @throws LogicException
179
+	 */
180
+	public function form($for_display = false)
181
+	{
182
+		if (! $this->formIsValid()) {
183
+			return null;
184
+		}
185
+		if ($for_display) {
186
+			$form_config = $this->formConfig();
187
+			if (
188
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
189
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
190
+			) {
191
+				$this->appendSubmitButton();
192
+				$this->clearFormButtonFloats();
193
+			}
194
+		}
195
+		return $this->form;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @return boolean
202
+	 * @throws LogicException
203
+	 */
204
+	public function formIsValid()
205
+	{
206
+		if (! $this->form instanceof EE_Form_Section_Proper) {
207
+			static $generated = false;
208
+			if (! $generated) {
209
+				$generated = true;
210
+				$form = apply_filters(
211
+					'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
212
+					$this->generate(),
213
+					$this
214
+				);
215
+				if ($form instanceof EE_Form_Section_Proper) {
216
+					$this->setForm($form);
217
+				}
218
+			}
219
+			return $this->verifyForm();
220
+		}
221
+		return true;
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * @return boolean
228
+	 * @throws LogicException
229
+	 */
230
+	public function verifyForm()
231
+	{
232
+		if ($this->form instanceof EE_Form_Section_Proper) {
233
+			return true;
234
+		}
235
+		throw new LogicException(
236
+			sprintf(
237
+				esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
238
+				$this->form_name
239
+			)
240
+		);
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * @param EE_Form_Section_Proper $form
247
+	 */
248
+	public function setForm(EE_Form_Section_Proper $form)
249
+	{
250
+		$this->form = $form;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * @return boolean
257
+	 */
258
+	public function displayable()
259
+	{
260
+		return $this->displayable;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @param boolean $displayable
267
+	 */
268
+	public function setDisplayable($displayable = false)
269
+	{
270
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * a public name for the form that can be displayed on the frontend of a site
277
+	 *
278
+	 * @return string
279
+	 */
280
+	public function formName()
281
+	{
282
+		return $this->form_name;
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * @param string $form_name
289
+	 * @throws InvalidDataTypeException
290
+	 */
291
+	public function setFormName($form_name)
292
+	{
293
+		if (! is_string($form_name)) {
294
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
295
+		}
296
+		$this->form_name = $form_name;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * a public name for the form that can be displayed, but only in the admin
303
+	 *
304
+	 * @return string
305
+	 */
306
+	public function adminName()
307
+	{
308
+		return $this->admin_name;
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * @param string $admin_name
315
+	 * @throws InvalidDataTypeException
316
+	 */
317
+	public function setAdminName($admin_name)
318
+	{
319
+		if (! is_string($admin_name)) {
320
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
321
+		}
322
+		$this->admin_name = $admin_name;
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * a URL friendly string that can be used for identifying the form
329
+	 *
330
+	 * @return string
331
+	 */
332
+	public function slug()
333
+	{
334
+		return $this->slug;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * @param string $slug
341
+	 * @throws InvalidDataTypeException
342
+	 */
343
+	public function setSlug($slug)
344
+	{
345
+		if (! is_string($slug)) {
346
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
347
+		}
348
+		$this->slug = $slug;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * @return string
355
+	 */
356
+	public function submitBtnText()
357
+	{
358
+		return $this->submit_btn_text;
359
+	}
360
+
361
+
362
+
363
+	/**
364
+	 * @param string $submit_btn_text
365
+	 * @throws InvalidDataTypeException
366
+	 * @throws InvalidArgumentException
367
+	 */
368
+	public function setSubmitBtnText($submit_btn_text)
369
+	{
370
+		if (! is_string($submit_btn_text)) {
371
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
372
+		}
373
+		if (empty($submit_btn_text)) {
374
+			throw new InvalidArgumentException(
375
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
376
+			);
377
+		}
378
+		$this->submit_btn_text = $submit_btn_text;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * @return string
385
+	 */
386
+	public function formAction()
387
+	{
388
+		return ! empty($this->form_args)
389
+			? add_query_arg($this->form_args, $this->form_action)
390
+			: $this->form_action;
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 * @param string $form_action
397
+	 * @throws InvalidDataTypeException
398
+	 */
399
+	public function setFormAction($form_action)
400
+	{
401
+		if (! is_string($form_action)) {
402
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
403
+		}
404
+		$this->form_action = $form_action;
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * @param array $form_args
411
+	 * @throws InvalidDataTypeException
412
+	 * @throws InvalidArgumentException
413
+	 */
414
+	public function addFormActionArgs($form_args = array())
415
+	{
416
+		if (is_object($form_args)) {
417
+			throw new InvalidDataTypeException(
418
+				'$form_args',
419
+				$form_args,
420
+				'anything other than an object was expected.'
421
+			);
422
+		}
423
+		if (empty($form_args)) {
424
+			throw new InvalidArgumentException(
425
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
426
+			);
427
+		}
428
+		$this->form_args = array_merge($this->form_args, $form_args);
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * @return string
435
+	 */
436
+	public function formConfig()
437
+	{
438
+		return $this->form_config;
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * @param string $form_config
445
+	 * @throws DomainException
446
+	 */
447
+	public function setFormConfig($form_config)
448
+	{
449
+		if (
450
+		! in_array(
451
+			$form_config,
452
+			array(
453
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
454
+				FormHandler::ADD_FORM_TAGS_ONLY,
455
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
456
+				FormHandler::DO_NOT_SETUP_FORM,
457
+			),
458
+			true
459
+		)
460
+		) {
461
+			throw new DomainException(
462
+				sprintf(
463
+					esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
464
+						'event_espresso'),
465
+					$form_config
466
+				)
467
+			);
468
+		}
469
+		$this->form_config = $form_config;
470
+	}
471
+
472
+
473
+
474
+	/**
475
+	 * called after the form is instantiated
476
+	 * and used for performing any logic that needs to occur early
477
+	 * before any of the other methods are called.
478
+	 * returns true if everything is ok to proceed,
479
+	 * and false if no further form logic should be implemented
480
+	 *
481
+	 * @return boolean
482
+	 */
483
+	public function initialize()
484
+	{
485
+		$this->form_has_errors = EE_Error::has_error(true);
486
+		return true;
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * used for setting up css and js
493
+	 *
494
+	 * @return void
495
+	 * @throws LogicException
496
+	 * @throws EE_Error
497
+	 */
498
+	public function enqueueStylesAndScripts()
499
+	{
500
+		$this->form(false)->enqueue_js();
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * creates and returns the actual form
507
+	 *
508
+	 * @return EE_Form_Section_Proper
509
+	 */
510
+	abstract public function generate();
511
+
512
+
513
+
514
+	/**
515
+	 * creates and returns an EE_Submit_Input labeled "Submit"
516
+	 *
517
+	 * @param string $text
518
+	 * @return EE_Submit_Input
519
+	 */
520
+	public function generateSubmitButton($text = '')
521
+	{
522
+		$text = ! empty($text) ? $text : $this->submitBtnText();
523
+		return new EE_Submit_Input(
524
+			array(
525
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
526
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
527
+				'html_class'            => 'ee-form-submit',
528
+				'html_label'            => '&nbsp;',
529
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
530
+				'default'               => $text,
531
+			)
532
+		);
533
+	}
534
+
535
+
536
+
537
+	/**
538
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
539
+	 *
540
+	 * @param string $text
541
+	 * @return void
542
+	 * @throws LogicException
543
+	 * @throws EE_Error
544
+	 */
545
+	public function appendSubmitButton($text = '')
546
+	{
547
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
548
+			return;
549
+		}
550
+		$this->form->add_subsections(
551
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
552
+			null,
553
+			false
554
+		);
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
561
+	 *
562
+	 * @param string $text
563
+	 * @return EE_Submit_Input
564
+	 */
565
+	public function generateCancelButton($text = '')
566
+	{
567
+		$cancel_button = new EE_Submit_Input(
568
+			array(
569
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
570
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
571
+				'html_class'            => 'ee-cancel-form',
572
+				'html_label'            => '&nbsp;',
573
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
574
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
575
+			)
576
+		);
577
+		$cancel_button->set_button_css_attributes(false);
578
+		return $cancel_button;
579
+	}
580
+
581
+
582
+
583
+	/**
584
+	 * appends a float clearing div onto end of form
585
+	 *
586
+	 * @return void
587
+	 * @throws EE_Error
588
+	 */
589
+	public function clearFormButtonFloats()
590
+	{
591
+		$this->form->add_subsections(
592
+			array(
593
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
594
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
595
+				),
596
+			),
597
+			null,
598
+			false
599
+		);
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
606
+	 * returns a string of HTML that can be directly echoed in a template
607
+	 *
608
+	 * @return string
609
+	 * @throws LogicException
610
+	 * @throws EE_Error
611
+	 */
612
+	public function display()
613
+	{
614
+		$form_html = apply_filters(
615
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
616
+			''
617
+		);
618
+		$form_config = $this->formConfig();
619
+		if (
620
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
+		) {
623
+			$form_html .= $this->form()->form_open($this->formAction());
624
+		}
625
+		$form_html .= $this->form(true)->get_html($this->form_has_errors);
626
+		if (
627
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
628
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
629
+		) {
630
+			$form_html .= $this->form()->form_close();
631
+		}
632
+		$form_html .= apply_filters(
633
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
634
+			''
635
+		);
636
+		return $form_html;
637
+	}
638
+
639
+
640
+
641
+	/**
642
+	 * handles processing the form submission
643
+	 * returns true or false depending on whether the form was processed successfully or not
644
+	 *
645
+	 * @param array $submitted_form_data
646
+	 * @return array
647
+	 * @throws EE_Error
648
+	 * @throws LogicException
649
+	 * @throws InvalidFormSubmissionException
650
+	 */
651
+	public function process($submitted_form_data = array())
652
+	{
653
+		if (! $this->form()->was_submitted($submitted_form_data)) {
654
+			throw new InvalidFormSubmissionException($this->form_name);
655
+		}
656
+		$this->form(true)->receive_form_submission($submitted_form_data);
657
+		if (! $this->form()->is_valid()) {
658
+			throw new InvalidFormSubmissionException(
659
+				$this->form_name,
660
+				sprintf(
661
+					esc_html__(
662
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
663
+						'event_espresso'
664
+					),
665
+					$this->form_name,
666
+					'<br />',
667
+					$this->form()->submission_error_message()
668
+				)
669
+			);
670
+		}
671
+		return $this->form()->valid_data();
672
+	}
673 673
 
674 674
 
675 675
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 use EventEspresso\core\exceptions\InvalidDataTypeException;
15 15
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
16 16
 
17
-if (! defined('EVENT_ESPRESSO_VERSION')) {
17
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
18 18
     exit('No direct script access allowed');
19 19
 }
20 20
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function form($for_display = false)
181 181
     {
182
-        if (! $this->formIsValid()) {
182
+        if ( ! $this->formIsValid()) {
183 183
             return null;
184 184
         }
185 185
         if ($for_display) {
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
      */
204 204
     public function formIsValid()
205 205
     {
206
-        if (! $this->form instanceof EE_Form_Section_Proper) {
206
+        if ( ! $this->form instanceof EE_Form_Section_Proper) {
207 207
             static $generated = false;
208
-            if (! $generated) {
208
+            if ( ! $generated) {
209 209
                 $generated = true;
210 210
                 $form = apply_filters(
211 211
                     'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function setFormName($form_name)
292 292
     {
293
-        if (! is_string($form_name)) {
293
+        if ( ! is_string($form_name)) {
294 294
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
295 295
         }
296 296
         $this->form_name = $form_name;
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      */
317 317
     public function setAdminName($admin_name)
318 318
     {
319
-        if (! is_string($admin_name)) {
319
+        if ( ! is_string($admin_name)) {
320 320
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
321 321
         }
322 322
         $this->admin_name = $admin_name;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      */
343 343
     public function setSlug($slug)
344 344
     {
345
-        if (! is_string($slug)) {
345
+        if ( ! is_string($slug)) {
346 346
             throw new InvalidDataTypeException('$slug', $slug, 'string');
347 347
         }
348 348
         $this->slug = $slug;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
      */
368 368
     public function setSubmitBtnText($submit_btn_text)
369 369
     {
370
-        if (! is_string($submit_btn_text)) {
370
+        if ( ! is_string($submit_btn_text)) {
371 371
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
372 372
         }
373 373
         if (empty($submit_btn_text)) {
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      */
399 399
     public function setFormAction($form_action)
400 400
     {
401
-        if (! is_string($form_action)) {
401
+        if ( ! is_string($form_action)) {
402 402
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
403 403
         }
404 404
         $this->form_action = $form_action;
@@ -522,11 +522,11 @@  discard block
 block discarded – undo
522 522
         $text = ! empty($text) ? $text : $this->submitBtnText();
523 523
         return new EE_Submit_Input(
524 524
             array(
525
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
526
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
525
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
526
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
527 527
                 'html_class'            => 'ee-form-submit',
528 528
                 'html_label'            => '&nbsp;',
529
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
529
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
530 530
                 'default'               => $text,
531 531
             )
532 532
         );
@@ -544,11 +544,11 @@  discard block
 block discarded – undo
544 544
      */
545 545
     public function appendSubmitButton($text = '')
546 546
     {
547
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
547
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
548 548
             return;
549 549
         }
550 550
         $this->form->add_subsections(
551
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
551
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
552 552
             null,
553 553
             false
554 554
         );
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
     {
567 567
         $cancel_button = new EE_Submit_Input(
568 568
             array(
569
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
570
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
569
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
570
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
571 571
                 'html_class'            => 'ee-cancel-form',
572 572
                 'html_label'            => '&nbsp;',
573
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
573
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
574 574
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
575 575
             )
576 576
         );
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
         $this->form->add_subsections(
592 592
             array(
593 593
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
594
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
594
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
595 595
                 ),
596 596
             ),
597 597
             null,
@@ -650,11 +650,11 @@  discard block
 block discarded – undo
650 650
      */
651 651
     public function process($submitted_form_data = array())
652 652
     {
653
-        if (! $this->form()->was_submitted($submitted_form_data)) {
653
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
654 654
             throw new InvalidFormSubmissionException($this->form_name);
655 655
         }
656 656
         $this->form(true)->receive_form_submission($submitted_form_data);
657
-        if (! $this->form()->is_valid()) {
657
+        if ( ! $this->form()->is_valid()) {
658 658
             throw new InvalidFormSubmissionException(
659 659
                 $this->form_name,
660 660
                 sprintf(
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +3299 added lines, -3299 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\InterminableInterface;
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * Event Espresso
@@ -30,2114 +30,2114 @@  discard block
 block discarded – undo
30 30
 {
31 31
 
32 32
 
33
-    //set in _init_page_props()
34
-    public $page_slug;
33
+	//set in _init_page_props()
34
+	public $page_slug;
35 35
 
36
-    public $page_label;
36
+	public $page_label;
37 37
 
38
-    public $page_folder;
38
+	public $page_folder;
39 39
 
40
-    //set in define_page_props()
41
-    protected $_admin_base_url;
40
+	//set in define_page_props()
41
+	protected $_admin_base_url;
42 42
 
43
-    protected $_admin_base_path;
43
+	protected $_admin_base_path;
44 44
 
45
-    protected $_admin_page_title;
45
+	protected $_admin_page_title;
46 46
 
47
-    protected $_labels;
47
+	protected $_labels;
48 48
 
49 49
 
50
-    //set early within EE_Admin_Init
51
-    protected $_wp_page_slug;
50
+	//set early within EE_Admin_Init
51
+	protected $_wp_page_slug;
52 52
 
53
-    //navtabs
54
-    protected $_nav_tabs;
53
+	//navtabs
54
+	protected $_nav_tabs;
55 55
 
56
-    protected $_default_nav_tab_name;
56
+	protected $_default_nav_tab_name;
57 57
 
58
-    //helptourstops
59
-    protected $_help_tour = array();
58
+	//helptourstops
59
+	protected $_help_tour = array();
60 60
 
61 61
 
62
-    //template variables (used by templates)
63
-    protected $_template_path;
62
+	//template variables (used by templates)
63
+	protected $_template_path;
64 64
 
65
-    protected $_column_template_path;
65
+	protected $_column_template_path;
66 66
 
67
-    /**
68
-     * @var array $_template_args
69
-     */
70
-    protected $_template_args = array();
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = array();
71 71
 
72
-    /**
73
-     * this will hold the list table object for a given view.
74
-     *
75
-     * @var EE_Admin_List_Table $_list_table_object
76
-     */
77
-    protected $_list_table_object;
72
+	/**
73
+	 * this will hold the list table object for a given view.
74
+	 *
75
+	 * @var EE_Admin_List_Table $_list_table_object
76
+	 */
77
+	protected $_list_table_object;
78 78
 
79
-    //bools
80
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79
+	//bools
80
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
81 81
 
82
-    protected $_routing;
82
+	protected $_routing;
83 83
 
84
-    //list table args
85
-    protected $_view;
84
+	//list table args
85
+	protected $_view;
86 86
 
87
-    protected $_views;
87
+	protected $_views;
88 88
 
89 89
 
90
-    //action => method pairs used for routing incoming requests
91
-    protected $_page_routes;
90
+	//action => method pairs used for routing incoming requests
91
+	protected $_page_routes;
92 92
 
93
-    protected $_page_config;
93
+	protected $_page_config;
94 94
 
95
-    //the current page route and route config
96
-    protected $_route;
95
+	//the current page route and route config
96
+	protected $_route;
97 97
 
98
-    protected $_route_config;
98
+	protected $_route_config;
99 99
 
100
-    /**
101
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
102
-     * actions.
103
-     *
104
-     * @since 4.6.x
105
-     * @var array.
106
-     */
107
-    protected $_default_route_query_args;
100
+	/**
101
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
102
+	 * actions.
103
+	 *
104
+	 * @since 4.6.x
105
+	 * @var array.
106
+	 */
107
+	protected $_default_route_query_args;
108 108
 
109
-    //set via request page and action args.
110
-    protected $_current_page;
109
+	//set via request page and action args.
110
+	protected $_current_page;
111 111
 
112
-    protected $_current_view;
112
+	protected $_current_view;
113 113
 
114
-    protected $_current_page_view_url;
114
+	protected $_current_page_view_url;
115 115
 
116
-    //sanitized request action (and nonce)
117
-    /**
118
-     * @var string $_req_action
119
-     */
120
-    protected $_req_action;
116
+	//sanitized request action (and nonce)
117
+	/**
118
+	 * @var string $_req_action
119
+	 */
120
+	protected $_req_action;
121 121
 
122
-    /**
123
-     * @var string $_req_nonce
124
-     */
125
-    protected $_req_nonce;
122
+	/**
123
+	 * @var string $_req_nonce
124
+	 */
125
+	protected $_req_nonce;
126 126
 
127
-    //search related
128
-    protected $_search_btn_label;
127
+	//search related
128
+	protected $_search_btn_label;
129 129
 
130
-    protected $_search_box_callback;
130
+	protected $_search_box_callback;
131 131
 
132
-    /**
133
-     * WP Current Screen object
134
-     *
135
-     * @var WP_Screen
136
-     */
137
-    protected $_current_screen;
132
+	/**
133
+	 * WP Current Screen object
134
+	 *
135
+	 * @var WP_Screen
136
+	 */
137
+	protected $_current_screen;
138 138
 
139
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
140
-    protected $_hook_obj;
139
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
140
+	protected $_hook_obj;
141 141
 
142
-    //for holding incoming request data
143
-    protected $_req_data;
142
+	//for holding incoming request data
143
+	protected $_req_data;
144 144
 
145
-    // yes / no array for admin form fields
146
-    protected $_yes_no_values = array();
147
-
148
-    //some default things shared by all child classes
149
-    protected $_default_espresso_metaboxes;
150
-
151
-    /**
152
-     *    EE_Registry Object
153
-     *
154
-     * @var    EE_Registry
155
-     * @access    protected
156
-     */
157
-    protected $EE = null;
158
-
159
-
160
-
161
-    /**
162
-     * This is just a property that flags whether the given route is a caffeinated route or not.
163
-     *
164
-     * @var boolean
165
-     */
166
-    protected $_is_caf = false;
167
-
168
-
169
-
170
-    /**
171
-     * @Constructor
172
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
173
-     * @access public
174
-     */
175
-    public function __construct($routing = true)
176
-    {
177
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
178
-            $this->_is_caf = true;
179
-        }
180
-        $this->_yes_no_values = array(
181
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
182
-                array('id' => false, 'text' => __('No', 'event_espresso')),
183
-        );
184
-        //set the _req_data property.
185
-        $this->_req_data = array_merge($_GET, $_POST);
186
-        //routing enabled?
187
-        $this->_routing = $routing;
188
-        //set initial page props (child method)
189
-        $this->_init_page_props();
190
-        //set global defaults
191
-        $this->_set_defaults();
192
-        //set early because incoming requests could be ajax related and we need to register those hooks.
193
-        $this->_global_ajax_hooks();
194
-        $this->_ajax_hooks();
195
-        //other_page_hooks have to be early too.
196
-        $this->_do_other_page_hooks();
197
-        //This just allows us to have extending classes do something specific
198
-        // before the parent constructor runs _page_setup().
199
-        if (method_exists($this, '_before_page_setup')) {
200
-            $this->_before_page_setup();
201
-        }
202
-        //set up page dependencies
203
-        $this->_page_setup();
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * _init_page_props
210
-     * Child classes use to set at least the following properties:
211
-     * $page_slug.
212
-     * $page_label.
213
-     *
214
-     * @abstract
215
-     * @access protected
216
-     * @return void
217
-     */
218
-    abstract protected function _init_page_props();
219
-
220
-
221
-
222
-    /**
223
-     * _ajax_hooks
224
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
225
-     * Note: within the ajax callback methods.
226
-     *
227
-     * @abstract
228
-     * @access protected
229
-     * @return void
230
-     */
231
-    abstract protected function _ajax_hooks();
232
-
233
-
234
-
235
-    /**
236
-     * _define_page_props
237
-     * child classes define page properties in here.  Must include at least:
238
-     * $_admin_base_url = base_url for all admin pages
239
-     * $_admin_page_title = default admin_page_title for admin pages
240
-     * $_labels = array of default labels for various automatically generated elements:
241
-     *    array(
242
-     *        'buttons' => array(
243
-     *            'add' => __('label for add new button'),
244
-     *            'edit' => __('label for edit button'),
245
-     *            'delete' => __('label for delete button')
246
-     *            )
247
-     *        )
248
-     *
249
-     * @abstract
250
-     * @access protected
251
-     * @return void
252
-     */
253
-    abstract protected function _define_page_props();
254
-
255
-
256
-
257
-    /**
258
-     * _set_page_routes
259
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
260
-     * route. Here's the format
261
-     * $this->_page_routes = array(
262
-     *        'default' => array(
263
-     *            'func' => '_default_method_handling_route',
264
-     *            'args' => array('array','of','args'),
265
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
266
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
267
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
268
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
269
-     *        ),
270
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
271
-     *        )
272
-     * )
273
-     *
274
-     * @abstract
275
-     * @access protected
276
-     * @return void
277
-     */
278
-    abstract protected function _set_page_routes();
279
-
280
-
281
-
282
-    /**
283
-     * _set_page_config
284
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
285
-     * Format:
286
-     * $this->_page_config = array(
287
-     *        'default' => array(
288
-     *            'labels' => array(
289
-     *                'buttons' => array(
290
-     *                    'add' => __('label for adding item'),
291
-     *                    'edit' => __('label for editing item'),
292
-     *                    'delete' => __('label for deleting item')
293
-     *                ),
294
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
295
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
296
-     *            'nav' => array(
297
-     *                'label' => __('Label for Tab', 'event_espresso').
298
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
299
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
300
-     *                'order' => 10, //required to indicate tab position.
301
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
302
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
303
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
304
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
305
-     *            this flag to make sure the necessary js gets enqueued on page load.
306
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
307
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
308
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
309
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
310
-     *                'tab_id' => array(
311
-     *                    'title' => 'tab_title',
312
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
313
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
314
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
315
-     *                    ),
316
-     *                'tab2_id' => array(
317
-     *                    'title' => 'tab2 title',
318
-     *                    'filename' => 'file_name_2'
319
-     *                    'callback' => 'callback_method_for_content',
320
-     *                 ),
321
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
322
-     *            'help_tour' => array(
323
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
324
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
325
-     *            ),
326
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
327
-     *            'require_nonce' to FALSE
328
-     *            )
329
-     * )
330
-     *
331
-     * @abstract
332
-     * @access protected
333
-     * @return void
334
-     */
335
-    abstract protected function _set_page_config();
336
-
337
-
338
-
339
-
340
-
341
-    /** end sample help_tour methods **/
342
-    /**
343
-     * _add_screen_options
344
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
345
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
346
-     *
347
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
348
-     *         see also WP_Screen object documents...
349
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
350
-     * @abstract
351
-     * @access protected
352
-     * @return void
353
-     */
354
-    abstract protected function _add_screen_options();
355
-
356
-
357
-
358
-    /**
359
-     * _add_feature_pointers
360
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
361
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
362
-     * Note: this is just a placeholder for now.  Implementation will come down the road
363
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
364
-     *
365
-     * @link   http://eamann.com/tech/wordpress-portland/
366
-     * @abstract
367
-     * @access protected
368
-     * @return void
369
-     */
370
-    abstract protected function _add_feature_pointers();
371
-
372
-
373
-
374
-    /**
375
-     * load_scripts_styles
376
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
377
-     * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
378
-     *
379
-     * @abstract
380
-     * @access public
381
-     * @return void
382
-     */
383
-    abstract public function load_scripts_styles();
384
-
385
-
386
-
387
-    /**
388
-     * admin_init
389
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
390
-     *
391
-     * @abstract
392
-     * @access public
393
-     * @return void
394
-     */
395
-    abstract public function admin_init();
396
-
397
-
398
-
399
-    /**
400
-     * admin_notices
401
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
402
-     *
403
-     * @abstract
404
-     * @access public
405
-     * @return void
406
-     */
407
-    abstract public function admin_notices();
408
-
409
-
410
-
411
-    /**
412
-     * admin_footer_scripts
413
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
414
-     *
415
-     * @access public
416
-     * @return void
417
-     */
418
-    abstract public function admin_footer_scripts();
419
-
420
-
421
-
422
-    /**
423
-     * admin_footer
424
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
425
-     *
426
-     * @access  public
427
-     * @return void
428
-     */
429
-    public function admin_footer()
430
-    {
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * _global_ajax_hooks
437
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
438
-     * Note: within the ajax callback methods.
439
-     *
440
-     * @abstract
441
-     * @access protected
442
-     * @return void
443
-     */
444
-    protected function _global_ajax_hooks()
445
-    {
446
-        //for lazy loading of metabox content
447
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
448
-    }
449
-
450
-
451
-
452
-    public function ajax_metabox_content()
453
-    {
454
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
455
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
456
-        self::cached_rss_display($contentid, $url);
457
-        wp_die();
458
-    }
459
-
460
-
461
-
462
-    /**
463
-     * _page_setup
464
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
465
-     *
466
-     * @final
467
-     * @access protected
468
-     * @return void
469
-     */
470
-    final protected function _page_setup()
471
-    {
472
-        //requires?
473
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
474
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
475
-        //next verify if we need to load anything...
476
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
477
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
478
-        global $ee_menu_slugs;
479
-        $ee_menu_slugs = (array)$ee_menu_slugs;
480
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
481
-            return;
482
-        }
483
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
484
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
485
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
486
-        }
487
-        // then set blank or -1 action values to 'default'
488
-        $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
489
-        //if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
490
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
492
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
493
-        $this->_current_view = $this->_req_action;
494
-        $this->_req_nonce = $this->_req_action . '_nonce';
495
-        $this->_define_page_props();
496
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
497
-        //default things
498
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
499
-        //set page configs
500
-        $this->_set_page_routes();
501
-        $this->_set_page_config();
502
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
503
-        if (isset($this->_req_data['wp_referer'])) {
504
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
505
-        }
506
-        //for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
507
-        if (method_exists($this, '_extend_page_config')) {
508
-            $this->_extend_page_config();
509
-        }
510
-        //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
511
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
512
-            $this->_extend_page_config_for_cpt();
513
-        }
514
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
515
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
516
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
517
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
518
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
519
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
520
-        }
521
-        //next route only if routing enabled
522
-        if ($this->_routing && ! defined('DOING_AJAX')) {
523
-            $this->_verify_routes();
524
-            //next let's just check user_access and kill if no access
525
-            $this->check_user_access();
526
-            if ($this->_is_UI_request) {
527
-                //admin_init stuff - global, all views for this page class, specific view
528
-                add_action('admin_init', array($this, 'admin_init'), 10);
529
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
530
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
531
-                }
532
-            } else {
533
-                //hijack regular WP loading and route admin request immediately
534
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
535
-                $this->route_admin_request();
536
-            }
537
-        }
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
544
-     *
545
-     * @access private
546
-     * @return void
547
-     */
548
-    private function _do_other_page_hooks()
549
-    {
550
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
551
-        foreach ($registered_pages as $page) {
552
-            //now let's setup the file name and class that should be present
553
-            $classname = str_replace('.class.php', '', $page);
554
-            //autoloaders should take care of loading file
555
-            if ( ! class_exists($classname)) {
556
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
557
-                $error_msg[] = $error_msg[0]
558
-                               . "\r\n"
559
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
560
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
561
-                throw new EE_Error(implode('||', $error_msg));
562
-            }
563
-            $a = new ReflectionClass($classname);
564
-            //notice we are passing the instance of this class to the hook object.
565
-            $hookobj[] = $a->newInstance($this);
566
-        }
567
-    }
568
-
569
-
570
-
571
-    public function load_page_dependencies()
572
-    {
573
-        try {
574
-            $this->_load_page_dependencies();
575
-        } catch (EE_Error $e) {
576
-            $e->get_error();
577
-        }
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * load_page_dependencies
584
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
585
-     *
586
-     * @access public
587
-     * @return void
588
-     */
589
-    protected function _load_page_dependencies()
590
-    {
591
-        //let's set the current_screen and screen options to override what WP set
592
-        $this->_current_screen = get_current_screen();
593
-        //load admin_notices - global, page class, and view specific
594
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
595
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
596
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
597
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
598
-        }
599
-        //load network admin_notices - global, page class, and view specific
600
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
601
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
602
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
603
-        }
604
-        //this will save any per_page screen options if they are present
605
-        $this->_set_per_page_screen_options();
606
-        //setup list table properties
607
-        $this->_set_list_table();
608
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
609
-        $this->_add_registered_meta_boxes();
610
-        $this->_add_screen_columns();
611
-        //add screen options - global, page child class, and view specific
612
-        $this->_add_global_screen_options();
613
-        $this->_add_screen_options();
614
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
615
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
616
-        }
617
-        //add help tab(s) and tours- set via page_config and qtips.
618
-        $this->_add_help_tour();
619
-        $this->_add_help_tabs();
620
-        $this->_add_qtips();
621
-        //add feature_pointers - global, page child class, and view specific
622
-        $this->_add_feature_pointers();
623
-        $this->_add_global_feature_pointers();
624
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
625
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
626
-        }
627
-        //enqueue scripts/styles - global, page class, and view specific
628
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
629
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
630
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
631
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
632
-        }
633
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
634
-        //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
635
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
636
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
637
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
638
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
639
-        }
640
-        //admin footer scripts
641
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
642
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
643
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
644
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
645
-        }
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
647
-        //targeted hook
648
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
649
-    }
650
-
651
-
652
-
653
-    /**
654
-     * _set_defaults
655
-     * This sets some global defaults for class properties.
656
-     */
657
-    private function _set_defaults()
658
-    {
659
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
660
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
661
-        $this->default_nav_tab_name = 'overview';
662
-        //init template args
663
-        $this->_template_args = array(
664
-                'admin_page_header'  => '',
665
-                'admin_page_content' => '',
666
-                'post_body_content'  => '',
667
-                'before_list_table'  => '',
668
-                'after_list_table'   => '',
669
-        );
670
-    }
671
-
672
-
673
-
674
-    /**
675
-     * route_admin_request
676
-     *
677
-     * @see    _route_admin_request()
678
-     * @access public
679
-     * @return void|exception error
680
-     */
681
-    public function route_admin_request()
682
-    {
683
-        try {
684
-            $this->_route_admin_request();
685
-        } catch (EE_Error $e) {
686
-            $e->get_error();
687
-        }
688
-    }
689
-
690
-
691
-
692
-    public function set_wp_page_slug($wp_page_slug)
693
-    {
694
-        $this->_wp_page_slug = $wp_page_slug;
695
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
696
-        if (is_network_admin()) {
697
-            $this->_wp_page_slug .= '-network';
698
-        }
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * _verify_routes
705
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
706
-     *
707
-     * @access protected
708
-     * @return void
709
-     */
710
-    protected function _verify_routes()
711
-    {
712
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
713
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
714
-            return false;
715
-        }
716
-        $this->_route = false;
717
-        $func = false;
718
-        $args = array();
719
-        // check that the page_routes array is not empty
720
-        if (empty($this->_page_routes)) {
721
-            // user error msg
722
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
723
-            // developer error msg
724
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
725
-            throw new EE_Error($error_msg);
726
-        }
727
-        // and that the requested page route exists
728
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
729
-            $this->_route = $this->_page_routes[$this->_req_action];
730
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
731
-        } else {
732
-            // user error msg
733
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
734
-            // developer error msg
735
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
736
-            throw new EE_Error($error_msg);
737
-        }
738
-        // and that a default route exists
739
-        if ( ! array_key_exists('default', $this->_page_routes)) {
740
-            // user error msg
741
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
742
-            // developer error msg
743
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
744
-            throw new EE_Error($error_msg);
745
-        }
746
-        //first lets' catch if the UI request has EVER been set.
747
-        if ($this->_is_UI_request === null) {
748
-            //lets set if this is a UI request or not.
749
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
750
-            //wait a minute... we might have a noheader in the route array
751
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
752
-        }
753
-        $this->_set_current_labels();
754
-    }
755
-
756
-
757
-
758
-    /**
759
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
760
-     *
761
-     * @param  string $route the route name we're verifying
762
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
763
-     */
764
-    protected function _verify_route($route)
765
-    {
766
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
767
-            return true;
768
-        } else {
769
-            // user error msg
770
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
771
-            // developer error msg
772
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
773
-            throw new EE_Error($error_msg);
774
-        }
775
-    }
776
-
777
-
778
-
779
-    /**
780
-     * perform nonce verification
781
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
782
-     *
783
-     * @param  string $nonce     The nonce sent
784
-     * @param  string $nonce_ref The nonce reference string (name0)
785
-     * @return mixed (bool|die)
786
-     */
787
-    protected function _verify_nonce($nonce, $nonce_ref)
788
-    {
789
-        // verify nonce against expected value
790
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
791
-            // these are not the droids you are looking for !!!
792
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
793
-            if (WP_DEBUG) {
794
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
795
-            }
796
-            if ( ! defined('DOING_AJAX')) {
797
-                wp_die($msg);
798
-            } else {
799
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
800
-                $this->_return_json();
801
-            }
802
-        }
803
-    }
804
-
805
-
806
-
807
-    /**
808
-     * _route_admin_request()
809
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
810
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
811
-     * in the page routes and then will try to load the corresponding method.
812
-     *
813
-     * @access protected
814
-     * @return void
815
-     * @throws \EE_Error
816
-     */
817
-    protected function _route_admin_request()
818
-    {
819
-        if ( ! $this->_is_UI_request) {
820
-            $this->_verify_routes();
821
-        }
822
-        $nonce_check = isset($this->_route_config['require_nonce'])
823
-            ? $this->_route_config['require_nonce']
824
-            : true;
825
-        if ($this->_req_action !== 'default' && $nonce_check) {
826
-            // set nonce from post data
827
-            $nonce = isset($this->_req_data[$this->_req_nonce])
828
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
829
-                : '';
830
-            $this->_verify_nonce($nonce, $this->_req_nonce);
831
-        }
832
-        //set the nav_tabs array but ONLY if this is  UI_request
833
-        if ($this->_is_UI_request) {
834
-            $this->_set_nav_tabs();
835
-        }
836
-        // grab callback function
837
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
838
-        // check if callback has args
839
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
840
-        $error_msg = '';
841
-        // action right before calling route
842
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
843
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
844
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
845
-        }
846
-        // right before calling the route, let's remove _wp_http_referer from the
847
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
848
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
849
-        if ( ! empty($func)) {
850
-            if (is_array($func)) {
851
-                list($class, $method) = $func;
852
-            } else if (strpos($func, '::') !== false) {
853
-                list($class, $method) = explode('::', $func);
854
-            } else {
855
-                $class = $this;
856
-                $method = $func;
857
-            }
858
-            if ( ! (is_object($class) && $class === $this)) {
859
-                // send along this admin page object for access by addons.
860
-                $args['admin_page_object'] = $this;
861
-            }
862
-
863
-            if (
864
-                //is it a method on a class that doesn't work?
865
-                (
866
-                    (
867
-                        method_exists($class, $method)
868
-                        && call_user_func_array(array($class, $method), $args) === false
869
-                    )
870
-                    && (
871
-                        //is it a standalone function that doesn't work?
872
-                        function_exists($method)
873
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
874
-                    )
875
-                )
876
-                || (
877
-                    //is it neither a class method NOR a standalone function?
878
-                    ! method_exists($class, $method)
879
-                    && ! function_exists($method)
880
-                )
881
-            ) {
882
-                // user error msg
883
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
884
-                // developer error msg
885
-                $error_msg .= '||';
886
-                $error_msg .= sprintf(
887
-                    __(
888
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
889
-                        'event_espresso'
890
-                    ),
891
-                    $method
892
-                );
893
-            }
894
-            if ( ! empty($error_msg)) {
895
-                throw new EE_Error($error_msg);
896
-            }
897
-        }
898
-        //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
899
-        //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
900
-        if ($this->_is_UI_request === false
901
-            && is_array($this->_route)
902
-            && ! empty($this->_route['headers_sent_route'])
903
-        ) {
904
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
905
-        }
906
-    }
907
-
908
-
909
-
910
-    /**
911
-     * This method just allows the resetting of page properties in the case where a no headers
912
-     * route redirects to a headers route in its route config.
913
-     *
914
-     * @since   4.3.0
915
-     * @param  string $new_route New (non header) route to redirect to.
916
-     * @return   void
917
-     */
918
-    protected function _reset_routing_properties($new_route)
919
-    {
920
-        $this->_is_UI_request = true;
921
-        //now we set the current route to whatever the headers_sent_route is set at
922
-        $this->_req_data['action'] = $new_route;
923
-        //rerun page setup
924
-        $this->_page_setup();
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * _add_query_arg
931
-     * adds nonce to array of arguments then calls WP add_query_arg function
932
-     *(internally just uses EEH_URL's function with the same name)
933
-     *
934
-     * @access public
935
-     * @param array  $args
936
-     * @param string $url
937
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
938
-     *                                        url in an associative array indexed by the key 'wp_referer';
939
-     *                                        Example usage:
940
-     *                                        If the current page is:
941
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
942
-     *                                        &action=default&event_id=20&month_range=March%202015
943
-     *                                        &_wpnonce=5467821
944
-     *                                        and you call:
945
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
946
-     *                                        array(
947
-     *                                        'action' => 'resend_something',
948
-     *                                        'page=>espresso_registrations'
949
-     *                                        ),
950
-     *                                        $some_url,
951
-     *                                        true
952
-     *                                        );
953
-     *                                        It will produce a url in this structure:
954
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
955
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
956
-     *                                        month_range]=March%202015
957
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
958
-     * @return string
959
-     */
960
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
961
-    {
962
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
963
-        if ($sticky) {
964
-            $request = $_REQUEST;
965
-            unset($request['_wp_http_referer']);
966
-            unset($request['wp_referer']);
967
-            foreach ($request as $key => $value) {
968
-                //do not add nonces
969
-                if (strpos($key, 'nonce') !== false) {
970
-                    continue;
971
-                }
972
-                $args['wp_referer[' . $key . ']'] = $value;
973
-            }
974
-        }
975
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * This returns a generated link that will load the related help tab.
982
-     *
983
-     * @param  string $help_tab_id the id for the connected help tab
984
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
985
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
986
-     * @uses EEH_Template::get_help_tab_link()
987
-     * @return string              generated link
988
-     */
989
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
990
-    {
991
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     * _add_help_tabs
998
-     * Note child classes define their help tabs within the page_config array.
999
-     *
1000
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1001
-     * @access protected
1002
-     * @return void
1003
-     */
1004
-    protected function _add_help_tabs()
1005
-    {
1006
-        $tour_buttons = '';
1007
-        if (isset($this->_page_config[$this->_req_action])) {
1008
-            $config = $this->_page_config[$this->_req_action];
1009
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1010
-            if (isset($this->_help_tour[$this->_req_action])) {
1011
-                $tb = array();
1012
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1013
-                foreach ($this->_help_tour['tours'] as $tour) {
1014
-                    //if this is the end tour then we don't need to setup a button
1015
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1016
-                        continue;
1017
-                    }
1018
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1019
-                }
1020
-                $tour_buttons .= implode('<br />', $tb);
1021
-                $tour_buttons .= '</div></div>';
1022
-            }
1023
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1024
-            if (is_array($config) && isset($config['help_sidebar'])) {
1025
-                //check that the callback given is valid
1026
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1027
-                    throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1028
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1029
-                }
1030
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1031
-                $content .= $tour_buttons; //add help tour buttons.
1032
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1033
-                $this->_current_screen->set_help_sidebar($content);
1034
-            }
1035
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1036
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1037
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1038
-            }
1039
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1040
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1041
-                $_ht['id'] = $this->page_slug;
1042
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1043
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1044
-                $this->_current_screen->add_help_tab($_ht);
1045
-            }/**/
1046
-            if ( ! isset($config['help_tabs'])) {
1047
-                return;
1048
-            } //no help tabs for this route
1049
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1050
-                //we're here so there ARE help tabs!
1051
-                //make sure we've got what we need
1052
-                if ( ! isset($cfg['title'])) {
1053
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1054
-                }
1055
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1056
-                    throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1057
-                            'event_espresso'));
1058
-                }
1059
-                //first priority goes to content.
1060
-                if ( ! empty($cfg['content'])) {
1061
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1062
-                    //second priority goes to filename
1063
-                } else if ( ! empty($cfg['filename'])) {
1064
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1065
-                    //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1066
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1067
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1068
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1069
-                        EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1070
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1071
-                        return;
1072
-                    }
1073
-                    $template_args['admin_page_obj'] = $this;
1074
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1075
-                } else {
1076
-                    $content = '';
1077
-                }
1078
-                //check if callback is valid
1079
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1080
-                    EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1081
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1082
-                    return;
1083
-                }
1084
-                //setup config array for help tab method
1085
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1086
-                $_ht = array(
1087
-                        'id'       => $id,
1088
-                        'title'    => $cfg['title'],
1089
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1090
-                        'content'  => $content,
1091
-                );
1092
-                $this->_current_screen->add_help_tab($_ht);
1093
-            }
1094
-        }
1095
-    }
1096
-
1097
-
1098
-
1099
-    /**
1100
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1101
-     *
1102
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1103
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1104
-     * @access protected
1105
-     * @return void
1106
-     */
1107
-    protected function _add_help_tour()
1108
-    {
1109
-        $tours = array();
1110
-        $this->_help_tour = array();
1111
-        //exit early if help tours are turned off globally
1112
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1113
-            return;
1114
-        }
1115
-        //loop through _page_config to find any help_tour defined
1116
-        foreach ($this->_page_config as $route => $config) {
1117
-            //we're only going to set things up for this route
1118
-            if ($route !== $this->_req_action) {
1119
-                continue;
1120
-            }
1121
-            if (isset($config['help_tour'])) {
1122
-                foreach ($config['help_tour'] as $tour) {
1123
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1124
-                    //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1125
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1126
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1127
-                    if ( ! is_readable($file_path)) {
1128
-                        EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1129
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1130
-                        return;
1131
-                    }
1132
-                    require_once $file_path;
1133
-                    if ( ! class_exists($tour)) {
1134
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1135
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1136
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1137
-                        throw new EE_Error(implode('||', $error_msg));
1138
-                    }
1139
-                    $a = new ReflectionClass($tour);
1140
-                    $tour_obj = $a->newInstance($this->_is_caf);
1141
-                    $tours[] = $tour_obj;
1142
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1143
-                }
1144
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1145
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1146
-                $tours[] = $end_stop_tour;
1147
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1148
-            }
1149
-        }
1150
-        if ( ! empty($tours)) {
1151
-            $this->_help_tour['tours'] = $tours;
1152
-        }
1153
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1154
-    }
1155
-
1156
-
1157
-
1158
-    /**
1159
-     * This simply sets up any qtips that have been defined in the page config
1160
-     *
1161
-     * @access protected
1162
-     * @return void
1163
-     */
1164
-    protected function _add_qtips()
1165
-    {
1166
-        if (isset($this->_route_config['qtips'])) {
1167
-            $qtips = (array)$this->_route_config['qtips'];
1168
-            //load qtip loader
1169
-            $path = array(
1170
-                    $this->_get_dir() . '/qtips/',
1171
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1172
-            );
1173
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1174
-        }
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * _set_nav_tabs
1181
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1182
-     *
1183
-     * @access protected
1184
-     * @return void
1185
-     */
1186
-    protected function _set_nav_tabs()
1187
-    {
1188
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1189
-        $i = 0;
1190
-        foreach ($this->_page_config as $slug => $config) {
1191
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1192
-                continue;
1193
-            } //no nav tab for this config
1194
-            //check for persistent flag
1195
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1196
-                continue;
1197
-            } //nav tab is only to appear when route requested.
1198
-            if ( ! $this->check_user_access($slug, true)) {
1199
-                continue;
1200
-            } //no nav tab becasue current user does not have access.
1201
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1202
-            $this->_nav_tabs[$slug] = array(
1203
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1204
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1205
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1206
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1207
-            );
1208
-            $i++;
1209
-        }
1210
-        //if $this->_nav_tabs is empty then lets set the default
1211
-        if (empty($this->_nav_tabs)) {
1212
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1213
-                    'url'       => $this->admin_base_url,
1214
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1215
-                    'css_class' => 'nav-tab-active',
1216
-                    'order'     => 10,
1217
-            );
1218
-        }
1219
-        //now let's sort the tabs according to order
1220
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     * _set_current_labels
1227
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1228
-     *
1229
-     * @access private
1230
-     * @return void
1231
-     */
1232
-    private function _set_current_labels()
1233
-    {
1234
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1235
-            foreach ($this->_route_config['labels'] as $label => $text) {
1236
-                if (is_array($text)) {
1237
-                    foreach ($text as $sublabel => $subtext) {
1238
-                        $this->_labels[$label][$sublabel] = $subtext;
1239
-                    }
1240
-                } else {
1241
-                    $this->_labels[$label] = $text;
1242
-                }
1243
-            }
1244
-        }
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     *        verifies user access for this admin page
1251
-     *
1252
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1253
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1254
-     * @return        BOOL|wp_die()
1255
-     */
1256
-    public function check_user_access($route_to_check = '', $verify_only = false)
1257
-    {
1258
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1259
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1260
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1261
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1262
-        if (empty($capability) && empty($route_to_check)) {
1263
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1264
-        } else {
1265
-            $capability = empty($capability) ? 'manage_options' : $capability;
1266
-        }
1267
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1268
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1269
-            if ($verify_only) {
1270
-                return false;
1271
-            } else {
1272
-                if ( is_user_logged_in() ) {
1273
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1274
-                } else {
1275
-                    return false;
1276
-                }
1277
-            }
1278
-        }
1279
-        return true;
1280
-    }
1281
-
1282
-
1283
-
1284
-    /**
1285
-     * admin_init_global
1286
-     * This runs all the code that we want executed within the WP admin_init hook.
1287
-     * This method executes for ALL EE Admin pages.
1288
-     *
1289
-     * @access public
1290
-     * @return void
1291
-     */
1292
-    public function admin_init_global()
1293
-    {
1294
-    }
1295
-
1296
-
1297
-
1298
-    /**
1299
-     * wp_loaded_global
1300
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1301
-     *
1302
-     * @access public
1303
-     * @return void
1304
-     */
1305
-    public function wp_loaded()
1306
-    {
1307
-    }
1308
-
1309
-
1310
-
1311
-    /**
1312
-     * admin_notices
1313
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1314
-     *
1315
-     * @access public
1316
-     * @return void
1317
-     */
1318
-    public function admin_notices_global()
1319
-    {
1320
-        $this->_display_no_javascript_warning();
1321
-        $this->_display_espresso_notices();
1322
-    }
1323
-
1324
-
1325
-
1326
-    public function network_admin_notices_global()
1327
-    {
1328
-        $this->_display_no_javascript_warning();
1329
-        $this->_display_espresso_notices();
1330
-    }
1331
-
1332
-
1333
-
1334
-    /**
1335
-     * admin_footer_scripts_global
1336
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1337
-     *
1338
-     * @access public
1339
-     * @return void
1340
-     */
1341
-    public function admin_footer_scripts_global()
1342
-    {
1343
-        $this->_add_admin_page_ajax_loading_img();
1344
-        $this->_add_admin_page_overlay();
1345
-        //if metaboxes are present we need to add the nonce field
1346
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1347
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1348
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1349
-        }
1350
-    }
1351
-
1352
-
1353
-
1354
-    /**
1355
-     * admin_footer_global
1356
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1357
-     *
1358
-     * @access  public
1359
-     * @return  void
1360
-     */
1361
-    public function admin_footer_global()
1362
-    {
1363
-        //dialog container for dialog helper
1364
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1365
-        $d_cont .= '<div class="ee-notices"></div>';
1366
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1367
-        $d_cont .= '</div>';
1368
-        echo $d_cont;
1369
-        //help tour stuff?
1370
-        if (isset($this->_help_tour[$this->_req_action])) {
1371
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1372
-        }
1373
-        //current set timezone for timezone js
1374
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1375
-    }
1376
-
1377
-
1378
-
1379
-    /**
1380
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1381
-     * For child classes:
1382
-     * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1383
-     * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1384
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1385
-     *    'help_trigger_id' => array(
1386
-     *        'title' => __('localized title for popup', 'event_espresso'),
1387
-     *        'content' => __('localized content for popup', 'event_espresso')
1388
-     *    )
1389
-     * );
1390
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1391
-     *
1392
-     * @access protected
1393
-     * @return string content
1394
-     */
1395
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1396
-    {
1397
-        $content = '';
1398
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1399
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1400
-        //loop through the array and setup content
1401
-        foreach ($help_array as $trigger => $help) {
1402
-            //make sure the array is setup properly
1403
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1404
-                throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1405
-                        'event_espresso'));
1406
-            }
1407
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1408
-            $template_args = array(
1409
-                    'help_popup_id'      => $trigger,
1410
-                    'help_popup_title'   => $help['title'],
1411
-                    'help_popup_content' => $help['content'],
1412
-            );
1413
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1414
-        }
1415
-        if ($display) {
1416
-            echo $content;
1417
-        } else {
1418
-            return $content;
1419
-        }
1420
-    }
1421
-
1422
-
1423
-
1424
-    /**
1425
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1426
-     *
1427
-     * @access private
1428
-     * @return array properly formatted array for help popup content
1429
-     */
1430
-    private function _get_help_content()
1431
-    {
1432
-        //what is the method we're looking for?
1433
-        $method_name = '_help_popup_content_' . $this->_req_action;
1434
-        //if method doesn't exist let's get out.
1435
-        if ( ! method_exists($this, $method_name)) {
1436
-            return array();
1437
-        }
1438
-        //k we're good to go let's retrieve the help array
1439
-        $help_array = call_user_func(array($this, $method_name));
1440
-        //make sure we've got an array!
1441
-        if ( ! is_array($help_array)) {
1442
-            throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1443
-        }
1444
-        return $help_array;
1445
-    }
1446
-
1447
-
1448
-
1449
-    /**
1450
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1451
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1452
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1453
-     *
1454
-     * @access protected
1455
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1456
-     * @param boolean $display    if false then we return the trigger string
1457
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1458
-     * @return string
1459
-     */
1460
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1461
-    {
1462
-        if (defined('DOING_AJAX')) {
1463
-            return;
1464
-        }
1465
-        //let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1466
-        $help_array = $this->_get_help_content();
1467
-        $help_content = '';
1468
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1469
-            $help_array[$trigger_id] = array(
1470
-                    'title'   => __('Missing Content', 'event_espresso'),
1471
-                    'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1472
-                            'event_espresso'),
1473
-            );
1474
-            $help_content = $this->_set_help_popup_content($help_array, false);
1475
-        }
1476
-        //let's setup the trigger
1477
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1478
-        $content = $content . $help_content;
1479
-        if ($display) {
1480
-            echo $content;
1481
-        } else {
1482
-            return $content;
1483
-        }
1484
-    }
1485
-
1486
-
1487
-
1488
-    /**
1489
-     * _add_global_screen_options
1490
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1491
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1492
-     *
1493
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1494
-     *         see also WP_Screen object documents...
1495
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1496
-     * @abstract
1497
-     * @access private
1498
-     * @return void
1499
-     */
1500
-    private function _add_global_screen_options()
1501
-    {
1502
-    }
1503
-
1504
-
1505
-
1506
-    /**
1507
-     * _add_global_feature_pointers
1508
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1509
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1510
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1511
-     *
1512
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1513
-     * @link   http://eamann.com/tech/wordpress-portland/
1514
-     * @abstract
1515
-     * @access protected
1516
-     * @return void
1517
-     */
1518
-    private function _add_global_feature_pointers()
1519
-    {
1520
-    }
1521
-
1522
-
1523
-
1524
-    /**
1525
-     * load_global_scripts_styles
1526
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1527
-     *
1528
-     * @return void
1529
-     */
1530
-    public function load_global_scripts_styles()
1531
-    {
1532
-        /** STYLES **/
1533
-        // add debugging styles
1534
-        if (WP_DEBUG) {
1535
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1536
-        }
1537
-        // register all styles
1538
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1539
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1540
-        //helpers styles
1541
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1542
-        /** SCRIPTS **/
1543
-        //register all scripts
1544
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1546
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1547
-        add_filter('FHEE_load_joyride', '__return_true');
1548
-        //script for sorting tables
1549
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1550
-        //script for parsing uri's
1551
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1552
-        //and parsing associative serialized form elements
1553
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        //helpers scripts
1555
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1557
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1558
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1559
-        //google charts
1560
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1561
-        // ENQUEUE ALL BASICS BY DEFAULT
1562
-        wp_enqueue_style('ee-admin-css');
1563
-        wp_enqueue_script('ee_admin_js');
1564
-        wp_enqueue_script('ee-accounting');
1565
-        wp_enqueue_script('jquery-validate');
1566
-        //taking care of metaboxes
1567
-        if (
1568
-            empty($this->_cpt_route)
1569
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1570
-        ) {
1571
-            wp_enqueue_script('dashboard');
1572
-        }
1573
-        // LOCALIZED DATA
1574
-        //localize script for ajax lazy loading
1575
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
-        /**
1578
-         * help tour stuff
1579
-         */
1580
-        if ( ! empty($this->_help_tour)) {
1581
-            //register the js for kicking things off
1582
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
-            //setup tours for the js tour object
1584
-            foreach ($this->_help_tour['tours'] as $tour) {
1585
-                $tours[] = array(
1586
-                        'id'      => $tour->get_slug(),
1587
-                        'options' => $tour->get_options(),
1588
-                );
1589
-            }
1590
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
-        }
1593
-    }
1594
-
1595
-
1596
-
1597
-    /**
1598
-     *        admin_footer_scripts_eei18n_js_strings
1599
-     *
1600
-     * @access        public
1601
-     * @return        void
1602
-     */
1603
-    public function admin_footer_scripts_eei18n_js_strings()
1604
-    {
1605
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
-        EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
-    }
1646
-
1647
-
1648
-
1649
-    /**
1650
-     *        load enhanced xdebug styles for ppl with failing eyesight
1651
-     *
1652
-     * @access        public
1653
-     * @return        void
1654
-     */
1655
-    public function add_xdebug_style()
1656
-    {
1657
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1658
-    }
1659
-
1660
-
1661
-    /************************/
1662
-    /** LIST TABLE METHODS **/
1663
-    /************************/
1664
-    /**
1665
-     * this sets up the list table if the current view requires it.
1666
-     *
1667
-     * @access protected
1668
-     * @return void
1669
-     */
1670
-    protected function _set_list_table()
1671
-    {
1672
-        //first is this a list_table view?
1673
-        if ( ! isset($this->_route_config['list_table'])) {
1674
-            return;
1675
-        } //not a list_table view so get out.
1676
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1677
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1678
-            //user error msg
1679
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1680
-            //developer error msg
1681
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1682
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1683
-            throw new EE_Error($error_msg);
1684
-        }
1685
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1686
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1687
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1688
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1689
-        $this->_set_list_table_view();
1690
-        $this->_set_list_table_object();
1691
-    }
1692
-
1693
-
1694
-
1695
-    /**
1696
-     *        set current view for List Table
1697
-     *
1698
-     * @access public
1699
-     * @return array
1700
-     */
1701
-    protected function _set_list_table_view()
1702
-    {
1703
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1704
-        // looking at active items or dumpster diving ?
1705
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1706
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1707
-        } else {
1708
-            $this->_view = sanitize_key($this->_req_data['status']);
1709
-        }
1710
-    }
1711
-
1712
-
1713
-
1714
-    /**
1715
-     * _set_list_table_object
1716
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1717
-     *
1718
-     * @throws \EE_Error
1719
-     */
1720
-    protected function _set_list_table_object()
1721
-    {
1722
-        if (isset($this->_route_config['list_table'])) {
1723
-            if ( ! class_exists($this->_route_config['list_table'])) {
1724
-                throw new EE_Error(
1725
-                        sprintf(
1726
-                                __(
1727
-                                        'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1728
-                                        'event_espresso'
1729
-                                ),
1730
-                                $this->_route_config['list_table'],
1731
-                                get_class($this)
1732
-                        )
1733
-                );
1734
-            }
1735
-            $list_table = $this->_route_config['list_table'];
1736
-            $this->_list_table_object = new $list_table($this);
1737
-        }
1738
-    }
1739
-
1740
-
1741
-
1742
-    /**
1743
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1744
-     *
1745
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1746
-     *                                                    urls.  The array should be indexed by the view it is being
1747
-     *                                                    added to.
1748
-     * @return array
1749
-     */
1750
-    public function get_list_table_view_RLs($extra_query_args = array())
1751
-    {
1752
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1753
-        if (empty($this->_views)) {
1754
-            $this->_views = array();
1755
-        }
1756
-        // cycle thru views
1757
-        foreach ($this->_views as $key => $view) {
1758
-            $query_args = array();
1759
-            // check for current view
1760
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1761
-            $query_args['action'] = $this->_req_action;
1762
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1763
-            $query_args['status'] = $view['slug'];
1764
-            //merge any other arguments sent in.
1765
-            if (isset($extra_query_args[$view['slug']])) {
1766
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1767
-            }
1768
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1769
-        }
1770
-        return $this->_views;
1771
-    }
1772
-
1773
-
1774
-
1775
-    /**
1776
-     * _entries_per_page_dropdown
1777
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1778
-     *
1779
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1780
-     * @access protected
1781
-     * @param int $max_entries total number of rows in the table
1782
-     * @return string
1783
-     */
1784
-    protected function _entries_per_page_dropdown($max_entries = false)
1785
-    {
1786
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1787
-        $values = array(10, 25, 50, 100);
1788
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1789
-        if ($max_entries) {
1790
-            $values[] = $max_entries;
1791
-            sort($values);
1792
-        }
1793
-        $entries_per_page_dropdown = '
145
+	// yes / no array for admin form fields
146
+	protected $_yes_no_values = array();
147
+
148
+	//some default things shared by all child classes
149
+	protected $_default_espresso_metaboxes;
150
+
151
+	/**
152
+	 *    EE_Registry Object
153
+	 *
154
+	 * @var    EE_Registry
155
+	 * @access    protected
156
+	 */
157
+	protected $EE = null;
158
+
159
+
160
+
161
+	/**
162
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
163
+	 *
164
+	 * @var boolean
165
+	 */
166
+	protected $_is_caf = false;
167
+
168
+
169
+
170
+	/**
171
+	 * @Constructor
172
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
173
+	 * @access public
174
+	 */
175
+	public function __construct($routing = true)
176
+	{
177
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
178
+			$this->_is_caf = true;
179
+		}
180
+		$this->_yes_no_values = array(
181
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
182
+				array('id' => false, 'text' => __('No', 'event_espresso')),
183
+		);
184
+		//set the _req_data property.
185
+		$this->_req_data = array_merge($_GET, $_POST);
186
+		//routing enabled?
187
+		$this->_routing = $routing;
188
+		//set initial page props (child method)
189
+		$this->_init_page_props();
190
+		//set global defaults
191
+		$this->_set_defaults();
192
+		//set early because incoming requests could be ajax related and we need to register those hooks.
193
+		$this->_global_ajax_hooks();
194
+		$this->_ajax_hooks();
195
+		//other_page_hooks have to be early too.
196
+		$this->_do_other_page_hooks();
197
+		//This just allows us to have extending classes do something specific
198
+		// before the parent constructor runs _page_setup().
199
+		if (method_exists($this, '_before_page_setup')) {
200
+			$this->_before_page_setup();
201
+		}
202
+		//set up page dependencies
203
+		$this->_page_setup();
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * _init_page_props
210
+	 * Child classes use to set at least the following properties:
211
+	 * $page_slug.
212
+	 * $page_label.
213
+	 *
214
+	 * @abstract
215
+	 * @access protected
216
+	 * @return void
217
+	 */
218
+	abstract protected function _init_page_props();
219
+
220
+
221
+
222
+	/**
223
+	 * _ajax_hooks
224
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
225
+	 * Note: within the ajax callback methods.
226
+	 *
227
+	 * @abstract
228
+	 * @access protected
229
+	 * @return void
230
+	 */
231
+	abstract protected function _ajax_hooks();
232
+
233
+
234
+
235
+	/**
236
+	 * _define_page_props
237
+	 * child classes define page properties in here.  Must include at least:
238
+	 * $_admin_base_url = base_url for all admin pages
239
+	 * $_admin_page_title = default admin_page_title for admin pages
240
+	 * $_labels = array of default labels for various automatically generated elements:
241
+	 *    array(
242
+	 *        'buttons' => array(
243
+	 *            'add' => __('label for add new button'),
244
+	 *            'edit' => __('label for edit button'),
245
+	 *            'delete' => __('label for delete button')
246
+	 *            )
247
+	 *        )
248
+	 *
249
+	 * @abstract
250
+	 * @access protected
251
+	 * @return void
252
+	 */
253
+	abstract protected function _define_page_props();
254
+
255
+
256
+
257
+	/**
258
+	 * _set_page_routes
259
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
260
+	 * route. Here's the format
261
+	 * $this->_page_routes = array(
262
+	 *        'default' => array(
263
+	 *            'func' => '_default_method_handling_route',
264
+	 *            'args' => array('array','of','args'),
265
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
266
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
267
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
268
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
269
+	 *        ),
270
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
271
+	 *        )
272
+	 * )
273
+	 *
274
+	 * @abstract
275
+	 * @access protected
276
+	 * @return void
277
+	 */
278
+	abstract protected function _set_page_routes();
279
+
280
+
281
+
282
+	/**
283
+	 * _set_page_config
284
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
285
+	 * Format:
286
+	 * $this->_page_config = array(
287
+	 *        'default' => array(
288
+	 *            'labels' => array(
289
+	 *                'buttons' => array(
290
+	 *                    'add' => __('label for adding item'),
291
+	 *                    'edit' => __('label for editing item'),
292
+	 *                    'delete' => __('label for deleting item')
293
+	 *                ),
294
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
295
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
296
+	 *            'nav' => array(
297
+	 *                'label' => __('Label for Tab', 'event_espresso').
298
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
299
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
300
+	 *                'order' => 10, //required to indicate tab position.
301
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
302
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
303
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
304
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
305
+	 *            this flag to make sure the necessary js gets enqueued on page load.
306
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
307
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
308
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
309
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
310
+	 *                'tab_id' => array(
311
+	 *                    'title' => 'tab_title',
312
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
313
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
314
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
315
+	 *                    ),
316
+	 *                'tab2_id' => array(
317
+	 *                    'title' => 'tab2 title',
318
+	 *                    'filename' => 'file_name_2'
319
+	 *                    'callback' => 'callback_method_for_content',
320
+	 *                 ),
321
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
322
+	 *            'help_tour' => array(
323
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
324
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
325
+	 *            ),
326
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
327
+	 *            'require_nonce' to FALSE
328
+	 *            )
329
+	 * )
330
+	 *
331
+	 * @abstract
332
+	 * @access protected
333
+	 * @return void
334
+	 */
335
+	abstract protected function _set_page_config();
336
+
337
+
338
+
339
+
340
+
341
+	/** end sample help_tour methods **/
342
+	/**
343
+	 * _add_screen_options
344
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
345
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
346
+	 *
347
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
348
+	 *         see also WP_Screen object documents...
349
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
350
+	 * @abstract
351
+	 * @access protected
352
+	 * @return void
353
+	 */
354
+	abstract protected function _add_screen_options();
355
+
356
+
357
+
358
+	/**
359
+	 * _add_feature_pointers
360
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
361
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
362
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
363
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
364
+	 *
365
+	 * @link   http://eamann.com/tech/wordpress-portland/
366
+	 * @abstract
367
+	 * @access protected
368
+	 * @return void
369
+	 */
370
+	abstract protected function _add_feature_pointers();
371
+
372
+
373
+
374
+	/**
375
+	 * load_scripts_styles
376
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
377
+	 * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
378
+	 *
379
+	 * @abstract
380
+	 * @access public
381
+	 * @return void
382
+	 */
383
+	abstract public function load_scripts_styles();
384
+
385
+
386
+
387
+	/**
388
+	 * admin_init
389
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
390
+	 *
391
+	 * @abstract
392
+	 * @access public
393
+	 * @return void
394
+	 */
395
+	abstract public function admin_init();
396
+
397
+
398
+
399
+	/**
400
+	 * admin_notices
401
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
402
+	 *
403
+	 * @abstract
404
+	 * @access public
405
+	 * @return void
406
+	 */
407
+	abstract public function admin_notices();
408
+
409
+
410
+
411
+	/**
412
+	 * admin_footer_scripts
413
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
414
+	 *
415
+	 * @access public
416
+	 * @return void
417
+	 */
418
+	abstract public function admin_footer_scripts();
419
+
420
+
421
+
422
+	/**
423
+	 * admin_footer
424
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
425
+	 *
426
+	 * @access  public
427
+	 * @return void
428
+	 */
429
+	public function admin_footer()
430
+	{
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * _global_ajax_hooks
437
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
438
+	 * Note: within the ajax callback methods.
439
+	 *
440
+	 * @abstract
441
+	 * @access protected
442
+	 * @return void
443
+	 */
444
+	protected function _global_ajax_hooks()
445
+	{
446
+		//for lazy loading of metabox content
447
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
448
+	}
449
+
450
+
451
+
452
+	public function ajax_metabox_content()
453
+	{
454
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
455
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
456
+		self::cached_rss_display($contentid, $url);
457
+		wp_die();
458
+	}
459
+
460
+
461
+
462
+	/**
463
+	 * _page_setup
464
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
465
+	 *
466
+	 * @final
467
+	 * @access protected
468
+	 * @return void
469
+	 */
470
+	final protected function _page_setup()
471
+	{
472
+		//requires?
473
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
474
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
475
+		//next verify if we need to load anything...
476
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
477
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
478
+		global $ee_menu_slugs;
479
+		$ee_menu_slugs = (array)$ee_menu_slugs;
480
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
481
+			return;
482
+		}
483
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
484
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
485
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
486
+		}
487
+		// then set blank or -1 action values to 'default'
488
+		$this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
489
+		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
490
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
492
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
493
+		$this->_current_view = $this->_req_action;
494
+		$this->_req_nonce = $this->_req_action . '_nonce';
495
+		$this->_define_page_props();
496
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
497
+		//default things
498
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
499
+		//set page configs
500
+		$this->_set_page_routes();
501
+		$this->_set_page_config();
502
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
503
+		if (isset($this->_req_data['wp_referer'])) {
504
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
505
+		}
506
+		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
507
+		if (method_exists($this, '_extend_page_config')) {
508
+			$this->_extend_page_config();
509
+		}
510
+		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
511
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
512
+			$this->_extend_page_config_for_cpt();
513
+		}
514
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
515
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
516
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
517
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
518
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
519
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
520
+		}
521
+		//next route only if routing enabled
522
+		if ($this->_routing && ! defined('DOING_AJAX')) {
523
+			$this->_verify_routes();
524
+			//next let's just check user_access and kill if no access
525
+			$this->check_user_access();
526
+			if ($this->_is_UI_request) {
527
+				//admin_init stuff - global, all views for this page class, specific view
528
+				add_action('admin_init', array($this, 'admin_init'), 10);
529
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
530
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
531
+				}
532
+			} else {
533
+				//hijack regular WP loading and route admin request immediately
534
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
535
+				$this->route_admin_request();
536
+			}
537
+		}
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
544
+	 *
545
+	 * @access private
546
+	 * @return void
547
+	 */
548
+	private function _do_other_page_hooks()
549
+	{
550
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
551
+		foreach ($registered_pages as $page) {
552
+			//now let's setup the file name and class that should be present
553
+			$classname = str_replace('.class.php', '', $page);
554
+			//autoloaders should take care of loading file
555
+			if ( ! class_exists($classname)) {
556
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
557
+				$error_msg[] = $error_msg[0]
558
+							   . "\r\n"
559
+							   . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
560
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
561
+				throw new EE_Error(implode('||', $error_msg));
562
+			}
563
+			$a = new ReflectionClass($classname);
564
+			//notice we are passing the instance of this class to the hook object.
565
+			$hookobj[] = $a->newInstance($this);
566
+		}
567
+	}
568
+
569
+
570
+
571
+	public function load_page_dependencies()
572
+	{
573
+		try {
574
+			$this->_load_page_dependencies();
575
+		} catch (EE_Error $e) {
576
+			$e->get_error();
577
+		}
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * load_page_dependencies
584
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
585
+	 *
586
+	 * @access public
587
+	 * @return void
588
+	 */
589
+	protected function _load_page_dependencies()
590
+	{
591
+		//let's set the current_screen and screen options to override what WP set
592
+		$this->_current_screen = get_current_screen();
593
+		//load admin_notices - global, page class, and view specific
594
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
595
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
596
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
597
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
598
+		}
599
+		//load network admin_notices - global, page class, and view specific
600
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
601
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
602
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
603
+		}
604
+		//this will save any per_page screen options if they are present
605
+		$this->_set_per_page_screen_options();
606
+		//setup list table properties
607
+		$this->_set_list_table();
608
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
609
+		$this->_add_registered_meta_boxes();
610
+		$this->_add_screen_columns();
611
+		//add screen options - global, page child class, and view specific
612
+		$this->_add_global_screen_options();
613
+		$this->_add_screen_options();
614
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
615
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
616
+		}
617
+		//add help tab(s) and tours- set via page_config and qtips.
618
+		$this->_add_help_tour();
619
+		$this->_add_help_tabs();
620
+		$this->_add_qtips();
621
+		//add feature_pointers - global, page child class, and view specific
622
+		$this->_add_feature_pointers();
623
+		$this->_add_global_feature_pointers();
624
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
625
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
626
+		}
627
+		//enqueue scripts/styles - global, page class, and view specific
628
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
629
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
630
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
631
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
632
+		}
633
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
634
+		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
635
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
636
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
637
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
638
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
639
+		}
640
+		//admin footer scripts
641
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
642
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
643
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
644
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
645
+		}
646
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
647
+		//targeted hook
648
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
649
+	}
650
+
651
+
652
+
653
+	/**
654
+	 * _set_defaults
655
+	 * This sets some global defaults for class properties.
656
+	 */
657
+	private function _set_defaults()
658
+	{
659
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
660
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
661
+		$this->default_nav_tab_name = 'overview';
662
+		//init template args
663
+		$this->_template_args = array(
664
+				'admin_page_header'  => '',
665
+				'admin_page_content' => '',
666
+				'post_body_content'  => '',
667
+				'before_list_table'  => '',
668
+				'after_list_table'   => '',
669
+		);
670
+	}
671
+
672
+
673
+
674
+	/**
675
+	 * route_admin_request
676
+	 *
677
+	 * @see    _route_admin_request()
678
+	 * @access public
679
+	 * @return void|exception error
680
+	 */
681
+	public function route_admin_request()
682
+	{
683
+		try {
684
+			$this->_route_admin_request();
685
+		} catch (EE_Error $e) {
686
+			$e->get_error();
687
+		}
688
+	}
689
+
690
+
691
+
692
+	public function set_wp_page_slug($wp_page_slug)
693
+	{
694
+		$this->_wp_page_slug = $wp_page_slug;
695
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
696
+		if (is_network_admin()) {
697
+			$this->_wp_page_slug .= '-network';
698
+		}
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * _verify_routes
705
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
706
+	 *
707
+	 * @access protected
708
+	 * @return void
709
+	 */
710
+	protected function _verify_routes()
711
+	{
712
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
713
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
714
+			return false;
715
+		}
716
+		$this->_route = false;
717
+		$func = false;
718
+		$args = array();
719
+		// check that the page_routes array is not empty
720
+		if (empty($this->_page_routes)) {
721
+			// user error msg
722
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
723
+			// developer error msg
724
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
725
+			throw new EE_Error($error_msg);
726
+		}
727
+		// and that the requested page route exists
728
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
729
+			$this->_route = $this->_page_routes[$this->_req_action];
730
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
731
+		} else {
732
+			// user error msg
733
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
734
+			// developer error msg
735
+			$error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
736
+			throw new EE_Error($error_msg);
737
+		}
738
+		// and that a default route exists
739
+		if ( ! array_key_exists('default', $this->_page_routes)) {
740
+			// user error msg
741
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
742
+			// developer error msg
743
+			$error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
744
+			throw new EE_Error($error_msg);
745
+		}
746
+		//first lets' catch if the UI request has EVER been set.
747
+		if ($this->_is_UI_request === null) {
748
+			//lets set if this is a UI request or not.
749
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
750
+			//wait a minute... we might have a noheader in the route array
751
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
752
+		}
753
+		$this->_set_current_labels();
754
+	}
755
+
756
+
757
+
758
+	/**
759
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
760
+	 *
761
+	 * @param  string $route the route name we're verifying
762
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
763
+	 */
764
+	protected function _verify_route($route)
765
+	{
766
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
767
+			return true;
768
+		} else {
769
+			// user error msg
770
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
771
+			// developer error msg
772
+			$error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
773
+			throw new EE_Error($error_msg);
774
+		}
775
+	}
776
+
777
+
778
+
779
+	/**
780
+	 * perform nonce verification
781
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
782
+	 *
783
+	 * @param  string $nonce     The nonce sent
784
+	 * @param  string $nonce_ref The nonce reference string (name0)
785
+	 * @return mixed (bool|die)
786
+	 */
787
+	protected function _verify_nonce($nonce, $nonce_ref)
788
+	{
789
+		// verify nonce against expected value
790
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
791
+			// these are not the droids you are looking for !!!
792
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
793
+			if (WP_DEBUG) {
794
+				$msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
795
+			}
796
+			if ( ! defined('DOING_AJAX')) {
797
+				wp_die($msg);
798
+			} else {
799
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
800
+				$this->_return_json();
801
+			}
802
+		}
803
+	}
804
+
805
+
806
+
807
+	/**
808
+	 * _route_admin_request()
809
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
810
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
811
+	 * in the page routes and then will try to load the corresponding method.
812
+	 *
813
+	 * @access protected
814
+	 * @return void
815
+	 * @throws \EE_Error
816
+	 */
817
+	protected function _route_admin_request()
818
+	{
819
+		if ( ! $this->_is_UI_request) {
820
+			$this->_verify_routes();
821
+		}
822
+		$nonce_check = isset($this->_route_config['require_nonce'])
823
+			? $this->_route_config['require_nonce']
824
+			: true;
825
+		if ($this->_req_action !== 'default' && $nonce_check) {
826
+			// set nonce from post data
827
+			$nonce = isset($this->_req_data[$this->_req_nonce])
828
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
829
+				: '';
830
+			$this->_verify_nonce($nonce, $this->_req_nonce);
831
+		}
832
+		//set the nav_tabs array but ONLY if this is  UI_request
833
+		if ($this->_is_UI_request) {
834
+			$this->_set_nav_tabs();
835
+		}
836
+		// grab callback function
837
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
838
+		// check if callback has args
839
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
840
+		$error_msg = '';
841
+		// action right before calling route
842
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
843
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
844
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
845
+		}
846
+		// right before calling the route, let's remove _wp_http_referer from the
847
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
848
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
849
+		if ( ! empty($func)) {
850
+			if (is_array($func)) {
851
+				list($class, $method) = $func;
852
+			} else if (strpos($func, '::') !== false) {
853
+				list($class, $method) = explode('::', $func);
854
+			} else {
855
+				$class = $this;
856
+				$method = $func;
857
+			}
858
+			if ( ! (is_object($class) && $class === $this)) {
859
+				// send along this admin page object for access by addons.
860
+				$args['admin_page_object'] = $this;
861
+			}
862
+
863
+			if (
864
+				//is it a method on a class that doesn't work?
865
+				(
866
+					(
867
+						method_exists($class, $method)
868
+						&& call_user_func_array(array($class, $method), $args) === false
869
+					)
870
+					&& (
871
+						//is it a standalone function that doesn't work?
872
+						function_exists($method)
873
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
874
+					)
875
+				)
876
+				|| (
877
+					//is it neither a class method NOR a standalone function?
878
+					! method_exists($class, $method)
879
+					&& ! function_exists($method)
880
+				)
881
+			) {
882
+				// user error msg
883
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
884
+				// developer error msg
885
+				$error_msg .= '||';
886
+				$error_msg .= sprintf(
887
+					__(
888
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
889
+						'event_espresso'
890
+					),
891
+					$method
892
+				);
893
+			}
894
+			if ( ! empty($error_msg)) {
895
+				throw new EE_Error($error_msg);
896
+			}
897
+		}
898
+		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
899
+		//now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
900
+		if ($this->_is_UI_request === false
901
+			&& is_array($this->_route)
902
+			&& ! empty($this->_route['headers_sent_route'])
903
+		) {
904
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
905
+		}
906
+	}
907
+
908
+
909
+
910
+	/**
911
+	 * This method just allows the resetting of page properties in the case where a no headers
912
+	 * route redirects to a headers route in its route config.
913
+	 *
914
+	 * @since   4.3.0
915
+	 * @param  string $new_route New (non header) route to redirect to.
916
+	 * @return   void
917
+	 */
918
+	protected function _reset_routing_properties($new_route)
919
+	{
920
+		$this->_is_UI_request = true;
921
+		//now we set the current route to whatever the headers_sent_route is set at
922
+		$this->_req_data['action'] = $new_route;
923
+		//rerun page setup
924
+		$this->_page_setup();
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * _add_query_arg
931
+	 * adds nonce to array of arguments then calls WP add_query_arg function
932
+	 *(internally just uses EEH_URL's function with the same name)
933
+	 *
934
+	 * @access public
935
+	 * @param array  $args
936
+	 * @param string $url
937
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
938
+	 *                                        url in an associative array indexed by the key 'wp_referer';
939
+	 *                                        Example usage:
940
+	 *                                        If the current page is:
941
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
942
+	 *                                        &action=default&event_id=20&month_range=March%202015
943
+	 *                                        &_wpnonce=5467821
944
+	 *                                        and you call:
945
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
946
+	 *                                        array(
947
+	 *                                        'action' => 'resend_something',
948
+	 *                                        'page=>espresso_registrations'
949
+	 *                                        ),
950
+	 *                                        $some_url,
951
+	 *                                        true
952
+	 *                                        );
953
+	 *                                        It will produce a url in this structure:
954
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
955
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
956
+	 *                                        month_range]=March%202015
957
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
958
+	 * @return string
959
+	 */
960
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
961
+	{
962
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
963
+		if ($sticky) {
964
+			$request = $_REQUEST;
965
+			unset($request['_wp_http_referer']);
966
+			unset($request['wp_referer']);
967
+			foreach ($request as $key => $value) {
968
+				//do not add nonces
969
+				if (strpos($key, 'nonce') !== false) {
970
+					continue;
971
+				}
972
+				$args['wp_referer[' . $key . ']'] = $value;
973
+			}
974
+		}
975
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * This returns a generated link that will load the related help tab.
982
+	 *
983
+	 * @param  string $help_tab_id the id for the connected help tab
984
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
985
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
986
+	 * @uses EEH_Template::get_help_tab_link()
987
+	 * @return string              generated link
988
+	 */
989
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
990
+	{
991
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 * _add_help_tabs
998
+	 * Note child classes define their help tabs within the page_config array.
999
+	 *
1000
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1001
+	 * @access protected
1002
+	 * @return void
1003
+	 */
1004
+	protected function _add_help_tabs()
1005
+	{
1006
+		$tour_buttons = '';
1007
+		if (isset($this->_page_config[$this->_req_action])) {
1008
+			$config = $this->_page_config[$this->_req_action];
1009
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1010
+			if (isset($this->_help_tour[$this->_req_action])) {
1011
+				$tb = array();
1012
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1013
+				foreach ($this->_help_tour['tours'] as $tour) {
1014
+					//if this is the end tour then we don't need to setup a button
1015
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1016
+						continue;
1017
+					}
1018
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1019
+				}
1020
+				$tour_buttons .= implode('<br />', $tb);
1021
+				$tour_buttons .= '</div></div>';
1022
+			}
1023
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1024
+			if (is_array($config) && isset($config['help_sidebar'])) {
1025
+				//check that the callback given is valid
1026
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1027
+					throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1028
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1029
+				}
1030
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1031
+				$content .= $tour_buttons; //add help tour buttons.
1032
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1033
+				$this->_current_screen->set_help_sidebar($content);
1034
+			}
1035
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1036
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1037
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1038
+			}
1039
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1040
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1041
+				$_ht['id'] = $this->page_slug;
1042
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1043
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1044
+				$this->_current_screen->add_help_tab($_ht);
1045
+			}/**/
1046
+			if ( ! isset($config['help_tabs'])) {
1047
+				return;
1048
+			} //no help tabs for this route
1049
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1050
+				//we're here so there ARE help tabs!
1051
+				//make sure we've got what we need
1052
+				if ( ! isset($cfg['title'])) {
1053
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1054
+				}
1055
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1056
+					throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1057
+							'event_espresso'));
1058
+				}
1059
+				//first priority goes to content.
1060
+				if ( ! empty($cfg['content'])) {
1061
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1062
+					//second priority goes to filename
1063
+				} else if ( ! empty($cfg['filename'])) {
1064
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1065
+					//it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1066
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1067
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1068
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1069
+						EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1070
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1071
+						return;
1072
+					}
1073
+					$template_args['admin_page_obj'] = $this;
1074
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1075
+				} else {
1076
+					$content = '';
1077
+				}
1078
+				//check if callback is valid
1079
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1080
+					EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1081
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1082
+					return;
1083
+				}
1084
+				//setup config array for help tab method
1085
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1086
+				$_ht = array(
1087
+						'id'       => $id,
1088
+						'title'    => $cfg['title'],
1089
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1090
+						'content'  => $content,
1091
+				);
1092
+				$this->_current_screen->add_help_tab($_ht);
1093
+			}
1094
+		}
1095
+	}
1096
+
1097
+
1098
+
1099
+	/**
1100
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1101
+	 *
1102
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1103
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1104
+	 * @access protected
1105
+	 * @return void
1106
+	 */
1107
+	protected function _add_help_tour()
1108
+	{
1109
+		$tours = array();
1110
+		$this->_help_tour = array();
1111
+		//exit early if help tours are turned off globally
1112
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1113
+			return;
1114
+		}
1115
+		//loop through _page_config to find any help_tour defined
1116
+		foreach ($this->_page_config as $route => $config) {
1117
+			//we're only going to set things up for this route
1118
+			if ($route !== $this->_req_action) {
1119
+				continue;
1120
+			}
1121
+			if (isset($config['help_tour'])) {
1122
+				foreach ($config['help_tour'] as $tour) {
1123
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1124
+					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1125
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1126
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1127
+					if ( ! is_readable($file_path)) {
1128
+						EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1129
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1130
+						return;
1131
+					}
1132
+					require_once $file_path;
1133
+					if ( ! class_exists($tour)) {
1134
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1135
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1136
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1137
+						throw new EE_Error(implode('||', $error_msg));
1138
+					}
1139
+					$a = new ReflectionClass($tour);
1140
+					$tour_obj = $a->newInstance($this->_is_caf);
1141
+					$tours[] = $tour_obj;
1142
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1143
+				}
1144
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1145
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1146
+				$tours[] = $end_stop_tour;
1147
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1148
+			}
1149
+		}
1150
+		if ( ! empty($tours)) {
1151
+			$this->_help_tour['tours'] = $tours;
1152
+		}
1153
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1154
+	}
1155
+
1156
+
1157
+
1158
+	/**
1159
+	 * This simply sets up any qtips that have been defined in the page config
1160
+	 *
1161
+	 * @access protected
1162
+	 * @return void
1163
+	 */
1164
+	protected function _add_qtips()
1165
+	{
1166
+		if (isset($this->_route_config['qtips'])) {
1167
+			$qtips = (array)$this->_route_config['qtips'];
1168
+			//load qtip loader
1169
+			$path = array(
1170
+					$this->_get_dir() . '/qtips/',
1171
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1172
+			);
1173
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1174
+		}
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * _set_nav_tabs
1181
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1182
+	 *
1183
+	 * @access protected
1184
+	 * @return void
1185
+	 */
1186
+	protected function _set_nav_tabs()
1187
+	{
1188
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1189
+		$i = 0;
1190
+		foreach ($this->_page_config as $slug => $config) {
1191
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1192
+				continue;
1193
+			} //no nav tab for this config
1194
+			//check for persistent flag
1195
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1196
+				continue;
1197
+			} //nav tab is only to appear when route requested.
1198
+			if ( ! $this->check_user_access($slug, true)) {
1199
+				continue;
1200
+			} //no nav tab becasue current user does not have access.
1201
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1202
+			$this->_nav_tabs[$slug] = array(
1203
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1204
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1205
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1206
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1207
+			);
1208
+			$i++;
1209
+		}
1210
+		//if $this->_nav_tabs is empty then lets set the default
1211
+		if (empty($this->_nav_tabs)) {
1212
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1213
+					'url'       => $this->admin_base_url,
1214
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1215
+					'css_class' => 'nav-tab-active',
1216
+					'order'     => 10,
1217
+			);
1218
+		}
1219
+		//now let's sort the tabs according to order
1220
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 * _set_current_labels
1227
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1228
+	 *
1229
+	 * @access private
1230
+	 * @return void
1231
+	 */
1232
+	private function _set_current_labels()
1233
+	{
1234
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1235
+			foreach ($this->_route_config['labels'] as $label => $text) {
1236
+				if (is_array($text)) {
1237
+					foreach ($text as $sublabel => $subtext) {
1238
+						$this->_labels[$label][$sublabel] = $subtext;
1239
+					}
1240
+				} else {
1241
+					$this->_labels[$label] = $text;
1242
+				}
1243
+			}
1244
+		}
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 *        verifies user access for this admin page
1251
+	 *
1252
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1253
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1254
+	 * @return        BOOL|wp_die()
1255
+	 */
1256
+	public function check_user_access($route_to_check = '', $verify_only = false)
1257
+	{
1258
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1259
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1260
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1261
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1262
+		if (empty($capability) && empty($route_to_check)) {
1263
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1264
+		} else {
1265
+			$capability = empty($capability) ? 'manage_options' : $capability;
1266
+		}
1267
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1268
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1269
+			if ($verify_only) {
1270
+				return false;
1271
+			} else {
1272
+				if ( is_user_logged_in() ) {
1273
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1274
+				} else {
1275
+					return false;
1276
+				}
1277
+			}
1278
+		}
1279
+		return true;
1280
+	}
1281
+
1282
+
1283
+
1284
+	/**
1285
+	 * admin_init_global
1286
+	 * This runs all the code that we want executed within the WP admin_init hook.
1287
+	 * This method executes for ALL EE Admin pages.
1288
+	 *
1289
+	 * @access public
1290
+	 * @return void
1291
+	 */
1292
+	public function admin_init_global()
1293
+	{
1294
+	}
1295
+
1296
+
1297
+
1298
+	/**
1299
+	 * wp_loaded_global
1300
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1301
+	 *
1302
+	 * @access public
1303
+	 * @return void
1304
+	 */
1305
+	public function wp_loaded()
1306
+	{
1307
+	}
1308
+
1309
+
1310
+
1311
+	/**
1312
+	 * admin_notices
1313
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1314
+	 *
1315
+	 * @access public
1316
+	 * @return void
1317
+	 */
1318
+	public function admin_notices_global()
1319
+	{
1320
+		$this->_display_no_javascript_warning();
1321
+		$this->_display_espresso_notices();
1322
+	}
1323
+
1324
+
1325
+
1326
+	public function network_admin_notices_global()
1327
+	{
1328
+		$this->_display_no_javascript_warning();
1329
+		$this->_display_espresso_notices();
1330
+	}
1331
+
1332
+
1333
+
1334
+	/**
1335
+	 * admin_footer_scripts_global
1336
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1337
+	 *
1338
+	 * @access public
1339
+	 * @return void
1340
+	 */
1341
+	public function admin_footer_scripts_global()
1342
+	{
1343
+		$this->_add_admin_page_ajax_loading_img();
1344
+		$this->_add_admin_page_overlay();
1345
+		//if metaboxes are present we need to add the nonce field
1346
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1347
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1348
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1349
+		}
1350
+	}
1351
+
1352
+
1353
+
1354
+	/**
1355
+	 * admin_footer_global
1356
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1357
+	 *
1358
+	 * @access  public
1359
+	 * @return  void
1360
+	 */
1361
+	public function admin_footer_global()
1362
+	{
1363
+		//dialog container for dialog helper
1364
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1365
+		$d_cont .= '<div class="ee-notices"></div>';
1366
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1367
+		$d_cont .= '</div>';
1368
+		echo $d_cont;
1369
+		//help tour stuff?
1370
+		if (isset($this->_help_tour[$this->_req_action])) {
1371
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1372
+		}
1373
+		//current set timezone for timezone js
1374
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1375
+	}
1376
+
1377
+
1378
+
1379
+	/**
1380
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1381
+	 * For child classes:
1382
+	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1383
+	 * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1384
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1385
+	 *    'help_trigger_id' => array(
1386
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1387
+	 *        'content' => __('localized content for popup', 'event_espresso')
1388
+	 *    )
1389
+	 * );
1390
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1391
+	 *
1392
+	 * @access protected
1393
+	 * @return string content
1394
+	 */
1395
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1396
+	{
1397
+		$content = '';
1398
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1399
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1400
+		//loop through the array and setup content
1401
+		foreach ($help_array as $trigger => $help) {
1402
+			//make sure the array is setup properly
1403
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1404
+				throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1405
+						'event_espresso'));
1406
+			}
1407
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1408
+			$template_args = array(
1409
+					'help_popup_id'      => $trigger,
1410
+					'help_popup_title'   => $help['title'],
1411
+					'help_popup_content' => $help['content'],
1412
+			);
1413
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1414
+		}
1415
+		if ($display) {
1416
+			echo $content;
1417
+		} else {
1418
+			return $content;
1419
+		}
1420
+	}
1421
+
1422
+
1423
+
1424
+	/**
1425
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1426
+	 *
1427
+	 * @access private
1428
+	 * @return array properly formatted array for help popup content
1429
+	 */
1430
+	private function _get_help_content()
1431
+	{
1432
+		//what is the method we're looking for?
1433
+		$method_name = '_help_popup_content_' . $this->_req_action;
1434
+		//if method doesn't exist let's get out.
1435
+		if ( ! method_exists($this, $method_name)) {
1436
+			return array();
1437
+		}
1438
+		//k we're good to go let's retrieve the help array
1439
+		$help_array = call_user_func(array($this, $method_name));
1440
+		//make sure we've got an array!
1441
+		if ( ! is_array($help_array)) {
1442
+			throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1443
+		}
1444
+		return $help_array;
1445
+	}
1446
+
1447
+
1448
+
1449
+	/**
1450
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1451
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1452
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1453
+	 *
1454
+	 * @access protected
1455
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1456
+	 * @param boolean $display    if false then we return the trigger string
1457
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1458
+	 * @return string
1459
+	 */
1460
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1461
+	{
1462
+		if (defined('DOING_AJAX')) {
1463
+			return;
1464
+		}
1465
+		//let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1466
+		$help_array = $this->_get_help_content();
1467
+		$help_content = '';
1468
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1469
+			$help_array[$trigger_id] = array(
1470
+					'title'   => __('Missing Content', 'event_espresso'),
1471
+					'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1472
+							'event_espresso'),
1473
+			);
1474
+			$help_content = $this->_set_help_popup_content($help_array, false);
1475
+		}
1476
+		//let's setup the trigger
1477
+		$content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1478
+		$content = $content . $help_content;
1479
+		if ($display) {
1480
+			echo $content;
1481
+		} else {
1482
+			return $content;
1483
+		}
1484
+	}
1485
+
1486
+
1487
+
1488
+	/**
1489
+	 * _add_global_screen_options
1490
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1491
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1492
+	 *
1493
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1494
+	 *         see also WP_Screen object documents...
1495
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1496
+	 * @abstract
1497
+	 * @access private
1498
+	 * @return void
1499
+	 */
1500
+	private function _add_global_screen_options()
1501
+	{
1502
+	}
1503
+
1504
+
1505
+
1506
+	/**
1507
+	 * _add_global_feature_pointers
1508
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1509
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1510
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1511
+	 *
1512
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1513
+	 * @link   http://eamann.com/tech/wordpress-portland/
1514
+	 * @abstract
1515
+	 * @access protected
1516
+	 * @return void
1517
+	 */
1518
+	private function _add_global_feature_pointers()
1519
+	{
1520
+	}
1521
+
1522
+
1523
+
1524
+	/**
1525
+	 * load_global_scripts_styles
1526
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1527
+	 *
1528
+	 * @return void
1529
+	 */
1530
+	public function load_global_scripts_styles()
1531
+	{
1532
+		/** STYLES **/
1533
+		// add debugging styles
1534
+		if (WP_DEBUG) {
1535
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1536
+		}
1537
+		// register all styles
1538
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1539
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1540
+		//helpers styles
1541
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1542
+		/** SCRIPTS **/
1543
+		//register all scripts
1544
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
+		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1546
+		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1547
+		add_filter('FHEE_load_joyride', '__return_true');
1548
+		//script for sorting tables
1549
+		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1550
+		//script for parsing uri's
1551
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1552
+		//and parsing associative serialized form elements
1553
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+		//helpers scripts
1555
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1557
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1558
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1559
+		//google charts
1560
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1561
+		// ENQUEUE ALL BASICS BY DEFAULT
1562
+		wp_enqueue_style('ee-admin-css');
1563
+		wp_enqueue_script('ee_admin_js');
1564
+		wp_enqueue_script('ee-accounting');
1565
+		wp_enqueue_script('jquery-validate');
1566
+		//taking care of metaboxes
1567
+		if (
1568
+			empty($this->_cpt_route)
1569
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1570
+		) {
1571
+			wp_enqueue_script('dashboard');
1572
+		}
1573
+		// LOCALIZED DATA
1574
+		//localize script for ajax lazy loading
1575
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
+		/**
1578
+		 * help tour stuff
1579
+		 */
1580
+		if ( ! empty($this->_help_tour)) {
1581
+			//register the js for kicking things off
1582
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
+			//setup tours for the js tour object
1584
+			foreach ($this->_help_tour['tours'] as $tour) {
1585
+				$tours[] = array(
1586
+						'id'      => $tour->get_slug(),
1587
+						'options' => $tour->get_options(),
1588
+				);
1589
+			}
1590
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
+		}
1593
+	}
1594
+
1595
+
1596
+
1597
+	/**
1598
+	 *        admin_footer_scripts_eei18n_js_strings
1599
+	 *
1600
+	 * @access        public
1601
+	 * @return        void
1602
+	 */
1603
+	public function admin_footer_scripts_eei18n_js_strings()
1604
+	{
1605
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
+		EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
+	}
1646
+
1647
+
1648
+
1649
+	/**
1650
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1651
+	 *
1652
+	 * @access        public
1653
+	 * @return        void
1654
+	 */
1655
+	public function add_xdebug_style()
1656
+	{
1657
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1658
+	}
1659
+
1660
+
1661
+	/************************/
1662
+	/** LIST TABLE METHODS **/
1663
+	/************************/
1664
+	/**
1665
+	 * this sets up the list table if the current view requires it.
1666
+	 *
1667
+	 * @access protected
1668
+	 * @return void
1669
+	 */
1670
+	protected function _set_list_table()
1671
+	{
1672
+		//first is this a list_table view?
1673
+		if ( ! isset($this->_route_config['list_table'])) {
1674
+			return;
1675
+		} //not a list_table view so get out.
1676
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1677
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1678
+			//user error msg
1679
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1680
+			//developer error msg
1681
+			$error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1682
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1683
+			throw new EE_Error($error_msg);
1684
+		}
1685
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1686
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1687
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1688
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1689
+		$this->_set_list_table_view();
1690
+		$this->_set_list_table_object();
1691
+	}
1692
+
1693
+
1694
+
1695
+	/**
1696
+	 *        set current view for List Table
1697
+	 *
1698
+	 * @access public
1699
+	 * @return array
1700
+	 */
1701
+	protected function _set_list_table_view()
1702
+	{
1703
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1704
+		// looking at active items or dumpster diving ?
1705
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1706
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1707
+		} else {
1708
+			$this->_view = sanitize_key($this->_req_data['status']);
1709
+		}
1710
+	}
1711
+
1712
+
1713
+
1714
+	/**
1715
+	 * _set_list_table_object
1716
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1717
+	 *
1718
+	 * @throws \EE_Error
1719
+	 */
1720
+	protected function _set_list_table_object()
1721
+	{
1722
+		if (isset($this->_route_config['list_table'])) {
1723
+			if ( ! class_exists($this->_route_config['list_table'])) {
1724
+				throw new EE_Error(
1725
+						sprintf(
1726
+								__(
1727
+										'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1728
+										'event_espresso'
1729
+								),
1730
+								$this->_route_config['list_table'],
1731
+								get_class($this)
1732
+						)
1733
+				);
1734
+			}
1735
+			$list_table = $this->_route_config['list_table'];
1736
+			$this->_list_table_object = new $list_table($this);
1737
+		}
1738
+	}
1739
+
1740
+
1741
+
1742
+	/**
1743
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1744
+	 *
1745
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1746
+	 *                                                    urls.  The array should be indexed by the view it is being
1747
+	 *                                                    added to.
1748
+	 * @return array
1749
+	 */
1750
+	public function get_list_table_view_RLs($extra_query_args = array())
1751
+	{
1752
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1753
+		if (empty($this->_views)) {
1754
+			$this->_views = array();
1755
+		}
1756
+		// cycle thru views
1757
+		foreach ($this->_views as $key => $view) {
1758
+			$query_args = array();
1759
+			// check for current view
1760
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1761
+			$query_args['action'] = $this->_req_action;
1762
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1763
+			$query_args['status'] = $view['slug'];
1764
+			//merge any other arguments sent in.
1765
+			if (isset($extra_query_args[$view['slug']])) {
1766
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1767
+			}
1768
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1769
+		}
1770
+		return $this->_views;
1771
+	}
1772
+
1773
+
1774
+
1775
+	/**
1776
+	 * _entries_per_page_dropdown
1777
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1778
+	 *
1779
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1780
+	 * @access protected
1781
+	 * @param int $max_entries total number of rows in the table
1782
+	 * @return string
1783
+	 */
1784
+	protected function _entries_per_page_dropdown($max_entries = false)
1785
+	{
1786
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1787
+		$values = array(10, 25, 50, 100);
1788
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1789
+		if ($max_entries) {
1790
+			$values[] = $max_entries;
1791
+			sort($values);
1792
+		}
1793
+		$entries_per_page_dropdown = '
1794 1794
 			<div id="entries-per-page-dv" class="alignleft actions">
1795 1795
 				<label class="hide-if-no-js">
1796 1796
 					Show
1797 1797
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1798
-        foreach ($values as $value) {
1799
-            if ($value < $max_entries) {
1800
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1801
-                $entries_per_page_dropdown .= '
1798
+		foreach ($values as $value) {
1799
+			if ($value < $max_entries) {
1800
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1801
+				$entries_per_page_dropdown .= '
1802 1802
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1803
-            }
1804
-        }
1805
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1806
-        $entries_per_page_dropdown .= '
1803
+			}
1804
+		}
1805
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1806
+		$entries_per_page_dropdown .= '
1807 1807
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1808
-        $entries_per_page_dropdown .= '
1808
+		$entries_per_page_dropdown .= '
1809 1809
 					</select>
1810 1810
 					entries
1811 1811
 				</label>
1812 1812
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1813 1813
 			</div>
1814 1814
 		';
1815
-        return $entries_per_page_dropdown;
1816
-    }
1817
-
1818
-
1819
-
1820
-    /**
1821
-     *        _set_search_attributes
1822
-     *
1823
-     * @access        protected
1824
-     * @return        void
1825
-     */
1826
-    public function _set_search_attributes()
1827
-    {
1828
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1829
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1830
-    }
1831
-
1832
-    /*** END LIST TABLE METHODS **/
1833
-    /*****************************/
1834
-    /**
1835
-     *        _add_registered_metaboxes
1836
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1837
-     *
1838
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1839
-     * @access private
1840
-     * @return void
1841
-     */
1842
-    private function _add_registered_meta_boxes()
1843
-    {
1844
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1845
-        //we only add meta boxes if the page_route calls for it
1846
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1847
-            && is_array(
1848
-                    $this->_route_config['metaboxes']
1849
-            )
1850
-        ) {
1851
-            // this simply loops through the callbacks provided
1852
-            // and checks if there is a corresponding callback registered by the child
1853
-            // if there is then we go ahead and process the metabox loader.
1854
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1855
-                // first check for Closures
1856
-                if ($metabox_callback instanceof Closure) {
1857
-                    $result = $metabox_callback();
1858
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1859
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1860
-                } else {
1861
-                    $result = call_user_func(array($this, &$metabox_callback));
1862
-                }
1863
-                if ($result === false) {
1864
-                    // user error msg
1865
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1866
-                    // developer error msg
1867
-                    $error_msg .= '||' . sprintf(
1868
-                                    __(
1869
-                                            'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1870
-                                            'event_espresso'
1871
-                                    ),
1872
-                                    $metabox_callback
1873
-                            );
1874
-                    throw new EE_Error($error_msg);
1875
-                }
1876
-            }
1877
-        }
1878
-    }
1879
-
1880
-
1881
-
1882
-    /**
1883
-     * _add_screen_columns
1884
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1885
-     *
1886
-     * @access private
1887
-     * @return void
1888
-     */
1889
-    private function _add_screen_columns()
1890
-    {
1891
-        if (
1892
-                is_array($this->_route_config)
1893
-                && isset($this->_route_config['columns'])
1894
-                && is_array($this->_route_config['columns'])
1895
-                && count($this->_route_config['columns']) === 2
1896
-        ) {
1897
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1898
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1899
-            $screen_id = $this->_current_screen->id;
1900
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1901
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1902
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1903
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1904
-            $this->_template_args['screen'] = $this->_current_screen;
1905
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1906
-            //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1907
-            $this->_route_config['has_metaboxes'] = true;
1908
-        }
1909
-    }
1910
-
1911
-
1912
-
1913
-    /**********************************/
1914
-    /** GLOBALLY AVAILABLE METABOXES **/
1915
-    /**
1916
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1917
-     * loaded on.
1918
-     */
1919
-    private function _espresso_news_post_box()
1920
-    {
1921
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1922
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1923
-                $this,
1924
-                'espresso_news_post_box',
1925
-        ), $this->_wp_page_slug, 'side');
1926
-    }
1927
-
1928
-
1929
-
1930
-    /**
1931
-     * Code for setting up espresso ratings request metabox.
1932
-     */
1933
-    protected function _espresso_ratings_request()
1934
-    {
1935
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1936
-            return '';
1937
-        }
1938
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1939
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1940
-                $this,
1941
-                'espresso_ratings_request',
1942
-        ), $this->_wp_page_slug, 'side');
1943
-    }
1944
-
1945
-
1946
-
1947
-    /**
1948
-     * Code for setting up espresso ratings request metabox content.
1949
-     */
1950
-    public function espresso_ratings_request()
1951
-    {
1952
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1953
-        EEH_Template::display_template($template_path, array());
1954
-    }
1955
-
1956
-
1957
-
1958
-    public static function cached_rss_display($rss_id, $url)
1959
-    {
1960
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1961
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1962
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1963
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1964
-        $post = '</div>' . "\n";
1965
-        $cache_key = 'ee_rss_' . md5($rss_id);
1966
-        if (false != ($output = get_transient($cache_key))) {
1967
-            echo $pre . $output . $post;
1968
-            return true;
1969
-        }
1970
-        if ( ! $doing_ajax) {
1971
-            echo $pre . $loading . $post;
1972
-            return false;
1973
-        }
1974
-        ob_start();
1975
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1976
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1977
-        return true;
1978
-    }
1979
-
1980
-
1981
-
1982
-    public function espresso_news_post_box()
1983
-    {
1984
-        ?>
1815
+		return $entries_per_page_dropdown;
1816
+	}
1817
+
1818
+
1819
+
1820
+	/**
1821
+	 *        _set_search_attributes
1822
+	 *
1823
+	 * @access        protected
1824
+	 * @return        void
1825
+	 */
1826
+	public function _set_search_attributes()
1827
+	{
1828
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1829
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1830
+	}
1831
+
1832
+	/*** END LIST TABLE METHODS **/
1833
+	/*****************************/
1834
+	/**
1835
+	 *        _add_registered_metaboxes
1836
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1837
+	 *
1838
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1839
+	 * @access private
1840
+	 * @return void
1841
+	 */
1842
+	private function _add_registered_meta_boxes()
1843
+	{
1844
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1845
+		//we only add meta boxes if the page_route calls for it
1846
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1847
+			&& is_array(
1848
+					$this->_route_config['metaboxes']
1849
+			)
1850
+		) {
1851
+			// this simply loops through the callbacks provided
1852
+			// and checks if there is a corresponding callback registered by the child
1853
+			// if there is then we go ahead and process the metabox loader.
1854
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1855
+				// first check for Closures
1856
+				if ($metabox_callback instanceof Closure) {
1857
+					$result = $metabox_callback();
1858
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1859
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1860
+				} else {
1861
+					$result = call_user_func(array($this, &$metabox_callback));
1862
+				}
1863
+				if ($result === false) {
1864
+					// user error msg
1865
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1866
+					// developer error msg
1867
+					$error_msg .= '||' . sprintf(
1868
+									__(
1869
+											'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1870
+											'event_espresso'
1871
+									),
1872
+									$metabox_callback
1873
+							);
1874
+					throw new EE_Error($error_msg);
1875
+				}
1876
+			}
1877
+		}
1878
+	}
1879
+
1880
+
1881
+
1882
+	/**
1883
+	 * _add_screen_columns
1884
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1885
+	 *
1886
+	 * @access private
1887
+	 * @return void
1888
+	 */
1889
+	private function _add_screen_columns()
1890
+	{
1891
+		if (
1892
+				is_array($this->_route_config)
1893
+				&& isset($this->_route_config['columns'])
1894
+				&& is_array($this->_route_config['columns'])
1895
+				&& count($this->_route_config['columns']) === 2
1896
+		) {
1897
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1898
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1899
+			$screen_id = $this->_current_screen->id;
1900
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1901
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1902
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1903
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1904
+			$this->_template_args['screen'] = $this->_current_screen;
1905
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1906
+			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1907
+			$this->_route_config['has_metaboxes'] = true;
1908
+		}
1909
+	}
1910
+
1911
+
1912
+
1913
+	/**********************************/
1914
+	/** GLOBALLY AVAILABLE METABOXES **/
1915
+	/**
1916
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1917
+	 * loaded on.
1918
+	 */
1919
+	private function _espresso_news_post_box()
1920
+	{
1921
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1922
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1923
+				$this,
1924
+				'espresso_news_post_box',
1925
+		), $this->_wp_page_slug, 'side');
1926
+	}
1927
+
1928
+
1929
+
1930
+	/**
1931
+	 * Code for setting up espresso ratings request metabox.
1932
+	 */
1933
+	protected function _espresso_ratings_request()
1934
+	{
1935
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1936
+			return '';
1937
+		}
1938
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1939
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1940
+				$this,
1941
+				'espresso_ratings_request',
1942
+		), $this->_wp_page_slug, 'side');
1943
+	}
1944
+
1945
+
1946
+
1947
+	/**
1948
+	 * Code for setting up espresso ratings request metabox content.
1949
+	 */
1950
+	public function espresso_ratings_request()
1951
+	{
1952
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1953
+		EEH_Template::display_template($template_path, array());
1954
+	}
1955
+
1956
+
1957
+
1958
+	public static function cached_rss_display($rss_id, $url)
1959
+	{
1960
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1961
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1962
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1963
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1964
+		$post = '</div>' . "\n";
1965
+		$cache_key = 'ee_rss_' . md5($rss_id);
1966
+		if (false != ($output = get_transient($cache_key))) {
1967
+			echo $pre . $output . $post;
1968
+			return true;
1969
+		}
1970
+		if ( ! $doing_ajax) {
1971
+			echo $pre . $loading . $post;
1972
+			return false;
1973
+		}
1974
+		ob_start();
1975
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1976
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1977
+		return true;
1978
+	}
1979
+
1980
+
1981
+
1982
+	public function espresso_news_post_box()
1983
+	{
1984
+		?>
1985 1985
         <div class="padding">
1986 1986
             <div id="espresso_news_post_box_content" class="infolinks">
1987 1987
                 <?php
1988
-                // Get RSS Feed(s)
1989
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1990
-                $url = urlencode($feed_url);
1991
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1992
-                ?>
1988
+				// Get RSS Feed(s)
1989
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1990
+				$url = urlencode($feed_url);
1991
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1992
+				?>
1993 1993
             </div>
1994 1994
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1995 1995
         </div>
1996 1996
         <?php
1997
-    }
1998
-
1999
-
2000
-
2001
-    private function _espresso_links_post_box()
2002
-    {
2003
-        //Hiding until we actually have content to put in here...
2004
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2005
-    }
2006
-
2007
-
2008
-
2009
-    public function espresso_links_post_box()
2010
-    {
2011
-        //Hiding until we actually have content to put in here...
2012
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2013
-        //EEH_Template::display_template( $templatepath );
2014
-    }
2015
-
2016
-
2017
-
2018
-    protected function _espresso_sponsors_post_box()
2019
-    {
2020
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2021
-        if ($show_sponsors) {
2022
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2023
-        }
2024
-    }
2025
-
2026
-
2027
-
2028
-    public function espresso_sponsors_post_box()
2029
-    {
2030
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2031
-        EEH_Template::display_template($templatepath);
2032
-    }
2033
-
2034
-
2035
-
2036
-    private function _publish_post_box()
2037
-    {
2038
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2039
-        //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2040
-        if ( ! empty($this->_labels['publishbox'])) {
2041
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2042
-        } else {
2043
-            $box_label = __('Publish', 'event_espresso');
2044
-        }
2045
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2046
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2047
-    }
2048
-
2049
-
2050
-
2051
-    public function editor_overview()
2052
-    {
2053
-        //if we have extra content set let's add it in if not make sure its empty
2054
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2055
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2056
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2057
-    }
2058
-
2059
-
2060
-    /** end of globally available metaboxes section **/
2061
-    /*************************************************/
2062
-    /**
2063
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2064
-     * protected method.
2065
-     *
2066
-     * @see   $this->_set_publish_post_box_vars for param details
2067
-     * @since 4.6.0
2068
-     */
2069
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2070
-    {
2071
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2072
-    }
2073
-
2074
-
2075
-
2076
-    /**
2077
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2078
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2079
-     * save, and save and close buttons to work properly, then you will want to include a
2080
-     * values for the name and id arguments.
2081
-     *
2082
-     * @todo  Add in validation for name/id arguments.
2083
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2084
-     * @param    int     $id                      id attached to the item published
2085
-     * @param    string  $delete                  page route callback for the delete action
2086
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2087
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2088
-     * @throws \EE_Error
2089
-     */
2090
-    protected function _set_publish_post_box_vars(
2091
-            $name = '',
2092
-            $id = 0,
2093
-            $delete = '',
2094
-            $save_close_redirect_URL = '',
2095
-            $both_btns = true
2096
-    ) {
2097
-        // if Save & Close, use a custom redirect URL or default to the main page?
2098
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2099
-        // create the Save & Close and Save buttons
2100
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2101
-        //if we have extra content set let's add it in if not make sure its empty
2102
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2103
-        if ($delete && ! empty($id)) {
2104
-            //make sure we have a default if just true is sent.
2105
-            $delete = ! empty($delete) ? $delete : 'delete';
2106
-            $delete_link_args = array($name => $id);
2107
-            $delete = $this->get_action_link_or_button(
2108
-                    $delete,
2109
-                    $delete,
2110
-                    $delete_link_args,
2111
-                    'submitdelete deletion',
2112
-                    '',
2113
-                    false
2114
-            );
2115
-        }
2116
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2117
-        if ( ! empty($name) && ! empty($id)) {
2118
-            $hidden_field_arr[$name] = array(
2119
-                    'type'  => 'hidden',
2120
-                    'value' => $id,
2121
-            );
2122
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2123
-        } else {
2124
-            $hf = '';
2125
-        }
2126
-        // add hidden field
2127
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2128
-    }
2129
-
2130
-
2131
-
2132
-    /**
2133
-     *        displays an error message to ppl who have javascript disabled
2134
-     *
2135
-     * @access        private
2136
-     * @return        string
2137
-     */
2138
-    private function _display_no_javascript_warning()
2139
-    {
2140
-        ?>
1997
+	}
1998
+
1999
+
2000
+
2001
+	private function _espresso_links_post_box()
2002
+	{
2003
+		//Hiding until we actually have content to put in here...
2004
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2005
+	}
2006
+
2007
+
2008
+
2009
+	public function espresso_links_post_box()
2010
+	{
2011
+		//Hiding until we actually have content to put in here...
2012
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2013
+		//EEH_Template::display_template( $templatepath );
2014
+	}
2015
+
2016
+
2017
+
2018
+	protected function _espresso_sponsors_post_box()
2019
+	{
2020
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2021
+		if ($show_sponsors) {
2022
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2023
+		}
2024
+	}
2025
+
2026
+
2027
+
2028
+	public function espresso_sponsors_post_box()
2029
+	{
2030
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2031
+		EEH_Template::display_template($templatepath);
2032
+	}
2033
+
2034
+
2035
+
2036
+	private function _publish_post_box()
2037
+	{
2038
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2039
+		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2040
+		if ( ! empty($this->_labels['publishbox'])) {
2041
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2042
+		} else {
2043
+			$box_label = __('Publish', 'event_espresso');
2044
+		}
2045
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2046
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2047
+	}
2048
+
2049
+
2050
+
2051
+	public function editor_overview()
2052
+	{
2053
+		//if we have extra content set let's add it in if not make sure its empty
2054
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2055
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2056
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2057
+	}
2058
+
2059
+
2060
+	/** end of globally available metaboxes section **/
2061
+	/*************************************************/
2062
+	/**
2063
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2064
+	 * protected method.
2065
+	 *
2066
+	 * @see   $this->_set_publish_post_box_vars for param details
2067
+	 * @since 4.6.0
2068
+	 */
2069
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2070
+	{
2071
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2072
+	}
2073
+
2074
+
2075
+
2076
+	/**
2077
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2078
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2079
+	 * save, and save and close buttons to work properly, then you will want to include a
2080
+	 * values for the name and id arguments.
2081
+	 *
2082
+	 * @todo  Add in validation for name/id arguments.
2083
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2084
+	 * @param    int     $id                      id attached to the item published
2085
+	 * @param    string  $delete                  page route callback for the delete action
2086
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2087
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2088
+	 * @throws \EE_Error
2089
+	 */
2090
+	protected function _set_publish_post_box_vars(
2091
+			$name = '',
2092
+			$id = 0,
2093
+			$delete = '',
2094
+			$save_close_redirect_URL = '',
2095
+			$both_btns = true
2096
+	) {
2097
+		// if Save & Close, use a custom redirect URL or default to the main page?
2098
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2099
+		// create the Save & Close and Save buttons
2100
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2101
+		//if we have extra content set let's add it in if not make sure its empty
2102
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2103
+		if ($delete && ! empty($id)) {
2104
+			//make sure we have a default if just true is sent.
2105
+			$delete = ! empty($delete) ? $delete : 'delete';
2106
+			$delete_link_args = array($name => $id);
2107
+			$delete = $this->get_action_link_or_button(
2108
+					$delete,
2109
+					$delete,
2110
+					$delete_link_args,
2111
+					'submitdelete deletion',
2112
+					'',
2113
+					false
2114
+			);
2115
+		}
2116
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2117
+		if ( ! empty($name) && ! empty($id)) {
2118
+			$hidden_field_arr[$name] = array(
2119
+					'type'  => 'hidden',
2120
+					'value' => $id,
2121
+			);
2122
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2123
+		} else {
2124
+			$hf = '';
2125
+		}
2126
+		// add hidden field
2127
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2128
+	}
2129
+
2130
+
2131
+
2132
+	/**
2133
+	 *        displays an error message to ppl who have javascript disabled
2134
+	 *
2135
+	 * @access        private
2136
+	 * @return        string
2137
+	 */
2138
+	private function _display_no_javascript_warning()
2139
+	{
2140
+		?>
2141 2141
         <noscript>
2142 2142
             <div id="no-js-message" class="error">
2143 2143
                 <p style="font-size:1.3em;">
@@ -2147,1267 +2147,1267 @@  discard block
 block discarded – undo
2147 2147
             </div>
2148 2148
         </noscript>
2149 2149
         <?php
2150
-    }
2150
+	}
2151 2151
 
2152 2152
 
2153 2153
 
2154
-    /**
2155
-     *        displays espresso success and/or error notices
2156
-     *
2157
-     * @access        private
2158
-     * @return        string
2159
-     */
2160
-    private function _display_espresso_notices()
2161
-    {
2162
-        $notices = $this->_get_transient(true);
2163
-        echo stripslashes($notices);
2164
-    }
2154
+	/**
2155
+	 *        displays espresso success and/or error notices
2156
+	 *
2157
+	 * @access        private
2158
+	 * @return        string
2159
+	 */
2160
+	private function _display_espresso_notices()
2161
+	{
2162
+		$notices = $this->_get_transient(true);
2163
+		echo stripslashes($notices);
2164
+	}
2165 2165
 
2166 2166
 
2167 2167
 
2168
-    /**
2169
-     *        spinny things pacify the masses
2170
-     *
2171
-     * @access private
2172
-     * @return string
2173
-     */
2174
-    protected function _add_admin_page_ajax_loading_img()
2175
-    {
2176
-        ?>
2168
+	/**
2169
+	 *        spinny things pacify the masses
2170
+	 *
2171
+	 * @access private
2172
+	 * @return string
2173
+	 */
2174
+	protected function _add_admin_page_ajax_loading_img()
2175
+	{
2176
+		?>
2177 2177
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2178 2178
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2179 2179
         </div>
2180 2180
         <?php
2181
-    }
2181
+	}
2182 2182
 
2183 2183
 
2184 2184
 
2185
-    /**
2186
-     *        add admin page overlay for modal boxes
2187
-     *
2188
-     * @access private
2189
-     * @return string
2190
-     */
2191
-    protected function _add_admin_page_overlay()
2192
-    {
2193
-        ?>
2185
+	/**
2186
+	 *        add admin page overlay for modal boxes
2187
+	 *
2188
+	 * @access private
2189
+	 * @return string
2190
+	 */
2191
+	protected function _add_admin_page_overlay()
2192
+	{
2193
+		?>
2194 2194
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2195 2195
         <?php
2196
-    }
2197
-
2198
-
2199
-
2200
-    /**
2201
-     * facade for add_meta_box
2202
-     *
2203
-     * @param string  $action        where the metabox get's displayed
2204
-     * @param string  $title         Title of Metabox (output in metabox header)
2205
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2206
-     * @param array   $callback_args an array of args supplied for the metabox
2207
-     * @param string  $column        what metabox column
2208
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2209
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2210
-     */
2211
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2212
-    {
2213
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2214
-        //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2215
-        if (empty($callback_args) && $create_func) {
2216
-            $callback_args = array(
2217
-                    'template_path' => $this->_template_path,
2218
-                    'template_args' => $this->_template_args,
2219
-            );
2220
-        }
2221
-        //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2222
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2223
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2224
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2225
-    }
2226
-
2227
-
2228
-
2229
-    /**
2230
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2231
-     *
2232
-     * @return [type] [description]
2233
-     */
2234
-    public function display_admin_page_with_metabox_columns()
2235
-    {
2236
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2237
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2238
-        //the final wrapper
2239
-        $this->admin_page_wrapper();
2240
-    }
2241
-
2242
-
2243
-
2244
-    /**
2245
-     *        generates  HTML wrapper for an admin details page
2246
-     *
2247
-     * @access public
2248
-     * @return void
2249
-     */
2250
-    public function display_admin_page_with_sidebar()
2251
-    {
2252
-        $this->_display_admin_page(true);
2253
-    }
2254
-
2255
-
2256
-
2257
-    /**
2258
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2259
-     *
2260
-     * @access public
2261
-     * @return void
2262
-     */
2263
-    public function display_admin_page_with_no_sidebar()
2264
-    {
2265
-        $this->_display_admin_page();
2266
-    }
2267
-
2268
-
2269
-
2270
-    /**
2271
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2272
-     *
2273
-     * @access public
2274
-     * @return void
2275
-     */
2276
-    public function display_about_admin_page()
2277
-    {
2278
-        $this->_display_admin_page(false, true);
2279
-    }
2280
-
2281
-
2282
-
2283
-    /**
2284
-     * display_admin_page
2285
-     * contains the code for actually displaying an admin page
2286
-     *
2287
-     * @access private
2288
-     * @param  boolean $sidebar true with sidebar, false without
2289
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2290
-     * @return void
2291
-     */
2292
-    private function _display_admin_page($sidebar = false, $about = false)
2293
-    {
2294
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2295
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2296
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2297
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2298
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2299
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2300
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2301
-                ? 'poststuff'
2302
-                : 'espresso-default-admin';
2303
-        $template_path = $sidebar
2304
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2305
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2306
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2307
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2308
-        }
2309
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2310
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2311
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2312
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2313
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2314
-        // the final template wrapper
2315
-        $this->admin_page_wrapper($about);
2316
-    }
2317
-
2318
-
2319
-
2320
-    /**
2321
-     * This is used to display caf preview pages.
2322
-     *
2323
-     * @since 4.3.2
2324
-     * @param string $utm_campaign_source what is the key used for google analytics link
2325
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2326
-     * @return void
2327
-     * @throws \EE_Error
2328
-     */
2329
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2330
-    {
2331
-        //let's generate a default preview action button if there isn't one already present.
2332
-        $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2333
-        $buy_now_url = add_query_arg(
2334
-                array(
2335
-                        'ee_ver'       => 'ee4',
2336
-                        'utm_source'   => 'ee4_plugin_admin',
2337
-                        'utm_medium'   => 'link',
2338
-                        'utm_campaign' => $utm_campaign_source,
2339
-                        'utm_content'  => 'buy_now_button',
2340
-                ),
2341
-                'http://eventespresso.com/pricing/'
2342
-        );
2343
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2344
-                ? $this->get_action_link_or_button(
2345
-                        '',
2346
-                        'buy_now',
2347
-                        array(),
2348
-                        'button-primary button-large',
2349
-                        $buy_now_url,
2350
-                        true
2351
-                )
2352
-                : $this->_template_args['preview_action_button'];
2353
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2354
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2355
-                $template_path,
2356
-                $this->_template_args,
2357
-                true
2358
-        );
2359
-        $this->_display_admin_page($display_sidebar);
2360
-    }
2361
-
2362
-
2363
-
2364
-    /**
2365
-     * display_admin_list_table_page_with_sidebar
2366
-     * generates HTML wrapper for an admin_page with list_table
2367
-     *
2368
-     * @access public
2369
-     * @return void
2370
-     */
2371
-    public function display_admin_list_table_page_with_sidebar()
2372
-    {
2373
-        $this->_display_admin_list_table_page(true);
2374
-    }
2375
-
2376
-
2377
-
2378
-    /**
2379
-     * display_admin_list_table_page_with_no_sidebar
2380
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2381
-     *
2382
-     * @access public
2383
-     * @return void
2384
-     */
2385
-    public function display_admin_list_table_page_with_no_sidebar()
2386
-    {
2387
-        $this->_display_admin_list_table_page();
2388
-    }
2389
-
2390
-
2391
-
2392
-    /**
2393
-     * generates html wrapper for an admin_list_table page
2394
-     *
2395
-     * @access private
2396
-     * @param boolean $sidebar whether to display with sidebar or not.
2397
-     * @return void
2398
-     */
2399
-    private function _display_admin_list_table_page($sidebar = false)
2400
-    {
2401
-        //setup search attributes
2402
-        $this->_set_search_attributes();
2403
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2404
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2405
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2406
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2407
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2408
-        $this->_template_args['list_table'] = $this->_list_table_object;
2409
-        $this->_template_args['current_route'] = $this->_req_action;
2410
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2411
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2412
-        if ( ! empty($ajax_sorting_callback)) {
2413
-            $sortable_list_table_form_fields = wp_nonce_field(
2414
-                    $ajax_sorting_callback . '_nonce',
2415
-                    $ajax_sorting_callback . '_nonce',
2416
-                    false,
2417
-                    false
2418
-            );
2419
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2420
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2421
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2422
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2423
-        } else {
2424
-            $sortable_list_table_form_fields = '';
2425
-        }
2426
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2427
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2428
-        $nonce_ref = $this->_req_action . '_nonce';
2429
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2430
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2431
-        //display message about search results?
2432
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2433
-                ? '<p class="ee-search-results">' . sprintf(
2434
-                        esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2435
-                        trim($this->_req_data['s'], '%')
2436
-                ) . '</p>'
2437
-                : '';
2438
-        // filter before_list_table template arg
2439
-        $this->_template_args['before_list_table'] = apply_filters(
2440
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2441
-            $this->_template_args['before_list_table'],
2442
-            $this->page_slug,
2443
-            $this->_req_data,
2444
-            $this->_req_action
2445
-        );
2446
-        // convert to array and filter again
2447
-        // arrays are easier to inject new items in a specific location,
2448
-        // but would not be backwards compatible, so we have to add a new filter
2449
-        $this->_template_args['before_list_table'] = implode(
2450
-            " \n",
2451
-            (array) apply_filters(
2452
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2453
-                (array) $this->_template_args['before_list_table'],
2454
-                $this->page_slug,
2455
-                $this->_req_data,
2456
-                $this->_req_action
2457
-            )
2458
-        );
2459
-        // filter after_list_table template arg
2460
-        $this->_template_args['after_list_table'] = apply_filters(
2461
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2462
-            $this->_template_args['after_list_table'],
2463
-            $this->page_slug,
2464
-            $this->_req_data,
2465
-            $this->_req_action
2466
-        );
2467
-        // convert to array and filter again
2468
-        // arrays are easier to inject new items in a specific location,
2469
-        // but would not be backwards compatible, so we have to add a new filter
2470
-        $this->_template_args['after_list_table'] = implode(
2471
-            " \n",
2472
-            (array) apply_filters(
2473
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2474
-                (array) $this->_template_args['after_list_table'],
2475
-                $this->page_slug,
2476
-                $this->_req_data,
2477
-                $this->_req_action
2478
-            )
2479
-        );
2480
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2481
-                $template_path,
2482
-                $this->_template_args,
2483
-                true
2484
-        );
2485
-        // the final template wrapper
2486
-        if ($sidebar) {
2487
-            $this->display_admin_page_with_sidebar();
2488
-        } else {
2489
-            $this->display_admin_page_with_no_sidebar();
2490
-        }
2491
-    }
2492
-
2493
-
2494
-
2495
-    /**
2496
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2497
-     * $items are expected in an array in the following format:
2498
-     * $legend_items = array(
2499
-     *        'item_id' => array(
2500
-     *            'icon' => 'http://url_to_icon_being_described.png',
2501
-     *            'desc' => __('localized description of item');
2502
-     *        )
2503
-     * );
2504
-     *
2505
-     * @param  array $items see above for format of array
2506
-     * @return string        html string of legend
2507
-     */
2508
-    protected function _display_legend($items)
2509
-    {
2510
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2511
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2512
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2513
-    }
2514
-
2515
-
2516
-    /**
2517
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2518
-     * The returned json object is created from an array in the following format:
2519
-     * array(
2520
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2521
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2522
-     *  'notices' => '', // - contains any EE_Error formatted notices
2523
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2524
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2525
-     *  specific template args that might be included in here)
2526
-     * )
2527
-     * The json object is populated by whatever is set in the $_template_args property.
2528
-     *
2529
-     * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2530
-     * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2531
-     * @return void
2532
-     */
2533
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
2534
-    {
2535
-        //make sure any EE_Error notices have been handled.
2536
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2537
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2538
-        unset($this->_template_args['data']);
2539
-        $json = array(
2540
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2541
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2542
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2543
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2544
-                'notices'   => EE_Error::get_notices(),
2545
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2546
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2547
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2548
-        );
2549
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2550
-        if (null === error_get_last() || ! headers_sent()) {
2551
-            header('Content-Type: application/json; charset=UTF-8');
2552
-        }
2553
-        echo wp_json_encode($json);
2554
-
2555
-        exit();
2556
-    }
2557
-
2558
-
2559
-
2560
-    /**
2561
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2562
-     *
2563
-     * @return void
2564
-     * @throws EE_Error
2565
-     */
2566
-    public function return_json()
2567
-    {
2568
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2569
-            $this->_return_json();
2570
-        } else {
2571
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2572
-        }
2573
-    }
2574
-
2575
-
2576
-
2577
-    /**
2578
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2579
-     *
2580
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2581
-     * @access   public
2582
-     */
2583
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2584
-    {
2585
-        $this->_hook_obj = $hook_obj;
2586
-    }
2587
-
2588
-
2589
-
2590
-    /**
2591
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2592
-     *
2593
-     * @access public
2594
-     * @param  boolean $about whether to use the special about page wrapper or default.
2595
-     * @return void
2596
-     */
2597
-    public function admin_page_wrapper($about = false)
2598
-    {
2599
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2600
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2601
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2602
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2603
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2604
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2605
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2606
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2607
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2608
-        // load settings page wrapper template
2609
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2610
-        //about page?
2611
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2612
-        if (defined('DOING_AJAX')) {
2613
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2614
-            $this->_return_json();
2615
-        } else {
2616
-            EEH_Template::display_template($template_path, $this->_template_args);
2617
-        }
2618
-    }
2619
-
2620
-
2621
-
2622
-    /**
2623
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2624
-     *
2625
-     * @return string html
2626
-     */
2627
-    protected function _get_main_nav_tabs()
2628
-    {
2629
-        //let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2630
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2631
-    }
2632
-
2633
-
2634
-
2635
-    /**
2636
-     *        sort nav tabs
2637
-     *
2638
-     * @access public
2639
-     * @param $a
2640
-     * @param $b
2641
-     * @return int
2642
-     */
2643
-    private function _sort_nav_tabs($a, $b)
2644
-    {
2645
-        if ($a['order'] == $b['order']) {
2646
-            return 0;
2647
-        }
2648
-        return ($a['order'] < $b['order']) ? -1 : 1;
2649
-    }
2650
-
2651
-
2652
-
2653
-    /**
2654
-     *    generates HTML for the forms used on admin pages
2655
-     *
2656
-     * @access protected
2657
-     * @param    array $input_vars - array of input field details
2658
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2659
-     * @return string
2660
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2661
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2662
-     */
2663
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2664
-    {
2665
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2666
-        return $content;
2667
-    }
2668
-
2669
-
2670
-
2671
-    /**
2672
-     * generates the "Save" and "Save & Close" buttons for edit forms
2673
-     *
2674
-     * @access protected
2675
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2676
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2677
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2678
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2679
-     */
2680
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2681
-    {
2682
-        //make sure $text and $actions are in an array
2683
-        $text = (array)$text;
2684
-        $actions = (array)$actions;
2685
-        $referrer_url = empty($referrer) ? '' : $referrer;
2686
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2687
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2688
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2689
-        $default_names = array('save', 'save_and_close');
2690
-        //add in a hidden index for the current page (so save and close redirects properly)
2691
-        $this->_template_args['save_buttons'] = $referrer_url;
2692
-        foreach ($button_text as $key => $button) {
2693
-            $ref = $default_names[$key];
2694
-            $id = $this->_current_view . '_' . $ref;
2695
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2696
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2697
-            if ( ! $both) {
2698
-                break;
2699
-            }
2700
-        }
2701
-    }
2702
-
2703
-
2704
-
2705
-    /**
2706
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2707
-     *
2708
-     * @see   $this->_set_add_edit_form_tags() for details on params
2709
-     * @since 4.6.0
2710
-     * @param string $route
2711
-     * @param array  $additional_hidden_fields
2712
-     */
2713
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2714
-    {
2715
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2716
-    }
2717
-
2718
-
2719
-
2720
-    /**
2721
-     * set form open and close tags on add/edit pages.
2722
-     *
2723
-     * @access protected
2724
-     * @param string $route                    the route you want the form to direct to
2725
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2726
-     * @return void
2727
-     */
2728
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2729
-    {
2730
-        if (empty($route)) {
2731
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2732
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2733
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2734
-        }
2735
-        // open form
2736
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2737
-        // add nonce
2738
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2739
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2740
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2741
-        // add REQUIRED form action
2742
-        $hidden_fields = array(
2743
-                'action' => array('type' => 'hidden', 'value' => $route),
2744
-        );
2745
-        // merge arrays
2746
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2747
-        // generate form fields
2748
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2749
-        // add fields to form
2750
-        foreach ((array)$form_fields as $field_name => $form_field) {
2751
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2752
-        }
2753
-        // close form
2754
-        $this->_template_args['after_admin_page_content'] = '</form>';
2755
-    }
2756
-
2757
-
2758
-
2759
-    /**
2760
-     * Public Wrapper for _redirect_after_action() method since its
2761
-     * discovered it would be useful for external code to have access.
2762
-     *
2763
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2764
-     * @since 4.5.0
2765
-     */
2766
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2767
-    {
2768
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2769
-    }
2770
-
2771
-
2772
-
2773
-    /**
2774
-     *    _redirect_after_action
2775
-     *
2776
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2777
-     * @param string $what               - what the action was performed on
2778
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2779
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2780
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2781
-     * @access protected
2782
-     * @return void
2783
-     */
2784
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2785
-    {
2786
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2787
-        //class name for actions/filters.
2788
-        $classname = get_class($this);
2789
-        //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2790
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2791
-        $notices = EE_Error::get_notices(false);
2792
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2793
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2794
-            EE_Error::overwrite_success();
2795
-        }
2796
-        if ( ! empty($what) && ! empty($action_desc)) {
2797
-            // how many records affected ? more than one record ? or just one ?
2798
-            if ($success > 1 && empty($notices['errors'])) {
2799
-                // set plural msg
2800
-                EE_Error::add_success(
2801
-                        sprintf(
2802
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2803
-                                $what,
2804
-                                $action_desc
2805
-                        ),
2806
-                        __FILE__, __FUNCTION__, __LINE__
2807
-                );
2808
-            } else if ($success == 1 && empty($notices['errors'])) {
2809
-                // set singular msg
2810
-                EE_Error::add_success(
2811
-                        sprintf(
2812
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2813
-                                $what,
2814
-                                $action_desc
2815
-                        ),
2816
-                        __FILE__, __FUNCTION__, __LINE__
2817
-                );
2818
-            }
2819
-        }
2820
-        // check that $query_args isn't something crazy
2821
-        if ( ! is_array($query_args)) {
2822
-            $query_args = array();
2823
-        }
2824
-        /**
2825
-         * Allow injecting actions before the query_args are modified for possible different
2826
-         * redirections on save and close actions
2827
-         *
2828
-         * @since 4.2.0
2829
-         * @param array $query_args       The original query_args array coming into the
2830
-         *                                method.
2831
-         */
2832
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2833
-        //calculate where we're going (if we have a "save and close" button pushed)
2834
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2835
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2836
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2837
-            // regenerate query args array from referrer URL
2838
-            parse_str($parsed_url['query'], $query_args);
2839
-            // correct page and action will be in the query args now
2840
-            $redirect_url = admin_url('admin.php');
2841
-        }
2842
-        //merge any default query_args set in _default_route_query_args property
2843
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2844
-            $args_to_merge = array();
2845
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2846
-                //is there a wp_referer array in our _default_route_query_args property?
2847
-                if ($query_param == 'wp_referer') {
2848
-                    $query_value = (array)$query_value;
2849
-                    foreach ($query_value as $reference => $value) {
2850
-                        if (strpos($reference, 'nonce') !== false) {
2851
-                            continue;
2852
-                        }
2853
-                        //finally we will override any arguments in the referer with
2854
-                        //what might be set on the _default_route_query_args array.
2855
-                        if (isset($this->_default_route_query_args[$reference])) {
2856
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2857
-                        } else {
2858
-                            $args_to_merge[$reference] = urlencode($value);
2859
-                        }
2860
-                    }
2861
-                    continue;
2862
-                }
2863
-                $args_to_merge[$query_param] = $query_value;
2864
-            }
2865
-            //now let's merge these arguments but override with what was specifically sent in to the
2866
-            //redirect.
2867
-            $query_args = array_merge($args_to_merge, $query_args);
2868
-        }
2869
-        $this->_process_notices($query_args);
2870
-        // generate redirect url
2871
-        // if redirecting to anything other than the main page, add a nonce
2872
-        if (isset($query_args['action'])) {
2873
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2874
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2875
-        }
2876
-        //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2877
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2878
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2879
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2880
-        if (defined('DOING_AJAX')) {
2881
-            $default_data = array(
2882
-                    'close'        => true,
2883
-                    'redirect_url' => $redirect_url,
2884
-                    'where'        => 'main',
2885
-                    'what'         => 'append',
2886
-            );
2887
-            $this->_template_args['success'] = $success;
2888
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2889
-            $this->_return_json();
2890
-        }
2891
-        wp_safe_redirect($redirect_url);
2892
-        exit();
2893
-    }
2894
-
2895
-
2896
-
2897
-    /**
2898
-     * process any notices before redirecting (or returning ajax request)
2899
-     * This method sets the $this->_template_args['notices'] attribute;
2900
-     *
2901
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2902
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2903
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2904
-     * @return void
2905
-     */
2906
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2907
-    {
2908
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2909
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2910
-            $notices = EE_Error::get_notices(false);
2911
-            if (empty($this->_template_args['success'])) {
2912
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2913
-            }
2914
-            if (empty($this->_template_args['errors'])) {
2915
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2916
-            }
2917
-            if (empty($this->_template_args['attention'])) {
2918
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2919
-            }
2920
-        }
2921
-        $this->_template_args['notices'] = EE_Error::get_notices();
2922
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2923
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2924
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2925
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2926
-        }
2927
-    }
2928
-
2929
-
2930
-
2931
-    /**
2932
-     * get_action_link_or_button
2933
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2934
-     *
2935
-     * @param string $action        use this to indicate which action the url is generated with.
2936
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2937
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2938
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2939
-     * @param string $base_url      If this is not provided
2940
-     *                              the _admin_base_url will be used as the default for the button base_url.
2941
-     *                              Otherwise this value will be used.
2942
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2943
-     * @return string
2944
-     * @throws \EE_Error
2945
-     */
2946
-    public function get_action_link_or_button(
2947
-            $action,
2948
-            $type = 'add',
2949
-            $extra_request = array(),
2950
-            $class = 'button-primary',
2951
-            $base_url = '',
2952
-            $exclude_nonce = false
2953
-    ) {
2954
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2955
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2956
-            throw new EE_Error(
2957
-                    sprintf(
2958
-                            __(
2959
-                                    'There is no page route for given action for the button.  This action was given: %s',
2960
-                                    'event_espresso'
2961
-                            ),
2962
-                            $action
2963
-                    )
2964
-            );
2965
-        }
2966
-        if ( ! isset($this->_labels['buttons'][$type])) {
2967
-            throw new EE_Error(
2968
-                    sprintf(
2969
-                            __(
2970
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2971
-                                    'event_espresso'
2972
-                            ),
2973
-                            $type
2974
-                    )
2975
-            );
2976
-        }
2977
-        //finally check user access for this button.
2978
-        $has_access = $this->check_user_access($action, true);
2979
-        if ( ! $has_access) {
2980
-            return '';
2981
-        }
2982
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2983
-        $query_args = array(
2984
-                'action' => $action,
2985
-        );
2986
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2987
-        if ( ! empty($extra_request)) {
2988
-            $query_args = array_merge($extra_request, $query_args);
2989
-        }
2990
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2991
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2992
-    }
2993
-
2994
-
2995
-
2996
-    /**
2997
-     * _per_page_screen_option
2998
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2999
-     *
3000
-     * @return void
3001
-     */
3002
-    protected function _per_page_screen_option()
3003
-    {
3004
-        $option = 'per_page';
3005
-        $args = array(
3006
-                'label'   => $this->_admin_page_title,
3007
-                'default' => 10,
3008
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3009
-        );
3010
-        //ONLY add the screen option if the user has access to it.
3011
-        if ($this->check_user_access($this->_current_view, true)) {
3012
-            add_screen_option($option, $args);
3013
-        }
3014
-    }
3015
-
3016
-
3017
-
3018
-    /**
3019
-     * set_per_page_screen_option
3020
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3021
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3022
-     *
3023
-     * @access private
3024
-     * @return void
3025
-     */
3026
-    private function _set_per_page_screen_options()
3027
-    {
3028
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3029
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3030
-            if ( ! $user = wp_get_current_user()) {
3031
-                return;
3032
-            }
3033
-            $option = $_POST['wp_screen_options']['option'];
3034
-            $value = $_POST['wp_screen_options']['value'];
3035
-            if ($option != sanitize_key($option)) {
3036
-                return;
3037
-            }
3038
-            $map_option = $option;
3039
-            $option = str_replace('-', '_', $option);
3040
-            switch ($map_option) {
3041
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3042
-                    $value = (int)$value;
3043
-                    if ($value < 1 || $value > 999) {
3044
-                        return;
3045
-                    }
3046
-                    break;
3047
-                default:
3048
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3049
-                    if (false === $value) {
3050
-                        return;
3051
-                    }
3052
-                    break;
3053
-            }
3054
-            update_user_meta($user->ID, $option, $value);
3055
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3056
-            exit;
3057
-        }
3058
-    }
3059
-
3060
-
3061
-
3062
-    /**
3063
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3064
-     *
3065
-     * @param array $data array that will be assigned to template args.
3066
-     */
3067
-    public function set_template_args($data)
3068
-    {
3069
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3070
-    }
3071
-
3072
-
3073
-
3074
-    /**
3075
-     * This makes available the WP transient system for temporarily moving data between routes
3076
-     *
3077
-     * @access protected
3078
-     * @param string $route             the route that should receive the transient
3079
-     * @param array  $data              the data that gets sent
3080
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3081
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3082
-     * @return void
3083
-     */
3084
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3085
-    {
3086
-        $user_id = get_current_user_id();
3087
-        if ( ! $skip_route_verify) {
3088
-            $this->_verify_route($route);
3089
-        }
3090
-        //now let's set the string for what kind of transient we're setting
3091
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3092
-        $data = $notices ? array('notices' => $data) : $data;
3093
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3094
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3095
-        if ($existing) {
3096
-            $data = array_merge((array)$data, (array)$existing);
3097
-        }
3098
-        if (is_multisite() && is_network_admin()) {
3099
-            set_site_transient($transient, $data, 8);
3100
-        } else {
3101
-            set_transient($transient, $data, 8);
3102
-        }
3103
-    }
3104
-
3105
-
3106
-
3107
-    /**
3108
-     * this retrieves the temporary transient that has been set for moving data between routes.
3109
-     *
3110
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3111
-     * @return mixed data
3112
-     */
3113
-    protected function _get_transient($notices = false, $route = false)
3114
-    {
3115
-        $user_id = get_current_user_id();
3116
-        $route = ! $route ? $this->_req_action : $route;
3117
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3118
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3119
-        //delete transient after retrieval (just in case it hasn't expired);
3120
-        if (is_multisite() && is_network_admin()) {
3121
-            delete_site_transient($transient);
3122
-        } else {
3123
-            delete_transient($transient);
3124
-        }
3125
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3126
-    }
3127
-
3128
-
3129
-
3130
-    /**
3131
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3132
-     * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3133
-     *
3134
-     * @return void
3135
-     */
3136
-    protected function _transient_garbage_collection()
3137
-    {
3138
-        global $wpdb;
3139
-        //retrieve all existing transients
3140
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3141
-        if ($results = $wpdb->get_results($query)) {
3142
-            foreach ($results as $result) {
3143
-                $transient = str_replace('_transient_', '', $result->option_name);
3144
-                get_transient($transient);
3145
-                if (is_multisite() && is_network_admin()) {
3146
-                    get_site_transient($transient);
3147
-                }
3148
-            }
3149
-        }
3150
-    }
3151
-
3152
-
3153
-
3154
-    /**
3155
-     * get_view
3156
-     *
3157
-     * @access public
3158
-     * @return string content of _view property
3159
-     */
3160
-    public function get_view()
3161
-    {
3162
-        return $this->_view;
3163
-    }
3164
-
3165
-
3166
-
3167
-    /**
3168
-     * getter for the protected $_views property
3169
-     *
3170
-     * @return array
3171
-     */
3172
-    public function get_views()
3173
-    {
3174
-        return $this->_views;
3175
-    }
3176
-
3177
-
3178
-
3179
-    /**
3180
-     * get_current_page
3181
-     *
3182
-     * @access public
3183
-     * @return string _current_page property value
3184
-     */
3185
-    public function get_current_page()
3186
-    {
3187
-        return $this->_current_page;
3188
-    }
3189
-
3190
-
3191
-
3192
-    /**
3193
-     * get_current_view
3194
-     *
3195
-     * @access public
3196
-     * @return string _current_view property value
3197
-     */
3198
-    public function get_current_view()
3199
-    {
3200
-        return $this->_current_view;
3201
-    }
3202
-
3203
-
3204
-
3205
-    /**
3206
-     * get_current_screen
3207
-     *
3208
-     * @access public
3209
-     * @return object The current WP_Screen object
3210
-     */
3211
-    public function get_current_screen()
3212
-    {
3213
-        return $this->_current_screen;
3214
-    }
3215
-
3216
-
3217
-
3218
-    /**
3219
-     * get_current_page_view_url
3220
-     *
3221
-     * @access public
3222
-     * @return string This returns the url for the current_page_view.
3223
-     */
3224
-    public function get_current_page_view_url()
3225
-    {
3226
-        return $this->_current_page_view_url;
3227
-    }
3228
-
3229
-
3230
-
3231
-    /**
3232
-     * just returns the _req_data property
3233
-     *
3234
-     * @return array
3235
-     */
3236
-    public function get_request_data()
3237
-    {
3238
-        return $this->_req_data;
3239
-    }
3240
-
3241
-
3242
-
3243
-    /**
3244
-     * returns the _req_data protected property
3245
-     *
3246
-     * @return string
3247
-     */
3248
-    public function get_req_action()
3249
-    {
3250
-        return $this->_req_action;
3251
-    }
3252
-
3253
-
3254
-
3255
-    /**
3256
-     * @return bool  value of $_is_caf property
3257
-     */
3258
-    public function is_caf()
3259
-    {
3260
-        return $this->_is_caf;
3261
-    }
3262
-
3263
-
3264
-
3265
-    /**
3266
-     * @return mixed
3267
-     */
3268
-    public function default_espresso_metaboxes()
3269
-    {
3270
-        return $this->_default_espresso_metaboxes;
3271
-    }
3272
-
3273
-
3274
-
3275
-    /**
3276
-     * @return mixed
3277
-     */
3278
-    public function admin_base_url()
3279
-    {
3280
-        return $this->_admin_base_url;
3281
-    }
3282
-
3283
-
3284
-
3285
-    /**
3286
-     * @return mixed
3287
-     */
3288
-    public function wp_page_slug()
3289
-    {
3290
-        return $this->_wp_page_slug;
3291
-    }
3292
-
3293
-
3294
-
3295
-    /**
3296
-     * updates  espresso configuration settings
3297
-     *
3298
-     * @access    protected
3299
-     * @param string                   $tab
3300
-     * @param EE_Config_Base|EE_Config $config
3301
-     * @param string                   $file file where error occurred
3302
-     * @param string                   $func function  where error occurred
3303
-     * @param string                   $line line no where error occurred
3304
-     * @return boolean
3305
-     */
3306
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3307
-    {
3308
-        //remove any options that are NOT going to be saved with the config settings.
3309
-        if (isset($config->core->ee_ueip_optin)) {
3310
-            $config->core->ee_ueip_has_notified = true;
3311
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3312
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3313
-            update_option('ee_ueip_has_notified', true);
3314
-        }
3315
-        // and save it (note we're also doing the network save here)
3316
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3317
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3318
-        if ($config_saved && $net_saved) {
3319
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3320
-            return true;
3321
-        } else {
3322
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3323
-            return false;
3324
-        }
3325
-    }
3326
-
3327
-
3328
-
3329
-    /**
3330
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3331
-     *
3332
-     * @return array
3333
-     */
3334
-    public function get_yes_no_values()
3335
-    {
3336
-        return $this->_yes_no_values;
3337
-    }
3338
-
3339
-
3340
-
3341
-    protected function _get_dir()
3342
-    {
3343
-        $reflector = new ReflectionClass(get_class($this));
3344
-        return dirname($reflector->getFileName());
3345
-    }
3346
-
3347
-
3348
-
3349
-    /**
3350
-     * A helper for getting a "next link".
3351
-     *
3352
-     * @param string $url   The url to link to
3353
-     * @param string $class The class to use.
3354
-     * @return string
3355
-     */
3356
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3357
-    {
3358
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3359
-    }
3360
-
3361
-
3362
-
3363
-    /**
3364
-     * A helper for getting a "previous link".
3365
-     *
3366
-     * @param string $url   The url to link to
3367
-     * @param string $class The class to use.
3368
-     * @return string
3369
-     */
3370
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3371
-    {
3372
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3373
-    }
3374
-
3375
-
3376
-
3377
-
3378
-
3379
-
3380
-
3381
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3382
-    /**
3383
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3384
-     * array.
3385
-     *
3386
-     * @return bool success/fail
3387
-     */
3388
-    protected function _process_resend_registration()
3389
-    {
3390
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3391
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3392
-        return $this->_template_args['success'];
3393
-    }
3394
-
3395
-
3396
-
3397
-    /**
3398
-     * This automatically processes any payment message notifications when manual payment has been applied.
3399
-     *
3400
-     * @access protected
3401
-     * @param \EE_Payment $payment
3402
-     * @return bool success/fail
3403
-     */
3404
-    protected function _process_payment_notification(EE_Payment $payment)
3405
-    {
3406
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3407
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3408
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3409
-        return $this->_template_args['success'];
3410
-    }
2196
+	}
2197
+
2198
+
2199
+
2200
+	/**
2201
+	 * facade for add_meta_box
2202
+	 *
2203
+	 * @param string  $action        where the metabox get's displayed
2204
+	 * @param string  $title         Title of Metabox (output in metabox header)
2205
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2206
+	 * @param array   $callback_args an array of args supplied for the metabox
2207
+	 * @param string  $column        what metabox column
2208
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2209
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2210
+	 */
2211
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2212
+	{
2213
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2214
+		//if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2215
+		if (empty($callback_args) && $create_func) {
2216
+			$callback_args = array(
2217
+					'template_path' => $this->_template_path,
2218
+					'template_args' => $this->_template_args,
2219
+			);
2220
+		}
2221
+		//if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2222
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2223
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2224
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2225
+	}
2226
+
2227
+
2228
+
2229
+	/**
2230
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2231
+	 *
2232
+	 * @return [type] [description]
2233
+	 */
2234
+	public function display_admin_page_with_metabox_columns()
2235
+	{
2236
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2237
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2238
+		//the final wrapper
2239
+		$this->admin_page_wrapper();
2240
+	}
2241
+
2242
+
2243
+
2244
+	/**
2245
+	 *        generates  HTML wrapper for an admin details page
2246
+	 *
2247
+	 * @access public
2248
+	 * @return void
2249
+	 */
2250
+	public function display_admin_page_with_sidebar()
2251
+	{
2252
+		$this->_display_admin_page(true);
2253
+	}
2254
+
2255
+
2256
+
2257
+	/**
2258
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2259
+	 *
2260
+	 * @access public
2261
+	 * @return void
2262
+	 */
2263
+	public function display_admin_page_with_no_sidebar()
2264
+	{
2265
+		$this->_display_admin_page();
2266
+	}
2267
+
2268
+
2269
+
2270
+	/**
2271
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2272
+	 *
2273
+	 * @access public
2274
+	 * @return void
2275
+	 */
2276
+	public function display_about_admin_page()
2277
+	{
2278
+		$this->_display_admin_page(false, true);
2279
+	}
2280
+
2281
+
2282
+
2283
+	/**
2284
+	 * display_admin_page
2285
+	 * contains the code for actually displaying an admin page
2286
+	 *
2287
+	 * @access private
2288
+	 * @param  boolean $sidebar true with sidebar, false without
2289
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2290
+	 * @return void
2291
+	 */
2292
+	private function _display_admin_page($sidebar = false, $about = false)
2293
+	{
2294
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2295
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2296
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2297
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2298
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2299
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2300
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2301
+				? 'poststuff'
2302
+				: 'espresso-default-admin';
2303
+		$template_path = $sidebar
2304
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2305
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2306
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2307
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2308
+		}
2309
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2310
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2311
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2312
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2313
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2314
+		// the final template wrapper
2315
+		$this->admin_page_wrapper($about);
2316
+	}
2317
+
2318
+
2319
+
2320
+	/**
2321
+	 * This is used to display caf preview pages.
2322
+	 *
2323
+	 * @since 4.3.2
2324
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2325
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2326
+	 * @return void
2327
+	 * @throws \EE_Error
2328
+	 */
2329
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2330
+	{
2331
+		//let's generate a default preview action button if there isn't one already present.
2332
+		$this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2333
+		$buy_now_url = add_query_arg(
2334
+				array(
2335
+						'ee_ver'       => 'ee4',
2336
+						'utm_source'   => 'ee4_plugin_admin',
2337
+						'utm_medium'   => 'link',
2338
+						'utm_campaign' => $utm_campaign_source,
2339
+						'utm_content'  => 'buy_now_button',
2340
+				),
2341
+				'http://eventespresso.com/pricing/'
2342
+		);
2343
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2344
+				? $this->get_action_link_or_button(
2345
+						'',
2346
+						'buy_now',
2347
+						array(),
2348
+						'button-primary button-large',
2349
+						$buy_now_url,
2350
+						true
2351
+				)
2352
+				: $this->_template_args['preview_action_button'];
2353
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2354
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2355
+				$template_path,
2356
+				$this->_template_args,
2357
+				true
2358
+		);
2359
+		$this->_display_admin_page($display_sidebar);
2360
+	}
2361
+
2362
+
2363
+
2364
+	/**
2365
+	 * display_admin_list_table_page_with_sidebar
2366
+	 * generates HTML wrapper for an admin_page with list_table
2367
+	 *
2368
+	 * @access public
2369
+	 * @return void
2370
+	 */
2371
+	public function display_admin_list_table_page_with_sidebar()
2372
+	{
2373
+		$this->_display_admin_list_table_page(true);
2374
+	}
2375
+
2376
+
2377
+
2378
+	/**
2379
+	 * display_admin_list_table_page_with_no_sidebar
2380
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2381
+	 *
2382
+	 * @access public
2383
+	 * @return void
2384
+	 */
2385
+	public function display_admin_list_table_page_with_no_sidebar()
2386
+	{
2387
+		$this->_display_admin_list_table_page();
2388
+	}
2389
+
2390
+
2391
+
2392
+	/**
2393
+	 * generates html wrapper for an admin_list_table page
2394
+	 *
2395
+	 * @access private
2396
+	 * @param boolean $sidebar whether to display with sidebar or not.
2397
+	 * @return void
2398
+	 */
2399
+	private function _display_admin_list_table_page($sidebar = false)
2400
+	{
2401
+		//setup search attributes
2402
+		$this->_set_search_attributes();
2403
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2404
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2405
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2406
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2407
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2408
+		$this->_template_args['list_table'] = $this->_list_table_object;
2409
+		$this->_template_args['current_route'] = $this->_req_action;
2410
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2411
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2412
+		if ( ! empty($ajax_sorting_callback)) {
2413
+			$sortable_list_table_form_fields = wp_nonce_field(
2414
+					$ajax_sorting_callback . '_nonce',
2415
+					$ajax_sorting_callback . '_nonce',
2416
+					false,
2417
+					false
2418
+			);
2419
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2420
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2421
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2422
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2423
+		} else {
2424
+			$sortable_list_table_form_fields = '';
2425
+		}
2426
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2427
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2428
+		$nonce_ref = $this->_req_action . '_nonce';
2429
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2430
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2431
+		//display message about search results?
2432
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2433
+				? '<p class="ee-search-results">' . sprintf(
2434
+						esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2435
+						trim($this->_req_data['s'], '%')
2436
+				) . '</p>'
2437
+				: '';
2438
+		// filter before_list_table template arg
2439
+		$this->_template_args['before_list_table'] = apply_filters(
2440
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2441
+			$this->_template_args['before_list_table'],
2442
+			$this->page_slug,
2443
+			$this->_req_data,
2444
+			$this->_req_action
2445
+		);
2446
+		// convert to array and filter again
2447
+		// arrays are easier to inject new items in a specific location,
2448
+		// but would not be backwards compatible, so we have to add a new filter
2449
+		$this->_template_args['before_list_table'] = implode(
2450
+			" \n",
2451
+			(array) apply_filters(
2452
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2453
+				(array) $this->_template_args['before_list_table'],
2454
+				$this->page_slug,
2455
+				$this->_req_data,
2456
+				$this->_req_action
2457
+			)
2458
+		);
2459
+		// filter after_list_table template arg
2460
+		$this->_template_args['after_list_table'] = apply_filters(
2461
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2462
+			$this->_template_args['after_list_table'],
2463
+			$this->page_slug,
2464
+			$this->_req_data,
2465
+			$this->_req_action
2466
+		);
2467
+		// convert to array and filter again
2468
+		// arrays are easier to inject new items in a specific location,
2469
+		// but would not be backwards compatible, so we have to add a new filter
2470
+		$this->_template_args['after_list_table'] = implode(
2471
+			" \n",
2472
+			(array) apply_filters(
2473
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2474
+				(array) $this->_template_args['after_list_table'],
2475
+				$this->page_slug,
2476
+				$this->_req_data,
2477
+				$this->_req_action
2478
+			)
2479
+		);
2480
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2481
+				$template_path,
2482
+				$this->_template_args,
2483
+				true
2484
+		);
2485
+		// the final template wrapper
2486
+		if ($sidebar) {
2487
+			$this->display_admin_page_with_sidebar();
2488
+		} else {
2489
+			$this->display_admin_page_with_no_sidebar();
2490
+		}
2491
+	}
2492
+
2493
+
2494
+
2495
+	/**
2496
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2497
+	 * $items are expected in an array in the following format:
2498
+	 * $legend_items = array(
2499
+	 *        'item_id' => array(
2500
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2501
+	 *            'desc' => __('localized description of item');
2502
+	 *        )
2503
+	 * );
2504
+	 *
2505
+	 * @param  array $items see above for format of array
2506
+	 * @return string        html string of legend
2507
+	 */
2508
+	protected function _display_legend($items)
2509
+	{
2510
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2511
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2512
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2513
+	}
2514
+
2515
+
2516
+	/**
2517
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2518
+	 * The returned json object is created from an array in the following format:
2519
+	 * array(
2520
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2521
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2522
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2523
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2524
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2525
+	 *  specific template args that might be included in here)
2526
+	 * )
2527
+	 * The json object is populated by whatever is set in the $_template_args property.
2528
+	 *
2529
+	 * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2530
+	 * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2531
+	 * @return void
2532
+	 */
2533
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
2534
+	{
2535
+		//make sure any EE_Error notices have been handled.
2536
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2537
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2538
+		unset($this->_template_args['data']);
2539
+		$json = array(
2540
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2541
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2542
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2543
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2544
+				'notices'   => EE_Error::get_notices(),
2545
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2546
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2547
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2548
+		);
2549
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2550
+		if (null === error_get_last() || ! headers_sent()) {
2551
+			header('Content-Type: application/json; charset=UTF-8');
2552
+		}
2553
+		echo wp_json_encode($json);
2554
+
2555
+		exit();
2556
+	}
2557
+
2558
+
2559
+
2560
+	/**
2561
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2562
+	 *
2563
+	 * @return void
2564
+	 * @throws EE_Error
2565
+	 */
2566
+	public function return_json()
2567
+	{
2568
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2569
+			$this->_return_json();
2570
+		} else {
2571
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2572
+		}
2573
+	}
2574
+
2575
+
2576
+
2577
+	/**
2578
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2579
+	 *
2580
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2581
+	 * @access   public
2582
+	 */
2583
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2584
+	{
2585
+		$this->_hook_obj = $hook_obj;
2586
+	}
2587
+
2588
+
2589
+
2590
+	/**
2591
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2592
+	 *
2593
+	 * @access public
2594
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2595
+	 * @return void
2596
+	 */
2597
+	public function admin_page_wrapper($about = false)
2598
+	{
2599
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2600
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2601
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2602
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2603
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2604
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2605
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2606
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2607
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2608
+		// load settings page wrapper template
2609
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2610
+		//about page?
2611
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2612
+		if (defined('DOING_AJAX')) {
2613
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2614
+			$this->_return_json();
2615
+		} else {
2616
+			EEH_Template::display_template($template_path, $this->_template_args);
2617
+		}
2618
+	}
2619
+
2620
+
2621
+
2622
+	/**
2623
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2624
+	 *
2625
+	 * @return string html
2626
+	 */
2627
+	protected function _get_main_nav_tabs()
2628
+	{
2629
+		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2630
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2631
+	}
2632
+
2633
+
2634
+
2635
+	/**
2636
+	 *        sort nav tabs
2637
+	 *
2638
+	 * @access public
2639
+	 * @param $a
2640
+	 * @param $b
2641
+	 * @return int
2642
+	 */
2643
+	private function _sort_nav_tabs($a, $b)
2644
+	{
2645
+		if ($a['order'] == $b['order']) {
2646
+			return 0;
2647
+		}
2648
+		return ($a['order'] < $b['order']) ? -1 : 1;
2649
+	}
2650
+
2651
+
2652
+
2653
+	/**
2654
+	 *    generates HTML for the forms used on admin pages
2655
+	 *
2656
+	 * @access protected
2657
+	 * @param    array $input_vars - array of input field details
2658
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2659
+	 * @return string
2660
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2661
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2662
+	 */
2663
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2664
+	{
2665
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2666
+		return $content;
2667
+	}
2668
+
2669
+
2670
+
2671
+	/**
2672
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2673
+	 *
2674
+	 * @access protected
2675
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2676
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2677
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2678
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2679
+	 */
2680
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2681
+	{
2682
+		//make sure $text and $actions are in an array
2683
+		$text = (array)$text;
2684
+		$actions = (array)$actions;
2685
+		$referrer_url = empty($referrer) ? '' : $referrer;
2686
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2687
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2688
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2689
+		$default_names = array('save', 'save_and_close');
2690
+		//add in a hidden index for the current page (so save and close redirects properly)
2691
+		$this->_template_args['save_buttons'] = $referrer_url;
2692
+		foreach ($button_text as $key => $button) {
2693
+			$ref = $default_names[$key];
2694
+			$id = $this->_current_view . '_' . $ref;
2695
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2696
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2697
+			if ( ! $both) {
2698
+				break;
2699
+			}
2700
+		}
2701
+	}
2702
+
2703
+
2704
+
2705
+	/**
2706
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2707
+	 *
2708
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2709
+	 * @since 4.6.0
2710
+	 * @param string $route
2711
+	 * @param array  $additional_hidden_fields
2712
+	 */
2713
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2714
+	{
2715
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2716
+	}
2717
+
2718
+
2719
+
2720
+	/**
2721
+	 * set form open and close tags on add/edit pages.
2722
+	 *
2723
+	 * @access protected
2724
+	 * @param string $route                    the route you want the form to direct to
2725
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2726
+	 * @return void
2727
+	 */
2728
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2729
+	{
2730
+		if (empty($route)) {
2731
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2732
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2733
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2734
+		}
2735
+		// open form
2736
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2737
+		// add nonce
2738
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2739
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2740
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2741
+		// add REQUIRED form action
2742
+		$hidden_fields = array(
2743
+				'action' => array('type' => 'hidden', 'value' => $route),
2744
+		);
2745
+		// merge arrays
2746
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2747
+		// generate form fields
2748
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2749
+		// add fields to form
2750
+		foreach ((array)$form_fields as $field_name => $form_field) {
2751
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2752
+		}
2753
+		// close form
2754
+		$this->_template_args['after_admin_page_content'] = '</form>';
2755
+	}
2756
+
2757
+
2758
+
2759
+	/**
2760
+	 * Public Wrapper for _redirect_after_action() method since its
2761
+	 * discovered it would be useful for external code to have access.
2762
+	 *
2763
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2764
+	 * @since 4.5.0
2765
+	 */
2766
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2767
+	{
2768
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2769
+	}
2770
+
2771
+
2772
+
2773
+	/**
2774
+	 *    _redirect_after_action
2775
+	 *
2776
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2777
+	 * @param string $what               - what the action was performed on
2778
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2779
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2780
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2781
+	 * @access protected
2782
+	 * @return void
2783
+	 */
2784
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2785
+	{
2786
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2787
+		//class name for actions/filters.
2788
+		$classname = get_class($this);
2789
+		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2790
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2791
+		$notices = EE_Error::get_notices(false);
2792
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2793
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2794
+			EE_Error::overwrite_success();
2795
+		}
2796
+		if ( ! empty($what) && ! empty($action_desc)) {
2797
+			// how many records affected ? more than one record ? or just one ?
2798
+			if ($success > 1 && empty($notices['errors'])) {
2799
+				// set plural msg
2800
+				EE_Error::add_success(
2801
+						sprintf(
2802
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2803
+								$what,
2804
+								$action_desc
2805
+						),
2806
+						__FILE__, __FUNCTION__, __LINE__
2807
+				);
2808
+			} else if ($success == 1 && empty($notices['errors'])) {
2809
+				// set singular msg
2810
+				EE_Error::add_success(
2811
+						sprintf(
2812
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2813
+								$what,
2814
+								$action_desc
2815
+						),
2816
+						__FILE__, __FUNCTION__, __LINE__
2817
+				);
2818
+			}
2819
+		}
2820
+		// check that $query_args isn't something crazy
2821
+		if ( ! is_array($query_args)) {
2822
+			$query_args = array();
2823
+		}
2824
+		/**
2825
+		 * Allow injecting actions before the query_args are modified for possible different
2826
+		 * redirections on save and close actions
2827
+		 *
2828
+		 * @since 4.2.0
2829
+		 * @param array $query_args       The original query_args array coming into the
2830
+		 *                                method.
2831
+		 */
2832
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2833
+		//calculate where we're going (if we have a "save and close" button pushed)
2834
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2835
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2836
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2837
+			// regenerate query args array from referrer URL
2838
+			parse_str($parsed_url['query'], $query_args);
2839
+			// correct page and action will be in the query args now
2840
+			$redirect_url = admin_url('admin.php');
2841
+		}
2842
+		//merge any default query_args set in _default_route_query_args property
2843
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2844
+			$args_to_merge = array();
2845
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2846
+				//is there a wp_referer array in our _default_route_query_args property?
2847
+				if ($query_param == 'wp_referer') {
2848
+					$query_value = (array)$query_value;
2849
+					foreach ($query_value as $reference => $value) {
2850
+						if (strpos($reference, 'nonce') !== false) {
2851
+							continue;
2852
+						}
2853
+						//finally we will override any arguments in the referer with
2854
+						//what might be set on the _default_route_query_args array.
2855
+						if (isset($this->_default_route_query_args[$reference])) {
2856
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2857
+						} else {
2858
+							$args_to_merge[$reference] = urlencode($value);
2859
+						}
2860
+					}
2861
+					continue;
2862
+				}
2863
+				$args_to_merge[$query_param] = $query_value;
2864
+			}
2865
+			//now let's merge these arguments but override with what was specifically sent in to the
2866
+			//redirect.
2867
+			$query_args = array_merge($args_to_merge, $query_args);
2868
+		}
2869
+		$this->_process_notices($query_args);
2870
+		// generate redirect url
2871
+		// if redirecting to anything other than the main page, add a nonce
2872
+		if (isset($query_args['action'])) {
2873
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2874
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2875
+		}
2876
+		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2877
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2878
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2879
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2880
+		if (defined('DOING_AJAX')) {
2881
+			$default_data = array(
2882
+					'close'        => true,
2883
+					'redirect_url' => $redirect_url,
2884
+					'where'        => 'main',
2885
+					'what'         => 'append',
2886
+			);
2887
+			$this->_template_args['success'] = $success;
2888
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2889
+			$this->_return_json();
2890
+		}
2891
+		wp_safe_redirect($redirect_url);
2892
+		exit();
2893
+	}
2894
+
2895
+
2896
+
2897
+	/**
2898
+	 * process any notices before redirecting (or returning ajax request)
2899
+	 * This method sets the $this->_template_args['notices'] attribute;
2900
+	 *
2901
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2902
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2903
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2904
+	 * @return void
2905
+	 */
2906
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2907
+	{
2908
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2909
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2910
+			$notices = EE_Error::get_notices(false);
2911
+			if (empty($this->_template_args['success'])) {
2912
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2913
+			}
2914
+			if (empty($this->_template_args['errors'])) {
2915
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2916
+			}
2917
+			if (empty($this->_template_args['attention'])) {
2918
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2919
+			}
2920
+		}
2921
+		$this->_template_args['notices'] = EE_Error::get_notices();
2922
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2923
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2924
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2925
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2926
+		}
2927
+	}
2928
+
2929
+
2930
+
2931
+	/**
2932
+	 * get_action_link_or_button
2933
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2934
+	 *
2935
+	 * @param string $action        use this to indicate which action the url is generated with.
2936
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2937
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2938
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2939
+	 * @param string $base_url      If this is not provided
2940
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2941
+	 *                              Otherwise this value will be used.
2942
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2943
+	 * @return string
2944
+	 * @throws \EE_Error
2945
+	 */
2946
+	public function get_action_link_or_button(
2947
+			$action,
2948
+			$type = 'add',
2949
+			$extra_request = array(),
2950
+			$class = 'button-primary',
2951
+			$base_url = '',
2952
+			$exclude_nonce = false
2953
+	) {
2954
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2955
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2956
+			throw new EE_Error(
2957
+					sprintf(
2958
+							__(
2959
+									'There is no page route for given action for the button.  This action was given: %s',
2960
+									'event_espresso'
2961
+							),
2962
+							$action
2963
+					)
2964
+			);
2965
+		}
2966
+		if ( ! isset($this->_labels['buttons'][$type])) {
2967
+			throw new EE_Error(
2968
+					sprintf(
2969
+							__(
2970
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2971
+									'event_espresso'
2972
+							),
2973
+							$type
2974
+					)
2975
+			);
2976
+		}
2977
+		//finally check user access for this button.
2978
+		$has_access = $this->check_user_access($action, true);
2979
+		if ( ! $has_access) {
2980
+			return '';
2981
+		}
2982
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2983
+		$query_args = array(
2984
+				'action' => $action,
2985
+		);
2986
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2987
+		if ( ! empty($extra_request)) {
2988
+			$query_args = array_merge($extra_request, $query_args);
2989
+		}
2990
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2991
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2992
+	}
2993
+
2994
+
2995
+
2996
+	/**
2997
+	 * _per_page_screen_option
2998
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2999
+	 *
3000
+	 * @return void
3001
+	 */
3002
+	protected function _per_page_screen_option()
3003
+	{
3004
+		$option = 'per_page';
3005
+		$args = array(
3006
+				'label'   => $this->_admin_page_title,
3007
+				'default' => 10,
3008
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3009
+		);
3010
+		//ONLY add the screen option if the user has access to it.
3011
+		if ($this->check_user_access($this->_current_view, true)) {
3012
+			add_screen_option($option, $args);
3013
+		}
3014
+	}
3015
+
3016
+
3017
+
3018
+	/**
3019
+	 * set_per_page_screen_option
3020
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3021
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3022
+	 *
3023
+	 * @access private
3024
+	 * @return void
3025
+	 */
3026
+	private function _set_per_page_screen_options()
3027
+	{
3028
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3029
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3030
+			if ( ! $user = wp_get_current_user()) {
3031
+				return;
3032
+			}
3033
+			$option = $_POST['wp_screen_options']['option'];
3034
+			$value = $_POST['wp_screen_options']['value'];
3035
+			if ($option != sanitize_key($option)) {
3036
+				return;
3037
+			}
3038
+			$map_option = $option;
3039
+			$option = str_replace('-', '_', $option);
3040
+			switch ($map_option) {
3041
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3042
+					$value = (int)$value;
3043
+					if ($value < 1 || $value > 999) {
3044
+						return;
3045
+					}
3046
+					break;
3047
+				default:
3048
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3049
+					if (false === $value) {
3050
+						return;
3051
+					}
3052
+					break;
3053
+			}
3054
+			update_user_meta($user->ID, $option, $value);
3055
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3056
+			exit;
3057
+		}
3058
+	}
3059
+
3060
+
3061
+
3062
+	/**
3063
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3064
+	 *
3065
+	 * @param array $data array that will be assigned to template args.
3066
+	 */
3067
+	public function set_template_args($data)
3068
+	{
3069
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3070
+	}
3071
+
3072
+
3073
+
3074
+	/**
3075
+	 * This makes available the WP transient system for temporarily moving data between routes
3076
+	 *
3077
+	 * @access protected
3078
+	 * @param string $route             the route that should receive the transient
3079
+	 * @param array  $data              the data that gets sent
3080
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3081
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3082
+	 * @return void
3083
+	 */
3084
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3085
+	{
3086
+		$user_id = get_current_user_id();
3087
+		if ( ! $skip_route_verify) {
3088
+			$this->_verify_route($route);
3089
+		}
3090
+		//now let's set the string for what kind of transient we're setting
3091
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3092
+		$data = $notices ? array('notices' => $data) : $data;
3093
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3094
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3095
+		if ($existing) {
3096
+			$data = array_merge((array)$data, (array)$existing);
3097
+		}
3098
+		if (is_multisite() && is_network_admin()) {
3099
+			set_site_transient($transient, $data, 8);
3100
+		} else {
3101
+			set_transient($transient, $data, 8);
3102
+		}
3103
+	}
3104
+
3105
+
3106
+
3107
+	/**
3108
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3109
+	 *
3110
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3111
+	 * @return mixed data
3112
+	 */
3113
+	protected function _get_transient($notices = false, $route = false)
3114
+	{
3115
+		$user_id = get_current_user_id();
3116
+		$route = ! $route ? $this->_req_action : $route;
3117
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3118
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3119
+		//delete transient after retrieval (just in case it hasn't expired);
3120
+		if (is_multisite() && is_network_admin()) {
3121
+			delete_site_transient($transient);
3122
+		} else {
3123
+			delete_transient($transient);
3124
+		}
3125
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3126
+	}
3127
+
3128
+
3129
+
3130
+	/**
3131
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3132
+	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3133
+	 *
3134
+	 * @return void
3135
+	 */
3136
+	protected function _transient_garbage_collection()
3137
+	{
3138
+		global $wpdb;
3139
+		//retrieve all existing transients
3140
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3141
+		if ($results = $wpdb->get_results($query)) {
3142
+			foreach ($results as $result) {
3143
+				$transient = str_replace('_transient_', '', $result->option_name);
3144
+				get_transient($transient);
3145
+				if (is_multisite() && is_network_admin()) {
3146
+					get_site_transient($transient);
3147
+				}
3148
+			}
3149
+		}
3150
+	}
3151
+
3152
+
3153
+
3154
+	/**
3155
+	 * get_view
3156
+	 *
3157
+	 * @access public
3158
+	 * @return string content of _view property
3159
+	 */
3160
+	public function get_view()
3161
+	{
3162
+		return $this->_view;
3163
+	}
3164
+
3165
+
3166
+
3167
+	/**
3168
+	 * getter for the protected $_views property
3169
+	 *
3170
+	 * @return array
3171
+	 */
3172
+	public function get_views()
3173
+	{
3174
+		return $this->_views;
3175
+	}
3176
+
3177
+
3178
+
3179
+	/**
3180
+	 * get_current_page
3181
+	 *
3182
+	 * @access public
3183
+	 * @return string _current_page property value
3184
+	 */
3185
+	public function get_current_page()
3186
+	{
3187
+		return $this->_current_page;
3188
+	}
3189
+
3190
+
3191
+
3192
+	/**
3193
+	 * get_current_view
3194
+	 *
3195
+	 * @access public
3196
+	 * @return string _current_view property value
3197
+	 */
3198
+	public function get_current_view()
3199
+	{
3200
+		return $this->_current_view;
3201
+	}
3202
+
3203
+
3204
+
3205
+	/**
3206
+	 * get_current_screen
3207
+	 *
3208
+	 * @access public
3209
+	 * @return object The current WP_Screen object
3210
+	 */
3211
+	public function get_current_screen()
3212
+	{
3213
+		return $this->_current_screen;
3214
+	}
3215
+
3216
+
3217
+
3218
+	/**
3219
+	 * get_current_page_view_url
3220
+	 *
3221
+	 * @access public
3222
+	 * @return string This returns the url for the current_page_view.
3223
+	 */
3224
+	public function get_current_page_view_url()
3225
+	{
3226
+		return $this->_current_page_view_url;
3227
+	}
3228
+
3229
+
3230
+
3231
+	/**
3232
+	 * just returns the _req_data property
3233
+	 *
3234
+	 * @return array
3235
+	 */
3236
+	public function get_request_data()
3237
+	{
3238
+		return $this->_req_data;
3239
+	}
3240
+
3241
+
3242
+
3243
+	/**
3244
+	 * returns the _req_data protected property
3245
+	 *
3246
+	 * @return string
3247
+	 */
3248
+	public function get_req_action()
3249
+	{
3250
+		return $this->_req_action;
3251
+	}
3252
+
3253
+
3254
+
3255
+	/**
3256
+	 * @return bool  value of $_is_caf property
3257
+	 */
3258
+	public function is_caf()
3259
+	{
3260
+		return $this->_is_caf;
3261
+	}
3262
+
3263
+
3264
+
3265
+	/**
3266
+	 * @return mixed
3267
+	 */
3268
+	public function default_espresso_metaboxes()
3269
+	{
3270
+		return $this->_default_espresso_metaboxes;
3271
+	}
3272
+
3273
+
3274
+
3275
+	/**
3276
+	 * @return mixed
3277
+	 */
3278
+	public function admin_base_url()
3279
+	{
3280
+		return $this->_admin_base_url;
3281
+	}
3282
+
3283
+
3284
+
3285
+	/**
3286
+	 * @return mixed
3287
+	 */
3288
+	public function wp_page_slug()
3289
+	{
3290
+		return $this->_wp_page_slug;
3291
+	}
3292
+
3293
+
3294
+
3295
+	/**
3296
+	 * updates  espresso configuration settings
3297
+	 *
3298
+	 * @access    protected
3299
+	 * @param string                   $tab
3300
+	 * @param EE_Config_Base|EE_Config $config
3301
+	 * @param string                   $file file where error occurred
3302
+	 * @param string                   $func function  where error occurred
3303
+	 * @param string                   $line line no where error occurred
3304
+	 * @return boolean
3305
+	 */
3306
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3307
+	{
3308
+		//remove any options that are NOT going to be saved with the config settings.
3309
+		if (isset($config->core->ee_ueip_optin)) {
3310
+			$config->core->ee_ueip_has_notified = true;
3311
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3312
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3313
+			update_option('ee_ueip_has_notified', true);
3314
+		}
3315
+		// and save it (note we're also doing the network save here)
3316
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3317
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3318
+		if ($config_saved && $net_saved) {
3319
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3320
+			return true;
3321
+		} else {
3322
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3323
+			return false;
3324
+		}
3325
+	}
3326
+
3327
+
3328
+
3329
+	/**
3330
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3331
+	 *
3332
+	 * @return array
3333
+	 */
3334
+	public function get_yes_no_values()
3335
+	{
3336
+		return $this->_yes_no_values;
3337
+	}
3338
+
3339
+
3340
+
3341
+	protected function _get_dir()
3342
+	{
3343
+		$reflector = new ReflectionClass(get_class($this));
3344
+		return dirname($reflector->getFileName());
3345
+	}
3346
+
3347
+
3348
+
3349
+	/**
3350
+	 * A helper for getting a "next link".
3351
+	 *
3352
+	 * @param string $url   The url to link to
3353
+	 * @param string $class The class to use.
3354
+	 * @return string
3355
+	 */
3356
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3357
+	{
3358
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3359
+	}
3360
+
3361
+
3362
+
3363
+	/**
3364
+	 * A helper for getting a "previous link".
3365
+	 *
3366
+	 * @param string $url   The url to link to
3367
+	 * @param string $class The class to use.
3368
+	 * @return string
3369
+	 */
3370
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3371
+	{
3372
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3373
+	}
3374
+
3375
+
3376
+
3377
+
3378
+
3379
+
3380
+
3381
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3382
+	/**
3383
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3384
+	 * array.
3385
+	 *
3386
+	 * @return bool success/fail
3387
+	 */
3388
+	protected function _process_resend_registration()
3389
+	{
3390
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3391
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3392
+		return $this->_template_args['success'];
3393
+	}
3394
+
3395
+
3396
+
3397
+	/**
3398
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3399
+	 *
3400
+	 * @access protected
3401
+	 * @param \EE_Payment $payment
3402
+	 * @return bool success/fail
3403
+	 */
3404
+	protected function _process_payment_notification(EE_Payment $payment)
3405
+	{
3406
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3407
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3408
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3409
+		return $this->_template_args['success'];
3410
+	}
3411 3411
 
3412 3412
 
3413 3413
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Indentation   +1112 added lines, -1112 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,1117 +17,1117 @@  discard block
 block discarded – undo
17 17
 class EE_Message_Resource_Manager
18 18
 {
19 19
 
20
-    /**
21
-     * This option in the database is used to keep a record of message types that have been activated for a messenger
22
-     * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
-     * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
-     * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
-     * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
-     * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
-     * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
-     * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
-     * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
-     * the "force" flag is respected if that message type is later re-registered.
31
-     *
32
-     * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
-     *
34
-     * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
-     * option that got superseded by later behaviour requirements.
36
-     */
37
-    const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
-
39
-    /**
40
-     * @type boolean $_initialized
41
-     */
42
-    protected $_initialized = false;
43
-
44
-    /**
45
-     * @type EE_Messenger_Collection $_messenger_collection_loader
46
-     */
47
-    protected $_messenger_collection_loader;
48
-
49
-    /**
50
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
51
-     */
52
-    protected $_message_type_collection_loader;
53
-
54
-    /**
55
-     * @type EEM_Message_Template_Group $_message_template_group_model
56
-     */
57
-    protected $_message_template_group_model;
58
-
59
-    /**
60
-     * @type EE_messenger[]
61
-     */
62
-    protected $_installed_messengers = array();
63
-
64
-    /**
65
-     * @type EE_message_type[]
66
-     */
67
-    protected $_installed_message_types = array();
68
-
69
-    /**
70
-     * Array of active messengers.
71
-     * Format is this:
72
-     * array(
73
-     *      'messenger_name' => EE_messenger
74
-     * )
75
-     *
76
-     * @type EE_messenger[]
77
-     */
78
-    protected $_active_messengers = array();
79
-
80
-    /**
81
-     * Formatted array of active message types grouped per messenger.
82
-     * Format is this:
83
-     * array(
84
-     *      'messenger_name' => array(
85
-     *          'settings' => array(
86
-     *              '{messenger_name}-message_types' => array(
87
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
-     *              )
89
-     *          )
90
-     *      )
91
-     * )
92
-     *
93
-     * @type array
94
-     */
95
-    protected $_active_message_types = array();
96
-
97
-
98
-    /**
99
-     * This holds the array of messengers and their corresponding message types that have
100
-     * been activated on a site at some point.  This is an important record that helps the messages system
101
-     * not accidentally reactivate something that was intentionally deactivated by a user.
102
-     *
103
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
-     *
105
-     * @type array
106
-     */
107
-    protected $_has_activated_messengers_and_message_types = array();
108
-
109
-    /**
110
-     * An array of unique message type contexts across all active message types.
111
-     * The array will be indexed by either 'slugs' or 'all'.
112
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
-     * slug. array(
114
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
-     * );
116
-     * The all index returns an array in this format:
117
-     * array(
118
-     *      'message_type_name' => array(
119
-     *          'context_slug' => array(
120
-     *              'label' => 'localized label for context',
121
-     *              'description' => 'localized description for context'
122
-     *          )
123
-     *      )
124
-     * );
125
-     *
126
-     * @type array
127
-     */
128
-    protected $_contexts = array();
129
-
130
-
131
-    /**
132
-     * EE_Message_Resource_Manager constructor.
133
-     *
134
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
-     */
138
-    function __construct(
139
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
-        EEM_Message_Template_Group $Message_Template_Group_Model
142
-    ) {
143
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return void
151
-     */
152
-    protected function _initialize_collections()
153
-    {
154
-        if ($this->_initialized) {
155
-            return;
156
-        }
157
-        $this->_initialized = true;
158
-        $this->_messenger_collection_loader->load_messengers_from_folder();
159
-        $this->_message_type_collection_loader->load_message_types_from_folder();
160
-        $this->get_has_activated_messengers_option(true);
161
-        $this->_set_active_messengers_and_message_types();
162
-    }
163
-
164
-
165
-    /**
166
-     * @return EE_Messenger_Collection
167
-     */
168
-    public function messenger_collection()
169
-    {
170
-        $this->_initialize_collections();
171
-        return $this->_messenger_collection_loader->messenger_collection();
172
-    }
173
-
174
-
175
-    /**
176
-     * @return EE_messenger[]
177
-     */
178
-    public function active_messengers()
179
-    {
180
-        $this->_initialize_collections();
181
-        return $this->_active_messengers;
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string $messenger_name
187
-     * @return \EE_messenger
188
-     */
189
-    public function get_messenger($messenger_name)
190
-    {
191
-        return $this->messenger_collection()->get_by_info($messenger_name);
192
-    }
193
-
194
-
195
-    /**
196
-     * This returns the corresponding EE_messenger object for the given string if it is active.
197
-     *
198
-     * @param string $messenger
199
-     * @return EE_messenger | null
200
-     */
201
-    public function get_active_messenger($messenger)
202
-    {
203
-        $this->_initialize_collections();
204
-        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
-    }
206
-
207
-
208
-    /**
209
-     * @return \EE_messenger[]
210
-     */
211
-    public function installed_messengers()
212
-    {
213
-        if (empty($this->_installed_messengers)) {
214
-            $this->_installed_messengers = array();
215
-            $this->messenger_collection()->rewind();
216
-            while ($this->messenger_collection()->valid()) {
217
-                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
-                $this->messenger_collection()->next();
219
-            }
220
-        }
221
-        return $this->_installed_messengers;
222
-    }
223
-
224
-
225
-    /**
226
-     * @param string $messenger_name
227
-     * @return \EE_messenger
228
-     * @throws \EE_Error
229
-     */
230
-    public function valid_messenger($messenger_name)
231
-    {
232
-        $messenger = $this->get_messenger($messenger_name);
233
-        if ($messenger instanceof EE_messenger) {
234
-            return $messenger;
235
-        }
236
-        throw new EE_Error(
237
-            sprintf(
238
-                __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
-                $messenger_name
240
-            )
241
-        );
242
-    }
243
-
244
-
245
-    /**
246
-     * @return EE_Message_Type_Collection
247
-     */
248
-    public function message_type_collection()
249
-    {
250
-        $this->_initialize_collections();
251
-        return $this->_message_type_collection_loader->message_type_collection();
252
-    }
253
-
254
-
255
-    /**
256
-     * @return array
257
-     */
258
-    public function active_message_types()
259
-    {
260
-        $this->_initialize_collections();
261
-        return $this->_active_message_types;
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $message_type_name
267
-     * @return \EE_message_type
268
-     */
269
-    public function get_message_type($message_type_name)
270
-    {
271
-        return $this->message_type_collection()->get_by_info($message_type_name);
272
-    }
273
-
274
-
275
-    /**
276
-     * This returns the EE_message_type from the active message types array ( if present );
277
-     *
278
-     * @param string $messenger_name
279
-     * @param string $message_type_name
280
-     * @return \EE_message_type|null
281
-     */
282
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
-    {
284
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
-            ? $this->get_message_type($message_type_name)
286
-            : null;
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns whether the given message type is active for the given messenger.
292
-     *
293
-     * @param string $messenger_name
294
-     * @param string $message_type_name
295
-     * @return bool
296
-     */
297
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
-    {
299
-        $this->_initialize_collections();
300
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
-    }
302
-
303
-
304
-    /**
305
-     * Returns whether the given messenger is active.
306
-     *
307
-     * @param string $messenger_name the name of the messenger to check if active.
308
-     * @return bool
309
-     */
310
-    public function is_messenger_active($messenger_name)
311
-    {
312
-        $this->_initialize_collections();
313
-        return ! empty($this->_active_message_types[$messenger_name]);
314
-    }
315
-
316
-
317
-    /**
318
-     * This returns any settings that might be on a message type for a messenger
319
-     *
320
-     * @param string $messenger_name    The slug of the messenger
321
-     * @param string $message_type_name The slug of the message type getting the settings for.
322
-     * @return array
323
-     */
324
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
-    {
326
-        $settings = array();
327
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
-                : array();
331
-        }
332
-        return $settings;
333
-    }
334
-
335
-
336
-    /**
337
-     * Returns whether the given messenger name has active message types on it.
338
-     * Infers whether the messenger is active or not as well.
339
-     *
340
-     * @param string $messenger_name
341
-     * @return bool
342
-     */
343
-    public function messenger_has_active_message_types($messenger_name)
344
-    {
345
-        $this->_initialize_collections();
346
-        return
347
-            ! empty($this->_active_message_types[$messenger_name])
348
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
-    }
350
-
351
-
352
-    /**
353
-     * This checks the _active_message_types property for any active message types
354
-     * that are present for the given messenger and returns them.
355
-     *
356
-     * @since 4.9.0
357
-     * @param string $messenger_name The messenger being checked
358
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
359
-     */
360
-    public function get_active_message_types_for_messenger($messenger_name)
361
-    {
362
-        $message_types = array();
363
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
364
-            return $message_types;
365
-        }
366
-        $installed_message_types = $this->installed_message_types();
367
-        foreach ($installed_message_types as $message_type_name => $message_type) {
368
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
-                $message_types[$message_type_name] = $message_type;
370
-            }
371
-        }
372
-        return $message_types;
373
-    }
374
-
375
-
376
-    /**
377
-     * This does NOT return the _active_message_types property but
378
-     * simply returns an array of active message type names from that property.
379
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
-     *
381
-     * @return array message_type references (string)
382
-     */
383
-    public function list_of_active_message_types()
384
-    {
385
-        $active_message_type_names = array();
386
-        $this->_initialize_collections();
387
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
-                continue;
390
-            }
391
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
-                if (! in_array($message_type_name, $active_message_type_names)) {
393
-                    $active_message_type_names[] = $message_type_name;
394
-                }
395
-            }
396
-        }
397
-        return $active_message_type_names;
398
-    }
399
-
400
-
401
-    /**
402
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
-     *
404
-     * @since 4.9.0
405
-     * @return \EE_message_type[]
406
-     */
407
-    public function get_active_message_type_objects()
408
-    {
409
-        $active_message_types      = array();
410
-        $installed_message_types   = $this->installed_message_types();
411
-        $active_message_type_names = $this->list_of_active_message_types();
412
-        foreach ($active_message_type_names as $active_message_type_name) {
413
-            if (isset($installed_message_types[$active_message_type_name])) {
414
-                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
-            }
416
-        }
417
-        return $active_message_types;
418
-    }
419
-
420
-
421
-    /**
422
-     * @return \EE_message_type[]
423
-     */
424
-    public function installed_message_types()
425
-    {
426
-        if (empty($this->_installed_message_types)) {
427
-            $this->message_type_collection()->rewind();
428
-            while ($this->message_type_collection()->valid()) {
429
-                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
-                $this->message_type_collection()->next();
431
-            }
432
-        }
433
-        return $this->_installed_message_types;
434
-    }
435
-
436
-
437
-    /**
438
-     * @param string $message_type_name
439
-     * @return \EE_message_type
440
-     * @throws \EE_Error
441
-     */
442
-    public function valid_message_type($message_type_name)
443
-    {
444
-        $message_type = $this->get_message_type($message_type_name);
445
-        if ($message_type instanceof EE_message_type) {
446
-            return $message_type;
447
-        }
448
-        throw new EE_Error(
449
-            sprintf(
450
-                __('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
-                $message_type_name
452
-            )
453
-        );
454
-    }
455
-
456
-
457
-    /**
458
-     * valid_message_type_for_messenger
459
-     *
460
-     * @param EE_messenger $messenger
461
-     * @param string       $message_type_name
462
-     * @return boolean
463
-     * @throws \EE_Error
464
-     */
465
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
-    {
467
-        $valid_message_types = $messenger->get_valid_message_types();
468
-        if (! in_array($message_type_name, $valid_message_types)) {
469
-            throw new EE_Error(
470
-                sprintf(
471
-                    __(
472
-                        'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
-                        'event_espresso'
474
-                    ),
475
-                    $message_type_name,
476
-                    __METHOD__,
477
-                    $messenger->name
478
-                )
479
-            );
480
-        }
481
-        return true;
482
-    }
483
-
484
-
485
-    /**
486
-     * Used to return active messengers array stored in the wp options table.
487
-     * If no value is present in the option then an empty array is returned.
488
-     *
489
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
-     *                          $_active_message_types property is pulled.
492
-     * @return array
493
-     */
494
-    public function get_active_messengers_option($reset = false)
495
-    {
496
-        if ($reset) {
497
-            $this->_active_message_types = get_option('ee_active_messengers', array());
498
-        }
499
-        return $this->_active_message_types;
500
-    }
501
-
502
-
503
-    /**
504
-     * Used to update the active messengers array stored in the wp options table.
505
-     *
506
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
-     *                                         representing this data is used.
508
-     * @return bool FALSE if not updated, TRUE if updated.
509
-     */
510
-    public function update_active_messengers_option($active_messenger_settings = array())
511
-    {
512
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
-        //make sure _active_message_types is updated (this is the internal cache for the settings).
514
-        $this->_active_message_types = $active_messenger_settings;
515
-        return update_option('ee_active_messengers', $active_messenger_settings);
516
-    }
517
-
518
-
519
-    /**
520
-     * Used to return has activated message types for messengers array stored in the wp options table.
521
-     * If no value is present in the option then an empty array is returned.
522
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
-     *
525
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
526
-     * @return array
527
-     */
528
-    public function get_has_activated_messengers_option($reset = false)
529
-    {
530
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
-            $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
-        }
533
-        return $this->_has_activated_messengers_and_message_types;
534
-    }
535
-
536
-
537
-    /**
538
-     * Used to update the has activated option in the db.
539
-     *
540
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
-     *
542
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
-     *                                        representing this data is used.
544
-     * @return bool FALSE if not updated, TRUE if updated.
545
-     */
546
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
547
-    {
548
-        //make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
-            $this->get_has_activated_messengers_option();
551
-        }
552
-        $has_activated_messengers = empty($has_activated_messengers)
553
-            ? $this->_has_activated_messengers_and_message_types
554
-            : $has_activated_messengers;
555
-        return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
-    }
557
-
558
-
559
-    /**
560
-     * wrapper for _set_active_messengers_and_message_types()
561
-     */
562
-    public function reset_active_messengers_and_message_types()
563
-    {
564
-        $this->_set_active_messengers_and_message_types();
565
-    }
566
-
567
-
568
-    /**
569
-     * Generate list of active messengers and message types from collection.
570
-     * This sets up the active messengers from what is present in the database.
571
-     */
572
-    protected function _set_active_messengers_and_message_types()
573
-    {
574
-        //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
-        // list of activated messengers as set via the admin
576
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
-        $this->get_active_messengers_option(true);
578
-        $this->ensure_messengers_are_active(array(), false, true);
579
-        $this->update_active_messengers_option();
580
-        $this->update_has_activated_messengers_option();
581
-    }
582
-
583
-
584
-    /**
585
-     * Ensures that the specified messenger is currently active.
586
-     * If not, activates it and its default message types.
587
-     *
588
-     * @param string $messenger_name
589
-     * @param bool   $update_option Whether to update the option in the db or not.
590
-     * @return boolean true if either already active or successfully activated.
591
-     */
592
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
-    {
594
-        if (! isset($this->_active_messengers[$messenger_name])) {
595
-            try {
596
-                $this->activate_messenger($messenger_name, array(), $update_option);
597
-            } catch (EE_Error $e) {
598
-                EE_Error::add_error(
599
-                    $e->getMessage(),
600
-                    __FILE__,
601
-                    __FUNCTION__,
602
-                    __LINE__
603
-                );
604
-                return false;
605
-            }
606
-        }
607
-        return true;
608
-    }
609
-
610
-
611
-    /**
612
-     * This ensures the given array of messenger names is active in the system.
613
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
-     * it will automatically activate the default message types for the messenger if its not active.
615
-     *
616
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
-     *                                (default) then will attempt to set the active messengers from the
618
-     *                                activated_messengers option
619
-     *                                (stored in $_active_message_types property).
620
-     * @param bool  $update_option    Whether to update the related active messengers option.
621
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
-     *                                will automatically be deactivated.
624
-     */
625
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
-    {
627
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
-
629
-        $not_installed = array();
630
-        foreach ($messenger_names as $messenger_name) {
631
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
-                $not_installed[] = $messenger_name;
633
-                $this->deactivate_messenger($messenger_name);
634
-                continue;
635
-            }
636
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
637
-        }
638
-
639
-        if (! empty($not_installed)) {
640
-            EE_Error::add_error(
641
-                sprintf(
642
-                    __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
-                    '<br />',
644
-                    implode(', ', $not_installed)
645
-                ),
646
-                __FILE__, __FUNCTION__, __LINE__
647
-            );
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
-     * This ALSO ensures that the given messenger is active as well!
655
-     *
656
-     * @param string $message_type_name message type name.
657
-     * @param        $messenger_name
658
-     * @param bool   $update_option     Whether to update the option in the db or not.
659
-     * @return bool  Returns true if already is active or if was activated successfully.
660
-     * @throws \EE_Error
661
-     */
662
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
-    {
664
-        // grab the messenger to work with.
665
-        $messenger = $this->valid_messenger($messenger_name);
666
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
-            //ensure messenger is active (that's an inherent coupling between active message types and the
668
-            //messenger they are being activated for.
669
-            try {
670
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
-                    //all is good so let's just get it active
672
-                    $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
-                }
674
-            } catch (EE_Error $e) {
675
-                EE_Error::add_error(
676
-                    $e->getMessage(),
677
-                    __FILE__,
678
-                    __FUNCTION__,
679
-                    __LINE__
680
-                );
681
-                return false;
682
-            }
683
-        }
684
-        return true;
685
-    }
686
-
687
-
688
-    /**
689
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
-     * messenger are active in one go.
691
-     *
692
-     * @param array  $message_type_names Array of message type names to ensure are active.
693
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
-     */
696
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
-    {
698
-        $message_type_names = (array)$message_type_names;
699
-        foreach ($message_type_names as $message_type_name) {
700
-            // note, intentionally not updating option here because we're in a loop.
701
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
702
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
-        }
704
-        if ($update_option) {
705
-            $this->update_active_messengers_option();
706
-            $this->update_has_activated_messengers_option();
707
-        }
708
-    }
709
-
710
-
711
-    /**
712
-     * Activates the specified messenger.
713
-     *
714
-     * @param string $messenger_name
715
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
-     *                                          If included we do NOT setup the default message types
717
-     *                                          (assuming they are already setup.)
718
-     * @param bool   $update_active_messengers_option
719
-     * @return array of generated templates
720
-     * @throws \EE_Error
721
-     */
722
-    public function activate_messenger(
723
-        $messenger_name,
724
-        $message_type_names = array(),
725
-        $update_active_messengers_option = true
726
-    ) {
727
-        $templates = array();
728
-        // grab the messenger to work with.
729
-        $messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
-        // it's inactive. Activate it.
731
-        if ($messenger instanceof EE_messenger) {
732
-            $this->_active_messengers[$messenger->name] = $messenger;
733
-            //activate incoming message types set to be activated with messenger.
734
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
-            // setup any initial settings for the messenger if necessary.
736
-            $this->add_settings_for_messenger($messenger->name);
737
-            if ($update_active_messengers_option) {
738
-                $this->update_active_messengers_option();
739
-                $this->update_has_activated_messengers_option();
740
-            }
741
-            //generate new templates if necessary and ensure all related templates that are already in the database are
742
-            //marked active.  Note, this will also deactivate a message type for a messenger if the template
743
-            //cannot be successfully created during its attempt (only happens for global template attempts).
744
-            if (! empty($message_type_names)) {
745
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
-            }
748
-        }
749
-        return $templates;
750
-    }
751
-
752
-
753
-    /**
754
-     * Activates given message types for the given EE_messenger object.
755
-     * Note: (very important) This method does not persist the activation to the database.
756
-     * See code implementing this method in this class for examples of how to persist.
757
-     *
758
-     * @param \EE_messenger $messenger
759
-     * @param  array        $message_type_names
760
-     * @return array
761
-     */
762
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
-    {
764
-        //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
-        //things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
-        //So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
-        //only override _active_message_types when an explicit array of $message_type_names has been provided.
768
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
-            ? $messenger->get_default_message_types()
770
-            : (array)$message_type_names;
771
-
772
-        //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
-        if (! isset($this->_active_message_types[$messenger->name])) {
774
-            $this->_active_message_types[$messenger->name]['settings'] = array();
775
-        }
776
-
777
-        if ($message_type_names) {
778
-            // cycle thru message types
779
-            foreach ($message_type_names as $message_type_name) {
780
-                //only register the message type as active IF it isn't already active
781
-                //and if its actually installed.
782
-                if (
783
-                ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
-                ) {
785
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
786
-                    $this->_set_messenger_has_activated_message_type(
787
-                        $messenger,
788
-                        $message_type_name
789
-                    );
790
-                }
791
-            }
792
-        }
793
-        return $message_type_names;
794
-    }
795
-
796
-
797
-    /**
798
-     * add_settings_for_message_type
799
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
-     * $this->update_active_messengers_option to persist.
801
-     *
802
-     * @param  string $messenger_name    The name of the messenger adding the settings for
803
-     * @param  string $message_type_name The name of the message type adding the settings for
804
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
-     */
806
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
-    {
808
-        // get installed message type from collection
809
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
-        //we need to setup any initial settings for message types
812
-        if ($message_type instanceof EE_message_type) {
813
-            $default_settings = $message_type->get_admin_settings_fields();
814
-            foreach ($default_settings as $field => $values) {
815
-                if (isset($new_settings[$field])) {
816
-                    $existing_settings[$field] = $new_settings[$field];
817
-                    continue;
818
-                }
819
-                if (! isset($existing_settings[$field])) {
820
-                    $existing_settings[$field] = $values['default'];
821
-                }
822
-            }
823
-        }
824
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
-    }
826
-
827
-
828
-    /**
829
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
-     * and message type.
831
-     *
832
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
-     *
834
-     * @access protected
835
-     * @param \EE_messenger $messenger
836
-     * @param string        $message_type_name
837
-     */
838
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
-    {
840
-
841
-        //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
-        if (empty($this->_has_activated_messengers_and_message_types)) {
843
-            $this->get_has_activated_messengers_option();
844
-        }
845
-
846
-        // make sure this messenger has a record in the has_activated array
847
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
-            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
-        }
850
-        // check if message type has already been added
851
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
-            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
-        }
854
-    }
855
-
856
-
857
-    /**
858
-     * add_settings_for_messenger
859
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
-     * $this->update_active_messengers_option to persist.
861
-     *
862
-     * @param string $messenger_name The name of the messenger the settings is being added for.
863
-     * @param array  $new_settings   An array of settings to update the existing settings.
864
-     */
865
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
-    {
867
-        $messenger = $this->get_messenger($messenger_name);
868
-        if ($messenger instanceof EE_messenger) {
869
-            $msgr_settings = $messenger->get_admin_settings_fields();
870
-            if (! empty($msgr_settings)) {
871
-                foreach ($msgr_settings as $field => $value) {
872
-                    //is there a new setting for this?
873
-                    if (isset($new_settings[$field])) {
874
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
-                        continue;
876
-                    }
877
-                    //only set the default if it isn't already set.
878
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
-                    }
881
-                }
882
-            }
883
-        }
884
-    }
885
-
886
-
887
-    /**
888
-     * deactivate_messenger
889
-     *
890
-     * @param  string|EE_messenger $messenger_name name of messenger
891
-     * @return void
892
-     */
893
-    public function deactivate_messenger($messenger_name)
894
-    {
895
-        $this->_initialize_collections();
896
-        if ($messenger_name instanceof EE_messenger) {
897
-            $messenger_name = $messenger_name->name;
898
-        }
899
-        unset($this->_active_messengers[$messenger_name]);
900
-        unset($this->_active_message_types[$messenger_name]);
901
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
-        $this->update_active_messengers_option();
903
-    }
904
-
905
-
906
-    /**
907
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
-     *
909
-     * @param  string $message_type_name     name of message type being deactivated
910
-     * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
-     *                                       type.  However, this can be overridden if we don't want this set (usually when
912
-     *                                       this is called as a part of deregistration of a custom message type)
913
-     */
914
-    public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
-    {
916
-        $this->_initialize_collections();
917
-        if ($message_type_name instanceof EE_message_type) {
918
-            $message_type_name = $message_type_name->name;
919
-        }
920
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
921
-            unset(
922
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
-            );
924
-
925
-            //we always record (even on deactivation) that a message type has been activated because there should at
926
-            //least be a record in the "has_activated" option that it WAS active at one point.
927
-            if ($set_has_active_record) {
928
-                $messenger = $this->get_messenger($messenger_name);
929
-                $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
-            }
931
-        }
932
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
-        $this->update_active_messengers_option();
934
-        $this->update_has_activated_messengers_option();
935
-    }
936
-
937
-
938
-    /**
939
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
940
-     *
941
-     * @param string $message_type_name Name of message type being deactivated.
942
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
-     */
944
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
-    {
946
-        $this->_initialize_collections();
947
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
-        }
950
-        $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
-            array($message_type_name));
952
-        $this->update_active_messengers_option();
953
-    }
954
-
955
-
956
-    /**
957
-     * Used to verify if a message can be sent for the given messenger and message type
958
-     * and that it is a generating messenger (used for generating message templates).
959
-     *
960
-     * @param EE_messenger    $messenger    messenger used in trigger
961
-     * @param EE_message_type $message_type message type used in trigger
962
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
-     */
964
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
-    {
966
-        //get the $messengers the message type says it can be used with.
967
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
-            if (
969
-                $messenger->name === $generating_messenger
970
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
-            ) {
972
-                return true;
973
-            }
974
-        }
975
-        return false;
976
-    }
977
-
978
-
979
-    /**
980
-     * This returns all the contexts that are registered by all message types.
981
-     * If $slugs_only is true,
982
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
-     * array(
984
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
-     * );
986
-     * If $slugs_only is false, then the format is:
987
-     * array(
988
-     *      'message_type_name' => array(
989
-     *          'context_slug' => array(
990
-     *              'label' => 'localized label for context',
991
-     *              'description' => 'localized description for context'
992
-     *          )
993
-     *      )
994
-     * );
995
-     * Keep in mind that although different message types may share the same context slugs,
996
-     * it is possible that the context is described differently by the message type.
997
-     *
998
-     * @since 4.9.0
999
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
-     *                           or all contexts indexed by message type.
1001
-     * @return array
1002
-     */
1003
-    public function get_all_contexts($slugs_only = true)
1004
-    {
1005
-        $key = $slugs_only ? 'slugs' : 'all';
1006
-        // check if contexts has been setup yet.
1007
-        if (empty($this->_contexts[$key])) {
1008
-            // So let's get all active message type objects and loop through to get all unique contexts
1009
-            foreach ($this->get_active_message_type_objects() as $message_type) {
1010
-                if ($message_type instanceof EE_message_type) {
1011
-                    $message_type_contexts = $message_type->get_contexts();
1012
-                    if ($slugs_only) {
1013
-                        foreach ($message_type_contexts as $context => $context_details) {
1014
-                            $this->_contexts[$key][$context] = $context_details['label'];
1015
-                        }
1016
-                    } else {
1017
-                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
-                    }
1019
-                }
1020
-            }
1021
-        }
1022
-        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * This checks the internal record of what message types are considered "active" and verifies that
1028
-     * there is an installed class definition for that message type.  If the active message type does not have a
1029
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
-     * any related message templates will be inactivated as well.
1031
-     *
1032
-     * @return bool   true means all active message types are valid, false means at least one message type was
1033
-     *                deactivated.
1034
-     */
1035
-    public function validate_active_message_types_are_installed()
1036
-    {
1037
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1038
-        $installed_message_types           = $this->installed_message_types();
1039
-        $all_message_types_valid           = true;
1040
-        //loop through list of active message types and verify they are installed.
1041
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1042
-            if (! isset($installed_message_types[$message_type_name])) {
1043
-                $this->remove_message_type_has_been_activated_from_all_messengers(
1044
-                    $message_type_name,
1045
-                    true
1046
-                );
1047
-                $this->deactivate_message_type($message_type_name, false);
1048
-                $all_message_types_valid = false;
1049
-            }
1050
-        }
1051
-        return $all_message_types_valid;
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
-     * to attempt automatically reactivating message types that should be activated by default or not.
1059
-     *
1060
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
-     *
1062
-     * @param $message_type_name
1063
-     * @param $messenger_name
1064
-     * @return bool
1065
-     */
1066
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
-    {
1068
-        $has_activated = $this->get_has_activated_messengers_option();
1069
-        return isset($has_activated[$messenger_name])
1070
-               && in_array($message_type_name, $has_activated[$messenger_name]);
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * This method unsets a message type from the given messenger has activated option.
1076
-     *
1077
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
-     *
1079
-     * @param string $message_type_name
1080
-     * @param string $messenger_name
1081
-     * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
-     *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
-     */
1084
-    public function remove_message_type_has_been_activated_for_messenger(
1085
-        $message_type_name,
1086
-        $messenger_name,
1087
-        $consider_current_state = false
1088
-    ) {
1089
-        if ($consider_current_state
1090
-            && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
-        ) {
1092
-            //when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
-            //record if the message type is currently active for this messenger.  This is used when we want to retain
1094
-            //the record for user initiated inactivations of the message type.
1095
-            return;
1096
-        }
1097
-        $has_activated = $this->get_has_activated_messengers_option();
1098
-        $key_for_message_type = isset($has_activated[$messenger_name])
1099
-            ? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
-            : false;
1101
-        if ($key_for_message_type !== false) {
1102
-            unset($has_activated[$messenger_name][$key_for_message_type]);
1103
-            $this->update_has_activated_messengers_option($has_activated);
1104
-            //reset the internal cached property
1105
-            $this->get_has_activated_messengers_option(true);
1106
-        }
1107
-    }
1108
-
1109
-
1110
-    /**
1111
-     * Removes a message type active record from all messengers it is attached to.
1112
-     *
1113
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
-     *
1115
-     * @param      $message_type_name
1116
-     * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
-     *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
-     */
1119
-    public function remove_message_type_has_been_activated_from_all_messengers(
1120
-        $message_type_name,
1121
-        $consider_current_state = false
1122
-    ) {
1123
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
-            $this->remove_message_type_has_been_activated_for_messenger(
1125
-                $message_type_name,
1126
-                $messenger_name,
1127
-                $consider_current_state
1128
-            );
1129
-        }
1130
-    }
20
+	/**
21
+	 * This option in the database is used to keep a record of message types that have been activated for a messenger
22
+	 * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
+	 * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
+	 * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
+	 * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
+	 * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
+	 * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
+	 * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
+	 * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
+	 * the "force" flag is respected if that message type is later re-registered.
31
+	 *
32
+	 * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
+	 *
34
+	 * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
+	 * option that got superseded by later behaviour requirements.
36
+	 */
37
+	const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
+
39
+	/**
40
+	 * @type boolean $_initialized
41
+	 */
42
+	protected $_initialized = false;
43
+
44
+	/**
45
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
46
+	 */
47
+	protected $_messenger_collection_loader;
48
+
49
+	/**
50
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
51
+	 */
52
+	protected $_message_type_collection_loader;
53
+
54
+	/**
55
+	 * @type EEM_Message_Template_Group $_message_template_group_model
56
+	 */
57
+	protected $_message_template_group_model;
58
+
59
+	/**
60
+	 * @type EE_messenger[]
61
+	 */
62
+	protected $_installed_messengers = array();
63
+
64
+	/**
65
+	 * @type EE_message_type[]
66
+	 */
67
+	protected $_installed_message_types = array();
68
+
69
+	/**
70
+	 * Array of active messengers.
71
+	 * Format is this:
72
+	 * array(
73
+	 *      'messenger_name' => EE_messenger
74
+	 * )
75
+	 *
76
+	 * @type EE_messenger[]
77
+	 */
78
+	protected $_active_messengers = array();
79
+
80
+	/**
81
+	 * Formatted array of active message types grouped per messenger.
82
+	 * Format is this:
83
+	 * array(
84
+	 *      'messenger_name' => array(
85
+	 *          'settings' => array(
86
+	 *              '{messenger_name}-message_types' => array(
87
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
+	 *              )
89
+	 *          )
90
+	 *      )
91
+	 * )
92
+	 *
93
+	 * @type array
94
+	 */
95
+	protected $_active_message_types = array();
96
+
97
+
98
+	/**
99
+	 * This holds the array of messengers and their corresponding message types that have
100
+	 * been activated on a site at some point.  This is an important record that helps the messages system
101
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
102
+	 *
103
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
+	 *
105
+	 * @type array
106
+	 */
107
+	protected $_has_activated_messengers_and_message_types = array();
108
+
109
+	/**
110
+	 * An array of unique message type contexts across all active message types.
111
+	 * The array will be indexed by either 'slugs' or 'all'.
112
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
+	 * slug. array(
114
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
+	 * );
116
+	 * The all index returns an array in this format:
117
+	 * array(
118
+	 *      'message_type_name' => array(
119
+	 *          'context_slug' => array(
120
+	 *              'label' => 'localized label for context',
121
+	 *              'description' => 'localized description for context'
122
+	 *          )
123
+	 *      )
124
+	 * );
125
+	 *
126
+	 * @type array
127
+	 */
128
+	protected $_contexts = array();
129
+
130
+
131
+	/**
132
+	 * EE_Message_Resource_Manager constructor.
133
+	 *
134
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
+	 */
138
+	function __construct(
139
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
+		EEM_Message_Template_Group $Message_Template_Group_Model
142
+	) {
143
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return void
151
+	 */
152
+	protected function _initialize_collections()
153
+	{
154
+		if ($this->_initialized) {
155
+			return;
156
+		}
157
+		$this->_initialized = true;
158
+		$this->_messenger_collection_loader->load_messengers_from_folder();
159
+		$this->_message_type_collection_loader->load_message_types_from_folder();
160
+		$this->get_has_activated_messengers_option(true);
161
+		$this->_set_active_messengers_and_message_types();
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return EE_Messenger_Collection
167
+	 */
168
+	public function messenger_collection()
169
+	{
170
+		$this->_initialize_collections();
171
+		return $this->_messenger_collection_loader->messenger_collection();
172
+	}
173
+
174
+
175
+	/**
176
+	 * @return EE_messenger[]
177
+	 */
178
+	public function active_messengers()
179
+	{
180
+		$this->_initialize_collections();
181
+		return $this->_active_messengers;
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string $messenger_name
187
+	 * @return \EE_messenger
188
+	 */
189
+	public function get_messenger($messenger_name)
190
+	{
191
+		return $this->messenger_collection()->get_by_info($messenger_name);
192
+	}
193
+
194
+
195
+	/**
196
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
197
+	 *
198
+	 * @param string $messenger
199
+	 * @return EE_messenger | null
200
+	 */
201
+	public function get_active_messenger($messenger)
202
+	{
203
+		$this->_initialize_collections();
204
+		return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return \EE_messenger[]
210
+	 */
211
+	public function installed_messengers()
212
+	{
213
+		if (empty($this->_installed_messengers)) {
214
+			$this->_installed_messengers = array();
215
+			$this->messenger_collection()->rewind();
216
+			while ($this->messenger_collection()->valid()) {
217
+				$this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
+				$this->messenger_collection()->next();
219
+			}
220
+		}
221
+		return $this->_installed_messengers;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @param string $messenger_name
227
+	 * @return \EE_messenger
228
+	 * @throws \EE_Error
229
+	 */
230
+	public function valid_messenger($messenger_name)
231
+	{
232
+		$messenger = $this->get_messenger($messenger_name);
233
+		if ($messenger instanceof EE_messenger) {
234
+			return $messenger;
235
+		}
236
+		throw new EE_Error(
237
+			sprintf(
238
+				__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
+				$messenger_name
240
+			)
241
+		);
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return EE_Message_Type_Collection
247
+	 */
248
+	public function message_type_collection()
249
+	{
250
+		$this->_initialize_collections();
251
+		return $this->_message_type_collection_loader->message_type_collection();
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return array
257
+	 */
258
+	public function active_message_types()
259
+	{
260
+		$this->_initialize_collections();
261
+		return $this->_active_message_types;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $message_type_name
267
+	 * @return \EE_message_type
268
+	 */
269
+	public function get_message_type($message_type_name)
270
+	{
271
+		return $this->message_type_collection()->get_by_info($message_type_name);
272
+	}
273
+
274
+
275
+	/**
276
+	 * This returns the EE_message_type from the active message types array ( if present );
277
+	 *
278
+	 * @param string $messenger_name
279
+	 * @param string $message_type_name
280
+	 * @return \EE_message_type|null
281
+	 */
282
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
+	{
284
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
+			? $this->get_message_type($message_type_name)
286
+			: null;
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns whether the given message type is active for the given messenger.
292
+	 *
293
+	 * @param string $messenger_name
294
+	 * @param string $message_type_name
295
+	 * @return bool
296
+	 */
297
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
+	{
299
+		$this->_initialize_collections();
300
+		return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
+	}
302
+
303
+
304
+	/**
305
+	 * Returns whether the given messenger is active.
306
+	 *
307
+	 * @param string $messenger_name the name of the messenger to check if active.
308
+	 * @return bool
309
+	 */
310
+	public function is_messenger_active($messenger_name)
311
+	{
312
+		$this->_initialize_collections();
313
+		return ! empty($this->_active_message_types[$messenger_name]);
314
+	}
315
+
316
+
317
+	/**
318
+	 * This returns any settings that might be on a message type for a messenger
319
+	 *
320
+	 * @param string $messenger_name    The slug of the messenger
321
+	 * @param string $message_type_name The slug of the message type getting the settings for.
322
+	 * @return array
323
+	 */
324
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
+	{
326
+		$settings = array();
327
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
+			$settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
+				? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
+				: array();
331
+		}
332
+		return $settings;
333
+	}
334
+
335
+
336
+	/**
337
+	 * Returns whether the given messenger name has active message types on it.
338
+	 * Infers whether the messenger is active or not as well.
339
+	 *
340
+	 * @param string $messenger_name
341
+	 * @return bool
342
+	 */
343
+	public function messenger_has_active_message_types($messenger_name)
344
+	{
345
+		$this->_initialize_collections();
346
+		return
347
+			! empty($this->_active_message_types[$messenger_name])
348
+			&& ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
+	}
350
+
351
+
352
+	/**
353
+	 * This checks the _active_message_types property for any active message types
354
+	 * that are present for the given messenger and returns them.
355
+	 *
356
+	 * @since 4.9.0
357
+	 * @param string $messenger_name The messenger being checked
358
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
359
+	 */
360
+	public function get_active_message_types_for_messenger($messenger_name)
361
+	{
362
+		$message_types = array();
363
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
364
+			return $message_types;
365
+		}
366
+		$installed_message_types = $this->installed_message_types();
367
+		foreach ($installed_message_types as $message_type_name => $message_type) {
368
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
+				$message_types[$message_type_name] = $message_type;
370
+			}
371
+		}
372
+		return $message_types;
373
+	}
374
+
375
+
376
+	/**
377
+	 * This does NOT return the _active_message_types property but
378
+	 * simply returns an array of active message type names from that property.
379
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
+	 *
381
+	 * @return array message_type references (string)
382
+	 */
383
+	public function list_of_active_message_types()
384
+	{
385
+		$active_message_type_names = array();
386
+		$this->_initialize_collections();
387
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
+			if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
+				continue;
390
+			}
391
+			foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
+				if (! in_array($message_type_name, $active_message_type_names)) {
393
+					$active_message_type_names[] = $message_type_name;
394
+				}
395
+			}
396
+		}
397
+		return $active_message_type_names;
398
+	}
399
+
400
+
401
+	/**
402
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
+	 *
404
+	 * @since 4.9.0
405
+	 * @return \EE_message_type[]
406
+	 */
407
+	public function get_active_message_type_objects()
408
+	{
409
+		$active_message_types      = array();
410
+		$installed_message_types   = $this->installed_message_types();
411
+		$active_message_type_names = $this->list_of_active_message_types();
412
+		foreach ($active_message_type_names as $active_message_type_name) {
413
+			if (isset($installed_message_types[$active_message_type_name])) {
414
+				$active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
+			}
416
+		}
417
+		return $active_message_types;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @return \EE_message_type[]
423
+	 */
424
+	public function installed_message_types()
425
+	{
426
+		if (empty($this->_installed_message_types)) {
427
+			$this->message_type_collection()->rewind();
428
+			while ($this->message_type_collection()->valid()) {
429
+				$this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
+				$this->message_type_collection()->next();
431
+			}
432
+		}
433
+		return $this->_installed_message_types;
434
+	}
435
+
436
+
437
+	/**
438
+	 * @param string $message_type_name
439
+	 * @return \EE_message_type
440
+	 * @throws \EE_Error
441
+	 */
442
+	public function valid_message_type($message_type_name)
443
+	{
444
+		$message_type = $this->get_message_type($message_type_name);
445
+		if ($message_type instanceof EE_message_type) {
446
+			return $message_type;
447
+		}
448
+		throw new EE_Error(
449
+			sprintf(
450
+				__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
+				$message_type_name
452
+			)
453
+		);
454
+	}
455
+
456
+
457
+	/**
458
+	 * valid_message_type_for_messenger
459
+	 *
460
+	 * @param EE_messenger $messenger
461
+	 * @param string       $message_type_name
462
+	 * @return boolean
463
+	 * @throws \EE_Error
464
+	 */
465
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
+	{
467
+		$valid_message_types = $messenger->get_valid_message_types();
468
+		if (! in_array($message_type_name, $valid_message_types)) {
469
+			throw new EE_Error(
470
+				sprintf(
471
+					__(
472
+						'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
+						'event_espresso'
474
+					),
475
+					$message_type_name,
476
+					__METHOD__,
477
+					$messenger->name
478
+				)
479
+			);
480
+		}
481
+		return true;
482
+	}
483
+
484
+
485
+	/**
486
+	 * Used to return active messengers array stored in the wp options table.
487
+	 * If no value is present in the option then an empty array is returned.
488
+	 *
489
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
+	 *                          $_active_message_types property is pulled.
492
+	 * @return array
493
+	 */
494
+	public function get_active_messengers_option($reset = false)
495
+	{
496
+		if ($reset) {
497
+			$this->_active_message_types = get_option('ee_active_messengers', array());
498
+		}
499
+		return $this->_active_message_types;
500
+	}
501
+
502
+
503
+	/**
504
+	 * Used to update the active messengers array stored in the wp options table.
505
+	 *
506
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
+	 *                                         representing this data is used.
508
+	 * @return bool FALSE if not updated, TRUE if updated.
509
+	 */
510
+	public function update_active_messengers_option($active_messenger_settings = array())
511
+	{
512
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
+		//make sure _active_message_types is updated (this is the internal cache for the settings).
514
+		$this->_active_message_types = $active_messenger_settings;
515
+		return update_option('ee_active_messengers', $active_messenger_settings);
516
+	}
517
+
518
+
519
+	/**
520
+	 * Used to return has activated message types for messengers array stored in the wp options table.
521
+	 * If no value is present in the option then an empty array is returned.
522
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
+	 *
525
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
526
+	 * @return array
527
+	 */
528
+	public function get_has_activated_messengers_option($reset = false)
529
+	{
530
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
+			$this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
+		}
533
+		return $this->_has_activated_messengers_and_message_types;
534
+	}
535
+
536
+
537
+	/**
538
+	 * Used to update the has activated option in the db.
539
+	 *
540
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
+	 *
542
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
+	 *                                        representing this data is used.
544
+	 * @return bool FALSE if not updated, TRUE if updated.
545
+	 */
546
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
547
+	{
548
+		//make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
+			$this->get_has_activated_messengers_option();
551
+		}
552
+		$has_activated_messengers = empty($has_activated_messengers)
553
+			? $this->_has_activated_messengers_and_message_types
554
+			: $has_activated_messengers;
555
+		return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
+	}
557
+
558
+
559
+	/**
560
+	 * wrapper for _set_active_messengers_and_message_types()
561
+	 */
562
+	public function reset_active_messengers_and_message_types()
563
+	{
564
+		$this->_set_active_messengers_and_message_types();
565
+	}
566
+
567
+
568
+	/**
569
+	 * Generate list of active messengers and message types from collection.
570
+	 * This sets up the active messengers from what is present in the database.
571
+	 */
572
+	protected function _set_active_messengers_and_message_types()
573
+	{
574
+		//echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
+		// list of activated messengers as set via the admin
576
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
+		$this->get_active_messengers_option(true);
578
+		$this->ensure_messengers_are_active(array(), false, true);
579
+		$this->update_active_messengers_option();
580
+		$this->update_has_activated_messengers_option();
581
+	}
582
+
583
+
584
+	/**
585
+	 * Ensures that the specified messenger is currently active.
586
+	 * If not, activates it and its default message types.
587
+	 *
588
+	 * @param string $messenger_name
589
+	 * @param bool   $update_option Whether to update the option in the db or not.
590
+	 * @return boolean true if either already active or successfully activated.
591
+	 */
592
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
+	{
594
+		if (! isset($this->_active_messengers[$messenger_name])) {
595
+			try {
596
+				$this->activate_messenger($messenger_name, array(), $update_option);
597
+			} catch (EE_Error $e) {
598
+				EE_Error::add_error(
599
+					$e->getMessage(),
600
+					__FILE__,
601
+					__FUNCTION__,
602
+					__LINE__
603
+				);
604
+				return false;
605
+			}
606
+		}
607
+		return true;
608
+	}
609
+
610
+
611
+	/**
612
+	 * This ensures the given array of messenger names is active in the system.
613
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
+	 * it will automatically activate the default message types for the messenger if its not active.
615
+	 *
616
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
+	 *                                (default) then will attempt to set the active messengers from the
618
+	 *                                activated_messengers option
619
+	 *                                (stored in $_active_message_types property).
620
+	 * @param bool  $update_option    Whether to update the related active messengers option.
621
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
+	 *                                will automatically be deactivated.
624
+	 */
625
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
+	{
627
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
+
629
+		$not_installed = array();
630
+		foreach ($messenger_names as $messenger_name) {
631
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
+				$not_installed[] = $messenger_name;
633
+				$this->deactivate_messenger($messenger_name);
634
+				continue;
635
+			}
636
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
637
+		}
638
+
639
+		if (! empty($not_installed)) {
640
+			EE_Error::add_error(
641
+				sprintf(
642
+					__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
+					'<br />',
644
+					implode(', ', $not_installed)
645
+				),
646
+				__FILE__, __FUNCTION__, __LINE__
647
+			);
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
+	 * This ALSO ensures that the given messenger is active as well!
655
+	 *
656
+	 * @param string $message_type_name message type name.
657
+	 * @param        $messenger_name
658
+	 * @param bool   $update_option     Whether to update the option in the db or not.
659
+	 * @return bool  Returns true if already is active or if was activated successfully.
660
+	 * @throws \EE_Error
661
+	 */
662
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
+	{
664
+		// grab the messenger to work with.
665
+		$messenger = $this->valid_messenger($messenger_name);
666
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
+			//ensure messenger is active (that's an inherent coupling between active message types and the
668
+			//messenger they are being activated for.
669
+			try {
670
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
+					//all is good so let's just get it active
672
+					$this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
+				}
674
+			} catch (EE_Error $e) {
675
+				EE_Error::add_error(
676
+					$e->getMessage(),
677
+					__FILE__,
678
+					__FUNCTION__,
679
+					__LINE__
680
+				);
681
+				return false;
682
+			}
683
+		}
684
+		return true;
685
+	}
686
+
687
+
688
+	/**
689
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
+	 * messenger are active in one go.
691
+	 *
692
+	 * @param array  $message_type_names Array of message type names to ensure are active.
693
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
+	 */
696
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
+	{
698
+		$message_type_names = (array)$message_type_names;
699
+		foreach ($message_type_names as $message_type_name) {
700
+			// note, intentionally not updating option here because we're in a loop.
701
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
702
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
+		}
704
+		if ($update_option) {
705
+			$this->update_active_messengers_option();
706
+			$this->update_has_activated_messengers_option();
707
+		}
708
+	}
709
+
710
+
711
+	/**
712
+	 * Activates the specified messenger.
713
+	 *
714
+	 * @param string $messenger_name
715
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
+	 *                                          If included we do NOT setup the default message types
717
+	 *                                          (assuming they are already setup.)
718
+	 * @param bool   $update_active_messengers_option
719
+	 * @return array of generated templates
720
+	 * @throws \EE_Error
721
+	 */
722
+	public function activate_messenger(
723
+		$messenger_name,
724
+		$message_type_names = array(),
725
+		$update_active_messengers_option = true
726
+	) {
727
+		$templates = array();
728
+		// grab the messenger to work with.
729
+		$messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
+		// it's inactive. Activate it.
731
+		if ($messenger instanceof EE_messenger) {
732
+			$this->_active_messengers[$messenger->name] = $messenger;
733
+			//activate incoming message types set to be activated with messenger.
734
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
+			// setup any initial settings for the messenger if necessary.
736
+			$this->add_settings_for_messenger($messenger->name);
737
+			if ($update_active_messengers_option) {
738
+				$this->update_active_messengers_option();
739
+				$this->update_has_activated_messengers_option();
740
+			}
741
+			//generate new templates if necessary and ensure all related templates that are already in the database are
742
+			//marked active.  Note, this will also deactivate a message type for a messenger if the template
743
+			//cannot be successfully created during its attempt (only happens for global template attempts).
744
+			if (! empty($message_type_names)) {
745
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
+			}
748
+		}
749
+		return $templates;
750
+	}
751
+
752
+
753
+	/**
754
+	 * Activates given message types for the given EE_messenger object.
755
+	 * Note: (very important) This method does not persist the activation to the database.
756
+	 * See code implementing this method in this class for examples of how to persist.
757
+	 *
758
+	 * @param \EE_messenger $messenger
759
+	 * @param  array        $message_type_names
760
+	 * @return array
761
+	 */
762
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
+	{
764
+		//If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
+		//things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
+		//So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
+		//only override _active_message_types when an explicit array of $message_type_names has been provided.
768
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
+			? $messenger->get_default_message_types()
770
+			: (array)$message_type_names;
771
+
772
+		//now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
+		if (! isset($this->_active_message_types[$messenger->name])) {
774
+			$this->_active_message_types[$messenger->name]['settings'] = array();
775
+		}
776
+
777
+		if ($message_type_names) {
778
+			// cycle thru message types
779
+			foreach ($message_type_names as $message_type_name) {
780
+				//only register the message type as active IF it isn't already active
781
+				//and if its actually installed.
782
+				if (
783
+				! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
+				) {
785
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
786
+					$this->_set_messenger_has_activated_message_type(
787
+						$messenger,
788
+						$message_type_name
789
+					);
790
+				}
791
+			}
792
+		}
793
+		return $message_type_names;
794
+	}
795
+
796
+
797
+	/**
798
+	 * add_settings_for_message_type
799
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
+	 * $this->update_active_messengers_option to persist.
801
+	 *
802
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
803
+	 * @param  string $message_type_name The name of the message type adding the settings for
804
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
+	 */
806
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
+	{
808
+		// get installed message type from collection
809
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
+		//we need to setup any initial settings for message types
812
+		if ($message_type instanceof EE_message_type) {
813
+			$default_settings = $message_type->get_admin_settings_fields();
814
+			foreach ($default_settings as $field => $values) {
815
+				if (isset($new_settings[$field])) {
816
+					$existing_settings[$field] = $new_settings[$field];
817
+					continue;
818
+				}
819
+				if (! isset($existing_settings[$field])) {
820
+					$existing_settings[$field] = $values['default'];
821
+				}
822
+			}
823
+		}
824
+		$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
+	}
826
+
827
+
828
+	/**
829
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
+	 * and message type.
831
+	 *
832
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
+	 *
834
+	 * @access protected
835
+	 * @param \EE_messenger $messenger
836
+	 * @param string        $message_type_name
837
+	 */
838
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
+	{
840
+
841
+		//if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
+		if (empty($this->_has_activated_messengers_and_message_types)) {
843
+			$this->get_has_activated_messengers_option();
844
+		}
845
+
846
+		// make sure this messenger has a record in the has_activated array
847
+		if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
+			$this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
+		}
850
+		// check if message type has already been added
851
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
+			$this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
+		}
854
+	}
855
+
856
+
857
+	/**
858
+	 * add_settings_for_messenger
859
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
+	 * $this->update_active_messengers_option to persist.
861
+	 *
862
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
863
+	 * @param array  $new_settings   An array of settings to update the existing settings.
864
+	 */
865
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
+	{
867
+		$messenger = $this->get_messenger($messenger_name);
868
+		if ($messenger instanceof EE_messenger) {
869
+			$msgr_settings = $messenger->get_admin_settings_fields();
870
+			if (! empty($msgr_settings)) {
871
+				foreach ($msgr_settings as $field => $value) {
872
+					//is there a new setting for this?
873
+					if (isset($new_settings[$field])) {
874
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
+						continue;
876
+					}
877
+					//only set the default if it isn't already set.
878
+					if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
+					}
881
+				}
882
+			}
883
+		}
884
+	}
885
+
886
+
887
+	/**
888
+	 * deactivate_messenger
889
+	 *
890
+	 * @param  string|EE_messenger $messenger_name name of messenger
891
+	 * @return void
892
+	 */
893
+	public function deactivate_messenger($messenger_name)
894
+	{
895
+		$this->_initialize_collections();
896
+		if ($messenger_name instanceof EE_messenger) {
897
+			$messenger_name = $messenger_name->name;
898
+		}
899
+		unset($this->_active_messengers[$messenger_name]);
900
+		unset($this->_active_message_types[$messenger_name]);
901
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
+		$this->update_active_messengers_option();
903
+	}
904
+
905
+
906
+	/**
907
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
+	 *
909
+	 * @param  string $message_type_name     name of message type being deactivated
910
+	 * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
+	 *                                       type.  However, this can be overridden if we don't want this set (usually when
912
+	 *                                       this is called as a part of deregistration of a custom message type)
913
+	 */
914
+	public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
+	{
916
+		$this->_initialize_collections();
917
+		if ($message_type_name instanceof EE_message_type) {
918
+			$message_type_name = $message_type_name->name;
919
+		}
920
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
921
+			unset(
922
+				$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
+			);
924
+
925
+			//we always record (even on deactivation) that a message type has been activated because there should at
926
+			//least be a record in the "has_activated" option that it WAS active at one point.
927
+			if ($set_has_active_record) {
928
+				$messenger = $this->get_messenger($messenger_name);
929
+				$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
+			}
931
+		}
932
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
+		$this->update_active_messengers_option();
934
+		$this->update_has_activated_messengers_option();
935
+	}
936
+
937
+
938
+	/**
939
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
940
+	 *
941
+	 * @param string $message_type_name Name of message type being deactivated.
942
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
+	 */
944
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
+	{
946
+		$this->_initialize_collections();
947
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
+			unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
+		}
950
+		$this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
+			array($message_type_name));
952
+		$this->update_active_messengers_option();
953
+	}
954
+
955
+
956
+	/**
957
+	 * Used to verify if a message can be sent for the given messenger and message type
958
+	 * and that it is a generating messenger (used for generating message templates).
959
+	 *
960
+	 * @param EE_messenger    $messenger    messenger used in trigger
961
+	 * @param EE_message_type $message_type message type used in trigger
962
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
+	 */
964
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
+	{
966
+		//get the $messengers the message type says it can be used with.
967
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
+			if (
969
+				$messenger->name === $generating_messenger
970
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
+			) {
972
+				return true;
973
+			}
974
+		}
975
+		return false;
976
+	}
977
+
978
+
979
+	/**
980
+	 * This returns all the contexts that are registered by all message types.
981
+	 * If $slugs_only is true,
982
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
+	 * array(
984
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
+	 * );
986
+	 * If $slugs_only is false, then the format is:
987
+	 * array(
988
+	 *      'message_type_name' => array(
989
+	 *          'context_slug' => array(
990
+	 *              'label' => 'localized label for context',
991
+	 *              'description' => 'localized description for context'
992
+	 *          )
993
+	 *      )
994
+	 * );
995
+	 * Keep in mind that although different message types may share the same context slugs,
996
+	 * it is possible that the context is described differently by the message type.
997
+	 *
998
+	 * @since 4.9.0
999
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
+	 *                           or all contexts indexed by message type.
1001
+	 * @return array
1002
+	 */
1003
+	public function get_all_contexts($slugs_only = true)
1004
+	{
1005
+		$key = $slugs_only ? 'slugs' : 'all';
1006
+		// check if contexts has been setup yet.
1007
+		if (empty($this->_contexts[$key])) {
1008
+			// So let's get all active message type objects and loop through to get all unique contexts
1009
+			foreach ($this->get_active_message_type_objects() as $message_type) {
1010
+				if ($message_type instanceof EE_message_type) {
1011
+					$message_type_contexts = $message_type->get_contexts();
1012
+					if ($slugs_only) {
1013
+						foreach ($message_type_contexts as $context => $context_details) {
1014
+							$this->_contexts[$key][$context] = $context_details['label'];
1015
+						}
1016
+					} else {
1017
+						$this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
+					}
1019
+				}
1020
+			}
1021
+		}
1022
+		return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * This checks the internal record of what message types are considered "active" and verifies that
1028
+	 * there is an installed class definition for that message type.  If the active message type does not have a
1029
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
+	 * any related message templates will be inactivated as well.
1031
+	 *
1032
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1033
+	 *                deactivated.
1034
+	 */
1035
+	public function validate_active_message_types_are_installed()
1036
+	{
1037
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1038
+		$installed_message_types           = $this->installed_message_types();
1039
+		$all_message_types_valid           = true;
1040
+		//loop through list of active message types and verify they are installed.
1041
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1042
+			if (! isset($installed_message_types[$message_type_name])) {
1043
+				$this->remove_message_type_has_been_activated_from_all_messengers(
1044
+					$message_type_name,
1045
+					true
1046
+				);
1047
+				$this->deactivate_message_type($message_type_name, false);
1048
+				$all_message_types_valid = false;
1049
+			}
1050
+		}
1051
+		return $all_message_types_valid;
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1059
+	 *
1060
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
+	 *
1062
+	 * @param $message_type_name
1063
+	 * @param $messenger_name
1064
+	 * @return bool
1065
+	 */
1066
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
+	{
1068
+		$has_activated = $this->get_has_activated_messengers_option();
1069
+		return isset($has_activated[$messenger_name])
1070
+			   && in_array($message_type_name, $has_activated[$messenger_name]);
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * This method unsets a message type from the given messenger has activated option.
1076
+	 *
1077
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
+	 *
1079
+	 * @param string $message_type_name
1080
+	 * @param string $messenger_name
1081
+	 * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
+	 *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
+	 */
1084
+	public function remove_message_type_has_been_activated_for_messenger(
1085
+		$message_type_name,
1086
+		$messenger_name,
1087
+		$consider_current_state = false
1088
+	) {
1089
+		if ($consider_current_state
1090
+			&& ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
+		) {
1092
+			//when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
+			//record if the message type is currently active for this messenger.  This is used when we want to retain
1094
+			//the record for user initiated inactivations of the message type.
1095
+			return;
1096
+		}
1097
+		$has_activated = $this->get_has_activated_messengers_option();
1098
+		$key_for_message_type = isset($has_activated[$messenger_name])
1099
+			? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
+			: false;
1101
+		if ($key_for_message_type !== false) {
1102
+			unset($has_activated[$messenger_name][$key_for_message_type]);
1103
+			$this->update_has_activated_messengers_option($has_activated);
1104
+			//reset the internal cached property
1105
+			$this->get_has_activated_messengers_option(true);
1106
+		}
1107
+	}
1108
+
1109
+
1110
+	/**
1111
+	 * Removes a message type active record from all messengers it is attached to.
1112
+	 *
1113
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
+	 *
1115
+	 * @param      $message_type_name
1116
+	 * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
+	 *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
+	 */
1119
+	public function remove_message_type_has_been_activated_from_all_messengers(
1120
+		$message_type_name,
1121
+		$consider_current_state = false
1122
+	) {
1123
+		foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
+			$this->remove_message_type_has_been_activated_for_messenger(
1125
+				$message_type_name,
1126
+				$messenger_name,
1127
+				$consider_current_state
1128
+			);
1129
+		}
1130
+	}
1131 1131
 }
1132 1132
 // End of file EE_Message_Resource_Manager.lib.php
1133 1133
 // Location: /EE_Message_Resource_Manager.lib.php
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298 298
     {
299 299
         $this->_initialize_collections();
300
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
300
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
301 301
     }
302 302
 
303 303
 
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
     {
326 326
         $settings = array();
327 327
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
328
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
329
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
330 330
                 : array();
331 331
         }
332 332
         return $settings;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
         $this->_initialize_collections();
346 346
         return
347 347
             ! empty($this->_active_message_types[$messenger_name])
348
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
348
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
349 349
     }
350 350
 
351 351
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
     public function get_active_message_types_for_messenger($messenger_name)
361 361
     {
362 362
         $message_types = array();
363
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
363
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
364 364
             return $message_types;
365 365
         }
366 366
         $installed_message_types = $this->installed_message_types();
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
         $active_message_type_names = array();
386 386
         $this->_initialize_collections();
387 387
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
388
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
389 389
                 continue;
390 390
             }
391
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
-                if (! in_array($message_type_name, $active_message_type_names)) {
391
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
392
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
393 393
                     $active_message_type_names[] = $message_type_name;
394 394
                 }
395 395
             }
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466 466
     {
467 467
         $valid_message_types = $messenger->get_valid_message_types();
468
-        if (! in_array($message_type_name, $valid_message_types)) {
468
+        if ( ! in_array($message_type_name, $valid_message_types)) {
469 469
             throw new EE_Error(
470 470
                 sprintf(
471 471
                     __(
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
      */
592 592
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
593 593
     {
594
-        if (! isset($this->_active_messengers[$messenger_name])) {
594
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
595 595
             try {
596 596
                 $this->activate_messenger($messenger_name, array(), $update_option);
597 597
             } catch (EE_Error $e) {
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
             $this->ensure_messenger_is_active($messenger_name, $update_option);
637 637
         }
638 638
 
639
-        if (! empty($not_installed)) {
639
+        if ( ! empty($not_installed)) {
640 640
             EE_Error::add_error(
641 641
                 sprintf(
642 642
                     __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
             //ensure messenger is active (that's an inherent coupling between active message types and the
668 668
             //messenger they are being activated for.
669 669
             try {
670
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
670
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671 671
                     //all is good so let's just get it active
672 672
                     $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673 673
                 }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
      */
696 696
     public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697 697
     {
698
-        $message_type_names = (array)$message_type_names;
698
+        $message_type_names = (array) $message_type_names;
699 699
         foreach ($message_type_names as $message_type_name) {
700 700
             // note, intentionally not updating option here because we're in a loop.
701 701
             // We'll follow the instructions of the incoming $update_option argument after the loop.
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
             //generate new templates if necessary and ensure all related templates that are already in the database are
742 742
             //marked active.  Note, this will also deactivate a message type for a messenger if the template
743 743
             //cannot be successfully created during its attempt (only happens for global template attempts).
744
-            if (! empty($message_type_names)) {
744
+            if ( ! empty($message_type_names)) {
745 745
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746 746
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747 747
             }
@@ -767,10 +767,10 @@  discard block
 block discarded – undo
767 767
         //only override _active_message_types when an explicit array of $message_type_names has been provided.
768 768
         $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769 769
             ? $messenger->get_default_message_types()
770
-            : (array)$message_type_names;
770
+            : (array) $message_type_names;
771 771
 
772 772
         //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
-        if (! isset($this->_active_message_types[$messenger->name])) {
773
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
774 774
             $this->_active_message_types[$messenger->name]['settings'] = array();
775 775
         }
776 776
 
@@ -816,12 +816,12 @@  discard block
 block discarded – undo
816 816
                     $existing_settings[$field] = $new_settings[$field];
817 817
                     continue;
818 818
                 }
819
-                if (! isset($existing_settings[$field])) {
819
+                if ( ! isset($existing_settings[$field])) {
820 820
                     $existing_settings[$field] = $values['default'];
821 821
                 }
822 822
             }
823 823
         }
824
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
824
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
825 825
     }
826 826
 
827 827
 
@@ -844,11 +844,11 @@  discard block
 block discarded – undo
844 844
         }
845 845
 
846 846
         // make sure this messenger has a record in the has_activated array
847
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
847
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848 848
             $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849 849
         }
850 850
         // check if message type has already been added
851
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
851
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852 852
             $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853 853
         }
854 854
     }
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
         $messenger = $this->get_messenger($messenger_name);
868 868
         if ($messenger instanceof EE_messenger) {
869 869
             $msgr_settings = $messenger->get_admin_settings_fields();
870
-            if (! empty($msgr_settings)) {
870
+            if ( ! empty($msgr_settings)) {
871 871
                 foreach ($msgr_settings as $field => $value) {
872 872
                     //is there a new setting for this?
873 873
                     if (isset($new_settings[$field])) {
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
                         continue;
876 876
                     }
877 877
                     //only set the default if it isn't already set.
878
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
878
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879 879
                         $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880 880
                     }
881 881
                 }
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
         }
920 920
         foreach ($this->_active_message_types as $messenger_name => $settings) {
921 921
             unset(
922
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
922
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
923 923
             );
924 924
 
925 925
             //we always record (even on deactivation) that a message type has been activated because there should at
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
     {
946 946
         $this->_initialize_collections();
947 947
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
948
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
949 949
         }
950 950
         $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951 951
             array($message_type_name));
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
         $all_message_types_valid           = true;
1040 1040
         //loop through list of active message types and verify they are installed.
1041 1041
         foreach ($list_of_active_message_type_names as $message_type_name) {
1042
-            if (! isset($installed_message_types[$message_type_name])) {
1042
+            if ( ! isset($installed_message_types[$message_type_name])) {
1043 1043
                 $this->remove_message_type_has_been_activated_from_all_messengers(
1044 1044
                     $message_type_name,
1045 1045
                     true
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
         $message_type_name,
1121 1121
         $consider_current_state = false
1122 1122
     ) {
1123
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1123
+        foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124 1124
             $this->remove_message_type_has_been_activated_for_messenger(
1125 1125
                 $message_type_name,
1126 1126
                 $messenger_name,
Please login to merge, or discard this patch.