@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * Returns template for the additional datetime. |
340 | 340 | * @param $template |
341 | 341 | * @param $template_args |
342 | - * @return mixed |
|
342 | + * @return string |
|
343 | 343 | * @throws DomainException |
344 | 344 | */ |
345 | 345 | public function add_additional_datetime_button($template, $template_args) |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * Returns the template for cloning a datetime. |
357 | 357 | * @param $template |
358 | 358 | * @param $template_args |
359 | - * @return mixed |
|
359 | + * @return string |
|
360 | 360 | * @throws DomainException |
361 | 361 | */ |
362 | 362 | public function add_datetime_clone_button($template, $template_args) |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * Returns the template for datetime timezones. |
374 | 374 | * @param $template |
375 | 375 | * @param $template_args |
376 | - * @return mixed |
|
376 | + * @return string |
|
377 | 377 | * @throws DomainException |
378 | 378 | */ |
379 | 379 | public function datetime_timezones_template($template, $template_args) |
@@ -14,1239 +14,1239 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * Extend_Events_Admin_Page constructor. |
|
19 | - * |
|
20 | - * @param bool $routing |
|
21 | - */ |
|
22 | - public function __construct($routing = true) |
|
23 | - { |
|
24 | - parent::__construct($routing); |
|
25 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
27 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
28 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
29 | - } |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Sets routes. |
|
35 | - */ |
|
36 | - protected function _extend_page_config() |
|
37 | - { |
|
38 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
39 | - //is there a evt_id in the request? |
|
40 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
41 | - ? $this->_req_data['EVT_ID'] |
|
42 | - : 0; |
|
43 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
44 | - //tkt_id? |
|
45 | - $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
46 | - ? $this->_req_data['TKT_ID'] |
|
47 | - : 0; |
|
48 | - $new_page_routes = array( |
|
49 | - 'duplicate_event' => array( |
|
50 | - 'func' => '_duplicate_event', |
|
51 | - 'capability' => 'ee_edit_event', |
|
52 | - 'obj_id' => $evt_id, |
|
53 | - 'noheader' => true, |
|
54 | - ), |
|
55 | - 'ticket_list_table' => array( |
|
56 | - 'func' => '_tickets_overview_list_table', |
|
57 | - 'capability' => 'ee_read_default_tickets', |
|
58 | - ), |
|
59 | - 'trash_ticket' => array( |
|
60 | - 'func' => '_trash_or_restore_ticket', |
|
61 | - 'capability' => 'ee_delete_default_ticket', |
|
62 | - 'obj_id' => $tkt_id, |
|
63 | - 'noheader' => true, |
|
64 | - 'args' => array('trash' => true), |
|
65 | - ), |
|
66 | - 'trash_tickets' => array( |
|
67 | - 'func' => '_trash_or_restore_ticket', |
|
68 | - 'capability' => 'ee_delete_default_tickets', |
|
69 | - 'noheader' => true, |
|
70 | - 'args' => array('trash' => true), |
|
71 | - ), |
|
72 | - 'restore_ticket' => array( |
|
73 | - 'func' => '_trash_or_restore_ticket', |
|
74 | - 'capability' => 'ee_delete_default_ticket', |
|
75 | - 'obj_id' => $tkt_id, |
|
76 | - 'noheader' => true, |
|
77 | - ), |
|
78 | - 'restore_tickets' => array( |
|
79 | - 'func' => '_trash_or_restore_ticket', |
|
80 | - 'capability' => 'ee_delete_default_tickets', |
|
81 | - 'noheader' => true, |
|
82 | - ), |
|
83 | - 'delete_ticket' => array( |
|
84 | - 'func' => '_delete_ticket', |
|
85 | - 'capability' => 'ee_delete_default_ticket', |
|
86 | - 'obj_id' => $tkt_id, |
|
87 | - 'noheader' => true, |
|
88 | - ), |
|
89 | - 'delete_tickets' => array( |
|
90 | - 'func' => '_delete_ticket', |
|
91 | - 'capability' => 'ee_delete_default_tickets', |
|
92 | - 'noheader' => true, |
|
93 | - ), |
|
94 | - 'import_page' => array( |
|
95 | - 'func' => '_import_page', |
|
96 | - 'capability' => 'import', |
|
97 | - ), |
|
98 | - 'import' => array( |
|
99 | - 'func' => '_import_events', |
|
100 | - 'capability' => 'import', |
|
101 | - 'noheader' => true, |
|
102 | - ), |
|
103 | - 'import_events' => array( |
|
104 | - 'func' => '_import_events', |
|
105 | - 'capability' => 'import', |
|
106 | - 'noheader' => true, |
|
107 | - ), |
|
108 | - 'export_events' => array( |
|
109 | - 'func' => '_events_export', |
|
110 | - 'capability' => 'export', |
|
111 | - 'noheader' => true, |
|
112 | - ), |
|
113 | - 'export_categories' => array( |
|
114 | - 'func' => '_categories_export', |
|
115 | - 'capability' => 'export', |
|
116 | - 'noheader' => true, |
|
117 | - ), |
|
118 | - 'sample_export_file' => array( |
|
119 | - 'func' => '_sample_export_file', |
|
120 | - 'capability' => 'export', |
|
121 | - 'noheader' => true, |
|
122 | - ), |
|
123 | - 'update_template_settings' => array( |
|
124 | - 'func' => '_update_template_settings', |
|
125 | - 'capability' => 'manage_options', |
|
126 | - 'noheader' => true, |
|
127 | - ), |
|
128 | - ); |
|
129 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
130 | - //partial route/config override |
|
131 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
132 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
133 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
135 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
136 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
137 | - //add tickets tab but only if there are more than one default ticket! |
|
138 | - $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
139 | - array(array('TKT_is_default' => 1)), |
|
140 | - 'TKT_ID', |
|
141 | - true |
|
142 | - ); |
|
143 | - if ($tkt_count > 1) { |
|
144 | - $new_page_config = array( |
|
145 | - 'ticket_list_table' => array( |
|
146 | - 'nav' => array( |
|
147 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
148 | - 'order' => 60, |
|
149 | - ), |
|
150 | - 'list_table' => 'Tickets_List_Table', |
|
151 | - 'require_nonce' => false, |
|
152 | - ), |
|
153 | - ); |
|
154 | - } |
|
155 | - //template settings |
|
156 | - $new_page_config['template_settings'] = array( |
|
157 | - 'nav' => array( |
|
158 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
159 | - 'order' => 30, |
|
160 | - ), |
|
161 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
162 | - 'help_tabs' => array( |
|
163 | - 'general_settings_templates_help_tab' => array( |
|
164 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
165 | - 'filename' => 'general_settings_templates', |
|
166 | - ), |
|
167 | - ), |
|
168 | - 'help_tour' => array('Templates_Help_Tour'), |
|
169 | - 'require_nonce' => false, |
|
170 | - ); |
|
171 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
172 | - //add filters and actions |
|
173 | - //modifying _views |
|
174 | - add_filter( |
|
175 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
176 | - array($this, 'add_additional_datetime_button'), |
|
177 | - 10, |
|
178 | - 2 |
|
179 | - ); |
|
180 | - add_filter( |
|
181 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
182 | - array($this, 'add_datetime_clone_button'), |
|
183 | - 10, |
|
184 | - 2 |
|
185 | - ); |
|
186 | - add_filter( |
|
187 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
188 | - array($this, 'datetime_timezones_template'), |
|
189 | - 10, |
|
190 | - 2 |
|
191 | - ); |
|
192 | - //filters for event list table |
|
193 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
194 | - add_filter( |
|
195 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
196 | - array($this, 'extra_list_table_actions'), |
|
197 | - 10, |
|
198 | - 2 |
|
199 | - ); |
|
200 | - //legend item |
|
201 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
202 | - add_action('admin_init', array($this, 'admin_init')); |
|
203 | - //heartbeat stuff |
|
204 | - add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * admin_init |
|
210 | - */ |
|
211 | - public function admin_init() |
|
212 | - { |
|
213 | - EE_Registry::$i18n_js_strings = array_merge( |
|
214 | - EE_Registry::$i18n_js_strings, |
|
215 | - array( |
|
216 | - 'image_confirm' => esc_html__( |
|
217 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
221 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
222 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
223 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
224 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
225 | - ) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
232 | - * accordingly. |
|
233 | - * |
|
234 | - * @param array $response The existing heartbeat response array. |
|
235 | - * @param array $data The incoming data package. |
|
236 | - * @return array possibly appended response. |
|
237 | - */ |
|
238 | - public function heartbeat_response($response, $data) |
|
239 | - { |
|
240 | - /** |
|
241 | - * check whether count of tickets is approaching the potential |
|
242 | - * limits for the server. |
|
243 | - */ |
|
244 | - if (! empty($data['input_count'])) { |
|
245 | - $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
246 | - $data['input_count'] |
|
247 | - ); |
|
248 | - } |
|
249 | - return $response; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * Add per page screen options to the default ticket list table view. |
|
255 | - */ |
|
256 | - protected function _add_screen_options_ticket_list_table() |
|
257 | - { |
|
258 | - $this->_per_page_screen_option(); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @param string $return |
|
264 | - * @param int $id |
|
265 | - * @param string $new_title |
|
266 | - * @param string $new_slug |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
270 | - { |
|
271 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
272 | - //make sure this is only when editing |
|
273 | - if (! empty($id)) { |
|
274 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
275 | - array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
276 | - $this->_admin_base_url |
|
277 | - ); |
|
278 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
279 | - $return .= '<a href="' |
|
280 | - . $href |
|
281 | - . '" title="' |
|
282 | - . $title |
|
283 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
284 | - . $title |
|
285 | - . '</button>'; |
|
286 | - } |
|
287 | - return $return; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Set the list table views for the default ticket list table view. |
|
293 | - */ |
|
294 | - public function _set_list_table_views_ticket_list_table() |
|
295 | - { |
|
296 | - $this->_views = array( |
|
297 | - 'all' => array( |
|
298 | - 'slug' => 'all', |
|
299 | - 'label' => esc_html__('All', 'event_espresso'), |
|
300 | - 'count' => 0, |
|
301 | - 'bulk_action' => array( |
|
302 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
303 | - ), |
|
304 | - ), |
|
305 | - 'trashed' => array( |
|
306 | - 'slug' => 'trashed', |
|
307 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
308 | - 'count' => 0, |
|
309 | - 'bulk_action' => array( |
|
310 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
311 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
312 | - ), |
|
313 | - ), |
|
314 | - ); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Enqueue scripts and styles for the event editor. |
|
320 | - */ |
|
321 | - public function load_scripts_styles_edit() |
|
322 | - { |
|
323 | - wp_register_script( |
|
324 | - 'ee-event-editor-heartbeat', |
|
325 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
326 | - array('ee_admin_js', 'heartbeat'), |
|
327 | - EVENT_ESPRESSO_VERSION, |
|
328 | - true |
|
329 | - ); |
|
330 | - wp_enqueue_script('ee-accounting'); |
|
331 | - //styles |
|
332 | - wp_enqueue_style('espresso-ui-theme'); |
|
333 | - wp_enqueue_script('event_editor_js'); |
|
334 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Returns template for the additional datetime. |
|
340 | - * @param $template |
|
341 | - * @param $template_args |
|
342 | - * @return mixed |
|
343 | - * @throws DomainException |
|
344 | - */ |
|
345 | - public function add_additional_datetime_button($template, $template_args) |
|
346 | - { |
|
347 | - return EEH_Template::display_template( |
|
348 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
349 | - $template_args, |
|
350 | - true |
|
351 | - ); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns the template for cloning a datetime. |
|
357 | - * @param $template |
|
358 | - * @param $template_args |
|
359 | - * @return mixed |
|
360 | - * @throws DomainException |
|
361 | - */ |
|
362 | - public function add_datetime_clone_button($template, $template_args) |
|
363 | - { |
|
364 | - return EEH_Template::display_template( |
|
365 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
366 | - $template_args, |
|
367 | - true |
|
368 | - ); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Returns the template for datetime timezones. |
|
374 | - * @param $template |
|
375 | - * @param $template_args |
|
376 | - * @return mixed |
|
377 | - * @throws DomainException |
|
378 | - */ |
|
379 | - public function datetime_timezones_template($template, $template_args) |
|
380 | - { |
|
381 | - return EEH_Template::display_template( |
|
382 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
383 | - $template_args, |
|
384 | - true |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Sets the views for the default list table view. |
|
391 | - */ |
|
392 | - protected function _set_list_table_views_default() |
|
393 | - { |
|
394 | - parent::_set_list_table_views_default(); |
|
395 | - $new_views = array( |
|
396 | - 'today' => array( |
|
397 | - 'slug' => 'today', |
|
398 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
399 | - 'count' => $this->total_events_today(), |
|
400 | - 'bulk_action' => array( |
|
401 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
402 | - ), |
|
403 | - ), |
|
404 | - 'month' => array( |
|
405 | - 'slug' => 'month', |
|
406 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
407 | - 'count' => $this->total_events_this_month(), |
|
408 | - 'bulk_action' => array( |
|
409 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
410 | - ), |
|
411 | - ), |
|
412 | - ); |
|
413 | - $this->_views = array_merge($this->_views, $new_views); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Returns the extra action links for the default list table view. |
|
419 | - * @param array $action_links |
|
420 | - * @param \EE_Event $event |
|
421 | - * @return array |
|
422 | - * @throws EE_Error |
|
423 | - */ |
|
424 | - public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
425 | - { |
|
426 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
427 | - 'ee_read_registrations', |
|
428 | - 'espresso_registrations_reports', |
|
429 | - $event->ID() |
|
430 | - ) |
|
431 | - ) { |
|
432 | - $reports_query_args = array( |
|
433 | - 'action' => 'reports', |
|
434 | - 'EVT_ID' => $event->ID(), |
|
435 | - ); |
|
436 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
437 | - $action_links[] = '<a href="' |
|
438 | - . $reports_link |
|
439 | - . '" title="' |
|
440 | - . esc_attr__('View Report', 'event_espresso') |
|
441 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
442 | - . "\n\t"; |
|
443 | - } |
|
444 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
445 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
446 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
447 | - 'see_notifications_for', |
|
448 | - null, |
|
449 | - array('EVT_ID' => $event->ID()) |
|
450 | - ); |
|
451 | - } |
|
452 | - return $action_links; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * @param $items |
|
458 | - * @return mixed |
|
459 | - */ |
|
460 | - public function additional_legend_items($items) |
|
461 | - { |
|
462 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
463 | - 'ee_read_registrations', |
|
464 | - 'espresso_registrations_reports' |
|
465 | - ) |
|
466 | - ) { |
|
467 | - $items['reports'] = array( |
|
468 | - 'class' => 'dashicons dashicons-chart-bar', |
|
469 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
470 | - ); |
|
471 | - } |
|
472 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
473 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
474 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
475 | - $items['view_related_messages'] = array( |
|
476 | - 'class' => $related_for_icon['css_class'], |
|
477 | - 'desc' => $related_for_icon['label'], |
|
478 | - ); |
|
479 | - } |
|
480 | - } |
|
481 | - return $items; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * This is the callback method for the duplicate event route |
|
487 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
488 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
489 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
490 | - * After duplication the redirect is to the new event edit page. |
|
491 | - * |
|
492 | - * @return void |
|
493 | - * @access protected |
|
494 | - * @throws EE_Error If EE_Event is not available with given ID |
|
495 | - */ |
|
496 | - protected function _duplicate_event() |
|
497 | - { |
|
498 | - // first make sure the ID for the event is in the request. |
|
499 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
500 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
501 | - EE_Error::add_error( |
|
502 | - esc_html__( |
|
503 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
504 | - 'event_espresso' |
|
505 | - ), |
|
506 | - __FILE__, |
|
507 | - __FUNCTION__, |
|
508 | - __LINE__ |
|
509 | - ); |
|
510 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
511 | - return; |
|
512 | - } |
|
513 | - //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
514 | - $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
515 | - if (! $orig_event instanceof EE_Event) { |
|
516 | - throw new EE_Error( |
|
517 | - sprintf( |
|
518 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
519 | - $this->_req_data['EVT_ID'] |
|
520 | - ) |
|
521 | - ); |
|
522 | - } |
|
523 | - //k now let's clone the $orig_event before getting relations |
|
524 | - $new_event = clone $orig_event; |
|
525 | - //original datetimes |
|
526 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
527 | - //other original relations |
|
528 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
529 | - //reset the ID and modify other details to make it clear this is a dupe |
|
530 | - $new_event->set('EVT_ID', 0); |
|
531 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
532 | - $new_event->set('EVT_name', $new_name); |
|
533 | - $new_event->set( |
|
534 | - 'EVT_slug', |
|
535 | - wp_unique_post_slug( |
|
536 | - sanitize_title($orig_event->name()), |
|
537 | - 0, |
|
538 | - 'publish', |
|
539 | - 'espresso_events', |
|
540 | - 0 |
|
541 | - ) |
|
542 | - ); |
|
543 | - $new_event->set('status', 'draft'); |
|
544 | - //duplicate discussion settings |
|
545 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
546 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
547 | - //save the new event |
|
548 | - $new_event->save(); |
|
549 | - //venues |
|
550 | - foreach ($orig_ven as $ven) { |
|
551 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
552 | - } |
|
553 | - $new_event->save(); |
|
554 | - //now we need to get the question group relations and handle that |
|
555 | - //first primary question groups |
|
556 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
557 | - 'Question_Group', |
|
558 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
559 | - ); |
|
560 | - if (! empty($orig_primary_qgs)) { |
|
561 | - foreach ($orig_primary_qgs as $id => $obj) { |
|
562 | - if ($obj instanceof EE_Question_Group) { |
|
563 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
564 | - } |
|
565 | - } |
|
566 | - } |
|
567 | - //next additional attendee question groups |
|
568 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
569 | - 'Question_Group', |
|
570 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
571 | - ); |
|
572 | - if (! empty($orig_additional_qgs)) { |
|
573 | - foreach ($orig_additional_qgs as $id => $obj) { |
|
574 | - if ($obj instanceof EE_Question_Group) { |
|
575 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
576 | - } |
|
577 | - } |
|
578 | - } |
|
579 | - //now save |
|
580 | - $new_event->save(); |
|
581 | - //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
582 | - $cloned_tickets = array(); |
|
583 | - foreach ($orig_datetimes as $orig_dtt) { |
|
584 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
585 | - continue; |
|
586 | - } |
|
587 | - $new_dtt = clone $orig_dtt; |
|
588 | - $orig_tkts = $orig_dtt->tickets(); |
|
589 | - //save new dtt then add to event |
|
590 | - $new_dtt->set('DTT_ID', 0); |
|
591 | - $new_dtt->set('DTT_sold', 0); |
|
592 | - $new_dtt->set_reserved(0); |
|
593 | - $new_dtt->save(); |
|
594 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
595 | - $new_event->save(); |
|
596 | - //now let's get the ticket relations setup. |
|
597 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
598 | - //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
599 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
600 | - continue; |
|
601 | - } |
|
602 | - //is this ticket archived? If it is then let's skip |
|
603 | - if ($orig_tkt->get('TKT_deleted')) { |
|
604 | - continue; |
|
605 | - } |
|
606 | - // does this original ticket already exist in the clone_tickets cache? |
|
607 | - // If so we'll just use the new ticket from it. |
|
608 | - if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
609 | - $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
610 | - } else { |
|
611 | - $new_tkt = clone $orig_tkt; |
|
612 | - //get relations on the $orig_tkt that we need to setup. |
|
613 | - $orig_prices = $orig_tkt->prices(); |
|
614 | - $new_tkt->set('TKT_ID', 0); |
|
615 | - $new_tkt->set('TKT_sold', 0); |
|
616 | - $new_tkt->set('TKT_reserved', 0); |
|
617 | - $new_tkt->save(); //make sure new ticket has ID. |
|
618 | - //price relations on new ticket need to be setup. |
|
619 | - foreach ($orig_prices as $orig_price) { |
|
620 | - $new_price = clone $orig_price; |
|
621 | - $new_price->set('PRC_ID', 0); |
|
622 | - $new_price->save(); |
|
623 | - $new_tkt->_add_relation_to($new_price, 'Price'); |
|
624 | - $new_tkt->save(); |
|
625 | - } |
|
626 | - } |
|
627 | - // k now we can add the new ticket as a relation to the new datetime |
|
628 | - // and make sure its added to our cached $cloned_tickets array |
|
629 | - // for use with later datetimes that have the same ticket. |
|
630 | - $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
631 | - $new_dtt->save(); |
|
632 | - $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
633 | - } |
|
634 | - } |
|
635 | - //clone taxonomy information |
|
636 | - $taxonomies_to_clone_with = apply_filters( |
|
637 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
638 | - array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
639 | - ); |
|
640 | - //get terms for original event (notice) |
|
641 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
642 | - //loop through terms and add them to new event. |
|
643 | - foreach ($orig_terms as $term) { |
|
644 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
645 | - } |
|
646 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
647 | - //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
648 | - if ($new_event->ID()) { |
|
649 | - $redirect_args = array( |
|
650 | - 'post' => $new_event->ID(), |
|
651 | - 'action' => 'edit', |
|
652 | - ); |
|
653 | - EE_Error::add_success( |
|
654 | - esc_html__( |
|
655 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
656 | - 'event_espresso' |
|
657 | - ) |
|
658 | - ); |
|
659 | - } else { |
|
660 | - $redirect_args = array( |
|
661 | - 'action' => 'default', |
|
662 | - ); |
|
663 | - EE_Error::add_error( |
|
664 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
665 | - __FILE__, |
|
666 | - __FUNCTION__, |
|
667 | - __LINE__ |
|
668 | - ); |
|
669 | - } |
|
670 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Generates output for the import page. |
|
676 | - * @throws DomainException |
|
677 | - */ |
|
678 | - protected function _import_page() |
|
679 | - { |
|
680 | - $title = esc_html__('Import', 'event_espresso'); |
|
681 | - $intro = esc_html__( |
|
682 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
683 | - 'event_espresso' |
|
684 | - ); |
|
685 | - $form_url = EVENTS_ADMIN_URL; |
|
686 | - $action = 'import_events'; |
|
687 | - $type = 'csv'; |
|
688 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
689 | - $title, $intro, $form_url, $action, $type |
|
690 | - ); |
|
691 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
692 | - array('action' => 'sample_export_file'), |
|
693 | - $this->_admin_base_url |
|
694 | - ); |
|
695 | - $content = EEH_Template::display_template( |
|
696 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
697 | - $this->_template_args, |
|
698 | - true |
|
699 | - ); |
|
700 | - $this->_template_args['admin_page_content'] = $content; |
|
701 | - $this->display_admin_page_with_sidebar(); |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - /** |
|
706 | - * _import_events |
|
707 | - * This handles displaying the screen and running imports for importing events. |
|
708 | - * |
|
709 | - * @return void |
|
710 | - */ |
|
711 | - protected function _import_events() |
|
712 | - { |
|
713 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
714 | - $success = EE_Import::instance()->import(); |
|
715 | - $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * _events_export |
|
721 | - * Will export all (or just the given event) to a Excel compatible file. |
|
722 | - * |
|
723 | - * @access protected |
|
724 | - * @return void |
|
725 | - */ |
|
726 | - protected function _events_export() |
|
727 | - { |
|
728 | - if (isset($this->_req_data['EVT_ID'])) { |
|
729 | - $event_ids = $this->_req_data['EVT_ID']; |
|
730 | - } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
731 | - $event_ids = $this->_req_data['EVT_IDs']; |
|
732 | - } else { |
|
733 | - $event_ids = null; |
|
734 | - } |
|
735 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
736 | - $new_request_args = array( |
|
737 | - 'export' => 'report', |
|
738 | - 'action' => 'all_event_data', |
|
739 | - 'EVT_ID' => $event_ids, |
|
740 | - ); |
|
741 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
742 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
743 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
744 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
745 | - $EE_Export->export(); |
|
746 | - } |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * handle category exports() |
|
752 | - * |
|
753 | - * @return void |
|
754 | - */ |
|
755 | - protected function _categories_export() |
|
756 | - { |
|
757 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
758 | - $new_request_args = array( |
|
759 | - 'export' => 'report', |
|
760 | - 'action' => 'categories', |
|
761 | - 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
762 | - ); |
|
763 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
764 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
765 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
766 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
767 | - $EE_Export->export(); |
|
768 | - } |
|
769 | - } |
|
770 | - |
|
771 | - |
|
772 | - /** |
|
773 | - * Creates a sample CSV file for importing |
|
774 | - */ |
|
775 | - protected function _sample_export_file() |
|
776 | - { |
|
777 | - // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
778 | - EE_Export::instance()->export_sample(); |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - /************* Template Settings *************/ |
|
783 | - /** |
|
784 | - * Generates template settings page output |
|
785 | - * @throws DomainException |
|
786 | - * @throws EE_Error |
|
787 | - */ |
|
788 | - protected function _template_settings() |
|
789 | - { |
|
790 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
791 | - /** |
|
792 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
793 | - * from General_Settings_Admin_Page to here. |
|
794 | - */ |
|
795 | - $this->_template_args = apply_filters( |
|
796 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
797 | - $this->_template_args |
|
798 | - ); |
|
799 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
800 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
801 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
802 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
803 | - $this->_template_args, |
|
804 | - true |
|
805 | - ); |
|
806 | - $this->display_admin_page_with_sidebar(); |
|
807 | - } |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * Handler for updating template settings. |
|
812 | - */ |
|
813 | - protected function _update_template_settings() |
|
814 | - { |
|
815 | - /** |
|
816 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
817 | - * from General_Settings_Admin_Page to here. |
|
818 | - */ |
|
819 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
820 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
821 | - EE_Registry::instance()->CFG->template_settings, |
|
822 | - $this->_req_data |
|
823 | - ); |
|
824 | - //update custom post type slugs and detect if we need to flush rewrite rules |
|
825 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
826 | - EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
827 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
828 | - : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
829 | - $what = 'Template Settings'; |
|
830 | - $success = $this->_update_espresso_configuration( |
|
831 | - $what, |
|
832 | - EE_Registry::instance()->CFG->template_settings, |
|
833 | - __FILE__, |
|
834 | - __FUNCTION__, |
|
835 | - __LINE__ |
|
836 | - ); |
|
837 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
838 | - update_option('ee_flush_rewrite_rules', true); |
|
839 | - } |
|
840 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
841 | - } |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * _premium_event_editor_meta_boxes |
|
846 | - * add all metaboxes related to the event_editor |
|
847 | - * |
|
848 | - * @access protected |
|
849 | - * @return void |
|
850 | - * @throws EE_Error |
|
851 | - */ |
|
852 | - protected function _premium_event_editor_meta_boxes() |
|
853 | - { |
|
854 | - $this->verify_cpt_object(); |
|
855 | - add_meta_box( |
|
856 | - 'espresso_event_editor_event_options', |
|
857 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
858 | - array($this, 'registration_options_meta_box'), |
|
859 | - $this->page_slug, |
|
860 | - 'side', |
|
861 | - 'core' |
|
862 | - ); |
|
863 | - } |
|
864 | - |
|
865 | - |
|
866 | - /** |
|
867 | - * override caf metabox |
|
868 | - * |
|
869 | - * @return void |
|
870 | - * @throws DomainException |
|
871 | - */ |
|
872 | - public function registration_options_meta_box() |
|
873 | - { |
|
874 | - $yes_no_values = array( |
|
875 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
876 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
877 | - ); |
|
878 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
879 | - array( |
|
880 | - EEM_Registration::status_id_cancelled, |
|
881 | - EEM_Registration::status_id_declined, |
|
882 | - EEM_Registration::status_id_incomplete, |
|
883 | - EEM_Registration::status_id_wait_list, |
|
884 | - ), |
|
885 | - true |
|
886 | - ); |
|
887 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
888 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
889 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
890 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
891 | - 'default_reg_status', |
|
892 | - $default_reg_status_values, |
|
893 | - $this->_cpt_model_obj->default_registration_status() |
|
894 | - ); |
|
895 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
896 | - 'display_desc', |
|
897 | - $yes_no_values, |
|
898 | - $this->_cpt_model_obj->display_description() |
|
899 | - ); |
|
900 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
901 | - 'display_ticket_selector', |
|
902 | - $yes_no_values, |
|
903 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
904 | - '', |
|
905 | - '', |
|
906 | - false |
|
907 | - ); |
|
908 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
909 | - 'EVT_default_registration_status', |
|
910 | - $default_reg_status_values, |
|
911 | - $this->_cpt_model_obj->default_registration_status() |
|
912 | - ); |
|
913 | - $template_args['additional_registration_options'] = apply_filters( |
|
914 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
915 | - '', |
|
916 | - $template_args, |
|
917 | - $yes_no_values, |
|
918 | - $default_reg_status_values |
|
919 | - ); |
|
920 | - EEH_Template::display_template( |
|
921 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
922 | - $template_args |
|
923 | - ); |
|
924 | - } |
|
925 | - |
|
926 | - |
|
927 | - |
|
928 | - /** |
|
929 | - * wp_list_table_mods for caf |
|
930 | - * ============================ |
|
931 | - */ |
|
932 | - /** |
|
933 | - * hook into list table filters and provide filters for caffeinated list table |
|
934 | - * |
|
935 | - * @param array $old_filters any existing filters present |
|
936 | - * @param array $list_table_obj the list table object |
|
937 | - * @return array new filters |
|
938 | - */ |
|
939 | - public function list_table_filters($old_filters, $list_table_obj) |
|
940 | - { |
|
941 | - $filters = array(); |
|
942 | - //first month/year filters |
|
943 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
944 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
945 | - //active status dropdown |
|
946 | - if ($status !== 'draft') { |
|
947 | - $filters[] = $this->active_status_dropdown( |
|
948 | - isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
949 | - ); |
|
950 | - } |
|
951 | - //category filter |
|
952 | - $filters[] = $this->category_dropdown(); |
|
953 | - return array_merge($old_filters, $filters); |
|
954 | - } |
|
955 | - |
|
956 | - |
|
957 | - /** |
|
958 | - * espresso_event_months_dropdown |
|
959 | - * |
|
960 | - * @access public |
|
961 | - * @return string dropdown listing month/year selections for events. |
|
962 | - */ |
|
963 | - public function espresso_event_months_dropdown() |
|
964 | - { |
|
965 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
966 | - // Note we need to include any other filters that are set! |
|
967 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
968 | - //categories? |
|
969 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
970 | - ? $this->_req_data['EVT_CAT'] |
|
971 | - : null; |
|
972 | - //active status? |
|
973 | - $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
974 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
975 | - return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
976 | - } |
|
977 | - |
|
978 | - |
|
979 | - /** |
|
980 | - * returns a list of "active" statuses on the event |
|
981 | - * |
|
982 | - * @param string $current_value whatever the current active status is |
|
983 | - * @return string |
|
984 | - */ |
|
985 | - public function active_status_dropdown($current_value = '') |
|
986 | - { |
|
987 | - $select_name = 'active_status'; |
|
988 | - $values = array( |
|
989 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
990 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
991 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
992 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
993 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
994 | - ); |
|
995 | - $id = 'id="espresso-active-status-dropdown-filter"'; |
|
996 | - $class = 'wide'; |
|
997 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
998 | - } |
|
999 | - |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
1003 | - * |
|
1004 | - * @access public |
|
1005 | - * @return string html |
|
1006 | - */ |
|
1007 | - public function category_dropdown() |
|
1008 | - { |
|
1009 | - $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
1010 | - return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
1011 | - } |
|
1012 | - |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * get total number of events today |
|
1016 | - * |
|
1017 | - * @access public |
|
1018 | - * @return int |
|
1019 | - * @throws EE_Error |
|
1020 | - */ |
|
1021 | - public function total_events_today() |
|
1022 | - { |
|
1023 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1024 | - 'DTT_EVT_start', |
|
1025 | - date('Y-m-d') . ' 00:00:00', |
|
1026 | - 'Y-m-d H:i:s', |
|
1027 | - 'UTC' |
|
1028 | - ); |
|
1029 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1030 | - 'DTT_EVT_start', |
|
1031 | - date('Y-m-d') . ' 23:59:59', |
|
1032 | - 'Y-m-d H:i:s', |
|
1033 | - 'UTC' |
|
1034 | - ); |
|
1035 | - $where = array( |
|
1036 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1037 | - ); |
|
1038 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1039 | - return $count; |
|
1040 | - } |
|
1041 | - |
|
1042 | - |
|
1043 | - /** |
|
1044 | - * get total number of events this month |
|
1045 | - * |
|
1046 | - * @access public |
|
1047 | - * @return int |
|
1048 | - * @throws EE_Error |
|
1049 | - */ |
|
1050 | - public function total_events_this_month() |
|
1051 | - { |
|
1052 | - //Dates |
|
1053 | - $this_year_r = date('Y'); |
|
1054 | - $this_month_r = date('m'); |
|
1055 | - $days_this_month = date('t'); |
|
1056 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1057 | - 'DTT_EVT_start', |
|
1058 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1059 | - 'Y-m-d H:i:s', |
|
1060 | - 'UTC' |
|
1061 | - ); |
|
1062 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1063 | - 'DTT_EVT_start', |
|
1064 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1065 | - 'Y-m-d H:i:s', |
|
1066 | - 'UTC' |
|
1067 | - ); |
|
1068 | - $where = array( |
|
1069 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1070 | - ); |
|
1071 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1072 | - return $count; |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - /** DEFAULT TICKETS STUFF **/ |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * Output default tickets list table view. |
|
1080 | - */ |
|
1081 | - public function _tickets_overview_list_table() |
|
1082 | - { |
|
1083 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1084 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * @param int $per_page |
|
1090 | - * @param bool $count |
|
1091 | - * @param bool $trashed |
|
1092 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
1093 | - */ |
|
1094 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1095 | - { |
|
1096 | - $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
1097 | - $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
1098 | - switch ($orderby) { |
|
1099 | - case 'TKT_name': |
|
1100 | - $orderby = array('TKT_name' => $order); |
|
1101 | - break; |
|
1102 | - case 'TKT_price': |
|
1103 | - $orderby = array('TKT_price' => $order); |
|
1104 | - break; |
|
1105 | - case 'TKT_uses': |
|
1106 | - $orderby = array('TKT_uses' => $order); |
|
1107 | - break; |
|
1108 | - case 'TKT_min': |
|
1109 | - $orderby = array('TKT_min' => $order); |
|
1110 | - break; |
|
1111 | - case 'TKT_max': |
|
1112 | - $orderby = array('TKT_max' => $order); |
|
1113 | - break; |
|
1114 | - case 'TKT_qty': |
|
1115 | - $orderby = array('TKT_qty' => $order); |
|
1116 | - break; |
|
1117 | - } |
|
1118 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
1119 | - ? $this->_req_data['paged'] |
|
1120 | - : 1; |
|
1121 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
1122 | - ? $this->_req_data['perpage'] |
|
1123 | - : $per_page; |
|
1124 | - $_where = array( |
|
1125 | - 'TKT_is_default' => 1, |
|
1126 | - 'TKT_deleted' => $trashed, |
|
1127 | - ); |
|
1128 | - $offset = ($current_page - 1) * $per_page; |
|
1129 | - $limit = array($offset, $per_page); |
|
1130 | - if (isset($this->_req_data['s'])) { |
|
1131 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1132 | - $_where['OR'] = array( |
|
1133 | - 'TKT_name' => array('LIKE', $sstr), |
|
1134 | - 'TKT_description' => array('LIKE', $sstr), |
|
1135 | - ); |
|
1136 | - } |
|
1137 | - $query_params = array( |
|
1138 | - $_where, |
|
1139 | - 'order_by' => $orderby, |
|
1140 | - 'limit' => $limit, |
|
1141 | - 'group_by' => 'TKT_ID', |
|
1142 | - ); |
|
1143 | - if ($count) { |
|
1144 | - return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
1145 | - } else { |
|
1146 | - return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
1147 | - } |
|
1148 | - } |
|
1149 | - |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * @param bool $trash |
|
1153 | - * @throws EE_Error |
|
1154 | - */ |
|
1155 | - protected function _trash_or_restore_ticket($trash = false) |
|
1156 | - { |
|
1157 | - $success = 1; |
|
1158 | - $TKT = EEM_Ticket::instance(); |
|
1159 | - //checkboxes? |
|
1160 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1161 | - //if array has more than one element then success message should be plural |
|
1162 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1163 | - //cycle thru the boxes |
|
1164 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1165 | - if ($trash) { |
|
1166 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1167 | - $success = 0; |
|
1168 | - } |
|
1169 | - } else { |
|
1170 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1171 | - $success = 0; |
|
1172 | - } |
|
1173 | - } |
|
1174 | - } |
|
1175 | - } else { |
|
1176 | - //grab single id and trash |
|
1177 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1178 | - if ($trash) { |
|
1179 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1180 | - $success = 0; |
|
1181 | - } |
|
1182 | - } else { |
|
1183 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1184 | - $success = 0; |
|
1185 | - } |
|
1186 | - } |
|
1187 | - } |
|
1188 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1189 | - $query_args = array( |
|
1190 | - 'action' => 'ticket_list_table', |
|
1191 | - 'status' => $trash ? '' : 'trashed', |
|
1192 | - ); |
|
1193 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1194 | - } |
|
1195 | - |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * Handles trashing default ticket. |
|
1199 | - */ |
|
1200 | - protected function _delete_ticket() |
|
1201 | - { |
|
1202 | - $success = 1; |
|
1203 | - //checkboxes? |
|
1204 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1205 | - //if array has more than one element then success message should be plural |
|
1206 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1207 | - //cycle thru the boxes |
|
1208 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1209 | - //delete |
|
1210 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1211 | - $success = 0; |
|
1212 | - } |
|
1213 | - } |
|
1214 | - } else { |
|
1215 | - //grab single id and trash |
|
1216 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1217 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1218 | - $success = 0; |
|
1219 | - } |
|
1220 | - } |
|
1221 | - $action_desc = 'deleted'; |
|
1222 | - $query_args = array( |
|
1223 | - 'action' => 'ticket_list_table', |
|
1224 | - 'status' => 'trashed', |
|
1225 | - ); |
|
1226 | - //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1227 | - if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1228 | - array(array('TKT_is_default' => 1)), |
|
1229 | - 'TKT_ID', |
|
1230 | - true |
|
1231 | - ) |
|
1232 | - ) { |
|
1233 | - $query_args = array(); |
|
1234 | - } |
|
1235 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1236 | - } |
|
1237 | - |
|
1238 | - |
|
1239 | - /** |
|
1240 | - * @param int $TKT_ID |
|
1241 | - * @return bool|int |
|
1242 | - * @throws EE_Error |
|
1243 | - */ |
|
1244 | - protected function _delete_the_ticket($TKT_ID) |
|
1245 | - { |
|
1246 | - $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1247 | - $tkt->_remove_relations('Datetime'); |
|
1248 | - //delete all related prices first |
|
1249 | - $tkt->delete_related_permanently('Price'); |
|
1250 | - return $tkt->delete_permanently(); |
|
1251 | - } |
|
17 | + /** |
|
18 | + * Extend_Events_Admin_Page constructor. |
|
19 | + * |
|
20 | + * @param bool $routing |
|
21 | + */ |
|
22 | + public function __construct($routing = true) |
|
23 | + { |
|
24 | + parent::__construct($routing); |
|
25 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
27 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
28 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
29 | + } |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Sets routes. |
|
35 | + */ |
|
36 | + protected function _extend_page_config() |
|
37 | + { |
|
38 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
39 | + //is there a evt_id in the request? |
|
40 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
41 | + ? $this->_req_data['EVT_ID'] |
|
42 | + : 0; |
|
43 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
44 | + //tkt_id? |
|
45 | + $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
46 | + ? $this->_req_data['TKT_ID'] |
|
47 | + : 0; |
|
48 | + $new_page_routes = array( |
|
49 | + 'duplicate_event' => array( |
|
50 | + 'func' => '_duplicate_event', |
|
51 | + 'capability' => 'ee_edit_event', |
|
52 | + 'obj_id' => $evt_id, |
|
53 | + 'noheader' => true, |
|
54 | + ), |
|
55 | + 'ticket_list_table' => array( |
|
56 | + 'func' => '_tickets_overview_list_table', |
|
57 | + 'capability' => 'ee_read_default_tickets', |
|
58 | + ), |
|
59 | + 'trash_ticket' => array( |
|
60 | + 'func' => '_trash_or_restore_ticket', |
|
61 | + 'capability' => 'ee_delete_default_ticket', |
|
62 | + 'obj_id' => $tkt_id, |
|
63 | + 'noheader' => true, |
|
64 | + 'args' => array('trash' => true), |
|
65 | + ), |
|
66 | + 'trash_tickets' => array( |
|
67 | + 'func' => '_trash_or_restore_ticket', |
|
68 | + 'capability' => 'ee_delete_default_tickets', |
|
69 | + 'noheader' => true, |
|
70 | + 'args' => array('trash' => true), |
|
71 | + ), |
|
72 | + 'restore_ticket' => array( |
|
73 | + 'func' => '_trash_or_restore_ticket', |
|
74 | + 'capability' => 'ee_delete_default_ticket', |
|
75 | + 'obj_id' => $tkt_id, |
|
76 | + 'noheader' => true, |
|
77 | + ), |
|
78 | + 'restore_tickets' => array( |
|
79 | + 'func' => '_trash_or_restore_ticket', |
|
80 | + 'capability' => 'ee_delete_default_tickets', |
|
81 | + 'noheader' => true, |
|
82 | + ), |
|
83 | + 'delete_ticket' => array( |
|
84 | + 'func' => '_delete_ticket', |
|
85 | + 'capability' => 'ee_delete_default_ticket', |
|
86 | + 'obj_id' => $tkt_id, |
|
87 | + 'noheader' => true, |
|
88 | + ), |
|
89 | + 'delete_tickets' => array( |
|
90 | + 'func' => '_delete_ticket', |
|
91 | + 'capability' => 'ee_delete_default_tickets', |
|
92 | + 'noheader' => true, |
|
93 | + ), |
|
94 | + 'import_page' => array( |
|
95 | + 'func' => '_import_page', |
|
96 | + 'capability' => 'import', |
|
97 | + ), |
|
98 | + 'import' => array( |
|
99 | + 'func' => '_import_events', |
|
100 | + 'capability' => 'import', |
|
101 | + 'noheader' => true, |
|
102 | + ), |
|
103 | + 'import_events' => array( |
|
104 | + 'func' => '_import_events', |
|
105 | + 'capability' => 'import', |
|
106 | + 'noheader' => true, |
|
107 | + ), |
|
108 | + 'export_events' => array( |
|
109 | + 'func' => '_events_export', |
|
110 | + 'capability' => 'export', |
|
111 | + 'noheader' => true, |
|
112 | + ), |
|
113 | + 'export_categories' => array( |
|
114 | + 'func' => '_categories_export', |
|
115 | + 'capability' => 'export', |
|
116 | + 'noheader' => true, |
|
117 | + ), |
|
118 | + 'sample_export_file' => array( |
|
119 | + 'func' => '_sample_export_file', |
|
120 | + 'capability' => 'export', |
|
121 | + 'noheader' => true, |
|
122 | + ), |
|
123 | + 'update_template_settings' => array( |
|
124 | + 'func' => '_update_template_settings', |
|
125 | + 'capability' => 'manage_options', |
|
126 | + 'noheader' => true, |
|
127 | + ), |
|
128 | + ); |
|
129 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
130 | + //partial route/config override |
|
131 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
132 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
133 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
135 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
136 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
137 | + //add tickets tab but only if there are more than one default ticket! |
|
138 | + $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
139 | + array(array('TKT_is_default' => 1)), |
|
140 | + 'TKT_ID', |
|
141 | + true |
|
142 | + ); |
|
143 | + if ($tkt_count > 1) { |
|
144 | + $new_page_config = array( |
|
145 | + 'ticket_list_table' => array( |
|
146 | + 'nav' => array( |
|
147 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
148 | + 'order' => 60, |
|
149 | + ), |
|
150 | + 'list_table' => 'Tickets_List_Table', |
|
151 | + 'require_nonce' => false, |
|
152 | + ), |
|
153 | + ); |
|
154 | + } |
|
155 | + //template settings |
|
156 | + $new_page_config['template_settings'] = array( |
|
157 | + 'nav' => array( |
|
158 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
159 | + 'order' => 30, |
|
160 | + ), |
|
161 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
162 | + 'help_tabs' => array( |
|
163 | + 'general_settings_templates_help_tab' => array( |
|
164 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
165 | + 'filename' => 'general_settings_templates', |
|
166 | + ), |
|
167 | + ), |
|
168 | + 'help_tour' => array('Templates_Help_Tour'), |
|
169 | + 'require_nonce' => false, |
|
170 | + ); |
|
171 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
172 | + //add filters and actions |
|
173 | + //modifying _views |
|
174 | + add_filter( |
|
175 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
176 | + array($this, 'add_additional_datetime_button'), |
|
177 | + 10, |
|
178 | + 2 |
|
179 | + ); |
|
180 | + add_filter( |
|
181 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
182 | + array($this, 'add_datetime_clone_button'), |
|
183 | + 10, |
|
184 | + 2 |
|
185 | + ); |
|
186 | + add_filter( |
|
187 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
188 | + array($this, 'datetime_timezones_template'), |
|
189 | + 10, |
|
190 | + 2 |
|
191 | + ); |
|
192 | + //filters for event list table |
|
193 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
194 | + add_filter( |
|
195 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
196 | + array($this, 'extra_list_table_actions'), |
|
197 | + 10, |
|
198 | + 2 |
|
199 | + ); |
|
200 | + //legend item |
|
201 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
202 | + add_action('admin_init', array($this, 'admin_init')); |
|
203 | + //heartbeat stuff |
|
204 | + add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * admin_init |
|
210 | + */ |
|
211 | + public function admin_init() |
|
212 | + { |
|
213 | + EE_Registry::$i18n_js_strings = array_merge( |
|
214 | + EE_Registry::$i18n_js_strings, |
|
215 | + array( |
|
216 | + 'image_confirm' => esc_html__( |
|
217 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
221 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
222 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
223 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
224 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
232 | + * accordingly. |
|
233 | + * |
|
234 | + * @param array $response The existing heartbeat response array. |
|
235 | + * @param array $data The incoming data package. |
|
236 | + * @return array possibly appended response. |
|
237 | + */ |
|
238 | + public function heartbeat_response($response, $data) |
|
239 | + { |
|
240 | + /** |
|
241 | + * check whether count of tickets is approaching the potential |
|
242 | + * limits for the server. |
|
243 | + */ |
|
244 | + if (! empty($data['input_count'])) { |
|
245 | + $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
246 | + $data['input_count'] |
|
247 | + ); |
|
248 | + } |
|
249 | + return $response; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * Add per page screen options to the default ticket list table view. |
|
255 | + */ |
|
256 | + protected function _add_screen_options_ticket_list_table() |
|
257 | + { |
|
258 | + $this->_per_page_screen_option(); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @param string $return |
|
264 | + * @param int $id |
|
265 | + * @param string $new_title |
|
266 | + * @param string $new_slug |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
270 | + { |
|
271 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
272 | + //make sure this is only when editing |
|
273 | + if (! empty($id)) { |
|
274 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
275 | + array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
276 | + $this->_admin_base_url |
|
277 | + ); |
|
278 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
279 | + $return .= '<a href="' |
|
280 | + . $href |
|
281 | + . '" title="' |
|
282 | + . $title |
|
283 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
284 | + . $title |
|
285 | + . '</button>'; |
|
286 | + } |
|
287 | + return $return; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Set the list table views for the default ticket list table view. |
|
293 | + */ |
|
294 | + public function _set_list_table_views_ticket_list_table() |
|
295 | + { |
|
296 | + $this->_views = array( |
|
297 | + 'all' => array( |
|
298 | + 'slug' => 'all', |
|
299 | + 'label' => esc_html__('All', 'event_espresso'), |
|
300 | + 'count' => 0, |
|
301 | + 'bulk_action' => array( |
|
302 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
303 | + ), |
|
304 | + ), |
|
305 | + 'trashed' => array( |
|
306 | + 'slug' => 'trashed', |
|
307 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
308 | + 'count' => 0, |
|
309 | + 'bulk_action' => array( |
|
310 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
311 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
312 | + ), |
|
313 | + ), |
|
314 | + ); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Enqueue scripts and styles for the event editor. |
|
320 | + */ |
|
321 | + public function load_scripts_styles_edit() |
|
322 | + { |
|
323 | + wp_register_script( |
|
324 | + 'ee-event-editor-heartbeat', |
|
325 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
326 | + array('ee_admin_js', 'heartbeat'), |
|
327 | + EVENT_ESPRESSO_VERSION, |
|
328 | + true |
|
329 | + ); |
|
330 | + wp_enqueue_script('ee-accounting'); |
|
331 | + //styles |
|
332 | + wp_enqueue_style('espresso-ui-theme'); |
|
333 | + wp_enqueue_script('event_editor_js'); |
|
334 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Returns template for the additional datetime. |
|
340 | + * @param $template |
|
341 | + * @param $template_args |
|
342 | + * @return mixed |
|
343 | + * @throws DomainException |
|
344 | + */ |
|
345 | + public function add_additional_datetime_button($template, $template_args) |
|
346 | + { |
|
347 | + return EEH_Template::display_template( |
|
348 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
349 | + $template_args, |
|
350 | + true |
|
351 | + ); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns the template for cloning a datetime. |
|
357 | + * @param $template |
|
358 | + * @param $template_args |
|
359 | + * @return mixed |
|
360 | + * @throws DomainException |
|
361 | + */ |
|
362 | + public function add_datetime_clone_button($template, $template_args) |
|
363 | + { |
|
364 | + return EEH_Template::display_template( |
|
365 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
366 | + $template_args, |
|
367 | + true |
|
368 | + ); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Returns the template for datetime timezones. |
|
374 | + * @param $template |
|
375 | + * @param $template_args |
|
376 | + * @return mixed |
|
377 | + * @throws DomainException |
|
378 | + */ |
|
379 | + public function datetime_timezones_template($template, $template_args) |
|
380 | + { |
|
381 | + return EEH_Template::display_template( |
|
382 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
383 | + $template_args, |
|
384 | + true |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Sets the views for the default list table view. |
|
391 | + */ |
|
392 | + protected function _set_list_table_views_default() |
|
393 | + { |
|
394 | + parent::_set_list_table_views_default(); |
|
395 | + $new_views = array( |
|
396 | + 'today' => array( |
|
397 | + 'slug' => 'today', |
|
398 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
399 | + 'count' => $this->total_events_today(), |
|
400 | + 'bulk_action' => array( |
|
401 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
402 | + ), |
|
403 | + ), |
|
404 | + 'month' => array( |
|
405 | + 'slug' => 'month', |
|
406 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
407 | + 'count' => $this->total_events_this_month(), |
|
408 | + 'bulk_action' => array( |
|
409 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
410 | + ), |
|
411 | + ), |
|
412 | + ); |
|
413 | + $this->_views = array_merge($this->_views, $new_views); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Returns the extra action links for the default list table view. |
|
419 | + * @param array $action_links |
|
420 | + * @param \EE_Event $event |
|
421 | + * @return array |
|
422 | + * @throws EE_Error |
|
423 | + */ |
|
424 | + public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
425 | + { |
|
426 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
427 | + 'ee_read_registrations', |
|
428 | + 'espresso_registrations_reports', |
|
429 | + $event->ID() |
|
430 | + ) |
|
431 | + ) { |
|
432 | + $reports_query_args = array( |
|
433 | + 'action' => 'reports', |
|
434 | + 'EVT_ID' => $event->ID(), |
|
435 | + ); |
|
436 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
437 | + $action_links[] = '<a href="' |
|
438 | + . $reports_link |
|
439 | + . '" title="' |
|
440 | + . esc_attr__('View Report', 'event_espresso') |
|
441 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
442 | + . "\n\t"; |
|
443 | + } |
|
444 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
445 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
446 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
447 | + 'see_notifications_for', |
|
448 | + null, |
|
449 | + array('EVT_ID' => $event->ID()) |
|
450 | + ); |
|
451 | + } |
|
452 | + return $action_links; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * @param $items |
|
458 | + * @return mixed |
|
459 | + */ |
|
460 | + public function additional_legend_items($items) |
|
461 | + { |
|
462 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
463 | + 'ee_read_registrations', |
|
464 | + 'espresso_registrations_reports' |
|
465 | + ) |
|
466 | + ) { |
|
467 | + $items['reports'] = array( |
|
468 | + 'class' => 'dashicons dashicons-chart-bar', |
|
469 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
470 | + ); |
|
471 | + } |
|
472 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
473 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
474 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
475 | + $items['view_related_messages'] = array( |
|
476 | + 'class' => $related_for_icon['css_class'], |
|
477 | + 'desc' => $related_for_icon['label'], |
|
478 | + ); |
|
479 | + } |
|
480 | + } |
|
481 | + return $items; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * This is the callback method for the duplicate event route |
|
487 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
488 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
489 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
490 | + * After duplication the redirect is to the new event edit page. |
|
491 | + * |
|
492 | + * @return void |
|
493 | + * @access protected |
|
494 | + * @throws EE_Error If EE_Event is not available with given ID |
|
495 | + */ |
|
496 | + protected function _duplicate_event() |
|
497 | + { |
|
498 | + // first make sure the ID for the event is in the request. |
|
499 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
500 | + if (! isset($this->_req_data['EVT_ID'])) { |
|
501 | + EE_Error::add_error( |
|
502 | + esc_html__( |
|
503 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
504 | + 'event_espresso' |
|
505 | + ), |
|
506 | + __FILE__, |
|
507 | + __FUNCTION__, |
|
508 | + __LINE__ |
|
509 | + ); |
|
510 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
511 | + return; |
|
512 | + } |
|
513 | + //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
514 | + $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
515 | + if (! $orig_event instanceof EE_Event) { |
|
516 | + throw new EE_Error( |
|
517 | + sprintf( |
|
518 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
519 | + $this->_req_data['EVT_ID'] |
|
520 | + ) |
|
521 | + ); |
|
522 | + } |
|
523 | + //k now let's clone the $orig_event before getting relations |
|
524 | + $new_event = clone $orig_event; |
|
525 | + //original datetimes |
|
526 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
527 | + //other original relations |
|
528 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
529 | + //reset the ID and modify other details to make it clear this is a dupe |
|
530 | + $new_event->set('EVT_ID', 0); |
|
531 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
532 | + $new_event->set('EVT_name', $new_name); |
|
533 | + $new_event->set( |
|
534 | + 'EVT_slug', |
|
535 | + wp_unique_post_slug( |
|
536 | + sanitize_title($orig_event->name()), |
|
537 | + 0, |
|
538 | + 'publish', |
|
539 | + 'espresso_events', |
|
540 | + 0 |
|
541 | + ) |
|
542 | + ); |
|
543 | + $new_event->set('status', 'draft'); |
|
544 | + //duplicate discussion settings |
|
545 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
546 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
547 | + //save the new event |
|
548 | + $new_event->save(); |
|
549 | + //venues |
|
550 | + foreach ($orig_ven as $ven) { |
|
551 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
552 | + } |
|
553 | + $new_event->save(); |
|
554 | + //now we need to get the question group relations and handle that |
|
555 | + //first primary question groups |
|
556 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
557 | + 'Question_Group', |
|
558 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
559 | + ); |
|
560 | + if (! empty($orig_primary_qgs)) { |
|
561 | + foreach ($orig_primary_qgs as $id => $obj) { |
|
562 | + if ($obj instanceof EE_Question_Group) { |
|
563 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
564 | + } |
|
565 | + } |
|
566 | + } |
|
567 | + //next additional attendee question groups |
|
568 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
569 | + 'Question_Group', |
|
570 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
571 | + ); |
|
572 | + if (! empty($orig_additional_qgs)) { |
|
573 | + foreach ($orig_additional_qgs as $id => $obj) { |
|
574 | + if ($obj instanceof EE_Question_Group) { |
|
575 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
576 | + } |
|
577 | + } |
|
578 | + } |
|
579 | + //now save |
|
580 | + $new_event->save(); |
|
581 | + //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
582 | + $cloned_tickets = array(); |
|
583 | + foreach ($orig_datetimes as $orig_dtt) { |
|
584 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
585 | + continue; |
|
586 | + } |
|
587 | + $new_dtt = clone $orig_dtt; |
|
588 | + $orig_tkts = $orig_dtt->tickets(); |
|
589 | + //save new dtt then add to event |
|
590 | + $new_dtt->set('DTT_ID', 0); |
|
591 | + $new_dtt->set('DTT_sold', 0); |
|
592 | + $new_dtt->set_reserved(0); |
|
593 | + $new_dtt->save(); |
|
594 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
595 | + $new_event->save(); |
|
596 | + //now let's get the ticket relations setup. |
|
597 | + foreach ((array)$orig_tkts as $orig_tkt) { |
|
598 | + //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
599 | + if (! $orig_tkt instanceof EE_Ticket) { |
|
600 | + continue; |
|
601 | + } |
|
602 | + //is this ticket archived? If it is then let's skip |
|
603 | + if ($orig_tkt->get('TKT_deleted')) { |
|
604 | + continue; |
|
605 | + } |
|
606 | + // does this original ticket already exist in the clone_tickets cache? |
|
607 | + // If so we'll just use the new ticket from it. |
|
608 | + if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
609 | + $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
610 | + } else { |
|
611 | + $new_tkt = clone $orig_tkt; |
|
612 | + //get relations on the $orig_tkt that we need to setup. |
|
613 | + $orig_prices = $orig_tkt->prices(); |
|
614 | + $new_tkt->set('TKT_ID', 0); |
|
615 | + $new_tkt->set('TKT_sold', 0); |
|
616 | + $new_tkt->set('TKT_reserved', 0); |
|
617 | + $new_tkt->save(); //make sure new ticket has ID. |
|
618 | + //price relations on new ticket need to be setup. |
|
619 | + foreach ($orig_prices as $orig_price) { |
|
620 | + $new_price = clone $orig_price; |
|
621 | + $new_price->set('PRC_ID', 0); |
|
622 | + $new_price->save(); |
|
623 | + $new_tkt->_add_relation_to($new_price, 'Price'); |
|
624 | + $new_tkt->save(); |
|
625 | + } |
|
626 | + } |
|
627 | + // k now we can add the new ticket as a relation to the new datetime |
|
628 | + // and make sure its added to our cached $cloned_tickets array |
|
629 | + // for use with later datetimes that have the same ticket. |
|
630 | + $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
631 | + $new_dtt->save(); |
|
632 | + $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
633 | + } |
|
634 | + } |
|
635 | + //clone taxonomy information |
|
636 | + $taxonomies_to_clone_with = apply_filters( |
|
637 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
638 | + array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
639 | + ); |
|
640 | + //get terms for original event (notice) |
|
641 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
642 | + //loop through terms and add them to new event. |
|
643 | + foreach ($orig_terms as $term) { |
|
644 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
645 | + } |
|
646 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
647 | + //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
648 | + if ($new_event->ID()) { |
|
649 | + $redirect_args = array( |
|
650 | + 'post' => $new_event->ID(), |
|
651 | + 'action' => 'edit', |
|
652 | + ); |
|
653 | + EE_Error::add_success( |
|
654 | + esc_html__( |
|
655 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
656 | + 'event_espresso' |
|
657 | + ) |
|
658 | + ); |
|
659 | + } else { |
|
660 | + $redirect_args = array( |
|
661 | + 'action' => 'default', |
|
662 | + ); |
|
663 | + EE_Error::add_error( |
|
664 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
665 | + __FILE__, |
|
666 | + __FUNCTION__, |
|
667 | + __LINE__ |
|
668 | + ); |
|
669 | + } |
|
670 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Generates output for the import page. |
|
676 | + * @throws DomainException |
|
677 | + */ |
|
678 | + protected function _import_page() |
|
679 | + { |
|
680 | + $title = esc_html__('Import', 'event_espresso'); |
|
681 | + $intro = esc_html__( |
|
682 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
683 | + 'event_espresso' |
|
684 | + ); |
|
685 | + $form_url = EVENTS_ADMIN_URL; |
|
686 | + $action = 'import_events'; |
|
687 | + $type = 'csv'; |
|
688 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
689 | + $title, $intro, $form_url, $action, $type |
|
690 | + ); |
|
691 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
692 | + array('action' => 'sample_export_file'), |
|
693 | + $this->_admin_base_url |
|
694 | + ); |
|
695 | + $content = EEH_Template::display_template( |
|
696 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
697 | + $this->_template_args, |
|
698 | + true |
|
699 | + ); |
|
700 | + $this->_template_args['admin_page_content'] = $content; |
|
701 | + $this->display_admin_page_with_sidebar(); |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + /** |
|
706 | + * _import_events |
|
707 | + * This handles displaying the screen and running imports for importing events. |
|
708 | + * |
|
709 | + * @return void |
|
710 | + */ |
|
711 | + protected function _import_events() |
|
712 | + { |
|
713 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
714 | + $success = EE_Import::instance()->import(); |
|
715 | + $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * _events_export |
|
721 | + * Will export all (or just the given event) to a Excel compatible file. |
|
722 | + * |
|
723 | + * @access protected |
|
724 | + * @return void |
|
725 | + */ |
|
726 | + protected function _events_export() |
|
727 | + { |
|
728 | + if (isset($this->_req_data['EVT_ID'])) { |
|
729 | + $event_ids = $this->_req_data['EVT_ID']; |
|
730 | + } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
731 | + $event_ids = $this->_req_data['EVT_IDs']; |
|
732 | + } else { |
|
733 | + $event_ids = null; |
|
734 | + } |
|
735 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
736 | + $new_request_args = array( |
|
737 | + 'export' => 'report', |
|
738 | + 'action' => 'all_event_data', |
|
739 | + 'EVT_ID' => $event_ids, |
|
740 | + ); |
|
741 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
742 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
743 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
744 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
745 | + $EE_Export->export(); |
|
746 | + } |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * handle category exports() |
|
752 | + * |
|
753 | + * @return void |
|
754 | + */ |
|
755 | + protected function _categories_export() |
|
756 | + { |
|
757 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
758 | + $new_request_args = array( |
|
759 | + 'export' => 'report', |
|
760 | + 'action' => 'categories', |
|
761 | + 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
762 | + ); |
|
763 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
764 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
765 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
766 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
767 | + $EE_Export->export(); |
|
768 | + } |
|
769 | + } |
|
770 | + |
|
771 | + |
|
772 | + /** |
|
773 | + * Creates a sample CSV file for importing |
|
774 | + */ |
|
775 | + protected function _sample_export_file() |
|
776 | + { |
|
777 | + // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
778 | + EE_Export::instance()->export_sample(); |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + /************* Template Settings *************/ |
|
783 | + /** |
|
784 | + * Generates template settings page output |
|
785 | + * @throws DomainException |
|
786 | + * @throws EE_Error |
|
787 | + */ |
|
788 | + protected function _template_settings() |
|
789 | + { |
|
790 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
791 | + /** |
|
792 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
793 | + * from General_Settings_Admin_Page to here. |
|
794 | + */ |
|
795 | + $this->_template_args = apply_filters( |
|
796 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
797 | + $this->_template_args |
|
798 | + ); |
|
799 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
800 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
801 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
802 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
803 | + $this->_template_args, |
|
804 | + true |
|
805 | + ); |
|
806 | + $this->display_admin_page_with_sidebar(); |
|
807 | + } |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * Handler for updating template settings. |
|
812 | + */ |
|
813 | + protected function _update_template_settings() |
|
814 | + { |
|
815 | + /** |
|
816 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
817 | + * from General_Settings_Admin_Page to here. |
|
818 | + */ |
|
819 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
820 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
821 | + EE_Registry::instance()->CFG->template_settings, |
|
822 | + $this->_req_data |
|
823 | + ); |
|
824 | + //update custom post type slugs and detect if we need to flush rewrite rules |
|
825 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
826 | + EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
827 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
828 | + : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
829 | + $what = 'Template Settings'; |
|
830 | + $success = $this->_update_espresso_configuration( |
|
831 | + $what, |
|
832 | + EE_Registry::instance()->CFG->template_settings, |
|
833 | + __FILE__, |
|
834 | + __FUNCTION__, |
|
835 | + __LINE__ |
|
836 | + ); |
|
837 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
838 | + update_option('ee_flush_rewrite_rules', true); |
|
839 | + } |
|
840 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
841 | + } |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * _premium_event_editor_meta_boxes |
|
846 | + * add all metaboxes related to the event_editor |
|
847 | + * |
|
848 | + * @access protected |
|
849 | + * @return void |
|
850 | + * @throws EE_Error |
|
851 | + */ |
|
852 | + protected function _premium_event_editor_meta_boxes() |
|
853 | + { |
|
854 | + $this->verify_cpt_object(); |
|
855 | + add_meta_box( |
|
856 | + 'espresso_event_editor_event_options', |
|
857 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
858 | + array($this, 'registration_options_meta_box'), |
|
859 | + $this->page_slug, |
|
860 | + 'side', |
|
861 | + 'core' |
|
862 | + ); |
|
863 | + } |
|
864 | + |
|
865 | + |
|
866 | + /** |
|
867 | + * override caf metabox |
|
868 | + * |
|
869 | + * @return void |
|
870 | + * @throws DomainException |
|
871 | + */ |
|
872 | + public function registration_options_meta_box() |
|
873 | + { |
|
874 | + $yes_no_values = array( |
|
875 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
876 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
877 | + ); |
|
878 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
879 | + array( |
|
880 | + EEM_Registration::status_id_cancelled, |
|
881 | + EEM_Registration::status_id_declined, |
|
882 | + EEM_Registration::status_id_incomplete, |
|
883 | + EEM_Registration::status_id_wait_list, |
|
884 | + ), |
|
885 | + true |
|
886 | + ); |
|
887 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
888 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
889 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
890 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
891 | + 'default_reg_status', |
|
892 | + $default_reg_status_values, |
|
893 | + $this->_cpt_model_obj->default_registration_status() |
|
894 | + ); |
|
895 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
896 | + 'display_desc', |
|
897 | + $yes_no_values, |
|
898 | + $this->_cpt_model_obj->display_description() |
|
899 | + ); |
|
900 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
901 | + 'display_ticket_selector', |
|
902 | + $yes_no_values, |
|
903 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
904 | + '', |
|
905 | + '', |
|
906 | + false |
|
907 | + ); |
|
908 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
909 | + 'EVT_default_registration_status', |
|
910 | + $default_reg_status_values, |
|
911 | + $this->_cpt_model_obj->default_registration_status() |
|
912 | + ); |
|
913 | + $template_args['additional_registration_options'] = apply_filters( |
|
914 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
915 | + '', |
|
916 | + $template_args, |
|
917 | + $yes_no_values, |
|
918 | + $default_reg_status_values |
|
919 | + ); |
|
920 | + EEH_Template::display_template( |
|
921 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
922 | + $template_args |
|
923 | + ); |
|
924 | + } |
|
925 | + |
|
926 | + |
|
927 | + |
|
928 | + /** |
|
929 | + * wp_list_table_mods for caf |
|
930 | + * ============================ |
|
931 | + */ |
|
932 | + /** |
|
933 | + * hook into list table filters and provide filters for caffeinated list table |
|
934 | + * |
|
935 | + * @param array $old_filters any existing filters present |
|
936 | + * @param array $list_table_obj the list table object |
|
937 | + * @return array new filters |
|
938 | + */ |
|
939 | + public function list_table_filters($old_filters, $list_table_obj) |
|
940 | + { |
|
941 | + $filters = array(); |
|
942 | + //first month/year filters |
|
943 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
944 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
945 | + //active status dropdown |
|
946 | + if ($status !== 'draft') { |
|
947 | + $filters[] = $this->active_status_dropdown( |
|
948 | + isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
949 | + ); |
|
950 | + } |
|
951 | + //category filter |
|
952 | + $filters[] = $this->category_dropdown(); |
|
953 | + return array_merge($old_filters, $filters); |
|
954 | + } |
|
955 | + |
|
956 | + |
|
957 | + /** |
|
958 | + * espresso_event_months_dropdown |
|
959 | + * |
|
960 | + * @access public |
|
961 | + * @return string dropdown listing month/year selections for events. |
|
962 | + */ |
|
963 | + public function espresso_event_months_dropdown() |
|
964 | + { |
|
965 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
966 | + // Note we need to include any other filters that are set! |
|
967 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
968 | + //categories? |
|
969 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
970 | + ? $this->_req_data['EVT_CAT'] |
|
971 | + : null; |
|
972 | + //active status? |
|
973 | + $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
974 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
975 | + return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
976 | + } |
|
977 | + |
|
978 | + |
|
979 | + /** |
|
980 | + * returns a list of "active" statuses on the event |
|
981 | + * |
|
982 | + * @param string $current_value whatever the current active status is |
|
983 | + * @return string |
|
984 | + */ |
|
985 | + public function active_status_dropdown($current_value = '') |
|
986 | + { |
|
987 | + $select_name = 'active_status'; |
|
988 | + $values = array( |
|
989 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
990 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
991 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
992 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
993 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
994 | + ); |
|
995 | + $id = 'id="espresso-active-status-dropdown-filter"'; |
|
996 | + $class = 'wide'; |
|
997 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
998 | + } |
|
999 | + |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
1003 | + * |
|
1004 | + * @access public |
|
1005 | + * @return string html |
|
1006 | + */ |
|
1007 | + public function category_dropdown() |
|
1008 | + { |
|
1009 | + $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
1010 | + return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
1011 | + } |
|
1012 | + |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * get total number of events today |
|
1016 | + * |
|
1017 | + * @access public |
|
1018 | + * @return int |
|
1019 | + * @throws EE_Error |
|
1020 | + */ |
|
1021 | + public function total_events_today() |
|
1022 | + { |
|
1023 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1024 | + 'DTT_EVT_start', |
|
1025 | + date('Y-m-d') . ' 00:00:00', |
|
1026 | + 'Y-m-d H:i:s', |
|
1027 | + 'UTC' |
|
1028 | + ); |
|
1029 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1030 | + 'DTT_EVT_start', |
|
1031 | + date('Y-m-d') . ' 23:59:59', |
|
1032 | + 'Y-m-d H:i:s', |
|
1033 | + 'UTC' |
|
1034 | + ); |
|
1035 | + $where = array( |
|
1036 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1037 | + ); |
|
1038 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1039 | + return $count; |
|
1040 | + } |
|
1041 | + |
|
1042 | + |
|
1043 | + /** |
|
1044 | + * get total number of events this month |
|
1045 | + * |
|
1046 | + * @access public |
|
1047 | + * @return int |
|
1048 | + * @throws EE_Error |
|
1049 | + */ |
|
1050 | + public function total_events_this_month() |
|
1051 | + { |
|
1052 | + //Dates |
|
1053 | + $this_year_r = date('Y'); |
|
1054 | + $this_month_r = date('m'); |
|
1055 | + $days_this_month = date('t'); |
|
1056 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1057 | + 'DTT_EVT_start', |
|
1058 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1059 | + 'Y-m-d H:i:s', |
|
1060 | + 'UTC' |
|
1061 | + ); |
|
1062 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1063 | + 'DTT_EVT_start', |
|
1064 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1065 | + 'Y-m-d H:i:s', |
|
1066 | + 'UTC' |
|
1067 | + ); |
|
1068 | + $where = array( |
|
1069 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1070 | + ); |
|
1071 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1072 | + return $count; |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + /** DEFAULT TICKETS STUFF **/ |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * Output default tickets list table view. |
|
1080 | + */ |
|
1081 | + public function _tickets_overview_list_table() |
|
1082 | + { |
|
1083 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1084 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * @param int $per_page |
|
1090 | + * @param bool $count |
|
1091 | + * @param bool $trashed |
|
1092 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
1093 | + */ |
|
1094 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1095 | + { |
|
1096 | + $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
1097 | + $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
1098 | + switch ($orderby) { |
|
1099 | + case 'TKT_name': |
|
1100 | + $orderby = array('TKT_name' => $order); |
|
1101 | + break; |
|
1102 | + case 'TKT_price': |
|
1103 | + $orderby = array('TKT_price' => $order); |
|
1104 | + break; |
|
1105 | + case 'TKT_uses': |
|
1106 | + $orderby = array('TKT_uses' => $order); |
|
1107 | + break; |
|
1108 | + case 'TKT_min': |
|
1109 | + $orderby = array('TKT_min' => $order); |
|
1110 | + break; |
|
1111 | + case 'TKT_max': |
|
1112 | + $orderby = array('TKT_max' => $order); |
|
1113 | + break; |
|
1114 | + case 'TKT_qty': |
|
1115 | + $orderby = array('TKT_qty' => $order); |
|
1116 | + break; |
|
1117 | + } |
|
1118 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
1119 | + ? $this->_req_data['paged'] |
|
1120 | + : 1; |
|
1121 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
1122 | + ? $this->_req_data['perpage'] |
|
1123 | + : $per_page; |
|
1124 | + $_where = array( |
|
1125 | + 'TKT_is_default' => 1, |
|
1126 | + 'TKT_deleted' => $trashed, |
|
1127 | + ); |
|
1128 | + $offset = ($current_page - 1) * $per_page; |
|
1129 | + $limit = array($offset, $per_page); |
|
1130 | + if (isset($this->_req_data['s'])) { |
|
1131 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1132 | + $_where['OR'] = array( |
|
1133 | + 'TKT_name' => array('LIKE', $sstr), |
|
1134 | + 'TKT_description' => array('LIKE', $sstr), |
|
1135 | + ); |
|
1136 | + } |
|
1137 | + $query_params = array( |
|
1138 | + $_where, |
|
1139 | + 'order_by' => $orderby, |
|
1140 | + 'limit' => $limit, |
|
1141 | + 'group_by' => 'TKT_ID', |
|
1142 | + ); |
|
1143 | + if ($count) { |
|
1144 | + return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
1145 | + } else { |
|
1146 | + return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
1147 | + } |
|
1148 | + } |
|
1149 | + |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * @param bool $trash |
|
1153 | + * @throws EE_Error |
|
1154 | + */ |
|
1155 | + protected function _trash_or_restore_ticket($trash = false) |
|
1156 | + { |
|
1157 | + $success = 1; |
|
1158 | + $TKT = EEM_Ticket::instance(); |
|
1159 | + //checkboxes? |
|
1160 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1161 | + //if array has more than one element then success message should be plural |
|
1162 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1163 | + //cycle thru the boxes |
|
1164 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1165 | + if ($trash) { |
|
1166 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1167 | + $success = 0; |
|
1168 | + } |
|
1169 | + } else { |
|
1170 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1171 | + $success = 0; |
|
1172 | + } |
|
1173 | + } |
|
1174 | + } |
|
1175 | + } else { |
|
1176 | + //grab single id and trash |
|
1177 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1178 | + if ($trash) { |
|
1179 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1180 | + $success = 0; |
|
1181 | + } |
|
1182 | + } else { |
|
1183 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1184 | + $success = 0; |
|
1185 | + } |
|
1186 | + } |
|
1187 | + } |
|
1188 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1189 | + $query_args = array( |
|
1190 | + 'action' => 'ticket_list_table', |
|
1191 | + 'status' => $trash ? '' : 'trashed', |
|
1192 | + ); |
|
1193 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1194 | + } |
|
1195 | + |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * Handles trashing default ticket. |
|
1199 | + */ |
|
1200 | + protected function _delete_ticket() |
|
1201 | + { |
|
1202 | + $success = 1; |
|
1203 | + //checkboxes? |
|
1204 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1205 | + //if array has more than one element then success message should be plural |
|
1206 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1207 | + //cycle thru the boxes |
|
1208 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1209 | + //delete |
|
1210 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1211 | + $success = 0; |
|
1212 | + } |
|
1213 | + } |
|
1214 | + } else { |
|
1215 | + //grab single id and trash |
|
1216 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1217 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1218 | + $success = 0; |
|
1219 | + } |
|
1220 | + } |
|
1221 | + $action_desc = 'deleted'; |
|
1222 | + $query_args = array( |
|
1223 | + 'action' => 'ticket_list_table', |
|
1224 | + 'status' => 'trashed', |
|
1225 | + ); |
|
1226 | + //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1227 | + if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1228 | + array(array('TKT_is_default' => 1)), |
|
1229 | + 'TKT_ID', |
|
1230 | + true |
|
1231 | + ) |
|
1232 | + ) { |
|
1233 | + $query_args = array(); |
|
1234 | + } |
|
1235 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1236 | + } |
|
1237 | + |
|
1238 | + |
|
1239 | + /** |
|
1240 | + * @param int $TKT_ID |
|
1241 | + * @return bool|int |
|
1242 | + * @throws EE_Error |
|
1243 | + */ |
|
1244 | + protected function _delete_the_ticket($TKT_ID) |
|
1245 | + { |
|
1246 | + $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1247 | + $tkt->_remove_relations('Datetime'); |
|
1248 | + //delete all related prices first |
|
1249 | + $tkt->delete_related_permanently('Price'); |
|
1250 | + return $tkt->delete_permanently(); |
|
1251 | + } |
|
1252 | 1252 | } |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | public function __construct($routing = true) |
23 | 23 | { |
24 | 24 | parent::__construct($routing); |
25 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
27 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
28 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
25 | + if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/'); |
|
27 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/'); |
|
28 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/'); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | protected function _extend_page_config() |
37 | 37 | { |
38 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
38 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events'; |
|
39 | 39 | //is there a evt_id in the request? |
40 | 40 | $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
41 | 41 | ? $this->_req_data['EVT_ID'] |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | 'help_tour' => array('Templates_Help_Tour'), |
169 | 169 | 'require_nonce' => false, |
170 | 170 | ); |
171 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
171 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
172 | 172 | //add filters and actions |
173 | 173 | //modifying _views |
174 | 174 | add_filter( |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * check whether count of tickets is approaching the potential |
242 | 242 | * limits for the server. |
243 | 243 | */ |
244 | - if (! empty($data['input_count'])) { |
|
244 | + if ( ! empty($data['input_count'])) { |
|
245 | 245 | $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
246 | 246 | $data['input_count'] |
247 | 247 | ); |
@@ -270,12 +270,12 @@ discard block |
||
270 | 270 | { |
271 | 271 | $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
272 | 272 | //make sure this is only when editing |
273 | - if (! empty($id)) { |
|
274 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
273 | + if ( ! empty($id)) { |
|
274 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
275 | 275 | array('action' => 'duplicate_event', 'EVT_ID' => $id), |
276 | 276 | $this->_admin_base_url |
277 | 277 | ); |
278 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
278 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
279 | 279 | $return .= '<a href="' |
280 | 280 | . $href |
281 | 281 | . '" title="' |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | { |
323 | 323 | wp_register_script( |
324 | 324 | 'ee-event-editor-heartbeat', |
325 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
325 | + EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js', |
|
326 | 326 | array('ee_admin_js', 'heartbeat'), |
327 | 327 | EVENT_ESPRESSO_VERSION, |
328 | 328 | true |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | public function add_additional_datetime_button($template, $template_args) |
346 | 346 | { |
347 | 347 | return EEH_Template::display_template( |
348 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
348 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php', |
|
349 | 349 | $template_args, |
350 | 350 | true |
351 | 351 | ); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | public function add_datetime_clone_button($template, $template_args) |
363 | 363 | { |
364 | 364 | return EEH_Template::display_template( |
365 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
365 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php', |
|
366 | 366 | $template_args, |
367 | 367 | true |
368 | 368 | ); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | public function datetime_timezones_template($template, $template_args) |
380 | 380 | { |
381 | 381 | return EEH_Template::display_template( |
382 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
382 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php', |
|
383 | 383 | $template_args, |
384 | 384 | true |
385 | 385 | ); |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | protected function _set_list_table_views_default() |
393 | 393 | { |
394 | 394 | parent::_set_list_table_views_default(); |
395 | - $new_views = array( |
|
395 | + $new_views = array( |
|
396 | 396 | 'today' => array( |
397 | 397 | 'slug' => 'today', |
398 | 398 | 'label' => esc_html__('Today', 'event_espresso'), |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | { |
498 | 498 | // first make sure the ID for the event is in the request. |
499 | 499 | // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
500 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
500 | + if ( ! isset($this->_req_data['EVT_ID'])) { |
|
501 | 501 | EE_Error::add_error( |
502 | 502 | esc_html__( |
503 | 503 | 'In order to duplicate an event an Event ID is required. None was given.', |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | } |
513 | 513 | //k we've got EVT_ID so let's use that to get the event we'll duplicate |
514 | 514 | $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
515 | - if (! $orig_event instanceof EE_Event) { |
|
515 | + if ( ! $orig_event instanceof EE_Event) { |
|
516 | 516 | throw new EE_Error( |
517 | 517 | sprintf( |
518 | 518 | esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | $orig_ven = $orig_event->get_many_related('Venue'); |
529 | 529 | //reset the ID and modify other details to make it clear this is a dupe |
530 | 530 | $new_event->set('EVT_ID', 0); |
531 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
531 | + $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso'); |
|
532 | 532 | $new_event->set('EVT_name', $new_name); |
533 | 533 | $new_event->set( |
534 | 534 | 'EVT_slug', |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | 'Question_Group', |
558 | 558 | array(array('Event_Question_Group.EQG_primary' => 1)) |
559 | 559 | ); |
560 | - if (! empty($orig_primary_qgs)) { |
|
560 | + if ( ! empty($orig_primary_qgs)) { |
|
561 | 561 | foreach ($orig_primary_qgs as $id => $obj) { |
562 | 562 | if ($obj instanceof EE_Question_Group) { |
563 | 563 | $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | 'Question_Group', |
570 | 570 | array(array('Event_Question_Group.EQG_primary' => 0)) |
571 | 571 | ); |
572 | - if (! empty($orig_additional_qgs)) { |
|
572 | + if ( ! empty($orig_additional_qgs)) { |
|
573 | 573 | foreach ($orig_additional_qgs as $id => $obj) { |
574 | 574 | if ($obj instanceof EE_Question_Group) { |
575 | 575 | $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
582 | 582 | $cloned_tickets = array(); |
583 | 583 | foreach ($orig_datetimes as $orig_dtt) { |
584 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
584 | + if ( ! $orig_dtt instanceof EE_Datetime) { |
|
585 | 585 | continue; |
586 | 586 | } |
587 | 587 | $new_dtt = clone $orig_dtt; |
@@ -594,9 +594,9 @@ discard block |
||
594 | 594 | $new_event->_add_relation_to($new_dtt, 'Datetime'); |
595 | 595 | $new_event->save(); |
596 | 596 | //now let's get the ticket relations setup. |
597 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
597 | + foreach ((array) $orig_tkts as $orig_tkt) { |
|
598 | 598 | //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
599 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
599 | + if ( ! $orig_tkt instanceof EE_Ticket) { |
|
600 | 600 | continue; |
601 | 601 | } |
602 | 602 | //is this ticket archived? If it is then let's skip |
@@ -692,8 +692,8 @@ discard block |
||
692 | 692 | array('action' => 'sample_export_file'), |
693 | 693 | $this->_admin_base_url |
694 | 694 | ); |
695 | - $content = EEH_Template::display_template( |
|
696 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
695 | + $content = EEH_Template::display_template( |
|
696 | + EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php', |
|
697 | 697 | $this->_template_args, |
698 | 698 | true |
699 | 699 | ); |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | */ |
711 | 711 | protected function _import_events() |
712 | 712 | { |
713 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
713 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
714 | 714 | $success = EE_Import::instance()->import(); |
715 | 715 | $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
716 | 716 | } |
@@ -738,9 +738,9 @@ discard block |
||
738 | 738 | 'action' => 'all_event_data', |
739 | 739 | 'EVT_ID' => $event_ids, |
740 | 740 | ); |
741 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
742 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
743 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
741 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
742 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
743 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
744 | 744 | $EE_Export = EE_Export::instance($this->_req_data); |
745 | 745 | $EE_Export->export(); |
746 | 746 | } |
@@ -760,9 +760,9 @@ discard block |
||
760 | 760 | 'action' => 'categories', |
761 | 761 | 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
762 | 762 | ); |
763 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
764 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
765 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
763 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
764 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
765 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
766 | 766 | $EE_Export = EE_Export::instance($this->_req_data); |
767 | 767 | $EE_Export->export(); |
768 | 768 | } |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | $this->_set_add_edit_form_tags('update_template_settings'); |
800 | 800 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
801 | 801 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
802 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
802 | + EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php', |
|
803 | 803 | $this->_template_args, |
804 | 804 | true |
805 | 805 | ); |
@@ -871,11 +871,11 @@ discard block |
||
871 | 871 | */ |
872 | 872 | public function registration_options_meta_box() |
873 | 873 | { |
874 | - $yes_no_values = array( |
|
874 | + $yes_no_values = array( |
|
875 | 875 | array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
876 | 876 | array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
877 | 877 | ); |
878 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
878 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
879 | 879 | array( |
880 | 880 | EEM_Registration::status_id_cancelled, |
881 | 881 | EEM_Registration::status_id_declined, |
@@ -892,12 +892,12 @@ discard block |
||
892 | 892 | $default_reg_status_values, |
893 | 893 | $this->_cpt_model_obj->default_registration_status() |
894 | 894 | ); |
895 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
895 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
896 | 896 | 'display_desc', |
897 | 897 | $yes_no_values, |
898 | 898 | $this->_cpt_model_obj->display_description() |
899 | 899 | ); |
900 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
900 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
901 | 901 | 'display_ticket_selector', |
902 | 902 | $yes_no_values, |
903 | 903 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | $default_reg_status_values |
919 | 919 | ); |
920 | 920 | EEH_Template::display_template( |
921 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
921 | + EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php', |
|
922 | 922 | $template_args |
923 | 923 | ); |
924 | 924 | } |
@@ -1022,13 +1022,13 @@ discard block |
||
1022 | 1022 | { |
1023 | 1023 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
1024 | 1024 | 'DTT_EVT_start', |
1025 | - date('Y-m-d') . ' 00:00:00', |
|
1025 | + date('Y-m-d').' 00:00:00', |
|
1026 | 1026 | 'Y-m-d H:i:s', |
1027 | 1027 | 'UTC' |
1028 | 1028 | ); |
1029 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1029 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1030 | 1030 | 'DTT_EVT_start', |
1031 | - date('Y-m-d') . ' 23:59:59', |
|
1031 | + date('Y-m-d').' 23:59:59', |
|
1032 | 1032 | 'Y-m-d H:i:s', |
1033 | 1033 | 'UTC' |
1034 | 1034 | ); |
@@ -1055,13 +1055,13 @@ discard block |
||
1055 | 1055 | $days_this_month = date('t'); |
1056 | 1056 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
1057 | 1057 | 'DTT_EVT_start', |
1058 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1058 | + $this_year_r.'-'.$this_month_r.'-01 00:00:00', |
|
1059 | 1059 | 'Y-m-d H:i:s', |
1060 | 1060 | 'UTC' |
1061 | 1061 | ); |
1062 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1062 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1063 | 1063 | 'DTT_EVT_start', |
1064 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1064 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59', |
|
1065 | 1065 | 'Y-m-d H:i:s', |
1066 | 1066 | 'UTC' |
1067 | 1067 | ); |
@@ -1128,7 +1128,7 @@ discard block |
||
1128 | 1128 | $offset = ($current_page - 1) * $per_page; |
1129 | 1129 | $limit = array($offset, $per_page); |
1130 | 1130 | if (isset($this->_req_data['s'])) { |
1131 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1131 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
1132 | 1132 | $_where['OR'] = array( |
1133 | 1133 | 'TKT_name' => array('LIKE', $sstr), |
1134 | 1134 | 'TKT_description' => array('LIKE', $sstr), |
@@ -1157,17 +1157,17 @@ discard block |
||
1157 | 1157 | $success = 1; |
1158 | 1158 | $TKT = EEM_Ticket::instance(); |
1159 | 1159 | //checkboxes? |
1160 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1160 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1161 | 1161 | //if array has more than one element then success message should be plural |
1162 | 1162 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
1163 | 1163 | //cycle thru the boxes |
1164 | 1164 | while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
1165 | 1165 | if ($trash) { |
1166 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1166 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
1167 | 1167 | $success = 0; |
1168 | 1168 | } |
1169 | 1169 | } else { |
1170 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1170 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
1171 | 1171 | $success = 0; |
1172 | 1172 | } |
1173 | 1173 | } |
@@ -1176,11 +1176,11 @@ discard block |
||
1176 | 1176 | //grab single id and trash |
1177 | 1177 | $TKT_ID = absint($this->_req_data['TKT_ID']); |
1178 | 1178 | if ($trash) { |
1179 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1179 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
1180 | 1180 | $success = 0; |
1181 | 1181 | } |
1182 | 1182 | } else { |
1183 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1183 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
1184 | 1184 | $success = 0; |
1185 | 1185 | } |
1186 | 1186 | } |
@@ -1201,20 +1201,20 @@ discard block |
||
1201 | 1201 | { |
1202 | 1202 | $success = 1; |
1203 | 1203 | //checkboxes? |
1204 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1204 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1205 | 1205 | //if array has more than one element then success message should be plural |
1206 | 1206 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
1207 | 1207 | //cycle thru the boxes |
1208 | 1208 | while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
1209 | 1209 | //delete |
1210 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1210 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
1211 | 1211 | $success = 0; |
1212 | 1212 | } |
1213 | 1213 | } |
1214 | 1214 | } else { |
1215 | 1215 | //grab single id and trash |
1216 | 1216 | $TKT_ID = absint($this->_req_data['TKT_ID']); |
1217 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1217 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
1218 | 1218 | $success = 0; |
1219 | 1219 | } |
1220 | 1220 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.007'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.007'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -18,998 +18,998 @@ discard block |
||
18 | 18 | final class EE_Capabilities extends EE_Base |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * the name of the wp option used to store caps previously initialized |
|
23 | - */ |
|
24 | - const option_name = 'ee_caps_initialized'; |
|
25 | - |
|
26 | - /** |
|
27 | - * instance of EE_Capabilities object |
|
28 | - * |
|
29 | - * @var EE_Capabilities |
|
30 | - */ |
|
31 | - private static $_instance; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * This is a map of caps that correspond to a default WP_Role. |
|
36 | - * Array is indexed by Role and values are ee capabilities. |
|
37 | - * |
|
38 | - * @since 4.5.0 |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $capabilities_map = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * This used to hold an array of EE_Meta_Capability_Map objects |
|
46 | - * that define the granular capabilities mapped to for a user depending on context. |
|
47 | - * |
|
48 | - * @var EE_Meta_Capability_Map[] |
|
49 | - */ |
|
50 | - private $_meta_caps = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * The internal $capabilities_map needs to be initialized before it can be used. |
|
54 | - * This flag tracks whether that has happened or not. |
|
55 | - * But for this to work, we need three states to indicate: |
|
56 | - * initialization has not occurred at all |
|
57 | - * initialization has started but is not complete |
|
58 | - * initialization is complete |
|
59 | - * The reason this is needed is because the addCaps() method |
|
60 | - * normally requires the $capabilities_map to be initialized, |
|
61 | - * but is also used during the initialization process. |
|
62 | - * So: |
|
63 | - * If initialized === null, init_caps() will be called before any other methods will run. |
|
64 | - * If initialized === false, then init_caps() is in the process of running it's logic. |
|
65 | - * If initialized === true, then init_caps() has completed the initialization process. |
|
66 | - * |
|
67 | - * @var boolean|null $initialized |
|
68 | - */ |
|
69 | - private $initialized; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var boolean $reset |
|
73 | - */ |
|
74 | - private $reset = false; |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * singleton method used to instantiate class object |
|
80 | - * |
|
81 | - * @since 4.5.0 |
|
82 | - * |
|
83 | - * @return EE_Capabilities |
|
84 | - */ |
|
85 | - public static function instance() |
|
86 | - { |
|
87 | - //check if instantiated, and if not do so. |
|
88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
89 | - self::$_instance = new self(); |
|
90 | - } |
|
91 | - return self::$_instance; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * private constructor |
|
98 | - * |
|
99 | - * @since 4.5.0 |
|
100 | - */ |
|
101 | - private function __construct() |
|
102 | - { |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
109 | - * |
|
110 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
111 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
112 | - * ensures that they are up to date. |
|
113 | - * |
|
114 | - * @since 4.5.0 |
|
115 | - * @return bool |
|
116 | - * @throws EE_Error |
|
117 | - */ |
|
118 | - public function init_caps($reset = false) |
|
119 | - { |
|
120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
121 | - return false; |
|
122 | - } |
|
123 | - $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
124 | - // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
125 | - if ($this->reset) { |
|
126 | - $this->initialized = null; |
|
127 | - $this->capabilities_map = array(); |
|
128 | - delete_option(self::option_name); |
|
129 | - } |
|
130 | - if ($this->initialized === null) { |
|
131 | - $this->initialized = false; |
|
132 | - do_action( |
|
133 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
134 | - $this->reset |
|
135 | - ); |
|
136 | - $this->addCaps($this->_init_caps_map()); |
|
137 | - $this->_set_meta_caps(); |
|
138 | - do_action( |
|
139 | - 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
140 | - $this->capabilities_map |
|
141 | - ); |
|
142 | - $this->initialized = true; |
|
143 | - } |
|
144 | - // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
145 | - $this->reset = false; |
|
146 | - return true; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * This sets the meta caps property. |
|
153 | - * |
|
154 | - * @since 4.5.0 |
|
155 | - * @return void |
|
156 | - * @throws EE_Error |
|
157 | - */ |
|
158 | - private function _set_meta_caps() |
|
159 | - { |
|
160 | - // get default meta caps and filter the returned array |
|
161 | - $this->_meta_caps = apply_filters( |
|
162 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
163 | - $this->_get_default_meta_caps_array() |
|
164 | - ); |
|
165 | - //add filter for map_meta_caps but only if models can query. |
|
166 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
167 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * This builds and returns the default meta_caps array only once. |
|
175 | - * |
|
176 | - * @since 4.8.28.rc.012 |
|
177 | - * @return array |
|
178 | - * @throws EE_Error |
|
179 | - */ |
|
180 | - private function _get_default_meta_caps_array() |
|
181 | - { |
|
182 | - static $default_meta_caps = array(); |
|
183 | - // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
184 | - if (empty($default_meta_caps)) { |
|
185 | - $default_meta_caps = array( |
|
186 | - //edits |
|
187 | - new EE_Meta_Capability_Map_Edit( |
|
188 | - 'ee_edit_event', |
|
189 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
190 | - ), |
|
191 | - new EE_Meta_Capability_Map_Edit( |
|
192 | - 'ee_edit_venue', |
|
193 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
194 | - ), |
|
195 | - new EE_Meta_Capability_Map_Edit( |
|
196 | - 'ee_edit_registration', |
|
197 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
198 | - ), |
|
199 | - new EE_Meta_Capability_Map_Edit( |
|
200 | - 'ee_edit_checkin', |
|
201 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
202 | - ), |
|
203 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
204 | - 'ee_edit_message', |
|
205 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
206 | - ), |
|
207 | - new EE_Meta_Capability_Map_Edit( |
|
208 | - 'ee_edit_default_ticket', |
|
209 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
210 | - ), |
|
211 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
212 | - 'ee_edit_question', |
|
213 | - array('Question', '', '', 'ee_edit_system_questions') |
|
214 | - ), |
|
215 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
216 | - 'ee_edit_question_group', |
|
217 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
218 | - ), |
|
219 | - new EE_Meta_Capability_Map_Edit( |
|
220 | - 'ee_edit_payment_method', |
|
221 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
222 | - ), |
|
223 | - //reads |
|
224 | - new EE_Meta_Capability_Map_Read( |
|
225 | - 'ee_read_event', |
|
226 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
227 | - ), |
|
228 | - new EE_Meta_Capability_Map_Read( |
|
229 | - 'ee_read_venue', |
|
230 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
231 | - ), |
|
232 | - new EE_Meta_Capability_Map_Read( |
|
233 | - 'ee_read_registration', |
|
234 | - array('Registration', '', '', 'ee_edit_others_registrations') |
|
235 | - ), |
|
236 | - new EE_Meta_Capability_Map_Read( |
|
237 | - 'ee_read_checkin', |
|
238 | - array('Registration', '', '', 'ee_read_others_checkins') |
|
239 | - ), |
|
240 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
241 | - 'ee_read_message', |
|
242 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
243 | - ), |
|
244 | - new EE_Meta_Capability_Map_Read( |
|
245 | - 'ee_read_default_ticket', |
|
246 | - array('Ticket', '', '', 'ee_read_others_default_tickets') |
|
247 | - ), |
|
248 | - new EE_Meta_Capability_Map_Read( |
|
249 | - 'ee_read_payment_method', |
|
250 | - array('Payment_Method', '', '', 'ee_read_others_payment_methods') |
|
251 | - ), |
|
252 | - //deletes |
|
253 | - new EE_Meta_Capability_Map_Delete( |
|
254 | - 'ee_delete_event', |
|
255 | - array( |
|
256 | - 'Event', |
|
257 | - 'ee_delete_published_events', |
|
258 | - 'ee_delete_others_events', |
|
259 | - 'ee_delete_private_events', |
|
260 | - ) |
|
261 | - ), |
|
262 | - new EE_Meta_Capability_Map_Delete( |
|
263 | - 'ee_delete_venue', |
|
264 | - array( |
|
265 | - 'Venue', |
|
266 | - 'ee_delete_published_venues', |
|
267 | - 'ee_delete_others_venues', |
|
268 | - 'ee_delete_private_venues', |
|
269 | - ) |
|
270 | - ), |
|
271 | - new EE_Meta_Capability_Map_Delete( |
|
272 | - 'ee_delete_registration', |
|
273 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
274 | - ), |
|
275 | - new EE_Meta_Capability_Map_Delete( |
|
276 | - 'ee_delete_checkin', |
|
277 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
278 | - ), |
|
279 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
280 | - 'ee_delete_message', |
|
281 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
282 | - ), |
|
283 | - new EE_Meta_Capability_Map_Delete( |
|
284 | - 'ee_delete_default_ticket', |
|
285 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
286 | - ), |
|
287 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
288 | - 'ee_delete_question', |
|
289 | - array('Question', '', '', 'delete_system_questions') |
|
290 | - ), |
|
291 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
292 | - 'ee_delete_question_group', |
|
293 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
294 | - ), |
|
295 | - new EE_Meta_Capability_Map_Delete( |
|
296 | - 'ee_delete_payment_method', |
|
297 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
298 | - ), |
|
299 | - ); |
|
300 | - } |
|
301 | - return $default_meta_caps; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
308 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
309 | - * |
|
310 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
311 | - * |
|
312 | - * @since 4.5.0 |
|
313 | - * @see wp-includes/capabilities.php |
|
314 | - * |
|
315 | - * @param array $caps actual users capabilities |
|
316 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
317 | - * @param int $user_id The user id |
|
318 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
319 | - * @return array actual users capabilities |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
323 | - { |
|
324 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
325 | - //loop through our _meta_caps array |
|
326 | - foreach ($this->_meta_caps as $meta_map) { |
|
327 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
328 | - continue; |
|
329 | - } |
|
330 | - // don't load models if there is no object ID in the args |
|
331 | - if (! empty($args[0])) { |
|
332 | - $meta_map->ensure_is_model(); |
|
333 | - } |
|
334 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
335 | - } |
|
336 | - } |
|
337 | - return $caps; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
344 | - * Note this array is filtered. |
|
345 | - * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
346 | - * |
|
347 | - * @since 4.5.0 |
|
348 | - * |
|
349 | - * @return array |
|
350 | - */ |
|
351 | - private function _init_caps_map() |
|
352 | - { |
|
353 | - return apply_filters( |
|
354 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
355 | - array( |
|
356 | - 'administrator' => array( |
|
357 | - //basic access |
|
358 | - 'ee_read_ee', |
|
359 | - //gateways |
|
360 | - /** |
|
361 | - * note that with payment method capabilities, although we've implemented |
|
362 | - * capability mapping which will be used for accessing payment methods owned by |
|
363 | - * other users. This is not fully implemented yet in the payment method ui. |
|
364 | - * Currently only the "plural" caps are in active use. |
|
365 | - * (Specific payment method caps are in use as well). |
|
366 | - **/ |
|
367 | - 'ee_manage_gateways', |
|
368 | - 'ee_read_payment_methods', |
|
369 | - 'ee_read_others_payment_methods', |
|
370 | - 'ee_edit_payment_methods', |
|
371 | - 'ee_edit_others_payment_methods', |
|
372 | - 'ee_delete_payment_methods', |
|
373 | - //events |
|
374 | - 'ee_publish_events', |
|
375 | - 'ee_read_private_events', |
|
376 | - 'ee_read_others_events', |
|
377 | - 'ee_read_events', |
|
378 | - 'ee_edit_events', |
|
379 | - 'ee_edit_published_events', |
|
380 | - 'ee_edit_others_events', |
|
381 | - 'ee_edit_private_events', |
|
382 | - 'ee_delete_published_events', |
|
383 | - 'ee_delete_private_events', |
|
384 | - 'ee_delete_events', |
|
385 | - 'ee_delete_others_events', |
|
386 | - //event categories |
|
387 | - 'ee_manage_event_categories', |
|
388 | - 'ee_edit_event_category', |
|
389 | - 'ee_delete_event_category', |
|
390 | - 'ee_assign_event_category', |
|
391 | - //venues |
|
392 | - 'ee_publish_venues', |
|
393 | - 'ee_read_venues', |
|
394 | - 'ee_read_others_venues', |
|
395 | - 'ee_read_private_venues', |
|
396 | - 'ee_edit_venues', |
|
397 | - 'ee_edit_others_venues', |
|
398 | - 'ee_edit_published_venues', |
|
399 | - 'ee_edit_private_venues', |
|
400 | - 'ee_delete_venues', |
|
401 | - 'ee_delete_others_venues', |
|
402 | - 'ee_delete_private_venues', |
|
403 | - 'ee_delete_published_venues', |
|
404 | - //venue categories |
|
405 | - 'ee_manage_venue_categories', |
|
406 | - 'ee_edit_venue_category', |
|
407 | - 'ee_delete_venue_category', |
|
408 | - 'ee_assign_venue_category', |
|
409 | - //contacts |
|
410 | - 'ee_read_contact', |
|
411 | - 'ee_read_contacts', |
|
412 | - 'ee_edit_contact', |
|
413 | - 'ee_edit_contacts', |
|
414 | - 'ee_delete_contact', |
|
415 | - 'ee_delete_contacts', |
|
416 | - //registrations |
|
417 | - 'ee_read_registrations', |
|
418 | - 'ee_read_others_registrations', |
|
419 | - 'ee_edit_registrations', |
|
420 | - 'ee_edit_others_registrations', |
|
421 | - 'ee_delete_registrations', |
|
422 | - //checkins |
|
423 | - 'ee_read_others_checkins', |
|
424 | - 'ee_read_checkins', |
|
425 | - 'ee_edit_checkins', |
|
426 | - 'ee_edit_others_checkins', |
|
427 | - 'ee_delete_checkin', |
|
428 | - 'ee_delete_checkins', |
|
429 | - 'ee_delete_others_checkins', |
|
430 | - //transactions && payments |
|
431 | - 'ee_read_transaction', |
|
432 | - 'ee_read_transactions', |
|
433 | - 'ee_edit_payments', |
|
434 | - 'ee_delete_payments', |
|
435 | - //messages |
|
436 | - 'ee_read_message', |
|
437 | - 'ee_read_messages', |
|
438 | - 'ee_read_others_messages', |
|
439 | - 'ee_read_global_messages', |
|
440 | - 'ee_edit_global_messages', |
|
441 | - 'ee_edit_messages', |
|
442 | - 'ee_edit_others_messages', |
|
443 | - 'ee_delete_message', |
|
444 | - 'ee_delete_messages', |
|
445 | - 'ee_delete_others_messages', |
|
446 | - 'ee_delete_global_messages', |
|
447 | - 'ee_send_message', |
|
448 | - //tickets |
|
449 | - 'ee_read_default_ticket', |
|
450 | - 'ee_read_default_tickets', |
|
451 | - 'ee_read_others_default_tickets', |
|
452 | - 'ee_edit_default_tickets', |
|
453 | - 'ee_edit_others_default_tickets', |
|
454 | - 'ee_delete_default_ticket', |
|
455 | - 'ee_delete_default_tickets', |
|
456 | - 'ee_delete_others_default_tickets', |
|
457 | - //prices |
|
458 | - 'ee_edit_default_price', |
|
459 | - 'ee_edit_default_prices', |
|
460 | - 'ee_delete_default_price', |
|
461 | - 'ee_delete_default_prices', |
|
462 | - 'ee_edit_default_price_type', |
|
463 | - 'ee_edit_default_price_types', |
|
464 | - 'ee_delete_default_price_type', |
|
465 | - 'ee_delete_default_price_types', |
|
466 | - 'ee_read_default_prices', |
|
467 | - 'ee_read_default_price_types', |
|
468 | - //registration form |
|
469 | - 'ee_edit_questions', |
|
470 | - 'ee_edit_system_questions', |
|
471 | - 'ee_read_questions', |
|
472 | - 'ee_delete_question', |
|
473 | - 'ee_delete_questions', |
|
474 | - 'ee_edit_question_groups', |
|
475 | - 'ee_read_question_groups', |
|
476 | - 'ee_edit_system_question_groups', |
|
477 | - 'ee_delete_question_group', |
|
478 | - 'ee_delete_question_groups', |
|
479 | - //event_type taxonomy |
|
480 | - 'ee_assign_event_type', |
|
481 | - 'ee_manage_event_types', |
|
482 | - 'ee_edit_event_type', |
|
483 | - 'ee_delete_event_type', |
|
484 | - ), |
|
485 | - 'ee_events_administrator' => array( |
|
486 | - //core wp caps |
|
487 | - 'read', |
|
488 | - 'read_private_pages', |
|
489 | - 'read_private_posts', |
|
490 | - 'edit_users', |
|
491 | - 'edit_posts', |
|
492 | - 'edit_pages', |
|
493 | - 'edit_published_posts', |
|
494 | - 'edit_published_pages', |
|
495 | - 'edit_private_pages', |
|
496 | - 'edit_private_posts', |
|
497 | - 'edit_others_posts', |
|
498 | - 'edit_others_pages', |
|
499 | - 'publish_posts', |
|
500 | - 'publish_pages', |
|
501 | - 'delete_posts', |
|
502 | - 'delete_pages', |
|
503 | - 'delete_private_pages', |
|
504 | - 'delete_private_posts', |
|
505 | - 'delete_published_pages', |
|
506 | - 'delete_published_posts', |
|
507 | - 'delete_others_posts', |
|
508 | - 'delete_others_pages', |
|
509 | - 'manage_categories', |
|
510 | - 'manage_links', |
|
511 | - 'moderate_comments', |
|
512 | - 'unfiltered_html', |
|
513 | - 'upload_files', |
|
514 | - 'export', |
|
515 | - 'import', |
|
516 | - 'list_users', |
|
517 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
518 | - //basic ee access |
|
519 | - 'ee_read_ee', |
|
520 | - //events |
|
521 | - 'ee_publish_events', |
|
522 | - 'ee_read_private_events', |
|
523 | - 'ee_read_others_events', |
|
524 | - 'ee_read_event', |
|
525 | - 'ee_read_events', |
|
526 | - 'ee_edit_event', |
|
527 | - 'ee_edit_events', |
|
528 | - 'ee_edit_published_events', |
|
529 | - 'ee_edit_others_events', |
|
530 | - 'ee_edit_private_events', |
|
531 | - 'ee_delete_published_events', |
|
532 | - 'ee_delete_private_events', |
|
533 | - 'ee_delete_event', |
|
534 | - 'ee_delete_events', |
|
535 | - 'ee_delete_others_events', |
|
536 | - //event categories |
|
537 | - 'ee_manage_event_categories', |
|
538 | - 'ee_edit_event_category', |
|
539 | - 'ee_delete_event_category', |
|
540 | - 'ee_assign_event_category', |
|
541 | - //venues |
|
542 | - 'ee_publish_venues', |
|
543 | - 'ee_read_venue', |
|
544 | - 'ee_read_venues', |
|
545 | - 'ee_read_others_venues', |
|
546 | - 'ee_read_private_venues', |
|
547 | - 'ee_edit_venue', |
|
548 | - 'ee_edit_venues', |
|
549 | - 'ee_edit_others_venues', |
|
550 | - 'ee_edit_published_venues', |
|
551 | - 'ee_edit_private_venues', |
|
552 | - 'ee_delete_venue', |
|
553 | - 'ee_delete_venues', |
|
554 | - 'ee_delete_others_venues', |
|
555 | - 'ee_delete_private_venues', |
|
556 | - 'ee_delete_published_venues', |
|
557 | - //venue categories |
|
558 | - 'ee_manage_venue_categories', |
|
559 | - 'ee_edit_venue_category', |
|
560 | - 'ee_delete_venue_category', |
|
561 | - 'ee_assign_venue_category', |
|
562 | - //contacts |
|
563 | - 'ee_read_contact', |
|
564 | - 'ee_read_contacts', |
|
565 | - 'ee_edit_contact', |
|
566 | - 'ee_edit_contacts', |
|
567 | - 'ee_delete_contact', |
|
568 | - 'ee_delete_contacts', |
|
569 | - //registrations |
|
570 | - 'ee_read_registrations', |
|
571 | - 'ee_read_others_registrations', |
|
572 | - 'ee_edit_registration', |
|
573 | - 'ee_edit_registrations', |
|
574 | - 'ee_edit_others_registrations', |
|
575 | - 'ee_delete_registration', |
|
576 | - 'ee_delete_registrations', |
|
577 | - //checkins |
|
578 | - 'ee_read_others_checkins', |
|
579 | - 'ee_read_checkins', |
|
580 | - 'ee_edit_checkin', |
|
581 | - 'ee_edit_checkins', |
|
582 | - 'ee_edit_others_checkins', |
|
583 | - 'ee_delete_checkins', |
|
584 | - 'ee_delete_others_checkins', |
|
585 | - //transactions && payments |
|
586 | - 'ee_read_transaction', |
|
587 | - 'ee_read_transactions', |
|
588 | - 'ee_edit_payments', |
|
589 | - 'ee_delete_payments', |
|
590 | - //messages |
|
591 | - 'ee_read_messages', |
|
592 | - 'ee_read_others_messages', |
|
593 | - 'ee_read_global_messages', |
|
594 | - 'ee_edit_global_messages', |
|
595 | - 'ee_edit_message', |
|
596 | - 'ee_edit_messages', |
|
597 | - 'ee_edit_others_messages', |
|
598 | - 'ee_delete_messages', |
|
599 | - 'ee_delete_others_messages', |
|
600 | - 'ee_delete_global_messages', |
|
601 | - 'ee_send_message', |
|
602 | - //tickets |
|
603 | - 'ee_read_default_tickets', |
|
604 | - 'ee_read_others_default_tickets', |
|
605 | - 'ee_edit_default_ticket', |
|
606 | - 'ee_edit_default_tickets', |
|
607 | - 'ee_edit_others_default_tickets', |
|
608 | - 'ee_delete_default_tickets', |
|
609 | - 'ee_delete_others_default_tickets', |
|
610 | - //prices |
|
611 | - 'ee_edit_default_price', |
|
612 | - 'ee_edit_default_prices', |
|
613 | - 'ee_delete_default_price', |
|
614 | - 'ee_delete_default_prices', |
|
615 | - 'ee_edit_default_price_type', |
|
616 | - 'ee_edit_default_price_types', |
|
617 | - 'ee_delete_default_price_type', |
|
618 | - 'ee_delete_default_price_types', |
|
619 | - 'ee_read_default_prices', |
|
620 | - 'ee_read_default_price_types', |
|
621 | - //registration form |
|
622 | - 'ee_edit_question', |
|
623 | - 'ee_edit_questions', |
|
624 | - 'ee_edit_system_questions', |
|
625 | - 'ee_read_questions', |
|
626 | - 'ee_delete_questions', |
|
627 | - 'ee_edit_question_group', |
|
628 | - 'ee_edit_question_groups', |
|
629 | - 'ee_read_question_groups', |
|
630 | - 'ee_edit_system_question_groups', |
|
631 | - 'ee_delete_question_groups', |
|
632 | - //event_type taxonomy |
|
633 | - 'ee_assign_event_type', |
|
634 | - 'ee_manage_event_types', |
|
635 | - 'ee_edit_event_type', |
|
636 | - 'ee_delete_event_type', |
|
637 | - ) |
|
638 | - ) |
|
639 | - ); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * @return bool |
|
646 | - * @throws EE_Error |
|
647 | - */ |
|
648 | - private function setupCapabilitiesMap() |
|
649 | - { |
|
650 | - // if the initialization process hasn't even started, then we need to call init_caps() |
|
651 | - if($this->initialized === null) { |
|
652 | - return $this->init_caps(); |
|
653 | - } |
|
654 | - // unless resetting, get caps from db if we haven't already |
|
655 | - $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
656 | - ? $this->capabilities_map |
|
657 | - : get_option(self::option_name, array()); |
|
658 | - return true; |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * @param bool $update |
|
665 | - * @return bool |
|
666 | - */ |
|
667 | - private function updateCapabilitiesMap($update = true) |
|
668 | - { |
|
669 | - return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
670 | - } |
|
671 | - |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Adds capabilities to roles. |
|
676 | - * |
|
677 | - * @since 4.9.42 |
|
678 | - * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
679 | - * Note that this should ONLY be called on activation hook |
|
680 | - * otherwise the caps will be added on every request. |
|
681 | - * @return bool |
|
682 | - * @throws \EE_Error |
|
683 | - */ |
|
684 | - public function addCaps(array $capabilities_to_add) |
|
685 | - { |
|
686 | - // don't do anything if the capabilities map can not be initialized |
|
687 | - if (! $this->setupCapabilitiesMap()) { |
|
688 | - return false; |
|
689 | - } |
|
690 | - // and filter the array so others can get in on the fun during resets |
|
691 | - $capabilities_to_add = apply_filters( |
|
692 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
693 | - $capabilities_to_add, |
|
694 | - $this->reset, |
|
695 | - $this->capabilities_map |
|
696 | - ); |
|
697 | - $update_capabilities_map = false; |
|
698 | - // if not reset, see what caps are new for each role. if they're new, add them. |
|
699 | - foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
700 | - if (is_array($caps_for_role)) { |
|
701 | - foreach ($caps_for_role as $cap) { |
|
702 | - if ( |
|
703 | - ! $this->capHasBeenAddedToRole($role, $cap) |
|
704 | - && $this->add_cap_to_role($role, $cap, true, false) |
|
705 | - ) { |
|
706 | - $update_capabilities_map = true; |
|
707 | - } |
|
708 | - } |
|
709 | - } |
|
710 | - } |
|
711 | - // now let's just save the cap that has been set but only if there's been a change. |
|
712 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
713 | - do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
714 | - return $updated; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
721 | - * |
|
722 | - * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
723 | - * @return bool |
|
724 | - * @throws \EE_Error |
|
725 | - */ |
|
726 | - public function removeCaps($caps_map) |
|
727 | - { |
|
728 | - // don't do anything if the capabilities map can not be initialized |
|
729 | - if (! $this->setupCapabilitiesMap()) { |
|
730 | - return false; |
|
731 | - } |
|
732 | - $update_capabilities_map = false; |
|
733 | - foreach ($caps_map as $role => $caps_for_role) { |
|
734 | - if (is_array($caps_for_role)) { |
|
735 | - foreach ($caps_for_role as $cap) { |
|
736 | - if ( |
|
737 | - $this->capHasBeenAddedToRole($role, $cap) |
|
738 | - && $this->remove_cap_from_role($role, $cap, false) |
|
739 | - ) { |
|
740 | - $update_capabilities_map = true; |
|
741 | - } |
|
742 | - } |
|
743 | - } |
|
744 | - } |
|
745 | - // maybe resave the caps |
|
746 | - return $this->updateCapabilitiesMap($update_capabilities_map); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - |
|
751 | - /** |
|
752 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
753 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
754 | - * this is a wrapper for $wp_role->add_cap() |
|
755 | - * |
|
756 | - * @see wp-includes/capabilities.php |
|
757 | - * @since 4.5.0 |
|
758 | - * @param string|WP_Role $role A WordPress role the capability is being added to |
|
759 | - * @param string $cap The capability being added to the role |
|
760 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
761 | - * @param bool $update_capabilities_map |
|
762 | - * @return bool |
|
763 | - * @throws \EE_Error |
|
764 | - */ |
|
765 | - public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
766 | - { |
|
767 | - // capture incoming value for $role because we may need it to create a new WP_Role |
|
768 | - $orig_role = $role; |
|
769 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
770 | - //if the role isn't available then we create it. |
|
771 | - if (! $role instanceof WP_Role) { |
|
772 | - // if a plugin wants to create a specific role name then they should create the role before |
|
773 | - // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
774 | - // - removes any `ee_` namespacing from the start of the slug. |
|
775 | - // - replaces `_` with ` ` (empty space). |
|
776 | - // - sentence case on the resulting string. |
|
777 | - $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
778 | - $role = add_role($orig_role, $role_label); |
|
779 | - } |
|
780 | - if ($role instanceof WP_Role) { |
|
781 | - // don't do anything if the capabilities map can not be initialized |
|
782 | - if (! $this->setupCapabilitiesMap()) { |
|
783 | - return false; |
|
784 | - } |
|
785 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
786 | - $role->add_cap($cap, $grant); |
|
787 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
788 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
789 | - return true; |
|
790 | - } |
|
791 | - } |
|
792 | - return false; |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
799 | - * Wrapper for $wp_role->remove_cap() |
|
800 | - * |
|
801 | - * @see wp-includes/capabilities.php |
|
802 | - * @since 4.5.0 |
|
803 | - * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
804 | - * @param string $cap The capability being removed |
|
805 | - * @param bool $update_capabilities_map |
|
806 | - * @return bool |
|
807 | - * @throws \EE_Error |
|
808 | - */ |
|
809 | - public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
810 | - { |
|
811 | - // don't do anything if the capabilities map can not be initialized |
|
812 | - if (! $this->setupCapabilitiesMap()) { |
|
813 | - return false; |
|
814 | - } |
|
815 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
816 | - if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
817 | - $role->remove_cap($cap); |
|
818 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
819 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
820 | - return true; |
|
821 | - } |
|
822 | - return false; |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * @param string $role_name |
|
829 | - * @param string $cap |
|
830 | - * @param bool $get_index |
|
831 | - * @return bool|mixed |
|
832 | - */ |
|
833 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
834 | - { |
|
835 | - if ( |
|
836 | - isset($this->capabilities_map[$role_name]) |
|
837 | - && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
838 | - ) { |
|
839 | - return $get_index ? $index : true; |
|
840 | - } |
|
841 | - return false; |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - |
|
846 | - /** |
|
847 | - * Wrapper for the native WP current_user_can() method. |
|
848 | - * This is provided as a handy method for a couple things: |
|
849 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
850 | - * write those filters wherever current_user_can is called). |
|
851 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
852 | - * |
|
853 | - * @since 4.5.0 |
|
854 | - * |
|
855 | - * @param string $cap The cap being checked. |
|
856 | - * @param string $context The context where the current_user_can is being called from. |
|
857 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
858 | - * filters. |
|
859 | - * |
|
860 | - * @return bool Whether user can or not. |
|
861 | - */ |
|
862 | - public function current_user_can($cap, $context, $id = 0) |
|
863 | - { |
|
864 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
865 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
866 | - $filtered_cap = apply_filters( |
|
867 | - 'FHEE__EE_Capabilities__current_user_can__cap', |
|
868 | - $filtered_cap, |
|
869 | - $context, |
|
870 | - $cap, |
|
871 | - $id |
|
872 | - ); |
|
873 | - return ! empty($id) |
|
874 | - ? current_user_can($filtered_cap, $id) |
|
875 | - : current_user_can($filtered_cap); |
|
876 | - } |
|
877 | - |
|
878 | - |
|
879 | - |
|
880 | - /** |
|
881 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
882 | - * |
|
883 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
884 | - * @param string $cap The capability string being checked |
|
885 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
886 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
887 | - * filters) |
|
888 | - * |
|
889 | - * @return bool Whether user can or not. |
|
890 | - */ |
|
891 | - public function user_can($user, $cap, $context, $id = 0) |
|
892 | - { |
|
893 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
894 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
895 | - $filtered_cap = apply_filters( |
|
896 | - 'FHEE__EE_Capabilities__user_can__cap', |
|
897 | - $filtered_cap, |
|
898 | - $context, |
|
899 | - $cap, |
|
900 | - $user, |
|
901 | - $id |
|
902 | - ); |
|
903 | - return ! empty($id) |
|
904 | - ? user_can($user, $filtered_cap, $id) |
|
905 | - : user_can($user, $filtered_cap); |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
912 | - * This is provided as a handy method for a couple things: |
|
913 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
914 | - * write those filters wherever current_user_can is called). |
|
915 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
916 | - * |
|
917 | - * @since 4.5.0 |
|
918 | - * |
|
919 | - * @param int $blog_id The blog id that is being checked for. |
|
920 | - * @param string $cap The cap being checked. |
|
921 | - * @param string $context The context where the current_user_can is being called from. |
|
922 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
923 | - * filters. |
|
924 | - * |
|
925 | - * @return bool Whether user can or not. |
|
926 | - */ |
|
927 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
928 | - { |
|
929 | - $user_can = ! empty($id) |
|
930 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
931 | - : current_user_can($blog_id, $cap); |
|
932 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
933 | - $user_can = apply_filters( |
|
934 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
935 | - $user_can, |
|
936 | - $blog_id, |
|
937 | - $cap, |
|
938 | - $id |
|
939 | - ); |
|
940 | - $user_can = apply_filters( |
|
941 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
942 | - $user_can, |
|
943 | - $context, |
|
944 | - $blog_id, |
|
945 | - $cap, |
|
946 | - $id |
|
947 | - ); |
|
948 | - return $user_can; |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * This helper method just returns an array of registered EE capabilities. |
|
955 | - * |
|
956 | - * @since 4.5.0 |
|
957 | - * @param string $role If empty then the entire role/capability map is returned. |
|
958 | - * Otherwise just the capabilities for the given role are returned. |
|
959 | - * @return array |
|
960 | - * @throws EE_Error |
|
961 | - */ |
|
962 | - public function get_ee_capabilities($role = 'administrator') |
|
963 | - { |
|
964 | - if (! $this->initialized) { |
|
965 | - $this->init_caps(); |
|
966 | - } |
|
967 | - if (empty($role)) { |
|
968 | - return $this->capabilities_map; |
|
969 | - } |
|
970 | - return isset($this->capabilities_map[ $role ]) |
|
971 | - ? $this->capabilities_map[ $role ] |
|
972 | - : array(); |
|
973 | - } |
|
974 | - |
|
975 | - |
|
976 | - |
|
977 | - /** |
|
978 | - * @deprecated 4.9.42 |
|
979 | - * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
980 | - * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
981 | - * @param array $caps_map Optional. |
|
982 | - * Can be used to send a custom map of roles and capabilities for setting them up. |
|
983 | - * Note that this should ONLY be called on activation hook or some other one-time |
|
984 | - * task otherwise the caps will be added on every request. |
|
985 | - * @return void |
|
986 | - * @throws EE_Error |
|
987 | - */ |
|
988 | - public function init_role_caps($reset = false, $caps_map = array()) |
|
989 | - { |
|
990 | - // If this method is called directly and reset is set as 'true', |
|
991 | - // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
992 | - // to guarantee that everything is set up correctly. |
|
993 | - // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
994 | - if ($reset) { |
|
995 | - EE_Error::doing_it_wrong( |
|
996 | - __METHOD__, |
|
997 | - sprintf( |
|
998 | - esc_html__( |
|
999 | - 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
1000 | - 'event_espresso' |
|
1001 | - ), |
|
1002 | - '$reset', |
|
1003 | - __METHOD__ . '()', |
|
1004 | - 'EE_Capabilities::init_caps()', |
|
1005 | - 'true' |
|
1006 | - ), |
|
1007 | - '4.9.42', |
|
1008 | - '5.0.0' |
|
1009 | - ); |
|
1010 | - } |
|
1011 | - $this->addCaps($caps_map); |
|
1012 | - } |
|
21 | + /** |
|
22 | + * the name of the wp option used to store caps previously initialized |
|
23 | + */ |
|
24 | + const option_name = 'ee_caps_initialized'; |
|
25 | + |
|
26 | + /** |
|
27 | + * instance of EE_Capabilities object |
|
28 | + * |
|
29 | + * @var EE_Capabilities |
|
30 | + */ |
|
31 | + private static $_instance; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * This is a map of caps that correspond to a default WP_Role. |
|
36 | + * Array is indexed by Role and values are ee capabilities. |
|
37 | + * |
|
38 | + * @since 4.5.0 |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $capabilities_map = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * This used to hold an array of EE_Meta_Capability_Map objects |
|
46 | + * that define the granular capabilities mapped to for a user depending on context. |
|
47 | + * |
|
48 | + * @var EE_Meta_Capability_Map[] |
|
49 | + */ |
|
50 | + private $_meta_caps = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * The internal $capabilities_map needs to be initialized before it can be used. |
|
54 | + * This flag tracks whether that has happened or not. |
|
55 | + * But for this to work, we need three states to indicate: |
|
56 | + * initialization has not occurred at all |
|
57 | + * initialization has started but is not complete |
|
58 | + * initialization is complete |
|
59 | + * The reason this is needed is because the addCaps() method |
|
60 | + * normally requires the $capabilities_map to be initialized, |
|
61 | + * but is also used during the initialization process. |
|
62 | + * So: |
|
63 | + * If initialized === null, init_caps() will be called before any other methods will run. |
|
64 | + * If initialized === false, then init_caps() is in the process of running it's logic. |
|
65 | + * If initialized === true, then init_caps() has completed the initialization process. |
|
66 | + * |
|
67 | + * @var boolean|null $initialized |
|
68 | + */ |
|
69 | + private $initialized; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var boolean $reset |
|
73 | + */ |
|
74 | + private $reset = false; |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * singleton method used to instantiate class object |
|
80 | + * |
|
81 | + * @since 4.5.0 |
|
82 | + * |
|
83 | + * @return EE_Capabilities |
|
84 | + */ |
|
85 | + public static function instance() |
|
86 | + { |
|
87 | + //check if instantiated, and if not do so. |
|
88 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
89 | + self::$_instance = new self(); |
|
90 | + } |
|
91 | + return self::$_instance; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * private constructor |
|
98 | + * |
|
99 | + * @since 4.5.0 |
|
100 | + */ |
|
101 | + private function __construct() |
|
102 | + { |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
109 | + * |
|
110 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
111 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
112 | + * ensures that they are up to date. |
|
113 | + * |
|
114 | + * @since 4.5.0 |
|
115 | + * @return bool |
|
116 | + * @throws EE_Error |
|
117 | + */ |
|
118 | + public function init_caps($reset = false) |
|
119 | + { |
|
120 | + if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
121 | + return false; |
|
122 | + } |
|
123 | + $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
124 | + // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
125 | + if ($this->reset) { |
|
126 | + $this->initialized = null; |
|
127 | + $this->capabilities_map = array(); |
|
128 | + delete_option(self::option_name); |
|
129 | + } |
|
130 | + if ($this->initialized === null) { |
|
131 | + $this->initialized = false; |
|
132 | + do_action( |
|
133 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
134 | + $this->reset |
|
135 | + ); |
|
136 | + $this->addCaps($this->_init_caps_map()); |
|
137 | + $this->_set_meta_caps(); |
|
138 | + do_action( |
|
139 | + 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
140 | + $this->capabilities_map |
|
141 | + ); |
|
142 | + $this->initialized = true; |
|
143 | + } |
|
144 | + // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
145 | + $this->reset = false; |
|
146 | + return true; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * This sets the meta caps property. |
|
153 | + * |
|
154 | + * @since 4.5.0 |
|
155 | + * @return void |
|
156 | + * @throws EE_Error |
|
157 | + */ |
|
158 | + private function _set_meta_caps() |
|
159 | + { |
|
160 | + // get default meta caps and filter the returned array |
|
161 | + $this->_meta_caps = apply_filters( |
|
162 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
163 | + $this->_get_default_meta_caps_array() |
|
164 | + ); |
|
165 | + //add filter for map_meta_caps but only if models can query. |
|
166 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
167 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * This builds and returns the default meta_caps array only once. |
|
175 | + * |
|
176 | + * @since 4.8.28.rc.012 |
|
177 | + * @return array |
|
178 | + * @throws EE_Error |
|
179 | + */ |
|
180 | + private function _get_default_meta_caps_array() |
|
181 | + { |
|
182 | + static $default_meta_caps = array(); |
|
183 | + // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
184 | + if (empty($default_meta_caps)) { |
|
185 | + $default_meta_caps = array( |
|
186 | + //edits |
|
187 | + new EE_Meta_Capability_Map_Edit( |
|
188 | + 'ee_edit_event', |
|
189 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
190 | + ), |
|
191 | + new EE_Meta_Capability_Map_Edit( |
|
192 | + 'ee_edit_venue', |
|
193 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
194 | + ), |
|
195 | + new EE_Meta_Capability_Map_Edit( |
|
196 | + 'ee_edit_registration', |
|
197 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
198 | + ), |
|
199 | + new EE_Meta_Capability_Map_Edit( |
|
200 | + 'ee_edit_checkin', |
|
201 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
202 | + ), |
|
203 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
204 | + 'ee_edit_message', |
|
205 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
206 | + ), |
|
207 | + new EE_Meta_Capability_Map_Edit( |
|
208 | + 'ee_edit_default_ticket', |
|
209 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
210 | + ), |
|
211 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
212 | + 'ee_edit_question', |
|
213 | + array('Question', '', '', 'ee_edit_system_questions') |
|
214 | + ), |
|
215 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
216 | + 'ee_edit_question_group', |
|
217 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
218 | + ), |
|
219 | + new EE_Meta_Capability_Map_Edit( |
|
220 | + 'ee_edit_payment_method', |
|
221 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
222 | + ), |
|
223 | + //reads |
|
224 | + new EE_Meta_Capability_Map_Read( |
|
225 | + 'ee_read_event', |
|
226 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
227 | + ), |
|
228 | + new EE_Meta_Capability_Map_Read( |
|
229 | + 'ee_read_venue', |
|
230 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
231 | + ), |
|
232 | + new EE_Meta_Capability_Map_Read( |
|
233 | + 'ee_read_registration', |
|
234 | + array('Registration', '', '', 'ee_edit_others_registrations') |
|
235 | + ), |
|
236 | + new EE_Meta_Capability_Map_Read( |
|
237 | + 'ee_read_checkin', |
|
238 | + array('Registration', '', '', 'ee_read_others_checkins') |
|
239 | + ), |
|
240 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
241 | + 'ee_read_message', |
|
242 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
243 | + ), |
|
244 | + new EE_Meta_Capability_Map_Read( |
|
245 | + 'ee_read_default_ticket', |
|
246 | + array('Ticket', '', '', 'ee_read_others_default_tickets') |
|
247 | + ), |
|
248 | + new EE_Meta_Capability_Map_Read( |
|
249 | + 'ee_read_payment_method', |
|
250 | + array('Payment_Method', '', '', 'ee_read_others_payment_methods') |
|
251 | + ), |
|
252 | + //deletes |
|
253 | + new EE_Meta_Capability_Map_Delete( |
|
254 | + 'ee_delete_event', |
|
255 | + array( |
|
256 | + 'Event', |
|
257 | + 'ee_delete_published_events', |
|
258 | + 'ee_delete_others_events', |
|
259 | + 'ee_delete_private_events', |
|
260 | + ) |
|
261 | + ), |
|
262 | + new EE_Meta_Capability_Map_Delete( |
|
263 | + 'ee_delete_venue', |
|
264 | + array( |
|
265 | + 'Venue', |
|
266 | + 'ee_delete_published_venues', |
|
267 | + 'ee_delete_others_venues', |
|
268 | + 'ee_delete_private_venues', |
|
269 | + ) |
|
270 | + ), |
|
271 | + new EE_Meta_Capability_Map_Delete( |
|
272 | + 'ee_delete_registration', |
|
273 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
274 | + ), |
|
275 | + new EE_Meta_Capability_Map_Delete( |
|
276 | + 'ee_delete_checkin', |
|
277 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
278 | + ), |
|
279 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
280 | + 'ee_delete_message', |
|
281 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
282 | + ), |
|
283 | + new EE_Meta_Capability_Map_Delete( |
|
284 | + 'ee_delete_default_ticket', |
|
285 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
286 | + ), |
|
287 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
288 | + 'ee_delete_question', |
|
289 | + array('Question', '', '', 'delete_system_questions') |
|
290 | + ), |
|
291 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
292 | + 'ee_delete_question_group', |
|
293 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
294 | + ), |
|
295 | + new EE_Meta_Capability_Map_Delete( |
|
296 | + 'ee_delete_payment_method', |
|
297 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
298 | + ), |
|
299 | + ); |
|
300 | + } |
|
301 | + return $default_meta_caps; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
308 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
309 | + * |
|
310 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
311 | + * |
|
312 | + * @since 4.5.0 |
|
313 | + * @see wp-includes/capabilities.php |
|
314 | + * |
|
315 | + * @param array $caps actual users capabilities |
|
316 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
317 | + * @param int $user_id The user id |
|
318 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
319 | + * @return array actual users capabilities |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
323 | + { |
|
324 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
325 | + //loop through our _meta_caps array |
|
326 | + foreach ($this->_meta_caps as $meta_map) { |
|
327 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
328 | + continue; |
|
329 | + } |
|
330 | + // don't load models if there is no object ID in the args |
|
331 | + if (! empty($args[0])) { |
|
332 | + $meta_map->ensure_is_model(); |
|
333 | + } |
|
334 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
335 | + } |
|
336 | + } |
|
337 | + return $caps; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
344 | + * Note this array is filtered. |
|
345 | + * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
346 | + * |
|
347 | + * @since 4.5.0 |
|
348 | + * |
|
349 | + * @return array |
|
350 | + */ |
|
351 | + private function _init_caps_map() |
|
352 | + { |
|
353 | + return apply_filters( |
|
354 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
355 | + array( |
|
356 | + 'administrator' => array( |
|
357 | + //basic access |
|
358 | + 'ee_read_ee', |
|
359 | + //gateways |
|
360 | + /** |
|
361 | + * note that with payment method capabilities, although we've implemented |
|
362 | + * capability mapping which will be used for accessing payment methods owned by |
|
363 | + * other users. This is not fully implemented yet in the payment method ui. |
|
364 | + * Currently only the "plural" caps are in active use. |
|
365 | + * (Specific payment method caps are in use as well). |
|
366 | + **/ |
|
367 | + 'ee_manage_gateways', |
|
368 | + 'ee_read_payment_methods', |
|
369 | + 'ee_read_others_payment_methods', |
|
370 | + 'ee_edit_payment_methods', |
|
371 | + 'ee_edit_others_payment_methods', |
|
372 | + 'ee_delete_payment_methods', |
|
373 | + //events |
|
374 | + 'ee_publish_events', |
|
375 | + 'ee_read_private_events', |
|
376 | + 'ee_read_others_events', |
|
377 | + 'ee_read_events', |
|
378 | + 'ee_edit_events', |
|
379 | + 'ee_edit_published_events', |
|
380 | + 'ee_edit_others_events', |
|
381 | + 'ee_edit_private_events', |
|
382 | + 'ee_delete_published_events', |
|
383 | + 'ee_delete_private_events', |
|
384 | + 'ee_delete_events', |
|
385 | + 'ee_delete_others_events', |
|
386 | + //event categories |
|
387 | + 'ee_manage_event_categories', |
|
388 | + 'ee_edit_event_category', |
|
389 | + 'ee_delete_event_category', |
|
390 | + 'ee_assign_event_category', |
|
391 | + //venues |
|
392 | + 'ee_publish_venues', |
|
393 | + 'ee_read_venues', |
|
394 | + 'ee_read_others_venues', |
|
395 | + 'ee_read_private_venues', |
|
396 | + 'ee_edit_venues', |
|
397 | + 'ee_edit_others_venues', |
|
398 | + 'ee_edit_published_venues', |
|
399 | + 'ee_edit_private_venues', |
|
400 | + 'ee_delete_venues', |
|
401 | + 'ee_delete_others_venues', |
|
402 | + 'ee_delete_private_venues', |
|
403 | + 'ee_delete_published_venues', |
|
404 | + //venue categories |
|
405 | + 'ee_manage_venue_categories', |
|
406 | + 'ee_edit_venue_category', |
|
407 | + 'ee_delete_venue_category', |
|
408 | + 'ee_assign_venue_category', |
|
409 | + //contacts |
|
410 | + 'ee_read_contact', |
|
411 | + 'ee_read_contacts', |
|
412 | + 'ee_edit_contact', |
|
413 | + 'ee_edit_contacts', |
|
414 | + 'ee_delete_contact', |
|
415 | + 'ee_delete_contacts', |
|
416 | + //registrations |
|
417 | + 'ee_read_registrations', |
|
418 | + 'ee_read_others_registrations', |
|
419 | + 'ee_edit_registrations', |
|
420 | + 'ee_edit_others_registrations', |
|
421 | + 'ee_delete_registrations', |
|
422 | + //checkins |
|
423 | + 'ee_read_others_checkins', |
|
424 | + 'ee_read_checkins', |
|
425 | + 'ee_edit_checkins', |
|
426 | + 'ee_edit_others_checkins', |
|
427 | + 'ee_delete_checkin', |
|
428 | + 'ee_delete_checkins', |
|
429 | + 'ee_delete_others_checkins', |
|
430 | + //transactions && payments |
|
431 | + 'ee_read_transaction', |
|
432 | + 'ee_read_transactions', |
|
433 | + 'ee_edit_payments', |
|
434 | + 'ee_delete_payments', |
|
435 | + //messages |
|
436 | + 'ee_read_message', |
|
437 | + 'ee_read_messages', |
|
438 | + 'ee_read_others_messages', |
|
439 | + 'ee_read_global_messages', |
|
440 | + 'ee_edit_global_messages', |
|
441 | + 'ee_edit_messages', |
|
442 | + 'ee_edit_others_messages', |
|
443 | + 'ee_delete_message', |
|
444 | + 'ee_delete_messages', |
|
445 | + 'ee_delete_others_messages', |
|
446 | + 'ee_delete_global_messages', |
|
447 | + 'ee_send_message', |
|
448 | + //tickets |
|
449 | + 'ee_read_default_ticket', |
|
450 | + 'ee_read_default_tickets', |
|
451 | + 'ee_read_others_default_tickets', |
|
452 | + 'ee_edit_default_tickets', |
|
453 | + 'ee_edit_others_default_tickets', |
|
454 | + 'ee_delete_default_ticket', |
|
455 | + 'ee_delete_default_tickets', |
|
456 | + 'ee_delete_others_default_tickets', |
|
457 | + //prices |
|
458 | + 'ee_edit_default_price', |
|
459 | + 'ee_edit_default_prices', |
|
460 | + 'ee_delete_default_price', |
|
461 | + 'ee_delete_default_prices', |
|
462 | + 'ee_edit_default_price_type', |
|
463 | + 'ee_edit_default_price_types', |
|
464 | + 'ee_delete_default_price_type', |
|
465 | + 'ee_delete_default_price_types', |
|
466 | + 'ee_read_default_prices', |
|
467 | + 'ee_read_default_price_types', |
|
468 | + //registration form |
|
469 | + 'ee_edit_questions', |
|
470 | + 'ee_edit_system_questions', |
|
471 | + 'ee_read_questions', |
|
472 | + 'ee_delete_question', |
|
473 | + 'ee_delete_questions', |
|
474 | + 'ee_edit_question_groups', |
|
475 | + 'ee_read_question_groups', |
|
476 | + 'ee_edit_system_question_groups', |
|
477 | + 'ee_delete_question_group', |
|
478 | + 'ee_delete_question_groups', |
|
479 | + //event_type taxonomy |
|
480 | + 'ee_assign_event_type', |
|
481 | + 'ee_manage_event_types', |
|
482 | + 'ee_edit_event_type', |
|
483 | + 'ee_delete_event_type', |
|
484 | + ), |
|
485 | + 'ee_events_administrator' => array( |
|
486 | + //core wp caps |
|
487 | + 'read', |
|
488 | + 'read_private_pages', |
|
489 | + 'read_private_posts', |
|
490 | + 'edit_users', |
|
491 | + 'edit_posts', |
|
492 | + 'edit_pages', |
|
493 | + 'edit_published_posts', |
|
494 | + 'edit_published_pages', |
|
495 | + 'edit_private_pages', |
|
496 | + 'edit_private_posts', |
|
497 | + 'edit_others_posts', |
|
498 | + 'edit_others_pages', |
|
499 | + 'publish_posts', |
|
500 | + 'publish_pages', |
|
501 | + 'delete_posts', |
|
502 | + 'delete_pages', |
|
503 | + 'delete_private_pages', |
|
504 | + 'delete_private_posts', |
|
505 | + 'delete_published_pages', |
|
506 | + 'delete_published_posts', |
|
507 | + 'delete_others_posts', |
|
508 | + 'delete_others_pages', |
|
509 | + 'manage_categories', |
|
510 | + 'manage_links', |
|
511 | + 'moderate_comments', |
|
512 | + 'unfiltered_html', |
|
513 | + 'upload_files', |
|
514 | + 'export', |
|
515 | + 'import', |
|
516 | + 'list_users', |
|
517 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
518 | + //basic ee access |
|
519 | + 'ee_read_ee', |
|
520 | + //events |
|
521 | + 'ee_publish_events', |
|
522 | + 'ee_read_private_events', |
|
523 | + 'ee_read_others_events', |
|
524 | + 'ee_read_event', |
|
525 | + 'ee_read_events', |
|
526 | + 'ee_edit_event', |
|
527 | + 'ee_edit_events', |
|
528 | + 'ee_edit_published_events', |
|
529 | + 'ee_edit_others_events', |
|
530 | + 'ee_edit_private_events', |
|
531 | + 'ee_delete_published_events', |
|
532 | + 'ee_delete_private_events', |
|
533 | + 'ee_delete_event', |
|
534 | + 'ee_delete_events', |
|
535 | + 'ee_delete_others_events', |
|
536 | + //event categories |
|
537 | + 'ee_manage_event_categories', |
|
538 | + 'ee_edit_event_category', |
|
539 | + 'ee_delete_event_category', |
|
540 | + 'ee_assign_event_category', |
|
541 | + //venues |
|
542 | + 'ee_publish_venues', |
|
543 | + 'ee_read_venue', |
|
544 | + 'ee_read_venues', |
|
545 | + 'ee_read_others_venues', |
|
546 | + 'ee_read_private_venues', |
|
547 | + 'ee_edit_venue', |
|
548 | + 'ee_edit_venues', |
|
549 | + 'ee_edit_others_venues', |
|
550 | + 'ee_edit_published_venues', |
|
551 | + 'ee_edit_private_venues', |
|
552 | + 'ee_delete_venue', |
|
553 | + 'ee_delete_venues', |
|
554 | + 'ee_delete_others_venues', |
|
555 | + 'ee_delete_private_venues', |
|
556 | + 'ee_delete_published_venues', |
|
557 | + //venue categories |
|
558 | + 'ee_manage_venue_categories', |
|
559 | + 'ee_edit_venue_category', |
|
560 | + 'ee_delete_venue_category', |
|
561 | + 'ee_assign_venue_category', |
|
562 | + //contacts |
|
563 | + 'ee_read_contact', |
|
564 | + 'ee_read_contacts', |
|
565 | + 'ee_edit_contact', |
|
566 | + 'ee_edit_contacts', |
|
567 | + 'ee_delete_contact', |
|
568 | + 'ee_delete_contacts', |
|
569 | + //registrations |
|
570 | + 'ee_read_registrations', |
|
571 | + 'ee_read_others_registrations', |
|
572 | + 'ee_edit_registration', |
|
573 | + 'ee_edit_registrations', |
|
574 | + 'ee_edit_others_registrations', |
|
575 | + 'ee_delete_registration', |
|
576 | + 'ee_delete_registrations', |
|
577 | + //checkins |
|
578 | + 'ee_read_others_checkins', |
|
579 | + 'ee_read_checkins', |
|
580 | + 'ee_edit_checkin', |
|
581 | + 'ee_edit_checkins', |
|
582 | + 'ee_edit_others_checkins', |
|
583 | + 'ee_delete_checkins', |
|
584 | + 'ee_delete_others_checkins', |
|
585 | + //transactions && payments |
|
586 | + 'ee_read_transaction', |
|
587 | + 'ee_read_transactions', |
|
588 | + 'ee_edit_payments', |
|
589 | + 'ee_delete_payments', |
|
590 | + //messages |
|
591 | + 'ee_read_messages', |
|
592 | + 'ee_read_others_messages', |
|
593 | + 'ee_read_global_messages', |
|
594 | + 'ee_edit_global_messages', |
|
595 | + 'ee_edit_message', |
|
596 | + 'ee_edit_messages', |
|
597 | + 'ee_edit_others_messages', |
|
598 | + 'ee_delete_messages', |
|
599 | + 'ee_delete_others_messages', |
|
600 | + 'ee_delete_global_messages', |
|
601 | + 'ee_send_message', |
|
602 | + //tickets |
|
603 | + 'ee_read_default_tickets', |
|
604 | + 'ee_read_others_default_tickets', |
|
605 | + 'ee_edit_default_ticket', |
|
606 | + 'ee_edit_default_tickets', |
|
607 | + 'ee_edit_others_default_tickets', |
|
608 | + 'ee_delete_default_tickets', |
|
609 | + 'ee_delete_others_default_tickets', |
|
610 | + //prices |
|
611 | + 'ee_edit_default_price', |
|
612 | + 'ee_edit_default_prices', |
|
613 | + 'ee_delete_default_price', |
|
614 | + 'ee_delete_default_prices', |
|
615 | + 'ee_edit_default_price_type', |
|
616 | + 'ee_edit_default_price_types', |
|
617 | + 'ee_delete_default_price_type', |
|
618 | + 'ee_delete_default_price_types', |
|
619 | + 'ee_read_default_prices', |
|
620 | + 'ee_read_default_price_types', |
|
621 | + //registration form |
|
622 | + 'ee_edit_question', |
|
623 | + 'ee_edit_questions', |
|
624 | + 'ee_edit_system_questions', |
|
625 | + 'ee_read_questions', |
|
626 | + 'ee_delete_questions', |
|
627 | + 'ee_edit_question_group', |
|
628 | + 'ee_edit_question_groups', |
|
629 | + 'ee_read_question_groups', |
|
630 | + 'ee_edit_system_question_groups', |
|
631 | + 'ee_delete_question_groups', |
|
632 | + //event_type taxonomy |
|
633 | + 'ee_assign_event_type', |
|
634 | + 'ee_manage_event_types', |
|
635 | + 'ee_edit_event_type', |
|
636 | + 'ee_delete_event_type', |
|
637 | + ) |
|
638 | + ) |
|
639 | + ); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * @return bool |
|
646 | + * @throws EE_Error |
|
647 | + */ |
|
648 | + private function setupCapabilitiesMap() |
|
649 | + { |
|
650 | + // if the initialization process hasn't even started, then we need to call init_caps() |
|
651 | + if($this->initialized === null) { |
|
652 | + return $this->init_caps(); |
|
653 | + } |
|
654 | + // unless resetting, get caps from db if we haven't already |
|
655 | + $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
656 | + ? $this->capabilities_map |
|
657 | + : get_option(self::option_name, array()); |
|
658 | + return true; |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * @param bool $update |
|
665 | + * @return bool |
|
666 | + */ |
|
667 | + private function updateCapabilitiesMap($update = true) |
|
668 | + { |
|
669 | + return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
670 | + } |
|
671 | + |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Adds capabilities to roles. |
|
676 | + * |
|
677 | + * @since 4.9.42 |
|
678 | + * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
679 | + * Note that this should ONLY be called on activation hook |
|
680 | + * otherwise the caps will be added on every request. |
|
681 | + * @return bool |
|
682 | + * @throws \EE_Error |
|
683 | + */ |
|
684 | + public function addCaps(array $capabilities_to_add) |
|
685 | + { |
|
686 | + // don't do anything if the capabilities map can not be initialized |
|
687 | + if (! $this->setupCapabilitiesMap()) { |
|
688 | + return false; |
|
689 | + } |
|
690 | + // and filter the array so others can get in on the fun during resets |
|
691 | + $capabilities_to_add = apply_filters( |
|
692 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
693 | + $capabilities_to_add, |
|
694 | + $this->reset, |
|
695 | + $this->capabilities_map |
|
696 | + ); |
|
697 | + $update_capabilities_map = false; |
|
698 | + // if not reset, see what caps are new for each role. if they're new, add them. |
|
699 | + foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
700 | + if (is_array($caps_for_role)) { |
|
701 | + foreach ($caps_for_role as $cap) { |
|
702 | + if ( |
|
703 | + ! $this->capHasBeenAddedToRole($role, $cap) |
|
704 | + && $this->add_cap_to_role($role, $cap, true, false) |
|
705 | + ) { |
|
706 | + $update_capabilities_map = true; |
|
707 | + } |
|
708 | + } |
|
709 | + } |
|
710 | + } |
|
711 | + // now let's just save the cap that has been set but only if there's been a change. |
|
712 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
713 | + do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
714 | + return $updated; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
721 | + * |
|
722 | + * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
723 | + * @return bool |
|
724 | + * @throws \EE_Error |
|
725 | + */ |
|
726 | + public function removeCaps($caps_map) |
|
727 | + { |
|
728 | + // don't do anything if the capabilities map can not be initialized |
|
729 | + if (! $this->setupCapabilitiesMap()) { |
|
730 | + return false; |
|
731 | + } |
|
732 | + $update_capabilities_map = false; |
|
733 | + foreach ($caps_map as $role => $caps_for_role) { |
|
734 | + if (is_array($caps_for_role)) { |
|
735 | + foreach ($caps_for_role as $cap) { |
|
736 | + if ( |
|
737 | + $this->capHasBeenAddedToRole($role, $cap) |
|
738 | + && $this->remove_cap_from_role($role, $cap, false) |
|
739 | + ) { |
|
740 | + $update_capabilities_map = true; |
|
741 | + } |
|
742 | + } |
|
743 | + } |
|
744 | + } |
|
745 | + // maybe resave the caps |
|
746 | + return $this->updateCapabilitiesMap($update_capabilities_map); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + |
|
751 | + /** |
|
752 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
753 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
754 | + * this is a wrapper for $wp_role->add_cap() |
|
755 | + * |
|
756 | + * @see wp-includes/capabilities.php |
|
757 | + * @since 4.5.0 |
|
758 | + * @param string|WP_Role $role A WordPress role the capability is being added to |
|
759 | + * @param string $cap The capability being added to the role |
|
760 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
761 | + * @param bool $update_capabilities_map |
|
762 | + * @return bool |
|
763 | + * @throws \EE_Error |
|
764 | + */ |
|
765 | + public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
766 | + { |
|
767 | + // capture incoming value for $role because we may need it to create a new WP_Role |
|
768 | + $orig_role = $role; |
|
769 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
770 | + //if the role isn't available then we create it. |
|
771 | + if (! $role instanceof WP_Role) { |
|
772 | + // if a plugin wants to create a specific role name then they should create the role before |
|
773 | + // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
774 | + // - removes any `ee_` namespacing from the start of the slug. |
|
775 | + // - replaces `_` with ` ` (empty space). |
|
776 | + // - sentence case on the resulting string. |
|
777 | + $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
778 | + $role = add_role($orig_role, $role_label); |
|
779 | + } |
|
780 | + if ($role instanceof WP_Role) { |
|
781 | + // don't do anything if the capabilities map can not be initialized |
|
782 | + if (! $this->setupCapabilitiesMap()) { |
|
783 | + return false; |
|
784 | + } |
|
785 | + if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
786 | + $role->add_cap($cap, $grant); |
|
787 | + $this->capabilities_map[ $role->name ][] = $cap; |
|
788 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
789 | + return true; |
|
790 | + } |
|
791 | + } |
|
792 | + return false; |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
799 | + * Wrapper for $wp_role->remove_cap() |
|
800 | + * |
|
801 | + * @see wp-includes/capabilities.php |
|
802 | + * @since 4.5.0 |
|
803 | + * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
804 | + * @param string $cap The capability being removed |
|
805 | + * @param bool $update_capabilities_map |
|
806 | + * @return bool |
|
807 | + * @throws \EE_Error |
|
808 | + */ |
|
809 | + public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
810 | + { |
|
811 | + // don't do anything if the capabilities map can not be initialized |
|
812 | + if (! $this->setupCapabilitiesMap()) { |
|
813 | + return false; |
|
814 | + } |
|
815 | + $role = $role instanceof WP_Role ? $role :get_role($role); |
|
816 | + if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
817 | + $role->remove_cap($cap); |
|
818 | + unset($this->capabilities_map[ $role->name ][ $index ]); |
|
819 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
820 | + return true; |
|
821 | + } |
|
822 | + return false; |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * @param string $role_name |
|
829 | + * @param string $cap |
|
830 | + * @param bool $get_index |
|
831 | + * @return bool|mixed |
|
832 | + */ |
|
833 | + private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
834 | + { |
|
835 | + if ( |
|
836 | + isset($this->capabilities_map[$role_name]) |
|
837 | + && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
838 | + ) { |
|
839 | + return $get_index ? $index : true; |
|
840 | + } |
|
841 | + return false; |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + |
|
846 | + /** |
|
847 | + * Wrapper for the native WP current_user_can() method. |
|
848 | + * This is provided as a handy method for a couple things: |
|
849 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
850 | + * write those filters wherever current_user_can is called). |
|
851 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
852 | + * |
|
853 | + * @since 4.5.0 |
|
854 | + * |
|
855 | + * @param string $cap The cap being checked. |
|
856 | + * @param string $context The context where the current_user_can is being called from. |
|
857 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
858 | + * filters. |
|
859 | + * |
|
860 | + * @return bool Whether user can or not. |
|
861 | + */ |
|
862 | + public function current_user_can($cap, $context, $id = 0) |
|
863 | + { |
|
864 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
865 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
866 | + $filtered_cap = apply_filters( |
|
867 | + 'FHEE__EE_Capabilities__current_user_can__cap', |
|
868 | + $filtered_cap, |
|
869 | + $context, |
|
870 | + $cap, |
|
871 | + $id |
|
872 | + ); |
|
873 | + return ! empty($id) |
|
874 | + ? current_user_can($filtered_cap, $id) |
|
875 | + : current_user_can($filtered_cap); |
|
876 | + } |
|
877 | + |
|
878 | + |
|
879 | + |
|
880 | + /** |
|
881 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
882 | + * |
|
883 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
884 | + * @param string $cap The capability string being checked |
|
885 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
886 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
887 | + * filters) |
|
888 | + * |
|
889 | + * @return bool Whether user can or not. |
|
890 | + */ |
|
891 | + public function user_can($user, $cap, $context, $id = 0) |
|
892 | + { |
|
893 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
894 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
895 | + $filtered_cap = apply_filters( |
|
896 | + 'FHEE__EE_Capabilities__user_can__cap', |
|
897 | + $filtered_cap, |
|
898 | + $context, |
|
899 | + $cap, |
|
900 | + $user, |
|
901 | + $id |
|
902 | + ); |
|
903 | + return ! empty($id) |
|
904 | + ? user_can($user, $filtered_cap, $id) |
|
905 | + : user_can($user, $filtered_cap); |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
912 | + * This is provided as a handy method for a couple things: |
|
913 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
914 | + * write those filters wherever current_user_can is called). |
|
915 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
916 | + * |
|
917 | + * @since 4.5.0 |
|
918 | + * |
|
919 | + * @param int $blog_id The blog id that is being checked for. |
|
920 | + * @param string $cap The cap being checked. |
|
921 | + * @param string $context The context where the current_user_can is being called from. |
|
922 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
923 | + * filters. |
|
924 | + * |
|
925 | + * @return bool Whether user can or not. |
|
926 | + */ |
|
927 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
928 | + { |
|
929 | + $user_can = ! empty($id) |
|
930 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
931 | + : current_user_can($blog_id, $cap); |
|
932 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
933 | + $user_can = apply_filters( |
|
934 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
935 | + $user_can, |
|
936 | + $blog_id, |
|
937 | + $cap, |
|
938 | + $id |
|
939 | + ); |
|
940 | + $user_can = apply_filters( |
|
941 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
942 | + $user_can, |
|
943 | + $context, |
|
944 | + $blog_id, |
|
945 | + $cap, |
|
946 | + $id |
|
947 | + ); |
|
948 | + return $user_can; |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * This helper method just returns an array of registered EE capabilities. |
|
955 | + * |
|
956 | + * @since 4.5.0 |
|
957 | + * @param string $role If empty then the entire role/capability map is returned. |
|
958 | + * Otherwise just the capabilities for the given role are returned. |
|
959 | + * @return array |
|
960 | + * @throws EE_Error |
|
961 | + */ |
|
962 | + public function get_ee_capabilities($role = 'administrator') |
|
963 | + { |
|
964 | + if (! $this->initialized) { |
|
965 | + $this->init_caps(); |
|
966 | + } |
|
967 | + if (empty($role)) { |
|
968 | + return $this->capabilities_map; |
|
969 | + } |
|
970 | + return isset($this->capabilities_map[ $role ]) |
|
971 | + ? $this->capabilities_map[ $role ] |
|
972 | + : array(); |
|
973 | + } |
|
974 | + |
|
975 | + |
|
976 | + |
|
977 | + /** |
|
978 | + * @deprecated 4.9.42 |
|
979 | + * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
980 | + * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
981 | + * @param array $caps_map Optional. |
|
982 | + * Can be used to send a custom map of roles and capabilities for setting them up. |
|
983 | + * Note that this should ONLY be called on activation hook or some other one-time |
|
984 | + * task otherwise the caps will be added on every request. |
|
985 | + * @return void |
|
986 | + * @throws EE_Error |
|
987 | + */ |
|
988 | + public function init_role_caps($reset = false, $caps_map = array()) |
|
989 | + { |
|
990 | + // If this method is called directly and reset is set as 'true', |
|
991 | + // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
992 | + // to guarantee that everything is set up correctly. |
|
993 | + // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
994 | + if ($reset) { |
|
995 | + EE_Error::doing_it_wrong( |
|
996 | + __METHOD__, |
|
997 | + sprintf( |
|
998 | + esc_html__( |
|
999 | + 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
1000 | + 'event_espresso' |
|
1001 | + ), |
|
1002 | + '$reset', |
|
1003 | + __METHOD__ . '()', |
|
1004 | + 'EE_Capabilities::init_caps()', |
|
1005 | + 'true' |
|
1006 | + ), |
|
1007 | + '4.9.42', |
|
1008 | + '5.0.0' |
|
1009 | + ); |
|
1010 | + } |
|
1011 | + $this->addCaps($caps_map); |
|
1012 | + } |
|
1013 | 1013 | |
1014 | 1014 | |
1015 | 1015 | |
@@ -1030,142 +1030,142 @@ discard block |
||
1030 | 1030 | abstract class EE_Meta_Capability_Map |
1031 | 1031 | { |
1032 | 1032 | |
1033 | - public $meta_cap; |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * @var EEM_Base |
|
1037 | - */ |
|
1038 | - protected $_model; |
|
1039 | - |
|
1040 | - protected $_model_name; |
|
1041 | - |
|
1042 | - public $published_cap = ''; |
|
1043 | - |
|
1044 | - public $others_cap = ''; |
|
1045 | - |
|
1046 | - public $private_cap = ''; |
|
1047 | - |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * constructor. |
|
1051 | - * Receives the setup arguments for the map. |
|
1052 | - * |
|
1053 | - * @since 4.5.0 |
|
1054 | - * |
|
1055 | - * @param string $meta_cap What meta capability is this mapping. |
|
1056 | - * @param array $map_values array { |
|
1057 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
1058 | - * capabilities that don't get mapped to. |
|
1059 | - * |
|
1060 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
1061 | - * should always be used when Menu Maps are registered via the |
|
1062 | - * plugin API as models are not allowed to be instantiated when |
|
1063 | - * in maintenance mode 2 (migrations). |
|
1064 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
1065 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
1066 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
1067 | - * } |
|
1068 | - * @throws EE_Error |
|
1069 | - */ |
|
1070 | - public function __construct($meta_cap, $map_values) |
|
1071 | - { |
|
1072 | - $this->meta_cap = $meta_cap; |
|
1073 | - //verify there are four args in the $map_values array; |
|
1074 | - if (count($map_values) !== 4) { |
|
1075 | - throw new EE_Error( |
|
1076 | - sprintf( |
|
1077 | - __( |
|
1078 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
1079 | - 'event_espresso' |
|
1080 | - ), |
|
1081 | - '<br>' . print_r($map_values, true) |
|
1082 | - ) |
|
1083 | - ); |
|
1084 | - } |
|
1085 | - //set properties |
|
1086 | - $this->_model = null; |
|
1087 | - $this->_model_name = $map_values[0]; |
|
1088 | - $this->published_cap = (string)$map_values[1]; |
|
1089 | - $this->others_cap = (string)$map_values[2]; |
|
1090 | - $this->private_cap = (string)$map_values[3]; |
|
1091 | - } |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * Makes it so this object stops filtering caps |
|
1095 | - */ |
|
1096 | - public function remove_filters() |
|
1097 | - { |
|
1098 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
1099 | - } |
|
1100 | - |
|
1101 | - |
|
1102 | - /** |
|
1103 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
1104 | - * |
|
1105 | - * @since 4.5.0 |
|
1106 | - * @throws EE_Error |
|
1107 | - * |
|
1108 | - * @return void |
|
1109 | - */ |
|
1110 | - public function ensure_is_model() |
|
1111 | - { |
|
1112 | - //is it already instantiated? |
|
1113 | - if ($this->_model instanceof EEM_Base) { |
|
1114 | - return; |
|
1115 | - } |
|
1116 | - //ensure model name is string |
|
1117 | - $this->_model_name = (string)$this->_model_name; |
|
1118 | - //error proof if the name has EEM in it |
|
1119 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
1120 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
1121 | - if (! $this->_model instanceof EEM_Base) { |
|
1122 | - throw new EE_Error( |
|
1123 | - sprintf( |
|
1124 | - __( |
|
1125 | - 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
1126 | - 'event_espresso' |
|
1127 | - ), |
|
1128 | - get_class($this), |
|
1129 | - $this->_model |
|
1130 | - ) |
|
1131 | - ); |
|
1132 | - } |
|
1133 | - } |
|
1134 | - |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * |
|
1138 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
1139 | - * @since 4.6.x |
|
1140 | - * |
|
1141 | - * @param $caps |
|
1142 | - * @param $cap |
|
1143 | - * @param $user_id |
|
1144 | - * @param $args |
|
1145 | - * |
|
1146 | - * @return array |
|
1147 | - */ |
|
1148 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
1149 | - { |
|
1150 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
1151 | - } |
|
1152 | - |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1156 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1157 | - * |
|
1158 | - * @since 4.5.0 |
|
1159 | - * @see wp-includes/capabilities.php |
|
1160 | - * |
|
1161 | - * @param array $caps actual users capabilities |
|
1162 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1163 | - * @param int $user_id The user id |
|
1164 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1165 | - * |
|
1166 | - * @return array actual users capabilities |
|
1167 | - */ |
|
1168 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
1033 | + public $meta_cap; |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * @var EEM_Base |
|
1037 | + */ |
|
1038 | + protected $_model; |
|
1039 | + |
|
1040 | + protected $_model_name; |
|
1041 | + |
|
1042 | + public $published_cap = ''; |
|
1043 | + |
|
1044 | + public $others_cap = ''; |
|
1045 | + |
|
1046 | + public $private_cap = ''; |
|
1047 | + |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * constructor. |
|
1051 | + * Receives the setup arguments for the map. |
|
1052 | + * |
|
1053 | + * @since 4.5.0 |
|
1054 | + * |
|
1055 | + * @param string $meta_cap What meta capability is this mapping. |
|
1056 | + * @param array $map_values array { |
|
1057 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
1058 | + * capabilities that don't get mapped to. |
|
1059 | + * |
|
1060 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
1061 | + * should always be used when Menu Maps are registered via the |
|
1062 | + * plugin API as models are not allowed to be instantiated when |
|
1063 | + * in maintenance mode 2 (migrations). |
|
1064 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
1065 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
1066 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
1067 | + * } |
|
1068 | + * @throws EE_Error |
|
1069 | + */ |
|
1070 | + public function __construct($meta_cap, $map_values) |
|
1071 | + { |
|
1072 | + $this->meta_cap = $meta_cap; |
|
1073 | + //verify there are four args in the $map_values array; |
|
1074 | + if (count($map_values) !== 4) { |
|
1075 | + throw new EE_Error( |
|
1076 | + sprintf( |
|
1077 | + __( |
|
1078 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
1079 | + 'event_espresso' |
|
1080 | + ), |
|
1081 | + '<br>' . print_r($map_values, true) |
|
1082 | + ) |
|
1083 | + ); |
|
1084 | + } |
|
1085 | + //set properties |
|
1086 | + $this->_model = null; |
|
1087 | + $this->_model_name = $map_values[0]; |
|
1088 | + $this->published_cap = (string)$map_values[1]; |
|
1089 | + $this->others_cap = (string)$map_values[2]; |
|
1090 | + $this->private_cap = (string)$map_values[3]; |
|
1091 | + } |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * Makes it so this object stops filtering caps |
|
1095 | + */ |
|
1096 | + public function remove_filters() |
|
1097 | + { |
|
1098 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
1099 | + } |
|
1100 | + |
|
1101 | + |
|
1102 | + /** |
|
1103 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
1104 | + * |
|
1105 | + * @since 4.5.0 |
|
1106 | + * @throws EE_Error |
|
1107 | + * |
|
1108 | + * @return void |
|
1109 | + */ |
|
1110 | + public function ensure_is_model() |
|
1111 | + { |
|
1112 | + //is it already instantiated? |
|
1113 | + if ($this->_model instanceof EEM_Base) { |
|
1114 | + return; |
|
1115 | + } |
|
1116 | + //ensure model name is string |
|
1117 | + $this->_model_name = (string)$this->_model_name; |
|
1118 | + //error proof if the name has EEM in it |
|
1119 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
1120 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
1121 | + if (! $this->_model instanceof EEM_Base) { |
|
1122 | + throw new EE_Error( |
|
1123 | + sprintf( |
|
1124 | + __( |
|
1125 | + 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
1126 | + 'event_espresso' |
|
1127 | + ), |
|
1128 | + get_class($this), |
|
1129 | + $this->_model |
|
1130 | + ) |
|
1131 | + ); |
|
1132 | + } |
|
1133 | + } |
|
1134 | + |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * |
|
1138 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
1139 | + * @since 4.6.x |
|
1140 | + * |
|
1141 | + * @param $caps |
|
1142 | + * @param $cap |
|
1143 | + * @param $user_id |
|
1144 | + * @param $args |
|
1145 | + * |
|
1146 | + * @return array |
|
1147 | + */ |
|
1148 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
1149 | + { |
|
1150 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
1151 | + } |
|
1152 | + |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1156 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1157 | + * |
|
1158 | + * @since 4.5.0 |
|
1159 | + * @see wp-includes/capabilities.php |
|
1160 | + * |
|
1161 | + * @param array $caps actual users capabilities |
|
1162 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1163 | + * @param int $user_id The user id |
|
1164 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1165 | + * |
|
1166 | + * @return array actual users capabilities |
|
1167 | + */ |
|
1168 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | |
@@ -1181,81 +1181,81 @@ discard block |
||
1181 | 1181 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
1182 | 1182 | { |
1183 | 1183 | |
1184 | - /** |
|
1185 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1186 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1187 | - * |
|
1188 | - * @since 4.5.0 |
|
1189 | - * @see wp-includes/capabilities.php |
|
1190 | - * |
|
1191 | - * @param array $caps actual users capabilities |
|
1192 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1193 | - * @param int $user_id The user id |
|
1194 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1195 | - * |
|
1196 | - * @return array actual users capabilities |
|
1197 | - */ |
|
1198 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1199 | - { |
|
1200 | - //only process if we're checking our mapped_cap |
|
1201 | - if ($cap !== $this->meta_cap) { |
|
1202 | - return $caps; |
|
1203 | - } |
|
1204 | - |
|
1205 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1206 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1207 | - unset($caps[$key]); |
|
1208 | - } |
|
1209 | - |
|
1210 | - //cast $user_id to int for later explicit comparisons |
|
1211 | - $user_id = (int) $user_id; |
|
1212 | - |
|
1213 | - /** @var EE_Base_Class $obj */ |
|
1214 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1215 | - //if no obj then let's just do cap |
|
1216 | - if (! $obj instanceof EE_Base_Class) { |
|
1217 | - $caps[] = 'do_not_allow'; |
|
1218 | - return $caps; |
|
1219 | - } |
|
1220 | - $caps[] = $cap . 's'; |
|
1221 | - if ($obj instanceof EE_CPT_Base) { |
|
1222 | - //if the item author is set and the user is the author... |
|
1223 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
1224 | - //if obj is published... |
|
1225 | - if ($obj->status() === 'publish') { |
|
1226 | - $caps[] = $this->published_cap; |
|
1227 | - } |
|
1228 | - } else { |
|
1229 | - //the user is trying to edit someone else's obj |
|
1230 | - if (! empty($this->others_cap)) { |
|
1231 | - $caps[] = $this->others_cap; |
|
1232 | - } |
|
1233 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1234 | - $caps[] = $this->published_cap; |
|
1235 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1236 | - $caps[] = $this->private_cap; |
|
1237 | - } |
|
1238 | - } |
|
1239 | - } else { |
|
1240 | - //not a cpt object so handled differently |
|
1241 | - $has_cap = false; |
|
1242 | - try { |
|
1243 | - $has_cap = method_exists($obj, 'wp_user') |
|
1244 | - && $obj->wp_user() |
|
1245 | - && $obj->wp_user() === $user_id; |
|
1246 | - } catch (Exception $e) { |
|
1247 | - if (WP_DEBUG) { |
|
1248 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1249 | - } |
|
1250 | - } |
|
1251 | - if (! $has_cap) { |
|
1252 | - if (! empty($this->others_cap)) { |
|
1253 | - $caps[] = $this->others_cap; |
|
1254 | - } |
|
1255 | - } |
|
1256 | - } |
|
1257 | - return $caps; |
|
1258 | - } |
|
1184 | + /** |
|
1185 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1186 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1187 | + * |
|
1188 | + * @since 4.5.0 |
|
1189 | + * @see wp-includes/capabilities.php |
|
1190 | + * |
|
1191 | + * @param array $caps actual users capabilities |
|
1192 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1193 | + * @param int $user_id The user id |
|
1194 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1195 | + * |
|
1196 | + * @return array actual users capabilities |
|
1197 | + */ |
|
1198 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1199 | + { |
|
1200 | + //only process if we're checking our mapped_cap |
|
1201 | + if ($cap !== $this->meta_cap) { |
|
1202 | + return $caps; |
|
1203 | + } |
|
1204 | + |
|
1205 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1206 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1207 | + unset($caps[$key]); |
|
1208 | + } |
|
1209 | + |
|
1210 | + //cast $user_id to int for later explicit comparisons |
|
1211 | + $user_id = (int) $user_id; |
|
1212 | + |
|
1213 | + /** @var EE_Base_Class $obj */ |
|
1214 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1215 | + //if no obj then let's just do cap |
|
1216 | + if (! $obj instanceof EE_Base_Class) { |
|
1217 | + $caps[] = 'do_not_allow'; |
|
1218 | + return $caps; |
|
1219 | + } |
|
1220 | + $caps[] = $cap . 's'; |
|
1221 | + if ($obj instanceof EE_CPT_Base) { |
|
1222 | + //if the item author is set and the user is the author... |
|
1223 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
1224 | + //if obj is published... |
|
1225 | + if ($obj->status() === 'publish') { |
|
1226 | + $caps[] = $this->published_cap; |
|
1227 | + } |
|
1228 | + } else { |
|
1229 | + //the user is trying to edit someone else's obj |
|
1230 | + if (! empty($this->others_cap)) { |
|
1231 | + $caps[] = $this->others_cap; |
|
1232 | + } |
|
1233 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1234 | + $caps[] = $this->published_cap; |
|
1235 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1236 | + $caps[] = $this->private_cap; |
|
1237 | + } |
|
1238 | + } |
|
1239 | + } else { |
|
1240 | + //not a cpt object so handled differently |
|
1241 | + $has_cap = false; |
|
1242 | + try { |
|
1243 | + $has_cap = method_exists($obj, 'wp_user') |
|
1244 | + && $obj->wp_user() |
|
1245 | + && $obj->wp_user() === $user_id; |
|
1246 | + } catch (Exception $e) { |
|
1247 | + if (WP_DEBUG) { |
|
1248 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1249 | + } |
|
1250 | + } |
|
1251 | + if (! $has_cap) { |
|
1252 | + if (! empty($this->others_cap)) { |
|
1253 | + $caps[] = $this->others_cap; |
|
1254 | + } |
|
1255 | + } |
|
1256 | + } |
|
1257 | + return $caps; |
|
1258 | + } |
|
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | |
@@ -1272,24 +1272,24 @@ discard block |
||
1272 | 1272 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
1273 | 1273 | { |
1274 | 1274 | |
1275 | - /** |
|
1276 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1277 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1278 | - * |
|
1279 | - * @since 4.5.0 |
|
1280 | - * @see wp-includes/capabilities.php |
|
1281 | - * |
|
1282 | - * @param array $caps actual users capabilities |
|
1283 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1284 | - * @param int $user_id The user id |
|
1285 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1286 | - * |
|
1287 | - * @return array actual users capabilities |
|
1288 | - */ |
|
1289 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1290 | - { |
|
1291 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1292 | - } |
|
1275 | + /** |
|
1276 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1277 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1278 | + * |
|
1279 | + * @since 4.5.0 |
|
1280 | + * @see wp-includes/capabilities.php |
|
1281 | + * |
|
1282 | + * @param array $caps actual users capabilities |
|
1283 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1284 | + * @param int $user_id The user id |
|
1285 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1286 | + * |
|
1287 | + * @return array actual users capabilities |
|
1288 | + */ |
|
1289 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1290 | + { |
|
1291 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1292 | + } |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | |
@@ -1305,85 +1305,85 @@ discard block |
||
1305 | 1305 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
1306 | 1306 | { |
1307 | 1307 | |
1308 | - /** |
|
1309 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1310 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1311 | - * |
|
1312 | - * @since 4.5.0 |
|
1313 | - * @see wp-includes/capabilities.php |
|
1314 | - * |
|
1315 | - * @param array $caps actual users capabilities |
|
1316 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1317 | - * @param int $user_id The user id |
|
1318 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1319 | - * |
|
1320 | - * @return array actual users capabilities |
|
1321 | - */ |
|
1322 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1323 | - { |
|
1324 | - //only process if we're checking our mapped cap; |
|
1325 | - if ($cap !== $this->meta_cap) { |
|
1326 | - return $caps; |
|
1327 | - } |
|
1328 | - |
|
1329 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1330 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1331 | - unset($caps[$key]); |
|
1332 | - } |
|
1333 | - |
|
1334 | - //cast $user_id to int for later explicit comparisons |
|
1335 | - $user_id = (int) $user_id; |
|
1336 | - |
|
1337 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1338 | - //if no obj then let's just do cap |
|
1339 | - if (! $obj instanceof EE_Base_Class) { |
|
1340 | - $caps[] = 'do_not_allow'; |
|
1341 | - return $caps; |
|
1342 | - } |
|
1343 | - |
|
1344 | - $caps[] = $cap . 's'; |
|
1345 | - if ($obj instanceof EE_CPT_Base) { |
|
1346 | - $status_obj = get_post_status_object($obj->status()); |
|
1347 | - if ($status_obj->public) { |
|
1348 | - return $caps; |
|
1349 | - } |
|
1350 | - //if the item author is set and the user is not the author... |
|
1351 | - if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
1352 | - if (! empty($this->others_cap)) { |
|
1353 | - $caps[] = $this->others_cap; |
|
1354 | - } |
|
1355 | - } |
|
1356 | - //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
1357 | - if ($status_obj->private |
|
1358 | - && ! empty($this->private_cap) |
|
1359 | - && $obj->wp_user() !== $user_id |
|
1360 | - ) { |
|
1361 | - //the user is trying to view a private object for an object they don't own. |
|
1362 | - $caps[] = $this->private_cap; |
|
1363 | - } |
|
1364 | - } else { |
|
1365 | - //not a cpt object so handled differently |
|
1366 | - $has_cap = false; |
|
1367 | - try { |
|
1368 | - $has_cap = method_exists($obj, 'wp_user') |
|
1369 | - && $obj->wp_user() |
|
1370 | - && $obj->wp_user() === $user_id; |
|
1371 | - } catch (Exception $e) { |
|
1372 | - if (WP_DEBUG) { |
|
1373 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1374 | - } |
|
1375 | - } |
|
1376 | - if (! $has_cap) { |
|
1377 | - if (! empty($this->private_cap)) { |
|
1378 | - $caps[] = $this->private_cap; |
|
1379 | - } |
|
1380 | - if (! empty($this->others_cap)) { |
|
1381 | - $caps[] = $this->others_cap; |
|
1382 | - } |
|
1383 | - } |
|
1384 | - } |
|
1385 | - return $caps; |
|
1386 | - } |
|
1308 | + /** |
|
1309 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1310 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1311 | + * |
|
1312 | + * @since 4.5.0 |
|
1313 | + * @see wp-includes/capabilities.php |
|
1314 | + * |
|
1315 | + * @param array $caps actual users capabilities |
|
1316 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1317 | + * @param int $user_id The user id |
|
1318 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1319 | + * |
|
1320 | + * @return array actual users capabilities |
|
1321 | + */ |
|
1322 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1323 | + { |
|
1324 | + //only process if we're checking our mapped cap; |
|
1325 | + if ($cap !== $this->meta_cap) { |
|
1326 | + return $caps; |
|
1327 | + } |
|
1328 | + |
|
1329 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1330 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1331 | + unset($caps[$key]); |
|
1332 | + } |
|
1333 | + |
|
1334 | + //cast $user_id to int for later explicit comparisons |
|
1335 | + $user_id = (int) $user_id; |
|
1336 | + |
|
1337 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1338 | + //if no obj then let's just do cap |
|
1339 | + if (! $obj instanceof EE_Base_Class) { |
|
1340 | + $caps[] = 'do_not_allow'; |
|
1341 | + return $caps; |
|
1342 | + } |
|
1343 | + |
|
1344 | + $caps[] = $cap . 's'; |
|
1345 | + if ($obj instanceof EE_CPT_Base) { |
|
1346 | + $status_obj = get_post_status_object($obj->status()); |
|
1347 | + if ($status_obj->public) { |
|
1348 | + return $caps; |
|
1349 | + } |
|
1350 | + //if the item author is set and the user is not the author... |
|
1351 | + if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
1352 | + if (! empty($this->others_cap)) { |
|
1353 | + $caps[] = $this->others_cap; |
|
1354 | + } |
|
1355 | + } |
|
1356 | + //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
1357 | + if ($status_obj->private |
|
1358 | + && ! empty($this->private_cap) |
|
1359 | + && $obj->wp_user() !== $user_id |
|
1360 | + ) { |
|
1361 | + //the user is trying to view a private object for an object they don't own. |
|
1362 | + $caps[] = $this->private_cap; |
|
1363 | + } |
|
1364 | + } else { |
|
1365 | + //not a cpt object so handled differently |
|
1366 | + $has_cap = false; |
|
1367 | + try { |
|
1368 | + $has_cap = method_exists($obj, 'wp_user') |
|
1369 | + && $obj->wp_user() |
|
1370 | + && $obj->wp_user() === $user_id; |
|
1371 | + } catch (Exception $e) { |
|
1372 | + if (WP_DEBUG) { |
|
1373 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1374 | + } |
|
1375 | + } |
|
1376 | + if (! $has_cap) { |
|
1377 | + if (! empty($this->private_cap)) { |
|
1378 | + $caps[] = $this->private_cap; |
|
1379 | + } |
|
1380 | + if (! empty($this->others_cap)) { |
|
1381 | + $caps[] = $this->others_cap; |
|
1382 | + } |
|
1383 | + } |
|
1384 | + } |
|
1385 | + return $caps; |
|
1386 | + } |
|
1387 | 1387 | } |
1388 | 1388 | |
1389 | 1389 | |
@@ -1400,56 +1400,56 @@ discard block |
||
1400 | 1400 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
1401 | 1401 | { |
1402 | 1402 | |
1403 | - /** |
|
1404 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1405 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1406 | - * |
|
1407 | - * @since 4.5.0 |
|
1408 | - * @see wp-includes/capabilities.php |
|
1409 | - * |
|
1410 | - * @param array $caps actual users capabilities |
|
1411 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1412 | - * @param int $user_id The user id |
|
1413 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1414 | - * |
|
1415 | - * @return array actual users capabilities |
|
1416 | - */ |
|
1417 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1418 | - { |
|
1419 | - //only process if we're checking our mapped_cap |
|
1420 | - if ($cap !== $this->meta_cap) { |
|
1421 | - return $caps; |
|
1422 | - } |
|
1423 | - |
|
1424 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1425 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1426 | - unset($caps[$key]); |
|
1427 | - } |
|
1428 | - |
|
1429 | - //cast $user_id to int for later explicit comparisons |
|
1430 | - $user_id = (int) $user_id; |
|
1431 | - |
|
1432 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1433 | - //if no obj then let's just do cap |
|
1434 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
1435 | - $caps[] = 'do_not_allow'; |
|
1436 | - return $caps; |
|
1437 | - } |
|
1438 | - $caps[] = $cap . 's'; |
|
1439 | - $is_global = $obj->is_global(); |
|
1440 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1441 | - if ($is_global) { |
|
1442 | - $caps[] = $this->private_cap; |
|
1443 | - } |
|
1444 | - } else { |
|
1445 | - if ($is_global) { |
|
1446 | - $caps[] = $this->private_cap; |
|
1447 | - } else { |
|
1448 | - $caps[] = $this->others_cap; |
|
1449 | - } |
|
1450 | - } |
|
1451 | - return $caps; |
|
1452 | - } |
|
1403 | + /** |
|
1404 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1405 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1406 | + * |
|
1407 | + * @since 4.5.0 |
|
1408 | + * @see wp-includes/capabilities.php |
|
1409 | + * |
|
1410 | + * @param array $caps actual users capabilities |
|
1411 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1412 | + * @param int $user_id The user id |
|
1413 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1414 | + * |
|
1415 | + * @return array actual users capabilities |
|
1416 | + */ |
|
1417 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1418 | + { |
|
1419 | + //only process if we're checking our mapped_cap |
|
1420 | + if ($cap !== $this->meta_cap) { |
|
1421 | + return $caps; |
|
1422 | + } |
|
1423 | + |
|
1424 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1425 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1426 | + unset($caps[$key]); |
|
1427 | + } |
|
1428 | + |
|
1429 | + //cast $user_id to int for later explicit comparisons |
|
1430 | + $user_id = (int) $user_id; |
|
1431 | + |
|
1432 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1433 | + //if no obj then let's just do cap |
|
1434 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
1435 | + $caps[] = 'do_not_allow'; |
|
1436 | + return $caps; |
|
1437 | + } |
|
1438 | + $caps[] = $cap . 's'; |
|
1439 | + $is_global = $obj->is_global(); |
|
1440 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1441 | + if ($is_global) { |
|
1442 | + $caps[] = $this->private_cap; |
|
1443 | + } |
|
1444 | + } else { |
|
1445 | + if ($is_global) { |
|
1446 | + $caps[] = $this->private_cap; |
|
1447 | + } else { |
|
1448 | + $caps[] = $this->others_cap; |
|
1449 | + } |
|
1450 | + } |
|
1451 | + return $caps; |
|
1452 | + } |
|
1453 | 1453 | } |
1454 | 1454 | |
1455 | 1455 | |
@@ -1466,44 +1466,44 @@ discard block |
||
1466 | 1466 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
1467 | 1467 | { |
1468 | 1468 | |
1469 | - /** |
|
1470 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1471 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1472 | - * |
|
1473 | - * @since 4.5.0 |
|
1474 | - * @see wp-includes/capabilities.php |
|
1475 | - * |
|
1476 | - * @param array $caps actual users capabilities |
|
1477 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1478 | - * @param int $user_id The user id |
|
1479 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1480 | - * |
|
1481 | - * @return array actual users capabilities |
|
1482 | - */ |
|
1483 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1484 | - { |
|
1485 | - //only process if we're checking our mapped_cap |
|
1486 | - if ($cap !== $this->meta_cap) { |
|
1487 | - return $caps; |
|
1488 | - } |
|
1489 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1490 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1491 | - unset($caps[$key]); |
|
1492 | - } |
|
1493 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1494 | - //if no obj then let's just do cap |
|
1495 | - if (! $obj instanceof EE_Base_Class) { |
|
1496 | - $caps[] = 'do_not_allow'; |
|
1497 | - return $caps; |
|
1498 | - } |
|
1499 | - $caps[] = $cap . 's'; |
|
1500 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1501 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1502 | - if ($is_system) { |
|
1503 | - $caps[] = $this->private_cap; |
|
1504 | - } |
|
1505 | - return $caps; |
|
1506 | - } |
|
1469 | + /** |
|
1470 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1471 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1472 | + * |
|
1473 | + * @since 4.5.0 |
|
1474 | + * @see wp-includes/capabilities.php |
|
1475 | + * |
|
1476 | + * @param array $caps actual users capabilities |
|
1477 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1478 | + * @param int $user_id The user id |
|
1479 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1480 | + * |
|
1481 | + * @return array actual users capabilities |
|
1482 | + */ |
|
1483 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1484 | + { |
|
1485 | + //only process if we're checking our mapped_cap |
|
1486 | + if ($cap !== $this->meta_cap) { |
|
1487 | + return $caps; |
|
1488 | + } |
|
1489 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1490 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1491 | + unset($caps[$key]); |
|
1492 | + } |
|
1493 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1494 | + //if no obj then let's just do cap |
|
1495 | + if (! $obj instanceof EE_Base_Class) { |
|
1496 | + $caps[] = 'do_not_allow'; |
|
1497 | + return $caps; |
|
1498 | + } |
|
1499 | + $caps[] = $cap . 's'; |
|
1500 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1501 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1502 | + if ($is_system) { |
|
1503 | + $caps[] = $this->private_cap; |
|
1504 | + } |
|
1505 | + return $caps; |
|
1506 | + } |
|
1507 | 1507 | |
1508 | 1508 | |
1509 | 1509 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public static function instance() |
86 | 86 | { |
87 | 87 | //check if instantiated, and if not do so. |
88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
88 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
89 | 89 | self::$_instance = new self(); |
90 | 90 | } |
91 | 91 | return self::$_instance; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function init_caps($reset = false) |
119 | 119 | { |
120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
120 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $this->_get_default_meta_caps_array() |
164 | 164 | ); |
165 | 165 | //add filter for map_meta_caps but only if models can query. |
166 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
166 | + if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
167 | 167 | add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
168 | 168 | } |
169 | 169 | } |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
325 | 325 | //loop through our _meta_caps array |
326 | 326 | foreach ($this->_meta_caps as $meta_map) { |
327 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
327 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
328 | 328 | continue; |
329 | 329 | } |
330 | 330 | // don't load models if there is no object ID in the args |
331 | - if (! empty($args[0])) { |
|
331 | + if ( ! empty($args[0])) { |
|
332 | 332 | $meta_map->ensure_is_model(); |
333 | 333 | } |
334 | 334 | $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | private function setupCapabilitiesMap() |
649 | 649 | { |
650 | 650 | // if the initialization process hasn't even started, then we need to call init_caps() |
651 | - if($this->initialized === null) { |
|
651 | + if ($this->initialized === null) { |
|
652 | 652 | return $this->init_caps(); |
653 | 653 | } |
654 | 654 | // unless resetting, get caps from db if we haven't already |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | public function addCaps(array $capabilities_to_add) |
685 | 685 | { |
686 | 686 | // don't do anything if the capabilities map can not be initialized |
687 | - if (! $this->setupCapabilitiesMap()) { |
|
687 | + if ( ! $this->setupCapabilitiesMap()) { |
|
688 | 688 | return false; |
689 | 689 | } |
690 | 690 | // and filter the array so others can get in on the fun during resets |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | public function removeCaps($caps_map) |
727 | 727 | { |
728 | 728 | // don't do anything if the capabilities map can not be initialized |
729 | - if (! $this->setupCapabilitiesMap()) { |
|
729 | + if ( ! $this->setupCapabilitiesMap()) { |
|
730 | 730 | return false; |
731 | 731 | } |
732 | 732 | $update_capabilities_map = false; |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | $orig_role = $role; |
769 | 769 | $role = $role instanceof WP_Role ? $role : get_role($role); |
770 | 770 | //if the role isn't available then we create it. |
771 | - if (! $role instanceof WP_Role) { |
|
771 | + if ( ! $role instanceof WP_Role) { |
|
772 | 772 | // if a plugin wants to create a specific role name then they should create the role before |
773 | 773 | // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
774 | 774 | // - removes any `ee_` namespacing from the start of the slug. |
@@ -779,12 +779,12 @@ discard block |
||
779 | 779 | } |
780 | 780 | if ($role instanceof WP_Role) { |
781 | 781 | // don't do anything if the capabilities map can not be initialized |
782 | - if (! $this->setupCapabilitiesMap()) { |
|
782 | + if ( ! $this->setupCapabilitiesMap()) { |
|
783 | 783 | return false; |
784 | 784 | } |
785 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
785 | + if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
786 | 786 | $role->add_cap($cap, $grant); |
787 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
787 | + $this->capabilities_map[$role->name][] = $cap; |
|
788 | 788 | $this->updateCapabilitiesMap($update_capabilities_map); |
789 | 789 | return true; |
790 | 790 | } |
@@ -809,13 +809,13 @@ discard block |
||
809 | 809 | public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
810 | 810 | { |
811 | 811 | // don't do anything if the capabilities map can not be initialized |
812 | - if (! $this->setupCapabilitiesMap()) { |
|
812 | + if ( ! $this->setupCapabilitiesMap()) { |
|
813 | 813 | return false; |
814 | 814 | } |
815 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
815 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
816 | 816 | if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
817 | 817 | $role->remove_cap($cap); |
818 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
818 | + unset($this->capabilities_map[$role->name][$index]); |
|
819 | 819 | $this->updateCapabilitiesMap($update_capabilities_map); |
820 | 820 | return true; |
821 | 821 | } |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | * @param bool $get_index |
831 | 831 | * @return bool|mixed |
832 | 832 | */ |
833 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
833 | + private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false) |
|
834 | 834 | { |
835 | 835 | if ( |
836 | 836 | isset($this->capabilities_map[$role_name]) |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | public function current_user_can($cap, $context, $id = 0) |
863 | 863 | { |
864 | 864 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
865 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
865 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
866 | 866 | $filtered_cap = apply_filters( |
867 | 867 | 'FHEE__EE_Capabilities__current_user_can__cap', |
868 | 868 | $filtered_cap, |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | public function user_can($user, $cap, $context, $id = 0) |
892 | 892 | { |
893 | 893 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
894 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
894 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
895 | 895 | $filtered_cap = apply_filters( |
896 | 896 | 'FHEE__EE_Capabilities__user_can__cap', |
897 | 897 | $filtered_cap, |
@@ -931,7 +931,7 @@ discard block |
||
931 | 931 | : current_user_can($blog_id, $cap); |
932 | 932 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
933 | 933 | $user_can = apply_filters( |
934 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
934 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, |
|
935 | 935 | $user_can, |
936 | 936 | $blog_id, |
937 | 937 | $cap, |
@@ -961,14 +961,14 @@ discard block |
||
961 | 961 | */ |
962 | 962 | public function get_ee_capabilities($role = 'administrator') |
963 | 963 | { |
964 | - if (! $this->initialized) { |
|
964 | + if ( ! $this->initialized) { |
|
965 | 965 | $this->init_caps(); |
966 | 966 | } |
967 | 967 | if (empty($role)) { |
968 | 968 | return $this->capabilities_map; |
969 | 969 | } |
970 | - return isset($this->capabilities_map[ $role ]) |
|
971 | - ? $this->capabilities_map[ $role ] |
|
970 | + return isset($this->capabilities_map[$role]) |
|
971 | + ? $this->capabilities_map[$role] |
|
972 | 972 | : array(); |
973 | 973 | } |
974 | 974 | |
@@ -1000,7 +1000,7 @@ discard block |
||
1000 | 1000 | 'event_espresso' |
1001 | 1001 | ), |
1002 | 1002 | '$reset', |
1003 | - __METHOD__ . '()', |
|
1003 | + __METHOD__.'()', |
|
1004 | 1004 | 'EE_Capabilities::init_caps()', |
1005 | 1005 | 'true' |
1006 | 1006 | ), |
@@ -1078,16 +1078,16 @@ discard block |
||
1078 | 1078 | 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
1079 | 1079 | 'event_espresso' |
1080 | 1080 | ), |
1081 | - '<br>' . print_r($map_values, true) |
|
1081 | + '<br>'.print_r($map_values, true) |
|
1082 | 1082 | ) |
1083 | 1083 | ); |
1084 | 1084 | } |
1085 | 1085 | //set properties |
1086 | 1086 | $this->_model = null; |
1087 | 1087 | $this->_model_name = $map_values[0]; |
1088 | - $this->published_cap = (string)$map_values[1]; |
|
1089 | - $this->others_cap = (string)$map_values[2]; |
|
1090 | - $this->private_cap = (string)$map_values[3]; |
|
1088 | + $this->published_cap = (string) $map_values[1]; |
|
1089 | + $this->others_cap = (string) $map_values[2]; |
|
1090 | + $this->private_cap = (string) $map_values[3]; |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | /** |
@@ -1114,11 +1114,11 @@ discard block |
||
1114 | 1114 | return; |
1115 | 1115 | } |
1116 | 1116 | //ensure model name is string |
1117 | - $this->_model_name = (string)$this->_model_name; |
|
1117 | + $this->_model_name = (string) $this->_model_name; |
|
1118 | 1118 | //error proof if the name has EEM in it |
1119 | 1119 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
1120 | 1120 | $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
1121 | - if (! $this->_model instanceof EEM_Base) { |
|
1121 | + if ( ! $this->_model instanceof EEM_Base) { |
|
1122 | 1122 | throw new EE_Error( |
1123 | 1123 | sprintf( |
1124 | 1124 | __( |
@@ -1213,11 +1213,11 @@ discard block |
||
1213 | 1213 | /** @var EE_Base_Class $obj */ |
1214 | 1214 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1215 | 1215 | //if no obj then let's just do cap |
1216 | - if (! $obj instanceof EE_Base_Class) { |
|
1216 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1217 | 1217 | $caps[] = 'do_not_allow'; |
1218 | 1218 | return $caps; |
1219 | 1219 | } |
1220 | - $caps[] = $cap . 's'; |
|
1220 | + $caps[] = $cap.'s'; |
|
1221 | 1221 | if ($obj instanceof EE_CPT_Base) { |
1222 | 1222 | //if the item author is set and the user is the author... |
1223 | 1223 | if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
@@ -1227,12 +1227,12 @@ discard block |
||
1227 | 1227 | } |
1228 | 1228 | } else { |
1229 | 1229 | //the user is trying to edit someone else's obj |
1230 | - if (! empty($this->others_cap)) { |
|
1230 | + if ( ! empty($this->others_cap)) { |
|
1231 | 1231 | $caps[] = $this->others_cap; |
1232 | 1232 | } |
1233 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1233 | + if ( ! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1234 | 1234 | $caps[] = $this->published_cap; |
1235 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1235 | + } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') { |
|
1236 | 1236 | $caps[] = $this->private_cap; |
1237 | 1237 | } |
1238 | 1238 | } |
@@ -1248,8 +1248,8 @@ discard block |
||
1248 | 1248 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
1249 | 1249 | } |
1250 | 1250 | } |
1251 | - if (! $has_cap) { |
|
1252 | - if (! empty($this->others_cap)) { |
|
1251 | + if ( ! $has_cap) { |
|
1252 | + if ( ! empty($this->others_cap)) { |
|
1253 | 1253 | $caps[] = $this->others_cap; |
1254 | 1254 | } |
1255 | 1255 | } |
@@ -1336,12 +1336,12 @@ discard block |
||
1336 | 1336 | |
1337 | 1337 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1338 | 1338 | //if no obj then let's just do cap |
1339 | - if (! $obj instanceof EE_Base_Class) { |
|
1339 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1340 | 1340 | $caps[] = 'do_not_allow'; |
1341 | 1341 | return $caps; |
1342 | 1342 | } |
1343 | 1343 | |
1344 | - $caps[] = $cap . 's'; |
|
1344 | + $caps[] = $cap.'s'; |
|
1345 | 1345 | if ($obj instanceof EE_CPT_Base) { |
1346 | 1346 | $status_obj = get_post_status_object($obj->status()); |
1347 | 1347 | if ($status_obj->public) { |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | } |
1350 | 1350 | //if the item author is set and the user is not the author... |
1351 | 1351 | if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
1352 | - if (! empty($this->others_cap)) { |
|
1352 | + if ( ! empty($this->others_cap)) { |
|
1353 | 1353 | $caps[] = $this->others_cap; |
1354 | 1354 | } |
1355 | 1355 | } |
@@ -1373,11 +1373,11 @@ discard block |
||
1373 | 1373 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
1374 | 1374 | } |
1375 | 1375 | } |
1376 | - if (! $has_cap) { |
|
1377 | - if (! empty($this->private_cap)) { |
|
1376 | + if ( ! $has_cap) { |
|
1377 | + if ( ! empty($this->private_cap)) { |
|
1378 | 1378 | $caps[] = $this->private_cap; |
1379 | 1379 | } |
1380 | - if (! empty($this->others_cap)) { |
|
1380 | + if ( ! empty($this->others_cap)) { |
|
1381 | 1381 | $caps[] = $this->others_cap; |
1382 | 1382 | } |
1383 | 1383 | } |
@@ -1431,11 +1431,11 @@ discard block |
||
1431 | 1431 | |
1432 | 1432 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1433 | 1433 | //if no obj then let's just do cap |
1434 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
1434 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
1435 | 1435 | $caps[] = 'do_not_allow'; |
1436 | 1436 | return $caps; |
1437 | 1437 | } |
1438 | - $caps[] = $cap . 's'; |
|
1438 | + $caps[] = $cap.'s'; |
|
1439 | 1439 | $is_global = $obj->is_global(); |
1440 | 1440 | if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
1441 | 1441 | if ($is_global) { |
@@ -1492,11 +1492,11 @@ discard block |
||
1492 | 1492 | } |
1493 | 1493 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1494 | 1494 | //if no obj then let's just do cap |
1495 | - if (! $obj instanceof EE_Base_Class) { |
|
1495 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1496 | 1496 | $caps[] = 'do_not_allow'; |
1497 | 1497 | return $caps; |
1498 | 1498 | } |
1499 | - $caps[] = $cap . 's'; |
|
1499 | + $caps[] = $cap.'s'; |
|
1500 | 1500 | $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
1501 | 1501 | $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
1502 | 1502 | if ($is_system) { |
@@ -18,92 +18,92 @@ |
||
18 | 18 | class PostRelatedCacheManager extends BasicCacheManager |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @type string |
|
23 | - */ |
|
24 | - const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
25 | - |
|
26 | - /** |
|
27 | - * wp-option option_name for tracking post related cache |
|
28 | - * |
|
29 | - * @type string |
|
30 | - */ |
|
31 | - const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * PostRelatedCacheManager constructor. |
|
37 | - * |
|
38 | - * @param CacheStorageInterface $cache_storage |
|
39 | - */ |
|
40 | - public function __construct(CacheStorageInterface $cache_storage) |
|
41 | - { |
|
42 | - parent::__construct($cache_storage); |
|
43 | - add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * returns a string that will be prepended to all cache identifiers |
|
50 | - * |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function cachePrefix() |
|
54 | - { |
|
55 | - return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * If you are caching content that pertains to a Post of any type, |
|
62 | - * then it is recommended to pass the post id and cache id prefix to this method |
|
63 | - * so that it can be added to the post related cache tracking. |
|
64 | - * Then, whenever that post is updated, the cache will automatically be deleted, |
|
65 | - * which helps to ensure that outdated cache content will not be served |
|
66 | - * |
|
67 | - * @param int $post_ID [required] |
|
68 | - * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
69 | - * May also be helpful to include an additional specific identifier, |
|
70 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
71 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
72 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
73 | - */ |
|
74 | - public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
75 | - { |
|
76 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
77 | - // if post is not already being tracked |
|
78 | - if ( ! isset($post_related_cache[$post_ID])) { |
|
79 | - // add array to add cache ids to |
|
80 | - $post_related_cache[$post_ID] = array(); |
|
81 | - } |
|
82 | - // add cache id to be tracked |
|
83 | - $post_related_cache[$post_ID][] = $id_prefix; |
|
84 | - update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * callback hooked into the WordPress "save_post" action |
|
91 | - * deletes any cache content associated with the post |
|
92 | - * |
|
93 | - * @param int $post_ID [required] |
|
94 | - */ |
|
95 | - public function clearPostRelatedCache($post_ID) |
|
96 | - { |
|
97 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
98 | - // if post is not being tracked |
|
99 | - if ( ! isset($post_related_cache[$post_ID])) { |
|
100 | - return; |
|
101 | - } |
|
102 | - // get cache id prefixes for post, and delete their corresponding transients |
|
103 | - $this->clear($post_related_cache[$post_ID]); |
|
104 | - unset($post_related_cache[$post_ID]); |
|
105 | - update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
106 | - } |
|
21 | + /** |
|
22 | + * @type string |
|
23 | + */ |
|
24 | + const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
25 | + |
|
26 | + /** |
|
27 | + * wp-option option_name for tracking post related cache |
|
28 | + * |
|
29 | + * @type string |
|
30 | + */ |
|
31 | + const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * PostRelatedCacheManager constructor. |
|
37 | + * |
|
38 | + * @param CacheStorageInterface $cache_storage |
|
39 | + */ |
|
40 | + public function __construct(CacheStorageInterface $cache_storage) |
|
41 | + { |
|
42 | + parent::__construct($cache_storage); |
|
43 | + add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * returns a string that will be prepended to all cache identifiers |
|
50 | + * |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function cachePrefix() |
|
54 | + { |
|
55 | + return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * If you are caching content that pertains to a Post of any type, |
|
62 | + * then it is recommended to pass the post id and cache id prefix to this method |
|
63 | + * so that it can be added to the post related cache tracking. |
|
64 | + * Then, whenever that post is updated, the cache will automatically be deleted, |
|
65 | + * which helps to ensure that outdated cache content will not be served |
|
66 | + * |
|
67 | + * @param int $post_ID [required] |
|
68 | + * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
69 | + * May also be helpful to include an additional specific identifier, |
|
70 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
71 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
72 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
73 | + */ |
|
74 | + public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
75 | + { |
|
76 | + $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
77 | + // if post is not already being tracked |
|
78 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
79 | + // add array to add cache ids to |
|
80 | + $post_related_cache[$post_ID] = array(); |
|
81 | + } |
|
82 | + // add cache id to be tracked |
|
83 | + $post_related_cache[$post_ID][] = $id_prefix; |
|
84 | + update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * callback hooked into the WordPress "save_post" action |
|
91 | + * deletes any cache content associated with the post |
|
92 | + * |
|
93 | + * @param int $post_ID [required] |
|
94 | + */ |
|
95 | + public function clearPostRelatedCache($post_ID) |
|
96 | + { |
|
97 | + $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
98 | + // if post is not being tracked |
|
99 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
100 | + return; |
|
101 | + } |
|
102 | + // get cache id prefixes for post, and delete their corresponding transients |
|
103 | + $this->clear($post_related_cache[$post_ID]); |
|
104 | + unset($post_related_cache[$post_ID]); |
|
105 | + update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | 109 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -21,731 +21,731 @@ discard block |
||
21 | 21 | class EE_Dependency_Map |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * This means that the requested class dependency is not present in the dependency map |
|
26 | - */ |
|
27 | - const not_registered = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | - */ |
|
32 | - const load_new_object = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | - */ |
|
38 | - const load_from_cache = 2; |
|
39 | - |
|
40 | - /** |
|
41 | - * When registering a dependency, |
|
42 | - * this indicates to keep any existing dependencies that already exist, |
|
43 | - * and simply discard any new dependencies declared in the incoming data |
|
44 | - */ |
|
45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * When registering a dependency, |
|
49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | - */ |
|
51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @type EE_Dependency_Map $_instance |
|
57 | - */ |
|
58 | - protected static $_instance; |
|
59 | - |
|
60 | - /** |
|
61 | - * @type EE_Request $request |
|
62 | - */ |
|
63 | - protected $_request; |
|
64 | - |
|
65 | - /** |
|
66 | - * @type EE_Response $response |
|
67 | - */ |
|
68 | - protected $_response; |
|
69 | - |
|
70 | - /** |
|
71 | - * @type LoaderInterface $loader |
|
72 | - */ |
|
73 | - protected $loader; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type array $_dependency_map |
|
77 | - */ |
|
78 | - protected $_dependency_map = array(); |
|
79 | - |
|
80 | - /** |
|
81 | - * @type array $_class_loaders |
|
82 | - */ |
|
83 | - protected $_class_loaders = array(); |
|
84 | - |
|
85 | - /** |
|
86 | - * @type array $_aliases |
|
87 | - */ |
|
88 | - protected $_aliases = array(); |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * EE_Dependency_Map constructor. |
|
94 | - * |
|
95 | - * @param EE_Request $request |
|
96 | - * @param EE_Response $response |
|
97 | - */ |
|
98 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | - { |
|
100 | - $this->_request = $request; |
|
101 | - $this->_response = $response; |
|
102 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | - do_action('EE_Dependency_Map____construct'); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidInterfaceException |
|
111 | - * @throws InvalidArgumentException |
|
112 | - */ |
|
113 | - public function initialize() |
|
114 | - { |
|
115 | - $this->_register_core_dependencies(); |
|
116 | - $this->_register_core_class_loaders(); |
|
117 | - $this->_register_core_aliases(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @singleton method used to instantiate class object |
|
124 | - * @access public |
|
125 | - * @param EE_Request $request |
|
126 | - * @param EE_Response $response |
|
127 | - * @return EE_Dependency_Map |
|
128 | - */ |
|
129 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | - { |
|
131 | - // check if class object is instantiated, and instantiated properly |
|
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | - } |
|
135 | - return self::$_instance; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param LoaderInterface $loader |
|
142 | - */ |
|
143 | - public function setLoader(LoaderInterface $loader) |
|
144 | - { |
|
145 | - $this->loader = $loader; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $class |
|
152 | - * @param array $dependencies |
|
153 | - * @param int $overwrite |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - public static function register_dependencies( |
|
157 | - $class, |
|
158 | - array $dependencies, |
|
159 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | - ) { |
|
161 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | - * to the class specified by the first parameter. |
|
169 | - * IMPORTANT !!! |
|
170 | - * The order of elements in the incoming $dependencies array MUST match |
|
171 | - * the order of the constructor parameters for the class in question. |
|
172 | - * This is especially important when overriding any existing dependencies that are registered. |
|
173 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | - * |
|
175 | - * @param string $class |
|
176 | - * @param array $dependencies |
|
177 | - * @param int $overwrite |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function registerDependencies( |
|
181 | - $class, |
|
182 | - array $dependencies, |
|
183 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | - ) { |
|
185 | - $registered = false; |
|
186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
188 | - } |
|
189 | - // we need to make sure that any aliases used when registering a dependency |
|
190 | - // get resolved to the correct class name |
|
191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
192 | - $alias = self::$_instance->get_alias($dependency); |
|
193 | - if ( |
|
194 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
196 | - ) { |
|
197 | - unset($dependencies[$dependency]); |
|
198 | - $dependencies[$alias] = $load_source; |
|
199 | - $registered = true; |
|
200 | - } |
|
201 | - } |
|
202 | - // now add our two lists of dependencies together. |
|
203 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
204 | - // so $dependencies is NOT overwritten because it is listed first |
|
205 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
206 | - // Union is way faster than array_merge() but should be used with caution... |
|
207 | - // especially with numerically indexed arrays |
|
208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
209 | - // now we need to ensure that the resulting dependencies |
|
210 | - // array only has the entries that are required for the class |
|
211 | - // so first count how many dependencies were originally registered for the class |
|
212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
213 | - // if that count is non-zero (meaning dependencies were already registered) |
|
214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
215 | - // then truncate the final array to match that count |
|
216 | - ? array_slice($dependencies, 0, $dependency_count) |
|
217 | - // otherwise just take the incoming array because nothing previously existed |
|
218 | - : $dependencies; |
|
219 | - return $registered; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @param string $class_name |
|
226 | - * @param string $loader |
|
227 | - * @return bool |
|
228 | - * @throws DomainException |
|
229 | - */ |
|
230 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
231 | - { |
|
232 | - if (strpos($class_name, '\\') !== false) { |
|
233 | - throw new DomainException( |
|
234 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
235 | - ); |
|
236 | - } |
|
237 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
238 | - if ( |
|
239 | - ! is_callable($loader) |
|
240 | - && ( |
|
241 | - strpos($loader, 'load_') !== 0 |
|
242 | - || ! method_exists('EE_Registry', $loader) |
|
243 | - ) |
|
244 | - ) { |
|
245 | - throw new DomainException( |
|
246 | - sprintf( |
|
247 | - esc_html__( |
|
248 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
249 | - 'event_espresso' |
|
250 | - ), |
|
251 | - $loader |
|
252 | - ) |
|
253 | - ); |
|
254 | - } |
|
255 | - $class_name = self::$_instance->get_alias($class_name); |
|
256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
258 | - return true; |
|
259 | - } |
|
260 | - return false; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return array |
|
267 | - */ |
|
268 | - public function dependency_map() |
|
269 | - { |
|
270 | - return $this->_dependency_map; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
277 | - * |
|
278 | - * @param string $class_name |
|
279 | - * @return boolean |
|
280 | - */ |
|
281 | - public function has($class_name = '') |
|
282 | - { |
|
283 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
290 | - * |
|
291 | - * @param string $class_name |
|
292 | - * @param string $dependency |
|
293 | - * @return bool |
|
294 | - */ |
|
295 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
296 | - { |
|
297 | - $dependency = $this->get_alias($dependency); |
|
298 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
299 | - ? true |
|
300 | - : false; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
307 | - * |
|
308 | - * @param string $class_name |
|
309 | - * @param string $dependency |
|
310 | - * @return int |
|
311 | - */ |
|
312 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
313 | - { |
|
314 | - $dependency = $this->get_alias($dependency); |
|
315 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
316 | - ? $this->_dependency_map[$class_name][$dependency] |
|
317 | - : EE_Dependency_Map::not_registered; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @param string $class_name |
|
324 | - * @return string | Closure |
|
325 | - */ |
|
326 | - public function class_loader($class_name) |
|
327 | - { |
|
328 | - // don't use loaders for FQCNs |
|
329 | - if(strpos($class_name, '\\') !== false){ |
|
330 | - return ''; |
|
331 | - } |
|
332 | - $class_name = $this->get_alias($class_name); |
|
333 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @return array |
|
340 | - */ |
|
341 | - public function class_loaders() |
|
342 | - { |
|
343 | - return $this->_class_loaders; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * adds an alias for a classname |
|
350 | - * |
|
351 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
352 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
353 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
354 | - */ |
|
355 | - public function add_alias($class_name, $alias, $for_class = '') |
|
356 | - { |
|
357 | - if ($for_class !== '') { |
|
358 | - if (! isset($this->_aliases[$for_class])) { |
|
359 | - $this->_aliases[$for_class] = array(); |
|
360 | - } |
|
361 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
362 | - } |
|
363 | - $this->_aliases[$class_name] = $alias; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * returns TRUE if the provided class name has an alias |
|
370 | - * |
|
371 | - * @param string $class_name |
|
372 | - * @param string $for_class |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function has_alias($class_name = '', $for_class = '') |
|
376 | - { |
|
377 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
378 | - || ( |
|
379 | - isset($this->_aliases[$class_name]) |
|
380 | - && ! is_array($this->_aliases[$class_name]) |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
388 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
389 | - * for example: |
|
390 | - * if the following two entries were added to the _aliases array: |
|
391 | - * array( |
|
392 | - * 'interface_alias' => 'some\namespace\interface' |
|
393 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
394 | - * ) |
|
395 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
396 | - * to load an instance of 'some\namespace\classname' |
|
397 | - * |
|
398 | - * @param string $class_name |
|
399 | - * @param string $for_class |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_alias($class_name = '', $for_class = '') |
|
403 | - { |
|
404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
405 | - return $class_name; |
|
406 | - } |
|
407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
408 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
409 | - } |
|
410 | - return $this->get_alias($this->_aliases[$class_name]); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
417 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
418 | - * This is done by using the following class constants: |
|
419 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
420 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
421 | - */ |
|
422 | - protected function _register_core_dependencies() |
|
423 | - { |
|
424 | - $this->_dependency_map = array( |
|
425 | - 'EE_Request_Handler' => array( |
|
426 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
427 | - ), |
|
428 | - 'EE_System' => array( |
|
429 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
430 | - ), |
|
431 | - 'EE_Session' => array( |
|
432 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
433 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
434 | - ), |
|
435 | - 'EE_Cart' => array( |
|
436 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
437 | - ), |
|
438 | - 'EE_Front_Controller' => array( |
|
439 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
440 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
441 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
442 | - ), |
|
443 | - 'EE_Messenger_Collection_Loader' => array( |
|
444 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
445 | - ), |
|
446 | - 'EE_Message_Type_Collection_Loader' => array( |
|
447 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
448 | - ), |
|
449 | - 'EE_Message_Resource_Manager' => array( |
|
450 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
451 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
452 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
453 | - ), |
|
454 | - 'EE_Message_Factory' => array( |
|
455 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
456 | - ), |
|
457 | - 'EE_messages' => array( |
|
458 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
459 | - ), |
|
460 | - 'EE_Messages_Generator' => array( |
|
461 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
462 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
463 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
465 | - ), |
|
466 | - 'EE_Messages_Processor' => array( |
|
467 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
468 | - ), |
|
469 | - 'EE_Messages_Queue' => array( |
|
470 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
471 | - ), |
|
472 | - 'EE_Messages_Template_Defaults' => array( |
|
473 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
474 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
475 | - ), |
|
476 | - 'EE_Message_To_Generate_From_Request' => array( |
|
477 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
478 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
481 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
482 | - ), |
|
483 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
484 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
485 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
488 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
489 | - ), |
|
490 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
491 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
492 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
493 | - ), |
|
494 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
495 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
496 | - ), |
|
497 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
498 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
499 | - ), |
|
500 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
501 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
502 | - ), |
|
503 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
504 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
505 | - ), |
|
506 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
507 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
508 | - ), |
|
509 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
510 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
511 | - ), |
|
512 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
513 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
514 | - ), |
|
515 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
516 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
517 | - ), |
|
518 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
519 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
522 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
525 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
528 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
531 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EE_Data_Migration_Class_Base' => array( |
|
534 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
535 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
536 | - ), |
|
537 | - 'EE_DMS_Core_4_1_0' => array( |
|
538 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | - ), |
|
541 | - 'EE_DMS_Core_4_2_0' => array( |
|
542 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EE_DMS_Core_4_3_0' => array( |
|
546 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | - ), |
|
549 | - 'EE_DMS_Core_4_4_0' => array( |
|
550 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | - ), |
|
553 | - 'EE_DMS_Core_4_5_0' => array( |
|
554 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EE_DMS_Core_4_6_0' => array( |
|
558 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | - ), |
|
561 | - 'EE_DMS_Core_4_7_0' => array( |
|
562 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | - ), |
|
565 | - 'EE_DMS_Core_4_8_0' => array( |
|
566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | - ), |
|
569 | - 'EE_DMS_Core_4_9_0' => array( |
|
570 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | - ), |
|
573 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
574 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
575 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
576 | - ), |
|
577 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
578 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
579 | - ), |
|
580 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
581 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
582 | - ), |
|
583 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
584 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
587 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
588 | - ), |
|
589 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
590 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
591 | - ), |
|
592 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
593 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
594 | - ), |
|
595 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
596 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
597 | - ), |
|
598 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
599 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
600 | - ), |
|
601 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
602 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
603 | - ), |
|
604 | - ); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * Registers how core classes are loaded. |
|
611 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
612 | - * 'EE_Request_Handler' => 'load_core' |
|
613 | - * 'EE_Messages_Queue' => 'load_lib' |
|
614 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
615 | - * or, if greater control is required, by providing a custom closure. For example: |
|
616 | - * 'Some_Class' => function () { |
|
617 | - * return new Some_Class(); |
|
618 | - * }, |
|
619 | - * This is required for instantiating dependencies |
|
620 | - * where an interface has been type hinted in a class constructor. For example: |
|
621 | - * 'Required_Interface' => function () { |
|
622 | - * return new A_Class_That_Implements_Required_Interface(); |
|
623 | - * }, |
|
624 | - */ |
|
625 | - protected function _register_core_class_loaders() |
|
626 | - { |
|
627 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
628 | - //be used in a closure. |
|
629 | - $request = &$this->_request; |
|
630 | - $response = &$this->_response; |
|
631 | - $loader = &$this->loader; |
|
632 | - $this->_class_loaders = array( |
|
633 | - //load_core |
|
634 | - 'EE_Capabilities' => 'load_core', |
|
635 | - 'EE_Encryption' => 'load_core', |
|
636 | - 'EE_Front_Controller' => 'load_core', |
|
637 | - 'EE_Module_Request_Router' => 'load_core', |
|
638 | - 'EE_Registry' => 'load_core', |
|
639 | - 'EE_Request' => function () use (&$request) { |
|
640 | - return $request; |
|
641 | - }, |
|
642 | - 'EE_Response' => function () use (&$response) { |
|
643 | - return $response; |
|
644 | - }, |
|
645 | - 'EE_Request_Handler' => 'load_core', |
|
646 | - 'EE_Session' => 'load_core', |
|
647 | - 'EE_System' => 'load_core', |
|
648 | - //load_lib |
|
649 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
650 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
651 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
652 | - 'EE_Messenger_Collection' => 'load_lib', |
|
653 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
654 | - 'EE_Messages_Processor' => 'load_lib', |
|
655 | - 'EE_Message_Repository' => 'load_lib', |
|
656 | - 'EE_Messages_Queue' => 'load_lib', |
|
657 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
658 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
659 | - 'EE_Messages_Generator' => function () { |
|
660 | - return EE_Registry::instance()->load_lib( |
|
661 | - 'Messages_Generator', |
|
662 | - array(), |
|
663 | - false, |
|
664 | - false |
|
665 | - ); |
|
666 | - }, |
|
667 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
668 | - return EE_Registry::instance()->load_lib( |
|
669 | - 'Messages_Template_Defaults', |
|
670 | - $arguments, |
|
671 | - false, |
|
672 | - false |
|
673 | - ); |
|
674 | - }, |
|
675 | - //load_model |
|
676 | - 'EEM_Message_Template_Group' => 'load_model', |
|
677 | - 'EEM_Message_Template' => 'load_model', |
|
678 | - //load_helper |
|
679 | - 'EEH_Parse_Shortcodes' => function () { |
|
680 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
681 | - return new EEH_Parse_Shortcodes(); |
|
682 | - } |
|
683 | - return null; |
|
684 | - }, |
|
685 | - 'EE_Template_Config' => function () { |
|
686 | - return EE_Config::instance()->template_settings; |
|
687 | - }, |
|
688 | - 'EE_Currency_Config' => function () { |
|
689 | - return EE_Config::instance()->currency; |
|
690 | - }, |
|
691 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
692 | - return $loader; |
|
693 | - }, |
|
694 | - ); |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * can be used for supplying alternate names for classes, |
|
701 | - * or for connecting interface names to instantiable classes |
|
702 | - */ |
|
703 | - protected function _register_core_aliases() |
|
704 | - { |
|
705 | - $this->_aliases = array( |
|
706 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
707 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
708 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
709 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
710 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
711 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
712 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
713 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
714 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
715 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
716 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
717 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
718 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
719 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
720 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
721 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
722 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
723 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
724 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
725 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
726 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
727 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
728 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
729 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
730 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
731 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
732 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
733 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
734 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
735 | - ); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
742 | - * request Primarily used by unit tests. |
|
743 | - */ |
|
744 | - public function reset() |
|
745 | - { |
|
746 | - $this->_register_core_class_loaders(); |
|
747 | - $this->_register_core_dependencies(); |
|
748 | - } |
|
24 | + /** |
|
25 | + * This means that the requested class dependency is not present in the dependency map |
|
26 | + */ |
|
27 | + const not_registered = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | + */ |
|
32 | + const load_new_object = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | + */ |
|
38 | + const load_from_cache = 2; |
|
39 | + |
|
40 | + /** |
|
41 | + * When registering a dependency, |
|
42 | + * this indicates to keep any existing dependencies that already exist, |
|
43 | + * and simply discard any new dependencies declared in the incoming data |
|
44 | + */ |
|
45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * When registering a dependency, |
|
49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | + */ |
|
51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @type EE_Dependency_Map $_instance |
|
57 | + */ |
|
58 | + protected static $_instance; |
|
59 | + |
|
60 | + /** |
|
61 | + * @type EE_Request $request |
|
62 | + */ |
|
63 | + protected $_request; |
|
64 | + |
|
65 | + /** |
|
66 | + * @type EE_Response $response |
|
67 | + */ |
|
68 | + protected $_response; |
|
69 | + |
|
70 | + /** |
|
71 | + * @type LoaderInterface $loader |
|
72 | + */ |
|
73 | + protected $loader; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type array $_dependency_map |
|
77 | + */ |
|
78 | + protected $_dependency_map = array(); |
|
79 | + |
|
80 | + /** |
|
81 | + * @type array $_class_loaders |
|
82 | + */ |
|
83 | + protected $_class_loaders = array(); |
|
84 | + |
|
85 | + /** |
|
86 | + * @type array $_aliases |
|
87 | + */ |
|
88 | + protected $_aliases = array(); |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * EE_Dependency_Map constructor. |
|
94 | + * |
|
95 | + * @param EE_Request $request |
|
96 | + * @param EE_Response $response |
|
97 | + */ |
|
98 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | + { |
|
100 | + $this->_request = $request; |
|
101 | + $this->_response = $response; |
|
102 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | + do_action('EE_Dependency_Map____construct'); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidInterfaceException |
|
111 | + * @throws InvalidArgumentException |
|
112 | + */ |
|
113 | + public function initialize() |
|
114 | + { |
|
115 | + $this->_register_core_dependencies(); |
|
116 | + $this->_register_core_class_loaders(); |
|
117 | + $this->_register_core_aliases(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @singleton method used to instantiate class object |
|
124 | + * @access public |
|
125 | + * @param EE_Request $request |
|
126 | + * @param EE_Response $response |
|
127 | + * @return EE_Dependency_Map |
|
128 | + */ |
|
129 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | + { |
|
131 | + // check if class object is instantiated, and instantiated properly |
|
132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | + } |
|
135 | + return self::$_instance; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param LoaderInterface $loader |
|
142 | + */ |
|
143 | + public function setLoader(LoaderInterface $loader) |
|
144 | + { |
|
145 | + $this->loader = $loader; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $class |
|
152 | + * @param array $dependencies |
|
153 | + * @param int $overwrite |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + public static function register_dependencies( |
|
157 | + $class, |
|
158 | + array $dependencies, |
|
159 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | + ) { |
|
161 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | + * to the class specified by the first parameter. |
|
169 | + * IMPORTANT !!! |
|
170 | + * The order of elements in the incoming $dependencies array MUST match |
|
171 | + * the order of the constructor parameters for the class in question. |
|
172 | + * This is especially important when overriding any existing dependencies that are registered. |
|
173 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | + * |
|
175 | + * @param string $class |
|
176 | + * @param array $dependencies |
|
177 | + * @param int $overwrite |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function registerDependencies( |
|
181 | + $class, |
|
182 | + array $dependencies, |
|
183 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | + ) { |
|
185 | + $registered = false; |
|
186 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
188 | + } |
|
189 | + // we need to make sure that any aliases used when registering a dependency |
|
190 | + // get resolved to the correct class name |
|
191 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
192 | + $alias = self::$_instance->get_alias($dependency); |
|
193 | + if ( |
|
194 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
195 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
196 | + ) { |
|
197 | + unset($dependencies[$dependency]); |
|
198 | + $dependencies[$alias] = $load_source; |
|
199 | + $registered = true; |
|
200 | + } |
|
201 | + } |
|
202 | + // now add our two lists of dependencies together. |
|
203 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
204 | + // so $dependencies is NOT overwritten because it is listed first |
|
205 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
206 | + // Union is way faster than array_merge() but should be used with caution... |
|
207 | + // especially with numerically indexed arrays |
|
208 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
209 | + // now we need to ensure that the resulting dependencies |
|
210 | + // array only has the entries that are required for the class |
|
211 | + // so first count how many dependencies were originally registered for the class |
|
212 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
213 | + // if that count is non-zero (meaning dependencies were already registered) |
|
214 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
215 | + // then truncate the final array to match that count |
|
216 | + ? array_slice($dependencies, 0, $dependency_count) |
|
217 | + // otherwise just take the incoming array because nothing previously existed |
|
218 | + : $dependencies; |
|
219 | + return $registered; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @param string $class_name |
|
226 | + * @param string $loader |
|
227 | + * @return bool |
|
228 | + * @throws DomainException |
|
229 | + */ |
|
230 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
231 | + { |
|
232 | + if (strpos($class_name, '\\') !== false) { |
|
233 | + throw new DomainException( |
|
234 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
235 | + ); |
|
236 | + } |
|
237 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
238 | + if ( |
|
239 | + ! is_callable($loader) |
|
240 | + && ( |
|
241 | + strpos($loader, 'load_') !== 0 |
|
242 | + || ! method_exists('EE_Registry', $loader) |
|
243 | + ) |
|
244 | + ) { |
|
245 | + throw new DomainException( |
|
246 | + sprintf( |
|
247 | + esc_html__( |
|
248 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
249 | + 'event_espresso' |
|
250 | + ), |
|
251 | + $loader |
|
252 | + ) |
|
253 | + ); |
|
254 | + } |
|
255 | + $class_name = self::$_instance->get_alias($class_name); |
|
256 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
258 | + return true; |
|
259 | + } |
|
260 | + return false; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return array |
|
267 | + */ |
|
268 | + public function dependency_map() |
|
269 | + { |
|
270 | + return $this->_dependency_map; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
277 | + * |
|
278 | + * @param string $class_name |
|
279 | + * @return boolean |
|
280 | + */ |
|
281 | + public function has($class_name = '') |
|
282 | + { |
|
283 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
290 | + * |
|
291 | + * @param string $class_name |
|
292 | + * @param string $dependency |
|
293 | + * @return bool |
|
294 | + */ |
|
295 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
296 | + { |
|
297 | + $dependency = $this->get_alias($dependency); |
|
298 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
299 | + ? true |
|
300 | + : false; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
307 | + * |
|
308 | + * @param string $class_name |
|
309 | + * @param string $dependency |
|
310 | + * @return int |
|
311 | + */ |
|
312 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
313 | + { |
|
314 | + $dependency = $this->get_alias($dependency); |
|
315 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
316 | + ? $this->_dependency_map[$class_name][$dependency] |
|
317 | + : EE_Dependency_Map::not_registered; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @param string $class_name |
|
324 | + * @return string | Closure |
|
325 | + */ |
|
326 | + public function class_loader($class_name) |
|
327 | + { |
|
328 | + // don't use loaders for FQCNs |
|
329 | + if(strpos($class_name, '\\') !== false){ |
|
330 | + return ''; |
|
331 | + } |
|
332 | + $class_name = $this->get_alias($class_name); |
|
333 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @return array |
|
340 | + */ |
|
341 | + public function class_loaders() |
|
342 | + { |
|
343 | + return $this->_class_loaders; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * adds an alias for a classname |
|
350 | + * |
|
351 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
352 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
353 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
354 | + */ |
|
355 | + public function add_alias($class_name, $alias, $for_class = '') |
|
356 | + { |
|
357 | + if ($for_class !== '') { |
|
358 | + if (! isset($this->_aliases[$for_class])) { |
|
359 | + $this->_aliases[$for_class] = array(); |
|
360 | + } |
|
361 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
362 | + } |
|
363 | + $this->_aliases[$class_name] = $alias; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * returns TRUE if the provided class name has an alias |
|
370 | + * |
|
371 | + * @param string $class_name |
|
372 | + * @param string $for_class |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function has_alias($class_name = '', $for_class = '') |
|
376 | + { |
|
377 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
378 | + || ( |
|
379 | + isset($this->_aliases[$class_name]) |
|
380 | + && ! is_array($this->_aliases[$class_name]) |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
388 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
389 | + * for example: |
|
390 | + * if the following two entries were added to the _aliases array: |
|
391 | + * array( |
|
392 | + * 'interface_alias' => 'some\namespace\interface' |
|
393 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
394 | + * ) |
|
395 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
396 | + * to load an instance of 'some\namespace\classname' |
|
397 | + * |
|
398 | + * @param string $class_name |
|
399 | + * @param string $for_class |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_alias($class_name = '', $for_class = '') |
|
403 | + { |
|
404 | + if (! $this->has_alias($class_name, $for_class)) { |
|
405 | + return $class_name; |
|
406 | + } |
|
407 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
408 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
409 | + } |
|
410 | + return $this->get_alias($this->_aliases[$class_name]); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
417 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
418 | + * This is done by using the following class constants: |
|
419 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
420 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
421 | + */ |
|
422 | + protected function _register_core_dependencies() |
|
423 | + { |
|
424 | + $this->_dependency_map = array( |
|
425 | + 'EE_Request_Handler' => array( |
|
426 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
427 | + ), |
|
428 | + 'EE_System' => array( |
|
429 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
430 | + ), |
|
431 | + 'EE_Session' => array( |
|
432 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
433 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
434 | + ), |
|
435 | + 'EE_Cart' => array( |
|
436 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
437 | + ), |
|
438 | + 'EE_Front_Controller' => array( |
|
439 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
440 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
441 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
442 | + ), |
|
443 | + 'EE_Messenger_Collection_Loader' => array( |
|
444 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
445 | + ), |
|
446 | + 'EE_Message_Type_Collection_Loader' => array( |
|
447 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
448 | + ), |
|
449 | + 'EE_Message_Resource_Manager' => array( |
|
450 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
451 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
452 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
453 | + ), |
|
454 | + 'EE_Message_Factory' => array( |
|
455 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
456 | + ), |
|
457 | + 'EE_messages' => array( |
|
458 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
459 | + ), |
|
460 | + 'EE_Messages_Generator' => array( |
|
461 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
462 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
463 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
465 | + ), |
|
466 | + 'EE_Messages_Processor' => array( |
|
467 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
468 | + ), |
|
469 | + 'EE_Messages_Queue' => array( |
|
470 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
471 | + ), |
|
472 | + 'EE_Messages_Template_Defaults' => array( |
|
473 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
474 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
475 | + ), |
|
476 | + 'EE_Message_To_Generate_From_Request' => array( |
|
477 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
478 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
481 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
482 | + ), |
|
483 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
484 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
485 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
488 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
489 | + ), |
|
490 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
491 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
492 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
493 | + ), |
|
494 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
495 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
496 | + ), |
|
497 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
498 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
499 | + ), |
|
500 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
501 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
502 | + ), |
|
503 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
504 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
505 | + ), |
|
506 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
507 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
508 | + ), |
|
509 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
510 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
511 | + ), |
|
512 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
513 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
514 | + ), |
|
515 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
516 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
517 | + ), |
|
518 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
519 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
522 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
525 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
528 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
531 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EE_Data_Migration_Class_Base' => array( |
|
534 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
535 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
536 | + ), |
|
537 | + 'EE_DMS_Core_4_1_0' => array( |
|
538 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | + ), |
|
541 | + 'EE_DMS_Core_4_2_0' => array( |
|
542 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EE_DMS_Core_4_3_0' => array( |
|
546 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | + ), |
|
549 | + 'EE_DMS_Core_4_4_0' => array( |
|
550 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | + ), |
|
553 | + 'EE_DMS_Core_4_5_0' => array( |
|
554 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EE_DMS_Core_4_6_0' => array( |
|
558 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | + ), |
|
561 | + 'EE_DMS_Core_4_7_0' => array( |
|
562 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | + ), |
|
565 | + 'EE_DMS_Core_4_8_0' => array( |
|
566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | + ), |
|
569 | + 'EE_DMS_Core_4_9_0' => array( |
|
570 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | + ), |
|
573 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
574 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
575 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
576 | + ), |
|
577 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
578 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
579 | + ), |
|
580 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
581 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
582 | + ), |
|
583 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
584 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
587 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
588 | + ), |
|
589 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
590 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
591 | + ), |
|
592 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
593 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
594 | + ), |
|
595 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
596 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
597 | + ), |
|
598 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
599 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
600 | + ), |
|
601 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
602 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
603 | + ), |
|
604 | + ); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * Registers how core classes are loaded. |
|
611 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
612 | + * 'EE_Request_Handler' => 'load_core' |
|
613 | + * 'EE_Messages_Queue' => 'load_lib' |
|
614 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
615 | + * or, if greater control is required, by providing a custom closure. For example: |
|
616 | + * 'Some_Class' => function () { |
|
617 | + * return new Some_Class(); |
|
618 | + * }, |
|
619 | + * This is required for instantiating dependencies |
|
620 | + * where an interface has been type hinted in a class constructor. For example: |
|
621 | + * 'Required_Interface' => function () { |
|
622 | + * return new A_Class_That_Implements_Required_Interface(); |
|
623 | + * }, |
|
624 | + */ |
|
625 | + protected function _register_core_class_loaders() |
|
626 | + { |
|
627 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
628 | + //be used in a closure. |
|
629 | + $request = &$this->_request; |
|
630 | + $response = &$this->_response; |
|
631 | + $loader = &$this->loader; |
|
632 | + $this->_class_loaders = array( |
|
633 | + //load_core |
|
634 | + 'EE_Capabilities' => 'load_core', |
|
635 | + 'EE_Encryption' => 'load_core', |
|
636 | + 'EE_Front_Controller' => 'load_core', |
|
637 | + 'EE_Module_Request_Router' => 'load_core', |
|
638 | + 'EE_Registry' => 'load_core', |
|
639 | + 'EE_Request' => function () use (&$request) { |
|
640 | + return $request; |
|
641 | + }, |
|
642 | + 'EE_Response' => function () use (&$response) { |
|
643 | + return $response; |
|
644 | + }, |
|
645 | + 'EE_Request_Handler' => 'load_core', |
|
646 | + 'EE_Session' => 'load_core', |
|
647 | + 'EE_System' => 'load_core', |
|
648 | + //load_lib |
|
649 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
650 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
651 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
652 | + 'EE_Messenger_Collection' => 'load_lib', |
|
653 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
654 | + 'EE_Messages_Processor' => 'load_lib', |
|
655 | + 'EE_Message_Repository' => 'load_lib', |
|
656 | + 'EE_Messages_Queue' => 'load_lib', |
|
657 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
658 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
659 | + 'EE_Messages_Generator' => function () { |
|
660 | + return EE_Registry::instance()->load_lib( |
|
661 | + 'Messages_Generator', |
|
662 | + array(), |
|
663 | + false, |
|
664 | + false |
|
665 | + ); |
|
666 | + }, |
|
667 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
668 | + return EE_Registry::instance()->load_lib( |
|
669 | + 'Messages_Template_Defaults', |
|
670 | + $arguments, |
|
671 | + false, |
|
672 | + false |
|
673 | + ); |
|
674 | + }, |
|
675 | + //load_model |
|
676 | + 'EEM_Message_Template_Group' => 'load_model', |
|
677 | + 'EEM_Message_Template' => 'load_model', |
|
678 | + //load_helper |
|
679 | + 'EEH_Parse_Shortcodes' => function () { |
|
680 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
681 | + return new EEH_Parse_Shortcodes(); |
|
682 | + } |
|
683 | + return null; |
|
684 | + }, |
|
685 | + 'EE_Template_Config' => function () { |
|
686 | + return EE_Config::instance()->template_settings; |
|
687 | + }, |
|
688 | + 'EE_Currency_Config' => function () { |
|
689 | + return EE_Config::instance()->currency; |
|
690 | + }, |
|
691 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
692 | + return $loader; |
|
693 | + }, |
|
694 | + ); |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * can be used for supplying alternate names for classes, |
|
701 | + * or for connecting interface names to instantiable classes |
|
702 | + */ |
|
703 | + protected function _register_core_aliases() |
|
704 | + { |
|
705 | + $this->_aliases = array( |
|
706 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
707 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
708 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
709 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
710 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
711 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
712 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
713 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
714 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
715 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
716 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
717 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
718 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
719 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
720 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
721 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
722 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
723 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
724 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
725 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
726 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
727 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
728 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
729 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
730 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
731 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
732 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
733 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
734 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
735 | + ); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
742 | + * request Primarily used by unit tests. |
|
743 | + */ |
|
744 | + public function reset() |
|
745 | + { |
|
746 | + $this->_register_core_class_loaders(); |
|
747 | + $this->_register_core_dependencies(); |
|
748 | + } |
|
749 | 749 | |
750 | 750 | |
751 | 751 | } |