Completed
Branch FET-9856-direct-instantiation (b332dc)
by
unknown
249:28 queued 238:33
created
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2550 added lines, -2550 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,2556 +17,2556 @@  discard block
 block discarded – undo
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19 19
 
20
-    /**
21
-     * This will hold the event object for event_details screen.
22
-     *
23
-     * @access protected
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-    /**
46
-     * @var EE_Event
47
-     */
48
-    protected $_cpt_model_obj = false;
49
-
50
-
51
-
52
-    protected function _init_page_props()
53
-    {
54
-        $this->page_slug = EVENTS_PG_SLUG;
55
-        $this->page_label = EVENTS_LABEL;
56
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
57
-        $this->_admin_base_path = EVENTS_ADMIN;
58
-        $this->_cpt_model_names = array(
59
-            'create_new' => 'EEM_Event',
60
-            'edit'       => 'EEM_Event',
61
-        );
62
-        $this->_cpt_edit_routes = array(
63
-            'espresso_events' => 'edit',
64
-        );
65
-        add_action(
66
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
-            array($this, 'verify_event_edit')
68
-        );
69
-    }
70
-
71
-
72
-
73
-    protected function _ajax_hooks()
74
-    {
75
-        //todo: all hooks for events ajax goes in here.
76
-    }
77
-
78
-
79
-
80
-    protected function _define_page_props()
81
-    {
82
-        $this->_admin_page_title = EVENTS_LABEL;
83
-        $this->_labels = array(
84
-            'buttons'      => array(
85
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
86
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
87
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
88
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
89
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
90
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
91
-            ),
92
-            'editor_title' => array(
93
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
94
-            ),
95
-            'publishbox'   => array(
96
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
97
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
98
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
99
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
100
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-
107
-    protected function _set_page_routes()
108
-    {
109
-        //load formatter helper
110
-        //load field generator helper
111
-        //is there a evt_id in the request?
112
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
113
-            ? $this->_req_data['EVT_ID'] : 0;
114
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
115
-        $this->_page_routes = array(
116
-            'default'                       => array(
117
-                'func'       => '_events_overview_list_table',
118
-                'capability' => 'ee_read_events',
119
-            ),
120
-            'create_new'                    => array(
121
-                'func'       => '_create_new_cpt_item',
122
-                'capability' => 'ee_edit_events',
123
-            ),
124
-            'edit'                          => array(
125
-                'func'       => '_edit_cpt_item',
126
-                'capability' => 'ee_edit_event',
127
-                'obj_id'     => $evt_id,
128
-            ),
129
-            'copy_event'                    => array(
130
-                'func'       => '_copy_events',
131
-                'capability' => 'ee_edit_event',
132
-                'obj_id'     => $evt_id,
133
-                'noheader'   => true,
134
-            ),
135
-            'trash_event'                   => array(
136
-                'func'       => '_trash_or_restore_event',
137
-                'args'       => array('event_status' => 'trash'),
138
-                'capability' => 'ee_delete_event',
139
-                'obj_id'     => $evt_id,
140
-                'noheader'   => true,
141
-            ),
142
-            'trash_events'                  => array(
143
-                'func'       => '_trash_or_restore_events',
144
-                'args'       => array('event_status' => 'trash'),
145
-                'capability' => 'ee_delete_events',
146
-                'noheader'   => true,
147
-            ),
148
-            'restore_event'                 => array(
149
-                'func'       => '_trash_or_restore_event',
150
-                'args'       => array('event_status' => 'draft'),
151
-                'capability' => 'ee_delete_event',
152
-                'obj_id'     => $evt_id,
153
-                'noheader'   => true,
154
-            ),
155
-            'restore_events'                => array(
156
-                'func'       => '_trash_or_restore_events',
157
-                'args'       => array('event_status' => 'draft'),
158
-                'capability' => 'ee_delete_events',
159
-                'noheader'   => true,
160
-            ),
161
-            'delete_event'                  => array(
162
-                'func'       => '_delete_event',
163
-                'capability' => 'ee_delete_event',
164
-                'obj_id'     => $evt_id,
165
-                'noheader'   => true,
166
-            ),
167
-            'delete_events'                 => array(
168
-                'func'       => '_delete_events',
169
-                'capability' => 'ee_delete_events',
170
-                'noheader'   => true,
171
-            ),
172
-            'view_report'                   => array(
173
-                'func'      => '_view_report',
174
-                'capablity' => 'ee_edit_events',
175
-            ),
176
-            'default_event_settings'        => array(
177
-                'func'       => '_default_event_settings',
178
-                'capability' => 'manage_options',
179
-            ),
180
-            'update_default_event_settings' => array(
181
-                'func'       => '_update_default_event_settings',
182
-                'capability' => 'manage_options',
183
-                'noheader'   => true,
184
-            ),
185
-            'template_settings'             => array(
186
-                'func'       => '_template_settings',
187
-                'capability' => 'manage_options',
188
-            ),
189
-            //event category tab related
190
-            'add_category'                  => array(
191
-                'func'       => '_category_details',
192
-                'capability' => 'ee_edit_event_category',
193
-                'args'       => array('add'),
194
-            ),
195
-            'edit_category'                 => array(
196
-                'func'       => '_category_details',
197
-                'capability' => 'ee_edit_event_category',
198
-                'args'       => array('edit'),
199
-            ),
200
-            'delete_categories'             => array(
201
-                'func'       => '_delete_categories',
202
-                'capability' => 'ee_delete_event_category',
203
-                'noheader'   => true,
204
-            ),
205
-            'delete_category'               => array(
206
-                'func'       => '_delete_categories',
207
-                'capability' => 'ee_delete_event_category',
208
-                'noheader'   => true,
209
-            ),
210
-            'insert_category'               => array(
211
-                'func'       => '_insert_or_update_category',
212
-                'args'       => array('new_category' => true),
213
-                'capability' => 'ee_edit_event_category',
214
-                'noheader'   => true,
215
-            ),
216
-            'update_category'               => array(
217
-                'func'       => '_insert_or_update_category',
218
-                'args'       => array('new_category' => false),
219
-                'capability' => 'ee_edit_event_category',
220
-                'noheader'   => true,
221
-            ),
222
-            'category_list'                 => array(
223
-                'func'       => '_category_list_table',
224
-                'capability' => 'ee_manage_event_categories',
225
-            ),
226
-        );
227
-    }
228
-
229
-
230
-
231
-    protected function _set_page_config()
232
-    {
233
-        $this->_page_config = array(
234
-            'default'                => array(
235
-                'nav'           => array(
236
-                    'label' => esc_html__('Overview', 'event_espresso'),
237
-                    'order' => 10,
238
-                ),
239
-                'list_table'    => 'Events_Admin_List_Table',
240
-                'help_tabs'     => array(
241
-                    'events_overview_help_tab'                       => array(
242
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
243
-                        'filename' => 'events_overview',
244
-                    ),
245
-                    'events_overview_table_column_headings_help_tab' => array(
246
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
247
-                        'filename' => 'events_overview_table_column_headings',
248
-                    ),
249
-                    'events_overview_filters_help_tab'               => array(
250
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
251
-                        'filename' => 'events_overview_filters',
252
-                    ),
253
-                    'events_overview_view_help_tab'                  => array(
254
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
255
-                        'filename' => 'events_overview_views',
256
-                    ),
257
-                    'events_overview_other_help_tab'                 => array(
258
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
259
-                        'filename' => 'events_overview_other',
260
-                    ),
261
-                ),
262
-                'help_tour'     => array(
263
-                    'Event_Overview_Help_Tour',
264
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
265
-                ),
266
-                'qtips'         => array(
267
-                    'EE_Event_List_Table_Tips',
268
-                ),
269
-                'require_nonce' => false,
270
-            ),
271
-            'create_new'             => array(
272
-                'nav'           => array(
273
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
274
-                    'order'      => 5,
275
-                    'persistent' => false,
276
-                ),
277
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
278
-                'help_tabs'     => array(
279
-                    'event_editor_help_tab'                            => array(
280
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
281
-                        'filename' => 'event_editor',
282
-                    ),
283
-                    'event_editor_title_richtexteditor_help_tab'       => array(
284
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
285
-                        'filename' => 'event_editor_title_richtexteditor',
286
-                    ),
287
-                    'event_editor_venue_details_help_tab'              => array(
288
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
289
-                        'filename' => 'event_editor_venue_details',
290
-                    ),
291
-                    'event_editor_event_datetimes_help_tab'            => array(
292
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
293
-                        'filename' => 'event_editor_event_datetimes',
294
-                    ),
295
-                    'event_editor_event_tickets_help_tab'              => array(
296
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
297
-                        'filename' => 'event_editor_event_tickets',
298
-                    ),
299
-                    'event_editor_event_registration_options_help_tab' => array(
300
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
301
-                        'filename' => 'event_editor_event_registration_options',
302
-                    ),
303
-                    'event_editor_tags_categories_help_tab'            => array(
304
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
305
-                        'filename' => 'event_editor_tags_categories',
306
-                    ),
307
-                    'event_editor_questions_registrants_help_tab'      => array(
308
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
309
-                        'filename' => 'event_editor_questions_registrants',
310
-                    ),
311
-                    'event_editor_save_new_event_help_tab'             => array(
312
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
313
-                        'filename' => 'event_editor_save_new_event',
314
-                    ),
315
-                    'event_editor_other_help_tab'                      => array(
316
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
317
-                        'filename' => 'event_editor_other',
318
-                    ),
319
-                ),
320
-                'help_tour'     => array(
321
-                    'Event_Editor_Help_Tour',
322
-                ),
323
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
324
-                'require_nonce' => false,
325
-            ),
326
-            'edit'                   => array(
327
-                'nav'           => array(
328
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
329
-                    'order'      => 5,
330
-                    'persistent' => false,
331
-                    'url'        => isset($this->_req_data['post'])
332
-                        ? EE_Admin_Page::add_query_args_and_nonce(
333
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
334
-                            $this->_current_page_view_url
335
-                        )
336
-                        : $this->_admin_base_url,
337
-                ),
338
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
339
-                'help_tabs'     => array(
340
-                    'event_editor_help_tab'                            => array(
341
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
342
-                        'filename' => 'event_editor',
343
-                    ),
344
-                    'event_editor_title_richtexteditor_help_tab'       => array(
345
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
346
-                        'filename' => 'event_editor_title_richtexteditor',
347
-                    ),
348
-                    'event_editor_venue_details_help_tab'              => array(
349
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
350
-                        'filename' => 'event_editor_venue_details',
351
-                    ),
352
-                    'event_editor_event_datetimes_help_tab'            => array(
353
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
354
-                        'filename' => 'event_editor_event_datetimes',
355
-                    ),
356
-                    'event_editor_event_tickets_help_tab'              => array(
357
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
358
-                        'filename' => 'event_editor_event_tickets',
359
-                    ),
360
-                    'event_editor_event_registration_options_help_tab' => array(
361
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
362
-                        'filename' => 'event_editor_event_registration_options',
363
-                    ),
364
-                    'event_editor_tags_categories_help_tab'            => array(
365
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
366
-                        'filename' => 'event_editor_tags_categories',
367
-                    ),
368
-                    'event_editor_questions_registrants_help_tab'      => array(
369
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
370
-                        'filename' => 'event_editor_questions_registrants',
371
-                    ),
372
-                    'event_editor_save_new_event_help_tab'             => array(
373
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
374
-                        'filename' => 'event_editor_save_new_event',
375
-                    ),
376
-                    'event_editor_other_help_tab'                      => array(
377
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
378
-                        'filename' => 'event_editor_other',
379
-                    ),
380
-                ),
381
-                /*'help_tour' => array(
20
+	/**
21
+	 * This will hold the event object for event_details screen.
22
+	 *
23
+	 * @access protected
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+	/**
46
+	 * @var EE_Event
47
+	 */
48
+	protected $_cpt_model_obj = false;
49
+
50
+
51
+
52
+	protected function _init_page_props()
53
+	{
54
+		$this->page_slug = EVENTS_PG_SLUG;
55
+		$this->page_label = EVENTS_LABEL;
56
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
57
+		$this->_admin_base_path = EVENTS_ADMIN;
58
+		$this->_cpt_model_names = array(
59
+			'create_new' => 'EEM_Event',
60
+			'edit'       => 'EEM_Event',
61
+		);
62
+		$this->_cpt_edit_routes = array(
63
+			'espresso_events' => 'edit',
64
+		);
65
+		add_action(
66
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
+			array($this, 'verify_event_edit')
68
+		);
69
+	}
70
+
71
+
72
+
73
+	protected function _ajax_hooks()
74
+	{
75
+		//todo: all hooks for events ajax goes in here.
76
+	}
77
+
78
+
79
+
80
+	protected function _define_page_props()
81
+	{
82
+		$this->_admin_page_title = EVENTS_LABEL;
83
+		$this->_labels = array(
84
+			'buttons'      => array(
85
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
86
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
87
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
88
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
89
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
90
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
91
+			),
92
+			'editor_title' => array(
93
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
94
+			),
95
+			'publishbox'   => array(
96
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
97
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
98
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
99
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
100
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+
107
+	protected function _set_page_routes()
108
+	{
109
+		//load formatter helper
110
+		//load field generator helper
111
+		//is there a evt_id in the request?
112
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
113
+			? $this->_req_data['EVT_ID'] : 0;
114
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
115
+		$this->_page_routes = array(
116
+			'default'                       => array(
117
+				'func'       => '_events_overview_list_table',
118
+				'capability' => 'ee_read_events',
119
+			),
120
+			'create_new'                    => array(
121
+				'func'       => '_create_new_cpt_item',
122
+				'capability' => 'ee_edit_events',
123
+			),
124
+			'edit'                          => array(
125
+				'func'       => '_edit_cpt_item',
126
+				'capability' => 'ee_edit_event',
127
+				'obj_id'     => $evt_id,
128
+			),
129
+			'copy_event'                    => array(
130
+				'func'       => '_copy_events',
131
+				'capability' => 'ee_edit_event',
132
+				'obj_id'     => $evt_id,
133
+				'noheader'   => true,
134
+			),
135
+			'trash_event'                   => array(
136
+				'func'       => '_trash_or_restore_event',
137
+				'args'       => array('event_status' => 'trash'),
138
+				'capability' => 'ee_delete_event',
139
+				'obj_id'     => $evt_id,
140
+				'noheader'   => true,
141
+			),
142
+			'trash_events'                  => array(
143
+				'func'       => '_trash_or_restore_events',
144
+				'args'       => array('event_status' => 'trash'),
145
+				'capability' => 'ee_delete_events',
146
+				'noheader'   => true,
147
+			),
148
+			'restore_event'                 => array(
149
+				'func'       => '_trash_or_restore_event',
150
+				'args'       => array('event_status' => 'draft'),
151
+				'capability' => 'ee_delete_event',
152
+				'obj_id'     => $evt_id,
153
+				'noheader'   => true,
154
+			),
155
+			'restore_events'                => array(
156
+				'func'       => '_trash_or_restore_events',
157
+				'args'       => array('event_status' => 'draft'),
158
+				'capability' => 'ee_delete_events',
159
+				'noheader'   => true,
160
+			),
161
+			'delete_event'                  => array(
162
+				'func'       => '_delete_event',
163
+				'capability' => 'ee_delete_event',
164
+				'obj_id'     => $evt_id,
165
+				'noheader'   => true,
166
+			),
167
+			'delete_events'                 => array(
168
+				'func'       => '_delete_events',
169
+				'capability' => 'ee_delete_events',
170
+				'noheader'   => true,
171
+			),
172
+			'view_report'                   => array(
173
+				'func'      => '_view_report',
174
+				'capablity' => 'ee_edit_events',
175
+			),
176
+			'default_event_settings'        => array(
177
+				'func'       => '_default_event_settings',
178
+				'capability' => 'manage_options',
179
+			),
180
+			'update_default_event_settings' => array(
181
+				'func'       => '_update_default_event_settings',
182
+				'capability' => 'manage_options',
183
+				'noheader'   => true,
184
+			),
185
+			'template_settings'             => array(
186
+				'func'       => '_template_settings',
187
+				'capability' => 'manage_options',
188
+			),
189
+			//event category tab related
190
+			'add_category'                  => array(
191
+				'func'       => '_category_details',
192
+				'capability' => 'ee_edit_event_category',
193
+				'args'       => array('add'),
194
+			),
195
+			'edit_category'                 => array(
196
+				'func'       => '_category_details',
197
+				'capability' => 'ee_edit_event_category',
198
+				'args'       => array('edit'),
199
+			),
200
+			'delete_categories'             => array(
201
+				'func'       => '_delete_categories',
202
+				'capability' => 'ee_delete_event_category',
203
+				'noheader'   => true,
204
+			),
205
+			'delete_category'               => array(
206
+				'func'       => '_delete_categories',
207
+				'capability' => 'ee_delete_event_category',
208
+				'noheader'   => true,
209
+			),
210
+			'insert_category'               => array(
211
+				'func'       => '_insert_or_update_category',
212
+				'args'       => array('new_category' => true),
213
+				'capability' => 'ee_edit_event_category',
214
+				'noheader'   => true,
215
+			),
216
+			'update_category'               => array(
217
+				'func'       => '_insert_or_update_category',
218
+				'args'       => array('new_category' => false),
219
+				'capability' => 'ee_edit_event_category',
220
+				'noheader'   => true,
221
+			),
222
+			'category_list'                 => array(
223
+				'func'       => '_category_list_table',
224
+				'capability' => 'ee_manage_event_categories',
225
+			),
226
+		);
227
+	}
228
+
229
+
230
+
231
+	protected function _set_page_config()
232
+	{
233
+		$this->_page_config = array(
234
+			'default'                => array(
235
+				'nav'           => array(
236
+					'label' => esc_html__('Overview', 'event_espresso'),
237
+					'order' => 10,
238
+				),
239
+				'list_table'    => 'Events_Admin_List_Table',
240
+				'help_tabs'     => array(
241
+					'events_overview_help_tab'                       => array(
242
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
243
+						'filename' => 'events_overview',
244
+					),
245
+					'events_overview_table_column_headings_help_tab' => array(
246
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
247
+						'filename' => 'events_overview_table_column_headings',
248
+					),
249
+					'events_overview_filters_help_tab'               => array(
250
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
251
+						'filename' => 'events_overview_filters',
252
+					),
253
+					'events_overview_view_help_tab'                  => array(
254
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
255
+						'filename' => 'events_overview_views',
256
+					),
257
+					'events_overview_other_help_tab'                 => array(
258
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
259
+						'filename' => 'events_overview_other',
260
+					),
261
+				),
262
+				'help_tour'     => array(
263
+					'Event_Overview_Help_Tour',
264
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
265
+				),
266
+				'qtips'         => array(
267
+					'EE_Event_List_Table_Tips',
268
+				),
269
+				'require_nonce' => false,
270
+			),
271
+			'create_new'             => array(
272
+				'nav'           => array(
273
+					'label'      => esc_html__('Add Event', 'event_espresso'),
274
+					'order'      => 5,
275
+					'persistent' => false,
276
+				),
277
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
278
+				'help_tabs'     => array(
279
+					'event_editor_help_tab'                            => array(
280
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
281
+						'filename' => 'event_editor',
282
+					),
283
+					'event_editor_title_richtexteditor_help_tab'       => array(
284
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
285
+						'filename' => 'event_editor_title_richtexteditor',
286
+					),
287
+					'event_editor_venue_details_help_tab'              => array(
288
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
289
+						'filename' => 'event_editor_venue_details',
290
+					),
291
+					'event_editor_event_datetimes_help_tab'            => array(
292
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
293
+						'filename' => 'event_editor_event_datetimes',
294
+					),
295
+					'event_editor_event_tickets_help_tab'              => array(
296
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
297
+						'filename' => 'event_editor_event_tickets',
298
+					),
299
+					'event_editor_event_registration_options_help_tab' => array(
300
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
301
+						'filename' => 'event_editor_event_registration_options',
302
+					),
303
+					'event_editor_tags_categories_help_tab'            => array(
304
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
305
+						'filename' => 'event_editor_tags_categories',
306
+					),
307
+					'event_editor_questions_registrants_help_tab'      => array(
308
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
309
+						'filename' => 'event_editor_questions_registrants',
310
+					),
311
+					'event_editor_save_new_event_help_tab'             => array(
312
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
313
+						'filename' => 'event_editor_save_new_event',
314
+					),
315
+					'event_editor_other_help_tab'                      => array(
316
+						'title'    => esc_html__('Event Other', 'event_espresso'),
317
+						'filename' => 'event_editor_other',
318
+					),
319
+				),
320
+				'help_tour'     => array(
321
+					'Event_Editor_Help_Tour',
322
+				),
323
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
324
+				'require_nonce' => false,
325
+			),
326
+			'edit'                   => array(
327
+				'nav'           => array(
328
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
329
+					'order'      => 5,
330
+					'persistent' => false,
331
+					'url'        => isset($this->_req_data['post'])
332
+						? EE_Admin_Page::add_query_args_and_nonce(
333
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
334
+							$this->_current_page_view_url
335
+						)
336
+						: $this->_admin_base_url,
337
+				),
338
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
339
+				'help_tabs'     => array(
340
+					'event_editor_help_tab'                            => array(
341
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
342
+						'filename' => 'event_editor',
343
+					),
344
+					'event_editor_title_richtexteditor_help_tab'       => array(
345
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
346
+						'filename' => 'event_editor_title_richtexteditor',
347
+					),
348
+					'event_editor_venue_details_help_tab'              => array(
349
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
350
+						'filename' => 'event_editor_venue_details',
351
+					),
352
+					'event_editor_event_datetimes_help_tab'            => array(
353
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
354
+						'filename' => 'event_editor_event_datetimes',
355
+					),
356
+					'event_editor_event_tickets_help_tab'              => array(
357
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
358
+						'filename' => 'event_editor_event_tickets',
359
+					),
360
+					'event_editor_event_registration_options_help_tab' => array(
361
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
362
+						'filename' => 'event_editor_event_registration_options',
363
+					),
364
+					'event_editor_tags_categories_help_tab'            => array(
365
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
366
+						'filename' => 'event_editor_tags_categories',
367
+					),
368
+					'event_editor_questions_registrants_help_tab'      => array(
369
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
370
+						'filename' => 'event_editor_questions_registrants',
371
+					),
372
+					'event_editor_save_new_event_help_tab'             => array(
373
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
374
+						'filename' => 'event_editor_save_new_event',
375
+					),
376
+					'event_editor_other_help_tab'                      => array(
377
+						'title'    => esc_html__('Event Other', 'event_espresso'),
378
+						'filename' => 'event_editor_other',
379
+					),
380
+				),
381
+				/*'help_tour' => array(
382 382
 					'Event_Edit_Help_Tour'
383 383
 				),*/
384
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
385
-                'require_nonce' => false,
386
-            ),
387
-            'default_event_settings' => array(
388
-                'nav'           => array(
389
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
390
-                    'order' => 40,
391
-                ),
392
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
393
-                'labels'        => array(
394
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
395
-                ),
396
-                'help_tabs'     => array(
397
-                    'default_settings_help_tab'        => array(
398
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
399
-                        'filename' => 'events_default_settings',
400
-                    ),
401
-                    'default_settings_status_help_tab' => array(
402
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
403
-                        'filename' => 'events_default_settings_status',
404
-                    ),
405
-                ),
406
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
407
-                'require_nonce' => false,
408
-            ),
409
-            //template settings
410
-            'template_settings'      => array(
411
-                'nav'           => array(
412
-                    'label' => esc_html__('Templates', 'event_espresso'),
413
-                    'order' => 30,
414
-                ),
415
-                'metaboxes'     => $this->_default_espresso_metaboxes,
416
-                'help_tabs'     => array(
417
-                    'general_settings_templates_help_tab' => array(
418
-                        'title'    => esc_html__('Templates', 'event_espresso'),
419
-                        'filename' => 'general_settings_templates',
420
-                    ),
421
-                ),
422
-                'help_tour'     => array('Templates_Help_Tour'),
423
-                'require_nonce' => false,
424
-            ),
425
-            //event category stuff
426
-            'add_category'           => array(
427
-                'nav'           => array(
428
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
429
-                    'order'      => 15,
430
-                    'persistent' => false,
431
-                ),
432
-                'help_tabs'     => array(
433
-                    'add_category_help_tab' => array(
434
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
435
-                        'filename' => 'events_add_category',
436
-                    ),
437
-                ),
438
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
439
-                'metaboxes'     => array('_publish_post_box'),
440
-                'require_nonce' => false,
441
-            ),
442
-            'edit_category'          => array(
443
-                'nav'           => array(
444
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
445
-                    'order'      => 15,
446
-                    'persistent' => false,
447
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
448
-                        ? add_query_arg(
449
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
450
-                            $this->_current_page_view_url
451
-                        )
452
-                        : $this->_admin_base_url,
453
-                ),
454
-                'help_tabs'     => array(
455
-                    'edit_category_help_tab' => array(
456
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
457
-                        'filename' => 'events_edit_category',
458
-                    ),
459
-                ),
460
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
461
-                'metaboxes'     => array('_publish_post_box'),
462
-                'require_nonce' => false,
463
-            ),
464
-            'category_list'          => array(
465
-                'nav'           => array(
466
-                    'label' => esc_html__('Categories', 'event_espresso'),
467
-                    'order' => 20,
468
-                ),
469
-                'list_table'    => 'Event_Categories_Admin_List_Table',
470
-                'help_tabs'     => array(
471
-                    'events_categories_help_tab'                       => array(
472
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
473
-                        'filename' => 'events_categories',
474
-                    ),
475
-                    'events_categories_table_column_headings_help_tab' => array(
476
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
477
-                        'filename' => 'events_categories_table_column_headings',
478
-                    ),
479
-                    'events_categories_view_help_tab'                  => array(
480
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
481
-                        'filename' => 'events_categories_views',
482
-                    ),
483
-                    'events_categories_other_help_tab'                 => array(
484
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
485
-                        'filename' => 'events_categories_other',
486
-                    ),
487
-                ),
488
-                'help_tour'     => array(
489
-                    'Event_Categories_Help_Tour',
490
-                ),
491
-                'metaboxes'     => $this->_default_espresso_metaboxes,
492
-                'require_nonce' => false,
493
-            ),
494
-        );
495
-    }
496
-
497
-
498
-
499
-    protected function _add_screen_options()
500
-    {
501
-        //todo
502
-    }
503
-
504
-
505
-
506
-    protected function _add_screen_options_default()
507
-    {
508
-        $this->_per_page_screen_option();
509
-    }
510
-
511
-
512
-
513
-    protected function _add_screen_options_category_list()
514
-    {
515
-        $page_title = $this->_admin_page_title;
516
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
517
-        $this->_per_page_screen_option();
518
-        $this->_admin_page_title = $page_title;
519
-    }
520
-
521
-
522
-
523
-    protected function _add_feature_pointers()
524
-    {
525
-        //todo
526
-    }
527
-
528
-
529
-
530
-    public function load_scripts_styles()
531
-    {
532
-        wp_register_style(
533
-            'events-admin-css',
534
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
535
-            array(),
536
-            EVENT_ESPRESSO_VERSION
537
-        );
538
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539
-        wp_enqueue_style('events-admin-css');
540
-        wp_enqueue_style('ee-cat-admin');
541
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
542
-        //registers for all views
543
-        //scripts
544
-        wp_register_script(
545
-            'event_editor_js',
546
-            EVENTS_ASSETS_URL . 'event_editor.js',
547
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
548
-            EVENT_ESPRESSO_VERSION,
549
-            true
550
-        );
551
-    }
552
-
553
-
554
-
555
-    /**
556
-     * enqueuing scripts and styles specific to this view
557
-     *
558
-     * @return void
559
-     */
560
-    public function load_scripts_styles_create_new()
561
-    {
562
-        $this->load_scripts_styles_edit();
563
-    }
564
-
565
-
566
-
567
-    /**
568
-     * enqueuing scripts and styles specific to this view
569
-     *
570
-     * @return void
571
-     */
572
-    public function load_scripts_styles_edit()
573
-    {
574
-        //styles
575
-        wp_enqueue_style('espresso-ui-theme');
576
-        wp_register_style(
577
-            'event-editor-css',
578
-            EVENTS_ASSETS_URL . 'event-editor.css',
579
-            array('ee-admin-css'),
580
-            EVENT_ESPRESSO_VERSION
581
-        );
582
-        wp_enqueue_style('event-editor-css');
583
-        //scripts
584
-        wp_register_script(
585
-            'event-datetime-metabox',
586
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
587
-            array('event_editor_js', 'ee-datepicker'),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_enqueue_script('event-datetime-metabox');
591
-    }
592
-
593
-
594
-
595
-    public function load_scripts_styles_add_category()
596
-    {
597
-        $this->load_scripts_styles_edit_category();
598
-    }
599
-
600
-
601
-
602
-    public function load_scripts_styles_edit_category()
603
-    {
604
-    }
605
-
606
-
607
-
608
-    protected function _set_list_table_views_category_list()
609
-    {
610
-        $this->_views = array(
611
-            'all' => array(
612
-                'slug'        => 'all',
613
-                'label'       => esc_html__('All', 'event_espresso'),
614
-                'count'       => 0,
615
-                'bulk_action' => array(
616
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
-                ),
618
-            ),
619
-        );
620
-    }
621
-
622
-
623
-
624
-    public function admin_init()
625
-    {
626
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
627
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
628
-            'event_espresso'
629
-        );
630
-    }
631
-
632
-
633
-
634
-    //nothing needed for events with these methods.
635
-    public function admin_notices()
636
-    {
637
-    }
638
-
639
-
640
-
641
-    public function admin_footer_scripts()
642
-    {
643
-    }
644
-
645
-
646
-
647
-    /**
648
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
649
-     * warning (via EE_Error::add_error());
650
-     *
651
-     * @param  EE_Event $event Event object
652
-     * @access public
653
-     * @return void
654
-     */
655
-    public function verify_event_edit($event = null)
656
-    {
657
-        // no event?
658
-        if (empty($event)) {
659
-            // set event
660
-            $event = $this->_cpt_model_obj;
661
-        }
662
-        // STILL no event?
663
-        if (empty ($event)) {
664
-            return;
665
-        }
666
-        $orig_status = $event->status();
667
-        // first check if event is active.
668
-        if (
669
-            $orig_status === EEM_Event::cancelled
670
-            || $orig_status === EEM_Event::postponed
671
-            || $event->is_expired()
672
-            || $event->is_inactive()
673
-        ) {
674
-            return;
675
-        }
676
-        //made it here so it IS active... next check that any of the tickets are sold.
677
-        if ($event->is_sold_out(true)) {
678
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
679
-                EE_Error::add_attention(
680
-                    sprintf(
681
-                        esc_html__(
682
-                            '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.',
683
-                            'event_espresso'
684
-                        ),
685
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
686
-                    )
687
-                );
688
-            }
689
-            return;
690
-        } else if ($orig_status === EEM_Event::sold_out) {
691
-            EE_Error::add_attention(
692
-                sprintf(
693
-                    esc_html__(
694
-                        '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.',
695
-                        'event_espresso'
696
-                    ),
697
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
698
-                )
699
-            );
700
-        }
701
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
702
-        if ( ! $event->tickets_on_sale()) {
703
-            return;
704
-        }
705
-        //made it here so show warning
706
-        $this->_edit_event_warning();
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
713
-     * When needed, hook this into a EE_Error::add_error() notice.
714
-     *
715
-     * @access protected
716
-     * @return void
717
-     */
718
-    protected function _edit_event_warning()
719
-    {
720
-        // we don't want to add warnings during these requests
721
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
722
-            return;
723
-        }
724
-        EE_Error::add_attention(
725
-            esc_html__(
726
-                '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.',
727
-                'event_espresso'
728
-            )
729
-        );
730
-    }
731
-
732
-
733
-
734
-    /**
735
-     * When a user is creating a new event, notify them if they haven't set their timezone.
736
-     * Otherwise, do the normal logic
737
-     *
738
-     * @return string
739
-     * @throws \EE_Error
740
-     */
741
-    protected function _create_new_cpt_item()
742
-    {
743
-        $gmt_offset = get_option('gmt_offset');
744
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
745
-        if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
746
-            EE_Error::add_attention(
747
-                sprintf(
748
-                    __(
749
-                        'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
750
-                        'event_espresso'
751
-                    ),
752
-                    '<a href="' . admin_url('options-general.php') . '">',
753
-                    '</a>'
754
-                ),
755
-                __FILE__,
756
-                __FUNCTION__,
757
-                __LINE__
758
-            );
759
-        }
760
-        return parent::_create_new_cpt_item();
761
-    }
762
-
763
-
764
-
765
-    protected function _set_list_table_views_default()
766
-    {
767
-        $this->_views = array(
768
-            'all'   => array(
769
-                'slug'        => 'all',
770
-                'label'       => esc_html__('View All Events', 'event_espresso'),
771
-                'count'       => 0,
772
-                'bulk_action' => array(
773
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
774
-                ),
775
-            ),
776
-            'draft' => array(
777
-                'slug'        => 'draft',
778
-                'label'       => esc_html__('Draft', 'event_espresso'),
779
-                'count'       => 0,
780
-                'bulk_action' => array(
781
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
782
-                ),
783
-            ),
784
-        );
785
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
786
-            $this->_views['trash'] = array(
787
-                'slug'        => 'trash',
788
-                'label'       => esc_html__('Trash', 'event_espresso'),
789
-                'count'       => 0,
790
-                'bulk_action' => array(
791
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
792
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
793
-                ),
794
-            );
795
-        }
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     * @return array
802
-     */
803
-    protected function _event_legend_items()
804
-    {
805
-        $items = array(
806
-            'view_details'   => array(
807
-                'class' => 'dashicons dashicons-search',
808
-                'desc'  => esc_html__('View Event', 'event_espresso'),
809
-            ),
810
-            'edit_event'     => array(
811
-                'class' => 'ee-icon ee-icon-calendar-edit',
812
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
813
-            ),
814
-            'view_attendees' => array(
815
-                'class' => 'dashicons dashicons-groups',
816
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
817
-            ),
818
-        );
819
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
820
-        $statuses = array(
821
-            'sold_out_status'  => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
823
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
824
-            ),
825
-            'active_status'    => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
827
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
828
-            ),
829
-            'upcoming_status'  => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
831
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
832
-            ),
833
-            'postponed_status' => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
835
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
836
-            ),
837
-            'cancelled_status' => array(
838
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
839
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
840
-            ),
841
-            'expired_status'   => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
843
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
844
-            ),
845
-            'inactive_status'  => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
847
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
848
-            ),
849
-        );
850
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
851
-        return array_merge($items, $statuses);
852
-    }
853
-
854
-
855
-
856
-    /**
857
-     * _event_model
858
-     *
859
-     * @return EEM_Event
860
-     */
861
-    private function _event_model()
862
-    {
863
-        if ( ! $this->_event_model instanceof EEM_Event) {
864
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
865
-        }
866
-        return $this->_event_model;
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * Adds extra buttons to the WP CPT permalink field row.
873
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
874
-     *
875
-     * @param  string $return    the current html
876
-     * @param  int    $id        the post id for the page
877
-     * @param  string $new_title What the title is
878
-     * @param  string $new_slug  what the slug is
879
-     * @return string            The new html string for the permalink area
880
-     */
881
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
882
-    {
883
-        //make sure this is only when editing
884
-        if ( ! empty($id)) {
885
-            $post = get_post($id);
886
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
887
-                       . esc_html__('Shortcode', 'event_espresso')
888
-                       . '</a> ';
889
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
890
-                       . $post->ID
891
-                       . ']">';
892
-        }
893
-        return $return;
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * _events_overview_list_table
900
-     * This contains the logic for showing the events_overview list
901
-     *
902
-     * @access protected
903
-     * @return void
904
-     */
905
-    protected function _events_overview_list_table()
906
-    {
907
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
908
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
909
-            get_post_type_archive_link('espresso_events'),
910
-            esc_html__("View Event Archive Page", "event_espresso"),
911
-            'button'
912
-        );
913
-        $this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items());
914
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
915
-                'create_new',
916
-                'add',
917
-                array(),
918
-                'add-new-h2'
919
-            );
920
-        $this->display_admin_list_table_page_with_no_sidebar();
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     * this allows for extra misc actions in the default WP publish box
927
-     *
928
-     * @return void
929
-     */
930
-    public function extra_misc_actions_publish_box()
931
-    {
932
-        $this->_generate_publish_box_extra_content();
933
-    }
934
-
935
-
936
-
937
-    /**
938
-     * @param string $post_id
939
-     * @param object $post
940
-     */
941
-    protected function _insert_update_cpt_item($post_id, $post)
942
-    {
943
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
944
-            //get out we're not processing an event save.
945
-            return;
946
-        }
947
-        $event_values = array(
948
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
949
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
950
-            'EVT_additional_limit'            => min(
951
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
952
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
953
-            ),
954
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
955
-                ? $this->_req_data['EVT_default_registration_status']
956
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
957
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
958
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
959
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
960
-                ? $this->_req_data['timezone_string'] : null,
961
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
962
-                ? $this->_req_data['externalURL'] : null,
963
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
964
-                ? $this->_req_data['event_phone'] : null,
965
-        );
966
-        //update event
967
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
968
-        //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!
969
-        $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
970
-        $event = $this->_event_model()->get_one(array($get_one_where));
971
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
972
-        $event_update_callbacks = apply_filters(
973
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
974
-            array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
975
-        );
976
-        $att_success = true;
977
-        foreach ($event_update_callbacks as $e_callback) {
978
-            $_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
979
-            $att_success = ! $att_success ? $att_success
980
-                : $_succ; //if ANY of these updates fail then we want the appropriate global error message
981
-        }
982
-        //any errors?
983
-        if ($success && false === $att_success) {
984
-            EE_Error::add_error(
985
-                esc_html__(
986
-                    'Event Details saved successfully but something went wrong with saving attachments.',
987
-                    'event_espresso'
988
-                ),
989
-                __FILE__,
990
-                __FUNCTION__,
991
-                __LINE__
992
-            );
993
-        } else if ($success === false) {
994
-            EE_Error::add_error(
995
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
996
-                __FILE__,
997
-                __FUNCTION__,
998
-                __LINE__
999
-            );
1000
-        }
1001
-    }
1002
-
1003
-
1004
-
1005
-    /**
1006
-     * @see parent::restore_item()
1007
-     * @param int $post_id
1008
-     * @param int $revision_id
1009
-     */
1010
-    protected function _restore_cpt_item($post_id, $revision_id)
1011
-    {
1012
-        //copy existing event meta to new post
1013
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1014
-        if ($post_evt instanceof EE_Event) {
1015
-            //meta revision restore
1016
-            $post_evt->restore_revision($revision_id);
1017
-            //related objs restore
1018
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1019
-        }
1020
-    }
1021
-
1022
-
1023
-
1024
-    /**
1025
-     * Attach the venue to the Event
1026
-     *
1027
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1028
-     * @param  array     $data   The request data from the form
1029
-     * @return bool           Success or fail.
1030
-     */
1031
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1032
-    {
1033
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1034
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1035
-        $rows_affected = null;
1036
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1037
-        // very important.  If we don't have a venue name...
1038
-        // then we'll get out because not necessary to create empty venue
1039
-        if (empty($data['venue_title'])) {
1040
-            return false;
1041
-        }
1042
-        $venue_array = array(
1043
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1044
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1045
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1046
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1047
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1048
-                : null,
1049
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1050
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1051
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1052
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1053
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1054
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1055
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1056
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1057
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1058
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1059
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1060
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1061
-            'status'              => 'publish',
1062
-        );
1063
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1064
-        if ( ! empty($venue_id)) {
1065
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1066
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1067
-            //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.
1068
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1069
-            return $rows_affected > 0 ? true : false;
1070
-        } else {
1071
-            //we insert the venue
1072
-            $venue_id = $venue_model->insert($venue_array);
1073
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1074
-            return ! empty($venue_id) ? true : false;
1075
-        }
1076
-        //when we have the ancestor come in it's already been handled by the revision save.
1077
-    }
1078
-
1079
-
1080
-
1081
-    /**
1082
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1083
-     *
1084
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1085
-     * @param  array    $data   The request data from the form
1086
-     * @return array
1087
-     */
1088
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1089
-    {
1090
-        $success = true;
1091
-        $saved_dtt = null;
1092
-        $saved_tickets = array();
1093
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1094
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1095
-            //trim all values to ensure any excess whitespace is removed.
1096
-            $dtt = array_map('trim', $dtt);
1097
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1098
-                : $dtt['DTT_EVT_start'];
1099
-            $datetime_values = array(
1100
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1101
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1102
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1103
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1104
-                'DTT_order'     => $row,
1105
-            );
1106
-            //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.
1107
-            if ( ! empty($dtt['DTT_ID'])) {
1108
-                $DTM = EE_Registry::instance()
1109
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1110
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1111
-                $DTM->set_date_format($incoming_date_formats[0]);
1112
-                $DTM->set_time_format($incoming_date_formats[1]);
1113
-                foreach ($datetime_values as $field => $value) {
1114
-                    $DTM->set($field, $value);
1115
-                }
1116
-                //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.
1117
-                $saved_dtts[$DTM->ID()] = $DTM;
1118
-            } else {
1119
-                $DTM = EE_Registry::instance()->load_class(
1120
-                    'Datetime',
1121
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1122
-                    false,
1123
-                    false
1124
-                );
1125
-                foreach ($datetime_values as $field => $value) {
1126
-                    $DTM->set($field, $value);
1127
-                }
1128
-            }
1129
-            $DTM->save();
1130
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1131
-            //load DTT helper
1132
-            //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.
1133
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1134
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1135
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1136
-                $DTT->save();
1137
-            }
1138
-            //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.
1139
-            $saved_dtt = $DTT;
1140
-            $success = ! $success ? $success : $DTT;
1141
-            //if ANY of these updates fail then we want the appropriate global error message.
1142
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1143
-        }
1144
-        //no dtts get deleted so we don't do any of that logic here.
1145
-        //update tickets next
1146
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1147
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1148
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1149
-            $update_prices = false;
1150
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1151
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1152
-            // trim inputs to ensure any excess whitespace is removed.
1153
-            $tkt = array_map('trim', $tkt);
1154
-            if (empty($tkt['TKT_start_date'])) {
1155
-                //let's use now in the set timezone.
1156
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1157
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1158
-            }
1159
-            if (empty($tkt['TKT_end_date'])) {
1160
-                //use the start date of the first datetime
1161
-                $dtt = $evtobj->first_datetime();
1162
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1163
-                    $incoming_date_formats[0],
1164
-                    $incoming_date_formats[1]
1165
-                );
1166
-            }
1167
-            $TKT_values = array(
1168
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1169
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1170
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1171
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1172
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1173
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1174
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1175
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1176
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1177
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1178
-                'TKT_row'         => $row,
1179
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1180
-                'TKT_price'       => $ticket_price,
1181
-            );
1182
-            //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.
1183
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1184
-                $TKT_values['TKT_ID'] = 0;
1185
-                $TKT_values['TKT_is_default'] = 0;
1186
-                $TKT_values['TKT_price'] = $ticket_price;
1187
-                $update_prices = true;
1188
-            }
1189
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1190
-            //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.
1191
-            //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.
1192
-            if ( ! empty($tkt['TKT_ID'])) {
1193
-                $TKT = EE_Registry::instance()
1194
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1195
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1196
-                if ($TKT instanceof EE_Ticket) {
1197
-                    $ticket_sold = $TKT->count_related(
1198
-                        'Registration',
1199
-                        array(
1200
-                            array(
1201
-                                'STS_ID' => array(
1202
-                                    'NOT IN',
1203
-                                    array(EEM_Registration::status_id_incomplete),
1204
-                                ),
1205
-                            ),
1206
-                        )
1207
-                    ) > 0 ? true : false;
1208
-                    //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.
1209
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1210
-                                      && ! $TKT->get(
1211
-                        'TKT_deleted'
1212
-                    ) ? true : false;
1213
-                    $TKT->set_date_format($incoming_date_formats[0]);
1214
-                    $TKT->set_time_format($incoming_date_formats[1]);
1215
-                    //set new values
1216
-                    foreach ($TKT_values as $field => $value) {
1217
-                        if ($field == 'TKT_qty') {
1218
-                            $TKT->set_qty($value);
1219
-                        } else {
1220
-                            $TKT->set($field, $value);
1221
-                        }
1222
-                    }
1223
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1224
-                    if ($create_new_TKT) {
1225
-                        //archive the old ticket first
1226
-                        $TKT->set('TKT_deleted', 1);
1227
-                        $TKT->save();
1228
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1229
-                        $saved_tickets[$TKT->ID()] = $TKT;
1230
-                        //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.
1231
-                        $TKT = clone $TKT;
1232
-                        $TKT->set('TKT_ID', 0);
1233
-                        $TKT->set('TKT_deleted', 0);
1234
-                        $TKT->set('TKT_price', $ticket_price);
1235
-                        $TKT->set('TKT_sold', 0);
1236
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1237
-                        $update_prices = true;
1238
-                    }
1239
-                    //make sure price is set if it hasn't been already
1240
-                    $TKT->set('TKT_price', $ticket_price);
1241
-                }
1242
-            } else {
1243
-                //no TKT_id so a new TKT
1244
-                $TKT_values['TKT_price'] = $ticket_price;
1245
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1246
-                if ($TKT instanceof EE_Ticket) {
1247
-                    //need to reset values to properly account for the date formats
1248
-                    $TKT->set_date_format($incoming_date_formats[0]);
1249
-                    $TKT->set_time_format($incoming_date_formats[1]);
1250
-                    $TKT->set_timezone($evtobj->get_timezone());
1251
-                    //set new values
1252
-                    foreach ($TKT_values as $field => $value) {
1253
-                        if ($field == 'TKT_qty') {
1254
-                            $TKT->set_qty($value);
1255
-                        } else {
1256
-                            $TKT->set($field, $value);
1257
-                        }
1258
-                    }
1259
-                    $update_prices = true;
1260
-                }
1261
-            }
1262
-            // cap ticket qty by datetime reg limits
1263
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1264
-            //update ticket.
1265
-            $TKT->save();
1266
-            //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.
1267
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1268
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1269
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1270
-                $TKT->save();
1271
-            }
1272
-            //initially let's add the ticket to the dtt
1273
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1274
-            $saved_tickets[$TKT->ID()] = $TKT;
1275
-            //add prices to ticket
1276
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1277
-        }
1278
-        //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.
1279
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1280
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1281
-        foreach ($tickets_removed as $id) {
1282
-            $id = absint($id);
1283
-            //get the ticket for this id
1284
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1285
-            //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)
1286
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1287
-            foreach ($dtts as $dtt) {
1288
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1289
-            }
1290
-            //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))
1291
-            $tkt_to_remove->delete_related_permanently('Price');
1292
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1293
-            $tkt_to_remove->delete_permanently();
1294
-        }
1295
-        return array($saved_dtt, $saved_tickets);
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * This attaches a list of given prices to a ticket.
1302
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1303
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1304
-     * price info and prices are automatically "archived" via the ticket.
1305
-     *
1306
-     * @access  private
1307
-     * @param array     $prices     Array of prices from the form.
1308
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1309
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1310
-     * @return  void
1311
-     */
1312
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1313
-    {
1314
-        foreach ($prices as $row => $prc) {
1315
-            $PRC_values = array(
1316
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1317
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1318
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1319
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1320
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1321
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1322
-                'PRC_order'      => $row,
1323
-            );
1324
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1325
-                $PRC_values['PRC_ID'] = 0;
1326
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1327
-            } else {
1328
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1329
-                //update this price with new values
1330
-                foreach ($PRC_values as $field => $newprc) {
1331
-                    $PRC->set($field, $newprc);
1332
-                }
1333
-                $PRC->save();
1334
-            }
1335
-            $ticket->_add_relation_to($PRC, 'Price');
1336
-        }
1337
-    }
1338
-
1339
-
1340
-
1341
-    /**
1342
-     * Add in our autosave ajax handlers
1343
-     *
1344
-     * @return void
1345
-     */
1346
-    protected function _ee_autosave_create_new()
1347
-    {
1348
-        // $this->_ee_autosave_edit();
1349
-    }
1350
-
1351
-
1352
-
1353
-    protected function _ee_autosave_edit()
1354
-    {
1355
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1356
-    }
1357
-
1358
-
1359
-
1360
-    /**
1361
-     *    _generate_publish_box_extra_content
1362
-     *
1363
-     * @access private
1364
-     * @return void
1365
-     */
1366
-    private function _generate_publish_box_extra_content()
1367
-    {
1368
-        //load formatter helper
1369
-        //args for getting related registrations
1370
-        $approved_query_args = array(
1371
-            array(
1372
-                'REG_deleted' => 0,
1373
-                'STS_ID'      => EEM_Registration::status_id_approved,
1374
-            ),
1375
-        );
1376
-        $not_approved_query_args = array(
1377
-            array(
1378
-                'REG_deleted' => 0,
1379
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1380
-            ),
1381
-        );
1382
-        $pending_payment_query_args = array(
1383
-            array(
1384
-                'REG_deleted' => 0,
1385
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1386
-            ),
1387
-        );
1388
-        // publish box
1389
-        $publish_box_extra_args = array(
1390
-            'view_approved_reg_url'        => add_query_arg(
1391
-                array(
1392
-                    'action'      => 'default',
1393
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1394
-                    '_reg_status' => EEM_Registration::status_id_approved,
1395
-                ),
1396
-                REG_ADMIN_URL
1397
-            ),
1398
-            'view_not_approved_reg_url'    => add_query_arg(
1399
-                array(
1400
-                    'action'      => 'default',
1401
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1402
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1403
-                ),
1404
-                REG_ADMIN_URL
1405
-            ),
1406
-            'view_pending_payment_reg_url' => add_query_arg(
1407
-                array(
1408
-                    'action'      => 'default',
1409
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1410
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1411
-                ),
1412
-                REG_ADMIN_URL
1413
-            ),
1414
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1415
-                'Registration',
1416
-                $approved_query_args
1417
-            ),
1418
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1419
-                'Registration',
1420
-                $not_approved_query_args
1421
-            ),
1422
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1423
-                'Registration',
1424
-                $pending_payment_query_args
1425
-            ),
1426
-            'misc_pub_section_class'       => apply_filters(
1427
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1428
-                'misc-pub-section'
1429
-            ),
1430
-            //'email_attendees_url' => add_query_arg(
1431
-            //	array(
1432
-            //		'event_admin_reports' => 'event_newsletter',
1433
-            //		'event_id' => $this->_cpt_model_obj->id
1434
-            //	),
1435
-            //	'admin.php?page=espresso_registrations'
1436
-            //),
1437
-        );
1438
-        ob_start();
1439
-        do_action(
1440
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1441
-            $this->_cpt_model_obj
1442
-        );
1443
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1444
-        // load template
1445
-        EEH_Template::display_template(
1446
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1447
-            $publish_box_extra_args
1448
-        );
1449
-    }
1450
-
1451
-
1452
-
1453
-    /**
1454
-     * This just returns whatever is set as the _event object property
1455
-     * //todo this will become obsolete once the models are in place
1456
-     *
1457
-     * @return object
1458
-     */
1459
-    public function get_event_object()
1460
-    {
1461
-        return $this->_cpt_model_obj;
1462
-    }
1463
-
1464
-
1465
-
1466
-
1467
-    /** METABOXES * */
1468
-    /**
1469
-     * _register_event_editor_meta_boxes
1470
-     * add all metaboxes related to the event_editor
1471
-     *
1472
-     * @return void
1473
-     */
1474
-    protected function _register_event_editor_meta_boxes()
1475
-    {
1476
-        $this->verify_cpt_object();
1477
-        add_meta_box(
1478
-            'espresso_event_editor_tickets',
1479
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1480
-            array($this, 'ticket_metabox'),
1481
-            $this->page_slug,
1482
-            'normal',
1483
-            'high'
1484
-        );
1485
-        add_meta_box(
1486
-            'espresso_event_editor_event_options',
1487
-            esc_html__('Event Registration Options', 'event_espresso'),
1488
-            array($this, 'registration_options_meta_box'),
1489
-            $this->page_slug,
1490
-            'side',
1491
-            'default'
1492
-        );
1493
-        // NOTE: if you're looking for other metaboxes in here,
1494
-        // where a metabox has a related management page in the admin
1495
-        // you will find it setup in the related management page's "_Hooks" file.
1496
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1497
-    }
1498
-
1499
-
1500
-
1501
-    public function ticket_metabox()
1502
-    {
1503
-        $existing_datetime_ids = $existing_ticket_ids = array();
1504
-        //defaults for template args
1505
-        $template_args = array(
1506
-            'existing_datetime_ids'    => '',
1507
-            'event_datetime_help_link' => '',
1508
-            'ticket_options_help_link' => '',
1509
-            'time'                     => null,
1510
-            'ticket_rows'              => '',
1511
-            'existing_ticket_ids'      => '',
1512
-            'total_ticket_rows'        => 1,
1513
-            'ticket_js_structure'      => '',
1514
-            'trash_icon'               => 'ee-lock-icon',
1515
-            'disabled'                 => '',
1516
-        );
1517
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1518
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1519
-        /**
1520
-         * 1. Start with retrieving Datetimes
1521
-         * 2. Fore each datetime get related tickets
1522
-         * 3. For each ticket get related prices
1523
-         */
1524
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1525
-        /** @type EE_Datetime $first_datetime */
1526
-        $first_datetime = reset($times);
1527
-        //do we get related tickets?
1528
-        if ($first_datetime instanceof EE_Datetime
1529
-            && $first_datetime->ID() !== 0
1530
-        ) {
1531
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1532
-            $template_args['time'] = $first_datetime;
1533
-            $related_tickets = $first_datetime->tickets(
1534
-                array(
1535
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1536
-                    'default_where_conditions' => 'none',
1537
-                )
1538
-            );
1539
-            if ( ! empty($related_tickets)) {
1540
-                $template_args['total_ticket_rows'] = count($related_tickets);
1541
-                $row = 0;
1542
-                foreach ($related_tickets as $ticket) {
1543
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1544
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1545
-                    $row++;
1546
-                }
1547
-            } else {
1548
-                $template_args['total_ticket_rows'] = 1;
1549
-                /** @type EE_Ticket $ticket */
1550
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1551
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1552
-            }
1553
-        } else {
1554
-            $template_args['time'] = $times[0];
1555
-            /** @type EE_Ticket $ticket */
1556
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1557
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1558
-            // NOTE: we're just sending the first default row
1559
-            // (decaf can't manage default tickets so this should be sufficient);
1560
-        }
1561
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1562
-            'event_editor_event_datetimes_help_tab'
1563
-        );
1564
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1565
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1566
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1567
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1568
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1569
-            true
1570
-        );
1571
-        $template = apply_filters(
1572
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1573
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1574
-        );
1575
-        EEH_Template::display_template($template, $template_args);
1576
-    }
1577
-
1578
-
1579
-
1580
-    /**
1581
-     * Setup an individual ticket form for the decaf event editor page
1582
-     *
1583
-     * @access private
1584
-     * @param  EE_Ticket $ticket   the ticket object
1585
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1586
-     * @param int        $row
1587
-     * @return string generated html for the ticket row.
1588
-     */
1589
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1590
-    {
1591
-        $template_args = array(
1592
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1593
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1594
-                : '',
1595
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1596
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1597
-            'TKT_name'            => $ticket->get('TKT_name'),
1598
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1599
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1600
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1601
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1602
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1603
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1604
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1605
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1606
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1607
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1608
-                : ' disabled=disabled',
1609
-        );
1610
-        $price = $ticket->ID() !== 0
1611
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1612
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1613
-        $price_args = array(
1614
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1615
-            'PRC_amount'            => $price->get('PRC_amount'),
1616
-            'PRT_ID'                => $price->get('PRT_ID'),
1617
-            'PRC_ID'                => $price->get('PRC_ID'),
1618
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1619
-        );
1620
-        //make sure we have default start and end dates if skeleton
1621
-        //handle rows that should NOT be empty
1622
-        if (empty($template_args['TKT_start_date'])) {
1623
-            //if empty then the start date will be now.
1624
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1625
-        }
1626
-        if (empty($template_args['TKT_end_date'])) {
1627
-            //get the earliest datetime (if present);
1628
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1629
-                ? $this->_cpt_model_obj->get_first_related(
1630
-                    'Datetime',
1631
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1632
-                )
1633
-                : null;
1634
-            if ( ! empty($earliest_dtt)) {
1635
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1636
-            } else {
1637
-                $template_args['TKT_end_date'] = date(
1638
-                    'Y-m-d h:i a',
1639
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1640
-                );
1641
-            }
1642
-        }
1643
-        $template_args = array_merge($template_args, $price_args);
1644
-        $template = apply_filters(
1645
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1646
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1647
-            $ticket
1648
-        );
1649
-        return EEH_Template::display_template($template, $template_args, true);
1650
-    }
1651
-
1652
-
1653
-
1654
-    public function registration_options_meta_box()
1655
-    {
1656
-        $yes_no_values = array(
1657
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1658
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1659
-        );
1660
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1661
-            array(
1662
-                EEM_Registration::status_id_cancelled,
1663
-                EEM_Registration::status_id_declined,
1664
-                EEM_Registration::status_id_incomplete,
1665
-            ),
1666
-            true
1667
-        );
1668
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1669
-        $template_args['_event'] = $this->_cpt_model_obj;
1670
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1671
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1672
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1673
-            'default_reg_status',
1674
-            $default_reg_status_values,
1675
-            $this->_cpt_model_obj->default_registration_status()
1676
-        );
1677
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1678
-            'display_desc',
1679
-            $yes_no_values,
1680
-            $this->_cpt_model_obj->display_description()
1681
-        );
1682
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1683
-            'display_ticket_selector',
1684
-            $yes_no_values,
1685
-            $this->_cpt_model_obj->display_ticket_selector(),
1686
-            '',
1687
-            '',
1688
-            false
1689
-        );
1690
-        $template_args['additional_registration_options'] = apply_filters(
1691
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1692
-            '',
1693
-            $template_args,
1694
-            $yes_no_values,
1695
-            $default_reg_status_values
1696
-        );
1697
-        EEH_Template::display_template(
1698
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1699
-            $template_args
1700
-        );
1701
-    }
1702
-
1703
-
1704
-
1705
-    /**
1706
-     * _get_events()
1707
-     * This method simply returns all the events (for the given _view and paging)
1708
-     *
1709
-     * @access public
1710
-     * @param int  $per_page     count of items per page (20 default);
1711
-     * @param int  $current_page what is the current page being viewed.
1712
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1713
-     *                           If FALSE then we return an array of event objects
1714
-     *                           that match the given _view and paging parameters.
1715
-     * @return array an array of event objects.
1716
-     */
1717
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1718
-    {
1719
-        $EEME = $this->_event_model();
1720
-        $offset = ($current_page - 1) * $per_page;
1721
-        $limit = $count ? null : $offset . ',' . $per_page;
1722
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1723
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1724
-        if (isset($this->_req_data['month_range'])) {
1725
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1726
-            $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1727
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1728
-        }
1729
-        $where = array();
1730
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1731
-        //determine what post_status our condition will have for the query.
1732
-        switch ($status) {
1733
-            case 'month' :
1734
-            case 'today' :
1735
-            case null :
1736
-            case 'all' :
1737
-                break;
1738
-            case 'draft' :
1739
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1740
-                break;
1741
-            default :
1742
-                $where['status'] = $status;
1743
-        }
1744
-        //categories?
1745
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1746
-            ? $this->_req_data['EVT_CAT'] : null;
1747
-        if ( ! empty ($category)) {
1748
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1749
-            $where['Term_Taxonomy.term_id'] = $category;
1750
-        }
1751
-        //date where conditions
1752
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1753
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1754
-            $DateTime = new DateTime(
1755
-                $year_r . '-' . $month_r . '-01 00:00:00',
1756
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1757
-            );
1758
-            $start = $DateTime->format(implode(' ', $start_formats));
1759
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1760
-                ->format('t'))->setTime(23, 59, 59)
1761
-                            ->format(implode(' ', $start_formats));
1762
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1763
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1764
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1765
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1766
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1767
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1768
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1769
-            $now = date('Y-m-01');
1770
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1771
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1772
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1773
-                            ->setTime(23, 59, 59)
1774
-                            ->format(implode(' ', $start_formats));
1775
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1776
-        }
1777
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1778
-            $where['EVT_wp_user'] = get_current_user_id();
1779
-        } else {
1780
-            if ( ! isset($where['status'])) {
1781
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1782
-                    $where['OR'] = array(
1783
-                        'status*restrict_private' => array('!=', 'private'),
1784
-                        'AND'                     => array(
1785
-                            'status*inclusive' => array('=', 'private'),
1786
-                            'EVT_wp_user'      => get_current_user_id(),
1787
-                        ),
1788
-                    );
1789
-                }
1790
-            }
1791
-        }
1792
-        if (isset($this->_req_data['EVT_wp_user'])) {
1793
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1794
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1795
-            ) {
1796
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1797
-            }
1798
-        }
1799
-        //search query handling
1800
-        if (isset($this->_req_data['s'])) {
1801
-            $search_string = '%' . $this->_req_data['s'] . '%';
1802
-            $where['OR'] = array(
1803
-                'EVT_name'       => array('LIKE', $search_string),
1804
-                'EVT_desc'       => array('LIKE', $search_string),
1805
-                'EVT_short_desc' => array('LIKE', $search_string),
1806
-            );
1807
-        }
1808
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1809
-        $query_params = apply_filters(
1810
-            'FHEE__Events_Admin_Page__get_events__query_params',
1811
-            array(
1812
-                $where,
1813
-                'limit'    => $limit,
1814
-                'order_by' => $orderby,
1815
-                'order'    => $order,
1816
-                'group_by' => 'EVT_ID',
1817
-            ),
1818
-            $this->_req_data
1819
-        );
1820
-        //let's first check if we have special requests coming in.
1821
-        if (isset($this->_req_data['active_status'])) {
1822
-            switch ($this->_req_data['active_status']) {
1823
-                case 'upcoming' :
1824
-                    return $EEME->get_upcoming_events($query_params, $count);
1825
-                    break;
1826
-                case 'expired' :
1827
-                    return $EEME->get_expired_events($query_params, $count);
1828
-                    break;
1829
-                case 'active' :
1830
-                    return $EEME->get_active_events($query_params, $count);
1831
-                    break;
1832
-                case 'inactive' :
1833
-                    return $EEME->get_inactive_events($query_params, $count);
1834
-                    break;
1835
-            }
1836
-        }
1837
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1838
-        return $events;
1839
-    }
1840
-
1841
-
1842
-
1843
-    /**
1844
-     * handling for WordPress CPT actions (trash, restore, delete)
1845
-     *
1846
-     * @param string $post_id
1847
-     */
1848
-    public function trash_cpt_item($post_id)
1849
-    {
1850
-        $this->_req_data['EVT_ID'] = $post_id;
1851
-        $this->_trash_or_restore_event('trash', false);
1852
-    }
1853
-
1854
-
1855
-
1856
-    /**
1857
-     * @param string $post_id
1858
-     */
1859
-    public function restore_cpt_item($post_id)
1860
-    {
1861
-        $this->_req_data['EVT_ID'] = $post_id;
1862
-        $this->_trash_or_restore_event('draft', false);
1863
-    }
1864
-
1865
-
1866
-
1867
-    /**
1868
-     * @param string $post_id
1869
-     */
1870
-    public function delete_cpt_item($post_id)
1871
-    {
1872
-        $this->_req_data['EVT_ID'] = $post_id;
1873
-        $this->_delete_event(false);
1874
-    }
1875
-
1876
-
1877
-
1878
-    /**
1879
-     * _trash_or_restore_event
1880
-     *
1881
-     * @access protected
1882
-     * @param  string $event_status
1883
-     * @param bool    $redirect_after
1884
-     */
1885
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1886
-    {
1887
-        //determine the event id and set to array.
1888
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1889
-        // loop thru events
1890
-        if ($EVT_ID) {
1891
-            // clean status
1892
-            $event_status = sanitize_key($event_status);
1893
-            // grab status
1894
-            if ( ! empty($event_status)) {
1895
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1896
-            } else {
1897
-                $success = false;
1898
-                $msg = esc_html__(
1899
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1900
-                    'event_espresso'
1901
-                );
1902
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1903
-            }
1904
-        } else {
1905
-            $success = false;
1906
-            $msg = esc_html__(
1907
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1908
-                'event_espresso'
1909
-            );
1910
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1911
-        }
1912
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1913
-        if ($redirect_after) {
1914
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1915
-        }
1916
-    }
1917
-
1918
-
1919
-
1920
-    /**
1921
-     * _trash_or_restore_events
1922
-     *
1923
-     * @access protected
1924
-     * @param  string $event_status
1925
-     * @return void
1926
-     */
1927
-    protected function _trash_or_restore_events($event_status = 'trash')
1928
-    {
1929
-        // clean status
1930
-        $event_status = sanitize_key($event_status);
1931
-        // grab status
1932
-        if ( ! empty($event_status)) {
1933
-            $success = true;
1934
-            //determine the event id and set to array.
1935
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1936
-            // loop thru events
1937
-            foreach ($EVT_IDs as $EVT_ID) {
1938
-                if ($EVT_ID = absint($EVT_ID)) {
1939
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1940
-                    $success = $results !== false ? $success : false;
1941
-                } else {
1942
-                    $msg = sprintf(
1943
-                        esc_html__(
1944
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1945
-                            'event_espresso'
1946
-                        ),
1947
-                        $EVT_ID
1948
-                    );
1949
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1950
-                    $success = false;
1951
-                }
1952
-            }
1953
-        } else {
1954
-            $success = false;
1955
-            $msg = esc_html__(
1956
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1957
-                'event_espresso'
1958
-            );
1959
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1960
-        }
1961
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1962
-        $success = $success ? 2 : false;
1963
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1964
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1965
-    }
1966
-
1967
-
1968
-
1969
-    /**
1970
-     * _trash_or_restore_events
1971
-     *
1972
-     * @access  private
1973
-     * @param  int    $EVT_ID
1974
-     * @param  string $event_status
1975
-     * @return bool
1976
-     */
1977
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
1978
-    {
1979
-        // grab event id
1980
-        if ( ! $EVT_ID) {
1981
-            $msg = esc_html__(
1982
-                'An error occurred. No Event ID or an invalid Event ID was received.',
1983
-                'event_espresso'
1984
-            );
1985
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1986
-            return false;
1987
-        }
1988
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1989
-        // clean status
1990
-        $event_status = sanitize_key($event_status);
1991
-        // grab status
1992
-        if (empty($event_status)) {
1993
-            $msg = esc_html__(
1994
-                'An error occurred. No Event Status or an invalid Event Status was received.',
1995
-                'event_espresso'
1996
-            );
1997
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1998
-            return false;
1999
-        }
2000
-        // was event trashed or restored ?
2001
-        switch ($event_status) {
2002
-            case 'draft' :
2003
-                $action = 'restored from the trash';
2004
-                $hook = 'AHEE_event_restored_from_trash';
2005
-                break;
2006
-            case 'trash' :
2007
-                $action = 'moved to the trash';
2008
-                $hook = 'AHEE_event_moved_to_trash';
2009
-                break;
2010
-            default :
2011
-                $action = 'updated';
2012
-                $hook = false;
2013
-        }
2014
-        //use class to change status
2015
-        $this->_cpt_model_obj->set_status($event_status);
2016
-        $success = $this->_cpt_model_obj->save();
2017
-        if ($success === false) {
2018
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2019
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2020
-            return false;
2021
-        }
2022
-        if ($hook) {
2023
-            do_action($hook);
2024
-        }
2025
-        return true;
2026
-    }
2027
-
2028
-
2029
-
2030
-    /**
2031
-     * _delete_event
2032
-     *
2033
-     * @access protected
2034
-     * @param bool $redirect_after
2035
-     */
2036
-    protected function _delete_event($redirect_after = true)
2037
-    {
2038
-        //determine the event id and set to array.
2039
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2040
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2041
-        // loop thru events
2042
-        if ($EVT_ID) {
2043
-            $success = $this->_permanently_delete_event($EVT_ID);
2044
-            // get list of events with no prices
2045
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2046
-            // remove this event from the list of events with no prices
2047
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2048
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2049
-            }
2050
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2051
-        } else {
2052
-            $success = false;
2053
-            $msg = esc_html__(
2054
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2055
-                'event_espresso'
2056
-            );
2057
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2058
-        }
2059
-        if ($redirect_after) {
2060
-            $this->_redirect_after_action(
2061
-                $success,
2062
-                'Event',
2063
-                'deleted',
2064
-                array('action' => 'default', 'status' => 'trash')
2065
-            );
2066
-        }
2067
-    }
2068
-
2069
-
2070
-
2071
-    /**
2072
-     * _delete_events
2073
-     *
2074
-     * @access protected
2075
-     * @return void
2076
-     */
2077
-    protected function _delete_events()
2078
-    {
2079
-        $success = true;
2080
-        // get list of events with no prices
2081
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2082
-        //determine the event id and set to array.
2083
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2084
-        // loop thru events
2085
-        foreach ($EVT_IDs as $EVT_ID) {
2086
-            $EVT_ID = absint($EVT_ID);
2087
-            if ($EVT_ID) {
2088
-                $results = $this->_permanently_delete_event($EVT_ID);
2089
-                $success = $results !== false ? $success : false;
2090
-                // remove this event from the list of events with no prices
2091
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2092
-            } else {
2093
-                $success = false;
2094
-                $msg = esc_html__(
2095
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2096
-                    'event_espresso'
2097
-                );
2098
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2099
-            }
2100
-        }
2101
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2102
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2103
-        $success = $success ? 2 : false;
2104
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2105
-    }
2106
-
2107
-
2108
-
2109
-    /**
2110
-     * _permanently_delete_event
2111
-     *
2112
-     * @access  private
2113
-     * @param  int $EVT_ID
2114
-     * @return bool
2115
-     */
2116
-    private function _permanently_delete_event($EVT_ID = 0)
2117
-    {
2118
-        // grab event id
2119
-        if ( ! $EVT_ID) {
2120
-            $msg = esc_html__(
2121
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2122
-                'event_espresso'
2123
-            );
2124
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2125
-            return false;
2126
-        }
2127
-        if (
2128
-            ! $this->_cpt_model_obj instanceof EE_Event
2129
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2130
-        ) {
2131
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2132
-        }
2133
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2134
-            return false;
2135
-        }
2136
-        //need to delete related tickets and prices first.
2137
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2138
-        foreach ($datetimes as $datetime) {
2139
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2140
-            $tickets = $datetime->get_many_related('Ticket');
2141
-            foreach ($tickets as $ticket) {
2142
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2143
-                $ticket->delete_related_permanently('Price');
2144
-                $ticket->delete_permanently();
2145
-            }
2146
-            $datetime->delete();
2147
-        }
2148
-        //what about related venues or terms?
2149
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2150
-        foreach ($venues as $venue) {
2151
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2152
-        }
2153
-        //any attached question groups?
2154
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2155
-        if ( ! empty($question_groups)) {
2156
-            foreach ($question_groups as $question_group) {
2157
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2158
-            }
2159
-        }
2160
-        //Message Template Groups
2161
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2162
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2163
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2164
-        foreach ($term_taxonomies as $term_taxonomy) {
2165
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2166
-        }
2167
-        $success = $this->_cpt_model_obj->delete_permanently();
2168
-        // did it all go as planned ?
2169
-        if ($success) {
2170
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2171
-            EE_Error::add_success($msg);
2172
-        } else {
2173
-            $msg = sprintf(
2174
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2175
-                $EVT_ID
2176
-            );
2177
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2178
-            return false;
2179
-        }
2180
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2181
-        return true;
2182
-    }
2183
-
2184
-
2185
-
2186
-    /**
2187
-     * get total number of events
2188
-     *
2189
-     * @access public
2190
-     * @return int
2191
-     */
2192
-    public function total_events()
2193
-    {
2194
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2195
-        return $count;
2196
-    }
2197
-
2198
-
2199
-
2200
-    /**
2201
-     * get total number of draft events
2202
-     *
2203
-     * @access public
2204
-     * @return int
2205
-     */
2206
-    public function total_events_draft()
2207
-    {
2208
-        $where = array(
2209
-            'status' => array('IN', array('draft', 'auto-draft')),
2210
-        );
2211
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2212
-        return $count;
2213
-    }
2214
-
2215
-
2216
-
2217
-    /**
2218
-     * get total number of trashed events
2219
-     *
2220
-     * @access public
2221
-     * @return int
2222
-     */
2223
-    public function total_trashed_events()
2224
-    {
2225
-        $where = array(
2226
-            'status' => 'trash',
2227
-        );
2228
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2229
-        return $count;
2230
-    }
2231
-
2232
-
2233
-
2234
-    /**
2235
-     *    _default_event_settings
2236
-     *    This generates the Default Settings Tab
2237
-     *
2238
-     * @return void
2239
-     */
2240
-    protected function _default_event_settings()
2241
-    {
2242
-        $this->_template_args['values'] = $this->_yes_no_values;
2243
-        $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2244
-        // exclude array
2245
-            array(
2246
-                EEM_Registration::status_id_cancelled,
2247
-                EEM_Registration::status_id_declined,
2248
-                EEM_Registration::status_id_incomplete,
2249
-                EEM_Registration::status_id_wait_list,
2250
-            ),
2251
-            // translated
2252
-            true
2253
-        );
2254
-        $this->_template_args['default_reg_status'] = isset(
2255
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID
2256
-                                                      )
2257
-                                                      && in_array(
2258
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID,
2259
-                                                          $this->_template_args['reg_status_array']
2260
-                                                      )
2261
-            ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2262
-            : EEM_Registration::status_id_pending_payment;
2263
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2264
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2265
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2266
-            EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2267
-            $this->_template_args,
2268
-            true
2269
-        );
2270
-        $this->display_admin_page_with_sidebar();
2271
-    }
2272
-
2273
-
2274
-
2275
-    /**
2276
-     * _update_default_event_settings
2277
-     *
2278
-     * @access protected
2279
-     * @return void
2280
-     */
2281
-    protected function _update_default_event_settings()
2282
-    {
2283
-        EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2284
-            ? sanitize_text_field($this->_req_data['default_reg_status'])
2285
-            : EEM_Registration::status_id_pending_payment;
2286
-        $what = 'Default Event Settings';
2287
-        $success = $this->_update_espresso_configuration(
2288
-            $what,
2289
-            EE_Config::instance(),
2290
-            __FILE__,
2291
-            __FUNCTION__,
2292
-            __LINE__
2293
-        );
2294
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2295
-    }
2296
-
2297
-
2298
-
2299
-    /*************        Templates        *************/
2300
-    protected function _template_settings()
2301
-    {
2302
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2303
-        $this->_template_args['preview_img'] = '<img src="'
2304
-                                               . EVENTS_ASSETS_URL
2305
-                                               . DS
2306
-                                               . 'images'
2307
-                                               . DS
2308
-                                               . 'caffeinated_template_features.jpg" alt="'
2309
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2310
-                                               . '" />';
2311
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2312
-                'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2313
-                'event_espresso'
2314
-            ) . '</strong>';
2315
-        $this->display_admin_caf_preview_page('template_settings_tab');
2316
-    }
2317
-
2318
-
2319
-    /** Event Category Stuff **/
2320
-    /**
2321
-     * set the _category property with the category object for the loaded page.
2322
-     *
2323
-     * @access private
2324
-     * @return void
2325
-     */
2326
-    private function _set_category_object()
2327
-    {
2328
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2329
-            return;
2330
-        } //already have the category object so get out.
2331
-        //set default category object
2332
-        $this->_set_empty_category_object();
2333
-        //only set if we've got an id
2334
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2335
-            return;
2336
-        }
2337
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2338
-        $term = get_term($category_id, 'espresso_event_categories');
2339
-        if ( ! empty($term)) {
2340
-            $this->_category->category_name = $term->name;
2341
-            $this->_category->category_identifier = $term->slug;
2342
-            $this->_category->category_desc = $term->description;
2343
-            $this->_category->id = $term->term_id;
2344
-            $this->_category->parent = $term->parent;
2345
-        }
2346
-    }
2347
-
2348
-
2349
-
2350
-    private function _set_empty_category_object()
2351
-    {
2352
-        $this->_category = new stdClass();
2353
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2354
-        $this->_category->id = $this->_category->parent = 0;
2355
-    }
2356
-
2357
-
2358
-
2359
-    protected function _category_list_table()
2360
-    {
2361
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2362
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2363
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2364
-                'add_category',
2365
-                'add_category',
2366
-                array(),
2367
-                'add-new-h2'
2368
-            );
2369
-        $this->display_admin_list_table_page_with_sidebar();
2370
-    }
2371
-
2372
-
2373
-
2374
-    /**
2375
-     * @param $view
2376
-     */
2377
-    protected function _category_details($view)
2378
-    {
2379
-        //load formatter helper
2380
-        //load field generator helper
2381
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2382
-        $this->_set_add_edit_form_tags($route);
2383
-        $this->_set_category_object();
2384
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2385
-        $delete_action = 'delete_category';
2386
-        //custom redirect
2387
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2388
-            array('action' => 'category_list'),
2389
-            $this->_admin_base_url
2390
-        );
2391
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2392
-        //take care of contents
2393
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2394
-        $this->display_admin_page_with_sidebar();
2395
-    }
2396
-
2397
-
2398
-
2399
-    /**
2400
-     * @return mixed
2401
-     */
2402
-    protected function _category_details_content()
2403
-    {
2404
-        $editor_args['category_desc'] = array(
2405
-            'type'          => 'wp_editor',
2406
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2407
-            'class'         => 'my_editor_custom',
2408
-            'wpeditor_args' => array('media_buttons' => false),
2409
-        );
2410
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2411
-        $all_terms = get_terms(
2412
-            array('espresso_event_categories'),
2413
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2414
-        );
2415
-        //setup category select for term parents.
2416
-        $category_select_values[] = array(
2417
-            'text' => esc_html__('No Parent', 'event_espresso'),
2418
-            'id'   => 0,
2419
-        );
2420
-        foreach ($all_terms as $term) {
2421
-            $category_select_values[] = array(
2422
-                'text' => $term->name,
2423
-                'id'   => $term->term_id,
2424
-            );
2425
-        }
2426
-        $category_select = EEH_Form_Fields::select_input(
2427
-            'category_parent',
2428
-            $category_select_values,
2429
-            $this->_category->parent
2430
-        );
2431
-        $template_args = array(
2432
-            'category'                 => $this->_category,
2433
-            'category_select'          => $category_select,
2434
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2435
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2436
-            'disable'                  => '',
2437
-            'disabled_message'         => false,
2438
-        );
2439
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2440
-        return EEH_Template::display_template($template, $template_args, true);
2441
-    }
2442
-
2443
-
2444
-
2445
-    protected function _delete_categories()
2446
-    {
2447
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2448
-            : (array)$this->_req_data['category_id'];
2449
-        foreach ($cat_ids as $cat_id) {
2450
-            $this->_delete_category($cat_id);
2451
-        }
2452
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2453
-        $query_args = array(
2454
-            'action' => 'category_list',
2455
-        );
2456
-        $this->_redirect_after_action(0, '', '', $query_args);
2457
-    }
2458
-
2459
-
2460
-
2461
-    /**
2462
-     * @param $cat_id
2463
-     */
2464
-    protected function _delete_category($cat_id)
2465
-    {
2466
-        $cat_id = absint($cat_id);
2467
-        wp_delete_term($cat_id, 'espresso_event_categories');
2468
-    }
2469
-
2470
-
2471
-
2472
-    /**
2473
-     * @param $new_category
2474
-     */
2475
-    protected function _insert_or_update_category($new_category)
2476
-    {
2477
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2478
-        $success = 0; //we already have a success message so lets not send another.
2479
-        if ($cat_id) {
2480
-            $query_args = array(
2481
-                'action'     => 'edit_category',
2482
-                'EVT_CAT_ID' => $cat_id,
2483
-            );
2484
-        } else {
2485
-            $query_args = array('action' => 'add_category');
2486
-        }
2487
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2488
-    }
2489
-
2490
-
2491
-
2492
-    /**
2493
-     * @param bool $update
2494
-     * @return bool|mixed|string
2495
-     */
2496
-    private function _insert_category($update = false)
2497
-    {
2498
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2499
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2500
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2501
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2502
-        if (empty($category_name)) {
2503
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2504
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2505
-            return false;
2506
-        }
2507
-        $term_args = array(
2508
-            'name'        => $category_name,
2509
-            'description' => $category_desc,
2510
-            'parent'      => $category_parent,
2511
-        );
2512
-        //was the category_identifier input disabled?
2513
-        if (isset($this->_req_data['category_identifier'])) {
2514
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2515
-        }
2516
-        $insert_ids = $update
2517
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2518
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2519
-        if ( ! is_array($insert_ids)) {
2520
-            $msg = esc_html__(
2521
-                'An error occurred and the category has not been saved to the database.',
2522
-                'event_espresso'
2523
-            );
2524
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2525
-        } else {
2526
-            $cat_id = $insert_ids['term_id'];
2527
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2528
-            EE_Error::add_success($msg);
2529
-        }
2530
-        return $cat_id;
2531
-    }
2532
-
2533
-
2534
-
2535
-    /**
2536
-     * @param int  $per_page
2537
-     * @param int  $current_page
2538
-     * @param bool $count
2539
-     * @return \EE_Base_Class[]|int
2540
-     */
2541
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2542
-    {
2543
-        //testing term stuff
2544
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2545
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2546
-        $limit = ($current_page - 1) * $per_page;
2547
-        $where = array('taxonomy' => 'espresso_event_categories');
2548
-        if (isset($this->_req_data['s'])) {
2549
-            $sstr = '%' . $this->_req_data['s'] . '%';
2550
-            $where['OR'] = array(
2551
-                'Term.name'   => array('LIKE', $sstr),
2552
-                'description' => array('LIKE', $sstr),
2553
-            );
2554
-        }
2555
-        $query_params = array(
2556
-            $where,
2557
-            'order_by'   => array($orderby => $order),
2558
-            'limit'      => $limit . ',' . $per_page,
2559
-            'force_join' => array('Term'),
2560
-        );
2561
-        $categories = $count
2562
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2563
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2564
-        return $categories;
2565
-    }
2566
-
2567
-
2568
-
2569
-    /* end category stuff */
2570
-    /**************/
384
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
385
+				'require_nonce' => false,
386
+			),
387
+			'default_event_settings' => array(
388
+				'nav'           => array(
389
+					'label' => esc_html__('Default Settings', 'event_espresso'),
390
+					'order' => 40,
391
+				),
392
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
393
+				'labels'        => array(
394
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
395
+				),
396
+				'help_tabs'     => array(
397
+					'default_settings_help_tab'        => array(
398
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
399
+						'filename' => 'events_default_settings',
400
+					),
401
+					'default_settings_status_help_tab' => array(
402
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
403
+						'filename' => 'events_default_settings_status',
404
+					),
405
+				),
406
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
407
+				'require_nonce' => false,
408
+			),
409
+			//template settings
410
+			'template_settings'      => array(
411
+				'nav'           => array(
412
+					'label' => esc_html__('Templates', 'event_espresso'),
413
+					'order' => 30,
414
+				),
415
+				'metaboxes'     => $this->_default_espresso_metaboxes,
416
+				'help_tabs'     => array(
417
+					'general_settings_templates_help_tab' => array(
418
+						'title'    => esc_html__('Templates', 'event_espresso'),
419
+						'filename' => 'general_settings_templates',
420
+					),
421
+				),
422
+				'help_tour'     => array('Templates_Help_Tour'),
423
+				'require_nonce' => false,
424
+			),
425
+			//event category stuff
426
+			'add_category'           => array(
427
+				'nav'           => array(
428
+					'label'      => esc_html__('Add Category', 'event_espresso'),
429
+					'order'      => 15,
430
+					'persistent' => false,
431
+				),
432
+				'help_tabs'     => array(
433
+					'add_category_help_tab' => array(
434
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
435
+						'filename' => 'events_add_category',
436
+					),
437
+				),
438
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
439
+				'metaboxes'     => array('_publish_post_box'),
440
+				'require_nonce' => false,
441
+			),
442
+			'edit_category'          => array(
443
+				'nav'           => array(
444
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
445
+					'order'      => 15,
446
+					'persistent' => false,
447
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
448
+						? add_query_arg(
449
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
450
+							$this->_current_page_view_url
451
+						)
452
+						: $this->_admin_base_url,
453
+				),
454
+				'help_tabs'     => array(
455
+					'edit_category_help_tab' => array(
456
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
457
+						'filename' => 'events_edit_category',
458
+					),
459
+				),
460
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
461
+				'metaboxes'     => array('_publish_post_box'),
462
+				'require_nonce' => false,
463
+			),
464
+			'category_list'          => array(
465
+				'nav'           => array(
466
+					'label' => esc_html__('Categories', 'event_espresso'),
467
+					'order' => 20,
468
+				),
469
+				'list_table'    => 'Event_Categories_Admin_List_Table',
470
+				'help_tabs'     => array(
471
+					'events_categories_help_tab'                       => array(
472
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
473
+						'filename' => 'events_categories',
474
+					),
475
+					'events_categories_table_column_headings_help_tab' => array(
476
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
477
+						'filename' => 'events_categories_table_column_headings',
478
+					),
479
+					'events_categories_view_help_tab'                  => array(
480
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
481
+						'filename' => 'events_categories_views',
482
+					),
483
+					'events_categories_other_help_tab'                 => array(
484
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
485
+						'filename' => 'events_categories_other',
486
+					),
487
+				),
488
+				'help_tour'     => array(
489
+					'Event_Categories_Help_Tour',
490
+				),
491
+				'metaboxes'     => $this->_default_espresso_metaboxes,
492
+				'require_nonce' => false,
493
+			),
494
+		);
495
+	}
496
+
497
+
498
+
499
+	protected function _add_screen_options()
500
+	{
501
+		//todo
502
+	}
503
+
504
+
505
+
506
+	protected function _add_screen_options_default()
507
+	{
508
+		$this->_per_page_screen_option();
509
+	}
510
+
511
+
512
+
513
+	protected function _add_screen_options_category_list()
514
+	{
515
+		$page_title = $this->_admin_page_title;
516
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
517
+		$this->_per_page_screen_option();
518
+		$this->_admin_page_title = $page_title;
519
+	}
520
+
521
+
522
+
523
+	protected function _add_feature_pointers()
524
+	{
525
+		//todo
526
+	}
527
+
528
+
529
+
530
+	public function load_scripts_styles()
531
+	{
532
+		wp_register_style(
533
+			'events-admin-css',
534
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
535
+			array(),
536
+			EVENT_ESPRESSO_VERSION
537
+		);
538
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539
+		wp_enqueue_style('events-admin-css');
540
+		wp_enqueue_style('ee-cat-admin');
541
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
542
+		//registers for all views
543
+		//scripts
544
+		wp_register_script(
545
+			'event_editor_js',
546
+			EVENTS_ASSETS_URL . 'event_editor.js',
547
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
548
+			EVENT_ESPRESSO_VERSION,
549
+			true
550
+		);
551
+	}
552
+
553
+
554
+
555
+	/**
556
+	 * enqueuing scripts and styles specific to this view
557
+	 *
558
+	 * @return void
559
+	 */
560
+	public function load_scripts_styles_create_new()
561
+	{
562
+		$this->load_scripts_styles_edit();
563
+	}
564
+
565
+
566
+
567
+	/**
568
+	 * enqueuing scripts and styles specific to this view
569
+	 *
570
+	 * @return void
571
+	 */
572
+	public function load_scripts_styles_edit()
573
+	{
574
+		//styles
575
+		wp_enqueue_style('espresso-ui-theme');
576
+		wp_register_style(
577
+			'event-editor-css',
578
+			EVENTS_ASSETS_URL . 'event-editor.css',
579
+			array('ee-admin-css'),
580
+			EVENT_ESPRESSO_VERSION
581
+		);
582
+		wp_enqueue_style('event-editor-css');
583
+		//scripts
584
+		wp_register_script(
585
+			'event-datetime-metabox',
586
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
587
+			array('event_editor_js', 'ee-datepicker'),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_enqueue_script('event-datetime-metabox');
591
+	}
592
+
593
+
594
+
595
+	public function load_scripts_styles_add_category()
596
+	{
597
+		$this->load_scripts_styles_edit_category();
598
+	}
599
+
600
+
601
+
602
+	public function load_scripts_styles_edit_category()
603
+	{
604
+	}
605
+
606
+
607
+
608
+	protected function _set_list_table_views_category_list()
609
+	{
610
+		$this->_views = array(
611
+			'all' => array(
612
+				'slug'        => 'all',
613
+				'label'       => esc_html__('All', 'event_espresso'),
614
+				'count'       => 0,
615
+				'bulk_action' => array(
616
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
+				),
618
+			),
619
+		);
620
+	}
621
+
622
+
623
+
624
+	public function admin_init()
625
+	{
626
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
627
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
628
+			'event_espresso'
629
+		);
630
+	}
631
+
632
+
633
+
634
+	//nothing needed for events with these methods.
635
+	public function admin_notices()
636
+	{
637
+	}
638
+
639
+
640
+
641
+	public function admin_footer_scripts()
642
+	{
643
+	}
644
+
645
+
646
+
647
+	/**
648
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
649
+	 * warning (via EE_Error::add_error());
650
+	 *
651
+	 * @param  EE_Event $event Event object
652
+	 * @access public
653
+	 * @return void
654
+	 */
655
+	public function verify_event_edit($event = null)
656
+	{
657
+		// no event?
658
+		if (empty($event)) {
659
+			// set event
660
+			$event = $this->_cpt_model_obj;
661
+		}
662
+		// STILL no event?
663
+		if (empty ($event)) {
664
+			return;
665
+		}
666
+		$orig_status = $event->status();
667
+		// first check if event is active.
668
+		if (
669
+			$orig_status === EEM_Event::cancelled
670
+			|| $orig_status === EEM_Event::postponed
671
+			|| $event->is_expired()
672
+			|| $event->is_inactive()
673
+		) {
674
+			return;
675
+		}
676
+		//made it here so it IS active... next check that any of the tickets are sold.
677
+		if ($event->is_sold_out(true)) {
678
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
679
+				EE_Error::add_attention(
680
+					sprintf(
681
+						esc_html__(
682
+							'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.',
683
+							'event_espresso'
684
+						),
685
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
686
+					)
687
+				);
688
+			}
689
+			return;
690
+		} else if ($orig_status === EEM_Event::sold_out) {
691
+			EE_Error::add_attention(
692
+				sprintf(
693
+					esc_html__(
694
+						'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.',
695
+						'event_espresso'
696
+					),
697
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
698
+				)
699
+			);
700
+		}
701
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
702
+		if ( ! $event->tickets_on_sale()) {
703
+			return;
704
+		}
705
+		//made it here so show warning
706
+		$this->_edit_event_warning();
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
713
+	 * When needed, hook this into a EE_Error::add_error() notice.
714
+	 *
715
+	 * @access protected
716
+	 * @return void
717
+	 */
718
+	protected function _edit_event_warning()
719
+	{
720
+		// we don't want to add warnings during these requests
721
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
722
+			return;
723
+		}
724
+		EE_Error::add_attention(
725
+			esc_html__(
726
+				'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.',
727
+				'event_espresso'
728
+			)
729
+		);
730
+	}
731
+
732
+
733
+
734
+	/**
735
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
736
+	 * Otherwise, do the normal logic
737
+	 *
738
+	 * @return string
739
+	 * @throws \EE_Error
740
+	 */
741
+	protected function _create_new_cpt_item()
742
+	{
743
+		$gmt_offset = get_option('gmt_offset');
744
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
745
+		if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
746
+			EE_Error::add_attention(
747
+				sprintf(
748
+					__(
749
+						'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
750
+						'event_espresso'
751
+					),
752
+					'<a href="' . admin_url('options-general.php') . '">',
753
+					'</a>'
754
+				),
755
+				__FILE__,
756
+				__FUNCTION__,
757
+				__LINE__
758
+			);
759
+		}
760
+		return parent::_create_new_cpt_item();
761
+	}
762
+
763
+
764
+
765
+	protected function _set_list_table_views_default()
766
+	{
767
+		$this->_views = array(
768
+			'all'   => array(
769
+				'slug'        => 'all',
770
+				'label'       => esc_html__('View All Events', 'event_espresso'),
771
+				'count'       => 0,
772
+				'bulk_action' => array(
773
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
774
+				),
775
+			),
776
+			'draft' => array(
777
+				'slug'        => 'draft',
778
+				'label'       => esc_html__('Draft', 'event_espresso'),
779
+				'count'       => 0,
780
+				'bulk_action' => array(
781
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
782
+				),
783
+			),
784
+		);
785
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
786
+			$this->_views['trash'] = array(
787
+				'slug'        => 'trash',
788
+				'label'       => esc_html__('Trash', 'event_espresso'),
789
+				'count'       => 0,
790
+				'bulk_action' => array(
791
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
792
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
793
+				),
794
+			);
795
+		}
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 * @return array
802
+	 */
803
+	protected function _event_legend_items()
804
+	{
805
+		$items = array(
806
+			'view_details'   => array(
807
+				'class' => 'dashicons dashicons-search',
808
+				'desc'  => esc_html__('View Event', 'event_espresso'),
809
+			),
810
+			'edit_event'     => array(
811
+				'class' => 'ee-icon ee-icon-calendar-edit',
812
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
813
+			),
814
+			'view_attendees' => array(
815
+				'class' => 'dashicons dashicons-groups',
816
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
817
+			),
818
+		);
819
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
820
+		$statuses = array(
821
+			'sold_out_status'  => array(
822
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
823
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
824
+			),
825
+			'active_status'    => array(
826
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
827
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
828
+			),
829
+			'upcoming_status'  => array(
830
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
831
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
832
+			),
833
+			'postponed_status' => array(
834
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
835
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
836
+			),
837
+			'cancelled_status' => array(
838
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
839
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
840
+			),
841
+			'expired_status'   => array(
842
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
843
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
844
+			),
845
+			'inactive_status'  => array(
846
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
847
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
848
+			),
849
+		);
850
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
851
+		return array_merge($items, $statuses);
852
+	}
853
+
854
+
855
+
856
+	/**
857
+	 * _event_model
858
+	 *
859
+	 * @return EEM_Event
860
+	 */
861
+	private function _event_model()
862
+	{
863
+		if ( ! $this->_event_model instanceof EEM_Event) {
864
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
865
+		}
866
+		return $this->_event_model;
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * Adds extra buttons to the WP CPT permalink field row.
873
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
874
+	 *
875
+	 * @param  string $return    the current html
876
+	 * @param  int    $id        the post id for the page
877
+	 * @param  string $new_title What the title is
878
+	 * @param  string $new_slug  what the slug is
879
+	 * @return string            The new html string for the permalink area
880
+	 */
881
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
882
+	{
883
+		//make sure this is only when editing
884
+		if ( ! empty($id)) {
885
+			$post = get_post($id);
886
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
887
+					   . esc_html__('Shortcode', 'event_espresso')
888
+					   . '</a> ';
889
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
890
+					   . $post->ID
891
+					   . ']">';
892
+		}
893
+		return $return;
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * _events_overview_list_table
900
+	 * This contains the logic for showing the events_overview list
901
+	 *
902
+	 * @access protected
903
+	 * @return void
904
+	 */
905
+	protected function _events_overview_list_table()
906
+	{
907
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
908
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
909
+			get_post_type_archive_link('espresso_events'),
910
+			esc_html__("View Event Archive Page", "event_espresso"),
911
+			'button'
912
+		);
913
+		$this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items());
914
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
915
+				'create_new',
916
+				'add',
917
+				array(),
918
+				'add-new-h2'
919
+			);
920
+		$this->display_admin_list_table_page_with_no_sidebar();
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 * this allows for extra misc actions in the default WP publish box
927
+	 *
928
+	 * @return void
929
+	 */
930
+	public function extra_misc_actions_publish_box()
931
+	{
932
+		$this->_generate_publish_box_extra_content();
933
+	}
934
+
935
+
936
+
937
+	/**
938
+	 * @param string $post_id
939
+	 * @param object $post
940
+	 */
941
+	protected function _insert_update_cpt_item($post_id, $post)
942
+	{
943
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
944
+			//get out we're not processing an event save.
945
+			return;
946
+		}
947
+		$event_values = array(
948
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
949
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
950
+			'EVT_additional_limit'            => min(
951
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
952
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
953
+			),
954
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
955
+				? $this->_req_data['EVT_default_registration_status']
956
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
957
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
958
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
959
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
960
+				? $this->_req_data['timezone_string'] : null,
961
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
962
+				? $this->_req_data['externalURL'] : null,
963
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
964
+				? $this->_req_data['event_phone'] : null,
965
+		);
966
+		//update event
967
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
968
+		//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!
969
+		$get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
970
+		$event = $this->_event_model()->get_one(array($get_one_where));
971
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
972
+		$event_update_callbacks = apply_filters(
973
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
974
+			array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
975
+		);
976
+		$att_success = true;
977
+		foreach ($event_update_callbacks as $e_callback) {
978
+			$_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
979
+			$att_success = ! $att_success ? $att_success
980
+				: $_succ; //if ANY of these updates fail then we want the appropriate global error message
981
+		}
982
+		//any errors?
983
+		if ($success && false === $att_success) {
984
+			EE_Error::add_error(
985
+				esc_html__(
986
+					'Event Details saved successfully but something went wrong with saving attachments.',
987
+					'event_espresso'
988
+				),
989
+				__FILE__,
990
+				__FUNCTION__,
991
+				__LINE__
992
+			);
993
+		} else if ($success === false) {
994
+			EE_Error::add_error(
995
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
996
+				__FILE__,
997
+				__FUNCTION__,
998
+				__LINE__
999
+			);
1000
+		}
1001
+	}
1002
+
1003
+
1004
+
1005
+	/**
1006
+	 * @see parent::restore_item()
1007
+	 * @param int $post_id
1008
+	 * @param int $revision_id
1009
+	 */
1010
+	protected function _restore_cpt_item($post_id, $revision_id)
1011
+	{
1012
+		//copy existing event meta to new post
1013
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1014
+		if ($post_evt instanceof EE_Event) {
1015
+			//meta revision restore
1016
+			$post_evt->restore_revision($revision_id);
1017
+			//related objs restore
1018
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1019
+		}
1020
+	}
1021
+
1022
+
1023
+
1024
+	/**
1025
+	 * Attach the venue to the Event
1026
+	 *
1027
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1028
+	 * @param  array     $data   The request data from the form
1029
+	 * @return bool           Success or fail.
1030
+	 */
1031
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1032
+	{
1033
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1034
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1035
+		$rows_affected = null;
1036
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1037
+		// very important.  If we don't have a venue name...
1038
+		// then we'll get out because not necessary to create empty venue
1039
+		if (empty($data['venue_title'])) {
1040
+			return false;
1041
+		}
1042
+		$venue_array = array(
1043
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1044
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1045
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1046
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1047
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1048
+				: null,
1049
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1050
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1051
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1052
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1053
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1054
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1055
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1056
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1057
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1058
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1059
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1060
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1061
+			'status'              => 'publish',
1062
+		);
1063
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1064
+		if ( ! empty($venue_id)) {
1065
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1066
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1067
+			//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.
1068
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1069
+			return $rows_affected > 0 ? true : false;
1070
+		} else {
1071
+			//we insert the venue
1072
+			$venue_id = $venue_model->insert($venue_array);
1073
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1074
+			return ! empty($venue_id) ? true : false;
1075
+		}
1076
+		//when we have the ancestor come in it's already been handled by the revision save.
1077
+	}
1078
+
1079
+
1080
+
1081
+	/**
1082
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1083
+	 *
1084
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1085
+	 * @param  array    $data   The request data from the form
1086
+	 * @return array
1087
+	 */
1088
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1089
+	{
1090
+		$success = true;
1091
+		$saved_dtt = null;
1092
+		$saved_tickets = array();
1093
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1094
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1095
+			//trim all values to ensure any excess whitespace is removed.
1096
+			$dtt = array_map('trim', $dtt);
1097
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1098
+				: $dtt['DTT_EVT_start'];
1099
+			$datetime_values = array(
1100
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1101
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1102
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1103
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1104
+				'DTT_order'     => $row,
1105
+			);
1106
+			//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.
1107
+			if ( ! empty($dtt['DTT_ID'])) {
1108
+				$DTM = EE_Registry::instance()
1109
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1110
+								  ->get_one_by_ID($dtt['DTT_ID']);
1111
+				$DTM->set_date_format($incoming_date_formats[0]);
1112
+				$DTM->set_time_format($incoming_date_formats[1]);
1113
+				foreach ($datetime_values as $field => $value) {
1114
+					$DTM->set($field, $value);
1115
+				}
1116
+				//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.
1117
+				$saved_dtts[$DTM->ID()] = $DTM;
1118
+			} else {
1119
+				$DTM = EE_Registry::instance()->load_class(
1120
+					'Datetime',
1121
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1122
+					false,
1123
+					false
1124
+				);
1125
+				foreach ($datetime_values as $field => $value) {
1126
+					$DTM->set($field, $value);
1127
+				}
1128
+			}
1129
+			$DTM->save();
1130
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1131
+			//load DTT helper
1132
+			//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.
1133
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1134
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1135
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1136
+				$DTT->save();
1137
+			}
1138
+			//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.
1139
+			$saved_dtt = $DTT;
1140
+			$success = ! $success ? $success : $DTT;
1141
+			//if ANY of these updates fail then we want the appropriate global error message.
1142
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1143
+		}
1144
+		//no dtts get deleted so we don't do any of that logic here.
1145
+		//update tickets next
1146
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1147
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1148
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1149
+			$update_prices = false;
1150
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1151
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1152
+			// trim inputs to ensure any excess whitespace is removed.
1153
+			$tkt = array_map('trim', $tkt);
1154
+			if (empty($tkt['TKT_start_date'])) {
1155
+				//let's use now in the set timezone.
1156
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1157
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1158
+			}
1159
+			if (empty($tkt['TKT_end_date'])) {
1160
+				//use the start date of the first datetime
1161
+				$dtt = $evtobj->first_datetime();
1162
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1163
+					$incoming_date_formats[0],
1164
+					$incoming_date_formats[1]
1165
+				);
1166
+			}
1167
+			$TKT_values = array(
1168
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1169
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1170
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1171
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1172
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1173
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1174
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1175
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1176
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1177
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1178
+				'TKT_row'         => $row,
1179
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1180
+				'TKT_price'       => $ticket_price,
1181
+			);
1182
+			//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.
1183
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1184
+				$TKT_values['TKT_ID'] = 0;
1185
+				$TKT_values['TKT_is_default'] = 0;
1186
+				$TKT_values['TKT_price'] = $ticket_price;
1187
+				$update_prices = true;
1188
+			}
1189
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1190
+			//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.
1191
+			//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.
1192
+			if ( ! empty($tkt['TKT_ID'])) {
1193
+				$TKT = EE_Registry::instance()
1194
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1195
+								  ->get_one_by_ID($tkt['TKT_ID']);
1196
+				if ($TKT instanceof EE_Ticket) {
1197
+					$ticket_sold = $TKT->count_related(
1198
+						'Registration',
1199
+						array(
1200
+							array(
1201
+								'STS_ID' => array(
1202
+									'NOT IN',
1203
+									array(EEM_Registration::status_id_incomplete),
1204
+								),
1205
+							),
1206
+						)
1207
+					) > 0 ? true : false;
1208
+					//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.
1209
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1210
+									  && ! $TKT->get(
1211
+						'TKT_deleted'
1212
+					) ? true : false;
1213
+					$TKT->set_date_format($incoming_date_formats[0]);
1214
+					$TKT->set_time_format($incoming_date_formats[1]);
1215
+					//set new values
1216
+					foreach ($TKT_values as $field => $value) {
1217
+						if ($field == 'TKT_qty') {
1218
+							$TKT->set_qty($value);
1219
+						} else {
1220
+							$TKT->set($field, $value);
1221
+						}
1222
+					}
1223
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1224
+					if ($create_new_TKT) {
1225
+						//archive the old ticket first
1226
+						$TKT->set('TKT_deleted', 1);
1227
+						$TKT->save();
1228
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1229
+						$saved_tickets[$TKT->ID()] = $TKT;
1230
+						//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.
1231
+						$TKT = clone $TKT;
1232
+						$TKT->set('TKT_ID', 0);
1233
+						$TKT->set('TKT_deleted', 0);
1234
+						$TKT->set('TKT_price', $ticket_price);
1235
+						$TKT->set('TKT_sold', 0);
1236
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1237
+						$update_prices = true;
1238
+					}
1239
+					//make sure price is set if it hasn't been already
1240
+					$TKT->set('TKT_price', $ticket_price);
1241
+				}
1242
+			} else {
1243
+				//no TKT_id so a new TKT
1244
+				$TKT_values['TKT_price'] = $ticket_price;
1245
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1246
+				if ($TKT instanceof EE_Ticket) {
1247
+					//need to reset values to properly account for the date formats
1248
+					$TKT->set_date_format($incoming_date_formats[0]);
1249
+					$TKT->set_time_format($incoming_date_formats[1]);
1250
+					$TKT->set_timezone($evtobj->get_timezone());
1251
+					//set new values
1252
+					foreach ($TKT_values as $field => $value) {
1253
+						if ($field == 'TKT_qty') {
1254
+							$TKT->set_qty($value);
1255
+						} else {
1256
+							$TKT->set($field, $value);
1257
+						}
1258
+					}
1259
+					$update_prices = true;
1260
+				}
1261
+			}
1262
+			// cap ticket qty by datetime reg limits
1263
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1264
+			//update ticket.
1265
+			$TKT->save();
1266
+			//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.
1267
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1268
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1269
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1270
+				$TKT->save();
1271
+			}
1272
+			//initially let's add the ticket to the dtt
1273
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1274
+			$saved_tickets[$TKT->ID()] = $TKT;
1275
+			//add prices to ticket
1276
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1277
+		}
1278
+		//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.
1279
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1280
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1281
+		foreach ($tickets_removed as $id) {
1282
+			$id = absint($id);
1283
+			//get the ticket for this id
1284
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1285
+			//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)
1286
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1287
+			foreach ($dtts as $dtt) {
1288
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1289
+			}
1290
+			//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))
1291
+			$tkt_to_remove->delete_related_permanently('Price');
1292
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1293
+			$tkt_to_remove->delete_permanently();
1294
+		}
1295
+		return array($saved_dtt, $saved_tickets);
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * This attaches a list of given prices to a ticket.
1302
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1303
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1304
+	 * price info and prices are automatically "archived" via the ticket.
1305
+	 *
1306
+	 * @access  private
1307
+	 * @param array     $prices     Array of prices from the form.
1308
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1309
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1310
+	 * @return  void
1311
+	 */
1312
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1313
+	{
1314
+		foreach ($prices as $row => $prc) {
1315
+			$PRC_values = array(
1316
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1317
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1318
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1319
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1320
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1321
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1322
+				'PRC_order'      => $row,
1323
+			);
1324
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1325
+				$PRC_values['PRC_ID'] = 0;
1326
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1327
+			} else {
1328
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1329
+				//update this price with new values
1330
+				foreach ($PRC_values as $field => $newprc) {
1331
+					$PRC->set($field, $newprc);
1332
+				}
1333
+				$PRC->save();
1334
+			}
1335
+			$ticket->_add_relation_to($PRC, 'Price');
1336
+		}
1337
+	}
1338
+
1339
+
1340
+
1341
+	/**
1342
+	 * Add in our autosave ajax handlers
1343
+	 *
1344
+	 * @return void
1345
+	 */
1346
+	protected function _ee_autosave_create_new()
1347
+	{
1348
+		// $this->_ee_autosave_edit();
1349
+	}
1350
+
1351
+
1352
+
1353
+	protected function _ee_autosave_edit()
1354
+	{
1355
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1356
+	}
1357
+
1358
+
1359
+
1360
+	/**
1361
+	 *    _generate_publish_box_extra_content
1362
+	 *
1363
+	 * @access private
1364
+	 * @return void
1365
+	 */
1366
+	private function _generate_publish_box_extra_content()
1367
+	{
1368
+		//load formatter helper
1369
+		//args for getting related registrations
1370
+		$approved_query_args = array(
1371
+			array(
1372
+				'REG_deleted' => 0,
1373
+				'STS_ID'      => EEM_Registration::status_id_approved,
1374
+			),
1375
+		);
1376
+		$not_approved_query_args = array(
1377
+			array(
1378
+				'REG_deleted' => 0,
1379
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1380
+			),
1381
+		);
1382
+		$pending_payment_query_args = array(
1383
+			array(
1384
+				'REG_deleted' => 0,
1385
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1386
+			),
1387
+		);
1388
+		// publish box
1389
+		$publish_box_extra_args = array(
1390
+			'view_approved_reg_url'        => add_query_arg(
1391
+				array(
1392
+					'action'      => 'default',
1393
+					'event_id'    => $this->_cpt_model_obj->ID(),
1394
+					'_reg_status' => EEM_Registration::status_id_approved,
1395
+				),
1396
+				REG_ADMIN_URL
1397
+			),
1398
+			'view_not_approved_reg_url'    => add_query_arg(
1399
+				array(
1400
+					'action'      => 'default',
1401
+					'event_id'    => $this->_cpt_model_obj->ID(),
1402
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1403
+				),
1404
+				REG_ADMIN_URL
1405
+			),
1406
+			'view_pending_payment_reg_url' => add_query_arg(
1407
+				array(
1408
+					'action'      => 'default',
1409
+					'event_id'    => $this->_cpt_model_obj->ID(),
1410
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1411
+				),
1412
+				REG_ADMIN_URL
1413
+			),
1414
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1415
+				'Registration',
1416
+				$approved_query_args
1417
+			),
1418
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1419
+				'Registration',
1420
+				$not_approved_query_args
1421
+			),
1422
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1423
+				'Registration',
1424
+				$pending_payment_query_args
1425
+			),
1426
+			'misc_pub_section_class'       => apply_filters(
1427
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1428
+				'misc-pub-section'
1429
+			),
1430
+			//'email_attendees_url' => add_query_arg(
1431
+			//	array(
1432
+			//		'event_admin_reports' => 'event_newsletter',
1433
+			//		'event_id' => $this->_cpt_model_obj->id
1434
+			//	),
1435
+			//	'admin.php?page=espresso_registrations'
1436
+			//),
1437
+		);
1438
+		ob_start();
1439
+		do_action(
1440
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1441
+			$this->_cpt_model_obj
1442
+		);
1443
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1444
+		// load template
1445
+		EEH_Template::display_template(
1446
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1447
+			$publish_box_extra_args
1448
+		);
1449
+	}
1450
+
1451
+
1452
+
1453
+	/**
1454
+	 * This just returns whatever is set as the _event object property
1455
+	 * //todo this will become obsolete once the models are in place
1456
+	 *
1457
+	 * @return object
1458
+	 */
1459
+	public function get_event_object()
1460
+	{
1461
+		return $this->_cpt_model_obj;
1462
+	}
1463
+
1464
+
1465
+
1466
+
1467
+	/** METABOXES * */
1468
+	/**
1469
+	 * _register_event_editor_meta_boxes
1470
+	 * add all metaboxes related to the event_editor
1471
+	 *
1472
+	 * @return void
1473
+	 */
1474
+	protected function _register_event_editor_meta_boxes()
1475
+	{
1476
+		$this->verify_cpt_object();
1477
+		add_meta_box(
1478
+			'espresso_event_editor_tickets',
1479
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1480
+			array($this, 'ticket_metabox'),
1481
+			$this->page_slug,
1482
+			'normal',
1483
+			'high'
1484
+		);
1485
+		add_meta_box(
1486
+			'espresso_event_editor_event_options',
1487
+			esc_html__('Event Registration Options', 'event_espresso'),
1488
+			array($this, 'registration_options_meta_box'),
1489
+			$this->page_slug,
1490
+			'side',
1491
+			'default'
1492
+		);
1493
+		// NOTE: if you're looking for other metaboxes in here,
1494
+		// where a metabox has a related management page in the admin
1495
+		// you will find it setup in the related management page's "_Hooks" file.
1496
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1497
+	}
1498
+
1499
+
1500
+
1501
+	public function ticket_metabox()
1502
+	{
1503
+		$existing_datetime_ids = $existing_ticket_ids = array();
1504
+		//defaults for template args
1505
+		$template_args = array(
1506
+			'existing_datetime_ids'    => '',
1507
+			'event_datetime_help_link' => '',
1508
+			'ticket_options_help_link' => '',
1509
+			'time'                     => null,
1510
+			'ticket_rows'              => '',
1511
+			'existing_ticket_ids'      => '',
1512
+			'total_ticket_rows'        => 1,
1513
+			'ticket_js_structure'      => '',
1514
+			'trash_icon'               => 'ee-lock-icon',
1515
+			'disabled'                 => '',
1516
+		);
1517
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1518
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1519
+		/**
1520
+		 * 1. Start with retrieving Datetimes
1521
+		 * 2. Fore each datetime get related tickets
1522
+		 * 3. For each ticket get related prices
1523
+		 */
1524
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1525
+		/** @type EE_Datetime $first_datetime */
1526
+		$first_datetime = reset($times);
1527
+		//do we get related tickets?
1528
+		if ($first_datetime instanceof EE_Datetime
1529
+			&& $first_datetime->ID() !== 0
1530
+		) {
1531
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1532
+			$template_args['time'] = $first_datetime;
1533
+			$related_tickets = $first_datetime->tickets(
1534
+				array(
1535
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1536
+					'default_where_conditions' => 'none',
1537
+				)
1538
+			);
1539
+			if ( ! empty($related_tickets)) {
1540
+				$template_args['total_ticket_rows'] = count($related_tickets);
1541
+				$row = 0;
1542
+				foreach ($related_tickets as $ticket) {
1543
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1544
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1545
+					$row++;
1546
+				}
1547
+			} else {
1548
+				$template_args['total_ticket_rows'] = 1;
1549
+				/** @type EE_Ticket $ticket */
1550
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1551
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1552
+			}
1553
+		} else {
1554
+			$template_args['time'] = $times[0];
1555
+			/** @type EE_Ticket $ticket */
1556
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1557
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1558
+			// NOTE: we're just sending the first default row
1559
+			// (decaf can't manage default tickets so this should be sufficient);
1560
+		}
1561
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1562
+			'event_editor_event_datetimes_help_tab'
1563
+		);
1564
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1565
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1566
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1567
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1568
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1569
+			true
1570
+		);
1571
+		$template = apply_filters(
1572
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1573
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1574
+		);
1575
+		EEH_Template::display_template($template, $template_args);
1576
+	}
1577
+
1578
+
1579
+
1580
+	/**
1581
+	 * Setup an individual ticket form for the decaf event editor page
1582
+	 *
1583
+	 * @access private
1584
+	 * @param  EE_Ticket $ticket   the ticket object
1585
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1586
+	 * @param int        $row
1587
+	 * @return string generated html for the ticket row.
1588
+	 */
1589
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1590
+	{
1591
+		$template_args = array(
1592
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1593
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1594
+				: '',
1595
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1596
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1597
+			'TKT_name'            => $ticket->get('TKT_name'),
1598
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1599
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1600
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1601
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1602
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1603
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1604
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1605
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1606
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1607
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1608
+				: ' disabled=disabled',
1609
+		);
1610
+		$price = $ticket->ID() !== 0
1611
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1612
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1613
+		$price_args = array(
1614
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1615
+			'PRC_amount'            => $price->get('PRC_amount'),
1616
+			'PRT_ID'                => $price->get('PRT_ID'),
1617
+			'PRC_ID'                => $price->get('PRC_ID'),
1618
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1619
+		);
1620
+		//make sure we have default start and end dates if skeleton
1621
+		//handle rows that should NOT be empty
1622
+		if (empty($template_args['TKT_start_date'])) {
1623
+			//if empty then the start date will be now.
1624
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1625
+		}
1626
+		if (empty($template_args['TKT_end_date'])) {
1627
+			//get the earliest datetime (if present);
1628
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1629
+				? $this->_cpt_model_obj->get_first_related(
1630
+					'Datetime',
1631
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1632
+				)
1633
+				: null;
1634
+			if ( ! empty($earliest_dtt)) {
1635
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1636
+			} else {
1637
+				$template_args['TKT_end_date'] = date(
1638
+					'Y-m-d h:i a',
1639
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1640
+				);
1641
+			}
1642
+		}
1643
+		$template_args = array_merge($template_args, $price_args);
1644
+		$template = apply_filters(
1645
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1646
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1647
+			$ticket
1648
+		);
1649
+		return EEH_Template::display_template($template, $template_args, true);
1650
+	}
1651
+
1652
+
1653
+
1654
+	public function registration_options_meta_box()
1655
+	{
1656
+		$yes_no_values = array(
1657
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1658
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1659
+		);
1660
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1661
+			array(
1662
+				EEM_Registration::status_id_cancelled,
1663
+				EEM_Registration::status_id_declined,
1664
+				EEM_Registration::status_id_incomplete,
1665
+			),
1666
+			true
1667
+		);
1668
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1669
+		$template_args['_event'] = $this->_cpt_model_obj;
1670
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1671
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1672
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1673
+			'default_reg_status',
1674
+			$default_reg_status_values,
1675
+			$this->_cpt_model_obj->default_registration_status()
1676
+		);
1677
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1678
+			'display_desc',
1679
+			$yes_no_values,
1680
+			$this->_cpt_model_obj->display_description()
1681
+		);
1682
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1683
+			'display_ticket_selector',
1684
+			$yes_no_values,
1685
+			$this->_cpt_model_obj->display_ticket_selector(),
1686
+			'',
1687
+			'',
1688
+			false
1689
+		);
1690
+		$template_args['additional_registration_options'] = apply_filters(
1691
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1692
+			'',
1693
+			$template_args,
1694
+			$yes_no_values,
1695
+			$default_reg_status_values
1696
+		);
1697
+		EEH_Template::display_template(
1698
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1699
+			$template_args
1700
+		);
1701
+	}
1702
+
1703
+
1704
+
1705
+	/**
1706
+	 * _get_events()
1707
+	 * This method simply returns all the events (for the given _view and paging)
1708
+	 *
1709
+	 * @access public
1710
+	 * @param int  $per_page     count of items per page (20 default);
1711
+	 * @param int  $current_page what is the current page being viewed.
1712
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1713
+	 *                           If FALSE then we return an array of event objects
1714
+	 *                           that match the given _view and paging parameters.
1715
+	 * @return array an array of event objects.
1716
+	 */
1717
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1718
+	{
1719
+		$EEME = $this->_event_model();
1720
+		$offset = ($current_page - 1) * $per_page;
1721
+		$limit = $count ? null : $offset . ',' . $per_page;
1722
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1723
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1724
+		if (isset($this->_req_data['month_range'])) {
1725
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1726
+			$month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1727
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1728
+		}
1729
+		$where = array();
1730
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1731
+		//determine what post_status our condition will have for the query.
1732
+		switch ($status) {
1733
+			case 'month' :
1734
+			case 'today' :
1735
+			case null :
1736
+			case 'all' :
1737
+				break;
1738
+			case 'draft' :
1739
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1740
+				break;
1741
+			default :
1742
+				$where['status'] = $status;
1743
+		}
1744
+		//categories?
1745
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1746
+			? $this->_req_data['EVT_CAT'] : null;
1747
+		if ( ! empty ($category)) {
1748
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1749
+			$where['Term_Taxonomy.term_id'] = $category;
1750
+		}
1751
+		//date where conditions
1752
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1753
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1754
+			$DateTime = new DateTime(
1755
+				$year_r . '-' . $month_r . '-01 00:00:00',
1756
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1757
+			);
1758
+			$start = $DateTime->format(implode(' ', $start_formats));
1759
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1760
+				->format('t'))->setTime(23, 59, 59)
1761
+							->format(implode(' ', $start_formats));
1762
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1763
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1764
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1765
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1766
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1767
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1768
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1769
+			$now = date('Y-m-01');
1770
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1771
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1772
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1773
+							->setTime(23, 59, 59)
1774
+							->format(implode(' ', $start_formats));
1775
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1776
+		}
1777
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1778
+			$where['EVT_wp_user'] = get_current_user_id();
1779
+		} else {
1780
+			if ( ! isset($where['status'])) {
1781
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1782
+					$where['OR'] = array(
1783
+						'status*restrict_private' => array('!=', 'private'),
1784
+						'AND'                     => array(
1785
+							'status*inclusive' => array('=', 'private'),
1786
+							'EVT_wp_user'      => get_current_user_id(),
1787
+						),
1788
+					);
1789
+				}
1790
+			}
1791
+		}
1792
+		if (isset($this->_req_data['EVT_wp_user'])) {
1793
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1794
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1795
+			) {
1796
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1797
+			}
1798
+		}
1799
+		//search query handling
1800
+		if (isset($this->_req_data['s'])) {
1801
+			$search_string = '%' . $this->_req_data['s'] . '%';
1802
+			$where['OR'] = array(
1803
+				'EVT_name'       => array('LIKE', $search_string),
1804
+				'EVT_desc'       => array('LIKE', $search_string),
1805
+				'EVT_short_desc' => array('LIKE', $search_string),
1806
+			);
1807
+		}
1808
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1809
+		$query_params = apply_filters(
1810
+			'FHEE__Events_Admin_Page__get_events__query_params',
1811
+			array(
1812
+				$where,
1813
+				'limit'    => $limit,
1814
+				'order_by' => $orderby,
1815
+				'order'    => $order,
1816
+				'group_by' => 'EVT_ID',
1817
+			),
1818
+			$this->_req_data
1819
+		);
1820
+		//let's first check if we have special requests coming in.
1821
+		if (isset($this->_req_data['active_status'])) {
1822
+			switch ($this->_req_data['active_status']) {
1823
+				case 'upcoming' :
1824
+					return $EEME->get_upcoming_events($query_params, $count);
1825
+					break;
1826
+				case 'expired' :
1827
+					return $EEME->get_expired_events($query_params, $count);
1828
+					break;
1829
+				case 'active' :
1830
+					return $EEME->get_active_events($query_params, $count);
1831
+					break;
1832
+				case 'inactive' :
1833
+					return $EEME->get_inactive_events($query_params, $count);
1834
+					break;
1835
+			}
1836
+		}
1837
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1838
+		return $events;
1839
+	}
1840
+
1841
+
1842
+
1843
+	/**
1844
+	 * handling for WordPress CPT actions (trash, restore, delete)
1845
+	 *
1846
+	 * @param string $post_id
1847
+	 */
1848
+	public function trash_cpt_item($post_id)
1849
+	{
1850
+		$this->_req_data['EVT_ID'] = $post_id;
1851
+		$this->_trash_or_restore_event('trash', false);
1852
+	}
1853
+
1854
+
1855
+
1856
+	/**
1857
+	 * @param string $post_id
1858
+	 */
1859
+	public function restore_cpt_item($post_id)
1860
+	{
1861
+		$this->_req_data['EVT_ID'] = $post_id;
1862
+		$this->_trash_or_restore_event('draft', false);
1863
+	}
1864
+
1865
+
1866
+
1867
+	/**
1868
+	 * @param string $post_id
1869
+	 */
1870
+	public function delete_cpt_item($post_id)
1871
+	{
1872
+		$this->_req_data['EVT_ID'] = $post_id;
1873
+		$this->_delete_event(false);
1874
+	}
1875
+
1876
+
1877
+
1878
+	/**
1879
+	 * _trash_or_restore_event
1880
+	 *
1881
+	 * @access protected
1882
+	 * @param  string $event_status
1883
+	 * @param bool    $redirect_after
1884
+	 */
1885
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1886
+	{
1887
+		//determine the event id and set to array.
1888
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1889
+		// loop thru events
1890
+		if ($EVT_ID) {
1891
+			// clean status
1892
+			$event_status = sanitize_key($event_status);
1893
+			// grab status
1894
+			if ( ! empty($event_status)) {
1895
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1896
+			} else {
1897
+				$success = false;
1898
+				$msg = esc_html__(
1899
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1900
+					'event_espresso'
1901
+				);
1902
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1903
+			}
1904
+		} else {
1905
+			$success = false;
1906
+			$msg = esc_html__(
1907
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1908
+				'event_espresso'
1909
+			);
1910
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1911
+		}
1912
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1913
+		if ($redirect_after) {
1914
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1915
+		}
1916
+	}
1917
+
1918
+
1919
+
1920
+	/**
1921
+	 * _trash_or_restore_events
1922
+	 *
1923
+	 * @access protected
1924
+	 * @param  string $event_status
1925
+	 * @return void
1926
+	 */
1927
+	protected function _trash_or_restore_events($event_status = 'trash')
1928
+	{
1929
+		// clean status
1930
+		$event_status = sanitize_key($event_status);
1931
+		// grab status
1932
+		if ( ! empty($event_status)) {
1933
+			$success = true;
1934
+			//determine the event id and set to array.
1935
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1936
+			// loop thru events
1937
+			foreach ($EVT_IDs as $EVT_ID) {
1938
+				if ($EVT_ID = absint($EVT_ID)) {
1939
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1940
+					$success = $results !== false ? $success : false;
1941
+				} else {
1942
+					$msg = sprintf(
1943
+						esc_html__(
1944
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1945
+							'event_espresso'
1946
+						),
1947
+						$EVT_ID
1948
+					);
1949
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1950
+					$success = false;
1951
+				}
1952
+			}
1953
+		} else {
1954
+			$success = false;
1955
+			$msg = esc_html__(
1956
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1957
+				'event_espresso'
1958
+			);
1959
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1960
+		}
1961
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1962
+		$success = $success ? 2 : false;
1963
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1964
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1965
+	}
1966
+
1967
+
1968
+
1969
+	/**
1970
+	 * _trash_or_restore_events
1971
+	 *
1972
+	 * @access  private
1973
+	 * @param  int    $EVT_ID
1974
+	 * @param  string $event_status
1975
+	 * @return bool
1976
+	 */
1977
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
1978
+	{
1979
+		// grab event id
1980
+		if ( ! $EVT_ID) {
1981
+			$msg = esc_html__(
1982
+				'An error occurred. No Event ID or an invalid Event ID was received.',
1983
+				'event_espresso'
1984
+			);
1985
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1986
+			return false;
1987
+		}
1988
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1989
+		// clean status
1990
+		$event_status = sanitize_key($event_status);
1991
+		// grab status
1992
+		if (empty($event_status)) {
1993
+			$msg = esc_html__(
1994
+				'An error occurred. No Event Status or an invalid Event Status was received.',
1995
+				'event_espresso'
1996
+			);
1997
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1998
+			return false;
1999
+		}
2000
+		// was event trashed or restored ?
2001
+		switch ($event_status) {
2002
+			case 'draft' :
2003
+				$action = 'restored from the trash';
2004
+				$hook = 'AHEE_event_restored_from_trash';
2005
+				break;
2006
+			case 'trash' :
2007
+				$action = 'moved to the trash';
2008
+				$hook = 'AHEE_event_moved_to_trash';
2009
+				break;
2010
+			default :
2011
+				$action = 'updated';
2012
+				$hook = false;
2013
+		}
2014
+		//use class to change status
2015
+		$this->_cpt_model_obj->set_status($event_status);
2016
+		$success = $this->_cpt_model_obj->save();
2017
+		if ($success === false) {
2018
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2019
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2020
+			return false;
2021
+		}
2022
+		if ($hook) {
2023
+			do_action($hook);
2024
+		}
2025
+		return true;
2026
+	}
2027
+
2028
+
2029
+
2030
+	/**
2031
+	 * _delete_event
2032
+	 *
2033
+	 * @access protected
2034
+	 * @param bool $redirect_after
2035
+	 */
2036
+	protected function _delete_event($redirect_after = true)
2037
+	{
2038
+		//determine the event id and set to array.
2039
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2040
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2041
+		// loop thru events
2042
+		if ($EVT_ID) {
2043
+			$success = $this->_permanently_delete_event($EVT_ID);
2044
+			// get list of events with no prices
2045
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2046
+			// remove this event from the list of events with no prices
2047
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2048
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2049
+			}
2050
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2051
+		} else {
2052
+			$success = false;
2053
+			$msg = esc_html__(
2054
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2055
+				'event_espresso'
2056
+			);
2057
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2058
+		}
2059
+		if ($redirect_after) {
2060
+			$this->_redirect_after_action(
2061
+				$success,
2062
+				'Event',
2063
+				'deleted',
2064
+				array('action' => 'default', 'status' => 'trash')
2065
+			);
2066
+		}
2067
+	}
2068
+
2069
+
2070
+
2071
+	/**
2072
+	 * _delete_events
2073
+	 *
2074
+	 * @access protected
2075
+	 * @return void
2076
+	 */
2077
+	protected function _delete_events()
2078
+	{
2079
+		$success = true;
2080
+		// get list of events with no prices
2081
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2082
+		//determine the event id and set to array.
2083
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2084
+		// loop thru events
2085
+		foreach ($EVT_IDs as $EVT_ID) {
2086
+			$EVT_ID = absint($EVT_ID);
2087
+			if ($EVT_ID) {
2088
+				$results = $this->_permanently_delete_event($EVT_ID);
2089
+				$success = $results !== false ? $success : false;
2090
+				// remove this event from the list of events with no prices
2091
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2092
+			} else {
2093
+				$success = false;
2094
+				$msg = esc_html__(
2095
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2096
+					'event_espresso'
2097
+				);
2098
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2099
+			}
2100
+		}
2101
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2102
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2103
+		$success = $success ? 2 : false;
2104
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2105
+	}
2106
+
2107
+
2108
+
2109
+	/**
2110
+	 * _permanently_delete_event
2111
+	 *
2112
+	 * @access  private
2113
+	 * @param  int $EVT_ID
2114
+	 * @return bool
2115
+	 */
2116
+	private function _permanently_delete_event($EVT_ID = 0)
2117
+	{
2118
+		// grab event id
2119
+		if ( ! $EVT_ID) {
2120
+			$msg = esc_html__(
2121
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2122
+				'event_espresso'
2123
+			);
2124
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2125
+			return false;
2126
+		}
2127
+		if (
2128
+			! $this->_cpt_model_obj instanceof EE_Event
2129
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2130
+		) {
2131
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2132
+		}
2133
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2134
+			return false;
2135
+		}
2136
+		//need to delete related tickets and prices first.
2137
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2138
+		foreach ($datetimes as $datetime) {
2139
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2140
+			$tickets = $datetime->get_many_related('Ticket');
2141
+			foreach ($tickets as $ticket) {
2142
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2143
+				$ticket->delete_related_permanently('Price');
2144
+				$ticket->delete_permanently();
2145
+			}
2146
+			$datetime->delete();
2147
+		}
2148
+		//what about related venues or terms?
2149
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2150
+		foreach ($venues as $venue) {
2151
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2152
+		}
2153
+		//any attached question groups?
2154
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2155
+		if ( ! empty($question_groups)) {
2156
+			foreach ($question_groups as $question_group) {
2157
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2158
+			}
2159
+		}
2160
+		//Message Template Groups
2161
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2162
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2163
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2164
+		foreach ($term_taxonomies as $term_taxonomy) {
2165
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2166
+		}
2167
+		$success = $this->_cpt_model_obj->delete_permanently();
2168
+		// did it all go as planned ?
2169
+		if ($success) {
2170
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2171
+			EE_Error::add_success($msg);
2172
+		} else {
2173
+			$msg = sprintf(
2174
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2175
+				$EVT_ID
2176
+			);
2177
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2178
+			return false;
2179
+		}
2180
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2181
+		return true;
2182
+	}
2183
+
2184
+
2185
+
2186
+	/**
2187
+	 * get total number of events
2188
+	 *
2189
+	 * @access public
2190
+	 * @return int
2191
+	 */
2192
+	public function total_events()
2193
+	{
2194
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2195
+		return $count;
2196
+	}
2197
+
2198
+
2199
+
2200
+	/**
2201
+	 * get total number of draft events
2202
+	 *
2203
+	 * @access public
2204
+	 * @return int
2205
+	 */
2206
+	public function total_events_draft()
2207
+	{
2208
+		$where = array(
2209
+			'status' => array('IN', array('draft', 'auto-draft')),
2210
+		);
2211
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2212
+		return $count;
2213
+	}
2214
+
2215
+
2216
+
2217
+	/**
2218
+	 * get total number of trashed events
2219
+	 *
2220
+	 * @access public
2221
+	 * @return int
2222
+	 */
2223
+	public function total_trashed_events()
2224
+	{
2225
+		$where = array(
2226
+			'status' => 'trash',
2227
+		);
2228
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2229
+		return $count;
2230
+	}
2231
+
2232
+
2233
+
2234
+	/**
2235
+	 *    _default_event_settings
2236
+	 *    This generates the Default Settings Tab
2237
+	 *
2238
+	 * @return void
2239
+	 */
2240
+	protected function _default_event_settings()
2241
+	{
2242
+		$this->_template_args['values'] = $this->_yes_no_values;
2243
+		$this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2244
+		// exclude array
2245
+			array(
2246
+				EEM_Registration::status_id_cancelled,
2247
+				EEM_Registration::status_id_declined,
2248
+				EEM_Registration::status_id_incomplete,
2249
+				EEM_Registration::status_id_wait_list,
2250
+			),
2251
+			// translated
2252
+			true
2253
+		);
2254
+		$this->_template_args['default_reg_status'] = isset(
2255
+														  EE_Registry::instance()->CFG->registration->default_STS_ID
2256
+													  )
2257
+													  && in_array(
2258
+														  EE_Registry::instance()->CFG->registration->default_STS_ID,
2259
+														  $this->_template_args['reg_status_array']
2260
+													  )
2261
+			? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2262
+			: EEM_Registration::status_id_pending_payment;
2263
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2264
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2265
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2266
+			EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2267
+			$this->_template_args,
2268
+			true
2269
+		);
2270
+		$this->display_admin_page_with_sidebar();
2271
+	}
2272
+
2273
+
2274
+
2275
+	/**
2276
+	 * _update_default_event_settings
2277
+	 *
2278
+	 * @access protected
2279
+	 * @return void
2280
+	 */
2281
+	protected function _update_default_event_settings()
2282
+	{
2283
+		EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2284
+			? sanitize_text_field($this->_req_data['default_reg_status'])
2285
+			: EEM_Registration::status_id_pending_payment;
2286
+		$what = 'Default Event Settings';
2287
+		$success = $this->_update_espresso_configuration(
2288
+			$what,
2289
+			EE_Config::instance(),
2290
+			__FILE__,
2291
+			__FUNCTION__,
2292
+			__LINE__
2293
+		);
2294
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2295
+	}
2296
+
2297
+
2298
+
2299
+	/*************        Templates        *************/
2300
+	protected function _template_settings()
2301
+	{
2302
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2303
+		$this->_template_args['preview_img'] = '<img src="'
2304
+											   . EVENTS_ASSETS_URL
2305
+											   . DS
2306
+											   . 'images'
2307
+											   . DS
2308
+											   . 'caffeinated_template_features.jpg" alt="'
2309
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2310
+											   . '" />';
2311
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2312
+				'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2313
+				'event_espresso'
2314
+			) . '</strong>';
2315
+		$this->display_admin_caf_preview_page('template_settings_tab');
2316
+	}
2317
+
2318
+
2319
+	/** Event Category Stuff **/
2320
+	/**
2321
+	 * set the _category property with the category object for the loaded page.
2322
+	 *
2323
+	 * @access private
2324
+	 * @return void
2325
+	 */
2326
+	private function _set_category_object()
2327
+	{
2328
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2329
+			return;
2330
+		} //already have the category object so get out.
2331
+		//set default category object
2332
+		$this->_set_empty_category_object();
2333
+		//only set if we've got an id
2334
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2335
+			return;
2336
+		}
2337
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2338
+		$term = get_term($category_id, 'espresso_event_categories');
2339
+		if ( ! empty($term)) {
2340
+			$this->_category->category_name = $term->name;
2341
+			$this->_category->category_identifier = $term->slug;
2342
+			$this->_category->category_desc = $term->description;
2343
+			$this->_category->id = $term->term_id;
2344
+			$this->_category->parent = $term->parent;
2345
+		}
2346
+	}
2347
+
2348
+
2349
+
2350
+	private function _set_empty_category_object()
2351
+	{
2352
+		$this->_category = new stdClass();
2353
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2354
+		$this->_category->id = $this->_category->parent = 0;
2355
+	}
2356
+
2357
+
2358
+
2359
+	protected function _category_list_table()
2360
+	{
2361
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2362
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2363
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2364
+				'add_category',
2365
+				'add_category',
2366
+				array(),
2367
+				'add-new-h2'
2368
+			);
2369
+		$this->display_admin_list_table_page_with_sidebar();
2370
+	}
2371
+
2372
+
2373
+
2374
+	/**
2375
+	 * @param $view
2376
+	 */
2377
+	protected function _category_details($view)
2378
+	{
2379
+		//load formatter helper
2380
+		//load field generator helper
2381
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2382
+		$this->_set_add_edit_form_tags($route);
2383
+		$this->_set_category_object();
2384
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2385
+		$delete_action = 'delete_category';
2386
+		//custom redirect
2387
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2388
+			array('action' => 'category_list'),
2389
+			$this->_admin_base_url
2390
+		);
2391
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2392
+		//take care of contents
2393
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2394
+		$this->display_admin_page_with_sidebar();
2395
+	}
2396
+
2397
+
2398
+
2399
+	/**
2400
+	 * @return mixed
2401
+	 */
2402
+	protected function _category_details_content()
2403
+	{
2404
+		$editor_args['category_desc'] = array(
2405
+			'type'          => 'wp_editor',
2406
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2407
+			'class'         => 'my_editor_custom',
2408
+			'wpeditor_args' => array('media_buttons' => false),
2409
+		);
2410
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2411
+		$all_terms = get_terms(
2412
+			array('espresso_event_categories'),
2413
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2414
+		);
2415
+		//setup category select for term parents.
2416
+		$category_select_values[] = array(
2417
+			'text' => esc_html__('No Parent', 'event_espresso'),
2418
+			'id'   => 0,
2419
+		);
2420
+		foreach ($all_terms as $term) {
2421
+			$category_select_values[] = array(
2422
+				'text' => $term->name,
2423
+				'id'   => $term->term_id,
2424
+			);
2425
+		}
2426
+		$category_select = EEH_Form_Fields::select_input(
2427
+			'category_parent',
2428
+			$category_select_values,
2429
+			$this->_category->parent
2430
+		);
2431
+		$template_args = array(
2432
+			'category'                 => $this->_category,
2433
+			'category_select'          => $category_select,
2434
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2435
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2436
+			'disable'                  => '',
2437
+			'disabled_message'         => false,
2438
+		);
2439
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2440
+		return EEH_Template::display_template($template, $template_args, true);
2441
+	}
2442
+
2443
+
2444
+
2445
+	protected function _delete_categories()
2446
+	{
2447
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2448
+			: (array)$this->_req_data['category_id'];
2449
+		foreach ($cat_ids as $cat_id) {
2450
+			$this->_delete_category($cat_id);
2451
+		}
2452
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2453
+		$query_args = array(
2454
+			'action' => 'category_list',
2455
+		);
2456
+		$this->_redirect_after_action(0, '', '', $query_args);
2457
+	}
2458
+
2459
+
2460
+
2461
+	/**
2462
+	 * @param $cat_id
2463
+	 */
2464
+	protected function _delete_category($cat_id)
2465
+	{
2466
+		$cat_id = absint($cat_id);
2467
+		wp_delete_term($cat_id, 'espresso_event_categories');
2468
+	}
2469
+
2470
+
2471
+
2472
+	/**
2473
+	 * @param $new_category
2474
+	 */
2475
+	protected function _insert_or_update_category($new_category)
2476
+	{
2477
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2478
+		$success = 0; //we already have a success message so lets not send another.
2479
+		if ($cat_id) {
2480
+			$query_args = array(
2481
+				'action'     => 'edit_category',
2482
+				'EVT_CAT_ID' => $cat_id,
2483
+			);
2484
+		} else {
2485
+			$query_args = array('action' => 'add_category');
2486
+		}
2487
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2488
+	}
2489
+
2490
+
2491
+
2492
+	/**
2493
+	 * @param bool $update
2494
+	 * @return bool|mixed|string
2495
+	 */
2496
+	private function _insert_category($update = false)
2497
+	{
2498
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2499
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2500
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2501
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2502
+		if (empty($category_name)) {
2503
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2504
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2505
+			return false;
2506
+		}
2507
+		$term_args = array(
2508
+			'name'        => $category_name,
2509
+			'description' => $category_desc,
2510
+			'parent'      => $category_parent,
2511
+		);
2512
+		//was the category_identifier input disabled?
2513
+		if (isset($this->_req_data['category_identifier'])) {
2514
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2515
+		}
2516
+		$insert_ids = $update
2517
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2518
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2519
+		if ( ! is_array($insert_ids)) {
2520
+			$msg = esc_html__(
2521
+				'An error occurred and the category has not been saved to the database.',
2522
+				'event_espresso'
2523
+			);
2524
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2525
+		} else {
2526
+			$cat_id = $insert_ids['term_id'];
2527
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2528
+			EE_Error::add_success($msg);
2529
+		}
2530
+		return $cat_id;
2531
+	}
2532
+
2533
+
2534
+
2535
+	/**
2536
+	 * @param int  $per_page
2537
+	 * @param int  $current_page
2538
+	 * @param bool $count
2539
+	 * @return \EE_Base_Class[]|int
2540
+	 */
2541
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2542
+	{
2543
+		//testing term stuff
2544
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2545
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2546
+		$limit = ($current_page - 1) * $per_page;
2547
+		$where = array('taxonomy' => 'espresso_event_categories');
2548
+		if (isset($this->_req_data['s'])) {
2549
+			$sstr = '%' . $this->_req_data['s'] . '%';
2550
+			$where['OR'] = array(
2551
+				'Term.name'   => array('LIKE', $sstr),
2552
+				'description' => array('LIKE', $sstr),
2553
+			);
2554
+		}
2555
+		$query_params = array(
2556
+			$where,
2557
+			'order_by'   => array($orderby => $order),
2558
+			'limit'      => $limit . ',' . $per_page,
2559
+			'force_join' => array('Term'),
2560
+		);
2561
+		$categories = $count
2562
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2563
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2564
+		return $categories;
2565
+	}
2566
+
2567
+
2568
+
2569
+	/* end category stuff */
2570
+	/**************/
2571 2571
 }
2572 2572
 //end class Events_Admin_Page
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -531,11 +531,11 @@  discard block
 block discarded – undo
531 531
     {
532 532
         wp_register_style(
533 533
             'events-admin-css',
534
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
534
+            EVENTS_ASSETS_URL.'events-admin-page.css',
535 535
             array(),
536 536
             EVENT_ESPRESSO_VERSION
537 537
         );
538
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
538
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539 539
         wp_enqueue_style('events-admin-css');
540 540
         wp_enqueue_style('ee-cat-admin');
541 541
         //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
         //scripts
544 544
         wp_register_script(
545 545
             'event_editor_js',
546
-            EVENTS_ASSETS_URL . 'event_editor.js',
546
+            EVENTS_ASSETS_URL.'event_editor.js',
547 547
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
548 548
             EVENT_ESPRESSO_VERSION,
549 549
             true
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
         wp_enqueue_style('espresso-ui-theme');
576 576
         wp_register_style(
577 577
             'event-editor-css',
578
-            EVENTS_ASSETS_URL . 'event-editor.css',
578
+            EVENTS_ASSETS_URL.'event-editor.css',
579 579
             array('ee-admin-css'),
580 580
             EVENT_ESPRESSO_VERSION
581 581
         );
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
         //scripts
584 584
         wp_register_script(
585 585
             'event-datetime-metabox',
586
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
586
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
587 587
             array('event_editor_js', 'ee-datepicker'),
588 588
             EVENT_ESPRESSO_VERSION
589 589
         );
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
                         'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
750 750
                         'event_espresso'
751 751
                     ),
752
-                    '<a href="' . admin_url('options-general.php') . '">',
752
+                    '<a href="'.admin_url('options-general.php').'">',
753 753
                     '</a>'
754 754
                 ),
755 755
                 __FILE__,
@@ -819,31 +819,31 @@  discard block
 block discarded – undo
819 819
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
820 820
         $statuses = array(
821 821
             'sold_out_status'  => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
822
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
823 823
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
824 824
             ),
825 825
             'active_status'    => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
826
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
827 827
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
828 828
             ),
829 829
             'upcoming_status'  => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
830
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
831 831
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
832 832
             ),
833 833
             'postponed_status' => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
834
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
835 835
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
836 836
             ),
837 837
             'cancelled_status' => array(
838
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
838
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
839 839
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
840 840
             ),
841 841
             'expired_status'   => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
842
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
843 843
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
844 844
             ),
845 845
             'inactive_status'  => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
846
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
847 847
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
848 848
             ),
849 849
         );
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
             'button'
912 912
         );
913 913
         $this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items());
914
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
914
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
915 915
                 'create_new',
916 916
                 'add',
917 917
                 array(),
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
      */
1031 1031
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1032 1032
     {
1033
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1033
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1034 1034
         $venue_model = EE_Registry::instance()->load_model('Venue');
1035 1035
         $rows_affected = null;
1036 1036
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1154,7 +1154,7 @@  discard block
 block discarded – undo
1154 1154
             if (empty($tkt['TKT_start_date'])) {
1155 1155
                 //let's use now in the set timezone.
1156 1156
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1157
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1157
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1158 1158
             }
1159 1159
             if (empty($tkt['TKT_end_date'])) {
1160 1160
                 //use the start date of the first datetime
@@ -1443,7 +1443,7 @@  discard block
 block discarded – undo
1443 1443
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1444 1444
         // load template
1445 1445
         EEH_Template::display_template(
1446
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1446
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1447 1447
             $publish_box_extra_args
1448 1448
         );
1449 1449
     }
@@ -1570,7 +1570,7 @@  discard block
 block discarded – undo
1570 1570
         );
1571 1571
         $template = apply_filters(
1572 1572
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1573
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1573
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1574 1574
         );
1575 1575
         EEH_Template::display_template($template, $template_args);
1576 1576
     }
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1590 1590
     {
1591 1591
         $template_args = array(
1592
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1592
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1593 1593
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1594 1594
                 : '',
1595 1595
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1643,7 +1643,7 @@  discard block
 block discarded – undo
1643 1643
         $template_args = array_merge($template_args, $price_args);
1644 1644
         $template = apply_filters(
1645 1645
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1646
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1646
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1647 1647
             $ticket
1648 1648
         );
1649 1649
         return EEH_Template::display_template($template, $template_args, true);
@@ -1695,7 +1695,7 @@  discard block
 block discarded – undo
1695 1695
             $default_reg_status_values
1696 1696
         );
1697 1697
         EEH_Template::display_template(
1698
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1698
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1699 1699
             $template_args
1700 1700
         );
1701 1701
     }
@@ -1718,7 +1718,7 @@  discard block
 block discarded – undo
1718 1718
     {
1719 1719
         $EEME = $this->_event_model();
1720 1720
         $offset = ($current_page - 1) * $per_page;
1721
-        $limit = $count ? null : $offset . ',' . $per_page;
1721
+        $limit = $count ? null : $offset.','.$per_page;
1722 1722
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1723 1723
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1724 1724
         if (isset($this->_req_data['month_range'])) {
@@ -1752,7 +1752,7 @@  discard block
 block discarded – undo
1752 1752
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1753 1753
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1754 1754
             $DateTime = new DateTime(
1755
-                $year_r . '-' . $month_r . '-01 00:00:00',
1755
+                $year_r.'-'.$month_r.'-01 00:00:00',
1756 1756
                 new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1757 1757
             );
1758 1758
             $start = $DateTime->format(implode(' ', $start_formats));
@@ -1798,7 +1798,7 @@  discard block
 block discarded – undo
1798 1798
         }
1799 1799
         //search query handling
1800 1800
         if (isset($this->_req_data['s'])) {
1801
-            $search_string = '%' . $this->_req_data['s'] . '%';
1801
+            $search_string = '%'.$this->_req_data['s'].'%';
1802 1802
             $where['OR'] = array(
1803 1803
                 'EVT_name'       => array('LIKE', $search_string),
1804 1804
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1932,7 +1932,7 @@  discard block
 block discarded – undo
1932 1932
         if ( ! empty($event_status)) {
1933 1933
             $success = true;
1934 1934
             //determine the event id and set to array.
1935
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1935
+            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1936 1936
             // loop thru events
1937 1937
             foreach ($EVT_IDs as $EVT_ID) {
1938 1938
                 if ($EVT_ID = absint($EVT_ID)) {
@@ -2080,7 +2080,7 @@  discard block
 block discarded – undo
2080 2080
         // get list of events with no prices
2081 2081
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2082 2082
         //determine the event id and set to array.
2083
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2083
+        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2084 2084
         // loop thru events
2085 2085
         foreach ($EVT_IDs as $EVT_ID) {
2086 2086
             $EVT_ID = absint($EVT_ID);
@@ -2263,7 +2263,7 @@  discard block
 block discarded – undo
2263 2263
         $this->_set_add_edit_form_tags('update_default_event_settings');
2264 2264
         $this->_set_publish_post_box_vars(null, false, false, null, false);
2265 2265
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2266
-            EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2266
+            EVENTS_TEMPLATE_PATH.'event_settings.template.php',
2267 2267
             $this->_template_args,
2268 2268
             true
2269 2269
         );
@@ -2308,10 +2308,10 @@  discard block
 block discarded – undo
2308 2308
                                                . 'caffeinated_template_features.jpg" alt="'
2309 2309
                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2310 2310
                                                . '" />';
2311
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2311
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__(
2312 2312
                 'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2313 2313
                 'event_espresso'
2314
-            ) . '</strong>';
2314
+            ).'</strong>';
2315 2315
         $this->display_admin_caf_preview_page('template_settings_tab');
2316 2316
     }
2317 2317
 
@@ -2360,7 +2360,7 @@  discard block
 block discarded – undo
2360 2360
     {
2361 2361
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2362 2362
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2363
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2363
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2364 2364
                 'add_category',
2365 2365
                 'add_category',
2366 2366
                 array(),
@@ -2436,7 +2436,7 @@  discard block
 block discarded – undo
2436 2436
             'disable'                  => '',
2437 2437
             'disabled_message'         => false,
2438 2438
         );
2439
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2439
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2440 2440
         return EEH_Template::display_template($template, $template_args, true);
2441 2441
     }
2442 2442
 
@@ -2444,8 +2444,8 @@  discard block
 block discarded – undo
2444 2444
 
2445 2445
     protected function _delete_categories()
2446 2446
     {
2447
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2448
-            : (array)$this->_req_data['category_id'];
2447
+        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2448
+            : (array) $this->_req_data['category_id'];
2449 2449
         foreach ($cat_ids as $cat_id) {
2450 2450
             $this->_delete_category($cat_id);
2451 2451
         }
@@ -2546,7 +2546,7 @@  discard block
 block discarded – undo
2546 2546
         $limit = ($current_page - 1) * $per_page;
2547 2547
         $where = array('taxonomy' => 'espresso_event_categories');
2548 2548
         if (isset($this->_req_data['s'])) {
2549
-            $sstr = '%' . $this->_req_data['s'] . '%';
2549
+            $sstr = '%'.$this->_req_data['s'].'%';
2550 2550
             $where['OR'] = array(
2551 2551
                 'Term.name'   => array('LIKE', $sstr),
2552 2552
                 'description' => array('LIKE', $sstr),
@@ -2555,7 +2555,7 @@  discard block
 block discarded – undo
2555 2555
         $query_params = array(
2556 2556
             $where,
2557 2557
             'order_by'   => array($orderby => $order),
2558
-            'limit'      => $limit . ',' . $per_page,
2558
+            'limit'      => $limit.','.$per_page,
2559 2559
             'force_join' => array('Term'),
2560 2560
         );
2561 2561
         $categories = $count
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1348 added lines, -1348 removed lines patch added patch discarded remove patch
@@ -13,1354 +13,1354 @@
 block discarded – undo
13 13
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
14 14
 {
15 15
 
16
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
17
-
18
-    /**
19
-     * Subsections
20
-     *
21
-     * @var EE_Form_Section_Validatable[]
22
-     */
23
-    protected $_subsections = array();
24
-
25
-    /**
26
-     * Strategy for laying out the form
27
-     *
28
-     * @var EE_Form_Section_Layout_Base
29
-     */
30
-    protected $_layout_strategy;
31
-
32
-    /**
33
-     * Whether or not this form has received and validated a form submission yet
34
-     *
35
-     * @var boolean
36
-     */
37
-    protected $_received_submission = false;
38
-
39
-    /**
40
-     * message displayed to users upon successful form submission
41
-     *
42
-     * @var string
43
-     */
44
-    protected $_form_submission_success_message = '';
45
-
46
-    /**
47
-     * message displayed to users upon unsuccessful form submission
48
-     *
49
-     * @var string
50
-     */
51
-    protected $_form_submission_error_message = '';
52
-
53
-    /**
54
-     * Stores all the data that will localized for form validation
55
-     *
56
-     * @var array
57
-     */
58
-    static protected $_js_localization = array();
59
-
60
-    /**
61
-     * whether or not the form's localized validation JS vars have been set
62
-     *
63
-     * @type boolean
64
-     */
65
-    static protected $_scripts_localized = false;
66
-
67
-
68
-
69
-    /**
70
-     * when constructing a proper form section, calls _construct_finalize on children
71
-     * so that they know who their parent is, and what name they've been given.
72
-     *
73
-     * @param array $options_array   {
74
-     * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
75
-     * @type        $include         string[] numerically-indexed where values are section names to be included,
76
-     *                               and in that order. This is handy if you want
77
-     *                               the subsections to be ordered differently than the default, and if you override
78
-     *                               which fields are shown
79
-     * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
80
-     *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
81
-     *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
82
-     *                               items from that list of inclusions)
83
-     * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
84
-     *                               } @see EE_Form_Section_Validatable::__construct()
85
-     * @throws \EE_Error
86
-     */
87
-    public function __construct($options_array = array())
88
-    {
89
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
90
-            $this);
91
-        //call parent first, as it may be setting the name
92
-        parent::__construct($options_array);
93
-        //if they've included subsections in the constructor, add them now
94
-        if (isset($options_array['include'])) {
95
-            //we are going to make sure we ONLY have those subsections to include
96
-            //AND we are going to make sure they're in that specified order
97
-            $reordered_subsections = array();
98
-            foreach ($options_array['include'] as $input_name) {
99
-                if (isset($this->_subsections[$input_name])) {
100
-                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
101
-                }
102
-            }
103
-            $this->_subsections = $reordered_subsections;
104
-        }
105
-        if (isset($options_array['exclude'])) {
106
-            $exclude = $options_array['exclude'];
107
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
108
-        }
109
-        if (isset($options_array['layout_strategy'])) {
110
-            $this->_layout_strategy = $options_array['layout_strategy'];
111
-        }
112
-        if ( ! $this->_layout_strategy) {
113
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
114
-        }
115
-        $this->_layout_strategy->_construct_finalize($this);
116
-        //ok so we are definitely going to want the forms JS,
117
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
118
-        if (did_action('wp_enqueue_scripts')
119
-            || did_action('admin_enqueue_scripts')
120
-        ) {
121
-            //ok so they've constructed this object after when they should have.
122
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
123
-            \EE_Form_Section_Proper::wp_enqueue_scripts(true);
124
-        } else {
125
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
126
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
127
-        }
128
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
129
-        if (isset($options_array['name'])) {
130
-            $this->_construct_finalize(null, $options_array['name']);
131
-        }
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * Finishes construction given the parent form section and this form section's name
138
-     *
139
-     * @param EE_Form_Section_Proper $parent_form_section
140
-     * @param string                 $name
141
-     * @throws \EE_Error
142
-     */
143
-    public function _construct_finalize($parent_form_section, $name)
144
-    {
145
-        parent::_construct_finalize($parent_form_section, $name);
146
-        $this->_set_default_name_if_empty();
147
-        $this->_set_default_html_id_if_empty();
148
-        foreach ($this->_subsections as $subsection_name => $subsection) {
149
-            if ($subsection instanceof EE_Form_Section_Base) {
150
-                $subsection->_construct_finalize($this, $subsection_name);
151
-            } else {
152
-                throw new EE_Error(
153
-                    sprintf(
154
-                        __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
155
-                            'event_espresso'),
156
-                        $subsection_name,
157
-                        get_class($this),
158
-                        $subsection ? get_class($subsection) : __('NULL', 'event_espresso')
159
-                    )
160
-                );
161
-            }
162
-        }
163
-        do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * Gets the layout strategy for this form section
170
-     *
171
-     * @return EE_Form_Section_Layout_Base
172
-     */
173
-    public function get_layout_strategy()
174
-    {
175
-        return $this->_layout_strategy;
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * Gets the HTML for a single input for this form section according
182
-     * to the layout strategy
183
-     *
184
-     * @param EE_Form_Input_Base $input
185
-     * @return string
186
-     */
187
-    public function get_html_for_input($input)
188
-    {
189
-        return $this->_layout_strategy->layout_input($input);
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     * was_submitted - checks if form inputs are present in request data
196
-     * Basically an alias for form_data_present_in() (which is used by both
197
-     * proper form sections and form inputs)
198
-     *
199
-     * @param null $form_data
200
-     * @return boolean
201
-     */
202
-    public function was_submitted($form_data = null)
203
-    {
204
-        return $this->form_data_present_in($form_data);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * After the form section is initially created, call this to sanitize the data in the submission
211
-     * which relates to this form section, validate it, and set it as properties on the form.
212
-     *
213
-     * @param array|null $req_data should usually be $_POST (the default).
214
-     *                             However, you CAN supply a different array.
215
-     *                             Consider using set_defaults() instead however.
216
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
217
-     *                             the inputs will have the correct name in the request data for this function
218
-     *                             to find them and populate the form with them.
219
-     *                             If you have a flat form (with only input subsections),
220
-     *                             you can supply a flat array where keys
221
-     *                             are the form input names and values are their values)
222
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
223
-     *                             of course, to validate that data, and set errors on the invalid values.
224
-     *                             But if the data has already been validated
225
-     *                             (eg you validated the data then stored it in the DB)
226
-     *                             you may want to skip this step.
227
-     */
228
-    public function receive_form_submission($req_data = null, $validate = true)
229
-    {
230
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
231
-            $validate);
232
-        if ($req_data === null) {
233
-            $req_data = array_merge($_GET, $_POST);
234
-        }
235
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
236
-            $this);
237
-        $this->_normalize($req_data);
238
-        if ($validate) {
239
-            $this->_validate();
240
-            //if it's invalid, we're going to want to re-display so remember what they submitted
241
-            if ( ! $this->is_valid()) {
242
-                $this->store_submitted_form_data_in_session();
243
-            }
244
-        }
245
-        do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * caches the originally submitted input values in the session
252
-     * so that they can be used to repopulate the form if it failed validation
253
-     *
254
-     * @return boolean whether or not the data was successfully stored in the session
255
-     */
256
-    protected function store_submitted_form_data_in_session()
257
-    {
258
-        return EE_Registry::instance()->SSN->set_session_data(
259
-            array(
260
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
261
-            )
262
-        );
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * retrieves the originally submitted input values in the session
269
-     * so that they can be used to repopulate the form if it failed validation
270
-     *
271
-     * @return array
272
-     */
273
-    protected function get_submitted_form_data_from_session()
274
-    {
275
-        $session = EE_Registry::instance()->SSN;
276
-        if ($session instanceof EE_Session) {
277
-            return $session->get_session_data(
278
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
279
-            );
280
-        } else {
281
-            return array();
282
-        }
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * flushed the originally submitted input values from the session
289
-     *
290
-     * @return boolean whether or not the data was successfully removed from the session
291
-     */
292
-    protected function flush_submitted_form_data_from_session()
293
-    {
294
-        return EE_Registry::instance()->SSN->reset_data(
295
-            array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
296
-        );
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * Populates this form and its subsections with data from the session.
303
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
304
-     * validation errors when displaying too)
305
-     * Returns true if the form was populated from the session, false otherwise
306
-     *
307
-     * @return boolean
308
-     */
309
-    public function populate_from_session()
310
-    {
311
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
312
-        if (empty($form_data_in_session)) {
313
-            return false;
314
-        }
315
-        $this->receive_form_submission($form_data_in_session);
316
-        $this->flush_submitted_form_data_from_session();
317
-        if ($this->form_data_present_in($form_data_in_session)) {
318
-            return true;
319
-        } else {
320
-            return false;
321
-        }
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * Populates the default data for the form, given an array where keys are
328
-     * the input names, and values are their values (preferably normalized to be their
329
-     * proper PHP types, not all strings... although that should be ok too).
330
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
331
-     * the value being an array formatted in teh same way
332
-     *
333
-     * @param array $default_data
334
-     */
335
-    public function populate_defaults($default_data)
336
-    {
337
-        foreach ($this->subsections() as $subsection_name => $subsection) {
338
-            if (isset($default_data[$subsection_name])) {
339
-                if ($subsection instanceof EE_Form_Input_Base) {
340
-                    $subsection->set_default($default_data[$subsection_name]);
341
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
342
-                    $subsection->populate_defaults($default_data[$subsection_name]);
343
-                }
344
-            }
345
-        }
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * returns true if subsection exists
352
-     *
353
-     * @param string $name
354
-     * @return boolean
355
-     */
356
-    public function subsection_exists($name)
357
-    {
358
-        return isset($this->_subsections[$name]) ? true : false;
359
-    }
360
-
361
-
362
-
363
-    /**
364
-     * Gets the subsection specified by its name
365
-     *
366
-     * @param string  $name
367
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
368
-     *                                                      so that the inputs will be properly configured.
369
-     *                                                      However, some client code may be ok
370
-     *                                                      with construction finalize being called later
371
-     *                                                      (realizing that the subsections' html names
372
-     *                                                      might not be set yet, etc.)
373
-     * @return EE_Form_Section_Base
374
-     * @throws \EE_Error
375
-     */
376
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
377
-    {
378
-        if ($require_construction_to_be_finalized) {
379
-            $this->ensure_construct_finalized_called();
380
-        }
381
-        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     * Gets all the validatable subsections of this form section
388
-     *
389
-     * @return EE_Form_Section_Validatable[]
390
-     */
391
-    public function get_validatable_subsections()
392
-    {
393
-        $validatable_subsections = array();
394
-        foreach ($this->subsections() as $name => $obj) {
395
-            if ($obj instanceof EE_Form_Section_Validatable) {
396
-                $validatable_subsections[$name] = $obj;
397
-            }
398
-        }
399
-        return $validatable_subsections;
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
406
-     * throw an EE_Error.
407
-     *
408
-     * @param string  $name
409
-     * @param boolean $require_construction_to_be_finalized most client code should
410
-     *                                                      leave this as TRUE so that the inputs will be properly
411
-     *                                                      configured. However, some client code may be ok with
412
-     *                                                      construction finalize being called later
413
-     *                                                      (realizing that the subsections' html names might not be
414
-     *                                                      set yet, etc.)
415
-     * @return EE_Form_Input_Base
416
-     * @throws EE_Error
417
-     */
418
-    public function get_input($name, $require_construction_to_be_finalized = true)
419
-    {
420
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
421
-        if ( ! $subsection instanceof EE_Form_Input_Base) {
422
-            throw new EE_Error(
423
-                sprintf(
424
-                    __(
425
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
426
-                        'event_espresso'
427
-                    ),
428
-                    $name,
429
-                    get_class($this),
430
-                    $subsection ? get_class($subsection) : __("NULL", 'event_espresso')
431
-                )
432
-            );
433
-        }
434
-        return $subsection;
435
-    }
436
-
437
-
438
-
439
-    /**
440
-     * Like get_input(), gets the proper subsection of the form given the name,
441
-     * otherwise throws an EE_Error
442
-     *
443
-     * @param string  $name
444
-     * @param boolean $require_construction_to_be_finalized most client code should
445
-     *                                                      leave this as TRUE so that the inputs will be properly
446
-     *                                                      configured. However, some client code may be ok with
447
-     *                                                      construction finalize being called later
448
-     *                                                      (realizing that the subsections' html names might not be
449
-     *                                                      set yet, etc.)
450
-     * @return EE_Form_Section_Proper
451
-     * @throws EE_Error
452
-     */
453
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
454
-    {
455
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
456
-        if ( ! $subsection instanceof EE_Form_Section_Proper) {
457
-            throw new EE_Error(
458
-                sprintf(
459
-                    __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
460
-                    $name,
461
-                    get_class($this)
462
-                )
463
-            );
464
-        }
465
-        return $subsection;
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     * Gets the value of the specified input. Should be called after receive_form_submission()
472
-     * or populate_defaults() on the form, where the normalized value on the input is set.
473
-     *
474
-     * @param string $name
475
-     * @return mixed depending on the input's type and its normalization strategy
476
-     * @throws \EE_Error
477
-     */
478
-    public function get_input_value($name)
479
-    {
480
-        $input = $this->get_input($name);
481
-        return $input->normalized_value();
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * Checks if this form section itself is valid, and then checks its subsections
488
-     *
489
-     * @throws EE_Error
490
-     * @return boolean
491
-     */
492
-    public function is_valid()
493
-    {
494
-        if ( ! $this->has_received_submission()) {
495
-            throw new EE_Error(
496
-                sprintf(
497
-                    __(
498
-                        "You cannot check if a form is valid before receiving the form submission using receive_form_submission",
499
-                        "event_espresso"
500
-                    )
501
-                )
502
-            );
503
-        }
504
-        if ( ! parent::is_valid()) {
505
-            return false;
506
-        }
507
-        // ok so no general errors to this entire form section.
508
-        // so let's check the subsections, but only set errors if that hasn't been done yet
509
-        $set_submission_errors = $this->submission_error_message() === '' ? true : false;
510
-        foreach ($this->get_validatable_subsections() as $subsection) {
511
-            if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
512
-                if ($set_submission_errors) {
513
-                    $this->set_submission_error_message($subsection->get_validation_error_string());
514
-                }
515
-                return false;
516
-            }
517
-        }
518
-        return true;
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     * gets teh default name of this form section if none is specified
525
-     *
526
-     * @return string
527
-     */
528
-    protected function _set_default_name_if_empty()
529
-    {
530
-        if ( ! $this->_name) {
531
-            $classname = get_class($this);
532
-            $default_name = str_replace("EE_", "", $classname);
533
-            $this->_name = $default_name;
534
-        }
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * Returns the HTML for the form, except for the form opening and closing tags
541
-     * (as the form section doesn't know where you necessarily want to send the information to),
542
-     * and except for a submit button. Enqueus JS and CSS; if called early enough we will
543
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
544
-     * Not doing_it_wrong because theoretically this CAN be used properly,
545
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
546
-     * any CSS.
547
-     *
548
-     * @throws \EE_Error
549
-     */
550
-    public function get_html_and_js()
551
-    {
552
-        $this->enqueue_js();
553
-        return $this->get_html();
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
560
-     *
561
-     * @param bool $display_previously_submitted_data
562
-     * @return string
563
-     */
564
-    public function get_html($display_previously_submitted_data = true)
565
-    {
566
-        $this->ensure_construct_finalized_called();
567
-        if ($display_previously_submitted_data) {
568
-            $this->populate_from_session();
569
-        }
570
-        return $this->_layout_strategy->layout_form();
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * enqueues JS and CSS for the form.
577
-     * It is preferred to call this before wp_enqueue_scripts so the
578
-     * scripts and styles can be put in the header, but if called later
579
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
580
-     * only be in the header; but in HTML5 its ok in the body.
581
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
582
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
583
-     *
584
-     * @return string
585
-     * @throws \EE_Error
586
-     */
587
-    public function enqueue_js()
588
-    {
589
-        $this->_enqueue_and_localize_form_js();
590
-        foreach ($this->subsections() as $subsection) {
591
-            $subsection->enqueue_js();
592
-        }
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
599
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
600
-     * the wp_enqueue_scripts hook.
601
-     * However, registering the form js and localizing it can happen when we
602
-     * actually output the form (which is preferred, seeing how teh form's fields
603
-     * could change until it's actually outputted)
604
-     *
605
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
606
-     *                                                    to be triggered automatically or not
607
-     * @return void
608
-     */
609
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
610
-    {
611
-        add_filter('FHEE_load_jquery_validate', '__return_true');
612
-        wp_register_script(
613
-            'ee_form_section_validation',
614
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
615
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
616
-            EVENT_ESPRESSO_VERSION,
617
-            true
618
-        );
619
-        wp_localize_script(
620
-            'ee_form_section_validation',
621
-            'ee_form_section_validation_init',
622
-            array('init' => $init_form_validation_automatically ? true : false)
623
-        );
624
-    }
625
-
626
-
627
-
628
-    /**
629
-     * gets the variables used by form_section_validation.js.
630
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
631
-     * but before the wordpress hook wp_loaded
632
-     *
633
-     * @throws \EE_Error
634
-     */
635
-    public function _enqueue_and_localize_form_js()
636
-    {
637
-        $this->ensure_construct_finalized_called();
638
-        //actually, we don't want to localize just yet. There may be other forms on the page.
639
-        //so we need to add our form section data to a static variable accessible by all form sections
640
-        //and localize it just before the footer
641
-        $this->localize_validation_rules();
642
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
643
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * add our form section data to a static variable accessible by all form sections
650
-     *
651
-     * @param bool $return_for_subsection
652
-     * @return void
653
-     * @throws \EE_Error
654
-     */
655
-    public function localize_validation_rules($return_for_subsection = false)
656
-    {
657
-        // we only want to localize vars ONCE for the entire form,
658
-        // so if the form section doesn't have a parent, then it must be the top dog
659
-        if ($return_for_subsection || ! $this->parent_section()) {
660
-            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
661
-                'form_section_id'  => $this->html_id(true),
662
-                'validation_rules' => $this->get_jquery_validation_rules(),
663
-                'other_data'       => $this->get_other_js_data(),
664
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
665
-            );
666
-            EE_Form_Section_Proper::$_scripts_localized = true;
667
-        }
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * Gets an array of extra data that will be useful for client-side javascript.
674
-     * This is primarily data added by inputs and forms in addition to any
675
-     * scripts they might enqueue
676
-     *
677
-     * @param array $form_other_js_data
678
-     * @return array
679
-     */
680
-    public function get_other_js_data($form_other_js_data = array())
681
-    {
682
-        foreach ($this->subsections() as $subsection) {
683
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
684
-        }
685
-        return $form_other_js_data;
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * Gets a flat array of inputs for this form section and its subsections.
692
-     * Keys are their form names, and values are the inputs themselves
693
-     *
694
-     * @return EE_Form_Input_Base
695
-     */
696
-    public function inputs_in_subsections()
697
-    {
698
-        $inputs = array();
699
-        foreach ($this->subsections() as $subsection) {
700
-            if ($subsection instanceof EE_Form_Input_Base) {
701
-                $inputs[$subsection->html_name()] = $subsection;
702
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
703
-                $inputs += $subsection->inputs_in_subsections();
704
-            }
705
-        }
706
-        return $inputs;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * Gets a flat array of all the validation errors.
713
-     * Keys are html names (because those should be unique)
714
-     * and values are a string of all their validation errors
715
-     *
716
-     * @return string[]
717
-     */
718
-    public function subsection_validation_errors_by_html_name()
719
-    {
720
-        $inputs = $this->inputs();
721
-        $errors = array();
722
-        foreach ($inputs as $form_input) {
723
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
724
-                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
725
-            }
726
-        }
727
-        return $errors;
728
-    }
729
-
730
-
731
-
732
-    /**
733
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
734
-     * Should be setup by each form during the _enqueues_and_localize_form_js
735
-     */
736
-    public static function localize_script_for_all_forms()
737
-    {
738
-        //allow inputs and stuff to hook in their JS and stuff here
739
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
740
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
741
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
742
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
743
-            : 'wp_default';
744
-        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
745
-        wp_enqueue_script('ee_form_section_validation');
746
-        wp_localize_script(
747
-            'ee_form_section_validation',
748
-            'ee_form_section_vars',
749
-            EE_Form_Section_Proper::$_js_localization
750
-        );
751
-    }
752
-
753
-
754
-
755
-    /**
756
-     * ensure_scripts_localized
757
-     */
758
-    public function ensure_scripts_localized()
759
-    {
760
-        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
761
-            $this->_enqueue_and_localize_form_js();
762
-        }
763
-    }
764
-
765
-
766
-
767
-    /**
768
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
769
-     * is that the key here should be the same as the custom validation rule put in the JS file
770
-     *
771
-     * @return array keys are custom validation rules, and values are internationalized strings
772
-     */
773
-    private static function _get_localized_error_messages()
774
-    {
775
-        return array(
776
-            'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
777
-            'regex'    => __('Please check your input', 'event_espresso'),
778
-        );
779
-    }
780
-
781
-
782
-
783
-    /**
784
-     * @return array
785
-     */
786
-    public static function js_localization()
787
-    {
788
-        return self::$_js_localization;
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     * @return array
795
-     */
796
-    public static function reset_js_localization()
797
-    {
798
-        self::$_js_localization = array();
799
-    }
800
-
801
-
802
-
803
-    /**
804
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
805
-     * See parent function for more...
806
-     *
807
-     * @return array
808
-     */
809
-    public function get_jquery_validation_rules()
810
-    {
811
-        $jquery_validation_rules = array();
812
-        foreach ($this->get_validatable_subsections() as $subsection) {
813
-            $jquery_validation_rules = array_merge(
814
-                $jquery_validation_rules,
815
-                $subsection->get_jquery_validation_rules()
816
-            );
817
-        }
818
-        return $jquery_validation_rules;
819
-    }
820
-
821
-
822
-
823
-    /**
824
-     * Sanitizes all the data and sets the sanitized value of each field
825
-     *
826
-     * @param array $req_data like $_POST
827
-     * @return void
828
-     */
829
-    protected function _normalize($req_data)
830
-    {
831
-        $this->_received_submission = true;
832
-        $this->_validation_errors = array();
833
-        foreach ($this->get_validatable_subsections() as $subsection) {
834
-            try {
835
-                $subsection->_normalize($req_data);
836
-            } catch (EE_Validation_Error $e) {
837
-                $subsection->add_validation_error($e);
838
-            }
839
-        }
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * Performs validation on this form section and its subsections.
846
-     * For each subsection,
847
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
848
-     * and passes it the subsection, then calls _validate on that subsection.
849
-     * If you need to perform validation on the form as a whole (considering multiple)
850
-     * you would be best to override this _validate method,
851
-     * calling parent::_validate() first.
852
-     */
853
-    protected function _validate()
854
-    {
855
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
856
-            if (method_exists($this, '_validate_' . $subsection_name)) {
857
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
858
-            }
859
-            $subsection->_validate();
860
-        }
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * Gets all the validated inputs for the form section
867
-     *
868
-     * @return array
869
-     */
870
-    public function valid_data()
871
-    {
872
-        $inputs = array();
873
-        foreach ($this->subsections() as $subsection_name => $subsection) {
874
-            if ($subsection instanceof EE_Form_Section_Proper) {
875
-                $inputs[$subsection_name] = $subsection->valid_data();
876
-            } else if ($subsection instanceof EE_Form_Input_Base) {
877
-                $inputs[$subsection_name] = $subsection->normalized_value();
878
-            }
879
-        }
880
-        return $inputs;
881
-    }
882
-
883
-
884
-
885
-    /**
886
-     * Gets all the inputs on this form section
887
-     *
888
-     * @return EE_Form_Input_Base[]
889
-     */
890
-    public function inputs()
891
-    {
892
-        $inputs = array();
893
-        foreach ($this->subsections() as $subsection_name => $subsection) {
894
-            if ($subsection instanceof EE_Form_Input_Base) {
895
-                $inputs[$subsection_name] = $subsection;
896
-            }
897
-        }
898
-        return $inputs;
899
-    }
900
-
901
-
902
-
903
-    /**
904
-     * Gets all the subsections which are a proper form
905
-     *
906
-     * @return EE_Form_Section_Proper[]
907
-     */
908
-    public function subforms()
909
-    {
910
-        $form_sections = array();
911
-        foreach ($this->subsections() as $name => $obj) {
912
-            if ($obj instanceof EE_Form_Section_Proper) {
913
-                $form_sections[$name] = $obj;
914
-            }
915
-        }
916
-        return $form_sections;
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
923
-     * Consider using inputs() or subforms()
924
-     * if you only want form inputs or proper form sections.
925
-     *
926
-     * @return EE_Form_Section_Proper[]
927
-     */
928
-    public function subsections()
929
-    {
930
-        $this->ensure_construct_finalized_called();
931
-        return $this->_subsections;
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * Returns a simple array where keys are input names, and values are their normalized
938
-     * values. (Similar to calling get_input_value on inputs)
939
-     *
940
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
941
-     *                                        or just this forms' direct children inputs
942
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
943
-     *                                        or allow multidimensional array
944
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
945
-     *                                        with array keys being input names
946
-     *                                        (regardless of whether they are from a subsection or not),
947
-     *                                        and if $flatten is FALSE it can be a multidimensional array
948
-     *                                        where keys are always subsection names and values are either
949
-     *                                        the input's normalized value, or an array like the top-level array
950
-     */
951
-    public function input_values($include_subform_inputs = false, $flatten = false)
952
-    {
953
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
954
-    }
955
-
956
-
957
-
958
-    /**
959
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
960
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
961
-     * is not necessarily the value we want to display to users. This creates an array
962
-     * where keys are the input names, and values are their display values
963
-     *
964
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
965
-     *                                        or just this forms' direct children inputs
966
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
967
-     *                                        or allow multidimensional array
968
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
969
-     *                                        with array keys being input names
970
-     *                                        (regardless of whether they are from a subsection or not),
971
-     *                                        and if $flatten is FALSE it can be a multidimensional array
972
-     *                                        where keys are always subsection names and values are either
973
-     *                                        the input's normalized value, or an array like the top-level array
974
-     */
975
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
976
-    {
977
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
978
-    }
979
-
980
-
981
-
982
-    /**
983
-     * Gets the input values from the form
984
-     *
985
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
986
-     *                                        or just the normalized value
987
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
988
-     *                                        or just this forms' direct children inputs
989
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
990
-     *                                        or allow multidimensional array
991
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
992
-     *                                        input names (regardless of whether they are from a subsection or not),
993
-     *                                        and if $flatten is FALSE it can be a multidimensional array
994
-     *                                        where keys are always subsection names and values are either
995
-     *                                        the input's normalized value, or an array like the top-level array
996
-     */
997
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
998
-    {
999
-        $input_values = array();
1000
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1001
-            if ($subsection instanceof EE_Form_Input_Base) {
1002
-                $input_values[$subsection_name] = $pretty
1003
-                    ? $subsection->pretty_value()
1004
-                    : $subsection->normalized_value();
1005
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1006
-                $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1007
-                if ($flatten) {
1008
-                    $input_values = array_merge($input_values, $subform_input_values);
1009
-                } else {
1010
-                    $input_values[$subsection_name] = $subform_input_values;
1011
-                }
1012
-            }
1013
-        }
1014
-        return $input_values;
1015
-    }
1016
-
1017
-
1018
-
1019
-    /**
1020
-     * Gets the originally submitted input values from the form
1021
-     *
1022
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1023
-     *                                   or just this forms' direct children inputs
1024
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1025
-     *                                   with array keys being input names
1026
-     *                                   (regardless of whether they are from a subsection or not),
1027
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1028
-     *                                   where keys are always subsection names and values are either
1029
-     *                                   the input's normalized value, or an array like the top-level array
1030
-     */
1031
-    public function submitted_values($include_subforms = false)
1032
-    {
1033
-        $submitted_values = array();
1034
-        foreach ($this->subsections() as $subsection) {
1035
-            if ($subsection instanceof EE_Form_Input_Base) {
1036
-                // is this input part of an array of inputs?
1037
-                if (strpos($subsection->html_name(), '[') !== false) {
1038
-                    $full_input_name = \EEH_Array::convert_array_values_to_keys(
1039
-                        explode('[', str_replace(']', '', $subsection->html_name())),
1040
-                        $subsection->raw_value()
1041
-                    );
1042
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1043
-                } else {
1044
-                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1045
-                }
1046
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1047
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1048
-                $submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1049
-            }
1050
-        }
1051
-        return $submitted_values;
1052
-    }
1053
-
1054
-
1055
-
1056
-    /**
1057
-     * Indicates whether or not this form has received a submission yet
1058
-     * (ie, had receive_form_submission called on it yet)
1059
-     *
1060
-     * @return boolean
1061
-     * @throws \EE_Error
1062
-     */
1063
-    public function has_received_submission()
1064
-    {
1065
-        $this->ensure_construct_finalized_called();
1066
-        return $this->_received_submission;
1067
-    }
1068
-
1069
-
1070
-
1071
-    /**
1072
-     * Equivalent to passing 'exclude' in the constructor's options array.
1073
-     * Removes the listed inputs from the form
1074
-     *
1075
-     * @param array $inputs_to_exclude values are the input names
1076
-     * @return void
1077
-     */
1078
-    public function exclude(array $inputs_to_exclude = array())
1079
-    {
1080
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1081
-            unset($this->_subsections[$input_to_exclude_name]);
1082
-        }
1083
-    }
1084
-
1085
-
1086
-
1087
-    /**
1088
-     * @param array $inputs_to_hide
1089
-     * @throws \EE_Error
1090
-     */
1091
-    public function hide($inputs_to_hide = array())
1092
-    {
1093
-        foreach ($inputs_to_hide as $input_to_hide) {
1094
-            $input = $this->get_input($input_to_hide);
1095
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1096
-        }
1097
-    }
1098
-
1099
-
1100
-
1101
-    /**
1102
-     * add_subsections
1103
-     * Adds the listed subsections to the form section.
1104
-     * If $subsection_name_to_target is provided,
1105
-     * then new subsections are added before or after that subsection,
1106
-     * otherwise to the start or end of the entire subsections array.
1107
-     *
1108
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1109
-     *                                                          where keys are their names
1110
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1111
-     *                                                          should be added before or after
1112
-     *                                                          IF $subsection_name_to_target is null,
1113
-     *                                                          then $new_subsections will be added to
1114
-     *                                                          the beginning or end of the entire subsections array
1115
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1116
-     *                                                          $subsection_name_to_target,
1117
-     *                                                          or if $subsection_name_to_target is null,
1118
-     *                                                          before or after entire subsections array
1119
-     * @return void
1120
-     * @throws \EE_Error
1121
-     */
1122
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1123
-    {
1124
-        foreach ($new_subsections as $subsection_name => $subsection) {
1125
-            if ( ! $subsection instanceof EE_Form_Section_Base) {
1126
-                EE_Error::add_error(
1127
-                    sprintf(
1128
-                        __(
1129
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1130
-                            "event_espresso"
1131
-                        ),
1132
-                        get_class($subsection),
1133
-                        $subsection_name,
1134
-                        $this->name()
1135
-                    )
1136
-                );
1137
-                unset($new_subsections[$subsection_name]);
1138
-            }
1139
-        }
1140
-        $this->_subsections = EEH_Array::insert_into_array(
1141
-            $this->_subsections,
1142
-            $new_subsections,
1143
-            $subsection_name_to_target,
1144
-            $add_before
1145
-        );
1146
-        if ($this->_construction_finalized) {
1147
-            foreach ($this->_subsections as $name => $subsection) {
1148
-                $subsection->_construct_finalize($this, $name);
1149
-            }
1150
-        }
1151
-    }
1152
-
1153
-
1154
-
1155
-    /**
1156
-     * Just gets all validatable subsections to clean their sensitive data
1157
-     */
1158
-    public function clean_sensitive_data()
1159
-    {
1160
-        foreach ($this->get_validatable_subsections() as $subsection) {
1161
-            $subsection->clean_sensitive_data();
1162
-        }
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * @param string $form_submission_error_message
1169
-     */
1170
-    public function set_submission_error_message($form_submission_error_message = '')
1171
-    {
1172
-        $this->_form_submission_error_message .= ! empty($form_submission_error_message)
1173
-            ? $form_submission_error_message
1174
-            : __('Form submission failed due to errors', 'event_espresso');
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * @return string
1181
-     */
1182
-    public function submission_error_message()
1183
-    {
1184
-        return $this->_form_submission_error_message;
1185
-    }
1186
-
1187
-
1188
-
1189
-    /**
1190
-     * @param string $form_submission_success_message
1191
-     */
1192
-    public function set_submission_success_message($form_submission_success_message)
1193
-    {
1194
-        $this->_form_submission_success_message .= ! empty($form_submission_success_message)
1195
-            ? $form_submission_success_message
1196
-            : __('Form submitted successfully', 'event_espresso');
1197
-    }
1198
-
1199
-
1200
-
1201
-    /**
1202
-     * @return string
1203
-     */
1204
-    public function submission_success_message()
1205
-    {
1206
-        return $this->_form_submission_success_message;
1207
-    }
1208
-
1209
-
1210
-
1211
-    /**
1212
-     * Returns the prefix that should be used on child of this form section for
1213
-     * their html names. If this form section itself has a parent, prepends ITS
1214
-     * prefix onto this form section's prefix. Used primarily by
1215
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1216
-     *
1217
-     * @return string
1218
-     * @throws \EE_Error
1219
-     */
1220
-    public function html_name_prefix()
1221
-    {
1222
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1223
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1224
-        } else {
1225
-            return $this->name();
1226
-        }
1227
-    }
1228
-
1229
-
1230
-
1231
-    /**
1232
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1233
-     * calls it (assumes there is no parent and that we want the name to be whatever
1234
-     * was set, which is probably nothing, or the classname)
1235
-     *
1236
-     * @return string
1237
-     * @throws \EE_Error
1238
-     */
1239
-    public function name()
1240
-    {
1241
-        $this->ensure_construct_finalized_called();
1242
-        return parent::name();
1243
-    }
1244
-
1245
-
1246
-
1247
-    /**
1248
-     * @return EE_Form_Section_Proper
1249
-     * @throws \EE_Error
1250
-     */
1251
-    public function parent_section()
1252
-    {
1253
-        $this->ensure_construct_finalized_called();
1254
-        return parent::parent_section();
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * make sure construction finalized was called, otherwise children might not be ready
1261
-     *
1262
-     * @return void
1263
-     * @throws \EE_Error
1264
-     */
1265
-    public function ensure_construct_finalized_called()
1266
-    {
1267
-        if ( ! $this->_construction_finalized) {
1268
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1269
-        }
1270
-    }
1271
-
1272
-
1273
-
1274
-    /**
1275
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1276
-     * are in teh form data. If any are found, returns true. Else false
1277
-     *
1278
-     * @param array $req_data
1279
-     * @return boolean
1280
-     */
1281
-    public function form_data_present_in($req_data = null)
1282
-    {
1283
-        if ($req_data === null) {
1284
-            $req_data = $_POST;
1285
-        }
1286
-        foreach ($this->subsections() as $subsection) {
1287
-            if ($subsection instanceof EE_Form_Input_Base) {
1288
-                if ($subsection->form_data_present_in($req_data)) {
1289
-                    return true;
1290
-                }
1291
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1292
-                if ($subsection->form_data_present_in($req_data)) {
1293
-                    return true;
1294
-                }
1295
-            }
1296
-        }
1297
-        return false;
1298
-    }
1299
-
1300
-
1301
-
1302
-    /**
1303
-     * Gets validation errors for this form section and subsections
1304
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1305
-     * gets the validation errors for ALL subsection
1306
-     *
1307
-     * @return EE_Validation_Error[]
1308
-     */
1309
-    public function get_validation_errors_accumulated()
1310
-    {
1311
-        $validation_errors = $this->get_validation_errors();
1312
-        foreach ($this->get_validatable_subsections() as $subsection) {
1313
-            if ($subsection instanceof EE_Form_Section_Proper) {
1314
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1315
-            } else {
1316
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1317
-            }
1318
-            if ($validation_errors_on_this_subsection) {
1319
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1320
-            }
1321
-        }
1322
-        return $validation_errors;
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     * This isn't just the name of an input, it's a path pointing to an input. The
1329
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1330
-     * dot-dot-slash (../) means to ascend into the parent section.
1331
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1332
-     * which will be returned.
1333
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1334
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1335
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1336
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1337
-     * Etc
1338
-     *
1339
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1340
-     * @return EE_Form_Section_Base
1341
-     */
1342
-    public function find_section_from_path($form_section_path)
1343
-    {
1344
-        //check if we can find the input from purely going straight up the tree
1345
-        $input = parent::find_section_from_path($form_section_path);
1346
-        if ($input instanceof EE_Form_Section_Base) {
1347
-            return $input;
1348
-        }
1349
-        $next_slash_pos = strpos($form_section_path, '/');
1350
-        if ($next_slash_pos !== false) {
1351
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1352
-            $subpath = substr($form_section_path, $next_slash_pos + 1);
1353
-        } else {
1354
-            $child_section_name = $form_section_path;
1355
-            $subpath = '';
1356
-        }
1357
-        $child_section = $this->get_subsection($child_section_name);
1358
-        if ($child_section instanceof EE_Form_Section_Base) {
1359
-            return $child_section->find_section_from_path($subpath);
1360
-        } else {
1361
-            return null;
1362
-        }
1363
-    }
16
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
17
+
18
+	/**
19
+	 * Subsections
20
+	 *
21
+	 * @var EE_Form_Section_Validatable[]
22
+	 */
23
+	protected $_subsections = array();
24
+
25
+	/**
26
+	 * Strategy for laying out the form
27
+	 *
28
+	 * @var EE_Form_Section_Layout_Base
29
+	 */
30
+	protected $_layout_strategy;
31
+
32
+	/**
33
+	 * Whether or not this form has received and validated a form submission yet
34
+	 *
35
+	 * @var boolean
36
+	 */
37
+	protected $_received_submission = false;
38
+
39
+	/**
40
+	 * message displayed to users upon successful form submission
41
+	 *
42
+	 * @var string
43
+	 */
44
+	protected $_form_submission_success_message = '';
45
+
46
+	/**
47
+	 * message displayed to users upon unsuccessful form submission
48
+	 *
49
+	 * @var string
50
+	 */
51
+	protected $_form_submission_error_message = '';
52
+
53
+	/**
54
+	 * Stores all the data that will localized for form validation
55
+	 *
56
+	 * @var array
57
+	 */
58
+	static protected $_js_localization = array();
59
+
60
+	/**
61
+	 * whether or not the form's localized validation JS vars have been set
62
+	 *
63
+	 * @type boolean
64
+	 */
65
+	static protected $_scripts_localized = false;
66
+
67
+
68
+
69
+	/**
70
+	 * when constructing a proper form section, calls _construct_finalize on children
71
+	 * so that they know who their parent is, and what name they've been given.
72
+	 *
73
+	 * @param array $options_array   {
74
+	 * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
75
+	 * @type        $include         string[] numerically-indexed where values are section names to be included,
76
+	 *                               and in that order. This is handy if you want
77
+	 *                               the subsections to be ordered differently than the default, and if you override
78
+	 *                               which fields are shown
79
+	 * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
80
+	 *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
81
+	 *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
82
+	 *                               items from that list of inclusions)
83
+	 * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
84
+	 *                               } @see EE_Form_Section_Validatable::__construct()
85
+	 * @throws \EE_Error
86
+	 */
87
+	public function __construct($options_array = array())
88
+	{
89
+		$options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
90
+			$this);
91
+		//call parent first, as it may be setting the name
92
+		parent::__construct($options_array);
93
+		//if they've included subsections in the constructor, add them now
94
+		if (isset($options_array['include'])) {
95
+			//we are going to make sure we ONLY have those subsections to include
96
+			//AND we are going to make sure they're in that specified order
97
+			$reordered_subsections = array();
98
+			foreach ($options_array['include'] as $input_name) {
99
+				if (isset($this->_subsections[$input_name])) {
100
+					$reordered_subsections[$input_name] = $this->_subsections[$input_name];
101
+				}
102
+			}
103
+			$this->_subsections = $reordered_subsections;
104
+		}
105
+		if (isset($options_array['exclude'])) {
106
+			$exclude = $options_array['exclude'];
107
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
108
+		}
109
+		if (isset($options_array['layout_strategy'])) {
110
+			$this->_layout_strategy = $options_array['layout_strategy'];
111
+		}
112
+		if ( ! $this->_layout_strategy) {
113
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
114
+		}
115
+		$this->_layout_strategy->_construct_finalize($this);
116
+		//ok so we are definitely going to want the forms JS,
117
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
118
+		if (did_action('wp_enqueue_scripts')
119
+			|| did_action('admin_enqueue_scripts')
120
+		) {
121
+			//ok so they've constructed this object after when they should have.
122
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
123
+			\EE_Form_Section_Proper::wp_enqueue_scripts(true);
124
+		} else {
125
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
126
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
127
+		}
128
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
129
+		if (isset($options_array['name'])) {
130
+			$this->_construct_finalize(null, $options_array['name']);
131
+		}
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * Finishes construction given the parent form section and this form section's name
138
+	 *
139
+	 * @param EE_Form_Section_Proper $parent_form_section
140
+	 * @param string                 $name
141
+	 * @throws \EE_Error
142
+	 */
143
+	public function _construct_finalize($parent_form_section, $name)
144
+	{
145
+		parent::_construct_finalize($parent_form_section, $name);
146
+		$this->_set_default_name_if_empty();
147
+		$this->_set_default_html_id_if_empty();
148
+		foreach ($this->_subsections as $subsection_name => $subsection) {
149
+			if ($subsection instanceof EE_Form_Section_Base) {
150
+				$subsection->_construct_finalize($this, $subsection_name);
151
+			} else {
152
+				throw new EE_Error(
153
+					sprintf(
154
+						__('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
155
+							'event_espresso'),
156
+						$subsection_name,
157
+						get_class($this),
158
+						$subsection ? get_class($subsection) : __('NULL', 'event_espresso')
159
+					)
160
+				);
161
+			}
162
+		}
163
+		do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * Gets the layout strategy for this form section
170
+	 *
171
+	 * @return EE_Form_Section_Layout_Base
172
+	 */
173
+	public function get_layout_strategy()
174
+	{
175
+		return $this->_layout_strategy;
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * Gets the HTML for a single input for this form section according
182
+	 * to the layout strategy
183
+	 *
184
+	 * @param EE_Form_Input_Base $input
185
+	 * @return string
186
+	 */
187
+	public function get_html_for_input($input)
188
+	{
189
+		return $this->_layout_strategy->layout_input($input);
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 * was_submitted - checks if form inputs are present in request data
196
+	 * Basically an alias for form_data_present_in() (which is used by both
197
+	 * proper form sections and form inputs)
198
+	 *
199
+	 * @param null $form_data
200
+	 * @return boolean
201
+	 */
202
+	public function was_submitted($form_data = null)
203
+	{
204
+		return $this->form_data_present_in($form_data);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * After the form section is initially created, call this to sanitize the data in the submission
211
+	 * which relates to this form section, validate it, and set it as properties on the form.
212
+	 *
213
+	 * @param array|null $req_data should usually be $_POST (the default).
214
+	 *                             However, you CAN supply a different array.
215
+	 *                             Consider using set_defaults() instead however.
216
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
217
+	 *                             the inputs will have the correct name in the request data for this function
218
+	 *                             to find them and populate the form with them.
219
+	 *                             If you have a flat form (with only input subsections),
220
+	 *                             you can supply a flat array where keys
221
+	 *                             are the form input names and values are their values)
222
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
223
+	 *                             of course, to validate that data, and set errors on the invalid values.
224
+	 *                             But if the data has already been validated
225
+	 *                             (eg you validated the data then stored it in the DB)
226
+	 *                             you may want to skip this step.
227
+	 */
228
+	public function receive_form_submission($req_data = null, $validate = true)
229
+	{
230
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
231
+			$validate);
232
+		if ($req_data === null) {
233
+			$req_data = array_merge($_GET, $_POST);
234
+		}
235
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
236
+			$this);
237
+		$this->_normalize($req_data);
238
+		if ($validate) {
239
+			$this->_validate();
240
+			//if it's invalid, we're going to want to re-display so remember what they submitted
241
+			if ( ! $this->is_valid()) {
242
+				$this->store_submitted_form_data_in_session();
243
+			}
244
+		}
245
+		do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * caches the originally submitted input values in the session
252
+	 * so that they can be used to repopulate the form if it failed validation
253
+	 *
254
+	 * @return boolean whether or not the data was successfully stored in the session
255
+	 */
256
+	protected function store_submitted_form_data_in_session()
257
+	{
258
+		return EE_Registry::instance()->SSN->set_session_data(
259
+			array(
260
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
261
+			)
262
+		);
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * retrieves the originally submitted input values in the session
269
+	 * so that they can be used to repopulate the form if it failed validation
270
+	 *
271
+	 * @return array
272
+	 */
273
+	protected function get_submitted_form_data_from_session()
274
+	{
275
+		$session = EE_Registry::instance()->SSN;
276
+		if ($session instanceof EE_Session) {
277
+			return $session->get_session_data(
278
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
279
+			);
280
+		} else {
281
+			return array();
282
+		}
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * flushed the originally submitted input values from the session
289
+	 *
290
+	 * @return boolean whether or not the data was successfully removed from the session
291
+	 */
292
+	protected function flush_submitted_form_data_from_session()
293
+	{
294
+		return EE_Registry::instance()->SSN->reset_data(
295
+			array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
296
+		);
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * Populates this form and its subsections with data from the session.
303
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
304
+	 * validation errors when displaying too)
305
+	 * Returns true if the form was populated from the session, false otherwise
306
+	 *
307
+	 * @return boolean
308
+	 */
309
+	public function populate_from_session()
310
+	{
311
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
312
+		if (empty($form_data_in_session)) {
313
+			return false;
314
+		}
315
+		$this->receive_form_submission($form_data_in_session);
316
+		$this->flush_submitted_form_data_from_session();
317
+		if ($this->form_data_present_in($form_data_in_session)) {
318
+			return true;
319
+		} else {
320
+			return false;
321
+		}
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * Populates the default data for the form, given an array where keys are
328
+	 * the input names, and values are their values (preferably normalized to be their
329
+	 * proper PHP types, not all strings... although that should be ok too).
330
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
331
+	 * the value being an array formatted in teh same way
332
+	 *
333
+	 * @param array $default_data
334
+	 */
335
+	public function populate_defaults($default_data)
336
+	{
337
+		foreach ($this->subsections() as $subsection_name => $subsection) {
338
+			if (isset($default_data[$subsection_name])) {
339
+				if ($subsection instanceof EE_Form_Input_Base) {
340
+					$subsection->set_default($default_data[$subsection_name]);
341
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
342
+					$subsection->populate_defaults($default_data[$subsection_name]);
343
+				}
344
+			}
345
+		}
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * returns true if subsection exists
352
+	 *
353
+	 * @param string $name
354
+	 * @return boolean
355
+	 */
356
+	public function subsection_exists($name)
357
+	{
358
+		return isset($this->_subsections[$name]) ? true : false;
359
+	}
360
+
361
+
362
+
363
+	/**
364
+	 * Gets the subsection specified by its name
365
+	 *
366
+	 * @param string  $name
367
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
368
+	 *                                                      so that the inputs will be properly configured.
369
+	 *                                                      However, some client code may be ok
370
+	 *                                                      with construction finalize being called later
371
+	 *                                                      (realizing that the subsections' html names
372
+	 *                                                      might not be set yet, etc.)
373
+	 * @return EE_Form_Section_Base
374
+	 * @throws \EE_Error
375
+	 */
376
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
377
+	{
378
+		if ($require_construction_to_be_finalized) {
379
+			$this->ensure_construct_finalized_called();
380
+		}
381
+		return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 * Gets all the validatable subsections of this form section
388
+	 *
389
+	 * @return EE_Form_Section_Validatable[]
390
+	 */
391
+	public function get_validatable_subsections()
392
+	{
393
+		$validatable_subsections = array();
394
+		foreach ($this->subsections() as $name => $obj) {
395
+			if ($obj instanceof EE_Form_Section_Validatable) {
396
+				$validatable_subsections[$name] = $obj;
397
+			}
398
+		}
399
+		return $validatable_subsections;
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
406
+	 * throw an EE_Error.
407
+	 *
408
+	 * @param string  $name
409
+	 * @param boolean $require_construction_to_be_finalized most client code should
410
+	 *                                                      leave this as TRUE so that the inputs will be properly
411
+	 *                                                      configured. However, some client code may be ok with
412
+	 *                                                      construction finalize being called later
413
+	 *                                                      (realizing that the subsections' html names might not be
414
+	 *                                                      set yet, etc.)
415
+	 * @return EE_Form_Input_Base
416
+	 * @throws EE_Error
417
+	 */
418
+	public function get_input($name, $require_construction_to_be_finalized = true)
419
+	{
420
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
421
+		if ( ! $subsection instanceof EE_Form_Input_Base) {
422
+			throw new EE_Error(
423
+				sprintf(
424
+					__(
425
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
426
+						'event_espresso'
427
+					),
428
+					$name,
429
+					get_class($this),
430
+					$subsection ? get_class($subsection) : __("NULL", 'event_espresso')
431
+				)
432
+			);
433
+		}
434
+		return $subsection;
435
+	}
436
+
437
+
438
+
439
+	/**
440
+	 * Like get_input(), gets the proper subsection of the form given the name,
441
+	 * otherwise throws an EE_Error
442
+	 *
443
+	 * @param string  $name
444
+	 * @param boolean $require_construction_to_be_finalized most client code should
445
+	 *                                                      leave this as TRUE so that the inputs will be properly
446
+	 *                                                      configured. However, some client code may be ok with
447
+	 *                                                      construction finalize being called later
448
+	 *                                                      (realizing that the subsections' html names might not be
449
+	 *                                                      set yet, etc.)
450
+	 * @return EE_Form_Section_Proper
451
+	 * @throws EE_Error
452
+	 */
453
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
454
+	{
455
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
456
+		if ( ! $subsection instanceof EE_Form_Section_Proper) {
457
+			throw new EE_Error(
458
+				sprintf(
459
+					__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
460
+					$name,
461
+					get_class($this)
462
+				)
463
+			);
464
+		}
465
+		return $subsection;
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
472
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
473
+	 *
474
+	 * @param string $name
475
+	 * @return mixed depending on the input's type and its normalization strategy
476
+	 * @throws \EE_Error
477
+	 */
478
+	public function get_input_value($name)
479
+	{
480
+		$input = $this->get_input($name);
481
+		return $input->normalized_value();
482
+	}
483
+
484
+
485
+
486
+	/**
487
+	 * Checks if this form section itself is valid, and then checks its subsections
488
+	 *
489
+	 * @throws EE_Error
490
+	 * @return boolean
491
+	 */
492
+	public function is_valid()
493
+	{
494
+		if ( ! $this->has_received_submission()) {
495
+			throw new EE_Error(
496
+				sprintf(
497
+					__(
498
+						"You cannot check if a form is valid before receiving the form submission using receive_form_submission",
499
+						"event_espresso"
500
+					)
501
+				)
502
+			);
503
+		}
504
+		if ( ! parent::is_valid()) {
505
+			return false;
506
+		}
507
+		// ok so no general errors to this entire form section.
508
+		// so let's check the subsections, but only set errors if that hasn't been done yet
509
+		$set_submission_errors = $this->submission_error_message() === '' ? true : false;
510
+		foreach ($this->get_validatable_subsections() as $subsection) {
511
+			if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
512
+				if ($set_submission_errors) {
513
+					$this->set_submission_error_message($subsection->get_validation_error_string());
514
+				}
515
+				return false;
516
+			}
517
+		}
518
+		return true;
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 * gets teh default name of this form section if none is specified
525
+	 *
526
+	 * @return string
527
+	 */
528
+	protected function _set_default_name_if_empty()
529
+	{
530
+		if ( ! $this->_name) {
531
+			$classname = get_class($this);
532
+			$default_name = str_replace("EE_", "", $classname);
533
+			$this->_name = $default_name;
534
+		}
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * Returns the HTML for the form, except for the form opening and closing tags
541
+	 * (as the form section doesn't know where you necessarily want to send the information to),
542
+	 * and except for a submit button. Enqueus JS and CSS; if called early enough we will
543
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
544
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
545
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
546
+	 * any CSS.
547
+	 *
548
+	 * @throws \EE_Error
549
+	 */
550
+	public function get_html_and_js()
551
+	{
552
+		$this->enqueue_js();
553
+		return $this->get_html();
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
560
+	 *
561
+	 * @param bool $display_previously_submitted_data
562
+	 * @return string
563
+	 */
564
+	public function get_html($display_previously_submitted_data = true)
565
+	{
566
+		$this->ensure_construct_finalized_called();
567
+		if ($display_previously_submitted_data) {
568
+			$this->populate_from_session();
569
+		}
570
+		return $this->_layout_strategy->layout_form();
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * enqueues JS and CSS for the form.
577
+	 * It is preferred to call this before wp_enqueue_scripts so the
578
+	 * scripts and styles can be put in the header, but if called later
579
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
580
+	 * only be in the header; but in HTML5 its ok in the body.
581
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
582
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
583
+	 *
584
+	 * @return string
585
+	 * @throws \EE_Error
586
+	 */
587
+	public function enqueue_js()
588
+	{
589
+		$this->_enqueue_and_localize_form_js();
590
+		foreach ($this->subsections() as $subsection) {
591
+			$subsection->enqueue_js();
592
+		}
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
599
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
600
+	 * the wp_enqueue_scripts hook.
601
+	 * However, registering the form js and localizing it can happen when we
602
+	 * actually output the form (which is preferred, seeing how teh form's fields
603
+	 * could change until it's actually outputted)
604
+	 *
605
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
606
+	 *                                                    to be triggered automatically or not
607
+	 * @return void
608
+	 */
609
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
610
+	{
611
+		add_filter('FHEE_load_jquery_validate', '__return_true');
612
+		wp_register_script(
613
+			'ee_form_section_validation',
614
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
615
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
616
+			EVENT_ESPRESSO_VERSION,
617
+			true
618
+		);
619
+		wp_localize_script(
620
+			'ee_form_section_validation',
621
+			'ee_form_section_validation_init',
622
+			array('init' => $init_form_validation_automatically ? true : false)
623
+		);
624
+	}
625
+
626
+
627
+
628
+	/**
629
+	 * gets the variables used by form_section_validation.js.
630
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
631
+	 * but before the wordpress hook wp_loaded
632
+	 *
633
+	 * @throws \EE_Error
634
+	 */
635
+	public function _enqueue_and_localize_form_js()
636
+	{
637
+		$this->ensure_construct_finalized_called();
638
+		//actually, we don't want to localize just yet. There may be other forms on the page.
639
+		//so we need to add our form section data to a static variable accessible by all form sections
640
+		//and localize it just before the footer
641
+		$this->localize_validation_rules();
642
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
643
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * add our form section data to a static variable accessible by all form sections
650
+	 *
651
+	 * @param bool $return_for_subsection
652
+	 * @return void
653
+	 * @throws \EE_Error
654
+	 */
655
+	public function localize_validation_rules($return_for_subsection = false)
656
+	{
657
+		// we only want to localize vars ONCE for the entire form,
658
+		// so if the form section doesn't have a parent, then it must be the top dog
659
+		if ($return_for_subsection || ! $this->parent_section()) {
660
+			EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
661
+				'form_section_id'  => $this->html_id(true),
662
+				'validation_rules' => $this->get_jquery_validation_rules(),
663
+				'other_data'       => $this->get_other_js_data(),
664
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
665
+			);
666
+			EE_Form_Section_Proper::$_scripts_localized = true;
667
+		}
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * Gets an array of extra data that will be useful for client-side javascript.
674
+	 * This is primarily data added by inputs and forms in addition to any
675
+	 * scripts they might enqueue
676
+	 *
677
+	 * @param array $form_other_js_data
678
+	 * @return array
679
+	 */
680
+	public function get_other_js_data($form_other_js_data = array())
681
+	{
682
+		foreach ($this->subsections() as $subsection) {
683
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
684
+		}
685
+		return $form_other_js_data;
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * Gets a flat array of inputs for this form section and its subsections.
692
+	 * Keys are their form names, and values are the inputs themselves
693
+	 *
694
+	 * @return EE_Form_Input_Base
695
+	 */
696
+	public function inputs_in_subsections()
697
+	{
698
+		$inputs = array();
699
+		foreach ($this->subsections() as $subsection) {
700
+			if ($subsection instanceof EE_Form_Input_Base) {
701
+				$inputs[$subsection->html_name()] = $subsection;
702
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
703
+				$inputs += $subsection->inputs_in_subsections();
704
+			}
705
+		}
706
+		return $inputs;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * Gets a flat array of all the validation errors.
713
+	 * Keys are html names (because those should be unique)
714
+	 * and values are a string of all their validation errors
715
+	 *
716
+	 * @return string[]
717
+	 */
718
+	public function subsection_validation_errors_by_html_name()
719
+	{
720
+		$inputs = $this->inputs();
721
+		$errors = array();
722
+		foreach ($inputs as $form_input) {
723
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
724
+				$errors[$form_input->html_name()] = $form_input->get_validation_error_string();
725
+			}
726
+		}
727
+		return $errors;
728
+	}
729
+
730
+
731
+
732
+	/**
733
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
734
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
735
+	 */
736
+	public static function localize_script_for_all_forms()
737
+	{
738
+		//allow inputs and stuff to hook in their JS and stuff here
739
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
740
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
741
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
742
+			? EE_Registry::instance()->CFG->registration->email_validation_level
743
+			: 'wp_default';
744
+		EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
745
+		wp_enqueue_script('ee_form_section_validation');
746
+		wp_localize_script(
747
+			'ee_form_section_validation',
748
+			'ee_form_section_vars',
749
+			EE_Form_Section_Proper::$_js_localization
750
+		);
751
+	}
752
+
753
+
754
+
755
+	/**
756
+	 * ensure_scripts_localized
757
+	 */
758
+	public function ensure_scripts_localized()
759
+	{
760
+		if ( ! EE_Form_Section_Proper::$_scripts_localized) {
761
+			$this->_enqueue_and_localize_form_js();
762
+		}
763
+	}
764
+
765
+
766
+
767
+	/**
768
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
769
+	 * is that the key here should be the same as the custom validation rule put in the JS file
770
+	 *
771
+	 * @return array keys are custom validation rules, and values are internationalized strings
772
+	 */
773
+	private static function _get_localized_error_messages()
774
+	{
775
+		return array(
776
+			'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
777
+			'regex'    => __('Please check your input', 'event_espresso'),
778
+		);
779
+	}
780
+
781
+
782
+
783
+	/**
784
+	 * @return array
785
+	 */
786
+	public static function js_localization()
787
+	{
788
+		return self::$_js_localization;
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 * @return array
795
+	 */
796
+	public static function reset_js_localization()
797
+	{
798
+		self::$_js_localization = array();
799
+	}
800
+
801
+
802
+
803
+	/**
804
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
805
+	 * See parent function for more...
806
+	 *
807
+	 * @return array
808
+	 */
809
+	public function get_jquery_validation_rules()
810
+	{
811
+		$jquery_validation_rules = array();
812
+		foreach ($this->get_validatable_subsections() as $subsection) {
813
+			$jquery_validation_rules = array_merge(
814
+				$jquery_validation_rules,
815
+				$subsection->get_jquery_validation_rules()
816
+			);
817
+		}
818
+		return $jquery_validation_rules;
819
+	}
820
+
821
+
822
+
823
+	/**
824
+	 * Sanitizes all the data and sets the sanitized value of each field
825
+	 *
826
+	 * @param array $req_data like $_POST
827
+	 * @return void
828
+	 */
829
+	protected function _normalize($req_data)
830
+	{
831
+		$this->_received_submission = true;
832
+		$this->_validation_errors = array();
833
+		foreach ($this->get_validatable_subsections() as $subsection) {
834
+			try {
835
+				$subsection->_normalize($req_data);
836
+			} catch (EE_Validation_Error $e) {
837
+				$subsection->add_validation_error($e);
838
+			}
839
+		}
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * Performs validation on this form section and its subsections.
846
+	 * For each subsection,
847
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
848
+	 * and passes it the subsection, then calls _validate on that subsection.
849
+	 * If you need to perform validation on the form as a whole (considering multiple)
850
+	 * you would be best to override this _validate method,
851
+	 * calling parent::_validate() first.
852
+	 */
853
+	protected function _validate()
854
+	{
855
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
856
+			if (method_exists($this, '_validate_' . $subsection_name)) {
857
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
858
+			}
859
+			$subsection->_validate();
860
+		}
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * Gets all the validated inputs for the form section
867
+	 *
868
+	 * @return array
869
+	 */
870
+	public function valid_data()
871
+	{
872
+		$inputs = array();
873
+		foreach ($this->subsections() as $subsection_name => $subsection) {
874
+			if ($subsection instanceof EE_Form_Section_Proper) {
875
+				$inputs[$subsection_name] = $subsection->valid_data();
876
+			} else if ($subsection instanceof EE_Form_Input_Base) {
877
+				$inputs[$subsection_name] = $subsection->normalized_value();
878
+			}
879
+		}
880
+		return $inputs;
881
+	}
882
+
883
+
884
+
885
+	/**
886
+	 * Gets all the inputs on this form section
887
+	 *
888
+	 * @return EE_Form_Input_Base[]
889
+	 */
890
+	public function inputs()
891
+	{
892
+		$inputs = array();
893
+		foreach ($this->subsections() as $subsection_name => $subsection) {
894
+			if ($subsection instanceof EE_Form_Input_Base) {
895
+				$inputs[$subsection_name] = $subsection;
896
+			}
897
+		}
898
+		return $inputs;
899
+	}
900
+
901
+
902
+
903
+	/**
904
+	 * Gets all the subsections which are a proper form
905
+	 *
906
+	 * @return EE_Form_Section_Proper[]
907
+	 */
908
+	public function subforms()
909
+	{
910
+		$form_sections = array();
911
+		foreach ($this->subsections() as $name => $obj) {
912
+			if ($obj instanceof EE_Form_Section_Proper) {
913
+				$form_sections[$name] = $obj;
914
+			}
915
+		}
916
+		return $form_sections;
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
923
+	 * Consider using inputs() or subforms()
924
+	 * if you only want form inputs or proper form sections.
925
+	 *
926
+	 * @return EE_Form_Section_Proper[]
927
+	 */
928
+	public function subsections()
929
+	{
930
+		$this->ensure_construct_finalized_called();
931
+		return $this->_subsections;
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * Returns a simple array where keys are input names, and values are their normalized
938
+	 * values. (Similar to calling get_input_value on inputs)
939
+	 *
940
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
941
+	 *                                        or just this forms' direct children inputs
942
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
943
+	 *                                        or allow multidimensional array
944
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
945
+	 *                                        with array keys being input names
946
+	 *                                        (regardless of whether they are from a subsection or not),
947
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
948
+	 *                                        where keys are always subsection names and values are either
949
+	 *                                        the input's normalized value, or an array like the top-level array
950
+	 */
951
+	public function input_values($include_subform_inputs = false, $flatten = false)
952
+	{
953
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
954
+	}
955
+
956
+
957
+
958
+	/**
959
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
960
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
961
+	 * is not necessarily the value we want to display to users. This creates an array
962
+	 * where keys are the input names, and values are their display values
963
+	 *
964
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
965
+	 *                                        or just this forms' direct children inputs
966
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
967
+	 *                                        or allow multidimensional array
968
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
969
+	 *                                        with array keys being input names
970
+	 *                                        (regardless of whether they are from a subsection or not),
971
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
972
+	 *                                        where keys are always subsection names and values are either
973
+	 *                                        the input's normalized value, or an array like the top-level array
974
+	 */
975
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
976
+	{
977
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
978
+	}
979
+
980
+
981
+
982
+	/**
983
+	 * Gets the input values from the form
984
+	 *
985
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
986
+	 *                                        or just the normalized value
987
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
988
+	 *                                        or just this forms' direct children inputs
989
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
990
+	 *                                        or allow multidimensional array
991
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
992
+	 *                                        input names (regardless of whether they are from a subsection or not),
993
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
994
+	 *                                        where keys are always subsection names and values are either
995
+	 *                                        the input's normalized value, or an array like the top-level array
996
+	 */
997
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
998
+	{
999
+		$input_values = array();
1000
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1001
+			if ($subsection instanceof EE_Form_Input_Base) {
1002
+				$input_values[$subsection_name] = $pretty
1003
+					? $subsection->pretty_value()
1004
+					: $subsection->normalized_value();
1005
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1006
+				$subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1007
+				if ($flatten) {
1008
+					$input_values = array_merge($input_values, $subform_input_values);
1009
+				} else {
1010
+					$input_values[$subsection_name] = $subform_input_values;
1011
+				}
1012
+			}
1013
+		}
1014
+		return $input_values;
1015
+	}
1016
+
1017
+
1018
+
1019
+	/**
1020
+	 * Gets the originally submitted input values from the form
1021
+	 *
1022
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1023
+	 *                                   or just this forms' direct children inputs
1024
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1025
+	 *                                   with array keys being input names
1026
+	 *                                   (regardless of whether they are from a subsection or not),
1027
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1028
+	 *                                   where keys are always subsection names and values are either
1029
+	 *                                   the input's normalized value, or an array like the top-level array
1030
+	 */
1031
+	public function submitted_values($include_subforms = false)
1032
+	{
1033
+		$submitted_values = array();
1034
+		foreach ($this->subsections() as $subsection) {
1035
+			if ($subsection instanceof EE_Form_Input_Base) {
1036
+				// is this input part of an array of inputs?
1037
+				if (strpos($subsection->html_name(), '[') !== false) {
1038
+					$full_input_name = \EEH_Array::convert_array_values_to_keys(
1039
+						explode('[', str_replace(']', '', $subsection->html_name())),
1040
+						$subsection->raw_value()
1041
+					);
1042
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1043
+				} else {
1044
+					$submitted_values[$subsection->html_name()] = $subsection->raw_value();
1045
+				}
1046
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1047
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1048
+				$submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1049
+			}
1050
+		}
1051
+		return $submitted_values;
1052
+	}
1053
+
1054
+
1055
+
1056
+	/**
1057
+	 * Indicates whether or not this form has received a submission yet
1058
+	 * (ie, had receive_form_submission called on it yet)
1059
+	 *
1060
+	 * @return boolean
1061
+	 * @throws \EE_Error
1062
+	 */
1063
+	public function has_received_submission()
1064
+	{
1065
+		$this->ensure_construct_finalized_called();
1066
+		return $this->_received_submission;
1067
+	}
1068
+
1069
+
1070
+
1071
+	/**
1072
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1073
+	 * Removes the listed inputs from the form
1074
+	 *
1075
+	 * @param array $inputs_to_exclude values are the input names
1076
+	 * @return void
1077
+	 */
1078
+	public function exclude(array $inputs_to_exclude = array())
1079
+	{
1080
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1081
+			unset($this->_subsections[$input_to_exclude_name]);
1082
+		}
1083
+	}
1084
+
1085
+
1086
+
1087
+	/**
1088
+	 * @param array $inputs_to_hide
1089
+	 * @throws \EE_Error
1090
+	 */
1091
+	public function hide($inputs_to_hide = array())
1092
+	{
1093
+		foreach ($inputs_to_hide as $input_to_hide) {
1094
+			$input = $this->get_input($input_to_hide);
1095
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1096
+		}
1097
+	}
1098
+
1099
+
1100
+
1101
+	/**
1102
+	 * add_subsections
1103
+	 * Adds the listed subsections to the form section.
1104
+	 * If $subsection_name_to_target is provided,
1105
+	 * then new subsections are added before or after that subsection,
1106
+	 * otherwise to the start or end of the entire subsections array.
1107
+	 *
1108
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1109
+	 *                                                          where keys are their names
1110
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1111
+	 *                                                          should be added before or after
1112
+	 *                                                          IF $subsection_name_to_target is null,
1113
+	 *                                                          then $new_subsections will be added to
1114
+	 *                                                          the beginning or end of the entire subsections array
1115
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1116
+	 *                                                          $subsection_name_to_target,
1117
+	 *                                                          or if $subsection_name_to_target is null,
1118
+	 *                                                          before or after entire subsections array
1119
+	 * @return void
1120
+	 * @throws \EE_Error
1121
+	 */
1122
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1123
+	{
1124
+		foreach ($new_subsections as $subsection_name => $subsection) {
1125
+			if ( ! $subsection instanceof EE_Form_Section_Base) {
1126
+				EE_Error::add_error(
1127
+					sprintf(
1128
+						__(
1129
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1130
+							"event_espresso"
1131
+						),
1132
+						get_class($subsection),
1133
+						$subsection_name,
1134
+						$this->name()
1135
+					)
1136
+				);
1137
+				unset($new_subsections[$subsection_name]);
1138
+			}
1139
+		}
1140
+		$this->_subsections = EEH_Array::insert_into_array(
1141
+			$this->_subsections,
1142
+			$new_subsections,
1143
+			$subsection_name_to_target,
1144
+			$add_before
1145
+		);
1146
+		if ($this->_construction_finalized) {
1147
+			foreach ($this->_subsections as $name => $subsection) {
1148
+				$subsection->_construct_finalize($this, $name);
1149
+			}
1150
+		}
1151
+	}
1152
+
1153
+
1154
+
1155
+	/**
1156
+	 * Just gets all validatable subsections to clean their sensitive data
1157
+	 */
1158
+	public function clean_sensitive_data()
1159
+	{
1160
+		foreach ($this->get_validatable_subsections() as $subsection) {
1161
+			$subsection->clean_sensitive_data();
1162
+		}
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * @param string $form_submission_error_message
1169
+	 */
1170
+	public function set_submission_error_message($form_submission_error_message = '')
1171
+	{
1172
+		$this->_form_submission_error_message .= ! empty($form_submission_error_message)
1173
+			? $form_submission_error_message
1174
+			: __('Form submission failed due to errors', 'event_espresso');
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * @return string
1181
+	 */
1182
+	public function submission_error_message()
1183
+	{
1184
+		return $this->_form_submission_error_message;
1185
+	}
1186
+
1187
+
1188
+
1189
+	/**
1190
+	 * @param string $form_submission_success_message
1191
+	 */
1192
+	public function set_submission_success_message($form_submission_success_message)
1193
+	{
1194
+		$this->_form_submission_success_message .= ! empty($form_submission_success_message)
1195
+			? $form_submission_success_message
1196
+			: __('Form submitted successfully', 'event_espresso');
1197
+	}
1198
+
1199
+
1200
+
1201
+	/**
1202
+	 * @return string
1203
+	 */
1204
+	public function submission_success_message()
1205
+	{
1206
+		return $this->_form_submission_success_message;
1207
+	}
1208
+
1209
+
1210
+
1211
+	/**
1212
+	 * Returns the prefix that should be used on child of this form section for
1213
+	 * their html names. If this form section itself has a parent, prepends ITS
1214
+	 * prefix onto this form section's prefix. Used primarily by
1215
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1216
+	 *
1217
+	 * @return string
1218
+	 * @throws \EE_Error
1219
+	 */
1220
+	public function html_name_prefix()
1221
+	{
1222
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1223
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1224
+		} else {
1225
+			return $this->name();
1226
+		}
1227
+	}
1228
+
1229
+
1230
+
1231
+	/**
1232
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1233
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1234
+	 * was set, which is probably nothing, or the classname)
1235
+	 *
1236
+	 * @return string
1237
+	 * @throws \EE_Error
1238
+	 */
1239
+	public function name()
1240
+	{
1241
+		$this->ensure_construct_finalized_called();
1242
+		return parent::name();
1243
+	}
1244
+
1245
+
1246
+
1247
+	/**
1248
+	 * @return EE_Form_Section_Proper
1249
+	 * @throws \EE_Error
1250
+	 */
1251
+	public function parent_section()
1252
+	{
1253
+		$this->ensure_construct_finalized_called();
1254
+		return parent::parent_section();
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * make sure construction finalized was called, otherwise children might not be ready
1261
+	 *
1262
+	 * @return void
1263
+	 * @throws \EE_Error
1264
+	 */
1265
+	public function ensure_construct_finalized_called()
1266
+	{
1267
+		if ( ! $this->_construction_finalized) {
1268
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1269
+		}
1270
+	}
1271
+
1272
+
1273
+
1274
+	/**
1275
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1276
+	 * are in teh form data. If any are found, returns true. Else false
1277
+	 *
1278
+	 * @param array $req_data
1279
+	 * @return boolean
1280
+	 */
1281
+	public function form_data_present_in($req_data = null)
1282
+	{
1283
+		if ($req_data === null) {
1284
+			$req_data = $_POST;
1285
+		}
1286
+		foreach ($this->subsections() as $subsection) {
1287
+			if ($subsection instanceof EE_Form_Input_Base) {
1288
+				if ($subsection->form_data_present_in($req_data)) {
1289
+					return true;
1290
+				}
1291
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1292
+				if ($subsection->form_data_present_in($req_data)) {
1293
+					return true;
1294
+				}
1295
+			}
1296
+		}
1297
+		return false;
1298
+	}
1299
+
1300
+
1301
+
1302
+	/**
1303
+	 * Gets validation errors for this form section and subsections
1304
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1305
+	 * gets the validation errors for ALL subsection
1306
+	 *
1307
+	 * @return EE_Validation_Error[]
1308
+	 */
1309
+	public function get_validation_errors_accumulated()
1310
+	{
1311
+		$validation_errors = $this->get_validation_errors();
1312
+		foreach ($this->get_validatable_subsections() as $subsection) {
1313
+			if ($subsection instanceof EE_Form_Section_Proper) {
1314
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1315
+			} else {
1316
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1317
+			}
1318
+			if ($validation_errors_on_this_subsection) {
1319
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1320
+			}
1321
+		}
1322
+		return $validation_errors;
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1329
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1330
+	 * dot-dot-slash (../) means to ascend into the parent section.
1331
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1332
+	 * which will be returned.
1333
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1334
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1335
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1336
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1337
+	 * Etc
1338
+	 *
1339
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1340
+	 * @return EE_Form_Section_Base
1341
+	 */
1342
+	public function find_section_from_path($form_section_path)
1343
+	{
1344
+		//check if we can find the input from purely going straight up the tree
1345
+		$input = parent::find_section_from_path($form_section_path);
1346
+		if ($input instanceof EE_Form_Section_Base) {
1347
+			return $input;
1348
+		}
1349
+		$next_slash_pos = strpos($form_section_path, '/');
1350
+		if ($next_slash_pos !== false) {
1351
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1352
+			$subpath = substr($form_section_path, $next_slash_pos + 1);
1353
+		} else {
1354
+			$child_section_name = $form_section_path;
1355
+			$subpath = '';
1356
+		}
1357
+		$child_section = $this->get_subsection($child_section_name);
1358
+		if ($child_section instanceof EE_Form_Section_Base) {
1359
+			return $child_section->find_section_from_path($subpath);
1360
+		} else {
1361
+			return null;
1362
+		}
1363
+	}
1364 1364
 
1365 1365
 }
1366 1366
 
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 2 patches
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -17,407 +17,407 @@  discard block
 block discarded – undo
17 17
 class EE_Payment_Method_Manager
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EE_Payment_Method_Manager object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array keys are classnames without 'EE_PMT_', values are their filepaths
30
-     */
31
-    protected $_payment_method_types = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EE_Payment_Method_Manager instance
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
44
-            self::$_instance = new self();
45
-        }
46
-        EE_Registry::instance()->load_lib('PMT_Base');
47
-        return self::$_instance;
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     * Resets the instance and returns a new one
54
-     *
55
-     * @return EE_Payment_Method_Manager
56
-     */
57
-    public static function reset()
58
-    {
59
-        self::$_instance = null;
60
-        return self::instance();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * If necessary, re-register payment methods
67
-     *
68
-     * @param boolean $force_recheck whether to recheck for payment method types,
69
-     *                               or just re-use the PMTs we found last time we checked during this request (if
70
-     *                               we have not yet checked during this request, then we need to check anyways)
71
-     */
72
-    public function maybe_register_payment_methods($force_recheck = false)
73
-    {
74
-        if ( ! $this->_payment_method_types || $force_recheck) {
75
-            $this->_register_payment_methods();
76
-            //if in admin lets ensure caps are set.
77
-            if (is_admin()) {
78
-                add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
79
-                EE_Registry::instance()->CAP->init_caps();
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     *        register_payment_methods
88
-     *
89
-     * @return array
90
-     */
91
-    protected function _register_payment_methods()
92
-    {
93
-        // grab list of installed modules
94
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
95
-        // filter list of modules to register
96
-        $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
97
-            $pm_to_register);
98
-        // loop through folders
99
-        foreach ($pm_to_register as $pm_path) {
100
-            $this->register_payment_method($pm_path);
101
-        }
102
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
103
-        // filter list of installed modules
104
-        //keep them organized alphabetically by the payment method type's name
105
-        ksort($this->_payment_method_types);
106
-        return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
107
-            $this->_payment_method_types);
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     *    register_payment_method- makes core aware of this payment method
114
-     *
115
-     * @access public
116
-     * @param string $payment_method_path - full path up to and including payment method folder
117
-     * @return boolean
118
-     */
119
-    public function register_payment_method($payment_method_path = '')
120
-    {
121
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
122
-        $module_ext = '.pm.php';
123
-        // make all separators match
124
-        $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
125
-        // grab and sanitize module name
126
-        $module_dir = basename($payment_method_path);
127
-        // create classname from module directory name
128
-        $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
129
-        // add class prefix
130
-        $module_class = 'EE_PMT_' . $module;
131
-        // does the module exist ?
132
-        if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
133
-            $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
134
-                'event_espresso'), $module);
135
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
136
-            return false;
137
-        }
138
-        if (WP_DEBUG === true) {
139
-            EEH_Debug_Tools::instance()->start_timer();
140
-        }
141
-        // load the module class file
142
-        require_once($payment_method_path . DS . $module_class . $module_ext);
143
-        if (WP_DEBUG === true) {
144
-            EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
145
-        }
146
-        // verify that class exists
147
-        if ( ! class_exists($module_class)) {
148
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
149
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
150
-            return false;
151
-        }
152
-        // add to array of registered modules
153
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
154
-        return true;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * Checks if a payment method has been registered, and if so includes it
161
-     *
162
-     * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
163
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
164
-     * @return boolean
165
-     */
166
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
167
-    {
168
-        if (
169
-            $force_recheck
170
-            || ! is_array($this->_payment_method_types)
171
-            || ! isset($this->_payment_method_types[$payment_method_name])
172
-        ) {
173
-            $this->maybe_register_payment_methods($force_recheck);
174
-        }
175
-        if (isset($this->_payment_method_types[$payment_method_name])) {
176
-            require_once($this->_payment_method_types[$payment_method_name]);
177
-            return true;
178
-        } else {
179
-            return false;
180
-        }
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * Returns all the classnames of the various payment method types
187
-     *
188
-     * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
189
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
190
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
191
-     * @return array
192
-     */
193
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
194
-    {
195
-        $this->maybe_register_payment_methods($force_recheck);
196
-        if ($with_prefixes) {
197
-            $classnames = array_keys($this->_payment_method_types);
198
-            $payment_methods = array();
199
-            foreach ($classnames as $classname) {
200
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
201
-            }
202
-            return $payment_methods;
203
-        } else {
204
-            return array_keys($this->_payment_method_types);
205
-        }
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     * Gets an object of each payment method type, none of which are bound to a
212
-     * payment method instance
213
-     *
214
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
215
-     * @return EE_PMT_Base[]
216
-     */
217
-    public function payment_method_types($force_recheck = false)
218
-    {
219
-        $this->maybe_register_payment_methods($force_recheck);
220
-        $pmt_objs = array();
221
-        foreach ($this->payment_method_type_names(true) as $classname) {
222
-            $pmt_objs[] = new $classname;
223
-        }
224
-        return $pmt_objs;
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * Changes the payment method's classname into the payment method type's name
231
-     * (as used on the payment method's table's PMD_type field)
232
-     *
233
-     * @param string $classname
234
-     * @return string
235
-     */
236
-    public function payment_method_type_sans_class_prefix($classname)
237
-    {
238
-        return str_replace("EE_PMT_", "", $classname);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Does the opposite of payment-method_type_sans_prefix
245
-     *
246
-     * @param string $type
247
-     * @return string
248
-     */
249
-    public function payment_method_class_from_type($type)
250
-    {
251
-        $this->maybe_register_payment_methods();
252
-        return "EE_PMT_" . $type;
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * Activates a payment method of the given type.
259
-     *
260
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
261
-     * @return \EE_Payment_Method
262
-     * @throws \EE_Error
263
-     */
264
-    public function activate_a_payment_method_of_type($payment_method_type)
265
-    {
266
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
267
-        if ( ! $payment_method instanceof EE_Payment_Method) {
268
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
269
-            if (class_exists($pm_type_class)) {
270
-                /** @var $pm_type_obj EE_PMT_Base */
271
-                $pm_type_obj = new $pm_type_class;
272
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
273
-                if ( ! $payment_method) {
274
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
275
-                }
276
-                $payment_method->set_type($payment_method_type);
277
-                $this->initialize_payment_method($payment_method);
278
-            } else {
279
-                throw new EE_Error(
280
-                    sprintf(
281
-                        __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
282
-                        $pm_type_class)
283
-                );
284
-            }
285
-        }
286
-        $payment_method->set_active();
287
-        $payment_method->save();
288
-        $this->set_usable_currencies_on_payment_method($payment_method);
289
-        if ($payment_method->type() === 'Invoice') {
290
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
291
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
292
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
293
-            $message_resource_manager->ensure_messenger_is_active('pdf');
294
-            EE_Error::add_persistent_admin_notice(
295
-                'invoice_pm_requirements_notice',
296
-                sprintf(
297
-                    __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
298
-                        'event_espresso'),
299
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
300
-                    '</a>'
301
-                ),
302
-                true
303
-            );
304
-        }
305
-        return $payment_method;
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * Creates a payment method of the specified type. Does not save it.
312
-     *
313
-     * @global WP_User    $current_user
314
-     * @param EE_PMT_Base $pm_type_obj
315
-     * @return EE_Payment_Method
316
-     * @throws \EE_Error
317
-     */
318
-    public function create_payment_method_of_type($pm_type_obj)
319
-    {
320
-        global $current_user;
321
-        $payment_method = EE_Payment_Method::new_instance(
322
-            array(
323
-                'PMD_type'       => $pm_type_obj->system_name(),
324
-                'PMD_name'       => $pm_type_obj->pretty_name(),
325
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
326
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
327
-                'PMD_wp_user'    => $current_user->ID,
328
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
329
-                        array(array('PMD_type' => array('!=', 'Admin_Only')))
330
-                    ) * 10,
331
-            )
332
-        );
333
-        return $payment_method;
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * Sets the initial payment method properties (including extra meta)
340
-     *
341
-     * @param EE_Payment_Method $payment_method
342
-     * @return EE_Payment_Method
343
-     * @throws \EE_Error
344
-     */
345
-    public function initialize_payment_method($payment_method)
346
-    {
347
-        $pm_type_obj = $payment_method->type_obj();
348
-        $payment_method->set_description($pm_type_obj->default_description());
349
-        if ( ! $payment_method->button_url()) {
350
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
351
-        }
352
-        //now add setup its default extra meta properties
353
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
354
-        if ( ! empty($extra_metas)) {
355
-            //verify the payment method has an ID before adding extra meta
356
-            if ( ! $payment_method->ID()) {
357
-                $payment_method->save();
358
-            }
359
-            foreach ($extra_metas as $meta_name => $input) {
360
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
361
-            }
362
-        }
363
-        return $payment_method;
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * Makes sure the payment method is related to the specified payment method
370
-     *
371
-     * @param EE_Payment_Method $payment_method
372
-     * @return EE_Payment_Method
373
-     * @throws \EE_Error
374
-     */
375
-    public function set_usable_currencies_on_payment_method($payment_method)
376
-    {
377
-        foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
378
-            $payment_method->_add_relation_to($currency_obj, 'Currency');
379
-        }
380
-        return $payment_method;
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Deactivates a payment method of the given payment method slug.
387
-     *
388
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
389
-     * @return int count of rows updated.
390
-     */
391
-    public function deactivate_payment_method($payment_method_slug)
392
-    {
393
-        EE_Log::instance()->log(
394
-            __FILE__,
395
-            __FUNCTION__,
396
-            sprintf(
397
-                __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
398
-                $payment_method_slug
399
-            ),
400
-            'payment_method_change'
401
-        );
402
-        $count_updated = EEM_Payment_Method::instance()->update(
403
-            array('PMD_scope' => array()),
404
-            array(array('PMD_slug' => $payment_method_slug))
405
-        );
406
-        return $count_updated;
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
413
-     * access caps.
414
-     *
415
-     * @param array $caps capabilities being filtered
416
-     * @return array
417
-     */
418
-    public function add_payment_method_caps($caps)
419
-    {
420
-        /* add dynamic caps from payment methods
20
+	/**
21
+	 *    instance of the EE_Payment_Method_Manager object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array keys are classnames without 'EE_PMT_', values are their filepaths
30
+	 */
31
+	protected $_payment_method_types = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EE_Payment_Method_Manager instance
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
44
+			self::$_instance = new self();
45
+		}
46
+		EE_Registry::instance()->load_lib('PMT_Base');
47
+		return self::$_instance;
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 * Resets the instance and returns a new one
54
+	 *
55
+	 * @return EE_Payment_Method_Manager
56
+	 */
57
+	public static function reset()
58
+	{
59
+		self::$_instance = null;
60
+		return self::instance();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * If necessary, re-register payment methods
67
+	 *
68
+	 * @param boolean $force_recheck whether to recheck for payment method types,
69
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
70
+	 *                               we have not yet checked during this request, then we need to check anyways)
71
+	 */
72
+	public function maybe_register_payment_methods($force_recheck = false)
73
+	{
74
+		if ( ! $this->_payment_method_types || $force_recheck) {
75
+			$this->_register_payment_methods();
76
+			//if in admin lets ensure caps are set.
77
+			if (is_admin()) {
78
+				add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
79
+				EE_Registry::instance()->CAP->init_caps();
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 *        register_payment_methods
88
+	 *
89
+	 * @return array
90
+	 */
91
+	protected function _register_payment_methods()
92
+	{
93
+		// grab list of installed modules
94
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
95
+		// filter list of modules to register
96
+		$pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
97
+			$pm_to_register);
98
+		// loop through folders
99
+		foreach ($pm_to_register as $pm_path) {
100
+			$this->register_payment_method($pm_path);
101
+		}
102
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
103
+		// filter list of installed modules
104
+		//keep them organized alphabetically by the payment method type's name
105
+		ksort($this->_payment_method_types);
106
+		return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
107
+			$this->_payment_method_types);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 *    register_payment_method- makes core aware of this payment method
114
+	 *
115
+	 * @access public
116
+	 * @param string $payment_method_path - full path up to and including payment method folder
117
+	 * @return boolean
118
+	 */
119
+	public function register_payment_method($payment_method_path = '')
120
+	{
121
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
122
+		$module_ext = '.pm.php';
123
+		// make all separators match
124
+		$payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
125
+		// grab and sanitize module name
126
+		$module_dir = basename($payment_method_path);
127
+		// create classname from module directory name
128
+		$module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
129
+		// add class prefix
130
+		$module_class = 'EE_PMT_' . $module;
131
+		// does the module exist ?
132
+		if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
133
+			$msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
134
+				'event_espresso'), $module);
135
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
136
+			return false;
137
+		}
138
+		if (WP_DEBUG === true) {
139
+			EEH_Debug_Tools::instance()->start_timer();
140
+		}
141
+		// load the module class file
142
+		require_once($payment_method_path . DS . $module_class . $module_ext);
143
+		if (WP_DEBUG === true) {
144
+			EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
145
+		}
146
+		// verify that class exists
147
+		if ( ! class_exists($module_class)) {
148
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
149
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
150
+			return false;
151
+		}
152
+		// add to array of registered modules
153
+		$this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
154
+		return true;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * Checks if a payment method has been registered, and if so includes it
161
+	 *
162
+	 * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
163
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
164
+	 * @return boolean
165
+	 */
166
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
167
+	{
168
+		if (
169
+			$force_recheck
170
+			|| ! is_array($this->_payment_method_types)
171
+			|| ! isset($this->_payment_method_types[$payment_method_name])
172
+		) {
173
+			$this->maybe_register_payment_methods($force_recheck);
174
+		}
175
+		if (isset($this->_payment_method_types[$payment_method_name])) {
176
+			require_once($this->_payment_method_types[$payment_method_name]);
177
+			return true;
178
+		} else {
179
+			return false;
180
+		}
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Returns all the classnames of the various payment method types
187
+	 *
188
+	 * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
189
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
190
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
191
+	 * @return array
192
+	 */
193
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
194
+	{
195
+		$this->maybe_register_payment_methods($force_recheck);
196
+		if ($with_prefixes) {
197
+			$classnames = array_keys($this->_payment_method_types);
198
+			$payment_methods = array();
199
+			foreach ($classnames as $classname) {
200
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
201
+			}
202
+			return $payment_methods;
203
+		} else {
204
+			return array_keys($this->_payment_method_types);
205
+		}
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 * Gets an object of each payment method type, none of which are bound to a
212
+	 * payment method instance
213
+	 *
214
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
215
+	 * @return EE_PMT_Base[]
216
+	 */
217
+	public function payment_method_types($force_recheck = false)
218
+	{
219
+		$this->maybe_register_payment_methods($force_recheck);
220
+		$pmt_objs = array();
221
+		foreach ($this->payment_method_type_names(true) as $classname) {
222
+			$pmt_objs[] = new $classname;
223
+		}
224
+		return $pmt_objs;
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * Changes the payment method's classname into the payment method type's name
231
+	 * (as used on the payment method's table's PMD_type field)
232
+	 *
233
+	 * @param string $classname
234
+	 * @return string
235
+	 */
236
+	public function payment_method_type_sans_class_prefix($classname)
237
+	{
238
+		return str_replace("EE_PMT_", "", $classname);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Does the opposite of payment-method_type_sans_prefix
245
+	 *
246
+	 * @param string $type
247
+	 * @return string
248
+	 */
249
+	public function payment_method_class_from_type($type)
250
+	{
251
+		$this->maybe_register_payment_methods();
252
+		return "EE_PMT_" . $type;
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * Activates a payment method of the given type.
259
+	 *
260
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
261
+	 * @return \EE_Payment_Method
262
+	 * @throws \EE_Error
263
+	 */
264
+	public function activate_a_payment_method_of_type($payment_method_type)
265
+	{
266
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
267
+		if ( ! $payment_method instanceof EE_Payment_Method) {
268
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
269
+			if (class_exists($pm_type_class)) {
270
+				/** @var $pm_type_obj EE_PMT_Base */
271
+				$pm_type_obj = new $pm_type_class;
272
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
273
+				if ( ! $payment_method) {
274
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
275
+				}
276
+				$payment_method->set_type($payment_method_type);
277
+				$this->initialize_payment_method($payment_method);
278
+			} else {
279
+				throw new EE_Error(
280
+					sprintf(
281
+						__('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
282
+						$pm_type_class)
283
+				);
284
+			}
285
+		}
286
+		$payment_method->set_active();
287
+		$payment_method->save();
288
+		$this->set_usable_currencies_on_payment_method($payment_method);
289
+		if ($payment_method->type() === 'Invoice') {
290
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
291
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
292
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
293
+			$message_resource_manager->ensure_messenger_is_active('pdf');
294
+			EE_Error::add_persistent_admin_notice(
295
+				'invoice_pm_requirements_notice',
296
+				sprintf(
297
+					__('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
298
+						'event_espresso'),
299
+					'<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
300
+					'</a>'
301
+				),
302
+				true
303
+			);
304
+		}
305
+		return $payment_method;
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * Creates a payment method of the specified type. Does not save it.
312
+	 *
313
+	 * @global WP_User    $current_user
314
+	 * @param EE_PMT_Base $pm_type_obj
315
+	 * @return EE_Payment_Method
316
+	 * @throws \EE_Error
317
+	 */
318
+	public function create_payment_method_of_type($pm_type_obj)
319
+	{
320
+		global $current_user;
321
+		$payment_method = EE_Payment_Method::new_instance(
322
+			array(
323
+				'PMD_type'       => $pm_type_obj->system_name(),
324
+				'PMD_name'       => $pm_type_obj->pretty_name(),
325
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
326
+				'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
327
+				'PMD_wp_user'    => $current_user->ID,
328
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
329
+						array(array('PMD_type' => array('!=', 'Admin_Only')))
330
+					) * 10,
331
+			)
332
+		);
333
+		return $payment_method;
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * Sets the initial payment method properties (including extra meta)
340
+	 *
341
+	 * @param EE_Payment_Method $payment_method
342
+	 * @return EE_Payment_Method
343
+	 * @throws \EE_Error
344
+	 */
345
+	public function initialize_payment_method($payment_method)
346
+	{
347
+		$pm_type_obj = $payment_method->type_obj();
348
+		$payment_method->set_description($pm_type_obj->default_description());
349
+		if ( ! $payment_method->button_url()) {
350
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
351
+		}
352
+		//now add setup its default extra meta properties
353
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
354
+		if ( ! empty($extra_metas)) {
355
+			//verify the payment method has an ID before adding extra meta
356
+			if ( ! $payment_method->ID()) {
357
+				$payment_method->save();
358
+			}
359
+			foreach ($extra_metas as $meta_name => $input) {
360
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
361
+			}
362
+		}
363
+		return $payment_method;
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * Makes sure the payment method is related to the specified payment method
370
+	 *
371
+	 * @param EE_Payment_Method $payment_method
372
+	 * @return EE_Payment_Method
373
+	 * @throws \EE_Error
374
+	 */
375
+	public function set_usable_currencies_on_payment_method($payment_method)
376
+	{
377
+		foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
378
+			$payment_method->_add_relation_to($currency_obj, 'Currency');
379
+		}
380
+		return $payment_method;
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Deactivates a payment method of the given payment method slug.
387
+	 *
388
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
389
+	 * @return int count of rows updated.
390
+	 */
391
+	public function deactivate_payment_method($payment_method_slug)
392
+	{
393
+		EE_Log::instance()->log(
394
+			__FILE__,
395
+			__FUNCTION__,
396
+			sprintf(
397
+				__('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
398
+				$payment_method_slug
399
+			),
400
+			'payment_method_change'
401
+		);
402
+		$count_updated = EEM_Payment_Method::instance()->update(
403
+			array('PMD_scope' => array()),
404
+			array(array('PMD_slug' => $payment_method_slug))
405
+		);
406
+		return $count_updated;
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
413
+	 * access caps.
414
+	 *
415
+	 * @param array $caps capabilities being filtered
416
+	 * @return array
417
+	 */
418
+	public function add_payment_method_caps($caps)
419
+	{
420
+		/* add dynamic caps from payment methods
421 421
          * at the time of writing, october 20 2014, these are the caps added:
422 422
          * ee_payment_method_admin_only
423 423
          * ee_payment_method_aim
@@ -431,10 +431,10 @@  discard block
 block discarded – undo
431 431
          * their related capability automatically added too, so long as they are
432 432
          * registered properly using EE_Register_Payment_Method::register()
433 433
          */
434
-        foreach ($this->payment_method_types() as $payment_method_type_obj) {
435
-            $caps['administrator'][] = $payment_method_type_obj->cap_name();
436
-        }
437
-        return $caps;
438
-    }
434
+		foreach ($this->payment_method_types() as $payment_method_type_obj) {
435
+			$caps['administrator'][] = $payment_method_type_obj->cap_name();
436
+		}
437
+		return $caps;
438
+	}
439 439
 
440 440
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
     protected function _register_payment_methods()
92 92
     {
93 93
         // grab list of installed modules
94
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
94
+        $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR);
95 95
         // filter list of modules to register
96 96
         $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
97 97
             $pm_to_register);
@@ -127,30 +127,30 @@  discard block
 block discarded – undo
127 127
         // create classname from module directory name
128 128
         $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
129 129
         // add class prefix
130
-        $module_class = 'EE_PMT_' . $module;
130
+        $module_class = 'EE_PMT_'.$module;
131 131
         // does the module exist ?
132
-        if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
132
+        if ( ! is_readable($payment_method_path.DS.$module_class.$module_ext)) {
133 133
             $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
134 134
                 'event_espresso'), $module);
135
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
135
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
136 136
             return false;
137 137
         }
138 138
         if (WP_DEBUG === true) {
139 139
             EEH_Debug_Tools::instance()->start_timer();
140 140
         }
141 141
         // load the module class file
142
-        require_once($payment_method_path . DS . $module_class . $module_ext);
142
+        require_once($payment_method_path.DS.$module_class.$module_ext);
143 143
         if (WP_DEBUG === true) {
144 144
             EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
145 145
         }
146 146
         // verify that class exists
147 147
         if ( ! class_exists($module_class)) {
148 148
             $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
149
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
150 150
             return false;
151 151
         }
152 152
         // add to array of registered modules
153
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
153
+        $this->_payment_method_types[$module] = $payment_method_path.DS.$module_class.$module_ext;
154 154
         return true;
155 155
     }
156 156
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     public function payment_method_class_from_type($type)
250 250
     {
251 251
         $this->maybe_register_payment_methods();
252
-        return "EE_PMT_" . $type;
252
+        return "EE_PMT_".$type;
253 253
     }
254 254
 
255 255
 
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
                 sprintf(
297 297
                     __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
298 298
                         'event_espresso'),
299
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
299
+                    '<a href="'.admin_url('admin.php?page=espresso_messages').'">',
300 300
                     '</a>'
301 301
                 ),
302 302
                 true
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                 'PMD_type'       => $pm_type_obj->system_name(),
324 324
                 'PMD_name'       => $pm_type_obj->pretty_name(),
325 325
                 'PMD_admin_name' => $pm_type_obj->pretty_name(),
326
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
326
+                'PMD_slug'       => $pm_type_obj->system_name(), //automatically converted to slug
327 327
                 'PMD_wp_user'    => $current_user->ID,
328 328
                 'PMD_order'      => EEM_Payment_Method::instance()->count(
329 329
                         array(array('PMD_type' => array('!=', 'Admin_Only')))
Please login to merge, or discard this patch.
core/libraries/plugin_api/db/EEME_Base.lib.php 3 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	public function __construct(){
73 73
 		if( ! $this->_model_name_extended){
74
-            throw new EE_Error(
75
-                __( "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
76
-                "event_espresso" )
77
-            );
74
+			throw new EE_Error(
75
+				__( "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
76
+				"event_espresso" )
77
+			);
78 78
 		}
79 79
 		$construct_end_action = 'AHEE__EEM_'.$this->_model_name_extended.'__construct__end';
80 80
 		if ( did_action( $construct_end_action )) {
@@ -95,30 +95,30 @@  discard block
 block discarded – undo
95 95
 
96 96
 
97 97
 
98
-    /**
99
-     * @param array $existing_tables
100
-     * @return array
101
-     */
102
-    public function add_extra_tables_on_filter( $existing_tables ){
103
-        return array_merge( (array)$existing_tables, $this->_extra_tables );
98
+	/**
99
+	 * @param array $existing_tables
100
+	 * @return array
101
+	 */
102
+	public function add_extra_tables_on_filter( $existing_tables ){
103
+		return array_merge( (array)$existing_tables, $this->_extra_tables );
104 104
 	}
105 105
 
106 106
 
107 107
 
108
-    /**
109
-     * @param array $existing_fields
110
-     * @return array
111
-     */
112
-    public function add_extra_fields_on_filter( $existing_fields ){
108
+	/**
109
+	 * @param array $existing_fields
110
+	 * @return array
111
+	 */
112
+	public function add_extra_fields_on_filter( $existing_fields ){
113 113
 		if( $this->_extra_fields){
114 114
 			foreach($this->_extra_fields as $table_alias => $fields){
115 115
 				if( ! isset( $existing_fields[ $table_alias ] ) ){
116 116
 					$existing_fields[ $table_alias ] = array();
117 117
 				}
118 118
 				$existing_fields[$table_alias] = array_merge(
119
-                    (array)$existing_fields[$table_alias],
120
-                    $this->_extra_fields[$table_alias]
121
-                );
119
+					(array)$existing_fields[$table_alias],
120
+					$this->_extra_fields[$table_alias]
121
+				);
122 122
 
123 123
 			}
124 124
 		}
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * @param array $existing_relations
132
-     * @return array
133
-     */
134
-    public function add_extra_relations_on_filter( $existing_relations ){
135
-        return  array_merge((array)$existing_relations,$this->_extra_relations);
130
+	/**
131
+	 * @param array $existing_relations
132
+	 * @return array
133
+	 */
134
+	public function add_extra_relations_on_filter( $existing_relations ){
135
+		return  array_merge((array)$existing_relations,$this->_extra_relations);
136 136
 	}
137 137
 
138 138
 
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 				remove_filter($callback_name,array($this,self::dynamic_callback_method_prefix.$method_name_on_model),10);
169 169
 			}
170 170
 		}
171
-        /** @var EEM_Base $model_to_reset */
172
-        $model_to_reset = 'EEM_' . $this->_model_name_extended;
171
+		/** @var EEM_Base $model_to_reset */
172
+		$model_to_reset = 'EEM_' . $this->_model_name_extended;
173 173
 		if ( class_exists( $model_to_reset ) ) {
174 174
 			$model_to_reset::reset();
175 175
 		}
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
 
178 178
 
179 179
 
180
-    /**
181
-     * @param string $callback_method_name
182
-     * @param array  $args
183
-     * @return mixed
184
-     * @throws EE_Error
185
-     */
186
-    public function __call( $callback_method_name, $args){
180
+	/**
181
+	 * @param string $callback_method_name
182
+	 * @param array  $args
183
+	 * @return mixed
184
+	 * @throws EE_Error
185
+	 */
186
+	public function __call( $callback_method_name, $args){
187 187
 		if(strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0){
188 188
 			//it's a dynamic callback for a method name
189 189
 			$method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
@@ -194,23 +194,23 @@  discard block
 block discarded – undo
194 194
 				return call_user_func_array(array($this,$extending_method), $args_provided_to_method_on_model);
195 195
 			}else{
196 196
 				throw new EE_Error(
197
-				    sprintf(
198
-				        __("An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", "event_espresso"),
199
-                        $this->_model_name_extended,
200
-                        get_class($this),
201
-                        $extending_method,$extending_method
202
-                    )
203
-                );
197
+					sprintf(
198
+						__("An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", "event_espresso"),
199
+						$this->_model_name_extended,
200
+						get_class($this),
201
+						$extending_method,$extending_method
202
+					)
203
+				);
204 204
 			}
205 205
 
206 206
 		}else{
207 207
 			throw new EE_Error(
208
-			    sprintf(
209
-			        __("There is no method named '%s' on '%s'", "event_espresso"),
210
-                    $callback_method_name,
211
-                    get_class($this)
212
-                )
213
-            );
208
+				sprintf(
209
+					__("There is no method named '%s' on '%s'", "event_espresso"),
210
+					$callback_method_name,
211
+					get_class($this)
212
+				)
213
+			);
214 214
 		}
215 215
 	}
216 216
 
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 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
 /**
@@ -69,27 +69,27 @@  discard block
 block discarded – undo
69 69
 	/**
70 70
 	 * @throws \EE_Error
71 71
 	 */
72
-	public function __construct(){
73
-		if( ! $this->_model_name_extended){
72
+	public function __construct() {
73
+		if ( ! $this->_model_name_extended) {
74 74
             throw new EE_Error(
75
-                __( "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
76
-                "event_espresso" )
75
+                __("When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
76
+                "event_espresso")
77 77
             );
78 78
 		}
79 79
 		$construct_end_action = 'AHEE__EEM_'.$this->_model_name_extended.'__construct__end';
80
-		if ( did_action( $construct_end_action )) {
80
+		if (did_action($construct_end_action)) {
81 81
 			throw new EE_Error(
82 82
 				sprintf(
83
-					__( "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", "event_espresso"),
83
+					__("Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", "event_espresso"),
84 84
 					get_class($this),
85 85
 					$this->_model_name_extended,
86 86
 					$construct_end_action
87 87
 				)
88 88
 			);
89 89
 		}
90
-		add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',array($this,'add_extra_tables_on_filter'));
91
-		add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',array($this,'add_extra_fields_on_filter'));
92
-		add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',array($this,'add_extra_relations_on_filter'));
90
+		add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', array($this, 'add_extra_tables_on_filter'));
91
+		add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', array($this, 'add_extra_fields_on_filter'));
92
+		add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', array($this, 'add_extra_relations_on_filter'));
93 93
 		$this->_register_extending_methods();
94 94
 	}
95 95
 
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
      * @param array $existing_tables
100 100
      * @return array
101 101
      */
102
-    public function add_extra_tables_on_filter( $existing_tables ){
103
-        return array_merge( (array)$existing_tables, $this->_extra_tables );
102
+    public function add_extra_tables_on_filter($existing_tables) {
103
+        return array_merge((array) $existing_tables, $this->_extra_tables);
104 104
 	}
105 105
 
106 106
 
@@ -109,14 +109,14 @@  discard block
 block discarded – undo
109 109
      * @param array $existing_fields
110 110
      * @return array
111 111
      */
112
-    public function add_extra_fields_on_filter( $existing_fields ){
113
-		if( $this->_extra_fields){
114
-			foreach($this->_extra_fields as $table_alias => $fields){
115
-				if( ! isset( $existing_fields[ $table_alias ] ) ){
116
-					$existing_fields[ $table_alias ] = array();
112
+    public function add_extra_fields_on_filter($existing_fields) {
113
+		if ($this->_extra_fields) {
114
+			foreach ($this->_extra_fields as $table_alias => $fields) {
115
+				if ( ! isset($existing_fields[$table_alias])) {
116
+					$existing_fields[$table_alias] = array();
117 117
 				}
118 118
 				$existing_fields[$table_alias] = array_merge(
119
-                    (array)$existing_fields[$table_alias],
119
+                    (array) $existing_fields[$table_alias],
120 120
                     $this->_extra_fields[$table_alias]
121 121
                 );
122 122
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
      * @param array $existing_relations
132 132
      * @return array
133 133
      */
134
-    public function add_extra_relations_on_filter( $existing_relations ){
135
-        return  array_merge((array)$existing_relations,$this->_extra_relations);
134
+    public function add_extra_relations_on_filter($existing_relations) {
135
+        return  array_merge((array) $existing_relations, $this->_extra_relations);
136 136
 	}
137 137
 
138 138
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the
142 142
 	 * model extended. (Internally uses filters, and the __call magic method)
143 143
 	 */
144
-	protected function _register_extending_methods(){
144
+	protected function _register_extending_methods() {
145 145
 		$all_methods = get_class_methods(get_class($this));
146
-		foreach($all_methods as $method_name){
147
-			if(strpos($method_name, self::extending_method_prefix) === 0){
146
+		foreach ($all_methods as $method_name) {
147
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
148 148
 				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
149 149
 				$callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
150
-				add_filter($callback_name,array($this,self::dynamic_callback_method_prefix.$method_name_on_model),10,10);
150
+				add_filter($callback_name, array($this, self::dynamic_callback_method_prefix.$method_name_on_model), 10, 10);
151 151
 			}
152 152
 		}
153 153
 	}
@@ -156,21 +156,21 @@  discard block
 block discarded – undo
156 156
 	 * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the
157 157
 	 * model extended. (Internally uses filters, and the __call magic method)
158 158
 	 */
159
-	public function deregister(){
160
-		remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',array($this,'add_extra_tables_on_filter'));
161
-		remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',array($this,'add_extra_fields_on_filter'));
162
-		remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',array($this,'add_extra_relations_on_filter'));
159
+	public function deregister() {
160
+		remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', array($this, 'add_extra_tables_on_filter'));
161
+		remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', array($this, 'add_extra_fields_on_filter'));
162
+		remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', array($this, 'add_extra_relations_on_filter'));
163 163
 		$all_methods = get_class_methods(get_class($this));
164
-		foreach($all_methods as $method_name){
165
-			if(strpos($method_name, self::extending_method_prefix) === 0){
164
+		foreach ($all_methods as $method_name) {
165
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
166 166
 				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
167 167
 				$callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
168
-				remove_filter($callback_name,array($this,self::dynamic_callback_method_prefix.$method_name_on_model),10);
168
+				remove_filter($callback_name, array($this, self::dynamic_callback_method_prefix.$method_name_on_model), 10);
169 169
 			}
170 170
 		}
171 171
         /** @var EEM_Base $model_to_reset */
172
-        $model_to_reset = 'EEM_' . $this->_model_name_extended;
173
-		if ( class_exists( $model_to_reset ) ) {
172
+        $model_to_reset = 'EEM_'.$this->_model_name_extended;
173
+		if (class_exists($model_to_reset)) {
174 174
 			$model_to_reset::reset();
175 175
 		}
176 176
 	}
@@ -183,27 +183,27 @@  discard block
 block discarded – undo
183 183
      * @return mixed
184 184
      * @throws EE_Error
185 185
      */
186
-    public function __call( $callback_method_name, $args){
187
-		if(strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0){
186
+    public function __call($callback_method_name, $args) {
187
+		if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) {
188 188
 			//it's a dynamic callback for a method name
189 189
 			$method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
190
-			list( $original_return_val, $model_called, $args_provided_to_method_on_model ) = (array) $args;
190
+			list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args;
191 191
 			$this->_ = $model_called;
192 192
 			$extending_method = self::extending_method_prefix.$method_called_on_model;
193
-			if(method_exists($this, $extending_method)){
194
-				return call_user_func_array(array($this,$extending_method), $args_provided_to_method_on_model);
195
-			}else{
193
+			if (method_exists($this, $extending_method)) {
194
+				return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
195
+			} else {
196 196
 				throw new EE_Error(
197 197
 				    sprintf(
198 198
 				        __("An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", "event_espresso"),
199 199
                         $this->_model_name_extended,
200 200
                         get_class($this),
201
-                        $extending_method,$extending_method
201
+                        $extending_method, $extending_method
202 202
                     )
203 203
                 );
204 204
 			}
205 205
 
206
-		}else{
206
+		} else {
207 207
 			throw new EE_Error(
208 208
 			    sprintf(
209 209
 			        __("There is no method named '%s' on '%s'", "event_espresso"),
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@  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 7
 /**
7 8
  *
@@ -192,7 +193,7 @@  discard block
 block discarded – undo
192 193
 			$extending_method = self::extending_method_prefix.$method_called_on_model;
193 194
 			if(method_exists($this, $extending_method)){
194 195
 				return call_user_func_array(array($this,$extending_method), $args_provided_to_method_on_model);
195
-			}else{
196
+			} else{
196 197
 				throw new EE_Error(
197 198
 				    sprintf(
198 199
 				        __("An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", "event_espresso"),
@@ -203,7 +204,7 @@  discard block
 block discarded – undo
203 204
                 );
204 205
 			}
205 206
 
206
-		}else{
207
+		} else{
207 208
 			throw new EE_Error(
208 209
 			    sprintf(
209 210
 			        __("There is no method named '%s' on '%s'", "event_espresso"),
Please login to merge, or discard this patch.
core/EE_Front_Controller.core.php 2 patches
Indentation   +663 added lines, -663 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
 /**
@@ -22,668 +22,668 @@  discard block
 block discarded – undo
22 22
 final class EE_Front_Controller
23 23
 {
24 24
 
25
-    /**
26
-     *    $_template_path
27
-     * @var    string $_template_path
28
-     * @access    public
29
-     */
30
-    private $_template_path;
31
-
32
-    /**
33
-     *    $_template
34
-     * @var    string $_template
35
-     * @access    public
36
-     */
37
-    private $_template;
38
-
39
-    /**
40
-     * @type  EE_Registry $Registry
41
-     * @access    protected
42
-     */
43
-    protected $Registry;
44
-
45
-    /**
46
-     * @type  EE_Request_Handler $Request_Handler
47
-     * @access    protected
48
-     */
49
-    protected $Request_Handler;
50
-
51
-    /**
52
-     * @type  EE_Module_Request_Router $Module_Request_Router
53
-     * @access    protected
54
-     */
55
-    protected $Module_Request_Router;
56
-
57
-
58
-    /**
59
-     *    class constructor
60
-     *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
61
-     *
62
-     * @access    public
63
-     * @param \EE_Registry              $Registry
64
-     * @param \EE_Request_Handler       $Request_Handler
65
-     * @param \EE_Module_Request_Router $Module_Request_Router
66
-     */
67
-    public function __construct(
68
-        EE_Registry $Registry,
69
-        EE_Request_Handler $Request_Handler,
70
-        EE_Module_Request_Router $Module_Request_Router
71
-    ) {
72
-        $this->Registry              = $Registry;
73
-        $this->Request_Handler       = $Request_Handler;
74
-        $this->Module_Request_Router = $Module_Request_Router;
75
-        // make sure template tags are loaded immediately so that themes don't break
76
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10);
77
-        // determine how to integrate WP_Query with the EE models
78
-        add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
79
-        // load other resources and begin to actually run shortcodes and modules
80
-        add_action('wp_loaded', array($this, 'wp_loaded'), 5);
81
-        // analyse the incoming WP request
82
-        add_action('parse_request', array($this, 'get_request'), 1, 1);
83
-        // process any content shortcodes
84
-        add_action('parse_request', array($this, '_initialize_shortcodes'), 5);
85
-        // process request with module factory
86
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
87
-        // before headers sent
88
-        add_action('wp', array($this, 'wp'), 5);
89
-        // load css and js
90
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1);
91
-        // header
92
-        add_action('wp_head', array($this, 'header_meta_tag'), 5);
93
-        add_filter('template_include', array($this, 'template_include'), 1);
94
-        // display errors
95
-        add_action('loop_start', array($this, 'display_errors'), 2);
96
-        // the content
97
-        // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
98
-        //exclude our private cpt comments
99
-        add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
100
-        //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
101
-        add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
102
-        // action hook EE
103
-        do_action('AHEE__EE_Front_Controller__construct__done', $this);
104
-        // for checking that browser cookies are enabled
105
-        if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) {
106
-            setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/');
107
-        }
108
-    }
109
-
110
-
111
-    /**
112
-     * @return EE_Request_Handler
113
-     */
114
-    public function Request_Handler()
115
-    {
116
-        return $this->Request_Handler;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return EE_Module_Request_Router
122
-     */
123
-    public function Module_Request_Router()
124
-    {
125
-        return $this->Module_Request_Router;
126
-    }
127
-
128
-
129
-
130
-
131
-
132
-    /***********************************************        INIT ACTION HOOK         ***********************************************/
133
-
134
-
135
-    /**
136
-     *    load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then
137
-     *    load it's functions.php file ( if not already loaded )
138
-     *
139
-     * @return void
140
-     */
141
-    public function load_espresso_template_tags()
142
-    {
143
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
144
-            require_once(EE_PUBLIC . 'template_tags.php');
145
-        }
146
-    }
147
-
148
-
149
-    /**
150
-     * filter_wp_comments
151
-     * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
152
-     * widgets/queries done on frontend
153
-     *
154
-     * @param  array $clauses array of comment clauses setup by WP_Comment_Query
155
-     * @return array array of comment clauses with modifications.
156
-     */
157
-    public function filter_wp_comments($clauses)
158
-    {
159
-        global $wpdb;
160
-        if (strpos($clauses['join'], $wpdb->posts) !== false) {
161
-            $cpts = EE_Register_CPTs::get_private_CPTs();
162
-            foreach ($cpts as $cpt => $details) {
163
-                $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
164
-            }
165
-        }
166
-        return $clauses;
167
-    }
168
-
169
-
170
-    /**
171
-     *    employ_CPT_Strategy
172
-     *
173
-     * @access    public
174
-     * @return    void
175
-     */
176
-    public function employ_CPT_Strategy()
177
-    {
178
-        if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
179
-            $this->Registry->load_core('CPT_Strategy');
180
-        }
181
-    }
182
-
183
-
184
-    /**
185
-     * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
186
-     *
187
-     * @param  string $url incoming url
188
-     * @return string         final assembled url
189
-     */
190
-    public function maybe_force_admin_ajax_ssl($url)
191
-    {
192
-        if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
193
-            $url = str_replace('http://', 'https://', $url);
194
-        }
195
-        return $url;
196
-    }
197
-
198
-
199
-
200
-
201
-
202
-
203
-    /***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
204
-
205
-
206
-    /**
207
-     *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
208
-     *    default priority init phases have run
209
-     *
210
-     * @access    public
211
-     * @return    void
212
-     */
213
-    public function wp_loaded()
214
-    {
215
-    }
216
-
217
-
218
-
219
-
220
-
221
-    /***********************************************        PARSE_REQUEST HOOK         ***********************************************/
222
-    /**
223
-     *    _get_request
224
-     *
225
-     * @access public
226
-     * @param WP $WP
227
-     * @return void
228
-     */
229
-    public function get_request(WP $WP)
230
-    {
231
-        do_action('AHEE__EE_Front_Controller__get_request__start');
232
-        $this->Request_Handler->parse_request($WP);
233
-        do_action('AHEE__EE_Front_Controller__get_request__complete');
234
-    }
235
-
236
-
237
-    /**
238
-     *    _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for
239
-     *    the currently requested page
240
-     *
241
-     * @access    public
242
-     * @param WP $WP
243
-     * @return    void
244
-     */
245
-    public function _initialize_shortcodes(WP $WP)
246
-    {
247
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this);
248
-        $this->Request_Handler->set_request_vars($WP);
249
-        // grab post_name from request
250
-        $current_post  = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
251
-            $this->Request_Handler->get('post_name'));
252
-        $show_on_front = get_option('show_on_front');
253
-        // if it's not set, then check if frontpage is blog
254
-        if (empty($current_post)) {
255
-            // yup.. this is the posts page, prepare to load all shortcode modules
256
-            $current_post = 'posts';
257
-            // unless..
258
-            if ($show_on_front === 'page') {
259
-                // some other page is set as the homepage
260
-                $page_on_front = get_option('page_on_front');
261
-                if ($page_on_front) {
262
-                    // k now we need to find the post_name for this page
263
-                    global $wpdb;
264
-                    $page_on_front = $wpdb->get_var(
265
-                        $wpdb->prepare(
266
-                            "SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d",
267
-                            $page_on_front
268
-                        )
269
-                    );
270
-                    // set the current post slug to what it actually is
271
-                    $current_post = $page_on_front ? $page_on_front : $current_post;
272
-                }
273
-            }
274
-        }
275
-        // where are posts being displayed ?
276
-        $page_for_posts = EE_Config::get_page_for_posts();
277
-        // in case $current_post is hierarchical like: /parent-page/current-page
278
-        $current_post = basename($current_post);
279
-        // are we on a category page?
280
-        $term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name',
281
-                $WP->query_vars);
282
-        // make sure shortcodes are set
283
-        if (isset($this->Registry->CFG->core->post_shortcodes)) {
284
-            if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) {
285
-                $this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array();
286
-            }
287
-            // cycle thru all posts with shortcodes set
288
-            foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) {
289
-                // filter shortcodes so
290
-                $post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes',
291
-                    $post_shortcodes);
292
-                // now cycle thru shortcodes
293
-                foreach ($post_shortcodes as $shortcode_class => $post_id) {
294
-                    // are we on this page, or on the blog page, or an EE CPT category page ?
295
-                    if ($current_post === $post_name || $term_exists) {
296
-                        // maybe init the shortcode
297
-                        $this->initialize_shortcode_if_active_on_page(
298
-                            $shortcode_class,
299
-                            $current_post,
300
-                            $page_for_posts,
301
-                            $post_id,
302
-                            $term_exists,
303
-                            $WP
304
-                        );
305
-                        // if this is NOT the "Posts page" and we have a valid entry
306
-                        // for the "Posts page" in our tracked post_shortcodes array
307
-                        // but the shortcode is not being tracked for this page
308
-                    } else if (
309
-                        $post_name !== $page_for_posts
310
-                        && isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])
311
-                        && ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class])
312
-                    ) {
313
-                        // then remove the "fallback" shortcode processor
314
-                        remove_shortcode($shortcode_class);
315
-                    }
316
-                }
317
-            }
318
-        }
319
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this);
320
-    }
321
-
322
-
323
-    /**
324
-     * @param string $shortcode_class
325
-     * @param string $current_post
326
-     * @param string $page_for_posts
327
-     * @param int    $post_id
328
-     * @param bool   $term_exists
329
-     * @param WP     $WP
330
-     */
331
-    protected function initialize_shortcode_if_active_on_page(
332
-        $shortcode_class,
333
-        $current_post,
334
-        $page_for_posts,
335
-        $post_id,
336
-        $term_exists,
337
-        $WP
338
-    ) {
339
-        // verify shortcode is in list of registered shortcodes
340
-        if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) {
341
-            if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) {
342
-                EE_Error::add_error(
343
-                    sprintf(
344
-                        __(
345
-                            'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.',
346
-                            'event_espresso'
347
-                        ),
348
-                        $shortcode_class
349
-                    ),
350
-                    __FILE__,
351
-                    __FUNCTION__,
352
-                    __LINE__
353
-                );
354
-                add_filter('FHEE_run_EE_the_content', '__return_true');
355
-            }
356
-            add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor'));
357
-            return;
358
-        }
359
-        // is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ?
360
-        if (
361
-            $term_exists
362
-            || $current_post === $page_for_posts
363
-            || isset($this->Registry->CFG->core->post_shortcodes[$current_post])
364
-        ) {
365
-            // let's pause to reflect on this...
366
-            $sc_reflector = new ReflectionClass('EES_' . $shortcode_class);
367
-            // ensure that class is actually a shortcode
368
-            if (
369
-                defined('WP_DEBUG')
370
-                && WP_DEBUG === true
371
-                && ! $sc_reflector->isSubclassOf('EES_Shortcode')
372
-            ) {
373
-                EE_Error::add_error(
374
-                    sprintf(
375
-                        __(
376
-                            'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
377
-                            'event_espresso'
378
-                        ),
379
-                        $shortcode_class
380
-                    ),
381
-                    __FILE__,
382
-                    __FUNCTION__,
383
-                    __LINE__
384
-                );
385
-                add_filter('FHEE_run_EE_the_content', '__return_true');
386
-                return;
387
-            }
388
-            // and pass the request object to the run method
389
-            $this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
390
-            // fire the shortcode class's run method, so that it can activate resources
391
-            $this->Registry->shortcodes->{$shortcode_class}->run($WP);
392
-        }
393
-    }
394
-
395
-
396
-    /**
397
-     *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
398
-     *
399
-     * @access    public
400
-     * @param   WP_Query $WP_Query
401
-     * @return    void
402
-     */
403
-    public function pre_get_posts($WP_Query)
404
-    {
405
-        // only load Module_Request_Router if this is the main query
406
-        if (
407
-            $this->Module_Request_Router instanceof EE_Module_Request_Router
408
-            && $WP_Query->is_main_query()
409
-        ) {
410
-            // cycle thru module routes
411
-            while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
412
-                // determine module and method for route
413
-                $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
414
-                if ($module instanceof EED_Module) {
415
-                    // get registered view for route
416
-                    $this->_template_path = $this->Module_Request_Router->get_view($route);
417
-                    // grab module name
418
-                    $module_name = $module->module_name();
419
-                    // map the module to the module objects
420
-                    $this->Registry->modules->{$module_name} = $module;
421
-                }
422
-            }
423
-        }
424
-    }
425
-
426
-
427
-
428
-
429
-
430
-    /***********************************************        WP HOOK         ***********************************************/
431
-
432
-
433
-    /**
434
-     *    wp - basically last chance to do stuff before headers sent
435
-     *
436
-     * @access    public
437
-     * @return    void
438
-     */
439
-    public function wp()
440
-    {
441
-    }
442
-
443
-
444
-
445
-    /***********************************************        WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK         ***********************************************/
446
-
447
-
448
-    /**
449
-     *    wp_enqueue_scripts
450
-     *
451
-     * @access    public
452
-     * @return    void
453
-     */
454
-    public function wp_enqueue_scripts()
455
-    {
456
-
457
-        // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_css', '__return_false' );
458
-        if (apply_filters('FHEE_load_css', true)) {
459
-
460
-            $this->Registry->CFG->template_settings->enable_default_style = true;
461
-            //Load the ThemeRoller styles if enabled
462
-            if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) {
463
-
464
-                //Load custom style sheet if available
465
-                if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
466
-                    wp_register_style('espresso_custom_css',
467
-                        EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
468
-                        EVENT_ESPRESSO_VERSION);
469
-                    wp_enqueue_style('espresso_custom_css');
470
-                }
471
-
472
-                if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
473
-                    wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
474
-                        array('dashicons'), EVENT_ESPRESSO_VERSION);
475
-                } else {
476
-                    wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
477
-                        array('dashicons'), EVENT_ESPRESSO_VERSION);
478
-                }
479
-                wp_enqueue_style('espresso_default');
480
-
481
-                if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
482
-                    wp_register_style('espresso_style',
483
-                        get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
484
-                        array('dashicons', 'espresso_default'));
485
-                } else {
486
-                    wp_register_style('espresso_style',
487
-                        EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
488
-                        array('dashicons', 'espresso_default'));
489
-                }
490
-
491
-            }
492
-
493
-        }
494
-
495
-        // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_js', '__return_false' );
496
-        if (apply_filters('FHEE_load_js', true)) {
497
-
498
-            wp_enqueue_script('jquery');
499
-            //let's make sure that all required scripts have been setup
500
-            if (function_exists('wp_script_is') && ! wp_script_is('jquery')) {
501
-                $msg = sprintf(
502
-                    __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.',
503
-                        'event_espresso'),
504
-                    '<em><br />',
505
-                    '</em>'
506
-                );
507
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
508
-            }
509
-            // load core js
510
-            wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
511
-                EVENT_ESPRESSO_VERSION, true);
512
-            wp_enqueue_script('espresso_core');
513
-            wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
514
-
515
-        }
516
-
517
-        //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
518
-        if (apply_filters('FHEE_load_qtip', false)) {
519
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
520
-        }
521
-
522
-
523
-        //accounting.js library
524
-        // @link http://josscrowcroft.github.io/accounting.js/
525
-        if (apply_filters('FHEE_load_accounting_js', false)) {
526
-            $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
527
-            wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
528
-                array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
529
-            wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
530
-            wp_enqueue_script('ee-accounting');
531
-
532
-            $currency_config = array(
533
-                'currency' => array(
534
-                    'symbol'    => $this->Registry->CFG->currency->sign,
535
-                    'format'    => array(
536
-                        'pos'  => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
537
-                        'neg'  => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
538
-                        'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s',
539
-                    ),
540
-                    'decimal'   => $this->Registry->CFG->currency->dec_mrk,
541
-                    'thousand'  => $this->Registry->CFG->currency->thsnds,
542
-                    'precision' => $this->Registry->CFG->currency->dec_plc,
543
-                ),
544
-                'number'   => array(
545
-                    'precision' => 0,
546
-                    'thousand'  => $this->Registry->CFG->currency->thsnds,
547
-                    'decimal'   => $this->Registry->CFG->currency->dec_mrk,
548
-                ),
549
-            );
550
-            wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
551
-        }
552
-
553
-        if ( ! function_exists('wp_head')) {
554
-            $msg = sprintf(
555
-                __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
556
-                    'event_espresso'),
557
-                '<em><br />',
558
-                '</em>'
559
-            );
560
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
561
-        }
562
-        if ( ! function_exists('wp_footer')) {
563
-            $msg = sprintf(
564
-                __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
565
-                    'event_espresso'),
566
-                '<em><br />',
567
-                '</em>'
568
-            );
569
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
570
-        }
571
-
572
-    }
573
-
574
-
575
-    /**
576
-     *    header_meta_tag
577
-     *
578
-     * @access    public
579
-     * @return    void
580
-     */
581
-    public function header_meta_tag()
582
-    {
583
-        print(
584
-            apply_filters(
585
-                'FHEE__EE_Front_Controller__header_meta_tag',
586
-                '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
587
-        );
588
-
589
-        //let's exclude all event type taxonomy term archive pages from search engine indexing
590
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
591
-        if (
592
-            is_tax('espresso_event_type')
593
-            && get_option( 'blog_public' ) !== '0'
594
-        ) {
595
-            print(
596
-                apply_filters(
597
-                    'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
598
-                    '<meta name="robots" content="noindex,follow" />' . "\n"
599
-                )
600
-            );
601
-        }
602
-    }
603
-
604
-
605
-
606
-
607
-    /***********************************************        THE_CONTENT FILTER HOOK         ***********************************************/
608
-    /**
609
-     *    the_content
610
-     *
611
-     * @access    public
612
-     * @param   $the_content
613
-     * @return    string
614
-     */
615
-    // public function the_content( $the_content ) {
616
-    // 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
617
-    // 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
618
-    // 	}
619
-    // 	return $the_content;
620
-    // }
621
-
622
-
623
-    /***********************************************        WP_FOOTER         ***********************************************/
624
-
625
-
626
-    /**
627
-     *    display_errors
628
-     *
629
-     * @access    public
630
-     * @return    string
631
-     */
632
-    public function display_errors()
633
-    {
634
-        static $shown_already = false;
635
-        do_action('AHEE__EE_Front_Controller__display_errors__begin');
636
-        if (
637
-            ! $shown_already
638
-            && apply_filters('FHEE__EE_Front_Controller__display_errors', true)
639
-            && is_main_query()
640
-            && ! is_feed()
641
-            && in_the_loop()
642
-            && $this->Request_Handler->is_espresso_page()
643
-        ) {
644
-            echo EE_Error::get_notices();
645
-            $shown_already = true;
646
-            EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
647
-        }
648
-        do_action('AHEE__EE_Front_Controller__display_errors__end');
649
-    }
650
-
651
-
652
-
653
-
654
-
655
-    /***********************************************        UTILITIES         ***********************************************/
656
-    /**
657
-     *    template_include
658
-     *
659
-     * @access    public
660
-     * @param   string $template_include_path
661
-     * @return    string
662
-     */
663
-    public function template_include($template_include_path = null)
664
-    {
665
-        if ($this->Request_Handler->is_espresso_page()) {
666
-            $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
667
-            $template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
668
-            $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
669
-            $this->_template      = basename($this->_template_path);
670
-            return $this->_template_path;
671
-        }
672
-        return $template_include_path;
673
-    }
674
-
675
-
676
-    /**
677
-     *    get_selected_template
678
-     *
679
-     * @access    public
680
-     * @param bool $with_path
681
-     * @return    string
682
-     */
683
-    public function get_selected_template($with_path = false)
684
-    {
685
-        return $with_path ? $this->_template_path : $this->_template;
686
-    }
25
+	/**
26
+	 *    $_template_path
27
+	 * @var    string $_template_path
28
+	 * @access    public
29
+	 */
30
+	private $_template_path;
31
+
32
+	/**
33
+	 *    $_template
34
+	 * @var    string $_template
35
+	 * @access    public
36
+	 */
37
+	private $_template;
38
+
39
+	/**
40
+	 * @type  EE_Registry $Registry
41
+	 * @access    protected
42
+	 */
43
+	protected $Registry;
44
+
45
+	/**
46
+	 * @type  EE_Request_Handler $Request_Handler
47
+	 * @access    protected
48
+	 */
49
+	protected $Request_Handler;
50
+
51
+	/**
52
+	 * @type  EE_Module_Request_Router $Module_Request_Router
53
+	 * @access    protected
54
+	 */
55
+	protected $Module_Request_Router;
56
+
57
+
58
+	/**
59
+	 *    class constructor
60
+	 *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
61
+	 *
62
+	 * @access    public
63
+	 * @param \EE_Registry              $Registry
64
+	 * @param \EE_Request_Handler       $Request_Handler
65
+	 * @param \EE_Module_Request_Router $Module_Request_Router
66
+	 */
67
+	public function __construct(
68
+		EE_Registry $Registry,
69
+		EE_Request_Handler $Request_Handler,
70
+		EE_Module_Request_Router $Module_Request_Router
71
+	) {
72
+		$this->Registry              = $Registry;
73
+		$this->Request_Handler       = $Request_Handler;
74
+		$this->Module_Request_Router = $Module_Request_Router;
75
+		// make sure template tags are loaded immediately so that themes don't break
76
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10);
77
+		// determine how to integrate WP_Query with the EE models
78
+		add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
79
+		// load other resources and begin to actually run shortcodes and modules
80
+		add_action('wp_loaded', array($this, 'wp_loaded'), 5);
81
+		// analyse the incoming WP request
82
+		add_action('parse_request', array($this, 'get_request'), 1, 1);
83
+		// process any content shortcodes
84
+		add_action('parse_request', array($this, '_initialize_shortcodes'), 5);
85
+		// process request with module factory
86
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
87
+		// before headers sent
88
+		add_action('wp', array($this, 'wp'), 5);
89
+		// load css and js
90
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1);
91
+		// header
92
+		add_action('wp_head', array($this, 'header_meta_tag'), 5);
93
+		add_filter('template_include', array($this, 'template_include'), 1);
94
+		// display errors
95
+		add_action('loop_start', array($this, 'display_errors'), 2);
96
+		// the content
97
+		// add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
98
+		//exclude our private cpt comments
99
+		add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
100
+		//make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
101
+		add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
102
+		// action hook EE
103
+		do_action('AHEE__EE_Front_Controller__construct__done', $this);
104
+		// for checking that browser cookies are enabled
105
+		if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) {
106
+			setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/');
107
+		}
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return EE_Request_Handler
113
+	 */
114
+	public function Request_Handler()
115
+	{
116
+		return $this->Request_Handler;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return EE_Module_Request_Router
122
+	 */
123
+	public function Module_Request_Router()
124
+	{
125
+		return $this->Module_Request_Router;
126
+	}
127
+
128
+
129
+
130
+
131
+
132
+	/***********************************************        INIT ACTION HOOK         ***********************************************/
133
+
134
+
135
+	/**
136
+	 *    load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then
137
+	 *    load it's functions.php file ( if not already loaded )
138
+	 *
139
+	 * @return void
140
+	 */
141
+	public function load_espresso_template_tags()
142
+	{
143
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
144
+			require_once(EE_PUBLIC . 'template_tags.php');
145
+		}
146
+	}
147
+
148
+
149
+	/**
150
+	 * filter_wp_comments
151
+	 * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
152
+	 * widgets/queries done on frontend
153
+	 *
154
+	 * @param  array $clauses array of comment clauses setup by WP_Comment_Query
155
+	 * @return array array of comment clauses with modifications.
156
+	 */
157
+	public function filter_wp_comments($clauses)
158
+	{
159
+		global $wpdb;
160
+		if (strpos($clauses['join'], $wpdb->posts) !== false) {
161
+			$cpts = EE_Register_CPTs::get_private_CPTs();
162
+			foreach ($cpts as $cpt => $details) {
163
+				$clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
164
+			}
165
+		}
166
+		return $clauses;
167
+	}
168
+
169
+
170
+	/**
171
+	 *    employ_CPT_Strategy
172
+	 *
173
+	 * @access    public
174
+	 * @return    void
175
+	 */
176
+	public function employ_CPT_Strategy()
177
+	{
178
+		if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
179
+			$this->Registry->load_core('CPT_Strategy');
180
+		}
181
+	}
182
+
183
+
184
+	/**
185
+	 * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
186
+	 *
187
+	 * @param  string $url incoming url
188
+	 * @return string         final assembled url
189
+	 */
190
+	public function maybe_force_admin_ajax_ssl($url)
191
+	{
192
+		if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
193
+			$url = str_replace('http://', 'https://', $url);
194
+		}
195
+		return $url;
196
+	}
197
+
198
+
199
+
200
+
201
+
202
+
203
+	/***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
204
+
205
+
206
+	/**
207
+	 *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
208
+	 *    default priority init phases have run
209
+	 *
210
+	 * @access    public
211
+	 * @return    void
212
+	 */
213
+	public function wp_loaded()
214
+	{
215
+	}
216
+
217
+
218
+
219
+
220
+
221
+	/***********************************************        PARSE_REQUEST HOOK         ***********************************************/
222
+	/**
223
+	 *    _get_request
224
+	 *
225
+	 * @access public
226
+	 * @param WP $WP
227
+	 * @return void
228
+	 */
229
+	public function get_request(WP $WP)
230
+	{
231
+		do_action('AHEE__EE_Front_Controller__get_request__start');
232
+		$this->Request_Handler->parse_request($WP);
233
+		do_action('AHEE__EE_Front_Controller__get_request__complete');
234
+	}
235
+
236
+
237
+	/**
238
+	 *    _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for
239
+	 *    the currently requested page
240
+	 *
241
+	 * @access    public
242
+	 * @param WP $WP
243
+	 * @return    void
244
+	 */
245
+	public function _initialize_shortcodes(WP $WP)
246
+	{
247
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this);
248
+		$this->Request_Handler->set_request_vars($WP);
249
+		// grab post_name from request
250
+		$current_post  = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
251
+			$this->Request_Handler->get('post_name'));
252
+		$show_on_front = get_option('show_on_front');
253
+		// if it's not set, then check if frontpage is blog
254
+		if (empty($current_post)) {
255
+			// yup.. this is the posts page, prepare to load all shortcode modules
256
+			$current_post = 'posts';
257
+			// unless..
258
+			if ($show_on_front === 'page') {
259
+				// some other page is set as the homepage
260
+				$page_on_front = get_option('page_on_front');
261
+				if ($page_on_front) {
262
+					// k now we need to find the post_name for this page
263
+					global $wpdb;
264
+					$page_on_front = $wpdb->get_var(
265
+						$wpdb->prepare(
266
+							"SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d",
267
+							$page_on_front
268
+						)
269
+					);
270
+					// set the current post slug to what it actually is
271
+					$current_post = $page_on_front ? $page_on_front : $current_post;
272
+				}
273
+			}
274
+		}
275
+		// where are posts being displayed ?
276
+		$page_for_posts = EE_Config::get_page_for_posts();
277
+		// in case $current_post is hierarchical like: /parent-page/current-page
278
+		$current_post = basename($current_post);
279
+		// are we on a category page?
280
+		$term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name',
281
+				$WP->query_vars);
282
+		// make sure shortcodes are set
283
+		if (isset($this->Registry->CFG->core->post_shortcodes)) {
284
+			if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) {
285
+				$this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array();
286
+			}
287
+			// cycle thru all posts with shortcodes set
288
+			foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) {
289
+				// filter shortcodes so
290
+				$post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes',
291
+					$post_shortcodes);
292
+				// now cycle thru shortcodes
293
+				foreach ($post_shortcodes as $shortcode_class => $post_id) {
294
+					// are we on this page, or on the blog page, or an EE CPT category page ?
295
+					if ($current_post === $post_name || $term_exists) {
296
+						// maybe init the shortcode
297
+						$this->initialize_shortcode_if_active_on_page(
298
+							$shortcode_class,
299
+							$current_post,
300
+							$page_for_posts,
301
+							$post_id,
302
+							$term_exists,
303
+							$WP
304
+						);
305
+						// if this is NOT the "Posts page" and we have a valid entry
306
+						// for the "Posts page" in our tracked post_shortcodes array
307
+						// but the shortcode is not being tracked for this page
308
+					} else if (
309
+						$post_name !== $page_for_posts
310
+						&& isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])
311
+						&& ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class])
312
+					) {
313
+						// then remove the "fallback" shortcode processor
314
+						remove_shortcode($shortcode_class);
315
+					}
316
+				}
317
+			}
318
+		}
319
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this);
320
+	}
321
+
322
+
323
+	/**
324
+	 * @param string $shortcode_class
325
+	 * @param string $current_post
326
+	 * @param string $page_for_posts
327
+	 * @param int    $post_id
328
+	 * @param bool   $term_exists
329
+	 * @param WP     $WP
330
+	 */
331
+	protected function initialize_shortcode_if_active_on_page(
332
+		$shortcode_class,
333
+		$current_post,
334
+		$page_for_posts,
335
+		$post_id,
336
+		$term_exists,
337
+		$WP
338
+	) {
339
+		// verify shortcode is in list of registered shortcodes
340
+		if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) {
341
+			if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) {
342
+				EE_Error::add_error(
343
+					sprintf(
344
+						__(
345
+							'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.',
346
+							'event_espresso'
347
+						),
348
+						$shortcode_class
349
+					),
350
+					__FILE__,
351
+					__FUNCTION__,
352
+					__LINE__
353
+				);
354
+				add_filter('FHEE_run_EE_the_content', '__return_true');
355
+			}
356
+			add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor'));
357
+			return;
358
+		}
359
+		// is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ?
360
+		if (
361
+			$term_exists
362
+			|| $current_post === $page_for_posts
363
+			|| isset($this->Registry->CFG->core->post_shortcodes[$current_post])
364
+		) {
365
+			// let's pause to reflect on this...
366
+			$sc_reflector = new ReflectionClass('EES_' . $shortcode_class);
367
+			// ensure that class is actually a shortcode
368
+			if (
369
+				defined('WP_DEBUG')
370
+				&& WP_DEBUG === true
371
+				&& ! $sc_reflector->isSubclassOf('EES_Shortcode')
372
+			) {
373
+				EE_Error::add_error(
374
+					sprintf(
375
+						__(
376
+							'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
377
+							'event_espresso'
378
+						),
379
+						$shortcode_class
380
+					),
381
+					__FILE__,
382
+					__FUNCTION__,
383
+					__LINE__
384
+				);
385
+				add_filter('FHEE_run_EE_the_content', '__return_true');
386
+				return;
387
+			}
388
+			// and pass the request object to the run method
389
+			$this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
390
+			// fire the shortcode class's run method, so that it can activate resources
391
+			$this->Registry->shortcodes->{$shortcode_class}->run($WP);
392
+		}
393
+	}
394
+
395
+
396
+	/**
397
+	 *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
398
+	 *
399
+	 * @access    public
400
+	 * @param   WP_Query $WP_Query
401
+	 * @return    void
402
+	 */
403
+	public function pre_get_posts($WP_Query)
404
+	{
405
+		// only load Module_Request_Router if this is the main query
406
+		if (
407
+			$this->Module_Request_Router instanceof EE_Module_Request_Router
408
+			&& $WP_Query->is_main_query()
409
+		) {
410
+			// cycle thru module routes
411
+			while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
412
+				// determine module and method for route
413
+				$module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
414
+				if ($module instanceof EED_Module) {
415
+					// get registered view for route
416
+					$this->_template_path = $this->Module_Request_Router->get_view($route);
417
+					// grab module name
418
+					$module_name = $module->module_name();
419
+					// map the module to the module objects
420
+					$this->Registry->modules->{$module_name} = $module;
421
+				}
422
+			}
423
+		}
424
+	}
425
+
426
+
427
+
428
+
429
+
430
+	/***********************************************        WP HOOK         ***********************************************/
431
+
432
+
433
+	/**
434
+	 *    wp - basically last chance to do stuff before headers sent
435
+	 *
436
+	 * @access    public
437
+	 * @return    void
438
+	 */
439
+	public function wp()
440
+	{
441
+	}
442
+
443
+
444
+
445
+	/***********************************************        WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK         ***********************************************/
446
+
447
+
448
+	/**
449
+	 *    wp_enqueue_scripts
450
+	 *
451
+	 * @access    public
452
+	 * @return    void
453
+	 */
454
+	public function wp_enqueue_scripts()
455
+	{
456
+
457
+		// css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_css', '__return_false' );
458
+		if (apply_filters('FHEE_load_css', true)) {
459
+
460
+			$this->Registry->CFG->template_settings->enable_default_style = true;
461
+			//Load the ThemeRoller styles if enabled
462
+			if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) {
463
+
464
+				//Load custom style sheet if available
465
+				if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
466
+					wp_register_style('espresso_custom_css',
467
+						EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
468
+						EVENT_ESPRESSO_VERSION);
469
+					wp_enqueue_style('espresso_custom_css');
470
+				}
471
+
472
+				if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
473
+					wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
474
+						array('dashicons'), EVENT_ESPRESSO_VERSION);
475
+				} else {
476
+					wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
477
+						array('dashicons'), EVENT_ESPRESSO_VERSION);
478
+				}
479
+				wp_enqueue_style('espresso_default');
480
+
481
+				if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
482
+					wp_register_style('espresso_style',
483
+						get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
484
+						array('dashicons', 'espresso_default'));
485
+				} else {
486
+					wp_register_style('espresso_style',
487
+						EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
488
+						array('dashicons', 'espresso_default'));
489
+				}
490
+
491
+			}
492
+
493
+		}
494
+
495
+		// js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_js', '__return_false' );
496
+		if (apply_filters('FHEE_load_js', true)) {
497
+
498
+			wp_enqueue_script('jquery');
499
+			//let's make sure that all required scripts have been setup
500
+			if (function_exists('wp_script_is') && ! wp_script_is('jquery')) {
501
+				$msg = sprintf(
502
+					__('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.',
503
+						'event_espresso'),
504
+					'<em><br />',
505
+					'</em>'
506
+				);
507
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
508
+			}
509
+			// load core js
510
+			wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
511
+				EVENT_ESPRESSO_VERSION, true);
512
+			wp_enqueue_script('espresso_core');
513
+			wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
514
+
515
+		}
516
+
517
+		//qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
518
+		if (apply_filters('FHEE_load_qtip', false)) {
519
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
520
+		}
521
+
522
+
523
+		//accounting.js library
524
+		// @link http://josscrowcroft.github.io/accounting.js/
525
+		if (apply_filters('FHEE_load_accounting_js', false)) {
526
+			$acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
527
+			wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
528
+				array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
529
+			wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
530
+			wp_enqueue_script('ee-accounting');
531
+
532
+			$currency_config = array(
533
+				'currency' => array(
534
+					'symbol'    => $this->Registry->CFG->currency->sign,
535
+					'format'    => array(
536
+						'pos'  => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
537
+						'neg'  => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
538
+						'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s',
539
+					),
540
+					'decimal'   => $this->Registry->CFG->currency->dec_mrk,
541
+					'thousand'  => $this->Registry->CFG->currency->thsnds,
542
+					'precision' => $this->Registry->CFG->currency->dec_plc,
543
+				),
544
+				'number'   => array(
545
+					'precision' => 0,
546
+					'thousand'  => $this->Registry->CFG->currency->thsnds,
547
+					'decimal'   => $this->Registry->CFG->currency->dec_mrk,
548
+				),
549
+			);
550
+			wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
551
+		}
552
+
553
+		if ( ! function_exists('wp_head')) {
554
+			$msg = sprintf(
555
+				__('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
556
+					'event_espresso'),
557
+				'<em><br />',
558
+				'</em>'
559
+			);
560
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
561
+		}
562
+		if ( ! function_exists('wp_footer')) {
563
+			$msg = sprintf(
564
+				__('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
565
+					'event_espresso'),
566
+				'<em><br />',
567
+				'</em>'
568
+			);
569
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
570
+		}
571
+
572
+	}
573
+
574
+
575
+	/**
576
+	 *    header_meta_tag
577
+	 *
578
+	 * @access    public
579
+	 * @return    void
580
+	 */
581
+	public function header_meta_tag()
582
+	{
583
+		print(
584
+			apply_filters(
585
+				'FHEE__EE_Front_Controller__header_meta_tag',
586
+				'<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
587
+		);
588
+
589
+		//let's exclude all event type taxonomy term archive pages from search engine indexing
590
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
591
+		if (
592
+			is_tax('espresso_event_type')
593
+			&& get_option( 'blog_public' ) !== '0'
594
+		) {
595
+			print(
596
+				apply_filters(
597
+					'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
598
+					'<meta name="robots" content="noindex,follow" />' . "\n"
599
+				)
600
+			);
601
+		}
602
+	}
603
+
604
+
605
+
606
+
607
+	/***********************************************        THE_CONTENT FILTER HOOK         ***********************************************/
608
+	/**
609
+	 *    the_content
610
+	 *
611
+	 * @access    public
612
+	 * @param   $the_content
613
+	 * @return    string
614
+	 */
615
+	// public function the_content( $the_content ) {
616
+	// 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
617
+	// 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
618
+	// 	}
619
+	// 	return $the_content;
620
+	// }
621
+
622
+
623
+	/***********************************************        WP_FOOTER         ***********************************************/
624
+
625
+
626
+	/**
627
+	 *    display_errors
628
+	 *
629
+	 * @access    public
630
+	 * @return    string
631
+	 */
632
+	public function display_errors()
633
+	{
634
+		static $shown_already = false;
635
+		do_action('AHEE__EE_Front_Controller__display_errors__begin');
636
+		if (
637
+			! $shown_already
638
+			&& apply_filters('FHEE__EE_Front_Controller__display_errors', true)
639
+			&& is_main_query()
640
+			&& ! is_feed()
641
+			&& in_the_loop()
642
+			&& $this->Request_Handler->is_espresso_page()
643
+		) {
644
+			echo EE_Error::get_notices();
645
+			$shown_already = true;
646
+			EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
647
+		}
648
+		do_action('AHEE__EE_Front_Controller__display_errors__end');
649
+	}
650
+
651
+
652
+
653
+
654
+
655
+	/***********************************************        UTILITIES         ***********************************************/
656
+	/**
657
+	 *    template_include
658
+	 *
659
+	 * @access    public
660
+	 * @param   string $template_include_path
661
+	 * @return    string
662
+	 */
663
+	public function template_include($template_include_path = null)
664
+	{
665
+		if ($this->Request_Handler->is_espresso_page()) {
666
+			$this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
667
+			$template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
668
+			$this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
669
+			$this->_template      = basename($this->_template_path);
670
+			return $this->_template_path;
671
+		}
672
+		return $template_include_path;
673
+	}
674
+
675
+
676
+	/**
677
+	 *    get_selected_template
678
+	 *
679
+	 * @access    public
680
+	 * @param bool $with_path
681
+	 * @return    string
682
+	 */
683
+	public function get_selected_template($with_path = false)
684
+	{
685
+		return $with_path ? $this->_template_path : $this->_template;
686
+	}
687 687
 
688 688
 
689 689
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public function load_espresso_template_tags()
142 142
     {
143
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
144
-            require_once(EE_PUBLIC . 'template_tags.php');
143
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
144
+            require_once(EE_PUBLIC.'template_tags.php');
145 145
         }
146 146
     }
147 147
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
             || isset($this->Registry->CFG->core->post_shortcodes[$current_post])
364 364
         ) {
365 365
             // let's pause to reflect on this...
366
-            $sc_reflector = new ReflectionClass('EES_' . $shortcode_class);
366
+            $sc_reflector = new ReflectionClass('EES_'.$shortcode_class);
367 367
             // ensure that class is actually a shortcode
368 368
             if (
369 369
                 defined('WP_DEBUG')
@@ -464,27 +464,27 @@  discard block
 block discarded – undo
464 464
                 //Load custom style sheet if available
465 465
                 if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
466 466
                     wp_register_style('espresso_custom_css',
467
-                        EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
467
+                        EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->Registry->CFG->template_settings->custom_style_sheet,
468 468
                         EVENT_ESPRESSO_VERSION);
469 469
                     wp_enqueue_style('espresso_custom_css');
470 470
                 }
471 471
 
472
-                if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
473
-                    wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
472
+                if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')) {
473
+                    wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css',
474 474
                         array('dashicons'), EVENT_ESPRESSO_VERSION);
475 475
                 } else {
476
-                    wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
476
+                    wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
477 477
                         array('dashicons'), EVENT_ESPRESSO_VERSION);
478 478
                 }
479 479
                 wp_enqueue_style('espresso_default');
480 480
 
481
-                if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
481
+                if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'style.css')) {
482 482
                     wp_register_style('espresso_style',
483
-                        get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
483
+                        get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'style.css',
484 484
                         array('dashicons', 'espresso_default'));
485 485
                 } else {
486 486
                     wp_register_style('espresso_style',
487
-                        EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
487
+                        EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'style.css',
488 488
                         array('dashicons', 'espresso_default'));
489 489
                 }
490 490
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
                 EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
508 508
             }
509 509
             // load core js
510
-            wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
510
+            wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'),
511 511
                 EVENT_ESPRESSO_VERSION, true);
512 512
             wp_enqueue_script('espresso_core');
513 513
             wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
         //accounting.js library
524 524
         // @link http://josscrowcroft.github.io/accounting.js/
525 525
         if (apply_filters('FHEE_load_accounting_js', false)) {
526
-            $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
527
-            wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
526
+            $acct_js = EE_THIRD_PARTY_URL.'accounting/accounting.js';
527
+            wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
528 528
                 array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
529 529
             wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
530 530
             wp_enqueue_script('ee-accounting');
@@ -583,19 +583,19 @@  discard block
 block discarded – undo
583 583
         print(
584 584
             apply_filters(
585 585
                 'FHEE__EE_Front_Controller__header_meta_tag',
586
-                '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
586
+                '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n")
587 587
         );
588 588
 
589 589
         //let's exclude all event type taxonomy term archive pages from search engine indexing
590 590
         //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
591 591
         if (
592 592
             is_tax('espresso_event_type')
593
-            && get_option( 'blog_public' ) !== '0'
593
+            && get_option('blog_public') !== '0'
594 594
         ) {
595 595
             print(
596 596
                 apply_filters(
597 597
                     'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
598
-                    '<meta name="robots" content="noindex,follow" />' . "\n"
598
+                    '<meta name="robots" content="noindex,follow" />'."\n"
599 599
                 )
600 600
             );
601 601
         }
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
         ) {
644 644
             echo EE_Error::get_notices();
645 645
             $shown_already = true;
646
-            EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
646
+            EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php');
647 647
         }
648 648
         do_action('AHEE__EE_Front_Controller__display_errors__end');
649 649
     }
Please login to merge, or discard this patch.
core/EE_Session.core.php 2 patches
Spacing   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\InvalidSessionDataException;
2 2
 
3
-if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
4 4
 /**
5 5
  *
6 6
  * EE_Session class
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	  * array for defining default session vars
92 92
 	  * @var array
93 93
 	  */
94
-	 private $_default_session_vars = array (
94
+	 private $_default_session_vars = array(
95 95
 		'id' => NULL,
96 96
 		'user_id' => NULL,
97 97
 		'ip_address' => NULL,
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 	  * @throws InvalidSessionDataException
112 112
 	  * @throws \EE_Error
113 113
 	  */
114
-	public static function instance( EE_Encryption $encryption = null ) {
114
+	public static function instance(EE_Encryption $encryption = null) {
115 115
 		// check if class object is instantiated
116 116
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
117 117
 		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
118
-		if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) {
119
-			self::$_instance = new self( $encryption );
118
+		if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
119
+			self::$_instance = new self($encryption);
120 120
 		}
121 121
 		return self::$_instance;
122 122
 	}
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 	  * @throws \EE_Error
133 133
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
134 134
 	  */
135
-	 protected function __construct( EE_Encryption $encryption = null ) {
135
+	 protected function __construct(EE_Encryption $encryption = null) {
136 136
 
137 137
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
138
-		if ( ! apply_filters( 'FHEE_load_EE_Session', TRUE ) ) {
138
+		if ( ! apply_filters('FHEE_load_EE_Session', TRUE)) {
139 139
 			return;
140 140
 		}
141
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
142
-		if ( ! defined( 'ESPRESSO_SESSION' ) ) {
143
-			define( 'ESPRESSO_SESSION', true );
141
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
142
+		if ( ! defined('ESPRESSO_SESSION')) {
143
+			define('ESPRESSO_SESSION', true);
144 144
 		}
145 145
 		// default session lifespan in seconds
146 146
 		$this->_lifespan = apply_filters(
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 		 * 		}
155 155
 		 */
156 156
 		// retrieve session options from db
157
-		$session_settings = (array) get_option( 'ee_session_settings', array() );
158
-		if ( ! empty( $session_settings )) {
157
+		$session_settings = (array) get_option('ee_session_settings', array());
158
+		if ( ! empty($session_settings)) {
159 159
 			// cycle though existing session options
160
-			foreach ( $session_settings as $var_name => $session_setting ) {
160
+			foreach ($session_settings as $var_name => $session_setting) {
161 161
 				// set values for class properties
162
-				$var_name = '_' . $var_name;
162
+				$var_name = '_'.$var_name;
163 163
 				$this->{$var_name} = $session_setting;
164 164
 			}
165 165
 		}
@@ -169,16 +169,16 @@  discard block
 block discarded – undo
169 169
         // encrypt data via: $this->encryption->encrypt();
170 170
         $this->encryption = $encryption;
171 171
 		// filter hook allows outside functions/classes/plugins to change default empty cart
172
-		$extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() );
173
-		array_merge( $this->_default_session_vars, $extra_default_session_vars );
172
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
173
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
174 174
 		// apply default session vars
175 175
 		$this->_set_defaults();
176 176
          add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
177 177
          // check request for 'clear_session' param
178
-		add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' ));
178
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
179 179
 		// once everything is all said and done,
180
-		add_action( 'shutdown', array( $this, 'update' ), 100 );
181
-		add_action( 'shutdown', array( $this, 'garbage_collection' ), 999 );
180
+		add_action('shutdown', array($this, 'update'), 100);
181
+		add_action('shutdown', array($this, 'garbage_collection'), 999);
182 182
 	}
183 183
 
184 184
 
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
 	 */
224 224
 	private function _set_defaults() {
225 225
 		// set some defaults
226
-		foreach ( $this->_default_session_vars as $key => $default_var ) {
227
-			if ( is_array( $default_var )) {
228
-				$this->_session_data[ $key ] = array();
226
+		foreach ($this->_default_session_vars as $key => $default_var) {
227
+			if (is_array($default_var)) {
228
+				$this->_session_data[$key] = array();
229 229
 			} else {
230
-				$this->_session_data[ $key ] = '';
230
+				$this->_session_data[$key] = '';
231 231
 			}
232 232
 		}
233 233
 	}
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	  * @param \EE_Cart $cart
250 250
 	  * @return bool
251 251
 	  */
252
-	 public function set_cart( EE_Cart $cart ) {
252
+	 public function set_cart(EE_Cart $cart) {
253 253
 		 $this->_session_data['cart'] = $cart;
254 254
 		 return TRUE;
255 255
 	 }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	  * @return \EE_Cart
270 270
 	  */
271 271
 	 public function cart() {
272
-		 return isset( $this->_session_data['cart'] ) ? $this->_session_data['cart'] : NULL;
272
+		 return isset($this->_session_data['cart']) ? $this->_session_data['cart'] : NULL;
273 273
 	 }
274 274
 
275 275
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	  * @param \EE_Checkout $checkout
279 279
 	  * @return bool
280 280
 	  */
281
-	 public function set_checkout( EE_Checkout $checkout ) {
281
+	 public function set_checkout(EE_Checkout $checkout) {
282 282
 		 $this->_session_data['checkout'] = $checkout;
283 283
 		 return TRUE;
284 284
 	 }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	  * @return \EE_Checkout
299 299
 	  */
300 300
 	 public function checkout() {
301
-		 return isset( $this->_session_data['checkout'] ) ? $this->_session_data['checkout'] : NULL;
301
+		 return isset($this->_session_data['checkout']) ? $this->_session_data['checkout'] : NULL;
302 302
 	 }
303 303
 
304 304
 
@@ -308,9 +308,9 @@  discard block
 block discarded – undo
308 308
 	  * @return bool
309 309
 	  * @throws \EE_Error
310 310
 	  */
311
-	 public function set_transaction( EE_Transaction $transaction ) {
311
+	 public function set_transaction(EE_Transaction $transaction) {
312 312
 		 // first remove the session from the transaction before we save the transaction in the session
313
-		 $transaction->set_txn_session_data( NULL );
313
+		 $transaction->set_txn_session_data(NULL);
314 314
 		 $this->_session_data['transaction'] = $transaction;
315 315
 		 return TRUE;
316 316
 	 }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	  * @return \EE_Transaction
331 331
 	  */
332 332
 	 public function transaction() {
333
-		 return isset( $this->_session_data['transaction'] ) ? $this->_session_data['transaction'] : NULL;
333
+		 return isset($this->_session_data['transaction']) ? $this->_session_data['transaction'] : NULL;
334 334
 	 }
335 335
 
336 336
 
@@ -342,15 +342,15 @@  discard block
 block discarded – undo
342 342
 	  * @param bool $reset_cache
343 343
 	  * @return    array
344 344
 	  */
345
-	public function get_session_data( $key = NULL, $reset_cache = FALSE ) {
346
-		if ( $reset_cache ) {
345
+	public function get_session_data($key = NULL, $reset_cache = FALSE) {
346
+		if ($reset_cache) {
347 347
 			$this->reset_cart();
348 348
 			$this->reset_checkout();
349 349
 			$this->reset_transaction();
350 350
 		}
351
-		 if ( ! empty( $key ))  {
352
-			return  isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL;
353
-		}  else  {
351
+		 if ( ! empty($key)) {
352
+			return  isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL;
353
+		} else {
354 354
 			return $this->_session_data;
355 355
 		}
356 356
 	}
@@ -363,20 +363,20 @@  discard block
 block discarded – undo
363 363
 	  * @param 	array $data
364 364
 	  * @return 	TRUE on success, FALSE on fail
365 365
 	  */
366
-	public function set_session_data( $data ) {
366
+	public function set_session_data($data) {
367 367
 
368 368
 		// nothing ??? bad data ??? go home!
369
-		if ( empty( $data ) || ! is_array( $data )) {
370
-			EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
369
+		if (empty($data) || ! is_array($data)) {
370
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
371 371
 			return FALSE;
372 372
 		}
373 373
 
374
-		foreach ( $data as $key =>$value ) {
375
-			if ( isset( $this->_default_session_vars[ $key ] )) {
376
-				EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ );
374
+		foreach ($data as $key =>$value) {
375
+			if (isset($this->_default_session_vars[$key])) {
376
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
377 377
 				return FALSE;
378 378
 			} else {
379
-				$this->_session_data[ $key ] = $value;
379
+				$this->_session_data[$key] = $value;
380 380
 			}
381 381
 		}
382 382
 
@@ -394,9 +394,9 @@  discard block
 block discarded – undo
394 394
 	  * @throws \EE_Error
395 395
 	  */
396 396
 	private function _espresso_session() {
397
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
397
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
398 398
 		// check that session has started
399
-		if ( session_id() === '' ) {
399
+		if (session_id() === '') {
400 400
 			//starts a new session if one doesn't already exist, or re-initiates an existing one
401 401
 			session_start();
402 402
 		}
@@ -405,38 +405,38 @@  discard block
 block discarded – undo
405 405
 		// and the visitors IP
406 406
 		$this->_ip_address = $this->_visitor_ip();
407 407
 		// set the "user agent"
408
-		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE;
408
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE;
409 409
 		// now let's retrieve what's in the db
410 410
         $session_data = $this->_retrieve_session_data();
411
-        if (! empty($session_data)) {
411
+        if ( ! empty($session_data)) {
412 412
             // get the current time in UTC
413
-			$this->_time = isset( $this->_time ) ? $this->_time : time();
413
+			$this->_time = isset($this->_time) ? $this->_time : time();
414 414
 			// and reset the session expiration
415
-			$this->_expiration = isset( $session_data['expiration'] )
415
+			$this->_expiration = isset($session_data['expiration'])
416 416
 				? $session_data['expiration']
417 417
 				: $this->_time + $this->_lifespan;
418 418
 		} else {
419 419
             // set initial site access time and the session expiration
420 420
 			$this->_set_init_access_and_expiration();
421 421
 			// set referer
422
-			$this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] )
423
-				? esc_attr( $_SERVER['HTTP_REFERER'] )
422
+			$this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
423
+				? esc_attr($_SERVER['HTTP_REFERER'])
424 424
 				: '';
425 425
 			// no previous session = go back and create one (on top of the data above)
426 426
 			return FALSE;
427 427
 		}
428 428
         // now the user agent
429
-		if ( $session_data['user_agent'] !== $this->_user_agent ) {
429
+		if ($session_data['user_agent'] !== $this->_user_agent) {
430 430
 			return FALSE;
431 431
 		}
432 432
 		// wait a minute... how old are you?
433
-		if ( $this->_time > $this->_expiration ) {
433
+		if ($this->_time > $this->_expiration) {
434 434
 			// yer too old fer me!
435 435
 			// wipe out everything that isn't a default session datum
436
-			$this->clear_session( __CLASS__, __FUNCTION__ );
436
+			$this->clear_session(__CLASS__, __FUNCTION__);
437 437
 		}
438 438
 		// make event espresso session data available to plugin
439
-		$this->_session_data = array_merge( $this->_session_data, $session_data );
439
+		$this->_session_data = array_merge($this->_session_data, $session_data);
440 440
 		return TRUE;
441 441
 
442 442
 	}
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
       */
453 453
      protected function _retrieve_session_data()
454 454
      {
455
-         $ssn_key = EE_Session::session_id_prefix . $this->_sid;
455
+         $ssn_key = EE_Session::session_id_prefix.$this->_sid;
456 456
          try {
457 457
              // we're using WP's Transient API to store session data using the PHP session ID as the option name
458 458
              $session_data = get_transient($ssn_key);
@@ -460,12 +460,12 @@  discard block
 block discarded – undo
460 460
 		         return array();
461 461
              }
462 462
              if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
463
-                 $hash_check = get_transient(EE_Session::hash_check_prefix . $this->_sid);
463
+                 $hash_check = get_transient(EE_Session::hash_check_prefix.$this->_sid);
464 464
                  if ($hash_check && $hash_check !== md5($session_data)) {
465 465
 	                 EE_Error::add_error(
466 466
                          sprintf(
467 467
                              __('The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', 'event_espresso'),
468
-                             EE_Session::session_id_prefix . $this->_sid
468
+                             EE_Session::session_id_prefix.$this->_sid
469 469
                          ),
470 470
                          __FILE__, __FUNCTION__, __LINE__
471 471
                      );
@@ -477,17 +477,17 @@  discard block
 block discarded – undo
477 477
              $row = $wpdb->get_row(
478 478
                  $wpdb->prepare(
479 479
                      "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
480
-                     '_transient_' . $ssn_key
480
+                     '_transient_'.$ssn_key
481 481
                  )
482 482
              );
483 483
              $session_data = is_object($row) ? $row->option_value : null;
484 484
              if ($session_data) {
485 485
                  $session_data = preg_replace_callback(
486 486
                      '!s:(d+):"(.*?)";!',
487
-                     function ($match) {
487
+                     function($match) {
488 488
                          return $match[1] === strlen($match[2])
489 489
                              ? $match[0]
490
-                             : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
490
+                             : 's:'.strlen($match[2]).':"'.$match[2].'";';
491 491
                      },
492 492
                      $session_data
493 493
                  );
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
                      'event_espresso'
509 509
                  );
510 510
                  $msg .= WP_DEBUG
511
-                     ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
511
+                     ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
512 512
                      : '';
513 513
                  throw new InvalidSessionDataException($msg, 0, $e);
514 514
              }
@@ -521,11 +521,11 @@  discard block
 block discarded – undo
521 521
                  'event_espresso'
522 522
              );
523 523
              $msg .= WP_DEBUG
524
-                 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
524
+                 ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
525 525
                  : '';
526 526
 	         throw new InvalidSessionDataException($msg);
527 527
          }
528
-	     if ( isset( $this->_session_data['transaction'] ) && absint( $this->_session_data['transaction'] ) !== 0 ) {
528
+	     if (isset($this->_session_data['transaction']) && absint($this->_session_data['transaction']) !== 0) {
529 529
 		     $this->_session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
530 530
 			     $this->_session_data['transaction']
531 531
 	         );
@@ -546,12 +546,12 @@  discard block
 block discarded – undo
546 546
 	  */
547 547
 	protected function _generate_session_id() {
548 548
 		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
549
-		if ( isset( $_REQUEST[ 'EESID' ] ) ) {
550
-			$session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] );
549
+		if (isset($_REQUEST['EESID'])) {
550
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
551 551
 		} else {
552
-			$session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() );
552
+			$session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
553 553
 		}
554
-		return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id );
554
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
555 555
 	}
556 556
 
557 557
 
@@ -563,20 +563,20 @@  discard block
 block discarded – undo
563 563
 	  */
564 564
 	protected function _get_sid_salt() {
565 565
 		// was session id salt already saved to db ?
566
-		if ( empty( $this->_sid_salt ) ) {
566
+		if (empty($this->_sid_salt)) {
567 567
 			// no?  then maybe use WP defined constant
568
-			if ( defined( 'AUTH_SALT' ) ) {
568
+			if (defined('AUTH_SALT')) {
569 569
 				$this->_sid_salt = AUTH_SALT;
570 570
 			}
571 571
 			// if salt doesn't exist or is too short
572
-			if ( empty( $this->_sid_salt ) || strlen( $this->_sid_salt ) < 32 ) {
572
+			if (empty($this->_sid_salt) || strlen($this->_sid_salt) < 32) {
573 573
 				// create a new one
574
-				$this->_sid_salt = wp_generate_password( 64 );
574
+				$this->_sid_salt = wp_generate_password(64);
575 575
 			}
576 576
 			// and save it as a permanent session setting
577
-			$session_settings = get_option( 'ee_session_settings' );
578
-			$session_settings[ 'sid_salt' ] = $this->_sid_salt;
579
-			update_option( 'ee_session_settings', $session_settings );
577
+			$session_settings = get_option('ee_session_settings');
578
+			$session_settings['sid_salt'] = $this->_sid_salt;
579
+			update_option('ee_session_settings', $session_settings);
580 580
 		}
581 581
 		return $this->_sid_salt;
582 582
 	}
@@ -604,19 +604,19 @@  discard block
 block discarded – undo
604 604
 	  * @param bool $new_session
605 605
 	  * @return TRUE on success, FALSE on fail
606 606
 	  */
607
-	public function update( $new_session = FALSE ) {
608
-		$this->_session_data = isset( $this->_session_data )
609
-			&& is_array( $this->_session_data )
610
-			&& isset( $this->_session_data['id'])
607
+	public function update($new_session = FALSE) {
608
+		$this->_session_data = isset($this->_session_data)
609
+			&& is_array($this->_session_data)
610
+			&& isset($this->_session_data['id'])
611 611
 			? $this->_session_data
612 612
 			: array();
613
-		if ( empty( $this->_session_data )) {
613
+		if (empty($this->_session_data)) {
614 614
 			$this->_set_defaults();
615 615
 		}
616 616
 		$session_data = array();
617
-		foreach ( $this->_session_data as $key => $value ) {
617
+		foreach ($this->_session_data as $key => $value) {
618 618
 
619
-			switch( $key ) {
619
+			switch ($key) {
620 620
 
621 621
 				case 'id' :
622 622
 					// session ID
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 				break;
635 635
 
636 636
 				case 'init_access' :
637
-					$session_data['init_access'] = absint( $value );
637
+					$session_data['init_access'] = absint($value);
638 638
 				break;
639 639
 
640 640
 				case 'last_access' :
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 
645 645
 				case 'expiration' :
646 646
 					// when the session expires
647
-					$session_data['expiration'] = ! empty( $this->_expiration )
647
+					$session_data['expiration'] = ! empty($this->_expiration)
648 648
 						? $this->_expiration
649 649
 						: $session_data['init_access'] + $this->_lifespan;
650 650
 				break;
@@ -656,11 +656,11 @@  discard block
 block discarded – undo
656 656
 
657 657
 				case 'pages_visited' :
658 658
 					$page_visit = $this->_get_page_visit();
659
-					if ( $page_visit ) {
659
+					if ($page_visit) {
660 660
 						// set pages visited where the first will be the http referrer
661
-						$this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit;
661
+						$this->_session_data['pages_visited'][$this->_time] = $page_visit;
662 662
 						// we'll only save the last 10 page visits.
663
-						$session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 );
663
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
664 664
 					}
665 665
 				break;
666 666
 
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 
675 675
 		$this->_session_data = $session_data;
676 676
 		// creating a new session does not require saving to the db just yet
677
-		if ( ! $new_session ) {
677
+		if ( ! $new_session) {
678 678
 			// ready? let's save
679
-			if ( $this->_save_session_to_db() ) {
679
+			if ($this->_save_session_to_db()) {
680 680
 				return TRUE;
681 681
 			} else {
682 682
 				return FALSE;
@@ -695,9 +695,9 @@  discard block
 block discarded – undo
695 695
 	 * 	@return bool
696 696
 	 */
697 697
 	private function _create_espresso_session( ) {
698
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' );
698
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
699 699
 		// use the update function for now with $new_session arg set to TRUE
700
-		return  $this->update( TRUE ) ? TRUE : FALSE;
700
+		return  $this->update(TRUE) ? TRUE : FALSE;
701 701
 	}
702 702
 
703 703
 
@@ -723,15 +723,15 @@  discard block
 block discarded – undo
723 723
 				// OR an admin request that is NOT AJAX
724 724
 				|| (
725 725
 					is_admin()
726
-					&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
726
+					&& ! (defined('DOING_AJAX') && DOING_AJAX)
727 727
 				)
728 728
 			)
729 729
 		) {
730 730
 			return false;
731 731
 		}
732 732
 		$transaction = $this->transaction();
733
-		if ( $transaction instanceof EE_Transaction ) {
734
-			if ( ! $transaction->ID() ) {
733
+		if ($transaction instanceof EE_Transaction) {
734
+			if ( ! $transaction->ID()) {
735 735
 				$transaction->save();
736 736
 			}
737 737
 			$this->_session_data['transaction'] = $transaction->ID();
@@ -739,13 +739,13 @@  discard block
 block discarded – undo
739 739
 		// then serialize all of our session data
740 740
 		$session_data = serialize($this->_session_data);
741 741
 		// do we need to also encode it to avoid corrupted data when saved to the db?
742
-		$session_data = $this->_use_encryption ? $this->encryption->base64_string_encode( $session_data ) : $session_data;
742
+		$session_data = $this->_use_encryption ? $this->encryption->base64_string_encode($session_data) : $session_data;
743 743
 		// maybe save hash check
744
-		if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) {
745
-			set_transient( EE_Session::hash_check_prefix . $this->_sid, md5( $session_data ), $this->_lifespan );
744
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
745
+			set_transient(EE_Session::hash_check_prefix.$this->_sid, md5($session_data), $this->_lifespan);
746 746
 		}
747 747
 		// we're using the Transient API for storing session data, cuz it's so damn simple -> set_transient(  transient ID, data, expiry )
748
-		return set_transient( EE_Session::session_id_prefix . $this->_sid, $session_data, $this->_lifespan );
748
+		return set_transient(EE_Session::session_id_prefix.$this->_sid, $session_data, $this->_lifespan);
749 749
 	}
750 750
 
751 751
 
@@ -771,10 +771,10 @@  discard block
 block discarded – undo
771 771
 			'HTTP_FORWARDED',
772 772
 			'REMOTE_ADDR'
773 773
 		);
774
-		foreach ( $server_keys as $key ){
775
-			if ( isset( $_SERVER[ $key ] )) {
776
-				foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) {
777
-					if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) {
774
+		foreach ($server_keys as $key) {
775
+			if (isset($_SERVER[$key])) {
776
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
777
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) {
778 778
 						$visitor_ip = $ip;
779 779
 					}
780 780
 				}
@@ -793,32 +793,32 @@  discard block
 block discarded – undo
793 793
 	 *			@return string
794 794
 	 */
795 795
 	public function _get_page_visit() {
796
-		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
796
+		$page_visit = home_url('/').'wp-admin/admin-ajax.php';
797 797
 		// check for request url
798
-		if ( isset( $_SERVER['REQUEST_URI'] )) {
798
+		if (isset($_SERVER['REQUEST_URI'])) {
799 799
 			$http_host = '';
800 800
 			$page_id = '?';
801 801
 			$e_reg = '';
802
-			$request_uri = esc_url( $_SERVER['REQUEST_URI'] );
803
-			$ru_bits = explode( '?', $request_uri );
802
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
803
+			$ru_bits = explode('?', $request_uri);
804 804
 			$request_uri = $ru_bits[0];
805 805
 			// check for and grab host as well
806
-			if ( isset( $_SERVER['HTTP_HOST'] )) {
807
-				$http_host = esc_url( $_SERVER['HTTP_HOST'] );
806
+			if (isset($_SERVER['HTTP_HOST'])) {
807
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
808 808
 			}
809 809
 			// check for page_id in SERVER REQUEST
810
-			if ( isset( $_REQUEST['page_id'] )) {
810
+			if (isset($_REQUEST['page_id'])) {
811 811
 				// rebuild $e_reg without any of the extra parameters
812
-				$page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&amp;';
812
+				$page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
813 813
 			}
814 814
 			// check for $e_reg in SERVER REQUEST
815
-			if ( isset( $_REQUEST['ee'] )) {
815
+			if (isset($_REQUEST['ee'])) {
816 816
 				// rebuild $e_reg without any of the extra parameters
817
-				$e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] );
817
+				$e_reg = 'ee='.esc_attr($_REQUEST['ee']);
818 818
 			}
819
-			$page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' );
819
+			$page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
820 820
 		}
821
-		return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : '';
821
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
822 822
 
823 823
 	}
824 824
 
@@ -847,14 +847,14 @@  discard block
 block discarded – undo
847 847
 	  * @param string $function
848 848
 	  * @return void
849 849
 	  */
850
-	public function clear_session( $class = '', $function = '' ) {
850
+	public function clear_session($class = '', $function = '') {
851 851
 		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
852
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' .  $function . '()' );
852
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
853 853
 		$this->reset_cart();
854 854
 		$this->reset_checkout();
855 855
 		$this->reset_transaction();
856 856
 		// wipe out everything that isn't a default session datum
857
-		$this->reset_data( array_keys( $this->_session_data ));
857
+		$this->reset_data(array_keys($this->_session_data));
858 858
 		// reset initial site access time and the session expiration
859 859
 		$this->_set_init_access_and_expiration();
860 860
 		$this->_save_session_to_db();
@@ -869,42 +869,42 @@  discard block
 block discarded – undo
869 869
 	  * @param bool  $show_all_notices
870 870
 	  * @return TRUE on success, FALSE on fail
871 871
 	  */
872
-	public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) {
872
+	public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) {
873 873
 		// if $data_to_reset is not in an array, then put it in one
874
-		if ( ! is_array( $data_to_reset ) ) {
875
-			$data_to_reset = array ( $data_to_reset );
874
+		if ( ! is_array($data_to_reset)) {
875
+			$data_to_reset = array($data_to_reset);
876 876
 		}
877 877
 		// nothing ??? go home!
878
-		if ( empty( $data_to_reset )) {
879
-			EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
878
+		if (empty($data_to_reset)) {
879
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
880 880
 			return FALSE;
881 881
 		}
882 882
 		$return_value = TRUE;
883 883
 		// since $data_to_reset is an array, cycle through the values
884
-		foreach ( $data_to_reset as $reset ) {
884
+		foreach ($data_to_reset as $reset) {
885 885
 
886 886
 			// first check to make sure it is a valid session var
887
-			if ( isset( $this->_session_data[ $reset ] )) {
887
+			if (isset($this->_session_data[$reset])) {
888 888
 				// then check to make sure it is not a default var
889
-				if ( ! array_key_exists( $reset, $this->_default_session_vars )) {
889
+				if ( ! array_key_exists($reset, $this->_default_session_vars)) {
890 890
 					// remove session var
891
-					unset( $this->_session_data[ $reset ] );
892
-					if ( $show_all_notices ) {
893
-						EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
891
+					unset($this->_session_data[$reset]);
892
+					if ($show_all_notices) {
893
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
894 894
 					}
895
-					$return_value = !isset($return_value) ? TRUE : $return_value;
895
+					$return_value = ! isset($return_value) ? TRUE : $return_value;
896 896
 
897 897
 				} else {
898 898
 					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
899
-					if ( $show_all_notices ) {
900
-						EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
899
+					if ($show_all_notices) {
900
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
901 901
 					}
902 902
 					$return_value = FALSE;
903 903
 				}
904 904
 
905
-			} else if ( $show_all_notices ) {
905
+			} else if ($show_all_notices) {
906 906
 				// oops! that session var does not exist!
907
-				EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
907
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
908 908
 				$return_value = FALSE;
909 909
 			}
910 910
 
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 *   @access public
925 925
 	 */
926 926
 	public function wp_loaded() {
927
-		if ( isset(  EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) {
928
-			$this->clear_session( __CLASS__, __FUNCTION__ );
927
+		if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) {
928
+			$this->clear_session(__CLASS__, __FUNCTION__);
929 929
 		}
930 930
 	}
931 931
 
@@ -950,24 +950,24 @@  discard block
 block discarded – undo
950 950
 	  */
951 951
 	 public function garbage_collection() {
952 952
 		 // only perform during regular requests
953
-		 if ( ! defined( 'DOING_AJAX') || ! DOING_AJAX ) {
953
+		 if ( ! defined('DOING_AJAX') || ! DOING_AJAX) {
954 954
 			 /** @type WPDB $wpdb */
955 955
 			 global $wpdb;
956 956
 			 // since transient expiration timestamps are set in the future, we can compare against NOW
957 957
 			 $expiration = time();
958
-			 $too_far_in_the_the_future = $expiration + ( $this->_lifespan * 2 );
958
+			 $too_far_in_the_the_future = $expiration + ($this->_lifespan * 2);
959 959
 			 // filter the query limit. Set to 0 to turn off garbage collection
960
-			 $expired_session_transient_delete_query_limit = absint( apply_filters( 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', 50 ));
960
+			 $expired_session_transient_delete_query_limit = absint(apply_filters('FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', 50));
961 961
 			 // non-zero LIMIT means take out the trash
962
-			 if ( $expired_session_transient_delete_query_limit ) {
962
+			 if ($expired_session_transient_delete_query_limit) {
963 963
 				 //array of transient keys that require garbage collection
964 964
 				 $session_keys = array(
965 965
 					 EE_Session::session_id_prefix,
966 966
 					 EE_Session::hash_check_prefix,
967 967
 				 );
968
-				 foreach ( $session_keys as $session_key ) {
969
-					 $session_key = str_replace( '_', '\_', $session_key );
970
-					 $session_key = '\_transient\_timeout\_' . $session_key . '%';
968
+				 foreach ($session_keys as $session_key) {
969
+					 $session_key = str_replace('_', '\_', $session_key);
970
+					 $session_key = '\_transient\_timeout\_'.$session_key.'%';
971 971
 					 $SQL = "
972 972
 					SELECT option_name
973 973
 					FROM {$wpdb->options}
@@ -977,25 +977,25 @@  discard block
 block discarded – undo
977 977
 					OR option_value > {$too_far_in_the_the_future} )
978 978
 					LIMIT {$expired_session_transient_delete_query_limit}
979 979
 				";
980
-					 $expired_sessions = $wpdb->get_col( $SQL );
980
+					 $expired_sessions = $wpdb->get_col($SQL);
981 981
 					 // valid results?
982
-					 if ( ! $expired_sessions instanceof WP_Error && ! empty( $expired_sessions ) ) {
982
+					 if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
983 983
 						 // format array of results into something usable within the actual DELETE query's IN clause
984 984
 						 $expired = array();
985
-						 foreach ( $expired_sessions as $expired_session ) {
986
-							 $expired[ ] = "'" . $expired_session . "'";
987
-							 $expired[ ] = "'" . str_replace( 'timeout_', '', $expired_session ) . "'";
985
+						 foreach ($expired_sessions as $expired_session) {
986
+							 $expired[] = "'".$expired_session."'";
987
+							 $expired[] = "'".str_replace('timeout_', '', $expired_session)."'";
988 988
 						 }
989
-						 $expired = implode( ', ', $expired );
989
+						 $expired = implode(', ', $expired);
990 990
 						 $SQL = "
991 991
 						DELETE FROM {$wpdb->options}
992 992
 						WHERE option_name
993 993
 						IN ( $expired );
994 994
 					 ";
995
-						 $results = $wpdb->query( $SQL );
995
+						 $results = $wpdb->query($SQL);
996 996
 						 // if something went wrong, then notify the admin
997
-						 if ( $results instanceof WP_Error && is_admin() ) {
998
-							 EE_Error::add_error( $results->get_error_message(), __FILE__, __FUNCTION__, __LINE__ );
997
+						 if ($results instanceof WP_Error && is_admin()) {
998
+							 EE_Error::add_error($results->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
999 999
 						 }
1000 1000
 					 }
1001 1001
 				 }
@@ -1016,34 +1016,34 @@  discard block
 block discarded – undo
1016 1016
 	  * @param $data1
1017 1017
 	  * @return string
1018 1018
 	  */
1019
-	 private function find_serialize_error( $data1 ) {
1019
+	 private function find_serialize_error($data1) {
1020 1020
 		$error = "<pre>";
1021 1021
 		 $data2 = preg_replace_callback(
1022 1022
 			 '!s:(\d+):"(.*?)";!',
1023
-			 function ( $match ) {
1024
-				 return ( $match[1] === strlen( $match[2] ) )
1023
+			 function($match) {
1024
+				 return ($match[1] === strlen($match[2]))
1025 1025
 					 ? $match[0]
1026 1026
 					 : 's:'
1027
-					   . strlen( $match[2] )
1027
+					   . strlen($match[2])
1028 1028
 					   . ':"'
1029 1029
 					   . $match[2]
1030 1030
 					   . '";';
1031 1031
 			 },
1032 1032
 			 $data1
1033 1033
 		 );
1034
-		$max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 );
1035
-		$error .= $data1 . PHP_EOL;
1036
-		$error .= $data2 . PHP_EOL;
1037
-		for ( $i = 0; $i < $max; $i++ ) {
1038
-			if ( @$data1[ $i ] !== @$data2[ $i ] ) {
1039
-				$error .= "Difference " . @$data1[ $i ] . " != " . @$data2[ $i ] . PHP_EOL;
1040
-				$error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . " != " . ord( @$data2[ $i ] ) . PHP_EOL;
1041
-				$error .= "\t-> Line Number = $i" . PHP_EOL;
1042
-				$start = ( $i - 20 );
1043
-				$start = ( $start < 0 ) ? 0 : $start;
1034
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1035
+		$error .= $data1.PHP_EOL;
1036
+		$error .= $data2.PHP_EOL;
1037
+		for ($i = 0; $i < $max; $i++) {
1038
+			if (@$data1[$i] !== @$data2[$i]) {
1039
+				$error .= "Difference ".@$data1[$i]." != ".@$data2[$i].PHP_EOL;
1040
+				$error .= "\t-> ORD number ".ord(@$data1[$i])." != ".ord(@$data2[$i]).PHP_EOL;
1041
+				$error .= "\t-> Line Number = $i".PHP_EOL;
1042
+				$start = ($i - 20);
1043
+				$start = ($start < 0) ? 0 : $start;
1044 1044
 				$length = 40;
1045 1045
 				$point = $max - $i;
1046
-				if ( $point < 20 ) {
1046
+				if ($point < 20) {
1047 1047
 					$rlength = 1;
1048 1048
 					$rpoint = -$point;
1049 1049
 				} else {
@@ -1052,16 +1052,16 @@  discard block
 block discarded – undo
1052 1052
 				}
1053 1053
 				$error .= "\t-> Section Data1  = ";
1054 1054
 				$error .= substr_replace(
1055
-					substr( $data1, $start, $length ),
1056
-					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1055
+					substr($data1, $start, $length),
1056
+					"<b style=\"color:green\">{$data1[$i]}</b>",
1057 1057
 					$rpoint,
1058 1058
 					$rlength
1059 1059
 				);
1060 1060
 				$error .= PHP_EOL;
1061 1061
 				$error .= "\t-> Section Data2  = ";
1062 1062
 				$error .= substr_replace(
1063
-					substr( $data2, $start, $length ),
1064
-					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1063
+					substr($data2, $start, $length),
1064
+					"<b style=\"color:red\">{$data2[$i]}</b>",
1065 1065
 					$rpoint,
1066 1066
 					$rlength
1067 1067
 				);
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 	  * set session data
424 424
 	  * @access 	public
425 425
 	  * @param 	array $data
426
-	  * @return 	TRUE on success, FALSE on fail
426
+	  * @return 	boolean on success, FALSE on fail
427 427
 	  */
428 428
 	public function set_session_data( $data ) {
429 429
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 	 /**
452 452
 	  * @initiate session
453 453
 	  * @access   private
454
-	  * @return TRUE on success, FALSE on fail
454
+	  * @return boolean on success, FALSE on fail
455 455
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
456 456
 	  * @throws \EE_Error
457 457
 	  */
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 	  * @update session data  prior to saving to the db
666 666
 	  * @access public
667 667
 	  * @param bool $new_session
668
-	  * @return TRUE on success, FALSE on fail
668
+	  * @return boolean on success, FALSE on fail
669 669
 	  */
670 670
 	public function update( $new_session = FALSE ) {
671 671
 		$this->_session_data = isset( $this->_session_data )
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 	  * @access public
931 931
 	  * @param array $data_to_reset
932 932
 	  * @param bool  $show_all_notices
933
-	  * @return TRUE on success, FALSE on fail
933
+	  * @return boolean on success, FALSE on fail
934 934
 	  */
935 935
 	public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) {
936 936
 		// if $data_to_reset is not in an array, then put it in one
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +3268 added lines, -3268 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -28,2116 +28,2116 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    //set in _init_page_props()
32
-    public $page_slug;
31
+	//set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    //set in define_page_props()
39
-    protected $_admin_base_url;
38
+	//set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    //set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	//set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    //navtabs
52
-    protected $_nav_tabs;
51
+	//navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    //helptourstops
57
-    protected $_help_tour = array();
56
+	//helptourstops
57
+	protected $_help_tour = array();
58 58
 
59 59
 
60
-    //template variables (used by templates)
61
-    protected $_template_path;
60
+	//template variables (used by templates)
61
+	protected $_template_path;
62 62
 
63
-    protected $_column_template_path;
63
+	protected $_column_template_path;
64 64
 
65
-    /**
66
-     * @var array $_template_args
67
-     */
68
-    protected $_template_args = array();
65
+	/**
66
+	 * @var array $_template_args
67
+	 */
68
+	protected $_template_args = array();
69 69
 
70
-    /**
71
-     * this will hold the list table object for a given view.
72
-     *
73
-     * @var EE_Admin_List_Table $_list_table_object
74
-     */
75
-    protected $_list_table_object;
70
+	/**
71
+	 * this will hold the list table object for a given view.
72
+	 *
73
+	 * @var EE_Admin_List_Table $_list_table_object
74
+	 */
75
+	protected $_list_table_object;
76 76
 
77
-    //bools
78
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
77
+	//bools
78
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79 79
 
80
-    protected $_routing;
80
+	protected $_routing;
81 81
 
82
-    //list table args
83
-    protected $_view;
82
+	//list table args
83
+	protected $_view;
84 84
 
85
-    protected $_views;
85
+	protected $_views;
86 86
 
87 87
 
88
-    //action => method pairs used for routing incoming requests
89
-    protected $_page_routes;
88
+	//action => method pairs used for routing incoming requests
89
+	protected $_page_routes;
90 90
 
91
-    protected $_page_config;
91
+	protected $_page_config;
92 92
 
93
-    //the current page route and route config
94
-    protected $_route;
93
+	//the current page route and route config
94
+	protected $_route;
95 95
 
96
-    protected $_route_config;
96
+	protected $_route_config;
97 97
 
98
-    /**
99
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
-     * actions.
101
-     *
102
-     * @since 4.6.x
103
-     * @var array.
104
-     */
105
-    protected $_default_route_query_args;
98
+	/**
99
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
+	 * actions.
101
+	 *
102
+	 * @since 4.6.x
103
+	 * @var array.
104
+	 */
105
+	protected $_default_route_query_args;
106 106
 
107
-    //set via request page and action args.
108
-    protected $_current_page;
107
+	//set via request page and action args.
108
+	protected $_current_page;
109 109
 
110
-    protected $_current_view;
110
+	protected $_current_view;
111 111
 
112
-    protected $_current_page_view_url;
112
+	protected $_current_page_view_url;
113 113
 
114
-    //sanitized request action (and nonce)
115
-    /**
116
-     * @var string $_req_action
117
-     */
118
-    protected $_req_action;
114
+	//sanitized request action (and nonce)
115
+	/**
116
+	 * @var string $_req_action
117
+	 */
118
+	protected $_req_action;
119 119
 
120
-    /**
121
-     * @var string $_req_nonce
122
-     */
123
-    protected $_req_nonce;
120
+	/**
121
+	 * @var string $_req_nonce
122
+	 */
123
+	protected $_req_nonce;
124 124
 
125
-    //search related
126
-    protected $_search_btn_label;
125
+	//search related
126
+	protected $_search_btn_label;
127 127
 
128
-    protected $_search_box_callback;
128
+	protected $_search_box_callback;
129 129
 
130
-    /**
131
-     * WP Current Screen object
132
-     *
133
-     * @var WP_Screen
134
-     */
135
-    protected $_current_screen;
130
+	/**
131
+	 * WP Current Screen object
132
+	 *
133
+	 * @var WP_Screen
134
+	 */
135
+	protected $_current_screen;
136 136
 
137
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
-    protected $_hook_obj;
137
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
+	protected $_hook_obj;
139 139
 
140
-    //for holding incoming request data
141
-    protected $_req_data;
140
+	//for holding incoming request data
141
+	protected $_req_data;
142 142
 
143
-    // yes / no array for admin form fields
144
-    protected $_yes_no_values = array();
145
-
146
-    //some default things shared by all child classes
147
-    protected $_default_espresso_metaboxes;
148
-
149
-    /**
150
-     *    EE_Registry Object
151
-     *
152
-     * @var    EE_Registry
153
-     * @access    protected
154
-     */
155
-    protected $EE = null;
156
-
157
-
158
-
159
-    /**
160
-     * This is just a property that flags whether the given route is a caffeinated route or not.
161
-     *
162
-     * @var boolean
163
-     */
164
-    protected $_is_caf = false;
165
-
166
-
167
-
168
-    /**
169
-     * @Constructor
170
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
-     * @access public
172
-     */
173
-    public function __construct($routing = true)
174
-    {
175
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
-            $this->_is_caf = true;
177
-        }
178
-        $this->_yes_no_values = array(
179
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
-                array('id' => false, 'text' => __('No', 'event_espresso')),
181
-        );
182
-        //set the _req_data property.
183
-        $this->_req_data = array_merge($_GET, $_POST);
184
-        //routing enabled?
185
-        $this->_routing = $routing;
186
-        //set initial page props (child method)
187
-        $this->_init_page_props();
188
-        //set global defaults
189
-        $this->_set_defaults();
190
-        //set early because incoming requests could be ajax related and we need to register those hooks.
191
-        $this->_global_ajax_hooks();
192
-        $this->_ajax_hooks();
193
-        //other_page_hooks have to be early too.
194
-        $this->_do_other_page_hooks();
195
-        //This just allows us to have extending clases do something specific before the parent constructor runs _page_setup.
196
-        if (method_exists($this, '_before_page_setup')) {
197
-            $this->_before_page_setup();
198
-        }
199
-        //set up page dependencies
200
-        $this->_page_setup();
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * _init_page_props
207
-     * Child classes use to set at least the following properties:
208
-     * $page_slug.
209
-     * $page_label.
210
-     *
211
-     * @abstract
212
-     * @access protected
213
-     * @return void
214
-     */
215
-    abstract protected function _init_page_props();
216
-
217
-
218
-
219
-    /**
220
-     * _ajax_hooks
221
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
222
-     * Note: within the ajax callback methods.
223
-     *
224
-     * @abstract
225
-     * @access protected
226
-     * @return void
227
-     */
228
-    abstract protected function _ajax_hooks();
229
-
230
-
231
-
232
-    /**
233
-     * _define_page_props
234
-     * child classes define page properties in here.  Must include at least:
235
-     * $_admin_base_url = base_url for all admin pages
236
-     * $_admin_page_title = default admin_page_title for admin pages
237
-     * $_labels = array of default labels for various automatically generated elements:
238
-     *    array(
239
-     *        'buttons' => array(
240
-     *            'add' => __('label for add new button'),
241
-     *            'edit' => __('label for edit button'),
242
-     *            'delete' => __('label for delete button')
243
-     *            )
244
-     *        )
245
-     *
246
-     * @abstract
247
-     * @access protected
248
-     * @return void
249
-     */
250
-    abstract protected function _define_page_props();
251
-
252
-
253
-
254
-    /**
255
-     * _set_page_routes
256
-     * 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'
257
-     * route. Here's the format
258
-     * $this->_page_routes = array(
259
-     *        'default' => array(
260
-     *            'func' => '_default_method_handling_route',
261
-     *            'args' => array('array','of','args'),
262
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
263
-     *            '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.
264
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
265
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
266
-     *        ),
267
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
268
-     *        )
269
-     * )
270
-     *
271
-     * @abstract
272
-     * @access protected
273
-     * @return void
274
-     */
275
-    abstract protected function _set_page_routes();
276
-
277
-
278
-
279
-    /**
280
-     * _set_page_config
281
-     * 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.
282
-     * Format:
283
-     * $this->_page_config = array(
284
-     *        'default' => array(
285
-     *            'labels' => array(
286
-     *                'buttons' => array(
287
-     *                    'add' => __('label for adding item'),
288
-     *                    'edit' => __('label for editing item'),
289
-     *                    'delete' => __('label for deleting item')
290
-     *                ),
291
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
292
-     *            ), //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
293
-     *            'nav' => array(
294
-     *                'label' => __('Label for Tab', 'event_espresso').
295
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
296
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
297
-     *                'order' => 10, //required to indicate tab position.
298
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
299
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
300
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
301
-     *            '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
302
-     *            this flag to make sure the necessary js gets enqueued on page load.
303
-     *            '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.
304
-     *            '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
305
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
306
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
307
-     *                'tab_id' => array(
308
-     *                    'title' => 'tab_title',
309
-     *                    '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
310
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
311
-     *                    '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
312
-     *                    ),
313
-     *                'tab2_id' => array(
314
-     *                    'title' => 'tab2 title',
315
-     *                    'filename' => 'file_name_2'
316
-     *                    'callback' => 'callback_method_for_content',
317
-     *                 ),
318
-     *            '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/
319
-     *            'help_tour' => array(
320
-     *                '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
321
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
322
-     *            ),
323
-     *            '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
324
-     *            'require_nonce' to FALSE
325
-     *            )
326
-     * )
327
-     *
328
-     * @abstract
329
-     * @access protected
330
-     * @return void
331
-     */
332
-    abstract protected function _set_page_config();
333
-
334
-
335
-
336
-
337
-
338
-    /** end sample help_tour methods **/
339
-    /**
340
-     * _add_screen_options
341
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
342
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
343
-     *
344
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
345
-     *         see also WP_Screen object documents...
346
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
347
-     * @abstract
348
-     * @access protected
349
-     * @return void
350
-     */
351
-    abstract protected function _add_screen_options();
352
-
353
-
354
-
355
-    /**
356
-     * _add_feature_pointers
357
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
358
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
359
-     * Note: this is just a placeholder for now.  Implementation will come down the road
360
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
361
-     *
362
-     * @link   http://eamann.com/tech/wordpress-portland/
363
-     * @abstract
364
-     * @access protected
365
-     * @return void
366
-     */
367
-    abstract protected function _add_feature_pointers();
368
-
369
-
370
-
371
-    /**
372
-     * load_scripts_styles
373
-     * 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
374
-     * 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)
375
-     *
376
-     * @abstract
377
-     * @access public
378
-     * @return void
379
-     */
380
-    abstract public function load_scripts_styles();
381
-
382
-
383
-
384
-    /**
385
-     * admin_init
386
-     * 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.
387
-     *
388
-     * @abstract
389
-     * @access public
390
-     * @return void
391
-     */
392
-    abstract public function admin_init();
393
-
394
-
395
-
396
-    /**
397
-     * admin_notices
398
-     * 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.
399
-     *
400
-     * @abstract
401
-     * @access public
402
-     * @return void
403
-     */
404
-    abstract public function admin_notices();
405
-
406
-
407
-
408
-    /**
409
-     * admin_footer_scripts
410
-     * 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.
411
-     *
412
-     * @access public
413
-     * @return void
414
-     */
415
-    abstract public function admin_footer_scripts();
416
-
417
-
418
-
419
-    /**
420
-     * admin_footer
421
-     * 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.
422
-     *
423
-     * @access  public
424
-     * @return void
425
-     */
426
-    public function admin_footer()
427
-    {
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * _global_ajax_hooks
434
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
435
-     * Note: within the ajax callback methods.
436
-     *
437
-     * @abstract
438
-     * @access protected
439
-     * @return void
440
-     */
441
-    protected function _global_ajax_hooks()
442
-    {
443
-        //for lazy loading of metabox content
444
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
445
-    }
446
-
447
-
448
-
449
-    public function ajax_metabox_content()
450
-    {
451
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
452
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
453
-        self::cached_rss_display($contentid, $url);
454
-        wp_die();
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * _page_setup
461
-     * 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.
462
-     *
463
-     * @final
464
-     * @access protected
465
-     * @return void
466
-     */
467
-    final protected function _page_setup()
468
-    {
469
-        //requires?
470
-        //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.
471
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
472
-        //next verify if we need to load anything...
473
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
474
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
475
-        global $ee_menu_slugs;
476
-        $ee_menu_slugs = (array)$ee_menu_slugs;
477
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
478
-            return false;
479
-        }
480
-        // 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
481
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
482
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
483
-        }
484
-        // then set blank or -1 action values to 'default'
485
-        $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';
486
-        //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.
487
-        $this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
488
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
489
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
490
-        $this->_current_view = $this->_req_action;
491
-        $this->_req_nonce = $this->_req_action . '_nonce';
492
-        $this->_define_page_props();
493
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
494
-        //default things
495
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
496
-        //set page configs
497
-        $this->_set_page_routes();
498
-        $this->_set_page_config();
499
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
500
-        if (isset($this->_req_data['wp_referer'])) {
501
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
502
-        }
503
-        //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
504
-        if (method_exists($this, '_extend_page_config')) {
505
-            $this->_extend_page_config();
506
-        }
507
-        //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.
508
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
509
-            $this->_extend_page_config_for_cpt();
510
-        }
511
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
512
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
513
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
514
-        //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
515
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
516
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
517
-        }
518
-        //next route only if routing enabled
519
-        if ($this->_routing && ! defined('DOING_AJAX')) {
520
-            $this->_verify_routes();
521
-            //next let's just check user_access and kill if no access
522
-            $this->check_user_access();
523
-            if ($this->_is_UI_request) {
524
-                //admin_init stuff - global, all views for this page class, specific view
525
-                add_action('admin_init', array($this, 'admin_init'), 10);
526
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
527
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
528
-                }
529
-            } else {
530
-                //hijack regular WP loading and route admin request immediately
531
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
532
-                $this->route_admin_request();
533
-            }
534
-        }
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
541
-     *
542
-     * @access private
543
-     * @return void
544
-     */
545
-    private function _do_other_page_hooks()
546
-    {
547
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
548
-        foreach ($registered_pages as $page) {
549
-            //now let's setup the file name and class that should be present
550
-            $classname = str_replace('.class.php', '', $page);
551
-            //autoloaders should take care of loading file
552
-            if ( ! class_exists($classname)) {
553
-                $error_msg[] = sprintf(__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554
-                $error_msg[] = $error_msg[0]
555
-                               . "\r\n"
556
-                               . sprintf(__('There is no class in place for the %s admin hooks page.%sMake sure you have <strong>%s</strong> defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
557
-                                'event_espresso'), $page, '<br />', $classname);
558
-                throw new EE_Error(implode('||', $error_msg));
559
-            }
560
-            $a = new ReflectionClass($classname);
561
-            //notice we are passing the instance of this class to the hook object.
562
-            $hookobj[] = $a->newInstance($this);
563
-        }
564
-    }
565
-
566
-
567
-
568
-    public function load_page_dependencies()
569
-    {
570
-        try {
571
-            $this->_load_page_dependencies();
572
-        } catch (EE_Error $e) {
573
-            $e->get_error();
574
-        }
575
-    }
576
-
577
-
578
-
579
-    /**
580
-     * load_page_dependencies
581
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
582
-     *
583
-     * @access public
584
-     * @return void
585
-     */
586
-    protected function _load_page_dependencies()
587
-    {
588
-        //let's set the current_screen and screen options to override what WP set
589
-        $this->_current_screen = get_current_screen();
590
-        //load admin_notices - global, page class, and view specific
591
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
592
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
593
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
594
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
595
-        }
596
-        //load network admin_notices - global, page class, and view specific
597
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
598
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
599
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
600
-        }
601
-        //this will save any per_page screen options if they are present
602
-        $this->_set_per_page_screen_options();
603
-        //setup list table properties
604
-        $this->_set_list_table();
605
-        // 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.
606
-        $this->_add_registered_meta_boxes();
607
-        $this->_add_screen_columns();
608
-        //add screen options - global, page child class, and view specific
609
-        $this->_add_global_screen_options();
610
-        $this->_add_screen_options();
611
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
612
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
613
-        }
614
-        //add help tab(s) and tours- set via page_config and qtips.
615
-        $this->_add_help_tour();
616
-        $this->_add_help_tabs();
617
-        $this->_add_qtips();
618
-        //add feature_pointers - global, page child class, and view specific
619
-        $this->_add_feature_pointers();
620
-        $this->_add_global_feature_pointers();
621
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
622
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
623
-        }
624
-        //enqueue scripts/styles - global, page class, and view specific
625
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
626
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
627
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
628
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
629
-        }
630
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
631
-        //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
632
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
633
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
634
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
635
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
636
-        }
637
-        //admin footer scripts
638
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
639
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
640
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
641
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
642
-        }
643
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
644
-        //targeted hook
645
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * _set_defaults
652
-     * This sets some global defaults for class properties.
653
-     */
654
-    private function _set_defaults()
655
-    {
656
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
657
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
658
-        $this->default_nav_tab_name = 'overview';
659
-        //init template args
660
-        $this->_template_args = array(
661
-                'admin_page_header'  => '',
662
-                'admin_page_content' => '',
663
-                'post_body_content'  => '',
664
-                'before_list_table'  => '',
665
-                'after_list_table'   => '',
666
-        );
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     * route_admin_request
673
-     *
674
-     * @see    _route_admin_request()
675
-     * @access public
676
-     * @return void|exception error
677
-     */
678
-    public function route_admin_request()
679
-    {
680
-        try {
681
-            $this->_route_admin_request();
682
-        } catch (EE_Error $e) {
683
-            $e->get_error();
684
-        }
685
-    }
686
-
687
-
688
-
689
-    public function set_wp_page_slug($wp_page_slug)
690
-    {
691
-        $this->_wp_page_slug = $wp_page_slug;
692
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
693
-        if (is_network_admin()) {
694
-            $this->_wp_page_slug .= '-network';
695
-        }
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * _verify_routes
702
-     * 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.
703
-     *
704
-     * @access protected
705
-     * @return void
706
-     */
707
-    protected function _verify_routes()
708
-    {
709
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
710
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
711
-            return false;
712
-        }
713
-        $this->_route = false;
714
-        $func = false;
715
-        $args = array();
716
-        // check that the page_routes array is not empty
717
-        if (empty($this->_page_routes)) {
718
-            // user error msg
719
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
720
-            // developer error msg
721
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722
-            throw new EE_Error($error_msg);
723
-        }
724
-        // and that the requested page route exists
725
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
726
-            $this->_route = $this->_page_routes[$this->_req_action];
727
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
728
-        } else {
729
-            // user error msg
730
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
731
-            // developer error msg
732
-            $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);
733
-            throw new EE_Error($error_msg);
734
-        }
735
-        // and that a default route exists
736
-        if ( ! array_key_exists('default', $this->_page_routes)) {
737
-            // user error msg
738
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
739
-            // developer error msg
740
-            $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');
741
-            throw new EE_Error($error_msg);
742
-        }
743
-        //first lets' catch if the UI request has EVER been set.
744
-        if ($this->_is_UI_request === null) {
745
-            //lets set if this is a UI request or not.
746
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
747
-            //wait a minute... we might have a noheader in the route array
748
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
749
-        }
750
-        $this->_set_current_labels();
751
-    }
752
-
753
-
754
-
755
-    /**
756
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
757
-     *
758
-     * @param  string $route the route name we're verifying
759
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
760
-     */
761
-    protected function _verify_route($route)
762
-    {
763
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
764
-            return true;
765
-        } else {
766
-            // user error msg
767
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
768
-            // developer error msg
769
-            $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);
770
-            throw new EE_Error($error_msg);
771
-        }
772
-    }
773
-
774
-
775
-
776
-    /**
777
-     * perform nonce verification
778
-     * 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!)
779
-     *
780
-     * @param  string $nonce     The nonce sent
781
-     * @param  string $nonce_ref The nonce reference string (name0)
782
-     * @return mixed (bool|die)
783
-     */
784
-    protected function _verify_nonce($nonce, $nonce_ref)
785
-    {
786
-        // verify nonce against expected value
787
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
788
-            // these are not the droids you are looking for !!!
789
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
790
-            if (WP_DEBUG) {
791
-                $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__);
792
-            }
793
-            if ( ! defined('DOING_AJAX')) {
794
-                wp_die($msg);
795
-            } else {
796
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
797
-                $this->_return_json();
798
-            }
799
-        }
800
-    }
801
-
802
-
803
-
804
-    /**
805
-     * _route_admin_request()
806
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
807
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
808
-     * in the page routes and then will try to load the corresponding method.
809
-     *
810
-     * @access protected
811
-     * @return void
812
-     * @throws \EE_Error
813
-     */
814
-    protected function _route_admin_request()
815
-    {
816
-        if ( ! $this->_is_UI_request) {
817
-            $this->_verify_routes();
818
-        }
819
-        $nonce_check = isset($this->_route_config['require_nonce'])
820
-            ? $this->_route_config['require_nonce']
821
-            : true;
822
-        if ($this->_req_action !== 'default' && $nonce_check) {
823
-            // set nonce from post data
824
-            $nonce = isset($this->_req_data[$this->_req_nonce])
825
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
826
-                : '';
827
-            $this->_verify_nonce($nonce, $this->_req_nonce);
828
-        }
829
-        //set the nav_tabs array but ONLY if this is  UI_request
830
-        if ($this->_is_UI_request) {
831
-            $this->_set_nav_tabs();
832
-        }
833
-        // grab callback function
834
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
835
-        // check if callback has args
836
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
837
-        $error_msg = '';
838
-        // action right before calling route
839
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
840
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
841
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
842
-        }
843
-        // right before calling the route, let's remove _wp_http_referer from the
844
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
845
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
846
-        if ( ! empty($func)) {
847
-            if (is_array($func)) {
848
-                list($class, $method) = $func;
849
-            } else if (strpos($func, '::') !== false) {
850
-                list($class, $method) = explode('::', $func);
851
-            } else {
852
-                $class = $this;
853
-                $method = $func;
854
-            }
855
-            if ( ! (is_object($class) && $class === $this)) {
856
-                // send along this admin page object for access by addons.
857
-                $args['admin_page_object'] = $this;
858
-            }
859
-            if (
860
-                //is it a method on a class that doesn't work?
861
-                (
862
-                    method_exists($class, $method)
863
-                    && call_user_func_array(array($class, $method), $args) === false
864
-                )
865
-                || (
866
-                    //is it a standalone function that doesn't work?
867
-                    function_exists($method)
868
-                    && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
869
-                )
870
-                || (
871
-                    //is it neither a class method NOR a standalone function?
872
-                    ! method_exists($class, $method)
873
-                    && ! function_exists($method)
874
-                )
875
-            ) {
876
-                // user error msg
877
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
878
-                // developer error msg
879
-                $error_msg .= '||';
880
-                $error_msg .= sprintf(
881
-                    __(
882
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
883
-                        'event_espresso'
884
-                    ),
885
-                    $method
886
-                );
887
-            }
888
-            if ( ! empty($error_msg)) {
889
-                throw new EE_Error($error_msg);
890
-            }
891
-        }
892
-        //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.
893
-        //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.
894
-        if ($this->_is_UI_request === false
895
-            && is_array($this->_route)
896
-            && ! empty($this->_route['headers_sent_route'])
897
-        ) {
898
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
899
-        }
900
-    }
901
-
902
-
903
-
904
-    /**
905
-     * This method just allows the resetting of page properties in the case where a no headers
906
-     * route redirects to a headers route in its route config.
907
-     *
908
-     * @since   4.3.0
909
-     * @param  string $new_route New (non header) route to redirect to.
910
-     * @return   void
911
-     */
912
-    protected function _reset_routing_properties($new_route)
913
-    {
914
-        $this->_is_UI_request = true;
915
-        //now we set the current route to whatever the headers_sent_route is set at
916
-        $this->_req_data['action'] = $new_route;
917
-        //rerun page setup
918
-        $this->_page_setup();
919
-    }
920
-
921
-
922
-
923
-    /**
924
-     * _add_query_arg
925
-     * adds nonce to array of arguments then calls WP add_query_arg function
926
-     *(internally just uses EEH_URL's function with the same name)
927
-     *
928
-     * @access public
929
-     * @param array  $args
930
-     * @param string $url
931
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
932
-     *                                        url in an associative array indexed by the key 'wp_referer';
933
-     *                                        Example usage:
934
-     *                                        If the current page is:
935
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
936
-     *                                        &action=default&event_id=20&month_range=March%202015
937
-     *                                        &_wpnonce=5467821
938
-     *                                        and you call:
939
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
940
-     *                                        array(
941
-     *                                        'action' => 'resend_something',
942
-     *                                        'page=>espresso_registrations'
943
-     *                                        ),
944
-     *                                        $some_url,
945
-     *                                        true
946
-     *                                        );
947
-     *                                        It will produce a url in this structure:
948
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
949
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
950
-     *                                        month_range]=March%202015
951
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
952
-     * @return string
953
-     */
954
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
955
-    {
956
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
957
-        if ($sticky) {
958
-            $request = $_REQUEST;
959
-            unset($request['_wp_http_referer']);
960
-            unset($request['wp_referer']);
961
-            foreach ($request as $key => $value) {
962
-                //do not add nonces
963
-                if (strpos($key, 'nonce') !== false) {
964
-                    continue;
965
-                }
966
-                $args['wp_referer[' . $key . ']'] = $value;
967
-            }
968
-        }
969
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
970
-    }
971
-
972
-
973
-
974
-    /**
975
-     * This returns a generated link that will load the related help tab.
976
-     *
977
-     * @param  string $help_tab_id the id for the connected help tab
978
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
979
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
980
-     * @uses EEH_Template::get_help_tab_link()
981
-     * @return string              generated link
982
-     */
983
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
984
-    {
985
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
986
-    }
987
-
988
-
989
-
990
-    /**
991
-     * _add_help_tabs
992
-     * Note child classes define their help tabs within the page_config array.
993
-     *
994
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
995
-     * @access protected
996
-     * @return void
997
-     */
998
-    protected function _add_help_tabs()
999
-    {
1000
-        $tour_buttons = '';
1001
-        if (isset($this->_page_config[$this->_req_action])) {
1002
-            $config = $this->_page_config[$this->_req_action];
1003
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1004
-            if (isset($this->_help_tour[$this->_req_action])) {
1005
-                $tb = array();
1006
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1007
-                foreach ($this->_help_tour['tours'] as $tour) {
1008
-                    //if this is the end tour then we don't need to setup a button
1009
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1010
-                        continue;
1011
-                    }
1012
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1013
-                }
1014
-                $tour_buttons .= implode('<br />', $tb);
1015
-                $tour_buttons .= '</div></div>';
1016
-            }
1017
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1018
-            if (is_array($config) && isset($config['help_sidebar'])) {
1019
-                //check that the callback given is valid
1020
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1021
-                    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',
1022
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1023
-                }
1024
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1025
-                $content .= $tour_buttons; //add help tour buttons.
1026
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1027
-                $this->_current_screen->set_help_sidebar($content);
1028
-            }
1029
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1030
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1031
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1032
-            }
1033
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1034
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1035
-                $_ht['id'] = $this->page_slug;
1036
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1037
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1038
-                $this->_current_screen->add_help_tab($_ht);
1039
-            }/**/
1040
-            if ( ! isset($config['help_tabs'])) {
1041
-                return;
1042
-            } //no help tabs for this route
1043
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1044
-                //we're here so there ARE help tabs!
1045
-                //make sure we've got what we need
1046
-                if ( ! isset($cfg['title'])) {
1047
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1048
-                }
1049
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1050
-                    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',
1051
-                            'event_espresso'));
1052
-                }
1053
-                //first priority goes to content.
1054
-                if ( ! empty($cfg['content'])) {
1055
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1056
-                    //second priority goes to filename
1057
-                } else if ( ! empty($cfg['filename'])) {
1058
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1059
-                    //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)
1060
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1061
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1062
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1063
-                        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',
1064
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1065
-                        return;
1066
-                    }
1067
-                    $template_args['admin_page_obj'] = $this;
1068
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1069
-                } else {
1070
-                    $content = '';
1071
-                }
1072
-                //check if callback is valid
1073
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1074
-                    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.',
1075
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1076
-                    return;
1077
-                }
1078
-                //setup config array for help tab method
1079
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1080
-                $_ht = array(
1081
-                        'id'       => $id,
1082
-                        'title'    => $cfg['title'],
1083
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1084
-                        'content'  => $content,
1085
-                );
1086
-                $this->_current_screen->add_help_tab($_ht);
1087
-            }
1088
-        }
1089
-    }
1090
-
1091
-
1092
-
1093
-    /**
1094
-     * 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
1095
-     *
1096
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1097
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1098
-     * @access protected
1099
-     * @return void
1100
-     */
1101
-    protected function _add_help_tour()
1102
-    {
1103
-        $tours = array();
1104
-        $this->_help_tour = array();
1105
-        //exit early if help tours are turned off globally
1106
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1107
-            return;
1108
-        }
1109
-        //loop through _page_config to find any help_tour defined
1110
-        foreach ($this->_page_config as $route => $config) {
1111
-            //we're only going to set things up for this route
1112
-            if ($route !== $this->_req_action) {
1113
-                continue;
1114
-            }
1115
-            if (isset($config['help_tour'])) {
1116
-                foreach ($config['help_tour'] as $tour) {
1117
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1118
-                    //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
1119
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1120
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1121
-                    if ( ! is_readable($file_path)) {
1122
-                        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'),
1123
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1124
-                        return;
1125
-                    }
1126
-                    require_once $file_path;
1127
-                    if ( ! class_exists($tour)) {
1128
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1129
-                        $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.',
1130
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1131
-                        throw new EE_Error(implode('||', $error_msg));
1132
-                    }
1133
-                    $a = new ReflectionClass($tour);
1134
-                    $tour_obj = $a->newInstance($this->_is_caf);
1135
-                    $tours[] = $tour_obj;
1136
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1137
-                }
1138
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1139
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1140
-                $tours[] = $end_stop_tour;
1141
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1142
-            }
1143
-        }
1144
-        if ( ! empty($tours)) {
1145
-            $this->_help_tour['tours'] = $tours;
1146
-        }
1147
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1148
-    }
1149
-
1150
-
1151
-
1152
-    /**
1153
-     * This simply sets up any qtips that have been defined in the page config
1154
-     *
1155
-     * @access protected
1156
-     * @return void
1157
-     */
1158
-    protected function _add_qtips()
1159
-    {
1160
-        if (isset($this->_route_config['qtips'])) {
1161
-            $qtips = (array)$this->_route_config['qtips'];
1162
-            //load qtip loader
1163
-            $path = array(
1164
-                    $this->_get_dir() . '/qtips/',
1165
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1166
-            );
1167
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1168
-        }
1169
-    }
1170
-
1171
-
1172
-
1173
-    /**
1174
-     * _set_nav_tabs
1175
-     * 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.
1176
-     *
1177
-     * @access protected
1178
-     * @return void
1179
-     */
1180
-    protected function _set_nav_tabs()
1181
-    {
1182
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1183
-        $i = 0;
1184
-        foreach ($this->_page_config as $slug => $config) {
1185
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1186
-                continue;
1187
-            } //no nav tab for this config
1188
-            //check for persistent flag
1189
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1190
-                continue;
1191
-            } //nav tab is only to appear when route requested.
1192
-            if ( ! $this->check_user_access($slug, true)) {
1193
-                continue;
1194
-            } //no nav tab becasue current user does not have access.
1195
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1196
-            $this->_nav_tabs[$slug] = array(
1197
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1198
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1199
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1200
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1201
-            );
1202
-            $i++;
1203
-        }
1204
-        //if $this->_nav_tabs is empty then lets set the default
1205
-        if (empty($this->_nav_tabs)) {
1206
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1207
-                    'url'       => $this->admin_base_url,
1208
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1209
-                    'css_class' => 'nav-tab-active',
1210
-                    'order'     => 10,
1211
-            );
1212
-        }
1213
-        //now let's sort the tabs according to order
1214
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1215
-    }
1216
-
1217
-
1218
-
1219
-    /**
1220
-     * _set_current_labels
1221
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1222
-     *
1223
-     * @access private
1224
-     * @return void
1225
-     */
1226
-    private function _set_current_labels()
1227
-    {
1228
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1229
-            foreach ($this->_route_config['labels'] as $label => $text) {
1230
-                if (is_array($text)) {
1231
-                    foreach ($text as $sublabel => $subtext) {
1232
-                        $this->_labels[$label][$sublabel] = $subtext;
1233
-                    }
1234
-                } else {
1235
-                    $this->_labels[$label] = $text;
1236
-                }
1237
-            }
1238
-        }
1239
-    }
1240
-
1241
-
1242
-
1243
-    /**
1244
-     *        verifies user access for this admin page
1245
-     *
1246
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1247
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1248
-     * @return        BOOL|wp_die()
1249
-     */
1250
-    public function check_user_access($route_to_check = '', $verify_only = false)
1251
-    {
1252
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1253
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1254
-        $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'])
1255
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1256
-        if (empty($capability) && empty($route_to_check)) {
1257
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1258
-        } else {
1259
-            $capability = empty($capability) ? 'manage_options' : $capability;
1260
-        }
1261
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1262
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1263
-            if ($verify_only) {
1264
-                return false;
1265
-            } else {
1266
-                if ( is_user_logged_in() ) {
1267
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1268
-                } else {
1269
-                    return false;
1270
-                }
1271
-            }
1272
-        }
1273
-        return true;
1274
-    }
1275
-
1276
-
1277
-
1278
-    /**
1279
-     * admin_init_global
1280
-     * This runs all the code that we want executed within the WP admin_init hook.
1281
-     * This method executes for ALL EE Admin pages.
1282
-     *
1283
-     * @access public
1284
-     * @return void
1285
-     */
1286
-    public function admin_init_global()
1287
-    {
1288
-    }
1289
-
1290
-
1291
-
1292
-    /**
1293
-     * wp_loaded_global
1294
-     * 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
1295
-     *
1296
-     * @access public
1297
-     * @return void
1298
-     */
1299
-    public function wp_loaded()
1300
-    {
1301
-    }
1302
-
1303
-
1304
-
1305
-    /**
1306
-     * admin_notices
1307
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1308
-     *
1309
-     * @access public
1310
-     * @return void
1311
-     */
1312
-    public function admin_notices_global()
1313
-    {
1314
-        $this->_display_no_javascript_warning();
1315
-        $this->_display_espresso_notices();
1316
-    }
1317
-
1318
-
1319
-
1320
-    public function network_admin_notices_global()
1321
-    {
1322
-        $this->_display_no_javascript_warning();
1323
-        $this->_display_espresso_notices();
1324
-    }
1325
-
1326
-
1327
-
1328
-    /**
1329
-     * admin_footer_scripts_global
1330
-     * 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.
1331
-     *
1332
-     * @access public
1333
-     * @return void
1334
-     */
1335
-    public function admin_footer_scripts_global()
1336
-    {
1337
-        $this->_add_admin_page_ajax_loading_img();
1338
-        $this->_add_admin_page_overlay();
1339
-        //if metaboxes are present we need to add the nonce field
1340
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1341
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1342
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1343
-        }
1344
-    }
1345
-
1346
-
1347
-
1348
-    /**
1349
-     * admin_footer_global
1350
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1351
-     *
1352
-     * @access  public
1353
-     * @return  void
1354
-     */
1355
-    public function admin_footer_global()
1356
-    {
1357
-        //dialog container for dialog helper
1358
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1359
-        $d_cont .= '<div class="ee-notices"></div>';
1360
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1361
-        $d_cont .= '</div>';
1362
-        echo $d_cont;
1363
-        //help tour stuff?
1364
-        if (isset($this->_help_tour[$this->_req_action])) {
1365
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1366
-        }
1367
-        //current set timezone for timezone js
1368
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1369
-    }
1370
-
1371
-
1372
-
1373
-    /**
1374
-     * 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.
1375
-     * For child classes:
1376
-     * 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
1377
-     * 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
1378
-     * '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(
1379
-     *    'help_trigger_id' => array(
1380
-     *        'title' => __('localized title for popup', 'event_espresso'),
1381
-     *        'content' => __('localized content for popup', 'event_espresso')
1382
-     *    )
1383
-     * );
1384
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1385
-     *
1386
-     * @access protected
1387
-     * @return string content
1388
-     */
1389
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1390
-    {
1391
-        $content = '';
1392
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1393
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1394
-        //loop through the array and setup content
1395
-        foreach ($help_array as $trigger => $help) {
1396
-            //make sure the array is setup properly
1397
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1398
-                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',
1399
-                        'event_espresso'));
1400
-            }
1401
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1402
-            $template_args = array(
1403
-                    'help_popup_id'      => $trigger,
1404
-                    'help_popup_title'   => $help['title'],
1405
-                    'help_popup_content' => $help['content'],
1406
-            );
1407
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1408
-        }
1409
-        if ($display) {
1410
-            echo $content;
1411
-        } else {
1412
-            return $content;
1413
-        }
1414
-    }
1415
-
1416
-
1417
-
1418
-    /**
1419
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1420
-     *
1421
-     * @access private
1422
-     * @return array properly formatted array for help popup content
1423
-     */
1424
-    private function _get_help_content()
1425
-    {
1426
-        //what is the method we're looking for?
1427
-        $method_name = '_help_popup_content_' . $this->_req_action;
1428
-        //if method doesn't exist let's get out.
1429
-        if ( ! method_exists($this, $method_name)) {
1430
-            return array();
1431
-        }
1432
-        //k we're good to go let's retrieve the help array
1433
-        $help_array = call_user_func(array($this, $method_name));
1434
-        //make sure we've got an array!
1435
-        if ( ! is_array($help_array)) {
1436
-            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'));
1437
-        }
1438
-        return $help_array;
1439
-    }
1440
-
1441
-
1442
-
1443
-    /**
1444
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1445
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1446
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1447
-     *
1448
-     * @access protected
1449
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1450
-     * @param boolean $display    if false then we return the trigger string
1451
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1452
-     * @return string
1453
-     */
1454
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1455
-    {
1456
-        if (defined('DOING_AJAX')) {
1457
-            return;
1458
-        }
1459
-        //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
1460
-        $help_array = $this->_get_help_content();
1461
-        $help_content = '';
1462
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1463
-            $help_array[$trigger_id] = array(
1464
-                    'title'   => __('Missing Content', 'event_espresso'),
1465
-                    '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.)',
1466
-                            'event_espresso'),
1467
-            );
1468
-            $help_content = $this->_set_help_popup_content($help_array, false);
1469
-        }
1470
-        //let's setup the trigger
1471
-        $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>';
1472
-        $content = $content . $help_content;
1473
-        if ($display) {
1474
-            echo $content;
1475
-        } else {
1476
-            return $content;
1477
-        }
1478
-    }
1479
-
1480
-
1481
-
1482
-    /**
1483
-     * _add_global_screen_options
1484
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1485
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1486
-     *
1487
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1488
-     *         see also WP_Screen object documents...
1489
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1490
-     * @abstract
1491
-     * @access private
1492
-     * @return void
1493
-     */
1494
-    private function _add_global_screen_options()
1495
-    {
1496
-    }
1497
-
1498
-
1499
-
1500
-    /**
1501
-     * _add_global_feature_pointers
1502
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1503
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1504
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1505
-     *
1506
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1507
-     * @link   http://eamann.com/tech/wordpress-portland/
1508
-     * @abstract
1509
-     * @access protected
1510
-     * @return void
1511
-     */
1512
-    private function _add_global_feature_pointers()
1513
-    {
1514
-    }
1515
-
1516
-
1517
-
1518
-    /**
1519
-     * load_global_scripts_styles
1520
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1521
-     *
1522
-     * @return void
1523
-     */
1524
-    public function load_global_scripts_styles()
1525
-    {
1526
-        /** STYLES **/
1527
-        // add debugging styles
1528
-        if (WP_DEBUG) {
1529
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1530
-        }
1531
-        //register all styles
1532
-        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);
1533
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1534
-        //helpers styles
1535
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1536
-        //enqueue global styles
1537
-        wp_enqueue_style('ee-admin-css');
1538
-        /** SCRIPTS **/
1539
-        //register all scripts
1540
-        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1541
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1542
-        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);
1543
-        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);
1544
-        // register jQuery Validate - see /includes/functions/wp_hooks.php
1545
-        add_filter('FHEE_load_jquery_validate', '__return_true');
1546
-        add_filter('FHEE_load_joyride', '__return_true');
1547
-        //script for sorting tables
1548
-        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);
1549
-        //script for parsing uri's
1550
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1551
-        //and parsing associative serialized form elements
1552
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1553
-        //helpers scripts
1554
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1555
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1557
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1558
-        //google charts
1559
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1560
-        //enqueue global scripts
1561
-        //taking care of metaboxes
1562
-        if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) {
1563
-            wp_enqueue_script('dashboard');
1564
-        }
1565
-        //enqueue thickbox for ee help popups.  default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups
1566
-        if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) {
1567
-            wp_enqueue_script('ee_admin_js');
1568
-            wp_enqueue_style('ee-admin-css');
1569
-        }
1570
-        //localize script for ajax lazy loading
1571
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1572
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1573
-        /**
1574
-         * help tour stuff
1575
-         */
1576
-        if ( ! empty($this->_help_tour)) {
1577
-            //register the js for kicking things off
1578
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1579
-            //setup tours for the js tour object
1580
-            foreach ($this->_help_tour['tours'] as $tour) {
1581
-                $tours[] = array(
1582
-                        'id'      => $tour->get_slug(),
1583
-                        'options' => $tour->get_options(),
1584
-                );
1585
-            }
1586
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1587
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1588
-        }
1589
-    }
1590
-
1591
-
1592
-
1593
-    /**
1594
-     *        admin_footer_scripts_eei18n_js_strings
1595
-     *
1596
-     * @access        public
1597
-     * @return        void
1598
-     */
1599
-    public function admin_footer_scripts_eei18n_js_strings()
1600
-    {
1601
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1602
-        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');
1603
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1604
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1605
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1606
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1641
-        //setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1642
-        //admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1643
-        //espresso_core is listed as a dependency of ee_admin_js.
1644
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
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 = '
143
+	// yes / no array for admin form fields
144
+	protected $_yes_no_values = array();
145
+
146
+	//some default things shared by all child classes
147
+	protected $_default_espresso_metaboxes;
148
+
149
+	/**
150
+	 *    EE_Registry Object
151
+	 *
152
+	 * @var    EE_Registry
153
+	 * @access    protected
154
+	 */
155
+	protected $EE = null;
156
+
157
+
158
+
159
+	/**
160
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
161
+	 *
162
+	 * @var boolean
163
+	 */
164
+	protected $_is_caf = false;
165
+
166
+
167
+
168
+	/**
169
+	 * @Constructor
170
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
+	 * @access public
172
+	 */
173
+	public function __construct($routing = true)
174
+	{
175
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
+			$this->_is_caf = true;
177
+		}
178
+		$this->_yes_no_values = array(
179
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
+				array('id' => false, 'text' => __('No', 'event_espresso')),
181
+		);
182
+		//set the _req_data property.
183
+		$this->_req_data = array_merge($_GET, $_POST);
184
+		//routing enabled?
185
+		$this->_routing = $routing;
186
+		//set initial page props (child method)
187
+		$this->_init_page_props();
188
+		//set global defaults
189
+		$this->_set_defaults();
190
+		//set early because incoming requests could be ajax related and we need to register those hooks.
191
+		$this->_global_ajax_hooks();
192
+		$this->_ajax_hooks();
193
+		//other_page_hooks have to be early too.
194
+		$this->_do_other_page_hooks();
195
+		//This just allows us to have extending clases do something specific before the parent constructor runs _page_setup.
196
+		if (method_exists($this, '_before_page_setup')) {
197
+			$this->_before_page_setup();
198
+		}
199
+		//set up page dependencies
200
+		$this->_page_setup();
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * _init_page_props
207
+	 * Child classes use to set at least the following properties:
208
+	 * $page_slug.
209
+	 * $page_label.
210
+	 *
211
+	 * @abstract
212
+	 * @access protected
213
+	 * @return void
214
+	 */
215
+	abstract protected function _init_page_props();
216
+
217
+
218
+
219
+	/**
220
+	 * _ajax_hooks
221
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
222
+	 * Note: within the ajax callback methods.
223
+	 *
224
+	 * @abstract
225
+	 * @access protected
226
+	 * @return void
227
+	 */
228
+	abstract protected function _ajax_hooks();
229
+
230
+
231
+
232
+	/**
233
+	 * _define_page_props
234
+	 * child classes define page properties in here.  Must include at least:
235
+	 * $_admin_base_url = base_url for all admin pages
236
+	 * $_admin_page_title = default admin_page_title for admin pages
237
+	 * $_labels = array of default labels for various automatically generated elements:
238
+	 *    array(
239
+	 *        'buttons' => array(
240
+	 *            'add' => __('label for add new button'),
241
+	 *            'edit' => __('label for edit button'),
242
+	 *            'delete' => __('label for delete button')
243
+	 *            )
244
+	 *        )
245
+	 *
246
+	 * @abstract
247
+	 * @access protected
248
+	 * @return void
249
+	 */
250
+	abstract protected function _define_page_props();
251
+
252
+
253
+
254
+	/**
255
+	 * _set_page_routes
256
+	 * 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'
257
+	 * route. Here's the format
258
+	 * $this->_page_routes = array(
259
+	 *        'default' => array(
260
+	 *            'func' => '_default_method_handling_route',
261
+	 *            'args' => array('array','of','args'),
262
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
263
+	 *            '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.
264
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
265
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
266
+	 *        ),
267
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
268
+	 *        )
269
+	 * )
270
+	 *
271
+	 * @abstract
272
+	 * @access protected
273
+	 * @return void
274
+	 */
275
+	abstract protected function _set_page_routes();
276
+
277
+
278
+
279
+	/**
280
+	 * _set_page_config
281
+	 * 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.
282
+	 * Format:
283
+	 * $this->_page_config = array(
284
+	 *        'default' => array(
285
+	 *            'labels' => array(
286
+	 *                'buttons' => array(
287
+	 *                    'add' => __('label for adding item'),
288
+	 *                    'edit' => __('label for editing item'),
289
+	 *                    'delete' => __('label for deleting item')
290
+	 *                ),
291
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
292
+	 *            ), //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
293
+	 *            'nav' => array(
294
+	 *                'label' => __('Label for Tab', 'event_espresso').
295
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
296
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
297
+	 *                'order' => 10, //required to indicate tab position.
298
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
299
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
300
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
301
+	 *            '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
302
+	 *            this flag to make sure the necessary js gets enqueued on page load.
303
+	 *            '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.
304
+	 *            '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
305
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
306
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
307
+	 *                'tab_id' => array(
308
+	 *                    'title' => 'tab_title',
309
+	 *                    '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
310
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
311
+	 *                    '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
312
+	 *                    ),
313
+	 *                'tab2_id' => array(
314
+	 *                    'title' => 'tab2 title',
315
+	 *                    'filename' => 'file_name_2'
316
+	 *                    'callback' => 'callback_method_for_content',
317
+	 *                 ),
318
+	 *            '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/
319
+	 *            'help_tour' => array(
320
+	 *                '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
321
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
322
+	 *            ),
323
+	 *            '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
324
+	 *            'require_nonce' to FALSE
325
+	 *            )
326
+	 * )
327
+	 *
328
+	 * @abstract
329
+	 * @access protected
330
+	 * @return void
331
+	 */
332
+	abstract protected function _set_page_config();
333
+
334
+
335
+
336
+
337
+
338
+	/** end sample help_tour methods **/
339
+	/**
340
+	 * _add_screen_options
341
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
342
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
343
+	 *
344
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
345
+	 *         see also WP_Screen object documents...
346
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
347
+	 * @abstract
348
+	 * @access protected
349
+	 * @return void
350
+	 */
351
+	abstract protected function _add_screen_options();
352
+
353
+
354
+
355
+	/**
356
+	 * _add_feature_pointers
357
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
358
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
359
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
360
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
361
+	 *
362
+	 * @link   http://eamann.com/tech/wordpress-portland/
363
+	 * @abstract
364
+	 * @access protected
365
+	 * @return void
366
+	 */
367
+	abstract protected function _add_feature_pointers();
368
+
369
+
370
+
371
+	/**
372
+	 * load_scripts_styles
373
+	 * 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
374
+	 * 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)
375
+	 *
376
+	 * @abstract
377
+	 * @access public
378
+	 * @return void
379
+	 */
380
+	abstract public function load_scripts_styles();
381
+
382
+
383
+
384
+	/**
385
+	 * admin_init
386
+	 * 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.
387
+	 *
388
+	 * @abstract
389
+	 * @access public
390
+	 * @return void
391
+	 */
392
+	abstract public function admin_init();
393
+
394
+
395
+
396
+	/**
397
+	 * admin_notices
398
+	 * 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.
399
+	 *
400
+	 * @abstract
401
+	 * @access public
402
+	 * @return void
403
+	 */
404
+	abstract public function admin_notices();
405
+
406
+
407
+
408
+	/**
409
+	 * admin_footer_scripts
410
+	 * 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.
411
+	 *
412
+	 * @access public
413
+	 * @return void
414
+	 */
415
+	abstract public function admin_footer_scripts();
416
+
417
+
418
+
419
+	/**
420
+	 * admin_footer
421
+	 * 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.
422
+	 *
423
+	 * @access  public
424
+	 * @return void
425
+	 */
426
+	public function admin_footer()
427
+	{
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * _global_ajax_hooks
434
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
435
+	 * Note: within the ajax callback methods.
436
+	 *
437
+	 * @abstract
438
+	 * @access protected
439
+	 * @return void
440
+	 */
441
+	protected function _global_ajax_hooks()
442
+	{
443
+		//for lazy loading of metabox content
444
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
445
+	}
446
+
447
+
448
+
449
+	public function ajax_metabox_content()
450
+	{
451
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
452
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
453
+		self::cached_rss_display($contentid, $url);
454
+		wp_die();
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * _page_setup
461
+	 * 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.
462
+	 *
463
+	 * @final
464
+	 * @access protected
465
+	 * @return void
466
+	 */
467
+	final protected function _page_setup()
468
+	{
469
+		//requires?
470
+		//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.
471
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
472
+		//next verify if we need to load anything...
473
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
474
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
475
+		global $ee_menu_slugs;
476
+		$ee_menu_slugs = (array)$ee_menu_slugs;
477
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
478
+			return false;
479
+		}
480
+		// 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
481
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
482
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
483
+		}
484
+		// then set blank or -1 action values to 'default'
485
+		$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';
486
+		//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.
487
+		$this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
488
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
489
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
490
+		$this->_current_view = $this->_req_action;
491
+		$this->_req_nonce = $this->_req_action . '_nonce';
492
+		$this->_define_page_props();
493
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
494
+		//default things
495
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
496
+		//set page configs
497
+		$this->_set_page_routes();
498
+		$this->_set_page_config();
499
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
500
+		if (isset($this->_req_data['wp_referer'])) {
501
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
502
+		}
503
+		//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
504
+		if (method_exists($this, '_extend_page_config')) {
505
+			$this->_extend_page_config();
506
+		}
507
+		//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.
508
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
509
+			$this->_extend_page_config_for_cpt();
510
+		}
511
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
512
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
513
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
514
+		//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
515
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
516
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
517
+		}
518
+		//next route only if routing enabled
519
+		if ($this->_routing && ! defined('DOING_AJAX')) {
520
+			$this->_verify_routes();
521
+			//next let's just check user_access and kill if no access
522
+			$this->check_user_access();
523
+			if ($this->_is_UI_request) {
524
+				//admin_init stuff - global, all views for this page class, specific view
525
+				add_action('admin_init', array($this, 'admin_init'), 10);
526
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
527
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
528
+				}
529
+			} else {
530
+				//hijack regular WP loading and route admin request immediately
531
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
532
+				$this->route_admin_request();
533
+			}
534
+		}
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
541
+	 *
542
+	 * @access private
543
+	 * @return void
544
+	 */
545
+	private function _do_other_page_hooks()
546
+	{
547
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
548
+		foreach ($registered_pages as $page) {
549
+			//now let's setup the file name and class that should be present
550
+			$classname = str_replace('.class.php', '', $page);
551
+			//autoloaders should take care of loading file
552
+			if ( ! class_exists($classname)) {
553
+				$error_msg[] = sprintf(__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554
+				$error_msg[] = $error_msg[0]
555
+							   . "\r\n"
556
+							   . sprintf(__('There is no class in place for the %s admin hooks page.%sMake sure you have <strong>%s</strong> defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
557
+								'event_espresso'), $page, '<br />', $classname);
558
+				throw new EE_Error(implode('||', $error_msg));
559
+			}
560
+			$a = new ReflectionClass($classname);
561
+			//notice we are passing the instance of this class to the hook object.
562
+			$hookobj[] = $a->newInstance($this);
563
+		}
564
+	}
565
+
566
+
567
+
568
+	public function load_page_dependencies()
569
+	{
570
+		try {
571
+			$this->_load_page_dependencies();
572
+		} catch (EE_Error $e) {
573
+			$e->get_error();
574
+		}
575
+	}
576
+
577
+
578
+
579
+	/**
580
+	 * load_page_dependencies
581
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
582
+	 *
583
+	 * @access public
584
+	 * @return void
585
+	 */
586
+	protected function _load_page_dependencies()
587
+	{
588
+		//let's set the current_screen and screen options to override what WP set
589
+		$this->_current_screen = get_current_screen();
590
+		//load admin_notices - global, page class, and view specific
591
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
592
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
593
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
594
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
595
+		}
596
+		//load network admin_notices - global, page class, and view specific
597
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
598
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
599
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
600
+		}
601
+		//this will save any per_page screen options if they are present
602
+		$this->_set_per_page_screen_options();
603
+		//setup list table properties
604
+		$this->_set_list_table();
605
+		// 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.
606
+		$this->_add_registered_meta_boxes();
607
+		$this->_add_screen_columns();
608
+		//add screen options - global, page child class, and view specific
609
+		$this->_add_global_screen_options();
610
+		$this->_add_screen_options();
611
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
612
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
613
+		}
614
+		//add help tab(s) and tours- set via page_config and qtips.
615
+		$this->_add_help_tour();
616
+		$this->_add_help_tabs();
617
+		$this->_add_qtips();
618
+		//add feature_pointers - global, page child class, and view specific
619
+		$this->_add_feature_pointers();
620
+		$this->_add_global_feature_pointers();
621
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
622
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
623
+		}
624
+		//enqueue scripts/styles - global, page class, and view specific
625
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
626
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
627
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
628
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
629
+		}
630
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
631
+		//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
632
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
633
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
634
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
635
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
636
+		}
637
+		//admin footer scripts
638
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
639
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
640
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
641
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
642
+		}
643
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
644
+		//targeted hook
645
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * _set_defaults
652
+	 * This sets some global defaults for class properties.
653
+	 */
654
+	private function _set_defaults()
655
+	{
656
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
657
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
658
+		$this->default_nav_tab_name = 'overview';
659
+		//init template args
660
+		$this->_template_args = array(
661
+				'admin_page_header'  => '',
662
+				'admin_page_content' => '',
663
+				'post_body_content'  => '',
664
+				'before_list_table'  => '',
665
+				'after_list_table'   => '',
666
+		);
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 * route_admin_request
673
+	 *
674
+	 * @see    _route_admin_request()
675
+	 * @access public
676
+	 * @return void|exception error
677
+	 */
678
+	public function route_admin_request()
679
+	{
680
+		try {
681
+			$this->_route_admin_request();
682
+		} catch (EE_Error $e) {
683
+			$e->get_error();
684
+		}
685
+	}
686
+
687
+
688
+
689
+	public function set_wp_page_slug($wp_page_slug)
690
+	{
691
+		$this->_wp_page_slug = $wp_page_slug;
692
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
693
+		if (is_network_admin()) {
694
+			$this->_wp_page_slug .= '-network';
695
+		}
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * _verify_routes
702
+	 * 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.
703
+	 *
704
+	 * @access protected
705
+	 * @return void
706
+	 */
707
+	protected function _verify_routes()
708
+	{
709
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
710
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
711
+			return false;
712
+		}
713
+		$this->_route = false;
714
+		$func = false;
715
+		$args = array();
716
+		// check that the page_routes array is not empty
717
+		if (empty($this->_page_routes)) {
718
+			// user error msg
719
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
720
+			// developer error msg
721
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722
+			throw new EE_Error($error_msg);
723
+		}
724
+		// and that the requested page route exists
725
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
726
+			$this->_route = $this->_page_routes[$this->_req_action];
727
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
728
+		} else {
729
+			// user error msg
730
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
731
+			// developer error msg
732
+			$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);
733
+			throw new EE_Error($error_msg);
734
+		}
735
+		// and that a default route exists
736
+		if ( ! array_key_exists('default', $this->_page_routes)) {
737
+			// user error msg
738
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
739
+			// developer error msg
740
+			$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');
741
+			throw new EE_Error($error_msg);
742
+		}
743
+		//first lets' catch if the UI request has EVER been set.
744
+		if ($this->_is_UI_request === null) {
745
+			//lets set if this is a UI request or not.
746
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
747
+			//wait a minute... we might have a noheader in the route array
748
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
749
+		}
750
+		$this->_set_current_labels();
751
+	}
752
+
753
+
754
+
755
+	/**
756
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
757
+	 *
758
+	 * @param  string $route the route name we're verifying
759
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
760
+	 */
761
+	protected function _verify_route($route)
762
+	{
763
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
764
+			return true;
765
+		} else {
766
+			// user error msg
767
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
768
+			// developer error msg
769
+			$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);
770
+			throw new EE_Error($error_msg);
771
+		}
772
+	}
773
+
774
+
775
+
776
+	/**
777
+	 * perform nonce verification
778
+	 * 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!)
779
+	 *
780
+	 * @param  string $nonce     The nonce sent
781
+	 * @param  string $nonce_ref The nonce reference string (name0)
782
+	 * @return mixed (bool|die)
783
+	 */
784
+	protected function _verify_nonce($nonce, $nonce_ref)
785
+	{
786
+		// verify nonce against expected value
787
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
788
+			// these are not the droids you are looking for !!!
789
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
790
+			if (WP_DEBUG) {
791
+				$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__);
792
+			}
793
+			if ( ! defined('DOING_AJAX')) {
794
+				wp_die($msg);
795
+			} else {
796
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
797
+				$this->_return_json();
798
+			}
799
+		}
800
+	}
801
+
802
+
803
+
804
+	/**
805
+	 * _route_admin_request()
806
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
807
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
808
+	 * in the page routes and then will try to load the corresponding method.
809
+	 *
810
+	 * @access protected
811
+	 * @return void
812
+	 * @throws \EE_Error
813
+	 */
814
+	protected function _route_admin_request()
815
+	{
816
+		if ( ! $this->_is_UI_request) {
817
+			$this->_verify_routes();
818
+		}
819
+		$nonce_check = isset($this->_route_config['require_nonce'])
820
+			? $this->_route_config['require_nonce']
821
+			: true;
822
+		if ($this->_req_action !== 'default' && $nonce_check) {
823
+			// set nonce from post data
824
+			$nonce = isset($this->_req_data[$this->_req_nonce])
825
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
826
+				: '';
827
+			$this->_verify_nonce($nonce, $this->_req_nonce);
828
+		}
829
+		//set the nav_tabs array but ONLY if this is  UI_request
830
+		if ($this->_is_UI_request) {
831
+			$this->_set_nav_tabs();
832
+		}
833
+		// grab callback function
834
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
835
+		// check if callback has args
836
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
837
+		$error_msg = '';
838
+		// action right before calling route
839
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
840
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
841
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
842
+		}
843
+		// right before calling the route, let's remove _wp_http_referer from the
844
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
845
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
846
+		if ( ! empty($func)) {
847
+			if (is_array($func)) {
848
+				list($class, $method) = $func;
849
+			} else if (strpos($func, '::') !== false) {
850
+				list($class, $method) = explode('::', $func);
851
+			} else {
852
+				$class = $this;
853
+				$method = $func;
854
+			}
855
+			if ( ! (is_object($class) && $class === $this)) {
856
+				// send along this admin page object for access by addons.
857
+				$args['admin_page_object'] = $this;
858
+			}
859
+			if (
860
+				//is it a method on a class that doesn't work?
861
+				(
862
+					method_exists($class, $method)
863
+					&& call_user_func_array(array($class, $method), $args) === false
864
+				)
865
+				|| (
866
+					//is it a standalone function that doesn't work?
867
+					function_exists($method)
868
+					&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
869
+				)
870
+				|| (
871
+					//is it neither a class method NOR a standalone function?
872
+					! method_exists($class, $method)
873
+					&& ! function_exists($method)
874
+				)
875
+			) {
876
+				// user error msg
877
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
878
+				// developer error msg
879
+				$error_msg .= '||';
880
+				$error_msg .= sprintf(
881
+					__(
882
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
883
+						'event_espresso'
884
+					),
885
+					$method
886
+				);
887
+			}
888
+			if ( ! empty($error_msg)) {
889
+				throw new EE_Error($error_msg);
890
+			}
891
+		}
892
+		//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.
893
+		//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.
894
+		if ($this->_is_UI_request === false
895
+			&& is_array($this->_route)
896
+			&& ! empty($this->_route['headers_sent_route'])
897
+		) {
898
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
899
+		}
900
+	}
901
+
902
+
903
+
904
+	/**
905
+	 * This method just allows the resetting of page properties in the case where a no headers
906
+	 * route redirects to a headers route in its route config.
907
+	 *
908
+	 * @since   4.3.0
909
+	 * @param  string $new_route New (non header) route to redirect to.
910
+	 * @return   void
911
+	 */
912
+	protected function _reset_routing_properties($new_route)
913
+	{
914
+		$this->_is_UI_request = true;
915
+		//now we set the current route to whatever the headers_sent_route is set at
916
+		$this->_req_data['action'] = $new_route;
917
+		//rerun page setup
918
+		$this->_page_setup();
919
+	}
920
+
921
+
922
+
923
+	/**
924
+	 * _add_query_arg
925
+	 * adds nonce to array of arguments then calls WP add_query_arg function
926
+	 *(internally just uses EEH_URL's function with the same name)
927
+	 *
928
+	 * @access public
929
+	 * @param array  $args
930
+	 * @param string $url
931
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
932
+	 *                                        url in an associative array indexed by the key 'wp_referer';
933
+	 *                                        Example usage:
934
+	 *                                        If the current page is:
935
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
936
+	 *                                        &action=default&event_id=20&month_range=March%202015
937
+	 *                                        &_wpnonce=5467821
938
+	 *                                        and you call:
939
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
940
+	 *                                        array(
941
+	 *                                        'action' => 'resend_something',
942
+	 *                                        'page=>espresso_registrations'
943
+	 *                                        ),
944
+	 *                                        $some_url,
945
+	 *                                        true
946
+	 *                                        );
947
+	 *                                        It will produce a url in this structure:
948
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
949
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
950
+	 *                                        month_range]=March%202015
951
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
952
+	 * @return string
953
+	 */
954
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
955
+	{
956
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
957
+		if ($sticky) {
958
+			$request = $_REQUEST;
959
+			unset($request['_wp_http_referer']);
960
+			unset($request['wp_referer']);
961
+			foreach ($request as $key => $value) {
962
+				//do not add nonces
963
+				if (strpos($key, 'nonce') !== false) {
964
+					continue;
965
+				}
966
+				$args['wp_referer[' . $key . ']'] = $value;
967
+			}
968
+		}
969
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
970
+	}
971
+
972
+
973
+
974
+	/**
975
+	 * This returns a generated link that will load the related help tab.
976
+	 *
977
+	 * @param  string $help_tab_id the id for the connected help tab
978
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
979
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
980
+	 * @uses EEH_Template::get_help_tab_link()
981
+	 * @return string              generated link
982
+	 */
983
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
984
+	{
985
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
986
+	}
987
+
988
+
989
+
990
+	/**
991
+	 * _add_help_tabs
992
+	 * Note child classes define their help tabs within the page_config array.
993
+	 *
994
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
995
+	 * @access protected
996
+	 * @return void
997
+	 */
998
+	protected function _add_help_tabs()
999
+	{
1000
+		$tour_buttons = '';
1001
+		if (isset($this->_page_config[$this->_req_action])) {
1002
+			$config = $this->_page_config[$this->_req_action];
1003
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1004
+			if (isset($this->_help_tour[$this->_req_action])) {
1005
+				$tb = array();
1006
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1007
+				foreach ($this->_help_tour['tours'] as $tour) {
1008
+					//if this is the end tour then we don't need to setup a button
1009
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1010
+						continue;
1011
+					}
1012
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1013
+				}
1014
+				$tour_buttons .= implode('<br />', $tb);
1015
+				$tour_buttons .= '</div></div>';
1016
+			}
1017
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1018
+			if (is_array($config) && isset($config['help_sidebar'])) {
1019
+				//check that the callback given is valid
1020
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1021
+					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',
1022
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1023
+				}
1024
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1025
+				$content .= $tour_buttons; //add help tour buttons.
1026
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1027
+				$this->_current_screen->set_help_sidebar($content);
1028
+			}
1029
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1030
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1031
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1032
+			}
1033
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1034
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1035
+				$_ht['id'] = $this->page_slug;
1036
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1037
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1038
+				$this->_current_screen->add_help_tab($_ht);
1039
+			}/**/
1040
+			if ( ! isset($config['help_tabs'])) {
1041
+				return;
1042
+			} //no help tabs for this route
1043
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1044
+				//we're here so there ARE help tabs!
1045
+				//make sure we've got what we need
1046
+				if ( ! isset($cfg['title'])) {
1047
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1048
+				}
1049
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1050
+					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',
1051
+							'event_espresso'));
1052
+				}
1053
+				//first priority goes to content.
1054
+				if ( ! empty($cfg['content'])) {
1055
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1056
+					//second priority goes to filename
1057
+				} else if ( ! empty($cfg['filename'])) {
1058
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1059
+					//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)
1060
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1061
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1062
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1063
+						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',
1064
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1065
+						return;
1066
+					}
1067
+					$template_args['admin_page_obj'] = $this;
1068
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1069
+				} else {
1070
+					$content = '';
1071
+				}
1072
+				//check if callback is valid
1073
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1074
+					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.',
1075
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1076
+					return;
1077
+				}
1078
+				//setup config array for help tab method
1079
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1080
+				$_ht = array(
1081
+						'id'       => $id,
1082
+						'title'    => $cfg['title'],
1083
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1084
+						'content'  => $content,
1085
+				);
1086
+				$this->_current_screen->add_help_tab($_ht);
1087
+			}
1088
+		}
1089
+	}
1090
+
1091
+
1092
+
1093
+	/**
1094
+	 * 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
1095
+	 *
1096
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1097
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1098
+	 * @access protected
1099
+	 * @return void
1100
+	 */
1101
+	protected function _add_help_tour()
1102
+	{
1103
+		$tours = array();
1104
+		$this->_help_tour = array();
1105
+		//exit early if help tours are turned off globally
1106
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1107
+			return;
1108
+		}
1109
+		//loop through _page_config to find any help_tour defined
1110
+		foreach ($this->_page_config as $route => $config) {
1111
+			//we're only going to set things up for this route
1112
+			if ($route !== $this->_req_action) {
1113
+				continue;
1114
+			}
1115
+			if (isset($config['help_tour'])) {
1116
+				foreach ($config['help_tour'] as $tour) {
1117
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1118
+					//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
1119
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1120
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1121
+					if ( ! is_readable($file_path)) {
1122
+						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'),
1123
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1124
+						return;
1125
+					}
1126
+					require_once $file_path;
1127
+					if ( ! class_exists($tour)) {
1128
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1129
+						$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.',
1130
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1131
+						throw new EE_Error(implode('||', $error_msg));
1132
+					}
1133
+					$a = new ReflectionClass($tour);
1134
+					$tour_obj = $a->newInstance($this->_is_caf);
1135
+					$tours[] = $tour_obj;
1136
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1137
+				}
1138
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1139
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1140
+				$tours[] = $end_stop_tour;
1141
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1142
+			}
1143
+		}
1144
+		if ( ! empty($tours)) {
1145
+			$this->_help_tour['tours'] = $tours;
1146
+		}
1147
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1148
+	}
1149
+
1150
+
1151
+
1152
+	/**
1153
+	 * This simply sets up any qtips that have been defined in the page config
1154
+	 *
1155
+	 * @access protected
1156
+	 * @return void
1157
+	 */
1158
+	protected function _add_qtips()
1159
+	{
1160
+		if (isset($this->_route_config['qtips'])) {
1161
+			$qtips = (array)$this->_route_config['qtips'];
1162
+			//load qtip loader
1163
+			$path = array(
1164
+					$this->_get_dir() . '/qtips/',
1165
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1166
+			);
1167
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1168
+		}
1169
+	}
1170
+
1171
+
1172
+
1173
+	/**
1174
+	 * _set_nav_tabs
1175
+	 * 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.
1176
+	 *
1177
+	 * @access protected
1178
+	 * @return void
1179
+	 */
1180
+	protected function _set_nav_tabs()
1181
+	{
1182
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1183
+		$i = 0;
1184
+		foreach ($this->_page_config as $slug => $config) {
1185
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1186
+				continue;
1187
+			} //no nav tab for this config
1188
+			//check for persistent flag
1189
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1190
+				continue;
1191
+			} //nav tab is only to appear when route requested.
1192
+			if ( ! $this->check_user_access($slug, true)) {
1193
+				continue;
1194
+			} //no nav tab becasue current user does not have access.
1195
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1196
+			$this->_nav_tabs[$slug] = array(
1197
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1198
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1199
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1200
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1201
+			);
1202
+			$i++;
1203
+		}
1204
+		//if $this->_nav_tabs is empty then lets set the default
1205
+		if (empty($this->_nav_tabs)) {
1206
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1207
+					'url'       => $this->admin_base_url,
1208
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1209
+					'css_class' => 'nav-tab-active',
1210
+					'order'     => 10,
1211
+			);
1212
+		}
1213
+		//now let's sort the tabs according to order
1214
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1215
+	}
1216
+
1217
+
1218
+
1219
+	/**
1220
+	 * _set_current_labels
1221
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1222
+	 *
1223
+	 * @access private
1224
+	 * @return void
1225
+	 */
1226
+	private function _set_current_labels()
1227
+	{
1228
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1229
+			foreach ($this->_route_config['labels'] as $label => $text) {
1230
+				if (is_array($text)) {
1231
+					foreach ($text as $sublabel => $subtext) {
1232
+						$this->_labels[$label][$sublabel] = $subtext;
1233
+					}
1234
+				} else {
1235
+					$this->_labels[$label] = $text;
1236
+				}
1237
+			}
1238
+		}
1239
+	}
1240
+
1241
+
1242
+
1243
+	/**
1244
+	 *        verifies user access for this admin page
1245
+	 *
1246
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1247
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1248
+	 * @return        BOOL|wp_die()
1249
+	 */
1250
+	public function check_user_access($route_to_check = '', $verify_only = false)
1251
+	{
1252
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1253
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1254
+		$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'])
1255
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1256
+		if (empty($capability) && empty($route_to_check)) {
1257
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1258
+		} else {
1259
+			$capability = empty($capability) ? 'manage_options' : $capability;
1260
+		}
1261
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1262
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1263
+			if ($verify_only) {
1264
+				return false;
1265
+			} else {
1266
+				if ( is_user_logged_in() ) {
1267
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1268
+				} else {
1269
+					return false;
1270
+				}
1271
+			}
1272
+		}
1273
+		return true;
1274
+	}
1275
+
1276
+
1277
+
1278
+	/**
1279
+	 * admin_init_global
1280
+	 * This runs all the code that we want executed within the WP admin_init hook.
1281
+	 * This method executes for ALL EE Admin pages.
1282
+	 *
1283
+	 * @access public
1284
+	 * @return void
1285
+	 */
1286
+	public function admin_init_global()
1287
+	{
1288
+	}
1289
+
1290
+
1291
+
1292
+	/**
1293
+	 * wp_loaded_global
1294
+	 * 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
1295
+	 *
1296
+	 * @access public
1297
+	 * @return void
1298
+	 */
1299
+	public function wp_loaded()
1300
+	{
1301
+	}
1302
+
1303
+
1304
+
1305
+	/**
1306
+	 * admin_notices
1307
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1308
+	 *
1309
+	 * @access public
1310
+	 * @return void
1311
+	 */
1312
+	public function admin_notices_global()
1313
+	{
1314
+		$this->_display_no_javascript_warning();
1315
+		$this->_display_espresso_notices();
1316
+	}
1317
+
1318
+
1319
+
1320
+	public function network_admin_notices_global()
1321
+	{
1322
+		$this->_display_no_javascript_warning();
1323
+		$this->_display_espresso_notices();
1324
+	}
1325
+
1326
+
1327
+
1328
+	/**
1329
+	 * admin_footer_scripts_global
1330
+	 * 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.
1331
+	 *
1332
+	 * @access public
1333
+	 * @return void
1334
+	 */
1335
+	public function admin_footer_scripts_global()
1336
+	{
1337
+		$this->_add_admin_page_ajax_loading_img();
1338
+		$this->_add_admin_page_overlay();
1339
+		//if metaboxes are present we need to add the nonce field
1340
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1341
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1342
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1343
+		}
1344
+	}
1345
+
1346
+
1347
+
1348
+	/**
1349
+	 * admin_footer_global
1350
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1351
+	 *
1352
+	 * @access  public
1353
+	 * @return  void
1354
+	 */
1355
+	public function admin_footer_global()
1356
+	{
1357
+		//dialog container for dialog helper
1358
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1359
+		$d_cont .= '<div class="ee-notices"></div>';
1360
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1361
+		$d_cont .= '</div>';
1362
+		echo $d_cont;
1363
+		//help tour stuff?
1364
+		if (isset($this->_help_tour[$this->_req_action])) {
1365
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1366
+		}
1367
+		//current set timezone for timezone js
1368
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1369
+	}
1370
+
1371
+
1372
+
1373
+	/**
1374
+	 * 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.
1375
+	 * For child classes:
1376
+	 * 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
1377
+	 * 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
1378
+	 * '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(
1379
+	 *    'help_trigger_id' => array(
1380
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1381
+	 *        'content' => __('localized content for popup', 'event_espresso')
1382
+	 *    )
1383
+	 * );
1384
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1385
+	 *
1386
+	 * @access protected
1387
+	 * @return string content
1388
+	 */
1389
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1390
+	{
1391
+		$content = '';
1392
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1393
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1394
+		//loop through the array and setup content
1395
+		foreach ($help_array as $trigger => $help) {
1396
+			//make sure the array is setup properly
1397
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1398
+				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',
1399
+						'event_espresso'));
1400
+			}
1401
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1402
+			$template_args = array(
1403
+					'help_popup_id'      => $trigger,
1404
+					'help_popup_title'   => $help['title'],
1405
+					'help_popup_content' => $help['content'],
1406
+			);
1407
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1408
+		}
1409
+		if ($display) {
1410
+			echo $content;
1411
+		} else {
1412
+			return $content;
1413
+		}
1414
+	}
1415
+
1416
+
1417
+
1418
+	/**
1419
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1420
+	 *
1421
+	 * @access private
1422
+	 * @return array properly formatted array for help popup content
1423
+	 */
1424
+	private function _get_help_content()
1425
+	{
1426
+		//what is the method we're looking for?
1427
+		$method_name = '_help_popup_content_' . $this->_req_action;
1428
+		//if method doesn't exist let's get out.
1429
+		if ( ! method_exists($this, $method_name)) {
1430
+			return array();
1431
+		}
1432
+		//k we're good to go let's retrieve the help array
1433
+		$help_array = call_user_func(array($this, $method_name));
1434
+		//make sure we've got an array!
1435
+		if ( ! is_array($help_array)) {
1436
+			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'));
1437
+		}
1438
+		return $help_array;
1439
+	}
1440
+
1441
+
1442
+
1443
+	/**
1444
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1445
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1446
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1447
+	 *
1448
+	 * @access protected
1449
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1450
+	 * @param boolean $display    if false then we return the trigger string
1451
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1452
+	 * @return string
1453
+	 */
1454
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1455
+	{
1456
+		if (defined('DOING_AJAX')) {
1457
+			return;
1458
+		}
1459
+		//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
1460
+		$help_array = $this->_get_help_content();
1461
+		$help_content = '';
1462
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1463
+			$help_array[$trigger_id] = array(
1464
+					'title'   => __('Missing Content', 'event_espresso'),
1465
+					'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.)',
1466
+							'event_espresso'),
1467
+			);
1468
+			$help_content = $this->_set_help_popup_content($help_array, false);
1469
+		}
1470
+		//let's setup the trigger
1471
+		$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>';
1472
+		$content = $content . $help_content;
1473
+		if ($display) {
1474
+			echo $content;
1475
+		} else {
1476
+			return $content;
1477
+		}
1478
+	}
1479
+
1480
+
1481
+
1482
+	/**
1483
+	 * _add_global_screen_options
1484
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1485
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1486
+	 *
1487
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1488
+	 *         see also WP_Screen object documents...
1489
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1490
+	 * @abstract
1491
+	 * @access private
1492
+	 * @return void
1493
+	 */
1494
+	private function _add_global_screen_options()
1495
+	{
1496
+	}
1497
+
1498
+
1499
+
1500
+	/**
1501
+	 * _add_global_feature_pointers
1502
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1503
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1504
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1505
+	 *
1506
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1507
+	 * @link   http://eamann.com/tech/wordpress-portland/
1508
+	 * @abstract
1509
+	 * @access protected
1510
+	 * @return void
1511
+	 */
1512
+	private function _add_global_feature_pointers()
1513
+	{
1514
+	}
1515
+
1516
+
1517
+
1518
+	/**
1519
+	 * load_global_scripts_styles
1520
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1521
+	 *
1522
+	 * @return void
1523
+	 */
1524
+	public function load_global_scripts_styles()
1525
+	{
1526
+		/** STYLES **/
1527
+		// add debugging styles
1528
+		if (WP_DEBUG) {
1529
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1530
+		}
1531
+		//register all styles
1532
+		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);
1533
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1534
+		//helpers styles
1535
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1536
+		//enqueue global styles
1537
+		wp_enqueue_style('ee-admin-css');
1538
+		/** SCRIPTS **/
1539
+		//register all scripts
1540
+		wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1541
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1542
+		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);
1543
+		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);
1544
+		// register jQuery Validate - see /includes/functions/wp_hooks.php
1545
+		add_filter('FHEE_load_jquery_validate', '__return_true');
1546
+		add_filter('FHEE_load_joyride', '__return_true');
1547
+		//script for sorting tables
1548
+		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);
1549
+		//script for parsing uri's
1550
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1551
+		//and parsing associative serialized form elements
1552
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1553
+		//helpers scripts
1554
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1555
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1556
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1557
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1558
+		//google charts
1559
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1560
+		//enqueue global scripts
1561
+		//taking care of metaboxes
1562
+		if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) {
1563
+			wp_enqueue_script('dashboard');
1564
+		}
1565
+		//enqueue thickbox for ee help popups.  default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups
1566
+		if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) {
1567
+			wp_enqueue_script('ee_admin_js');
1568
+			wp_enqueue_style('ee-admin-css');
1569
+		}
1570
+		//localize script for ajax lazy loading
1571
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1572
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1573
+		/**
1574
+		 * help tour stuff
1575
+		 */
1576
+		if ( ! empty($this->_help_tour)) {
1577
+			//register the js for kicking things off
1578
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1579
+			//setup tours for the js tour object
1580
+			foreach ($this->_help_tour['tours'] as $tour) {
1581
+				$tours[] = array(
1582
+						'id'      => $tour->get_slug(),
1583
+						'options' => $tour->get_options(),
1584
+				);
1585
+			}
1586
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1587
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1588
+		}
1589
+	}
1590
+
1591
+
1592
+
1593
+	/**
1594
+	 *        admin_footer_scripts_eei18n_js_strings
1595
+	 *
1596
+	 * @access        public
1597
+	 * @return        void
1598
+	 */
1599
+	public function admin_footer_scripts_eei18n_js_strings()
1600
+	{
1601
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1602
+		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');
1603
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1604
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1605
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1606
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1641
+		//setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1642
+		//admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1643
+		//espresso_core is listed as a dependency of ee_admin_js.
1644
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
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,1234 +2147,1234 @@  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 _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 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'] .= apply_filters(
2433
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2434
-                ! empty($this->_req_data['s'])
2435
-                        ? '<p class="ee-search-results">' . sprintf(
2436
-                                __('Displaying search results for the search string: <strong><em>%s</em></strong>', 'event_espresso'),
2437
-                                trim($this->_req_data['s'], '%')
2438
-                        ) . '</p>'
2439
-                        : '',
2440
-                $this->page_slug,
2441
-                $this->_req_data,
2442
-                $this->_req_action
2443
-        );
2444
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2445
-                $template_path,
2446
-                $this->_template_args,
2447
-                true
2448
-        );
2449
-        // the final template wrapper
2450
-        if ($sidebar) {
2451
-            $this->display_admin_page_with_sidebar();
2452
-        } else {
2453
-            $this->display_admin_page_with_no_sidebar();
2454
-        }
2455
-    }
2456
-
2457
-
2458
-
2459
-    /**
2460
-     * 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.
2461
-     * $items are expected in an array in the following format:
2462
-     * $legend_items = array(
2463
-     *        'item_id' => array(
2464
-     *            'icon' => 'http://url_to_icon_being_described.png',
2465
-     *            'desc' => __('localized description of item');
2466
-     *        )
2467
-     * );
2468
-     *
2469
-     * @param  array $items see above for format of array
2470
-     * @return string        html string of legend
2471
-     */
2472
-    protected function _display_legend($items)
2473
-    {
2474
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2475
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2476
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2477
-    }
2478
-
2479
-
2480
-
2481
-    /**
2482
-     * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2483
-     *
2484
-     * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2485
-     *                             The returned json object is created from an array in the following format:
2486
-     *                             array(
2487
-     *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2488
-     *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2489
-     *                             'notices' => '', // - contains any EE_Error formatted notices
2490
-     *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2491
-     *                             '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
2492
-     *                             specific template args that might be included in here)
2493
-     *                             )
2494
-     *                             The json object is populated by whatever is set in the $_template_args property.
2495
-     * @return void
2496
-     */
2497
-    protected function _return_json($sticky_notices = false)
2498
-    {
2499
-        //make sure any EE_Error notices have been handled.
2500
-        $this->_process_notices(array(), true, $sticky_notices);
2501
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2502
-        unset($this->_template_args['data']);
2503
-        $json = array(
2504
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2505
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2506
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2507
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2508
-                'notices'   => EE_Error::get_notices(),
2509
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2510
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2511
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2512
-        );
2513
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2514
-        if (null === error_get_last() || ! headers_sent()) {
2515
-            header('Content-Type: application/json; charset=UTF-8');
2516
-        }
2517
-        if (function_exists('wp_json_encode')) {
2518
-            echo wp_json_encode($json);
2519
-        } else {
2520
-            echo json_encode($json);
2521
-        }
2522
-        exit();
2523
-    }
2524
-
2525
-
2526
-
2527
-    /**
2528
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2529
-     *
2530
-     * @return void
2531
-     * @throws EE_Error
2532
-     */
2533
-    public function return_json()
2534
-    {
2535
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2536
-            $this->_return_json();
2537
-        } else {
2538
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2539
-        }
2540
-    }
2541
-
2542
-
2543
-
2544
-    /**
2545
-     * 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.
2546
-     *
2547
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2548
-     * @access   public
2549
-     */
2550
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2551
-    {
2552
-        $this->_hook_obj = $hook_obj;
2553
-    }
2554
-
2555
-
2556
-
2557
-    /**
2558
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2559
-     *
2560
-     * @access public
2561
-     * @param  boolean $about whether to use the special about page wrapper or default.
2562
-     * @return void
2563
-     */
2564
-    public function admin_page_wrapper($about = false)
2565
-    {
2566
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2567
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2568
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2569
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2570
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2571
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2572
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2573
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2574
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2575
-        // load settings page wrapper template
2576
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2577
-        //about page?
2578
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2579
-        if (defined('DOING_AJAX')) {
2580
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2581
-            $this->_return_json();
2582
-        } else {
2583
-            EEH_Template::display_template($template_path, $this->_template_args);
2584
-        }
2585
-    }
2586
-
2587
-
2588
-
2589
-    /**
2590
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2591
-     *
2592
-     * @return string html
2593
-     */
2594
-    protected function _get_main_nav_tabs()
2595
-    {
2596
-        //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)
2597
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2598
-    }
2599
-
2600
-
2601
-
2602
-    /**
2603
-     *        sort nav tabs
2604
-     *
2605
-     * @access public
2606
-     * @param $a
2607
-     * @param $b
2608
-     * @return int
2609
-     */
2610
-    private function _sort_nav_tabs($a, $b)
2611
-    {
2612
-        if ($a['order'] == $b['order']) {
2613
-            return 0;
2614
-        }
2615
-        return ($a['order'] < $b['order']) ? -1 : 1;
2616
-    }
2617
-
2618
-
2619
-
2620
-    /**
2621
-     *    generates HTML for the forms used on admin pages
2622
-     *
2623
-     * @access protected
2624
-     * @param    array $input_vars - array of input field details
2625
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2626
-     * @return string
2627
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2628
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2629
-     */
2630
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2631
-    {
2632
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2633
-        return $content;
2634
-    }
2635
-
2636
-
2637
-
2638
-    /**
2639
-     * generates the "Save" and "Save & Close" buttons for edit forms
2640
-     *
2641
-     * @access protected
2642
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2643
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2644
-     * @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.
2645
-     * @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).
2646
-     */
2647
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2648
-    {
2649
-        //make sure $text and $actions are in an array
2650
-        $text = (array)$text;
2651
-        $actions = (array)$actions;
2652
-        $referrer_url = empty($referrer) ? '' : $referrer;
2653
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2654
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2655
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2656
-        $default_names = array('save', 'save_and_close');
2657
-        //add in a hidden index for the current page (so save and close redirects properly)
2658
-        $this->_template_args['save_buttons'] = $referrer_url;
2659
-        foreach ($button_text as $key => $button) {
2660
-            $ref = $default_names[$key];
2661
-            $id = $this->_current_view . '_' . $ref;
2662
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2663
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2664
-            if ( ! $both) {
2665
-                break;
2666
-            }
2667
-        }
2668
-    }
2669
-
2670
-
2671
-
2672
-    /**
2673
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2674
-     *
2675
-     * @see   $this->_set_add_edit_form_tags() for details on params
2676
-     * @since 4.6.0
2677
-     * @param string $route
2678
-     * @param array  $additional_hidden_fields
2679
-     */
2680
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2681
-    {
2682
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2683
-    }
2684
-
2685
-
2686
-
2687
-    /**
2688
-     * set form open and close tags on add/edit pages.
2689
-     *
2690
-     * @access protected
2691
-     * @param string $route                    the route you want the form to direct to
2692
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2693
-     * @return void
2694
-     */
2695
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2696
-    {
2697
-        if (empty($route)) {
2698
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2699
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2700
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2701
-        }
2702
-        // open form
2703
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2704
-        // add nonce
2705
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2706
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2707
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2708
-        // add REQUIRED form action
2709
-        $hidden_fields = array(
2710
-                'action' => array('type' => 'hidden', 'value' => $route),
2711
-        );
2712
-        // merge arrays
2713
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2714
-        // generate form fields
2715
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2716
-        // add fields to form
2717
-        foreach ((array)$form_fields as $field_name => $form_field) {
2718
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2719
-        }
2720
-        // close form
2721
-        $this->_template_args['after_admin_page_content'] = '</form>';
2722
-    }
2723
-
2724
-
2725
-
2726
-    /**
2727
-     * Public Wrapper for _redirect_after_action() method since its
2728
-     * discovered it would be useful for external code to have access.
2729
-     *
2730
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2731
-     * @since 4.5.0
2732
-     */
2733
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2734
-    {
2735
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2736
-    }
2737
-
2738
-
2739
-
2740
-    /**
2741
-     *    _redirect_after_action
2742
-     *
2743
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2744
-     * @param string $what               - what the action was performed on
2745
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2746
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2747
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2748
-     * @access protected
2749
-     * @return void
2750
-     */
2751
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2752
-    {
2753
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2754
-        //class name for actions/filters.
2755
-        $classname = get_class($this);
2756
-        //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
2757
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2758
-        $notices = EE_Error::get_notices(false);
2759
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2760
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2761
-            EE_Error::overwrite_success();
2762
-        }
2763
-        if ( ! empty($what) && ! empty($action_desc)) {
2764
-            // how many records affected ? more than one record ? or just one ?
2765
-            if ($success > 1 && empty($notices['errors'])) {
2766
-                // set plural msg
2767
-                EE_Error::add_success(
2768
-                        sprintf(
2769
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2770
-                                $what,
2771
-                                $action_desc
2772
-                        ),
2773
-                        __FILE__, __FUNCTION__, __LINE__
2774
-                );
2775
-            } else if ($success == 1 && empty($notices['errors'])) {
2776
-                // set singular msg
2777
-                EE_Error::add_success(
2778
-                        sprintf(
2779
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2780
-                                $what,
2781
-                                $action_desc
2782
-                        ),
2783
-                        __FILE__, __FUNCTION__, __LINE__
2784
-                );
2785
-            }
2786
-        }
2787
-        // check that $query_args isn't something crazy
2788
-        if ( ! is_array($query_args)) {
2789
-            $query_args = array();
2790
-        }
2791
-        /**
2792
-         * Allow injecting actions before the query_args are modified for possible different
2793
-         * redirections on save and close actions
2794
-         *
2795
-         * @since 4.2.0
2796
-         * @param array $query_args       The original query_args array coming into the
2797
-         *                                method.
2798
-         */
2799
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2800
-        //calculate where we're going (if we have a "save and close" button pushed)
2801
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2802
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2803
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2804
-            // regenerate query args array from referrer URL
2805
-            parse_str($parsed_url['query'], $query_args);
2806
-            // correct page and action will be in the query args now
2807
-            $redirect_url = admin_url('admin.php');
2808
-        }
2809
-        //merge any default query_args set in _default_route_query_args property
2810
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2811
-            $args_to_merge = array();
2812
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2813
-                //is there a wp_referer array in our _default_route_query_args property?
2814
-                if ($query_param == 'wp_referer') {
2815
-                    $query_value = (array)$query_value;
2816
-                    foreach ($query_value as $reference => $value) {
2817
-                        if (strpos($reference, 'nonce') !== false) {
2818
-                            continue;
2819
-                        }
2820
-                        //finally we will override any arguments in the referer with
2821
-                        //what might be set on the _default_route_query_args array.
2822
-                        if (isset($this->_default_route_query_args[$reference])) {
2823
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2824
-                        } else {
2825
-                            $args_to_merge[$reference] = urlencode($value);
2826
-                        }
2827
-                    }
2828
-                    continue;
2829
-                }
2830
-                $args_to_merge[$query_param] = $query_value;
2831
-            }
2832
-            //now let's merge these arguments but override with what was specifically sent in to the
2833
-            //redirect.
2834
-            $query_args = array_merge($args_to_merge, $query_args);
2835
-        }
2836
-        $this->_process_notices($query_args);
2837
-        // generate redirect url
2838
-        // if redirecting to anything other than the main page, add a nonce
2839
-        if (isset($query_args['action'])) {
2840
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2841
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2842
-        }
2843
-        //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).
2844
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2845
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2846
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2847
-        if (defined('DOING_AJAX')) {
2848
-            $default_data = array(
2849
-                    'close'        => true,
2850
-                    'redirect_url' => $redirect_url,
2851
-                    'where'        => 'main',
2852
-                    'what'         => 'append',
2853
-            );
2854
-            $this->_template_args['success'] = $success;
2855
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2856
-            $this->_return_json();
2857
-        }
2858
-        wp_safe_redirect($redirect_url);
2859
-        exit();
2860
-    }
2861
-
2862
-
2863
-
2864
-    /**
2865
-     * process any notices before redirecting (or returning ajax request)
2866
-     * This method sets the $this->_template_args['notices'] attribute;
2867
-     *
2868
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2869
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2870
-     * @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.
2871
-     * @return void
2872
-     */
2873
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2874
-    {
2875
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2876
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2877
-            $notices = EE_Error::get_notices(false);
2878
-            if (empty($this->_template_args['success'])) {
2879
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2880
-            }
2881
-            if (empty($this->_template_args['errors'])) {
2882
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2883
-            }
2884
-            if (empty($this->_template_args['attention'])) {
2885
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2886
-            }
2887
-        }
2888
-        $this->_template_args['notices'] = EE_Error::get_notices();
2889
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2890
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2891
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2892
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2893
-        }
2894
-    }
2895
-
2896
-
2897
-
2898
-    /**
2899
-     * get_action_link_or_button
2900
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2901
-     *
2902
-     * @param string $action        use this to indicate which action the url is generated with.
2903
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2904
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2905
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2906
-     * @param string $base_url      If this is not provided
2907
-     *                              the _admin_base_url will be used as the default for the button base_url.
2908
-     *                              Otherwise this value will be used.
2909
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2910
-     * @return string
2911
-     * @throws \EE_Error
2912
-     */
2913
-    public function get_action_link_or_button(
2914
-            $action,
2915
-            $type = 'add',
2916
-            $extra_request = array(),
2917
-            $class = 'button-primary',
2918
-            $base_url = '',
2919
-            $exclude_nonce = false
2920
-    ) {
2921
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2922
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2923
-            throw new EE_Error(
2924
-                    sprintf(
2925
-                            __(
2926
-                                    'There is no page route for given action for the button.  This action was given: %s',
2927
-                                    'event_espresso'
2928
-                            ),
2929
-                            $action
2930
-                    )
2931
-            );
2932
-        }
2933
-        if ( ! isset($this->_labels['buttons'][$type])) {
2934
-            throw new EE_Error(
2935
-                    sprintf(
2936
-                            __(
2937
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2938
-                                    'event_espresso'
2939
-                            ),
2940
-                            $type
2941
-                    )
2942
-            );
2943
-        }
2944
-        //finally check user access for this button.
2945
-        $has_access = $this->check_user_access($action, true);
2946
-        if ( ! $has_access) {
2947
-            return '';
2948
-        }
2949
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2950
-        $query_args = array(
2951
-                'action' => $action,
2952
-        );
2953
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2954
-        if ( ! empty($extra_request)) {
2955
-            $query_args = array_merge($extra_request, $query_args);
2956
-        }
2957
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2958
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2959
-    }
2960
-
2961
-
2962
-
2963
-    /**
2964
-     * _per_page_screen_option
2965
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2966
-     *
2967
-     * @return void
2968
-     */
2969
-    protected function _per_page_screen_option()
2970
-    {
2971
-        $option = 'per_page';
2972
-        $args = array(
2973
-                'label'   => $this->_admin_page_title,
2974
-                'default' => 10,
2975
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
2976
-        );
2977
-        //ONLY add the screen option if the user has access to it.
2978
-        if ($this->check_user_access($this->_current_view, true)) {
2979
-            add_screen_option($option, $args);
2980
-        }
2981
-    }
2982
-
2983
-
2984
-
2985
-    /**
2986
-     * set_per_page_screen_option
2987
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
2988
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
2989
-     *
2990
-     * @access private
2991
-     * @return void
2992
-     */
2993
-    private function _set_per_page_screen_options()
2994
-    {
2995
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
2996
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
2997
-            if ( ! $user = wp_get_current_user()) {
2998
-                return;
2999
-            }
3000
-            $option = $_POST['wp_screen_options']['option'];
3001
-            $value = $_POST['wp_screen_options']['value'];
3002
-            if ($option != sanitize_key($option)) {
3003
-                return;
3004
-            }
3005
-            $map_option = $option;
3006
-            $option = str_replace('-', '_', $option);
3007
-            switch ($map_option) {
3008
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3009
-                    $value = (int)$value;
3010
-                    if ($value < 1 || $value > 999) {
3011
-                        return;
3012
-                    }
3013
-                    break;
3014
-                default:
3015
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3016
-                    if (false === $value) {
3017
-                        return;
3018
-                    }
3019
-                    break;
3020
-            }
3021
-            update_user_meta($user->ID, $option, $value);
3022
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3023
-            exit;
3024
-        }
3025
-    }
3026
-
3027
-
3028
-
3029
-    /**
3030
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3031
-     *
3032
-     * @param array $data array that will be assigned to template args.
3033
-     */
3034
-    public function set_template_args($data)
3035
-    {
3036
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3037
-    }
3038
-
3039
-
3040
-
3041
-    /**
3042
-     * This makes available the WP transient system for temporarily moving data between routes
3043
-     *
3044
-     * @access protected
3045
-     * @param string $route             the route that should receive the transient
3046
-     * @param array  $data              the data that gets sent
3047
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3048
-     * @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.
3049
-     * @return void
3050
-     */
3051
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3052
-    {
3053
-        $user_id = get_current_user_id();
3054
-        if ( ! $skip_route_verify) {
3055
-            $this->_verify_route($route);
3056
-        }
3057
-        //now let's set the string for what kind of transient we're setting
3058
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3059
-        $data = $notices ? array('notices' => $data) : $data;
3060
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3061
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3062
-        if ($existing) {
3063
-            $data = array_merge((array)$data, (array)$existing);
3064
-        }
3065
-        if (is_multisite() && is_network_admin()) {
3066
-            set_site_transient($transient, $data, 8);
3067
-        } else {
3068
-            set_transient($transient, $data, 8);
3069
-        }
3070
-    }
3071
-
3072
-
3073
-
3074
-    /**
3075
-     * this retrieves the temporary transient that has been set for moving data between routes.
3076
-     *
3077
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3078
-     * @return mixed data
3079
-     */
3080
-    protected function _get_transient($notices = false, $route = false)
3081
-    {
3082
-        $user_id = get_current_user_id();
3083
-        $route = ! $route ? $this->_req_action : $route;
3084
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3085
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3086
-        //delete transient after retrieval (just in case it hasn't expired);
3087
-        if (is_multisite() && is_network_admin()) {
3088
-            delete_site_transient($transient);
3089
-        } else {
3090
-            delete_transient($transient);
3091
-        }
3092
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3093
-    }
3094
-
3095
-
3096
-
3097
-    /**
3098
-     * 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.
3099
-     * 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.)
3100
-     *
3101
-     * @return void
3102
-     */
3103
-    protected function _transient_garbage_collection()
3104
-    {
3105
-        global $wpdb;
3106
-        //retrieve all existing transients
3107
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3108
-        if ($results = $wpdb->get_results($query)) {
3109
-            foreach ($results as $result) {
3110
-                $transient = str_replace('_transient_', '', $result->option_name);
3111
-                get_transient($transient);
3112
-                if (is_multisite() && is_network_admin()) {
3113
-                    get_site_transient($transient);
3114
-                }
3115
-            }
3116
-        }
3117
-    }
3118
-
3119
-
3120
-
3121
-    /**
3122
-     * get_view
3123
-     *
3124
-     * @access public
3125
-     * @return string content of _view property
3126
-     */
3127
-    public function get_view()
3128
-    {
3129
-        return $this->_view;
3130
-    }
3131
-
3132
-
3133
-
3134
-    /**
3135
-     * getter for the protected $_views property
3136
-     *
3137
-     * @return array
3138
-     */
3139
-    public function get_views()
3140
-    {
3141
-        return $this->_views;
3142
-    }
3143
-
3144
-
3145
-
3146
-    /**
3147
-     * get_current_page
3148
-     *
3149
-     * @access public
3150
-     * @return string _current_page property value
3151
-     */
3152
-    public function get_current_page()
3153
-    {
3154
-        return $this->_current_page;
3155
-    }
3156
-
3157
-
3158
-
3159
-    /**
3160
-     * get_current_view
3161
-     *
3162
-     * @access public
3163
-     * @return string _current_view property value
3164
-     */
3165
-    public function get_current_view()
3166
-    {
3167
-        return $this->_current_view;
3168
-    }
3169
-
3170
-
3171
-
3172
-    /**
3173
-     * get_current_screen
3174
-     *
3175
-     * @access public
3176
-     * @return object The current WP_Screen object
3177
-     */
3178
-    public function get_current_screen()
3179
-    {
3180
-        return $this->_current_screen;
3181
-    }
3182
-
3183
-
3184
-
3185
-    /**
3186
-     * get_current_page_view_url
3187
-     *
3188
-     * @access public
3189
-     * @return string This returns the url for the current_page_view.
3190
-     */
3191
-    public function get_current_page_view_url()
3192
-    {
3193
-        return $this->_current_page_view_url;
3194
-    }
3195
-
3196
-
3197
-
3198
-    /**
3199
-     * just returns the _req_data property
3200
-     *
3201
-     * @return array
3202
-     */
3203
-    public function get_request_data()
3204
-    {
3205
-        return $this->_req_data;
3206
-    }
3207
-
3208
-
3209
-
3210
-    /**
3211
-     * returns the _req_data protected property
3212
-     *
3213
-     * @return string
3214
-     */
3215
-    public function get_req_action()
3216
-    {
3217
-        return $this->_req_action;
3218
-    }
3219
-
3220
-
3221
-
3222
-    /**
3223
-     * @return bool  value of $_is_caf property
3224
-     */
3225
-    public function is_caf()
3226
-    {
3227
-        return $this->_is_caf;
3228
-    }
3229
-
3230
-
3231
-
3232
-    /**
3233
-     * @return mixed
3234
-     */
3235
-    public function default_espresso_metaboxes()
3236
-    {
3237
-        return $this->_default_espresso_metaboxes;
3238
-    }
3239
-
3240
-
3241
-
3242
-    /**
3243
-     * @return mixed
3244
-     */
3245
-    public function admin_base_url()
3246
-    {
3247
-        return $this->_admin_base_url;
3248
-    }
3249
-
3250
-
3251
-
3252
-    /**
3253
-     * @return mixed
3254
-     */
3255
-    public function wp_page_slug()
3256
-    {
3257
-        return $this->_wp_page_slug;
3258
-    }
3259
-
3260
-
3261
-
3262
-    /**
3263
-     * updates  espresso configuration settings
3264
-     *
3265
-     * @access    protected
3266
-     * @param string                   $tab
3267
-     * @param EE_Config_Base|EE_Config $config
3268
-     * @param string                   $file file where error occurred
3269
-     * @param string                   $func function  where error occurred
3270
-     * @param string                   $line line no where error occurred
3271
-     * @return boolean
3272
-     */
3273
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3274
-    {
3275
-        //remove any options that are NOT going to be saved with the config settings.
3276
-        if (isset($config->core->ee_ueip_optin)) {
3277
-            $config->core->ee_ueip_has_notified = true;
3278
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3279
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3280
-            update_option('ee_ueip_has_notified', true);
3281
-        }
3282
-        // and save it (note we're also doing the network save here)
3283
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3284
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3285
-        if ($config_saved && $net_saved) {
3286
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3287
-            return true;
3288
-        } else {
3289
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3290
-            return false;
3291
-        }
3292
-    }
3293
-
3294
-
3295
-
3296
-    /**
3297
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3298
-     *
3299
-     * @return array
3300
-     */
3301
-    public function get_yes_no_values()
3302
-    {
3303
-        return $this->_yes_no_values;
3304
-    }
3305
-
3306
-
3307
-
3308
-    protected function _get_dir()
3309
-    {
3310
-        $reflector = new ReflectionClass(get_class($this));
3311
-        return dirname($reflector->getFileName());
3312
-    }
3313
-
3314
-
3315
-
3316
-    /**
3317
-     * A helper for getting a "next link".
3318
-     *
3319
-     * @param string $url   The url to link to
3320
-     * @param string $class The class to use.
3321
-     * @return string
3322
-     */
3323
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3324
-    {
3325
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3326
-    }
3327
-
3328
-
3329
-
3330
-    /**
3331
-     * A helper for getting a "previous link".
3332
-     *
3333
-     * @param string $url   The url to link to
3334
-     * @param string $class The class to use.
3335
-     * @return string
3336
-     */
3337
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3338
-    {
3339
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3340
-    }
3341
-
3342
-
3343
-
3344
-
3345
-
3346
-
3347
-
3348
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3349
-    /**
3350
-     * 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
3351
-     * array.
3352
-     *
3353
-     * @return bool success/fail
3354
-     */
3355
-    protected function _process_resend_registration()
3356
-    {
3357
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3358
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3359
-        return $this->_template_args['success'];
3360
-    }
3361
-
3362
-
3363
-
3364
-    /**
3365
-     * This automatically processes any payment message notifications when manual payment has been applied.
3366
-     *
3367
-     * @access protected
3368
-     * @param \EE_Payment $payment
3369
-     * @return bool success/fail
3370
-     */
3371
-    protected function _process_payment_notification(EE_Payment $payment)
3372
-    {
3373
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3374
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3375
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3376
-        return $this->_template_args['success'];
3377
-    }
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 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'] .= apply_filters(
2433
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2434
+				! empty($this->_req_data['s'])
2435
+						? '<p class="ee-search-results">' . sprintf(
2436
+								__('Displaying search results for the search string: <strong><em>%s</em></strong>', 'event_espresso'),
2437
+								trim($this->_req_data['s'], '%')
2438
+						) . '</p>'
2439
+						: '',
2440
+				$this->page_slug,
2441
+				$this->_req_data,
2442
+				$this->_req_action
2443
+		);
2444
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2445
+				$template_path,
2446
+				$this->_template_args,
2447
+				true
2448
+		);
2449
+		// the final template wrapper
2450
+		if ($sidebar) {
2451
+			$this->display_admin_page_with_sidebar();
2452
+		} else {
2453
+			$this->display_admin_page_with_no_sidebar();
2454
+		}
2455
+	}
2456
+
2457
+
2458
+
2459
+	/**
2460
+	 * 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.
2461
+	 * $items are expected in an array in the following format:
2462
+	 * $legend_items = array(
2463
+	 *        'item_id' => array(
2464
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2465
+	 *            'desc' => __('localized description of item');
2466
+	 *        )
2467
+	 * );
2468
+	 *
2469
+	 * @param  array $items see above for format of array
2470
+	 * @return string        html string of legend
2471
+	 */
2472
+	protected function _display_legend($items)
2473
+	{
2474
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2475
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2476
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2477
+	}
2478
+
2479
+
2480
+
2481
+	/**
2482
+	 * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2483
+	 *
2484
+	 * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2485
+	 *                             The returned json object is created from an array in the following format:
2486
+	 *                             array(
2487
+	 *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2488
+	 *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2489
+	 *                             'notices' => '', // - contains any EE_Error formatted notices
2490
+	 *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2491
+	 *                             '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
2492
+	 *                             specific template args that might be included in here)
2493
+	 *                             )
2494
+	 *                             The json object is populated by whatever is set in the $_template_args property.
2495
+	 * @return void
2496
+	 */
2497
+	protected function _return_json($sticky_notices = false)
2498
+	{
2499
+		//make sure any EE_Error notices have been handled.
2500
+		$this->_process_notices(array(), true, $sticky_notices);
2501
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2502
+		unset($this->_template_args['data']);
2503
+		$json = array(
2504
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2505
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2506
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2507
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2508
+				'notices'   => EE_Error::get_notices(),
2509
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2510
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2511
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2512
+		);
2513
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2514
+		if (null === error_get_last() || ! headers_sent()) {
2515
+			header('Content-Type: application/json; charset=UTF-8');
2516
+		}
2517
+		if (function_exists('wp_json_encode')) {
2518
+			echo wp_json_encode($json);
2519
+		} else {
2520
+			echo json_encode($json);
2521
+		}
2522
+		exit();
2523
+	}
2524
+
2525
+
2526
+
2527
+	/**
2528
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2529
+	 *
2530
+	 * @return void
2531
+	 * @throws EE_Error
2532
+	 */
2533
+	public function return_json()
2534
+	{
2535
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2536
+			$this->_return_json();
2537
+		} else {
2538
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2539
+		}
2540
+	}
2541
+
2542
+
2543
+
2544
+	/**
2545
+	 * 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.
2546
+	 *
2547
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2548
+	 * @access   public
2549
+	 */
2550
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2551
+	{
2552
+		$this->_hook_obj = $hook_obj;
2553
+	}
2554
+
2555
+
2556
+
2557
+	/**
2558
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2559
+	 *
2560
+	 * @access public
2561
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2562
+	 * @return void
2563
+	 */
2564
+	public function admin_page_wrapper($about = false)
2565
+	{
2566
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2567
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2568
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2569
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2570
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2571
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2572
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2573
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2574
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2575
+		// load settings page wrapper template
2576
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2577
+		//about page?
2578
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2579
+		if (defined('DOING_AJAX')) {
2580
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2581
+			$this->_return_json();
2582
+		} else {
2583
+			EEH_Template::display_template($template_path, $this->_template_args);
2584
+		}
2585
+	}
2586
+
2587
+
2588
+
2589
+	/**
2590
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2591
+	 *
2592
+	 * @return string html
2593
+	 */
2594
+	protected function _get_main_nav_tabs()
2595
+	{
2596
+		//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)
2597
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2598
+	}
2599
+
2600
+
2601
+
2602
+	/**
2603
+	 *        sort nav tabs
2604
+	 *
2605
+	 * @access public
2606
+	 * @param $a
2607
+	 * @param $b
2608
+	 * @return int
2609
+	 */
2610
+	private function _sort_nav_tabs($a, $b)
2611
+	{
2612
+		if ($a['order'] == $b['order']) {
2613
+			return 0;
2614
+		}
2615
+		return ($a['order'] < $b['order']) ? -1 : 1;
2616
+	}
2617
+
2618
+
2619
+
2620
+	/**
2621
+	 *    generates HTML for the forms used on admin pages
2622
+	 *
2623
+	 * @access protected
2624
+	 * @param    array $input_vars - array of input field details
2625
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2626
+	 * @return string
2627
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2628
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2629
+	 */
2630
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2631
+	{
2632
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2633
+		return $content;
2634
+	}
2635
+
2636
+
2637
+
2638
+	/**
2639
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2640
+	 *
2641
+	 * @access protected
2642
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2643
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2644
+	 * @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.
2645
+	 * @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).
2646
+	 */
2647
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2648
+	{
2649
+		//make sure $text and $actions are in an array
2650
+		$text = (array)$text;
2651
+		$actions = (array)$actions;
2652
+		$referrer_url = empty($referrer) ? '' : $referrer;
2653
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2654
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2655
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2656
+		$default_names = array('save', 'save_and_close');
2657
+		//add in a hidden index for the current page (so save and close redirects properly)
2658
+		$this->_template_args['save_buttons'] = $referrer_url;
2659
+		foreach ($button_text as $key => $button) {
2660
+			$ref = $default_names[$key];
2661
+			$id = $this->_current_view . '_' . $ref;
2662
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2663
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2664
+			if ( ! $both) {
2665
+				break;
2666
+			}
2667
+		}
2668
+	}
2669
+
2670
+
2671
+
2672
+	/**
2673
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2674
+	 *
2675
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2676
+	 * @since 4.6.0
2677
+	 * @param string $route
2678
+	 * @param array  $additional_hidden_fields
2679
+	 */
2680
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2681
+	{
2682
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2683
+	}
2684
+
2685
+
2686
+
2687
+	/**
2688
+	 * set form open and close tags on add/edit pages.
2689
+	 *
2690
+	 * @access protected
2691
+	 * @param string $route                    the route you want the form to direct to
2692
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2693
+	 * @return void
2694
+	 */
2695
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2696
+	{
2697
+		if (empty($route)) {
2698
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2699
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2700
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2701
+		}
2702
+		// open form
2703
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2704
+		// add nonce
2705
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2706
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2707
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2708
+		// add REQUIRED form action
2709
+		$hidden_fields = array(
2710
+				'action' => array('type' => 'hidden', 'value' => $route),
2711
+		);
2712
+		// merge arrays
2713
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2714
+		// generate form fields
2715
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2716
+		// add fields to form
2717
+		foreach ((array)$form_fields as $field_name => $form_field) {
2718
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2719
+		}
2720
+		// close form
2721
+		$this->_template_args['after_admin_page_content'] = '</form>';
2722
+	}
2723
+
2724
+
2725
+
2726
+	/**
2727
+	 * Public Wrapper for _redirect_after_action() method since its
2728
+	 * discovered it would be useful for external code to have access.
2729
+	 *
2730
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2731
+	 * @since 4.5.0
2732
+	 */
2733
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2734
+	{
2735
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2736
+	}
2737
+
2738
+
2739
+
2740
+	/**
2741
+	 *    _redirect_after_action
2742
+	 *
2743
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2744
+	 * @param string $what               - what the action was performed on
2745
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2746
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2747
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2748
+	 * @access protected
2749
+	 * @return void
2750
+	 */
2751
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2752
+	{
2753
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2754
+		//class name for actions/filters.
2755
+		$classname = get_class($this);
2756
+		//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
2757
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2758
+		$notices = EE_Error::get_notices(false);
2759
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2760
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2761
+			EE_Error::overwrite_success();
2762
+		}
2763
+		if ( ! empty($what) && ! empty($action_desc)) {
2764
+			// how many records affected ? more than one record ? or just one ?
2765
+			if ($success > 1 && empty($notices['errors'])) {
2766
+				// set plural msg
2767
+				EE_Error::add_success(
2768
+						sprintf(
2769
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2770
+								$what,
2771
+								$action_desc
2772
+						),
2773
+						__FILE__, __FUNCTION__, __LINE__
2774
+				);
2775
+			} else if ($success == 1 && empty($notices['errors'])) {
2776
+				// set singular msg
2777
+				EE_Error::add_success(
2778
+						sprintf(
2779
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2780
+								$what,
2781
+								$action_desc
2782
+						),
2783
+						__FILE__, __FUNCTION__, __LINE__
2784
+				);
2785
+			}
2786
+		}
2787
+		// check that $query_args isn't something crazy
2788
+		if ( ! is_array($query_args)) {
2789
+			$query_args = array();
2790
+		}
2791
+		/**
2792
+		 * Allow injecting actions before the query_args are modified for possible different
2793
+		 * redirections on save and close actions
2794
+		 *
2795
+		 * @since 4.2.0
2796
+		 * @param array $query_args       The original query_args array coming into the
2797
+		 *                                method.
2798
+		 */
2799
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2800
+		//calculate where we're going (if we have a "save and close" button pushed)
2801
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2802
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2803
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2804
+			// regenerate query args array from referrer URL
2805
+			parse_str($parsed_url['query'], $query_args);
2806
+			// correct page and action will be in the query args now
2807
+			$redirect_url = admin_url('admin.php');
2808
+		}
2809
+		//merge any default query_args set in _default_route_query_args property
2810
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2811
+			$args_to_merge = array();
2812
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2813
+				//is there a wp_referer array in our _default_route_query_args property?
2814
+				if ($query_param == 'wp_referer') {
2815
+					$query_value = (array)$query_value;
2816
+					foreach ($query_value as $reference => $value) {
2817
+						if (strpos($reference, 'nonce') !== false) {
2818
+							continue;
2819
+						}
2820
+						//finally we will override any arguments in the referer with
2821
+						//what might be set on the _default_route_query_args array.
2822
+						if (isset($this->_default_route_query_args[$reference])) {
2823
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2824
+						} else {
2825
+							$args_to_merge[$reference] = urlencode($value);
2826
+						}
2827
+					}
2828
+					continue;
2829
+				}
2830
+				$args_to_merge[$query_param] = $query_value;
2831
+			}
2832
+			//now let's merge these arguments but override with what was specifically sent in to the
2833
+			//redirect.
2834
+			$query_args = array_merge($args_to_merge, $query_args);
2835
+		}
2836
+		$this->_process_notices($query_args);
2837
+		// generate redirect url
2838
+		// if redirecting to anything other than the main page, add a nonce
2839
+		if (isset($query_args['action'])) {
2840
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2841
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2842
+		}
2843
+		//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).
2844
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2845
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2846
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2847
+		if (defined('DOING_AJAX')) {
2848
+			$default_data = array(
2849
+					'close'        => true,
2850
+					'redirect_url' => $redirect_url,
2851
+					'where'        => 'main',
2852
+					'what'         => 'append',
2853
+			);
2854
+			$this->_template_args['success'] = $success;
2855
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2856
+			$this->_return_json();
2857
+		}
2858
+		wp_safe_redirect($redirect_url);
2859
+		exit();
2860
+	}
2861
+
2862
+
2863
+
2864
+	/**
2865
+	 * process any notices before redirecting (or returning ajax request)
2866
+	 * This method sets the $this->_template_args['notices'] attribute;
2867
+	 *
2868
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2869
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2870
+	 * @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.
2871
+	 * @return void
2872
+	 */
2873
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2874
+	{
2875
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2876
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2877
+			$notices = EE_Error::get_notices(false);
2878
+			if (empty($this->_template_args['success'])) {
2879
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2880
+			}
2881
+			if (empty($this->_template_args['errors'])) {
2882
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2883
+			}
2884
+			if (empty($this->_template_args['attention'])) {
2885
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2886
+			}
2887
+		}
2888
+		$this->_template_args['notices'] = EE_Error::get_notices();
2889
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2890
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2891
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2892
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2893
+		}
2894
+	}
2895
+
2896
+
2897
+
2898
+	/**
2899
+	 * get_action_link_or_button
2900
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2901
+	 *
2902
+	 * @param string $action        use this to indicate which action the url is generated with.
2903
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2904
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2905
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2906
+	 * @param string $base_url      If this is not provided
2907
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2908
+	 *                              Otherwise this value will be used.
2909
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2910
+	 * @return string
2911
+	 * @throws \EE_Error
2912
+	 */
2913
+	public function get_action_link_or_button(
2914
+			$action,
2915
+			$type = 'add',
2916
+			$extra_request = array(),
2917
+			$class = 'button-primary',
2918
+			$base_url = '',
2919
+			$exclude_nonce = false
2920
+	) {
2921
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2922
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2923
+			throw new EE_Error(
2924
+					sprintf(
2925
+							__(
2926
+									'There is no page route for given action for the button.  This action was given: %s',
2927
+									'event_espresso'
2928
+							),
2929
+							$action
2930
+					)
2931
+			);
2932
+		}
2933
+		if ( ! isset($this->_labels['buttons'][$type])) {
2934
+			throw new EE_Error(
2935
+					sprintf(
2936
+							__(
2937
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2938
+									'event_espresso'
2939
+							),
2940
+							$type
2941
+					)
2942
+			);
2943
+		}
2944
+		//finally check user access for this button.
2945
+		$has_access = $this->check_user_access($action, true);
2946
+		if ( ! $has_access) {
2947
+			return '';
2948
+		}
2949
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2950
+		$query_args = array(
2951
+				'action' => $action,
2952
+		);
2953
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2954
+		if ( ! empty($extra_request)) {
2955
+			$query_args = array_merge($extra_request, $query_args);
2956
+		}
2957
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2958
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2959
+	}
2960
+
2961
+
2962
+
2963
+	/**
2964
+	 * _per_page_screen_option
2965
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2966
+	 *
2967
+	 * @return void
2968
+	 */
2969
+	protected function _per_page_screen_option()
2970
+	{
2971
+		$option = 'per_page';
2972
+		$args = array(
2973
+				'label'   => $this->_admin_page_title,
2974
+				'default' => 10,
2975
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
2976
+		);
2977
+		//ONLY add the screen option if the user has access to it.
2978
+		if ($this->check_user_access($this->_current_view, true)) {
2979
+			add_screen_option($option, $args);
2980
+		}
2981
+	}
2982
+
2983
+
2984
+
2985
+	/**
2986
+	 * set_per_page_screen_option
2987
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
2988
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
2989
+	 *
2990
+	 * @access private
2991
+	 * @return void
2992
+	 */
2993
+	private function _set_per_page_screen_options()
2994
+	{
2995
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
2996
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
2997
+			if ( ! $user = wp_get_current_user()) {
2998
+				return;
2999
+			}
3000
+			$option = $_POST['wp_screen_options']['option'];
3001
+			$value = $_POST['wp_screen_options']['value'];
3002
+			if ($option != sanitize_key($option)) {
3003
+				return;
3004
+			}
3005
+			$map_option = $option;
3006
+			$option = str_replace('-', '_', $option);
3007
+			switch ($map_option) {
3008
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3009
+					$value = (int)$value;
3010
+					if ($value < 1 || $value > 999) {
3011
+						return;
3012
+					}
3013
+					break;
3014
+				default:
3015
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3016
+					if (false === $value) {
3017
+						return;
3018
+					}
3019
+					break;
3020
+			}
3021
+			update_user_meta($user->ID, $option, $value);
3022
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3023
+			exit;
3024
+		}
3025
+	}
3026
+
3027
+
3028
+
3029
+	/**
3030
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3031
+	 *
3032
+	 * @param array $data array that will be assigned to template args.
3033
+	 */
3034
+	public function set_template_args($data)
3035
+	{
3036
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3037
+	}
3038
+
3039
+
3040
+
3041
+	/**
3042
+	 * This makes available the WP transient system for temporarily moving data between routes
3043
+	 *
3044
+	 * @access protected
3045
+	 * @param string $route             the route that should receive the transient
3046
+	 * @param array  $data              the data that gets sent
3047
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3048
+	 * @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.
3049
+	 * @return void
3050
+	 */
3051
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3052
+	{
3053
+		$user_id = get_current_user_id();
3054
+		if ( ! $skip_route_verify) {
3055
+			$this->_verify_route($route);
3056
+		}
3057
+		//now let's set the string for what kind of transient we're setting
3058
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3059
+		$data = $notices ? array('notices' => $data) : $data;
3060
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3061
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3062
+		if ($existing) {
3063
+			$data = array_merge((array)$data, (array)$existing);
3064
+		}
3065
+		if (is_multisite() && is_network_admin()) {
3066
+			set_site_transient($transient, $data, 8);
3067
+		} else {
3068
+			set_transient($transient, $data, 8);
3069
+		}
3070
+	}
3071
+
3072
+
3073
+
3074
+	/**
3075
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3076
+	 *
3077
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3078
+	 * @return mixed data
3079
+	 */
3080
+	protected function _get_transient($notices = false, $route = false)
3081
+	{
3082
+		$user_id = get_current_user_id();
3083
+		$route = ! $route ? $this->_req_action : $route;
3084
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3085
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3086
+		//delete transient after retrieval (just in case it hasn't expired);
3087
+		if (is_multisite() && is_network_admin()) {
3088
+			delete_site_transient($transient);
3089
+		} else {
3090
+			delete_transient($transient);
3091
+		}
3092
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3093
+	}
3094
+
3095
+
3096
+
3097
+	/**
3098
+	 * 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.
3099
+	 * 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.)
3100
+	 *
3101
+	 * @return void
3102
+	 */
3103
+	protected function _transient_garbage_collection()
3104
+	{
3105
+		global $wpdb;
3106
+		//retrieve all existing transients
3107
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3108
+		if ($results = $wpdb->get_results($query)) {
3109
+			foreach ($results as $result) {
3110
+				$transient = str_replace('_transient_', '', $result->option_name);
3111
+				get_transient($transient);
3112
+				if (is_multisite() && is_network_admin()) {
3113
+					get_site_transient($transient);
3114
+				}
3115
+			}
3116
+		}
3117
+	}
3118
+
3119
+
3120
+
3121
+	/**
3122
+	 * get_view
3123
+	 *
3124
+	 * @access public
3125
+	 * @return string content of _view property
3126
+	 */
3127
+	public function get_view()
3128
+	{
3129
+		return $this->_view;
3130
+	}
3131
+
3132
+
3133
+
3134
+	/**
3135
+	 * getter for the protected $_views property
3136
+	 *
3137
+	 * @return array
3138
+	 */
3139
+	public function get_views()
3140
+	{
3141
+		return $this->_views;
3142
+	}
3143
+
3144
+
3145
+
3146
+	/**
3147
+	 * get_current_page
3148
+	 *
3149
+	 * @access public
3150
+	 * @return string _current_page property value
3151
+	 */
3152
+	public function get_current_page()
3153
+	{
3154
+		return $this->_current_page;
3155
+	}
3156
+
3157
+
3158
+
3159
+	/**
3160
+	 * get_current_view
3161
+	 *
3162
+	 * @access public
3163
+	 * @return string _current_view property value
3164
+	 */
3165
+	public function get_current_view()
3166
+	{
3167
+		return $this->_current_view;
3168
+	}
3169
+
3170
+
3171
+
3172
+	/**
3173
+	 * get_current_screen
3174
+	 *
3175
+	 * @access public
3176
+	 * @return object The current WP_Screen object
3177
+	 */
3178
+	public function get_current_screen()
3179
+	{
3180
+		return $this->_current_screen;
3181
+	}
3182
+
3183
+
3184
+
3185
+	/**
3186
+	 * get_current_page_view_url
3187
+	 *
3188
+	 * @access public
3189
+	 * @return string This returns the url for the current_page_view.
3190
+	 */
3191
+	public function get_current_page_view_url()
3192
+	{
3193
+		return $this->_current_page_view_url;
3194
+	}
3195
+
3196
+
3197
+
3198
+	/**
3199
+	 * just returns the _req_data property
3200
+	 *
3201
+	 * @return array
3202
+	 */
3203
+	public function get_request_data()
3204
+	{
3205
+		return $this->_req_data;
3206
+	}
3207
+
3208
+
3209
+
3210
+	/**
3211
+	 * returns the _req_data protected property
3212
+	 *
3213
+	 * @return string
3214
+	 */
3215
+	public function get_req_action()
3216
+	{
3217
+		return $this->_req_action;
3218
+	}
3219
+
3220
+
3221
+
3222
+	/**
3223
+	 * @return bool  value of $_is_caf property
3224
+	 */
3225
+	public function is_caf()
3226
+	{
3227
+		return $this->_is_caf;
3228
+	}
3229
+
3230
+
3231
+
3232
+	/**
3233
+	 * @return mixed
3234
+	 */
3235
+	public function default_espresso_metaboxes()
3236
+	{
3237
+		return $this->_default_espresso_metaboxes;
3238
+	}
3239
+
3240
+
3241
+
3242
+	/**
3243
+	 * @return mixed
3244
+	 */
3245
+	public function admin_base_url()
3246
+	{
3247
+		return $this->_admin_base_url;
3248
+	}
3249
+
3250
+
3251
+
3252
+	/**
3253
+	 * @return mixed
3254
+	 */
3255
+	public function wp_page_slug()
3256
+	{
3257
+		return $this->_wp_page_slug;
3258
+	}
3259
+
3260
+
3261
+
3262
+	/**
3263
+	 * updates  espresso configuration settings
3264
+	 *
3265
+	 * @access    protected
3266
+	 * @param string                   $tab
3267
+	 * @param EE_Config_Base|EE_Config $config
3268
+	 * @param string                   $file file where error occurred
3269
+	 * @param string                   $func function  where error occurred
3270
+	 * @param string                   $line line no where error occurred
3271
+	 * @return boolean
3272
+	 */
3273
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3274
+	{
3275
+		//remove any options that are NOT going to be saved with the config settings.
3276
+		if (isset($config->core->ee_ueip_optin)) {
3277
+			$config->core->ee_ueip_has_notified = true;
3278
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3279
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3280
+			update_option('ee_ueip_has_notified', true);
3281
+		}
3282
+		// and save it (note we're also doing the network save here)
3283
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3284
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3285
+		if ($config_saved && $net_saved) {
3286
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3287
+			return true;
3288
+		} else {
3289
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3290
+			return false;
3291
+		}
3292
+	}
3293
+
3294
+
3295
+
3296
+	/**
3297
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3298
+	 *
3299
+	 * @return array
3300
+	 */
3301
+	public function get_yes_no_values()
3302
+	{
3303
+		return $this->_yes_no_values;
3304
+	}
3305
+
3306
+
3307
+
3308
+	protected function _get_dir()
3309
+	{
3310
+		$reflector = new ReflectionClass(get_class($this));
3311
+		return dirname($reflector->getFileName());
3312
+	}
3313
+
3314
+
3315
+
3316
+	/**
3317
+	 * A helper for getting a "next link".
3318
+	 *
3319
+	 * @param string $url   The url to link to
3320
+	 * @param string $class The class to use.
3321
+	 * @return string
3322
+	 */
3323
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3324
+	{
3325
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3326
+	}
3327
+
3328
+
3329
+
3330
+	/**
3331
+	 * A helper for getting a "previous link".
3332
+	 *
3333
+	 * @param string $url   The url to link to
3334
+	 * @param string $class The class to use.
3335
+	 * @return string
3336
+	 */
3337
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3338
+	{
3339
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3340
+	}
3341
+
3342
+
3343
+
3344
+
3345
+
3346
+
3347
+
3348
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3349
+	/**
3350
+	 * 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
3351
+	 * array.
3352
+	 *
3353
+	 * @return bool success/fail
3354
+	 */
3355
+	protected function _process_resend_registration()
3356
+	{
3357
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3358
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3359
+		return $this->_template_args['success'];
3360
+	}
3361
+
3362
+
3363
+
3364
+	/**
3365
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3366
+	 *
3367
+	 * @access protected
3368
+	 * @param \EE_Payment $payment
3369
+	 * @return bool success/fail
3370
+	 */
3371
+	protected function _process_payment_notification(EE_Payment $payment)
3372
+	{
3373
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3374
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3375
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3376
+		return $this->_template_args['success'];
3377
+	}
3378 3378
 
3379 3379
 
3380 3380
 }
Please login to merge, or discard this patch.
Spacing   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
         $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
474 474
         $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
475 475
         global $ee_menu_slugs;
476
-        $ee_menu_slugs = (array)$ee_menu_slugs;
476
+        $ee_menu_slugs = (array) $ee_menu_slugs;
477 477
         if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
478 478
             return false;
479 479
         }
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
489 489
         $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
490 490
         $this->_current_view = $this->_req_action;
491
-        $this->_req_nonce = $this->_req_action . '_nonce';
491
+        $this->_req_nonce = $this->_req_action.'_nonce';
492 492
         $this->_define_page_props();
493 493
         $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
494 494
         //default things
@@ -509,11 +509,11 @@  discard block
 block discarded – undo
509 509
             $this->_extend_page_config_for_cpt();
510 510
         }
511 511
         //filter routes and page_config so addons can add their stuff. Filtering done per class
512
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
513
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
512
+        $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this);
513
+        $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this);
514 514
         //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
515
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
516
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
515
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
516
+            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2);
517 517
         }
518 518
         //next route only if routing enabled
519 519
         if ($this->_routing && ! defined('DOING_AJAX')) {
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
             if ($this->_is_UI_request) {
524 524
                 //admin_init stuff - global, all views for this page class, specific view
525 525
                 add_action('admin_init', array($this, 'admin_init'), 10);
526
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
527
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
526
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
527
+                    add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15);
528 528
                 }
529 529
             } else {
530 530
                 //hijack regular WP loading and route admin request immediately
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
      */
545 545
     private function _do_other_page_hooks()
546 546
     {
547
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
547
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array());
548 548
         foreach ($registered_pages as $page) {
549 549
             //now let's setup the file name and class that should be present
550 550
             $classname = str_replace('.class.php', '', $page);
@@ -590,13 +590,13 @@  discard block
 block discarded – undo
590 590
         //load admin_notices - global, page class, and view specific
591 591
         add_action('admin_notices', array($this, 'admin_notices_global'), 5);
592 592
         add_action('admin_notices', array($this, 'admin_notices'), 10);
593
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
594
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
593
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
594
+            add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15);
595 595
         }
596 596
         //load network admin_notices - global, page class, and view specific
597 597
         add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
598
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
599
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
598
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
599
+            add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view));
600 600
         }
601 601
         //this will save any per_page screen options if they are present
602 602
         $this->_set_per_page_screen_options();
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
         //add screen options - global, page child class, and view specific
609 609
         $this->_add_global_screen_options();
610 610
         $this->_add_screen_options();
611
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
612
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
611
+        if (method_exists($this, '_add_screen_options_'.$this->_current_view)) {
612
+            call_user_func(array($this, '_add_screen_options_'.$this->_current_view));
613 613
         }
614 614
         //add help tab(s) and tours- set via page_config and qtips.
615 615
         $this->_add_help_tour();
@@ -618,31 +618,31 @@  discard block
 block discarded – undo
618 618
         //add feature_pointers - global, page child class, and view specific
619 619
         $this->_add_feature_pointers();
620 620
         $this->_add_global_feature_pointers();
621
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
622
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
621
+        if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) {
622
+            call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view));
623 623
         }
624 624
         //enqueue scripts/styles - global, page class, and view specific
625 625
         add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
626 626
         add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
627
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
628
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
627
+        if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) {
628
+            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15);
629 629
         }
630 630
         add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
631 631
         //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
632 632
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
633 633
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
634
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
635
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
634
+        if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) {
635
+            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101);
636 636
         }
637 637
         //admin footer scripts
638 638
         add_action('admin_footer', array($this, 'admin_footer_global'), 99);
639 639
         add_action('admin_footer', array($this, 'admin_footer'), 100);
640
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
641
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
640
+        if (method_exists($this, 'admin_footer_'.$this->_current_view)) {
641
+            add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101);
642 642
         }
643 643
         do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
644 644
         //targeted hook
645
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
645
+        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action);
646 646
     }
647 647
 
648 648
 
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
             // user error msg
719 719
             $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
720 720
             // developer error msg
721
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
721
+            $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722 722
             throw new EE_Error($error_msg);
723 723
         }
724 724
         // and that the requested page route exists
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
             // user error msg
730 730
             $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
731 731
             // developer error msg
732
-            $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);
732
+            $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);
733 733
             throw new EE_Error($error_msg);
734 734
         }
735 735
         // and that a default route exists
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
             // user error msg
738 738
             $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
739 739
             // developer error msg
740
-            $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');
740
+            $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');
741 741
             throw new EE_Error($error_msg);
742 742
         }
743 743
         //first lets' catch if the UI request has EVER been set.
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
             // user error msg
767 767
             $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
768 768
             // developer error msg
769
-            $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);
769
+            $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);
770 770
             throw new EE_Error($error_msg);
771 771
         }
772 772
     }
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             // these are not the droids you are looking for !!!
789 789
             $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
790 790
             if (WP_DEBUG) {
791
-                $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__);
791
+                $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__);
792 792
             }
793 793
             if ( ! defined('DOING_AJAX')) {
794 794
                 wp_die($msg);
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
                 if (strpos($key, 'nonce') !== false) {
964 964
                     continue;
965 965
                 }
966
-                $args['wp_referer[' . $key . ']'] = $value;
966
+                $args['wp_referer['.$key.']'] = $value;
967 967
             }
968 968
         }
969 969
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
                     if ($tour instanceof EE_Help_Tour_final_stop) {
1010 1010
                         continue;
1011 1011
                     }
1012
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1012
+                    $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>';
1013 1013
                 }
1014 1014
                 $tour_buttons .= implode('<br />', $tb);
1015 1015
                 $tour_buttons .= '</div></div>';
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
                     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',
1022 1022
                             'event_espresso'), $config['help_sidebar'], get_class($this)));
1023 1023
                 }
1024
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1024
+                $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1025 1025
                 $content .= $tour_buttons; //add help tour buttons.
1026 1026
                 //do we have any help tours setup?  Cause if we do we want to add the buttons
1027 1027
                 $this->_current_screen->set_help_sidebar($content);
@@ -1034,13 +1034,13 @@  discard block
 block discarded – undo
1034 1034
             if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1035 1035
                 $_ht['id'] = $this->page_slug;
1036 1036
                 $_ht['title'] = __('Help Tours', 'event_espresso');
1037
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1037
+                $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>';
1038 1038
                 $this->_current_screen->add_help_tab($_ht);
1039 1039
             }/**/
1040 1040
             if ( ! isset($config['help_tabs'])) {
1041 1041
                 return;
1042 1042
             } //no help tabs for this route
1043
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1043
+            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1044 1044
                 //we're here so there ARE help tabs!
1045 1045
                 //make sure we've got what we need
1046 1046
                 if ( ! isset($cfg['title'])) {
@@ -1055,9 +1055,9 @@  discard block
 block discarded – undo
1055 1055
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1056 1056
                     //second priority goes to filename
1057 1057
                 } else if ( ! empty($cfg['filename'])) {
1058
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1058
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1059 1059
                     //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)
1060
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1060
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path;
1061 1061
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1062 1062
                     if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1063 1063
                         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',
@@ -1076,7 +1076,7 @@  discard block
 block discarded – undo
1076 1076
                     return;
1077 1077
                 }
1078 1078
                 //setup config array for help tab method
1079
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1079
+                $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1080 1080
                 $_ht = array(
1081 1081
                         'id'       => $id,
1082 1082
                         'title'    => $cfg['title'],
@@ -1114,9 +1114,9 @@  discard block
 block discarded – undo
1114 1114
             }
1115 1115
             if (isset($config['help_tour'])) {
1116 1116
                 foreach ($config['help_tour'] as $tour) {
1117
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1117
+                    $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php';
1118 1118
                     //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
1119
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1119
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path;
1120 1120
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1121 1121
                     if ( ! is_readable($file_path)) {
1122 1122
                         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'),
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
                     require_once $file_path;
1127 1127
                     if ( ! class_exists($tour)) {
1128 1128
                         $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1129
-                        $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.',
1129
+                        $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.',
1130 1130
                                         'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1131 1131
                         throw new EE_Error(implode('||', $error_msg));
1132 1132
                     }
@@ -1158,11 +1158,11 @@  discard block
 block discarded – undo
1158 1158
     protected function _add_qtips()
1159 1159
     {
1160 1160
         if (isset($this->_route_config['qtips'])) {
1161
-            $qtips = (array)$this->_route_config['qtips'];
1161
+            $qtips = (array) $this->_route_config['qtips'];
1162 1162
             //load qtip loader
1163 1163
             $path = array(
1164
-                    $this->_get_dir() . '/qtips/',
1165
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1164
+                    $this->_get_dir().'/qtips/',
1165
+                    EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1166 1166
             );
1167 1167
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1168 1168
         }
@@ -1192,11 +1192,11 @@  discard block
 block discarded – undo
1192 1192
             if ( ! $this->check_user_access($slug, true)) {
1193 1193
                 continue;
1194 1194
             } //no nav tab becasue current user does not have access.
1195
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1195
+            $css_class = isset($config['css_class']) ? $config['css_class'].' ' : '';
1196 1196
             $this->_nav_tabs[$slug] = array(
1197 1197
                     'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1198 1198
                     'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1199
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1199
+                    'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class,
1200 1200
                     'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1201 1201
             );
1202 1202
             $i++;
@@ -1259,11 +1259,11 @@  discard block
 block discarded – undo
1259 1259
             $capability = empty($capability) ? 'manage_options' : $capability;
1260 1260
         }
1261 1261
         $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1262
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1262
+        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) {
1263 1263
             if ($verify_only) {
1264 1264
                 return false;
1265 1265
             } else {
1266
-                if ( is_user_logged_in() ) {
1266
+                if (is_user_logged_in()) {
1267 1267
                     wp_die(__('You do not have access to this route.', 'event_espresso'));
1268 1268
                 } else {
1269 1269
                     return false;
@@ -1355,7 +1355,7 @@  discard block
 block discarded – undo
1355 1355
     public function admin_footer_global()
1356 1356
     {
1357 1357
         //dialog container for dialog helper
1358
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1358
+        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n";
1359 1359
         $d_cont .= '<div class="ee-notices"></div>';
1360 1360
         $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1361 1361
         $d_cont .= '</div>';
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
             echo implode('<br />', $this->_help_tour[$this->_req_action]);
1366 1366
         }
1367 1367
         //current set timezone for timezone js
1368
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1368
+        echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>';
1369 1369
     }
1370 1370
 
1371 1371
 
@@ -1390,7 +1390,7 @@  discard block
 block discarded – undo
1390 1390
     {
1391 1391
         $content = '';
1392 1392
         $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1393
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1393
+        $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php';
1394 1394
         //loop through the array and setup content
1395 1395
         foreach ($help_array as $trigger => $help) {
1396 1396
             //make sure the array is setup properly
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
     private function _get_help_content()
1425 1425
     {
1426 1426
         //what is the method we're looking for?
1427
-        $method_name = '_help_popup_content_' . $this->_req_action;
1427
+        $method_name = '_help_popup_content_'.$this->_req_action;
1428 1428
         //if method doesn't exist let's get out.
1429 1429
         if ( ! method_exists($this, $method_name)) {
1430 1430
             return array();
@@ -1468,8 +1468,8 @@  discard block
 block discarded – undo
1468 1468
             $help_content = $this->_set_help_popup_content($help_array, false);
1469 1469
         }
1470 1470
         //let's setup the trigger
1471
-        $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>';
1472
-        $content = $content . $help_content;
1471
+        $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>';
1472
+        $content = $content.$help_content;
1473 1473
         if ($display) {
1474 1474
             echo $content;
1475 1475
         } else {
@@ -1529,32 +1529,32 @@  discard block
 block discarded – undo
1529 1529
             add_action('admin_head', array($this, 'add_xdebug_style'));
1530 1530
         }
1531 1531
         //register all styles
1532
-        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);
1533
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1532
+        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);
1533
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1534 1534
         //helpers styles
1535
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1535
+        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1536 1536
         //enqueue global styles
1537 1537
         wp_enqueue_style('ee-admin-css');
1538 1538
         /** SCRIPTS **/
1539 1539
         //register all scripts
1540
-        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1541
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1542
-        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);
1543
-        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);
1540
+        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1541
+        wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1542
+        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);
1543
+        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);
1544 1544
         // register jQuery Validate - see /includes/functions/wp_hooks.php
1545 1545
         add_filter('FHEE_load_jquery_validate', '__return_true');
1546 1546
         add_filter('FHEE_load_joyride', '__return_true');
1547 1547
         //script for sorting tables
1548
-        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);
1548
+        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);
1549 1549
         //script for parsing uri's
1550
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550
+        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1551 1551
         //and parsing associative serialized form elements
1552
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552
+        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1553 1553
         //helpers scripts
1554
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1555
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1557
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1554
+        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1555
+        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1556
+        wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1557
+        wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1558 1558
         //google charts
1559 1559
         wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1560 1560
         //enqueue global scripts
@@ -1575,7 +1575,7 @@  discard block
 block discarded – undo
1575 1575
          */
1576 1576
         if ( ! empty($this->_help_tour)) {
1577 1577
             //register the js for kicking things off
1578
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1578
+            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1579 1579
             //setup tours for the js tour object
1580 1580
             foreach ($this->_help_tour['tours'] as $tour) {
1581 1581
                 $tours[] = array(
@@ -1674,17 +1674,17 @@  discard block
 block discarded – undo
1674 1674
             return;
1675 1675
         } //not a list_table view so get out.
1676 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) {
1677
+        if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) {
1678 1678
             //user error msg
1679 1679
             $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1680 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);
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 1683
             throw new EE_Error($error_msg);
1684 1684
         }
1685 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);
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 1688
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1689 1689
         $this->_set_list_table_view();
1690 1690
         $this->_set_list_table_object();
@@ -1759,7 +1759,7 @@  discard block
 block discarded – undo
1759 1759
             // check for current view
1760 1760
             $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1761 1761
             $query_args['action'] = $this->_req_action;
1762
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1762
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
1763 1763
             $query_args['status'] = $view['slug'];
1764 1764
             //merge any other arguments sent in.
1765 1765
             if (isset($extra_query_args[$view['slug']])) {
@@ -1797,14 +1797,14 @@  discard block
 block discarded – undo
1797 1797
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1798 1798
         foreach ($values as $value) {
1799 1799
             if ($value < $max_entries) {
1800
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1800
+                $selected = $value == $per_page ? ' selected="'.$per_page.'"' : '';
1801 1801
                 $entries_per_page_dropdown .= '
1802
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1802
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
1803 1803
             }
1804 1804
         }
1805
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1805
+        $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : '';
1806 1806
         $entries_per_page_dropdown .= '
1807
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1807
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
1808 1808
         $entries_per_page_dropdown .= '
1809 1809
 					</select>
1810 1810
 					entries
@@ -1826,7 +1826,7 @@  discard block
 block discarded – undo
1826 1826
     public function _set_search_attributes()
1827 1827
     {
1828 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;
1829
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
1830 1830
     }
1831 1831
 
1832 1832
     /*** END LIST TABLE METHODS **/
@@ -1864,7 +1864,7 @@  discard block
 block discarded – undo
1864 1864
                     // user error msg
1865 1865
                     $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1866 1866
                     // developer error msg
1867
-                    $error_msg .= '||' . sprintf(
1867
+                    $error_msg .= '||'.sprintf(
1868 1868
                                     __(
1869 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 1870
                                             'event_espresso'
@@ -1894,15 +1894,15 @@  discard block
 block discarded – undo
1894 1894
                 && is_array($this->_route_config['columns'])
1895 1895
                 && count($this->_route_config['columns']) === 2
1896 1896
         ) {
1897
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1897
+            add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1]));
1898 1898
             $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1899 1899
             $screen_id = $this->_current_screen->id;
1900
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1900
+            $screen_columns = (int) get_user_option("screen_layout_$screen_id");
1901 1901
             $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1902
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1902
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
1903 1903
             $this->_template_args['current_page'] = $this->_wp_page_slug;
1904 1904
             $this->_template_args['screen'] = $this->_current_screen;
1905
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1905
+            $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php';
1906 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 1907
             $this->_route_config['has_metaboxes'] = true;
1908 1908
         }
@@ -1949,7 +1949,7 @@  discard block
 block discarded – undo
1949 1949
      */
1950 1950
     public function espresso_ratings_request()
1951 1951
     {
1952
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1952
+        $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php';
1953 1953
         EEH_Template::display_template($template_path, array());
1954 1954
     }
1955 1955
 
@@ -1957,18 +1957,18 @@  discard block
 block discarded – undo
1957 1957
 
1958 1958
     public static function cached_rss_display($rss_id, $url)
1959 1959
     {
1960
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1960
+        $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading&#8230;').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>';
1961 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);
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 1966
         if (false != ($output = get_transient($cache_key))) {
1967
-            echo $pre . $output . $post;
1967
+            echo $pre.$output.$post;
1968 1968
             return true;
1969 1969
         }
1970 1970
         if ( ! $doing_ajax) {
1971
-            echo $pre . $loading . $post;
1971
+            echo $pre.$loading.$post;
1972 1972
             return false;
1973 1973
         }
1974 1974
         ob_start();
@@ -2027,7 +2027,7 @@  discard block
 block discarded – undo
2027 2027
 
2028 2028
     public function espresso_sponsors_post_box()
2029 2029
     {
2030
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2030
+        $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php';
2031 2031
         EEH_Template::display_template($templatepath);
2032 2032
     }
2033 2033
 
@@ -2035,7 +2035,7 @@  discard block
 block discarded – undo
2035 2035
 
2036 2036
     private function _publish_post_box()
2037 2037
     {
2038
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2038
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2039 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 2040
         if ( ! empty($this->_labels['publishbox'])) {
2041 2041
             $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
@@ -2052,7 +2052,7 @@  discard block
 block discarded – undo
2052 2052
     {
2053 2053
         //if we have extra content set let's add it in if not make sure its empty
2054 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';
2055
+        $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php';
2056 2056
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2057 2057
     }
2058 2058
 
@@ -2221,7 +2221,7 @@  discard block
 block discarded – undo
2221 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 2222
         $call_back_func = $create_func ? create_function('$post, $metabox',
2223 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);
2224
+        add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2225 2225
     }
2226 2226
 
2227 2227
 
@@ -2301,10 +2301,10 @@  discard block
 block discarded – undo
2301 2301
                 ? 'poststuff'
2302 2302
                 : 'espresso-default-admin';
2303 2303
         $template_path = $sidebar
2304
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2305
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2304
+                ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php'
2305
+                : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2306 2306
         if (defined('DOING_AJAX') && DOING_AJAX) {
2307
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2307
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2308 2308
         }
2309 2309
         $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2310 2310
         $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
@@ -2350,7 +2350,7 @@  discard block
 block discarded – undo
2350 2350
                         true
2351 2351
                 )
2352 2352
                 : $this->_template_args['preview_action_button'];
2353
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2353
+        $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php';
2354 2354
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2355 2355
                 $template_path,
2356 2356
                 $this->_template_args,
@@ -2401,7 +2401,7 @@  discard block
 block discarded – undo
2401 2401
         //setup search attributes
2402 2402
         $this->_set_search_attributes();
2403 2403
         $this->_template_args['current_page'] = $this->_wp_page_slug;
2404
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2404
+        $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2405 2405
         $this->_template_args['table_url'] = defined('DOING_AJAX')
2406 2406
                 ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2407 2407
                 : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
@@ -2411,31 +2411,31 @@  discard block
 block discarded – undo
2411 2411
         $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2412 2412
         if ( ! empty($ajax_sorting_callback)) {
2413 2413
             $sortable_list_table_form_fields = wp_nonce_field(
2414
-                    $ajax_sorting_callback . '_nonce',
2415
-                    $ajax_sorting_callback . '_nonce',
2414
+                    $ajax_sorting_callback.'_nonce',
2415
+                    $ajax_sorting_callback.'_nonce',
2416 2416
                     false,
2417 2417
                     false
2418 2418
             );
2419 2419
             //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2420 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 . '" />';
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 2423
         } else {
2424 2424
             $sortable_list_table_form_fields = '';
2425 2425
         }
2426 2426
         $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2427 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) . '">';
2428
+        $nonce_ref = $this->_req_action.'_nonce';
2429
+        $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2430 2430
         $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2431 2431
         //display message about search results?
2432 2432
         $this->_template_args['before_list_table'] .= apply_filters(
2433 2433
                 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2434 2434
                 ! empty($this->_req_data['s'])
2435
-                        ? '<p class="ee-search-results">' . sprintf(
2435
+                        ? '<p class="ee-search-results">'.sprintf(
2436 2436
                                 __('Displaying search results for the search string: <strong><em>%s</em></strong>', 'event_espresso'),
2437 2437
                                 trim($this->_req_data['s'], '%')
2438
-                        ) . '</p>'
2438
+                        ).'</p>'
2439 2439
                         : '',
2440 2440
                 $this->page_slug,
2441 2441
                 $this->_req_data,
@@ -2471,8 +2471,8 @@  discard block
 block discarded – undo
2471 2471
      */
2472 2472
     protected function _display_legend($items)
2473 2473
     {
2474
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2475
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2474
+        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this);
2475
+        $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php';
2476 2476
         return EEH_Template::display_template($legend_template, $this->_template_args, true);
2477 2477
     }
2478 2478
 
@@ -2567,15 +2567,15 @@  discard block
 block discarded – undo
2567 2567
         $this->_nav_tabs = $this->_get_main_nav_tabs();
2568 2568
         $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2569 2569
         $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2570
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2570
+        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view,
2571 2571
                 isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2572
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2572
+        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view,
2573 2573
                 isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2574 2574
         $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2575 2575
         // load settings page wrapper template
2576
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2576
+        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php';
2577 2577
         //about page?
2578
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2578
+        $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path;
2579 2579
         if (defined('DOING_AJAX')) {
2580 2580
             $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2581 2581
             $this->_return_json();
@@ -2647,20 +2647,20 @@  discard block
 block discarded – undo
2647 2647
     protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2648 2648
     {
2649 2649
         //make sure $text and $actions are in an array
2650
-        $text = (array)$text;
2651
-        $actions = (array)$actions;
2650
+        $text = (array) $text;
2651
+        $actions = (array) $actions;
2652 2652
         $referrer_url = empty($referrer) ? '' : $referrer;
2653
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2654
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2653
+        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />'
2654
+                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />';
2655 2655
         $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2656 2656
         $default_names = array('save', 'save_and_close');
2657 2657
         //add in a hidden index for the current page (so save and close redirects properly)
2658 2658
         $this->_template_args['save_buttons'] = $referrer_url;
2659 2659
         foreach ($button_text as $key => $button) {
2660 2660
             $ref = $default_names[$key];
2661
-            $id = $this->_current_view . '_' . $ref;
2661
+            $id = $this->_current_view.'_'.$ref;
2662 2662
             $name = ! empty($actions) ? $actions[$key] : $ref;
2663
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2663
+            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />';
2664 2664
             if ( ! $both) {
2665 2665
                 break;
2666 2666
             }
@@ -2696,15 +2696,15 @@  discard block
 block discarded – undo
2696 2696
     {
2697 2697
         if (empty($route)) {
2698 2698
             $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2699
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2700
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2699
+            $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2700
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
2701 2701
         }
2702 2702
         // open form
2703
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2703
+        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >';
2704 2704
         // add nonce
2705
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2705
+        $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
2706 2706
         //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2707
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2707
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
2708 2708
         // add REQUIRED form action
2709 2709
         $hidden_fields = array(
2710 2710
                 'action' => array('type' => 'hidden', 'value' => $route),
@@ -2714,8 +2714,8 @@  discard block
 block discarded – undo
2714 2714
         // generate form fields
2715 2715
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2716 2716
         // add fields to form
2717
-        foreach ((array)$form_fields as $field_name => $form_field) {
2718
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2717
+        foreach ((array) $form_fields as $field_name => $form_field) {
2718
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
2719 2719
         }
2720 2720
         // close form
2721 2721
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -2796,7 +2796,7 @@  discard block
 block discarded – undo
2796 2796
          * @param array $query_args       The original query_args array coming into the
2797 2797
          *                                method.
2798 2798
          */
2799
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2799
+        do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args);
2800 2800
         //calculate where we're going (if we have a "save and close" button pushed)
2801 2801
         if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2802 2802
             // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
@@ -2812,7 +2812,7 @@  discard block
 block discarded – undo
2812 2812
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
2813 2813
                 //is there a wp_referer array in our _default_route_query_args property?
2814 2814
                 if ($query_param == 'wp_referer') {
2815
-                    $query_value = (array)$query_value;
2815
+                    $query_value = (array) $query_value;
2816 2816
                     foreach ($query_value as $reference => $value) {
2817 2817
                         if (strpos($reference, 'nonce') !== false) {
2818 2818
                             continue;
@@ -2838,11 +2838,11 @@  discard block
 block discarded – undo
2838 2838
         // if redirecting to anything other than the main page, add a nonce
2839 2839
         if (isset($query_args['action'])) {
2840 2840
             // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2841
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2841
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
2842 2842
         }
2843 2843
         //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).
2844
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2845
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2844
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
2845
+        $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2846 2846
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2847 2847
         if (defined('DOING_AJAX')) {
2848 2848
             $default_data = array(
@@ -2972,7 +2972,7 @@  discard block
 block discarded – undo
2972 2972
         $args = array(
2973 2973
                 'label'   => $this->_admin_page_title,
2974 2974
                 'default' => 10,
2975
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
2975
+                'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
2976 2976
         );
2977 2977
         //ONLY add the screen option if the user has access to it.
2978 2978
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3005,8 +3005,8 @@  discard block
 block discarded – undo
3005 3005
             $map_option = $option;
3006 3006
             $option = str_replace('-', '_', $option);
3007 3007
             switch ($map_option) {
3008
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3009
-                    $value = (int)$value;
3008
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3009
+                    $value = (int) $value;
3010 3010
                     if ($value < 1 || $value > 999) {
3011 3011
                         return;
3012 3012
                     }
@@ -3033,7 +3033,7 @@  discard block
 block discarded – undo
3033 3033
      */
3034 3034
     public function set_template_args($data)
3035 3035
     {
3036
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3036
+        $this->_template_args = array_merge($this->_template_args, (array) $data);
3037 3037
     }
3038 3038
 
3039 3039
 
@@ -3055,12 +3055,12 @@  discard block
 block discarded – undo
3055 3055
             $this->_verify_route($route);
3056 3056
         }
3057 3057
         //now let's set the string for what kind of transient we're setting
3058
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3058
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3059 3059
         $data = $notices ? array('notices' => $data) : $data;
3060 3060
         //is there already a transient for this route?  If there is then let's ADD to that transient
3061 3061
         $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3062 3062
         if ($existing) {
3063
-            $data = array_merge((array)$data, (array)$existing);
3063
+            $data = array_merge((array) $data, (array) $existing);
3064 3064
         }
3065 3065
         if (is_multisite() && is_network_admin()) {
3066 3066
             set_site_transient($transient, $data, 8);
@@ -3081,7 +3081,7 @@  discard block
 block discarded – undo
3081 3081
     {
3082 3082
         $user_id = get_current_user_id();
3083 3083
         $route = ! $route ? $this->_req_action : $route;
3084
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3084
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3085 3085
         $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3086 3086
         //delete transient after retrieval (just in case it hasn't expired);
3087 3087
         if (is_multisite() && is_network_admin()) {
@@ -3322,7 +3322,7 @@  discard block
 block discarded – undo
3322 3322
      */
3323 3323
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3324 3324
     {
3325
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3325
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3326 3326
     }
3327 3327
 
3328 3328
 
@@ -3336,7 +3336,7 @@  discard block
 block discarded – undo
3336 3336
      */
3337 3337
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3338 3338
     {
3339
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3339
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3340 3340
     }
3341 3341
 
3342 3342
 
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,239 +40,239 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.029');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.029');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        /**
197
-         *    espresso_plugin_activation
198
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
199
-         */
200
-        function espresso_plugin_activation()
201
-        {
202
-            update_option('ee_espresso_activation', true);
203
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		/**
197
+		 *    espresso_plugin_activation
198
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
199
+		 */
200
+		function espresso_plugin_activation()
201
+		{
202
+			update_option('ee_espresso_activation', true);
203
+		}
204 204
 
205
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
206
-        /**
207
-         *    espresso_load_error_handling
208
-         *    this function loads EE's class for handling exceptions and errors
209
-         */
210
-        function espresso_load_error_handling()
211
-        {
212
-            // load debugging tools
213
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
214
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
215
-                EEH_Debug_Tools::instance();
216
-            }
217
-            // load error handling
218
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
219
-                require_once(EE_CORE . 'EE_Error.core.php');
220
-            } else {
221
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
222
-            }
223
-        }
205
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
206
+		/**
207
+		 *    espresso_load_error_handling
208
+		 *    this function loads EE's class for handling exceptions and errors
209
+		 */
210
+		function espresso_load_error_handling()
211
+		{
212
+			// load debugging tools
213
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
214
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
215
+				EEH_Debug_Tools::instance();
216
+			}
217
+			// load error handling
218
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
219
+				require_once(EE_CORE . 'EE_Error.core.php');
220
+			} else {
221
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
222
+			}
223
+		}
224 224
 
225
-        /**
226
-         *    espresso_load_required
227
-         *    given a class name and path, this function will load that file or throw an exception
228
-         *
229
-         * @param    string $classname
230
-         * @param    string $full_path_to_file
231
-         * @throws    EE_Error
232
-         */
233
-        function espresso_load_required($classname, $full_path_to_file)
234
-        {
235
-            static $error_handling_loaded = false;
236
-            if ( ! $error_handling_loaded) {
237
-                espresso_load_error_handling();
238
-                $error_handling_loaded = true;
239
-            }
240
-            if (is_readable($full_path_to_file)) {
241
-                require_once($full_path_to_file);
242
-            } else {
243
-                throw new EE_Error (
244
-                        sprintf(
245
-                                esc_html__(
246
-                                        'The %s class file could not be located or is not readable due to file permissions.',
247
-                                        'event_espresso'
248
-                                ),
249
-                                $classname
250
-                        )
251
-                );
252
-            }
253
-        }
225
+		/**
226
+		 *    espresso_load_required
227
+		 *    given a class name and path, this function will load that file or throw an exception
228
+		 *
229
+		 * @param    string $classname
230
+		 * @param    string $full_path_to_file
231
+		 * @throws    EE_Error
232
+		 */
233
+		function espresso_load_required($classname, $full_path_to_file)
234
+		{
235
+			static $error_handling_loaded = false;
236
+			if ( ! $error_handling_loaded) {
237
+				espresso_load_error_handling();
238
+				$error_handling_loaded = true;
239
+			}
240
+			if (is_readable($full_path_to_file)) {
241
+				require_once($full_path_to_file);
242
+			} else {
243
+				throw new EE_Error (
244
+						sprintf(
245
+								esc_html__(
246
+										'The %s class file could not be located or is not readable due to file permissions.',
247
+										'event_espresso'
248
+								),
249
+								$classname
250
+						)
251
+				);
252
+			}
253
+		}
254 254
 
255
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
256
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
257
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
258
-        new EE_Bootstrap();
259
-    }
255
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
256
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
257
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
258
+		new EE_Bootstrap();
259
+	}
260 260
 }
261 261
 if ( ! function_exists('espresso_deactivate_plugin')) {
262
-    /**
263
-     *    deactivate_plugin
264
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
265
-     *
266
-     * @access public
267
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
268
-     * @return    void
269
-     */
270
-    function espresso_deactivate_plugin($plugin_basename = '')
271
-    {
272
-        if ( ! function_exists('deactivate_plugins')) {
273
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
274
-        }
275
-        unset($_GET['activate'], $_REQUEST['activate']);
276
-        deactivate_plugins($plugin_basename);
277
-    }
262
+	/**
263
+	 *    deactivate_plugin
264
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
265
+	 *
266
+	 * @access public
267
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
268
+	 * @return    void
269
+	 */
270
+	function espresso_deactivate_plugin($plugin_basename = '')
271
+	{
272
+		if ( ! function_exists('deactivate_plugins')) {
273
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
274
+		}
275
+		unset($_GET['activate'], $_REQUEST['activate']);
276
+		deactivate_plugins($plugin_basename);
277
+	}
278 278
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha/EED_Recaptcha.module.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.
Spacing   +130 added lines, -131 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @return EED_Recaptcha
44 44
 	 */
45 45
 	public static function instance() {
46
-		return parent::get_instance( __CLASS__ );
46
+		return parent::get_instance(__CLASS__);
47 47
 	}
48 48
 
49 49
 
@@ -59,32 +59,32 @@  discard block
 block discarded – undo
59 59
 		if (
60 60
 			EE_Registry::instance()->CFG->registration->use_captcha
61 61
 			&& ! (
62
-				EE_Registry::instance()->REQ->get( 'step', '' ) === 'payment_options'
63
-				&& (boolean) EE_Registry::instance()->REQ->get( 'revisit', false ) === true
62
+				EE_Registry::instance()->REQ->get('step', '') === 'payment_options'
63
+				&& (boolean) EE_Registry::instance()->REQ->get('revisit', false) === true
64 64
 			)
65 65
 		) {
66 66
 			EED_Recaptcha::set_definitions();
67 67
 			EED_Recaptcha::enqueue_styles_and_scripts();
68
-			add_action( 'wp', array( 'EED_Recaptcha', 'set_late_hooks' ), 1, 0 );
68
+			add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
69 69
 			add_action(
70 70
 				'AHEE__before_spco_whats_next_buttons',
71
-				array( 'EED_Recaptcha', 'display_recaptcha' ), 10, 0
71
+				array('EED_Recaptcha', 'display_recaptcha'), 10, 0
72 72
 			);
73 73
 			add_filter(
74 74
 				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
75
-				array( 'EED_Recaptcha', 'not_a_robot' ), 10
75
+				array('EED_Recaptcha', 'not_a_robot'), 10
76 76
 			);
77 77
 			add_filter(
78 78
 				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
79
-				array( 'EED_Recaptcha', 'not_a_robot' ), 10
79
+				array('EED_Recaptcha', 'not_a_robot'), 10
80 80
 			);
81 81
 			add_filter(
82 82
 				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
83
-				array( 'EED_Recaptcha', 'recaptcha_response' ), 10, 1
83
+				array('EED_Recaptcha', 'recaptcha_response'), 10, 1
84 84
 			);
85 85
 			add_filter(
86 86
 				'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
87
-				array( 'EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method' ), 10, 1
87
+				array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method'), 10, 1
88 88
 			);
89 89
 		}
90 90
 	}
@@ -103,18 +103,18 @@  discard block
 block discarded – undo
103 103
 		if (
104 104
 			EE_Registry::instance()->CFG->registration->use_captcha
105 105
 			&& ! (
106
-				EE_Registry::instance()->REQ->get( 'step', '' ) === 'payment_options'
107
-				&& (boolean) EE_Registry::instance()->REQ->get( 'revisit', false ) === true
106
+				EE_Registry::instance()->REQ->get('step', '') === 'payment_options'
107
+				&& (boolean) EE_Registry::instance()->REQ->get('revisit', false) === true
108 108
 			)
109 109
 		) {
110 110
 			EED_Recaptcha::enqueue_styles_and_scripts();
111
-			add_filter( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', array( 'EED_Recaptcha', 'not_a_robot' ), 10 );
112
-			add_filter( 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', array( 'EED_Recaptcha', 'not_a_robot' ), 10 );
113
-			add_filter( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', array( 'EED_Recaptcha', 'recaptcha_response' ), 10, 1 );
111
+			add_filter('FHEE__EED_Single_Page_Checkout__init___continue_reg', array('EED_Recaptcha', 'not_a_robot'), 10);
112
+			add_filter('FHEE__EE_SPCO_Reg_Step__set_completed___completed', array('EED_Recaptcha', 'not_a_robot'), 10);
113
+			add_filter('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', array('EED_Recaptcha', 'recaptcha_response'), 10, 1);
114 114
 		}
115 115
 		// admin settings
116
-		add_action( 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', array( 'EED_Recaptcha', 'admin_settings' ), 10, 1 );
117
-		add_filter( 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', array( 'EED_Recaptcha', 'update_admin_settings' ), 10, 1 );
116
+		add_action('AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', array('EED_Recaptcha', 'admin_settings'), 10, 1);
117
+		add_filter('FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', array('EED_Recaptcha', 'update_admin_settings'), 10, 1);
118 118
 	}
119 119
 
120 120
 
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 	 *  @return 	void
127 127
 	 */
128 128
 	public static function set_definitions() {
129
-		if ( is_user_logged_in() ) {
129
+		if (is_user_logged_in()) {
130 130
 			EED_Recaptcha::$_not_a_robot = true;
131 131
 		}
132
-		define( 'RECAPTCHA_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS );
133
-		define( 'RECAPTCHA_BASE_URL', plugin_dir_url( __FILE__ ));
132
+		define('RECAPTCHA_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS);
133
+		define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
134 134
 	}
135 135
 
136 136
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	public static function set_late_hooks() {
145 145
 		add_filter(
146 146
 			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
147
-			array( 'EED_Recaptcha', 'not_a_robot' )
147
+			array('EED_Recaptcha', 'not_a_robot')
148 148
 		);
149 149
 	}
150 150
 
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
 	 *  @return 	void
158 158
 	 */
159 159
 	public static function enqueue_styles_and_scripts() {
160
-		wp_register_script( 'espresso_recaptcha', RECAPTCHA_BASE_URL . 'scripts' . DS . 'espresso_recaptcha.js', array( 'single_page_checkout' ), EVENT_ESPRESSO_VERSION, TRUE );
161
-		wp_register_script( 'google_recaptcha', 'https://www.google.com/recaptcha/api.js?hl=' . EE_Registry::instance()->CFG->registration->recaptcha_language, array( 'espresso_recaptcha' ), EVENT_ESPRESSO_VERSION, TRUE );
162
-		EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( 'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', 'event_espresso' );
163
-		EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __( 'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', 'event_espresso' );
164
-		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( 'Please complete the anti-spam test before proceeding.', 'event_espresso' );
160
+		wp_register_script('espresso_recaptcha', RECAPTCHA_BASE_URL.'scripts'.DS.'espresso_recaptcha.js', array('single_page_checkout'), EVENT_ESPRESSO_VERSION, TRUE);
161
+		wp_register_script('google_recaptcha', 'https://www.google.com/recaptcha/api.js?hl='.EE_Registry::instance()->CFG->registration->recaptcha_language, array('espresso_recaptcha'), EVENT_ESPRESSO_VERSION, TRUE);
162
+		EE_Registry::$i18n_js_strings['no_SPCO_error'] = __('It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', 'event_espresso');
163
+		EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __('There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', 'event_espresso');
164
+		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __('Please complete the anti-spam test before proceeding.', 'event_espresso');
165 165
 	}
166 166
 
167 167
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @access    public
173 173
 	 * @param \WP $WP
174 174
 	 */
175
-	public function run( $WP ) {
175
+	public function run($WP) {
176 176
 	}
177 177
 
178 178
 
@@ -182,8 +182,7 @@  discard block
 block discarded – undo
182 182
 	 *  @return boolean
183 183
 	 */
184 184
 	public static function not_a_robot() {
185
-		$not_a_robot = is_bool( EED_Recaptcha::$_not_a_robot ) ? EED_Recaptcha::$_not_a_robot :
186
-			EED_Recaptcha::recaptcha_passed();
185
+		$not_a_robot = is_bool(EED_Recaptcha::$_not_a_robot) ? EED_Recaptcha::$_not_a_robot : EED_Recaptcha::recaptcha_passed();
187 186
 		return $not_a_robot;
188 187
 	}
189 188
 
@@ -199,22 +198,22 @@  discard block
 block discarded – undo
199 198
 	 */
200 199
 	public static function display_recaptcha() {
201 200
 		// logged in means you have already passed a turing test of sorts
202
-		if ( is_user_logged_in() ) {
201
+		if (is_user_logged_in()) {
203 202
 			return;
204 203
 		}
205 204
 		// don't display if not using recaptcha or user is logged in
206
-		if ( EE_Registry::instance()->CFG->registration->use_captcha ) {
205
+		if (EE_Registry::instance()->CFG->registration->use_captcha) {
207 206
 			// only display if they have NOT passed the test yet
208
-			if ( ! EED_Recaptcha::$_not_a_robot ) {
207
+			if ( ! EED_Recaptcha::$_not_a_robot) {
209 208
 				EEH_Template::display_template(
210
-					RECAPTCHA_BASE_PATH . DS . 'templates' . DS . 'recaptcha.template.php',
209
+					RECAPTCHA_BASE_PATH.DS.'templates'.DS.'recaptcha.template.php',
211 210
 					array(
212 211
 						'recaptcha_publickey' 	=> EE_Registry::instance()->CFG->registration->recaptcha_publickey,
213 212
 						'recaptcha_theme' 		=> EE_Registry::instance()->CFG->registration->recaptcha_theme,
214 213
 						'recaptcha_type' 			=> EE_Registry::instance()->CFG->registration->recaptcha_type
215 214
 					)
216 215
 				);
217
-				wp_enqueue_script( 'google_recaptcha' );
216
+				wp_enqueue_script('google_recaptcha');
218 217
 			}
219 218
 		}
220 219
 	}
@@ -245,17 +244,17 @@  discard block
 block discarded – undo
245 244
 	 */
246 245
 	public static function recaptcha_passed() {
247 246
 		// logged in means you have already passed a turing test of sorts
248
-		if ( is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha() ) {
247
+		if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
249 248
 			return TRUE;
250 249
 		}
251 250
 		// was test already passed?
252
-		$recaptcha_passed = EE_Registry::instance()->SSN->get_session_data( 'recaptcha_passed' );
253
-		$recaptcha_passed = filter_var( $recaptcha_passed, FILTER_VALIDATE_BOOLEAN );
251
+		$recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
252
+		$recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
254 253
 		// verify recaptcha
255 254
 		EED_Recaptcha::_get_recaptcha_response();
256
-		if ( ! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response ) {
255
+		if ( ! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
257 256
 			$recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
258
-			EE_Registry::instance()->SSN->set_session_data( array( 'recaptcha_passed' => $recaptcha_passed ));
257
+			EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
259 258
 		}
260 259
 		EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
261 260
 		return $recaptcha_passed;
@@ -270,8 +269,8 @@  discard block
 block discarded – undo
270 269
 	 * @param array $recaptcha_response
271 270
 	 * @return boolean
272 271
 	 */
273
-	public static function recaptcha_response( $recaptcha_response = array() ) {
274
-		if ( EED_Recaptcha::_bypass_recaptcha() ) {
272
+	public static function recaptcha_response($recaptcha_response = array()) {
273
+		if (EED_Recaptcha::_bypass_recaptcha()) {
275 274
 			$recaptcha_response['bypass_recaptcha'] = TRUE;
276 275
 			$recaptcha_response['recaptcha_passed'] = TRUE;
277 276
 		} else {
@@ -291,16 +290,16 @@  discard block
 block discarded – undo
291 290
 	 */
292 291
 	private static function _bypass_recaptcha() {
293 292
 		// an array of key value pairs that must match exactly with the incoming request, in order to bypass recaptcha for the current request ONLY
294
-		$bypass_request_params_array = apply_filters( 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', array() );
293
+		$bypass_request_params_array = apply_filters('FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', array());
295 294
 		// does $bypass_request_params_array have any values ?
296
-		if ( empty( $bypass_request_params_array )) {
295
+		if (empty($bypass_request_params_array)) {
297 296
 			return FALSE;
298 297
 		}
299 298
 		// initially set bypass to TRUE
300 299
 		$bypass_recaptcha = TRUE;
301
-		foreach ( $bypass_request_params_array as $key => $value ) {
300
+		foreach ($bypass_request_params_array as $key => $value) {
302 301
 			// if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, otherwise carry over it's value. This way, one missed setting results in no bypass
303
-			$bypass_recaptcha = isset( $_REQUEST[ $key ] ) && $_REQUEST[ $key ] === $value ? $bypass_recaptcha : FALSE;
302
+			$bypass_recaptcha = isset($_REQUEST[$key]) && $_REQUEST[$key] === $value ? $bypass_recaptcha : FALSE;
304 303
 		}
305 304
 		return $bypass_recaptcha;
306 305
 	}
@@ -315,7 +314,7 @@  discard block
 block discarded – undo
315 314
 	 * 	@return 	boolean
316 315
 	 */
317 316
 	private static function _get_recaptcha_response() {
318
-		EED_Recaptcha::$_recaptcha_response = EE_Registry::instance()->REQ->get( 'g-recaptcha-response', false );
317
+		EED_Recaptcha::$_recaptcha_response = EE_Registry::instance()->REQ->get('g-recaptcha-response', false);
319 318
 	}
320 319
 
321 320
 
@@ -329,26 +328,26 @@  discard block
 block discarded – undo
329 328
 	 */
330 329
 	private static function _process_recaptcha_response() {
331 330
 		// verify library is loaded
332
-		if ( ! class_exists( '\\ReCaptcha\\ReCaptcha' )) {
333
-			require_once( RECAPTCHA_BASE_PATH . DS . 'autoload.php' );
331
+		if ( ! class_exists('\\ReCaptcha\\ReCaptcha')) {
332
+			require_once(RECAPTCHA_BASE_PATH.DS.'autoload.php');
334 333
 		}
335 334
 		// The response from reCAPTCHA
336 335
 		EED_Recaptcha::_get_recaptcha_response();
337 336
 		$recaptcha_response = EED_Recaptcha::$_recaptcha_response;
338 337
 		// Was there a reCAPTCHA response?
339
-		if ( $recaptcha_response ) {
338
+		if ($recaptcha_response) {
340 339
 			// if allow_url_fopen is Off, then set a different request method
341
-			$request_method = ! ini_get( 'allow_url_fopen' ) ? new \ReCaptcha\RequestMethod\SocketPost() : null;
340
+			$request_method = ! ini_get('allow_url_fopen') ? new \ReCaptcha\RequestMethod\SocketPost() : null;
342 341
 			$recaptcha = new \ReCaptcha\ReCaptcha(
343 342
 				EE_Registry::instance()->CFG->registration->recaptcha_privatekey,
344 343
 				$request_method
345 344
 			);
346 345
 			$recaptcha_response = $recaptcha->verify(
347 346
 				EED_Recaptcha::$_recaptcha_response,
348
-				$_SERVER[ 'REMOTE_ADDR' ]
347
+				$_SERVER['REMOTE_ADDR']
349 348
 			);
350 349
 		}
351
-		if ( $recaptcha_response instanceof \ReCaptcha\Response && $recaptcha_response->isSuccess() ) {
350
+		if ($recaptcha_response instanceof \ReCaptcha\Response && $recaptcha_response->isSuccess()) {
352 351
 			return TRUE;
353 352
 		}
354 353
 		// sorry... it appears you can't don't know what soup or hamburgers are !!!
@@ -392,12 +391,12 @@  discard block
 block discarded – undo
392 391
 				'subsections' 			=> apply_filters(
393 392
 					'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections',
394 393
 					array(
395
-						'main_settings_hdr' 				=> new EE_Form_Section_HTML( EEH_HTML::h2( __( 'reCAPTCHA Anti-spam Settings', 'event_espresso' ) . EEH_Template::get_help_tab_link( 'recaptcha_info' ))),
394
+						'main_settings_hdr' 				=> new EE_Form_Section_HTML(EEH_HTML::h2(__('reCAPTCHA Anti-spam Settings', 'event_espresso').EEH_Template::get_help_tab_link('recaptcha_info'))),
396 395
 						'main_settings' 						=> EED_Recaptcha::_recaptcha_main_settings(),
397
-						'appearance_settings_hdr' 	=> new EE_Form_Section_HTML( EEH_HTML::h2( __( 'reCAPTCHA Appearance', 'event_espresso' ) )),
396
+						'appearance_settings_hdr' 	=> new EE_Form_Section_HTML(EEH_HTML::h2(__('reCAPTCHA Appearance', 'event_espresso'))),
398 397
 						'appearance_settings' 			=> EED_Recaptcha::_recaptcha_appearance_settings(),
399 398
 						// 'recaptcha_example' 				=> new EE_Form_Section_HTML( EED_Recaptcha::display_recaptcha() ),
400
-						'required_fields_note' 			=> new EE_Form_Section_HTML( EEH_HTML::p( __( 'All fields marked with a * are required fields', 'event_espresso' ), '', 'grey-text' ))
399
+						'required_fields_note' 			=> new EE_Form_Section_HTML(EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text'))
401 400
 					)
402 401
 				)
403 402
 			)
@@ -424,28 +423,28 @@  discard block
 block discarded – undo
424 423
 					array(
425 424
 						'use_captcha' 				=> new EE_Yes_No_Input(
426 425
 							array(
427
-								'html_label_text'	 	=> __( 'Use reCAPTCHA', 'event_espresso' ),
426
+								'html_label_text'	 	=> __('Use reCAPTCHA', 'event_espresso'),
428 427
 								'html_help_text' 		=> sprintf(
429
-									__( 'reCAPTCHA is a free service that  protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.', 'event_espresso' ),
428
+									__('reCAPTCHA is a free service that  protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.', 'event_espresso'),
430 429
 									'<a href="https://www.google.com/recaptcha/intro/index.html">',
431 430
 									'</a>'
432 431
 								),
433
-								'default' 								=> isset( EE_Registry::instance()->CFG->registration->use_captcha ) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE,
432
+								'default' 								=> isset(EE_Registry::instance()->CFG->registration->use_captcha) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE,
434 433
 								'display_html_label_text' 	=> FALSE
435 434
 							)
436 435
 						),
437 436
 						'recaptcha_publickey' 		=> new EE_Text_Input(
438 437
 							array(
439
-								'html_label_text'	 	=> __( 'Site Key', 'event_espresso' ),
440
-								'html_help_text' 		=> __( 'The site key is used to display the widget on your site.', 'event_espresso' ),
441
-								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) : ''
438
+								'html_label_text'	 	=> __('Site Key', 'event_espresso'),
439
+								'html_help_text' 		=> __('The site key is used to display the widget on your site.', 'event_espresso'),
440
+								'default' 					=> isset(EE_Registry::instance()->CFG->registration->recaptcha_publickey) ? stripslashes(EE_Registry::instance()->CFG->registration->recaptcha_publickey) : ''
442 441
 							)
443 442
 						),
444 443
 						'recaptcha_privatekey' 		=> new EE_Text_Input(
445 444
 							array(
446
-								'html_label_text'	 	=> __( 'Secret Key', 'event_espresso' ),
447
-								'html_help_text' 		=> __( 'The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.', 'event_espresso' ),
448
-								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) : ''
445
+								'html_label_text'	 	=> __('Secret Key', 'event_espresso'),
446
+								'html_help_text' 		=> __('The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.', 'event_espresso'),
447
+								'default' 					=> isset(EE_Registry::instance()->CFG->registration->recaptcha_privatekey) ? stripslashes(EE_Registry::instance()->CFG->registration->recaptcha_privatekey) : ''
449 448
 							)
450 449
 						)
451 450
 					)
@@ -477,81 +476,81 @@  discard block
 block discarded – undo
477 476
 					array(
478 477
 						'recaptcha_theme' 		=> new EE_Radio_Button_Input(
479 478
 							array(
480
-								'light' => __( 'Light', 'event_espresso' ),
481
-								'dark' => __( 'Dark', 'event_espresso' )
479
+								'light' => __('Light', 'event_espresso'),
480
+								'dark' => __('Dark', 'event_espresso')
482 481
 							),
483 482
 							array(
484
-								'html_label_text'	 	=> __( 'Theme', 'event_espresso' ),
485
-								'html_help_text' 		=> __( 'The color theme of the widget.', 'event_espresso' ),
486
-								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_theme ) ? EE_Registry::instance()->CFG->registration->recaptcha_theme : 'light',
483
+								'html_label_text'	 	=> __('Theme', 'event_espresso'),
484
+								'html_help_text' 		=> __('The color theme of the widget.', 'event_espresso'),
485
+								'default' 					=> isset(EE_Registry::instance()->CFG->registration->recaptcha_theme) ? EE_Registry::instance()->CFG->registration->recaptcha_theme : 'light',
487 486
 								'display_html_label_text' => FALSE
488 487
 							)
489 488
 						),
490 489
 						'recaptcha_type' 		=> new EE_Radio_Button_Input(
491 490
 							array(
492
-								'image' => __( 'Image', 'event_espresso' ),
493
-								'audio' => __( 'Audio', 'event_espresso' )
491
+								'image' => __('Image', 'event_espresso'),
492
+								'audio' => __('Audio', 'event_espresso')
494 493
 							),
495 494
 							array(
496
-								'html_label_text'	 	=> __( 'Type', 'event_espresso' ),
497
-								'html_help_text' 		=> __( 'The type of CAPTCHA to serve.', 'event_espresso' ),
498
-								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_type ) ? EE_Registry::instance()->CFG->registration->recaptcha_type : 'image',
495
+								'html_label_text'	 	=> __('Type', 'event_espresso'),
496
+								'html_help_text' 		=> __('The type of CAPTCHA to serve.', 'event_espresso'),
497
+								'default' 					=> isset(EE_Registry::instance()->CFG->registration->recaptcha_type) ? EE_Registry::instance()->CFG->registration->recaptcha_type : 'image',
499 498
 								'display_html_label_text' =>FALSE
500 499
 							)
501 500
 						),
502 501
 						'recaptcha_language' 		=> new EE_Select_Input(
503 502
 							array(
504
-								 'ar' 			=> __( 'Arabic', 'event_espresso' ),
505
-								 'bg' 		=> __( 'Bulgarian', 'event_espresso' ),
506
-								 'ca' 			=> __( 'Catalan', 'event_espresso' ),
507
-								 'zh-CN' 	=>  __( 'Chinese (Simplified)', 'event_espresso' ),
508
-								 'zh-TW' 	=>  __( 'Chinese (Traditional)	', 'event_espresso' ),
509
-								 'hr' 			=> __( 'Croatian', 'event_espresso' ),
510
-								 'cs' 			=> __( 'Czech', 'event_espresso' ),
511
-								 'da' 			=> __( 'Danish', 'event_espresso' ),
512
-								 'nl' 			=> __( 'Dutch', 'event_espresso' ),
513
-								 'en-GB' 	=>  __( 'English (UK)', 'event_espresso' ),
514
-								 'en' 			=> __( 'English (US)', 'event_espresso' ),
515
-								 'fil' 			=> __( 'Filipino', 'event_espresso' ),
516
-								 'fi' 			=> __( 'Finnish', 'event_espresso' ),
517
-								 'fr' 			=> __( 'French', 'event_espresso' ),
518
-								 'fr-CA' 	=>  __( 'French (Canadian)', 'event_espresso' ),
519
-								 'de' 			=> __( 'German', 'event_espresso' ),
520
-								 'de-AT' 	=>  __( 'German (Austria)', 'event_espresso' ),
521
-								 'de-CH' 	=>  __( 'German (Switzerland)', 'event_espresso' ),
522
-								 'el' 			=> __( 'Greek', 'event_espresso' ),
523
-								 'iw' 			=> __( 'Hebrew', 'event_espresso' ),
524
-								 'hi' 			=> __( 'Hindi', 'event_espresso' ),
525
-								 'hu' 		=> __( 'Hungarian', 'event_espresso' ),
526
-								 'id' 			=> __( 'Indonesian', 'event_espresso' ),
527
-								 'it' 			=> __( 'Italian', 'event_espresso' ),
528
-								 'ja' 			=> __( 'Japanese', 'event_espresso' ),
529
-								 'ko' 			=> __( 'Korean', 'event_espresso' ),
530
-								 'lv' 			=> __( 'Latvian', 'event_espresso' ),
531
-								 'lt' 			=> __( 'Lithuanian', 'event_espresso' ),
532
-								 'no' 		=> __( 'Norwegian', 'event_espresso' ),
533
-								 'fa' 			=> __( 'Persian', 'event_espresso' ),
534
-								 'pl' 			=> __( 'Polish', 'event_espresso' ),
535
-								 'pt' 			=> __( 'Portuguese', 'event_espresso' ),
536
-								 'pt-BR' 	=>  __( 'Portuguese (Brazil)', 'event_espresso' ),
537
-								 'pt-PT' 	=>  __( 'Portuguese (Portugal)', 'event_espresso' ),
538
-								 'ro' 			=> __( 'Romanian', 'event_espresso' ),
539
-								 'ru' 			=> __( 'Russian', 'event_espresso' ),
540
-								 'sr' 			=> __( 'Serbian', 'event_espresso' ),
541
-								 'sk' 			=> __( 'Slovak', 'event_espresso' ),
542
-								 'sl' 			=> __( 'Slovenian', 'event_espresso' ),
543
-								 'es' 			=> __( 'Spanish', 'event_espresso' ),
544
-								 'es-419' 	=>  __( 'Spanish (Latin America)', 'event_espresso' ),
545
-								 'sv' 			=> __( 'Swedish', 'event_espresso' ),
546
-								 'th' 			=> __( 'Thai', 'event_espresso' ),
547
-								 'tr' 			=> __( 'Turkish', 'event_espresso' ),
548
-								 'uk' 			=> __( 'Ukrainian', 'event_espresso' ),
549
-								 'vi' 			=> __( 'Vietnamese', 'event_espresso')
503
+								 'ar' 			=> __('Arabic', 'event_espresso'),
504
+								 'bg' 		=> __('Bulgarian', 'event_espresso'),
505
+								 'ca' 			=> __('Catalan', 'event_espresso'),
506
+								 'zh-CN' 	=>  __('Chinese (Simplified)', 'event_espresso'),
507
+								 'zh-TW' 	=>  __('Chinese (Traditional)	', 'event_espresso'),
508
+								 'hr' 			=> __('Croatian', 'event_espresso'),
509
+								 'cs' 			=> __('Czech', 'event_espresso'),
510
+								 'da' 			=> __('Danish', 'event_espresso'),
511
+								 'nl' 			=> __('Dutch', 'event_espresso'),
512
+								 'en-GB' 	=>  __('English (UK)', 'event_espresso'),
513
+								 'en' 			=> __('English (US)', 'event_espresso'),
514
+								 'fil' 			=> __('Filipino', 'event_espresso'),
515
+								 'fi' 			=> __('Finnish', 'event_espresso'),
516
+								 'fr' 			=> __('French', 'event_espresso'),
517
+								 'fr-CA' 	=>  __('French (Canadian)', 'event_espresso'),
518
+								 'de' 			=> __('German', 'event_espresso'),
519
+								 'de-AT' 	=>  __('German (Austria)', 'event_espresso'),
520
+								 'de-CH' 	=>  __('German (Switzerland)', 'event_espresso'),
521
+								 'el' 			=> __('Greek', 'event_espresso'),
522
+								 'iw' 			=> __('Hebrew', 'event_espresso'),
523
+								 'hi' 			=> __('Hindi', 'event_espresso'),
524
+								 'hu' 		=> __('Hungarian', 'event_espresso'),
525
+								 'id' 			=> __('Indonesian', 'event_espresso'),
526
+								 'it' 			=> __('Italian', 'event_espresso'),
527
+								 'ja' 			=> __('Japanese', 'event_espresso'),
528
+								 'ko' 			=> __('Korean', 'event_espresso'),
529
+								 'lv' 			=> __('Latvian', 'event_espresso'),
530
+								 'lt' 			=> __('Lithuanian', 'event_espresso'),
531
+								 'no' 		=> __('Norwegian', 'event_espresso'),
532
+								 'fa' 			=> __('Persian', 'event_espresso'),
533
+								 'pl' 			=> __('Polish', 'event_espresso'),
534
+								 'pt' 			=> __('Portuguese', 'event_espresso'),
535
+								 'pt-BR' 	=>  __('Portuguese (Brazil)', 'event_espresso'),
536
+								 'pt-PT' 	=>  __('Portuguese (Portugal)', 'event_espresso'),
537
+								 'ro' 			=> __('Romanian', 'event_espresso'),
538
+								 'ru' 			=> __('Russian', 'event_espresso'),
539
+								 'sr' 			=> __('Serbian', 'event_espresso'),
540
+								 'sk' 			=> __('Slovak', 'event_espresso'),
541
+								 'sl' 			=> __('Slovenian', 'event_espresso'),
542
+								 'es' 			=> __('Spanish', 'event_espresso'),
543
+								 'es-419' 	=>  __('Spanish (Latin America)', 'event_espresso'),
544
+								 'sv' 			=> __('Swedish', 'event_espresso'),
545
+								 'th' 			=> __('Thai', 'event_espresso'),
546
+								 'tr' 			=> __('Turkish', 'event_espresso'),
547
+								 'uk' 			=> __('Ukrainian', 'event_espresso'),
548
+								 'vi' 			=> __('Vietnamese', 'event_espresso')
550 549
 							),
551 550
 							array(
552
-								'html_label_text'	 	=> __( 'Language', 'event_espresso' ),
553
-								'html_help_text' 		=> __( 'Forces the widget to render in a specific language.', 'event_espresso' ),
554
-								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_language ) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en'
551
+								'html_label_text'	 	=> __('Language', 'event_espresso'),
552
+								'html_help_text' 		=> __('Forces the widget to render in a specific language.', 'event_espresso'),
553
+								'default' 					=> isset(EE_Registry::instance()->CFG->registration->recaptcha_language) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en'
555 554
 							)
556 555
 						)
557 556
 					)
@@ -599,25 +598,25 @@  discard block
 block discarded – undo
599 598
 	 * @param EE_Registration_Config $EE_Registration_Config
600 599
 	 * @return array
601 600
 	 */
602
-	public static function update_admin_settings( EE_Registration_Config $EE_Registration_Config ) {
601
+	public static function update_admin_settings(EE_Registration_Config $EE_Registration_Config) {
603 602
 		try {
604 603
 			$recaptcha_settings_form = EED_Recaptcha::_recaptcha_settings_form();
605 604
 			// if not displaying a form, then check for form submission
606
-			if ( $recaptcha_settings_form->was_submitted() ) {
605
+			if ($recaptcha_settings_form->was_submitted()) {
607 606
 				// capture form data
608 607
 				$recaptcha_settings_form->receive_form_submission();
609 608
 				// validate form data
610
-				if ( $recaptcha_settings_form->is_valid() ) {
609
+				if ($recaptcha_settings_form->is_valid()) {
611 610
 					// grab validated data from form
612 611
 					$valid_data = $recaptcha_settings_form->valid_data();
613 612
 					// user proofing recaptcha:  If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message.
614 613
 					if (
615
-						apply_filters( 'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', TRUE, $EE_Registration_Config )
614
+						apply_filters('FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', TRUE, $EE_Registration_Config)
616 615
 						&& $valid_data['main_settings']['use_captcha']
617
-						&& ( ! $EE_Registration_Config->use_captcha && ( empty( $valid_data['main_settings']['recaptcha_publickey'] ) || empty( $valid_data['main_settings']['recaptcha_privatekey'] )))
616
+						&& ( ! $EE_Registration_Config->use_captcha && (empty($valid_data['main_settings']['recaptcha_publickey']) || empty($valid_data['main_settings']['recaptcha_privatekey'])))
618 617
 					) {
619 618
 						$valid_data['main_settings']['use_captcha'] = FALSE;
620
-						EE_Error::add_error( __('The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
619
+						EE_Error::add_error(__('The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
621 620
 					}
622 621
 					$EE_Registration_Config->use_captcha = $valid_data['main_settings']['use_captcha'];
623 622
 					$EE_Registration_Config->recaptcha_publickey = $valid_data['main_settings']['recaptcha_publickey'];
@@ -626,12 +625,12 @@  discard block
 block discarded – undo
626 625
 					$EE_Registration_Config->recaptcha_theme = $valid_data['appearance_settings']['recaptcha_theme'];
627 626
 					$EE_Registration_Config->recaptcha_language = $valid_data['appearance_settings']['recaptcha_language'];
628 627
 				} else {
629
-					if ( $recaptcha_settings_form->submission_error_message() != '' ) {
630
-						EE_Error::add_error( $recaptcha_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__ );
628
+					if ($recaptcha_settings_form->submission_error_message() != '') {
629
+						EE_Error::add_error($recaptcha_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__);
631 630
 					}
632 631
 				}
633 632
 			}
634
-		} catch( EE_Error $e ) {
633
+		} catch (EE_Error $e) {
635 634
 			$e->get_error();
636 635
 		}
637 636
 
Please login to merge, or discard this patch.