@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -23,2223 +23,2223 @@ discard block |
||
23 | 23 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registration |
|
28 | - */ |
|
29 | - private $_registration; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Event |
|
33 | - */ |
|
34 | - private $_reg_event; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EE_Session |
|
38 | - */ |
|
39 | - private $_session; |
|
40 | - |
|
41 | - private static $_reg_status; |
|
42 | - |
|
43 | - /** |
|
44 | - * Form for displaying the custom questions for this registration. |
|
45 | - * This gets used a few times throughout the request so its best to cache it |
|
46 | - * |
|
47 | - * @var EE_Registration_Custom_Questions_Form |
|
48 | - */ |
|
49 | - protected $_reg_custom_questions_form = null; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * constructor |
|
54 | - * |
|
55 | - * @Constructor |
|
56 | - * @access public |
|
57 | - * @param bool $routing |
|
58 | - * @return Registrations_Admin_Page |
|
59 | - */ |
|
60 | - public function __construct($routing = true) |
|
61 | - { |
|
62 | - parent::__construct($routing); |
|
63 | - add_action('wp_loaded', array($this, 'wp_loaded')); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - public function wp_loaded() |
|
68 | - { |
|
69 | - // when adding a new registration... |
|
70 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
71 | - EE_System::do_not_cache(); |
|
72 | - if (! isset($this->_req_data['processing_registration']) |
|
73 | - || absint($this->_req_data['processing_registration']) !== 1 |
|
74 | - ) { |
|
75 | - // and it's NOT the attendee information reg step |
|
76 | - // force cookie expiration by setting time to last week |
|
77 | - setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
78 | - // and update the global |
|
79 | - $_COOKIE['ee_registration_added'] = 0; |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - protected function _init_page_props() |
|
86 | - { |
|
87 | - $this->page_slug = REG_PG_SLUG; |
|
88 | - $this->_admin_base_url = REG_ADMIN_URL; |
|
89 | - $this->_admin_base_path = REG_ADMIN; |
|
90 | - $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
91 | - $this->_cpt_routes = array( |
|
92 | - 'add_new_attendee' => 'espresso_attendees', |
|
93 | - 'edit_attendee' => 'espresso_attendees', |
|
94 | - 'insert_attendee' => 'espresso_attendees', |
|
95 | - 'update_attendee' => 'espresso_attendees', |
|
96 | - ); |
|
97 | - $this->_cpt_model_names = array( |
|
98 | - 'add_new_attendee' => 'EEM_Attendee', |
|
99 | - 'edit_attendee' => 'EEM_Attendee', |
|
100 | - ); |
|
101 | - $this->_cpt_edit_routes = array( |
|
102 | - 'espresso_attendees' => 'edit_attendee', |
|
103 | - ); |
|
104 | - $this->_pagenow_map = array( |
|
105 | - 'add_new_attendee' => 'post-new.php', |
|
106 | - 'edit_attendee' => 'post.php', |
|
107 | - 'trash' => 'post.php', |
|
108 | - ); |
|
109 | - add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
110 | - //add filters so that the comment urls don't take users to a confusing 404 page |
|
111 | - add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - public function clear_comment_link($link, $comment, $args) |
|
116 | - { |
|
117 | - //gotta make sure this only happens on this route |
|
118 | - $post_type = get_post_type($comment->comment_post_ID); |
|
119 | - if ($post_type === 'espresso_attendees') { |
|
120 | - return '#commentsdiv'; |
|
121 | - } |
|
122 | - return $link; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - protected function _ajax_hooks() |
|
127 | - { |
|
128 | - //todo: all hooks for registrations ajax goes in here |
|
129 | - add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - protected function _define_page_props() |
|
134 | - { |
|
135 | - $this->_admin_page_title = $this->page_label; |
|
136 | - $this->_labels = array( |
|
137 | - 'buttons' => array( |
|
138 | - 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
139 | - 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
140 | - 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
141 | - 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
142 | - 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
143 | - 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
144 | - 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
145 | - 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
146 | - ), |
|
147 | - 'publishbox' => array( |
|
148 | - 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
149 | - 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
150 | - ), |
|
151 | - 'hide_add_button_on_cpt_route' => array( |
|
152 | - 'edit_attendee' => true, |
|
153 | - ), |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * grab url requests and route them |
|
160 | - * |
|
161 | - * @access private |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - public function _set_page_routes() |
|
165 | - { |
|
166 | - $this->_get_registration_status_array(); |
|
167 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
168 | - ? $this->_req_data['_REG_ID'] : 0; |
|
169 | - $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID']) |
|
170 | - ? $this->_req_data['reg_status_change_form']['REG_ID'] |
|
171 | - : $reg_id; |
|
172 | - $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
173 | - ? $this->_req_data['ATT_ID'] : 0; |
|
174 | - $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
175 | - ? $this->_req_data['post'] |
|
176 | - : $att_id; |
|
177 | - $this->_page_routes = array( |
|
178 | - 'default' => array( |
|
179 | - 'func' => '_registrations_overview_list_table', |
|
180 | - 'capability' => 'ee_read_registrations', |
|
181 | - ), |
|
182 | - 'view_registration' => array( |
|
183 | - 'func' => '_registration_details', |
|
184 | - 'capability' => 'ee_read_registration', |
|
185 | - 'obj_id' => $reg_id, |
|
186 | - ), |
|
187 | - 'edit_registration' => array( |
|
188 | - 'func' => '_update_attendee_registration_form', |
|
189 | - 'noheader' => true, |
|
190 | - 'headers_sent_route' => 'view_registration', |
|
191 | - 'capability' => 'ee_edit_registration', |
|
192 | - 'obj_id' => $reg_id, |
|
193 | - '_REG_ID' => $reg_id, |
|
194 | - ), |
|
195 | - 'trash_registrations' => array( |
|
196 | - 'func' => '_trash_or_restore_registrations', |
|
197 | - 'args' => array('trash' => true), |
|
198 | - 'noheader' => true, |
|
199 | - 'capability' => 'ee_delete_registrations', |
|
200 | - ), |
|
201 | - 'restore_registrations' => array( |
|
202 | - 'func' => '_trash_or_restore_registrations', |
|
203 | - 'args' => array('trash' => false), |
|
204 | - 'noheader' => true, |
|
205 | - 'capability' => 'ee_delete_registrations', |
|
206 | - ), |
|
207 | - 'delete_registrations' => array( |
|
208 | - 'func' => '_delete_registrations', |
|
209 | - 'noheader' => true, |
|
210 | - 'capability' => 'ee_delete_registrations', |
|
211 | - ), |
|
212 | - 'new_registration' => array( |
|
213 | - 'func' => 'new_registration', |
|
214 | - 'capability' => 'ee_edit_registrations', |
|
215 | - ), |
|
216 | - 'process_reg_step' => array( |
|
217 | - 'func' => 'process_reg_step', |
|
218 | - 'noheader' => true, |
|
219 | - 'capability' => 'ee_edit_registrations', |
|
220 | - ), |
|
221 | - 'redirect_to_txn' => array( |
|
222 | - 'func' => 'redirect_to_txn', |
|
223 | - 'noheader' => true, |
|
224 | - 'capability' => 'ee_edit_registrations', |
|
225 | - ), |
|
226 | - 'change_reg_status' => array( |
|
227 | - 'func' => '_change_reg_status', |
|
228 | - 'noheader' => true, |
|
229 | - 'capability' => 'ee_edit_registration', |
|
230 | - 'obj_id' => $reg_id, |
|
231 | - ), |
|
232 | - 'approve_registration' => array( |
|
233 | - 'func' => 'approve_registration', |
|
234 | - 'noheader' => true, |
|
235 | - 'capability' => 'ee_edit_registration', |
|
236 | - 'obj_id' => $reg_id, |
|
237 | - ), |
|
238 | - 'approve_and_notify_registration' => array( |
|
239 | - 'func' => 'approve_registration', |
|
240 | - 'noheader' => true, |
|
241 | - 'args' => array(true), |
|
242 | - 'capability' => 'ee_edit_registration', |
|
243 | - 'obj_id' => $reg_id, |
|
244 | - ), |
|
245 | - 'approve_registrations' => array( |
|
246 | - 'func' => 'bulk_action_on_registrations', |
|
247 | - 'noheader' => true, |
|
248 | - 'capability' => 'ee_edit_registrations', |
|
249 | - 'args' => array('approve') |
|
250 | - ), |
|
251 | - 'approve_and_notify_registrations' => array( |
|
252 | - 'func' => 'bulk_action_on_registrations', |
|
253 | - 'noheader' => true, |
|
254 | - 'capability' => 'ee_edit_registrations', |
|
255 | - 'args' => array('approve', true) |
|
256 | - ), |
|
257 | - 'decline_registration' => array( |
|
258 | - 'func' => 'decline_registration', |
|
259 | - 'noheader' => true, |
|
260 | - 'capability' => 'ee_edit_registration', |
|
261 | - 'obj_id' => $reg_id, |
|
262 | - ), |
|
263 | - 'decline_and_notify_registration' => array( |
|
264 | - 'func' => 'decline_registration', |
|
265 | - 'noheader' => true, |
|
266 | - 'args' => array(true), |
|
267 | - 'capability' => 'ee_edit_registration', |
|
268 | - 'obj_id' => $reg_id, |
|
269 | - ), |
|
270 | - 'decline_registrations' => array( |
|
271 | - 'func' => 'bulk_action_on_registrations', |
|
272 | - 'noheader' => true, |
|
273 | - 'capability' => 'ee_edit_registrations', |
|
274 | - 'args' => array('decline') |
|
275 | - ), |
|
276 | - 'decline_and_notify_registrations' => array( |
|
277 | - 'func' => 'bulk_action_on_registrations', |
|
278 | - 'noheader' => true, |
|
279 | - 'capability' => 'ee_edit_registrations', |
|
280 | - 'args' => array('decline', true) |
|
281 | - ), |
|
282 | - 'pending_registration' => array( |
|
283 | - 'func' => 'pending_registration', |
|
284 | - 'noheader' => true, |
|
285 | - 'capability' => 'ee_edit_registration', |
|
286 | - 'obj_id' => $reg_id, |
|
287 | - ), |
|
288 | - 'pending_and_notify_registration' => array( |
|
289 | - 'func' => 'pending_registration', |
|
290 | - 'noheader' => true, |
|
291 | - 'args' => array(true), |
|
292 | - 'capability' => 'ee_edit_registration', |
|
293 | - 'obj_id' => $reg_id, |
|
294 | - ), |
|
295 | - 'pending_registrations' => array( |
|
296 | - 'func' => 'bulk_action_on_registrations', |
|
297 | - 'noheader' => true, |
|
298 | - 'capability' => 'ee_edit_registrations', |
|
299 | - 'args' => array('pending') |
|
300 | - ), |
|
301 | - 'pending_and_notify_registrations' => array( |
|
302 | - 'func' => 'bulk_action_on_registrations', |
|
303 | - 'noheader' => true, |
|
304 | - 'capability' => 'ee_edit_registrations', |
|
305 | - 'args' => array('pending', true) |
|
306 | - ), |
|
307 | - 'no_approve_registration' => array( |
|
308 | - 'func' => 'not_approve_registration', |
|
309 | - 'noheader' => true, |
|
310 | - 'capability' => 'ee_edit_registration', |
|
311 | - 'obj_id' => $reg_id, |
|
312 | - ), |
|
313 | - 'no_approve_and_notify_registration' => array( |
|
314 | - 'func' => 'not_approve_registration', |
|
315 | - 'noheader' => true, |
|
316 | - 'args' => array(true), |
|
317 | - 'capability' => 'ee_edit_registration', |
|
318 | - 'obj_id' => $reg_id, |
|
319 | - ), |
|
320 | - 'no_approve_registrations' => array( |
|
321 | - 'func' => 'bulk_action_on_registrations', |
|
322 | - 'noheader' => true, |
|
323 | - 'capability' => 'ee_edit_registrations', |
|
324 | - 'args' => array('not_approve') |
|
325 | - ), |
|
326 | - 'no_approve_and_notify_registrations' => array( |
|
327 | - 'func' => 'bulk_action_on_registrations', |
|
328 | - 'noheader' => true, |
|
329 | - 'capability' => 'ee_edit_registrations', |
|
330 | - 'args' => array('not_approve', true) |
|
331 | - ), |
|
332 | - 'cancel_registration' => array( |
|
333 | - 'func' => 'cancel_registration', |
|
334 | - 'noheader' => true, |
|
335 | - 'capability' => 'ee_edit_registration', |
|
336 | - 'obj_id' => $reg_id, |
|
337 | - ), |
|
338 | - 'cancel_and_notify_registration' => array( |
|
339 | - 'func' => 'cancel_registration', |
|
340 | - 'noheader' => true, |
|
341 | - 'args' => array(true), |
|
342 | - 'capability' => 'ee_edit_registration', |
|
343 | - 'obj_id' => $reg_id, |
|
344 | - ), |
|
345 | - 'cancel_registrations' => array( |
|
346 | - 'func' => 'bulk_action_on_registrations', |
|
347 | - 'noheader' => true, |
|
348 | - 'capability' => 'ee_edit_registrations', |
|
349 | - 'args' => array('cancel') |
|
350 | - ), |
|
351 | - 'cancel_and_notify_registrations' => array( |
|
352 | - 'func' => 'bulk_action_on_registrations', |
|
353 | - 'noheader' => true, |
|
354 | - 'capability' => 'ee_edit_registrations', |
|
355 | - 'args' => array('cancel', true) |
|
356 | - ), |
|
357 | - 'wait_list_registration' => array( |
|
358 | - 'func' => 'wait_list_registration', |
|
359 | - 'noheader' => true, |
|
360 | - 'capability' => 'ee_edit_registration', |
|
361 | - 'obj_id' => $reg_id, |
|
362 | - ), |
|
363 | - 'contact_list' => array( |
|
364 | - 'func' => '_attendee_contact_list_table', |
|
365 | - 'capability' => 'ee_read_contacts', |
|
366 | - ), |
|
367 | - 'add_new_attendee' => array( |
|
368 | - 'func' => '_create_new_cpt_item', |
|
369 | - 'args' => array( |
|
370 | - 'new_attendee' => true, |
|
371 | - 'capability' => 'ee_edit_contacts', |
|
372 | - ), |
|
373 | - ), |
|
374 | - 'edit_attendee' => array( |
|
375 | - 'func' => '_edit_cpt_item', |
|
376 | - 'capability' => 'ee_edit_contacts', |
|
377 | - 'obj_id' => $att_id, |
|
378 | - ), |
|
379 | - 'duplicate_attendee' => array( |
|
380 | - 'func' => '_duplicate_attendee', |
|
381 | - 'noheader' => true, |
|
382 | - 'capability' => 'ee_edit_contacts', |
|
383 | - 'obj_id' => $att_id, |
|
384 | - ), |
|
385 | - 'insert_attendee' => array( |
|
386 | - 'func' => '_insert_or_update_attendee', |
|
387 | - 'args' => array( |
|
388 | - 'new_attendee' => true, |
|
389 | - ), |
|
390 | - 'noheader' => true, |
|
391 | - 'capability' => 'ee_edit_contacts', |
|
392 | - ), |
|
393 | - 'update_attendee' => array( |
|
394 | - 'func' => '_insert_or_update_attendee', |
|
395 | - 'args' => array( |
|
396 | - 'new_attendee' => false, |
|
397 | - ), |
|
398 | - 'noheader' => true, |
|
399 | - 'capability' => 'ee_edit_contacts', |
|
400 | - 'obj_id' => $att_id, |
|
401 | - ), |
|
402 | - 'trash_attendees' => array( |
|
403 | - 'func' => '_trash_or_restore_attendees', |
|
404 | - 'args' => array( |
|
405 | - 'trash' => 'true' |
|
406 | - ), |
|
407 | - 'noheader' => true, |
|
408 | - 'capability' => 'ee_delete_contacts' |
|
409 | - ), |
|
410 | - 'trash_attendee' => array( |
|
411 | - 'func' => '_trash_or_restore_attendees', |
|
412 | - 'args' => array( |
|
413 | - 'trash' => true, |
|
414 | - ), |
|
415 | - 'noheader' => true, |
|
416 | - 'capability' => 'ee_delete_contacts', |
|
417 | - 'obj_id' => $att_id, |
|
418 | - ), |
|
419 | - 'restore_attendees' => array( |
|
420 | - 'func' => '_trash_or_restore_attendees', |
|
421 | - 'args' => array( |
|
422 | - 'trash' => false, |
|
423 | - ), |
|
424 | - 'noheader' => true, |
|
425 | - 'capability' => 'ee_delete_contacts', |
|
426 | - 'obj_id' => $att_id, |
|
427 | - ), |
|
428 | - 'resend_registration' => array( |
|
429 | - 'func' => '_resend_registration', |
|
430 | - 'noheader' => true, |
|
431 | - 'capability' => 'ee_send_message', |
|
432 | - ), |
|
433 | - 'registrations_report' => array( |
|
434 | - 'func' => '_registrations_report', |
|
435 | - 'noheader' => true, |
|
436 | - 'capability' => 'ee_read_registrations', |
|
437 | - ), |
|
438 | - 'contact_list_export' => array( |
|
439 | - 'func' => '_contact_list_export', |
|
440 | - 'noheader' => true, |
|
441 | - 'capability' => 'export', |
|
442 | - ), |
|
443 | - 'contact_list_report' => array( |
|
444 | - 'func' => '_contact_list_report', |
|
445 | - 'noheader' => true, |
|
446 | - 'capability' => 'ee_read_contacts', |
|
447 | - ), |
|
448 | - ); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - protected function _set_page_config() |
|
453 | - { |
|
454 | - $this->_page_config = array( |
|
455 | - 'default' => array( |
|
456 | - 'nav' => array( |
|
457 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
458 | - 'order' => 5, |
|
459 | - ), |
|
460 | - 'help_tabs' => array( |
|
461 | - 'registrations_overview_help_tab' => array( |
|
462 | - 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
463 | - 'filename' => 'registrations_overview', |
|
464 | - ), |
|
465 | - 'registrations_overview_table_column_headings_help_tab' => array( |
|
466 | - 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
467 | - 'filename' => 'registrations_overview_table_column_headings', |
|
468 | - ), |
|
469 | - 'registrations_overview_filters_help_tab' => array( |
|
470 | - 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
471 | - 'filename' => 'registrations_overview_filters', |
|
472 | - ), |
|
473 | - 'registrations_overview_views_help_tab' => array( |
|
474 | - 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
475 | - 'filename' => 'registrations_overview_views', |
|
476 | - ), |
|
477 | - 'registrations_regoverview_other_help_tab' => array( |
|
478 | - 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
479 | - 'filename' => 'registrations_overview_other', |
|
480 | - ), |
|
481 | - ), |
|
482 | - 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
483 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
484 | - 'list_table' => 'EE_Registrations_List_Table', |
|
485 | - 'require_nonce' => false, |
|
486 | - ), |
|
487 | - 'view_registration' => array( |
|
488 | - 'nav' => array( |
|
489 | - 'label' => esc_html__('REG Details', 'event_espresso'), |
|
490 | - 'order' => 15, |
|
491 | - 'url' => isset($this->_req_data['_REG_ID']) |
|
492 | - ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
493 | - : $this->_admin_base_url, |
|
494 | - 'persistent' => false, |
|
495 | - ), |
|
496 | - 'help_tabs' => array( |
|
497 | - 'registrations_details_help_tab' => array( |
|
498 | - 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
499 | - 'filename' => 'registrations_details', |
|
500 | - ), |
|
501 | - 'registrations_details_table_help_tab' => array( |
|
502 | - 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
503 | - 'filename' => 'registrations_details_table', |
|
504 | - ), |
|
505 | - 'registrations_details_form_answers_help_tab' => array( |
|
506 | - 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
507 | - 'filename' => 'registrations_details_form_answers', |
|
508 | - ), |
|
509 | - 'registrations_details_registrant_details_help_tab' => array( |
|
510 | - 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
511 | - 'filename' => 'registrations_details_registrant_details', |
|
512 | - ), |
|
513 | - ), |
|
514 | - 'help_tour' => array('Registration_Details_Help_Tour'), |
|
515 | - 'metaboxes' => array_merge( |
|
516 | - $this->_default_espresso_metaboxes, |
|
517 | - array('_registration_details_metaboxes') |
|
518 | - ), |
|
519 | - 'require_nonce' => false, |
|
520 | - ), |
|
521 | - 'new_registration' => array( |
|
522 | - 'nav' => array( |
|
523 | - 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
524 | - 'url' => '#', |
|
525 | - 'order' => 15, |
|
526 | - 'persistent' => false, |
|
527 | - ), |
|
528 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
529 | - 'labels' => array( |
|
530 | - 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
531 | - ), |
|
532 | - 'require_nonce' => false, |
|
533 | - ), |
|
534 | - 'add_new_attendee' => array( |
|
535 | - 'nav' => array( |
|
536 | - 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
537 | - 'order' => 15, |
|
538 | - 'persistent' => false, |
|
539 | - ), |
|
540 | - 'metaboxes' => array_merge( |
|
541 | - $this->_default_espresso_metaboxes, |
|
542 | - array('_publish_post_box', 'attendee_editor_metaboxes') |
|
543 | - ), |
|
544 | - 'require_nonce' => false, |
|
545 | - ), |
|
546 | - 'edit_attendee' => array( |
|
547 | - 'nav' => array( |
|
548 | - 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
549 | - 'order' => 15, |
|
550 | - 'persistent' => false, |
|
551 | - 'url' => isset($this->_req_data['ATT_ID']) |
|
552 | - ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
553 | - : $this->_admin_base_url, |
|
554 | - ), |
|
555 | - 'metaboxes' => array('attendee_editor_metaboxes'), |
|
556 | - 'require_nonce' => false, |
|
557 | - ), |
|
558 | - 'contact_list' => array( |
|
559 | - 'nav' => array( |
|
560 | - 'label' => esc_html__('Contact List', 'event_espresso'), |
|
561 | - 'order' => 20, |
|
562 | - ), |
|
563 | - 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
564 | - 'help_tabs' => array( |
|
565 | - 'registrations_contact_list_help_tab' => array( |
|
566 | - 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
567 | - 'filename' => 'registrations_contact_list', |
|
568 | - ), |
|
569 | - 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
570 | - 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
571 | - 'filename' => 'registrations_contact_list_table_column_headings', |
|
572 | - ), |
|
573 | - 'registrations_contact_list_views_help_tab' => array( |
|
574 | - 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
575 | - 'filename' => 'registrations_contact_list_views', |
|
576 | - ), |
|
577 | - 'registrations_contact_list_other_help_tab' => array( |
|
578 | - 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
579 | - 'filename' => 'registrations_contact_list_other', |
|
580 | - ), |
|
581 | - ), |
|
582 | - 'help_tour' => array('Contact_List_Help_Tour'), |
|
583 | - 'metaboxes' => array(), |
|
584 | - 'require_nonce' => false, |
|
585 | - ), |
|
586 | - //override default cpt routes |
|
587 | - 'create_new' => '', |
|
588 | - 'edit' => '', |
|
589 | - ); |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * The below methods aren't used by this class currently |
|
595 | - */ |
|
596 | - protected function _add_screen_options() |
|
597 | - { |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - protected function _add_feature_pointers() |
|
602 | - { |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - public function admin_init() |
|
607 | - { |
|
608 | - EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
609 | - 'click "Update Registration Questions" to save your changes', |
|
610 | - 'event_espresso' |
|
611 | - ); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - public function admin_notices() |
|
616 | - { |
|
617 | - } |
|
618 | - |
|
619 | - |
|
620 | - public function admin_footer_scripts() |
|
621 | - { |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - /** |
|
626 | - * get list of registration statuses |
|
627 | - * |
|
628 | - * @access private |
|
629 | - * @return void |
|
630 | - */ |
|
631 | - private function _get_registration_status_array() |
|
632 | - { |
|
633 | - self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - protected function _add_screen_options_default() |
|
638 | - { |
|
639 | - $this->_per_page_screen_option(); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - protected function _add_screen_options_contact_list() |
|
644 | - { |
|
645 | - $page_title = $this->_admin_page_title; |
|
646 | - $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
647 | - $this->_per_page_screen_option(); |
|
648 | - $this->_admin_page_title = $page_title; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - public function load_scripts_styles() |
|
653 | - { |
|
654 | - //style |
|
655 | - wp_register_style( |
|
656 | - 'espresso_reg', |
|
657 | - REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
658 | - array('ee-admin-css'), |
|
659 | - EVENT_ESPRESSO_VERSION |
|
660 | - ); |
|
661 | - wp_enqueue_style('espresso_reg'); |
|
662 | - //script |
|
663 | - wp_register_script( |
|
664 | - 'espresso_reg', |
|
665 | - REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
666 | - array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
667 | - EVENT_ESPRESSO_VERSION, |
|
668 | - true |
|
669 | - ); |
|
670 | - wp_enqueue_script('espresso_reg'); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - public function load_scripts_styles_edit_attendee() |
|
675 | - { |
|
676 | - //stuff to only show up on our attendee edit details page. |
|
677 | - $attendee_details_translations = array( |
|
678 | - 'att_publish_text' => sprintf( |
|
679 | - esc_html__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
680 | - $this->_cpt_model_obj->get_datetime('ATT_created') |
|
681 | - ), |
|
682 | - ); |
|
683 | - wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
684 | - wp_enqueue_script('jquery-validate'); |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - public function load_scripts_styles_view_registration() |
|
689 | - { |
|
690 | - //styles |
|
691 | - wp_enqueue_style('espresso-ui-theme'); |
|
692 | - //scripts |
|
693 | - $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
694 | - $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - public function load_scripts_styles_contact_list() |
|
699 | - { |
|
700 | - wp_deregister_style('espresso_reg'); |
|
701 | - wp_register_style( |
|
702 | - 'espresso_att', |
|
703 | - REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
704 | - array('ee-admin-css'), |
|
705 | - EVENT_ESPRESSO_VERSION |
|
706 | - ); |
|
707 | - wp_enqueue_style('espresso_att'); |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - public function load_scripts_styles_new_registration() |
|
712 | - { |
|
713 | - wp_register_script( |
|
714 | - 'ee-spco-for-admin', |
|
715 | - REG_ASSETS_URL . 'spco_for_admin.js', |
|
716 | - array('underscore', 'jquery'), |
|
717 | - EVENT_ESPRESSO_VERSION, |
|
718 | - true |
|
719 | - ); |
|
720 | - wp_enqueue_script('ee-spco-for-admin'); |
|
721 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
722 | - EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
723 | - EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
724 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
725 | - } |
|
726 | - |
|
727 | - |
|
728 | - public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
729 | - { |
|
730 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
731 | - } |
|
732 | - |
|
733 | - |
|
734 | - public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
735 | - { |
|
736 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - protected function _set_list_table_views_default() |
|
741 | - { |
|
742 | - //for notification related bulk actions we need to make sure only active messengers have an option. |
|
743 | - EED_Messages::set_autoloaders(); |
|
744 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
745 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
746 | - $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
747 | - //key= bulk_action_slug, value= message type. |
|
748 | - $match_array = array( |
|
749 | - 'approve_registrations' => 'registration', |
|
750 | - 'decline_registrations' => 'declined_registration', |
|
751 | - 'pending_registrations' => 'pending_approval', |
|
752 | - 'no_approve_registrations' => 'not_approved_registration', |
|
753 | - 'cancel_registrations' => 'cancelled_registration', |
|
754 | - ); |
|
755 | - $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
756 | - 'ee_send_message', |
|
757 | - 'batch_send_messages' |
|
758 | - ); |
|
759 | - /** setup reg status bulk actions **/ |
|
760 | - $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
761 | - if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
762 | - $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
763 | - 'Approve and Notify Registrations', |
|
764 | - 'event_espresso' |
|
765 | - ); |
|
766 | - } |
|
767 | - $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
768 | - if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
769 | - $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
770 | - 'Decline and Notify Registrations', |
|
771 | - 'event_espresso' |
|
772 | - ); |
|
773 | - } |
|
774 | - $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
775 | - 'Set Registrations to Pending Payment', |
|
776 | - 'event_espresso' |
|
777 | - ); |
|
778 | - if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
779 | - $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
780 | - 'Set Registrations to Pending Payment and Notify', |
|
781 | - 'event_espresso' |
|
782 | - ); |
|
783 | - } |
|
784 | - $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
785 | - 'Set Registrations to Not Approved', |
|
786 | - 'event_espresso' |
|
787 | - ); |
|
788 | - if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
789 | - $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
790 | - 'Set Registrations to Not Approved and Notify', |
|
791 | - 'event_espresso' |
|
792 | - ); |
|
793 | - } |
|
794 | - $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
795 | - if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
796 | - $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
797 | - 'Cancel Registrations and Notify', |
|
798 | - 'event_espresso' |
|
799 | - ); |
|
800 | - } |
|
801 | - $def_reg_status_actions = apply_filters( |
|
802 | - 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
803 | - $def_reg_status_actions, |
|
804 | - $active_mts |
|
805 | - ); |
|
806 | - |
|
807 | - $this->_views = array( |
|
808 | - 'all' => array( |
|
809 | - 'slug' => 'all', |
|
810 | - 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
811 | - 'count' => 0, |
|
812 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
813 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
814 | - )), |
|
815 | - ), |
|
816 | - 'month' => array( |
|
817 | - 'slug' => 'month', |
|
818 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
819 | - 'count' => 0, |
|
820 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
821 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
822 | - )), |
|
823 | - ), |
|
824 | - 'today' => array( |
|
825 | - 'slug' => 'today', |
|
826 | - 'label' => sprintf( |
|
827 | - esc_html__('Today - %s', 'event_espresso'), |
|
828 | - date('M d, Y', current_time('timestamp')) |
|
829 | - ), |
|
830 | - 'count' => 0, |
|
831 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
832 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
833 | - )), |
|
834 | - ), |
|
835 | - ); |
|
836 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
837 | - 'ee_delete_registrations', |
|
838 | - 'espresso_registrations_delete_registration' |
|
839 | - )) { |
|
840 | - $this->_views['incomplete'] = array( |
|
841 | - 'slug' => 'incomplete', |
|
842 | - 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
843 | - 'count' => 0, |
|
844 | - 'bulk_action' => array( |
|
845 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
846 | - ), |
|
847 | - ); |
|
848 | - $this->_views['trash'] = array( |
|
849 | - 'slug' => 'trash', |
|
850 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
851 | - 'count' => 0, |
|
852 | - 'bulk_action' => array( |
|
853 | - 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
854 | - 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
855 | - ), |
|
856 | - ); |
|
857 | - } |
|
858 | - } |
|
859 | - |
|
860 | - |
|
861 | - protected function _set_list_table_views_contact_list() |
|
862 | - { |
|
863 | - $this->_views = array( |
|
864 | - 'in_use' => array( |
|
865 | - 'slug' => 'in_use', |
|
866 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
867 | - 'count' => 0, |
|
868 | - 'bulk_action' => array( |
|
869 | - 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
870 | - ), |
|
871 | - ), |
|
872 | - ); |
|
873 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
874 | - 'espresso_registrations_trash_attendees') |
|
875 | - ) { |
|
876 | - $this->_views['trash'] = array( |
|
877 | - 'slug' => 'trash', |
|
878 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
879 | - 'count' => 0, |
|
880 | - 'bulk_action' => array( |
|
881 | - 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
882 | - ), |
|
883 | - ); |
|
884 | - } |
|
885 | - } |
|
886 | - |
|
887 | - |
|
888 | - protected function _registration_legend_items() |
|
889 | - { |
|
890 | - $fc_items = array( |
|
891 | - 'star-icon' => array( |
|
892 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
893 | - 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
894 | - ), |
|
895 | - 'view_details' => array( |
|
896 | - 'class' => 'dashicons dashicons-clipboard', |
|
897 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
898 | - ), |
|
899 | - 'edit_attendee' => array( |
|
900 | - 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
901 | - 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
902 | - ), |
|
903 | - 'view_transaction' => array( |
|
904 | - 'class' => 'dashicons dashicons-cart', |
|
905 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
906 | - ), |
|
907 | - 'view_invoice' => array( |
|
908 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
909 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
910 | - ), |
|
911 | - ); |
|
912 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
913 | - 'ee_send_message', |
|
914 | - 'espresso_registrations_resend_registration' |
|
915 | - )) { |
|
916 | - $fc_items['resend_registration'] = array( |
|
917 | - 'class' => 'dashicons dashicons-email-alt', |
|
918 | - 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
919 | - ); |
|
920 | - } else { |
|
921 | - $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
922 | - } |
|
923 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
924 | - 'ee_read_global_messages', |
|
925 | - 'view_filtered_messages' |
|
926 | - )) { |
|
927 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
928 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
929 | - $fc_items['view_related_messages'] = array( |
|
930 | - 'class' => $related_for_icon['css_class'], |
|
931 | - 'desc' => $related_for_icon['label'], |
|
932 | - ); |
|
933 | - } |
|
934 | - } |
|
935 | - $sc_items = array( |
|
936 | - 'approved_status' => array( |
|
937 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
938 | - 'desc' => EEH_Template::pretty_status( |
|
939 | - EEM_Registration::status_id_approved, |
|
940 | - false, |
|
941 | - 'sentence' |
|
942 | - ), |
|
943 | - ), |
|
944 | - 'pending_status' => array( |
|
945 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
946 | - 'desc' => EEH_Template::pretty_status( |
|
947 | - EEM_Registration::status_id_pending_payment, |
|
948 | - false, |
|
949 | - 'sentence' |
|
950 | - ), |
|
951 | - ), |
|
952 | - 'wait_list' => array( |
|
953 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
954 | - 'desc' => EEH_Template::pretty_status( |
|
955 | - EEM_Registration::status_id_wait_list, |
|
956 | - false, |
|
957 | - 'sentence' |
|
958 | - ), |
|
959 | - ), |
|
960 | - 'incomplete_status' => array( |
|
961 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
962 | - 'desc' => EEH_Template::pretty_status( |
|
963 | - EEM_Registration::status_id_incomplete, |
|
964 | - false, |
|
965 | - 'sentence' |
|
966 | - ), |
|
967 | - ), |
|
968 | - 'not_approved' => array( |
|
969 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
970 | - 'desc' => EEH_Template::pretty_status( |
|
971 | - EEM_Registration::status_id_not_approved, |
|
972 | - false, |
|
973 | - 'sentence' |
|
974 | - ), |
|
975 | - ), |
|
976 | - 'declined_status' => array( |
|
977 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
978 | - 'desc' => EEH_Template::pretty_status( |
|
979 | - EEM_Registration::status_id_declined, |
|
980 | - false, |
|
981 | - 'sentence' |
|
982 | - ), |
|
983 | - ), |
|
984 | - 'cancelled_status' => array( |
|
985 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
986 | - 'desc' => EEH_Template::pretty_status( |
|
987 | - EEM_Registration::status_id_cancelled, |
|
988 | - false, |
|
989 | - 'sentence' |
|
990 | - ), |
|
991 | - ), |
|
992 | - ); |
|
993 | - return array_merge($fc_items, $sc_items); |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - |
|
998 | - /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
999 | - /** |
|
1000 | - * @throws \EE_Error |
|
1001 | - */ |
|
1002 | - protected function _registrations_overview_list_table() |
|
1003 | - { |
|
1004 | - $this->_template_args['admin_page_header'] = ''; |
|
1005 | - $EVT_ID = ! empty($this->_req_data['event_id']) |
|
1006 | - ? absint($this->_req_data['event_id']) |
|
1007 | - : 0; |
|
1008 | - if ($EVT_ID) { |
|
1009 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
1010 | - 'ee_edit_registrations', |
|
1011 | - 'espresso_registrations_new_registration', |
|
1012 | - $EVT_ID |
|
1013 | - )) { |
|
1014 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
1015 | - 'new_registration', |
|
1016 | - 'add-registrant', |
|
1017 | - array('event_id' => $EVT_ID), |
|
1018 | - 'add-new-h2' |
|
1019 | - ); |
|
1020 | - } |
|
1021 | - $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
1022 | - if ($event instanceof EE_Event) { |
|
1023 | - $this->_template_args['admin_page_header'] = sprintf( |
|
1024 | - esc_html__( |
|
1025 | - '%s Viewing registrations for the event: %s%s', |
|
1026 | - 'event_espresso' |
|
1027 | - ), |
|
1028 | - '<h3 style="line-height:1.5em;">', |
|
1029 | - '<br /><a href="' |
|
1030 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
1031 | - array( |
|
1032 | - 'action' => 'edit', |
|
1033 | - 'post' => $event->ID(), |
|
1034 | - ), |
|
1035 | - EVENTS_ADMIN_URL |
|
1036 | - ) |
|
1037 | - . '"> ' |
|
1038 | - . $event->get('EVT_name') |
|
1039 | - . ' </a> ', |
|
1040 | - '</h3>' |
|
1041 | - ); |
|
1042 | - } |
|
1043 | - $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
1044 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1045 | - if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
1046 | - $this->_template_args['admin_page_header'] = substr( |
|
1047 | - $this->_template_args['admin_page_header'], |
|
1048 | - 0, |
|
1049 | - -5 |
|
1050 | - ); |
|
1051 | - $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
1052 | - $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1053 | - $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
1054 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
1055 | - $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
1056 | - } |
|
1057 | - } |
|
1058 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
1059 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * This sets the _registration property for the registration details screen |
|
1065 | - * |
|
1066 | - * @access private |
|
1067 | - * @return bool |
|
1068 | - */ |
|
1069 | - private function _set_registration_object() |
|
1070 | - { |
|
1071 | - //get out if we've already set the object |
|
1072 | - if (is_object($this->_registration)) { |
|
1073 | - return true; |
|
1074 | - } |
|
1075 | - $REG = EEM_Registration::instance(); |
|
1076 | - $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
1077 | - if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
1078 | - return true; |
|
1079 | - } else { |
|
1080 | - $error_msg = sprintf( |
|
1081 | - esc_html__( |
|
1082 | - 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
1083 | - 'event_espresso' |
|
1084 | - ), |
|
1085 | - $REG_ID |
|
1086 | - ); |
|
1087 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
1088 | - $this->_registration = null; |
|
1089 | - return false; |
|
1090 | - } |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * Used to retrieve registrations for the list table. |
|
1096 | - * |
|
1097 | - * @param int $per_page |
|
1098 | - * @param bool $count |
|
1099 | - * @param bool $this_month |
|
1100 | - * @param bool $today |
|
1101 | - * @return EE_Registration[]|int |
|
1102 | - * @throws EE_Error |
|
1103 | - */ |
|
1104 | - public function get_registrations( |
|
1105 | - $per_page = 10, |
|
1106 | - $count = false, |
|
1107 | - $this_month = false, |
|
1108 | - $today = false |
|
1109 | - ) { |
|
1110 | - if ($this_month) { |
|
1111 | - $this->_req_data['status'] = 'month'; |
|
1112 | - } |
|
1113 | - if ($today) { |
|
1114 | - $this->_req_data['status'] = 'today'; |
|
1115 | - } |
|
1116 | - $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
1117 | - /** |
|
1118 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1119 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1120 | - * @see EEM_Base::get_all() |
|
1121 | - */ |
|
1122 | - $query_params['group_by'] = ''; |
|
1123 | - |
|
1124 | - return $count |
|
1125 | - ? EEM_Registration::instance()->count($query_params) |
|
1126 | - /** @type EE_Registration[] */ |
|
1127 | - : EEM_Registration::instance()->get_all($query_params); |
|
1128 | - } |
|
1129 | - |
|
1130 | - |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
1134 | - * Note: this listens to values on the request for some of the query parameters. |
|
1135 | - * |
|
1136 | - * @param array $request |
|
1137 | - * @param int $per_page |
|
1138 | - * @param bool $count |
|
1139 | - * @return array |
|
1140 | - */ |
|
1141 | - protected function _get_registration_query_parameters( |
|
1142 | - $request = array(), |
|
1143 | - $per_page = 10, |
|
1144 | - $count = false |
|
1145 | - ) { |
|
1146 | - |
|
1147 | - $query_params = array( |
|
1148 | - 0 => $this->_get_where_conditions_for_registrations_query( |
|
1149 | - $request |
|
1150 | - ), |
|
1151 | - 'caps' => EEM_Registration::caps_read_admin, |
|
1152 | - 'default_where_conditions' => 'this_model_only', |
|
1153 | - ); |
|
1154 | - if (! $count) { |
|
1155 | - $query_params = array_merge( |
|
1156 | - $query_params, |
|
1157 | - $this->_get_orderby_for_registrations_query(), |
|
1158 | - $this->_get_limit($per_page) |
|
1159 | - ); |
|
1160 | - } |
|
1161 | - |
|
1162 | - return $query_params; |
|
1163 | - } |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
1168 | - * |
|
1169 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
1170 | - * @return array |
|
1171 | - */ |
|
1172 | - protected function _add_event_id_to_where_conditions(array $request) |
|
1173 | - { |
|
1174 | - $where = array(); |
|
1175 | - if (! empty($request['event_id'])) { |
|
1176 | - $where['EVT_ID'] = absint($request['event_id']); |
|
1177 | - } |
|
1178 | - return $where; |
|
1179 | - } |
|
1180 | - |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
1184 | - * |
|
1185 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
1186 | - * @return array |
|
1187 | - */ |
|
1188 | - protected function _add_category_id_to_where_conditions(array $request) |
|
1189 | - { |
|
1190 | - $where = array(); |
|
1191 | - if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
1192 | - $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
1193 | - } |
|
1194 | - return $where; |
|
1195 | - } |
|
1196 | - |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
1200 | - * |
|
1201 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
1202 | - * @return array |
|
1203 | - */ |
|
1204 | - protected function _add_datetime_id_to_where_conditions(array $request) |
|
1205 | - { |
|
1206 | - $where = array(); |
|
1207 | - if (! empty($request['datetime_id'])) { |
|
1208 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
1209 | - } |
|
1210 | - if (! empty($request['DTT_ID'])) { |
|
1211 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
1212 | - } |
|
1213 | - return $where; |
|
1214 | - } |
|
1215 | - |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
1219 | - * |
|
1220 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
1221 | - * @return array |
|
1222 | - */ |
|
1223 | - protected function _add_registration_status_to_where_conditions(array $request) |
|
1224 | - { |
|
1225 | - $where = array(); |
|
1226 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
1227 | - $registration_status = ! empty($request['_reg_status']) |
|
1228 | - ? sanitize_text_field($request['_reg_status']) |
|
1229 | - : ''; |
|
1230 | - |
|
1231 | - /* |
|
26 | + /** |
|
27 | + * @var EE_Registration |
|
28 | + */ |
|
29 | + private $_registration; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Event |
|
33 | + */ |
|
34 | + private $_reg_event; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EE_Session |
|
38 | + */ |
|
39 | + private $_session; |
|
40 | + |
|
41 | + private static $_reg_status; |
|
42 | + |
|
43 | + /** |
|
44 | + * Form for displaying the custom questions for this registration. |
|
45 | + * This gets used a few times throughout the request so its best to cache it |
|
46 | + * |
|
47 | + * @var EE_Registration_Custom_Questions_Form |
|
48 | + */ |
|
49 | + protected $_reg_custom_questions_form = null; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * constructor |
|
54 | + * |
|
55 | + * @Constructor |
|
56 | + * @access public |
|
57 | + * @param bool $routing |
|
58 | + * @return Registrations_Admin_Page |
|
59 | + */ |
|
60 | + public function __construct($routing = true) |
|
61 | + { |
|
62 | + parent::__construct($routing); |
|
63 | + add_action('wp_loaded', array($this, 'wp_loaded')); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + public function wp_loaded() |
|
68 | + { |
|
69 | + // when adding a new registration... |
|
70 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
71 | + EE_System::do_not_cache(); |
|
72 | + if (! isset($this->_req_data['processing_registration']) |
|
73 | + || absint($this->_req_data['processing_registration']) !== 1 |
|
74 | + ) { |
|
75 | + // and it's NOT the attendee information reg step |
|
76 | + // force cookie expiration by setting time to last week |
|
77 | + setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
78 | + // and update the global |
|
79 | + $_COOKIE['ee_registration_added'] = 0; |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + protected function _init_page_props() |
|
86 | + { |
|
87 | + $this->page_slug = REG_PG_SLUG; |
|
88 | + $this->_admin_base_url = REG_ADMIN_URL; |
|
89 | + $this->_admin_base_path = REG_ADMIN; |
|
90 | + $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
91 | + $this->_cpt_routes = array( |
|
92 | + 'add_new_attendee' => 'espresso_attendees', |
|
93 | + 'edit_attendee' => 'espresso_attendees', |
|
94 | + 'insert_attendee' => 'espresso_attendees', |
|
95 | + 'update_attendee' => 'espresso_attendees', |
|
96 | + ); |
|
97 | + $this->_cpt_model_names = array( |
|
98 | + 'add_new_attendee' => 'EEM_Attendee', |
|
99 | + 'edit_attendee' => 'EEM_Attendee', |
|
100 | + ); |
|
101 | + $this->_cpt_edit_routes = array( |
|
102 | + 'espresso_attendees' => 'edit_attendee', |
|
103 | + ); |
|
104 | + $this->_pagenow_map = array( |
|
105 | + 'add_new_attendee' => 'post-new.php', |
|
106 | + 'edit_attendee' => 'post.php', |
|
107 | + 'trash' => 'post.php', |
|
108 | + ); |
|
109 | + add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
110 | + //add filters so that the comment urls don't take users to a confusing 404 page |
|
111 | + add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + public function clear_comment_link($link, $comment, $args) |
|
116 | + { |
|
117 | + //gotta make sure this only happens on this route |
|
118 | + $post_type = get_post_type($comment->comment_post_ID); |
|
119 | + if ($post_type === 'espresso_attendees') { |
|
120 | + return '#commentsdiv'; |
|
121 | + } |
|
122 | + return $link; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + protected function _ajax_hooks() |
|
127 | + { |
|
128 | + //todo: all hooks for registrations ajax goes in here |
|
129 | + add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + protected function _define_page_props() |
|
134 | + { |
|
135 | + $this->_admin_page_title = $this->page_label; |
|
136 | + $this->_labels = array( |
|
137 | + 'buttons' => array( |
|
138 | + 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
139 | + 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
140 | + 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
141 | + 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
142 | + 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
143 | + 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
144 | + 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
145 | + 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
146 | + ), |
|
147 | + 'publishbox' => array( |
|
148 | + 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
149 | + 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
150 | + ), |
|
151 | + 'hide_add_button_on_cpt_route' => array( |
|
152 | + 'edit_attendee' => true, |
|
153 | + ), |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * grab url requests and route them |
|
160 | + * |
|
161 | + * @access private |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + public function _set_page_routes() |
|
165 | + { |
|
166 | + $this->_get_registration_status_array(); |
|
167 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
168 | + ? $this->_req_data['_REG_ID'] : 0; |
|
169 | + $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID']) |
|
170 | + ? $this->_req_data['reg_status_change_form']['REG_ID'] |
|
171 | + : $reg_id; |
|
172 | + $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
173 | + ? $this->_req_data['ATT_ID'] : 0; |
|
174 | + $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
175 | + ? $this->_req_data['post'] |
|
176 | + : $att_id; |
|
177 | + $this->_page_routes = array( |
|
178 | + 'default' => array( |
|
179 | + 'func' => '_registrations_overview_list_table', |
|
180 | + 'capability' => 'ee_read_registrations', |
|
181 | + ), |
|
182 | + 'view_registration' => array( |
|
183 | + 'func' => '_registration_details', |
|
184 | + 'capability' => 'ee_read_registration', |
|
185 | + 'obj_id' => $reg_id, |
|
186 | + ), |
|
187 | + 'edit_registration' => array( |
|
188 | + 'func' => '_update_attendee_registration_form', |
|
189 | + 'noheader' => true, |
|
190 | + 'headers_sent_route' => 'view_registration', |
|
191 | + 'capability' => 'ee_edit_registration', |
|
192 | + 'obj_id' => $reg_id, |
|
193 | + '_REG_ID' => $reg_id, |
|
194 | + ), |
|
195 | + 'trash_registrations' => array( |
|
196 | + 'func' => '_trash_or_restore_registrations', |
|
197 | + 'args' => array('trash' => true), |
|
198 | + 'noheader' => true, |
|
199 | + 'capability' => 'ee_delete_registrations', |
|
200 | + ), |
|
201 | + 'restore_registrations' => array( |
|
202 | + 'func' => '_trash_or_restore_registrations', |
|
203 | + 'args' => array('trash' => false), |
|
204 | + 'noheader' => true, |
|
205 | + 'capability' => 'ee_delete_registrations', |
|
206 | + ), |
|
207 | + 'delete_registrations' => array( |
|
208 | + 'func' => '_delete_registrations', |
|
209 | + 'noheader' => true, |
|
210 | + 'capability' => 'ee_delete_registrations', |
|
211 | + ), |
|
212 | + 'new_registration' => array( |
|
213 | + 'func' => 'new_registration', |
|
214 | + 'capability' => 'ee_edit_registrations', |
|
215 | + ), |
|
216 | + 'process_reg_step' => array( |
|
217 | + 'func' => 'process_reg_step', |
|
218 | + 'noheader' => true, |
|
219 | + 'capability' => 'ee_edit_registrations', |
|
220 | + ), |
|
221 | + 'redirect_to_txn' => array( |
|
222 | + 'func' => 'redirect_to_txn', |
|
223 | + 'noheader' => true, |
|
224 | + 'capability' => 'ee_edit_registrations', |
|
225 | + ), |
|
226 | + 'change_reg_status' => array( |
|
227 | + 'func' => '_change_reg_status', |
|
228 | + 'noheader' => true, |
|
229 | + 'capability' => 'ee_edit_registration', |
|
230 | + 'obj_id' => $reg_id, |
|
231 | + ), |
|
232 | + 'approve_registration' => array( |
|
233 | + 'func' => 'approve_registration', |
|
234 | + 'noheader' => true, |
|
235 | + 'capability' => 'ee_edit_registration', |
|
236 | + 'obj_id' => $reg_id, |
|
237 | + ), |
|
238 | + 'approve_and_notify_registration' => array( |
|
239 | + 'func' => 'approve_registration', |
|
240 | + 'noheader' => true, |
|
241 | + 'args' => array(true), |
|
242 | + 'capability' => 'ee_edit_registration', |
|
243 | + 'obj_id' => $reg_id, |
|
244 | + ), |
|
245 | + 'approve_registrations' => array( |
|
246 | + 'func' => 'bulk_action_on_registrations', |
|
247 | + 'noheader' => true, |
|
248 | + 'capability' => 'ee_edit_registrations', |
|
249 | + 'args' => array('approve') |
|
250 | + ), |
|
251 | + 'approve_and_notify_registrations' => array( |
|
252 | + 'func' => 'bulk_action_on_registrations', |
|
253 | + 'noheader' => true, |
|
254 | + 'capability' => 'ee_edit_registrations', |
|
255 | + 'args' => array('approve', true) |
|
256 | + ), |
|
257 | + 'decline_registration' => array( |
|
258 | + 'func' => 'decline_registration', |
|
259 | + 'noheader' => true, |
|
260 | + 'capability' => 'ee_edit_registration', |
|
261 | + 'obj_id' => $reg_id, |
|
262 | + ), |
|
263 | + 'decline_and_notify_registration' => array( |
|
264 | + 'func' => 'decline_registration', |
|
265 | + 'noheader' => true, |
|
266 | + 'args' => array(true), |
|
267 | + 'capability' => 'ee_edit_registration', |
|
268 | + 'obj_id' => $reg_id, |
|
269 | + ), |
|
270 | + 'decline_registrations' => array( |
|
271 | + 'func' => 'bulk_action_on_registrations', |
|
272 | + 'noheader' => true, |
|
273 | + 'capability' => 'ee_edit_registrations', |
|
274 | + 'args' => array('decline') |
|
275 | + ), |
|
276 | + 'decline_and_notify_registrations' => array( |
|
277 | + 'func' => 'bulk_action_on_registrations', |
|
278 | + 'noheader' => true, |
|
279 | + 'capability' => 'ee_edit_registrations', |
|
280 | + 'args' => array('decline', true) |
|
281 | + ), |
|
282 | + 'pending_registration' => array( |
|
283 | + 'func' => 'pending_registration', |
|
284 | + 'noheader' => true, |
|
285 | + 'capability' => 'ee_edit_registration', |
|
286 | + 'obj_id' => $reg_id, |
|
287 | + ), |
|
288 | + 'pending_and_notify_registration' => array( |
|
289 | + 'func' => 'pending_registration', |
|
290 | + 'noheader' => true, |
|
291 | + 'args' => array(true), |
|
292 | + 'capability' => 'ee_edit_registration', |
|
293 | + 'obj_id' => $reg_id, |
|
294 | + ), |
|
295 | + 'pending_registrations' => array( |
|
296 | + 'func' => 'bulk_action_on_registrations', |
|
297 | + 'noheader' => true, |
|
298 | + 'capability' => 'ee_edit_registrations', |
|
299 | + 'args' => array('pending') |
|
300 | + ), |
|
301 | + 'pending_and_notify_registrations' => array( |
|
302 | + 'func' => 'bulk_action_on_registrations', |
|
303 | + 'noheader' => true, |
|
304 | + 'capability' => 'ee_edit_registrations', |
|
305 | + 'args' => array('pending', true) |
|
306 | + ), |
|
307 | + 'no_approve_registration' => array( |
|
308 | + 'func' => 'not_approve_registration', |
|
309 | + 'noheader' => true, |
|
310 | + 'capability' => 'ee_edit_registration', |
|
311 | + 'obj_id' => $reg_id, |
|
312 | + ), |
|
313 | + 'no_approve_and_notify_registration' => array( |
|
314 | + 'func' => 'not_approve_registration', |
|
315 | + 'noheader' => true, |
|
316 | + 'args' => array(true), |
|
317 | + 'capability' => 'ee_edit_registration', |
|
318 | + 'obj_id' => $reg_id, |
|
319 | + ), |
|
320 | + 'no_approve_registrations' => array( |
|
321 | + 'func' => 'bulk_action_on_registrations', |
|
322 | + 'noheader' => true, |
|
323 | + 'capability' => 'ee_edit_registrations', |
|
324 | + 'args' => array('not_approve') |
|
325 | + ), |
|
326 | + 'no_approve_and_notify_registrations' => array( |
|
327 | + 'func' => 'bulk_action_on_registrations', |
|
328 | + 'noheader' => true, |
|
329 | + 'capability' => 'ee_edit_registrations', |
|
330 | + 'args' => array('not_approve', true) |
|
331 | + ), |
|
332 | + 'cancel_registration' => array( |
|
333 | + 'func' => 'cancel_registration', |
|
334 | + 'noheader' => true, |
|
335 | + 'capability' => 'ee_edit_registration', |
|
336 | + 'obj_id' => $reg_id, |
|
337 | + ), |
|
338 | + 'cancel_and_notify_registration' => array( |
|
339 | + 'func' => 'cancel_registration', |
|
340 | + 'noheader' => true, |
|
341 | + 'args' => array(true), |
|
342 | + 'capability' => 'ee_edit_registration', |
|
343 | + 'obj_id' => $reg_id, |
|
344 | + ), |
|
345 | + 'cancel_registrations' => array( |
|
346 | + 'func' => 'bulk_action_on_registrations', |
|
347 | + 'noheader' => true, |
|
348 | + 'capability' => 'ee_edit_registrations', |
|
349 | + 'args' => array('cancel') |
|
350 | + ), |
|
351 | + 'cancel_and_notify_registrations' => array( |
|
352 | + 'func' => 'bulk_action_on_registrations', |
|
353 | + 'noheader' => true, |
|
354 | + 'capability' => 'ee_edit_registrations', |
|
355 | + 'args' => array('cancel', true) |
|
356 | + ), |
|
357 | + 'wait_list_registration' => array( |
|
358 | + 'func' => 'wait_list_registration', |
|
359 | + 'noheader' => true, |
|
360 | + 'capability' => 'ee_edit_registration', |
|
361 | + 'obj_id' => $reg_id, |
|
362 | + ), |
|
363 | + 'contact_list' => array( |
|
364 | + 'func' => '_attendee_contact_list_table', |
|
365 | + 'capability' => 'ee_read_contacts', |
|
366 | + ), |
|
367 | + 'add_new_attendee' => array( |
|
368 | + 'func' => '_create_new_cpt_item', |
|
369 | + 'args' => array( |
|
370 | + 'new_attendee' => true, |
|
371 | + 'capability' => 'ee_edit_contacts', |
|
372 | + ), |
|
373 | + ), |
|
374 | + 'edit_attendee' => array( |
|
375 | + 'func' => '_edit_cpt_item', |
|
376 | + 'capability' => 'ee_edit_contacts', |
|
377 | + 'obj_id' => $att_id, |
|
378 | + ), |
|
379 | + 'duplicate_attendee' => array( |
|
380 | + 'func' => '_duplicate_attendee', |
|
381 | + 'noheader' => true, |
|
382 | + 'capability' => 'ee_edit_contacts', |
|
383 | + 'obj_id' => $att_id, |
|
384 | + ), |
|
385 | + 'insert_attendee' => array( |
|
386 | + 'func' => '_insert_or_update_attendee', |
|
387 | + 'args' => array( |
|
388 | + 'new_attendee' => true, |
|
389 | + ), |
|
390 | + 'noheader' => true, |
|
391 | + 'capability' => 'ee_edit_contacts', |
|
392 | + ), |
|
393 | + 'update_attendee' => array( |
|
394 | + 'func' => '_insert_or_update_attendee', |
|
395 | + 'args' => array( |
|
396 | + 'new_attendee' => false, |
|
397 | + ), |
|
398 | + 'noheader' => true, |
|
399 | + 'capability' => 'ee_edit_contacts', |
|
400 | + 'obj_id' => $att_id, |
|
401 | + ), |
|
402 | + 'trash_attendees' => array( |
|
403 | + 'func' => '_trash_or_restore_attendees', |
|
404 | + 'args' => array( |
|
405 | + 'trash' => 'true' |
|
406 | + ), |
|
407 | + 'noheader' => true, |
|
408 | + 'capability' => 'ee_delete_contacts' |
|
409 | + ), |
|
410 | + 'trash_attendee' => array( |
|
411 | + 'func' => '_trash_or_restore_attendees', |
|
412 | + 'args' => array( |
|
413 | + 'trash' => true, |
|
414 | + ), |
|
415 | + 'noheader' => true, |
|
416 | + 'capability' => 'ee_delete_contacts', |
|
417 | + 'obj_id' => $att_id, |
|
418 | + ), |
|
419 | + 'restore_attendees' => array( |
|
420 | + 'func' => '_trash_or_restore_attendees', |
|
421 | + 'args' => array( |
|
422 | + 'trash' => false, |
|
423 | + ), |
|
424 | + 'noheader' => true, |
|
425 | + 'capability' => 'ee_delete_contacts', |
|
426 | + 'obj_id' => $att_id, |
|
427 | + ), |
|
428 | + 'resend_registration' => array( |
|
429 | + 'func' => '_resend_registration', |
|
430 | + 'noheader' => true, |
|
431 | + 'capability' => 'ee_send_message', |
|
432 | + ), |
|
433 | + 'registrations_report' => array( |
|
434 | + 'func' => '_registrations_report', |
|
435 | + 'noheader' => true, |
|
436 | + 'capability' => 'ee_read_registrations', |
|
437 | + ), |
|
438 | + 'contact_list_export' => array( |
|
439 | + 'func' => '_contact_list_export', |
|
440 | + 'noheader' => true, |
|
441 | + 'capability' => 'export', |
|
442 | + ), |
|
443 | + 'contact_list_report' => array( |
|
444 | + 'func' => '_contact_list_report', |
|
445 | + 'noheader' => true, |
|
446 | + 'capability' => 'ee_read_contacts', |
|
447 | + ), |
|
448 | + ); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + protected function _set_page_config() |
|
453 | + { |
|
454 | + $this->_page_config = array( |
|
455 | + 'default' => array( |
|
456 | + 'nav' => array( |
|
457 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
458 | + 'order' => 5, |
|
459 | + ), |
|
460 | + 'help_tabs' => array( |
|
461 | + 'registrations_overview_help_tab' => array( |
|
462 | + 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
463 | + 'filename' => 'registrations_overview', |
|
464 | + ), |
|
465 | + 'registrations_overview_table_column_headings_help_tab' => array( |
|
466 | + 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
467 | + 'filename' => 'registrations_overview_table_column_headings', |
|
468 | + ), |
|
469 | + 'registrations_overview_filters_help_tab' => array( |
|
470 | + 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
471 | + 'filename' => 'registrations_overview_filters', |
|
472 | + ), |
|
473 | + 'registrations_overview_views_help_tab' => array( |
|
474 | + 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
475 | + 'filename' => 'registrations_overview_views', |
|
476 | + ), |
|
477 | + 'registrations_regoverview_other_help_tab' => array( |
|
478 | + 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
479 | + 'filename' => 'registrations_overview_other', |
|
480 | + ), |
|
481 | + ), |
|
482 | + 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
483 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
484 | + 'list_table' => 'EE_Registrations_List_Table', |
|
485 | + 'require_nonce' => false, |
|
486 | + ), |
|
487 | + 'view_registration' => array( |
|
488 | + 'nav' => array( |
|
489 | + 'label' => esc_html__('REG Details', 'event_espresso'), |
|
490 | + 'order' => 15, |
|
491 | + 'url' => isset($this->_req_data['_REG_ID']) |
|
492 | + ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
493 | + : $this->_admin_base_url, |
|
494 | + 'persistent' => false, |
|
495 | + ), |
|
496 | + 'help_tabs' => array( |
|
497 | + 'registrations_details_help_tab' => array( |
|
498 | + 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
499 | + 'filename' => 'registrations_details', |
|
500 | + ), |
|
501 | + 'registrations_details_table_help_tab' => array( |
|
502 | + 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
503 | + 'filename' => 'registrations_details_table', |
|
504 | + ), |
|
505 | + 'registrations_details_form_answers_help_tab' => array( |
|
506 | + 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
507 | + 'filename' => 'registrations_details_form_answers', |
|
508 | + ), |
|
509 | + 'registrations_details_registrant_details_help_tab' => array( |
|
510 | + 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
511 | + 'filename' => 'registrations_details_registrant_details', |
|
512 | + ), |
|
513 | + ), |
|
514 | + 'help_tour' => array('Registration_Details_Help_Tour'), |
|
515 | + 'metaboxes' => array_merge( |
|
516 | + $this->_default_espresso_metaboxes, |
|
517 | + array('_registration_details_metaboxes') |
|
518 | + ), |
|
519 | + 'require_nonce' => false, |
|
520 | + ), |
|
521 | + 'new_registration' => array( |
|
522 | + 'nav' => array( |
|
523 | + 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
524 | + 'url' => '#', |
|
525 | + 'order' => 15, |
|
526 | + 'persistent' => false, |
|
527 | + ), |
|
528 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
529 | + 'labels' => array( |
|
530 | + 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
531 | + ), |
|
532 | + 'require_nonce' => false, |
|
533 | + ), |
|
534 | + 'add_new_attendee' => array( |
|
535 | + 'nav' => array( |
|
536 | + 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
537 | + 'order' => 15, |
|
538 | + 'persistent' => false, |
|
539 | + ), |
|
540 | + 'metaboxes' => array_merge( |
|
541 | + $this->_default_espresso_metaboxes, |
|
542 | + array('_publish_post_box', 'attendee_editor_metaboxes') |
|
543 | + ), |
|
544 | + 'require_nonce' => false, |
|
545 | + ), |
|
546 | + 'edit_attendee' => array( |
|
547 | + 'nav' => array( |
|
548 | + 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
549 | + 'order' => 15, |
|
550 | + 'persistent' => false, |
|
551 | + 'url' => isset($this->_req_data['ATT_ID']) |
|
552 | + ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
553 | + : $this->_admin_base_url, |
|
554 | + ), |
|
555 | + 'metaboxes' => array('attendee_editor_metaboxes'), |
|
556 | + 'require_nonce' => false, |
|
557 | + ), |
|
558 | + 'contact_list' => array( |
|
559 | + 'nav' => array( |
|
560 | + 'label' => esc_html__('Contact List', 'event_espresso'), |
|
561 | + 'order' => 20, |
|
562 | + ), |
|
563 | + 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
564 | + 'help_tabs' => array( |
|
565 | + 'registrations_contact_list_help_tab' => array( |
|
566 | + 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
567 | + 'filename' => 'registrations_contact_list', |
|
568 | + ), |
|
569 | + 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
570 | + 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
571 | + 'filename' => 'registrations_contact_list_table_column_headings', |
|
572 | + ), |
|
573 | + 'registrations_contact_list_views_help_tab' => array( |
|
574 | + 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
575 | + 'filename' => 'registrations_contact_list_views', |
|
576 | + ), |
|
577 | + 'registrations_contact_list_other_help_tab' => array( |
|
578 | + 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
579 | + 'filename' => 'registrations_contact_list_other', |
|
580 | + ), |
|
581 | + ), |
|
582 | + 'help_tour' => array('Contact_List_Help_Tour'), |
|
583 | + 'metaboxes' => array(), |
|
584 | + 'require_nonce' => false, |
|
585 | + ), |
|
586 | + //override default cpt routes |
|
587 | + 'create_new' => '', |
|
588 | + 'edit' => '', |
|
589 | + ); |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * The below methods aren't used by this class currently |
|
595 | + */ |
|
596 | + protected function _add_screen_options() |
|
597 | + { |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + protected function _add_feature_pointers() |
|
602 | + { |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + public function admin_init() |
|
607 | + { |
|
608 | + EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
609 | + 'click "Update Registration Questions" to save your changes', |
|
610 | + 'event_espresso' |
|
611 | + ); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + public function admin_notices() |
|
616 | + { |
|
617 | + } |
|
618 | + |
|
619 | + |
|
620 | + public function admin_footer_scripts() |
|
621 | + { |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + /** |
|
626 | + * get list of registration statuses |
|
627 | + * |
|
628 | + * @access private |
|
629 | + * @return void |
|
630 | + */ |
|
631 | + private function _get_registration_status_array() |
|
632 | + { |
|
633 | + self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + protected function _add_screen_options_default() |
|
638 | + { |
|
639 | + $this->_per_page_screen_option(); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + protected function _add_screen_options_contact_list() |
|
644 | + { |
|
645 | + $page_title = $this->_admin_page_title; |
|
646 | + $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
647 | + $this->_per_page_screen_option(); |
|
648 | + $this->_admin_page_title = $page_title; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + public function load_scripts_styles() |
|
653 | + { |
|
654 | + //style |
|
655 | + wp_register_style( |
|
656 | + 'espresso_reg', |
|
657 | + REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
658 | + array('ee-admin-css'), |
|
659 | + EVENT_ESPRESSO_VERSION |
|
660 | + ); |
|
661 | + wp_enqueue_style('espresso_reg'); |
|
662 | + //script |
|
663 | + wp_register_script( |
|
664 | + 'espresso_reg', |
|
665 | + REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
666 | + array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
667 | + EVENT_ESPRESSO_VERSION, |
|
668 | + true |
|
669 | + ); |
|
670 | + wp_enqueue_script('espresso_reg'); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + public function load_scripts_styles_edit_attendee() |
|
675 | + { |
|
676 | + //stuff to only show up on our attendee edit details page. |
|
677 | + $attendee_details_translations = array( |
|
678 | + 'att_publish_text' => sprintf( |
|
679 | + esc_html__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
680 | + $this->_cpt_model_obj->get_datetime('ATT_created') |
|
681 | + ), |
|
682 | + ); |
|
683 | + wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
684 | + wp_enqueue_script('jquery-validate'); |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + public function load_scripts_styles_view_registration() |
|
689 | + { |
|
690 | + //styles |
|
691 | + wp_enqueue_style('espresso-ui-theme'); |
|
692 | + //scripts |
|
693 | + $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
694 | + $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + public function load_scripts_styles_contact_list() |
|
699 | + { |
|
700 | + wp_deregister_style('espresso_reg'); |
|
701 | + wp_register_style( |
|
702 | + 'espresso_att', |
|
703 | + REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
704 | + array('ee-admin-css'), |
|
705 | + EVENT_ESPRESSO_VERSION |
|
706 | + ); |
|
707 | + wp_enqueue_style('espresso_att'); |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + public function load_scripts_styles_new_registration() |
|
712 | + { |
|
713 | + wp_register_script( |
|
714 | + 'ee-spco-for-admin', |
|
715 | + REG_ASSETS_URL . 'spco_for_admin.js', |
|
716 | + array('underscore', 'jquery'), |
|
717 | + EVENT_ESPRESSO_VERSION, |
|
718 | + true |
|
719 | + ); |
|
720 | + wp_enqueue_script('ee-spco-for-admin'); |
|
721 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
722 | + EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
723 | + EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
724 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
725 | + } |
|
726 | + |
|
727 | + |
|
728 | + public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
729 | + { |
|
730 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
731 | + } |
|
732 | + |
|
733 | + |
|
734 | + public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
735 | + { |
|
736 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + protected function _set_list_table_views_default() |
|
741 | + { |
|
742 | + //for notification related bulk actions we need to make sure only active messengers have an option. |
|
743 | + EED_Messages::set_autoloaders(); |
|
744 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
745 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
746 | + $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
747 | + //key= bulk_action_slug, value= message type. |
|
748 | + $match_array = array( |
|
749 | + 'approve_registrations' => 'registration', |
|
750 | + 'decline_registrations' => 'declined_registration', |
|
751 | + 'pending_registrations' => 'pending_approval', |
|
752 | + 'no_approve_registrations' => 'not_approved_registration', |
|
753 | + 'cancel_registrations' => 'cancelled_registration', |
|
754 | + ); |
|
755 | + $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
756 | + 'ee_send_message', |
|
757 | + 'batch_send_messages' |
|
758 | + ); |
|
759 | + /** setup reg status bulk actions **/ |
|
760 | + $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
761 | + if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
762 | + $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
763 | + 'Approve and Notify Registrations', |
|
764 | + 'event_espresso' |
|
765 | + ); |
|
766 | + } |
|
767 | + $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
768 | + if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
769 | + $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
770 | + 'Decline and Notify Registrations', |
|
771 | + 'event_espresso' |
|
772 | + ); |
|
773 | + } |
|
774 | + $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
775 | + 'Set Registrations to Pending Payment', |
|
776 | + 'event_espresso' |
|
777 | + ); |
|
778 | + if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
779 | + $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
780 | + 'Set Registrations to Pending Payment and Notify', |
|
781 | + 'event_espresso' |
|
782 | + ); |
|
783 | + } |
|
784 | + $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
785 | + 'Set Registrations to Not Approved', |
|
786 | + 'event_espresso' |
|
787 | + ); |
|
788 | + if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
789 | + $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
790 | + 'Set Registrations to Not Approved and Notify', |
|
791 | + 'event_espresso' |
|
792 | + ); |
|
793 | + } |
|
794 | + $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
795 | + if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
796 | + $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
797 | + 'Cancel Registrations and Notify', |
|
798 | + 'event_espresso' |
|
799 | + ); |
|
800 | + } |
|
801 | + $def_reg_status_actions = apply_filters( |
|
802 | + 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
803 | + $def_reg_status_actions, |
|
804 | + $active_mts |
|
805 | + ); |
|
806 | + |
|
807 | + $this->_views = array( |
|
808 | + 'all' => array( |
|
809 | + 'slug' => 'all', |
|
810 | + 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
811 | + 'count' => 0, |
|
812 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
813 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
814 | + )), |
|
815 | + ), |
|
816 | + 'month' => array( |
|
817 | + 'slug' => 'month', |
|
818 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
819 | + 'count' => 0, |
|
820 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
821 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
822 | + )), |
|
823 | + ), |
|
824 | + 'today' => array( |
|
825 | + 'slug' => 'today', |
|
826 | + 'label' => sprintf( |
|
827 | + esc_html__('Today - %s', 'event_espresso'), |
|
828 | + date('M d, Y', current_time('timestamp')) |
|
829 | + ), |
|
830 | + 'count' => 0, |
|
831 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
832 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
833 | + )), |
|
834 | + ), |
|
835 | + ); |
|
836 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
837 | + 'ee_delete_registrations', |
|
838 | + 'espresso_registrations_delete_registration' |
|
839 | + )) { |
|
840 | + $this->_views['incomplete'] = array( |
|
841 | + 'slug' => 'incomplete', |
|
842 | + 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
843 | + 'count' => 0, |
|
844 | + 'bulk_action' => array( |
|
845 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
846 | + ), |
|
847 | + ); |
|
848 | + $this->_views['trash'] = array( |
|
849 | + 'slug' => 'trash', |
|
850 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
851 | + 'count' => 0, |
|
852 | + 'bulk_action' => array( |
|
853 | + 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
854 | + 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
855 | + ), |
|
856 | + ); |
|
857 | + } |
|
858 | + } |
|
859 | + |
|
860 | + |
|
861 | + protected function _set_list_table_views_contact_list() |
|
862 | + { |
|
863 | + $this->_views = array( |
|
864 | + 'in_use' => array( |
|
865 | + 'slug' => 'in_use', |
|
866 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
867 | + 'count' => 0, |
|
868 | + 'bulk_action' => array( |
|
869 | + 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
870 | + ), |
|
871 | + ), |
|
872 | + ); |
|
873 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
874 | + 'espresso_registrations_trash_attendees') |
|
875 | + ) { |
|
876 | + $this->_views['trash'] = array( |
|
877 | + 'slug' => 'trash', |
|
878 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
879 | + 'count' => 0, |
|
880 | + 'bulk_action' => array( |
|
881 | + 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
882 | + ), |
|
883 | + ); |
|
884 | + } |
|
885 | + } |
|
886 | + |
|
887 | + |
|
888 | + protected function _registration_legend_items() |
|
889 | + { |
|
890 | + $fc_items = array( |
|
891 | + 'star-icon' => array( |
|
892 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
893 | + 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
894 | + ), |
|
895 | + 'view_details' => array( |
|
896 | + 'class' => 'dashicons dashicons-clipboard', |
|
897 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
898 | + ), |
|
899 | + 'edit_attendee' => array( |
|
900 | + 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
901 | + 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
902 | + ), |
|
903 | + 'view_transaction' => array( |
|
904 | + 'class' => 'dashicons dashicons-cart', |
|
905 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
906 | + ), |
|
907 | + 'view_invoice' => array( |
|
908 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
909 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
910 | + ), |
|
911 | + ); |
|
912 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
913 | + 'ee_send_message', |
|
914 | + 'espresso_registrations_resend_registration' |
|
915 | + )) { |
|
916 | + $fc_items['resend_registration'] = array( |
|
917 | + 'class' => 'dashicons dashicons-email-alt', |
|
918 | + 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
919 | + ); |
|
920 | + } else { |
|
921 | + $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
922 | + } |
|
923 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
924 | + 'ee_read_global_messages', |
|
925 | + 'view_filtered_messages' |
|
926 | + )) { |
|
927 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
928 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
929 | + $fc_items['view_related_messages'] = array( |
|
930 | + 'class' => $related_for_icon['css_class'], |
|
931 | + 'desc' => $related_for_icon['label'], |
|
932 | + ); |
|
933 | + } |
|
934 | + } |
|
935 | + $sc_items = array( |
|
936 | + 'approved_status' => array( |
|
937 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
938 | + 'desc' => EEH_Template::pretty_status( |
|
939 | + EEM_Registration::status_id_approved, |
|
940 | + false, |
|
941 | + 'sentence' |
|
942 | + ), |
|
943 | + ), |
|
944 | + 'pending_status' => array( |
|
945 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
946 | + 'desc' => EEH_Template::pretty_status( |
|
947 | + EEM_Registration::status_id_pending_payment, |
|
948 | + false, |
|
949 | + 'sentence' |
|
950 | + ), |
|
951 | + ), |
|
952 | + 'wait_list' => array( |
|
953 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
954 | + 'desc' => EEH_Template::pretty_status( |
|
955 | + EEM_Registration::status_id_wait_list, |
|
956 | + false, |
|
957 | + 'sentence' |
|
958 | + ), |
|
959 | + ), |
|
960 | + 'incomplete_status' => array( |
|
961 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
962 | + 'desc' => EEH_Template::pretty_status( |
|
963 | + EEM_Registration::status_id_incomplete, |
|
964 | + false, |
|
965 | + 'sentence' |
|
966 | + ), |
|
967 | + ), |
|
968 | + 'not_approved' => array( |
|
969 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
970 | + 'desc' => EEH_Template::pretty_status( |
|
971 | + EEM_Registration::status_id_not_approved, |
|
972 | + false, |
|
973 | + 'sentence' |
|
974 | + ), |
|
975 | + ), |
|
976 | + 'declined_status' => array( |
|
977 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
978 | + 'desc' => EEH_Template::pretty_status( |
|
979 | + EEM_Registration::status_id_declined, |
|
980 | + false, |
|
981 | + 'sentence' |
|
982 | + ), |
|
983 | + ), |
|
984 | + 'cancelled_status' => array( |
|
985 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
986 | + 'desc' => EEH_Template::pretty_status( |
|
987 | + EEM_Registration::status_id_cancelled, |
|
988 | + false, |
|
989 | + 'sentence' |
|
990 | + ), |
|
991 | + ), |
|
992 | + ); |
|
993 | + return array_merge($fc_items, $sc_items); |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + |
|
998 | + /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
999 | + /** |
|
1000 | + * @throws \EE_Error |
|
1001 | + */ |
|
1002 | + protected function _registrations_overview_list_table() |
|
1003 | + { |
|
1004 | + $this->_template_args['admin_page_header'] = ''; |
|
1005 | + $EVT_ID = ! empty($this->_req_data['event_id']) |
|
1006 | + ? absint($this->_req_data['event_id']) |
|
1007 | + : 0; |
|
1008 | + if ($EVT_ID) { |
|
1009 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
1010 | + 'ee_edit_registrations', |
|
1011 | + 'espresso_registrations_new_registration', |
|
1012 | + $EVT_ID |
|
1013 | + )) { |
|
1014 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
1015 | + 'new_registration', |
|
1016 | + 'add-registrant', |
|
1017 | + array('event_id' => $EVT_ID), |
|
1018 | + 'add-new-h2' |
|
1019 | + ); |
|
1020 | + } |
|
1021 | + $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
1022 | + if ($event instanceof EE_Event) { |
|
1023 | + $this->_template_args['admin_page_header'] = sprintf( |
|
1024 | + esc_html__( |
|
1025 | + '%s Viewing registrations for the event: %s%s', |
|
1026 | + 'event_espresso' |
|
1027 | + ), |
|
1028 | + '<h3 style="line-height:1.5em;">', |
|
1029 | + '<br /><a href="' |
|
1030 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
1031 | + array( |
|
1032 | + 'action' => 'edit', |
|
1033 | + 'post' => $event->ID(), |
|
1034 | + ), |
|
1035 | + EVENTS_ADMIN_URL |
|
1036 | + ) |
|
1037 | + . '"> ' |
|
1038 | + . $event->get('EVT_name') |
|
1039 | + . ' </a> ', |
|
1040 | + '</h3>' |
|
1041 | + ); |
|
1042 | + } |
|
1043 | + $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
1044 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1045 | + if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
1046 | + $this->_template_args['admin_page_header'] = substr( |
|
1047 | + $this->_template_args['admin_page_header'], |
|
1048 | + 0, |
|
1049 | + -5 |
|
1050 | + ); |
|
1051 | + $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
1052 | + $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1053 | + $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
1054 | + $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
1055 | + $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
1056 | + } |
|
1057 | + } |
|
1058 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
1059 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * This sets the _registration property for the registration details screen |
|
1065 | + * |
|
1066 | + * @access private |
|
1067 | + * @return bool |
|
1068 | + */ |
|
1069 | + private function _set_registration_object() |
|
1070 | + { |
|
1071 | + //get out if we've already set the object |
|
1072 | + if (is_object($this->_registration)) { |
|
1073 | + return true; |
|
1074 | + } |
|
1075 | + $REG = EEM_Registration::instance(); |
|
1076 | + $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
1077 | + if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
1078 | + return true; |
|
1079 | + } else { |
|
1080 | + $error_msg = sprintf( |
|
1081 | + esc_html__( |
|
1082 | + 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
1083 | + 'event_espresso' |
|
1084 | + ), |
|
1085 | + $REG_ID |
|
1086 | + ); |
|
1087 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
1088 | + $this->_registration = null; |
|
1089 | + return false; |
|
1090 | + } |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * Used to retrieve registrations for the list table. |
|
1096 | + * |
|
1097 | + * @param int $per_page |
|
1098 | + * @param bool $count |
|
1099 | + * @param bool $this_month |
|
1100 | + * @param bool $today |
|
1101 | + * @return EE_Registration[]|int |
|
1102 | + * @throws EE_Error |
|
1103 | + */ |
|
1104 | + public function get_registrations( |
|
1105 | + $per_page = 10, |
|
1106 | + $count = false, |
|
1107 | + $this_month = false, |
|
1108 | + $today = false |
|
1109 | + ) { |
|
1110 | + if ($this_month) { |
|
1111 | + $this->_req_data['status'] = 'month'; |
|
1112 | + } |
|
1113 | + if ($today) { |
|
1114 | + $this->_req_data['status'] = 'today'; |
|
1115 | + } |
|
1116 | + $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
1117 | + /** |
|
1118 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1119 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1120 | + * @see EEM_Base::get_all() |
|
1121 | + */ |
|
1122 | + $query_params['group_by'] = ''; |
|
1123 | + |
|
1124 | + return $count |
|
1125 | + ? EEM_Registration::instance()->count($query_params) |
|
1126 | + /** @type EE_Registration[] */ |
|
1127 | + : EEM_Registration::instance()->get_all($query_params); |
|
1128 | + } |
|
1129 | + |
|
1130 | + |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
1134 | + * Note: this listens to values on the request for some of the query parameters. |
|
1135 | + * |
|
1136 | + * @param array $request |
|
1137 | + * @param int $per_page |
|
1138 | + * @param bool $count |
|
1139 | + * @return array |
|
1140 | + */ |
|
1141 | + protected function _get_registration_query_parameters( |
|
1142 | + $request = array(), |
|
1143 | + $per_page = 10, |
|
1144 | + $count = false |
|
1145 | + ) { |
|
1146 | + |
|
1147 | + $query_params = array( |
|
1148 | + 0 => $this->_get_where_conditions_for_registrations_query( |
|
1149 | + $request |
|
1150 | + ), |
|
1151 | + 'caps' => EEM_Registration::caps_read_admin, |
|
1152 | + 'default_where_conditions' => 'this_model_only', |
|
1153 | + ); |
|
1154 | + if (! $count) { |
|
1155 | + $query_params = array_merge( |
|
1156 | + $query_params, |
|
1157 | + $this->_get_orderby_for_registrations_query(), |
|
1158 | + $this->_get_limit($per_page) |
|
1159 | + ); |
|
1160 | + } |
|
1161 | + |
|
1162 | + return $query_params; |
|
1163 | + } |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
1168 | + * |
|
1169 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
1170 | + * @return array |
|
1171 | + */ |
|
1172 | + protected function _add_event_id_to_where_conditions(array $request) |
|
1173 | + { |
|
1174 | + $where = array(); |
|
1175 | + if (! empty($request['event_id'])) { |
|
1176 | + $where['EVT_ID'] = absint($request['event_id']); |
|
1177 | + } |
|
1178 | + return $where; |
|
1179 | + } |
|
1180 | + |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
1184 | + * |
|
1185 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
1186 | + * @return array |
|
1187 | + */ |
|
1188 | + protected function _add_category_id_to_where_conditions(array $request) |
|
1189 | + { |
|
1190 | + $where = array(); |
|
1191 | + if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
1192 | + $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
1193 | + } |
|
1194 | + return $where; |
|
1195 | + } |
|
1196 | + |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
1200 | + * |
|
1201 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
1202 | + * @return array |
|
1203 | + */ |
|
1204 | + protected function _add_datetime_id_to_where_conditions(array $request) |
|
1205 | + { |
|
1206 | + $where = array(); |
|
1207 | + if (! empty($request['datetime_id'])) { |
|
1208 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
1209 | + } |
|
1210 | + if (! empty($request['DTT_ID'])) { |
|
1211 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
1212 | + } |
|
1213 | + return $where; |
|
1214 | + } |
|
1215 | + |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
1219 | + * |
|
1220 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
1221 | + * @return array |
|
1222 | + */ |
|
1223 | + protected function _add_registration_status_to_where_conditions(array $request) |
|
1224 | + { |
|
1225 | + $where = array(); |
|
1226 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
1227 | + $registration_status = ! empty($request['_reg_status']) |
|
1228 | + ? sanitize_text_field($request['_reg_status']) |
|
1229 | + : ''; |
|
1230 | + |
|
1231 | + /* |
|
1232 | 1232 | * If filtering by registration status, then we show registrations matching that status. |
1233 | 1233 | * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
1234 | 1234 | * UNLESS viewing trashed registrations. |
1235 | 1235 | */ |
1236 | - if (! empty($registration_status)) { |
|
1237 | - $where['STS_ID'] = $registration_status; |
|
1238 | - } else { |
|
1239 | - //make sure we exclude incomplete registrations, but only if not trashed. |
|
1240 | - if ($view === 'trash') { |
|
1241 | - $where['REG_deleted'] = true; |
|
1242 | - } elseif ($view === 'incomplete') { |
|
1243 | - $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
1244 | - } else { |
|
1245 | - $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
1246 | - } |
|
1247 | - } |
|
1248 | - return $where; |
|
1249 | - } |
|
1250 | - |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
1254 | - * |
|
1255 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
1256 | - * @return array |
|
1257 | - * @throws EE_Error |
|
1258 | - */ |
|
1259 | - protected function _add_date_to_where_conditions(array $request) |
|
1260 | - { |
|
1261 | - $where = array(); |
|
1262 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
1263 | - $month_range = ! empty($request['month_range']) |
|
1264 | - ? sanitize_text_field($request['month_range']) |
|
1265 | - : ''; |
|
1266 | - $retrieve_for_today = $view === 'today'; |
|
1267 | - $retrieve_for_this_month = $view === 'month'; |
|
1268 | - |
|
1269 | - if ($retrieve_for_today) { |
|
1270 | - $now = date('Y-m-d', current_time('timestamp')); |
|
1271 | - $where['REG_date'] = array( |
|
1272 | - 'BETWEEN', |
|
1273 | - array( |
|
1274 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
1275 | - 'REG_date', |
|
1276 | - $now . ' 00:00:00', |
|
1277 | - 'Y-m-d H:i:s' |
|
1278 | - ), |
|
1279 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
1280 | - 'REG_date', |
|
1281 | - $now . ' 23:59:59', |
|
1282 | - 'Y-m-d H:i:s' |
|
1283 | - ), |
|
1284 | - ), |
|
1285 | - ); |
|
1286 | - } elseif ($retrieve_for_this_month) { |
|
1287 | - $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
1288 | - $days_this_month = date('t', current_time('timestamp')); |
|
1289 | - $where['REG_date'] = array( |
|
1290 | - 'BETWEEN', |
|
1291 | - array( |
|
1292 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
1293 | - 'REG_date', |
|
1294 | - $current_year_and_month . '-01 00:00:00', |
|
1295 | - 'Y-m-d H:i:s' |
|
1296 | - ), |
|
1297 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
1298 | - 'REG_date', |
|
1299 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
1300 | - 'Y-m-d H:i:s' |
|
1301 | - ), |
|
1302 | - ), |
|
1303 | - ); |
|
1304 | - } elseif ($month_range) { |
|
1305 | - $pieces = explode(' ', $month_range, 3); |
|
1306 | - $month_requested = ! empty($pieces[0]) |
|
1307 | - ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
1308 | - : ''; |
|
1309 | - $year_requested = ! empty($pieces[1]) |
|
1310 | - ? $pieces[1] |
|
1311 | - : ''; |
|
1312 | - //if there is not a month or year then we can't go further |
|
1313 | - if ($month_requested && $year_requested) { |
|
1314 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
1315 | - $where['REG_date'] = array( |
|
1316 | - 'BETWEEN', |
|
1317 | - array( |
|
1318 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
1319 | - 'REG_date', |
|
1320 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
1321 | - 'Y-m-d H:i:s' |
|
1322 | - ), |
|
1323 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
1324 | - 'REG_date', |
|
1325 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
1326 | - 'Y-m-d H:i:s' |
|
1327 | - ), |
|
1328 | - ), |
|
1329 | - ); |
|
1330 | - } |
|
1331 | - } |
|
1332 | - return $where; |
|
1333 | - } |
|
1334 | - |
|
1335 | - |
|
1336 | - /** |
|
1337 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
1338 | - * |
|
1339 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
1340 | - * @return array |
|
1341 | - */ |
|
1342 | - protected function _add_search_to_where_conditions(array $request) |
|
1343 | - { |
|
1344 | - $where = array(); |
|
1345 | - if (! empty($request['s'])) { |
|
1346 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
1347 | - $where['OR*search_conditions'] = array( |
|
1348 | - 'Event.EVT_name' => array('LIKE', $search_string), |
|
1349 | - 'Event.EVT_desc' => array('LIKE', $search_string), |
|
1350 | - 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
1351 | - 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
1352 | - 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
1353 | - 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
1354 | - 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
1355 | - 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
1356 | - 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
1357 | - 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
1358 | - 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
1359 | - 'REG_final_price' => array('LIKE', $search_string), |
|
1360 | - 'REG_code' => array('LIKE', $search_string), |
|
1361 | - 'REG_count' => array('LIKE', $search_string), |
|
1362 | - 'REG_group_size' => array('LIKE', $search_string), |
|
1363 | - 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
1364 | - 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
1365 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
1366 | - ); |
|
1367 | - } |
|
1368 | - return $where; |
|
1369 | - } |
|
1370 | - |
|
1371 | - |
|
1372 | - /** |
|
1373 | - * Sets up the where conditions for the registrations query. |
|
1374 | - * |
|
1375 | - * @param array $request |
|
1376 | - * @return array |
|
1377 | - * @throws EE_Error |
|
1378 | - */ |
|
1379 | - protected function _get_where_conditions_for_registrations_query($request) |
|
1380 | - { |
|
1381 | - return apply_filters( |
|
1382 | - 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
1383 | - array_merge( |
|
1384 | - $this->_add_event_id_to_where_conditions($request), |
|
1385 | - $this->_add_category_id_to_where_conditions($request), |
|
1386 | - $this->_add_datetime_id_to_where_conditions($request), |
|
1387 | - $this->_add_registration_status_to_where_conditions($request), |
|
1388 | - $this->_add_date_to_where_conditions($request), |
|
1389 | - $this->_add_search_to_where_conditions($request) |
|
1390 | - ), |
|
1391 | - $request |
|
1392 | - ); |
|
1393 | - } |
|
1394 | - |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * Sets up the orderby for the registrations query. |
|
1398 | - * |
|
1399 | - * @return array |
|
1400 | - */ |
|
1401 | - protected function _get_orderby_for_registrations_query() |
|
1402 | - { |
|
1403 | - $orderby_field = ! empty($this->_req_data['orderby']) |
|
1404 | - ? sanitize_text_field($this->_req_data['orderby']) |
|
1405 | - : ''; |
|
1406 | - switch ($orderby_field) { |
|
1407 | - case '_REG_ID': |
|
1408 | - $orderby_field = 'REG_ID'; |
|
1409 | - break; |
|
1410 | - case '_Reg_status': |
|
1411 | - $orderby_field = 'STS_ID'; |
|
1412 | - break; |
|
1413 | - case 'ATT_fname': |
|
1414 | - $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
1415 | - break; |
|
1416 | - case 'ATT_lname': |
|
1417 | - $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
1418 | - break; |
|
1419 | - case 'event_name': |
|
1420 | - $orderby_field = 'Event.EVT_name'; |
|
1421 | - break; |
|
1422 | - case 'DTT_EVT_start': |
|
1423 | - $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
1424 | - break; |
|
1425 | - default: //'REG_date' |
|
1426 | - $orderby_field = 'REG_date'; |
|
1427 | - } |
|
1428 | - |
|
1429 | - //order |
|
1430 | - $order = ! empty($this->_req_data['order']) |
|
1431 | - ? sanitize_text_field($this->_req_data['order']) |
|
1432 | - : 'DESC'; |
|
1433 | - |
|
1434 | - //mutate orderby_field |
|
1435 | - $orderby_field = array_combine( |
|
1436 | - (array) $orderby_field, |
|
1437 | - array_fill(0, count($orderby_field), $order) |
|
1438 | - ); |
|
1439 | - //because there are many registrations with the same date, define |
|
1440 | - //a secondary way to order them, otherwise MySQL seems to be a bit random |
|
1441 | - if (empty($order['REG_ID'])) { |
|
1442 | - $orderby_field['REG_ID'] = $order; |
|
1443 | - } |
|
1444 | - return array('order_by' => $orderby_field); |
|
1445 | - } |
|
1446 | - |
|
1447 | - |
|
1448 | - /** |
|
1449 | - * Sets up the limit for the registrations query. |
|
1450 | - * |
|
1451 | - * @param $per_page |
|
1452 | - * @return array |
|
1453 | - */ |
|
1454 | - protected function _get_limit($per_page) |
|
1455 | - { |
|
1456 | - $current_page = ! empty($this->_req_data['paged']) |
|
1457 | - ? absint($this->_req_data['paged']) |
|
1458 | - : 1; |
|
1459 | - $per_page = ! empty($this->_req_data['perpage']) |
|
1460 | - ? $this->_req_data['perpage'] |
|
1461 | - : $per_page; |
|
1462 | - |
|
1463 | - //-1 means return all results so get out if that's set. |
|
1464 | - if ((int)$per_page === -1) { |
|
1465 | - return array(); |
|
1466 | - } |
|
1467 | - $per_page = absint($per_page); |
|
1468 | - $offset = ($current_page - 1) * $per_page; |
|
1469 | - return array('limit' => array($offset, $per_page)); |
|
1470 | - } |
|
1471 | - |
|
1472 | - |
|
1473 | - public function get_registration_status_array() |
|
1474 | - { |
|
1475 | - return self::$_reg_status; |
|
1476 | - } |
|
1477 | - |
|
1478 | - |
|
1479 | - |
|
1480 | - |
|
1481 | - /*************************************** REGISTRATION DETAILS ***************************************/ |
|
1482 | - /** |
|
1483 | - * generates HTML for the View Registration Details Admin page |
|
1484 | - * |
|
1485 | - * @access protected |
|
1486 | - * @return void |
|
1487 | - * @throws DomainException |
|
1488 | - * @throws EE_Error |
|
1489 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1490 | - */ |
|
1491 | - protected function _registration_details() |
|
1492 | - { |
|
1493 | - $this->_template_args = array(); |
|
1494 | - $this->_set_registration_object(); |
|
1495 | - if (is_object($this->_registration)) { |
|
1496 | - $transaction = $this->_registration->transaction() |
|
1497 | - ? $this->_registration->transaction() |
|
1498 | - : EE_Transaction::new_instance(); |
|
1499 | - $this->_session = $transaction->session_data(); |
|
1500 | - $event_id = $this->_registration->event_ID(); |
|
1501 | - $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
1502 | - $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
1503 | - $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
1504 | - $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
1505 | - $this->_template_args['grand_total'] = $transaction->total(); |
|
1506 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
1507 | - // link back to overview |
|
1508 | - $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
1509 | - $this->_template_args['registration'] = $this->_registration; |
|
1510 | - $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1511 | - array( |
|
1512 | - 'action' => 'default', |
|
1513 | - 'event_id' => $event_id, |
|
1514 | - ), |
|
1515 | - REG_ADMIN_URL |
|
1516 | - ); |
|
1517 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1518 | - array( |
|
1519 | - 'action' => 'default', |
|
1520 | - 'EVT_ID' => $event_id, |
|
1521 | - 'page' => 'espresso_transactions', |
|
1522 | - ), |
|
1523 | - admin_url('admin.php') |
|
1524 | - ); |
|
1525 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1526 | - array( |
|
1527 | - 'page' => 'espresso_events', |
|
1528 | - 'action' => 'edit', |
|
1529 | - 'post' => $event_id, |
|
1530 | - ), |
|
1531 | - admin_url('admin.php') |
|
1532 | - ); |
|
1533 | - //next and previous links |
|
1534 | - $next_reg = $this->_registration->next( |
|
1535 | - null, |
|
1536 | - array(), |
|
1537 | - 'REG_ID' |
|
1538 | - ); |
|
1539 | - $this->_template_args['next_registration'] = $next_reg |
|
1540 | - ? $this->_next_link( |
|
1541 | - EE_Admin_Page::add_query_args_and_nonce( |
|
1542 | - array( |
|
1543 | - 'action' => 'view_registration', |
|
1544 | - '_REG_ID' => $next_reg['REG_ID'], |
|
1545 | - ), |
|
1546 | - REG_ADMIN_URL |
|
1547 | - ), |
|
1548 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
1549 | - ) |
|
1550 | - : ''; |
|
1551 | - $previous_reg = $this->_registration->previous( |
|
1552 | - null, |
|
1553 | - array(), |
|
1554 | - 'REG_ID' |
|
1555 | - ); |
|
1556 | - $this->_template_args['previous_registration'] = $previous_reg |
|
1557 | - ? $this->_previous_link( |
|
1558 | - EE_Admin_Page::add_query_args_and_nonce( |
|
1559 | - array( |
|
1560 | - 'action' => 'view_registration', |
|
1561 | - '_REG_ID' => $previous_reg['REG_ID'], |
|
1562 | - ), |
|
1563 | - REG_ADMIN_URL |
|
1564 | - ), |
|
1565 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
1566 | - ) |
|
1567 | - : ''; |
|
1568 | - // grab header |
|
1569 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
1570 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
1571 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
1572 | - $template_path, |
|
1573 | - $this->_template_args, |
|
1574 | - true |
|
1575 | - ); |
|
1576 | - } else { |
|
1577 | - $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
1578 | - } |
|
1579 | - // the details template wrapper |
|
1580 | - $this->display_admin_page_with_sidebar(); |
|
1581 | - } |
|
1582 | - |
|
1583 | - |
|
1584 | - protected function _registration_details_metaboxes() |
|
1585 | - { |
|
1586 | - do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
1587 | - $this->_set_registration_object(); |
|
1588 | - $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
1589 | - add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'), |
|
1590 | - array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
1591 | - add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'), |
|
1592 | - array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
1593 | - if ($attendee instanceof EE_Attendee |
|
1594 | - && EE_Registry::instance()->CAP->current_user_can( |
|
1595 | - 'ee_edit_registration', |
|
1596 | - 'edit-reg-questions-mbox', |
|
1597 | - $this->_registration->ID() |
|
1598 | - ) |
|
1599 | - ) { |
|
1600 | - add_meta_box( |
|
1601 | - 'edit-reg-questions-mbox', |
|
1602 | - esc_html__('Registration Form Answers', 'event_espresso'), |
|
1603 | - array($this, '_reg_questions_meta_box'), |
|
1604 | - $this->wp_page_slug, |
|
1605 | - 'normal', |
|
1606 | - 'high' |
|
1607 | - ); |
|
1608 | - } |
|
1609 | - add_meta_box( |
|
1610 | - 'edit-reg-registrant-mbox', |
|
1611 | - esc_html__('Contact Details', 'event_espresso'), |
|
1612 | - array($this, '_reg_registrant_side_meta_box'), |
|
1613 | - $this->wp_page_slug, |
|
1614 | - 'side', |
|
1615 | - 'high' |
|
1616 | - ); |
|
1617 | - if ($this->_registration->group_size() > 1) { |
|
1618 | - add_meta_box( |
|
1619 | - 'edit-reg-attendees-mbox', |
|
1620 | - esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
1621 | - array($this, '_reg_attendees_meta_box'), |
|
1622 | - $this->wp_page_slug, |
|
1623 | - 'normal', |
|
1624 | - 'high' |
|
1625 | - ); |
|
1626 | - } |
|
1627 | - } |
|
1628 | - |
|
1629 | - |
|
1630 | - /** |
|
1631 | - * set_reg_status_buttons_metabox |
|
1632 | - * |
|
1633 | - * @access protected |
|
1634 | - * @return string |
|
1635 | - * @throws \EE_Error |
|
1636 | - */ |
|
1637 | - public function set_reg_status_buttons_metabox() |
|
1638 | - { |
|
1639 | - $this->_set_registration_object(); |
|
1640 | - $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
1641 | - echo $change_reg_status_form->form_open( |
|
1642 | - self::add_query_args_and_nonce( |
|
1643 | - array( |
|
1644 | - 'action' => 'change_reg_status', |
|
1645 | - ), |
|
1646 | - REG_ADMIN_URL |
|
1647 | - ) |
|
1648 | - ); |
|
1649 | - echo $change_reg_status_form->get_html(); |
|
1650 | - echo $change_reg_status_form->form_close(); |
|
1651 | - } |
|
1652 | - |
|
1653 | - |
|
1654 | - |
|
1655 | - /** |
|
1656 | - * @return EE_Form_Section_Proper |
|
1657 | - * @throws EE_Error |
|
1658 | - */ |
|
1659 | - protected function _generate_reg_status_change_form() |
|
1660 | - { |
|
1661 | - return new EE_Form_Section_Proper(array( |
|
1662 | - 'name' => 'reg_status_change_form', |
|
1663 | - 'html_id' => 'reg-status-change-form', |
|
1664 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1665 | - 'subsections' => array( |
|
1666 | - 'return' => new EE_Hidden_Input(array( |
|
1667 | - 'name' => 'return', |
|
1668 | - 'default' => 'view_registration', |
|
1669 | - )), |
|
1670 | - 'REG_ID' => new EE_Hidden_Input(array( |
|
1671 | - 'name' => 'REG_ID', |
|
1672 | - 'default' => $this->_registration->ID(), |
|
1673 | - )), |
|
1674 | - 'current_status' => new EE_Form_Section_HTML( |
|
1675 | - EEH_HTML::tr( |
|
1676 | - EEH_HTML::th( |
|
1677 | - EEH_HTML::label( |
|
1678 | - EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso') |
|
1679 | - ) |
|
1680 | - ) |
|
1681 | - ) |
|
1682 | - . EEH_HTML::td( |
|
1683 | - EEH_HTML::strong( |
|
1684 | - $this->_registration->pretty_status(), |
|
1685 | - '', |
|
1686 | - 'status-' . $this->_registration->status_ID(), |
|
1687 | - 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
1688 | - ) |
|
1689 | - ) |
|
1690 | - ) |
|
1691 | - ), |
|
1692 | - 'reg_status' => new EE_Select_Input( |
|
1693 | - $this->_get_reg_statuses(), |
|
1694 | - array( |
|
1695 | - 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
1696 | - 'default' => $this->_registration->status_ID(), |
|
1697 | - ) |
|
1698 | - ), |
|
1699 | - 'send_notifications' => new EE_Yes_No_Input( |
|
1700 | - array( |
|
1701 | - 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
1702 | - 'default' => false, |
|
1703 | - 'html_help_text' => esc_html__( |
|
1704 | - 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
1705 | - 'event_espresso' |
|
1706 | - ), |
|
1707 | - ) |
|
1708 | - ), |
|
1709 | - 'submit' => new EE_Submit_Input( |
|
1710 | - array( |
|
1711 | - 'html_class' => 'button-primary', |
|
1712 | - 'html_label_text' => ' ', |
|
1713 | - 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
1714 | - ) |
|
1715 | - ), |
|
1716 | - ), |
|
1717 | - )); |
|
1718 | - } |
|
1719 | - |
|
1720 | - |
|
1721 | - /** |
|
1722 | - * Returns an array of all the buttons for the various statuses and switch status actions |
|
1723 | - * |
|
1724 | - * @return array |
|
1725 | - * @throws EE_Error |
|
1726 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1727 | - */ |
|
1728 | - protected function _get_reg_statuses() |
|
1729 | - { |
|
1730 | - $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
1731 | - unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
1732 | - // get current reg status |
|
1733 | - $current_status = $this->_registration->status_ID(); |
|
1734 | - // is registration for free event? This will determine whether to display the pending payment option |
|
1735 | - if ( |
|
1736 | - $current_status !== EEM_Registration::status_id_pending_payment |
|
1737 | - && $this->_registration->transaction()->is_free() |
|
1738 | - ) { |
|
1739 | - unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
1740 | - } |
|
1741 | - return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
1742 | - } |
|
1743 | - |
|
1744 | - |
|
1745 | - |
|
1746 | - /** |
|
1747 | - * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
1748 | - * |
|
1749 | - * @param bool $status REG status given for changing registrations to. |
|
1750 | - * @param bool $notify Whether to send messages notifications or not. |
|
1751 | - * @return array (array with reg_id(s) updated and whether update was successful. |
|
1752 | - * @throws \EE_Error |
|
1753 | - */ |
|
1754 | - protected function _set_registration_status_from_request($status = false, $notify = false) |
|
1755 | - { |
|
1756 | - if (isset($this->_req_data['reg_status_change_form'])) { |
|
1757 | - $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
1758 | - ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
1759 | - } else { |
|
1760 | - $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
1761 | - } |
|
1762 | - $success = $this->_set_registration_status($REG_IDs, $status); |
|
1763 | - //notify? |
|
1764 | - if ($success |
|
1765 | - && $notify |
|
1766 | - && EE_Registry::instance()->CAP->current_user_can( |
|
1767 | - 'ee_send_message', |
|
1768 | - 'espresso_registrations_resend_registration' |
|
1769 | - ) |
|
1770 | - ) { |
|
1771 | - $this->_process_resend_registration(); |
|
1772 | - } |
|
1773 | - return $success; |
|
1774 | - } |
|
1775 | - |
|
1776 | - |
|
1777 | - |
|
1778 | - /** |
|
1779 | - * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
1780 | - * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
1781 | - * |
|
1782 | - * @param array $REG_IDs |
|
1783 | - * @param bool $status |
|
1784 | - * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
1785 | - * @throws \RuntimeException |
|
1786 | - * @throws \EE_Error |
|
1787 | - * the array of updated registrations). |
|
1788 | - * @throws EE_Error |
|
1789 | - * @throws RuntimeException |
|
1790 | - */ |
|
1791 | - protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
1792 | - { |
|
1793 | - $success = false; |
|
1794 | - // typecast $REG_IDs |
|
1795 | - $REG_IDs = (array)$REG_IDs; |
|
1796 | - if ( ! empty($REG_IDs)) { |
|
1797 | - $success = true; |
|
1798 | - // set default status if none is passed |
|
1799 | - $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
1800 | - // sanitize $REG_IDs |
|
1801 | - $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
1802 | - //loop through REG_ID's and change status |
|
1803 | - foreach ($REG_IDs as $REG_ID) { |
|
1804 | - $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
1805 | - if ($registration instanceof EE_Registration) { |
|
1806 | - $registration->set_status($status); |
|
1807 | - $result = $registration->save(); |
|
1808 | - // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
1809 | - $success = $result !== false ? $success : false; |
|
1810 | - } |
|
1811 | - } |
|
1812 | - } |
|
1813 | - //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
1814 | - $this->_req_data['_REG_ID'] = $REG_IDs; |
|
1815 | - //return $success and processed registrations |
|
1816 | - return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
1817 | - } |
|
1818 | - |
|
1819 | - |
|
1820 | - /** |
|
1821 | - * Common logic for setting up success message and redirecting to appropriate route |
|
1822 | - * |
|
1823 | - * @param string $STS_ID status id for the registration changed to |
|
1824 | - * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
1825 | - * @return void |
|
1826 | - */ |
|
1827 | - protected function _reg_status_change_return($STS_ID, $notify = false) |
|
1828 | - { |
|
1829 | - $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
1830 | - : array('success' => false); |
|
1831 | - $success = isset($result['success']) && $result['success']; |
|
1832 | - //setup success message |
|
1833 | - if ($success) { |
|
1834 | - if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
1835 | - $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
1836 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
1837 | - } else { |
|
1838 | - $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
1839 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
1840 | - } |
|
1841 | - EE_Error::add_success($msg); |
|
1842 | - } else { |
|
1843 | - EE_Error::add_error( |
|
1844 | - esc_html__( |
|
1845 | - 'Something went wrong, and the status was not changed', |
|
1846 | - 'event_espresso' |
|
1847 | - ), __FILE__, __LINE__, __FUNCTION__ |
|
1848 | - ); |
|
1849 | - } |
|
1850 | - if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
1851 | - $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
1852 | - } else { |
|
1853 | - $route = array('action' => 'default'); |
|
1854 | - } |
|
1855 | - //unset nonces |
|
1856 | - foreach ($this->_req_data as $ref => $value) { |
|
1857 | - if (strpos($ref, 'nonce') !== false) { |
|
1858 | - unset($this->_req_data[$ref]); |
|
1859 | - continue; |
|
1860 | - } |
|
1861 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
1862 | - $this->_req_data[$ref] = $value; |
|
1863 | - } |
|
1864 | - //merge request vars so that the reloaded list table contains any existing filter query params |
|
1865 | - $route = array_merge($this->_req_data, $route); |
|
1866 | - $this->_redirect_after_action($success, '', '', $route, true); |
|
1867 | - } |
|
1868 | - |
|
1869 | - |
|
1870 | - /** |
|
1871 | - * incoming reg status change from reg details page. |
|
1872 | - * |
|
1873 | - * @return void |
|
1874 | - */ |
|
1875 | - protected function _change_reg_status() |
|
1876 | - { |
|
1877 | - $this->_req_data['return'] = 'view_registration'; |
|
1878 | - //set notify based on whether the send notifications toggle is set or not |
|
1879 | - $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
1880 | - //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
1881 | - $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
1882 | - ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
1883 | - switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
1884 | - case EEM_Registration::status_id_approved : |
|
1885 | - case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
1886 | - $this->approve_registration($notify); |
|
1887 | - break; |
|
1888 | - case EEM_Registration::status_id_pending_payment : |
|
1889 | - case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
1890 | - $this->pending_registration($notify); |
|
1891 | - break; |
|
1892 | - case EEM_Registration::status_id_not_approved : |
|
1893 | - case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
1894 | - $this->not_approve_registration($notify); |
|
1895 | - break; |
|
1896 | - case EEM_Registration::status_id_declined : |
|
1897 | - case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
1898 | - $this->decline_registration($notify); |
|
1899 | - break; |
|
1900 | - case EEM_Registration::status_id_cancelled : |
|
1901 | - case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
1902 | - $this->cancel_registration($notify); |
|
1903 | - break; |
|
1904 | - case EEM_Registration::status_id_wait_list : |
|
1905 | - case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
1906 | - $this->wait_list_registration($notify); |
|
1907 | - break; |
|
1908 | - case EEM_Registration::status_id_incomplete : |
|
1909 | - default : |
|
1910 | - $result['success'] = false; |
|
1911 | - unset($this->_req_data['return']); |
|
1912 | - $this->_reg_status_change_return('', false); |
|
1913 | - break; |
|
1914 | - } |
|
1915 | - } |
|
1916 | - |
|
1917 | - |
|
1918 | - /** |
|
1919 | - * Callback for bulk action routes. |
|
1920 | - * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
1921 | - * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
1922 | - * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
1923 | - * when an action is happening on just a single registration). |
|
1924 | - * @param $action |
|
1925 | - * @param bool $notify |
|
1926 | - */ |
|
1927 | - protected function bulk_action_on_registrations($action, $notify = false) { |
|
1928 | - do_action( |
|
1929 | - 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
1930 | - $this, |
|
1931 | - $action, |
|
1932 | - $notify |
|
1933 | - ); |
|
1934 | - $method = $action . '_registration'; |
|
1935 | - if (method_exists($this, $method)) { |
|
1936 | - $this->$method($notify); |
|
1937 | - } |
|
1938 | - } |
|
1939 | - |
|
1940 | - |
|
1941 | - /** |
|
1942 | - * approve_registration |
|
1943 | - * |
|
1944 | - * @access protected |
|
1945 | - * @param bool $notify whether or not to notify the registrant about their approval. |
|
1946 | - * @return void |
|
1947 | - */ |
|
1948 | - protected function approve_registration($notify = false) |
|
1949 | - { |
|
1950 | - $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
1951 | - } |
|
1952 | - |
|
1953 | - |
|
1954 | - /** |
|
1955 | - * decline_registration |
|
1956 | - * |
|
1957 | - * @access protected |
|
1958 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
1959 | - * @return void |
|
1960 | - */ |
|
1961 | - protected function decline_registration($notify = false) |
|
1962 | - { |
|
1963 | - $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
1964 | - } |
|
1965 | - |
|
1966 | - |
|
1967 | - /** |
|
1968 | - * cancel_registration |
|
1969 | - * |
|
1970 | - * @access protected |
|
1971 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
1972 | - * @return void |
|
1973 | - */ |
|
1974 | - protected function cancel_registration($notify = false) |
|
1975 | - { |
|
1976 | - $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
1977 | - } |
|
1978 | - |
|
1979 | - |
|
1980 | - /** |
|
1981 | - * not_approve_registration |
|
1982 | - * |
|
1983 | - * @access protected |
|
1984 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
1985 | - * @return void |
|
1986 | - */ |
|
1987 | - protected function not_approve_registration($notify = false) |
|
1988 | - { |
|
1989 | - $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
1990 | - } |
|
1991 | - |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * decline_registration |
|
1995 | - * |
|
1996 | - * @access protected |
|
1997 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
1998 | - * @return void |
|
1999 | - */ |
|
2000 | - protected function pending_registration($notify = false) |
|
2001 | - { |
|
2002 | - $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
2003 | - } |
|
2004 | - |
|
2005 | - |
|
2006 | - /** |
|
2007 | - * waitlist_registration |
|
2008 | - * |
|
2009 | - * @access protected |
|
2010 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
2011 | - * @return void |
|
2012 | - */ |
|
2013 | - protected function wait_list_registration($notify = false) |
|
2014 | - { |
|
2015 | - $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
2016 | - } |
|
2017 | - |
|
2018 | - |
|
2019 | - /** |
|
2020 | - * generates HTML for the Registration main meta box |
|
2021 | - * |
|
2022 | - * @access public |
|
2023 | - * @return void |
|
2024 | - * @throws DomainException |
|
2025 | - * @throws EE_Error |
|
2026 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
2027 | - */ |
|
2028 | - public function _reg_details_meta_box() |
|
2029 | - { |
|
2030 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
2031 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
2032 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
2033 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
2034 | - : EE_Transaction::new_instance(); |
|
2035 | - $this->_session = $transaction->session_data(); |
|
2036 | - $filters = new EE_Line_Item_Filter_Collection(); |
|
2037 | - //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
2038 | - $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
2039 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
2040 | - $transaction->total_line_item()); |
|
2041 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
2042 | - $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
2043 | - 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
2044 | - $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
2045 | - $filtered_line_item_tree, |
|
2046 | - array('EE_Registration' => $this->_registration) |
|
2047 | - ); |
|
2048 | - $attendee = $this->_registration->attendee(); |
|
2049 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
2050 | - 'ee_read_transaction', |
|
2051 | - 'espresso_transactions_view_transaction' |
|
2052 | - )) { |
|
2053 | - $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
2054 | - EE_Admin_Page::add_query_args_and_nonce( |
|
2055 | - array( |
|
2056 | - 'action' => 'view_transaction', |
|
2057 | - 'TXN_ID' => $transaction->ID(), |
|
2058 | - ), |
|
2059 | - TXN_ADMIN_URL |
|
2060 | - ), |
|
2061 | - esc_html__(' View Transaction', 'event_espresso'), |
|
2062 | - 'button secondary-button right', |
|
2063 | - 'dashicons dashicons-cart' |
|
2064 | - ); |
|
2065 | - } else { |
|
2066 | - $this->_template_args['view_transaction_button'] = ''; |
|
2067 | - } |
|
2068 | - if ($attendee instanceof EE_Attendee |
|
2069 | - && EE_Registry::instance()->CAP->current_user_can( |
|
2070 | - 'ee_send_message', |
|
2071 | - 'espresso_registrations_resend_registration' |
|
2072 | - ) |
|
2073 | - ) { |
|
2074 | - $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
2075 | - EE_Admin_Page::add_query_args_and_nonce( |
|
2076 | - array( |
|
2077 | - 'action' => 'resend_registration', |
|
2078 | - '_REG_ID' => $this->_registration->ID(), |
|
2079 | - 'redirect_to' => 'view_registration', |
|
2080 | - ), |
|
2081 | - REG_ADMIN_URL |
|
2082 | - ), |
|
2083 | - esc_html__(' Resend Registration', 'event_espresso'), |
|
2084 | - 'button secondary-button right', |
|
2085 | - 'dashicons dashicons-email-alt' |
|
2086 | - ); |
|
2087 | - } else { |
|
2088 | - $this->_template_args['resend_registration_button'] = ''; |
|
2089 | - } |
|
2090 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
2091 | - $payment = $transaction->get_first_related('Payment'); |
|
2092 | - $payment = ! $payment instanceof EE_Payment |
|
2093 | - ? EE_Payment::new_instance() |
|
2094 | - : $payment; |
|
2095 | - $payment_method = $payment->get_first_related('Payment_Method'); |
|
2096 | - $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
2097 | - ? EE_Payment_Method::new_instance() |
|
2098 | - : $payment_method; |
|
2099 | - $reg_details = array( |
|
2100 | - 'payment_method' => $payment_method->name(), |
|
2101 | - 'response_msg' => $payment->gateway_response(), |
|
2102 | - 'registration_id' => $this->_registration->get('REG_code'), |
|
2103 | - 'registration_session' => $this->_registration->session_ID(), |
|
2104 | - 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
2105 | - 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
2106 | - ); |
|
2107 | - if (isset($reg_details['registration_id'])) { |
|
2108 | - $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
2109 | - $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
2110 | - 'Registration ID', |
|
2111 | - 'event_espresso' |
|
2112 | - ); |
|
2113 | - $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
2114 | - } |
|
2115 | - if (isset($reg_details['payment_method'])) { |
|
2116 | - $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
2117 | - $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
2118 | - 'Most Recent Payment Method', |
|
2119 | - 'event_espresso' |
|
2120 | - ); |
|
2121 | - $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
2122 | - $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
2123 | - $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
2124 | - 'Payment method response', |
|
2125 | - 'event_espresso' |
|
2126 | - ); |
|
2127 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
2128 | - } |
|
2129 | - $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
2130 | - $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
2131 | - 'Registration Session', |
|
2132 | - 'event_espresso' |
|
2133 | - ); |
|
2134 | - $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
2135 | - $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
2136 | - $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
2137 | - 'Registration placed from IP', |
|
2138 | - 'event_espresso' |
|
2139 | - ); |
|
2140 | - $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
2141 | - $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
2142 | - $this->_template_args['reg_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
2143 | - 'event_espresso'); |
|
2144 | - $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
2145 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
2146 | - array( |
|
2147 | - 'action' => 'default', |
|
2148 | - 'event_id' => $this->_registration->event_ID(), |
|
2149 | - ), |
|
2150 | - REG_ADMIN_URL |
|
2151 | - ); |
|
2152 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
2153 | - $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
2154 | - $template_path = |
|
2155 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
2156 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2157 | - } |
|
2158 | - |
|
2159 | - |
|
2160 | - /** |
|
2161 | - * generates HTML for the Registration Questions meta box. |
|
2162 | - * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
2163 | - * otherwise uses new forms system |
|
2164 | - * |
|
2165 | - * @access public |
|
2166 | - * @return void |
|
2167 | - * @throws DomainException |
|
2168 | - * @throws EE_Error |
|
2169 | - */ |
|
2170 | - public function _reg_questions_meta_box() |
|
2171 | - { |
|
2172 | - //allow someone to override this method entirely |
|
2173 | - if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
2174 | - $this->_registration)) { |
|
2175 | - $form = $this->_get_reg_custom_questions_form( |
|
2176 | - $this->_registration->ID() |
|
2177 | - ); |
|
2178 | - $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
2179 | - ? $form->get_html_and_js() |
|
2180 | - : ''; |
|
2181 | - $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
2182 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
2183 | - $template_path = |
|
2184 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
2185 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2186 | - } |
|
2187 | - } |
|
2188 | - |
|
2189 | - |
|
2190 | - /** |
|
2191 | - * form_before_question_group |
|
2192 | - * |
|
2193 | - * @deprecated as of 4.8.32.rc.000 |
|
2194 | - * @access public |
|
2195 | - * @param string $output |
|
2196 | - * @return string |
|
2197 | - */ |
|
2198 | - public function form_before_question_group($output) |
|
2199 | - { |
|
2200 | - EE_Error::doing_it_wrong( |
|
2201 | - __CLASS__ . '::' . __FUNCTION__, |
|
2202 | - esc_html__( |
|
2203 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2204 | - 'event_espresso' |
|
2205 | - ), |
|
2206 | - '4.8.32.rc.000' |
|
2207 | - ); |
|
2208 | - return ' |
|
1236 | + if (! empty($registration_status)) { |
|
1237 | + $where['STS_ID'] = $registration_status; |
|
1238 | + } else { |
|
1239 | + //make sure we exclude incomplete registrations, but only if not trashed. |
|
1240 | + if ($view === 'trash') { |
|
1241 | + $where['REG_deleted'] = true; |
|
1242 | + } elseif ($view === 'incomplete') { |
|
1243 | + $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
1244 | + } else { |
|
1245 | + $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
1246 | + } |
|
1247 | + } |
|
1248 | + return $where; |
|
1249 | + } |
|
1250 | + |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
1254 | + * |
|
1255 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
1256 | + * @return array |
|
1257 | + * @throws EE_Error |
|
1258 | + */ |
|
1259 | + protected function _add_date_to_where_conditions(array $request) |
|
1260 | + { |
|
1261 | + $where = array(); |
|
1262 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
1263 | + $month_range = ! empty($request['month_range']) |
|
1264 | + ? sanitize_text_field($request['month_range']) |
|
1265 | + : ''; |
|
1266 | + $retrieve_for_today = $view === 'today'; |
|
1267 | + $retrieve_for_this_month = $view === 'month'; |
|
1268 | + |
|
1269 | + if ($retrieve_for_today) { |
|
1270 | + $now = date('Y-m-d', current_time('timestamp')); |
|
1271 | + $where['REG_date'] = array( |
|
1272 | + 'BETWEEN', |
|
1273 | + array( |
|
1274 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
1275 | + 'REG_date', |
|
1276 | + $now . ' 00:00:00', |
|
1277 | + 'Y-m-d H:i:s' |
|
1278 | + ), |
|
1279 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
1280 | + 'REG_date', |
|
1281 | + $now . ' 23:59:59', |
|
1282 | + 'Y-m-d H:i:s' |
|
1283 | + ), |
|
1284 | + ), |
|
1285 | + ); |
|
1286 | + } elseif ($retrieve_for_this_month) { |
|
1287 | + $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
1288 | + $days_this_month = date('t', current_time('timestamp')); |
|
1289 | + $where['REG_date'] = array( |
|
1290 | + 'BETWEEN', |
|
1291 | + array( |
|
1292 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
1293 | + 'REG_date', |
|
1294 | + $current_year_and_month . '-01 00:00:00', |
|
1295 | + 'Y-m-d H:i:s' |
|
1296 | + ), |
|
1297 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
1298 | + 'REG_date', |
|
1299 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
1300 | + 'Y-m-d H:i:s' |
|
1301 | + ), |
|
1302 | + ), |
|
1303 | + ); |
|
1304 | + } elseif ($month_range) { |
|
1305 | + $pieces = explode(' ', $month_range, 3); |
|
1306 | + $month_requested = ! empty($pieces[0]) |
|
1307 | + ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
1308 | + : ''; |
|
1309 | + $year_requested = ! empty($pieces[1]) |
|
1310 | + ? $pieces[1] |
|
1311 | + : ''; |
|
1312 | + //if there is not a month or year then we can't go further |
|
1313 | + if ($month_requested && $year_requested) { |
|
1314 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
1315 | + $where['REG_date'] = array( |
|
1316 | + 'BETWEEN', |
|
1317 | + array( |
|
1318 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
1319 | + 'REG_date', |
|
1320 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
1321 | + 'Y-m-d H:i:s' |
|
1322 | + ), |
|
1323 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
1324 | + 'REG_date', |
|
1325 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
1326 | + 'Y-m-d H:i:s' |
|
1327 | + ), |
|
1328 | + ), |
|
1329 | + ); |
|
1330 | + } |
|
1331 | + } |
|
1332 | + return $where; |
|
1333 | + } |
|
1334 | + |
|
1335 | + |
|
1336 | + /** |
|
1337 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
1338 | + * |
|
1339 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
1340 | + * @return array |
|
1341 | + */ |
|
1342 | + protected function _add_search_to_where_conditions(array $request) |
|
1343 | + { |
|
1344 | + $where = array(); |
|
1345 | + if (! empty($request['s'])) { |
|
1346 | + $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
1347 | + $where['OR*search_conditions'] = array( |
|
1348 | + 'Event.EVT_name' => array('LIKE', $search_string), |
|
1349 | + 'Event.EVT_desc' => array('LIKE', $search_string), |
|
1350 | + 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
1351 | + 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
1352 | + 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
1353 | + 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
1354 | + 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
1355 | + 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
1356 | + 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
1357 | + 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
1358 | + 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
1359 | + 'REG_final_price' => array('LIKE', $search_string), |
|
1360 | + 'REG_code' => array('LIKE', $search_string), |
|
1361 | + 'REG_count' => array('LIKE', $search_string), |
|
1362 | + 'REG_group_size' => array('LIKE', $search_string), |
|
1363 | + 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
1364 | + 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
1365 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
1366 | + ); |
|
1367 | + } |
|
1368 | + return $where; |
|
1369 | + } |
|
1370 | + |
|
1371 | + |
|
1372 | + /** |
|
1373 | + * Sets up the where conditions for the registrations query. |
|
1374 | + * |
|
1375 | + * @param array $request |
|
1376 | + * @return array |
|
1377 | + * @throws EE_Error |
|
1378 | + */ |
|
1379 | + protected function _get_where_conditions_for_registrations_query($request) |
|
1380 | + { |
|
1381 | + return apply_filters( |
|
1382 | + 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
1383 | + array_merge( |
|
1384 | + $this->_add_event_id_to_where_conditions($request), |
|
1385 | + $this->_add_category_id_to_where_conditions($request), |
|
1386 | + $this->_add_datetime_id_to_where_conditions($request), |
|
1387 | + $this->_add_registration_status_to_where_conditions($request), |
|
1388 | + $this->_add_date_to_where_conditions($request), |
|
1389 | + $this->_add_search_to_where_conditions($request) |
|
1390 | + ), |
|
1391 | + $request |
|
1392 | + ); |
|
1393 | + } |
|
1394 | + |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * Sets up the orderby for the registrations query. |
|
1398 | + * |
|
1399 | + * @return array |
|
1400 | + */ |
|
1401 | + protected function _get_orderby_for_registrations_query() |
|
1402 | + { |
|
1403 | + $orderby_field = ! empty($this->_req_data['orderby']) |
|
1404 | + ? sanitize_text_field($this->_req_data['orderby']) |
|
1405 | + : ''; |
|
1406 | + switch ($orderby_field) { |
|
1407 | + case '_REG_ID': |
|
1408 | + $orderby_field = 'REG_ID'; |
|
1409 | + break; |
|
1410 | + case '_Reg_status': |
|
1411 | + $orderby_field = 'STS_ID'; |
|
1412 | + break; |
|
1413 | + case 'ATT_fname': |
|
1414 | + $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
1415 | + break; |
|
1416 | + case 'ATT_lname': |
|
1417 | + $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
1418 | + break; |
|
1419 | + case 'event_name': |
|
1420 | + $orderby_field = 'Event.EVT_name'; |
|
1421 | + break; |
|
1422 | + case 'DTT_EVT_start': |
|
1423 | + $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
1424 | + break; |
|
1425 | + default: //'REG_date' |
|
1426 | + $orderby_field = 'REG_date'; |
|
1427 | + } |
|
1428 | + |
|
1429 | + //order |
|
1430 | + $order = ! empty($this->_req_data['order']) |
|
1431 | + ? sanitize_text_field($this->_req_data['order']) |
|
1432 | + : 'DESC'; |
|
1433 | + |
|
1434 | + //mutate orderby_field |
|
1435 | + $orderby_field = array_combine( |
|
1436 | + (array) $orderby_field, |
|
1437 | + array_fill(0, count($orderby_field), $order) |
|
1438 | + ); |
|
1439 | + //because there are many registrations with the same date, define |
|
1440 | + //a secondary way to order them, otherwise MySQL seems to be a bit random |
|
1441 | + if (empty($order['REG_ID'])) { |
|
1442 | + $orderby_field['REG_ID'] = $order; |
|
1443 | + } |
|
1444 | + return array('order_by' => $orderby_field); |
|
1445 | + } |
|
1446 | + |
|
1447 | + |
|
1448 | + /** |
|
1449 | + * Sets up the limit for the registrations query. |
|
1450 | + * |
|
1451 | + * @param $per_page |
|
1452 | + * @return array |
|
1453 | + */ |
|
1454 | + protected function _get_limit($per_page) |
|
1455 | + { |
|
1456 | + $current_page = ! empty($this->_req_data['paged']) |
|
1457 | + ? absint($this->_req_data['paged']) |
|
1458 | + : 1; |
|
1459 | + $per_page = ! empty($this->_req_data['perpage']) |
|
1460 | + ? $this->_req_data['perpage'] |
|
1461 | + : $per_page; |
|
1462 | + |
|
1463 | + //-1 means return all results so get out if that's set. |
|
1464 | + if ((int)$per_page === -1) { |
|
1465 | + return array(); |
|
1466 | + } |
|
1467 | + $per_page = absint($per_page); |
|
1468 | + $offset = ($current_page - 1) * $per_page; |
|
1469 | + return array('limit' => array($offset, $per_page)); |
|
1470 | + } |
|
1471 | + |
|
1472 | + |
|
1473 | + public function get_registration_status_array() |
|
1474 | + { |
|
1475 | + return self::$_reg_status; |
|
1476 | + } |
|
1477 | + |
|
1478 | + |
|
1479 | + |
|
1480 | + |
|
1481 | + /*************************************** REGISTRATION DETAILS ***************************************/ |
|
1482 | + /** |
|
1483 | + * generates HTML for the View Registration Details Admin page |
|
1484 | + * |
|
1485 | + * @access protected |
|
1486 | + * @return void |
|
1487 | + * @throws DomainException |
|
1488 | + * @throws EE_Error |
|
1489 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1490 | + */ |
|
1491 | + protected function _registration_details() |
|
1492 | + { |
|
1493 | + $this->_template_args = array(); |
|
1494 | + $this->_set_registration_object(); |
|
1495 | + if (is_object($this->_registration)) { |
|
1496 | + $transaction = $this->_registration->transaction() |
|
1497 | + ? $this->_registration->transaction() |
|
1498 | + : EE_Transaction::new_instance(); |
|
1499 | + $this->_session = $transaction->session_data(); |
|
1500 | + $event_id = $this->_registration->event_ID(); |
|
1501 | + $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
1502 | + $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
1503 | + $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
1504 | + $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
1505 | + $this->_template_args['grand_total'] = $transaction->total(); |
|
1506 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
1507 | + // link back to overview |
|
1508 | + $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
1509 | + $this->_template_args['registration'] = $this->_registration; |
|
1510 | + $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1511 | + array( |
|
1512 | + 'action' => 'default', |
|
1513 | + 'event_id' => $event_id, |
|
1514 | + ), |
|
1515 | + REG_ADMIN_URL |
|
1516 | + ); |
|
1517 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1518 | + array( |
|
1519 | + 'action' => 'default', |
|
1520 | + 'EVT_ID' => $event_id, |
|
1521 | + 'page' => 'espresso_transactions', |
|
1522 | + ), |
|
1523 | + admin_url('admin.php') |
|
1524 | + ); |
|
1525 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1526 | + array( |
|
1527 | + 'page' => 'espresso_events', |
|
1528 | + 'action' => 'edit', |
|
1529 | + 'post' => $event_id, |
|
1530 | + ), |
|
1531 | + admin_url('admin.php') |
|
1532 | + ); |
|
1533 | + //next and previous links |
|
1534 | + $next_reg = $this->_registration->next( |
|
1535 | + null, |
|
1536 | + array(), |
|
1537 | + 'REG_ID' |
|
1538 | + ); |
|
1539 | + $this->_template_args['next_registration'] = $next_reg |
|
1540 | + ? $this->_next_link( |
|
1541 | + EE_Admin_Page::add_query_args_and_nonce( |
|
1542 | + array( |
|
1543 | + 'action' => 'view_registration', |
|
1544 | + '_REG_ID' => $next_reg['REG_ID'], |
|
1545 | + ), |
|
1546 | + REG_ADMIN_URL |
|
1547 | + ), |
|
1548 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
1549 | + ) |
|
1550 | + : ''; |
|
1551 | + $previous_reg = $this->_registration->previous( |
|
1552 | + null, |
|
1553 | + array(), |
|
1554 | + 'REG_ID' |
|
1555 | + ); |
|
1556 | + $this->_template_args['previous_registration'] = $previous_reg |
|
1557 | + ? $this->_previous_link( |
|
1558 | + EE_Admin_Page::add_query_args_and_nonce( |
|
1559 | + array( |
|
1560 | + 'action' => 'view_registration', |
|
1561 | + '_REG_ID' => $previous_reg['REG_ID'], |
|
1562 | + ), |
|
1563 | + REG_ADMIN_URL |
|
1564 | + ), |
|
1565 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
1566 | + ) |
|
1567 | + : ''; |
|
1568 | + // grab header |
|
1569 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
1570 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
1571 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
1572 | + $template_path, |
|
1573 | + $this->_template_args, |
|
1574 | + true |
|
1575 | + ); |
|
1576 | + } else { |
|
1577 | + $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
1578 | + } |
|
1579 | + // the details template wrapper |
|
1580 | + $this->display_admin_page_with_sidebar(); |
|
1581 | + } |
|
1582 | + |
|
1583 | + |
|
1584 | + protected function _registration_details_metaboxes() |
|
1585 | + { |
|
1586 | + do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
1587 | + $this->_set_registration_object(); |
|
1588 | + $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
1589 | + add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'), |
|
1590 | + array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
1591 | + add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'), |
|
1592 | + array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
1593 | + if ($attendee instanceof EE_Attendee |
|
1594 | + && EE_Registry::instance()->CAP->current_user_can( |
|
1595 | + 'ee_edit_registration', |
|
1596 | + 'edit-reg-questions-mbox', |
|
1597 | + $this->_registration->ID() |
|
1598 | + ) |
|
1599 | + ) { |
|
1600 | + add_meta_box( |
|
1601 | + 'edit-reg-questions-mbox', |
|
1602 | + esc_html__('Registration Form Answers', 'event_espresso'), |
|
1603 | + array($this, '_reg_questions_meta_box'), |
|
1604 | + $this->wp_page_slug, |
|
1605 | + 'normal', |
|
1606 | + 'high' |
|
1607 | + ); |
|
1608 | + } |
|
1609 | + add_meta_box( |
|
1610 | + 'edit-reg-registrant-mbox', |
|
1611 | + esc_html__('Contact Details', 'event_espresso'), |
|
1612 | + array($this, '_reg_registrant_side_meta_box'), |
|
1613 | + $this->wp_page_slug, |
|
1614 | + 'side', |
|
1615 | + 'high' |
|
1616 | + ); |
|
1617 | + if ($this->_registration->group_size() > 1) { |
|
1618 | + add_meta_box( |
|
1619 | + 'edit-reg-attendees-mbox', |
|
1620 | + esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
1621 | + array($this, '_reg_attendees_meta_box'), |
|
1622 | + $this->wp_page_slug, |
|
1623 | + 'normal', |
|
1624 | + 'high' |
|
1625 | + ); |
|
1626 | + } |
|
1627 | + } |
|
1628 | + |
|
1629 | + |
|
1630 | + /** |
|
1631 | + * set_reg_status_buttons_metabox |
|
1632 | + * |
|
1633 | + * @access protected |
|
1634 | + * @return string |
|
1635 | + * @throws \EE_Error |
|
1636 | + */ |
|
1637 | + public function set_reg_status_buttons_metabox() |
|
1638 | + { |
|
1639 | + $this->_set_registration_object(); |
|
1640 | + $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
1641 | + echo $change_reg_status_form->form_open( |
|
1642 | + self::add_query_args_and_nonce( |
|
1643 | + array( |
|
1644 | + 'action' => 'change_reg_status', |
|
1645 | + ), |
|
1646 | + REG_ADMIN_URL |
|
1647 | + ) |
|
1648 | + ); |
|
1649 | + echo $change_reg_status_form->get_html(); |
|
1650 | + echo $change_reg_status_form->form_close(); |
|
1651 | + } |
|
1652 | + |
|
1653 | + |
|
1654 | + |
|
1655 | + /** |
|
1656 | + * @return EE_Form_Section_Proper |
|
1657 | + * @throws EE_Error |
|
1658 | + */ |
|
1659 | + protected function _generate_reg_status_change_form() |
|
1660 | + { |
|
1661 | + return new EE_Form_Section_Proper(array( |
|
1662 | + 'name' => 'reg_status_change_form', |
|
1663 | + 'html_id' => 'reg-status-change-form', |
|
1664 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1665 | + 'subsections' => array( |
|
1666 | + 'return' => new EE_Hidden_Input(array( |
|
1667 | + 'name' => 'return', |
|
1668 | + 'default' => 'view_registration', |
|
1669 | + )), |
|
1670 | + 'REG_ID' => new EE_Hidden_Input(array( |
|
1671 | + 'name' => 'REG_ID', |
|
1672 | + 'default' => $this->_registration->ID(), |
|
1673 | + )), |
|
1674 | + 'current_status' => new EE_Form_Section_HTML( |
|
1675 | + EEH_HTML::tr( |
|
1676 | + EEH_HTML::th( |
|
1677 | + EEH_HTML::label( |
|
1678 | + EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso') |
|
1679 | + ) |
|
1680 | + ) |
|
1681 | + ) |
|
1682 | + . EEH_HTML::td( |
|
1683 | + EEH_HTML::strong( |
|
1684 | + $this->_registration->pretty_status(), |
|
1685 | + '', |
|
1686 | + 'status-' . $this->_registration->status_ID(), |
|
1687 | + 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
1688 | + ) |
|
1689 | + ) |
|
1690 | + ) |
|
1691 | + ), |
|
1692 | + 'reg_status' => new EE_Select_Input( |
|
1693 | + $this->_get_reg_statuses(), |
|
1694 | + array( |
|
1695 | + 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
1696 | + 'default' => $this->_registration->status_ID(), |
|
1697 | + ) |
|
1698 | + ), |
|
1699 | + 'send_notifications' => new EE_Yes_No_Input( |
|
1700 | + array( |
|
1701 | + 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
1702 | + 'default' => false, |
|
1703 | + 'html_help_text' => esc_html__( |
|
1704 | + 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
1705 | + 'event_espresso' |
|
1706 | + ), |
|
1707 | + ) |
|
1708 | + ), |
|
1709 | + 'submit' => new EE_Submit_Input( |
|
1710 | + array( |
|
1711 | + 'html_class' => 'button-primary', |
|
1712 | + 'html_label_text' => ' ', |
|
1713 | + 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
1714 | + ) |
|
1715 | + ), |
|
1716 | + ), |
|
1717 | + )); |
|
1718 | + } |
|
1719 | + |
|
1720 | + |
|
1721 | + /** |
|
1722 | + * Returns an array of all the buttons for the various statuses and switch status actions |
|
1723 | + * |
|
1724 | + * @return array |
|
1725 | + * @throws EE_Error |
|
1726 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1727 | + */ |
|
1728 | + protected function _get_reg_statuses() |
|
1729 | + { |
|
1730 | + $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
1731 | + unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
1732 | + // get current reg status |
|
1733 | + $current_status = $this->_registration->status_ID(); |
|
1734 | + // is registration for free event? This will determine whether to display the pending payment option |
|
1735 | + if ( |
|
1736 | + $current_status !== EEM_Registration::status_id_pending_payment |
|
1737 | + && $this->_registration->transaction()->is_free() |
|
1738 | + ) { |
|
1739 | + unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
1740 | + } |
|
1741 | + return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
1742 | + } |
|
1743 | + |
|
1744 | + |
|
1745 | + |
|
1746 | + /** |
|
1747 | + * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
1748 | + * |
|
1749 | + * @param bool $status REG status given for changing registrations to. |
|
1750 | + * @param bool $notify Whether to send messages notifications or not. |
|
1751 | + * @return array (array with reg_id(s) updated and whether update was successful. |
|
1752 | + * @throws \EE_Error |
|
1753 | + */ |
|
1754 | + protected function _set_registration_status_from_request($status = false, $notify = false) |
|
1755 | + { |
|
1756 | + if (isset($this->_req_data['reg_status_change_form'])) { |
|
1757 | + $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
1758 | + ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
1759 | + } else { |
|
1760 | + $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
1761 | + } |
|
1762 | + $success = $this->_set_registration_status($REG_IDs, $status); |
|
1763 | + //notify? |
|
1764 | + if ($success |
|
1765 | + && $notify |
|
1766 | + && EE_Registry::instance()->CAP->current_user_can( |
|
1767 | + 'ee_send_message', |
|
1768 | + 'espresso_registrations_resend_registration' |
|
1769 | + ) |
|
1770 | + ) { |
|
1771 | + $this->_process_resend_registration(); |
|
1772 | + } |
|
1773 | + return $success; |
|
1774 | + } |
|
1775 | + |
|
1776 | + |
|
1777 | + |
|
1778 | + /** |
|
1779 | + * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
1780 | + * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
1781 | + * |
|
1782 | + * @param array $REG_IDs |
|
1783 | + * @param bool $status |
|
1784 | + * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
1785 | + * @throws \RuntimeException |
|
1786 | + * @throws \EE_Error |
|
1787 | + * the array of updated registrations). |
|
1788 | + * @throws EE_Error |
|
1789 | + * @throws RuntimeException |
|
1790 | + */ |
|
1791 | + protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
1792 | + { |
|
1793 | + $success = false; |
|
1794 | + // typecast $REG_IDs |
|
1795 | + $REG_IDs = (array)$REG_IDs; |
|
1796 | + if ( ! empty($REG_IDs)) { |
|
1797 | + $success = true; |
|
1798 | + // set default status if none is passed |
|
1799 | + $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
1800 | + // sanitize $REG_IDs |
|
1801 | + $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
1802 | + //loop through REG_ID's and change status |
|
1803 | + foreach ($REG_IDs as $REG_ID) { |
|
1804 | + $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
1805 | + if ($registration instanceof EE_Registration) { |
|
1806 | + $registration->set_status($status); |
|
1807 | + $result = $registration->save(); |
|
1808 | + // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
1809 | + $success = $result !== false ? $success : false; |
|
1810 | + } |
|
1811 | + } |
|
1812 | + } |
|
1813 | + //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
1814 | + $this->_req_data['_REG_ID'] = $REG_IDs; |
|
1815 | + //return $success and processed registrations |
|
1816 | + return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
1817 | + } |
|
1818 | + |
|
1819 | + |
|
1820 | + /** |
|
1821 | + * Common logic for setting up success message and redirecting to appropriate route |
|
1822 | + * |
|
1823 | + * @param string $STS_ID status id for the registration changed to |
|
1824 | + * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
1825 | + * @return void |
|
1826 | + */ |
|
1827 | + protected function _reg_status_change_return($STS_ID, $notify = false) |
|
1828 | + { |
|
1829 | + $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
1830 | + : array('success' => false); |
|
1831 | + $success = isset($result['success']) && $result['success']; |
|
1832 | + //setup success message |
|
1833 | + if ($success) { |
|
1834 | + if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
1835 | + $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
1836 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
1837 | + } else { |
|
1838 | + $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
1839 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
1840 | + } |
|
1841 | + EE_Error::add_success($msg); |
|
1842 | + } else { |
|
1843 | + EE_Error::add_error( |
|
1844 | + esc_html__( |
|
1845 | + 'Something went wrong, and the status was not changed', |
|
1846 | + 'event_espresso' |
|
1847 | + ), __FILE__, __LINE__, __FUNCTION__ |
|
1848 | + ); |
|
1849 | + } |
|
1850 | + if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
1851 | + $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
1852 | + } else { |
|
1853 | + $route = array('action' => 'default'); |
|
1854 | + } |
|
1855 | + //unset nonces |
|
1856 | + foreach ($this->_req_data as $ref => $value) { |
|
1857 | + if (strpos($ref, 'nonce') !== false) { |
|
1858 | + unset($this->_req_data[$ref]); |
|
1859 | + continue; |
|
1860 | + } |
|
1861 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
1862 | + $this->_req_data[$ref] = $value; |
|
1863 | + } |
|
1864 | + //merge request vars so that the reloaded list table contains any existing filter query params |
|
1865 | + $route = array_merge($this->_req_data, $route); |
|
1866 | + $this->_redirect_after_action($success, '', '', $route, true); |
|
1867 | + } |
|
1868 | + |
|
1869 | + |
|
1870 | + /** |
|
1871 | + * incoming reg status change from reg details page. |
|
1872 | + * |
|
1873 | + * @return void |
|
1874 | + */ |
|
1875 | + protected function _change_reg_status() |
|
1876 | + { |
|
1877 | + $this->_req_data['return'] = 'view_registration'; |
|
1878 | + //set notify based on whether the send notifications toggle is set or not |
|
1879 | + $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
1880 | + //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
1881 | + $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
1882 | + ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
1883 | + switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
1884 | + case EEM_Registration::status_id_approved : |
|
1885 | + case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
1886 | + $this->approve_registration($notify); |
|
1887 | + break; |
|
1888 | + case EEM_Registration::status_id_pending_payment : |
|
1889 | + case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
1890 | + $this->pending_registration($notify); |
|
1891 | + break; |
|
1892 | + case EEM_Registration::status_id_not_approved : |
|
1893 | + case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
1894 | + $this->not_approve_registration($notify); |
|
1895 | + break; |
|
1896 | + case EEM_Registration::status_id_declined : |
|
1897 | + case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
1898 | + $this->decline_registration($notify); |
|
1899 | + break; |
|
1900 | + case EEM_Registration::status_id_cancelled : |
|
1901 | + case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
1902 | + $this->cancel_registration($notify); |
|
1903 | + break; |
|
1904 | + case EEM_Registration::status_id_wait_list : |
|
1905 | + case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
1906 | + $this->wait_list_registration($notify); |
|
1907 | + break; |
|
1908 | + case EEM_Registration::status_id_incomplete : |
|
1909 | + default : |
|
1910 | + $result['success'] = false; |
|
1911 | + unset($this->_req_data['return']); |
|
1912 | + $this->_reg_status_change_return('', false); |
|
1913 | + break; |
|
1914 | + } |
|
1915 | + } |
|
1916 | + |
|
1917 | + |
|
1918 | + /** |
|
1919 | + * Callback for bulk action routes. |
|
1920 | + * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
1921 | + * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
1922 | + * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
1923 | + * when an action is happening on just a single registration). |
|
1924 | + * @param $action |
|
1925 | + * @param bool $notify |
|
1926 | + */ |
|
1927 | + protected function bulk_action_on_registrations($action, $notify = false) { |
|
1928 | + do_action( |
|
1929 | + 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
1930 | + $this, |
|
1931 | + $action, |
|
1932 | + $notify |
|
1933 | + ); |
|
1934 | + $method = $action . '_registration'; |
|
1935 | + if (method_exists($this, $method)) { |
|
1936 | + $this->$method($notify); |
|
1937 | + } |
|
1938 | + } |
|
1939 | + |
|
1940 | + |
|
1941 | + /** |
|
1942 | + * approve_registration |
|
1943 | + * |
|
1944 | + * @access protected |
|
1945 | + * @param bool $notify whether or not to notify the registrant about their approval. |
|
1946 | + * @return void |
|
1947 | + */ |
|
1948 | + protected function approve_registration($notify = false) |
|
1949 | + { |
|
1950 | + $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
1951 | + } |
|
1952 | + |
|
1953 | + |
|
1954 | + /** |
|
1955 | + * decline_registration |
|
1956 | + * |
|
1957 | + * @access protected |
|
1958 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
1959 | + * @return void |
|
1960 | + */ |
|
1961 | + protected function decline_registration($notify = false) |
|
1962 | + { |
|
1963 | + $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
1964 | + } |
|
1965 | + |
|
1966 | + |
|
1967 | + /** |
|
1968 | + * cancel_registration |
|
1969 | + * |
|
1970 | + * @access protected |
|
1971 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
1972 | + * @return void |
|
1973 | + */ |
|
1974 | + protected function cancel_registration($notify = false) |
|
1975 | + { |
|
1976 | + $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
1977 | + } |
|
1978 | + |
|
1979 | + |
|
1980 | + /** |
|
1981 | + * not_approve_registration |
|
1982 | + * |
|
1983 | + * @access protected |
|
1984 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
1985 | + * @return void |
|
1986 | + */ |
|
1987 | + protected function not_approve_registration($notify = false) |
|
1988 | + { |
|
1989 | + $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
1990 | + } |
|
1991 | + |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * decline_registration |
|
1995 | + * |
|
1996 | + * @access protected |
|
1997 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
1998 | + * @return void |
|
1999 | + */ |
|
2000 | + protected function pending_registration($notify = false) |
|
2001 | + { |
|
2002 | + $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
2003 | + } |
|
2004 | + |
|
2005 | + |
|
2006 | + /** |
|
2007 | + * waitlist_registration |
|
2008 | + * |
|
2009 | + * @access protected |
|
2010 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
2011 | + * @return void |
|
2012 | + */ |
|
2013 | + protected function wait_list_registration($notify = false) |
|
2014 | + { |
|
2015 | + $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
2016 | + } |
|
2017 | + |
|
2018 | + |
|
2019 | + /** |
|
2020 | + * generates HTML for the Registration main meta box |
|
2021 | + * |
|
2022 | + * @access public |
|
2023 | + * @return void |
|
2024 | + * @throws DomainException |
|
2025 | + * @throws EE_Error |
|
2026 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
2027 | + */ |
|
2028 | + public function _reg_details_meta_box() |
|
2029 | + { |
|
2030 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
2031 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
2032 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
2033 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
2034 | + : EE_Transaction::new_instance(); |
|
2035 | + $this->_session = $transaction->session_data(); |
|
2036 | + $filters = new EE_Line_Item_Filter_Collection(); |
|
2037 | + //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
2038 | + $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
2039 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
2040 | + $transaction->total_line_item()); |
|
2041 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
2042 | + $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
2043 | + 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
2044 | + $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
2045 | + $filtered_line_item_tree, |
|
2046 | + array('EE_Registration' => $this->_registration) |
|
2047 | + ); |
|
2048 | + $attendee = $this->_registration->attendee(); |
|
2049 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
2050 | + 'ee_read_transaction', |
|
2051 | + 'espresso_transactions_view_transaction' |
|
2052 | + )) { |
|
2053 | + $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
2054 | + EE_Admin_Page::add_query_args_and_nonce( |
|
2055 | + array( |
|
2056 | + 'action' => 'view_transaction', |
|
2057 | + 'TXN_ID' => $transaction->ID(), |
|
2058 | + ), |
|
2059 | + TXN_ADMIN_URL |
|
2060 | + ), |
|
2061 | + esc_html__(' View Transaction', 'event_espresso'), |
|
2062 | + 'button secondary-button right', |
|
2063 | + 'dashicons dashicons-cart' |
|
2064 | + ); |
|
2065 | + } else { |
|
2066 | + $this->_template_args['view_transaction_button'] = ''; |
|
2067 | + } |
|
2068 | + if ($attendee instanceof EE_Attendee |
|
2069 | + && EE_Registry::instance()->CAP->current_user_can( |
|
2070 | + 'ee_send_message', |
|
2071 | + 'espresso_registrations_resend_registration' |
|
2072 | + ) |
|
2073 | + ) { |
|
2074 | + $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
2075 | + EE_Admin_Page::add_query_args_and_nonce( |
|
2076 | + array( |
|
2077 | + 'action' => 'resend_registration', |
|
2078 | + '_REG_ID' => $this->_registration->ID(), |
|
2079 | + 'redirect_to' => 'view_registration', |
|
2080 | + ), |
|
2081 | + REG_ADMIN_URL |
|
2082 | + ), |
|
2083 | + esc_html__(' Resend Registration', 'event_espresso'), |
|
2084 | + 'button secondary-button right', |
|
2085 | + 'dashicons dashicons-email-alt' |
|
2086 | + ); |
|
2087 | + } else { |
|
2088 | + $this->_template_args['resend_registration_button'] = ''; |
|
2089 | + } |
|
2090 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
2091 | + $payment = $transaction->get_first_related('Payment'); |
|
2092 | + $payment = ! $payment instanceof EE_Payment |
|
2093 | + ? EE_Payment::new_instance() |
|
2094 | + : $payment; |
|
2095 | + $payment_method = $payment->get_first_related('Payment_Method'); |
|
2096 | + $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
2097 | + ? EE_Payment_Method::new_instance() |
|
2098 | + : $payment_method; |
|
2099 | + $reg_details = array( |
|
2100 | + 'payment_method' => $payment_method->name(), |
|
2101 | + 'response_msg' => $payment->gateway_response(), |
|
2102 | + 'registration_id' => $this->_registration->get('REG_code'), |
|
2103 | + 'registration_session' => $this->_registration->session_ID(), |
|
2104 | + 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
2105 | + 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
2106 | + ); |
|
2107 | + if (isset($reg_details['registration_id'])) { |
|
2108 | + $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
2109 | + $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
2110 | + 'Registration ID', |
|
2111 | + 'event_espresso' |
|
2112 | + ); |
|
2113 | + $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
2114 | + } |
|
2115 | + if (isset($reg_details['payment_method'])) { |
|
2116 | + $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
2117 | + $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
2118 | + 'Most Recent Payment Method', |
|
2119 | + 'event_espresso' |
|
2120 | + ); |
|
2121 | + $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
2122 | + $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
2123 | + $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
2124 | + 'Payment method response', |
|
2125 | + 'event_espresso' |
|
2126 | + ); |
|
2127 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
2128 | + } |
|
2129 | + $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
2130 | + $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
2131 | + 'Registration Session', |
|
2132 | + 'event_espresso' |
|
2133 | + ); |
|
2134 | + $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
2135 | + $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
2136 | + $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
2137 | + 'Registration placed from IP', |
|
2138 | + 'event_espresso' |
|
2139 | + ); |
|
2140 | + $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
2141 | + $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
2142 | + $this->_template_args['reg_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
2143 | + 'event_espresso'); |
|
2144 | + $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
2145 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
2146 | + array( |
|
2147 | + 'action' => 'default', |
|
2148 | + 'event_id' => $this->_registration->event_ID(), |
|
2149 | + ), |
|
2150 | + REG_ADMIN_URL |
|
2151 | + ); |
|
2152 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
2153 | + $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
2154 | + $template_path = |
|
2155 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
2156 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2157 | + } |
|
2158 | + |
|
2159 | + |
|
2160 | + /** |
|
2161 | + * generates HTML for the Registration Questions meta box. |
|
2162 | + * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
2163 | + * otherwise uses new forms system |
|
2164 | + * |
|
2165 | + * @access public |
|
2166 | + * @return void |
|
2167 | + * @throws DomainException |
|
2168 | + * @throws EE_Error |
|
2169 | + */ |
|
2170 | + public function _reg_questions_meta_box() |
|
2171 | + { |
|
2172 | + //allow someone to override this method entirely |
|
2173 | + if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
2174 | + $this->_registration)) { |
|
2175 | + $form = $this->_get_reg_custom_questions_form( |
|
2176 | + $this->_registration->ID() |
|
2177 | + ); |
|
2178 | + $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
2179 | + ? $form->get_html_and_js() |
|
2180 | + : ''; |
|
2181 | + $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
2182 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
2183 | + $template_path = |
|
2184 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
2185 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2186 | + } |
|
2187 | + } |
|
2188 | + |
|
2189 | + |
|
2190 | + /** |
|
2191 | + * form_before_question_group |
|
2192 | + * |
|
2193 | + * @deprecated as of 4.8.32.rc.000 |
|
2194 | + * @access public |
|
2195 | + * @param string $output |
|
2196 | + * @return string |
|
2197 | + */ |
|
2198 | + public function form_before_question_group($output) |
|
2199 | + { |
|
2200 | + EE_Error::doing_it_wrong( |
|
2201 | + __CLASS__ . '::' . __FUNCTION__, |
|
2202 | + esc_html__( |
|
2203 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2204 | + 'event_espresso' |
|
2205 | + ), |
|
2206 | + '4.8.32.rc.000' |
|
2207 | + ); |
|
2208 | + return ' |
|
2209 | 2209 | <table class="form-table ee-width-100"> |
2210 | 2210 | <tbody> |
2211 | 2211 | '; |
2212 | - } |
|
2213 | - |
|
2214 | - |
|
2215 | - /** |
|
2216 | - * form_after_question_group |
|
2217 | - * |
|
2218 | - * @deprecated as of 4.8.32.rc.000 |
|
2219 | - * @access public |
|
2220 | - * @param string $output |
|
2221 | - * @return string |
|
2222 | - */ |
|
2223 | - public function form_after_question_group($output) |
|
2224 | - { |
|
2225 | - EE_Error::doing_it_wrong( |
|
2226 | - __CLASS__ . '::' . __FUNCTION__, |
|
2227 | - esc_html__( |
|
2228 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2229 | - 'event_espresso' |
|
2230 | - ), |
|
2231 | - '4.8.32.rc.000' |
|
2232 | - ); |
|
2233 | - return ' |
|
2212 | + } |
|
2213 | + |
|
2214 | + |
|
2215 | + /** |
|
2216 | + * form_after_question_group |
|
2217 | + * |
|
2218 | + * @deprecated as of 4.8.32.rc.000 |
|
2219 | + * @access public |
|
2220 | + * @param string $output |
|
2221 | + * @return string |
|
2222 | + */ |
|
2223 | + public function form_after_question_group($output) |
|
2224 | + { |
|
2225 | + EE_Error::doing_it_wrong( |
|
2226 | + __CLASS__ . '::' . __FUNCTION__, |
|
2227 | + esc_html__( |
|
2228 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2229 | + 'event_espresso' |
|
2230 | + ), |
|
2231 | + '4.8.32.rc.000' |
|
2232 | + ); |
|
2233 | + return ' |
|
2234 | 2234 | <tr class="hide-if-no-js"> |
2235 | 2235 | <th> </th> |
2236 | 2236 | <td class="reg-admin-edit-attendee-question-td"> |
2237 | 2237 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
2238 | - . esc_attr__('click to edit question', 'event_espresso') |
|
2239 | - . '"> |
|
2238 | + . esc_attr__('click to edit question', 'event_espresso') |
|
2239 | + . '"> |
|
2240 | 2240 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
2241 | - . esc_html__('edit the above question group', 'event_espresso') |
|
2242 | - . '</span> |
|
2241 | + . esc_html__('edit the above question group', 'event_espresso') |
|
2242 | + . '</span> |
|
2243 | 2243 | <div class="dashicons dashicons-edit"></div> |
2244 | 2244 | </a> |
2245 | 2245 | </td> |
@@ -2247,558 +2247,558 @@ discard block |
||
2247 | 2247 | </tbody> |
2248 | 2248 | </table> |
2249 | 2249 | '; |
2250 | - } |
|
2251 | - |
|
2252 | - |
|
2253 | - /** |
|
2254 | - * form_form_field_label_wrap |
|
2255 | - * |
|
2256 | - * @deprecated as of 4.8.32.rc.000 |
|
2257 | - * @access public |
|
2258 | - * @param string $label |
|
2259 | - * @return string |
|
2260 | - */ |
|
2261 | - public function form_form_field_label_wrap($label) |
|
2262 | - { |
|
2263 | - EE_Error::doing_it_wrong( |
|
2264 | - __CLASS__ . '::' . __FUNCTION__, |
|
2265 | - esc_html__( |
|
2266 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2267 | - 'event_espresso' |
|
2268 | - ), |
|
2269 | - '4.8.32.rc.000' |
|
2270 | - ); |
|
2271 | - return ' |
|
2250 | + } |
|
2251 | + |
|
2252 | + |
|
2253 | + /** |
|
2254 | + * form_form_field_label_wrap |
|
2255 | + * |
|
2256 | + * @deprecated as of 4.8.32.rc.000 |
|
2257 | + * @access public |
|
2258 | + * @param string $label |
|
2259 | + * @return string |
|
2260 | + */ |
|
2261 | + public function form_form_field_label_wrap($label) |
|
2262 | + { |
|
2263 | + EE_Error::doing_it_wrong( |
|
2264 | + __CLASS__ . '::' . __FUNCTION__, |
|
2265 | + esc_html__( |
|
2266 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2267 | + 'event_espresso' |
|
2268 | + ), |
|
2269 | + '4.8.32.rc.000' |
|
2270 | + ); |
|
2271 | + return ' |
|
2272 | 2272 | <tr> |
2273 | 2273 | <th> |
2274 | 2274 | ' . $label . ' |
2275 | 2275 | </th>'; |
2276 | - } |
|
2277 | - |
|
2278 | - |
|
2279 | - /** |
|
2280 | - * form_form_field_input__wrap |
|
2281 | - * |
|
2282 | - * @deprecated as of 4.8.32.rc.000 |
|
2283 | - * @access public |
|
2284 | - * @param string $input |
|
2285 | - * @return string |
|
2286 | - */ |
|
2287 | - public function form_form_field_input__wrap($input) |
|
2288 | - { |
|
2289 | - EE_Error::doing_it_wrong( |
|
2290 | - __CLASS__ . '::' . __FUNCTION__, |
|
2291 | - esc_html__( |
|
2292 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2293 | - 'event_espresso' |
|
2294 | - ), |
|
2295 | - '4.8.32.rc.000' |
|
2296 | - ); |
|
2297 | - return ' |
|
2276 | + } |
|
2277 | + |
|
2278 | + |
|
2279 | + /** |
|
2280 | + * form_form_field_input__wrap |
|
2281 | + * |
|
2282 | + * @deprecated as of 4.8.32.rc.000 |
|
2283 | + * @access public |
|
2284 | + * @param string $input |
|
2285 | + * @return string |
|
2286 | + */ |
|
2287 | + public function form_form_field_input__wrap($input) |
|
2288 | + { |
|
2289 | + EE_Error::doing_it_wrong( |
|
2290 | + __CLASS__ . '::' . __FUNCTION__, |
|
2291 | + esc_html__( |
|
2292 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
2293 | + 'event_espresso' |
|
2294 | + ), |
|
2295 | + '4.8.32.rc.000' |
|
2296 | + ); |
|
2297 | + return ' |
|
2298 | 2298 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
2299 | 2299 | ' . $input . ' |
2300 | 2300 | </td> |
2301 | 2301 | </tr>'; |
2302 | - } |
|
2303 | - |
|
2304 | - |
|
2305 | - /** |
|
2306 | - * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
2307 | - * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
2308 | - * to display the page |
|
2309 | - * |
|
2310 | - * @access protected |
|
2311 | - * @return void |
|
2312 | - * @throws EE_Error |
|
2313 | - */ |
|
2314 | - protected function _update_attendee_registration_form() |
|
2315 | - { |
|
2316 | - do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
2317 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
2318 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
2319 | - $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
2320 | - if ($success) { |
|
2321 | - $what = esc_html__('Registration Form', 'event_espresso'); |
|
2322 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
2323 | - : array('action' => 'default'); |
|
2324 | - $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
2325 | - } |
|
2326 | - } |
|
2327 | - } |
|
2328 | - |
|
2329 | - |
|
2330 | - /** |
|
2331 | - * Gets the form for saving registrations custom questions (if done |
|
2332 | - * previously retrieves the cached form object, which may have validation errors in it) |
|
2333 | - * |
|
2334 | - * @param int $REG_ID |
|
2335 | - * @return EE_Registration_Custom_Questions_Form |
|
2336 | - * @throws EE_Error |
|
2337 | - */ |
|
2338 | - protected function _get_reg_custom_questions_form($REG_ID) |
|
2339 | - { |
|
2340 | - if ( ! $this->_reg_custom_questions_form) { |
|
2341 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
2342 | - $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
2343 | - EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
2344 | - ); |
|
2345 | - $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
2346 | - } |
|
2347 | - return $this->_reg_custom_questions_form; |
|
2348 | - } |
|
2349 | - |
|
2350 | - |
|
2351 | - /** |
|
2352 | - * Saves |
|
2353 | - * |
|
2354 | - * @access private |
|
2355 | - * @param bool $REG_ID |
|
2356 | - * @return bool |
|
2357 | - * @throws EE_Error |
|
2358 | - */ |
|
2359 | - private function _save_reg_custom_questions_form($REG_ID = false) |
|
2360 | - { |
|
2361 | - if ( ! $REG_ID) { |
|
2362 | - EE_Error::add_error( |
|
2363 | - esc_html__( |
|
2364 | - 'An error occurred. No registration ID was received.', 'event_espresso'), |
|
2365 | - __FILE__, __FUNCTION__, __LINE__ |
|
2366 | - ); |
|
2367 | - } |
|
2368 | - $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
2369 | - $form->receive_form_submission($this->_req_data); |
|
2370 | - $success = false; |
|
2371 | - if ($form->is_valid()) { |
|
2372 | - foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
2373 | - foreach ($question_group_form->inputs() as $question_id => $input) { |
|
2374 | - $where_conditions = array( |
|
2375 | - 'QST_ID' => $question_id, |
|
2376 | - 'REG_ID' => $REG_ID, |
|
2377 | - ); |
|
2378 | - $possibly_new_values = array( |
|
2379 | - 'ANS_value' => $input->normalized_value(), |
|
2380 | - ); |
|
2381 | - $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
2382 | - if ($answer instanceof EE_Answer) { |
|
2383 | - $success = $answer->save($possibly_new_values); |
|
2384 | - } else { |
|
2385 | - //insert it then |
|
2386 | - $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
2387 | - $answer = EE_Answer::new_instance($cols_n_vals); |
|
2388 | - $success = $answer->save(); |
|
2389 | - } |
|
2390 | - } |
|
2391 | - } |
|
2392 | - } else { |
|
2393 | - EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
2394 | - } |
|
2395 | - return $success; |
|
2396 | - } |
|
2397 | - |
|
2398 | - |
|
2399 | - /** |
|
2400 | - * generates HTML for the Registration main meta box |
|
2401 | - * |
|
2402 | - * @access public |
|
2403 | - * @return void |
|
2404 | - * @throws DomainException |
|
2405 | - * @throws EE_Error |
|
2406 | - */ |
|
2407 | - public function _reg_attendees_meta_box() |
|
2408 | - { |
|
2409 | - $REG = EEM_Registration::instance(); |
|
2410 | - //get all other registrations on this transaction, and cache |
|
2411 | - //the attendees for them so we don't have to run another query using force_join |
|
2412 | - $registrations = $REG->get_all(array( |
|
2413 | - array( |
|
2414 | - 'TXN_ID' => $this->_registration->transaction_ID(), |
|
2415 | - 'REG_ID' => array('!=', $this->_registration->ID()), |
|
2416 | - ), |
|
2417 | - 'force_join' => array('Attendee'), |
|
2418 | - )); |
|
2419 | - $this->_template_args['attendees'] = array(); |
|
2420 | - $this->_template_args['attendee_notice'] = ''; |
|
2421 | - if (empty($registrations) |
|
2422 | - || (is_array($registrations) |
|
2423 | - && ! EEH_Array::get_one_item_from_array($registrations)) |
|
2424 | - ) { |
|
2425 | - EE_Error::add_error( |
|
2426 | - esc_html__( |
|
2427 | - 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
2428 | - 'event_espresso' |
|
2429 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
2430 | - ); |
|
2431 | - $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
2432 | - } else { |
|
2433 | - $att_nmbr = 1; |
|
2434 | - foreach ($registrations as $registration) { |
|
2435 | - /* @var $registration EE_Registration */ |
|
2436 | - $attendee = $registration->attendee() |
|
2437 | - ? $registration->attendee() |
|
2438 | - : EEM_Attendee::instance() |
|
2439 | - ->create_default_object(); |
|
2440 | - $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
2441 | - $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname(); |
|
2442 | - $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname(); |
|
2443 | - $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email(); |
|
2444 | - $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); |
|
2445 | - $this->_template_args['attendees'][$att_nmbr]['address'] = implode( |
|
2446 | - ', ', |
|
2447 | - $attendee->full_address_as_array() |
|
2448 | - ); |
|
2449 | - $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
2450 | - array( |
|
2451 | - 'action' => 'edit_attendee', |
|
2452 | - 'post' => $attendee->ID(), |
|
2453 | - ), |
|
2454 | - REG_ADMIN_URL |
|
2455 | - ); |
|
2456 | - $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
2457 | - $att_nmbr++; |
|
2458 | - } |
|
2459 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
2460 | - } |
|
2461 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
2462 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2463 | - } |
|
2464 | - |
|
2465 | - |
|
2466 | - /** |
|
2467 | - * generates HTML for the Edit Registration side meta box |
|
2468 | - * |
|
2469 | - * @access public |
|
2470 | - * @return void |
|
2471 | - * @throws DomainException |
|
2472 | - * @throws EE_Error |
|
2473 | - */ |
|
2474 | - public function _reg_registrant_side_meta_box() |
|
2475 | - { |
|
2476 | - /*@var $attendee EE_Attendee */ |
|
2477 | - $att_check = $this->_registration->attendee(); |
|
2478 | - $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
2479 | - //now let's determine if this is not the primary registration. If it isn't then we set the |
|
2480 | - //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
2481 | - //primary registration object (that way we know if we need to show create button or not) |
|
2482 | - if ( ! $this->_registration->is_primary_registrant()) { |
|
2483 | - $primary_registration = $this->_registration->get_primary_registration(); |
|
2484 | - $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
2485 | - : null; |
|
2486 | - if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
2487 | - //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
2488 | - //custom attendee object so let's not worry about the primary reg. |
|
2489 | - $primary_registration = null; |
|
2490 | - } |
|
2491 | - } else { |
|
2492 | - $primary_registration = null; |
|
2493 | - } |
|
2494 | - $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
2495 | - $this->_template_args['fname'] = $attendee->fname(); |
|
2496 | - $this->_template_args['lname'] = $attendee->lname(); |
|
2497 | - $this->_template_args['email'] = $attendee->email(); |
|
2498 | - $this->_template_args['phone'] = $attendee->phone(); |
|
2499 | - $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
2500 | - //edit link |
|
2501 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
2502 | - 'action' => 'edit_attendee', |
|
2503 | - 'post' => $attendee->ID(), |
|
2504 | - ), REG_ADMIN_URL); |
|
2505 | - $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
2506 | - //create link |
|
2507 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
2508 | - ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
2509 | - 'action' => 'duplicate_attendee', |
|
2510 | - '_REG_ID' => $this->_registration->ID(), |
|
2511 | - ), REG_ADMIN_URL) : ''; |
|
2512 | - $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
2513 | - $this->_template_args['att_check'] = $att_check; |
|
2514 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
2515 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2516 | - } |
|
2517 | - |
|
2518 | - |
|
2519 | - /** |
|
2520 | - * trash or restore registrations |
|
2521 | - * |
|
2522 | - * @param boolean $trash whether to archive or restore |
|
2523 | - * @return void |
|
2524 | - * @throws EE_Error |
|
2525 | - * @throws RuntimeException |
|
2526 | - * @access protected |
|
2527 | - */ |
|
2528 | - protected function _trash_or_restore_registrations($trash = true) |
|
2529 | - { |
|
2530 | - //if empty _REG_ID then get out because there's nothing to do |
|
2531 | - if (empty($this->_req_data['_REG_ID'])) { |
|
2532 | - EE_Error::add_error( |
|
2533 | - sprintf( |
|
2534 | - esc_html__( |
|
2535 | - 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
2536 | - 'event_espresso' |
|
2537 | - ), |
|
2538 | - $trash ? 'trash' : 'restore' |
|
2539 | - ), |
|
2540 | - __FILE__, __LINE__, __FUNCTION__ |
|
2541 | - ); |
|
2542 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
2543 | - } |
|
2544 | - $success = 0; |
|
2545 | - $overwrite_msgs = false; |
|
2546 | - //Checkboxes |
|
2547 | - if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
2548 | - $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
2549 | - } |
|
2550 | - $reg_count = count($this->_req_data['_REG_ID']); |
|
2551 | - // cycle thru checkboxes |
|
2552 | - foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
2553 | - /** @var EE_Registration $REG */ |
|
2554 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
2555 | - $payments = $REG->registration_payments(); |
|
2556 | - if (! empty($payments)) { |
|
2557 | - $name = $REG->attendee() instanceof EE_Attendee |
|
2558 | - ? $REG->attendee()->full_name() |
|
2559 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
2560 | - $overwrite_msgs = true; |
|
2561 | - EE_Error::add_error( |
|
2562 | - sprintf( |
|
2563 | - esc_html__( |
|
2564 | - 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
2565 | - 'event_espresso' |
|
2566 | - ), |
|
2567 | - $name |
|
2568 | - ), |
|
2569 | - __FILE__, __FUNCTION__, __LINE__ |
|
2570 | - ); |
|
2571 | - //can't trash this registration because it has payments. |
|
2572 | - continue; |
|
2573 | - } |
|
2574 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
2575 | - if ($updated) { |
|
2576 | - $success++; |
|
2577 | - } |
|
2578 | - } |
|
2579 | - $this->_redirect_after_action( |
|
2580 | - $success === $reg_count, // were ALL registrations affected? |
|
2581 | - $success > 1 |
|
2582 | - ? esc_html__('Registrations', 'event_espresso') |
|
2583 | - : esc_html__('Registration', 'event_espresso'), |
|
2584 | - $trash |
|
2585 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
2586 | - : esc_html__('restored', 'event_espresso'), |
|
2587 | - array('action' => 'default'), |
|
2588 | - $overwrite_msgs |
|
2589 | - ); |
|
2590 | - } |
|
2591 | - |
|
2592 | - |
|
2593 | - /** |
|
2594 | - * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
2595 | - * registration but also. |
|
2596 | - * 1. Removing relations to EE_Attendee |
|
2597 | - * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
2598 | - * ALSO trashed. |
|
2599 | - * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
2600 | - * 4. Removing relationships between all tickets and the related registrations |
|
2601 | - * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
2602 | - * 6. Deleting permanently any related Checkins. |
|
2603 | - * |
|
2604 | - * @return void |
|
2605 | - * @throws EE_Error |
|
2606 | - */ |
|
2607 | - protected function _delete_registrations() |
|
2608 | - { |
|
2609 | - $REG_MDL = EEM_Registration::instance(); |
|
2610 | - $success = 1; |
|
2611 | - //Checkboxes |
|
2612 | - if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
2613 | - // if array has more than one element than success message should be plural |
|
2614 | - $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
2615 | - // cycle thru checkboxes |
|
2616 | - while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
2617 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
2618 | - if ( ! $REG instanceof EE_Registration) { |
|
2619 | - continue; |
|
2620 | - } |
|
2621 | - $deleted = $this->_delete_registration($REG); |
|
2622 | - if ( ! $deleted) { |
|
2623 | - $success = 0; |
|
2624 | - } |
|
2625 | - } |
|
2626 | - } else { |
|
2627 | - // grab single id and delete |
|
2628 | - $REG_ID = $this->_req_data['_REG_ID']; |
|
2629 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
2630 | - $deleted = $this->_delete_registration($REG); |
|
2631 | - if ( ! $deleted) { |
|
2632 | - $success = 0; |
|
2633 | - } |
|
2634 | - } |
|
2635 | - $what = $success > 1 |
|
2636 | - ? esc_html__('Registrations', 'event_espresso') |
|
2637 | - : esc_html__('Registration', 'event_espresso'); |
|
2638 | - $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
2639 | - $this->_redirect_after_action( |
|
2640 | - $success, |
|
2641 | - $what, |
|
2642 | - $action_desc, |
|
2643 | - array('action' => 'default'), |
|
2644 | - true |
|
2645 | - ); |
|
2646 | - } |
|
2647 | - |
|
2648 | - |
|
2649 | - /** |
|
2650 | - * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
2651 | - * models get affected. |
|
2652 | - * |
|
2653 | - * @param EE_Registration $REG registration to be deleted permenantly |
|
2654 | - * @return bool true = successful deletion, false = fail. |
|
2655 | - * @throws EE_Error |
|
2656 | - */ |
|
2657 | - protected function _delete_registration(EE_Registration $REG) |
|
2658 | - { |
|
2659 | - //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
2660 | - //registrations on the transaction that are NOT trashed. |
|
2661 | - $TXN = $REG->get_first_related('Transaction'); |
|
2662 | - $REGS = $TXN->get_many_related('Registration'); |
|
2663 | - $all_trashed = true; |
|
2664 | - foreach ($REGS as $registration) { |
|
2665 | - if ( ! $registration->get('REG_deleted')) { |
|
2666 | - $all_trashed = false; |
|
2667 | - } |
|
2668 | - } |
|
2669 | - if ( ! $all_trashed) { |
|
2670 | - EE_Error::add_error( |
|
2671 | - esc_html__( |
|
2672 | - 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
2673 | - 'event_espresso' |
|
2674 | - ), |
|
2675 | - __FILE__, __FUNCTION__, __LINE__ |
|
2676 | - ); |
|
2677 | - return false; |
|
2678 | - } |
|
2679 | - //k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
2680 | - //separately from THIS one). |
|
2681 | - foreach ($REGS as $registration) { |
|
2682 | - //delete related answers |
|
2683 | - $registration->delete_related_permanently('Answer'); |
|
2684 | - //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
2685 | - $attendee = $registration->get_first_related('Attendee'); |
|
2686 | - if ($attendee instanceof EE_Attendee) { |
|
2687 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
2688 | - } |
|
2689 | - //now remove relationships to tickets on this registration. |
|
2690 | - $registration->_remove_relations('Ticket'); |
|
2691 | - //now delete permanently the checkins related to this registration. |
|
2692 | - $registration->delete_related_permanently('Checkin'); |
|
2693 | - if ($registration->ID() === $REG->ID()) { |
|
2694 | - continue; |
|
2695 | - } //we don't want to delete permanently the existing registration just yet. |
|
2696 | - //remove relation to transaction for these registrations if NOT the existing registrations |
|
2697 | - $registration->_remove_relations('Transaction'); |
|
2698 | - //delete permanently any related messages. |
|
2699 | - $registration->delete_related_permanently('Message'); |
|
2700 | - //now delete this registration permanently |
|
2701 | - $registration->delete_permanently(); |
|
2702 | - } |
|
2703 | - //now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
2704 | - // (the transaction and line items should be all that's left). |
|
2705 | - // delete the line items related to the transaction for this registration. |
|
2706 | - $TXN->delete_related_permanently('Line_Item'); |
|
2707 | - //we need to remove all the relationships on the transaction |
|
2708 | - $TXN->delete_related_permanently('Payment'); |
|
2709 | - $TXN->delete_related_permanently('Extra_Meta'); |
|
2710 | - $TXN->delete_related_permanently('Message'); |
|
2711 | - //now we can delete this REG permanently (and the transaction of course) |
|
2712 | - $REG->delete_related_permanently('Transaction'); |
|
2713 | - return $REG->delete_permanently(); |
|
2714 | - } |
|
2715 | - |
|
2716 | - |
|
2717 | - /** |
|
2718 | - * generates HTML for the Register New Attendee Admin page |
|
2719 | - * |
|
2720 | - * @access private |
|
2721 | - * @throws DomainException |
|
2722 | - * @throws EE_Error |
|
2723 | - */ |
|
2724 | - public function new_registration() |
|
2725 | - { |
|
2726 | - if ( ! $this->_set_reg_event()) { |
|
2727 | - throw new EE_Error( |
|
2728 | - esc_html__( |
|
2729 | - 'Unable to continue with registering because there is no Event ID in the request', |
|
2730 | - 'event_espresso' |
|
2731 | - ) |
|
2732 | - ); |
|
2733 | - } |
|
2734 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
2735 | - // gotta start with a clean slate if we're not coming here via ajax |
|
2736 | - if ( ! defined('DOING_AJAX') |
|
2737 | - && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
2738 | - ) { |
|
2739 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
2740 | - } |
|
2741 | - $this->_template_args['event_name'] = ''; |
|
2742 | - // event name |
|
2743 | - if ($this->_reg_event) { |
|
2744 | - $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
2745 | - $edit_event_url = self::add_query_args_and_nonce(array( |
|
2746 | - 'action' => 'edit', |
|
2747 | - 'post' => $this->_reg_event->ID(), |
|
2748 | - ), EVENTS_ADMIN_URL); |
|
2749 | - $edit_event_lnk = '<a href="' |
|
2750 | - . $edit_event_url |
|
2751 | - . '" title="' |
|
2752 | - . esc_attr__('Edit ', 'event_espresso') |
|
2753 | - . $this->_reg_event->name() |
|
2754 | - . '">' |
|
2755 | - . esc_html__('Edit Event', 'event_espresso') |
|
2756 | - . '</a>'; |
|
2757 | - $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
2758 | - . $edit_event_lnk |
|
2759 | - . '</span>'; |
|
2760 | - } |
|
2761 | - $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
2762 | - if (defined('DOING_AJAX')) { |
|
2763 | - $this->_return_json(); |
|
2764 | - } |
|
2765 | - // grab header |
|
2766 | - $template_path = |
|
2767 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
2768 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
2769 | - $this->_template_args, true); |
|
2770 | - //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
2771 | - // the details template wrapper |
|
2772 | - $this->display_admin_page_with_sidebar(); |
|
2773 | - } |
|
2774 | - |
|
2775 | - |
|
2776 | - /** |
|
2777 | - * This returns the content for a registration step |
|
2778 | - * |
|
2779 | - * @access protected |
|
2780 | - * @return string html |
|
2781 | - * @throws DomainException |
|
2782 | - * @throws EE_Error |
|
2783 | - */ |
|
2784 | - protected function _get_registration_step_content() |
|
2785 | - { |
|
2786 | - if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
2787 | - $warning_msg = sprintf( |
|
2788 | - esc_html__( |
|
2789 | - '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
2790 | - 'event_espresso' |
|
2791 | - ), |
|
2792 | - '<br />', |
|
2793 | - '<h3 class="important-notice">', |
|
2794 | - '</h3>', |
|
2795 | - '<div class="float-right">', |
|
2796 | - '<span id="redirect_timer" class="important-notice">30</span>', |
|
2797 | - '</div>', |
|
2798 | - '<b>', |
|
2799 | - '</b>' |
|
2800 | - ); |
|
2801 | - return ' |
|
2302 | + } |
|
2303 | + |
|
2304 | + |
|
2305 | + /** |
|
2306 | + * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
2307 | + * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
2308 | + * to display the page |
|
2309 | + * |
|
2310 | + * @access protected |
|
2311 | + * @return void |
|
2312 | + * @throws EE_Error |
|
2313 | + */ |
|
2314 | + protected function _update_attendee_registration_form() |
|
2315 | + { |
|
2316 | + do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
2317 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
2318 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
2319 | + $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
2320 | + if ($success) { |
|
2321 | + $what = esc_html__('Registration Form', 'event_espresso'); |
|
2322 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
2323 | + : array('action' => 'default'); |
|
2324 | + $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
2325 | + } |
|
2326 | + } |
|
2327 | + } |
|
2328 | + |
|
2329 | + |
|
2330 | + /** |
|
2331 | + * Gets the form for saving registrations custom questions (if done |
|
2332 | + * previously retrieves the cached form object, which may have validation errors in it) |
|
2333 | + * |
|
2334 | + * @param int $REG_ID |
|
2335 | + * @return EE_Registration_Custom_Questions_Form |
|
2336 | + * @throws EE_Error |
|
2337 | + */ |
|
2338 | + protected function _get_reg_custom_questions_form($REG_ID) |
|
2339 | + { |
|
2340 | + if ( ! $this->_reg_custom_questions_form) { |
|
2341 | + require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
2342 | + $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
2343 | + EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
2344 | + ); |
|
2345 | + $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
2346 | + } |
|
2347 | + return $this->_reg_custom_questions_form; |
|
2348 | + } |
|
2349 | + |
|
2350 | + |
|
2351 | + /** |
|
2352 | + * Saves |
|
2353 | + * |
|
2354 | + * @access private |
|
2355 | + * @param bool $REG_ID |
|
2356 | + * @return bool |
|
2357 | + * @throws EE_Error |
|
2358 | + */ |
|
2359 | + private function _save_reg_custom_questions_form($REG_ID = false) |
|
2360 | + { |
|
2361 | + if ( ! $REG_ID) { |
|
2362 | + EE_Error::add_error( |
|
2363 | + esc_html__( |
|
2364 | + 'An error occurred. No registration ID was received.', 'event_espresso'), |
|
2365 | + __FILE__, __FUNCTION__, __LINE__ |
|
2366 | + ); |
|
2367 | + } |
|
2368 | + $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
2369 | + $form->receive_form_submission($this->_req_data); |
|
2370 | + $success = false; |
|
2371 | + if ($form->is_valid()) { |
|
2372 | + foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
2373 | + foreach ($question_group_form->inputs() as $question_id => $input) { |
|
2374 | + $where_conditions = array( |
|
2375 | + 'QST_ID' => $question_id, |
|
2376 | + 'REG_ID' => $REG_ID, |
|
2377 | + ); |
|
2378 | + $possibly_new_values = array( |
|
2379 | + 'ANS_value' => $input->normalized_value(), |
|
2380 | + ); |
|
2381 | + $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
2382 | + if ($answer instanceof EE_Answer) { |
|
2383 | + $success = $answer->save($possibly_new_values); |
|
2384 | + } else { |
|
2385 | + //insert it then |
|
2386 | + $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
2387 | + $answer = EE_Answer::new_instance($cols_n_vals); |
|
2388 | + $success = $answer->save(); |
|
2389 | + } |
|
2390 | + } |
|
2391 | + } |
|
2392 | + } else { |
|
2393 | + EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
2394 | + } |
|
2395 | + return $success; |
|
2396 | + } |
|
2397 | + |
|
2398 | + |
|
2399 | + /** |
|
2400 | + * generates HTML for the Registration main meta box |
|
2401 | + * |
|
2402 | + * @access public |
|
2403 | + * @return void |
|
2404 | + * @throws DomainException |
|
2405 | + * @throws EE_Error |
|
2406 | + */ |
|
2407 | + public function _reg_attendees_meta_box() |
|
2408 | + { |
|
2409 | + $REG = EEM_Registration::instance(); |
|
2410 | + //get all other registrations on this transaction, and cache |
|
2411 | + //the attendees for them so we don't have to run another query using force_join |
|
2412 | + $registrations = $REG->get_all(array( |
|
2413 | + array( |
|
2414 | + 'TXN_ID' => $this->_registration->transaction_ID(), |
|
2415 | + 'REG_ID' => array('!=', $this->_registration->ID()), |
|
2416 | + ), |
|
2417 | + 'force_join' => array('Attendee'), |
|
2418 | + )); |
|
2419 | + $this->_template_args['attendees'] = array(); |
|
2420 | + $this->_template_args['attendee_notice'] = ''; |
|
2421 | + if (empty($registrations) |
|
2422 | + || (is_array($registrations) |
|
2423 | + && ! EEH_Array::get_one_item_from_array($registrations)) |
|
2424 | + ) { |
|
2425 | + EE_Error::add_error( |
|
2426 | + esc_html__( |
|
2427 | + 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
2428 | + 'event_espresso' |
|
2429 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
2430 | + ); |
|
2431 | + $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
2432 | + } else { |
|
2433 | + $att_nmbr = 1; |
|
2434 | + foreach ($registrations as $registration) { |
|
2435 | + /* @var $registration EE_Registration */ |
|
2436 | + $attendee = $registration->attendee() |
|
2437 | + ? $registration->attendee() |
|
2438 | + : EEM_Attendee::instance() |
|
2439 | + ->create_default_object(); |
|
2440 | + $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
2441 | + $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname(); |
|
2442 | + $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname(); |
|
2443 | + $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email(); |
|
2444 | + $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); |
|
2445 | + $this->_template_args['attendees'][$att_nmbr]['address'] = implode( |
|
2446 | + ', ', |
|
2447 | + $attendee->full_address_as_array() |
|
2448 | + ); |
|
2449 | + $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
2450 | + array( |
|
2451 | + 'action' => 'edit_attendee', |
|
2452 | + 'post' => $attendee->ID(), |
|
2453 | + ), |
|
2454 | + REG_ADMIN_URL |
|
2455 | + ); |
|
2456 | + $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
2457 | + $att_nmbr++; |
|
2458 | + } |
|
2459 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
2460 | + } |
|
2461 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
2462 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2463 | + } |
|
2464 | + |
|
2465 | + |
|
2466 | + /** |
|
2467 | + * generates HTML for the Edit Registration side meta box |
|
2468 | + * |
|
2469 | + * @access public |
|
2470 | + * @return void |
|
2471 | + * @throws DomainException |
|
2472 | + * @throws EE_Error |
|
2473 | + */ |
|
2474 | + public function _reg_registrant_side_meta_box() |
|
2475 | + { |
|
2476 | + /*@var $attendee EE_Attendee */ |
|
2477 | + $att_check = $this->_registration->attendee(); |
|
2478 | + $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
2479 | + //now let's determine if this is not the primary registration. If it isn't then we set the |
|
2480 | + //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
2481 | + //primary registration object (that way we know if we need to show create button or not) |
|
2482 | + if ( ! $this->_registration->is_primary_registrant()) { |
|
2483 | + $primary_registration = $this->_registration->get_primary_registration(); |
|
2484 | + $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
2485 | + : null; |
|
2486 | + if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
2487 | + //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
2488 | + //custom attendee object so let's not worry about the primary reg. |
|
2489 | + $primary_registration = null; |
|
2490 | + } |
|
2491 | + } else { |
|
2492 | + $primary_registration = null; |
|
2493 | + } |
|
2494 | + $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
2495 | + $this->_template_args['fname'] = $attendee->fname(); |
|
2496 | + $this->_template_args['lname'] = $attendee->lname(); |
|
2497 | + $this->_template_args['email'] = $attendee->email(); |
|
2498 | + $this->_template_args['phone'] = $attendee->phone(); |
|
2499 | + $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
2500 | + //edit link |
|
2501 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
2502 | + 'action' => 'edit_attendee', |
|
2503 | + 'post' => $attendee->ID(), |
|
2504 | + ), REG_ADMIN_URL); |
|
2505 | + $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
2506 | + //create link |
|
2507 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
2508 | + ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
2509 | + 'action' => 'duplicate_attendee', |
|
2510 | + '_REG_ID' => $this->_registration->ID(), |
|
2511 | + ), REG_ADMIN_URL) : ''; |
|
2512 | + $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
2513 | + $this->_template_args['att_check'] = $att_check; |
|
2514 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
2515 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
2516 | + } |
|
2517 | + |
|
2518 | + |
|
2519 | + /** |
|
2520 | + * trash or restore registrations |
|
2521 | + * |
|
2522 | + * @param boolean $trash whether to archive or restore |
|
2523 | + * @return void |
|
2524 | + * @throws EE_Error |
|
2525 | + * @throws RuntimeException |
|
2526 | + * @access protected |
|
2527 | + */ |
|
2528 | + protected function _trash_or_restore_registrations($trash = true) |
|
2529 | + { |
|
2530 | + //if empty _REG_ID then get out because there's nothing to do |
|
2531 | + if (empty($this->_req_data['_REG_ID'])) { |
|
2532 | + EE_Error::add_error( |
|
2533 | + sprintf( |
|
2534 | + esc_html__( |
|
2535 | + 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
2536 | + 'event_espresso' |
|
2537 | + ), |
|
2538 | + $trash ? 'trash' : 'restore' |
|
2539 | + ), |
|
2540 | + __FILE__, __LINE__, __FUNCTION__ |
|
2541 | + ); |
|
2542 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
2543 | + } |
|
2544 | + $success = 0; |
|
2545 | + $overwrite_msgs = false; |
|
2546 | + //Checkboxes |
|
2547 | + if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
2548 | + $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
2549 | + } |
|
2550 | + $reg_count = count($this->_req_data['_REG_ID']); |
|
2551 | + // cycle thru checkboxes |
|
2552 | + foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
2553 | + /** @var EE_Registration $REG */ |
|
2554 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
2555 | + $payments = $REG->registration_payments(); |
|
2556 | + if (! empty($payments)) { |
|
2557 | + $name = $REG->attendee() instanceof EE_Attendee |
|
2558 | + ? $REG->attendee()->full_name() |
|
2559 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
2560 | + $overwrite_msgs = true; |
|
2561 | + EE_Error::add_error( |
|
2562 | + sprintf( |
|
2563 | + esc_html__( |
|
2564 | + 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
2565 | + 'event_espresso' |
|
2566 | + ), |
|
2567 | + $name |
|
2568 | + ), |
|
2569 | + __FILE__, __FUNCTION__, __LINE__ |
|
2570 | + ); |
|
2571 | + //can't trash this registration because it has payments. |
|
2572 | + continue; |
|
2573 | + } |
|
2574 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
2575 | + if ($updated) { |
|
2576 | + $success++; |
|
2577 | + } |
|
2578 | + } |
|
2579 | + $this->_redirect_after_action( |
|
2580 | + $success === $reg_count, // were ALL registrations affected? |
|
2581 | + $success > 1 |
|
2582 | + ? esc_html__('Registrations', 'event_espresso') |
|
2583 | + : esc_html__('Registration', 'event_espresso'), |
|
2584 | + $trash |
|
2585 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
2586 | + : esc_html__('restored', 'event_espresso'), |
|
2587 | + array('action' => 'default'), |
|
2588 | + $overwrite_msgs |
|
2589 | + ); |
|
2590 | + } |
|
2591 | + |
|
2592 | + |
|
2593 | + /** |
|
2594 | + * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
2595 | + * registration but also. |
|
2596 | + * 1. Removing relations to EE_Attendee |
|
2597 | + * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
2598 | + * ALSO trashed. |
|
2599 | + * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
2600 | + * 4. Removing relationships between all tickets and the related registrations |
|
2601 | + * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
2602 | + * 6. Deleting permanently any related Checkins. |
|
2603 | + * |
|
2604 | + * @return void |
|
2605 | + * @throws EE_Error |
|
2606 | + */ |
|
2607 | + protected function _delete_registrations() |
|
2608 | + { |
|
2609 | + $REG_MDL = EEM_Registration::instance(); |
|
2610 | + $success = 1; |
|
2611 | + //Checkboxes |
|
2612 | + if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
2613 | + // if array has more than one element than success message should be plural |
|
2614 | + $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
2615 | + // cycle thru checkboxes |
|
2616 | + while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
2617 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
2618 | + if ( ! $REG instanceof EE_Registration) { |
|
2619 | + continue; |
|
2620 | + } |
|
2621 | + $deleted = $this->_delete_registration($REG); |
|
2622 | + if ( ! $deleted) { |
|
2623 | + $success = 0; |
|
2624 | + } |
|
2625 | + } |
|
2626 | + } else { |
|
2627 | + // grab single id and delete |
|
2628 | + $REG_ID = $this->_req_data['_REG_ID']; |
|
2629 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
2630 | + $deleted = $this->_delete_registration($REG); |
|
2631 | + if ( ! $deleted) { |
|
2632 | + $success = 0; |
|
2633 | + } |
|
2634 | + } |
|
2635 | + $what = $success > 1 |
|
2636 | + ? esc_html__('Registrations', 'event_espresso') |
|
2637 | + : esc_html__('Registration', 'event_espresso'); |
|
2638 | + $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
2639 | + $this->_redirect_after_action( |
|
2640 | + $success, |
|
2641 | + $what, |
|
2642 | + $action_desc, |
|
2643 | + array('action' => 'default'), |
|
2644 | + true |
|
2645 | + ); |
|
2646 | + } |
|
2647 | + |
|
2648 | + |
|
2649 | + /** |
|
2650 | + * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
2651 | + * models get affected. |
|
2652 | + * |
|
2653 | + * @param EE_Registration $REG registration to be deleted permenantly |
|
2654 | + * @return bool true = successful deletion, false = fail. |
|
2655 | + * @throws EE_Error |
|
2656 | + */ |
|
2657 | + protected function _delete_registration(EE_Registration $REG) |
|
2658 | + { |
|
2659 | + //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
2660 | + //registrations on the transaction that are NOT trashed. |
|
2661 | + $TXN = $REG->get_first_related('Transaction'); |
|
2662 | + $REGS = $TXN->get_many_related('Registration'); |
|
2663 | + $all_trashed = true; |
|
2664 | + foreach ($REGS as $registration) { |
|
2665 | + if ( ! $registration->get('REG_deleted')) { |
|
2666 | + $all_trashed = false; |
|
2667 | + } |
|
2668 | + } |
|
2669 | + if ( ! $all_trashed) { |
|
2670 | + EE_Error::add_error( |
|
2671 | + esc_html__( |
|
2672 | + 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
2673 | + 'event_espresso' |
|
2674 | + ), |
|
2675 | + __FILE__, __FUNCTION__, __LINE__ |
|
2676 | + ); |
|
2677 | + return false; |
|
2678 | + } |
|
2679 | + //k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
2680 | + //separately from THIS one). |
|
2681 | + foreach ($REGS as $registration) { |
|
2682 | + //delete related answers |
|
2683 | + $registration->delete_related_permanently('Answer'); |
|
2684 | + //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
2685 | + $attendee = $registration->get_first_related('Attendee'); |
|
2686 | + if ($attendee instanceof EE_Attendee) { |
|
2687 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
2688 | + } |
|
2689 | + //now remove relationships to tickets on this registration. |
|
2690 | + $registration->_remove_relations('Ticket'); |
|
2691 | + //now delete permanently the checkins related to this registration. |
|
2692 | + $registration->delete_related_permanently('Checkin'); |
|
2693 | + if ($registration->ID() === $REG->ID()) { |
|
2694 | + continue; |
|
2695 | + } //we don't want to delete permanently the existing registration just yet. |
|
2696 | + //remove relation to transaction for these registrations if NOT the existing registrations |
|
2697 | + $registration->_remove_relations('Transaction'); |
|
2698 | + //delete permanently any related messages. |
|
2699 | + $registration->delete_related_permanently('Message'); |
|
2700 | + //now delete this registration permanently |
|
2701 | + $registration->delete_permanently(); |
|
2702 | + } |
|
2703 | + //now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
2704 | + // (the transaction and line items should be all that's left). |
|
2705 | + // delete the line items related to the transaction for this registration. |
|
2706 | + $TXN->delete_related_permanently('Line_Item'); |
|
2707 | + //we need to remove all the relationships on the transaction |
|
2708 | + $TXN->delete_related_permanently('Payment'); |
|
2709 | + $TXN->delete_related_permanently('Extra_Meta'); |
|
2710 | + $TXN->delete_related_permanently('Message'); |
|
2711 | + //now we can delete this REG permanently (and the transaction of course) |
|
2712 | + $REG->delete_related_permanently('Transaction'); |
|
2713 | + return $REG->delete_permanently(); |
|
2714 | + } |
|
2715 | + |
|
2716 | + |
|
2717 | + /** |
|
2718 | + * generates HTML for the Register New Attendee Admin page |
|
2719 | + * |
|
2720 | + * @access private |
|
2721 | + * @throws DomainException |
|
2722 | + * @throws EE_Error |
|
2723 | + */ |
|
2724 | + public function new_registration() |
|
2725 | + { |
|
2726 | + if ( ! $this->_set_reg_event()) { |
|
2727 | + throw new EE_Error( |
|
2728 | + esc_html__( |
|
2729 | + 'Unable to continue with registering because there is no Event ID in the request', |
|
2730 | + 'event_espresso' |
|
2731 | + ) |
|
2732 | + ); |
|
2733 | + } |
|
2734 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
2735 | + // gotta start with a clean slate if we're not coming here via ajax |
|
2736 | + if ( ! defined('DOING_AJAX') |
|
2737 | + && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
2738 | + ) { |
|
2739 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
2740 | + } |
|
2741 | + $this->_template_args['event_name'] = ''; |
|
2742 | + // event name |
|
2743 | + if ($this->_reg_event) { |
|
2744 | + $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
2745 | + $edit_event_url = self::add_query_args_and_nonce(array( |
|
2746 | + 'action' => 'edit', |
|
2747 | + 'post' => $this->_reg_event->ID(), |
|
2748 | + ), EVENTS_ADMIN_URL); |
|
2749 | + $edit_event_lnk = '<a href="' |
|
2750 | + . $edit_event_url |
|
2751 | + . '" title="' |
|
2752 | + . esc_attr__('Edit ', 'event_espresso') |
|
2753 | + . $this->_reg_event->name() |
|
2754 | + . '">' |
|
2755 | + . esc_html__('Edit Event', 'event_espresso') |
|
2756 | + . '</a>'; |
|
2757 | + $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
2758 | + . $edit_event_lnk |
|
2759 | + . '</span>'; |
|
2760 | + } |
|
2761 | + $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
2762 | + if (defined('DOING_AJAX')) { |
|
2763 | + $this->_return_json(); |
|
2764 | + } |
|
2765 | + // grab header |
|
2766 | + $template_path = |
|
2767 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
2768 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
2769 | + $this->_template_args, true); |
|
2770 | + //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
2771 | + // the details template wrapper |
|
2772 | + $this->display_admin_page_with_sidebar(); |
|
2773 | + } |
|
2774 | + |
|
2775 | + |
|
2776 | + /** |
|
2777 | + * This returns the content for a registration step |
|
2778 | + * |
|
2779 | + * @access protected |
|
2780 | + * @return string html |
|
2781 | + * @throws DomainException |
|
2782 | + * @throws EE_Error |
|
2783 | + */ |
|
2784 | + protected function _get_registration_step_content() |
|
2785 | + { |
|
2786 | + if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
2787 | + $warning_msg = sprintf( |
|
2788 | + esc_html__( |
|
2789 | + '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
2790 | + 'event_espresso' |
|
2791 | + ), |
|
2792 | + '<br />', |
|
2793 | + '<h3 class="important-notice">', |
|
2794 | + '</h3>', |
|
2795 | + '<div class="float-right">', |
|
2796 | + '<span id="redirect_timer" class="important-notice">30</span>', |
|
2797 | + '</div>', |
|
2798 | + '<b>', |
|
2799 | + '</b>' |
|
2800 | + ); |
|
2801 | + return ' |
|
2802 | 2802 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
2803 | 2803 | <script > |
2804 | 2804 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
@@ -2811,792 +2811,792 @@ discard block |
||
2811 | 2811 | } |
2812 | 2812 | }, 800 ); |
2813 | 2813 | </script >'; |
2814 | - } |
|
2815 | - $template_args = array( |
|
2816 | - 'title' => '', |
|
2817 | - 'content' => '', |
|
2818 | - 'step_button_text' => '', |
|
2819 | - 'show_notification_toggle' => false, |
|
2820 | - ); |
|
2821 | - //to indicate we're processing a new registration |
|
2822 | - $hidden_fields = array( |
|
2823 | - 'processing_registration' => array( |
|
2824 | - 'type' => 'hidden', |
|
2825 | - 'value' => 0, |
|
2826 | - ), |
|
2827 | - 'event_id' => array( |
|
2828 | - 'type' => 'hidden', |
|
2829 | - 'value' => $this->_reg_event->ID(), |
|
2830 | - ), |
|
2831 | - ); |
|
2832 | - //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
2833 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
2834 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
2835 | - switch ($step) { |
|
2836 | - case 'ticket' : |
|
2837 | - $hidden_fields['processing_registration']['value'] = 1; |
|
2838 | - $template_args['title'] = esc_html__( |
|
2839 | - 'Step One: Select the Ticket for this registration', |
|
2840 | - 'event_espresso' |
|
2841 | - ); |
|
2842 | - $template_args['content'] = |
|
2843 | - EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
2844 | - $template_args['step_button_text'] = esc_html__( |
|
2845 | - 'Add Tickets and Continue to Registrant Details', |
|
2846 | - 'event_espresso' |
|
2847 | - ); |
|
2848 | - $template_args['show_notification_toggle'] = false; |
|
2849 | - break; |
|
2850 | - case 'questions' : |
|
2851 | - $hidden_fields['processing_registration']['value'] = 2; |
|
2852 | - $template_args['title'] = esc_html__( |
|
2853 | - 'Step Two: Add Registrant Details for this Registration', |
|
2854 | - 'event_espresso' |
|
2855 | - ); |
|
2856 | - //in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
2857 | - // properly by the first process_reg_step run. |
|
2858 | - $template_args['content'] = |
|
2859 | - EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
2860 | - $template_args['step_button_text'] = esc_html__( |
|
2861 | - 'Save Registration and Continue to Details', |
|
2862 | - 'event_espresso' |
|
2863 | - ); |
|
2864 | - $template_args['show_notification_toggle'] = true; |
|
2865 | - break; |
|
2866 | - } |
|
2867 | - //we come back to the process_registration_step route. |
|
2868 | - $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
2869 | - return EEH_Template::display_template( |
|
2870 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
2871 | - $template_args, |
|
2872 | - true |
|
2873 | - ); |
|
2874 | - } |
|
2875 | - |
|
2876 | - |
|
2877 | - /** |
|
2878 | - * set_reg_event |
|
2879 | - * |
|
2880 | - * @access private |
|
2881 | - * @return bool |
|
2882 | - * @throws EE_Error |
|
2883 | - */ |
|
2884 | - private function _set_reg_event() |
|
2885 | - { |
|
2886 | - if (is_object($this->_reg_event)) { |
|
2887 | - return true; |
|
2888 | - } |
|
2889 | - $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
2890 | - if ( ! $EVT_ID) { |
|
2891 | - return false; |
|
2892 | - } |
|
2893 | - $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2894 | - return true; |
|
2895 | - } |
|
2896 | - |
|
2897 | - |
|
2898 | - /** |
|
2899 | - * process_reg_step |
|
2900 | - * |
|
2901 | - * @access public |
|
2902 | - * @return string |
|
2903 | - * @throws DomainException |
|
2904 | - * @throws EE_Error |
|
2905 | - * @throws RuntimeException |
|
2906 | - */ |
|
2907 | - public function process_reg_step() |
|
2908 | - { |
|
2909 | - EE_System::do_not_cache(); |
|
2910 | - $this->_set_reg_event(); |
|
2911 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
2912 | - EE_Registry::instance()->REQ->set('uts', time()); |
|
2913 | - //what step are we on? |
|
2914 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
2915 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
2916 | - //if doing ajax then we need to verify the nonce |
|
2917 | - if (defined('DOING_AJAX')) { |
|
2918 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
2919 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
2920 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
2921 | - } |
|
2922 | - switch ($step) { |
|
2923 | - case 'ticket' : |
|
2924 | - //process ticket selection |
|
2925 | - $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
2926 | - if ($success) { |
|
2927 | - EE_Error::add_success( |
|
2928 | - esc_html__( |
|
2929 | - 'Tickets Selected. Now complete the registration.', |
|
2930 | - 'event_espresso' |
|
2931 | - ) |
|
2932 | - ); |
|
2933 | - } else { |
|
2934 | - $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
2935 | - } |
|
2936 | - if (defined('DOING_AJAX')) { |
|
2937 | - $this->new_registration(); //display next step |
|
2938 | - } else { |
|
2939 | - $query_args = array( |
|
2940 | - 'action' => 'new_registration', |
|
2941 | - 'processing_registration' => 1, |
|
2942 | - 'event_id' => $this->_reg_event->ID(), |
|
2943 | - 'uts' => time(), |
|
2944 | - ); |
|
2945 | - $this->_redirect_after_action( |
|
2946 | - false, |
|
2947 | - '', |
|
2948 | - '', |
|
2949 | - $query_args, |
|
2950 | - true |
|
2951 | - ); |
|
2952 | - } |
|
2953 | - break; |
|
2954 | - case 'questions' : |
|
2955 | - if (! isset( |
|
2956 | - $this->_req_data['txn_reg_status_change'], |
|
2957 | - $this->_req_data['txn_reg_status_change']['send_notifications']) |
|
2958 | - ) { |
|
2959 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
2960 | - } |
|
2961 | - //process registration |
|
2962 | - $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
2963 | - if ($cart instanceof EE_Cart) { |
|
2964 | - $grand_total = $cart->get_cart_grand_total(); |
|
2965 | - if ($grand_total instanceof EE_Line_Item) { |
|
2966 | - $grand_total->save_this_and_descendants_to_txn(); |
|
2967 | - } |
|
2968 | - } |
|
2969 | - if ( ! $transaction instanceof EE_Transaction) { |
|
2970 | - $query_args = array( |
|
2971 | - 'action' => 'new_registration', |
|
2972 | - 'processing_registration' => 2, |
|
2973 | - 'event_id' => $this->_reg_event->ID(), |
|
2974 | - 'uts' => time(), |
|
2975 | - ); |
|
2976 | - if (defined('DOING_AJAX')) { |
|
2977 | - //display registration form again because there are errors (maybe validation?) |
|
2978 | - $this->new_registration(); |
|
2979 | - return; |
|
2980 | - } else { |
|
2981 | - $this->_redirect_after_action( |
|
2982 | - false, |
|
2983 | - '', |
|
2984 | - '', |
|
2985 | - $query_args, |
|
2986 | - true |
|
2987 | - ); |
|
2988 | - return; |
|
2989 | - } |
|
2990 | - } |
|
2991 | - // maybe update status, and make sure to save transaction if not done already |
|
2992 | - if ( ! $transaction->update_status_based_on_total_paid()) { |
|
2993 | - $transaction->save(); |
|
2994 | - } |
|
2995 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
2996 | - $this->_req_data = array(); |
|
2997 | - $query_args = array( |
|
2998 | - 'action' => 'redirect_to_txn', |
|
2999 | - 'TXN_ID' => $transaction->ID(), |
|
3000 | - 'EVT_ID' => $this->_reg_event->ID(), |
|
3001 | - 'event_name' => urlencode($this->_reg_event->name()), |
|
3002 | - 'redirect_from' => 'new_registration', |
|
3003 | - ); |
|
3004 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
3005 | - break; |
|
3006 | - } |
|
3007 | - //what are you looking here for? Should be nothing to do at this point. |
|
3008 | - } |
|
3009 | - |
|
3010 | - |
|
3011 | - /** |
|
3012 | - * redirect_to_txn |
|
3013 | - * |
|
3014 | - * @access public |
|
3015 | - * @return void |
|
3016 | - * @throws EE_Error |
|
3017 | - */ |
|
3018 | - public function redirect_to_txn() |
|
3019 | - { |
|
3020 | - EE_System::do_not_cache(); |
|
3021 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
3022 | - $query_args = array( |
|
3023 | - 'action' => 'view_transaction', |
|
3024 | - 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
3025 | - 'page' => 'espresso_transactions', |
|
3026 | - ); |
|
3027 | - if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
3028 | - $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
3029 | - $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
3030 | - $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
3031 | - } |
|
3032 | - EE_Error::add_success( |
|
3033 | - esc_html__( |
|
3034 | - 'Registration Created. Please review the transaction and add any payments as necessary', |
|
3035 | - 'event_espresso' |
|
3036 | - ) |
|
3037 | - ); |
|
3038 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
3039 | - } |
|
3040 | - |
|
3041 | - |
|
3042 | - /** |
|
3043 | - * generates HTML for the Attendee Contact List |
|
3044 | - * |
|
3045 | - * @access protected |
|
3046 | - * @return void |
|
3047 | - */ |
|
3048 | - protected function _attendee_contact_list_table() |
|
3049 | - { |
|
3050 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3051 | - $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
3052 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
3053 | - } |
|
3054 | - |
|
3055 | - |
|
3056 | - /** |
|
3057 | - * get_attendees |
|
3058 | - * |
|
3059 | - * @param $per_page |
|
3060 | - * @param bool $count whether to return count or data. |
|
3061 | - * @param bool $trash |
|
3062 | - * @return array |
|
3063 | - * @throws EE_Error |
|
3064 | - * @access public |
|
3065 | - */ |
|
3066 | - public function get_attendees($per_page, $count = false, $trash = false) |
|
3067 | - { |
|
3068 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3069 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
3070 | - $ATT_MDL = EEM_Attendee::instance(); |
|
3071 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
3072 | - switch ($this->_req_data['orderby']) { |
|
3073 | - case 'ATT_ID': |
|
3074 | - $orderby = 'ATT_ID'; |
|
3075 | - break; |
|
3076 | - case 'ATT_fname': |
|
3077 | - $orderby = 'ATT_fname'; |
|
3078 | - break; |
|
3079 | - case 'ATT_email': |
|
3080 | - $orderby = 'ATT_email'; |
|
3081 | - break; |
|
3082 | - case 'ATT_city': |
|
3083 | - $orderby = 'ATT_city'; |
|
3084 | - break; |
|
3085 | - case 'STA_ID': |
|
3086 | - $orderby = 'STA_ID'; |
|
3087 | - break; |
|
3088 | - case 'CNT_ID': |
|
3089 | - $orderby = 'CNT_ID'; |
|
3090 | - break; |
|
3091 | - default: |
|
3092 | - $orderby = 'ATT_lname'; |
|
3093 | - } |
|
3094 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
3095 | - ? $this->_req_data['order'] |
|
3096 | - : 'ASC'; |
|
3097 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
3098 | - ? $this->_req_data['paged'] |
|
3099 | - : 1; |
|
3100 | - $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
3101 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
3102 | - ? $this->_req_data['perpage'] |
|
3103 | - : $per_page; |
|
3104 | - $_where = array(); |
|
3105 | - if ( ! empty($this->_req_data['s'])) { |
|
3106 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
3107 | - $_where['OR'] = array( |
|
3108 | - 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
3109 | - 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
3110 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
3111 | - 'ATT_fname' => array('LIKE', $sstr), |
|
3112 | - 'ATT_lname' => array('LIKE', $sstr), |
|
3113 | - 'ATT_short_bio' => array('LIKE', $sstr), |
|
3114 | - 'ATT_email' => array('LIKE', $sstr), |
|
3115 | - 'ATT_address' => array('LIKE', $sstr), |
|
3116 | - 'ATT_address2' => array('LIKE', $sstr), |
|
3117 | - 'ATT_city' => array('LIKE', $sstr), |
|
3118 | - 'Country.CNT_name' => array('LIKE', $sstr), |
|
3119 | - 'State.STA_name' => array('LIKE', $sstr), |
|
3120 | - 'ATT_phone' => array('LIKE', $sstr), |
|
3121 | - 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
3122 | - 'Registration.REG_code' => array('LIKE', $sstr), |
|
3123 | - 'Registration.REG_count' => array('LIKE', $sstr), |
|
3124 | - 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
3125 | - ); |
|
3126 | - } |
|
3127 | - $offset = ($current_page - 1) * $per_page; |
|
3128 | - $limit = $count ? null : array($offset, $per_page); |
|
3129 | - if ($trash) { |
|
3130 | - $_where['status'] = array('!=', 'publish'); |
|
3131 | - $all_attendees = $count |
|
3132 | - ? $ATT_MDL->count(array( |
|
3133 | - $_where, |
|
3134 | - 'order_by' => array($orderby => $sort), |
|
3135 | - 'limit' => $limit, |
|
3136 | - ), 'ATT_ID', true) |
|
3137 | - : $ATT_MDL->get_all(array( |
|
3138 | - $_where, |
|
3139 | - 'order_by' => array($orderby => $sort), |
|
3140 | - 'limit' => $limit, |
|
3141 | - )); |
|
3142 | - } else { |
|
3143 | - $_where['status'] = array('IN', array('publish')); |
|
3144 | - $all_attendees = $count |
|
3145 | - ? $ATT_MDL->count(array( |
|
3146 | - $_where, |
|
3147 | - 'order_by' => array($orderby => $sort), |
|
3148 | - 'limit' => $limit, |
|
3149 | - ), 'ATT_ID', true) |
|
3150 | - : $ATT_MDL->get_all(array( |
|
3151 | - $_where, |
|
3152 | - 'order_by' => array($orderby => $sort), |
|
3153 | - 'limit' => $limit, |
|
3154 | - )); |
|
3155 | - } |
|
3156 | - return $all_attendees; |
|
3157 | - } |
|
3158 | - |
|
3159 | - |
|
3160 | - /** |
|
3161 | - * This is just taking care of resending the registration confirmation |
|
3162 | - * |
|
3163 | - * @access protected |
|
3164 | - * @return void |
|
3165 | - */ |
|
3166 | - protected function _resend_registration() |
|
3167 | - { |
|
3168 | - $this->_process_resend_registration(); |
|
3169 | - $query_args = isset($this->_req_data['redirect_to']) |
|
3170 | - ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
3171 | - : array('action' => 'default'); |
|
3172 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
3173 | - } |
|
3174 | - |
|
3175 | - /** |
|
3176 | - * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
3177 | - * to use when selecting registrations |
|
3178 | - * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
3179 | - * the query parameters from the request |
|
3180 | - * @return void ends the request with a redirect or download |
|
3181 | - */ |
|
3182 | - public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
3183 | - { |
|
3184 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
3185 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce( |
|
3186 | - array( |
|
3187 | - 'page' => 'espresso_batch', |
|
3188 | - 'batch' => 'file', |
|
3189 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
3190 | - 'filters' => urlencode( |
|
3191 | - serialize( |
|
3192 | - call_user_func( |
|
3193 | - array( $this, $method_name_for_getting_query_params ), |
|
3194 | - EEH_Array::is_set( |
|
3195 | - $this->_req_data, |
|
3196 | - 'filters', |
|
3197 | - array() |
|
3198 | - ) |
|
3199 | - ) |
|
3200 | - ) |
|
3201 | - ), |
|
3202 | - 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
3203 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
3204 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
3205 | - ))); |
|
3206 | - } else { |
|
3207 | - $new_request_args = array( |
|
3208 | - 'export' => 'report', |
|
3209 | - 'action' => 'registrations_report_for_event', |
|
3210 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
3211 | - ); |
|
3212 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
3213 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
3214 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
3215 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
3216 | - $EE_Export->export(); |
|
3217 | - } |
|
3218 | - } |
|
3219 | - } |
|
3220 | - |
|
3221 | - |
|
3222 | - |
|
3223 | - /** |
|
3224 | - * Creates a registration report using only query parameters in the request |
|
3225 | - * @return void |
|
3226 | - */ |
|
3227 | - public function _registrations_report() |
|
3228 | - { |
|
3229 | - $this->_registrations_report_base('_get_registration_query_parameters'); |
|
3230 | - } |
|
3231 | - |
|
3232 | - |
|
3233 | - public function _contact_list_export() |
|
3234 | - { |
|
3235 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
3236 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
3237 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
3238 | - $EE_Export->export_attendees(); |
|
3239 | - } |
|
3240 | - } |
|
3241 | - |
|
3242 | - |
|
3243 | - public function _contact_list_report() |
|
3244 | - { |
|
3245 | - if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
3246 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
3247 | - 'page' => 'espresso_batch', |
|
3248 | - 'batch' => 'file', |
|
3249 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
3250 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
3251 | - ))); |
|
3252 | - } else { |
|
3253 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
3254 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
3255 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
3256 | - $EE_Export->report_attendees(); |
|
3257 | - } |
|
3258 | - } |
|
3259 | - } |
|
3260 | - |
|
3261 | - |
|
3262 | - |
|
3263 | - |
|
3264 | - |
|
3265 | - /*************************************** ATTENDEE DETAILS ***************************************/ |
|
3266 | - /** |
|
3267 | - * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
3268 | - * |
|
3269 | - * @return void |
|
3270 | - * @throws EE_Error |
|
3271 | - */ |
|
3272 | - protected function _duplicate_attendee() |
|
3273 | - { |
|
3274 | - $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
3275 | - //verify we have necessary info |
|
3276 | - if (empty($this->_req_data['_REG_ID'])) { |
|
3277 | - EE_Error::add_error( |
|
3278 | - esc_html__( |
|
3279 | - 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
3280 | - 'event_espresso' |
|
3281 | - ), __FILE__, __LINE__, __FUNCTION__ |
|
3282 | - ); |
|
3283 | - $query_args = array('action' => $action); |
|
3284 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
3285 | - } |
|
3286 | - //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
3287 | - $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
3288 | - $attendee = $registration->attendee(); |
|
3289 | - //remove relation of existing attendee on registration |
|
3290 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
3291 | - //new attendee |
|
3292 | - $new_attendee = clone $attendee; |
|
3293 | - $new_attendee->set('ATT_ID', 0); |
|
3294 | - $new_attendee->save(); |
|
3295 | - //add new attendee to reg |
|
3296 | - $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
3297 | - EE_Error::add_success( |
|
3298 | - esc_html__( |
|
3299 | - 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
3300 | - 'event_espresso' |
|
3301 | - ) |
|
3302 | - ); |
|
3303 | - //redirect to edit page for attendee |
|
3304 | - $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
3305 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
3306 | - } |
|
3307 | - |
|
3308 | - |
|
3309 | - //related to cpt routes |
|
3310 | - protected function _insert_update_cpt_item($post_id, $post) |
|
3311 | - { |
|
3312 | - $success = true; |
|
3313 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
3314 | - //for attendee updates |
|
3315 | - if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
3316 | - //note we should only be UPDATING attendees at this point. |
|
3317 | - $updated_fields = array( |
|
3318 | - 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
3319 | - 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
3320 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
3321 | - 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
3322 | - 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
3323 | - 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
3324 | - 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
3325 | - 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
3326 | - 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
3327 | - 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
3328 | - 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
3329 | - ); |
|
3330 | - foreach ($updated_fields as $field => $value) { |
|
3331 | - $attendee->set($field, $value); |
|
3332 | - } |
|
3333 | - $success = $attendee->save(); |
|
3334 | - $attendee_update_callbacks = apply_filters( |
|
3335 | - 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
3336 | - array() |
|
3337 | - ); |
|
3338 | - foreach ($attendee_update_callbacks as $a_callback) { |
|
3339 | - if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
3340 | - throw new EE_Error( |
|
3341 | - sprintf( |
|
3342 | - esc_html__( |
|
3343 | - 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
3344 | - 'event_espresso' |
|
3345 | - ), |
|
3346 | - $a_callback |
|
3347 | - ) |
|
3348 | - ); |
|
3349 | - } |
|
3350 | - } |
|
3351 | - } |
|
3352 | - if ($success === false) { |
|
3353 | - EE_Error::add_error( |
|
3354 | - esc_html__( |
|
3355 | - 'Something went wrong with updating the meta table data for the registration.', |
|
3356 | - 'event_espresso' |
|
3357 | - ), |
|
3358 | - __FILE__, __FUNCTION__, __LINE__ |
|
3359 | - ); |
|
3360 | - } |
|
3361 | - } |
|
3362 | - |
|
3363 | - |
|
3364 | - public function trash_cpt_item($post_id) |
|
3365 | - { |
|
3366 | - } |
|
3367 | - |
|
3368 | - |
|
3369 | - public function delete_cpt_item($post_id) |
|
3370 | - { |
|
3371 | - } |
|
3372 | - |
|
3373 | - |
|
3374 | - public function restore_cpt_item($post_id) |
|
3375 | - { |
|
3376 | - } |
|
3377 | - |
|
3378 | - |
|
3379 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
3380 | - { |
|
3381 | - } |
|
3382 | - |
|
3383 | - |
|
3384 | - public function attendee_editor_metaboxes() |
|
3385 | - { |
|
3386 | - $this->verify_cpt_object(); |
|
3387 | - remove_meta_box( |
|
3388 | - 'postexcerpt', |
|
3389 | - esc_html__('Excerpt', 'event_espresso'), |
|
3390 | - 'post_excerpt_meta_box', |
|
3391 | - $this->_cpt_routes[$this->_req_action], |
|
3392 | - 'normal', |
|
3393 | - 'core' |
|
3394 | - ); |
|
3395 | - remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
3396 | - if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
3397 | - add_meta_box( |
|
3398 | - 'postexcerpt', |
|
3399 | - esc_html__('Short Biography', 'event_espresso'), |
|
3400 | - 'post_excerpt_meta_box', |
|
3401 | - $this->_cpt_routes[$this->_req_action], |
|
3402 | - 'normal' |
|
3403 | - ); |
|
3404 | - } |
|
3405 | - if (post_type_supports('espresso_attendees', 'comments')) { |
|
3406 | - add_meta_box( |
|
3407 | - 'commentsdiv', |
|
3408 | - esc_html__('Notes on the Contact', 'event_espresso'), |
|
3409 | - 'post_comment_meta_box', |
|
3410 | - $this->_cpt_routes[$this->_req_action], |
|
3411 | - 'normal', |
|
3412 | - 'core' |
|
3413 | - ); |
|
3414 | - } |
|
3415 | - add_meta_box( |
|
3416 | - 'attendee_contact_info', |
|
3417 | - esc_html__('Contact Info', 'event_espresso'), |
|
3418 | - array($this, 'attendee_contact_info'), |
|
3419 | - $this->_cpt_routes[$this->_req_action], |
|
3420 | - 'side', |
|
3421 | - 'core' |
|
3422 | - ); |
|
3423 | - add_meta_box( |
|
3424 | - 'attendee_details_address', |
|
3425 | - esc_html__('Address Details', 'event_espresso'), |
|
3426 | - array($this, 'attendee_address_details'), |
|
3427 | - $this->_cpt_routes[$this->_req_action], |
|
3428 | - 'normal', |
|
3429 | - 'core' |
|
3430 | - ); |
|
3431 | - add_meta_box( |
|
3432 | - 'attendee_registrations', |
|
3433 | - esc_html__('Registrations for this Contact', 'event_espresso'), |
|
3434 | - array($this, 'attendee_registrations_meta_box'), |
|
3435 | - $this->_cpt_routes[$this->_req_action], |
|
3436 | - 'normal', |
|
3437 | - 'high' |
|
3438 | - ); |
|
3439 | - } |
|
3440 | - |
|
3441 | - |
|
3442 | - /** |
|
3443 | - * Metabox for attendee contact info |
|
3444 | - * |
|
3445 | - * @param WP_Post $post wp post object |
|
3446 | - * @return string attendee contact info ( and form ) |
|
3447 | - * @throws DomainException |
|
3448 | - */ |
|
3449 | - public function attendee_contact_info($post) |
|
3450 | - { |
|
3451 | - //get attendee object ( should already have it ) |
|
3452 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
3453 | - $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
3454 | - EEH_Template::display_template($template, $this->_template_args); |
|
3455 | - } |
|
3456 | - |
|
3457 | - |
|
3458 | - /** |
|
3459 | - * Metabox for attendee details |
|
3460 | - * |
|
3461 | - * @param WP_Post $post wp post object |
|
3462 | - * @return string attendee address details (and form) |
|
3463 | - * @throws DomainException |
|
3464 | - */ |
|
3465 | - public function attendee_address_details($post) |
|
3466 | - { |
|
3467 | - //get attendee object (should already have it) |
|
3468 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
3469 | - $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
3470 | - new EE_Question_Form_Input( |
|
3471 | - EE_Question::new_instance( |
|
3472 | - array( |
|
3473 | - 'QST_ID' => 0, |
|
3474 | - 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
3475 | - 'QST_system' => 'admin-state', |
|
3476 | - ) |
|
3477 | - ), |
|
3478 | - EE_Answer::new_instance( |
|
3479 | - array( |
|
3480 | - 'ANS_ID' => 0, |
|
3481 | - 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
3482 | - ) |
|
3483 | - ), |
|
3484 | - array( |
|
3485 | - 'input_id' => 'STA_ID', |
|
3486 | - 'input_name' => 'STA_ID', |
|
3487 | - 'input_prefix' => '', |
|
3488 | - 'append_qstn_id' => false, |
|
3489 | - ) |
|
3490 | - ) |
|
3491 | - ); |
|
3492 | - $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
3493 | - new EE_Question_Form_Input( |
|
3494 | - EE_Question::new_instance( |
|
3495 | - array( |
|
3496 | - 'QST_ID' => 0, |
|
3497 | - 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
3498 | - 'QST_system' => 'admin-country', |
|
3499 | - ) |
|
3500 | - ), |
|
3501 | - EE_Answer::new_instance( |
|
3502 | - array( |
|
3503 | - 'ANS_ID' => 0, |
|
3504 | - 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
3505 | - ) |
|
3506 | - ), |
|
3507 | - array( |
|
3508 | - 'input_id' => 'CNT_ISO', |
|
3509 | - 'input_name' => 'CNT_ISO', |
|
3510 | - 'input_prefix' => '', |
|
3511 | - 'append_qstn_id' => false, |
|
3512 | - ) |
|
3513 | - ) |
|
3514 | - ); |
|
3515 | - $template = |
|
3516 | - REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
3517 | - EEH_Template::display_template($template, $this->_template_args); |
|
3518 | - } |
|
3519 | - |
|
3520 | - |
|
3521 | - /** |
|
3522 | - * _attendee_details |
|
3523 | - * |
|
3524 | - * @access protected |
|
3525 | - * @param $post |
|
3526 | - * @return void |
|
3527 | - * @throws DomainException |
|
3528 | - * @throws EE_Error |
|
3529 | - */ |
|
3530 | - public function attendee_registrations_meta_box($post) |
|
3531 | - { |
|
3532 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
3533 | - $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
3534 | - $template = |
|
3535 | - REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
3536 | - EEH_Template::display_template($template, $this->_template_args); |
|
3537 | - } |
|
3538 | - |
|
3539 | - |
|
3540 | - /** |
|
3541 | - * add in the form fields for the attendee edit |
|
3542 | - * |
|
3543 | - * @param WP_Post $post wp post object |
|
3544 | - * @return string html for new form. |
|
3545 | - * @throws DomainException |
|
3546 | - */ |
|
3547 | - public function after_title_form_fields($post) |
|
3548 | - { |
|
3549 | - if ($post->post_type == 'espresso_attendees') { |
|
3550 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
3551 | - $template_args['attendee'] = $this->_cpt_model_obj; |
|
3552 | - EEH_Template::display_template($template, $template_args); |
|
3553 | - } |
|
3554 | - } |
|
3555 | - |
|
3556 | - |
|
3557 | - /** |
|
3558 | - * _trash_or_restore_attendee |
|
3559 | - * |
|
3560 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
3561 | - * @return void |
|
3562 | - * @throws EE_Error |
|
3563 | - * @access protected |
|
3564 | - */ |
|
3565 | - protected function _trash_or_restore_attendees($trash = true) |
|
3566 | - { |
|
3567 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3568 | - $ATT_MDL = EEM_Attendee::instance(); |
|
3569 | - $success = 1; |
|
3570 | - //Checkboxes |
|
3571 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
3572 | - // if array has more than one element than success message should be plural |
|
3573 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
3574 | - // cycle thru checkboxes |
|
3575 | - while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
3576 | - $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
3577 | - : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
3578 | - if ( ! $updated) { |
|
3579 | - $success = 0; |
|
3580 | - } |
|
3581 | - } |
|
3582 | - } else { |
|
3583 | - // grab single id and delete |
|
3584 | - $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
3585 | - //get attendee |
|
3586 | - $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
3587 | - $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
3588 | - $updated = $att->save(); |
|
3589 | - if ( ! $updated) { |
|
3590 | - $success = 0; |
|
3591 | - } |
|
3592 | - } |
|
3593 | - $what = $success > 1 |
|
3594 | - ? esc_html__('Contacts', 'event_espresso') |
|
3595 | - : esc_html__('Contact', 'event_espresso'); |
|
3596 | - $action_desc = $trash |
|
3597 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
3598 | - : esc_html__('restored', 'event_espresso'); |
|
3599 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
3600 | - } |
|
2814 | + } |
|
2815 | + $template_args = array( |
|
2816 | + 'title' => '', |
|
2817 | + 'content' => '', |
|
2818 | + 'step_button_text' => '', |
|
2819 | + 'show_notification_toggle' => false, |
|
2820 | + ); |
|
2821 | + //to indicate we're processing a new registration |
|
2822 | + $hidden_fields = array( |
|
2823 | + 'processing_registration' => array( |
|
2824 | + 'type' => 'hidden', |
|
2825 | + 'value' => 0, |
|
2826 | + ), |
|
2827 | + 'event_id' => array( |
|
2828 | + 'type' => 'hidden', |
|
2829 | + 'value' => $this->_reg_event->ID(), |
|
2830 | + ), |
|
2831 | + ); |
|
2832 | + //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
2833 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
2834 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
2835 | + switch ($step) { |
|
2836 | + case 'ticket' : |
|
2837 | + $hidden_fields['processing_registration']['value'] = 1; |
|
2838 | + $template_args['title'] = esc_html__( |
|
2839 | + 'Step One: Select the Ticket for this registration', |
|
2840 | + 'event_espresso' |
|
2841 | + ); |
|
2842 | + $template_args['content'] = |
|
2843 | + EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
2844 | + $template_args['step_button_text'] = esc_html__( |
|
2845 | + 'Add Tickets and Continue to Registrant Details', |
|
2846 | + 'event_espresso' |
|
2847 | + ); |
|
2848 | + $template_args['show_notification_toggle'] = false; |
|
2849 | + break; |
|
2850 | + case 'questions' : |
|
2851 | + $hidden_fields['processing_registration']['value'] = 2; |
|
2852 | + $template_args['title'] = esc_html__( |
|
2853 | + 'Step Two: Add Registrant Details for this Registration', |
|
2854 | + 'event_espresso' |
|
2855 | + ); |
|
2856 | + //in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
2857 | + // properly by the first process_reg_step run. |
|
2858 | + $template_args['content'] = |
|
2859 | + EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
2860 | + $template_args['step_button_text'] = esc_html__( |
|
2861 | + 'Save Registration and Continue to Details', |
|
2862 | + 'event_espresso' |
|
2863 | + ); |
|
2864 | + $template_args['show_notification_toggle'] = true; |
|
2865 | + break; |
|
2866 | + } |
|
2867 | + //we come back to the process_registration_step route. |
|
2868 | + $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
2869 | + return EEH_Template::display_template( |
|
2870 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
2871 | + $template_args, |
|
2872 | + true |
|
2873 | + ); |
|
2874 | + } |
|
2875 | + |
|
2876 | + |
|
2877 | + /** |
|
2878 | + * set_reg_event |
|
2879 | + * |
|
2880 | + * @access private |
|
2881 | + * @return bool |
|
2882 | + * @throws EE_Error |
|
2883 | + */ |
|
2884 | + private function _set_reg_event() |
|
2885 | + { |
|
2886 | + if (is_object($this->_reg_event)) { |
|
2887 | + return true; |
|
2888 | + } |
|
2889 | + $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
2890 | + if ( ! $EVT_ID) { |
|
2891 | + return false; |
|
2892 | + } |
|
2893 | + $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2894 | + return true; |
|
2895 | + } |
|
2896 | + |
|
2897 | + |
|
2898 | + /** |
|
2899 | + * process_reg_step |
|
2900 | + * |
|
2901 | + * @access public |
|
2902 | + * @return string |
|
2903 | + * @throws DomainException |
|
2904 | + * @throws EE_Error |
|
2905 | + * @throws RuntimeException |
|
2906 | + */ |
|
2907 | + public function process_reg_step() |
|
2908 | + { |
|
2909 | + EE_System::do_not_cache(); |
|
2910 | + $this->_set_reg_event(); |
|
2911 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
2912 | + EE_Registry::instance()->REQ->set('uts', time()); |
|
2913 | + //what step are we on? |
|
2914 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
2915 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
2916 | + //if doing ajax then we need to verify the nonce |
|
2917 | + if (defined('DOING_AJAX')) { |
|
2918 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
2919 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
2920 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
2921 | + } |
|
2922 | + switch ($step) { |
|
2923 | + case 'ticket' : |
|
2924 | + //process ticket selection |
|
2925 | + $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
2926 | + if ($success) { |
|
2927 | + EE_Error::add_success( |
|
2928 | + esc_html__( |
|
2929 | + 'Tickets Selected. Now complete the registration.', |
|
2930 | + 'event_espresso' |
|
2931 | + ) |
|
2932 | + ); |
|
2933 | + } else { |
|
2934 | + $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
2935 | + } |
|
2936 | + if (defined('DOING_AJAX')) { |
|
2937 | + $this->new_registration(); //display next step |
|
2938 | + } else { |
|
2939 | + $query_args = array( |
|
2940 | + 'action' => 'new_registration', |
|
2941 | + 'processing_registration' => 1, |
|
2942 | + 'event_id' => $this->_reg_event->ID(), |
|
2943 | + 'uts' => time(), |
|
2944 | + ); |
|
2945 | + $this->_redirect_after_action( |
|
2946 | + false, |
|
2947 | + '', |
|
2948 | + '', |
|
2949 | + $query_args, |
|
2950 | + true |
|
2951 | + ); |
|
2952 | + } |
|
2953 | + break; |
|
2954 | + case 'questions' : |
|
2955 | + if (! isset( |
|
2956 | + $this->_req_data['txn_reg_status_change'], |
|
2957 | + $this->_req_data['txn_reg_status_change']['send_notifications']) |
|
2958 | + ) { |
|
2959 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
2960 | + } |
|
2961 | + //process registration |
|
2962 | + $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
2963 | + if ($cart instanceof EE_Cart) { |
|
2964 | + $grand_total = $cart->get_cart_grand_total(); |
|
2965 | + if ($grand_total instanceof EE_Line_Item) { |
|
2966 | + $grand_total->save_this_and_descendants_to_txn(); |
|
2967 | + } |
|
2968 | + } |
|
2969 | + if ( ! $transaction instanceof EE_Transaction) { |
|
2970 | + $query_args = array( |
|
2971 | + 'action' => 'new_registration', |
|
2972 | + 'processing_registration' => 2, |
|
2973 | + 'event_id' => $this->_reg_event->ID(), |
|
2974 | + 'uts' => time(), |
|
2975 | + ); |
|
2976 | + if (defined('DOING_AJAX')) { |
|
2977 | + //display registration form again because there are errors (maybe validation?) |
|
2978 | + $this->new_registration(); |
|
2979 | + return; |
|
2980 | + } else { |
|
2981 | + $this->_redirect_after_action( |
|
2982 | + false, |
|
2983 | + '', |
|
2984 | + '', |
|
2985 | + $query_args, |
|
2986 | + true |
|
2987 | + ); |
|
2988 | + return; |
|
2989 | + } |
|
2990 | + } |
|
2991 | + // maybe update status, and make sure to save transaction if not done already |
|
2992 | + if ( ! $transaction->update_status_based_on_total_paid()) { |
|
2993 | + $transaction->save(); |
|
2994 | + } |
|
2995 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
2996 | + $this->_req_data = array(); |
|
2997 | + $query_args = array( |
|
2998 | + 'action' => 'redirect_to_txn', |
|
2999 | + 'TXN_ID' => $transaction->ID(), |
|
3000 | + 'EVT_ID' => $this->_reg_event->ID(), |
|
3001 | + 'event_name' => urlencode($this->_reg_event->name()), |
|
3002 | + 'redirect_from' => 'new_registration', |
|
3003 | + ); |
|
3004 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
3005 | + break; |
|
3006 | + } |
|
3007 | + //what are you looking here for? Should be nothing to do at this point. |
|
3008 | + } |
|
3009 | + |
|
3010 | + |
|
3011 | + /** |
|
3012 | + * redirect_to_txn |
|
3013 | + * |
|
3014 | + * @access public |
|
3015 | + * @return void |
|
3016 | + * @throws EE_Error |
|
3017 | + */ |
|
3018 | + public function redirect_to_txn() |
|
3019 | + { |
|
3020 | + EE_System::do_not_cache(); |
|
3021 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
3022 | + $query_args = array( |
|
3023 | + 'action' => 'view_transaction', |
|
3024 | + 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
3025 | + 'page' => 'espresso_transactions', |
|
3026 | + ); |
|
3027 | + if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
3028 | + $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
3029 | + $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
3030 | + $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
3031 | + } |
|
3032 | + EE_Error::add_success( |
|
3033 | + esc_html__( |
|
3034 | + 'Registration Created. Please review the transaction and add any payments as necessary', |
|
3035 | + 'event_espresso' |
|
3036 | + ) |
|
3037 | + ); |
|
3038 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
3039 | + } |
|
3040 | + |
|
3041 | + |
|
3042 | + /** |
|
3043 | + * generates HTML for the Attendee Contact List |
|
3044 | + * |
|
3045 | + * @access protected |
|
3046 | + * @return void |
|
3047 | + */ |
|
3048 | + protected function _attendee_contact_list_table() |
|
3049 | + { |
|
3050 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3051 | + $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
3052 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
3053 | + } |
|
3054 | + |
|
3055 | + |
|
3056 | + /** |
|
3057 | + * get_attendees |
|
3058 | + * |
|
3059 | + * @param $per_page |
|
3060 | + * @param bool $count whether to return count or data. |
|
3061 | + * @param bool $trash |
|
3062 | + * @return array |
|
3063 | + * @throws EE_Error |
|
3064 | + * @access public |
|
3065 | + */ |
|
3066 | + public function get_attendees($per_page, $count = false, $trash = false) |
|
3067 | + { |
|
3068 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3069 | + require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
3070 | + $ATT_MDL = EEM_Attendee::instance(); |
|
3071 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
3072 | + switch ($this->_req_data['orderby']) { |
|
3073 | + case 'ATT_ID': |
|
3074 | + $orderby = 'ATT_ID'; |
|
3075 | + break; |
|
3076 | + case 'ATT_fname': |
|
3077 | + $orderby = 'ATT_fname'; |
|
3078 | + break; |
|
3079 | + case 'ATT_email': |
|
3080 | + $orderby = 'ATT_email'; |
|
3081 | + break; |
|
3082 | + case 'ATT_city': |
|
3083 | + $orderby = 'ATT_city'; |
|
3084 | + break; |
|
3085 | + case 'STA_ID': |
|
3086 | + $orderby = 'STA_ID'; |
|
3087 | + break; |
|
3088 | + case 'CNT_ID': |
|
3089 | + $orderby = 'CNT_ID'; |
|
3090 | + break; |
|
3091 | + default: |
|
3092 | + $orderby = 'ATT_lname'; |
|
3093 | + } |
|
3094 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
3095 | + ? $this->_req_data['order'] |
|
3096 | + : 'ASC'; |
|
3097 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
3098 | + ? $this->_req_data['paged'] |
|
3099 | + : 1; |
|
3100 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
3101 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
3102 | + ? $this->_req_data['perpage'] |
|
3103 | + : $per_page; |
|
3104 | + $_where = array(); |
|
3105 | + if ( ! empty($this->_req_data['s'])) { |
|
3106 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
3107 | + $_where['OR'] = array( |
|
3108 | + 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
3109 | + 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
3110 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
3111 | + 'ATT_fname' => array('LIKE', $sstr), |
|
3112 | + 'ATT_lname' => array('LIKE', $sstr), |
|
3113 | + 'ATT_short_bio' => array('LIKE', $sstr), |
|
3114 | + 'ATT_email' => array('LIKE', $sstr), |
|
3115 | + 'ATT_address' => array('LIKE', $sstr), |
|
3116 | + 'ATT_address2' => array('LIKE', $sstr), |
|
3117 | + 'ATT_city' => array('LIKE', $sstr), |
|
3118 | + 'Country.CNT_name' => array('LIKE', $sstr), |
|
3119 | + 'State.STA_name' => array('LIKE', $sstr), |
|
3120 | + 'ATT_phone' => array('LIKE', $sstr), |
|
3121 | + 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
3122 | + 'Registration.REG_code' => array('LIKE', $sstr), |
|
3123 | + 'Registration.REG_count' => array('LIKE', $sstr), |
|
3124 | + 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
3125 | + ); |
|
3126 | + } |
|
3127 | + $offset = ($current_page - 1) * $per_page; |
|
3128 | + $limit = $count ? null : array($offset, $per_page); |
|
3129 | + if ($trash) { |
|
3130 | + $_where['status'] = array('!=', 'publish'); |
|
3131 | + $all_attendees = $count |
|
3132 | + ? $ATT_MDL->count(array( |
|
3133 | + $_where, |
|
3134 | + 'order_by' => array($orderby => $sort), |
|
3135 | + 'limit' => $limit, |
|
3136 | + ), 'ATT_ID', true) |
|
3137 | + : $ATT_MDL->get_all(array( |
|
3138 | + $_where, |
|
3139 | + 'order_by' => array($orderby => $sort), |
|
3140 | + 'limit' => $limit, |
|
3141 | + )); |
|
3142 | + } else { |
|
3143 | + $_where['status'] = array('IN', array('publish')); |
|
3144 | + $all_attendees = $count |
|
3145 | + ? $ATT_MDL->count(array( |
|
3146 | + $_where, |
|
3147 | + 'order_by' => array($orderby => $sort), |
|
3148 | + 'limit' => $limit, |
|
3149 | + ), 'ATT_ID', true) |
|
3150 | + : $ATT_MDL->get_all(array( |
|
3151 | + $_where, |
|
3152 | + 'order_by' => array($orderby => $sort), |
|
3153 | + 'limit' => $limit, |
|
3154 | + )); |
|
3155 | + } |
|
3156 | + return $all_attendees; |
|
3157 | + } |
|
3158 | + |
|
3159 | + |
|
3160 | + /** |
|
3161 | + * This is just taking care of resending the registration confirmation |
|
3162 | + * |
|
3163 | + * @access protected |
|
3164 | + * @return void |
|
3165 | + */ |
|
3166 | + protected function _resend_registration() |
|
3167 | + { |
|
3168 | + $this->_process_resend_registration(); |
|
3169 | + $query_args = isset($this->_req_data['redirect_to']) |
|
3170 | + ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
3171 | + : array('action' => 'default'); |
|
3172 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
3173 | + } |
|
3174 | + |
|
3175 | + /** |
|
3176 | + * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
3177 | + * to use when selecting registrations |
|
3178 | + * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
3179 | + * the query parameters from the request |
|
3180 | + * @return void ends the request with a redirect or download |
|
3181 | + */ |
|
3182 | + public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
3183 | + { |
|
3184 | + if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
3185 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce( |
|
3186 | + array( |
|
3187 | + 'page' => 'espresso_batch', |
|
3188 | + 'batch' => 'file', |
|
3189 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
3190 | + 'filters' => urlencode( |
|
3191 | + serialize( |
|
3192 | + call_user_func( |
|
3193 | + array( $this, $method_name_for_getting_query_params ), |
|
3194 | + EEH_Array::is_set( |
|
3195 | + $this->_req_data, |
|
3196 | + 'filters', |
|
3197 | + array() |
|
3198 | + ) |
|
3199 | + ) |
|
3200 | + ) |
|
3201 | + ), |
|
3202 | + 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
3203 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
3204 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
3205 | + ))); |
|
3206 | + } else { |
|
3207 | + $new_request_args = array( |
|
3208 | + 'export' => 'report', |
|
3209 | + 'action' => 'registrations_report_for_event', |
|
3210 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
3211 | + ); |
|
3212 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
3213 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
3214 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
3215 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
3216 | + $EE_Export->export(); |
|
3217 | + } |
|
3218 | + } |
|
3219 | + } |
|
3220 | + |
|
3221 | + |
|
3222 | + |
|
3223 | + /** |
|
3224 | + * Creates a registration report using only query parameters in the request |
|
3225 | + * @return void |
|
3226 | + */ |
|
3227 | + public function _registrations_report() |
|
3228 | + { |
|
3229 | + $this->_registrations_report_base('_get_registration_query_parameters'); |
|
3230 | + } |
|
3231 | + |
|
3232 | + |
|
3233 | + public function _contact_list_export() |
|
3234 | + { |
|
3235 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
3236 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
3237 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
3238 | + $EE_Export->export_attendees(); |
|
3239 | + } |
|
3240 | + } |
|
3241 | + |
|
3242 | + |
|
3243 | + public function _contact_list_report() |
|
3244 | + { |
|
3245 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
3246 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
3247 | + 'page' => 'espresso_batch', |
|
3248 | + 'batch' => 'file', |
|
3249 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
3250 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
3251 | + ))); |
|
3252 | + } else { |
|
3253 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
3254 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
3255 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
3256 | + $EE_Export->report_attendees(); |
|
3257 | + } |
|
3258 | + } |
|
3259 | + } |
|
3260 | + |
|
3261 | + |
|
3262 | + |
|
3263 | + |
|
3264 | + |
|
3265 | + /*************************************** ATTENDEE DETAILS ***************************************/ |
|
3266 | + /** |
|
3267 | + * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
3268 | + * |
|
3269 | + * @return void |
|
3270 | + * @throws EE_Error |
|
3271 | + */ |
|
3272 | + protected function _duplicate_attendee() |
|
3273 | + { |
|
3274 | + $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
3275 | + //verify we have necessary info |
|
3276 | + if (empty($this->_req_data['_REG_ID'])) { |
|
3277 | + EE_Error::add_error( |
|
3278 | + esc_html__( |
|
3279 | + 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
3280 | + 'event_espresso' |
|
3281 | + ), __FILE__, __LINE__, __FUNCTION__ |
|
3282 | + ); |
|
3283 | + $query_args = array('action' => $action); |
|
3284 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
3285 | + } |
|
3286 | + //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
3287 | + $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
3288 | + $attendee = $registration->attendee(); |
|
3289 | + //remove relation of existing attendee on registration |
|
3290 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
3291 | + //new attendee |
|
3292 | + $new_attendee = clone $attendee; |
|
3293 | + $new_attendee->set('ATT_ID', 0); |
|
3294 | + $new_attendee->save(); |
|
3295 | + //add new attendee to reg |
|
3296 | + $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
3297 | + EE_Error::add_success( |
|
3298 | + esc_html__( |
|
3299 | + 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
3300 | + 'event_espresso' |
|
3301 | + ) |
|
3302 | + ); |
|
3303 | + //redirect to edit page for attendee |
|
3304 | + $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
3305 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
3306 | + } |
|
3307 | + |
|
3308 | + |
|
3309 | + //related to cpt routes |
|
3310 | + protected function _insert_update_cpt_item($post_id, $post) |
|
3311 | + { |
|
3312 | + $success = true; |
|
3313 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
3314 | + //for attendee updates |
|
3315 | + if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
3316 | + //note we should only be UPDATING attendees at this point. |
|
3317 | + $updated_fields = array( |
|
3318 | + 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
3319 | + 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
3320 | + 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
3321 | + 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
3322 | + 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
3323 | + 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
3324 | + 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
3325 | + 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
3326 | + 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
3327 | + 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
3328 | + 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
3329 | + ); |
|
3330 | + foreach ($updated_fields as $field => $value) { |
|
3331 | + $attendee->set($field, $value); |
|
3332 | + } |
|
3333 | + $success = $attendee->save(); |
|
3334 | + $attendee_update_callbacks = apply_filters( |
|
3335 | + 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
3336 | + array() |
|
3337 | + ); |
|
3338 | + foreach ($attendee_update_callbacks as $a_callback) { |
|
3339 | + if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
3340 | + throw new EE_Error( |
|
3341 | + sprintf( |
|
3342 | + esc_html__( |
|
3343 | + 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
3344 | + 'event_espresso' |
|
3345 | + ), |
|
3346 | + $a_callback |
|
3347 | + ) |
|
3348 | + ); |
|
3349 | + } |
|
3350 | + } |
|
3351 | + } |
|
3352 | + if ($success === false) { |
|
3353 | + EE_Error::add_error( |
|
3354 | + esc_html__( |
|
3355 | + 'Something went wrong with updating the meta table data for the registration.', |
|
3356 | + 'event_espresso' |
|
3357 | + ), |
|
3358 | + __FILE__, __FUNCTION__, __LINE__ |
|
3359 | + ); |
|
3360 | + } |
|
3361 | + } |
|
3362 | + |
|
3363 | + |
|
3364 | + public function trash_cpt_item($post_id) |
|
3365 | + { |
|
3366 | + } |
|
3367 | + |
|
3368 | + |
|
3369 | + public function delete_cpt_item($post_id) |
|
3370 | + { |
|
3371 | + } |
|
3372 | + |
|
3373 | + |
|
3374 | + public function restore_cpt_item($post_id) |
|
3375 | + { |
|
3376 | + } |
|
3377 | + |
|
3378 | + |
|
3379 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
3380 | + { |
|
3381 | + } |
|
3382 | + |
|
3383 | + |
|
3384 | + public function attendee_editor_metaboxes() |
|
3385 | + { |
|
3386 | + $this->verify_cpt_object(); |
|
3387 | + remove_meta_box( |
|
3388 | + 'postexcerpt', |
|
3389 | + esc_html__('Excerpt', 'event_espresso'), |
|
3390 | + 'post_excerpt_meta_box', |
|
3391 | + $this->_cpt_routes[$this->_req_action], |
|
3392 | + 'normal', |
|
3393 | + 'core' |
|
3394 | + ); |
|
3395 | + remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
3396 | + if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
3397 | + add_meta_box( |
|
3398 | + 'postexcerpt', |
|
3399 | + esc_html__('Short Biography', 'event_espresso'), |
|
3400 | + 'post_excerpt_meta_box', |
|
3401 | + $this->_cpt_routes[$this->_req_action], |
|
3402 | + 'normal' |
|
3403 | + ); |
|
3404 | + } |
|
3405 | + if (post_type_supports('espresso_attendees', 'comments')) { |
|
3406 | + add_meta_box( |
|
3407 | + 'commentsdiv', |
|
3408 | + esc_html__('Notes on the Contact', 'event_espresso'), |
|
3409 | + 'post_comment_meta_box', |
|
3410 | + $this->_cpt_routes[$this->_req_action], |
|
3411 | + 'normal', |
|
3412 | + 'core' |
|
3413 | + ); |
|
3414 | + } |
|
3415 | + add_meta_box( |
|
3416 | + 'attendee_contact_info', |
|
3417 | + esc_html__('Contact Info', 'event_espresso'), |
|
3418 | + array($this, 'attendee_contact_info'), |
|
3419 | + $this->_cpt_routes[$this->_req_action], |
|
3420 | + 'side', |
|
3421 | + 'core' |
|
3422 | + ); |
|
3423 | + add_meta_box( |
|
3424 | + 'attendee_details_address', |
|
3425 | + esc_html__('Address Details', 'event_espresso'), |
|
3426 | + array($this, 'attendee_address_details'), |
|
3427 | + $this->_cpt_routes[$this->_req_action], |
|
3428 | + 'normal', |
|
3429 | + 'core' |
|
3430 | + ); |
|
3431 | + add_meta_box( |
|
3432 | + 'attendee_registrations', |
|
3433 | + esc_html__('Registrations for this Contact', 'event_espresso'), |
|
3434 | + array($this, 'attendee_registrations_meta_box'), |
|
3435 | + $this->_cpt_routes[$this->_req_action], |
|
3436 | + 'normal', |
|
3437 | + 'high' |
|
3438 | + ); |
|
3439 | + } |
|
3440 | + |
|
3441 | + |
|
3442 | + /** |
|
3443 | + * Metabox for attendee contact info |
|
3444 | + * |
|
3445 | + * @param WP_Post $post wp post object |
|
3446 | + * @return string attendee contact info ( and form ) |
|
3447 | + * @throws DomainException |
|
3448 | + */ |
|
3449 | + public function attendee_contact_info($post) |
|
3450 | + { |
|
3451 | + //get attendee object ( should already have it ) |
|
3452 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
3453 | + $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
3454 | + EEH_Template::display_template($template, $this->_template_args); |
|
3455 | + } |
|
3456 | + |
|
3457 | + |
|
3458 | + /** |
|
3459 | + * Metabox for attendee details |
|
3460 | + * |
|
3461 | + * @param WP_Post $post wp post object |
|
3462 | + * @return string attendee address details (and form) |
|
3463 | + * @throws DomainException |
|
3464 | + */ |
|
3465 | + public function attendee_address_details($post) |
|
3466 | + { |
|
3467 | + //get attendee object (should already have it) |
|
3468 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
3469 | + $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
3470 | + new EE_Question_Form_Input( |
|
3471 | + EE_Question::new_instance( |
|
3472 | + array( |
|
3473 | + 'QST_ID' => 0, |
|
3474 | + 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
3475 | + 'QST_system' => 'admin-state', |
|
3476 | + ) |
|
3477 | + ), |
|
3478 | + EE_Answer::new_instance( |
|
3479 | + array( |
|
3480 | + 'ANS_ID' => 0, |
|
3481 | + 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
3482 | + ) |
|
3483 | + ), |
|
3484 | + array( |
|
3485 | + 'input_id' => 'STA_ID', |
|
3486 | + 'input_name' => 'STA_ID', |
|
3487 | + 'input_prefix' => '', |
|
3488 | + 'append_qstn_id' => false, |
|
3489 | + ) |
|
3490 | + ) |
|
3491 | + ); |
|
3492 | + $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
3493 | + new EE_Question_Form_Input( |
|
3494 | + EE_Question::new_instance( |
|
3495 | + array( |
|
3496 | + 'QST_ID' => 0, |
|
3497 | + 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
3498 | + 'QST_system' => 'admin-country', |
|
3499 | + ) |
|
3500 | + ), |
|
3501 | + EE_Answer::new_instance( |
|
3502 | + array( |
|
3503 | + 'ANS_ID' => 0, |
|
3504 | + 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
3505 | + ) |
|
3506 | + ), |
|
3507 | + array( |
|
3508 | + 'input_id' => 'CNT_ISO', |
|
3509 | + 'input_name' => 'CNT_ISO', |
|
3510 | + 'input_prefix' => '', |
|
3511 | + 'append_qstn_id' => false, |
|
3512 | + ) |
|
3513 | + ) |
|
3514 | + ); |
|
3515 | + $template = |
|
3516 | + REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
3517 | + EEH_Template::display_template($template, $this->_template_args); |
|
3518 | + } |
|
3519 | + |
|
3520 | + |
|
3521 | + /** |
|
3522 | + * _attendee_details |
|
3523 | + * |
|
3524 | + * @access protected |
|
3525 | + * @param $post |
|
3526 | + * @return void |
|
3527 | + * @throws DomainException |
|
3528 | + * @throws EE_Error |
|
3529 | + */ |
|
3530 | + public function attendee_registrations_meta_box($post) |
|
3531 | + { |
|
3532 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
3533 | + $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
3534 | + $template = |
|
3535 | + REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
3536 | + EEH_Template::display_template($template, $this->_template_args); |
|
3537 | + } |
|
3538 | + |
|
3539 | + |
|
3540 | + /** |
|
3541 | + * add in the form fields for the attendee edit |
|
3542 | + * |
|
3543 | + * @param WP_Post $post wp post object |
|
3544 | + * @return string html for new form. |
|
3545 | + * @throws DomainException |
|
3546 | + */ |
|
3547 | + public function after_title_form_fields($post) |
|
3548 | + { |
|
3549 | + if ($post->post_type == 'espresso_attendees') { |
|
3550 | + $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
3551 | + $template_args['attendee'] = $this->_cpt_model_obj; |
|
3552 | + EEH_Template::display_template($template, $template_args); |
|
3553 | + } |
|
3554 | + } |
|
3555 | + |
|
3556 | + |
|
3557 | + /** |
|
3558 | + * _trash_or_restore_attendee |
|
3559 | + * |
|
3560 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
3561 | + * @return void |
|
3562 | + * @throws EE_Error |
|
3563 | + * @access protected |
|
3564 | + */ |
|
3565 | + protected function _trash_or_restore_attendees($trash = true) |
|
3566 | + { |
|
3567 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3568 | + $ATT_MDL = EEM_Attendee::instance(); |
|
3569 | + $success = 1; |
|
3570 | + //Checkboxes |
|
3571 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
3572 | + // if array has more than one element than success message should be plural |
|
3573 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
3574 | + // cycle thru checkboxes |
|
3575 | + while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
3576 | + $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
3577 | + : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
3578 | + if ( ! $updated) { |
|
3579 | + $success = 0; |
|
3580 | + } |
|
3581 | + } |
|
3582 | + } else { |
|
3583 | + // grab single id and delete |
|
3584 | + $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
3585 | + //get attendee |
|
3586 | + $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
3587 | + $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
3588 | + $updated = $att->save(); |
|
3589 | + if ( ! $updated) { |
|
3590 | + $success = 0; |
|
3591 | + } |
|
3592 | + } |
|
3593 | + $what = $success > 1 |
|
3594 | + ? esc_html__('Contacts', 'event_espresso') |
|
3595 | + : esc_html__('Contact', 'event_espresso'); |
|
3596 | + $action_desc = $trash |
|
3597 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
3598 | + : esc_html__('restored', 'event_espresso'); |
|
3599 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
3600 | + } |
|
3601 | 3601 | |
3602 | 3602 | } |
@@ -1,5 +1,5 @@ discard block |
||
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 |
@@ -30,44 +30,44 @@ discard block |
||
30 | 30 | { |
31 | 31 | |
32 | 32 | |
33 | - public function do_initial_loads() |
|
34 | - { |
|
35 | - //we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
|
36 | - //This is important because we have hooks that help redirect custom post type saves |
|
37 | - if (! isset($_REQUEST['page']) |
|
38 | - || (isset($_REQUEST['page']) |
|
39 | - && $_REQUEST['page'] |
|
40 | - != $this->_menu_map->menu_slug)) { |
|
41 | - $this->_routing = false; |
|
42 | - $this->_initialize_admin_page(); |
|
43 | - } else { |
|
44 | - //normal init loads |
|
45 | - $this->_initialize_admin_page(); |
|
46 | - //added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality |
|
47 | - remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization'); |
|
48 | - add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100); |
|
49 | - //end removal of autosave functionality. |
|
50 | - } |
|
51 | - } |
|
33 | + public function do_initial_loads() |
|
34 | + { |
|
35 | + //we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
|
36 | + //This is important because we have hooks that help redirect custom post type saves |
|
37 | + if (! isset($_REQUEST['page']) |
|
38 | + || (isset($_REQUEST['page']) |
|
39 | + && $_REQUEST['page'] |
|
40 | + != $this->_menu_map->menu_slug)) { |
|
41 | + $this->_routing = false; |
|
42 | + $this->_initialize_admin_page(); |
|
43 | + } else { |
|
44 | + //normal init loads |
|
45 | + $this->_initialize_admin_page(); |
|
46 | + //added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality |
|
47 | + remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization'); |
|
48 | + add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100); |
|
49 | + //end removal of autosave functionality. |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - public function wp_just_in_time_script_localization() |
|
55 | - { |
|
56 | - wp_localize_script( |
|
57 | - 'autosave', |
|
58 | - 'autosaveL10n', |
|
59 | - array( |
|
60 | - 'autosaveInterval' => 172800, |
|
61 | - 'savingText' => __('Saving Draft…'), |
|
62 | - 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
54 | + public function wp_just_in_time_script_localization() |
|
55 | + { |
|
56 | + wp_localize_script( |
|
57 | + 'autosave', |
|
58 | + 'autosaveL10n', |
|
59 | + array( |
|
60 | + 'autosaveInterval' => 172800, |
|
61 | + 'savingText' => __('Saving Draft…'), |
|
62 | + 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | 68 | |
69 | - public function adjust_post_lock_window($interval) |
|
70 | - { |
|
71 | - return 172800; |
|
72 | - } |
|
69 | + public function adjust_post_lock_window($interval) |
|
70 | + { |
|
71 | + return 172800; |
|
72 | + } |
|
73 | 73 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | //we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
36 | 36 | //This is important because we have hooks that help redirect custom post type saves |
37 | - if (! isset($_REQUEST['page']) |
|
37 | + if ( ! isset($_REQUEST['page']) |
|
38 | 38 | || (isset($_REQUEST['page']) |
39 | 39 | && $_REQUEST['page'] |
40 | 40 | != $this->_menu_map->menu_slug)) { |
@@ -222,7 +222,7 @@ |
||
222 | 222 | /** |
223 | 223 | * constructor |
224 | 224 | * |
225 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
225 | + * @param EE_Admin_Page $adminpage the calling admin_page_object |
|
226 | 226 | */ |
227 | 227 | public function __construct(EE_Admin_Page $adminpage) |
228 | 228 | { |
@@ -1,6 +1,6 @@ discard block |
||
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 | |
@@ -28,729 +28,729 @@ discard block |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * we're just going to use this to hold the name of the caller class (child class name) |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $caller; |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
42 | - * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
43 | - * used later to make sure we require the needed files. |
|
44 | - * |
|
45 | - * @var bool |
|
46 | - */ |
|
47 | - protected $_extend; |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * child classes MUST set this property so that the page object can be loaded correctly |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_name; |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * This is set by child classes and is an associative array of ajax hooks in the format: |
|
62 | - * array( |
|
63 | - * 'ajax_action_ref' => 'executing_method'; //must be public |
|
64 | - * ) |
|
65 | - * |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $_ajax_func; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
73 | - * array( |
|
74 | - * 'page_route' => 'executing_method' //must be public |
|
75 | - * ) |
|
76 | - * |
|
77 | - * @var array |
|
78 | - */ |
|
79 | - protected $_init_func; |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
85 | - * array( |
|
86 | - * 0 => array( |
|
87 | - * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
88 | - * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
89 | - * will be added to each route. |
|
90 | - * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
91 | - * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
92 | - * method arguments. |
|
93 | - * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
94 | - * automatically) |
|
95 | - * 'priority' => 'default', //default 'default' (optional) |
|
96 | - * 'label' => __('Localized Title', 'event_espresso'), |
|
97 | - * 'context' => 'advanced' //advanced is default (optional), |
|
98 | - * 'callback_args' => array() //any callback args to include (optional) |
|
99 | - * ) |
|
100 | - * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
101 | - * |
|
102 | - * @var array |
|
103 | - */ |
|
104 | - protected $_metaboxes; |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
110 | - * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
111 | - * array: array( |
|
112 | - * 0 => array( |
|
113 | - * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
114 | - * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
115 | - * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
116 | - * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
117 | - * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
118 | - * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
119 | - * id for the screen the metabox is on. |
|
120 | - * ) |
|
121 | - * ) |
|
122 | - * |
|
123 | - * @var array |
|
124 | - */ |
|
125 | - protected $_remove_metaboxes; |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
131 | - * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
132 | - * second array index is for indicating what routes each script/style loads on. array( |
|
133 | - * 'registers' => array( |
|
134 | - * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
135 | - * argument to link scripts together. |
|
136 | - * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
137 | - * 'url' => 'http://urltoscript.css.js', |
|
138 | - * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
139 | - * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
140 | - * gets loaded before the one you are setting here. |
|
141 | - * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
142 | - * ), |
|
143 | - * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
144 | - * the script gets enqueued on. |
|
145 | - * 'script_ref' => array('route_one', 'route_two') |
|
146 | - * ), |
|
147 | - * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
148 | - * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
149 | - * the object. |
|
150 | - * 'scrip_ref' => array( |
|
151 | - * 'NAME_OF_JS_OBJECT' => array( |
|
152 | - * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
153 | - * 'some_data' => 5 |
|
154 | - * ) |
|
155 | - * ) |
|
156 | - * ) |
|
157 | - * ) |
|
158 | - * |
|
159 | - * @var array |
|
160 | - */ |
|
161 | - protected $_scripts_styles; |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * This is a property that will contain the current route. |
|
166 | - * |
|
167 | - * @var string; |
|
168 | - */ |
|
169 | - protected $_current_route; |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
175 | - * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
176 | - * 'wp_hook_reference' => 1 |
|
177 | - * ) |
|
178 | - * ) |
|
179 | - * |
|
180 | - * @var array |
|
181 | - */ |
|
182 | - protected $_wp_action_filters_priority; |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
188 | - * |
|
189 | - * @var array |
|
190 | - */ |
|
191 | - protected $_req_data; |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * This just holds an instance of the page object for this hook |
|
197 | - * |
|
198 | - * @var EE_Admin_Page |
|
199 | - */ |
|
200 | - protected $_page_object; |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
206 | - * |
|
207 | - * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
208 | - */ |
|
209 | - protected $_adminpage_obj; |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Holds EE_Registry object |
|
215 | - * |
|
216 | - * @var EE_Registry |
|
217 | - */ |
|
218 | - protected $EE = null; |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * constructor |
|
224 | - * |
|
225 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
226 | - */ |
|
227 | - public function __construct(EE_Admin_Page $adminpage) |
|
228 | - { |
|
229 | - |
|
230 | - $this->_adminpage_obj = $adminpage; |
|
231 | - $this->_req_data = array_merge($_GET, $_POST); |
|
232 | - $this->_set_defaults(); |
|
233 | - $this->_set_hooks_properties(); |
|
234 | - //first let's verify we're on the right page |
|
235 | - if (! isset($this->_req_data['page']) |
|
236 | - || (isset($this->_req_data['page']) |
|
237 | - && $this->_adminpage_obj->page_slug |
|
238 | - != $this->_req_data['page'])) { |
|
239 | - return; |
|
240 | - } //get out nothing more to be done here. |
|
241 | - //allow for extends to modify properties |
|
242 | - if (method_exists($this, '_extend_properties')) { |
|
243 | - $this->_extend_properties(); |
|
244 | - } |
|
245 | - $this->_set_page_object(); |
|
246 | - $this->_init_hooks(); |
|
247 | - $this->_load_custom_methods(); |
|
248 | - $this->_load_routed_hooks(); |
|
249 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
250 | - add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
251 | - add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
252 | - $this->_ajax_hooks(); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * used by child classes to set the following properties: |
|
259 | - * $_ajax_func (optional) |
|
260 | - * $_init_func (optional) |
|
261 | - * $_metaboxes (optional) |
|
262 | - * $_scripts (optional) |
|
263 | - * $_styles (optional) |
|
264 | - * $_name (required) |
|
265 | - * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
266 | - * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
267 | - * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
268 | - * |
|
269 | - * @access protected |
|
270 | - * @abstract |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - abstract protected function _set_hooks_properties(); |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
279 | - * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
280 | - * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
281 | - * |
|
282 | - * @access public |
|
283 | - * @return void |
|
284 | - */ |
|
285 | - public function enqueue_scripts_styles() |
|
286 | - { |
|
287 | - |
|
288 | - if (! empty($this->_scripts_styles)) { |
|
289 | - //first let's do all the registrations |
|
290 | - if (! isset($this->_scripts_styles['registers'])) { |
|
291 | - $msg[] = __( |
|
292 | - 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
293 | - 'event_espresso' |
|
294 | - ); |
|
295 | - $msg[] = sprintf( |
|
296 | - __( |
|
297 | - 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
298 | - 'event_espresso' |
|
299 | - ), |
|
300 | - '<strong>' . $this->caller . '</strong>' |
|
301 | - ); |
|
302 | - throw new EE_Error(implode('||', $msg)); |
|
303 | - } |
|
304 | - foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
305 | - $defaults = array( |
|
306 | - 'type' => 'js', |
|
307 | - 'url' => '', |
|
308 | - 'depends' => array(), |
|
309 | - 'version' => EVENT_ESPRESSO_VERSION, |
|
310 | - 'footer' => true, |
|
311 | - ); |
|
312 | - $details = wp_parse_args($details, $defaults); |
|
313 | - extract($details); |
|
314 | - //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
315 | - $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
316 | - //let's make sure we're not missing any REQUIRED parameters |
|
317 | - if (empty($url)) { |
|
318 | - $msg[] = sprintf( |
|
319 | - __('Missing the url for the requested %s', 'event_espresso'), |
|
320 | - $type == 'js' ? 'script' : 'stylesheet' |
|
321 | - ); |
|
322 | - $msg[] = sprintf( |
|
323 | - __( |
|
324 | - 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
325 | - 'event_espresso' |
|
326 | - ), |
|
327 | - '<strong>' . $this->caller . '</strong>', |
|
328 | - $ref |
|
329 | - ); |
|
330 | - throw new EE_Error(implode('||', $msg)); |
|
331 | - } |
|
332 | - //made it here so let's do the appropriate registration |
|
333 | - $type == 'js' |
|
334 | - ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
335 | - : wp_register_style( |
|
336 | - $ref, |
|
337 | - $url, |
|
338 | - $depends, |
|
339 | - $version |
|
340 | - ); |
|
341 | - } |
|
342 | - //k now lets do the enqueues |
|
343 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
344 | - return; |
|
345 | - } //not sure if we should throw an error here or not. |
|
346 | - foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
347 | - //make sure $routes is an array |
|
348 | - $routes = (array)$routes; |
|
349 | - if (in_array($this->_current_route, $routes)) { |
|
350 | - $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
351 | - : wp_enqueue_style($ref); |
|
352 | - //if we have a localization for the script let's do that too. |
|
353 | - if (isset($this->_scripts_styles['localize'][$ref])) { |
|
354 | - foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
355 | - wp_localize_script( |
|
356 | - $ref, |
|
357 | - $object_name, |
|
358 | - $this->_scripts_styles['localize'][$ref][$object_name] |
|
359 | - ); |
|
360 | - } |
|
361 | - } |
|
362 | - } |
|
363 | - } |
|
364 | - //let's do the deregisters |
|
365 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
366 | - return; |
|
367 | - } |
|
368 | - foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
369 | - $defaults = array( |
|
370 | - 'type' => 'js', |
|
371 | - ); |
|
372 | - $details = wp_parse_args($details, $defaults); |
|
373 | - extract($details); |
|
374 | - $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
375 | - } |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * just set the defaults for the hooks properties. |
|
383 | - * |
|
384 | - * @access private |
|
385 | - * @return void |
|
386 | - */ |
|
387 | - private function _set_defaults() |
|
388 | - { |
|
389 | - $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
390 | - $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
391 | - $this->caller = get_class($this); |
|
392 | - $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * this sets the _page_object property |
|
399 | - * |
|
400 | - * @access protected |
|
401 | - * @return void |
|
402 | - */ |
|
403 | - protected function _set_page_object() |
|
404 | - { |
|
405 | - //first make sure $this->_name is set |
|
406 | - if (empty($this->_name)) { |
|
407 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
408 | - $msg[] = sprintf( |
|
409 | - __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
410 | - $this->caller |
|
411 | - ); |
|
412 | - throw new EE_Error(implode('||', $msg)); |
|
413 | - } |
|
414 | - $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
|
415 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
416 | - //first default file (if exists) |
|
417 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
418 | - if (is_readable($decaf_file)) { |
|
419 | - require_once($decaf_file); |
|
420 | - } |
|
421 | - //now we have to do require for extended file (if needed) |
|
422 | - if ($this->_extend) { |
|
423 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
424 | - } |
|
425 | - //if we've got an extended class we use that! |
|
426 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
427 | - //let's make sure the class exists |
|
428 | - if (! class_exists($ref)) { |
|
429 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
430 | - $msg[] = sprintf( |
|
431 | - __( |
|
432 | - 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
433 | - 'event_espresso' |
|
434 | - ), |
|
435 | - $ref |
|
436 | - ); |
|
437 | - throw new EE_Error(implode('||', $msg)); |
|
438 | - } |
|
439 | - $a = new ReflectionClass($ref); |
|
440 | - $this->_page_object = $a->newInstance(false); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
446 | - * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
447 | - * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
448 | - * |
|
449 | - * @access private |
|
450 | - * @return void |
|
451 | - */ |
|
452 | - private function _load_custom_methods() |
|
453 | - { |
|
454 | - /** |
|
455 | - * method cannot be named 'default' (@see http://us3.php |
|
456 | - * .net/manual/en/reserved.keywords.php) so need to |
|
457 | - * handle routes that are "default" |
|
458 | - * |
|
459 | - * @since 4.3.0 |
|
460 | - */ |
|
461 | - $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
462 | - //these run before the Admin_Page route executes. |
|
463 | - if (method_exists($this, $method_callback)) { |
|
464 | - call_user_func(array($this, $method_callback)); |
|
465 | - } |
|
466 | - //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
467 | - //first the actions |
|
468 | - //note that these action hooks will have the $query_args value available. |
|
469 | - $admin_class_name = get_class($this->_adminpage_obj); |
|
470 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
471 | - add_action( |
|
472 | - 'AHEE__' |
|
473 | - . $admin_class_name |
|
474 | - . '___redirect_after_action__before_redirect_modification_' |
|
475 | - . $this->_current_route, |
|
476 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
477 | - 10 |
|
478 | - ); |
|
479 | - } |
|
480 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
481 | - add_action( |
|
482 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
483 | - array($this, '_redirect_action_' . $this->_current_route), |
|
484 | - 10 |
|
485 | - ); |
|
486 | - } |
|
487 | - //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
488 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
489 | - add_filter( |
|
490 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
491 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
492 | - 10, |
|
493 | - 2 |
|
494 | - ); |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
502 | - * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
503 | - * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
504 | - * |
|
505 | - * @return void |
|
506 | - */ |
|
507 | - private function _load_routed_hooks() |
|
508 | - { |
|
509 | - |
|
510 | - //this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
511 | - $hook_filter_array = array( |
|
512 | - 'admin_footer' => array( |
|
513 | - 'type' => 'action', |
|
514 | - 'argnum' => 1, |
|
515 | - 'priority' => 10, |
|
516 | - ), |
|
517 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
518 | - 'type' => 'filter', |
|
519 | - 'argnum' => 1, |
|
520 | - 'priority' => 10, |
|
521 | - ), |
|
522 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
523 | - 'type' => 'filter', |
|
524 | - 'argnum' => 1, |
|
525 | - 'priority' => 10, |
|
526 | - ), |
|
527 | - 'FHEE_list_table_views' => array( |
|
528 | - 'type' => 'filter', |
|
529 | - 'argnum' => 1, |
|
530 | - 'priority' => 10, |
|
531 | - ), |
|
532 | - 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
533 | - 'type' => 'action', |
|
534 | - 'argnum' => 1, |
|
535 | - 'priority' => 10, |
|
536 | - ), |
|
537 | - ); |
|
538 | - foreach ($hook_filter_array as $hook => $args) { |
|
539 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
540 | - if (isset($this->_wp_action_filters_priority[$hook])) { |
|
541 | - $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
542 | - } |
|
543 | - if ($args['type'] == 'action') { |
|
544 | - add_action( |
|
545 | - $hook, |
|
546 | - array($this, $this->_current_route . '_' . $hook), |
|
547 | - $args['priority'], |
|
548 | - $args['argnum'] |
|
549 | - ); |
|
550 | - } else { |
|
551 | - add_filter( |
|
552 | - $hook, |
|
553 | - array($this, $this->_current_route . '_' . $hook), |
|
554 | - $args['priority'], |
|
555 | - $args['argnum'] |
|
556 | - ); |
|
557 | - } |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Loop throught the $_ajax_func array and add_actions for the array. |
|
565 | - * |
|
566 | - * @return void |
|
567 | - */ |
|
568 | - private function _ajax_hooks() |
|
569 | - { |
|
570 | - |
|
571 | - if (empty($this->_ajax_func)) { |
|
572 | - return; |
|
573 | - } //get out there's nothing to take care of. |
|
574 | - foreach ($this->_ajax_func as $action => $method) { |
|
575 | - //make sure method exists |
|
576 | - if (! method_exists($this, $method)) { |
|
577 | - $msg[] = __( |
|
578 | - 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
579 | - 'event_espresso' |
|
580 | - ) . '<br />'; |
|
581 | - $msg[] = sprintf( |
|
582 | - __( |
|
583 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
584 | - 'event_espresso' |
|
585 | - ), |
|
586 | - $method, |
|
587 | - $this->caller |
|
588 | - ); |
|
589 | - throw new EE_Error(implode('||', $msg)); |
|
590 | - } |
|
591 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
592 | - } |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Loop throught the $_init_func array and add_actions for the array. |
|
599 | - * |
|
600 | - * @return void |
|
601 | - */ |
|
602 | - protected function _init_hooks() |
|
603 | - { |
|
604 | - if (empty($this->_init_func)) { |
|
605 | - return; |
|
606 | - } //get out there's nothing to take care of. |
|
607 | - //We need to determine what page_route we are on! |
|
608 | - $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
609 | - foreach ($this->_init_func as $route => $method) { |
|
610 | - //make sure method exists |
|
611 | - if (! method_exists($this, $method)) { |
|
612 | - $msg[] = __( |
|
613 | - 'There is no corresponding method for the hook labeled in the _init_func array', |
|
614 | - 'event_espresso' |
|
615 | - ) . '<br />'; |
|
616 | - $msg[] = sprintf( |
|
617 | - __( |
|
618 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
619 | - 'event_espresso' |
|
620 | - ), |
|
621 | - $method, |
|
622 | - $this->caller |
|
623 | - ); |
|
624 | - throw new EE_Error(implode('||', $msg)); |
|
625 | - } |
|
626 | - if ($route == $this->_current_route) { |
|
627 | - add_action('admin_init', array($this, $method)); |
|
628 | - } |
|
629 | - } |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * Loop through the _metaboxes property and add_metaboxes accordingly |
|
636 | - * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
637 | - * |
|
638 | - * @access public |
|
639 | - * @return void |
|
640 | - */ |
|
641 | - public function add_metaboxes() |
|
642 | - { |
|
643 | - if (empty($this->_metaboxes)) { |
|
644 | - return; |
|
645 | - } //get out we don't have any metaboxes to set for this connection |
|
646 | - $this->_handle_metabox_array($this->_metaboxes); |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - |
|
651 | - private function _handle_metabox_array($boxes, $add = true) |
|
652 | - { |
|
653 | - |
|
654 | - foreach ($boxes as $box) { |
|
655 | - if (! isset($box['page_route'])) { |
|
656 | - continue; |
|
657 | - } //we dont' have a valid array |
|
658 | - //let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
659 | - $box['page_route'] = (array)$box['page_route']; |
|
660 | - foreach ($box['page_route'] as $route) { |
|
661 | - if ($route != $this->_current_route) { |
|
662 | - continue; |
|
663 | - } //get out we only add metaboxes for set route. |
|
664 | - if ($add) { |
|
665 | - $this->_add_metabox($box); |
|
666 | - } else { |
|
667 | - $this->_remove_metabox($box); |
|
668 | - } |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
677 | - * |
|
678 | - * @access public |
|
679 | - * @return void |
|
680 | - */ |
|
681 | - public function remove_metaboxes() |
|
682 | - { |
|
683 | - |
|
684 | - if (empty($this->_remove_metaboxes)) { |
|
685 | - return; |
|
686 | - } //get out there are no metaboxes to remove |
|
687 | - $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * This just handles adding a metabox |
|
693 | - * |
|
694 | - * @access private |
|
695 | - * @param array $args an array of args that have been set for this metabox by the child class |
|
696 | - */ |
|
697 | - private function _add_metabox($args) |
|
698 | - { |
|
699 | - $current_screen = get_current_screen(); |
|
700 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
701 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
702 | - //set defaults |
|
703 | - $defaults = array( |
|
704 | - 'func' => $func, |
|
705 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
706 | - 'priority' => 'default', |
|
707 | - 'label' => $this->caller, |
|
708 | - 'context' => 'advanced', |
|
709 | - 'callback_args' => array(), |
|
710 | - 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
711 | - ); |
|
712 | - $args = wp_parse_args($args, $defaults); |
|
713 | - extract($args); |
|
714 | - //make sure method exists |
|
715 | - if (! method_exists($this, $func)) { |
|
716 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
717 | - $msg[] = sprintf( |
|
718 | - __( |
|
719 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
720 | - 'event_espresso' |
|
721 | - ), |
|
722 | - $func, |
|
723 | - $this->caller |
|
724 | - ); |
|
725 | - throw new EE_Error(implode('||', $msg)); |
|
726 | - } |
|
727 | - //everything checks out so lets add the metabox |
|
728 | - add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - |
|
733 | - private function _remove_metabox($args) |
|
734 | - { |
|
735 | - $current_screen = get_current_screen(); |
|
736 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
737 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
738 | - //set defaults |
|
739 | - $defaults = array( |
|
740 | - 'id' => isset($args['id']) |
|
741 | - ? $args['id'] |
|
742 | - : $this->_current_route |
|
743 | - . '_' |
|
744 | - . $this->caller |
|
745 | - . '_' |
|
746 | - . $func |
|
747 | - . '_metabox', |
|
748 | - 'context' => 'default', |
|
749 | - 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id |
|
750 | - ); |
|
751 | - $args = wp_parse_args($args, $defaults); |
|
752 | - extract($args); |
|
753 | - //everything checks out so lets remove the box! |
|
754 | - remove_meta_box($id, $screen, $context); |
|
755 | - } |
|
31 | + /** |
|
32 | + * we're just going to use this to hold the name of the caller class (child class name) |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $caller; |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
42 | + * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
43 | + * used later to make sure we require the needed files. |
|
44 | + * |
|
45 | + * @var bool |
|
46 | + */ |
|
47 | + protected $_extend; |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * child classes MUST set this property so that the page object can be loaded correctly |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_name; |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * This is set by child classes and is an associative array of ajax hooks in the format: |
|
62 | + * array( |
|
63 | + * 'ajax_action_ref' => 'executing_method'; //must be public |
|
64 | + * ) |
|
65 | + * |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $_ajax_func; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
73 | + * array( |
|
74 | + * 'page_route' => 'executing_method' //must be public |
|
75 | + * ) |
|
76 | + * |
|
77 | + * @var array |
|
78 | + */ |
|
79 | + protected $_init_func; |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
85 | + * array( |
|
86 | + * 0 => array( |
|
87 | + * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
88 | + * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
89 | + * will be added to each route. |
|
90 | + * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
91 | + * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
92 | + * method arguments. |
|
93 | + * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
94 | + * automatically) |
|
95 | + * 'priority' => 'default', //default 'default' (optional) |
|
96 | + * 'label' => __('Localized Title', 'event_espresso'), |
|
97 | + * 'context' => 'advanced' //advanced is default (optional), |
|
98 | + * 'callback_args' => array() //any callback args to include (optional) |
|
99 | + * ) |
|
100 | + * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
101 | + * |
|
102 | + * @var array |
|
103 | + */ |
|
104 | + protected $_metaboxes; |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
110 | + * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
111 | + * array: array( |
|
112 | + * 0 => array( |
|
113 | + * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
114 | + * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
115 | + * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
116 | + * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
117 | + * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
118 | + * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
119 | + * id for the screen the metabox is on. |
|
120 | + * ) |
|
121 | + * ) |
|
122 | + * |
|
123 | + * @var array |
|
124 | + */ |
|
125 | + protected $_remove_metaboxes; |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
131 | + * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
132 | + * second array index is for indicating what routes each script/style loads on. array( |
|
133 | + * 'registers' => array( |
|
134 | + * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
135 | + * argument to link scripts together. |
|
136 | + * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
137 | + * 'url' => 'http://urltoscript.css.js', |
|
138 | + * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
139 | + * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
140 | + * gets loaded before the one you are setting here. |
|
141 | + * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
142 | + * ), |
|
143 | + * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
144 | + * the script gets enqueued on. |
|
145 | + * 'script_ref' => array('route_one', 'route_two') |
|
146 | + * ), |
|
147 | + * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
148 | + * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
149 | + * the object. |
|
150 | + * 'scrip_ref' => array( |
|
151 | + * 'NAME_OF_JS_OBJECT' => array( |
|
152 | + * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
153 | + * 'some_data' => 5 |
|
154 | + * ) |
|
155 | + * ) |
|
156 | + * ) |
|
157 | + * ) |
|
158 | + * |
|
159 | + * @var array |
|
160 | + */ |
|
161 | + protected $_scripts_styles; |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * This is a property that will contain the current route. |
|
166 | + * |
|
167 | + * @var string; |
|
168 | + */ |
|
169 | + protected $_current_route; |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
175 | + * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
176 | + * 'wp_hook_reference' => 1 |
|
177 | + * ) |
|
178 | + * ) |
|
179 | + * |
|
180 | + * @var array |
|
181 | + */ |
|
182 | + protected $_wp_action_filters_priority; |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
188 | + * |
|
189 | + * @var array |
|
190 | + */ |
|
191 | + protected $_req_data; |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * This just holds an instance of the page object for this hook |
|
197 | + * |
|
198 | + * @var EE_Admin_Page |
|
199 | + */ |
|
200 | + protected $_page_object; |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
206 | + * |
|
207 | + * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
208 | + */ |
|
209 | + protected $_adminpage_obj; |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Holds EE_Registry object |
|
215 | + * |
|
216 | + * @var EE_Registry |
|
217 | + */ |
|
218 | + protected $EE = null; |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * constructor |
|
224 | + * |
|
225 | + * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
226 | + */ |
|
227 | + public function __construct(EE_Admin_Page $adminpage) |
|
228 | + { |
|
229 | + |
|
230 | + $this->_adminpage_obj = $adminpage; |
|
231 | + $this->_req_data = array_merge($_GET, $_POST); |
|
232 | + $this->_set_defaults(); |
|
233 | + $this->_set_hooks_properties(); |
|
234 | + //first let's verify we're on the right page |
|
235 | + if (! isset($this->_req_data['page']) |
|
236 | + || (isset($this->_req_data['page']) |
|
237 | + && $this->_adminpage_obj->page_slug |
|
238 | + != $this->_req_data['page'])) { |
|
239 | + return; |
|
240 | + } //get out nothing more to be done here. |
|
241 | + //allow for extends to modify properties |
|
242 | + if (method_exists($this, '_extend_properties')) { |
|
243 | + $this->_extend_properties(); |
|
244 | + } |
|
245 | + $this->_set_page_object(); |
|
246 | + $this->_init_hooks(); |
|
247 | + $this->_load_custom_methods(); |
|
248 | + $this->_load_routed_hooks(); |
|
249 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
250 | + add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
251 | + add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
252 | + $this->_ajax_hooks(); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * used by child classes to set the following properties: |
|
259 | + * $_ajax_func (optional) |
|
260 | + * $_init_func (optional) |
|
261 | + * $_metaboxes (optional) |
|
262 | + * $_scripts (optional) |
|
263 | + * $_styles (optional) |
|
264 | + * $_name (required) |
|
265 | + * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
266 | + * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
267 | + * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
268 | + * |
|
269 | + * @access protected |
|
270 | + * @abstract |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + abstract protected function _set_hooks_properties(); |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
279 | + * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
280 | + * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
281 | + * |
|
282 | + * @access public |
|
283 | + * @return void |
|
284 | + */ |
|
285 | + public function enqueue_scripts_styles() |
|
286 | + { |
|
287 | + |
|
288 | + if (! empty($this->_scripts_styles)) { |
|
289 | + //first let's do all the registrations |
|
290 | + if (! isset($this->_scripts_styles['registers'])) { |
|
291 | + $msg[] = __( |
|
292 | + 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
293 | + 'event_espresso' |
|
294 | + ); |
|
295 | + $msg[] = sprintf( |
|
296 | + __( |
|
297 | + 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
298 | + 'event_espresso' |
|
299 | + ), |
|
300 | + '<strong>' . $this->caller . '</strong>' |
|
301 | + ); |
|
302 | + throw new EE_Error(implode('||', $msg)); |
|
303 | + } |
|
304 | + foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
305 | + $defaults = array( |
|
306 | + 'type' => 'js', |
|
307 | + 'url' => '', |
|
308 | + 'depends' => array(), |
|
309 | + 'version' => EVENT_ESPRESSO_VERSION, |
|
310 | + 'footer' => true, |
|
311 | + ); |
|
312 | + $details = wp_parse_args($details, $defaults); |
|
313 | + extract($details); |
|
314 | + //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
315 | + $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
316 | + //let's make sure we're not missing any REQUIRED parameters |
|
317 | + if (empty($url)) { |
|
318 | + $msg[] = sprintf( |
|
319 | + __('Missing the url for the requested %s', 'event_espresso'), |
|
320 | + $type == 'js' ? 'script' : 'stylesheet' |
|
321 | + ); |
|
322 | + $msg[] = sprintf( |
|
323 | + __( |
|
324 | + 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
325 | + 'event_espresso' |
|
326 | + ), |
|
327 | + '<strong>' . $this->caller . '</strong>', |
|
328 | + $ref |
|
329 | + ); |
|
330 | + throw new EE_Error(implode('||', $msg)); |
|
331 | + } |
|
332 | + //made it here so let's do the appropriate registration |
|
333 | + $type == 'js' |
|
334 | + ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
335 | + : wp_register_style( |
|
336 | + $ref, |
|
337 | + $url, |
|
338 | + $depends, |
|
339 | + $version |
|
340 | + ); |
|
341 | + } |
|
342 | + //k now lets do the enqueues |
|
343 | + if (! isset($this->_scripts_styles['enqueues'])) { |
|
344 | + return; |
|
345 | + } //not sure if we should throw an error here or not. |
|
346 | + foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
347 | + //make sure $routes is an array |
|
348 | + $routes = (array)$routes; |
|
349 | + if (in_array($this->_current_route, $routes)) { |
|
350 | + $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
351 | + : wp_enqueue_style($ref); |
|
352 | + //if we have a localization for the script let's do that too. |
|
353 | + if (isset($this->_scripts_styles['localize'][$ref])) { |
|
354 | + foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
355 | + wp_localize_script( |
|
356 | + $ref, |
|
357 | + $object_name, |
|
358 | + $this->_scripts_styles['localize'][$ref][$object_name] |
|
359 | + ); |
|
360 | + } |
|
361 | + } |
|
362 | + } |
|
363 | + } |
|
364 | + //let's do the deregisters |
|
365 | + if (! isset($this->_scripts_styles['deregisters'])) { |
|
366 | + return; |
|
367 | + } |
|
368 | + foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
369 | + $defaults = array( |
|
370 | + 'type' => 'js', |
|
371 | + ); |
|
372 | + $details = wp_parse_args($details, $defaults); |
|
373 | + extract($details); |
|
374 | + $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
375 | + } |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * just set the defaults for the hooks properties. |
|
383 | + * |
|
384 | + * @access private |
|
385 | + * @return void |
|
386 | + */ |
|
387 | + private function _set_defaults() |
|
388 | + { |
|
389 | + $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
390 | + $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
391 | + $this->caller = get_class($this); |
|
392 | + $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * this sets the _page_object property |
|
399 | + * |
|
400 | + * @access protected |
|
401 | + * @return void |
|
402 | + */ |
|
403 | + protected function _set_page_object() |
|
404 | + { |
|
405 | + //first make sure $this->_name is set |
|
406 | + if (empty($this->_name)) { |
|
407 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
408 | + $msg[] = sprintf( |
|
409 | + __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
410 | + $this->caller |
|
411 | + ); |
|
412 | + throw new EE_Error(implode('||', $msg)); |
|
413 | + } |
|
414 | + $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
|
415 | + $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
416 | + //first default file (if exists) |
|
417 | + $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
418 | + if (is_readable($decaf_file)) { |
|
419 | + require_once($decaf_file); |
|
420 | + } |
|
421 | + //now we have to do require for extended file (if needed) |
|
422 | + if ($this->_extend) { |
|
423 | + require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
424 | + } |
|
425 | + //if we've got an extended class we use that! |
|
426 | + $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
427 | + //let's make sure the class exists |
|
428 | + if (! class_exists($ref)) { |
|
429 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
430 | + $msg[] = sprintf( |
|
431 | + __( |
|
432 | + 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
433 | + 'event_espresso' |
|
434 | + ), |
|
435 | + $ref |
|
436 | + ); |
|
437 | + throw new EE_Error(implode('||', $msg)); |
|
438 | + } |
|
439 | + $a = new ReflectionClass($ref); |
|
440 | + $this->_page_object = $a->newInstance(false); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
446 | + * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
447 | + * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
448 | + * |
|
449 | + * @access private |
|
450 | + * @return void |
|
451 | + */ |
|
452 | + private function _load_custom_methods() |
|
453 | + { |
|
454 | + /** |
|
455 | + * method cannot be named 'default' (@see http://us3.php |
|
456 | + * .net/manual/en/reserved.keywords.php) so need to |
|
457 | + * handle routes that are "default" |
|
458 | + * |
|
459 | + * @since 4.3.0 |
|
460 | + */ |
|
461 | + $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
462 | + //these run before the Admin_Page route executes. |
|
463 | + if (method_exists($this, $method_callback)) { |
|
464 | + call_user_func(array($this, $method_callback)); |
|
465 | + } |
|
466 | + //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
467 | + //first the actions |
|
468 | + //note that these action hooks will have the $query_args value available. |
|
469 | + $admin_class_name = get_class($this->_adminpage_obj); |
|
470 | + if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
471 | + add_action( |
|
472 | + 'AHEE__' |
|
473 | + . $admin_class_name |
|
474 | + . '___redirect_after_action__before_redirect_modification_' |
|
475 | + . $this->_current_route, |
|
476 | + array($this, '_redirect_action_early_' . $this->_current_route), |
|
477 | + 10 |
|
478 | + ); |
|
479 | + } |
|
480 | + if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
481 | + add_action( |
|
482 | + 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
483 | + array($this, '_redirect_action_' . $this->_current_route), |
|
484 | + 10 |
|
485 | + ); |
|
486 | + } |
|
487 | + //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
488 | + if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
489 | + add_filter( |
|
490 | + 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
491 | + array($this, '_redirect_filter_' . $this->_current_route), |
|
492 | + 10, |
|
493 | + 2 |
|
494 | + ); |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
502 | + * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
503 | + * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
504 | + * |
|
505 | + * @return void |
|
506 | + */ |
|
507 | + private function _load_routed_hooks() |
|
508 | + { |
|
509 | + |
|
510 | + //this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
511 | + $hook_filter_array = array( |
|
512 | + 'admin_footer' => array( |
|
513 | + 'type' => 'action', |
|
514 | + 'argnum' => 1, |
|
515 | + 'priority' => 10, |
|
516 | + ), |
|
517 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
518 | + 'type' => 'filter', |
|
519 | + 'argnum' => 1, |
|
520 | + 'priority' => 10, |
|
521 | + ), |
|
522 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
523 | + 'type' => 'filter', |
|
524 | + 'argnum' => 1, |
|
525 | + 'priority' => 10, |
|
526 | + ), |
|
527 | + 'FHEE_list_table_views' => array( |
|
528 | + 'type' => 'filter', |
|
529 | + 'argnum' => 1, |
|
530 | + 'priority' => 10, |
|
531 | + ), |
|
532 | + 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
533 | + 'type' => 'action', |
|
534 | + 'argnum' => 1, |
|
535 | + 'priority' => 10, |
|
536 | + ), |
|
537 | + ); |
|
538 | + foreach ($hook_filter_array as $hook => $args) { |
|
539 | + if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
540 | + if (isset($this->_wp_action_filters_priority[$hook])) { |
|
541 | + $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
542 | + } |
|
543 | + if ($args['type'] == 'action') { |
|
544 | + add_action( |
|
545 | + $hook, |
|
546 | + array($this, $this->_current_route . '_' . $hook), |
|
547 | + $args['priority'], |
|
548 | + $args['argnum'] |
|
549 | + ); |
|
550 | + } else { |
|
551 | + add_filter( |
|
552 | + $hook, |
|
553 | + array($this, $this->_current_route . '_' . $hook), |
|
554 | + $args['priority'], |
|
555 | + $args['argnum'] |
|
556 | + ); |
|
557 | + } |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Loop throught the $_ajax_func array and add_actions for the array. |
|
565 | + * |
|
566 | + * @return void |
|
567 | + */ |
|
568 | + private function _ajax_hooks() |
|
569 | + { |
|
570 | + |
|
571 | + if (empty($this->_ajax_func)) { |
|
572 | + return; |
|
573 | + } //get out there's nothing to take care of. |
|
574 | + foreach ($this->_ajax_func as $action => $method) { |
|
575 | + //make sure method exists |
|
576 | + if (! method_exists($this, $method)) { |
|
577 | + $msg[] = __( |
|
578 | + 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
579 | + 'event_espresso' |
|
580 | + ) . '<br />'; |
|
581 | + $msg[] = sprintf( |
|
582 | + __( |
|
583 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
584 | + 'event_espresso' |
|
585 | + ), |
|
586 | + $method, |
|
587 | + $this->caller |
|
588 | + ); |
|
589 | + throw new EE_Error(implode('||', $msg)); |
|
590 | + } |
|
591 | + add_action('wp_ajax_' . $action, array($this, $method)); |
|
592 | + } |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Loop throught the $_init_func array and add_actions for the array. |
|
599 | + * |
|
600 | + * @return void |
|
601 | + */ |
|
602 | + protected function _init_hooks() |
|
603 | + { |
|
604 | + if (empty($this->_init_func)) { |
|
605 | + return; |
|
606 | + } //get out there's nothing to take care of. |
|
607 | + //We need to determine what page_route we are on! |
|
608 | + $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
609 | + foreach ($this->_init_func as $route => $method) { |
|
610 | + //make sure method exists |
|
611 | + if (! method_exists($this, $method)) { |
|
612 | + $msg[] = __( |
|
613 | + 'There is no corresponding method for the hook labeled in the _init_func array', |
|
614 | + 'event_espresso' |
|
615 | + ) . '<br />'; |
|
616 | + $msg[] = sprintf( |
|
617 | + __( |
|
618 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
619 | + 'event_espresso' |
|
620 | + ), |
|
621 | + $method, |
|
622 | + $this->caller |
|
623 | + ); |
|
624 | + throw new EE_Error(implode('||', $msg)); |
|
625 | + } |
|
626 | + if ($route == $this->_current_route) { |
|
627 | + add_action('admin_init', array($this, $method)); |
|
628 | + } |
|
629 | + } |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * Loop through the _metaboxes property and add_metaboxes accordingly |
|
636 | + * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
637 | + * |
|
638 | + * @access public |
|
639 | + * @return void |
|
640 | + */ |
|
641 | + public function add_metaboxes() |
|
642 | + { |
|
643 | + if (empty($this->_metaboxes)) { |
|
644 | + return; |
|
645 | + } //get out we don't have any metaboxes to set for this connection |
|
646 | + $this->_handle_metabox_array($this->_metaboxes); |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + |
|
651 | + private function _handle_metabox_array($boxes, $add = true) |
|
652 | + { |
|
653 | + |
|
654 | + foreach ($boxes as $box) { |
|
655 | + if (! isset($box['page_route'])) { |
|
656 | + continue; |
|
657 | + } //we dont' have a valid array |
|
658 | + //let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
659 | + $box['page_route'] = (array)$box['page_route']; |
|
660 | + foreach ($box['page_route'] as $route) { |
|
661 | + if ($route != $this->_current_route) { |
|
662 | + continue; |
|
663 | + } //get out we only add metaboxes for set route. |
|
664 | + if ($add) { |
|
665 | + $this->_add_metabox($box); |
|
666 | + } else { |
|
667 | + $this->_remove_metabox($box); |
|
668 | + } |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
677 | + * |
|
678 | + * @access public |
|
679 | + * @return void |
|
680 | + */ |
|
681 | + public function remove_metaboxes() |
|
682 | + { |
|
683 | + |
|
684 | + if (empty($this->_remove_metaboxes)) { |
|
685 | + return; |
|
686 | + } //get out there are no metaboxes to remove |
|
687 | + $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * This just handles adding a metabox |
|
693 | + * |
|
694 | + * @access private |
|
695 | + * @param array $args an array of args that have been set for this metabox by the child class |
|
696 | + */ |
|
697 | + private function _add_metabox($args) |
|
698 | + { |
|
699 | + $current_screen = get_current_screen(); |
|
700 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
701 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
702 | + //set defaults |
|
703 | + $defaults = array( |
|
704 | + 'func' => $func, |
|
705 | + 'id' => $this->caller . '_' . $func . '_metabox', |
|
706 | + 'priority' => 'default', |
|
707 | + 'label' => $this->caller, |
|
708 | + 'context' => 'advanced', |
|
709 | + 'callback_args' => array(), |
|
710 | + 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
711 | + ); |
|
712 | + $args = wp_parse_args($args, $defaults); |
|
713 | + extract($args); |
|
714 | + //make sure method exists |
|
715 | + if (! method_exists($this, $func)) { |
|
716 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
717 | + $msg[] = sprintf( |
|
718 | + __( |
|
719 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
720 | + 'event_espresso' |
|
721 | + ), |
|
722 | + $func, |
|
723 | + $this->caller |
|
724 | + ); |
|
725 | + throw new EE_Error(implode('||', $msg)); |
|
726 | + } |
|
727 | + //everything checks out so lets add the metabox |
|
728 | + add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + |
|
733 | + private function _remove_metabox($args) |
|
734 | + { |
|
735 | + $current_screen = get_current_screen(); |
|
736 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
737 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
738 | + //set defaults |
|
739 | + $defaults = array( |
|
740 | + 'id' => isset($args['id']) |
|
741 | + ? $args['id'] |
|
742 | + : $this->_current_route |
|
743 | + . '_' |
|
744 | + . $this->caller |
|
745 | + . '_' |
|
746 | + . $func |
|
747 | + . '_metabox', |
|
748 | + 'context' => 'default', |
|
749 | + 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id |
|
750 | + ); |
|
751 | + $args = wp_parse_args($args, $defaults); |
|
752 | + extract($args); |
|
753 | + //everything checks out so lets remove the box! |
|
754 | + remove_meta_box($id, $screen, $context); |
|
755 | + } |
|
756 | 756 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $this->_set_defaults(); |
233 | 233 | $this->_set_hooks_properties(); |
234 | 234 | //first let's verify we're on the right page |
235 | - if (! isset($this->_req_data['page']) |
|
235 | + if ( ! isset($this->_req_data['page']) |
|
236 | 236 | || (isset($this->_req_data['page']) |
237 | 237 | && $this->_adminpage_obj->page_slug |
238 | 238 | != $this->_req_data['page'])) { |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | public function enqueue_scripts_styles() |
286 | 286 | { |
287 | 287 | |
288 | - if (! empty($this->_scripts_styles)) { |
|
288 | + if ( ! empty($this->_scripts_styles)) { |
|
289 | 289 | //first let's do all the registrations |
290 | - if (! isset($this->_scripts_styles['registers'])) { |
|
290 | + if ( ! isset($this->_scripts_styles['registers'])) { |
|
291 | 291 | $msg[] = __( |
292 | 292 | 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
293 | 293 | 'event_espresso' |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
298 | 298 | 'event_espresso' |
299 | 299 | ), |
300 | - '<strong>' . $this->caller . '</strong>' |
|
300 | + '<strong>'.$this->caller.'</strong>' |
|
301 | 301 | ); |
302 | 302 | throw new EE_Error(implode('||', $msg)); |
303 | 303 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | 'version' => EVENT_ESPRESSO_VERSION, |
310 | 310 | 'footer' => true, |
311 | 311 | ); |
312 | - $details = wp_parse_args($details, $defaults); |
|
312 | + $details = wp_parse_args($details, $defaults); |
|
313 | 313 | extract($details); |
314 | 314 | //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
315 | 315 | $this->_scripts_styles['registers'][$ref]['type'] = $type; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
325 | 325 | 'event_espresso' |
326 | 326 | ), |
327 | - '<strong>' . $this->caller . '</strong>', |
|
327 | + '<strong>'.$this->caller.'</strong>', |
|
328 | 328 | $ref |
329 | 329 | ); |
330 | 330 | throw new EE_Error(implode('||', $msg)); |
@@ -340,12 +340,12 @@ discard block |
||
340 | 340 | ); |
341 | 341 | } |
342 | 342 | //k now lets do the enqueues |
343 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
343 | + if ( ! isset($this->_scripts_styles['enqueues'])) { |
|
344 | 344 | return; |
345 | 345 | } //not sure if we should throw an error here or not. |
346 | 346 | foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
347 | 347 | //make sure $routes is an array |
348 | - $routes = (array)$routes; |
|
348 | + $routes = (array) $routes; |
|
349 | 349 | if (in_array($this->_current_route, $routes)) { |
350 | 350 | $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
351 | 351 | : wp_enqueue_style($ref); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | } |
363 | 363 | } |
364 | 364 | //let's do the deregisters |
365 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
365 | + if ( ! isset($this->_scripts_styles['deregisters'])) { |
|
366 | 366 | return; |
367 | 367 | } |
368 | 368 | foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
@@ -412,20 +412,20 @@ discard block |
||
412 | 412 | throw new EE_Error(implode('||', $msg)); |
413 | 413 | } |
414 | 414 | $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
415 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message |
|
415 | + $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; //take the message -> The_Message |
|
416 | 416 | //first default file (if exists) |
417 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
417 | + $decaf_file = EE_ADMIN_PAGES.$this->_name.DS.$ref.'.core.php'; |
|
418 | 418 | if (is_readable($decaf_file)) { |
419 | 419 | require_once($decaf_file); |
420 | 420 | } |
421 | 421 | //now we have to do require for extended file (if needed) |
422 | 422 | if ($this->_extend) { |
423 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
423 | + require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.DS.'Extend_'.$ref.'.core.php'); |
|
424 | 424 | } |
425 | 425 | //if we've got an extended class we use that! |
426 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
426 | + $ref = $this->_extend ? 'Extend_'.$ref : $ref; |
|
427 | 427 | //let's make sure the class exists |
428 | - if (! class_exists($ref)) { |
|
428 | + if ( ! class_exists($ref)) { |
|
429 | 429 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
430 | 430 | $msg[] = sprintf( |
431 | 431 | __( |
@@ -467,28 +467,28 @@ discard block |
||
467 | 467 | //first the actions |
468 | 468 | //note that these action hooks will have the $query_args value available. |
469 | 469 | $admin_class_name = get_class($this->_adminpage_obj); |
470 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
470 | + if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) { |
|
471 | 471 | add_action( |
472 | 472 | 'AHEE__' |
473 | 473 | . $admin_class_name |
474 | 474 | . '___redirect_after_action__before_redirect_modification_' |
475 | 475 | . $this->_current_route, |
476 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
476 | + array($this, '_redirect_action_early_'.$this->_current_route), |
|
477 | 477 | 10 |
478 | 478 | ); |
479 | 479 | } |
480 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
480 | + if (method_exists($this, '_redirect_action_'.$this->_current_route)) { |
|
481 | 481 | add_action( |
482 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
483 | - array($this, '_redirect_action_' . $this->_current_route), |
|
482 | + 'AHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
483 | + array($this, '_redirect_action_'.$this->_current_route), |
|
484 | 484 | 10 |
485 | 485 | ); |
486 | 486 | } |
487 | 487 | //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
488 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
488 | + if (method_exists($this, '_redirect_filter_'.$this->_current_route)) { |
|
489 | 489 | add_filter( |
490 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
491 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
490 | + 'FHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
491 | + array($this, '_redirect_filter_'.$this->_current_route), |
|
492 | 492 | 10, |
493 | 493 | 2 |
494 | 494 | ); |
@@ -514,12 +514,12 @@ discard block |
||
514 | 514 | 'argnum' => 1, |
515 | 515 | 'priority' => 10, |
516 | 516 | ), |
517 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
517 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array( |
|
518 | 518 | 'type' => 'filter', |
519 | 519 | 'argnum' => 1, |
520 | 520 | 'priority' => 10, |
521 | 521 | ), |
522 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
522 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug => array( |
|
523 | 523 | 'type' => 'filter', |
524 | 524 | 'argnum' => 1, |
525 | 525 | 'priority' => 10, |
@@ -536,21 +536,21 @@ discard block |
||
536 | 536 | ), |
537 | 537 | ); |
538 | 538 | foreach ($hook_filter_array as $hook => $args) { |
539 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
539 | + if (method_exists($this, $this->_current_route.'_'.$hook)) { |
|
540 | 540 | if (isset($this->_wp_action_filters_priority[$hook])) { |
541 | 541 | $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
542 | 542 | } |
543 | 543 | if ($args['type'] == 'action') { |
544 | 544 | add_action( |
545 | 545 | $hook, |
546 | - array($this, $this->_current_route . '_' . $hook), |
|
546 | + array($this, $this->_current_route.'_'.$hook), |
|
547 | 547 | $args['priority'], |
548 | 548 | $args['argnum'] |
549 | 549 | ); |
550 | 550 | } else { |
551 | 551 | add_filter( |
552 | 552 | $hook, |
553 | - array($this, $this->_current_route . '_' . $hook), |
|
553 | + array($this, $this->_current_route.'_'.$hook), |
|
554 | 554 | $args['priority'], |
555 | 555 | $args['argnum'] |
556 | 556 | ); |
@@ -573,11 +573,11 @@ discard block |
||
573 | 573 | } //get out there's nothing to take care of. |
574 | 574 | foreach ($this->_ajax_func as $action => $method) { |
575 | 575 | //make sure method exists |
576 | - if (! method_exists($this, $method)) { |
|
576 | + if ( ! method_exists($this, $method)) { |
|
577 | 577 | $msg[] = __( |
578 | 578 | 'There is no corresponding method for the hook labeled in the _ajax_func array', |
579 | 579 | 'event_espresso' |
580 | - ) . '<br />'; |
|
580 | + ).'<br />'; |
|
581 | 581 | $msg[] = sprintf( |
582 | 582 | __( |
583 | 583 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | ); |
589 | 589 | throw new EE_Error(implode('||', $msg)); |
590 | 590 | } |
591 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
591 | + add_action('wp_ajax_'.$action, array($this, $method)); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
@@ -608,11 +608,11 @@ discard block |
||
608 | 608 | $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
609 | 609 | foreach ($this->_init_func as $route => $method) { |
610 | 610 | //make sure method exists |
611 | - if (! method_exists($this, $method)) { |
|
611 | + if ( ! method_exists($this, $method)) { |
|
612 | 612 | $msg[] = __( |
613 | 613 | 'There is no corresponding method for the hook labeled in the _init_func array', |
614 | 614 | 'event_espresso' |
615 | - ) . '<br />'; |
|
615 | + ).'<br />'; |
|
616 | 616 | $msg[] = sprintf( |
617 | 617 | __( |
618 | 618 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -652,11 +652,11 @@ discard block |
||
652 | 652 | { |
653 | 653 | |
654 | 654 | foreach ($boxes as $box) { |
655 | - if (! isset($box['page_route'])) { |
|
655 | + if ( ! isset($box['page_route'])) { |
|
656 | 656 | continue; |
657 | 657 | } //we dont' have a valid array |
658 | 658 | //let's make sure $box['page_route'] is an array so the "foreach" will work. |
659 | - $box['page_route'] = (array)$box['page_route']; |
|
659 | + $box['page_route'] = (array) $box['page_route']; |
|
660 | 660 | foreach ($box['page_route'] as $route) { |
661 | 661 | if ($route != $this->_current_route) { |
662 | 662 | continue; |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | //set defaults |
703 | 703 | $defaults = array( |
704 | 704 | 'func' => $func, |
705 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
705 | + 'id' => $this->caller.'_'.$func.'_metabox', |
|
706 | 706 | 'priority' => 'default', |
707 | 707 | 'label' => $this->caller, |
708 | 708 | 'context' => 'advanced', |
@@ -712,8 +712,8 @@ discard block |
||
712 | 712 | $args = wp_parse_args($args, $defaults); |
713 | 713 | extract($args); |
714 | 714 | //make sure method exists |
715 | - if (! method_exists($this, $func)) { |
|
716 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
715 | + if ( ! method_exists($this, $func)) { |
|
716 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />'; |
|
717 | 717 | $msg[] = sprintf( |
718 | 718 | __( |
719 | 719 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -205,7 +205,6 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @access public |
207 | 207 | * @uses _initialize_admin_page() |
208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
209 | 208 | * @return void |
210 | 209 | */ |
211 | 210 | public function initialize_admin_page() |
@@ -221,6 +220,9 @@ discard block |
||
221 | 220 | |
222 | 221 | |
223 | 222 | |
223 | + /** |
|
224 | + * @param string $wp_page_slug |
|
225 | + */ |
|
224 | 226 | public function set_page_dependencies($wp_page_slug) |
225 | 227 | { |
226 | 228 | if (! $this->_load_page) { |
@@ -1,5 +1,5 @@ discard block |
||
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,443 +28,443 @@ discard block |
||
28 | 28 | abstract class EE_Admin_Page_Init extends EE_Base |
29 | 29 | { |
30 | 30 | |
31 | - //identity properties (set in _set_defaults and _set_init_properties) |
|
32 | - public $label; |
|
33 | - |
|
34 | - /** |
|
35 | - * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
36 | - * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $capability; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * This holds the menu map object for this admin page. |
|
45 | - * |
|
46 | - * @var EE_Admin_Page_Menu_Map |
|
47 | - */ |
|
48 | - protected $_menu_map; |
|
49 | - |
|
50 | - /** |
|
51 | - * deprecated |
|
52 | - */ |
|
53 | - public $menu_label; |
|
54 | - public $menu_slug; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - //set in _set_defaults |
|
59 | - protected $_folder_name; |
|
60 | - protected $_folder_path; |
|
61 | - protected $_file_name; |
|
62 | - public $hook_file; |
|
63 | - protected $_wp_page_slug; |
|
64 | - protected $_routing; |
|
65 | - |
|
66 | - |
|
67 | - //will hold page object. |
|
68 | - protected $_loaded_page_object; |
|
69 | - |
|
70 | - |
|
71 | - //for caf |
|
72 | - protected $_files_hooked; |
|
73 | - protected $_hook_paths; |
|
74 | - |
|
75 | - //load_page? |
|
76 | - private $_load_page; |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @Constructor |
|
82 | - * @access public |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - public function __construct() |
|
86 | - { |
|
87 | - //set global defaults |
|
88 | - $this->_set_defaults(); |
|
89 | - //set properties that are always available with objects. |
|
90 | - $this->_set_init_properties(); |
|
91 | - //global styles/scripts across all wp admin pages |
|
92 | - add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
93 | - //load initial stuff. |
|
94 | - $this->_set_file_and_folder_name(); |
|
95 | - $this->_set_menu_map(); |
|
96 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
97 | - EE_Error::doing_it_wrong( |
|
98 | - get_class($this) . '::$_menu_map', |
|
99 | - sprintf( |
|
100 | - __( |
|
101 | - 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - get_class($this) |
|
105 | - ), |
|
106 | - '4.4.0' |
|
107 | - ); |
|
108 | - return; |
|
109 | - } |
|
110 | - //set default capability |
|
111 | - $this->_set_capability(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * _set_init_properties |
|
118 | - * Child classes use to set the following properties: |
|
119 | - * $label |
|
120 | - * |
|
121 | - * @abstract |
|
122 | - * @access protected |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - abstract protected function _set_init_properties(); |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
131 | - * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
132 | - * |
|
133 | - * @since 4.4.0 |
|
134 | - * @ return void. |
|
135 | - */ |
|
136 | - protected function _set_menu_map() |
|
137 | - { |
|
138 | - return array(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * returns the menu map for this admin page |
|
145 | - * |
|
146 | - * @since 4.4.0 |
|
147 | - * @return EE_Admin_Page_Menu_Map |
|
148 | - */ |
|
149 | - public function get_menu_map() |
|
150 | - { |
|
151 | - return $this->_menu_map; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * This loads scripts and styles for the EE_Admin system |
|
158 | - * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
159 | - * |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - public function load_wp_global_scripts_styles() |
|
163 | - { |
|
164 | - wp_register_style( |
|
165 | - 'espresso_menu', |
|
166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
167 | - array('dashicons'), |
|
168 | - EVENT_ESPRESSO_VERSION |
|
169 | - ); |
|
170 | - wp_enqueue_style('espresso_menu'); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * this sets default properties (might be overridden in _set_init_properties); |
|
177 | - * |
|
178 | - * @access private |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function _set_defaults() |
|
182 | - { |
|
183 | - $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
184 | - $this->_routing = true; |
|
185 | - $this->_load_page = false; |
|
186 | - $this->_files_hooked = $this->_hook_paths = array(); |
|
187 | - //menu_map |
|
188 | - $this->_menu_map = $this->get_menu_map(); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - protected function _set_capability() |
|
194 | - { |
|
195 | - $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * initialize_admin_page |
|
203 | - * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
204 | - * EE_Admin_Init class. |
|
205 | - * |
|
206 | - * @access public |
|
207 | - * @uses _initialize_admin_page() |
|
208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function initialize_admin_page() |
|
212 | - { |
|
213 | - //let's check user access first |
|
214 | - $this->_check_user_access(); |
|
215 | - if (! is_object($this->_loaded_page_object)) { |
|
216 | - return; |
|
217 | - } |
|
218 | - $this->_loaded_page_object->route_admin_request(); |
|
219 | - return; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - public function set_page_dependencies($wp_page_slug) |
|
225 | - { |
|
226 | - if (! $this->_load_page) { |
|
227 | - return; |
|
228 | - } |
|
229 | - if (! is_object($this->_loaded_page_object)) { |
|
230 | - $msg[] = __( |
|
231 | - 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
232 | - 'event_espresso' |
|
233 | - ); |
|
234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
235 | - __( |
|
236 | - 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - $this->_file_name, |
|
240 | - $this->_file_name, |
|
241 | - $this->_folder_path . $this->_file_name, |
|
242 | - $this->_menu_map->menu_slug |
|
243 | - ); |
|
244 | - throw new EE_Error(implode('||', $msg)); |
|
245 | - } |
|
246 | - $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
247 | - $page_hook = 'load-' . $wp_page_slug; |
|
248 | - //hook into page load hook so all page specific stuff get's loaded. |
|
249 | - if (! empty($wp_page_slug)) { |
|
250 | - add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
257 | - * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
258 | - * |
|
259 | - * @return void |
|
260 | - */ |
|
261 | - public function do_initial_loads() |
|
262 | - { |
|
263 | - //no loading or initializing if menu map is setup incorrectly. |
|
264 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
265 | - return; |
|
266 | - } |
|
267 | - $this->_initialize_admin_page(); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * all we're doing here is setting the $_file_name property for later use. |
|
273 | - * |
|
274 | - * @access private |
|
275 | - * @return void |
|
276 | - */ |
|
277 | - private function _set_file_and_folder_name() |
|
278 | - { |
|
279 | - $bt = debug_backtrace(); |
|
280 | - //for more reliable determination of folder name |
|
281 | - //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
282 | - $class = get_class($this); |
|
283 | - foreach ($bt as $index => $values) { |
|
284 | - if (isset($values['class']) && $values['class'] == $class) { |
|
285 | - $file_index = $index - 1; |
|
286 | - $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
287 | - if (! empty($this->_folder_name)) { |
|
288 | - break; |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
293 | - $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
294 | - $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
295 | - $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
301 | - * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
302 | - * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
303 | - * events_Messages_Hooks.class.php |
|
304 | - * |
|
305 | - * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
306 | - * files/classes |
|
307 | - * @return array |
|
308 | - */ |
|
309 | - public function register_hooks($extend = false) |
|
310 | - { |
|
311 | - |
|
312 | - //get a list of files in the directory that have the "Hook" in their name an |
|
313 | - //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
314 | - if ($extend) { |
|
315 | - $hook_files_glob_path = apply_filters( |
|
316 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
317 | - EE_CORE_CAF_ADMIN_EXTEND |
|
318 | - . $this->_folder_name |
|
319 | - . DS |
|
320 | - . '*' |
|
321 | - . $this->_file_name |
|
322 | - . '_Hooks_Extend.class.php' |
|
323 | - ); |
|
324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
325 | - } |
|
326 | - //loop through decaf folders |
|
327 | - $hook_files_glob_path = apply_filters( |
|
328 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
330 | - ); |
|
331 | - $this->_hook_paths = array_merge( |
|
332 | - $this->_register_hook_files($hook_files_glob_path), |
|
333 | - $this->_hook_paths |
|
334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
335 | - return $this->_hook_paths; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - |
|
340 | - protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
341 | - { |
|
342 | - $hook_paths = array(); |
|
343 | - if ($hook_files = glob($hook_files_glob_path)) { |
|
344 | - if (empty($hook_files)) { |
|
345 | - return array(); |
|
346 | - } |
|
347 | - foreach ($hook_files as $file) { |
|
348 | - //lets get the linked admin. |
|
349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
350 | - : str_replace($this->_folder_path, '', $file); |
|
351 | - $replace = $extend |
|
352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
353 | - : '_' |
|
354 | - . $this->_file_name |
|
355 | - . '_Hooks.class.php'; |
|
356 | - $rel_admin = str_replace($replace, '', $hook_file); |
|
357 | - $rel_admin = strtolower($rel_admin); |
|
358 | - $hook_paths[] = $file; |
|
359 | - //make sure we haven't already got a hook setup for this page path |
|
360 | - if (in_array($rel_admin, $this->_files_hooked)) { |
|
361 | - continue; |
|
362 | - } |
|
363 | - $this->hook_file = $hook_file; |
|
364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
365 | - $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
366 | - $this->_files_hooked[] = $rel_admin; |
|
367 | - } |
|
368 | - } |
|
369 | - return $hook_paths; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - public function load_admin_hook($registered_pages) |
|
375 | - { |
|
376 | - $this->hook_file; |
|
377 | - $hook_file = (array)$this->hook_file; |
|
378 | - return array_merge($hook_file, $registered_pages); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * _initialize_admin_page |
|
384 | - * |
|
385 | - * @see initialize_admin_page() for info |
|
386 | - */ |
|
387 | - protected function _initialize_admin_page() |
|
388 | - { |
|
389 | - |
|
390 | - //JUST CHECK WE'RE ON RIGHT PAGE. |
|
391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
392 | - return; |
|
393 | - } //not on the right page so let's get out. |
|
394 | - $this->_load_page = true; |
|
395 | - //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
396 | - // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
397 | - //we don't need to do a page_request check here because it's only called via WP menu system. |
|
398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
400 | - $admin_page = apply_filters( |
|
401 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
402 | - $admin_page |
|
403 | - ); |
|
404 | - // define requested admin page class name then load the file and instantiate |
|
405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
406 | - $path_to_file = apply_filters( |
|
407 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
408 | - $path_to_file |
|
409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
410 | - if (is_readable($path_to_file)) { |
|
411 | - // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
412 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
413 | - do_action( |
|
414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
415 | - ); |
|
416 | - require_once($path_to_file); |
|
417 | - $a = new ReflectionClass($admin_page); |
|
418 | - $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
419 | - } |
|
420 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - public function get_admin_page_name() |
|
427 | - { |
|
428 | - return $this->_file_name . '_Admin_Page'; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * @return mixed |
|
435 | - */ |
|
436 | - public function loaded_page_object() |
|
437 | - { |
|
438 | - return $this->_loaded_page_object; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - // public function set_autoloaders( $className ) { |
|
446 | - // $dir_ref = array( |
|
447 | - // $this->_folder_path => array('core','class') |
|
448 | - // ); |
|
449 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
450 | - // } |
|
451 | - /** |
|
452 | - * _check_user_access |
|
453 | - * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
454 | - * WordPress die message. |
|
455 | - * |
|
456 | - * @return bool|die true if pass (or admin) wp_die if fail |
|
457 | - */ |
|
458 | - private function _check_user_access() |
|
459 | - { |
|
460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
461 | - $this->_menu_map->capability, |
|
462 | - $this->_menu_map->menu_slug |
|
463 | - )) { |
|
464 | - wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
465 | - } |
|
466 | - return true; |
|
467 | - } |
|
31 | + //identity properties (set in _set_defaults and _set_init_properties) |
|
32 | + public $label; |
|
33 | + |
|
34 | + /** |
|
35 | + * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
36 | + * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $capability; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * This holds the menu map object for this admin page. |
|
45 | + * |
|
46 | + * @var EE_Admin_Page_Menu_Map |
|
47 | + */ |
|
48 | + protected $_menu_map; |
|
49 | + |
|
50 | + /** |
|
51 | + * deprecated |
|
52 | + */ |
|
53 | + public $menu_label; |
|
54 | + public $menu_slug; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + //set in _set_defaults |
|
59 | + protected $_folder_name; |
|
60 | + protected $_folder_path; |
|
61 | + protected $_file_name; |
|
62 | + public $hook_file; |
|
63 | + protected $_wp_page_slug; |
|
64 | + protected $_routing; |
|
65 | + |
|
66 | + |
|
67 | + //will hold page object. |
|
68 | + protected $_loaded_page_object; |
|
69 | + |
|
70 | + |
|
71 | + //for caf |
|
72 | + protected $_files_hooked; |
|
73 | + protected $_hook_paths; |
|
74 | + |
|
75 | + //load_page? |
|
76 | + private $_load_page; |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @Constructor |
|
82 | + * @access public |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + public function __construct() |
|
86 | + { |
|
87 | + //set global defaults |
|
88 | + $this->_set_defaults(); |
|
89 | + //set properties that are always available with objects. |
|
90 | + $this->_set_init_properties(); |
|
91 | + //global styles/scripts across all wp admin pages |
|
92 | + add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
93 | + //load initial stuff. |
|
94 | + $this->_set_file_and_folder_name(); |
|
95 | + $this->_set_menu_map(); |
|
96 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
97 | + EE_Error::doing_it_wrong( |
|
98 | + get_class($this) . '::$_menu_map', |
|
99 | + sprintf( |
|
100 | + __( |
|
101 | + 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + get_class($this) |
|
105 | + ), |
|
106 | + '4.4.0' |
|
107 | + ); |
|
108 | + return; |
|
109 | + } |
|
110 | + //set default capability |
|
111 | + $this->_set_capability(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * _set_init_properties |
|
118 | + * Child classes use to set the following properties: |
|
119 | + * $label |
|
120 | + * |
|
121 | + * @abstract |
|
122 | + * @access protected |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + abstract protected function _set_init_properties(); |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
131 | + * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
132 | + * |
|
133 | + * @since 4.4.0 |
|
134 | + * @ return void. |
|
135 | + */ |
|
136 | + protected function _set_menu_map() |
|
137 | + { |
|
138 | + return array(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * returns the menu map for this admin page |
|
145 | + * |
|
146 | + * @since 4.4.0 |
|
147 | + * @return EE_Admin_Page_Menu_Map |
|
148 | + */ |
|
149 | + public function get_menu_map() |
|
150 | + { |
|
151 | + return $this->_menu_map; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * This loads scripts and styles for the EE_Admin system |
|
158 | + * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
159 | + * |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + public function load_wp_global_scripts_styles() |
|
163 | + { |
|
164 | + wp_register_style( |
|
165 | + 'espresso_menu', |
|
166 | + EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
167 | + array('dashicons'), |
|
168 | + EVENT_ESPRESSO_VERSION |
|
169 | + ); |
|
170 | + wp_enqueue_style('espresso_menu'); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * this sets default properties (might be overridden in _set_init_properties); |
|
177 | + * |
|
178 | + * @access private |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function _set_defaults() |
|
182 | + { |
|
183 | + $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
184 | + $this->_routing = true; |
|
185 | + $this->_load_page = false; |
|
186 | + $this->_files_hooked = $this->_hook_paths = array(); |
|
187 | + //menu_map |
|
188 | + $this->_menu_map = $this->get_menu_map(); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + protected function _set_capability() |
|
194 | + { |
|
195 | + $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
196 | + $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * initialize_admin_page |
|
203 | + * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
204 | + * EE_Admin_Init class. |
|
205 | + * |
|
206 | + * @access public |
|
207 | + * @uses _initialize_admin_page() |
|
208 | + * @param string $dir_name directory name for specific admin_page being loaded. |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function initialize_admin_page() |
|
212 | + { |
|
213 | + //let's check user access first |
|
214 | + $this->_check_user_access(); |
|
215 | + if (! is_object($this->_loaded_page_object)) { |
|
216 | + return; |
|
217 | + } |
|
218 | + $this->_loaded_page_object->route_admin_request(); |
|
219 | + return; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + public function set_page_dependencies($wp_page_slug) |
|
225 | + { |
|
226 | + if (! $this->_load_page) { |
|
227 | + return; |
|
228 | + } |
|
229 | + if (! is_object($this->_loaded_page_object)) { |
|
230 | + $msg[] = __( |
|
231 | + 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
232 | + 'event_espresso' |
|
233 | + ); |
|
234 | + $msg[] = $msg[0] . "\r\n" . sprintf( |
|
235 | + __( |
|
236 | + 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + $this->_file_name, |
|
240 | + $this->_file_name, |
|
241 | + $this->_folder_path . $this->_file_name, |
|
242 | + $this->_menu_map->menu_slug |
|
243 | + ); |
|
244 | + throw new EE_Error(implode('||', $msg)); |
|
245 | + } |
|
246 | + $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
247 | + $page_hook = 'load-' . $wp_page_slug; |
|
248 | + //hook into page load hook so all page specific stuff get's loaded. |
|
249 | + if (! empty($wp_page_slug)) { |
|
250 | + add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
257 | + * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
258 | + * |
|
259 | + * @return void |
|
260 | + */ |
|
261 | + public function do_initial_loads() |
|
262 | + { |
|
263 | + //no loading or initializing if menu map is setup incorrectly. |
|
264 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
265 | + return; |
|
266 | + } |
|
267 | + $this->_initialize_admin_page(); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * all we're doing here is setting the $_file_name property for later use. |
|
273 | + * |
|
274 | + * @access private |
|
275 | + * @return void |
|
276 | + */ |
|
277 | + private function _set_file_and_folder_name() |
|
278 | + { |
|
279 | + $bt = debug_backtrace(); |
|
280 | + //for more reliable determination of folder name |
|
281 | + //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
282 | + $class = get_class($this); |
|
283 | + foreach ($bt as $index => $values) { |
|
284 | + if (isset($values['class']) && $values['class'] == $class) { |
|
285 | + $file_index = $index - 1; |
|
286 | + $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
287 | + if (! empty($this->_folder_name)) { |
|
288 | + break; |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
293 | + $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
294 | + $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
295 | + $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
301 | + * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
302 | + * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
303 | + * events_Messages_Hooks.class.php |
|
304 | + * |
|
305 | + * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
306 | + * files/classes |
|
307 | + * @return array |
|
308 | + */ |
|
309 | + public function register_hooks($extend = false) |
|
310 | + { |
|
311 | + |
|
312 | + //get a list of files in the directory that have the "Hook" in their name an |
|
313 | + //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
314 | + if ($extend) { |
|
315 | + $hook_files_glob_path = apply_filters( |
|
316 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
317 | + EE_CORE_CAF_ADMIN_EXTEND |
|
318 | + . $this->_folder_name |
|
319 | + . DS |
|
320 | + . '*' |
|
321 | + . $this->_file_name |
|
322 | + . '_Hooks_Extend.class.php' |
|
323 | + ); |
|
324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
325 | + } |
|
326 | + //loop through decaf folders |
|
327 | + $hook_files_glob_path = apply_filters( |
|
328 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
329 | + $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
330 | + ); |
|
331 | + $this->_hook_paths = array_merge( |
|
332 | + $this->_register_hook_files($hook_files_glob_path), |
|
333 | + $this->_hook_paths |
|
334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
335 | + return $this->_hook_paths; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + |
|
340 | + protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
341 | + { |
|
342 | + $hook_paths = array(); |
|
343 | + if ($hook_files = glob($hook_files_glob_path)) { |
|
344 | + if (empty($hook_files)) { |
|
345 | + return array(); |
|
346 | + } |
|
347 | + foreach ($hook_files as $file) { |
|
348 | + //lets get the linked admin. |
|
349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
350 | + : str_replace($this->_folder_path, '', $file); |
|
351 | + $replace = $extend |
|
352 | + ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
353 | + : '_' |
|
354 | + . $this->_file_name |
|
355 | + . '_Hooks.class.php'; |
|
356 | + $rel_admin = str_replace($replace, '', $hook_file); |
|
357 | + $rel_admin = strtolower($rel_admin); |
|
358 | + $hook_paths[] = $file; |
|
359 | + //make sure we haven't already got a hook setup for this page path |
|
360 | + if (in_array($rel_admin, $this->_files_hooked)) { |
|
361 | + continue; |
|
362 | + } |
|
363 | + $this->hook_file = $hook_file; |
|
364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
365 | + $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
366 | + $this->_files_hooked[] = $rel_admin; |
|
367 | + } |
|
368 | + } |
|
369 | + return $hook_paths; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + public function load_admin_hook($registered_pages) |
|
375 | + { |
|
376 | + $this->hook_file; |
|
377 | + $hook_file = (array)$this->hook_file; |
|
378 | + return array_merge($hook_file, $registered_pages); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * _initialize_admin_page |
|
384 | + * |
|
385 | + * @see initialize_admin_page() for info |
|
386 | + */ |
|
387 | + protected function _initialize_admin_page() |
|
388 | + { |
|
389 | + |
|
390 | + //JUST CHECK WE'RE ON RIGHT PAGE. |
|
391 | + if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
392 | + return; |
|
393 | + } //not on the right page so let's get out. |
|
394 | + $this->_load_page = true; |
|
395 | + //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
396 | + // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
397 | + //we don't need to do a page_request check here because it's only called via WP menu system. |
|
398 | + $admin_page = $this->_file_name . '_Admin_Page'; |
|
399 | + $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
400 | + $admin_page = apply_filters( |
|
401 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
402 | + $admin_page |
|
403 | + ); |
|
404 | + // define requested admin page class name then load the file and instantiate |
|
405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
406 | + $path_to_file = apply_filters( |
|
407 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
408 | + $path_to_file |
|
409 | + );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
410 | + if (is_readable($path_to_file)) { |
|
411 | + // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
412 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
413 | + do_action( |
|
414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
415 | + ); |
|
416 | + require_once($path_to_file); |
|
417 | + $a = new ReflectionClass($admin_page); |
|
418 | + $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
419 | + } |
|
420 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + public function get_admin_page_name() |
|
427 | + { |
|
428 | + return $this->_file_name . '_Admin_Page'; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * @return mixed |
|
435 | + */ |
|
436 | + public function loaded_page_object() |
|
437 | + { |
|
438 | + return $this->_loaded_page_object; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + // public function set_autoloaders( $className ) { |
|
446 | + // $dir_ref = array( |
|
447 | + // $this->_folder_path => array('core','class') |
|
448 | + // ); |
|
449 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
450 | + // } |
|
451 | + /** |
|
452 | + * _check_user_access |
|
453 | + * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
454 | + * WordPress die message. |
|
455 | + * |
|
456 | + * @return bool|die true if pass (or admin) wp_die if fail |
|
457 | + */ |
|
458 | + private function _check_user_access() |
|
459 | + { |
|
460 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
461 | + $this->_menu_map->capability, |
|
462 | + $this->_menu_map->menu_slug |
|
463 | + )) { |
|
464 | + wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
465 | + } |
|
466 | + return true; |
|
467 | + } |
|
468 | 468 | |
469 | 469 | } |
470 | 470 | // end of file: includes/core/admin/EE_Admin_Page_Init.core.php |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $this->_set_menu_map(); |
96 | 96 | if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
97 | 97 | EE_Error::doing_it_wrong( |
98 | - get_class($this) . '::$_menu_map', |
|
98 | + get_class($this).'::$_menu_map', |
|
99 | 99 | sprintf( |
100 | 100 | __( |
101 | 101 | 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | { |
164 | 164 | wp_register_style( |
165 | 165 | 'espresso_menu', |
166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
166 | + EE_ADMIN_URL.'assets/admin-menu-styles.css', |
|
167 | 167 | array('dashicons'), |
168 | 168 | EVENT_ESPRESSO_VERSION |
169 | 169 | ); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | protected function _set_capability() |
194 | 194 | { |
195 | 195 | $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
196 | + $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | { |
213 | 213 | //let's check user access first |
214 | 214 | $this->_check_user_access(); |
215 | - if (! is_object($this->_loaded_page_object)) { |
|
215 | + if ( ! is_object($this->_loaded_page_object)) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | $this->_loaded_page_object->route_admin_request(); |
@@ -223,30 +223,30 @@ discard block |
||
223 | 223 | |
224 | 224 | public function set_page_dependencies($wp_page_slug) |
225 | 225 | { |
226 | - if (! $this->_load_page) { |
|
226 | + if ( ! $this->_load_page) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | - if (! is_object($this->_loaded_page_object)) { |
|
229 | + if ( ! is_object($this->_loaded_page_object)) { |
|
230 | 230 | $msg[] = __( |
231 | 231 | 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
232 | 232 | 'event_espresso' |
233 | 233 | ); |
234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
234 | + $msg[] = $msg[0]."\r\n".sprintf( |
|
235 | 235 | __( |
236 | 236 | 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
237 | 237 | 'event_espresso' |
238 | 238 | ), |
239 | 239 | $this->_file_name, |
240 | 240 | $this->_file_name, |
241 | - $this->_folder_path . $this->_file_name, |
|
241 | + $this->_folder_path.$this->_file_name, |
|
242 | 242 | $this->_menu_map->menu_slug |
243 | 243 | ); |
244 | 244 | throw new EE_Error(implode('||', $msg)); |
245 | 245 | } |
246 | 246 | $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
247 | - $page_hook = 'load-' . $wp_page_slug; |
|
247 | + $page_hook = 'load-'.$wp_page_slug; |
|
248 | 248 | //hook into page load hook so all page specific stuff get's loaded. |
249 | - if (! empty($wp_page_slug)) { |
|
249 | + if ( ! empty($wp_page_slug)) { |
|
250 | 250 | add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
251 | 251 | } |
252 | 252 | } |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | if (isset($values['class']) && $values['class'] == $class) { |
285 | 285 | $file_index = $index - 1; |
286 | 286 | $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
287 | - if (! empty($this->_folder_name)) { |
|
287 | + if ( ! empty($this->_folder_name)) { |
|
288 | 288 | break; |
289 | 289 | } |
290 | 290 | } |
291 | 291 | } |
292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
292 | + $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.DS; |
|
293 | 293 | $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
294 | 294 | $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
295 | 295 | $this->_file_name = str_replace(' ', '_', $this->_file_name); |
@@ -321,17 +321,17 @@ discard block |
||
321 | 321 | . $this->_file_name |
322 | 322 | . '_Hooks_Extend.class.php' |
323 | 323 | ); |
324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
325 | 325 | } |
326 | 326 | //loop through decaf folders |
327 | 327 | $hook_files_glob_path = apply_filters( |
328 | 328 | 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
329 | + $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php' |
|
330 | 330 | ); |
331 | - $this->_hook_paths = array_merge( |
|
331 | + $this->_hook_paths = array_merge( |
|
332 | 332 | $this->_register_hook_files($hook_files_glob_path), |
333 | 333 | $this->_hook_paths |
334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
335 | 335 | return $this->_hook_paths; |
336 | 336 | } |
337 | 337 | |
@@ -346,10 +346,10 @@ discard block |
||
346 | 346 | } |
347 | 347 | foreach ($hook_files as $file) { |
348 | 348 | //lets get the linked admin. |
349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.DS, '', $file) |
|
350 | 350 | : str_replace($this->_folder_path, '', $file); |
351 | 351 | $replace = $extend |
352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
352 | + ? '_'.$this->_file_name.'_Hooks_Extend.class.php' |
|
353 | 353 | : '_' |
354 | 354 | . $this->_file_name |
355 | 355 | . '_Hooks.class.php'; |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | continue; |
362 | 362 | } |
363 | 363 | $this->hook_file = $hook_file; |
364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin; |
|
365 | 365 | $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
366 | 366 | $this->_files_hooked[] = $rel_admin; |
367 | 367 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | public function load_admin_hook($registered_pages) |
375 | 375 | { |
376 | 376 | $this->hook_file; |
377 | - $hook_file = (array)$this->hook_file; |
|
377 | + $hook_file = (array) $this->hook_file; |
|
378 | 378 | return array_merge($hook_file, $registered_pages); |
379 | 379 | } |
380 | 380 | |
@@ -388,44 +388,44 @@ discard block |
||
388 | 388 | { |
389 | 389 | |
390 | 390 | //JUST CHECK WE'RE ON RIGHT PAGE. |
391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
391 | + if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
392 | 392 | return; |
393 | 393 | } //not on the right page so let's get out. |
394 | 394 | $this->_load_page = true; |
395 | 395 | //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
396 | 396 | // spl_autoload_register(array( $this, 'set_autoloaders') ); |
397 | 397 | //we don't need to do a page_request check here because it's only called via WP menu system. |
398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
398 | + $admin_page = $this->_file_name.'_Admin_Page'; |
|
399 | + $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page; |
|
400 | 400 | $admin_page = apply_filters( |
401 | 401 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
402 | 402 | $admin_page |
403 | 403 | ); |
404 | 404 | // define requested admin page class name then load the file and instantiate |
405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path.$admin_page.'.core.php'); |
|
406 | 406 | $path_to_file = apply_filters( |
407 | 407 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
408 | 408 | $path_to_file |
409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
409 | + ); //so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
410 | 410 | if (is_readable($path_to_file)) { |
411 | 411 | // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
412 | 412 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
413 | 413 | do_action( |
414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug |
|
415 | 415 | ); |
416 | 416 | require_once($path_to_file); |
417 | 417 | $a = new ReflectionClass($admin_page); |
418 | 418 | $this->_loaded_page_object = $a->newInstance($this->_routing); |
419 | 419 | } |
420 | 420 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
425 | 425 | |
426 | 426 | public function get_admin_page_name() |
427 | 427 | { |
428 | - return $this->_file_name . '_Admin_Page'; |
|
428 | + return $this->_file_name.'_Admin_Page'; |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | */ |
458 | 458 | private function _check_user_access() |
459 | 459 | { |
460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
460 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
461 | 461 | $this->_menu_map->capability, |
462 | 462 | $this->_menu_map->menu_slug |
463 | 463 | )) { |
@@ -1,6 +1,6 @@ discard block |
||
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 | |
@@ -26,750 +26,750 @@ discard block |
||
26 | 26 | class EE_Admin_Page_Loader |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * _installed_pages |
|
31 | - * objects for page_init objects detected and loaded |
|
32 | - * |
|
33 | - * @access private |
|
34 | - * @var \EE_Admin_Page_Init[] |
|
35 | - */ |
|
36 | - private $_installed_pages = array(); |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * this is used to hold the registry of menu slugs for all the installed admin pages |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private $_menu_slugs = array(); |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * _caffeinated_extends |
|
50 | - * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
51 | - * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - private $_caffeinated_extends = array(); |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * _current_caf_extend_slug |
|
61 | - * This property is used for holding the page slug that is required for referencing the correct |
|
62 | - * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
63 | - * |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - private $_current_caf_extend_slug; |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * _caf_autoloader |
|
72 | - * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the |
|
73 | - * caffeinated/new directory. This array is then used to setup a corresponding dynamic autoloader for these pages |
|
74 | - * classes. |
|
75 | - * |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - // private $_caf_autoloader = array(); |
|
79 | - /** |
|
80 | - * _prepped_menu_maps |
|
81 | - * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
82 | - * |
|
83 | - * @since 4.4.0 |
|
84 | - * @var EE_Admin_Page_Menu_Map[] |
|
85 | - */ |
|
86 | - private $_prepped_menu_maps = array(); |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * _admin_menu_groups |
|
92 | - * array that holds the group headings and details for |
|
93 | - * |
|
94 | - * @access private |
|
95 | - * @var array |
|
96 | - */ |
|
97 | - private $_admin_menu_groups = array(); |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
103 | - * pages. |
|
104 | - * |
|
105 | - * @var string |
|
106 | - */ |
|
107 | - public $hook_file; |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * constructor |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @return \EE_Admin_Page_Loader |
|
116 | - */ |
|
117 | - public function __construct() |
|
118 | - { |
|
119 | - //load menu_map classes |
|
120 | - EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
121 | - //define the default "groups" for the admin_pages |
|
122 | - $this->_set_menu_groups(); |
|
123 | - //let's set default autoloaders. Note that this just sets autoloaders for root admin files. |
|
124 | - // spl_autoload_register( array( $this, 'init_autoloaders') ); |
|
125 | - //let's do a scan and see what installed pages we have |
|
126 | - $this->_get_installed_pages(); |
|
127 | - //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
128 | - add_action('admin_menu', array($this, 'set_menus')); |
|
129 | - add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
136 | - * files in the caffeinated folder. |
|
137 | - * |
|
138 | - * @access private |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - private function _define_caffeinated_constants() |
|
142 | - { |
|
143 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
145 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
146 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
147 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
148 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
149 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * _set_menu_groups |
|
157 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
158 | - * |
|
159 | - * @access private |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - private function _set_menu_groups() |
|
163 | - { |
|
164 | - |
|
165 | - //set array of EE_Admin_Page_Menu_Group objects |
|
166 | - $groups = array( |
|
167 | - 'main' => new EE_Admin_Page_Menu_Group( |
|
168 | - array( |
|
169 | - 'menu_label' => __('Main', 'event_espresso'), |
|
170 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
171 | - 'menu_slug' => 'main', |
|
172 | - 'capability' => 'ee_read_ee', |
|
173 | - 'menu_order' => 0, |
|
174 | - 'parent_slug' => 'espresso_events', |
|
175 | - ) |
|
176 | - ), |
|
177 | - 'management' => new EE_Admin_Page_Menu_Group( |
|
178 | - array( |
|
179 | - 'menu_label' => __('Management', 'event_espresso'), |
|
180 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
181 | - 'menu_slug' => 'management', |
|
182 | - 'capability' => 'ee_read_ee', |
|
183 | - 'menu_order' => 10, |
|
184 | - 'parent_slug' => 'espresso_events', |
|
185 | - ) |
|
186 | - ), |
|
187 | - 'settings' => new EE_Admin_Page_Menu_Group( |
|
188 | - array( |
|
189 | - 'menu_label' => __('Settings', 'event_espresso'), |
|
190 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
191 | - 'menu_slug' => 'settings', |
|
192 | - 'capability' => 'ee_read_ee', |
|
193 | - 'menu_order' => 30, |
|
194 | - 'parent_slug' => 'espresso_events', |
|
195 | - ) |
|
196 | - ), |
|
197 | - 'templates' => new EE_Admin_Page_Menu_Group( |
|
198 | - array( |
|
199 | - 'menu_label' => __('Templates', 'event_espresso'), |
|
200 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
201 | - 'menu_slug' => 'templates', |
|
202 | - 'capability' => 'ee_read_ee', |
|
203 | - 'menu_order' => 40, |
|
204 | - 'parent_slug' => 'espresso_events', |
|
205 | - ) |
|
206 | - ), |
|
207 | - 'extras' => new EE_Admin_Page_Menu_Group( |
|
208 | - array( |
|
209 | - 'menu_label' => __('Extras', 'event_espresso'), |
|
210 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
211 | - 'menu_slug' => 'extras', |
|
212 | - 'capability' => 'ee_read_ee', |
|
213 | - 'menu_order' => 50, |
|
214 | - 'parent_slug' => 'espresso_events', |
|
215 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
216 | - ) |
|
217 | - ), |
|
218 | - 'tools' => new EE_Admin_Page_Menu_Group( |
|
219 | - array( |
|
220 | - 'menu_label' => __("Tools", "event_espresso"), |
|
221 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
222 | - 'menu_slug' => 'tools', |
|
223 | - 'capability' => 'ee_read_ee', |
|
224 | - 'menu_order' => 60, |
|
225 | - 'parent_slug' => 'espresso_events', |
|
226 | - ) |
|
227 | - ), |
|
228 | - 'addons' => new EE_Admin_Page_Menu_Group( |
|
229 | - array( |
|
230 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
231 | - 'menu_label' => __('Add-ons', 'event_espresso'), |
|
232 | - 'menu_slug' => 'addons', |
|
233 | - 'capability' => 'ee_read_ee', |
|
234 | - 'menu_order' => 20, |
|
235 | - 'parent_slug' => 'espresso_events', |
|
236 | - ) |
|
237 | - ), |
|
238 | - ); |
|
239 | - $this->_admin_menu_groups = apply_filters( |
|
240 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
241 | - $groups |
|
242 | - ); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
249 | - * slug. The other utility with this function is it validates that all the groups are instances of |
|
250 | - * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
251 | - * |
|
252 | - * @since 4.4.0 |
|
253 | - * @throws \EE_Error |
|
254 | - * @return EE_Admin_Page_Menu_Group[] |
|
255 | - */ |
|
256 | - private function _rearrange_menu_groups() |
|
257 | - { |
|
258 | - $groups = array(); |
|
259 | - //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
260 | - usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
261 | - foreach ($this->_admin_menu_groups as $group) { |
|
262 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
263 | - throw new EE_Error( |
|
264 | - sprintf( |
|
265 | - __( |
|
266 | - 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
267 | - 'event_espresso' |
|
268 | - ), |
|
269 | - print_r($group, true) |
|
270 | - ) |
|
271 | - ); |
|
272 | - } |
|
273 | - $groups[$group->menu_slug] = $group; |
|
274 | - } |
|
275 | - return $groups; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * _get_installed_pages |
|
282 | - * This just gets the list of installed EE_Admin_pages. |
|
283 | - * |
|
284 | - * @access private |
|
285 | - * @throws EE_Error |
|
286 | - * @return void |
|
287 | - */ |
|
288 | - private function _get_installed_pages() |
|
289 | - { |
|
290 | - $installed_refs = array(); |
|
291 | - $exclude = array('assets', 'templates'); |
|
292 | - // grab everything in the admin core directory |
|
293 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
294 | - if ($admin_screens) { |
|
295 | - foreach ($admin_screens as $admin_screen) { |
|
296 | - // files and anything in the exclude array need not apply |
|
297 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
298 | - // these folders represent the different EE admin pages |
|
299 | - $installed_refs[basename($admin_screen)] = $admin_screen; |
|
300 | - } |
|
301 | - } |
|
302 | - } |
|
303 | - if (empty($installed_refs)) { |
|
304 | - $error_msg[] = __( |
|
305 | - 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
306 | - 'event_espresso' |
|
307 | - ); |
|
308 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
309 | - __( |
|
310 | - 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
311 | - 'event_espresso' |
|
312 | - ), |
|
313 | - EE_ADMIN_PAGES |
|
314 | - ); |
|
315 | - throw new EE_Error(implode('||', $error_msg)); |
|
316 | - } |
|
317 | - //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
318 | - $installed_refs = $this->_set_caffeinated($installed_refs); |
|
319 | - //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
320 | - $installed_refs = apply_filters( |
|
321 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
322 | - $installed_refs |
|
323 | - ); |
|
324 | - $this->_caffeinated_extends = apply_filters( |
|
325 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
326 | - $this->_caffeinated_extends |
|
327 | - ); |
|
328 | - //loop through admin pages and setup the $_installed_pages array. |
|
329 | - $hooks_ref = array(); |
|
330 | - foreach ($installed_refs as $page => $path) { |
|
331 | - // set autoloaders for our admin page classes based on included path information |
|
332 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
333 | - // build list of installed pages |
|
334 | - $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
335 | - // verify returned object |
|
336 | - if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
337 | - if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
338 | - continue; |
|
339 | - } |
|
340 | - //skip if in full maintenance mode and maintenance_mode_parent is set |
|
341 | - $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
342 | - if (empty($maintenance_mode_parent) |
|
343 | - && EE_Maintenance_Mode::instance()->level() |
|
344 | - == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
345 | - unset($installed_refs[$page]); |
|
346 | - continue; |
|
347 | - } |
|
348 | - $this->_menu_slugs[$this->_installed_pages[$page]->get_menu_map()->menu_slug] = $page; |
|
349 | - //flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
350 | - $extend = false; |
|
351 | - //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
352 | - if (isset($this->_caffeinated_extends[$page])) { |
|
353 | - $this->_current_caf_extend_slug = $page; |
|
354 | - $path_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__' |
|
355 | - . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
356 | - . '_' |
|
357 | - . $this->_installed_pages[$page]->get_admin_page_name(); |
|
358 | - $path_runtime = 'return "' |
|
359 | - . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"] |
|
360 | - . '";'; |
|
361 | - $page_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__' |
|
362 | - . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
363 | - . '_' |
|
364 | - . $this->_installed_pages[$page]->get_admin_page_name(); |
|
365 | - $page_runtime = 'return "' |
|
366 | - . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"] |
|
367 | - . '";'; |
|
368 | - $hook_function_path = create_function('$path_to_file', $path_runtime); |
|
369 | - $hook_function_page = create_function('$admin_page', $page_runtime); |
|
370 | - add_filter($path_hook, $hook_function_path); |
|
371 | - add_filter($page_hook, $hook_function_page); |
|
372 | - $extend = true; |
|
373 | - } |
|
374 | - //let's do the registered hooks |
|
375 | - $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
376 | - $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
377 | - } |
|
378 | - } |
|
379 | - //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
380 | - //first make sure we've got unique values |
|
381 | - $hooks_ref = array_unique($hooks_ref); |
|
382 | - //now let's loop and require! |
|
383 | - foreach ($hooks_ref as $path) { |
|
384 | - require_once($path); |
|
385 | - } |
|
386 | - //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
387 | - global $ee_menu_slugs; |
|
388 | - $ee_menu_slugs = $this->_menu_slugs; |
|
389 | - //we need to loop again to run any early code |
|
390 | - foreach ($installed_refs as $page => $path) { |
|
391 | - if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
392 | - $this->_installed_pages[$page]->do_initial_loads(); |
|
393 | - } |
|
394 | - } |
|
395 | - do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * get_admin_page_object |
|
402 | - * |
|
403 | - * @param string $page_slug |
|
404 | - * @return EE_Admin_Page |
|
405 | - */ |
|
406 | - public function get_admin_page_object($page_slug = '') |
|
407 | - { |
|
408 | - if (isset($this->_installed_pages[$page_slug])) { |
|
409 | - return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
410 | - } |
|
411 | - return null; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * _get_classname_for_admin_page |
|
418 | - * generates an "Admin Page" class based on the directory name |
|
419 | - * |
|
420 | - * @param $dir_name |
|
421 | - * @return string |
|
422 | - */ |
|
423 | - private function _get_classname_for_admin_page($dir_name = '') |
|
424 | - { |
|
425 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
426 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * _get_classname_for_admin_init_page |
|
433 | - * generates an "Admin Page Init" class based on the directory name |
|
434 | - * |
|
435 | - * @param $dir_name |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - private function _get_classname_for_admin_init_page($dir_name = '') |
|
439 | - { |
|
440 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
441 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * _load_admin_page |
|
448 | - * Loads and instantiates page_init object for a single EE_admin page. |
|
449 | - * |
|
450 | - * @param string $page page_reference |
|
451 | - * @param string $path |
|
452 | - * @throws EE_Error |
|
453 | - * @return object|bool return page object if valid, bool false if not. |
|
454 | - */ |
|
455 | - private function _load_admin_page($page = '', $path = '') |
|
456 | - { |
|
457 | - $class_name = $this->_get_classname_for_admin_init_page($page); |
|
458 | - EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
459 | - if (! class_exists($class_name)) { |
|
460 | - $inner_error_msg = '<br />' . sprintf( |
|
461 | - esc_html__( |
|
462 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
463 | - 'event_espresso' |
|
464 | - ), |
|
465 | - '<strong>' . $class_name . '</strong>' |
|
466 | - ); |
|
467 | - $error_msg[] = sprintf( |
|
468 | - __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
469 | - $page |
|
470 | - ); |
|
471 | - $error_msg[] = $error_msg[0] |
|
472 | - . "\r\n" |
|
473 | - . sprintf( |
|
474 | - esc_html__( |
|
475 | - 'There is no Init class in place for the %s admin page.', |
|
476 | - 'event_espresso' |
|
477 | - ), |
|
478 | - $page |
|
479 | - ) |
|
480 | - . $inner_error_msg; |
|
481 | - throw new EE_Error(implode('||', $error_msg)); |
|
482 | - } |
|
483 | - $a = new ReflectionClass($class_name); |
|
484 | - return $a->newInstance(); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * set_menus |
|
491 | - * This method sets up the menus for EE Admin Pages |
|
492 | - * |
|
493 | - * @access private |
|
494 | - * @return void |
|
495 | - */ |
|
496 | - public function set_menus() |
|
497 | - { |
|
498 | - //prep the menu pages (sort, group.) |
|
499 | - $this->_prep_pages(); |
|
500 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
501 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
502 | - $menu_map->add_menu_page(false); |
|
503 | - } |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * set_network_menus |
|
510 | - * This method sets up the menus for network EE Admin Pages. |
|
511 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
512 | - * are only added to the menu map if they are intended for the admin menu |
|
513 | - * |
|
514 | - * @return void |
|
515 | - */ |
|
516 | - public function set_network_menus() |
|
517 | - { |
|
518 | - $this->_prep_pages(); |
|
519 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
520 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
521 | - $menu_map->add_menu_page(true); |
|
522 | - } |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * _prep_pages |
|
530 | - * sets the _prepped_menu_maps property |
|
531 | - * |
|
532 | - * @access private |
|
533 | - * @throws EE_Error |
|
534 | - * @return void |
|
535 | - */ |
|
536 | - private function _prep_pages() |
|
537 | - { |
|
538 | - $pages_array = array(); |
|
539 | - //rearrange _admin_menu_groups to be indexed by group slug. |
|
540 | - $menu_groups = $this->_rearrange_menu_groups(); |
|
541 | - foreach ($this->_installed_pages as $page) { |
|
542 | - if ($page instanceof EE_Admin_page_Init) { |
|
543 | - $page_map = $page->get_menu_map(); |
|
544 | - //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
545 | - if (is_array($page_map) || empty($page_map)) { |
|
546 | - EE_Error::add_persistent_admin_notice( |
|
547 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
548 | - sprintf( |
|
549 | - __( |
|
550 | - 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
551 | - 'event_espresso' |
|
552 | - ), |
|
553 | - $page->label |
|
554 | - ) |
|
555 | - ); |
|
556 | - continue; |
|
557 | - } |
|
558 | - //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
559 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
560 | - throw new EE_Error( |
|
561 | - sprintf( |
|
562 | - __( |
|
563 | - 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
564 | - 'event_espresso' |
|
565 | - ), |
|
566 | - $page->label, |
|
567 | - $page_map |
|
568 | - ) |
|
569 | - ); |
|
570 | - } |
|
571 | - //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
572 | - if (empty($page_map->maintenance_mode_parent) |
|
573 | - && EE_Maintenance_Mode::instance()->level() |
|
574 | - == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
575 | - continue; |
|
576 | - } |
|
577 | - //assign to group (remember $page_map has the admin page stored in it). |
|
578 | - $pages_array[$page_map->menu_group][] = $page_map; |
|
579 | - } |
|
580 | - } |
|
581 | - if (empty($pages_array)) { |
|
582 | - throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
583 | - } |
|
584 | - //let's sort the groups, make sure it's a valid group, add header (if to show). |
|
585 | - foreach ($pages_array as $group => $menu_maps) { |
|
586 | - //valid_group? |
|
587 | - if (! array_key_exists($group, $menu_groups)) { |
|
588 | - continue; |
|
589 | - } |
|
590 | - //sort pages. |
|
591 | - usort($menu_maps, array($this, '_sort_menu_maps')); |
|
592 | - //prepend header |
|
593 | - array_unshift($menu_maps, $menu_groups[$group]); |
|
594 | - //reset $pages_array with prepped data |
|
595 | - $pages_array[$group] = $menu_maps; |
|
596 | - } |
|
597 | - //now let's setup the _prepped_menu_maps property |
|
598 | - foreach ($menu_groups as $group => $group_objs) { |
|
599 | - if (isset($pages_array[$group])) { |
|
600 | - $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
601 | - } |
|
602 | - }/**/ |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
609 | - * In this method there are three checks being done: |
|
610 | - * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
611 | - * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
612 | - * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
613 | - * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
614 | - * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
615 | - * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
616 | - * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
617 | - * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
618 | - * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
619 | - * admin_pages) |
|
620 | - * |
|
621 | - * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
622 | - * loaded. |
|
623 | - * @return array |
|
624 | - */ |
|
625 | - private function _set_caffeinated($installed_refs) |
|
626 | - { |
|
627 | - |
|
628 | - //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
629 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
630 | - return $installed_refs; |
|
631 | - } |
|
632 | - $this->_define_caffeinated_constants(); |
|
633 | - $exclude = array('tickets'); |
|
634 | - //okay let's setup an "New" pages first (we'll return installed refs later) |
|
635 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
636 | - if ($new_admin_screens) { |
|
637 | - foreach ($new_admin_screens as $admin_screen) { |
|
638 | - // files and anything in the exclude array need not apply |
|
639 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
640 | - // these folders represent the different NEW EE admin pages |
|
641 | - $installed_refs[basename($admin_screen)] = $admin_screen; |
|
642 | - // set autoloaders for our admin page classes based on included path information |
|
643 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
644 | - // $this->_caf_autoloader[] = array( |
|
645 | - // 'dir' => 'new', |
|
646 | - // 'folder' => basename( $admin_screen ) |
|
647 | - // ); |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
652 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
653 | - if ($extends) { |
|
654 | - foreach ($extends as $extend) { |
|
655 | - if (is_dir($extend)) { |
|
656 | - $extend_ref = basename($extend); |
|
657 | - //now let's make sure there is a file that matches the expected format |
|
658 | - $filename = str_replace( |
|
659 | - ' ', |
|
660 | - '_', |
|
661 | - ucwords( |
|
662 | - str_replace( |
|
663 | - '_', |
|
664 | - ' ', |
|
665 | - $extend_ref |
|
666 | - ) |
|
667 | - ) |
|
668 | - ); |
|
669 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
670 | - $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
671 | - array('\\', '/'), |
|
672 | - DS, |
|
673 | - EE_CORE_CAF_ADMIN |
|
674 | - . 'extend' |
|
675 | - . DS |
|
676 | - . $extend_ref |
|
677 | - . DS |
|
678 | - . $filename |
|
679 | - . '.core.php' |
|
680 | - ); |
|
681 | - $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
682 | - // set autoloaders for our admin page classes based on included path information |
|
683 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
684 | - // $this->_caf_autoloader[] = array( |
|
685 | - // 'dir' => 'extend', |
|
686 | - // 'folder' => $extend_ref |
|
687 | - // ); |
|
688 | - } |
|
689 | - } |
|
690 | - } |
|
691 | - //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
692 | - $ee_admin_hooks = array(); |
|
693 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
694 | - if ($hooks) { |
|
695 | - foreach ($hooks as $hook) { |
|
696 | - if (is_readable($hook)) { |
|
697 | - require_once $hook; |
|
698 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
699 | - $classname = str_replace('.class.php', '', $classname); |
|
700 | - if (class_exists($classname)) { |
|
701 | - $a = new ReflectionClass($classname); |
|
702 | - $ee_admin_hooks[] = $a->newInstance(); |
|
703 | - } |
|
704 | - } |
|
705 | - } |
|
706 | - }/**/ |
|
707 | - $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
708 | - return $installed_refs; |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * Initial autoloader registration |
|
717 | - * This just sets up the autoloader for the root admin files |
|
718 | - * |
|
719 | - * @param string $className incoming classname to check for autoload |
|
720 | - * @return void |
|
721 | - */ |
|
722 | - // public function init_autoloaders( $className ) { |
|
723 | - // $dir_ref = array( |
|
724 | - // EE_ADMIN => array('core', 'class') |
|
725 | - // ); |
|
726 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
727 | - // } |
|
728 | - /** |
|
729 | - * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the |
|
730 | - * caffeinated folders. |
|
731 | - * |
|
732 | - * @access public |
|
733 | - * @param string $className in coming classname being called |
|
734 | - * @return void |
|
735 | - */ |
|
736 | - // public function caffeinated_autoloaders( $className ) { |
|
737 | - // //let's setup an array of paths to check (for each subsystem) |
|
738 | - // $dir_ref = array(); |
|
739 | - // foreach ( $this->_caf_autoloader as $pathinfo) { |
|
740 | - // $dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class'); |
|
741 | - // } |
|
742 | - // |
|
743 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
744 | - // } |
|
745 | - /** |
|
746 | - * Utility method for sorting the _menu_maps (callback for usort php function) |
|
747 | - * |
|
748 | - * @since 4.4.0 |
|
749 | - * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
750 | - * @param EE_Admin_Page_Menu_Map $b being compared to |
|
751 | - * @return int sort order |
|
752 | - */ |
|
753 | - private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
754 | - { |
|
755 | - if ($a->menu_order == $b->menu_order) { |
|
756 | - return 0; |
|
757 | - } |
|
758 | - return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * _default_header_link |
|
765 | - * This is just a dummy method to use with header submenu items |
|
766 | - * |
|
767 | - * @return bool false |
|
768 | - */ |
|
769 | - public function _default_header_link() |
|
770 | - { |
|
771 | - return false; |
|
772 | - } |
|
29 | + /** |
|
30 | + * _installed_pages |
|
31 | + * objects for page_init objects detected and loaded |
|
32 | + * |
|
33 | + * @access private |
|
34 | + * @var \EE_Admin_Page_Init[] |
|
35 | + */ |
|
36 | + private $_installed_pages = array(); |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * this is used to hold the registry of menu slugs for all the installed admin pages |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private $_menu_slugs = array(); |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * _caffeinated_extends |
|
50 | + * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
51 | + * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + private $_caffeinated_extends = array(); |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * _current_caf_extend_slug |
|
61 | + * This property is used for holding the page slug that is required for referencing the correct |
|
62 | + * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
63 | + * |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + private $_current_caf_extend_slug; |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * _caf_autoloader |
|
72 | + * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the |
|
73 | + * caffeinated/new directory. This array is then used to setup a corresponding dynamic autoloader for these pages |
|
74 | + * classes. |
|
75 | + * |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + // private $_caf_autoloader = array(); |
|
79 | + /** |
|
80 | + * _prepped_menu_maps |
|
81 | + * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
82 | + * |
|
83 | + * @since 4.4.0 |
|
84 | + * @var EE_Admin_Page_Menu_Map[] |
|
85 | + */ |
|
86 | + private $_prepped_menu_maps = array(); |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * _admin_menu_groups |
|
92 | + * array that holds the group headings and details for |
|
93 | + * |
|
94 | + * @access private |
|
95 | + * @var array |
|
96 | + */ |
|
97 | + private $_admin_menu_groups = array(); |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
103 | + * pages. |
|
104 | + * |
|
105 | + * @var string |
|
106 | + */ |
|
107 | + public $hook_file; |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * constructor |
|
113 | + * |
|
114 | + * @access public |
|
115 | + * @return \EE_Admin_Page_Loader |
|
116 | + */ |
|
117 | + public function __construct() |
|
118 | + { |
|
119 | + //load menu_map classes |
|
120 | + EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
121 | + //define the default "groups" for the admin_pages |
|
122 | + $this->_set_menu_groups(); |
|
123 | + //let's set default autoloaders. Note that this just sets autoloaders for root admin files. |
|
124 | + // spl_autoload_register( array( $this, 'init_autoloaders') ); |
|
125 | + //let's do a scan and see what installed pages we have |
|
126 | + $this->_get_installed_pages(); |
|
127 | + //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
128 | + add_action('admin_menu', array($this, 'set_menus')); |
|
129 | + add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
136 | + * files in the caffeinated folder. |
|
137 | + * |
|
138 | + * @access private |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + private function _define_caffeinated_constants() |
|
142 | + { |
|
143 | + if (! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
145 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
146 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
147 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
148 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
149 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * _set_menu_groups |
|
157 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
158 | + * |
|
159 | + * @access private |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + private function _set_menu_groups() |
|
163 | + { |
|
164 | + |
|
165 | + //set array of EE_Admin_Page_Menu_Group objects |
|
166 | + $groups = array( |
|
167 | + 'main' => new EE_Admin_Page_Menu_Group( |
|
168 | + array( |
|
169 | + 'menu_label' => __('Main', 'event_espresso'), |
|
170 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
171 | + 'menu_slug' => 'main', |
|
172 | + 'capability' => 'ee_read_ee', |
|
173 | + 'menu_order' => 0, |
|
174 | + 'parent_slug' => 'espresso_events', |
|
175 | + ) |
|
176 | + ), |
|
177 | + 'management' => new EE_Admin_Page_Menu_Group( |
|
178 | + array( |
|
179 | + 'menu_label' => __('Management', 'event_espresso'), |
|
180 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
181 | + 'menu_slug' => 'management', |
|
182 | + 'capability' => 'ee_read_ee', |
|
183 | + 'menu_order' => 10, |
|
184 | + 'parent_slug' => 'espresso_events', |
|
185 | + ) |
|
186 | + ), |
|
187 | + 'settings' => new EE_Admin_Page_Menu_Group( |
|
188 | + array( |
|
189 | + 'menu_label' => __('Settings', 'event_espresso'), |
|
190 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
191 | + 'menu_slug' => 'settings', |
|
192 | + 'capability' => 'ee_read_ee', |
|
193 | + 'menu_order' => 30, |
|
194 | + 'parent_slug' => 'espresso_events', |
|
195 | + ) |
|
196 | + ), |
|
197 | + 'templates' => new EE_Admin_Page_Menu_Group( |
|
198 | + array( |
|
199 | + 'menu_label' => __('Templates', 'event_espresso'), |
|
200 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
201 | + 'menu_slug' => 'templates', |
|
202 | + 'capability' => 'ee_read_ee', |
|
203 | + 'menu_order' => 40, |
|
204 | + 'parent_slug' => 'espresso_events', |
|
205 | + ) |
|
206 | + ), |
|
207 | + 'extras' => new EE_Admin_Page_Menu_Group( |
|
208 | + array( |
|
209 | + 'menu_label' => __('Extras', 'event_espresso'), |
|
210 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
211 | + 'menu_slug' => 'extras', |
|
212 | + 'capability' => 'ee_read_ee', |
|
213 | + 'menu_order' => 50, |
|
214 | + 'parent_slug' => 'espresso_events', |
|
215 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
216 | + ) |
|
217 | + ), |
|
218 | + 'tools' => new EE_Admin_Page_Menu_Group( |
|
219 | + array( |
|
220 | + 'menu_label' => __("Tools", "event_espresso"), |
|
221 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
222 | + 'menu_slug' => 'tools', |
|
223 | + 'capability' => 'ee_read_ee', |
|
224 | + 'menu_order' => 60, |
|
225 | + 'parent_slug' => 'espresso_events', |
|
226 | + ) |
|
227 | + ), |
|
228 | + 'addons' => new EE_Admin_Page_Menu_Group( |
|
229 | + array( |
|
230 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
231 | + 'menu_label' => __('Add-ons', 'event_espresso'), |
|
232 | + 'menu_slug' => 'addons', |
|
233 | + 'capability' => 'ee_read_ee', |
|
234 | + 'menu_order' => 20, |
|
235 | + 'parent_slug' => 'espresso_events', |
|
236 | + ) |
|
237 | + ), |
|
238 | + ); |
|
239 | + $this->_admin_menu_groups = apply_filters( |
|
240 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
241 | + $groups |
|
242 | + ); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
249 | + * slug. The other utility with this function is it validates that all the groups are instances of |
|
250 | + * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
251 | + * |
|
252 | + * @since 4.4.0 |
|
253 | + * @throws \EE_Error |
|
254 | + * @return EE_Admin_Page_Menu_Group[] |
|
255 | + */ |
|
256 | + private function _rearrange_menu_groups() |
|
257 | + { |
|
258 | + $groups = array(); |
|
259 | + //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
260 | + usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
261 | + foreach ($this->_admin_menu_groups as $group) { |
|
262 | + if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
263 | + throw new EE_Error( |
|
264 | + sprintf( |
|
265 | + __( |
|
266 | + 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
267 | + 'event_espresso' |
|
268 | + ), |
|
269 | + print_r($group, true) |
|
270 | + ) |
|
271 | + ); |
|
272 | + } |
|
273 | + $groups[$group->menu_slug] = $group; |
|
274 | + } |
|
275 | + return $groups; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * _get_installed_pages |
|
282 | + * This just gets the list of installed EE_Admin_pages. |
|
283 | + * |
|
284 | + * @access private |
|
285 | + * @throws EE_Error |
|
286 | + * @return void |
|
287 | + */ |
|
288 | + private function _get_installed_pages() |
|
289 | + { |
|
290 | + $installed_refs = array(); |
|
291 | + $exclude = array('assets', 'templates'); |
|
292 | + // grab everything in the admin core directory |
|
293 | + $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
294 | + if ($admin_screens) { |
|
295 | + foreach ($admin_screens as $admin_screen) { |
|
296 | + // files and anything in the exclude array need not apply |
|
297 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
298 | + // these folders represent the different EE admin pages |
|
299 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
300 | + } |
|
301 | + } |
|
302 | + } |
|
303 | + if (empty($installed_refs)) { |
|
304 | + $error_msg[] = __( |
|
305 | + 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
306 | + 'event_espresso' |
|
307 | + ); |
|
308 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
309 | + __( |
|
310 | + 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
311 | + 'event_espresso' |
|
312 | + ), |
|
313 | + EE_ADMIN_PAGES |
|
314 | + ); |
|
315 | + throw new EE_Error(implode('||', $error_msg)); |
|
316 | + } |
|
317 | + //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
318 | + $installed_refs = $this->_set_caffeinated($installed_refs); |
|
319 | + //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
320 | + $installed_refs = apply_filters( |
|
321 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
322 | + $installed_refs |
|
323 | + ); |
|
324 | + $this->_caffeinated_extends = apply_filters( |
|
325 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
326 | + $this->_caffeinated_extends |
|
327 | + ); |
|
328 | + //loop through admin pages and setup the $_installed_pages array. |
|
329 | + $hooks_ref = array(); |
|
330 | + foreach ($installed_refs as $page => $path) { |
|
331 | + // set autoloaders for our admin page classes based on included path information |
|
332 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
333 | + // build list of installed pages |
|
334 | + $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
335 | + // verify returned object |
|
336 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
337 | + if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
338 | + continue; |
|
339 | + } |
|
340 | + //skip if in full maintenance mode and maintenance_mode_parent is set |
|
341 | + $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
342 | + if (empty($maintenance_mode_parent) |
|
343 | + && EE_Maintenance_Mode::instance()->level() |
|
344 | + == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
345 | + unset($installed_refs[$page]); |
|
346 | + continue; |
|
347 | + } |
|
348 | + $this->_menu_slugs[$this->_installed_pages[$page]->get_menu_map()->menu_slug] = $page; |
|
349 | + //flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
350 | + $extend = false; |
|
351 | + //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
352 | + if (isset($this->_caffeinated_extends[$page])) { |
|
353 | + $this->_current_caf_extend_slug = $page; |
|
354 | + $path_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__' |
|
355 | + . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
356 | + . '_' |
|
357 | + . $this->_installed_pages[$page]->get_admin_page_name(); |
|
358 | + $path_runtime = 'return "' |
|
359 | + . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"] |
|
360 | + . '";'; |
|
361 | + $page_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__' |
|
362 | + . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
|
363 | + . '_' |
|
364 | + . $this->_installed_pages[$page]->get_admin_page_name(); |
|
365 | + $page_runtime = 'return "' |
|
366 | + . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"] |
|
367 | + . '";'; |
|
368 | + $hook_function_path = create_function('$path_to_file', $path_runtime); |
|
369 | + $hook_function_page = create_function('$admin_page', $page_runtime); |
|
370 | + add_filter($path_hook, $hook_function_path); |
|
371 | + add_filter($page_hook, $hook_function_page); |
|
372 | + $extend = true; |
|
373 | + } |
|
374 | + //let's do the registered hooks |
|
375 | + $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
376 | + $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
377 | + } |
|
378 | + } |
|
379 | + //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
380 | + //first make sure we've got unique values |
|
381 | + $hooks_ref = array_unique($hooks_ref); |
|
382 | + //now let's loop and require! |
|
383 | + foreach ($hooks_ref as $path) { |
|
384 | + require_once($path); |
|
385 | + } |
|
386 | + //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
387 | + global $ee_menu_slugs; |
|
388 | + $ee_menu_slugs = $this->_menu_slugs; |
|
389 | + //we need to loop again to run any early code |
|
390 | + foreach ($installed_refs as $page => $path) { |
|
391 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
392 | + $this->_installed_pages[$page]->do_initial_loads(); |
|
393 | + } |
|
394 | + } |
|
395 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * get_admin_page_object |
|
402 | + * |
|
403 | + * @param string $page_slug |
|
404 | + * @return EE_Admin_Page |
|
405 | + */ |
|
406 | + public function get_admin_page_object($page_slug = '') |
|
407 | + { |
|
408 | + if (isset($this->_installed_pages[$page_slug])) { |
|
409 | + return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
410 | + } |
|
411 | + return null; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * _get_classname_for_admin_page |
|
418 | + * generates an "Admin Page" class based on the directory name |
|
419 | + * |
|
420 | + * @param $dir_name |
|
421 | + * @return string |
|
422 | + */ |
|
423 | + private function _get_classname_for_admin_page($dir_name = '') |
|
424 | + { |
|
425 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
426 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * _get_classname_for_admin_init_page |
|
433 | + * generates an "Admin Page Init" class based on the directory name |
|
434 | + * |
|
435 | + * @param $dir_name |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + private function _get_classname_for_admin_init_page($dir_name = '') |
|
439 | + { |
|
440 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
441 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * _load_admin_page |
|
448 | + * Loads and instantiates page_init object for a single EE_admin page. |
|
449 | + * |
|
450 | + * @param string $page page_reference |
|
451 | + * @param string $path |
|
452 | + * @throws EE_Error |
|
453 | + * @return object|bool return page object if valid, bool false if not. |
|
454 | + */ |
|
455 | + private function _load_admin_page($page = '', $path = '') |
|
456 | + { |
|
457 | + $class_name = $this->_get_classname_for_admin_init_page($page); |
|
458 | + EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
459 | + if (! class_exists($class_name)) { |
|
460 | + $inner_error_msg = '<br />' . sprintf( |
|
461 | + esc_html__( |
|
462 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
463 | + 'event_espresso' |
|
464 | + ), |
|
465 | + '<strong>' . $class_name . '</strong>' |
|
466 | + ); |
|
467 | + $error_msg[] = sprintf( |
|
468 | + __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
469 | + $page |
|
470 | + ); |
|
471 | + $error_msg[] = $error_msg[0] |
|
472 | + . "\r\n" |
|
473 | + . sprintf( |
|
474 | + esc_html__( |
|
475 | + 'There is no Init class in place for the %s admin page.', |
|
476 | + 'event_espresso' |
|
477 | + ), |
|
478 | + $page |
|
479 | + ) |
|
480 | + . $inner_error_msg; |
|
481 | + throw new EE_Error(implode('||', $error_msg)); |
|
482 | + } |
|
483 | + $a = new ReflectionClass($class_name); |
|
484 | + return $a->newInstance(); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * set_menus |
|
491 | + * This method sets up the menus for EE Admin Pages |
|
492 | + * |
|
493 | + * @access private |
|
494 | + * @return void |
|
495 | + */ |
|
496 | + public function set_menus() |
|
497 | + { |
|
498 | + //prep the menu pages (sort, group.) |
|
499 | + $this->_prep_pages(); |
|
500 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
501 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
502 | + $menu_map->add_menu_page(false); |
|
503 | + } |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * set_network_menus |
|
510 | + * This method sets up the menus for network EE Admin Pages. |
|
511 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
512 | + * are only added to the menu map if they are intended for the admin menu |
|
513 | + * |
|
514 | + * @return void |
|
515 | + */ |
|
516 | + public function set_network_menus() |
|
517 | + { |
|
518 | + $this->_prep_pages(); |
|
519 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
520 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
521 | + $menu_map->add_menu_page(true); |
|
522 | + } |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * _prep_pages |
|
530 | + * sets the _prepped_menu_maps property |
|
531 | + * |
|
532 | + * @access private |
|
533 | + * @throws EE_Error |
|
534 | + * @return void |
|
535 | + */ |
|
536 | + private function _prep_pages() |
|
537 | + { |
|
538 | + $pages_array = array(); |
|
539 | + //rearrange _admin_menu_groups to be indexed by group slug. |
|
540 | + $menu_groups = $this->_rearrange_menu_groups(); |
|
541 | + foreach ($this->_installed_pages as $page) { |
|
542 | + if ($page instanceof EE_Admin_page_Init) { |
|
543 | + $page_map = $page->get_menu_map(); |
|
544 | + //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
545 | + if (is_array($page_map) || empty($page_map)) { |
|
546 | + EE_Error::add_persistent_admin_notice( |
|
547 | + 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
548 | + sprintf( |
|
549 | + __( |
|
550 | + 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
551 | + 'event_espresso' |
|
552 | + ), |
|
553 | + $page->label |
|
554 | + ) |
|
555 | + ); |
|
556 | + continue; |
|
557 | + } |
|
558 | + //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
559 | + if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
560 | + throw new EE_Error( |
|
561 | + sprintf( |
|
562 | + __( |
|
563 | + 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
564 | + 'event_espresso' |
|
565 | + ), |
|
566 | + $page->label, |
|
567 | + $page_map |
|
568 | + ) |
|
569 | + ); |
|
570 | + } |
|
571 | + //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
572 | + if (empty($page_map->maintenance_mode_parent) |
|
573 | + && EE_Maintenance_Mode::instance()->level() |
|
574 | + == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
575 | + continue; |
|
576 | + } |
|
577 | + //assign to group (remember $page_map has the admin page stored in it). |
|
578 | + $pages_array[$page_map->menu_group][] = $page_map; |
|
579 | + } |
|
580 | + } |
|
581 | + if (empty($pages_array)) { |
|
582 | + throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
583 | + } |
|
584 | + //let's sort the groups, make sure it's a valid group, add header (if to show). |
|
585 | + foreach ($pages_array as $group => $menu_maps) { |
|
586 | + //valid_group? |
|
587 | + if (! array_key_exists($group, $menu_groups)) { |
|
588 | + continue; |
|
589 | + } |
|
590 | + //sort pages. |
|
591 | + usort($menu_maps, array($this, '_sort_menu_maps')); |
|
592 | + //prepend header |
|
593 | + array_unshift($menu_maps, $menu_groups[$group]); |
|
594 | + //reset $pages_array with prepped data |
|
595 | + $pages_array[$group] = $menu_maps; |
|
596 | + } |
|
597 | + //now let's setup the _prepped_menu_maps property |
|
598 | + foreach ($menu_groups as $group => $group_objs) { |
|
599 | + if (isset($pages_array[$group])) { |
|
600 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
601 | + } |
|
602 | + }/**/ |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
609 | + * In this method there are three checks being done: |
|
610 | + * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
611 | + * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
612 | + * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
613 | + * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
614 | + * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
615 | + * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
616 | + * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
617 | + * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
618 | + * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
619 | + * admin_pages) |
|
620 | + * |
|
621 | + * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
622 | + * loaded. |
|
623 | + * @return array |
|
624 | + */ |
|
625 | + private function _set_caffeinated($installed_refs) |
|
626 | + { |
|
627 | + |
|
628 | + //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
629 | + if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
630 | + return $installed_refs; |
|
631 | + } |
|
632 | + $this->_define_caffeinated_constants(); |
|
633 | + $exclude = array('tickets'); |
|
634 | + //okay let's setup an "New" pages first (we'll return installed refs later) |
|
635 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
636 | + if ($new_admin_screens) { |
|
637 | + foreach ($new_admin_screens as $admin_screen) { |
|
638 | + // files and anything in the exclude array need not apply |
|
639 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
640 | + // these folders represent the different NEW EE admin pages |
|
641 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
642 | + // set autoloaders for our admin page classes based on included path information |
|
643 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
644 | + // $this->_caf_autoloader[] = array( |
|
645 | + // 'dir' => 'new', |
|
646 | + // 'folder' => basename( $admin_screen ) |
|
647 | + // ); |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
652 | + $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
653 | + if ($extends) { |
|
654 | + foreach ($extends as $extend) { |
|
655 | + if (is_dir($extend)) { |
|
656 | + $extend_ref = basename($extend); |
|
657 | + //now let's make sure there is a file that matches the expected format |
|
658 | + $filename = str_replace( |
|
659 | + ' ', |
|
660 | + '_', |
|
661 | + ucwords( |
|
662 | + str_replace( |
|
663 | + '_', |
|
664 | + ' ', |
|
665 | + $extend_ref |
|
666 | + ) |
|
667 | + ) |
|
668 | + ); |
|
669 | + $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
670 | + $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
671 | + array('\\', '/'), |
|
672 | + DS, |
|
673 | + EE_CORE_CAF_ADMIN |
|
674 | + . 'extend' |
|
675 | + . DS |
|
676 | + . $extend_ref |
|
677 | + . DS |
|
678 | + . $filename |
|
679 | + . '.core.php' |
|
680 | + ); |
|
681 | + $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
682 | + // set autoloaders for our admin page classes based on included path information |
|
683 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
684 | + // $this->_caf_autoloader[] = array( |
|
685 | + // 'dir' => 'extend', |
|
686 | + // 'folder' => $extend_ref |
|
687 | + // ); |
|
688 | + } |
|
689 | + } |
|
690 | + } |
|
691 | + //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
692 | + $ee_admin_hooks = array(); |
|
693 | + $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
694 | + if ($hooks) { |
|
695 | + foreach ($hooks as $hook) { |
|
696 | + if (is_readable($hook)) { |
|
697 | + require_once $hook; |
|
698 | + $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
699 | + $classname = str_replace('.class.php', '', $classname); |
|
700 | + if (class_exists($classname)) { |
|
701 | + $a = new ReflectionClass($classname); |
|
702 | + $ee_admin_hooks[] = $a->newInstance(); |
|
703 | + } |
|
704 | + } |
|
705 | + } |
|
706 | + }/**/ |
|
707 | + $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
708 | + return $installed_refs; |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * Initial autoloader registration |
|
717 | + * This just sets up the autoloader for the root admin files |
|
718 | + * |
|
719 | + * @param string $className incoming classname to check for autoload |
|
720 | + * @return void |
|
721 | + */ |
|
722 | + // public function init_autoloaders( $className ) { |
|
723 | + // $dir_ref = array( |
|
724 | + // EE_ADMIN => array('core', 'class') |
|
725 | + // ); |
|
726 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
727 | + // } |
|
728 | + /** |
|
729 | + * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the |
|
730 | + * caffeinated folders. |
|
731 | + * |
|
732 | + * @access public |
|
733 | + * @param string $className in coming classname being called |
|
734 | + * @return void |
|
735 | + */ |
|
736 | + // public function caffeinated_autoloaders( $className ) { |
|
737 | + // //let's setup an array of paths to check (for each subsystem) |
|
738 | + // $dir_ref = array(); |
|
739 | + // foreach ( $this->_caf_autoloader as $pathinfo) { |
|
740 | + // $dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class'); |
|
741 | + // } |
|
742 | + // |
|
743 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
744 | + // } |
|
745 | + /** |
|
746 | + * Utility method for sorting the _menu_maps (callback for usort php function) |
|
747 | + * |
|
748 | + * @since 4.4.0 |
|
749 | + * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
750 | + * @param EE_Admin_Page_Menu_Map $b being compared to |
|
751 | + * @return int sort order |
|
752 | + */ |
|
753 | + private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
754 | + { |
|
755 | + if ($a->menu_order == $b->menu_order) { |
|
756 | + return 0; |
|
757 | + } |
|
758 | + return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * _default_header_link |
|
765 | + * This is just a dummy method to use with header submenu items |
|
766 | + * |
|
767 | + * @return bool false |
|
768 | + */ |
|
769 | + public function _default_header_link() |
|
770 | + { |
|
771 | + return false; |
|
772 | + } |
|
773 | 773 | |
774 | 774 | |
775 | 775 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function _define_caffeinated_constants() |
142 | 142 | { |
143 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
145 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
146 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
147 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
148 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
149 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
143 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
144 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
145 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
146 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
147 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
148 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
149 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
260 | 260 | usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
261 | 261 | foreach ($this->_admin_menu_groups as $group) { |
262 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
262 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group) { |
|
263 | 263 | throw new EE_Error( |
264 | 264 | sprintf( |
265 | 265 | __( |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | $installed_refs = array(); |
291 | 291 | $exclude = array('assets', 'templates'); |
292 | 292 | // grab everything in the admin core directory |
293 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
293 | + $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR); |
|
294 | 294 | if ($admin_screens) { |
295 | 295 | foreach ($admin_screens as $admin_screen) { |
296 | 296 | // files and anything in the exclude array need not apply |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
306 | 306 | 'event_espresso' |
307 | 307 | ); |
308 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
308 | + $error_msg[] = $error_msg[0]."\r\n".sprintf( |
|
309 | 309 | __( |
310 | 310 | 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
311 | 311 | 'event_espresso' |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
318 | 318 | $installed_refs = $this->_set_caffeinated($installed_refs); |
319 | 319 | //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
320 | - $installed_refs = apply_filters( |
|
320 | + $installed_refs = apply_filters( |
|
321 | 321 | 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
322 | 322 | $installed_refs |
323 | 323 | ); |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
335 | 335 | // verify returned object |
336 | 336 | if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
337 | - if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
337 | + if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
338 | 338 | continue; |
339 | 339 | } |
340 | 340 | //skip if in full maintenance mode and maintenance_mode_parent is set |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | . $this->_installed_pages[$page]->get_menu_map()->menu_slug |
363 | 363 | . '_' |
364 | 364 | . $this->_installed_pages[$page]->get_admin_page_name(); |
365 | - $page_runtime = 'return "' |
|
365 | + $page_runtime = 'return "' |
|
366 | 366 | . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"] |
367 | 367 | . '";'; |
368 | 368 | $hook_function_path = create_function('$path_to_file', $path_runtime); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | private function _get_classname_for_admin_page($dir_name = '') |
424 | 424 | { |
425 | 425 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
426 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
426 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page'; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | private function _get_classname_for_admin_init_page($dir_name = '') |
439 | 439 | { |
440 | 440 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
441 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
441 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | |
@@ -456,19 +456,19 @@ discard block |
||
456 | 456 | { |
457 | 457 | $class_name = $this->_get_classname_for_admin_init_page($page); |
458 | 458 | EE_Registry::instance()->load_file($path, $class_name, 'core'); |
459 | - if (! class_exists($class_name)) { |
|
460 | - $inner_error_msg = '<br />' . sprintf( |
|
459 | + if ( ! class_exists($class_name)) { |
|
460 | + $inner_error_msg = '<br />'.sprintf( |
|
461 | 461 | esc_html__( |
462 | 462 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
463 | 463 | 'event_espresso' |
464 | 464 | ), |
465 | - '<strong>' . $class_name . '</strong>' |
|
465 | + '<strong>'.$class_name.'</strong>' |
|
466 | 466 | ); |
467 | - $error_msg[] = sprintf( |
|
467 | + $error_msg[] = sprintf( |
|
468 | 468 | __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
469 | 469 | $page |
470 | 470 | ); |
471 | - $error_msg[] = $error_msg[0] |
|
471 | + $error_msg[] = $error_msg[0] |
|
472 | 472 | . "\r\n" |
473 | 473 | . sprintf( |
474 | 474 | esc_html__( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
545 | 545 | if (is_array($page_map) || empty($page_map)) { |
546 | 546 | EE_Error::add_persistent_admin_notice( |
547 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
547 | + 'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION, |
|
548 | 548 | sprintf( |
549 | 549 | __( |
550 | 550 | 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | continue; |
557 | 557 | } |
558 | 558 | //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
559 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
559 | + if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
560 | 560 | throw new EE_Error( |
561 | 561 | sprintf( |
562 | 562 | __( |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | //let's sort the groups, make sure it's a valid group, add header (if to show). |
585 | 585 | foreach ($pages_array as $group => $menu_maps) { |
586 | 586 | //valid_group? |
587 | - if (! array_key_exists($group, $menu_groups)) { |
|
587 | + if ( ! array_key_exists($group, $menu_groups)) { |
|
588 | 588 | continue; |
589 | 589 | } |
590 | 590 | //sort pages. |
@@ -626,13 +626,13 @@ discard block |
||
626 | 626 | { |
627 | 627 | |
628 | 628 | //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
629 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
629 | + if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
630 | 630 | return $installed_refs; |
631 | 631 | } |
632 | 632 | $this->_define_caffeinated_constants(); |
633 | 633 | $exclude = array('tickets'); |
634 | 634 | //okay let's setup an "New" pages first (we'll return installed refs later) |
635 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
635 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR); |
|
636 | 636 | if ($new_admin_screens) { |
637 | 637 | foreach ($new_admin_screens as $admin_screen) { |
638 | 638 | // files and anything in the exclude array need not apply |
@@ -649,13 +649,13 @@ discard block |
||
649 | 649 | } |
650 | 650 | } |
651 | 651 | //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
652 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
652 | + $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR); |
|
653 | 653 | if ($extends) { |
654 | 654 | foreach ($extends as $extend) { |
655 | 655 | if (is_dir($extend)) { |
656 | 656 | $extend_ref = basename($extend); |
657 | 657 | //now let's make sure there is a file that matches the expected format |
658 | - $filename = str_replace( |
|
658 | + $filename = str_replace( |
|
659 | 659 | ' ', |
660 | 660 | '_', |
661 | 661 | ucwords( |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | ) |
667 | 667 | ) |
668 | 668 | ); |
669 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
669 | + $filename = 'Extend_'.$filename.'_Admin_Page'; |
|
670 | 670 | $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
671 | 671 | array('\\', '/'), |
672 | 672 | DS, |
@@ -690,12 +690,12 @@ discard block |
||
690 | 690 | } |
691 | 691 | //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
692 | 692 | $ee_admin_hooks = array(); |
693 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
693 | + $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php'); |
|
694 | 694 | if ($hooks) { |
695 | 695 | foreach ($hooks as $hook) { |
696 | 696 | if (is_readable($hook)) { |
697 | 697 | require_once $hook; |
698 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
698 | + $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook); |
|
699 | 699 | $classname = str_replace('.class.php', '', $classname); |
700 | 700 | if (class_exists($classname)) { |
701 | 701 | $a = new ReflectionClass($classname); |
@@ -1,5 +1,5 @@ discard block |
||
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 | /** |
@@ -12,869 +12,869 @@ discard block |
||
12 | 12 | class EE_Message extends EE_Base_Class implements EEI_Admin_Links |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
17 | - * @type null |
|
18 | - */ |
|
19 | - public $template_pack; |
|
20 | - |
|
21 | - /** |
|
22 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
23 | - * @type null |
|
24 | - */ |
|
25 | - public $template_variation; |
|
26 | - |
|
27 | - /** |
|
28 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
29 | - * @type string |
|
30 | - */ |
|
31 | - public $content = ''; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @type EE_messenger $_messenger |
|
36 | - */ |
|
37 | - protected $_messenger = null; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type EE_message_type $_message_type |
|
41 | - */ |
|
42 | - protected $_message_type = null; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array $props_n_values |
|
47 | - * @param string $timezone |
|
48 | - * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
49 | - * format. |
|
50 | - * @return EE_Message |
|
51 | - */ |
|
52 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
53 | - { |
|
54 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
55 | - //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
56 | - if ( ! $has_object) { |
|
57 | - EE_Registry::instance()->load_helper('URL'); |
|
58 | - $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
59 | - } |
|
60 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @param array $props_n_values |
|
66 | - * @param string $timezone |
|
67 | - * @return EE_Message |
|
68 | - */ |
|
69 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
70 | - { |
|
71 | - return new self($props_n_values, true, $timezone); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Gets MSG_token |
|
77 | - * |
|
78 | - * @return int |
|
79 | - */ |
|
80 | - public function MSG_token() |
|
81 | - { |
|
82 | - return $this->get('MSG_token'); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Sets MSG_token |
|
88 | - * |
|
89 | - * @param int $MSG_token |
|
90 | - */ |
|
91 | - public function set_MSG_token($MSG_token) |
|
92 | - { |
|
93 | - $this->set('MSG_token', $MSG_token); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Gets GRP_ID |
|
99 | - * |
|
100 | - * @return int |
|
101 | - */ |
|
102 | - public function GRP_ID() |
|
103 | - { |
|
104 | - return $this->get('GRP_ID'); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sets GRP_ID |
|
110 | - * |
|
111 | - * @param int $GRP_ID |
|
112 | - */ |
|
113 | - public function set_GRP_ID($GRP_ID) |
|
114 | - { |
|
115 | - $this->set('GRP_ID', $GRP_ID); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Gets TXN_ID |
|
121 | - * |
|
122 | - * @return int |
|
123 | - */ |
|
124 | - public function TXN_ID() |
|
125 | - { |
|
126 | - return $this->get('TXN_ID'); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Sets TXN_ID |
|
132 | - * |
|
133 | - * @param int $TXN_ID |
|
134 | - */ |
|
135 | - public function set_TXN_ID($TXN_ID) |
|
136 | - { |
|
137 | - $this->set('TXN_ID', $TXN_ID); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Gets messenger |
|
143 | - * |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public function messenger() |
|
147 | - { |
|
148 | - return $this->get('MSG_messenger'); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Sets messenger |
|
154 | - * |
|
155 | - * @param string $messenger |
|
156 | - */ |
|
157 | - public function set_messenger($messenger) |
|
158 | - { |
|
159 | - $this->set('MSG_messenger', $messenger); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns corresponding messenger object for the set messenger on this message |
|
165 | - * |
|
166 | - * @return EE_messenger | null |
|
167 | - */ |
|
168 | - public function messenger_object() |
|
169 | - { |
|
170 | - return $this->_messenger; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Sets messenger |
|
176 | - * |
|
177 | - * @param EE_messenger $messenger |
|
178 | - */ |
|
179 | - public function set_messenger_object(EE_messenger $messenger) |
|
180 | - { |
|
181 | - $this->_messenger = $messenger; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * validates messenger |
|
187 | - * |
|
188 | - * @param bool $throw_exceptions |
|
189 | - * @return bool |
|
190 | - * @throws \EE_Error |
|
191 | - */ |
|
192 | - public function valid_messenger($throw_exceptions = false) |
|
193 | - { |
|
194 | - if ($this->_messenger instanceof EE_messenger) { |
|
195 | - return true; |
|
196 | - } |
|
197 | - if ($throw_exceptions) { |
|
198 | - throw new EE_Error( |
|
199 | - sprintf( |
|
200 | - __( |
|
201 | - 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
202 | - 'event_espresso' |
|
203 | - ), |
|
204 | - $this->messenger() |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * This returns the set localized label for the messenger on this message. |
|
214 | - * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
215 | - * with this message. |
|
216 | - * |
|
217 | - * @param bool $plural whether to return the plural label or not. |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public function messenger_label($plural = false) |
|
221 | - { |
|
222 | - $label_type = $plural ? 'plural' : 'singular'; |
|
223 | - $messenger = $this->messenger_object(); |
|
224 | - return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Gets message_type |
|
230 | - * |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function message_type() |
|
234 | - { |
|
235 | - return $this->get('MSG_message_type'); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Sets message_type |
|
241 | - * |
|
242 | - * @param string $message_type |
|
243 | - */ |
|
244 | - public function set_message_type($message_type) |
|
245 | - { |
|
246 | - $this->set('MSG_message_type', $message_type); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * Returns the message type object for the set message type on this message |
|
252 | - * |
|
253 | - * @return EE_message_type | null |
|
254 | - */ |
|
255 | - public function message_type_object() |
|
256 | - { |
|
257 | - return $this->_message_type; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * Sets message_type |
|
263 | - * |
|
264 | - * @param EE_message_type $message_type |
|
265 | - * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
266 | - * the message type or not. |
|
267 | - */ |
|
268 | - public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
269 | - { |
|
270 | - $this->_message_type = $message_type; |
|
271 | - if ($set_priority) { |
|
272 | - $this->set_priority($this->_message_type->get_priority()); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * validates message_type |
|
279 | - * |
|
280 | - * @param bool $throw_exceptions |
|
281 | - * @return bool |
|
282 | - * @throws \EE_Error |
|
283 | - */ |
|
284 | - public function valid_message_type($throw_exceptions = false) |
|
285 | - { |
|
286 | - if ($this->_message_type instanceof EE_message_type) { |
|
287 | - return true; |
|
288 | - } |
|
289 | - if ($throw_exceptions) { |
|
290 | - throw new EE_Error( |
|
291 | - sprintf( |
|
292 | - __( |
|
293 | - 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
294 | - 'event_espresso' |
|
295 | - ), |
|
296 | - $this->message_type() |
|
297 | - ) |
|
298 | - ); |
|
299 | - } |
|
300 | - return false; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
306 | - * |
|
307 | - * @param bool $throw_exceptions |
|
308 | - * @return bool |
|
309 | - * @throws \EE_Error |
|
310 | - */ |
|
311 | - public function is_valid($throw_exceptions = false) |
|
312 | - { |
|
313 | - if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
314 | - return true; |
|
315 | - } |
|
316 | - return false; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * This validates whether the internal messenger and message type objects are valid for sending. |
|
322 | - * Three checks are done: |
|
323 | - * 1. There is a valid messenger object. |
|
324 | - * 2. There is a valid message type object. |
|
325 | - * 3. The message type object is active for the messenger. |
|
326 | - * |
|
327 | - * @throws EE_Error But only if $throw_exceptions is set to true. |
|
328 | - * @param bool $throw_exceptions |
|
329 | - * @return bool |
|
330 | - */ |
|
331 | - public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
332 | - { |
|
333 | - $valid = false; |
|
334 | - if ($this->is_valid($throw_exceptions)) { |
|
335 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
336 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
337 | - $valid = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(), |
|
338 | - $this->message_type()); |
|
339 | - if ( ! $valid && $throw_exceptions) { |
|
340 | - throw new EE_Error( |
|
341 | - sprintf( |
|
342 | - __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
343 | - 'event_espresso'), |
|
344 | - $this->message_type(), |
|
345 | - $this->messenger() |
|
346 | - ) |
|
347 | - ); |
|
348 | - } |
|
349 | - } |
|
350 | - return $valid; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * This returns the set localized label for the message type on this message. |
|
356 | - * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
357 | - * with this message. |
|
358 | - * |
|
359 | - * @param bool $plural whether to return the plural label or not. |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - public function message_type_label($plural = false) |
|
363 | - { |
|
364 | - $label_type = $plural ? 'plural' : 'singular'; |
|
365 | - $message_type = $this->message_type_object(); |
|
366 | - return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace( |
|
367 | - '_', |
|
368 | - ' ', |
|
369 | - $this->message_type() |
|
370 | - ); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * Gets context |
|
376 | - * |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function context() |
|
380 | - { |
|
381 | - return $this->get('MSG_context'); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
387 | - * types. Otherwise, this will just return the set context slug on this object. |
|
388 | - * |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function context_label() |
|
392 | - { |
|
393 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
394 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
395 | - $contexts = $message_resource_manager->get_all_contexts(); |
|
396 | - return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Sets context |
|
402 | - * |
|
403 | - * @param string $context |
|
404 | - */ |
|
405 | - public function set_context($context) |
|
406 | - { |
|
407 | - $this->set('MSG_context', $context); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Gets recipient_ID |
|
413 | - * |
|
414 | - * @return int |
|
415 | - */ |
|
416 | - public function recipient_ID() |
|
417 | - { |
|
418 | - return $this->get('MSG_recipient_ID'); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Sets recipient_ID |
|
424 | - * |
|
425 | - * @param string $recipient_ID |
|
426 | - */ |
|
427 | - public function set_recipient_ID($recipient_ID) |
|
428 | - { |
|
429 | - $this->set('MSG_recipient_ID', $recipient_ID); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Gets recipient_type |
|
435 | - * |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function recipient_type() |
|
439 | - { |
|
440 | - return $this->get('MSG_recipient_type'); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Return the related object matching the recipient type and ID. |
|
446 | - * |
|
447 | - * @return EE_Base_Class | null |
|
448 | - */ |
|
449 | - public function recipient_object() |
|
450 | - { |
|
451 | - if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
452 | - return null; |
|
453 | - } |
|
454 | - |
|
455 | - return $this->get_first_related($this->recipient_type()); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Sets recipient_type |
|
461 | - * |
|
462 | - * @param string $recipient_type |
|
463 | - */ |
|
464 | - public function set_recipient_type($recipient_type) |
|
465 | - { |
|
466 | - $this->set('MSG_recipient_type', $recipient_type); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Gets content |
|
472 | - * |
|
473 | - * @return string |
|
474 | - */ |
|
475 | - public function content() |
|
476 | - { |
|
477 | - return $this->get('MSG_content'); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Sets content |
|
483 | - * |
|
484 | - * @param string $content |
|
485 | - */ |
|
486 | - public function set_content($content) |
|
487 | - { |
|
488 | - $this->set('MSG_content', $content); |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * Gets subject |
|
494 | - * |
|
495 | - * @return string |
|
496 | - */ |
|
497 | - public function subject() |
|
498 | - { |
|
499 | - return $this->get('MSG_subject'); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Sets subject |
|
505 | - * |
|
506 | - * @param string $subject |
|
507 | - */ |
|
508 | - public function set_subject($subject) |
|
509 | - { |
|
510 | - $this->set('MSG_subject', $subject); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Gets to |
|
516 | - * |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function to() |
|
520 | - { |
|
521 | - $to = $this->get('MSG_to'); |
|
522 | - return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * Sets to |
|
528 | - * |
|
529 | - * @param string $to |
|
530 | - */ |
|
531 | - public function set_to($to) |
|
532 | - { |
|
533 | - $this->set('MSG_to', $to); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Gets from |
|
539 | - * |
|
540 | - * @return string |
|
541 | - */ |
|
542 | - public function from() |
|
543 | - { |
|
544 | - return $this->get('MSG_from'); |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * Sets from |
|
550 | - * |
|
551 | - * @param string $from |
|
552 | - */ |
|
553 | - public function set_from($from) |
|
554 | - { |
|
555 | - $this->set('MSG_from', $from); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Gets priority |
|
561 | - * |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function priority() |
|
565 | - { |
|
566 | - return $this->get('MSG_priority'); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * Sets priority |
|
572 | - * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
573 | - * this method calls the send_now method to verify that. |
|
574 | - * |
|
575 | - * @param int $priority |
|
576 | - */ |
|
577 | - public function set_priority($priority) |
|
578 | - { |
|
579 | - $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
580 | - parent::set('MSG_priority', $priority); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Overrides parent::set method so we can capture any sets for priority. |
|
586 | - * |
|
587 | - * @see parent::set() for phpdocs |
|
588 | - * @param string $field_name |
|
589 | - * @param mixed $field_value |
|
590 | - * @param bool $use_default |
|
591 | - * @throws EE_Error |
|
592 | - */ |
|
593 | - public function set($field_name, $field_value, $use_default = false) |
|
594 | - { |
|
595 | - if ($field_name === 'MSG_priority') { |
|
596 | - $this->set_priority($field_value); |
|
597 | - } |
|
598 | - parent::set($field_name, $field_value, $use_default); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @return bool |
|
604 | - * @throws \EE_Error |
|
605 | - */ |
|
606 | - public function send_now() |
|
607 | - { |
|
608 | - $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority(); |
|
609 | - return $send_now === EEM_Message::priority_high ? true : false; |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Gets STS_ID |
|
615 | - * |
|
616 | - * @return string |
|
617 | - */ |
|
618 | - public function STS_ID() |
|
619 | - { |
|
620 | - return $this->get('STS_ID'); |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Sets STS_ID |
|
626 | - * |
|
627 | - * @param string $STS_ID |
|
628 | - */ |
|
629 | - public function set_STS_ID($STS_ID) |
|
630 | - { |
|
631 | - $this->set('STS_ID', $STS_ID); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * Gets created |
|
637 | - * |
|
638 | - * @return string |
|
639 | - */ |
|
640 | - public function created() |
|
641 | - { |
|
642 | - return $this->get('MSG_created'); |
|
643 | - } |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * Sets created |
|
648 | - * |
|
649 | - * @param string $created |
|
650 | - */ |
|
651 | - public function set_created($created) |
|
652 | - { |
|
653 | - $this->set('MSG_created', $created); |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - /** |
|
658 | - * Gets modified |
|
659 | - * |
|
660 | - * @return string |
|
661 | - */ |
|
662 | - public function modified() |
|
663 | - { |
|
664 | - return $this->get('MSG_modified'); |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * Sets modified |
|
670 | - * |
|
671 | - * @param string $modified |
|
672 | - */ |
|
673 | - public function set_modified($modified) |
|
674 | - { |
|
675 | - $this->set('MSG_modified', $modified); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * Sets generation data for this message. |
|
681 | - * |
|
682 | - * @param mixed $data |
|
683 | - */ |
|
684 | - public function set_generation_data($data) |
|
685 | - { |
|
686 | - $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * Returns any set generation data for this message. |
|
692 | - * |
|
693 | - * @return mixed|null |
|
694 | - */ |
|
695 | - public function get_generation_data() |
|
696 | - { |
|
697 | - return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * Gets any error message. |
|
703 | - * |
|
704 | - * @return mixed|null |
|
705 | - */ |
|
706 | - public function error_message() |
|
707 | - { |
|
708 | - return $this->get_field_or_extra_meta('MSG_error'); |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * Sets an error message. |
|
714 | - * |
|
715 | - * @param $message |
|
716 | - * @return bool|int |
|
717 | - */ |
|
718 | - public function set_error_message($message) |
|
719 | - { |
|
720 | - return $this->set_field_or_extra_meta('MSG_error', $message); |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * This retrieves the associated template pack with this message. |
|
726 | - * |
|
727 | - * @return EE_Messages_Template_Pack | null |
|
728 | - */ |
|
729 | - public function get_template_pack() |
|
730 | - { |
|
731 | - /** |
|
732 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
733 | - */ |
|
734 | - if ( ! empty($this->template_pack)) { |
|
735 | - return $this->template_pack; |
|
736 | - } |
|
737 | - /** @type EE_Message_Template_Group $grp */ |
|
738 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
739 | - //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
740 | - if ( ! $grp instanceof EE_Message_Template_Group) { |
|
741 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
742 | - array( |
|
743 | - array( |
|
744 | - 'MTP_messenger' => $this->messenger(), |
|
745 | - 'MTP_message_type' => $this->message_type(), |
|
746 | - 'MTP_is_global' => true, |
|
747 | - ), |
|
748 | - ) |
|
749 | - ); |
|
750 | - } |
|
751 | - |
|
752 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * Retrieves the variation used for generating this message. |
|
758 | - * |
|
759 | - * @return string |
|
760 | - */ |
|
761 | - public function get_template_pack_variation() |
|
762 | - { |
|
763 | - /** |
|
764 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
765 | - */ |
|
766 | - if ( ! empty($this->template_variation)) { |
|
767 | - return $this->template_variation; |
|
768 | - } |
|
769 | - |
|
770 | - /** @type EE_Message_Template_Group $grp */ |
|
771 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
772 | - |
|
773 | - //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
774 | - if ( ! $grp instanceof EE_Message_Template_Group) { |
|
775 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
776 | - array( |
|
777 | - array( |
|
778 | - 'MTP_messenger' => $this->messenger(), |
|
779 | - 'MTP_message_type' => $this->message_type(), |
|
780 | - 'MTP_is_global' => true, |
|
781 | - ), |
|
782 | - ) |
|
783 | - ); |
|
784 | - } |
|
785 | - |
|
786 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Return the link to the admin details for the object. |
|
791 | - * |
|
792 | - * @return string |
|
793 | - */ |
|
794 | - public function get_admin_details_link() |
|
795 | - { |
|
796 | - EE_Registry::instance()->load_helper('URL'); |
|
797 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
798 | - switch ($this->STS_ID()) { |
|
799 | - case EEM_Message::status_failed : |
|
800 | - case EEM_Message::status_debug_only : |
|
801 | - return EEH_MSG_Template::generate_error_display_trigger($this); |
|
802 | - break; |
|
803 | - |
|
804 | - case EEM_Message::status_sent : |
|
805 | - return EEH_MSG_Template::generate_browser_trigger($this); |
|
806 | - break; |
|
807 | - |
|
808 | - default : |
|
809 | - return ''; |
|
810 | - } |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
815 | - * |
|
816 | - * @return string |
|
817 | - */ |
|
818 | - public function get_admin_edit_link() |
|
819 | - { |
|
820 | - return $this->get_admin_details_link(); |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Returns the link to a settings page for the object. |
|
825 | - * |
|
826 | - * @return string |
|
827 | - */ |
|
828 | - public function get_admin_settings_link() |
|
829 | - { |
|
830 | - EE_Registry::instance()->load_helper('URL'); |
|
831 | - return EEH_URL::add_query_args_and_nonce( |
|
832 | - array( |
|
833 | - 'page' => 'espresso_messages', |
|
834 | - 'action' => 'settings', |
|
835 | - ), |
|
836 | - admin_url('admin.php') |
|
837 | - ); |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
842 | - * |
|
843 | - * @return string |
|
844 | - */ |
|
845 | - public function get_admin_overview_link() |
|
846 | - { |
|
847 | - EE_Registry::instance()->load_helper('URL'); |
|
848 | - return EEH_URL::add_query_args_and_nonce( |
|
849 | - array( |
|
850 | - 'page' => 'espresso_messages', |
|
851 | - 'action' => 'default', |
|
852 | - ), |
|
853 | - admin_url('admin.php') |
|
854 | - ); |
|
855 | - } |
|
856 | - |
|
857 | - |
|
858 | - /** |
|
859 | - * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
860 | - * it. |
|
861 | - * Note this also SAVES the current message object to the db because it adds an error message to accompany the status. |
|
862 | - * |
|
863 | - */ |
|
864 | - public function set_messenger_is_executing() |
|
865 | - { |
|
866 | - $this->set_STS_ID( EEM_Message::status_messenger_executing ); |
|
867 | - $this->set_error_message( |
|
868 | - esc_html__( |
|
869 | - 'A message with this status indicates that there was a problem that occurred while the message was being |
|
15 | + /** |
|
16 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
17 | + * @type null |
|
18 | + */ |
|
19 | + public $template_pack; |
|
20 | + |
|
21 | + /** |
|
22 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
23 | + * @type null |
|
24 | + */ |
|
25 | + public $template_variation; |
|
26 | + |
|
27 | + /** |
|
28 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
29 | + * @type string |
|
30 | + */ |
|
31 | + public $content = ''; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @type EE_messenger $_messenger |
|
36 | + */ |
|
37 | + protected $_messenger = null; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type EE_message_type $_message_type |
|
41 | + */ |
|
42 | + protected $_message_type = null; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array $props_n_values |
|
47 | + * @param string $timezone |
|
48 | + * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
49 | + * format. |
|
50 | + * @return EE_Message |
|
51 | + */ |
|
52 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
53 | + { |
|
54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
55 | + //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
56 | + if ( ! $has_object) { |
|
57 | + EE_Registry::instance()->load_helper('URL'); |
|
58 | + $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
59 | + } |
|
60 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @param array $props_n_values |
|
66 | + * @param string $timezone |
|
67 | + * @return EE_Message |
|
68 | + */ |
|
69 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
70 | + { |
|
71 | + return new self($props_n_values, true, $timezone); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Gets MSG_token |
|
77 | + * |
|
78 | + * @return int |
|
79 | + */ |
|
80 | + public function MSG_token() |
|
81 | + { |
|
82 | + return $this->get('MSG_token'); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Sets MSG_token |
|
88 | + * |
|
89 | + * @param int $MSG_token |
|
90 | + */ |
|
91 | + public function set_MSG_token($MSG_token) |
|
92 | + { |
|
93 | + $this->set('MSG_token', $MSG_token); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Gets GRP_ID |
|
99 | + * |
|
100 | + * @return int |
|
101 | + */ |
|
102 | + public function GRP_ID() |
|
103 | + { |
|
104 | + return $this->get('GRP_ID'); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sets GRP_ID |
|
110 | + * |
|
111 | + * @param int $GRP_ID |
|
112 | + */ |
|
113 | + public function set_GRP_ID($GRP_ID) |
|
114 | + { |
|
115 | + $this->set('GRP_ID', $GRP_ID); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Gets TXN_ID |
|
121 | + * |
|
122 | + * @return int |
|
123 | + */ |
|
124 | + public function TXN_ID() |
|
125 | + { |
|
126 | + return $this->get('TXN_ID'); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Sets TXN_ID |
|
132 | + * |
|
133 | + * @param int $TXN_ID |
|
134 | + */ |
|
135 | + public function set_TXN_ID($TXN_ID) |
|
136 | + { |
|
137 | + $this->set('TXN_ID', $TXN_ID); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Gets messenger |
|
143 | + * |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public function messenger() |
|
147 | + { |
|
148 | + return $this->get('MSG_messenger'); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Sets messenger |
|
154 | + * |
|
155 | + * @param string $messenger |
|
156 | + */ |
|
157 | + public function set_messenger($messenger) |
|
158 | + { |
|
159 | + $this->set('MSG_messenger', $messenger); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns corresponding messenger object for the set messenger on this message |
|
165 | + * |
|
166 | + * @return EE_messenger | null |
|
167 | + */ |
|
168 | + public function messenger_object() |
|
169 | + { |
|
170 | + return $this->_messenger; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Sets messenger |
|
176 | + * |
|
177 | + * @param EE_messenger $messenger |
|
178 | + */ |
|
179 | + public function set_messenger_object(EE_messenger $messenger) |
|
180 | + { |
|
181 | + $this->_messenger = $messenger; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * validates messenger |
|
187 | + * |
|
188 | + * @param bool $throw_exceptions |
|
189 | + * @return bool |
|
190 | + * @throws \EE_Error |
|
191 | + */ |
|
192 | + public function valid_messenger($throw_exceptions = false) |
|
193 | + { |
|
194 | + if ($this->_messenger instanceof EE_messenger) { |
|
195 | + return true; |
|
196 | + } |
|
197 | + if ($throw_exceptions) { |
|
198 | + throw new EE_Error( |
|
199 | + sprintf( |
|
200 | + __( |
|
201 | + 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
202 | + 'event_espresso' |
|
203 | + ), |
|
204 | + $this->messenger() |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * This returns the set localized label for the messenger on this message. |
|
214 | + * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
215 | + * with this message. |
|
216 | + * |
|
217 | + * @param bool $plural whether to return the plural label or not. |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public function messenger_label($plural = false) |
|
221 | + { |
|
222 | + $label_type = $plural ? 'plural' : 'singular'; |
|
223 | + $messenger = $this->messenger_object(); |
|
224 | + return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Gets message_type |
|
230 | + * |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function message_type() |
|
234 | + { |
|
235 | + return $this->get('MSG_message_type'); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Sets message_type |
|
241 | + * |
|
242 | + * @param string $message_type |
|
243 | + */ |
|
244 | + public function set_message_type($message_type) |
|
245 | + { |
|
246 | + $this->set('MSG_message_type', $message_type); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * Returns the message type object for the set message type on this message |
|
252 | + * |
|
253 | + * @return EE_message_type | null |
|
254 | + */ |
|
255 | + public function message_type_object() |
|
256 | + { |
|
257 | + return $this->_message_type; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * Sets message_type |
|
263 | + * |
|
264 | + * @param EE_message_type $message_type |
|
265 | + * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
266 | + * the message type or not. |
|
267 | + */ |
|
268 | + public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
269 | + { |
|
270 | + $this->_message_type = $message_type; |
|
271 | + if ($set_priority) { |
|
272 | + $this->set_priority($this->_message_type->get_priority()); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * validates message_type |
|
279 | + * |
|
280 | + * @param bool $throw_exceptions |
|
281 | + * @return bool |
|
282 | + * @throws \EE_Error |
|
283 | + */ |
|
284 | + public function valid_message_type($throw_exceptions = false) |
|
285 | + { |
|
286 | + if ($this->_message_type instanceof EE_message_type) { |
|
287 | + return true; |
|
288 | + } |
|
289 | + if ($throw_exceptions) { |
|
290 | + throw new EE_Error( |
|
291 | + sprintf( |
|
292 | + __( |
|
293 | + 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
294 | + 'event_espresso' |
|
295 | + ), |
|
296 | + $this->message_type() |
|
297 | + ) |
|
298 | + ); |
|
299 | + } |
|
300 | + return false; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
306 | + * |
|
307 | + * @param bool $throw_exceptions |
|
308 | + * @return bool |
|
309 | + * @throws \EE_Error |
|
310 | + */ |
|
311 | + public function is_valid($throw_exceptions = false) |
|
312 | + { |
|
313 | + if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
314 | + return true; |
|
315 | + } |
|
316 | + return false; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * This validates whether the internal messenger and message type objects are valid for sending. |
|
322 | + * Three checks are done: |
|
323 | + * 1. There is a valid messenger object. |
|
324 | + * 2. There is a valid message type object. |
|
325 | + * 3. The message type object is active for the messenger. |
|
326 | + * |
|
327 | + * @throws EE_Error But only if $throw_exceptions is set to true. |
|
328 | + * @param bool $throw_exceptions |
|
329 | + * @return bool |
|
330 | + */ |
|
331 | + public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
332 | + { |
|
333 | + $valid = false; |
|
334 | + if ($this->is_valid($throw_exceptions)) { |
|
335 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
336 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
337 | + $valid = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(), |
|
338 | + $this->message_type()); |
|
339 | + if ( ! $valid && $throw_exceptions) { |
|
340 | + throw new EE_Error( |
|
341 | + sprintf( |
|
342 | + __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
343 | + 'event_espresso'), |
|
344 | + $this->message_type(), |
|
345 | + $this->messenger() |
|
346 | + ) |
|
347 | + ); |
|
348 | + } |
|
349 | + } |
|
350 | + return $valid; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * This returns the set localized label for the message type on this message. |
|
356 | + * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
357 | + * with this message. |
|
358 | + * |
|
359 | + * @param bool $plural whether to return the plural label or not. |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + public function message_type_label($plural = false) |
|
363 | + { |
|
364 | + $label_type = $plural ? 'plural' : 'singular'; |
|
365 | + $message_type = $this->message_type_object(); |
|
366 | + return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace( |
|
367 | + '_', |
|
368 | + ' ', |
|
369 | + $this->message_type() |
|
370 | + ); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * Gets context |
|
376 | + * |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function context() |
|
380 | + { |
|
381 | + return $this->get('MSG_context'); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
387 | + * types. Otherwise, this will just return the set context slug on this object. |
|
388 | + * |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function context_label() |
|
392 | + { |
|
393 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
394 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
395 | + $contexts = $message_resource_manager->get_all_contexts(); |
|
396 | + return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Sets context |
|
402 | + * |
|
403 | + * @param string $context |
|
404 | + */ |
|
405 | + public function set_context($context) |
|
406 | + { |
|
407 | + $this->set('MSG_context', $context); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Gets recipient_ID |
|
413 | + * |
|
414 | + * @return int |
|
415 | + */ |
|
416 | + public function recipient_ID() |
|
417 | + { |
|
418 | + return $this->get('MSG_recipient_ID'); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Sets recipient_ID |
|
424 | + * |
|
425 | + * @param string $recipient_ID |
|
426 | + */ |
|
427 | + public function set_recipient_ID($recipient_ID) |
|
428 | + { |
|
429 | + $this->set('MSG_recipient_ID', $recipient_ID); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Gets recipient_type |
|
435 | + * |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function recipient_type() |
|
439 | + { |
|
440 | + return $this->get('MSG_recipient_type'); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Return the related object matching the recipient type and ID. |
|
446 | + * |
|
447 | + * @return EE_Base_Class | null |
|
448 | + */ |
|
449 | + public function recipient_object() |
|
450 | + { |
|
451 | + if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
452 | + return null; |
|
453 | + } |
|
454 | + |
|
455 | + return $this->get_first_related($this->recipient_type()); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Sets recipient_type |
|
461 | + * |
|
462 | + * @param string $recipient_type |
|
463 | + */ |
|
464 | + public function set_recipient_type($recipient_type) |
|
465 | + { |
|
466 | + $this->set('MSG_recipient_type', $recipient_type); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Gets content |
|
472 | + * |
|
473 | + * @return string |
|
474 | + */ |
|
475 | + public function content() |
|
476 | + { |
|
477 | + return $this->get('MSG_content'); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Sets content |
|
483 | + * |
|
484 | + * @param string $content |
|
485 | + */ |
|
486 | + public function set_content($content) |
|
487 | + { |
|
488 | + $this->set('MSG_content', $content); |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * Gets subject |
|
494 | + * |
|
495 | + * @return string |
|
496 | + */ |
|
497 | + public function subject() |
|
498 | + { |
|
499 | + return $this->get('MSG_subject'); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Sets subject |
|
505 | + * |
|
506 | + * @param string $subject |
|
507 | + */ |
|
508 | + public function set_subject($subject) |
|
509 | + { |
|
510 | + $this->set('MSG_subject', $subject); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Gets to |
|
516 | + * |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function to() |
|
520 | + { |
|
521 | + $to = $this->get('MSG_to'); |
|
522 | + return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * Sets to |
|
528 | + * |
|
529 | + * @param string $to |
|
530 | + */ |
|
531 | + public function set_to($to) |
|
532 | + { |
|
533 | + $this->set('MSG_to', $to); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Gets from |
|
539 | + * |
|
540 | + * @return string |
|
541 | + */ |
|
542 | + public function from() |
|
543 | + { |
|
544 | + return $this->get('MSG_from'); |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * Sets from |
|
550 | + * |
|
551 | + * @param string $from |
|
552 | + */ |
|
553 | + public function set_from($from) |
|
554 | + { |
|
555 | + $this->set('MSG_from', $from); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Gets priority |
|
561 | + * |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function priority() |
|
565 | + { |
|
566 | + return $this->get('MSG_priority'); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * Sets priority |
|
572 | + * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
573 | + * this method calls the send_now method to verify that. |
|
574 | + * |
|
575 | + * @param int $priority |
|
576 | + */ |
|
577 | + public function set_priority($priority) |
|
578 | + { |
|
579 | + $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
580 | + parent::set('MSG_priority', $priority); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Overrides parent::set method so we can capture any sets for priority. |
|
586 | + * |
|
587 | + * @see parent::set() for phpdocs |
|
588 | + * @param string $field_name |
|
589 | + * @param mixed $field_value |
|
590 | + * @param bool $use_default |
|
591 | + * @throws EE_Error |
|
592 | + */ |
|
593 | + public function set($field_name, $field_value, $use_default = false) |
|
594 | + { |
|
595 | + if ($field_name === 'MSG_priority') { |
|
596 | + $this->set_priority($field_value); |
|
597 | + } |
|
598 | + parent::set($field_name, $field_value, $use_default); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @return bool |
|
604 | + * @throws \EE_Error |
|
605 | + */ |
|
606 | + public function send_now() |
|
607 | + { |
|
608 | + $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority(); |
|
609 | + return $send_now === EEM_Message::priority_high ? true : false; |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Gets STS_ID |
|
615 | + * |
|
616 | + * @return string |
|
617 | + */ |
|
618 | + public function STS_ID() |
|
619 | + { |
|
620 | + return $this->get('STS_ID'); |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Sets STS_ID |
|
626 | + * |
|
627 | + * @param string $STS_ID |
|
628 | + */ |
|
629 | + public function set_STS_ID($STS_ID) |
|
630 | + { |
|
631 | + $this->set('STS_ID', $STS_ID); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * Gets created |
|
637 | + * |
|
638 | + * @return string |
|
639 | + */ |
|
640 | + public function created() |
|
641 | + { |
|
642 | + return $this->get('MSG_created'); |
|
643 | + } |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * Sets created |
|
648 | + * |
|
649 | + * @param string $created |
|
650 | + */ |
|
651 | + public function set_created($created) |
|
652 | + { |
|
653 | + $this->set('MSG_created', $created); |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + /** |
|
658 | + * Gets modified |
|
659 | + * |
|
660 | + * @return string |
|
661 | + */ |
|
662 | + public function modified() |
|
663 | + { |
|
664 | + return $this->get('MSG_modified'); |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * Sets modified |
|
670 | + * |
|
671 | + * @param string $modified |
|
672 | + */ |
|
673 | + public function set_modified($modified) |
|
674 | + { |
|
675 | + $this->set('MSG_modified', $modified); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * Sets generation data for this message. |
|
681 | + * |
|
682 | + * @param mixed $data |
|
683 | + */ |
|
684 | + public function set_generation_data($data) |
|
685 | + { |
|
686 | + $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * Returns any set generation data for this message. |
|
692 | + * |
|
693 | + * @return mixed|null |
|
694 | + */ |
|
695 | + public function get_generation_data() |
|
696 | + { |
|
697 | + return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * Gets any error message. |
|
703 | + * |
|
704 | + * @return mixed|null |
|
705 | + */ |
|
706 | + public function error_message() |
|
707 | + { |
|
708 | + return $this->get_field_or_extra_meta('MSG_error'); |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * Sets an error message. |
|
714 | + * |
|
715 | + * @param $message |
|
716 | + * @return bool|int |
|
717 | + */ |
|
718 | + public function set_error_message($message) |
|
719 | + { |
|
720 | + return $this->set_field_or_extra_meta('MSG_error', $message); |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * This retrieves the associated template pack with this message. |
|
726 | + * |
|
727 | + * @return EE_Messages_Template_Pack | null |
|
728 | + */ |
|
729 | + public function get_template_pack() |
|
730 | + { |
|
731 | + /** |
|
732 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
733 | + */ |
|
734 | + if ( ! empty($this->template_pack)) { |
|
735 | + return $this->template_pack; |
|
736 | + } |
|
737 | + /** @type EE_Message_Template_Group $grp */ |
|
738 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
739 | + //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
740 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
741 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
742 | + array( |
|
743 | + array( |
|
744 | + 'MTP_messenger' => $this->messenger(), |
|
745 | + 'MTP_message_type' => $this->message_type(), |
|
746 | + 'MTP_is_global' => true, |
|
747 | + ), |
|
748 | + ) |
|
749 | + ); |
|
750 | + } |
|
751 | + |
|
752 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * Retrieves the variation used for generating this message. |
|
758 | + * |
|
759 | + * @return string |
|
760 | + */ |
|
761 | + public function get_template_pack_variation() |
|
762 | + { |
|
763 | + /** |
|
764 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
765 | + */ |
|
766 | + if ( ! empty($this->template_variation)) { |
|
767 | + return $this->template_variation; |
|
768 | + } |
|
769 | + |
|
770 | + /** @type EE_Message_Template_Group $grp */ |
|
771 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
772 | + |
|
773 | + //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
774 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
775 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
776 | + array( |
|
777 | + array( |
|
778 | + 'MTP_messenger' => $this->messenger(), |
|
779 | + 'MTP_message_type' => $this->message_type(), |
|
780 | + 'MTP_is_global' => true, |
|
781 | + ), |
|
782 | + ) |
|
783 | + ); |
|
784 | + } |
|
785 | + |
|
786 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Return the link to the admin details for the object. |
|
791 | + * |
|
792 | + * @return string |
|
793 | + */ |
|
794 | + public function get_admin_details_link() |
|
795 | + { |
|
796 | + EE_Registry::instance()->load_helper('URL'); |
|
797 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
798 | + switch ($this->STS_ID()) { |
|
799 | + case EEM_Message::status_failed : |
|
800 | + case EEM_Message::status_debug_only : |
|
801 | + return EEH_MSG_Template::generate_error_display_trigger($this); |
|
802 | + break; |
|
803 | + |
|
804 | + case EEM_Message::status_sent : |
|
805 | + return EEH_MSG_Template::generate_browser_trigger($this); |
|
806 | + break; |
|
807 | + |
|
808 | + default : |
|
809 | + return ''; |
|
810 | + } |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
815 | + * |
|
816 | + * @return string |
|
817 | + */ |
|
818 | + public function get_admin_edit_link() |
|
819 | + { |
|
820 | + return $this->get_admin_details_link(); |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Returns the link to a settings page for the object. |
|
825 | + * |
|
826 | + * @return string |
|
827 | + */ |
|
828 | + public function get_admin_settings_link() |
|
829 | + { |
|
830 | + EE_Registry::instance()->load_helper('URL'); |
|
831 | + return EEH_URL::add_query_args_and_nonce( |
|
832 | + array( |
|
833 | + 'page' => 'espresso_messages', |
|
834 | + 'action' => 'settings', |
|
835 | + ), |
|
836 | + admin_url('admin.php') |
|
837 | + ); |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
842 | + * |
|
843 | + * @return string |
|
844 | + */ |
|
845 | + public function get_admin_overview_link() |
|
846 | + { |
|
847 | + EE_Registry::instance()->load_helper('URL'); |
|
848 | + return EEH_URL::add_query_args_and_nonce( |
|
849 | + array( |
|
850 | + 'page' => 'espresso_messages', |
|
851 | + 'action' => 'default', |
|
852 | + ), |
|
853 | + admin_url('admin.php') |
|
854 | + ); |
|
855 | + } |
|
856 | + |
|
857 | + |
|
858 | + /** |
|
859 | + * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
860 | + * it. |
|
861 | + * Note this also SAVES the current message object to the db because it adds an error message to accompany the status. |
|
862 | + * |
|
863 | + */ |
|
864 | + public function set_messenger_is_executing() |
|
865 | + { |
|
866 | + $this->set_STS_ID( EEM_Message::status_messenger_executing ); |
|
867 | + $this->set_error_message( |
|
868 | + esc_html__( |
|
869 | + 'A message with this status indicates that there was a problem that occurred while the message was being |
|
870 | 870 | processed by the messenger. It is still possible that the message was sent successfully, but at some |
871 | 871 | point during the processing there was a failure. This usually is indicative of a timeout issue with PHP |
872 | 872 | or memory limits being reached. If you see this repeatedly you may want to consider upgrading the memory |
873 | 873 | available to PHP on your server.', |
874 | - 'event_espresso' |
|
875 | - ) |
|
876 | - ); |
|
877 | - } |
|
874 | + 'event_espresso' |
|
875 | + ) |
|
876 | + ); |
|
877 | + } |
|
878 | 878 | } |
879 | 879 | /* End of file EE_Message.class.php */ |
880 | 880 | /* Location: /core/db_classes/EE_Message.class.php */ |
881 | 881 | \ No newline at end of file |
@@ -13,72 +13,72 @@ |
||
13 | 13 | trait BaseCoreAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Core method for going to an Event Espresso Admin page. |
|
18 | - * @param string $page |
|
19 | - * @param string $action |
|
20 | - * @param string $additional_params |
|
21 | - */ |
|
22 | - public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | - { |
|
24 | - $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Core method for going to an Event Espresso Admin page. |
|
18 | + * @param string $page |
|
19 | + * @param string $action |
|
20 | + * @param string $additional_params |
|
21 | + */ |
|
22 | + public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | + { |
|
24 | + $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | - * @return \EventEspressoAcceptanceTester; |
|
31 | - */ |
|
32 | - protected function actor() |
|
33 | - { |
|
34 | - /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | - return $this; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | + * @return \EventEspressoAcceptanceTester; |
|
31 | + */ |
|
32 | + protected function actor() |
|
33 | + { |
|
34 | + /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | + return $this; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Use this to set the per page option for a list table page. |
|
41 | - * Assumes you are on a page that has this field exposed. |
|
42 | - * |
|
43 | - * @param int|string $per_page_value |
|
44 | - * @throws \Codeception\Exception\TestRuntimeException |
|
45 | - */ |
|
46 | - public function setPerPageOptionForScreen($per_page_value) |
|
47 | - { |
|
48 | - $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
49 | - $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
50 | - $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
51 | - $this->actor()->wait(8); |
|
52 | - } |
|
39 | + /** |
|
40 | + * Use this to set the per page option for a list table page. |
|
41 | + * Assumes you are on a page that has this field exposed. |
|
42 | + * |
|
43 | + * @param int|string $per_page_value |
|
44 | + * @throws \Codeception\Exception\TestRuntimeException |
|
45 | + */ |
|
46 | + public function setPerPageOptionForScreen($per_page_value) |
|
47 | + { |
|
48 | + $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
49 | + $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
50 | + $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
51 | + $this->actor()->wait(8); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Use this to append a given value to a wpEditor instance. |
|
58 | - * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
59 | - * the value is added to the text area. |
|
60 | - * |
|
61 | - * @param $field_reference |
|
62 | - * @param $value |
|
63 | - * @throws \Codeception\Exception\ElementNotFound |
|
64 | - */ |
|
65 | - public function appendToWPEditorField($field_reference, $value) |
|
66 | - { |
|
67 | - $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
68 | - $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
69 | - } |
|
56 | + /** |
|
57 | + * Use this to append a given value to a wpEditor instance. |
|
58 | + * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
59 | + * the value is added to the text area. |
|
60 | + * |
|
61 | + * @param $field_reference |
|
62 | + * @param $value |
|
63 | + * @throws \Codeception\Exception\ElementNotFound |
|
64 | + */ |
|
65 | + public function appendToWPEditorField($field_reference, $value) |
|
66 | + { |
|
67 | + $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
68 | + $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Use to select and submit the given bulk action. |
|
74 | - * @param string $bulk_action_option |
|
75 | - */ |
|
76 | - public function submitBulkActionOnListTable($bulk_action_option) |
|
77 | - { |
|
78 | - $this->actor()->selectOption( |
|
79 | - CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
80 | - $bulk_action_option |
|
81 | - ); |
|
82 | - $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
83 | - } |
|
72 | + /** |
|
73 | + * Use to select and submit the given bulk action. |
|
74 | + * @param string $bulk_action_option |
|
75 | + */ |
|
76 | + public function submitBulkActionOnListTable($bulk_action_option) |
|
77 | + { |
|
78 | + $this->actor()->selectOption( |
|
79 | + CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
80 | + $bulk_action_option |
|
81 | + ); |
|
82 | + $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
83 | + } |
|
84 | 84 | } |
@@ -13,30 +13,30 @@ |
||
13 | 13 | trait RegistrationsAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * This will select all checkboxes on a registration list table for the given array of |
|
18 | - * registration ids. |
|
19 | - * Assumes the actor is on a list table page for registrations. |
|
20 | - * @param $registration_ids |
|
21 | - */ |
|
22 | - public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
23 | - { |
|
24 | - foreach ($registration_ids as $registration_id) { |
|
25 | - $this->actor()->checkOption( |
|
26 | - RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
27 | - ); |
|
28 | - } |
|
29 | - } |
|
16 | + /** |
|
17 | + * This will select all checkboxes on a registration list table for the given array of |
|
18 | + * registration ids. |
|
19 | + * Assumes the actor is on a list table page for registrations. |
|
20 | + * @param $registration_ids |
|
21 | + */ |
|
22 | + public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
23 | + { |
|
24 | + foreach ($registration_ids as $registration_id) { |
|
25 | + $this->actor()->checkOption( |
|
26 | + RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
27 | + ); |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Navigates the actor to the default registration list table page. |
|
34 | - * @param string $additional_params |
|
35 | - */ |
|
36 | - public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage( |
|
39 | - RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
40 | - ); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Navigates the actor to the default registration list table page. |
|
34 | + * @param string $additional_params |
|
35 | + */ |
|
36 | + public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage( |
|
39 | + RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -13,70 +13,70 @@ |
||
13 | 13 | */ |
14 | 14 | trait Checkout |
15 | 15 | { |
16 | - /** |
|
17 | - * @param $value |
|
18 | - * @param int $attendee_number |
|
19 | - */ |
|
20 | - public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
21 | - { |
|
22 | - $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
23 | - } |
|
16 | + /** |
|
17 | + * @param $value |
|
18 | + * @param int $attendee_number |
|
19 | + */ |
|
20 | + public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
21 | + { |
|
22 | + $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param $value |
|
27 | - * @param int $attendee_number |
|
28 | - */ |
|
29 | - public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
30 | - { |
|
31 | - $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
32 | - } |
|
25 | + /** |
|
26 | + * @param $value |
|
27 | + * @param int $attendee_number |
|
28 | + */ |
|
29 | + public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
30 | + { |
|
31 | + $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param $value |
|
36 | - * @param int $attendee_number |
|
37 | - */ |
|
38 | - public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
39 | - { |
|
40 | - $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
41 | - } |
|
34 | + /** |
|
35 | + * @param $value |
|
36 | + * @param int $attendee_number |
|
37 | + */ |
|
38 | + public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
39 | + { |
|
40 | + $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Clicks the next registration step button. |
|
46 | - */ |
|
47 | - public function goToNextRegistrationStep() |
|
48 | - { |
|
49 | - $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
50 | - } |
|
44 | + /** |
|
45 | + * Clicks the next registration step button. |
|
46 | + */ |
|
47 | + public function goToNextRegistrationStep() |
|
48 | + { |
|
49 | + $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * Selects the payment option for the given payment method slug. |
|
55 | - * |
|
56 | - * @param string $payment_method_slug |
|
57 | - * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
58 | - * payment option select box is complete. Otherwise its up to calling code to |
|
59 | - * wait for whatever is needed after selecting the payment method. |
|
60 | - */ |
|
61 | - public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
62 | - { |
|
63 | - $this->actor()->selectOption( |
|
64 | - CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
65 | - $payment_method_slug |
|
66 | - ); |
|
67 | - if ($verify_selected) { |
|
68 | - $this->actor()->waitForText('Important information regarding your payment'); |
|
69 | - } |
|
70 | - } |
|
53 | + /** |
|
54 | + * Selects the payment option for the given payment method slug. |
|
55 | + * |
|
56 | + * @param string $payment_method_slug |
|
57 | + * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
58 | + * payment option select box is complete. Otherwise its up to calling code to |
|
59 | + * wait for whatever is needed after selecting the payment method. |
|
60 | + */ |
|
61 | + public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
62 | + { |
|
63 | + $this->actor()->selectOption( |
|
64 | + CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
65 | + $payment_method_slug |
|
66 | + ); |
|
67 | + if ($verify_selected) { |
|
68 | + $this->actor()->waitForText('Important information regarding your payment'); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * Submits the payment options step form. |
|
75 | - * Assumes the actor is in the context of the payment options SPCO step. |
|
76 | - */ |
|
77 | - public function submitPaymentOptionsRegistrationStepForm() |
|
78 | - { |
|
79 | - $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
80 | - } |
|
73 | + /** |
|
74 | + * Submits the payment options step form. |
|
75 | + * Assumes the actor is in the context of the payment options SPCO step. |
|
76 | + */ |
|
77 | + public function submitPaymentOptionsRegistrationStepForm() |
|
78 | + { |
|
79 | + $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | \ No newline at end of file |